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

handling UserSemantic decoration on Input variables #2670

Closed
bashbaug opened this issue Aug 12, 2024 · 3 comments
Closed

handling UserSemantic decoration on Input variables #2670

bashbaug opened this issue Aug 12, 2024 · 3 comments

Comments

@bashbaug
Copy link
Contributor

I've been slowly adding testing for SPIR-V 1.4 features and I found an issue UserSemantic decorations on Input variables. My test can be found here:

KhronosGroup/OpenCL-CTS@main...bashbaug:OpenCL-CTS:spirv-14-part3

There seems to be two problems:

  1. The SPIR-V LLVM Translator currently doesn't handle the OpDecorateString and OpMemberDecorateString instructions (see also Missing SPIR-V 1.4 features/changes #2460). This one seems pretty straightforward, and we should just parse OpDecorateString similar to the way we are currently parsing OpDecorate, at least for now. Once we sort out the difference between OpDecorate and OpDecorateString we might only want to parse the UserSematic decoration using OpDecorateString, but we can cross that bridge when we come to it.

  2. The SPIR-V LLVM Translator also doesn't seem to be properly handling the UserSemantic decoration on Input variables. When there are UserSemantic decorations on an input variable, it turns into an "llvm.global.annotation":

@__spirv_BuiltInGlobalInvocationId = external addrspace(7) constant <3 x i64>
@0 = private unnamed_addr constant [4 x i8] c"FOO\00", section "llvm.metadata"
@1 = private unnamed_addr constant [4 x i8] c"BAR\00", section "llvm.metadata"
@2 = private unnamed_addr constant [15 x i8] c"FOO? BAR. BAZ!\00", section "llvm.metadata"
@llvm.global.annotations = appending global [3 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr addrspacecast (ptr addrspace(7) @__spirv_BuiltInGlobalInvocationId to ptr), ptr @0, ptr undef, i32 undef, ptr undef }, { ptr, ptr, ptr, i32, ptr } { ptr addrspacecast (ptr addrspace(7) @__spirv_BuiltInGlobalInvocationId to ptr), ptr @1, ptr undef, i32 undef, ptr undef }, { ptr, ptr, ptr, i32, ptr } { ptr addrspacecast (ptr addrspace(7) @__spirv_BuiltInGlobalInvocationId to ptr), ptr @2, ptr undef, i32 undef, ptr undef }], section "llvm.metadata"

This case is not currently handled by replaceUsesOfBuiltinVar, so we hit an llvm_unreachable and we crash.

I'm open to suggestions how best to solve this issue. Here are a few possibilities I can think of Most of these options assume we don't care about preserving the UserSemantic decoration:

a. If a UserSematic decoration is on a variable in the Input storage class, just ignore it, since it's going to cause trouble later on.
b. If the use of the builtin var is a ConstantExpr, like it is in the snip above, replace the use with some other safe value (maybe NULL?).

Is there some other clever way to preserve the UserSemantic decoration?

@MrSidims
Copy link
Contributor

IMHO the best way to handle it would be to teach replaceUsesOfBuiltinVar that use of the builtin variable might be an annotation intrinsic and in this case annotate the result of the function call that is being generated by replaceUsesOfBuiltinVar. The problem though that LLVM annotation intrinsics aren't matching this role. Alternatively we have a mechanism to represent decorations via !spirv.Decorate metadata, which carries information about the decoration and its values. For the Builtin Variables we may check if they are decorated early on and generate the metadata instead of the annotation intrinsic and then copy this metadata on the function call. Probably this solution is middle term, so for now we can just ignore annotation on the Builtin GV.

There is one extra potential issue though, the spec says: "If decorating a variable, it must be in the Input or Output storage classes." about UserSemantic decoration, while we add it for more storage classes. This I don't know how to handle apart of modifying the spec and allowing extra storage classes.

@bashbaug
Copy link
Contributor Author

There is one extra potential issue though, the spec says: "If decorating a variable, it must be in the Input or Output storage classes." about UserSemantic decoration, while we add it for more storage classes. This I don't know how to handle apart of modifying the spec and allowing extra storage classes.

Yes, we are currently being naughty about UserSemantic decorations, though hopefully only when specific Clang annotations are present. I'm a little surprised that the SPIR-V validator isn't complaining when we use UserSemantic decorations on other variables or functions.

See also internal Khronos SPIR-V issue 508.

Do we have a use-case for UserSemantic decorations on input variables currently? If not, I'm inclined to ignore them. Since the UserSemantic decorations are intended to express user-facing annotations, not annotations for the driver, this might be the right long-term solution also.

MrSidims pushed a commit that referenced this issue Aug 20, 2024
…ng (#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see #2460 and #2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for #2670, but I'll do that in a separate PR.
@bashbaug
Copy link
Contributor Author

Closing - if needed, we can add additional handling for UserSemantic decorations on Input variables in the future, but what we have currently is good enough for now. Thanks!

svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 18, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 18, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh added a commit that referenced this issue Oct 18, 2024
…emberDecorateString (#2677) (#2767)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see #2460 and #2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for #2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)

Co-authored-by: Ben Ashbaugh <[email protected]>
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this issue Oct 22, 2024
…emberDecorateString (KhronosGroup#2677)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see KhronosGroup#2460 and KhronosGroup#2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for KhronosGroup#2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)
svenvh added a commit that referenced this issue Oct 23, 2024
…emberDecorateString (#2677) (#2774)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see #2460 and #2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for #2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)

Co-authored-by: Ben Ashbaugh <[email protected]>
svenvh added a commit that referenced this issue Oct 23, 2024
…emberDecorateString (#2677) (#2775)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see #2460 and #2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for #2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)

Co-authored-by: Ben Ashbaugh <[email protected]>
svenvh added a commit that referenced this issue Oct 23, 2024
…emberDecorateString (#2677) (#2776)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see #2460 and #2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for #2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)

Co-authored-by: Ben Ashbaugh <[email protected]>
svenvh added a commit that referenced this issue Oct 23, 2024
…emberDecorateString (#2677) (#2777)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see #2460 and #2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for #2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)

Co-authored-by: Ben Ashbaugh <[email protected]>
svenvh added a commit that referenced this issue Oct 23, 2024
…emberDecorateString (#2677) (#2778)

This PR adds "reverse translation" (from SPIR-V to LLVM IR) support for OpDecorateString and OpMemberDecorateString, see #2460 and #2670. These instructions are currently treated as synonyms for OpDecorate and OpMemberDecorate. We'll want to tidy this up at some point, but at least for now we won't crash if we see these instructions.

I'll still need to add proper support for decorating variables in the input storage class for #2670, but I'll do that in a separate PR.

(cherry picked from commit f7057b4)

Co-authored-by: Ben Ashbaugh <[email protected]>
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

No branches or pull requests

2 participants