LukasBanana/XShaderCompiler

Translation not emitting layout qualifiers?

rgthomas opened this issue · 2 comments

It's very likely that this is my mistake, as I'm not nearly as familiar with GLSL as with HLSL, but I've been having trouble getting the translator to emit layout qualifiers in situations where I expected it would. Our engine sets shader constants using positions, which is why I'd like to get explicit positions and bindings in the translated GLSL. Here's a simplified test case I tried:

xsc invocation:
xsc.exe --extension ON --comments ON -Vin HLSL3 -Vout GLSL450 -Fblanks OFF -Wall ON --explicit-bind ON -T frag -o test.frag test.psh

Input HLSL:

struct Input
{
    float4 pos : POSITION;
    float2 texcoord : TEXCOORD0;
};

uniform float4 SampleDelta : register(c0);
uniform float4 Sharpness : register(c1);

uniform sampler2D Ssao : register(s0);

float4 main(Input input) : COLOR
{
    float4 uv = float4(input.texcoord * Sharpness.xy + SampleDelta.xy, 0, 0);
    return tex2Dlod(Ssao, uv);
}

Output GLSL:

// GLSL Fragment Shader "main"
// Generated by XShaderCompiler
// 31/07/2018 23:52:15
#version 450
in vec2 xsv_TEXCOORD0;
layout(location = 0) out vec4 SV_Target0;
uniform vec4 SampleDelta;
uniform vec4 Sharpness;
uniform sampler2D Ssao;
void main()
{
    vec4 uv = vec4(xsv_TEXCOORD0 * Sharpness.xy + SampleDelta.xy, 0, 0);
    vec4 xst_temp0 = uv;
    SV_Target0 = textureLod(Ssao, xst_temp0.xy, xst_temp0.w);
}

My expectation is that I'd get something like this for the uniforms:

layout(position=0) uniform vec4 SampleDelta;
layout(position=1) uniform vec4 Sharpness;
layout(binding=0) uniform sampler2D Ssao;

Any info you can provide is appreciated! Thanks!

Xsc was originally only designed for HLSL Shader Model 4 and 5, but some HLSL3 and Cg features were later added.
The c0 and c1 registers are currently not handled, but I'll see what I can do.
Your command line is correct though.

Should be fixed with 71a2350.
I also added your code sample as Sampler2DonSM3.hlsl to the tests afterwards.
Let me know if it works for you.