summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2020-12-30 01:41:42 -0300
committerGravatar ReinUsesLisp2020-12-30 01:41:42 -0300
commit59c46f9de94d3eab3aec3ff2abc74bd3aa8a056c (patch)
treeb3446487d21e13b26e9950e4143347586877d094
parenthost_shaders: Add block linear upload compute shaders (diff)
downloadyuzu-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.txt1
-rw-r--r--src/video_core/host_shaders/pitch_unswizzle.comp86
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
8find_program(GLSLANGVALIDATOR "glslangValidator" REQUIRED) 9find_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
34BEGIN_PUSH_CONSTANTS
35UNIFORM(0) uvec2 origin;
36UNIFORM(1) ivec2 destination;
37UNIFORM(2) uint bytes_per_block;
38UNIFORM(3) uint pitch;
39END_PUSH_CONSTANTS
40
41#if HAS_EXTENDED_TYPES
42layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU8 { uint8_t u8data[]; };
43layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU16 { uint16_t u16data[]; };
44#endif
45layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU32 { uint u32data[]; };
46layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU64 { uvec2 u64data[]; };
47layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU128 { uvec4 u128data[]; };
48
49layout(binding = BINDING_OUTPUT_IMAGE) writeonly uniform uimage2D output_image;
50
51layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in;
52
53uvec4 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
76void 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}