diff options
| -rw-r--r-- | tests/compute/textureSamplingTest.slang | 103 | ||||
| -rw-r--r-- | tests/compute/textureSamplingTest.slang.expected.txt | 1 | ||||
| -rw-r--r-- | tools/render-test/main.cpp | 20 | ||||
| -rw-r--r-- | tools/render-test/options.cpp | 4 | ||||
| -rw-r--r-- | tools/render-test/options.h | 3 | ||||
| -rw-r--r-- | tools/render-test/render-d3d11.cpp | 18 | ||||
| -rw-r--r-- | tools/render-test/render-gl.cpp | 10 | ||||
| -rw-r--r-- | tools/render-test/render.h | 1 | ||||
| -rw-r--r-- | tools/render-test/shader-input-layout.cpp | 14 | ||||
| -rw-r--r-- | tools/render-test/shader-input-layout.h | 4 | ||||
| -rw-r--r-- | tools/slang-test/main.cpp | 7 |
11 files changed, 157 insertions, 28 deletions
diff --git a/tests/compute/textureSamplingTest.slang b/tests/compute/textureSamplingTest.slang new file mode 100644 index 000000000..c715ec89e --- /dev/null +++ b/tests/compute/textureSamplingTest.slang @@ -0,0 +1,103 @@ +//TEST(smoke,compute):COMPARE_RENDER_COMPUTE: +//TEST_INPUT: Texture1D(size=4, content = one) : dxbinding(0),glbinding(0) +//TEST_INPUT: Texture2D(size=4, content = one) : dxbinding(1),glbinding(1) +//TEST_INPUT: Texture3D(size=4, content = one) : dxbinding(2),glbinding(2) +//TEST_INPUT: TextureCube(size=4, content = one) : dxbinding(3),glbinding(3) +//TEST_INPUT: Texture1D(size=4, content = one, arrayLength=2) : dxbinding(4),glbinding(4) +//TEST_INPUT: Texture2D(size=4, content = one, arrayLength=2) : dxbinding(5),glbinding(5) +//TEST_INPUT: TextureCube(size=4, content = one, arrayLength=2) : dxbinding(6),glbinding(6) +//TEST_INPUT: Sampler : dxbinding(0),glbinding(0,1,2,3,4,5,6) +//TEST_INPUT: ubuffer(data=[0], stride=4):dxbinding(1),glbinding(0),out + + +Texture1D t1D; +Texture2D t2D; +Texture3D t3D; +TextureCube tCube; +Texture1DArray t1dArray; +Texture2DArray t2dArray; +TextureCubeArray tCubeArray; +SamplerState samplerState; +RWStructuredBuffer<float> outputBuffer; + +cbuffer Uniforms +{ + float4x4 modelViewProjection; +} + +struct AssembledVertex +{ + float3 position; + float3 color; + float2 uv; +}; + +struct CoarseVertex +{ + float3 color; + float2 uv; +}; + +struct Fragment +{ + float4 color; +}; + + +// Vertex Shader + +struct VertexStageInput +{ + AssembledVertex assembledVertex : A; +}; + +struct VertexStageOutput +{ + CoarseVertex coarseVertex : CoarseVertex; + float4 sv_position : SV_Position; +}; + +VertexStageOutput vertexMain(VertexStageInput input) +{ + VertexStageOutput output; + + float3 position = input.assembledVertex.position; + float3 color = input.assembledVertex.color; + + output.coarseVertex.color = color; + output.sv_position = mul(modelViewProjection, float4(position, 1.0)); + output.coarseVertex.uv = input.assembledVertex.uv; + return output; +} + +// Fragment Shader + +struct FragmentStageInput +{ + CoarseVertex coarseVertex : CoarseVertex; +}; + +struct FragmentStageOutput +{ + Fragment fragment : SV_Target; +}; + +FragmentStageOutput fragmentMain(FragmentStageInput input) +{ + FragmentStageOutput output; + + float3 color = input.coarseVertex.color; + float2 uv = input.coarseVertex.uv; + output.fragment.color = float4(color, 1.0); + + float4 val = 0.0; + val += t1D.Sample(samplerState, uv.x); + val += t2D.Sample(samplerState, uv); + val += t3D.Sample (samplerState, float3(uv, 0.5)); + val += t1dArray.Sample(samplerState, float2(uv.x, 0.0)); + val += t2dArray.Sample(samplerState, float3(uv, 0.0)); + val += tCubeArray.Sample(samplerState, float4(uv, 0.5, 0.0)); + val += tCube.Sample(samplerState, float3(uv, 0.5)); + outputBuffer[0] = val.x; + return output; +}
\ No newline at end of file diff --git a/tests/compute/textureSamplingTest.slang.expected.txt b/tests/compute/textureSamplingTest.slang.expected.txt new file mode 100644 index 000000000..acf037f69 --- /dev/null +++ b/tests/compute/textureSamplingTest.slang.expected.txt @@ -0,0 +1 @@ +40E00000
\ No newline at end of file diff --git a/tools/render-test/main.cpp b/tools/render-test/main.cpp index d3247e55f..cb0eb927d 100644 --- a/tools/render-test/main.cpp +++ b/tools/render-test/main.cpp @@ -37,13 +37,14 @@ struct Vertex { float position[3]; float color[3]; + float uv[2]; }; static const int kVertexCount = 3; static const Vertex kVertexData[kVertexCount] = { - { { 0, 0, 0.5 }, {1, 0, 0} }, - { { 0, 1, 0.5 }, {0, 0, 1} }, - { { 1, 0, 0.5 }, {0, 1, 0} }, + { { 0, 0, 0.5 }, {1, 0, 0} , {0, 0} }, + { { 0, 1, 0.5 }, {0, 0, 1} , {1, 0} }, + { { 1, 0, 0.5 }, {0, 1, 0} , {1, 1} }, }; @@ -65,9 +66,9 @@ static char const* computeEntryPointName = "computeMain"; // "Profile" to use when compiling for HLSL targets // TODO: does this belong here? -static char const* vertexProfileName = "vs_4_0"; -static char const* fragmentProfileName = "ps_4_0"; -static char const* computeProfileName = "cs_4_0"; +static char const* vertexProfileName = "vs_5_0"; +static char const* fragmentProfileName = "ps_5_0"; +static char const* computeProfileName = "cs_5_0"; Error initializeShaders( ShaderCompiler* shaderCompiler) @@ -101,7 +102,7 @@ Error initializeShaders( ShaderCompileRequest compileRequest; compileRequest.source = sourceInfo; - if (gOptions.shaderType == ShaderProgramType::Graphics) + if (gOptions.shaderType == ShaderProgramType::Graphics || gOptions.shaderType == ShaderProgramType::GraphicsCompute) { compileRequest.vertexShader.source = sourceInfo; compileRequest.vertexShader.name = vertexEntryPointName; @@ -157,9 +158,10 @@ Error initializeInner( InputElementDesc inputElements[] = { { "A", 0, Format::RGB_Float32, offsetof(Vertex, position) }, { "A", 1, Format::RGB_Float32, offsetof(Vertex, color) }, + { "A", 2, Format::RG_Float32, offsetof(Vertex, uv) }, }; - gInputLayout = renderer->createInputLayout(&inputElements[0], 2); + gInputLayout = renderer->createInputLayout(&inputElements[0], sizeof(inputElements)/sizeof(inputElements[0])); if(!gInputLayout) return Error::Unexpected; @@ -409,7 +411,7 @@ int main( // If we are in a mode where output is requested, we need to snapshot the back buffer here if (gOptions.outputPath) { - if (gOptions.shaderType == ShaderProgramType::Compute) + if (gOptions.shaderType == ShaderProgramType::Compute || gOptions.shaderType == ShaderProgramType::GraphicsCompute) renderer->serializeOutput(gBindingState, gOptions.outputPath); else renderer->captureScreenShot(gOptions.outputPath); diff --git a/tools/render-test/options.cpp b/tools/render-test/options.cpp index 89a68b27f..629016155 100644 --- a/tools/render-test/options.cpp +++ b/tools/render-test/options.cpp @@ -100,6 +100,10 @@ void parseOptions(int* argc, char** argv) { gOptions.shaderType = ShaderProgramType::Graphics; } + else if (strcmp(arg, "-gcompute") == 0) + { + gOptions.shaderType = ShaderProgramType::GraphicsCompute; + } else { fprintf(stderr, "unknown option '%s'\n", arg); diff --git a/tools/render-test/options.h b/tools/render-test/options.h index a36e0a809..2c48c4ceb 100644 --- a/tools/render-test/options.h +++ b/tools/render-test/options.h @@ -34,7 +34,8 @@ enum enum class ShaderProgramType { Graphics, - Compute + Compute, + GraphicsCompute }; struct Options diff --git a/tools/render-test/render-d3d11.cpp b/tools/render-test/render-d3d11.cpp index f90d3fbbe..cdb9f20bd 100644 --- a/tools/render-test/render-d3d11.cpp +++ b/tools/render-test/render-d3d11.cpp @@ -339,7 +339,7 @@ public: hr = D3D11CreateDeviceAndSwapChain_( NULL, // adapter (use default) D3D_DRIVER_TYPE_WARP, -// D3D_DRIVER_TYPE_HARDWARE, + //D3D_DRIVER_TYPE_HARDWARE, NULL, // software deviceFlags, &featureLevels[ii], @@ -520,7 +520,8 @@ public: { case Format::RGB_Float32: return DXGI_FORMAT_R32G32B32_FLOAT; - + case Format::RG_Float32: + return DXGI_FORMAT_R32G32_FLOAT; default: return DXGI_FORMAT_UNKNOWN; } @@ -556,7 +557,9 @@ public: case Format::RGB_Float32: typeName = "float3"; break; - + case Format::RG_Float32: + typeName = "float2"; + break; default: return nullptr; } @@ -570,7 +573,7 @@ public: hlslCursor += sprintf(hlslCursor, "\n) : SV_Position { return 0; }"); - auto dxVertexShaderBlob = compileHLSLShader("inputLayout", hlslBuffer, "main", "vs_4_0"); + auto dxVertexShaderBlob = compileHLSLShader("inputLayout", hlslBuffer, "main", "vs_5_0"); if(!dxVertexShaderBlob) return nullptr; @@ -894,6 +897,7 @@ public: viewDesc.Texture1DArray.FirstArraySlice = 0; viewDesc.Texture1DArray.MipLevels = texData.mipLevels; viewDesc.Texture1DArray.MostDetailedMip = 0; + viewDesc.Format = desc.Format; dxDevice->CreateShaderResourceView(texture, &viewDesc, &viewOut); } else if (inputDesc.dimension == 2) @@ -934,6 +938,7 @@ public: desc.Usage = D3D11_USAGE_DEFAULT; desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; + viewDesc.Format = desc.Format; ID3D11Texture2D * texture; dxDevice->CreateTexture2D(&desc, subRes.Buffer(), &texture); dxDevice->CreateShaderResourceView(texture, &viewDesc, &viewOut); @@ -946,7 +951,7 @@ public: desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS; - desc.MipLevels = texData.mipLevels; + desc.MipLevels = 1; viewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; desc.Width = texData.textureSize; desc.Height = texData.textureSize; @@ -956,8 +961,9 @@ public: dxDevice->CreateTexture3D(&desc, subRes.Buffer(), &texture); if (inputDesc.arrayLength != 0) viewDesc.ViewDimension = (D3D11_SRV_DIMENSION)(int)(viewDesc.ViewDimension + 1); - viewDesc.Texture3D.MipLevels = texData.mipLevels; + viewDesc.Texture3D.MipLevels = 1; viewDesc.Texture3D.MostDetailedMip = 0; + viewDesc.Format = desc.Format; dxDevice->CreateShaderResourceView(texture, &viewDesc, &viewOut); } } diff --git a/tools/render-test/render-gl.cpp b/tools/render-test/render-gl.cpp index e983dad70..d19e71743 100644 --- a/tools/render-test/render-gl.cpp +++ b/tools/render-test/render-gl.cpp @@ -287,6 +287,7 @@ public: case Format::NAME: do { VertexAttributeFormat result = {COUNT, TYPE, NORMALIZED}; return result; } while (0) CASE(RGB_Float32, 3, GL_FLOAT, GL_FALSE); + CASE(RG_Float32, 2, GL_FLOAT, GL_FALSE); #undef CASE @@ -625,7 +626,7 @@ public: { ShaderInputType type; GLuint handle; - int binding; + List<int> binding; int bindTarget; int bufferSize; bool isOutput = false; @@ -789,14 +790,15 @@ public: switch (entry.type) { case ShaderInputType::Buffer: - glBindBufferBase(entry.bindTarget, entry.binding, entry.handle); + glBindBufferBase(entry.bindTarget, entry.binding[0], entry.handle); break; case ShaderInputType::Sampler: - glBindSampler(entry.binding, entry.handle); + for (auto b : entry.binding) + glBindSampler(b, entry.handle); break; case ShaderInputType::Texture: case ShaderInputType::CombinedTextureSampler: - glActiveTexture(GL_TEXTURE0 + entry.binding); + glActiveTexture(GL_TEXTURE0 + entry.binding[0]); glBindTexture(entry.bindTarget, entry.handle); break; } diff --git a/tools/render-test/render.h b/tools/render-test/render.h index 706868e9a..24610eb4d 100644 --- a/tools/render-test/render.h +++ b/tools/render-test/render.h @@ -43,6 +43,7 @@ enum class Format { Unknown, RGB_Float32, + RG_Float32, }; enum class BufferFlavor diff --git a/tools/render-test/shader-input-layout.cpp b/tools/render-test/shader-input-layout.cpp index 47ba767ae..ef78fe3d5 100644 --- a/tools/render-test/shader-input-layout.cpp +++ b/tools/render-test/shader-input-layout.cpp @@ -171,8 +171,8 @@ namespace renderer_test else break; } + parser.Read(")"); } - parser.Read(")"); // parse bindings if (parser.LookAhead(":")) { @@ -190,11 +190,13 @@ namespace renderer_test { parser.ReadToken(); parser.Read("("); - entry.glslBinding = entry.glslLocation = parser.ReadInt(); - if (parser.LookAhead(",")) + while (!parser.IsEnd() && !parser.LookAhead(")")) { - parser.Read(","); - entry.glslLocation = parser.ReadInt(); + entry.glslBinding.Add(parser.ReadInt()); + if (parser.LookAhead(",")) + parser.Read(","); + else + break; } parser.Read(")"); } @@ -223,7 +225,7 @@ namespace renderer_test int arrLen = inputDesc.arrayLength; if (arrLen == 0) arrLen = 1; - List<List<unsigned int>> dataBuffer; + List<List<unsigned int>> & dataBuffer = output.dataBuffer; int arraySize = arrLen; if (inputDesc.isCube) arraySize *= 6; diff --git a/tools/render-test/shader-input-layout.h b/tools/render-test/shader-input-layout.h index 9dae75270..9602e4fe8 100644 --- a/tools/render-test/shader-input-layout.h +++ b/tools/render-test/shader-input-layout.h @@ -46,8 +46,8 @@ namespace renderer_test InputSamplerDesc samplerDesc; bool isOutput = false; int hlslBinding = -1; - int glslBinding = -1; - int glslLocation = -1; + Slang::List<int> glslBinding; + }; struct TextureData diff --git a/tools/slang-test/main.cpp b/tools/slang-test/main.cpp index cdea6b4dc..de75fa68c 100644 --- a/tools/slang-test/main.cpp +++ b/tools/slang-test/main.cpp @@ -1187,6 +1187,11 @@ TestResult doSlangComputeComparisonTest(TestInput& input) return doComputeComparisonTestRunImpl(input, "-slang -compute", input.outputStem + ".expected.txt"); } +TestResult doSlangRenderComputeComparisonTest(TestInput& input) +{ + return doComputeComparisonTestRunImpl(input, "-slang -gcompute", input.outputStem + ".expected.txt"); +} + TestResult doRenderComparisonTestRun(TestInput& input, char const* langOption, char const* outputKind, String* outOutput) { // TODO: delete any existing files at the output path(s) to avoid stale outputs leading to a false pass @@ -1386,6 +1391,8 @@ TestResult runTest( { "COMPARE_HLSL_CROSS_COMPILE_RENDER", &runHLSLCrossCompileRenderComparisonTest}, { "COMPARE_HLSL_GLSL_RENDER", &runHLSLAndGLSLComparisonTest }, { "COMPARE_COMPUTE", &doSlangComputeComparisonTest}, + { "COMPARE_RENDER_COMPUTE", &doSlangRenderComputeComparisonTest }, + #else { "COMPARE_HLSL", &skipTest }, { "COMPARE_HLSL_RENDER", &skipTest }, |
