ConvertD32S8ToD24S8ShaderSource.comp 1.5 KB

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