/ src / Ryujinx.Graphics.Vulkan / Shaders / ConvertD32S8ToD24S8ShaderSource.comp
ConvertD32S8ToD24S8ShaderSource.comp
 1  #version 450 core
 2  
 3  #extension GL_EXT_scalar_block_layout : require
 4  
 5  layout (local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
 6  
 7  layout (std430, set = 0, binding = 0) uniform stride_arguments
 8  {
 9      int pixelCount;
10      int dstStartOffset;
11  };
12  
13  layout (std430, set = 1, binding = 1) buffer in_s
14  {
15      uint[] in_data;
16  };
17  
18  layout (std430, set = 1, binding = 2) buffer out_s
19  {
20      uint[] out_data;
21  };
22  
23  void main()
24  {
25      // Determine what slice of the stride copies this invocation will perform.
26      int invocations = int(gl_WorkGroupSize.x * gl_NumWorkGroups.x);
27  
28      int copiesRequired = pixelCount;
29  
30      // Find the copies that this invocation should perform.
31      
32      // - Copies that all invocations perform.
33      int allInvocationCopies = copiesRequired / invocations;
34  
35      // - Extra remainder copy that this invocation performs.
36      int index = int(gl_GlobalInvocationID.x);
37      int extra = (index < (copiesRequired % invocations)) ? 1 : 0;
38  
39      int copyCount = allInvocationCopies + extra;
40  
41      // Finally, get the starting offset. Make sure to count extra copies.
42  
43      int startCopy = allInvocationCopies * index + min(copiesRequired % invocations, index);
44  
45      int srcOffset = startCopy * 2;
46      int dstOffset = dstStartOffset + startCopy;
47  
48      // Perform the conversion for this region.
49      for (int i = 0; i < copyCount; i++)
50      {
51          float depth = uintBitsToFloat(in_data[srcOffset++]);
52          uint stencil = in_data[srcOffset++];
53  
54          uint rescaledDepth = uint(clamp(depth, 0.0, 1.0) * 16777215.0);
55  
56          out_data[dstOffset++] = (rescaledDepth << 8) | (stencil & 0xff);
57      }
58  }