From 925b177bad048af489624f02ce14ce2ce365507b Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 23 Apr 2020 14:48:15 +0100 Subject: [PATCH] Support Proj sampling variants with manual q divide --- renderdoc/driver/vulkan/vk_shaderdebug.cpp | 69 ++++++++++++---------- util/test/demos/vk/vk_shader_debug_zoo.cpp | 5 ++ 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/renderdoc/driver/vulkan/vk_shaderdebug.cpp b/renderdoc/driver/vulkan/vk_shaderdebug.cpp index cee02876e..e42f8dd7b 100644 --- a/renderdoc/driver/vulkan/vk_shaderdebug.cpp +++ b/renderdoc/driver/vulkan/vk_shaderdebug.cpp @@ -632,16 +632,33 @@ public: constParams.operation = (uint32_t)opcode; - // proj opcodes have an extra q parameter + // proj opcodes have an extra q parameter, but we do the divide ourselves and 'demote' these to + // non-proj variants + bool proj = false; switch(opcode) { case rdcspv::Op::ImageSampleProjExplicitLod: + { + constParams.operation = (uint32_t)rdcspv::Op::ImageSampleExplicitLod; + proj = true; + break; + } case rdcspv::Op::ImageSampleProjImplicitLod: + { + constParams.operation = (uint32_t)rdcspv::Op::ImageSampleImplicitLod; + proj = true; + break; + } case rdcspv::Op::ImageSampleProjDrefExplicitLod: + { + constParams.operation = (uint32_t)rdcspv::Op::ImageSampleDrefExplicitLod; + proj = true; + break; + } case rdcspv::Op::ImageSampleProjDrefImplicitLod: { - coords++; - gradCoords++; + constParams.operation = (uint32_t)rdcspv::Op::ImageSampleDrefImplicitLod; + proj = true; break; } default: break; @@ -753,6 +770,16 @@ public: if(coords >= 3) uniformParams.uvw.z = uv.value.f.z; + if(proj) + { + // do the divide ourselves rather than severely complicating the sample shader (as proj + // variants need non-arrayed textures) + float q = uv.value.fv[coords]; + uniformParams.uvw.x /= q; + uniformParams.uvw.y /= q; + uniformParams.uvw.z /= q; + } + if(operands.flags & rdcspv::ImageOperands::MinLod) uniformParams.minlod = lane.GetSrc(operands.minLod).value.f.x; @@ -1831,8 +1858,6 @@ private: uint32_t sampIdx = (uint32_t)ShaderDebugBind::Sampler; - // TODO handle Proj opcodes, that need non-arrayed texture views, or else a manual divide - rdcspv::Id zerof = editor.AddConstantImmediate(0.0f); for(uint32_t i = (uint32_t)ShaderDebugBind::First; i < (uint32_t)ShaderDebugBind::Count; i++) @@ -1897,12 +1922,8 @@ private: rdcspv::Id combined = cases.add(rdcspv::OpSampledImage( texSampCombinedTypes[i], editor.MakeId(), loadedImage, loadedSampler)); - if(op == rdcspv::Op::ImageSampleExplicitLod || op == rdcspv::Op::ImageSampleImplicitLod) - lodResult = cases.add(rdcspv::OpImageSampleExplicitLod(resultType, editor.MakeId(), - combined, coord[i], operands)); - else - lodResult = cases.add(rdcspv::OpImageSampleProjExplicitLod( - resultType, editor.MakeId(), combined, coord[i], operands)); + lodResult = cases.add(rdcspv::OpImageSampleExplicitLod(resultType, editor.MakeId(), + combined, coord[i], operands)); cases.add(rdcspv::OpBranch(mergeLabel)); } @@ -1917,12 +1938,8 @@ private: rdcspv::Id combined = cases.add(rdcspv::OpSampledImage( texSampCombinedTypes[i], editor.MakeId(), loadedImage, loadedSampler)); - if(op == rdcspv::Op::ImageSampleExplicitLod || op == rdcspv::Op::ImageSampleImplicitLod) - gradResult = cases.add(rdcspv::OpImageSampleExplicitLod(resultType, editor.MakeId(), - combined, coord[i], operands)); - else - gradResult = cases.add(rdcspv::OpImageSampleProjExplicitLod( - resultType, editor.MakeId(), combined, coord[i], operands)); + gradResult = cases.add(rdcspv::OpImageSampleExplicitLod(resultType, editor.MakeId(), + combined, coord[i], operands)); cases.add(rdcspv::OpBranch(mergeLabel)); } @@ -1965,13 +1982,8 @@ private: rdcspv::Id combined = cases.add(rdcspv::OpSampledImage( texSampCombinedTypes[i], editor.MakeId(), loadedImage, loadedSampler)); - if(op == rdcspv::Op::ImageSampleDrefExplicitLod || - op == rdcspv::Op::ImageSampleDrefImplicitLod) - lodResult = cases.add(rdcspv::OpImageSampleDrefExplicitLod( - scalarResultType, editor.MakeId(), combined, coord[i], compare, operands)); - else - lodResult = cases.add(rdcspv::OpImageSampleProjDrefExplicitLod( - scalarResultType, editor.MakeId(), combined, coord[i], compare, operands)); + lodResult = cases.add(rdcspv::OpImageSampleDrefExplicitLod( + scalarResultType, editor.MakeId(), combined, coord[i], compare, operands)); cases.add(rdcspv::OpBranch(mergeLabel)); } @@ -1986,13 +1998,8 @@ private: rdcspv::Id combined = cases.add(rdcspv::OpSampledImage( texSampCombinedTypes[i], editor.MakeId(), loadedImage, loadedSampler)); - if(op == rdcspv::Op::ImageSampleDrefExplicitLod || - op == rdcspv::Op::ImageSampleDrefImplicitLod) - gradResult = cases.add(rdcspv::OpImageSampleDrefExplicitLod( - scalarResultType, editor.MakeId(), combined, coord[i], compare, operands)); - else - gradResult = cases.add(rdcspv::OpImageSampleProjDrefExplicitLod( - scalarResultType, editor.MakeId(), combined, coord[i], compare, operands)); + gradResult = cases.add(rdcspv::OpImageSampleDrefExplicitLod( + scalarResultType, editor.MakeId(), combined, coord[i], compare, operands)); cases.add(rdcspv::OpBranch(mergeLabel)); } diff --git a/util/test/demos/vk/vk_shader_debug_zoo.cpp b/util/test/demos/vk/vk_shader_debug_zoo.cpp index 06322553b..29d7da1df 100644 --- a/util/test/demos/vk/vk_shader_debug_zoo.cpp +++ b/util/test/demos/vk/vk_shader_debug_zoo.cpp @@ -1069,6 +1069,11 @@ void main() Color = storebuf.x; break; } + case 129: + { + Color = textureProj(linearSampledImage, vec3(inpos, 0.5f)); + break; + } default: break; } }