Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLSL legacy samplers cause invalid output. #1365

Closed
slembcke opened this issue Apr 26, 2018 · 2 comments
Closed

HLSL legacy samplers cause invalid output. #1365

slembcke opened this issue Apr 26, 2018 · 2 comments

Comments

@slembcke
Copy link

slembcke commented Apr 26, 2018

If a HLSL shader declares a sampler2D uniform, that uniform is dropped when cross-compiling to GLSL using glslangValidator/spirv-cross.

For example, this is my input HLSL:

struct FragInput {
	float4 position : SV_POSITION;
	float2 uv : TEXCOORD0;
};

uniform sampler2D tex;

float4 FShader(in FragInput IN) : SV_TARGET0 {
	return tex2D(tex, IN.uv);
}

This is the resulting GLSL:

#version 450

layout(location = 0) in vec2 IN_uv;
layout(location = 0) out vec4 _entryPointOutput;

void main()
{
    _entryPointOutput = texture(tex, IN_uv.x);
}

Since I can run GLSL shaders that use DX9 style samplers through spirv-opt and back, I figured it was a glslangValidator bug. I compiled both the HLSL and the expected GLSL output and disassembled them. The only functional difference I could find was that the HLSL version had this line:

        %20 = OpTypeSampler

While the GLSL version had these two lines:

         %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
         %20 = OpTypeSampledImage %10

Both versions perform the texture lookup using OpImageSampleImplicitLod, but according to the SPIR-V docs for it, only the OpTypeSampledImage argument is correct to pass to it. spirv-val seems to agree:

error: 34: Expected Sampled Image to be of type OpTypeSampledImage: ImageSampleImplicitLod

If I swap it out for those two lines, reassemble and cross compile it to GLSL, then the output correctly contains the sampler declaration and passes validation.

@slembcke slembcke changed the title HLSL legacy sampler2D support. HLSL legacy samplers cause invalid output. Apr 26, 2018
@slembcke
Copy link
Author

Hmm. Seems like this isn't implemented and was supposed to throw an error or something:
https://github.com/KhronosGroup/glslang/blob/master/hlsl/hlslGrammar.cpp?utf8=%E2%9C%93#L274

@johnkslang
Copy link
Member

I think there are some conflating comments here, as the DX9 path to the unimplemented(...) might not be taken (and some other things). But, fundamentally, yes, glslang is not supporting DX9.

This is captured in #362. So, if that's the real issue here, we can close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants