Skip to content

[SPIR-V] Declaration of the Image Type for RWTexture has explicit format but image writes and stores emit unformatted. #6979

Closed

Description

Description

DXC declares the image type with a "guessed" format e.g. rg32f for a float32_t but then does unformatted writes.

Edit: the guessing isn't a problem, I can correct with e.g. [[vk::image_format("rg16f")]] attribute

The SPIR-V legalization pass should probably "patch in" the actual format into the read and write ops from the image type declaration (by following the access and pointer chains).

Steps to Reproduce

Suprised no SPIR-V validation step caught this
https://godbolt.org/z/Y9Ex8oEhs

Actual Behavior

The following declaration is emitted

%type_3d_image = OpTypeImage %float 3D 2 0 0 2 Rg32f

but a following store op is used

OpImageWrite %15 %17 %9 None

The Image Format must not be Unknown, unless the StorageImageWriteWithoutFormat Capability was declared.

and the StorageImageWriteWithoutFormat is not emitted by DXC.

The generated SPIR-V shouldn't be valid.

So on one hand you declare with a format, but the store op is unformatted !?

P.S. the reads are also emitted unformatted https://godbolt.org/z/KWh4x5fh9

This is a bigger problem because the ReadWithoutFormat capability is not ubiquitous yet.

Environment

  • DXC version Godbolt trunk
  • Host Operating System Godbolt

Activity

  1. added
    bug
    needs-triage
    spirv
    on Oct 21, 2024
  2. devshgraphicsprogramming commented on Oct 21, 2024

    @devshgraphicsprogramming
    Author

    I think I see the problem, the drivers can already do this

    The SPIR-V legalization pass should probably "patch in" the actual format into the read and write ops from the image type declaration (by following the access and pointer chains).

    Hence the reads/writes are never truly unformatted.

    That doesn't change the fact that if the SPIR-V validators were actually to care about the ops being legal, they'd need the formats patched in.

  3. devshgraphicsprogramming commented on Oct 21, 2024

    @devshgraphicsprogramming
    Author

    Nathan Gauër (@Keenuts) did you accidentally break [[vk::image_format("unknown")]] with some of your PRs ?

    https://godbolt.org/z/97vhvz9vP

    Also did you ever emit the WriteWithoutFormat and ReadWtihoutFormat capabilities if such a type was also used in a store/load op?

  4. Keenuts commented on Oct 22, 2024

    @Keenuts
    Collaborator

    The following declaration is emitted

    %type_3d_image = OpTypeImage %float 3D 2 0 0 2 Rg32f
    

    but a following store op is used

    OpImageWrite %15 %17 %9 None
    

    The Image Format must not be Unknown, unless the StorageImageWriteWithoutFormat Capability was declared.

    I don't see the issue here.
    (Aside the OpUndef caused by the static), the OpImageWrite image has a format Rg32f, which is not unknown. Meaning we can emit this write without the capability.
    Am I missing something here?

  5. devshgraphicsprogramming commented on Oct 22, 2024

    @devshgraphicsprogramming
    Author

    The following declaration is emitted

    %type_3d_image = OpTypeImage %float 3D 2 0 0 2 Rg32f
    

    but a following store op is used

    OpImageWrite %15 %17 %9 None
    

    The Image Format must not be Unknown, unless the StorageImageWriteWithoutFormat Capability was declared.

    I don't see the issue here. (Aside the OpUndef caused by the static), the OpImageWrite image has a format Rg32f, which is not unknown. Meaning we can emit this write without the capability. Am I missing something here?

    Two issues:

    1. SPIR-V Spec says that you can't emit a write with None without the capability, doesn't matter if the format is known on the actual descriptor (unless I'm reading the spec wrong?)
    2. There's no way for me to declare None on the OpTypeImage
  6. Keenuts commented on Oct 22, 2024

    @Keenuts
    Collaborator
    1. SPIR-V Spec says that you can't emit a write with None without the capability, doesn't matter if the format is known on the actual descriptor (unless I'm reading the spec wrong?)

    Seems like one of us misunderstand something. My understanding:

    • OpTypeImage -> if Unknown + OpImageWrite, caps is required. Otherwise, not.
    • The None of the OpImageWrite is not the format, but marks that there are no additional operands.

    Here, the OpTypeImage is generated with Rg32f, meaning the capability is not required. Code seems valid to me.

    1. There's no way for me to declare None on the OpTypeImage

    You mean Unknown ?
    That's another issue. I'm currently investigating. Seems like DXC was never able to generate Unknown with this attribute, as we used Unknown to mark the absence of attribute and guess a format.
    This meant we always tried to guess, and it hid another bug later down the road with the capability.
    I'm working on a fix to allow "unknown" in the image_format attribute & fix the capability.
    But this issue it not the same as the one originally reported. (I'll track it in a new issue)

  7. devshgraphicsprogramming commented on Oct 23, 2024

    @devshgraphicsprogramming
    Author
    • OpTypeImage -> if Unknown + OpImageWrite, caps is required. Otherwise, not.
    • The None of the OpImageWrite is not the format, but marks that there are no additional operands.
      You mean Unknown ?

    Ugh I misred the spec/SPIR-V disassembly None and Unknown have the same enum, the None on the ImageWrite and Load is just no-extra operands. Sorry about that

  8. moved this from For Google to Triaged in HLSL Triageon Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triagespirv

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions