summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-10-23 10:44:08 -0400
committerYong He <yonghe@outlook.com>2017-10-23 10:44:08 -0400
commit4d6be3588ac5b5b62e19900b12de90ce1e1ff744 (patch)
tree43fb004d9283849c670dfd869d75b8f621036b9e
parentcc6184ebc4d0611be892eaff119de99f8b9e1ca6 (diff)
parent624d122a3a110922cd54aab7bbf13f1cac8fbbff (diff)
Merge https://github.com/shader-slang/slang
-rw-r--r--.gitignore1
-rw-r--r--source/slang/emit.cpp31
-rw-r--r--source/slang/ir.cpp25
-rw-r--r--source/slang/slang.cpp1
-rw-r--r--tests/compute/generics-simple.slang26
-rw-r--r--tests/compute/generics-simple.slang.expected.txt4
-rw-r--r--tools/slang-test/main.cpp56
7 files changed, 126 insertions, 18 deletions
diff --git a/.gitignore b/.gitignore
index 26a5f0506..0be132a45 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,6 +18,7 @@ intermediate/
*.expected
*.expected.png
*.actual.png
+*.actual.txt
# Files generated by other shader compilers
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index da9489a75..f76ab1db1 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -5091,6 +5091,37 @@ emitDeclImpl(decl, nullptr);
EmitContext* context,
IRValue* inst)
{
+ // Don't emit semantics if we aren't translating down to HLSL
+ switch (context->shared->target)
+ {
+ case CodeGenTarget::HLSL:
+ break;
+
+ default:
+ return;
+ }
+
+ if(auto layoutDecoration = inst->findDecoration<IRLayoutDecoration>())
+ {
+ if(auto varLayout = layoutDecoration->layout.As<VarLayout>())
+ {
+ if(varLayout->flags & VarLayoutFlag::HasSemantic)
+ {
+ Emit(" : ");
+ emit(varLayout->semanticName);
+ if(varLayout->semanticIndex)
+ {
+ Emit(varLayout->semanticIndex);
+ }
+
+ return;
+ }
+ }
+ }
+
+ // TODO(tfoley): should we ever need to use the high-level declaration
+ // for this? It seems like the wrong approach...
+
auto decoration = inst->findDecoration<IRHighLevelDeclDecoration>();
if( decoration )
{
diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp
index 4bf9de5d3..14639de7e 100644
--- a/source/slang/ir.cpp
+++ b/source/slang/ir.cpp
@@ -3094,6 +3094,31 @@ namespace Slang
clonedFunc,
entryPointLayout);
+ // We will also go on and attach layout information
+ // to the function parameters, so that we have it
+ // available directly on the parameters, rather
+ // than having to look it up on the original entry-point layout.
+ if( auto firstBlock = clonedFunc->getFirstBlock() )
+ {
+ UInt paramLayoutCount = entryPointLayout->fields.Count();
+ UInt paramCounter = 0;
+ for( auto pp = firstBlock->getFirstParam(); pp; pp = pp->getNextParam() )
+ {
+ UInt paramIndex = paramCounter++;
+ if( paramIndex < paramLayoutCount )
+ {
+ auto paramLayout = entryPointLayout->fields[paramIndex];
+ context->builder->addLayoutDecoration(
+ pp,
+ paramLayout);
+ }
+ else
+ {
+ SLANG_UNEXPECTED("too many parameters");
+ }
+ }
+ }
+
return clonedFunc;
}
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index dff322c29..da7601d41 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -918,6 +918,7 @@ SLANG_API int spCompile(
catch (...)
{
req->mSink.diagnose(Slang::SourceLoc(), Slang::Diagnostics::compilationAborted);
+ req->mDiagnosticOutput = req->mSink.outputBuffer.ProduceString();
return 1;
}
#else
diff --git a/tests/compute/generics-simple.slang b/tests/compute/generics-simple.slang
new file mode 100644
index 000000000..0002e444b
--- /dev/null
+++ b/tests/compute/generics-simple.slang
@@ -0,0 +1,26 @@
+//TEST(smoke,compute):COMPARE_COMPUTE:-xslang -use-ir
+
+// Confirm that generics syntax can be used in user
+// code and generates valid output.
+
+RWStructuredBuffer<float> outputBuffer;
+
+
+__generic<T>
+T test(T val)
+{
+ return val;
+}
+
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+
+ float inVal = float(tid);
+
+ float outVal = test<float>(inVal);
+
+ outputBuffer[tid] = outVal;
+} \ No newline at end of file
diff --git a/tests/compute/generics-simple.slang.expected.txt b/tests/compute/generics-simple.slang.expected.txt
new file mode 100644
index 000000000..fdaa30664
--- /dev/null
+++ b/tests/compute/generics-simple.slang.expected.txt
@@ -0,0 +1,4 @@
+0.0
+1.0
+2.0
+3.0 \ No newline at end of file
diff --git a/tools/slang-test/main.cpp b/tools/slang-test/main.cpp
index 272c1b618..676cb6875 100644
--- a/tools/slang-test/main.cpp
+++ b/tools/slang-test/main.cpp
@@ -752,6 +752,28 @@ TestResult runReflectionTest(TestInput& input)
return result;
}
+String getExpectedOutput(String const& outputStem)
+{
+ String expectedOutputPath = outputStem + ".expected";
+ String expectedOutput;
+ try
+ {
+ expectedOutput = Slang::File::ReadAllText(expectedOutputPath);
+ }
+ catch (Slang::IOException)
+ {
+ }
+
+ // If no expected output file was found, then we
+ // expect everything to be empty
+ if (expectedOutput.Length() == 0)
+ {
+ expectedOutput = "result code = 0\nstandard error = {\n}\nstandard output = {\n}\n";
+ }
+
+ return expectedOutput;
+}
+
TestResult runEvalTest(TestInput& input)
{
// We are going to load and evaluate the code
@@ -775,23 +797,7 @@ TestResult runEvalTest(TestInput& input)
}
String actualOutput = getOutput(spawner);
-
- String expectedOutputPath = outputStem + ".expected";
- String expectedOutput;
- try
- {
- expectedOutput = Slang::File::ReadAllText(expectedOutputPath);
- }
- catch (Slang::IOException)
- {
- }
-
- // If no expected output file was found, then we
- // expect everything to be empty
- if (expectedOutput.Length() == 0)
- {
- expectedOutput = "result code = 0\nstandard error = {\n}\nstandard output = {\n}\n";
- }
+ String expectedOutput = getExpectedOutput(outputStem);
TestResult result = kTestResult_Pass;
@@ -1135,6 +1141,19 @@ TestResult doComputeComparisonTestRunImpl(TestInput& input, const char * langOpt
return kTestResult_Fail;
}
+ auto actualOutput = getOutput(spawner);
+ auto expectedOutput = getExpectedOutput(outputStem);
+ if(actualOutput != expectedOutput)
+ {
+ String actualOutputPath = outputStem + ".actual";
+ Slang::File::WriteAllText(actualOutputPath, actualOutput);
+
+ maybeDumpOutput(expectedOutput, actualOutput);
+
+ return kTestResult_Fail;
+ }
+
+
// check against reference output
if (!File::Exists(outputStem + ".actual.txt"))
return kTestResult_Fail;
@@ -1358,14 +1377,15 @@ TestResult runTest(
{ "COMPARE_HLSL_RENDER", &runHLSLRenderComparisonTest },
{ "COMPARE_HLSL_CROSS_COMPILE_RENDER", &runHLSLCrossCompileRenderComparisonTest},
{ "COMPARE_HLSL_GLSL_RENDER", &runHLSLAndGLSLComparisonTest },
+ { "COMPARE_COMPUTE", &doSlangComputeComparisonTest},
#else
{ "COMPARE_HLSL", &skipTest },
{ "COMPARE_HLSL_RENDER", &skipTest },
{ "COMPARE_HLSL_CROSS_COMPILE_RENDER", &skipTest},
{ "COMPARE_HLSL_GLSL_RENDER", &skipTest },
+ { "COMPARE_COMPUTE", &skipTest},
#endif
{ "COMPARE_GLSL", &runGLSLComparisonTest },
- { "COMPARE_COMPUTE", &doSlangComputeComparisonTest},
{ "CROSS_COMPILE", &runCrossCompilerTest },
{ "EVAL", &runEvalTest },