diff options
| author | 2020-12-30 01:41:42 -0300 | |
|---|---|---|
| committer | 2020-12-30 01:41:42 -0300 | |
| commit | 59c46f9de94d3eab3aec3ff2abc74bd3aa8a056c (patch) | |
| tree | b3446487d21e13b26e9950e4143347586877d094 | |
| parent | host_shaders: Add block linear upload compute shaders (diff) | |
| download | yuzu-59c46f9de94d3eab3aec3ff2abc74bd3aa8a056c.tar.gz yuzu-59c46f9de94d3eab3aec3ff2abc74bd3aa8a056c.tar.xz yuzu-59c46f9de94d3eab3aec3ff2abc74bd3aa8a056c.zip | |
host_shaders: Add pitch linear upload compute shader
| -rw-r--r-- | src/video_core/host_shaders/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/video_core/host_shaders/pitch_unswizzle.comp | 86 |
2 files changed, 87 insertions, 0 deletions
diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt index 7feb6df99..1983e7dc9 100644 --- a/src/video_core/host_shaders/CMakeLists.txt +++ b/src/video_core/host_shaders/CMakeLists.txt | |||
| @@ -3,6 +3,7 @@ set(SHADER_FILES | |||
| 3 | block_linear_unswizzle_3d.comp | 3 | block_linear_unswizzle_3d.comp |
| 4 | opengl_present.frag | 4 | opengl_present.frag |
| 5 | opengl_present.vert | 5 | opengl_present.vert |
| 6 | pitch_unswizzle.comp | ||
| 6 | ) | 7 | ) |
| 7 | 8 | ||
| 8 | find_program(GLSLANGVALIDATOR "glslangValidator" REQUIRED) | 9 | find_program(GLSLANGVALIDATOR "glslangValidator" REQUIRED) |
diff --git a/src/video_core/host_shaders/pitch_unswizzle.comp b/src/video_core/host_shaders/pitch_unswizzle.comp new file mode 100644 index 000000000..cb48ec170 --- /dev/null +++ b/src/video_core/host_shaders/pitch_unswizzle.comp | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #version 430 | ||
| 6 | |||
| 7 | #ifdef VULKAN | ||
| 8 | |||
| 9 | #extension GL_EXT_shader_16bit_storage : require | ||
| 10 | #extension GL_EXT_shader_8bit_storage : require | ||
| 11 | #define HAS_EXTENDED_TYPES 1 | ||
| 12 | #define BEGIN_PUSH_CONSTANTS layout(push_constant) uniform PushConstants { | ||
| 13 | #define END_PUSH_CONSTANTS }; | ||
| 14 | #define UNIFORM(n) | ||
| 15 | #define BINDING_INPUT_BUFFER 0 | ||
| 16 | #define BINDING_OUTPUT_IMAGE 1 | ||
| 17 | |||
| 18 | #else // ^^^ Vulkan ^^^ // vvv OpenGL vvv | ||
| 19 | |||
| 20 | #extension GL_NV_gpu_shader5 : enable | ||
| 21 | #ifdef GL_NV_gpu_shader5 | ||
| 22 | #define HAS_EXTENDED_TYPES 1 | ||
| 23 | #else | ||
| 24 | #define HAS_EXTENDED_TYPES 0 | ||
| 25 | #endif | ||
| 26 | #define BEGIN_PUSH_CONSTANTS | ||
| 27 | #define END_PUSH_CONSTANTS | ||
| 28 | #define UNIFORM(n) layout (location = n) uniform | ||
| 29 | #define BINDING_INPUT_BUFFER 0 | ||
| 30 | #define BINDING_OUTPUT_IMAGE 0 | ||
| 31 | |||
| 32 | #endif | ||
| 33 | |||
| 34 | BEGIN_PUSH_CONSTANTS | ||
| 35 | UNIFORM(0) uvec2 origin; | ||
| 36 | UNIFORM(1) ivec2 destination; | ||
| 37 | UNIFORM(2) uint bytes_per_block; | ||
| 38 | UNIFORM(3) uint pitch; | ||
| 39 | END_PUSH_CONSTANTS | ||
| 40 | |||
| 41 | #if HAS_EXTENDED_TYPES | ||
| 42 | layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU8 { uint8_t u8data[]; }; | ||
| 43 | layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU16 { uint16_t u16data[]; }; | ||
| 44 | #endif | ||
| 45 | layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU32 { uint u32data[]; }; | ||
| 46 | layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU64 { uvec2 u64data[]; }; | ||
| 47 | layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU128 { uvec4 u128data[]; }; | ||
| 48 | |||
| 49 | layout(binding = BINDING_OUTPUT_IMAGE) writeonly uniform uimage2D output_image; | ||
| 50 | |||
| 51 | layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in; | ||
| 52 | |||
| 53 | uvec4 ReadTexel(uint offset) { | ||
| 54 | switch (bytes_per_block) { | ||
| 55 | #if HAS_EXTENDED_TYPES | ||
| 56 | case 1: | ||
| 57 | return uvec4(u8data[offset], 0, 0, 0); | ||
| 58 | case 2: | ||
| 59 | return uvec4(u16data[offset / 2], 0, 0, 0); | ||
| 60 | #else | ||
| 61 | case 1: | ||
| 62 | return uvec4(bitfieldExtract(u32data[offset / 4], int((offset * 8) & 24), 8), 0, 0, 0); | ||
| 63 | case 2: | ||
| 64 | return uvec4(bitfieldExtract(u32data[offset / 4], int((offset * 8) & 16), 16), 0, 0, 0); | ||
| 65 | #endif | ||
| 66 | case 4: | ||
| 67 | return uvec4(u32data[offset / 4], 0, 0, 0); | ||
| 68 | case 8: | ||
| 69 | return uvec4(u64data[offset / 8], 0, 0); | ||
| 70 | case 16: | ||
| 71 | return u128data[offset / 16]; | ||
| 72 | } | ||
| 73 | return uvec4(0); | ||
| 74 | } | ||
| 75 | |||
| 76 | void main() { | ||
| 77 | uvec2 pos = gl_GlobalInvocationID.xy + origin; | ||
| 78 | |||
| 79 | uint offset = 0; | ||
| 80 | offset += pos.x * bytes_per_block; | ||
| 81 | offset += pos.y * pitch; | ||
| 82 | |||
| 83 | const uvec4 texel = ReadTexel(offset); | ||
| 84 | const ivec2 coord = ivec2(gl_GlobalInvocationID.xy) + destination; | ||
| 85 | imageStore(output_image, coord, texel); | ||
| 86 | } | ||