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

An issue with template type deduction and globallycoherent? #5999

Open
simonwongms opened this issue Nov 9, 2023 · 10 comments
Open

An issue with template type deduction and globallycoherent? #5999

simonwongms opened this issue Nov 9, 2023 · 10 comments
Labels
bug Bug, regression, crash hlsl2021 Pertaining to HLSL2021 features shader-linking Bugs related to library targets and linking type-system Bugs relating to inconsistencies in HLSL's type system
Milestone

Comments

@simonwongms
Copy link

We have a variable of type ‘globallycoherent RWByteAddressBuffer’. When this is passed to a templated function where the buffer is a templated parameter, the globallycoherent part seems to be missed?
Now, I don’t know if the compiled out dxil is actually correct and the warning/error is a false positive. We hadn’t noticed any visual artifacts in the June GDK.

I’ve distilled the hlsl into bare bones to repro this issue. This is obviously not a shader that does anything. It’s just stripped down to illustrate the issue and trigger the error/warning.

I am able to reproduce this in shader playground:
https://shader-playground.timjones.io/98b958c232fe4b88326d5be6b2570013

The error output there matches the ones I get in the GDK

Environment
dxcompiler_xs.dll!DxcCreateInstance: 1.7 - 2310.2310.11301.10016

@simonwongms simonwongms added bug Bug, regression, crash needs-triage Awaiting triage labels Nov 9, 2023
@pow2clk pow2clk added the hlsl2021 Pertaining to HLSL2021 features label Nov 14, 2023
@pow2clk pow2clk moved this to Done in HLSL Triage Nov 14, 2023
@pow2clk pow2clk removed the needs-triage Awaiting triage label Nov 14, 2023
@simonwongms
Copy link
Author

Just wanted to check on the status of this. Thanks

@KStocky
Copy link

KStocky commented Dec 11, 2023

+1 For this. Another example in shader playground https://shader-playground.timjones.io/b050891fa1644437bf69e0ccc655801f. I would expect "globallycoherent RWBuffer" to be a different type from "RWBuffer" considering how you can't assign a globallycoherent RWBuffer to a regular RWBuffer.

@simonwongms
Copy link
Author

Good find. Your example would probably help narrow down the source of the compiler's confusion. It looks like a different issue on the surface, but probably points to something related. eg something(s) does not recognize 'globallycoherent' as a keyword.

@llvm-beanz
Copy link
Collaborator

llvm-beanz commented Jan 18, 2024

Compiler Explorer Link (because shader playground is really slow to load).

@pow2clk
Copy link
Member

pow2clk commented Jan 18, 2024

Thanks Chris, I was about to send the same link. Also worth noting, this link uses the trunk compiler which has made the warning message more helpful.

In this, a warning is produced, which isn't explicitly said in this bug. I know @simonwongms said that they didn't know if the codegen was right. Given that this example passes a globallycoherent object into a parameter that isn't, I expect the qualifier is getting stripped. I think that's correct. If there are codegen issues elsewhere, we'll need an example to consider them.

The test @KStocky added is appreciated and we should incorporate some testing for this. Otherwise, I don't see any action needed here. Am I missing something?

@llvm-beanz llvm-beanz added the shader-linking Bugs related to library targets and linking label Jan 18, 2024
@llvm-beanz
Copy link
Collaborator

I think @KStocky's example here shows how this can become an error: https://godbolt.org/z/sP6rKvYov

We do need to figure out how we want to resolve this properly. This especially becomes a problem if we support cross-translation unit linking. In that scenario we'll need globallycoherent to be retained across call boundaries.

I think we get lucky today that the codegen is correct in most cases because we just propagate globallycoherent when the resources all get resolved back to a single underlying resource. IIUC, the point of the warning was originally to notify users when a non-globallycoherent resource becomes globallycoherent because somewhere in the usage chain it gains the property. If we continue working on supporting shader linking, this property will be much more important to act as a proper type qualifier.

@simonwongms
Copy link
Author

simonwongms commented Jan 18, 2024 via email

@llvm-beanz
Copy link
Collaborator

So it does seem to generate the correct code in this example, which would mean that the error/warning is a false positive.

The warning isn't a false positive. The code is converting between globallycoherent and non-globallycoherent resource types. This causes DXC to propagate the globallycoherent annotation to the non-globallycoherent resources. While that does make the code "correct" it also means you're getting extra memory barriers and syncs, which the compiler can't tell if you actually intended. Hence the warning.

The problem is that because of how globallycoherent was implemented the compiler drops the annotation when resolving overloads and template instantiations (which is a bug that is hard to fix).

We've had a bunch of issues relating to type annotations like globallycoherent interacting with templates, and with HLSL library shaders. Resolving those is going to likely require some re-design of globallycoherent and will probably require breaking changes to the language so we'd need to track it as a feature for a new language version.

@KStocky
Copy link

KStocky commented Jan 22, 2024

We've had a bunch of issues relating to type annotations like globallycoherent interacting with templates, and with HLSL library shaders.

Would this be the same bug as something like row_major for example. It is also a type qualifier that does not seem to participate in template type resolution.

@llvm-beanz
Copy link
Collaborator

We've had a bunch of issues relating to type annotations like globallycoherent interacting with templates, and with HLSL library shaders.

Would this be the same bug as something like row_major for example. It is also a type qualifier that does not seem to participate in template type resolution.

Yes, same basic problem different attribute. The matrix orientation and globallycoherent keywords are implemented as attributes, so whenever we need a "canonical type" we lose them. Canonical type resolutions occur in a bunch of places whenever the compiler needs to de-sugar or fully resolve a type.

We really need these keywords to be implemented as type qualifiers (which in clang are effectively just special attributes, that stick around during canonicalization).

@damyanp damyanp added the type-system Bugs relating to inconsistencies in HLSL's type system label Oct 28, 2024
@damyanp damyanp added this to the Dormant milestone Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug, regression, crash hlsl2021 Pertaining to HLSL2021 features shader-linking Bugs related to library targets and linking type-system Bugs relating to inconsistencies in HLSL's type system
Projects
Status: Triaged
Development

No branches or pull requests

5 participants