From 5894c3b1a96e9db41f50b2b178f81568ff421776 Mon Sep 17 00:00:00 2001 From: "YONGH\\yongh" Date: Wed, 25 Oct 2017 16:33:18 -0400 Subject: finish up opengl renderer implementation for input resource binding. --- tools/render-test/render-gl.cpp | 200 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 196 insertions(+), 4 deletions(-) (limited to 'tools/render-test/render-gl.cpp') diff --git a/tools/render-test/render-gl.cpp b/tools/render-test/render-gl.cpp index ff9d54eb6..e983dad70 100644 --- a/tools/render-test/render-gl.cpp +++ b/tools/render-test/render-gl.cpp @@ -7,7 +7,7 @@ #include #include #include - +#include "core/basic.h" #include "external/stb/stb_image_write.h" // TODO(tfoley): eventually we should be able to run these @@ -59,8 +59,15 @@ F(glDisableVertexAttribArray, PFNGLDISABLEVERTEXATTRIBARRAYPROC) \ F(glDebugMessageCallback, PFNGLDEBUGMESSAGECALLBACKPROC) \ F(glDispatchCompute, PFNGLDISPATCHCOMPUTEPROC) \ + F(glActiveTexture, PFNGLACTIVETEXTUREPROC) \ + F(glCreateSamplers, PFNGLCREATESAMPLERSPROC) \ + F(glBindSampler, PFNGLBINDSAMPLERPROC) \ + F(glTexImage3D, PFNGLTEXIMAGE3DPROC) \ + F(glSamplerParameteri, PFNGLSAMPLERPARAMETERIPROC) \ /* end */ +using namespace Slang; + namespace renderer_test { class GLRenderer : public Renderer, public ShaderCompiler @@ -614,19 +621,204 @@ public: glDispatchCompute(x, y, z); } + struct GLBindingEntry + { + ShaderInputType type; + GLuint handle; + int binding; + int bindTarget; + int bufferSize; + bool isOutput = false; + }; + struct GLBindingState + { + List entries; + }; + + void createInputBuffer(GLBindingEntry & rs, InputBufferDesc bufDesc, List & bufferData) + { + rs.bindTarget = (bufDesc.type == InputBufferType::StorageBuffer ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER); + glGenBuffers(1, &rs.handle); + glBindBuffer(rs.bindTarget, rs.handle); + glBufferData(rs.bindTarget, bufferData.Count() * sizeof(unsigned int), bufferData.Buffer(), GL_STATIC_READ); + glBindBuffer(rs.bindTarget, 0); + } + + void createInputTexture(GLBindingEntry & rs, InputTextureDesc texDesc, InputSamplerDesc samplerDesc) + { + TextureData texData; + generateTextureData(texData, texDesc); + glGenTextures(1, &rs.handle); + switch (texDesc.dimension) + { + case 1: + if (texDesc.arrayLength > 0) + { + rs.bindTarget = GL_TEXTURE_1D_ARRAY; + glBindTexture(rs.bindTarget, rs.handle); + int slice = 0; + for (int i = 0; i < texData.arraySize; i++) + for (int j = 0; j < texData.mipLevels; j++) + { + glTexImage2D(rs.bindTarget, j, GL_RGBA8, texData.textureSize, i, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData.dataBuffer[slice].Buffer()); + slice++; + } + } + else + { + rs.bindTarget = GL_TEXTURE_1D; + glBindTexture(rs.bindTarget, rs.handle); + for (int i = 0; i < texData.mipLevels; i++) + glTexImage1D(rs.bindTarget, i, GL_RGBA8, texData.textureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData.dataBuffer[i].Buffer()); + } + break; + case 2: + if (texDesc.arrayLength > 0) + { + if (texDesc.isCube) + rs.bindTarget = GL_TEXTURE_CUBE_MAP_ARRAY; + else + rs.bindTarget = GL_TEXTURE_2D_ARRAY; + glBindTexture(rs.bindTarget, rs.handle); + for (auto i = 0u; i < texData.dataBuffer.Count(); i++) + glTexImage3D(rs.bindTarget, i % texData.mipLevels, GL_RGBA8, texData.textureSize, texData.textureSize, i, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData.dataBuffer[i].Buffer()); + } + else + { + if (texDesc.isCube) + { + rs.bindTarget = GL_TEXTURE_CUBE_MAP; + glBindTexture(rs.bindTarget, rs.handle); + for (int j = 0; j < 6; j++) + { + for (int i = 0; i < texData.mipLevels; i++) + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + j, i, GL_RGBA8, texData.textureSize, texData.textureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData.dataBuffer[i + j*texData.mipLevels].Buffer()); + } + } + else + { + rs.bindTarget = GL_TEXTURE_2D; + glBindTexture(rs.bindTarget, rs.handle); + for (int i = 0; i < texData.mipLevels; i++) + glTexImage2D(rs.bindTarget, i, GL_RGBA8, texData.textureSize, texData.textureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData.dataBuffer[i].Buffer()); + } + } + break; + case 3: + rs.bindTarget = GL_TEXTURE_3D; + glBindTexture(rs.bindTarget, rs.handle); + for (int i = 0; i < texData.mipLevels; i++) + glTexImage3D(rs.bindTarget, i, GL_RGBA8, texData.textureSize, texData.textureSize, texData.textureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData.dataBuffer[i].Buffer()); + break; + } + glTexParameteri(rs.bindTarget, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(rs.bindTarget, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(rs.bindTarget, GL_TEXTURE_WRAP_R, GL_REPEAT); + + if (samplerDesc.isCompareSampler) + { + glTexParameteri(rs.bindTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(rs.bindTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(rs.bindTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8.0f); + } + else + { + glTexParameteri(rs.bindTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(rs.bindTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(rs.bindTarget, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); + glTexParameteri(rs.bindTarget, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); + } + } + + void createInputSampler(GLBindingEntry & rs, InputSamplerDesc samplerDesc) + { + glCreateSamplers(1, &rs.handle); + glSamplerParameteri(rs.handle, GL_TEXTURE_WRAP_S, GL_REPEAT); + glSamplerParameteri(rs.handle, GL_TEXTURE_WRAP_T, GL_REPEAT); + glSamplerParameteri(rs.handle, GL_TEXTURE_WRAP_R, GL_REPEAT); + + if (samplerDesc.isCompareSampler) + { + glSamplerParameteri(rs.handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glSamplerParameteri(rs.handle, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameteri(rs.handle, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8.0f); + } + else + { + glSamplerParameteri(rs.handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glSamplerParameteri(rs.handle, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameteri(rs.handle, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); + glSamplerParameteri(rs.handle, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); + } + } + virtual BindingState * createBindingState(const ShaderInputLayout & layout) { - return nullptr; + GLBindingState * rs = new GLBindingState(); + for (auto & entry : layout.entries) + { + GLBindingEntry rsEntry; + rsEntry.isOutput = entry.isOutput; + rsEntry.binding = entry.glslBinding; + rsEntry.type = entry.type; + switch (entry.type) + { + case ShaderInputType::Buffer: + createInputBuffer(rsEntry, entry.bufferDesc, entry.bufferData); + break; + case ShaderInputType::Texture: + createInputTexture(rsEntry, entry.textureDesc, InputSamplerDesc()); + break; + case ShaderInputType::CombinedTextureSampler: + createInputTexture(rsEntry, entry.textureDesc, entry.samplerDesc); + break; + case ShaderInputType::Sampler: + createInputSampler(rsEntry, entry.samplerDesc); + break; + } + rs->entries.Add(rsEntry); + } + return (BindingState*)rs; } virtual void setBindingState(BindingState * state) { - + GLBindingState * glState = (GLBindingState*)state; + for (auto & entry : glState->entries) + { + switch (entry.type) + { + case ShaderInputType::Buffer: + glBindBufferBase(entry.bindTarget, entry.binding, entry.handle); + break; + case ShaderInputType::Sampler: + glBindSampler(entry.binding, entry.handle); + break; + case ShaderInputType::Texture: + case ShaderInputType::CombinedTextureSampler: + glActiveTexture(GL_TEXTURE0 + entry.binding); + glBindTexture(entry.bindTarget, entry.handle); + break; + } + } } virtual void serializeOutput(BindingState* state, const char * fileName) { - + GLBindingState * glState = (GLBindingState*)state; + FILE * f = fopen(fileName, "wt"); + for (auto & entry : glState->entries) + { + if (entry.isOutput) + { + glBindBuffer(entry.bindTarget, entry.handle); + auto ptr = (unsigned int *)glMapBuffer(entry.bindTarget, GL_READ_ONLY); + for (auto i = 0u; i < entry.bufferSize / sizeof(unsigned int); i++) + fprintf(f, "%X\n", ptr[i]); + glUnmapBuffer(entry.bindTarget); + } + } + fclose(f); } }; -- cgit v1.2.3 From 52ceff4beee7cdc7d47eb9292a35e9f610a80bdc Mon Sep 17 00:00:00 2001 From: "YONGH\\yongh" Date: Wed, 25 Oct 2017 17:59:45 -0400 Subject: add new test mode: COMPARE_RENDER_COMPUTE, which runs a input vertex/fragment shader pair, but instead of comparing the resulting framebuffer, it expects the test shader to write results into a UAV, and compares the pixel shader UAV output to the reference output. --- tests/compute/textureSamplingTest.slang | 103 +++++++++++++++++++++ .../compute/textureSamplingTest.slang.expected.txt | 1 + tools/render-test/main.cpp | 20 ++-- tools/render-test/options.cpp | 4 + tools/render-test/options.h | 3 +- tools/render-test/render-d3d11.cpp | 18 ++-- tools/render-test/render-gl.cpp | 10 +- tools/render-test/render.h | 1 + tools/render-test/shader-input-layout.cpp | 14 +-- tools/render-test/shader-input-layout.h | 4 +- tools/slang-test/main.cpp | 7 ++ 11 files changed, 157 insertions(+), 28 deletions(-) create mode 100644 tests/compute/textureSamplingTest.slang create mode 100644 tests/compute/textureSamplingTest.slang.expected.txt (limited to 'tools/render-test/render-gl.cpp') 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 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 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> dataBuffer; + List> & 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 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 }, -- cgit v1.2.3 From 14d93b03c2238cfc9541f92c2d5ab24a7373b82d Mon Sep 17 00:00:00 2001 From: "YONGH\\yongh" Date: Wed, 25 Oct 2017 22:13:11 -0400 Subject: fix d3d11 usage --- tools/render-test/render-d3d11.cpp | 70 +++++++++++++------------------------- tools/render-test/render-gl.cpp | 6 ---- tools/render-test/render.h | 8 +---- 3 files changed, 24 insertions(+), 60 deletions(-) (limited to 'tools/render-test/render-gl.cpp') diff --git a/tools/render-test/render-d3d11.cpp b/tools/render-test/render-d3d11.cpp index eec87c1a7..3bb9d3e4e 100644 --- a/tools/render-test/render-d3d11.cpp +++ b/tools/render-test/render-d3d11.cpp @@ -54,6 +54,7 @@ struct D3DBinding struct D3DBindingState { List bindings; + int numRenderTargets = 0; }; // @@ -452,7 +453,6 @@ public: struct D3DBuffer { - ID3D11UnorderedAccessView * view = nullptr; ID3D11Buffer * buffer = nullptr; }; @@ -470,19 +470,10 @@ public: break; case BufferFlavor::Vertex: - dxBufferDesc.Usage = D3D11_USAGE_DEFAULT; + dxBufferDesc.Usage = D3D11_USAGE_DYNAMIC; dxBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - dxBufferDesc.CPUAccessFlags = 0; + dxBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; break; - - case BufferFlavor::Storage: - dxBufferDesc.Usage = D3D11_USAGE_DEFAULT; - dxBufferDesc.BindFlags = D3D11_BIND_UNORDERED_ACCESS; - dxBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - dxBufferDesc.StructureByteStride = sizeof(float); - dxBufferDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; - break; - default: return nullptr; } @@ -500,17 +491,6 @@ public: D3DBuffer * rs = new D3DBuffer(); rs->buffer = dxBuffer; - if (desc.flavor == BufferFlavor::Storage) - { - D3D11_UNORDERED_ACCESS_VIEW_DESC viewDesc; - memset(&viewDesc, 0, sizeof(viewDesc)); - viewDesc.Buffer.FirstElement = 0; - viewDesc.Buffer.NumElements = 512; - viewDesc.Buffer.Flags = 0; - viewDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; - viewDesc.Format = DXGI_FORMAT_UNKNOWN; - dxDevice->CreateUnorderedAccessView(dxBuffer, &viewDesc, &rs->view); - } return (Buffer*) rs; } @@ -714,18 +694,6 @@ public: (UINT) startSlot, (UINT) slotCount, &dxConstantBuffers[0]->buffer); } - virtual void setStorageBuffers(UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* offsets) override - { - auto dxContext = dxImmediateContext; - - // TODO: actually use those offsets - - auto dxStorageBuffers = (D3DBuffer* const*)buffers; - dxContext->CSSetUnorderedAccessViews( - (UINT)startSlot, (UINT)slotCount, &dxStorageBuffers[0]->view, 0); - } - - virtual void draw(UInt vertexCount, UInt startVertex) override { auto dxContext = dxImmediateContext; @@ -808,15 +776,13 @@ public: desc.ByteWidth = bufferData.Count() * sizeof(unsigned int); if (bufferDesc.type == InputBufferType::ConstantBuffer) { - desc.Usage = D3D11_USAGE_DYNAMIC; + desc.Usage = D3D11_USAGE_DEFAULT; desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER | D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; } else { desc.Usage = D3D11_USAGE_DEFAULT; desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; if (bufferDesc.stride != 0) { desc.StructureByteStride = bufferDesc.stride; @@ -876,7 +842,7 @@ public: { D3D11_TEXTURE1D_DESC desc = { 0 }; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + desc.CPUAccessFlags = 0; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.MiscFlags = 0; desc.MipLevels = texData.mipLevels; @@ -905,7 +871,7 @@ public: D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc; D3D11_TEXTURE2D_DESC desc = { 0 }; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + desc.CPUAccessFlags = 0; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.MiscFlags = 0; desc.MipLevels = texData.mipLevels; @@ -948,7 +914,7 @@ public: D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc; D3D11_TEXTURE3D_DESC desc = { 0 }; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + desc.CPUAccessFlags = 0; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.MiscFlags = 0; desc.MipLevels = 1; @@ -989,6 +955,7 @@ public: virtual BindingState * createBindingState(const ShaderInputLayout & layout) { D3DBindingState * rs = new D3DBindingState(); + rs->numRenderTargets = layout.numRenderTargets; for (auto & entry : layout.entries) { D3DBinding rsEntry; @@ -1037,8 +1004,8 @@ public: if (isCompute) dxContext->CSSetUnorderedAccessViews(binding.binding, 1, &binding.uav, nullptr); else - dxContext->OMSetRenderTargetsAndUnorderedAccessViews(D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, - nullptr, nullptr, binding.binding, 1, &binding.uav, nullptr); + dxContext->OMSetRenderTargetsAndUnorderedAccessViews(currentBindings->numRenderTargets, + dxRenderTargetViews.Buffer(), nullptr, binding.binding, 1, &binding.uav, nullptr); } else { @@ -1105,10 +1072,21 @@ public: { if (binding.buffer) { - auto ptr = (unsigned int *)map(binding.buffer, MapFlavor::HostRead); + // create staging buffer + ID3D11Buffer* stageBuf; + D3D11_BUFFER_DESC bufDesc; + memset(&bufDesc, 0, sizeof(bufDesc)); + bufDesc.BindFlags = 0; + bufDesc.ByteWidth = binding.bufferLength; + bufDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + bufDesc.Usage = D3D11_USAGE_STAGING; + dxDevice->CreateBuffer(&bufDesc, nullptr, &stageBuf); + dxContext->CopyResource(stageBuf, binding.buffer); + auto ptr = (unsigned int *)map(stageBuf, MapFlavor::HostRead); for (auto i = 0u; i < binding.bufferLength / sizeof(unsigned int); i++) fprintf(f, "%X\n", ptr[i]); - unmap(binding.buffer); + unmap(stageBuf); + stageBuf->Release(); } else { @@ -1122,8 +1100,6 @@ public: } }; - - Renderer* createD3D11Renderer() { return new D3D11Renderer(); diff --git a/tools/render-test/render-gl.cpp b/tools/render-test/render-gl.cpp index d19e71743..9563ced96 100644 --- a/tools/render-test/render-gl.cpp +++ b/tools/render-test/render-gl.cpp @@ -410,12 +410,6 @@ public: bindBufferImpl(GL_UNIFORM_BUFFER, startSlot, slotCount, buffers, offsets); } - - virtual void setStorageBuffers(UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* offsets) override - { - bindBufferImpl(GL_SHADER_STORAGE_BUFFER, startSlot, slotCount, buffers, offsets); - } - void flushStateForDraw() { auto layout = this->boundInputLayout; diff --git a/tools/render-test/render.h b/tools/render-test/render.h index 24610eb4d..dec48cda4 100644 --- a/tools/render-test/render.h +++ b/tools/render-test/render.h @@ -49,8 +49,7 @@ enum class Format enum class BufferFlavor { Constant, - Vertex, - Storage, + Vertex }; struct BufferDesc @@ -114,15 +113,10 @@ public: virtual void setShaderProgram(ShaderProgram* program) = 0; virtual void setConstantBuffers(UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* offsets) = 0; - virtual void setStorageBuffers(UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* offsets) = 0; inline void setConstantBuffer(UInt slot, Buffer* buffer, UInt offset = 0) { setConstantBuffers(slot, 1, &buffer, &offset); } - inline void setStorageBuffer(UInt slot, Buffer* buffer, UInt offset = 0) - { - setStorageBuffers(slot, 1, &buffer, &offset); - } virtual void draw(UInt vertexCount, UInt startVertex = 0) = 0; virtual void dispatchCompute(int x, int y, int z) = 0; }; -- cgit v1.2.3