diff --git a/ShaderRecomp/shader_common.hlsli b/ShaderRecomp/shader_common.hlsli index 93c0ef2..4ab7f4e 100644 --- a/ShaderRecomp/shader_common.hlsli +++ b/ShaderRecomp/shader_common.hlsli @@ -42,9 +42,25 @@ Texture3D g_Texture3DDescriptorHeap[] : register(t0, space1); TextureCube g_TextureCubeDescriptorHeap[] : register(t0, space2); SamplerState g_SamplerDescriptorHeap[] : register(s0, space3); -float4 tfetch2D(uint resourceDescriptorIndex, uint samplerDescriptorIndex, float2 texCoord) + +float4 tfetch2D(uint resourceDescriptorIndex, uint samplerDescriptorIndex, float2 texCoord, float2 offset) { - return g_Texture2DDescriptorHeap[resourceDescriptorIndex].Sample(g_SamplerDescriptorHeap[samplerDescriptorIndex], texCoord); + Texture2D texture = g_Texture2DDescriptorHeap[resourceDescriptorIndex]; + + uint2 dimensions; + texture.GetDimensions(dimensions.x, dimensions.y); + + return texture.Sample(g_SamplerDescriptorHeap[samplerDescriptorIndex], texCoord + offset / dimensions); +} + +float2 getWeights2D(uint resourceDescriptorIndex, uint samplerDescriptorIndex, float2 texCoord, float2 offset) +{ + Texture2D texture = g_Texture2DDescriptorHeap[resourceDescriptorIndex]; + + uint2 dimensions; + texture.GetDimensions(dimensions.x, dimensions.y); + + return frac(texCoord * dimensions + offset - 0.5); } float4 tfetch3D(uint resourceDescriptorIndex, uint samplerDescriptorIndex, float3 texCoord) diff --git a/ShaderRecomp/shader_recompiler.cpp b/ShaderRecomp/shader_recompiler.cpp index ca22d40..6713984 100644 --- a/ShaderRecomp/shader_recompiler.cpp +++ b/ShaderRecomp/shader_recompiler.cpp @@ -216,7 +216,7 @@ void ShaderRecompiler::recompile(const VertexFetchInstruction& instr, uint32_t a void ShaderRecompiler::recompile(const TextureFetchInstruction& instr) { - if (instr.opcode != FetchOpcode::TextureFetch) + if (instr.opcode != FetchOpcode::TextureFetch && instr.opcode != FetchOpcode::GetTextureWeights) return; if (instr.isPredicated) @@ -233,7 +233,16 @@ void ShaderRecompiler::recompile(const TextureFetchInstruction& instr) print("r{}.", instr.dstRegister); printDstSwizzle(instr.dstSwizzle, false); - out += " = tfetch"; + out += " = "; + switch (instr.opcode) + { + case FetchOpcode::TextureFetch: + out += "tfetch"; + break; + case FetchOpcode::GetTextureWeights: + out += "getWeights"; + break; + } uint32_t componentCount = 0; switch (instr.dimension) @@ -267,8 +276,15 @@ void ShaderRecompiler::recompile(const TextureFetchInstruction& instr) for (size_t i = 0; i < componentCount; i++) out += SWIZZLES[((instr.srcSwizzle >> (i * 2))) & 0x3]; - if (instr.dimension == TextureDimension::TextureCube) + switch (instr.dimension) + { + case TextureDimension::Texture2D: + print(", float2({}, {})", instr.offsetX * 0.5f, instr.offsetY * 0.5f); + break; + case TextureDimension::TextureCube: out += ", cubeMapData"; + break; + } out += ").";