From 1fb3c1536587d6ed085f13af78101cbfb3481dca Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Thu, 27 Feb 2025 10:28:13 -0800 Subject: [PATCH 01/31] Fix overload resolution for `ModuleDeclarationDecl` (#6483) * Fix overload resolution for `MemberExp`r's base expression Also fixed an issue where `ModuleDeclarationDecl` priority during overload resolution was inverted. * Made the fix slightly simpler.. * Update overload-resolve.slang --- source/slang/slang-check-expr.cpp | 6 ++++- source/slang/slang-check-overload.cpp | 2 +- .../namespace-import/overload-resolve.slang | 25 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tests/language-feature/namespaces/namespace-import/overload-resolve.slang diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 1fb2b336f0..b249bb343e 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -4848,17 +4848,21 @@ Expr* SemanticsVisitor::maybeInsertImplicitOpForMemberBase( // baseExpr = maybeOpenExistential(baseExpr); + // In case our base expressin is still overloaded, we can perform + // some more refinement. + // // Handle the case of an overloaded base expression // here, in case we can use the name of the member to // disambiguate which of the candidates is meant, or if // we can return an overloaded result. + // if (auto overloadedExpr = as(baseExpr)) { // If a member (dynamic or static) lookup result contains both the actual definition // and the interface definition obtained from inheritance, we want to filter out // the interface definitions. LookupResult filteredLookupResult; - for (auto lookupResult : overloadedExpr->lookupResult2) + for (auto lookupResult : overloadedExpr->lookupResult2.items) { bool shouldRemove = false; if (lookupResult.declRef.getParent().as()) diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 01cd303c78..5e55eb70f9 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -1345,7 +1345,7 @@ int SemanticsVisitor::CompareLookupResultItems( bool leftIsModule = (as(left.declRef) != nullptr); bool rightIsModule = (as(right.declRef) != nullptr); if (leftIsModule != rightIsModule) - return int(rightIsModule) - int(leftIsModule); + return int(leftIsModule) - int(rightIsModule); // If both are interface requirements, prefer the more derived interface. if (leftIsInterfaceRequirement && rightIsInterfaceRequirement) diff --git a/tests/language-feature/namespaces/namespace-import/overload-resolve.slang b/tests/language-feature/namespaces/namespace-import/overload-resolve.slang new file mode 100644 index 0000000000..0b483d9160 --- /dev/null +++ b/tests/language-feature/namespaces/namespace-import/overload-resolve.slang @@ -0,0 +1,25 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj + +module test; + +namespace test +{ + vector f(vector x) + { + return x; + } +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + int tid = dispatchThreadID.x; + int inVal = tid; + // Should be able to resolve 'test' properly (and not get confused by the module declaration with the same name) + int outVal = test.f<3>(vector(1, 2, 3)).y; + outputBuffer[tid] = outVal; + // CHECK: 2 +} From 2ebf9555a54c00f45b1cd0bdd7f6c163120bb845 Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Thu, 27 Feb 2025 20:29:00 +0200 Subject: [PATCH 02/31] Document bug with global session teardown in user guide (#6479) This closes #6344. Co-authored-by: Yong He --- docs/user-guide/08-compiling.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/user-guide/08-compiling.md b/docs/user-guide/08-compiling.md index c600b8cbb9..1a730e26bd 100644 --- a/docs/user-guide/08-compiling.md +++ b/docs/user-guide/08-compiling.md @@ -603,6 +603,10 @@ for compiling GLSL code. Without this setting, compiling GLSL code will result i > Currently, the global session type is *not* thread-safe. > Applications that wish to compile on multiple threads will need to ensure that each concurrent thread compiles with a distinct global session. +> #### Note #### +> Currently, the global session should be freed after any objects created from it. +> See [issue 6344](https://github.com/shader-slang/slang/issues/6344). + ### Creating a Session A _session_ uses the interface `slang::ISession`, and represents a scope for compilation with a consistent set of compiler options. From 6cf15f4ea1fe044d8227440dcc30ac712334568e Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 27 Feb 2025 10:32:14 -0800 Subject: [PATCH 03/31] Allow `.member` syntax on vector and scalars. (#6424) * Allow `.member` syntax on vector and scalars. * Fix. * fix. * Fix. * update comment. * Fix tests. * Fix warning. * Add more tests. --- source/slang/slang-check-expr.cpp | 166 ++++++++---------- source/slang/slang-check-overload.cpp | 18 +- .../slang-language-server-completion.cpp | 29 +-- .../slang/slang-language-server-completion.h | 5 +- tests/bugs/invalid-swizzle-count.slang | 4 +- .../diagnostics/matrix-swizzle.slang.expected | 26 +-- tests/front-end/matrix-member.slang | 17 ++ tests/front-end/scalar-member.slang | 17 ++ tests/front-end/vector-member.slang | 17 ++ .../member-completion-broken-syntax-3.slang | 10 +- tests/language-server/scalar-member.slang | 9 + tests/language-server/vector-member.slang | 7 +- tools/slang-test/slang-test-main.cpp | 18 +- 13 files changed, 200 insertions(+), 143 deletions(-) create mode 100644 tests/front-end/matrix-member.slang create mode 100644 tests/front-end/scalar-member.slang create mode 100644 tests/front-end/vector-member.slang create mode 100644 tests/language-server/scalar-member.slang diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index b249bb343e..b730069b65 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -4136,12 +4136,6 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr( IntegerLiteralValue baseElementRowCount, IntegerLiteralValue baseElementColCount) { - MatrixSwizzleExpr* swizExpr = m_astBuilder->create(); - swizExpr->loc = memberRefExpr->loc; - swizExpr->base = memberRefExpr->baseExpression; - swizExpr->memberOpLoc = memberRefExpr->memberOperatorLoc; - swizExpr->checked = true; - // We can have up to 4 swizzles of two elements each MatrixCoord elementCoords[4]; int elementCount = 0; @@ -4170,24 +4164,14 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr( // Throw out swizzling with more than 4 output elements if (elementCount >= 4) { - getSink()->diagnose( - swizExpr, - Diagnostics::invalidSwizzleExpr, - swizzleText, - baseElementType->toString()); - return CreateErrorExpr(memberRefExpr); + return nullptr; } MatrixCoord elementCoord = {0, 0}; // Check for the preceding underscore if (*cursor++ != '_') { - getSink()->diagnose( - swizExpr, - Diagnostics::invalidSwizzleExpr, - swizzleText, - baseElementType->toString()); - return CreateErrorExpr(memberRefExpr); + return nullptr; } // Check for one or zero indexing @@ -4196,12 +4180,7 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr( // Can't mix one and zero indexing if (zeroIndexOffset == 1) { - getSink()->diagnose( - swizExpr, - Diagnostics::invalidSwizzleExpr, - swizzleText, - baseElementType->toString()); - return CreateErrorExpr(memberRefExpr); + return nullptr; } zeroIndexOffset = 0; // Increment the index since we saw 'm' @@ -4212,12 +4191,7 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr( // Can't mix one and zero indexing if (zeroIndexOffset == 0) { - getSink()->diagnose( - swizExpr, - Diagnostics::invalidSwizzleExpr, - swizzleText, - baseElementType->toString()); - return CreateErrorExpr(memberRefExpr); + return nullptr; } zeroIndexOffset = 1; } @@ -4229,13 +4203,7 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr( if (ch < '0' || ch > '4') { - // An invalid character in the swizzle is an error - getSink()->diagnose( - swizExpr, - Diagnostics::invalidSwizzleExpr, - swizzleText, - baseElementType->toString()); - return CreateErrorExpr(memberRefExpr); + return nullptr; } const int subIndex = ch - '0' - zeroIndexOffset; @@ -4255,12 +4223,7 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr( // Account for off-by-one and reject 0 if oneIndexed if (subIndex >= elementLimit || subIndex < 0) { - getSink()->diagnose( - swizExpr, - Diagnostics::invalidSwizzleExpr, - swizzleText, - baseElementType->toString()); - return CreateErrorExpr(memberRefExpr); + return nullptr; } } // Check if we've seen this index before @@ -4275,6 +4238,12 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr( elementCount++; } + MatrixSwizzleExpr* swizExpr = m_astBuilder->create(); + swizExpr->loc = memberRefExpr->loc; + swizExpr->base = memberRefExpr->baseExpression; + swizExpr->memberOpLoc = memberRefExpr->memberOperatorLoc; + swizExpr->checked = true; + // Store our list in the actual AST node for (int ee = 0; ee < elementCount; ++ee) { @@ -4324,11 +4293,7 @@ Expr* SemanticsVisitor::CheckMatrixSwizzleExpr( constantColCount->getValue()); } } - getSink()->diagnose( - memberRefExpr, - Diagnostics::unimplemented, - "swizzle on matrix of unknown size"); - return CreateErrorExpr(memberRefExpr); + return nullptr; } Expr* SemanticsVisitor::checkTupleSwizzleExpr(MemberExpr* memberExpr, TupleType* baseTupleType) @@ -4439,26 +4404,13 @@ Expr* SemanticsVisitor::CheckSwizzleExpr( Type* baseElementType, IntegerLiteralValue baseElementCount) { - SwizzleExpr* swizExpr = m_astBuilder->create(); - swizExpr->loc = memberRefExpr->loc; - swizExpr->base = memberRefExpr->baseExpression; - swizExpr->memberOpLoc = memberRefExpr->memberOperatorLoc; IntegerLiteralValue limitElement = baseElementCount; ShortList elementIndices; bool anyDuplicates = false; bool anyError = false; - if (memberRefExpr->name == getSession()->getCompletionRequestTokenName()) - { - auto& suggestions = getLinkage()->contentAssistInfo.completionSuggestions; - suggestions.clear(); - suggestions.scopeKind = CompletionSuggestions::ScopeKind::Swizzle; - suggestions.swizzleBaseType = - memberRefExpr->baseExpression ? memberRefExpr->baseExpression->type : nullptr; - suggestions.elementCount[0] = baseElementCount; - suggestions.elementCount[1] = 0; - } + auto swizzleText = getText(memberRefExpr->name); for (Index i = 0; i < swizzleText.getLength(); i++) @@ -4518,18 +4470,18 @@ Expr* SemanticsVisitor::CheckSwizzleExpr( elementIndices.add(elementIndex); } - swizExpr->elementIndices = _Move(elementIndices); - if (anyError) { - getSink()->diagnose( - swizExpr, - Diagnostics::invalidSwizzleExpr, - swizzleText, - baseElementType->toString()); - return CreateErrorExpr(memberRefExpr); + return nullptr; } - else if (swizExpr->elementIndices.getCount() == 1) + + SwizzleExpr* swizExpr = m_astBuilder->create(); + swizExpr->loc = memberRefExpr->loc; + swizExpr->base = memberRefExpr->baseExpression; + swizExpr->memberOpLoc = memberRefExpr->memberOperatorLoc; + swizExpr->elementIndices = _Move(elementIndices); + + if (swizExpr->elementIndices.getCount() == 1) { // single-component swizzle produces a scalar // @@ -4568,11 +4520,7 @@ Expr* SemanticsVisitor::CheckSwizzleExpr( } else { - getSink()->diagnose( - memberRefExpr, - Diagnostics::unimplemented, - "swizzle on vector of unknown size"); - return CreateErrorExpr(memberRefExpr); + return nullptr; } } @@ -4914,6 +4862,28 @@ Expr* SemanticsVisitor::checkGeneralMemberLookupExpr(MemberExpr* expr, Type* bas if (expr->name == getSession()->getCompletionRequestTokenName()) { suggestCompletionItems(CompletionSuggestions::ScopeKind::Member, lookupResult); + if (expr->baseExpression) + { + if (auto vectorType = as(expr->baseExpression->type)) + { + auto& suggestions = getLinkage()->contentAssistInfo.completionSuggestions; + suggestions.scopeKind = CompletionSuggestions::ScopeKind::Swizzle; + suggestions.elementCount[1] = 0; + suggestions.swizzleBaseType = vectorType; + if (auto elementCount = as(vectorType->getElementCount())) + suggestions.elementCount[0] = elementCount->getValue(); + else + suggestions.elementCount[0] = 1; + } + else if (auto scalarType = as(expr->baseExpression->type)) + { + auto& suggestions = getLinkage()->contentAssistInfo.completionSuggestions; + suggestions.scopeKind = CompletionSuggestions::ScopeKind::Swizzle; + suggestions.elementCount[1] = 0; + suggestions.elementCount[0] = 1; + suggestions.swizzleBaseType = scalarType; + } + } } return createLookupResultExpr(expr->name, lookupResult, expr->baseExpression, expr->loc, expr); } @@ -4942,34 +4912,36 @@ Expr* SemanticsExprVisitor::visitMemberExpr(MemberExpr* expr) if (auto modifiedType = as(baseType)) baseType = modifiedType->getBase(); - // Note: Checking for vector types before declaration-reference types, - // because vectors are also declaration reference types... + // Try handle swizzle-able types (scalar,vector,matrix) first. + // If checking as a swizzle failed for these types, + // we will fallback to normal member lookup. // - // Also note: the way this is done right now means that the ability - // to swizzle vectors interferes with any chance of looking up - // members via extension, for vector or scalar types. - // - if (auto baseMatrixType = as(baseType)) + if (auto baseScalarType = as(baseType)) { - return CheckMatrixSwizzleExpr( - expr, - baseMatrixType->getElementType(), - baseMatrixType->getRowCount(), - baseMatrixType->getColumnCount()); + // Treat scalar like a 1-element vector when swizzling + auto swizzle = CheckSwizzleExpr(expr, baseScalarType, 1); + if (swizzle) + return swizzle; } - if (auto baseVecType = as(baseType)) + else if (auto baseVecType = as(baseType)) { - return CheckSwizzleExpr( - expr, - baseVecType->getElementType(), - baseVecType->getElementCount()); + auto swizzle = + CheckSwizzleExpr(expr, baseVecType->getElementType(), baseVecType->getElementCount()); + if (swizzle) + return swizzle; } - else if (auto baseScalarType = as(baseType)) + else if (auto baseMatrixType = as(baseType)) { - // Treat scalar like a 1-element vector when swizzling - return CheckSwizzleExpr(expr, baseScalarType, 1); + auto swizzle = CheckMatrixSwizzleExpr( + expr, + baseMatrixType->getElementType(), + baseMatrixType->getRowCount(), + baseMatrixType->getColumnCount()); + if (swizzle) + return swizzle; } - else if (as(baseType)) + + if (as(baseType)) { return _lookupStaticMember(expr, expr->baseExpression); } diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 5e55eb70f9..21fc21df65 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -1316,15 +1316,17 @@ int SemanticsVisitor::CompareLookupResultItems( // Add a special case for constructors, where we prefer the one that is not synthesized, if (auto leftCtor = as(left.declRef.getDecl())) { - auto rightCtor = as(right.declRef.getDecl()); - bool leftIsSynthesized = - leftCtor->containsFlavor(ConstructorDecl::ConstructorFlavor::SynthesizedDefault); - bool rightIsSynthesized = - rightCtor->containsFlavor(ConstructorDecl::ConstructorFlavor::SynthesizedDefault); - - if (leftIsSynthesized != rightIsSynthesized) + if (auto rightCtor = as(right.declRef.getDecl())) { - return int(leftIsSynthesized) - int(rightIsSynthesized); + bool leftIsSynthesized = leftCtor->containsFlavor( + ConstructorDecl::ConstructorFlavor::SynthesizedDefault); + bool rightIsSynthesized = rightCtor->containsFlavor( + ConstructorDecl::ConstructorFlavor::SynthesizedDefault); + + if (leftIsSynthesized != rightIsSynthesized) + { + return int(leftIsSynthesized) - int(rightIsSynthesized); + } } } diff --git a/source/slang/slang-language-server-completion.cpp b/source/slang/slang-language-server-completion.cpp index 77ed330029..1e5bae4b05 100644 --- a/source/slang/slang-language-server-completion.cpp +++ b/source/slang/slang-language-server-completion.cpp @@ -512,11 +512,14 @@ LanguageServerResult CompletionContext::tryCompleteMemberAndSy CompletionResult CompletionContext::collectMembersAndSymbols() { + List result; + auto linkage = version->linkage; if (linkage->contentAssistInfo.completionSuggestions.scopeKind == CompletionSuggestions::ScopeKind::Swizzle) { - return createSwizzleCandidates( + createSwizzleCandidates( + result, linkage->contentAssistInfo.completionSuggestions.swizzleBaseType, linkage->contentAssistInfo.completionSuggestions.elementCount); } @@ -526,12 +529,12 @@ CompletionResult CompletionContext::collectMembersAndSymbols() { return createCapabilityCandidates(); } - List result; bool useCommitChars = true; bool addKeywords = false; switch (linkage->contentAssistInfo.completionSuggestions.scopeKind) { case CompletionSuggestions::ScopeKind::Member: + case CompletionSuggestions::ScopeKind::Swizzle: useCommitChars = (commitCharacterBehavior == CommitCharacterBehavior::MembersOnly || commitCharacterBehavior == CommitCharacterBehavior::All); @@ -698,13 +701,12 @@ CompletionResult CompletionContext::createCapabilityCandidates() return result; } -CompletionResult CompletionContext::createSwizzleCandidates( +void CompletionContext::createSwizzleCandidates( + List& result, Type* type, IntegerLiteralValue elementCount[2]) { - List result; // Hard code members for vector and matrix types. - result.clear(); if (auto vectorType = as(type)) { const char* memberNames[4] = {"x", "y", "z", "w"}; @@ -724,6 +726,17 @@ CompletionResult CompletionContext::createSwizzleCandidates( result.add(item); } } + else if (auto scalarType = as(type)) + { + String typeStr; + typeStr = scalarType->toString(); + LanguageServerProtocol::CompletionItem item; + item.data = 0; + item.detail = typeStr; + item.kind = LanguageServerProtocol::kCompletionItemKindVariable; + item.label = "x"; + result.add(item); + } else if (auto matrixType = as(type)) { Type* elementType = nullptr; @@ -769,12 +782,6 @@ CompletionResult CompletionContext::createSwizzleCandidates( result.add(item); } } - for (auto& item : result) - { - for (auto ch : getCommitChars()) - item.commitCharacters.add(ch); - } - return result; } LanguageServerProtocol::CompletionItem CompletionContext::generateGUIDCompletionItem() diff --git a/source/slang/slang-language-server-completion.h b/source/slang/slang-language-server-completion.h index 560702deaa..fab1c8a755 100644 --- a/source/slang/slang-language-server-completion.h +++ b/source/slang/slang-language-server-completion.h @@ -55,7 +55,10 @@ struct CompletionContext CompletionResult collectMembersAndSymbols(); - CompletionResult createSwizzleCandidates(Type* baseType, IntegerLiteralValue elementCount[2]); + void createSwizzleCandidates( + List& result, + Type* type, + IntegerLiteralValue elementCount[2]); CompletionResult createCapabilityCandidates(); CompletionResult collectAttributes(); LanguageServerProtocol::CompletionItem generateGUIDCompletionItem(); diff --git a/tests/bugs/invalid-swizzle-count.slang b/tests/bugs/invalid-swizzle-count.slang index 811cf6f444..93cb1fdcc1 100644 --- a/tests/bugs/invalid-swizzle-count.slang +++ b/tests/bugs/invalid-swizzle-count.slang @@ -1,6 +1,6 @@ //TEST:SIMPLE(filecheck=CHECK): -target spirv -stage compute -entry computeMain -emit-spirv-directly -// CHECK: error 30052 -// CHECK-NOT: error 30052 +// CHECK: error 30027 +// CHECK-NOT: error 30027 RWStructuredBuffer outputBuffer; [numthreads(1,1,1)] diff --git a/tests/diagnostics/matrix-swizzle.slang.expected b/tests/diagnostics/matrix-swizzle.slang.expected index 832ddd7390..3c88531612 100644 --- a/tests/diagnostics/matrix-swizzle.slang.expected +++ b/tests/diagnostics/matrix-swizzle.slang.expected @@ -1,42 +1,42 @@ result code = -1 standard error = { -tests/diagnostics/matrix-swizzle.slang(8): error 30052: invalid swizzle pattern '_14' on type 'int' +tests/diagnostics/matrix-swizzle.slang(8): error 30027: '_14' is not a member of 'matrix'. int c = m1._14; // Out of bounds ^~~ -tests/diagnostics/matrix-swizzle.slang(9): error 30052: invalid swizzle pattern '_32' on type 'int' +tests/diagnostics/matrix-swizzle.slang(9): error 30027: '_32' is not a member of 'matrix'. c = m1._32; ^~~ -tests/diagnostics/matrix-swizzle.slang(10): error 30052: invalid swizzle pattern '_m22' on type 'int' +tests/diagnostics/matrix-swizzle.slang(10): error 30027: '_m22' is not a member of 'matrix'. c = m2._m22; ^~~~ -tests/diagnostics/matrix-swizzle.slang(11): error 30052: invalid swizzle pattern '_' on type 'int' +tests/diagnostics/matrix-swizzle.slang(11): error 30027: '_' is not a member of 'matrix'. c = m2._; // unfinished ^ -tests/diagnostics/matrix-swizzle.slang(12): error 30052: invalid swizzle pattern '_m' on type 'int' +tests/diagnostics/matrix-swizzle.slang(12): error 30027: '_m' is not a member of 'matrix'. c = m2._m; ^~ -tests/diagnostics/matrix-swizzle.slang(13): error 30052: invalid swizzle pattern '_1' on type 'int' +tests/diagnostics/matrix-swizzle.slang(13): error 30027: '_1' is not a member of 'matrix'. c = m2._1; ^~ -tests/diagnostics/matrix-swizzle.slang(14): error 30052: invalid swizzle pattern '_m1' on type 'int' +tests/diagnostics/matrix-swizzle.slang(14): error 30027: '_m1' is not a member of 'matrix'. c = m2._m1; ^~~ -tests/diagnostics/matrix-swizzle.slang(15): error 30052: invalid swizzle pattern '_m12_' on type 'int' +tests/diagnostics/matrix-swizzle.slang(15): error 30027: '_m12_' is not a member of 'matrix'. c = m2._m12_; ^~~~~ -tests/diagnostics/matrix-swizzle.slang(16): error 30052: invalid swizzle pattern '_m11_11' on type 'int' +tests/diagnostics/matrix-swizzle.slang(16): error 30027: '_m11_11' is not a member of 'matrix'. int2 c2 = m1._m11_11; // Mixing of 1 and 0-indexing ^~~~~~~ -tests/diagnostics/matrix-swizzle.slang(17): error 30052: invalid swizzle pattern '_11_11_11_11_11' on type 'int' +tests/diagnostics/matrix-swizzle.slang(17): error 30027: '_11_11_11_11_11' is not a member of 'matrix'. c = m1._11_11_11_11_11; // More than 4 elements ^~~~~~~~~~~~~~~ -tests/diagnostics/matrix-swizzle.slang(18): error 30052: invalid swizzle pattern 'x' on type 'int' +tests/diagnostics/matrix-swizzle.slang(18): error 30027: 'x' is not a member of 'matrix'. c = m1.x; // Invalid character ^ -tests/diagnostics/matrix-swizzle.slang(19): error 30052: invalid swizzle pattern '_x' on type 'int' +tests/diagnostics/matrix-swizzle.slang(19): error 30027: '_x' is not a member of 'matrix'. c = m1._x; ^~ -tests/diagnostics/matrix-swizzle.slang(20): error 30052: invalid swizzle pattern 'x123' on type 'int' +tests/diagnostics/matrix-swizzle.slang(20): error 30027: 'x123' is not a member of 'matrix'. c = m1.x123; ^~~~ } diff --git a/tests/front-end/matrix-member.slang b/tests/front-end/matrix-member.slang new file mode 100644 index 0000000000..447fe715fd --- /dev/null +++ b/tests/front-end/matrix-member.slang @@ -0,0 +1,17 @@ +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-output-using-type + +extension float2x2 +{ + float sum() { return this[0][0] + this[1][1]; } +} + +//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride = 4) +RWStructuredBuffer outputBuffer; + +[numthreads(1,1,1)] +void computeMain() +{ + float2x2 v = {1,2,3,4}; + // CHECK: 5 + outputBuffer[0] = v.sum(); +} \ No newline at end of file diff --git a/tests/front-end/scalar-member.slang b/tests/front-end/scalar-member.slang new file mode 100644 index 0000000000..b85b8772c3 --- /dev/null +++ b/tests/front-end/scalar-member.slang @@ -0,0 +1,17 @@ +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-output-using-type + +extension float +{ + float sum() { return this + 1; } +} + +//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride = 4) +RWStructuredBuffer outputBuffer; + +[numthreads(1,1,1)] +void computeMain() +{ + float v = 10.0; + // CHECK: 11 + outputBuffer[0] = v.sum(); +} \ No newline at end of file diff --git a/tests/front-end/vector-member.slang b/tests/front-end/vector-member.slang new file mode 100644 index 0000000000..adced39e46 --- /dev/null +++ b/tests/front-end/vector-member.slang @@ -0,0 +1,17 @@ +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-output-using-type + +extension float3 +{ + float sum() { return this.x + this.y + this.z; } +} + +//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride = 4) +RWStructuredBuffer outputBuffer; + +[numthreads(1,1,1)] +void computeMain() +{ + float3 v = { 1, 2, 3 }; + // CHECK: 6 + outputBuffer[0] = v.sum(); +} \ No newline at end of file diff --git a/tests/language-server/member-completion-broken-syntax-3.slang b/tests/language-server/member-completion-broken-syntax-3.slang index 316afc5418..9d497f9e13 100644 --- a/tests/language-server/member-completion-broken-syntax-3.slang +++ b/tests/language-server/member-completion-broken-syntax-3.slang @@ -1,9 +1,13 @@ -//TEST:LANG_SERVER: -//COMPLETE:7,9 +//TEST:LANG_SERVER(filecheck=CHECK): float3 m() { float3 val = 0; +//COMPLETE:7,9 val. return val; -} \ No newline at end of file +} + +// CHECK: x +// CHECK: y +// CHECK: z \ No newline at end of file diff --git a/tests/language-server/scalar-member.slang b/tests/language-server/scalar-member.slang new file mode 100644 index 0000000000..6b12ab8976 --- /dev/null +++ b/tests/language-server/scalar-member.slang @@ -0,0 +1,9 @@ +//TEST:LANG_SERVER(filecheck=CHECK): +void f() +{ + float v; +//COMPLETE:6,7 + v. +} + +// CHECK: x \ No newline at end of file diff --git a/tests/language-server/vector-member.slang b/tests/language-server/vector-member.slang index 5d624e56d2..341544ac09 100644 --- a/tests/language-server/vector-member.slang +++ b/tests/language-server/vector-member.slang @@ -1,7 +1,12 @@ -//TEST:LANG_SERVER: +//TEST:LANG_SERVER(filecheck=CHECK): void f() { float4 v; //COMPLETE:6,7 v. } + +// CHECK: x +// CHECK: y +// CHECK: z +// CHECK: w \ No newline at end of file diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 10bc99017b..57328c210f 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -2037,9 +2037,13 @@ TestResult runLanguageServerTest(TestContext* context, TestInput& input) int callId = 2; for (auto line : lines) { - if (line.startsWith("//COMPLETE:")) + line = line.trimStart(); + if (!line.startsWith("//")) + continue; + line = line.tail(2).trimStart(); + if (line.startsWith("COMPLETE:")) { - auto arg = line.tail(UnownedStringSlice("//COMPLETE:").getLength()); + auto arg = line.tail(UnownedStringSlice("COMPLETE:").getLength()); Int linePos, colPos; parseLocation(arg, 0, linePos, colPos); @@ -2074,9 +2078,9 @@ TestResult runLanguageServerTest(TestContext* context, TestInput& input) } } } - else if (line.startsWith("//SIGNATURE:")) + else if (line.startsWith("SIGNATURE:")) { - auto arg = line.tail(UnownedStringSlice("//SIGNATURE:").getLength()); + auto arg = line.tail(UnownedStringSlice("SIGNATURE:").getLength()); Int linePos, colPos; parseLocation(arg, 0, linePos, colPos); @@ -2116,9 +2120,9 @@ TestResult runLanguageServerTest(TestContext* context, TestInput& input) } } } - else if (line.startsWith("//HOVER:")) + else if (line.startsWith("HOVER:")) { - auto arg = line.tail(UnownedStringSlice("//HOVER:").getLength()); + auto arg = line.tail(UnownedStringSlice("HOVER:").getLength()); Int linePos, colPos; parseLocation(arg, 0, linePos, colPos); @@ -2150,7 +2154,7 @@ TestResult runLanguageServerTest(TestContext* context, TestInput& input) actualOutputSB << "\ncontent:\n" << hover.contents.value << "\n"; } } - else if (line.startsWith("//DIAGNOSTICS")) + else if (line.startsWith("DIAGNOSTICS")) { if (!diagnosticsReceived) { From 90b3817498d9cf664346f04dcea71f48ce81993e Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 27 Feb 2025 13:21:20 -0800 Subject: [PATCH 04/31] Make capability diagnostic message more friendly. (#6474) * Make capability diagnostic message more friendly. * Fix. * Fix. * Fix. * Fix test. * Update expected fail setting for aarch64/linux * Fix. --- .github/workflows/ci.yml | 3 +- source/slang/slang-ast-base.h | 6 +- source/slang/slang-check-decl.cpp | 167 ++++++++++++------ source/slang/slang-diagnostic-defs.h | 8 +- source/slang/slang-syntax.cpp | 14 +- tests/diagnostics/discard-in-rt.slang | 24 +++ .../capabilitySimplification1.slang | 2 +- .../capabilitySimplification3.slang | 2 +- .../capability/explicit-shader-stage-2.slang | 2 +- 9 files changed, 162 insertions(+), 66 deletions(-) create mode 100644 tests/diagnostics/discard-in-rt.slang diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6cf72fdee1..9e0b03dbcb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -166,7 +166,8 @@ jobs: -use-test-server \ -category ${{ matrix.test-category }} \ -api all-dx12 \ - -expected-failure-list tests/expected-failure-github.txt + -expected-failure-list tests/expected-failure-github.txt \ + -expected-failure-list tests/expected-failure-record-replay-tests.txt else "$bin_dir/slang-test" \ -use-test-server \ diff --git a/source/slang/slang-ast-base.h b/source/slang/slang-ast-base.h index 9cc36e5304..8f85334d67 100644 --- a/source/slang/slang-ast-base.h +++ b/source/slang/slang-ast-base.h @@ -741,9 +741,9 @@ class ModifiableSyntaxNode : public SyntaxNode } }; -struct DeclReferenceWithLoc +struct ProvenenceNodeWithLoc { - Decl* referencedDecl; + NodeBase* referencedNode; SourceLoc referenceLoc; }; @@ -789,7 +789,7 @@ class Decl : public DeclBase bool isChildOf(Decl* other) const; // Track the decl reference that caused the requirement of a capability atom. - SLANG_UNREFLECTED List capabilityRequirementProvenance; + SLANG_UNREFLECTED List capabilityRequirementProvenance; SLANG_UNREFLECTED bool hiddenFromLookup = false; diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index f12d11bdf2..486ac6e9c9 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -12744,11 +12744,11 @@ static void _propagateRequirement( // if stmt inside parent, set the provenance tracker to the calling function if (!decl) decl = visitor->getParentFuncOfVisitor(); - if (referencedDecl && decl) + if (referencedNode && decl) { // Here we store a childDecl that added/removed capabilities from a parentDecl decl->capabilityRequirementProvenance.add( - DeclReferenceWithLoc{referencedDecl, referenceLoc}); + ProvenenceNodeWithLoc{referencedNode, referenceLoc}); } }; @@ -12977,15 +12977,19 @@ CapabilitySet SemanticsDeclCapabilityVisitor::getDeclaredCapabilitySet(Decl* dec // The requirement for `foo` should be glsl+glsl_ext_1 | spirv. // CapabilitySet declaredCaps; + CapabilityAtom stageToJoin = CapabilityAtom::Invalid; for (Decl* parent = decl; parent; parent = getParentDecl(parent)) { CapabilitySet localDeclaredCaps; bool shouldBreak = false; if (!as(parent) || parent->inferredCapabilityRequirements.isEmpty()) { - for (auto decoration : parent->getModifiersOfType()) + for (auto mod : parent->modifiers) { - localDeclaredCaps.unionWith(decoration->capabilitySet); + if (auto decoration = as(mod)) + localDeclaredCaps.unionWith(decoration->capabilitySet); + else if (auto entrypoint = as(mod)) + stageToJoin = entrypoint->capabilitySet.getTargetStage(); } } else @@ -13001,6 +13005,8 @@ CapabilitySet SemanticsDeclCapabilityVisitor::getDeclaredCapabilitySet(Decl* dec if (shouldBreak) break; } + if (!declaredCaps.isEmpty() && stageToJoin != CapabilityAtom::Invalid) + declaredCaps.join(CapabilitySet((CapabilityName)stageToJoin)); return declaredCaps; } @@ -13298,63 +13304,83 @@ void diagnoseMissingCapabilityProvenance( Decl* decl, CapabilitySet& setToFind) { - HashSet checkedDecls; - DeclReferenceWithLoc declWithRef; - declWithRef.referencedDecl = decl; - declWithRef.referenceLoc = (decl) ? decl->loc : SourceLoc(); + HashSet checkedDecls; + ProvenenceNodeWithLoc provNode; + provNode.referencedNode = decl; + provNode.referenceLoc = (decl) ? decl->loc : SourceLoc(); bool bottomOfProvenanceStack = false; // Find the bottom of the atom provenance stack which fails to contain `setToFind` - while (!bottomOfProvenanceStack && declWithRef.referencedDecl) + while (!bottomOfProvenanceStack && provNode.referencedNode) { bottomOfProvenanceStack = true; - for (auto& i : declWithRef.referencedDecl->capabilityRequirementProvenance) + if (auto referencedDecl = as(provNode.referencedNode)) { - if (checkedDecls.contains(i.referencedDecl)) - continue; - checkedDecls.add(i.referencedDecl); - - if (!i.referencedDecl->inferredCapabilityRequirements.implies(setToFind)) + for (auto& i : referencedDecl->capabilityRequirementProvenance) { - // We found a source of the incompatible capability, follow this - // element inside the provenance stack until we are at the bottom - declWithRef = i; - bottomOfProvenanceStack = false; - break; + if (checkedDecls.contains(i.referencedNode)) + continue; + checkedDecls.add(i.referencedNode); + auto innerReferencedDecl = as(i.referencedNode); + if (!innerReferencedDecl || + !innerReferencedDecl->inferredCapabilityRequirements.implies(setToFind)) + { + // We found a source of the incompatible capability, follow this + // element inside the provenance stack until we are at the bottom + provNode = i; + bottomOfProvenanceStack = false; + break; + } } } + else + { + bottomOfProvenanceStack = true; + } } - if (!declWithRef.referencedDecl) + if (!provNode.referencedNode) return; - // Diagnose the use-site - maybeDiagnose( - sink, - optionSet, - DiagnosticCategory::Capability, - declWithRef.referenceLoc, - Diagnostics::seeUsingOf, - declWithRef.referencedDecl); - // Diagnose the definition as the problem - maybeDiagnose( - sink, - optionSet, - DiagnosticCategory::Capability, - declWithRef.referencedDecl->loc, - Diagnostics::seeDefinitionOf, - declWithRef.referencedDecl); - - // If we find a 'require' modifier, this is contributing to the overall capability - // incompatibility. We should hint to the user that this declaration is problematic. - if (auto requireCapabilityAttribute = - declWithRef.referencedDecl->findModifier()) + if (auto referencedDecl = as(provNode.referencedNode)) + { + // Diagnose the use-site maybeDiagnose( sink, optionSet, DiagnosticCategory::Capability, - requireCapabilityAttribute->loc, - Diagnostics::seeDeclarationOf, - requireCapabilityAttribute); + provNode.referenceLoc, + Diagnostics::seeUsingOf, + referencedDecl); + // Diagnose the definition as the problem + maybeDiagnose( + sink, + optionSet, + DiagnosticCategory::Capability, + referencedDecl->loc, + Diagnostics::seeDefinitionOf, + referencedDecl); + // If we find a 'require' modifier, this is contributing to the overall capability + // incompatibility. We should hint to the user that this declaration is problematic. + if (auto requireCapabilityAttribute = + referencedDecl->findModifier()) + maybeDiagnose( + sink, + optionSet, + DiagnosticCategory::Capability, + requireCapabilityAttribute->loc, + Diagnostics::seeDeclarationOf, + requireCapabilityAttribute); + } + else + { + maybeDiagnose( + sink, + optionSet, + DiagnosticCategory::Capability, + provNode.referenceLoc, + Diagnostics::seeUsingOf, + provNode.referencedNode->astNodeType); + } } void diagnoseCapabilityProvenance( @@ -13372,7 +13398,20 @@ void diagnoseCapabilityProvenance( printedDecls.add(declToPrint); for (auto& provenance : declToPrint->capabilityRequirementProvenance) { - if (!provenance.referencedDecl->inferredCapabilityRequirements.implies(atomToFind)) + auto referencedDecl = as(provenance.referencedNode); + if (!referencedDecl) + { + maybeDiagnose( + sink, + optionSet, + DiagnosticCategory::Capability, + provenance.referenceLoc, + Diagnostics::seeUsingOf, + provenance.referencedNode->astNodeType); + break; + } + + if (!referencedDecl->inferredCapabilityRequirements.implies(atomToFind)) continue; maybeDiagnose( sink, @@ -13380,8 +13419,8 @@ void diagnoseCapabilityProvenance( DiagnosticCategory::Capability, provenance.referenceLoc, Diagnostics::seeUsingOf, - provenance.referencedDecl); - declToPrint = provenance.referencedDecl; + referencedDecl); + declToPrint = referencedDecl; if (printedDecls.contains(declToPrint)) break; if (declToPrint->findModifier()) @@ -13487,14 +13526,30 @@ void SemanticsDeclCapabilityVisitor::diagnoseUndeclaredCapability( for (auto i : simplifiedFailedAtomsSet) { CapabilityAtom formattedAtom = asAtom(i); - maybeDiagnose( - getSink(), - this->getOptionSet(), - DiagnosticCategory::Capability, - decl->loc, - diagnosticInfo, - decl, - formattedAtom); + CapabilityName canonicalName; + if (isStageAtom((CapabilityName)formattedAtom, canonicalName)) + { + // Provide a more friendly message if atom is a stage. + maybeDiagnose( + getSink(), + this->getOptionSet(), + DiagnosticCategory::Capability, + decl->loc, + Diagnostics::declHasDependenciesNotCompatibleOnStage, + decl, + formattedAtom); + } + else + { + maybeDiagnose( + getSink(), + this->getOptionSet(), + DiagnosticCategory::Capability, + decl->loc, + diagnosticInfo, + decl, + formattedAtom); + } // Print provenances. diagnoseCapabilityProvenance( this->getOptionSet(), diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h index 789eac88f0..761dc4768a 100644 --- a/source/slang/slang-diagnostic-defs.h +++ b/source/slang/slang-diagnostic-defs.h @@ -987,7 +987,7 @@ DIAGNOSTIC( 36107, Error, entryPointUsesUnavailableCapability, - "entrypoint '$0' does not support compilation target '$1' with stage '$2'") + "entrypoint '$0' uses features that are not available in '$2' stage for '$1' target.") DIAGNOSTIC( 36108, Error, @@ -1025,7 +1025,11 @@ DIAGNOSTIC( Error, capabilityHasMultipleStages, "Capability '$0' is targeting stages '$1', only allowed to use 1 unique stage here.") - +DIAGNOSTIC( + 36117, + Error, + declHasDependenciesNotCompatibleOnStage, + "'$0' uses features that are not available in '$1' stage.") // Attributes DIAGNOSTIC(31000, Warning, unknownAttributeName, "unknown attribute '$0'") diff --git a/source/slang/slang-syntax.cpp b/source/slang/slang-syntax.cpp index e479f1b9d8..efb5814e68 100644 --- a/source/slang/slang-syntax.cpp +++ b/source/slang/slang-syntax.cpp @@ -223,8 +223,20 @@ void printDiagnosticArg(StringBuilder& sb, ASTNodeType nodeType) case ASTNodeType::RequireCapabilityDecl: sb << "__require_capability"; break; + case ASTNodeType::DiscardStmt: + sb << "discard"; + break; default: - sb << "decl"; + if (ASTClassInfo::getInfo(nodeType)->isDerivedFrom((uint32_t)ASTNodeType::Expr)) + sb << "expression"; + else if (ASTClassInfo::getInfo(nodeType)->isDerivedFrom((uint32_t)ASTNodeType::Stmt)) + sb << "statement"; + else if (ASTClassInfo::getInfo(nodeType)->isDerivedFrom((uint32_t)ASTNodeType::Decl)) + sb << "decl"; + else if (ASTClassInfo::getInfo(nodeType)->isDerivedFrom((uint32_t)ASTNodeType::Val)) + sb << "val"; + else + sb << "node"; break; } } diff --git a/tests/diagnostics/discard-in-rt.slang b/tests/diagnostics/discard-in-rt.slang new file mode 100644 index 0000000000..93c3d1038c --- /dev/null +++ b/tests/diagnostics/discard-in-rt.slang @@ -0,0 +1,24 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +// CHECK: 'closestHit' uses features that are not available in 'closesthit' stage. +// CHECK: see using of 'discard' + +struct PrimaryRayPayload{} +[require(spvRayTracingKHR)] +[shader("closesthit")] +void closestHit( + inout PrimaryRayPayload rayData : SV_RayPayload, + BuiltInTriangleIntersectionAttributes attribs : SV_IntersectionAttributes) +{ + discard; +} + +// CHECK: 'closestHit1' uses features that are not available in 'closesthit' stage +// CHECK: see using of 'discard' +[shader("closesthit")] +void closestHit1( + inout PrimaryRayPayload rayData : SV_RayPayload, + BuiltInTriangleIntersectionAttributes attribs : SV_IntersectionAttributes) +{ + discard; +} diff --git a/tests/language-feature/capability/capabilitySimplification1.slang b/tests/language-feature/capability/capabilitySimplification1.slang index 1d781a45e3..440ac1cedf 100644 --- a/tests/language-feature/capability/capabilitySimplification1.slang +++ b/tests/language-feature/capability/capabilitySimplification1.slang @@ -5,7 +5,7 @@ // CHECK_IGNORE_CAPS-NOT: error 36107 // CHECK: error 36107 -// CHECK-SAME: entrypoint 'computeMain' does not support compilation target 'glsl' with stage 'compute' +// CHECK-SAME: entrypoint 'computeMain' uses features that are not available in 'compute' stage for 'glsl' target. // CHECK: capabilitySimplification1.slang(21): note: see using of 'WaveMultiPrefixCountBits' // CHECK-NOT: see using of 'WaveMultiPrefixCountBits' // CHECK: {{.*}}.meta.slang({{.*}}): note: see definition of 'WaveMultiPrefixCountBits' diff --git a/tests/language-feature/capability/capabilitySimplification3.slang b/tests/language-feature/capability/capabilitySimplification3.slang index 808c19bf60..150f926a91 100644 --- a/tests/language-feature/capability/capabilitySimplification3.slang +++ b/tests/language-feature/capability/capabilitySimplification3.slang @@ -4,7 +4,7 @@ // CHECK_IGNORE_CAPS-NOT: error 36107 -// CHECK: error 36107: entrypoint 'computeMain' does not support compilation target 'glsl' with stage 'compute' +// CHECK: error 36107: entrypoint 'computeMain' uses features that are not available in 'compute' stage for 'glsl' target. // CHECK: capabilitySimplification3.slang(16): note: see using of 'WaveMultiPrefixCountBits' // CHECK-NOT: see using of 'WaveMultiPrefixCountBits' // CHECK: {{.*}}.meta.slang({{.*}}): note: see definition of 'WaveMultiPrefixCountBits' diff --git a/tests/language-feature/capability/explicit-shader-stage-2.slang b/tests/language-feature/capability/explicit-shader-stage-2.slang index b4c6d3cfe6..a01cff7c28 100644 --- a/tests/language-feature/capability/explicit-shader-stage-2.slang +++ b/tests/language-feature/capability/explicit-shader-stage-2.slang @@ -1,7 +1,7 @@ //TEST:SIMPLE(filecheck=CHECK): -target hlsl -entry main -allow-glsl -profile sm_5_0 //TEST:SIMPLE(filecheck=CHECK_IGNORE_CAPS): -target hlsl -entry main -allow-glsl -profile sm_5_0 -ignore-capabilities -//CHECK: error 36107: entrypoint 'main' does not support compilation target 'hlsl' with stage 'fragment' +//CHECK: error 36107: entrypoint 'main' uses features that are not available in 'fragment' stage for 'hlsl' target. //CHECK_IGNORE_CAPS-NOT: error 36100 [shader("fragment")] float4 main() From 6f2ce72b038b34e84819ddfc5d658166ed879eaa Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 27 Feb 2025 16:57:52 -0800 Subject: [PATCH 05/31] Map `SV_InstanceID` to `gl_InstanceIndex-gl_BaseInstance` (#6468) * Map `SV_InstanceID` to `gl_InstanceIndex-gl_BaseInstance` * Fix ci. --- .github/workflows/ci.yml | 2 +- source/slang/glsl.meta.slang | 22 ++++- source/slang/slang-artifact-output-util.cpp | 2 + source/slang/slang-compiler.cpp | 22 +++++ source/slang/slang-compiler.h | 20 ----- source/slang/slang-emit-c-like.cpp | 19 +++++ source/slang/slang-emit-c-like.h | 2 +- source/slang/slang-emit-glsl.cpp | 6 ++ source/slang/slang-emit-spirv.cpp | 16 +++- source/slang/slang-ir-glsl-legalize.cpp | 80 ++++++++++++++++++- source/slang/slang-ir-inst-defs.h | 3 + source/slang/slang-ir-insts.h | 32 ++++++++ source/slang/slang-ir-spirv-legalize.cpp | 52 +++++++----- tests/bugs/gh-3087-multi-entry-point.slang | 18 +++-- .../system-values-draw-parameters.slang | 2 +- tests/spirv/sv_instance.slang | 14 ++++ 16 files changed, 259 insertions(+), 53 deletions(-) create mode 100644 tests/spirv/sv_instance.slang diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e0b03dbcb..4fc7be6772 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -177,7 +177,7 @@ jobs: -expected-failure-list tests/expected-failure-record-replay-tests.txt fi - name: Run Slang examples - if: steps.filter.outputs.should-run == 'true' && matrix.platform != 'wasm' + if: steps.filter.outputs.should-run == 'true' && matrix.platform != 'wasm' && matrix.full-gpu-tests run: | .github/workflows/ci-examples.sh \ --bin-dir "$bin_dir" \ diff --git a/source/slang/glsl.meta.slang b/source/slang/glsl.meta.slang index 6f0ca1bf34..eed6cc6908 100644 --- a/source/slang/glsl.meta.slang +++ b/source/slang/glsl.meta.slang @@ -136,7 +136,27 @@ public property uint3 gl_WorkGroupSize // TODO: define overload for tessellation control stage. public in int gl_InvocationID : SV_GSInstanceID; -public in int gl_InstanceIndex : SV_InstanceID; +internal in int __sv_InstanceIndex : SV_InstanceID; + +// SPIRV InstanceIndex builtin for vertex shader +public property int gl_InstanceIndex +{ + [require(vertex)] + get + { + __target_switch + { + default: + return __sv_InstanceIndex; + case glsl: + __intrinsic_asm "gl_InstanceIndex"; + case spirv: + return spirv_asm { + result:$$int = OpLoad builtin(InstanceIndex:int); + }; + } + } +} public in bool gl_FrontFacing : SV_IsFrontFace; // TODO: define overload for geometry stage. diff --git a/source/slang/slang-artifact-output-util.cpp b/source/slang/slang-artifact-output-util.cpp index 2d9dae1cf0..0e297955f5 100644 --- a/source/slang/slang-artifact-output-util.cpp +++ b/source/slang/slang-artifact-output-util.cpp @@ -6,6 +6,8 @@ #include "../core/slang-string-util.h" #include "../core/slang-type-text-util.h" +#include + // Artifact #include "../compiler-core/slang-artifact-desc-util.h" #include "../compiler-core/slang-artifact-util.h" diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 04ebb753c1..58cc55e713 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -16,6 +16,8 @@ #include "slang-check-impl.h" #include "slang-check.h" +#include + // Artifact #include "../compiler-core/slang-artifact-associated.h" #include "../compiler-core/slang-artifact-container-util.h" @@ -1835,6 +1837,26 @@ SlangResult CodeGenContext::_emitEntryPoints(ComPtr& outArtifact) return SLANG_FAIL; } +// Helper class for recording compile time. +struct CompileTimerRAII +{ + std::chrono::high_resolution_clock::time_point startTime; + Session* session; + CompileTimerRAII(Session* inSession) + { + startTime = std::chrono::high_resolution_clock::now(); + session = inSession; + } + ~CompileTimerRAII() + { + double elapsedTime = std::chrono::duration_cast( + std::chrono::high_resolution_clock::now() - startTime) + .count() / + 1e6; + session->addTotalCompileTime(elapsedTime); + } +}; + // Do emit logic for a zero or more entry points SlangResult CodeGenContext::emitEntryPoints(ComPtr& outArtifact) { diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 6175d25ccd..10da324008 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -3757,26 +3757,6 @@ SLANG_FORCE_INLINE SlangSourceLanguage asExternal(SourceLanguage sourceLanguage) return (SlangSourceLanguage)sourceLanguage; } -// Helper class for recording compile time. -struct CompileTimerRAII -{ - std::chrono::high_resolution_clock::time_point startTime; - Session* session; - CompileTimerRAII(Session* inSession) - { - startTime = std::chrono::high_resolution_clock::now(); - session = inSession; - } - ~CompileTimerRAII() - { - double elapsedTime = std::chrono::duration_cast( - std::chrono::high_resolution_clock::now() - startTime) - .count() / - 1e6; - session->addTotalCompileTime(elapsedTime); - } -}; - // helpers for error/warning reporting enum class DiagnosticCategory { diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index db2c0150f7..946e9c429f 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -345,6 +345,20 @@ IRNumThreadsDecoration* CLikeSourceEmitter::getComputeThreadGroupSize( return decor; } +String CLikeSourceEmitter::getTargetBuiltinVarName(IRInst* inst, IRTargetBuiltinVarName builtinName) +{ + switch (builtinName) + { + case IRTargetBuiltinVarName::SpvInstanceIndex: + return "gl_InstanceIndex"; + case IRTargetBuiltinVarName::SpvBaseInstance: + return "gl_BaseInstance"; + } + if (auto linkage = inst->findDecoration()) + return linkage->getMangledName(); + return generateName(inst); +} + List CLikeSourceEmitter::getSortedWitnessTableEntries( IRWitnessTable* witnessTable) { @@ -1208,6 +1222,11 @@ String CLikeSourceEmitter::generateName(IRInst* inst) return externCppDecoration->getName(); } + if (auto builtinTargetVarDecoration = inst->findDecoration()) + { + return getTargetBuiltinVarName(inst, builtinTargetVarDecoration->getBuiltinVarName()); + } + // If we have a name hint on the instruction, then we will try to use that // to provide the basis for the actual name in the output code. if (auto nameHintDecoration = inst->findDecoration()) diff --git a/source/slang/slang-emit-c-like.h b/source/slang/slang-emit-c-like.h index e83b6e5861..6fe7f5d34d 100644 --- a/source/slang/slang-emit-c-like.h +++ b/source/slang/slang-emit-c-like.h @@ -243,7 +243,6 @@ class CLikeSourceEmitter : public SourceEmitterBase Linkage* getLinkage() { return m_codeGenContext->getLinkage(); } ComponentType* getProgram() { return m_codeGenContext->getProgram(); } TargetProgram* getTargetProgram() { return m_codeGenContext->getTargetProgram(); } - // // Types // @@ -519,6 +518,7 @@ class CLikeSourceEmitter : public SourceEmitterBase protected: virtual void emitGlobalParamDefaultVal(IRGlobalParam* inst) { SLANG_UNUSED(inst); } virtual void emitPostDeclarationAttributesForType(IRInst* type) { SLANG_UNUSED(type); } + virtual String getTargetBuiltinVarName(IRInst* inst, IRTargetBuiltinVarName builtinName); virtual bool doesTargetSupportPtrTypes() { return false; } virtual bool isResourceTypeBindless(IRType* type) { diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index 25dab3fb35..776c539b48 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -1791,6 +1791,12 @@ bool GLSLSourceEmitter::tryEmitGlobalParamImpl(IRGlobalParam* varDecl, IRType* v } } + if (varDecl->findDecoration()) + { + // By default, we don't need to emit a definition for target builtin variables. + return true; + } + // Do the default thing return false; } diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index e0367be89d..802df915e6 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -4417,8 +4417,11 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex continue; } } - paramsSet.add(spvGlobalInst); referencedBuiltinIRVars.add(globalInst); + // Don't add duplicate vars to the interface list. + bool paramAdded = paramsSet.add(spvGlobalInst); + if (!paramAdded) + continue; // Don't add a global param to the interface if it is a // specialization constant. @@ -5288,6 +5291,17 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex { IRBuilder builder(m_irModule); builder.setInsertBefore(inst); + if (auto builtinVarDecor = inst->findDecoration()) + { + switch (builtinVarDecor->getBuiltinVarName()) + { + case IRTargetBuiltinVarName::SpvInstanceIndex: + return getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInInstanceIndex, inst); + case IRTargetBuiltinVarName::SpvBaseInstance: + requireSPIRVCapability(SpvCapabilityDrawParameters); + return getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInBaseInstance, inst); + } + } if (auto layout = getVarLayout(inst)) { if (auto systemValueAttr = layout->findAttr()) diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp index 11d5399cf8..1123e1f2ad 100644 --- a/source/slang/slang-ir-glsl-legalize.cpp +++ b/source/slang/slang-ir-glsl-legalize.cpp @@ -236,6 +236,9 @@ struct GLSLSystemValueInfo // The kind of the system value that requires special treatment. GLSLSystemValueKind kind = GLSLSystemValueKind::General; + + // The target builtin name. + IRTargetBuiltinVarName targetVarName = IRTargetBuiltinVarName::Unknown; }; static void leafAddressesImpl(List& ret, const ScalarizedVal& v) @@ -283,6 +286,7 @@ struct GLSLLegalizationContext DiagnosticSink* sink; Stage stage; IRFunc* entryPointFunc; + Dictionary builtinVarMap; /// This dictionary stores all bindings of 'VaryingIn/VaryingOut'. We assume 'space' is 0. Dictionary usedBindingIndex; @@ -414,7 +418,7 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo( char const* outerArrayName = nullptr; int arrayIndex = -1; GLSLSystemValueKind systemValueKind = GLSLSystemValueKind::General; - + IRTargetBuiltinVarName targetVarName = IRTargetBuiltinVarName::Unknown; auto semanticInst = varLayout->findSystemValueSemanticAttr(); if (!semanticInst) return nullptr; @@ -621,6 +625,9 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo( requiredType = builder->getBasicType(BaseType::Int); name = "gl_InstanceIndex"; + targetVarName = IRTargetBuiltinVarName::HlslInstanceID; + context->requireSPIRVVersion(SemanticVersion(1, 3)); + context->requireGLSLExtension(toSlice("GL_ARB_shader_draw_parameters")); } else if (semanticName == "sv_isfrontface") { @@ -869,6 +876,7 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo( name = "gl_BaseInstance"; } + inStorage->targetVarName = targetVarName; if (name) { inStorage->name = name; @@ -976,6 +984,12 @@ void createVarLayoutForLegalizedGlobalParam( default: break; } + + if (systemValueInfo->targetVarName != IRTargetBuiltinVarName::Unknown) + { + builder->addTargetBuiltinVarDecoration(globalParam, systemValueInfo->targetVarName); + context->builtinVarMap[systemValueInfo->targetVarName] = globalParam; + } } } @@ -1261,8 +1275,8 @@ ScalarizedVal createSimpleGLSLGlobalVarying( auto systemSemantic = inVarLayout->findAttr(); // Validate the system value, convert to a regular parameter if this is not a valid system // value for a given target. - if (systemSemantic && isSPIRV(codeGenContext->getTargetFormat()) && - systemSemantic->getName().caseInsensitiveEquals(UnownedStringSlice("sv_instanceid")) && + if (systemSemantic && systemValueInfo && isSPIRV(codeGenContext->getTargetFormat()) && + systemValueInfo->targetVarName == IRTargetBuiltinVarName::HlslInstanceID && ((stage == Stage::Fragment) || (stage == Stage::Vertex && inVarLayout->usesResourceKind(LayoutResourceKind::VaryingOutput)))) @@ -1287,6 +1301,7 @@ ScalarizedVal createSimpleGLSLGlobalVarying( newVarLayout->sourceLoc = inVarLayout->sourceLoc; inVarLayout->replaceUsesWith(newVarLayout); + systemValueInfo->targetVarName = IRTargetBuiltinVarName::Unknown; } } @@ -3746,6 +3761,60 @@ ScalarizedVal legalizeEntryPointReturnValueForGLSL( return result; } +void legalizeTargetBuiltinVar(GLSLLegalizationContext& context) +{ + List> workItems; + for (auto [builtinVarName, varInst] : context.builtinVarMap) + { + if (builtinVarName == IRTargetBuiltinVarName::HlslInstanceID) + { + workItems.add(KeyValuePair(builtinVarName, varInst)); + } + } + + auto getOrCreateBuiltinVar = [&](IRTargetBuiltinVarName name, IRType* type) + { + if (auto var = context.builtinVarMap.tryGetValue(name)) + return *var; + IRBuilder builder(context.entryPointFunc); + builder.setInsertBefore(context.entryPointFunc); + IRInst* var = builder.createGlobalParam(type); + builder.addTargetBuiltinVarDecoration(var, name); + return var; + }; + for (auto& kv : workItems) + { + auto builtinVarName = kv.key; + auto varInst = kv.value; + + // Repalce SV_InstanceID with gl_InstanceIndex - gl_BaseInstance. + if (builtinVarName == IRTargetBuiltinVarName::HlslInstanceID) + { + auto instanceIndex = getOrCreateBuiltinVar( + IRTargetBuiltinVarName::SpvInstanceIndex, + varInst->getDataType()); + auto baseInstance = getOrCreateBuiltinVar( + IRTargetBuiltinVarName::SpvBaseInstance, + varInst->getDataType()); + traverseUses( + varInst, + [&](IRUse* use) + { + auto user = use->getUser(); + if (user->getOp() == kIROp_Load) + { + IRBuilder builder(use->getUser()); + builder.setInsertBefore(use->getUser()); + auto sub = builder.emitSub( + tryGetPointedToType(&builder, varInst->getDataType()), + builder.emitLoad(instanceIndex), + builder.emitLoad(baseInstance)); + user->replaceUsesWith(sub); + } + }); + } + } +} void legalizeEntryPointForGLSL( Session* session, @@ -3937,6 +4006,11 @@ void legalizeEntryPointForGLSL( value.globalParam->setFullType(sizedArrayType); } } + + // Some system value vars can't be mapped 1:1 to a GLSL/Vulkan builtin, + // for example, SV_InstanceID should map to gl_InstanceIndex - gl_BaseInstance, + // we will replace these builtins with additional compute logic here. + legalizeTargetBuiltinVar(context); } void decorateModuleWithSPIRVVersion(IRModule* module, SemanticVersion spirvVersion) diff --git a/source/slang/slang-ir-inst-defs.h b/source/slang/slang-ir-inst-defs.h index 9ffaeeeb9d..3e2872cb7a 100644 --- a/source/slang/slang-ir-inst-defs.h +++ b/source/slang/slang-ir-inst-defs.h @@ -926,6 +926,9 @@ INST_RANGE(BindingQuery, GetRegisterIndex, GetRegisterSpace) INST(ExportDecoration, export, 1, 0) INST_RANGE(LinkageDecoration, ImportDecoration, ExportDecoration) + /// Mark a global variable as a target builtin variable. + INST(TargetBuiltinVarDecoration, TargetBuiltinVar, 1, 0) + /// Marks an inst as coming from an `extern` symbol defined in the user code. INST(UserExternDecoration, UserExtern, 0, 0) diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h index 7c975cfcdf..4efb7d6715 100644 --- a/source/slang/slang-ir-insts.h +++ b/source/slang/slang-ir-insts.h @@ -193,6 +193,14 @@ enum class IRInterpolationMode PerVertex, }; +enum class IRTargetBuiltinVarName +{ + Unknown, + HlslInstanceID, + SpvInstanceIndex, + SpvBaseInstance, +}; + struct IRInterpolationModeDecoration : IRDecoration { enum @@ -705,6 +713,18 @@ struct IRLinkageDecoration : IRDecoration UnownedStringSlice getMangledName() { return getMangledNameOperand()->getStringSlice(); } }; +// Mark a global variable as a target buitlin variable. +struct IRTargetBuiltinVarDecoration : IRDecoration +{ + IR_LEAF_ISA(TargetBuiltinVarDecoration) + + IRIntLit* getBuiltinVarOperand() { return cast(getOperand(0)); } + IRTargetBuiltinVarName getBuiltinVarName() + { + return IRTargetBuiltinVarName(getBuiltinVarOperand()->getValue()); + } +}; + struct IRUserExternDecoration : IRDecoration { enum @@ -4658,6 +4678,18 @@ struct IRBuilder // void addLayoutDecoration(IRInst* value, Layout* layout); IRLayoutDecoration* addLayoutDecoration(IRInst* value, IRLayout* layout); + IRDecoration* addTargetBuiltinVarDecoration( + IRInst* value, + IRTargetBuiltinVarName builtinVarName) + { + IRInst* operands[] = {getIntValue((IRIntegerValue)builtinVarName)}; + return addDecoration( + value, + kIROp_TargetBuiltinVarDecoration, + operands, + SLANG_COUNT_OF(operands)); + } + // IRLayout* getLayout(Layout* astLayout); IRTypeSizeAttr* getTypeSizeAttr(LayoutResourceKind kind, LayoutSize size); diff --git a/source/slang/slang-ir-spirv-legalize.cpp b/source/slang/slang-ir-spirv-legalize.cpp index c672180b70..b19af364e0 100644 --- a/source/slang/slang-ir-spirv-legalize.cpp +++ b/source/slang/slang-ir-spirv-legalize.cpp @@ -422,20 +422,10 @@ struct SPIRVLegalizationContext : public SourceEmitterBase } AddressSpace addressSpace = AddressSpace::ThreadLocal; - // Figure out storage class based on var layout. - if (auto layout = getVarLayout(inst)) - { - auto cls = getGlobalParamAddressSpace(layout); - if (cls != AddressSpace::Generic) - addressSpace = cls; - else if (auto systemValueAttr = layout->findAttr()) - { - String semanticName = systemValueAttr->getName(); - semanticName = semanticName.toLower(); - if (semanticName == "sv_pointsize") - addressSpace = AddressSpace::BuiltinInput; - } - } + // Figure out storage class based on builtin info or var layout. + auto cls = getGlobalParamAddressSpace(inst); + if (cls != AddressSpace::Generic) + addressSpace = cls; // Don't do any processing for specialization constants. if (addressSpace == AddressSpace::SpecializationConstant) @@ -635,8 +625,22 @@ struct SPIRVLegalizationContext : public SourceEmitterBase return addressSpace; } - AddressSpace getGlobalParamAddressSpace(IRVarLayout* varLayout) + AddressSpace getGlobalParamAddressSpace(IRInst* varInst) { + if (auto builtinDecor = varInst->findDecoration()) + { + switch (builtinDecor->getBuiltinVarName()) + { + case IRTargetBuiltinVarName::SpvInstanceIndex: + case IRTargetBuiltinVarName::SpvBaseInstance: + return AddressSpace::BuiltinInput; + } + } + + auto varLayout = getVarLayout(varInst); + if (!varLayout) + return AddressSpace::Generic; + auto typeLayout = varLayout->getTypeLayout()->unwrapArray(); if (auto parameterGroupTypeLayout = as(typeLayout)) { @@ -663,15 +667,25 @@ struct SPIRVLegalizationContext : public SourceEmitterBase "resolve a storage class address space."); } } + auto systemValueAttr = varLayout->findSystemValueSemanticAttr(); + + if (systemValueAttr) + { + // TODO: is this needed? + String semanticName = systemValueAttr->getName(); + semanticName = semanticName.toLower(); + if (semanticName == "sv_pointsize") + result = AddressSpace::BuiltinInput; + } switch (result) { case AddressSpace::Input: - if (varLayout->findSystemValueSemanticAttr()) + if (systemValueAttr) result = AddressSpace::BuiltinInput; break; case AddressSpace::Output: - if (varLayout->findSystemValueSemanticAttr()) + if (systemValueAttr) result = AddressSpace::BuiltinOutput; break; } @@ -781,9 +795,9 @@ struct SPIRVLegalizationContext : public SourceEmitterBase { addressSpace = AddressSpace::GroupShared; } - else if (const auto varLayout = getVarLayout(inst)) + else { - auto cls = getGlobalParamAddressSpace(varLayout); + auto cls = getGlobalParamAddressSpace(inst); if (cls != AddressSpace::Generic) addressSpace = cls; } diff --git a/tests/bugs/gh-3087-multi-entry-point.slang b/tests/bugs/gh-3087-multi-entry-point.slang index d3aa574c7c..edfda08afe 100644 --- a/tests/bugs/gh-3087-multi-entry-point.slang +++ b/tests/bugs/gh-3087-multi-entry-point.slang @@ -3,14 +3,20 @@ // CHECK-DAG: OpEntryPoint Vertex // CHECK-DAG: OpEntryPoint Fragment -// we should only have 1 'BuiltIn InstanceIndex' since the `Output` and `Input` semantic -// for `InstanceIndex` should be converted to a non-builtin -// CHECK-DAG: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex -// CHECK-NOT: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex - // We require 1 `Flat` for the fragment input `uint` // CHECK-DAG: OpDecorate %{{[1-9][0-9]*}} Flat -// CHECK-NOT: OpDecorate %{{[1-9][0-9]*}} Flat + +// CHECK-DAG: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex + +// The vertex shader should be using the builtin InstanceIndex var. +// CHECK: %vmain = OpFunction +// CHECK: InstanceIndex +// CHECK: OpFunctionEnd + +// The fragment shader should not be using the builtin InstanceIndex var. +// CHECK: %pmain = OpFunction +// CHECK-NOT: InstanceIndex +// CHECK: OpFunctionEnd struct VIn { diff --git a/tests/hlsl-intrinsic/system-values-draw-parameters.slang b/tests/hlsl-intrinsic/system-values-draw-parameters.slang index e453669398..009efffa1f 100644 --- a/tests/hlsl-intrinsic/system-values-draw-parameters.slang +++ b/tests/hlsl-intrinsic/system-values-draw-parameters.slang @@ -32,7 +32,7 @@ VSOutput main(VSInput input, // CHECK_HLSL: SV_StartVertexLocation // CHECK_METAL: base_vertex - // CHECK_SPIRV: BuiltIn BaseInstance + // CHECK_SPIRV: BuiltIn InstanceIndex // CHECK_GLSL: gl_BaseInstance // CHECK_HLSL: SV_StartInstanceLocation // CHECK_METAL: base_instance diff --git a/tests/spirv/sv_instance.slang b/tests/spirv/sv_instance.slang new file mode 100644 index 0000000000..e71c6c7faf --- /dev/null +++ b/tests/spirv/sv_instance.slang @@ -0,0 +1,14 @@ +//TEST:SIMPLE(filecheck=GLSL): -target glsl -entry vertMain -stage vertex +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +// CHECK-DAG: %[[REG1:[0-9a-zA-Z_]+]] = OpLoad %int %gl_BaseInstance +// CHECK-DAG: %[[REG2:[0-9a-zA-Z_]+]] = OpLoad %int %gl_InstanceIndex +// CHECK-DAG: OpISub %int %[[REG2]] %[[REG1]] + +// GLSL: gl_InstanceIndex - gl_BaseInstance + +[shader("vertex")] +float4 vertMain(int i : SV_InstanceID) : SV_Position +{ + return i; +} \ No newline at end of file From cd20e94af9f384c03e8be69f6c8ce9e97212cc9b Mon Sep 17 00:00:00 2001 From: Devon Date: Thu, 27 Feb 2025 18:52:14 -0700 Subject: [PATCH 06/31] Add inner texture type to reflection json (#6416) * Add inner texture type to reflection json * Add expected result of test * Adjust test expected results * Fix ci test result --------- Co-authored-by: Yong He --- source/slang/slang-reflection-json.cpp | 4 + .../hlsl-to-vulkan-array.hlsl.expected | 10 +- .../hlsl-to-vulkan-combined.hlsl.expected | 16 +- .../hlsl-to-vulkan-global.hlsl.expected | 10 +- ...lsl-to-vulkan-shift-implicit.hlsl.expected | 20 +- .../hlsl-to-vulkan-shift.hlsl.expected | 20 +- .../cpp-resource-reflection.slang.64.expected | 6 +- .../sampler-feedback-basic.slang.expected | 12 +- tests/reflection/arrays.hlsl.expected | 30 ++- tests/reflection/binding-gl.hlsl.expected | 30 ++- .../binding-push-constant-gl.hlsl.expected | 30 ++- tests/reflection/cross-compile.slang.expected | 10 +- tests/reflection/default-space.slang.expected | 30 ++- .../explicit-register-space.slang.expected | 10 +- .../global-type-params.slang.expected | 10 +- tests/reflection/multi-file.hlsl.expected | 50 +++- ...ameter-block-explicit-space.slang.expected | 60 ++++- .../parameter-block.slang.1.expected | 30 ++- .../parameter-block.slang.2.expected | 30 ++- .../reflection/parameter-block.slang.expected | 30 ++- .../reflect-imported-code.hlsl.expected | 20 +- tests/reflection/reflection0.hlsl.expected | 10 +- .../resource-in-cbuffer.hlsl.expected | 20 +- .../reflection/shared-modifier.hlsl.expected | 10 +- tests/reflection/texture-resource-type.slang | 21 ++ .../texture-resource-type.slang.expected | 220 ++++++++++++++++++ .../unbounded-arrays.hlsl.1.expected | 60 ++++- .../reflection/used-parameters.slang.expected | 40 +++- 28 files changed, 787 insertions(+), 62 deletions(-) create mode 100644 tests/reflection/texture-resource-type.slang create mode 100644 tests/reflection/texture-resource-type.slang.expected diff --git a/source/slang/slang-reflection-json.cpp b/source/slang/slang-reflection-json.cpp index 993832ad61..4e8b6b2a47 100644 --- a/source/slang/slang-reflection-json.cpp +++ b/source/slang/slang-reflection-json.cpp @@ -514,6 +514,10 @@ static void emitReflectionTypeInfoJSON(PrettyWriter& writer, slang::TypeReflecti break; case SLANG_STRUCTURED_BUFFER: + case SLANG_TEXTURE_1D: + case SLANG_TEXTURE_2D: + case SLANG_TEXTURE_3D: + case SLANG_TEXTURE_CUBE: if (auto resultType = type->getResourceResultType()) { writer.maybeComma(); diff --git a/tests/bindings/hlsl-to-vulkan-array.hlsl.expected b/tests/bindings/hlsl-to-vulkan-array.hlsl.expected index c5d71a65fd..b8deb13142 100644 --- a/tests/bindings/hlsl-to-vulkan-array.hlsl.expected +++ b/tests/bindings/hlsl-to-vulkan-array.hlsl.expected @@ -22,7 +22,15 @@ standard output = { "name": "tex", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} }, diff --git a/tests/bindings/hlsl-to-vulkan-combined.hlsl.expected b/tests/bindings/hlsl-to-vulkan-combined.hlsl.expected index 1194d50b4c..32c99bd784 100644 --- a/tests/bindings/hlsl-to-vulkan-combined.hlsl.expected +++ b/tests/bindings/hlsl-to-vulkan-combined.hlsl.expected @@ -9,7 +9,11 @@ standard output = { "binding": {"kind": "descriptorTableSlot", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "scalar", + "scalarType": "float32" + } } }, { @@ -17,7 +21,15 @@ standard output = { "binding": {"kind": "descriptorTableSlot", "index": 1}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } } ], diff --git a/tests/bindings/hlsl-to-vulkan-global.hlsl.expected b/tests/bindings/hlsl-to-vulkan-global.hlsl.expected index 7fe1f8e422..8d3a19458f 100644 --- a/tests/bindings/hlsl-to-vulkan-global.hlsl.expected +++ b/tests/bindings/hlsl-to-vulkan-global.hlsl.expected @@ -25,7 +25,15 @@ standard output = { "binding": {"kind": "descriptorTableSlot", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { diff --git a/tests/bindings/hlsl-to-vulkan-shift-implicit.hlsl.expected b/tests/bindings/hlsl-to-vulkan-shift-implicit.hlsl.expected index a873b4149b..85d13552a9 100644 --- a/tests/bindings/hlsl-to-vulkan-shift-implicit.hlsl.expected +++ b/tests/bindings/hlsl-to-vulkan-shift-implicit.hlsl.expected @@ -9,7 +9,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 10}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -81,7 +89,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 11}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { diff --git a/tests/bindings/hlsl-to-vulkan-shift.hlsl.expected b/tests/bindings/hlsl-to-vulkan-shift.hlsl.expected index 23e2b1bdae..fd54b96922 100644 --- a/tests/bindings/hlsl-to-vulkan-shift.hlsl.expected +++ b/tests/bindings/hlsl-to-vulkan-shift.hlsl.expected @@ -9,7 +9,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 5}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -81,7 +89,15 @@ standard output = { "binding": {"kind": "shaderResource", "space": 2, "index": 7}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { diff --git a/tests/cross-compile/cpp-resource-reflection.slang.64.expected b/tests/cross-compile/cpp-resource-reflection.slang.64.expected index b863827e98..4ded43e3ee 100644 --- a/tests/cross-compile/cpp-resource-reflection.slang.64.expected +++ b/tests/cross-compile/cpp-resource-reflection.slang.64.expected @@ -95,7 +95,11 @@ standard output = { "binding": {"kind": "uniform", "offset": 24, "size": 8}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "scalar", + "scalarType": "float32" + } } }, { diff --git a/tests/hlsl-intrinsic/sampler-feedback/sampler-feedback-basic.slang.expected b/tests/hlsl-intrinsic/sampler-feedback/sampler-feedback-basic.slang.expected index 2464028180..fe6eb13353 100644 --- a/tests/hlsl-intrinsic/sampler-feedback/sampler-feedback-basic.slang.expected +++ b/tests/hlsl-intrinsic/sampler-feedback/sampler-feedback-basic.slang.expected @@ -67,7 +67,11 @@ standard output = { "binding": {"kind": "shaderResource", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "scalar", + "scalarType": "float32" + } } }, { @@ -76,7 +80,11 @@ standard output = { "type": { "kind": "resource", "baseShape": "texture2D", - "array": true + "array": true, + "resultType": { + "kind": "scalar", + "scalarType": "float32" + } } }, { diff --git a/tests/reflection/arrays.hlsl.expected b/tests/reflection/arrays.hlsl.expected index f53d63723c..3e0bd6723e 100644 --- a/tests/reflection/arrays.hlsl.expected +++ b/tests/reflection/arrays.hlsl.expected @@ -90,7 +90,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -101,7 +109,15 @@ standard output = { "elementCount": 16, "elementType": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } } }, @@ -110,7 +126,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 17}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { diff --git a/tests/reflection/binding-gl.hlsl.expected b/tests/reflection/binding-gl.hlsl.expected index 73c4da3aef..67df7c2679 100644 --- a/tests/reflection/binding-gl.hlsl.expected +++ b/tests/reflection/binding-gl.hlsl.expected @@ -90,7 +90,15 @@ standard output = { "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 1}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -98,7 +106,15 @@ standard output = { "binding": {"kind": "descriptorTableSlot", "space": 3, "index": 2}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -106,7 +122,15 @@ standard output = { "binding": {"kind": "descriptorTableSlot", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { diff --git a/tests/reflection/binding-push-constant-gl.hlsl.expected b/tests/reflection/binding-push-constant-gl.hlsl.expected index 6570625e99..7321c5face 100644 --- a/tests/reflection/binding-push-constant-gl.hlsl.expected +++ b/tests/reflection/binding-push-constant-gl.hlsl.expected @@ -147,7 +147,15 @@ standard output = { "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 1}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -155,7 +163,15 @@ standard output = { "binding": {"kind": "descriptorTableSlot", "space": 3, "index": 2}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -163,7 +179,15 @@ standard output = { "binding": {"kind": "descriptorTableSlot", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { diff --git a/tests/reflection/cross-compile.slang.expected b/tests/reflection/cross-compile.slang.expected index f85e4e0e9a..2cd77fee22 100644 --- a/tests/reflection/cross-compile.slang.expected +++ b/tests/reflection/cross-compile.slang.expected @@ -9,7 +9,15 @@ standard output = { "binding": {"kind": "descriptorTableSlot", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { diff --git a/tests/reflection/default-space.slang.expected b/tests/reflection/default-space.slang.expected index c6ec6c19ff..17cc327363 100644 --- a/tests/reflection/default-space.slang.expected +++ b/tests/reflection/default-space.slang.expected @@ -9,7 +9,15 @@ standard output = { "binding": {"kind": "shaderResource", "space": 99, "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -25,7 +33,15 @@ standard output = { "name": "b", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} } @@ -43,7 +59,15 @@ standard output = { "name": "b", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} } diff --git a/tests/reflection/explicit-register-space.slang.expected b/tests/reflection/explicit-register-space.slang.expected index 725318084b..a43efd2bd9 100644 --- a/tests/reflection/explicit-register-space.slang.expected +++ b/tests/reflection/explicit-register-space.slang.expected @@ -9,7 +9,15 @@ standard output = { "binding": {"kind": "shaderResource", "space": 2, "index": 1}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } } ], diff --git a/tests/reflection/global-type-params.slang.expected b/tests/reflection/global-type-params.slang.expected index 0da9c975e2..07180b7ea7 100644 --- a/tests/reflection/global-type-params.slang.expected +++ b/tests/reflection/global-type-params.slang.expected @@ -71,7 +71,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { diff --git a/tests/reflection/multi-file.hlsl.expected b/tests/reflection/multi-file.hlsl.expected index 0472a0b0ae..804e5874ff 100644 --- a/tests/reflection/multi-file.hlsl.expected +++ b/tests/reflection/multi-file.hlsl.expected @@ -9,7 +9,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -135,7 +143,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 1}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -261,7 +277,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 2}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -387,7 +411,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 3}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -395,7 +427,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 4}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } } ], diff --git a/tests/reflection/parameter-block-explicit-space.slang.expected b/tests/reflection/parameter-block-explicit-space.slang.expected index 9080298399..347f0fd5cf 100644 --- a/tests/reflection/parameter-block-explicit-space.slang.expected +++ b/tests/reflection/parameter-block-explicit-space.slang.expected @@ -29,7 +29,15 @@ standard output = { "name": "at1", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} }, @@ -37,7 +45,15 @@ standard output = { "name": "at2", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 1} }, @@ -77,7 +93,15 @@ standard output = { "name": "at1", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} }, @@ -85,7 +109,15 @@ standard output = { "name": "at2", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 1} }, @@ -131,7 +163,15 @@ standard output = { "name": "bt", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} }, @@ -171,7 +211,15 @@ standard output = { "name": "bt", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} }, diff --git a/tests/reflection/parameter-block.slang.1.expected b/tests/reflection/parameter-block.slang.1.expected index 5b1b456243..59fe157873 100644 --- a/tests/reflection/parameter-block.slang.1.expected +++ b/tests/reflection/parameter-block.slang.1.expected @@ -20,7 +20,15 @@ standard output = { "name": "t", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} }, @@ -45,7 +53,15 @@ standard output = { "name": "t", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} }, @@ -70,7 +86,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 1}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } } ], diff --git a/tests/reflection/parameter-block.slang.2.expected b/tests/reflection/parameter-block.slang.2.expected index 31477df38c..ef7b21e1a3 100644 --- a/tests/reflection/parameter-block.slang.2.expected +++ b/tests/reflection/parameter-block.slang.2.expected @@ -17,7 +17,15 @@ standard output = { "name": "t", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} }, @@ -42,7 +50,15 @@ standard output = { "name": "t", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} }, @@ -67,7 +83,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } } ], diff --git a/tests/reflection/parameter-block.slang.expected b/tests/reflection/parameter-block.slang.expected index 48b1bccbdd..f3c31d4a95 100644 --- a/tests/reflection/parameter-block.slang.expected +++ b/tests/reflection/parameter-block.slang.expected @@ -17,7 +17,15 @@ standard output = { "name": "t", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "descriptorTableSlot", "index": 0} }, @@ -42,7 +50,15 @@ standard output = { "name": "t", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "descriptorTableSlot", "index": 0} }, @@ -64,7 +80,15 @@ standard output = { "binding": {"kind": "descriptorTableSlot", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } } ], diff --git a/tests/reflection/reflect-imported-code.hlsl.expected b/tests/reflection/reflect-imported-code.hlsl.expected index cff6c50bbe..8a906d0f7a 100644 --- a/tests/reflection/reflect-imported-code.hlsl.expected +++ b/tests/reflection/reflect-imported-code.hlsl.expected @@ -9,7 +9,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -63,7 +71,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 1}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { diff --git a/tests/reflection/reflection0.hlsl.expected b/tests/reflection/reflection0.hlsl.expected index 10f228cb18..f435aa8290 100644 --- a/tests/reflection/reflection0.hlsl.expected +++ b/tests/reflection/reflection0.hlsl.expected @@ -9,7 +9,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { diff --git a/tests/reflection/resource-in-cbuffer.hlsl.expected b/tests/reflection/resource-in-cbuffer.hlsl.expected index 7d4251684e..f85a5fb59f 100644 --- a/tests/reflection/resource-in-cbuffer.hlsl.expected +++ b/tests/reflection/resource-in-cbuffer.hlsl.expected @@ -32,7 +32,15 @@ standard output = { "name": "myTexture", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} }, @@ -76,7 +84,15 @@ standard output = { "name": "myTexture", "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} }, diff --git a/tests/reflection/shared-modifier.hlsl.expected b/tests/reflection/shared-modifier.hlsl.expected index 61774ed197..252c764d26 100644 --- a/tests/reflection/shared-modifier.hlsl.expected +++ b/tests/reflection/shared-modifier.hlsl.expected @@ -9,7 +9,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { diff --git a/tests/reflection/texture-resource-type.slang b/tests/reflection/texture-resource-type.slang new file mode 100644 index 0000000000..2455ba611f --- /dev/null +++ b/tests/reflection/texture-resource-type.slang @@ -0,0 +1,21 @@ +// texture-resource-type.slang + +// Tests reflection of inner texture type. + +//TEST:REFLECTION:-stage compute -entry main -target hlsl + +Texture2D NoParameters; +Texture2D FloatTexture; +Texture2D FloatTwoTexture; +Texture2D FloatFourTexture; +Texture2D IntTexture; +Texture2D IntTwoTexture; +Texture2D IntFourTexture; +Texture2D UintTexture; +Texture2D UintTwoTexture; +Texture2D UintFourTexture; + +[numthreads(1, 1, 1)] +void main(uint3 dispatchThreadID : SV_DispatchThreadID) +{ +} diff --git a/tests/reflection/texture-resource-type.slang.expected b/tests/reflection/texture-resource-type.slang.expected new file mode 100644 index 0000000000..48d1f0f797 --- /dev/null +++ b/tests/reflection/texture-resource-type.slang.expected @@ -0,0 +1,220 @@ +result code = 0 +standard error = { +} +standard output = { +{ + "parameters": [ + { + "name": "NoParameters", + "binding": {"kind": "shaderResource", "index": 0}, + "type": { + "kind": "resource", + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } + } + }, + { + "name": "FloatTexture", + "binding": {"kind": "shaderResource", "index": 1}, + "type": { + "kind": "resource", + "baseShape": "texture2D", + "resultType": { + "kind": "scalar", + "scalarType": "float32" + } + } + }, + { + "name": "FloatTwoTexture", + "binding": {"kind": "shaderResource", "index": 2}, + "type": { + "kind": "resource", + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 2, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } + } + }, + { + "name": "FloatFourTexture", + "binding": {"kind": "shaderResource", "index": 3}, + "type": { + "kind": "resource", + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } + } + }, + { + "name": "IntTexture", + "binding": {"kind": "shaderResource", "index": 4}, + "type": { + "kind": "resource", + "baseShape": "texture2D", + "resultType": { + "kind": "scalar", + "scalarType": "int32" + } + } + }, + { + "name": "IntTwoTexture", + "binding": {"kind": "shaderResource", "index": 5}, + "type": { + "kind": "resource", + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 2, + "elementType": { + "kind": "scalar", + "scalarType": "int32" + } + } + } + }, + { + "name": "IntFourTexture", + "binding": {"kind": "shaderResource", "index": 6}, + "type": { + "kind": "resource", + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "int32" + } + } + } + }, + { + "name": "UintTexture", + "binding": {"kind": "shaderResource", "index": 7}, + "type": { + "kind": "resource", + "baseShape": "texture2D", + "resultType": { + "kind": "scalar", + "scalarType": "uint32" + } + } + }, + { + "name": "UintTwoTexture", + "binding": {"kind": "shaderResource", "index": 8}, + "type": { + "kind": "resource", + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 2, + "elementType": { + "kind": "scalar", + "scalarType": "uint32" + } + } + } + }, + { + "name": "UintFourTexture", + "binding": {"kind": "shaderResource", "index": 9}, + "type": { + "kind": "resource", + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "uint32" + } + } + } + } + ], + "entryPoints": [ + { + "name": "main", + "stage": "compute", + "parameters": [ + { + "name": "dispatchThreadID", + "semanticName": "SV_DISPATCHTHREADID", + "type": { + "kind": "vector", + "elementCount": 3, + "elementType": { + "kind": "scalar", + "scalarType": "uint32" + } + } + } + ], + "threadGroupSize": [1, 1, 1], + "bindings": [ + { + "name": "NoParameters", + "binding": {"kind": "shaderResource", "index": 0, "used": 0} + }, + { + "name": "FloatTexture", + "binding": {"kind": "shaderResource", "index": 1, "used": 0} + }, + { + "name": "FloatTwoTexture", + "binding": {"kind": "shaderResource", "index": 2, "used": 0} + }, + { + "name": "FloatFourTexture", + "binding": {"kind": "shaderResource", "index": 3, "used": 0} + }, + { + "name": "IntTexture", + "binding": {"kind": "shaderResource", "index": 4, "used": 0} + }, + { + "name": "IntTwoTexture", + "binding": {"kind": "shaderResource", "index": 5, "used": 0} + }, + { + "name": "IntFourTexture", + "binding": {"kind": "shaderResource", "index": 6, "used": 0} + }, + { + "name": "UintTexture", + "binding": {"kind": "shaderResource", "index": 7, "used": 0} + }, + { + "name": "UintTwoTexture", + "binding": {"kind": "shaderResource", "index": 8, "used": 0} + }, + { + "name": "UintFourTexture", + "binding": {"kind": "shaderResource", "index": 9, "used": 0} + } + ] + } + ] +} +} diff --git a/tests/reflection/unbounded-arrays.hlsl.1.expected b/tests/reflection/unbounded-arrays.hlsl.1.expected index c8d8f6bed5..e4eb111ffb 100644 --- a/tests/reflection/unbounded-arrays.hlsl.1.expected +++ b/tests/reflection/unbounded-arrays.hlsl.1.expected @@ -23,7 +23,15 @@ standard output = { "elementCount": 0, "elementType": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } } }, @@ -32,7 +40,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -40,7 +56,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 1}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -51,7 +75,15 @@ standard output = { "elementCount": 0, "elementType": { "kind": "resource", - "baseShape": "textureCube" + "baseShape": "textureCube", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } } }, @@ -60,7 +92,15 @@ standard output = { "binding": {"kind": "shaderResource", "space": 1, "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -77,7 +117,15 @@ standard output = { "name": "t", "type": { "kind": "resource", - "baseShape": "texture3D" + "baseShape": "texture3D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } }, "binding": {"kind": "shaderResource", "index": 0} }, diff --git a/tests/reflection/used-parameters.slang.expected b/tests/reflection/used-parameters.slang.expected index fb63e55f90..0a4fba1049 100644 --- a/tests/reflection/used-parameters.slang.expected +++ b/tests/reflection/used-parameters.slang.expected @@ -107,7 +107,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 0}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -115,7 +123,15 @@ standard output = { "binding": {"kind": "shaderResource", "index": 1}, "type": { "kind": "resource", - "baseShape": "texture2D" + "baseShape": "texture2D", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -164,7 +180,15 @@ standard output = { "type": { "kind": "resource", "baseShape": "texture2D", - "access": "readWrite" + "access": "readWrite", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { @@ -173,7 +197,15 @@ standard output = { "type": { "kind": "resource", "baseShape": "texture2D", - "access": "readWrite" + "access": "readWrite", + "resultType": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } } }, { From 38734ec1f6644f1565aeb91106f371b14d3ba07a Mon Sep 17 00:00:00 2001 From: Simon Kallweit <64953474+skallweitNV@users.noreply.github.com> Date: Fri, 28 Feb 2025 02:54:22 +0100 Subject: [PATCH 07/31] update slang-rhi (shader object refactor) (#6251) * remove unused resource * define buffer data * add vs2022 build presets * update slang-rhi API usage * update slang-rhi --------- Co-authored-by: Yong He --- CMakePresets.json | 15 ++++++ external/slang-rhi | 2 +- tests/bugs/ray-query-in-generic.slang | 2 - .../compute/byte-address-buffer-aligned.slang | 1 + tests/compute/byte-address-buffer-array.slang | 1 + tools/render-test/options.cpp | 4 +- tools/render-test/options.h | 2 +- tools/render-test/render-test-main.cpp | 53 +++++++------------ tools/slang-test/slang-test-main.cpp | 2 +- 9 files changed, 42 insertions(+), 40 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 3f8c92a51a..c893948577 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -104,6 +104,21 @@ "configurePreset": "default", "configuration": "RelWithDebInfo" }, + { + "name": "vs2022-debug", + "configurePreset": "vs2022", + "configuration": "Debug" + }, + { + "name": "vs2022-release", + "configurePreset": "vs2022", + "configuration": "Release" + }, + { + "name": "vs2022-releaseWithDebugInfo", + "configurePreset": "vs2022", + "configuration": "RelWithDebInfo" + }, { "name": "emscripten", "configurePreset": "emscripten", diff --git a/external/slang-rhi b/external/slang-rhi index e3393c5067..6b6cc8f951 160000 --- a/external/slang-rhi +++ b/external/slang-rhi @@ -1 +1 @@ -Subproject commit e3393c5067e49e327e6d56ced5509428fcda5d18 +Subproject commit 6b6cc8f9513732c2f8627eeefce7ea7e1a95415d diff --git a/tests/bugs/ray-query-in-generic.slang b/tests/bugs/ray-query-in-generic.slang index 62cbf11b66..c416f2780f 100644 --- a/tests/bugs/ray-query-in-generic.slang +++ b/tests/bugs/ray-query-in-generic.slang @@ -36,8 +36,6 @@ struct Ray float3 eval(float t) { return origin + t * dir; } }; -RaytracingAccelerationStructure sceneBVH; - uint getCommittedStatus(RayQuery q) { return q.CommittedStatus(); diff --git a/tests/compute/byte-address-buffer-aligned.slang b/tests/compute/byte-address-buffer-aligned.slang index f959ec66dd..0e848b75c2 100644 --- a/tests/compute/byte-address-buffer-aligned.slang +++ b/tests/compute/byte-address-buffer-aligned.slang @@ -9,6 +9,7 @@ // Confirm compilation of `(RW)ByteAddressBuffer` with aligned load / stores to wider data types. +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=buffer0 [vk::binding(2, 3)] RWByteAddressBuffer buffer0; [shader("compute")] diff --git a/tests/compute/byte-address-buffer-array.slang b/tests/compute/byte-address-buffer-array.slang index 4ac4a612a1..77cfb07d2d 100644 --- a/tests/compute/byte-address-buffer-array.slang +++ b/tests/compute/byte-address-buffer-array.slang @@ -9,6 +9,7 @@ // Confirm compilation of `(RW)ByteAddressBuffer` with aligned load / stores to wider data types. +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=buffer [vk::binding(2, 3)] RWByteAddressBuffer buffer; struct Block { float4 val[2]; diff --git a/tools/render-test/options.cpp b/tools/render-test/options.cpp index e0b38bf317..ed6c6a3c66 100644 --- a/tools/render-test/options.cpp +++ b/tools/render-test/options.cpp @@ -249,9 +249,9 @@ static rhi::DeviceType _toRenderType(Slang::RenderApiType apiType) { SLANG_RETURN_ON_FAIL(reader.expectArg(outOptions.entryPointName)); } - else if (argValue == "-enable-backend-validation") + else if (argValue == "-enable-debug-layers") { - outOptions.enableBackendValidation = true; + outOptions.enableDebugLayers = true; } else if (argValue == "-dx12-experimental") { diff --git a/tools/render-test/options.h b/tools/render-test/options.h index f041c3e84e..d94504c10c 100644 --- a/tools/render-test/options.h +++ b/tools/render-test/options.h @@ -87,7 +87,7 @@ struct Options bool generateSPIRVDirectly = true; - bool enableBackendValidation = false; + bool enableDebugLayers = false; bool dx12Experimental = false; diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp index c9f367c30a..f6a303d623 100644 --- a/tools/render-test/render-test-main.cpp +++ b/tools/render-test/render-test-main.cpp @@ -355,7 +355,7 @@ struct AssignValsFromLayoutContext if (field.name.getLength() == 0) { // If no name was given, assume by-indexing matching is requested - auto fieldCursor = dstCursor.getElement((GfxIndex)fieldIndex); + auto fieldCursor = dstCursor.getElement((uint32_t)fieldIndex); if (!fieldCursor.isValid()) { StdWriters::getError().print( @@ -638,7 +638,7 @@ SlangResult RenderTestApp::initialize( SLANG_RETURN_ON_FAIL( device->createBuffer(vertexBufferDesc, kVertexData, m_vertexBuffer.writeRef())); - ColorTargetState colorTarget; + ColorTargetDesc colorTarget; colorTarget.format = Format::R8G8B8A8_UNORM; RenderPipelineDesc desc; desc.program = m_shaderProgram; @@ -653,7 +653,7 @@ SlangResult RenderTestApp::initialize( case Options::ShaderProgramType::GraphicsMeshCompute: case Options::ShaderProgramType::GraphicsTaskMeshCompute: { - ColorTargetState colorTarget; + ColorTargetDesc colorTarget; colorTarget.format = Format::R8G8B8A8_UNORM; RenderPipelineDesc desc; desc.program = m_shaderProgram; @@ -986,15 +986,10 @@ Result RenderTestApp::update() auto encoder = m_queue->createCommandEncoder(); if (m_options.shaderType == Options::ShaderProgramType::Compute) { - auto rootObject = m_device->createRootShaderObject(m_pipeline); - applyBinding(rootObject); - rootObject->finalize(); - auto passEncoder = encoder->beginComputePass(); - ComputeState state; - state.pipeline = static_cast(m_pipeline.get()); - state.rootObject = rootObject; - passEncoder->setComputeState(state); + auto rootObject = + passEncoder->bindPipeline(static_cast(m_pipeline.get())); + applyBinding(rootObject); passEncoder->dispatchCompute( m_options.computeDispatchSize[0], m_options.computeDispatchSize[1], @@ -1003,16 +998,11 @@ Result RenderTestApp::update() } else if (m_options.shaderType == Options::ShaderProgramType::RayTracing) { - auto rootObject = m_device->createRootShaderObject(m_pipeline); - applyBinding(rootObject); - rootObject->finalize(); - auto passEncoder = encoder->beginRayTracingPass(); - RayTracingState state; - state.pipeline = static_cast(m_pipeline.get()); - state.rootObject = rootObject; - state.shaderTable = m_shaderTable; - passEncoder->setRayTracingState(state); + auto rootObject = passEncoder->bindPipeline( + static_cast(m_pipeline.get()), + m_shaderTable); + applyBinding(rootObject); passEncoder->dispatchRays( 0, m_options.computeDispatchSize[0], @@ -1022,11 +1012,6 @@ Result RenderTestApp::update() } else { - auto rootObject = m_device->createRootShaderObject(m_pipeline); - applyBinding(rootObject); - setProjectionMatrix(rootObject); - rootObject->finalize(); - RenderPassColorAttachment colorAttachment = {}; colorAttachment.view = m_colorBufferView; colorAttachment.loadOp = LoadOp::Clear; @@ -1041,13 +1026,15 @@ Result RenderTestApp::update() renderPass.depthStencilAttachment = &depthStencilAttachment; auto passEncoder = encoder->beginRenderPass(renderPass); + auto rootObject = + passEncoder->bindPipeline(static_cast(m_pipeline.get())); + applyBinding(rootObject); + setProjectionMatrix(rootObject); RenderState state; - state.pipeline = static_cast(m_pipeline.get()); - state.rootObject = rootObject; - state.viewports[0] = Viewport((float)gWindowWidth, (float)gWindowHeight); + state.viewports[0] = Viewport::fromSize(gWindowWidth, gWindowHeight); state.viewportCount = 1; - state.scissorRects[0] = ScissorRect(gWindowWidth, gWindowHeight); + state.scissorRects[0] = ScissorRect::fromSize(gWindowWidth, gWindowHeight); state.scissorRectCount = 1; if (m_options.shaderType == Options::ShaderProgramType::GraphicsMeshCompute || @@ -1413,9 +1400,6 @@ static SlangResult _innerMain( desc.debugCallback = &debugCallback; #endif - if (options.enableBackendValidation) - desc.enableBackendValidation = true; - desc.slang.lineDirectiveMode = SLANG_LINE_DIRECTIVE_MODE_NONE; if (options.generateSPIRVDirectly) desc.slang.targetFlags = SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY; @@ -1460,7 +1444,10 @@ static SlangResult _innerMain( desc.slang.slangGlobalSession = session; desc.slang.targetProfile = options.profileName.getBuffer(); { - getRHI()->enableDebugLayers(); + if (options.enableDebugLayers) + { + getRHI()->enableDebugLayers(); + } SlangResult res = getRHI()->createDevice(desc, device.writeRef()); if (SLANG_FAILED(res)) { diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 57328c210f..b8fb45c47a 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -3528,7 +3528,7 @@ TestResult runComputeComparisonImpl( // This is due to the limitation that Slang RPC implementation expects only // one time communication. if (input.spawnType != SpawnType::UseTestServer) - cmdLine.addArg("-enable-backend-validation"); + cmdLine.addArg("-enable-debug-layers"); #endif if (context->isExecuting()) From 96f19629d4cfbe282af010cee704409a6fb2f59c Mon Sep 17 00:00:00 2001 From: Mukund Keshava Date: Fri, 28 Feb 2025 07:26:42 +0530 Subject: [PATCH 08/31] Remove adapter option from slang-test (#6475) Fixes #6390 This commit removes the deprecated -adapter command-line option from slang-test. This change aligns with commit 015bde8d5a46f32979c00dbb1feb4b3d80729c44, which previously removed the adapter option from render-test and implemented the more AdapterLUID mechanism. Co-authored-by: Ellie Hermaszewska Co-authored-by: Yong He --- tools/slang-test/options.cpp | 9 --------- tools/slang-test/options.h | 3 --- tools/slang-test/slang-test-main.cpp | 7 +------ 3 files changed, 1 insertion(+), 18 deletions(-) diff --git a/tools/slang-test/options.cpp b/tools/slang-test/options.cpp index b3f4bdc104..45533fe492 100644 --- a/tools/slang-test/options.cpp +++ b/tools/slang-test/options.cpp @@ -190,15 +190,6 @@ static bool _isSubCommand(const char* arg) argCursor++; // Assumed to be handle by .bat file that called us } - else if (strcmp(arg, "-adapter") == 0) - { - if (argCursor == argEnd) - { - stdError.print("error: expected operand for '%s'\n", arg); - return SLANG_FAIL; - } - optionsOut->adapter = *argCursor++; - } else if (strcmp(arg, "-server-count") == 0) { if (argCursor == argEnd) diff --git a/tools/slang-test/options.h b/tools/slang-test/options.h index a127d1050d..3939590f06 100644 --- a/tools/slang-test/options.h +++ b/tools/slang-test/options.h @@ -112,9 +112,6 @@ struct Options Slang::RenderApiFlags synthesizedTestApis = Slang::RenderApiFlag::AllOf & ~(Slang::RenderApiFlag::Vulkan | Slang::RenderApiFlag::CPU); - // The adapter to use. If empty will match first found adapter. - Slang::String adapter; - // If true, print detailed adapter information bool showAdapterInfo = false; diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index b8fb45c47a..51dcf79ceb 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -159,7 +159,7 @@ typedef TestResult (*TestCallback)(TestContext* context, TestInput& input); // Globals // Pre declare -static void _addRenderTestOptions(const Options& options, CommandLine& cmdLine); +static void _addRenderTestOptions(const Options& options, CommandLine& ioCmdLine); /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!! Functions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ @@ -3305,11 +3305,6 @@ TestResult runGLSLComparisonTest(TestContext* context, TestInput& input) static void _addRenderTestOptions(const Options& options, CommandLine& ioCmdLine) { - if (options.adapter.getLength()) - { - ioCmdLine.addArg("-adapter"); - ioCmdLine.addArg(options.adapter); - } if (!options.emitSPIRVDirectly) { ioCmdLine.addArg("-emit-spirv-via-glsl"); From 4d415f6af2266cc38798d72f6816c60b91a5003c Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Fri, 28 Feb 2025 03:58:07 +0200 Subject: [PATCH 09/31] Fix a bug where Session::parseCommandLineArguments returns invalid data (#6461) This helps to address issue #4760. Co-authored-by: Yong He --- source/slang/slang.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 001354162b..cd8cabfe5e 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1108,17 +1108,19 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Session::parseCommandLineArguments( if (outDesc->structureSize < sizeof(slang::SessionDesc)) return SLANG_E_BUFFER_TOO_SMALL; RefPtr outData = new ParsedCommandLineData(); - SerializedOptionsData optionData; RefPtr tempReq = new EndToEndCompileRequest(this); tempReq->processCommandLineArguments(argv, argc); + outData->options.setCount(1 + tempReq->getLinkage()->targets.getCount()); + int optionDataIndex = 0; + SerializedOptionsData& optionData = outData->options[optionDataIndex]; + optionDataIndex++; tempReq->getOptionSet().serialize(&optionData); - outData->options.add(optionData); for (auto target : tempReq->getLinkage()->targets) { slang::TargetDesc tdesc; - SerializedOptionsData targetOptionData; + SerializedOptionsData& targetOptionData = outData->options[optionDataIndex]; + optionDataIndex++; tempReq->getTargetOptionSet(target).serialize(&targetOptionData); - outData->options.add(targetOptionData); tdesc.compilerOptionEntryCount = (uint32_t)targetOptionData.entries.getCount(); tdesc.compilerOptionEntries = targetOptionData.entries.getBuffer(); outData->targets.add(tdesc); From 9fd3e7c150ed9723c153948312a226345f3b8633 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 27 Feb 2025 21:06:15 -0800 Subject: [PATCH 10/31] Fix CI settings. (#6491) * fix ci. * fix. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- .github/workflows/ci.yml | 17 +++++++++++++---- .github/workflows/release.yml | 8 +++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4fc7be6772..66d33bc087 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,6 +47,8 @@ jobs: - { config: release, test-category: full } # default not full gpu tests - full-gpu-tests: false + - build-llvm: true + - { platform: wasm, build-llvm: false } # The runners don't have a GPU by default except for the self-hosted ones - has-gpu: false # Self-hosted aarch64 build @@ -56,8 +58,9 @@ jobs: platform: aarch64 test-category: smoke full-gpu-tests: false - runs-on: [self-hosted, Linux, ARM64] - has-gpu: true + runs-on: ubuntu-22.04-arm + has-gpu: false + build-llvm: false # Self-hosted full gpu build - os: windows config: release @@ -110,7 +113,7 @@ jobs: compiler: ${{matrix.compiler}} platform: ${{matrix.platform}} config: ${{matrix.config}} - build-llvm: ${{ matrix.platform != 'wasm' }} + build-llvm: ${{ matrix.build-llvm }} - name: Build Slang if: steps.filter.outputs.should-run == 'true' run: | @@ -140,6 +143,12 @@ jobs: "-DSLANG_SLANG_LLVM_BINARY_URL=$(pwd)/build/dist-release/slang-llvm.zip" \ "-DCMAKE_COMPILE_WARNING_AS_ERROR=${{matrix.warnings-as-errors}}" cmake --workflow --preset "${{matrix.config}}" + elif [[ "${{ matrix.build-llvm }}" = "false" ]]; then + # linux aarch64 cannot build llvm. + cmake --preset default --fresh \ + -DSLANG_SLANG_LLVM_FLAVOR=DISABLE \ + -DCMAKE_COMPILE_WARNING_AS_ERROR=${{matrix.warnings-as-errors}} + cmake --workflow --preset "${{matrix.config}}" else # Otherwise, use the "system" llvm we have just build or got from the # cache in the setup phase @@ -150,7 +159,7 @@ jobs: fi fi - name: Test Slang - if: steps.filter.outputs.should-run == 'true' && matrix.platform != 'wasm' + if: steps.filter.outputs.should-run == 'true' && matrix.platform != 'wasm' && matrix.platform != 'aarch64' run: | export SLANG_RUN_SPIRV_VALIDATION=1 export SLANG_USE_SPV_SOURCE_LANGUAGE_UNKNOWN=1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e6e9a5a8da..637ca32110 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,7 +24,13 @@ jobs: platform: [x86_64, aarch64] test-category: [smoke] include: - - { os: linux, runs-on: ubuntu-20.04, compiler: gcc } + - { os: linux, platform:x86_64, runs-on: ubuntu-22.04, compiler: gcc } + - { + os: linux, + platform:aarch64, + runs-on: ubuntu-22.04-arm, + compiler: gcc, + } - { os: windows, runs-on: windows-latest, compiler: cl } - { os: macos, runs-on: macos-latest, compiler: clang } From 42a8c4b1bcb50fda45b199236b27aaa28dd1d758 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 27 Feb 2025 21:20:13 -0800 Subject: [PATCH 11/31] Fix release CI. (#6492) * Fix release CI. * fix. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- .github/workflows/release.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 637ca32110..f715bcaf84 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,10 +24,15 @@ jobs: platform: [x86_64, aarch64] test-category: [smoke] include: - - { os: linux, platform:x86_64, runs-on: ubuntu-22.04, compiler: gcc } - { os: linux, - platform:aarch64, + platform: x86_64, + runs-on: ubuntu-22.04, + compiler: gcc, + } + - { + os: linux, + platform: aarch64, runs-on: ubuntu-22.04-arm, compiler: gcc, } From 5d0e3e932a03f2b491e7592a17affc6b973a6a64 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 27 Feb 2025 21:35:45 -0800 Subject: [PATCH 12/31] Fix doc build. (#6493) --- docs/_layouts/deprecated.html | 226 +++++++++++++++++++++++++++++++ docs/deprecated/a1-02-slangpy.md | 3 +- 2 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 docs/_layouts/deprecated.html diff --git a/docs/_layouts/deprecated.html b/docs/_layouts/deprecated.html new file mode 100644 index 0000000000..41bcaf87ff --- /dev/null +++ b/docs/_layouts/deprecated.html @@ -0,0 +1,226 @@ + + + + + + + + + + + + + + {% seo %} + + + +
+ +
+
+ {% include anchor_headings.html html=content anchorBody="" %} +
+ +
+ {% if site.github.is_project_page %} + {{ site.title | default: site.github.repository_name }} is maintained by {{ site.github.owner_name }}
+ {% endif %} + This page was generated by GitHub Pages. +
+
+
+ + + + + \ No newline at end of file diff --git a/docs/deprecated/a1-02-slangpy.md b/docs/deprecated/a1-02-slangpy.md index f3dd24a924..1862f4674a 100644 --- a/docs/deprecated/a1-02-slangpy.md +++ b/docs/deprecated/a1-02-slangpy.md @@ -1,7 +1,6 @@ --- layout: user-guide -permalink: "docs/user-guide -/a1-02-slangpy" +permalink: "docs/user-guide/a1-02-slangpy" --- Using Slang to Write PyTorch Kernels From 8a8ff3cf3b10f5719503c9163592e3b0820b8d3d Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 27 Feb 2025 21:38:48 -0800 Subject: [PATCH 13/31] Fix doc. (#6494) --- docs/deprecated/a1-02-slangpy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/deprecated/a1-02-slangpy.md b/docs/deprecated/a1-02-slangpy.md index 1862f4674a..a2d169dee3 100644 --- a/docs/deprecated/a1-02-slangpy.md +++ b/docs/deprecated/a1-02-slangpy.md @@ -1,5 +1,5 @@ --- -layout: user-guide +layout: deprecated permalink: "docs/user-guide/a1-02-slangpy" --- From 930b6018db472e33005be3d2cac526ed493cf38b Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 27 Feb 2025 21:41:03 -0800 Subject: [PATCH 14/31] Fix doc. (#6495) --- docs/_layouts/deprecated.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_layouts/deprecated.html b/docs/_layouts/deprecated.html index 41bcaf87ff..922f0d0a2e 100644 --- a/docs/_layouts/deprecated.html +++ b/docs/_layouts/deprecated.html @@ -181,7 +181,7 @@