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: passing gl_ClipDistance into a function call causes invalid code-gen #2411

Closed
Try opened this issue Nov 10, 2024 · 1 comment · Fixed by #2429
Closed

HLSL: passing gl_ClipDistance into a function call causes invalid code-gen #2411

Try opened this issue Nov 10, 2024 · 1 comment · Fixed by #2429

Comments

@Try
Copy link
Contributor

Try commented Nov 10, 2024

Caused by type mismatch of clip-distance builtin in HLSL(float4) and GLSL(float[4]). Presumably mesh-shader only case.

Relevant part of original shader:

pos = mapViewport(pos, gl_MeshVerticesEXT[laneID].gl_ClipDistance);

spirv-cross output:

float param_3[4];
float4 _522 = mapViewport(param_2, param_3);
gl_MeshVerticesEXT[laneID].gl_ClipDistance = param_3; // cannot implicitly convert from 'float [4]' to '__restrict float4'
@Try
Copy link
Contributor Author

Try commented Nov 18, 2024

gl_MeshVerticesEXT[laneID].gl_ClipDistance = param_3

This line in spirv:

%53 = OpLoad %9 %51  // param3
%55 = OpAccessChain %54 %38 %16 %20  // &gl_MeshVerticesEXT[laneID].gl_ClipDistance
OpStore %55 %53

Here OpStore, results into CompilerGLSL::cast_to_variable_store call. In theory cast_to_variable_store should already handle builtins, except it is broken and unable to recognize structure-members as builtin.

Offended part of code:

void CompilerGLSL::cast_to_variable_store(uint32_t target_id, std::string &expr, const SPIRType &expr_type)
{
        // returns gl_MeshVerticesEXT and loses information about whole access chain
	auto *var = maybe_get_backing_variable(target_id); 
	if (var)
		target_id = var->self;

	// Access chain also has no DecorationBuiltIn in this case
	if (!has_decoration(target_id, DecorationBuiltIn))
		return;

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

Successfully merging a pull request may close this issue.

1 participant