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

Template type on struct breaks this pointer (hlsl-2021) #3732

Closed
Jasper-Bekkers opened this issue Apr 30, 2021 · 4 comments · Fixed by #4112
Closed

Template type on struct breaks this pointer (hlsl-2021) #3732

Jasper-Bekkers opened this issue Apr 30, 2021 · 4 comments · Fixed by #4112
Labels
hlsl2021 Pertaining to HLSL2021 features

Comments

@Jasper-Bekkers
Copy link

template<typename T>
struct SimpleBuffer {
    uint handle;

    T Load() {
        ByteAddressBuffer buf = ResourceDescriptorHeap[this.handle];
        return (T)0;
    }
};

[numthreads(1,1,1)]
void main() {
    SimpleBuffer<uint> b;
    b.Load();
}

Regular structs with this in their methods (with access through the . operator) do work, however, once a template argument is introduced DXC yields this error message:

dxc -Tcs_6_6 -Emain -enable-templates test_bindless.hlsl

test_bindless.hlsl:6:60: error: member reference type 'SimpleBuffer<unsigned int> *' is a pointer; did you mean to use '->'?
        ByteAddressBuffer buf = ResourceDescriptorHeap[this.handle];
                                                       ~~~~^
                                                           ->
test_bindless.hlsl:14:7: note: in instantiation of member function 'SimpleBuffer<unsigned int>::Load' requested here
    b.Load();
@Jasper-Bekkers
Copy link
Author

@tcorringham You may be interested in this

@ghostplant
Copy link

ghostplant commented May 10, 2021

@j-dahl Is CS_6_0 supporting template function? Why does my following implementations failed to compile?

template <class T> T subfunc(T x) { return x * x; }

I am using runtime API instead of dxc.exe like this:

m_pCompiler->Compile(pSrcBlob.Get(), L"ShaderFile", entryName, profile, NULL, 0, NULL, 0, NULL, &pResult)

Is it possible to pass -enable-templates to the API above?

@Jasper-Bekkers
Copy link
Author

@ghostplant at the moment template support is very experimental and requires you to be on a separate branch (and have -enable-templates turned on). This issue concerns that branch (and is an actual compiler bug) so it may be best not to reply to it with general support questions since that might distract from the actual issue.

@ghostplant
Copy link

Thanks, can you estimate when template-supported DXC can be ported into Visual Studio's SDK plugin? Currently I found that generating all-type functions is painful.

@tex3d tex3d added the templates label Jun 9, 2021
@pow2clk pow2clk added hlsl2021 Pertaining to HLSL2021 features and removed templates labels Oct 13, 2021
llvm-beanz added a commit to llvm-beanz/DirectXShaderCompiler that referenced this issue Nov 30, 2021
Prior to this change explicit `this` access inside a struct was treated
as a reference, but implicit `this` was still a pointer type. With this
change `this` is always a reference type.

This has no impact on code generation since references and pointers all
digress to addresses, but it does make the AST more accurately reflect
the types and it resolves microsoft#3732.
llvm-beanz added a commit that referenced this issue Dec 2, 2021
* Make `this` more consistently a reference type

Prior to this change explicit `this` access inside a struct was treated
as a reference, but implicit `this` was still a pointer type. With this
change `this` is always a reference type.

This has no impact on code generation since references and pointers all
digress to addresses, but it does make the AST more accurately reflect
the types and it resolves #3732.

* Updating test case to handle incorrect operator
llvm-beanz added a commit to llvm-beanz/DirectXShaderCompiler that referenced this issue Dec 3, 2021
* Make `this` more consistently a reference type

Prior to this change explicit `this` access inside a struct was treated
as a reference, but implicit `this` was still a pointer type. With this
change `this` is always a reference type.

This has no impact on code generation since references and pointers all
digress to addresses, but it does make the AST more accurately reflect
the types and it resolves microsoft#3732.

* Updating test case to handle incorrect operator
llvm-beanz added a commit that referenced this issue Dec 3, 2021
* Make `this` more consistently a reference type

Prior to this change explicit `this` access inside a struct was treated
as a reference, but implicit `this` was still a pointer type. With this
change `this` is always a reference type.

This has no impact on code generation since references and pointers all
digress to addresses, but it does make the AST more accurately reflect
the types and it resolves #3732.

* Updating test case to handle incorrect operator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hlsl2021 Pertaining to HLSL2021 features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants