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

[SPIR-V] Variable cannot be replaced: invalid instruction - functor struct with no members variable not declared as static #5962

Closed
devshgraphicsprogramming opened this issue Nov 2, 2023 · 0 comments · Fixed by KhronosGroup/SPIRV-Tools#5553
Assignees
Labels
bug Bug, regression, crash spirv Work related to SPIR-V

Comments

@devshgraphicsprogramming

Description
I've made a "functor" for accessing my scratch groupshared memory in templated algorithms:

groupshared uint32_t scratch[ScratchSz];

template<uint32_t offset>
struct ScratchProxy
{
	uint32_t get(const uint32_t ix)
	{
		return scratch[ix+offset];
	}

	void set(const uint32_t ix, const uint32_t value)
	{
		scratch[ix+offset] = value;
	}
};

ScratchProxy<0> arithmeticAccessor;

I can "fix" this in two ways:

  • declare the artihmeticAccessor as static
  • add a dummy member to ScratchProxy struct

I think this has something to do with the fact that all non-static globals map to a hidden UBO/ConstantBuffer, and this struct's sizeof() is 0

Would be nice for this case to either:

  • produce a more intelligible and helpful error/diagnostic (e.g. "cannot use zero-sized structs in SSBO/UBO"
  • compile successfully like DXIL output by noticing we don't actually have to store/load anything from $Globals

Steps to Reproduce
Compile this repro: https://godbolt.org/z/987efPv1b
with: -HV 202x -T cs_6_7 -fspv-target-env=vulkan1.3 -enable-16bit-types -fvk-use-scalar-layout -Wno-c++11-extensions -O0 -spirv

The -fvk-use-scalar-layout doesn't matter, fails either way.

Obviously it passes without -spirv and emits DXIL.

Actual Behavior

Fails compilation with

fatal error: failed to legalize SPIR-V: Variable cannot be replaced: invalid instruction
  OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID %output

Environment

  • DXC version: latest & godbolt DXC trunk
  • Host Operating System: Windows and Linux
@devshgraphicsprogramming devshgraphicsprogramming added bug Bug, regression, crash needs-triage Awaiting triage spirv Work related to SPIR-V labels Nov 2, 2023
@llvm-beanz llvm-beanz moved this to For Google in HLSL Triage Nov 7, 2023
@sudonatalie sudonatalie self-assigned this Nov 21, 2023
@sudonatalie sudonatalie removed the needs-triage Awaiting triage label Nov 21, 2023
@sudonatalie sudonatalie moved this from For Google to Done in HLSL Triage Nov 21, 2023
sudonatalie added a commit to sudonatalie/SPIRV-Tools that referenced this issue Jan 31, 2024
Add OpEntryPoint to the list of instructions processed by the
DescriptorScalarReplacement pass. This is necessary for SPIR-V 1.4 and
above where global variables must be included in the interface.

Fixes microsoft/DirectXShaderCompiler#5962
sudonatalie added a commit to KhronosGroup/SPIRV-Tools that referenced this issue Feb 1, 2024
Add OpEntryPoint to the list of instructions processed by the
DescriptorScalarReplacement pass. This is necessary for SPIR-V 1.4 and
above where global variables must be included in the interface.

Fixes microsoft/DirectXShaderCompiler#5962
sudonatalie added a commit to sudonatalie/DirectXShaderCompiler that referenced this issue Feb 1, 2024
Bump submodules to include the fix for microsoft#5962
sudonatalie added a commit to sudonatalie/DirectXShaderCompiler that referenced this issue Feb 1, 2024
Bump submodules to include the fix for microsoft#5962
sudonatalie added a commit that referenced this issue Feb 2, 2024
Bump submodules to include the fix for #5962
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug, regression, crash spirv Work related to SPIR-V
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants