From 91ac1555d7838961c3b5c41d5af39c7a881f59eb Mon Sep 17 00:00:00 2001 From: "YONGH\\yongh" Date: Mon, 30 Oct 2017 19:40:13 -0400 Subject: Fixing issue #236 --- tools/slang-test/main.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/slang-test/main.cpp b/tools/slang-test/main.cpp index 5b4337d12..0ff6535b8 100644 --- a/tools/slang-test/main.cpp +++ b/tools/slang-test/main.cpp @@ -1134,7 +1134,11 @@ TestResult runComputeComparisonImpl(TestInput& input, const char * langOption, S spawner.pushArgument(langOption); spawner.pushArgument("-o"); - spawner.pushArgument(outputStem + ".actual.txt"); + auto actualOutputFile = outputStem + ".actual.txt"; + spawner.pushArgument(actualOutputFile); + + // clear the stale actual output file first. This will allow us to detect error if render-test fails and outputs nothing. + File::WriteAllText(actualOutputFile, ""); if (spawnAndWait(outputStem, spawner) != kOSError_None) { @@ -1145,7 +1149,7 @@ TestResult runComputeComparisonImpl(TestInput& input, const char * langOption, S auto actualOutput = getOutput(spawner); // check against reference output - if (!File::Exists(outputStem + ".actual.txt")) + if (!File::Exists(actualOutputFile)) { printf("render-test not producing expected outputs.\n"); printf("render-test output:\n%s\n", actualOutput.Buffer()); @@ -1156,7 +1160,7 @@ TestResult runComputeComparisonImpl(TestInput& input, const char * langOption, S printf("referenceOutput %s not found.\n", referenceOutput.Buffer()); return kTestResult_Fail; } - auto actualOutputContent = File::ReadAllText(outputStem + ".actual.txt"); + auto actualOutputContent = File::ReadAllText(actualOutputFile); auto actualProgramOutput = Split(actualOutputContent, '\n'); auto referenceProgramOutput = Split(File::ReadAllText(referenceOutput), '\n'); auto printOutput = [&]() -- cgit v1.2.3 From 84f381cc180b3176d6a58da4085ee8470f246922 Mon Sep 17 00:00:00 2001 From: "YONGH\\yongh" Date: Mon, 30 Oct 2017 21:18:20 -0400 Subject: work in-progress, add parsing for assoc type decls and member type expressions --- source/slang/decl-defs.h | 5 +++++ source/slang/parser.cpp | 38 +++++++++++++++++++++++++++++++++--- source/slang/syntax.cpp | 27 +++++++++++++++++++++++++ source/slang/type-defs.h | 23 ++++++++++++++++++++++ tests/compute/assoctype-simple.slang | 34 ++++++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 tests/compute/assoctype-simple.slang diff --git a/source/slang/decl-defs.h b/source/slang/decl-defs.h index c96fe6d09..4021f5a38 100644 --- a/source/slang/decl-defs.h +++ b/source/slang/decl-defs.h @@ -122,6 +122,11 @@ SYNTAX_CLASS(TypeDefDecl, SimpleTypeDecl) SYNTAX_FIELD(TypeExp, type) END_SYNTAX_CLASS() +// An 'assoctype' declaration +SYNTAX_CLASS(AssocTypeDecl, SimpleTypeDecl) + SYNTAX_FIELD(TypeExp, constraint) +END_SYNTAX_CLASS() + // A scope for local declarations (e.g., as part of a statement) SIMPLE_SYNTAX_CLASS(ScopeDecl, ContainerDecl) diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index 322f403e6..554eebc18 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -544,6 +544,21 @@ namespace Slang return typeDefDecl; } + RefPtr ParseAssocType(Parser * parser, void *) + { + RefPtr assocTypeDecl = new AssocTypeDecl(); + + auto nameToken = parser->ReadToken(TokenType::Identifier); + assocTypeDecl->nameAndLoc = NameLoc(nameToken); + assocTypeDecl->loc = nameToken.loc; + if (parser->LookAheadToken(TokenType::Colon)) + { + auto type = parser->ParseTypeExp(); + assocTypeDecl->constraint = type; + } + return assocTypeDecl; + } + // Add a modifier to a list of modifiers being built static void AddModifier(RefPtr** ioModifierLink, RefPtr modifier) { @@ -1396,6 +1411,16 @@ namespace Slang return genericApp; } + static RefPtr parseMemberType(Parser * parser, RefPtr base) + { + RefPtr memberExpr = new MemberExpr(); + parser->ReadToken(TokenType::Dot); + parser->FillPosition(memberExpr.Ptr()); + memberExpr->BaseExpression = base; + memberExpr->name = expectIdentifier(parser).name; + return memberExpr; + } + // Parse option `[]` braces after a type expression, that indicate an array type static RefPtr parsePostfixTypeSuffix( Parser* parser, @@ -1452,9 +1477,16 @@ namespace Slang RefPtr typeExpr = basicType; - if (parser->LookAheadToken(TokenType::OpLess)) + while (parser->LookAheadToken(TokenType::OpLess) || parser->LookAheadToken(TokenType::Dot)) { - typeExpr = parseGenericApp(parser, typeExpr); + if (parser->LookAheadToken(TokenType::OpLess)) + { + typeExpr = parseGenericApp(parser, typeExpr); + } + else + { + typeExpr = parseMemberType(parser, typeExpr); + } } // GLSL allows `[]` directly in a type specifier @@ -4029,8 +4061,8 @@ namespace Slang // Add syntax for declaration keywords #define DECL(KEYWORD, CALLBACK) \ addBuiltinSyntax(session, scope, #KEYWORD, &CALLBACK) - DECL(typedef, ParseTypeDef); + DECL(assoctype, ParseAssocType); DECL(cbuffer, parseHLSLCBufferDecl); DECL(tbuffer, parseHLSLTBufferDecl); DECL(__generic, ParseGenericDecl); diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index 6cf3fd7c9..165b2d132 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -940,6 +940,33 @@ void Type::accept(IValVisitor* visitor, void* extra) return this; } + // AssocTypeDeclRefType + + String AssocTypeDeclRefType::ToString() + { + // TODO: what is appropriate here? + return ""; + } + + bool AssocTypeDeclRefType::EqualsImpl(Type * type) + { + if (auto assocTypeDeclRefType = type->As()) + { + return declRef.Equals(assocTypeDeclRefType->declRef); + } + return false; + } + + int AssocTypeDeclRefType::GetHashCode() + { + return declRef.GetHashCode(); + } + + Type* AssocTypeDeclRefType::CreateCanonicalType() + { + return this; + } + // ArithmeticExpressionType // VectorExpressionType diff --git a/source/slang/type-defs.h b/source/slang/type-defs.h index 2010d07b4..7648e0b87 100644 --- a/source/slang/type-defs.h +++ b/source/slang/type-defs.h @@ -491,3 +491,26 @@ protected: virtual Type* CreateCanonicalType() override; ) END_SYNTAX_CLASS() + +// The "type" of an expression that references a asscoiated type decl (via 'assoctype' keyword). +SYNTAX_CLASS(AssocTypeDeclRefType, Type) + DECL_FIELD(DeclRef, declRef) + RAW( + AssocTypeDeclRefType() + {} + AssocTypeDeclRefType( + DeclRef declRef) + : declRef(declRef) + {} + + + DeclRef const& GetDeclRef() const { return declRef; } + + virtual String ToString() override; + + protected: + virtual bool EqualsImpl(Type * type) override; + virtual int GetHashCode() override; + virtual Type* CreateCanonicalType() override; + ) +END_SYNTAX_CLASS() \ No newline at end of file diff --git a/tests/compute/assoctype-simple.slang b/tests/compute/assoctype-simple.slang new file mode 100644 index 000000000..5a2c339a6 --- /dev/null +++ b/tests/compute/assoctype-simple.slang @@ -0,0 +1,34 @@ +//TEST(smoke,compute):COMPARE_COMPUTE:-xslang -use-ir +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out +// Confirm that generics syntax can be used in user +// code and generates valid output. + +RWStructuredBuffer outputBuffer; + +interface ISimple +{ + assoctype T; + T add(T v0, T v1); +} + +struct Simple : ISimple +{ + typedef float T; + T add(T v0, float v1) + { + return v0 + v1; + } +}; + +__generic +T.T test(T simple, T.T v0, T.T v1) +{ + return simple.add(v0, v1); +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + float outVal = test(Simple(), 2.0, 1.0); // == 3.0 + outputBuffer[tid] = outVal; +} \ No newline at end of file -- cgit v1.2.3 From 436c906a36fc7ff4f767d303cb5824995cd117d8 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 31 Oct 2017 04:26:06 -0400 Subject: Revert "work in-progress, add parsing for assoc type decls and member type expressions" This reverts commit 84f381cc180b3176d6a58da4085ee8470f246922. --- source/slang/decl-defs.h | 5 ----- source/slang/parser.cpp | 38 +++--------------------------------- source/slang/syntax.cpp | 27 ------------------------- source/slang/type-defs.h | 23 ---------------------- tests/compute/assoctype-simple.slang | 34 -------------------------------- 5 files changed, 3 insertions(+), 124 deletions(-) delete mode 100644 tests/compute/assoctype-simple.slang diff --git a/source/slang/decl-defs.h b/source/slang/decl-defs.h index 4021f5a38..c96fe6d09 100644 --- a/source/slang/decl-defs.h +++ b/source/slang/decl-defs.h @@ -122,11 +122,6 @@ SYNTAX_CLASS(TypeDefDecl, SimpleTypeDecl) SYNTAX_FIELD(TypeExp, type) END_SYNTAX_CLASS() -// An 'assoctype' declaration -SYNTAX_CLASS(AssocTypeDecl, SimpleTypeDecl) - SYNTAX_FIELD(TypeExp, constraint) -END_SYNTAX_CLASS() - // A scope for local declarations (e.g., as part of a statement) SIMPLE_SYNTAX_CLASS(ScopeDecl, ContainerDecl) diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index 554eebc18..322f403e6 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -544,21 +544,6 @@ namespace Slang return typeDefDecl; } - RefPtr ParseAssocType(Parser * parser, void *) - { - RefPtr assocTypeDecl = new AssocTypeDecl(); - - auto nameToken = parser->ReadToken(TokenType::Identifier); - assocTypeDecl->nameAndLoc = NameLoc(nameToken); - assocTypeDecl->loc = nameToken.loc; - if (parser->LookAheadToken(TokenType::Colon)) - { - auto type = parser->ParseTypeExp(); - assocTypeDecl->constraint = type; - } - return assocTypeDecl; - } - // Add a modifier to a list of modifiers being built static void AddModifier(RefPtr** ioModifierLink, RefPtr modifier) { @@ -1411,16 +1396,6 @@ namespace Slang return genericApp; } - static RefPtr parseMemberType(Parser * parser, RefPtr base) - { - RefPtr memberExpr = new MemberExpr(); - parser->ReadToken(TokenType::Dot); - parser->FillPosition(memberExpr.Ptr()); - memberExpr->BaseExpression = base; - memberExpr->name = expectIdentifier(parser).name; - return memberExpr; - } - // Parse option `[]` braces after a type expression, that indicate an array type static RefPtr parsePostfixTypeSuffix( Parser* parser, @@ -1477,16 +1452,9 @@ namespace Slang RefPtr typeExpr = basicType; - while (parser->LookAheadToken(TokenType::OpLess) || parser->LookAheadToken(TokenType::Dot)) + if (parser->LookAheadToken(TokenType::OpLess)) { - if (parser->LookAheadToken(TokenType::OpLess)) - { - typeExpr = parseGenericApp(parser, typeExpr); - } - else - { - typeExpr = parseMemberType(parser, typeExpr); - } + typeExpr = parseGenericApp(parser, typeExpr); } // GLSL allows `[]` directly in a type specifier @@ -4061,8 +4029,8 @@ namespace Slang // Add syntax for declaration keywords #define DECL(KEYWORD, CALLBACK) \ addBuiltinSyntax(session, scope, #KEYWORD, &CALLBACK) + DECL(typedef, ParseTypeDef); - DECL(assoctype, ParseAssocType); DECL(cbuffer, parseHLSLCBufferDecl); DECL(tbuffer, parseHLSLTBufferDecl); DECL(__generic, ParseGenericDecl); diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index 165b2d132..6cf3fd7c9 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -940,33 +940,6 @@ void Type::accept(IValVisitor* visitor, void* extra) return this; } - // AssocTypeDeclRefType - - String AssocTypeDeclRefType::ToString() - { - // TODO: what is appropriate here? - return ""; - } - - bool AssocTypeDeclRefType::EqualsImpl(Type * type) - { - if (auto assocTypeDeclRefType = type->As()) - { - return declRef.Equals(assocTypeDeclRefType->declRef); - } - return false; - } - - int AssocTypeDeclRefType::GetHashCode() - { - return declRef.GetHashCode(); - } - - Type* AssocTypeDeclRefType::CreateCanonicalType() - { - return this; - } - // ArithmeticExpressionType // VectorExpressionType diff --git a/source/slang/type-defs.h b/source/slang/type-defs.h index 7648e0b87..2010d07b4 100644 --- a/source/slang/type-defs.h +++ b/source/slang/type-defs.h @@ -491,26 +491,3 @@ protected: virtual Type* CreateCanonicalType() override; ) END_SYNTAX_CLASS() - -// The "type" of an expression that references a asscoiated type decl (via 'assoctype' keyword). -SYNTAX_CLASS(AssocTypeDeclRefType, Type) - DECL_FIELD(DeclRef, declRef) - RAW( - AssocTypeDeclRefType() - {} - AssocTypeDeclRefType( - DeclRef declRef) - : declRef(declRef) - {} - - - DeclRef const& GetDeclRef() const { return declRef; } - - virtual String ToString() override; - - protected: - virtual bool EqualsImpl(Type * type) override; - virtual int GetHashCode() override; - virtual Type* CreateCanonicalType() override; - ) -END_SYNTAX_CLASS() \ No newline at end of file diff --git a/tests/compute/assoctype-simple.slang b/tests/compute/assoctype-simple.slang deleted file mode 100644 index 5a2c339a6..000000000 --- a/tests/compute/assoctype-simple.slang +++ /dev/null @@ -1,34 +0,0 @@ -//TEST(smoke,compute):COMPARE_COMPUTE:-xslang -use-ir -//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out -// Confirm that generics syntax can be used in user -// code and generates valid output. - -RWStructuredBuffer outputBuffer; - -interface ISimple -{ - assoctype T; - T add(T v0, T v1); -} - -struct Simple : ISimple -{ - typedef float T; - T add(T v0, float v1) - { - return v0 + v1; - } -}; - -__generic -T.T test(T simple, T.T v0, T.T v1) -{ - return simple.add(v0, v1); -} - -[numthreads(4, 1, 1)] -void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) -{ - float outVal = test(Simple(), 2.0, 1.0); // == 3.0 - outputBuffer[tid] = outVal; -} \ No newline at end of file -- cgit v1.2.3 From 8ba5d28be28fff7ac3a99a0046cac9fd9897d16e Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 31 Oct 2017 05:56:28 -0400 Subject: initiate rebuild --- tools/render-test/render-gl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/render-test/render-gl.cpp b/tools/render-test/render-gl.cpp index 9563ced96..a853a53a4 100644 --- a/tools/render-test/render-gl.cpp +++ b/tools/render-test/render-gl.cpp @@ -609,7 +609,7 @@ public: } return shaderID; - } + } virtual void dispatchCompute(int x, int y, int z) override { -- cgit v1.2.3