From 24baf58ae39b67f9c189db7542ea7a7f6d513d11 Mon Sep 17 00:00:00 2001 From: DrChat Date: Fri, 23 Feb 2018 00:00:07 -0600 Subject: [PATCH] [SPIR-V] Proper implementation of getGradients --- src/xenia/gpu/spirv_shader_translator.cc | 29 ++++++++++-------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/xenia/gpu/spirv_shader_translator.cc b/src/xenia/gpu/spirv_shader_translator.cc index 6171ba165..db5256b1e 100644 --- a/src/xenia/gpu/spirv_shader_translator.cc +++ b/src/xenia/gpu/spirv_shader_translator.cc @@ -1846,26 +1846,21 @@ void SpirvShaderTranslator::ProcessTextureFetchInstruction( dest = b.createTextureCall(spv::NoPrecision, vec4_float_type_, false, false, false, false, false, params); } break; + case FetchOpcode::kGetTextureGradients: { - auto texture_index = - b.makeUintConstant(tex_binding_map_[instr.operands[2].storage_index]); - auto texture_ptr = - b.createAccessChain(spv::StorageClass::StorageClassUniformConstant, - tex_[dim_idx], std::vector({texture_index})); - auto texture = b.createLoad(texture_ptr); + Id src_x = b.createCompositeExtract(src, float_type_, 0); + Id src_y = b.createCompositeExtract(src, float_type_, 1); - Id grad = LoadFromOperand(instr.operands[1]); - Id gradX = b.createCompositeExtract(grad, float_type_, 0); - Id gradY = b.createCompositeExtract(grad, float_type_, 1); - - spv::Builder::TextureParameters params = {0}; - params.coords = src; - params.sampler = texture; - params.gradX = gradX; - params.gradY = gradY; - dest = b.createTextureCall(spv::NoPrecision, vec4_float_type_, false, - false, false, false, false, params); + dest = b.createCompositeConstruct( + vec4_float_type_, + { + b.createUnaryOp(spv::OpDPdx, float_type_, src_x), + b.createUnaryOp(spv::OpDPdy, float_type_, src_x), + b.createUnaryOp(spv::OpDPdx, float_type_, src_y), + b.createUnaryOp(spv::OpDPdy, float_type_, src_y), + }); } break; + case FetchOpcode::kGetTextureWeights: { // fract(src0 * textureSize); auto texture_index =