microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
2.98k stars 666 forks source link

[SPIR-V] Bitfields in structs fail to compile to SPIR-V #6483

Open noahwhygodwhy opened 3 months ago

noahwhygodwhy commented 3 months ago

Description

Structs with a specific setup of bitfields fail to compile to SPIR-V with the error

fatal error: generated SPIR-V is invalid: Index is out of bounds, can not find index 1 in the structure <id> '2'. This structure has 1 members. Largest valid index is 0.
  %19 = OpCompositeExtract %uint %17 1

I looked through and there were quite a few other issues that seemed like they might be related, but they all seemed to be resolved/merged pre-March 2024 release, and this issue is still present in that release version.

Steps to Reproduce

A struct with uint bitfields fails to compile when one of the members of the struct is accessed via a method that is not a structured buffer.

Here is the smallest example I could make. The compile options are at the top, followed by the error message, followed by the non-working example. At the bottom is a piece of code that I think functionally does the same thing, but successfully compiles. https://godbolt.org/z/hYd6faK1j

Actual Behavior Should compile successfully to spir-v as it does to dxil.

Environment

noahwhygodwhy commented 3 months ago

Sorry. Did I mess up? I'm assuming marking this as For Google means that this is intended behavior and I should google how bitfields in spirv work and that this is expected? I only opened a issue because the error message asked.

sudonatalie commented 3 months ago

Thank you for reporting @noahwhygodwhy ! This is a bug, we'll take a look. The "For Google" tag is just to help us categorize incoming issues between the different teams at Microsoft and Google working on this repository.