hlslfragment-shader

Issue with reading texture data inside RESHADE Pixel Shader


I am new to reshade, but not new to programming as a whole. I tried to implement a compute shader using modern re shade, who's information was then passed to a pixel shader that passed that data to the screen. However, I got the error X4532 cannot map expression to cs_5_0 instruction set. Here's some code that will reproduce the error

#include "ReShade.fxh"
texture2D renderTarget { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
storage2D storageTarget{ Texture = renderTarget; };
sampler2D sampleTarget { Texture = renderTarget; MinFilter = POINT; MagFilter = POINT; };
void compute(uint3 id : SV_DispatchThreadID)
{
    tex2Dstore(storageTarget, id.xy, tex2D(ReShade::BackBuffer, (float) id.xy * BUFFER_PIXEL_SIZE));
}
float3 finalPass(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
    return tex2D(sampleTarget, texcoord).rgb;
}
technique test
{
    pass
    {
        ComputeShader = compute<8, 8>;
        DispatchSizeX = BUFFER_SCREEN_SIZE.x / 8.0f;
        DispatchSizeY = BUFFER_SCREEN_SIZE.y / 8.0f;
    }
    pass
    {
        VertexShader = PostProcessVS;
        PixelShader = finalPass;
    }
}

This error shows up in vertex shaders commonly, because of mip map levels, but there is almost no information about this error showing up in pixel shaders online. I have no idea what I am doing wrong here, and because of the way REShade is compiled it makes it very difficult to verify if a change I have made has actually fixed the problem, or masked it behind another problem noticed by the compiler first. (Note: ReShade uses a language very similar to HLSL but they are not exactly the same, so if you are an HLSL veteran and something looks like a syntax error, this is why.)


Solution

  • Alright I figured it out, and it's something incredibly stupid. The RenderTarget Property of the pass with the compute shader in it has to be the same as the texture inside your storage 2D object. And, your texture sampler has to be replaced with the tex(size)lod function in order to specify the mip map level.