[llvm-branch-commits] [clang] [HLSL] Implement default constant buffer `$Globals` (PR #125807)
@@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-compute \ +// RUN: -fnative-half-type -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s + +// CHECK: %"struct.__cblayout_$Globals" = type { float, float, %struct.__cblayout_S } +// CHECK: %struct.__cblayout_S = type { float } + +// CHECK-DAG: @"$Globals.cb" = external constant target("dx.CBuffer", %"struct.__cblayout_$Globals") +// CHECK-DAG: @a = external addrspace(2) global float +// CHECK-DAG: @g = external addrspace(2) global float +// CHECK-DAG: @h = external addrspace(2) global %struct.__cblayout_S + +struct EmptyStruct { +}; + +struct S { + RWBuffer buf; + EmptyStruct es; + float ea[0]; + float b; +}; + +float a; +RWBuffer b; +EmptyStruct c; +float d[0]; +RWBuffer e[2]; +groupshared float f; +float g; +S h; + +RWBuffer Buf; + +[numthreads(4,1,1)] +void main() { + Buf[0] = a; +} + +// CHECK: !hlsl.cblayouts = !{![[S_LAYOUT:.*]], ![[CB_LAYOUT:.*]]} +// CHECK: !hlsl.cbs = !{![[CB:.*]]} + +// CHECK: ![[S_LAYOUT]] = !{!"struct.__cblayout_S", i32 4, i32 0} +// CHECK: ![[CB_LAYOUT]] = !{!"struct.__cblayout_$Globals", i32 20, i32 0, i32 4, i32 16} +// CHECK: ![[CB]] = !{ptr @"$Globals.cb", ptr addrspace(2) @a, ptr addrspace(2) @g, ptr addrspace(2) @h} spall wrote: newline https://github.com/llvm/llvm-project/pull/125807 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement default constant buffer `$Globals` (PR #125807)
@@ -5753,6 +5765,30 @@ void HLSLBufferDecl::addLayoutStruct(CXXRecordDecl *LS) { addDecl(LS); } +void HLSLBufferDecl::addDefaultBufferDecl(Decl *D) { + assert(isImplicit() && + "default decls can only be added to the implicit/default constant " + "buffer $Globals"); + DefaultBufferDecls.push_back(D); +} + +HLSLBufferDecl::buffer_decl_iterator +HLSLBufferDecl::buffer_decls_begin() const { + return buffer_decl_iterator(llvm::iterator_range(DefaultBufferDecls.begin(), + DefaultBufferDecls.end()), + decl_range(decls_begin(), decls_end())); +} + +HLSLBufferDecl::buffer_decl_iterator HLSLBufferDecl::buffer_decls_end() const { + return buffer_decl_iterator( + llvm::iterator_range(DefaultBufferDecls.end(), DefaultBufferDecls.end()), spall wrote: this is supposed to say end, end? https://github.com/llvm/llvm-project/pull/125807 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement default constant buffer `$Globals` (PR #125807)
@@ -5072,6 +5080,20 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext { return static_cast(const_cast(DC)); } + // Iterator for the buffer decls. Concatenates the list of decls parented spall wrote: I just want to clarify what this comment says. The children decls of this hlslbufferdecl are concatenated with the list of default buffer decls? Does the order of this matter? https://github.com/llvm/llvm-project/pull/125807 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement default constant buffer `$Globals` (PR #125807)
@@ -159,11 +159,16 @@ class SemaHLSL : public SemaBase { // List of all resource bindings ResourceBindings Bindings; + // default constant buffer $Globals + HLSLBufferDecl *DefaultCBuffer; + private: void collectResourcesOnVarDecl(VarDecl *D); void collectResourcesOnUserRecordDecl(const VarDecl *VD, const RecordType *RT); void processExplicitBindingsOnDecl(VarDecl *D); + + void diagnoseAvailabilityViolations(TranslationUnitDecl *TU); spall wrote: Why do you want this to be private now? https://github.com/llvm/llvm-project/pull/125807 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Implement default constant buffer `$Globals` (PR #125807)
@@ -286,10 +286,7 @@ void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl, .str( && "layout type does not match the converted element type"); -// there might be resources inside the used defined structs -if (VDTy->isStructureType() && VDTy->isHLSLIntangibleType()) - // FIXME: handle resources in cbuffer structs - llvm_unreachable("resources in cbuffer are not supported yet"); +// FIXME: handle resources in cbuffer user-defined structs spall wrote: this is future work? not a reminder for this pr? https://github.com/llvm/llvm-project/pull/125807 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)
https://github.com/spall edited https://github.com/llvm/llvm-project/pull/123985 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)
@@ -647,6 +648,40 @@ void SemaHLSL::emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, << NewFnName << FixItHint::CreateReplacement(FullRange, OS.str()); } +void SemaHLSL::handleRootSignatureAttr(Decl *D, const ParsedAttr &AL) { + if (AL.getNumArgs() != 1) +return; + + StringRef Signature; + if (!SemaRef.checkStringLiteralArgumentAttr(AL, 0, Signature)) +return; + + SourceLocation Loc = AL.getArgAsExpr(0)->getExprLoc(); + // FIXME: pass down below to lexer when fp is supported + // llvm::RoundingMode RM = SemaRef.CurFPFeatures.getRoundingMode(); + SmallVector Tokens; + hlsl::RootSignatureLexer Lexer(Signature, Loc, SemaRef.getPreprocessor()); + if (Lexer.Lex(Tokens)) +return; + + SmallVector Elements; + hlsl::RootSignatureParser Parser(Elements, Tokens, + SemaRef.getPreprocessor().getDiagnostics()); + if (Parser.Parse()) spall wrote: The parser and lexer were defined/tested in a different PR? https://github.com/llvm/llvm-project/pull/123985 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)
@@ -647,6 +648,40 @@ void SemaHLSL::emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, << NewFnName << FixItHint::CreateReplacement(FullRange, OS.str()); } +void SemaHLSL::handleRootSignatureAttr(Decl *D, const ParsedAttr &AL) { + if (AL.getNumArgs() != 1) spall wrote: is this a failure state? https://github.com/llvm/llvm-project/pull/123985 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)
@@ -647,6 +648,40 @@ void SemaHLSL::emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, << NewFnName << FixItHint::CreateReplacement(FullRange, OS.str()); } +void SemaHLSL::handleRootSignatureAttr(Decl *D, const ParsedAttr &AL) { + if (AL.getNumArgs() != 1) +return; + + StringRef Signature; + if (!SemaRef.checkStringLiteralArgumentAttr(AL, 0, Signature)) +return; + + SourceLocation Loc = AL.getArgAsExpr(0)->getExprLoc(); + // FIXME: pass down below to lexer when fp is supported + // llvm::RoundingMode RM = SemaRef.CurFPFeatures.getRoundingMode(); + SmallVector Tokens; + hlsl::RootSignatureLexer Lexer(Signature, Loc, SemaRef.getPreprocessor()); + if (Lexer.Lex(Tokens)) spall wrote: This is a failure state? If the lexer returns true the lexing failed? Are error messages being produced? https://github.com/llvm/llvm-project/pull/123985 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)
https://github.com/spall commented: LGTM, I'm not familiar enough with root signature syntax to say if the tests are complete and the lexer/parser isn't included in this PR as far as I can tell, so I assume it works. https://github.com/llvm/llvm-project/pull/123985 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)
@@ -0,0 +1,54 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - %s -verify + +// This file mirrors the diagnostics testing in ParseHLSLRootSignatureTest.cpp +// to verify that the correct diagnostics strings are output + +// Lexer related tests + +#define InvalidToken \ + "DescriptorTable( " \ + " invalid " \ + ")" + +[RootSignature(InvalidToken)] // expected-error {{unable to lex a valid Root Signature token}} +void bad_root_signature_1() {} + +#define InvalidEmptyNumber \ + "DescriptorTable( " \ + " CBV(t32, space = +) " \ + ")" + +[RootSignature(InvalidEmptyNumber)] // expected-error {{expected number literal is not a supported number literal of unsigned integer or integer}} +void bad_root_signature_2() {} + +#define InvalidOverflowNumber \ + "DescriptorTable( " \ + " CBV(t32, space = 98273498327498273487) " \ + ")" + +[RootSignature(InvalidOverflowNumber)] // expected-error {{provided unsigned integer literal '98273498327498273487' that overflows the maximum of 32 bits}} +void bad_root_signature_3() {} + +#define InvalidEOS \ + "DescriptorTable( " spall wrote: Is it worth adding a test with too many parens? https://github.com/llvm/llvm-project/pull/123985 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Create symbols for resource handles (PR #119775)
https://github.com/spall approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/119775 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)
https://github.com/spall edited https://github.com/llvm/llvm-project/pull/123985 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [HLSL] Allow resource annotations to specify only register space (PR #135287)
@@ -163,11 +163,16 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs, SourceLocation SlotLoc = Tok.getLocation(); ArgExprs.push_back(ParseIdentifierLoc()); -// Add numeric_constant for fix-it. -if (SlotStr.size() == 1 && Tok.is(tok::numeric_constant)) +if (SlotStr.size() == 1) { + if (!Tok.is(tok::numeric_constant)) { +Diag(Tok.getLocation(), diag::err_expected) << tok::numeric_constant; +SkipUntil(tok::r_paren, StopAtSemi); // skip through ) spall wrote: I'm unfamiliar with the parsing code so this might be a dumb question, but why do you SkipUntil here? What happens after the code returns? https://github.com/llvm/llvm-project/pull/135287 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add parsing infastructure for StaticSampler (PR #140180)
@@ -606,6 +644,30 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) { return Params; } +std::optional +RootSignatureParser::parseStaticSamplerParams() { + assert(CurToken.TokKind == TokenKind::pu_l_paren && + "Expects to only be invoked starting at given token"); + + ParsedStaticSamplerParams Params; + do { +// `s` POS_INT +if (tryConsumeExpectedToken(TokenKind::sReg)) { + if (Params.Reg.has_value()) { +getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) +<< CurToken.TokKind; +return std::nullopt; + } + auto Reg = parseRegister(); + if (!Reg.has_value()) spall wrote: what does this case look like? Why is this not a parsing error? https://github.com/llvm/llvm-project/pull/140180 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add parsing infastructure for StaticSampler (PR #140180)
@@ -223,6 +223,34 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) { ASSERT_TRUE(Consumer->isSatisfied()); } +TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) { spall wrote: Should you add a test where the parsing is unsuccessful? https://github.com/llvm/llvm-project/pull/140180 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add parsing infastructure for StaticSampler (PR #140180)
@@ -606,6 +644,30 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) { return Params; } +std::optional +RootSignatureParser::parseStaticSamplerParams() { + assert(CurToken.TokKind == TokenKind::pu_l_paren && + "Expects to only be invoked starting at given token"); + + ParsedStaticSamplerParams Params; + do { +// `s` POS_INT +if (tryConsumeExpectedToken(TokenKind::sReg)) { + if (Params.Reg.has_value()) { +getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) +<< CurToken.TokKind; +return std::nullopt; + } + auto Reg = parseRegister(); + if (!Reg.has_value()) +return std::nullopt; + Params.Reg = Reg; +} + } while (tryConsumeExpectedToken(TokenKind::pu_comma)); spall wrote: It looks like this parsing code allows stuff of the form 'StaticSampler(,)', and from looking at a DXC example it seems that is allowed https://godbolt.org/z/j7qP11h9W. It is amusing this is so permissive, and I wonder if there is a reason for that. https://github.com/llvm/llvm-project/pull/140180 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Move the scalarizer pass to before dxil-flatten-arrays (PR #146800)
https://github.com/spall approved this pull request. Nit on the PR description. you didn't move the scalarizerPass, you moved the DXILFlattenArrays pass to be immediately after the scalarizerPass. https://github.com/llvm/llvm-project/pull/146800 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits