Shader cross compilation fails on my shader


#1

I wrote a custom shader for (trying to) render screen space geometry. It’s not absolutely vital that it works, I just want to test bsf with less code (I don’t have to write code for proper orthographic positioning this way). Also I’d like to test out how easy it is to make custom shaders with bsf.

This is the error I’m getting (both with vulkan and opengl backends):

[ERROR] Shader cross compilation failed. Log: 

2 ERRORS
--------
in 'float4 fsmain(in VStoFS input)':
context error (41:20) : invalid class intrinsic 'Sample' for type 'SamplerState'
            return imageSampler.Sample(image, input.uv0);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
analyzing input code failed

		 in bs::String bs::crossCompile(const String&, bs::GpuProgramType, bs::CrossCompileOutput, bool, bs::UINT32&, bs::SHADER_DESC*, bs::Vector<bs::GpuProgramType>*) [/home/hhyyrylainen/Projects/Leviathan/ThirdParty/bsf/Source/Plugins/bsfSL/BsSLFXCompiler.cpp:730]

From looking at other bsl files included with bsf they seem to be using the same function so I’m a bit confused why my shader isn’t working.

This is my shader, I may have made a mistake in it:

options
{
    sort = backtofront;
    transparent = true;
};

shader ScreenSpaceGUI
{
    depth
    {
        write = false;
    };

    blend
    {
        target
        {
            enabled = true;
            color = { srcA, srcIA, add };
        };
    };
    
    code
    {
        struct VStoFS
        {
            float4 position : SV_Position;
            float2 uv0 : TEXCOORD0;
        };

        [alias(image)]
        SamplerState imageSampler
        {
            Filter = MIN_MAG_MIP_LINEAR;
            AddressU = Clamp;
            AddressV = Clamp;
        };
        
        Texture2D image = black;

        cbuffer PerObject
        {
             float4x4 gMatWorldViewProj;
        }

        struct VertexInput
        {
            float3 position : POSITION;
            float2 uv0 : TEXCOORD0;
        };
        
        VStoFS vsmain(VertexInput input)
        {
            VStoFS output;
        
            output.uv0 = input.uv0;
            output.position = float4(input.position, 1.f);
            return output;
        }
        
        float4 fsmain(in VStoFS input) : SV_Target0
        {
            return imageSampler.Sample(image, input.uv0);
        }   
    };
};

#2

You just have the texture & sampler switched around. It should be image.Sample(sampler, uv).


#3

Thanks, that was it.
Now I just need to figure out why nothing is rendered and my program crashes when ran with RenderDoc… that’s going to be not fun.