diff options
| author | YONGH\yongh <yonghe@outlook.com> | 2017-10-20 18:24:30 -0400 |
|---|---|---|
| committer | YONGH\yongh <yonghe@outlook.com> | 2017-10-20 18:24:30 -0400 |
| commit | 0ee4d4b54732239b946bae7fde32bb21aa5a3ec3 (patch) | |
| tree | 0c5f4a7f6f43e60802d354aa98a3983994f4f4bd /tools/render-test | |
| parent | 5a18dc704a2f5eecebcbdd77682a40ba8316d253 (diff) | |
in-progress work: allow render-test to generate and bind various resource inputs for running test shaders with arbitrary parameter definitions.
This commit contains the parser of the resource input definition.
Diffstat (limited to 'tools/render-test')
| -rw-r--r-- | tools/render-test/main.cpp | 12 | ||||
| -rw-r--r-- | tools/render-test/render-d3d11.cpp | 10 | ||||
| -rw-r--r-- | tools/render-test/render-gl.cpp | 10 | ||||
| -rw-r--r-- | tools/render-test/render-test.vcxproj | 13 | ||||
| -rw-r--r-- | tools/render-test/render-test.vcxproj.filters | 6 | ||||
| -rw-r--r-- | tools/render-test/render.h | 7 | ||||
| -rw-r--r-- | tools/render-test/shader-input-layout.cpp | 180 | ||||
| -rw-r--r-- | tools/render-test/shader-input-layout.h | 52 |
8 files changed, 284 insertions, 6 deletions
diff --git a/tools/render-test/main.cpp b/tools/render-test/main.cpp index 6907ba40f..02b1963ff 100644 --- a/tools/render-test/main.cpp +++ b/tools/render-test/main.cpp @@ -5,7 +5,7 @@ #include "render-d3d11.h" #include "render-gl.h" #include "slang-support.h" - +#include "shader-input-layout.h" #include <stdio.h> #include <stdlib.h> @@ -55,7 +55,9 @@ Buffer* gConstantBuffer; InputLayout* gInputLayout; Buffer* gVertexBuffer; Buffer* gComputeResultBuffer; -ShaderProgram* gShaderProgram; +ShaderProgram* gShaderProgram; +BindingState* gBindingState; +ShaderInputLayout gShaderInputLayout; // Entry point name to use for vertex/fragment shader static char const* vertexEntryPointName = "vertexMain"; @@ -92,6 +94,8 @@ Error initializeShaders( fclose(sourceFile); sourceText[sourceSize] = 0; + gShaderInputLayout.Parse(sourceText); + ShaderCompileRequest::SourceInfo sourceInfo; sourceInfo.path = sourcePath; sourceInfo.text = sourceText; @@ -144,6 +148,7 @@ Error initializeInner( err = initializeShaders(shaderCompiler); if(err != Error::None) return err; + gBindingState = renderer->createBindingState(gShaderInputLayout); // Do other initialization that doesn't depend on the source language. @@ -222,7 +227,7 @@ void renderFrameInner( renderer->setShaderProgram(gShaderProgram); renderer->setConstantBuffer(0, gConstantBuffer); - + renderer->setBindingState(gBindingState); // renderer->draw(3); @@ -232,6 +237,7 @@ void runCompute(Renderer * renderer) { renderer->setShaderProgram(gShaderProgram); renderer->setStorageBuffer(0, gComputeResultBuffer); + renderer->setBindingState(gBindingState); renderer->dispatchCompute(1, 1, 1); } diff --git a/tools/render-test/render-d3d11.cpp b/tools/render-test/render-d3d11.cpp index 6e9e04a78..8915952e0 100644 --- a/tools/render-test/render-d3d11.cpp +++ b/tools/render-test/render-d3d11.cpp @@ -751,6 +751,16 @@ public: auto dxContext = dxImmediateContext; dxContext->Dispatch(x, y, z); } + + virtual BindingState * createBindingState(const ShaderInputLayout & layout) + { + return nullptr; + } + + virtual void setBindingState(BindingState * state) + { + + } }; diff --git a/tools/render-test/render-gl.cpp b/tools/render-test/render-gl.cpp index 55647fb25..79dd09ad9 100644 --- a/tools/render-test/render-gl.cpp +++ b/tools/render-test/render-gl.cpp @@ -613,6 +613,16 @@ public: { glDispatchCompute(x, y, z); } + + virtual BindingState * createBindingState(const ShaderInputLayout & layout) + { + return nullptr; + } + + virtual void setBindingState(BindingState * state) + { + + } }; diff --git a/tools/render-test/render-test.vcxproj b/tools/render-test/render-test.vcxproj index 94af429e8..0b0f6b05e 100644 --- a/tools/render-test/render-test.vcxproj +++ b/tools/render-test/render-test.vcxproj @@ -96,6 +96,8 @@ <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>../../source/</AdditionalIncludeDirectories> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> </ClCompile> <Link> <SubSystem>Console</SubSystem> @@ -109,6 +111,8 @@ <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> <PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>../../source/</AdditionalIncludeDirectories> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> </ClCompile> <Link> <SubSystem>Console</SubSystem> @@ -124,6 +128,8 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>../../source/</AdditionalIncludeDirectories> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> </ClCompile> <Link> <SubSystem>Console</SubSystem> @@ -141,6 +147,8 @@ <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>../../source/</AdditionalIncludeDirectories> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> </ClCompile> <Link> <SubSystem>Console</SubSystem> @@ -154,6 +162,7 @@ <ClCompile Include="options.cpp" /> <ClCompile Include="render-d3d11.cpp" /> <ClCompile Include="render-gl.cpp" /> + <ClCompile Include="shader-input-layout.cpp" /> <ClCompile Include="slang-support.cpp" /> </ItemGroup> <ItemGroup> @@ -161,10 +170,14 @@ <ClInclude Include="render-d3d11.h" /> <ClInclude Include="render-gl.h" /> <ClInclude Include="render.h" /> + <ClInclude Include="shader-input-layout.h" /> <ClInclude Include="slang-support.h" /> <ClInclude Include="window.h" /> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\..\source\core\core.vcxproj"> + <Project>{f9be7957-8399-899e-0c49-e714fddd4b65}</Project> + </ProjectReference> <ProjectReference Include="..\..\source\slang\slang.vcxproj"> <Project>{db00da62-0533-4afd-b59f-a67d5b3a0808}</Project> </ProjectReference> diff --git a/tools/render-test/render-test.vcxproj.filters b/tools/render-test/render-test.vcxproj.filters index 6e0ff295a..985e24b8b 100644 --- a/tools/render-test/render-test.vcxproj.filters +++ b/tools/render-test/render-test.vcxproj.filters @@ -30,6 +30,9 @@ <ClCompile Include="slang-support.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="shader-input-layout.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="options.h"> @@ -50,5 +53,8 @@ <ClInclude Include="slang-support.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="shader-input-layout.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> </Project>
\ No newline at end of file diff --git a/tools/render-test/render.h b/tools/render-test/render.h index 7f8f2fffa..426b0738a 100644 --- a/tools/render-test/render.h +++ b/tools/render-test/render.h @@ -3,13 +3,14 @@ #include "options.h" #include "window.h" +#include "shader-input-layout.h" namespace renderer_test { typedef struct Buffer Buffer; typedef struct InputLayout InputLayout; typedef struct ShaderProgram ShaderProgram; - +typedef struct BindingState BindingState; struct ShaderCompileRequest { struct SourceInfo @@ -93,7 +94,7 @@ public: virtual Buffer* createBuffer(BufferDesc const& desc) = 0; virtual InputLayout* createInputLayout(InputElementDesc const* inputElements, UInt inputElementCount) = 0; - + virtual BindingState* createBindingState(const ShaderInputLayout & shaderInput) = 0; virtual ShaderCompiler* getShaderCompiler() = 0; virtual void* map(Buffer* buffer, MapFlavor flavor) = 0; @@ -101,7 +102,7 @@ public: virtual void setInputLayout(InputLayout* inputLayout) = 0; virtual void setPrimitiveTopology(PrimitiveTopology topology) = 0; - + virtual void setBindingState(BindingState * state) = 0; virtual void setVertexBuffers(UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* strides, UInt const* offsets) = 0; inline void setVertexBuffer(UInt slot, Buffer* buffer, UInt stride, UInt offset = 0) diff --git a/tools/render-test/shader-input-layout.cpp b/tools/render-test/shader-input-layout.cpp new file mode 100644 index 000000000..c97028441 --- /dev/null +++ b/tools/render-test/shader-input-layout.cpp @@ -0,0 +1,180 @@ +#include "shader-input-layout.h" +#include "core/token-reader.h" + +namespace renderer_test +{ + using namespace Slang; + void ShaderInputLayout::Parse(const char * source) + { + entries.Clear(); + auto lines = Split(source, '\n'); + for (auto & line : lines) + { + if (line.StartsWith("//TEST_INPUT:")) + { + auto lineContent = line.SubString(13, line.Length() - 13); + TokenReader parser(lineContent); + try + { + ShaderInputLayoutEntry entry; + + if (parser.LookAhead("cbuffer")) + { + entry.type = ShaderInputType::Buffer; + entry.bufferDesc.type = InputBufferType::ConstantBuffer; + } + else if (parser.LookAhead("ubuffer")) + { + entry.type = ShaderInputType::Buffer; + entry.bufferDesc.type = InputBufferType::StorageBuffer; + } + else if (parser.LookAhead("Texture1D")) + { + entry.type = ShaderInputType::Texture; + entry.textureDesc.dimension = 1; + } + else if (parser.LookAhead("Texture2D")) + { + entry.type = ShaderInputType::Texture; + entry.textureDesc.dimension = 2; + } + else if (parser.LookAhead("Texture3D")) + { + entry.type = ShaderInputType::Texture; + entry.textureDesc.dimension = 3; + } + else if (parser.LookAhead("TextureCube")) + { + entry.type = ShaderInputType::Texture; + entry.textureDesc.dimension = 2; + entry.textureDesc.isCube = true; + } + else if (parser.LookAhead("Sampler")) + { + entry.type = ShaderInputType::Sampler; + } + else if (parser.LookAhead("Sampler1D")) + { + entry.type = ShaderInputType::CombinedTextureSampler; + entry.textureDesc.dimension = 1; + } + else if (parser.LookAhead("Sampler2D")) + { + entry.type = ShaderInputType::CombinedTextureSampler; + entry.textureDesc.dimension = 2; + } + else if (parser.LookAhead("Sampler3D")) + { + entry.type = ShaderInputType::CombinedTextureSampler; + entry.textureDesc.dimension = 3; + } + else if (parser.LookAhead("SamplerCube")) + { + entry.type = ShaderInputType::CombinedTextureSampler; + entry.textureDesc.dimension = 2; + entry.textureDesc.isCube = true; + } + parser.ReadToken(); + // parse options + if (parser.LookAhead("(")) + { + parser.Read("("); + while (!parser.IsEnd() && !parser.LookAhead(")")) + { + auto word = parser.ReadWord(); + if (word == "depth") + { + entry.textureDesc.isDepthTexture = true; + } + else if (word == "depthCompare") + { + entry.samplerDesc.isCompareSampler = true; + } + else if (word == "arrayLength") + { + parser.Read("="); + entry.textureDesc.arrayLength = parser.ReadInt(); + } + else if (word == "stride") + { + parser.Read("="); + entry.bufferDesc.stride = parser.ReadInt(); + } + else if (word == "data") + { + parser.Read("="); + parser.Read("["); + while (!parser.IsEnd() && !parser.LookAhead("]")) + { + if (parser.NextToken().Type == TokenType::IntLiteral) + { + entry.bufferData.Add(parser.ReadUInt()); + } + else + { + auto floatNum = parser.ReadFloat(); + entry.bufferData.Add(*(unsigned int*)&floatNum); + } + } + parser.Read("]"); + } + if (parser.LookAhead(",")) + parser.Read(","); + else + break; + } + parser.Read(")"); + // parse bindings + if (parser.LookAhead(":")) + { + parser.Read(":"); + while (!parser.IsEnd()) + { + if (parser.LookAhead("register")) + { + parser.ReadToken(); + parser.Read("("); + auto reg = parser.ReadWord(); + entry.hlslRegister = parser.ReadInt(); + parser.Read(")"); + } + else if (parser.LookAhead("layout")) + { + parser.ReadToken(); + parser.Read("("); + while (!parser.IsEnd() && !parser.LookAhead(")")) + { + auto word = parser.ReadWord(); + if (word == "binding") + { + parser.Read("="); + entry.glslBinding = parser.ReadInt(); + } + else if (word == "location") + { + parser.Read("="); + entry.glslLocation = parser.ReadInt(); + } + if (parser.LookAhead(",")) + parser.Read(","); + else + break; + } + parser.Read(")"); + } + if (parser.LookAhead(",")) + parser.Read(","); + } + } + } + } + catch (TextFormatException) + { + throw TextFormatException("Invalid input syntax at line " + parser.NextToken().Position.Line); + } + } + } + + + } +}
\ No newline at end of file diff --git a/tools/render-test/shader-input-layout.h b/tools/render-test/shader-input-layout.h new file mode 100644 index 000000000..788a72224 --- /dev/null +++ b/tools/render-test/shader-input-layout.h @@ -0,0 +1,52 @@ +#ifndef SLANG_TEST_SHADER_INPUT_LAYOUT_H +#define SLANG_TEST_SHADER_INPUT_LAYOUT_H + +#include "core/basic.h" + +namespace renderer_test +{ + enum class ShaderInputType + { + Buffer, Texture, Sampler, CombinedTextureSampler + }; + struct InputTextureDesc + { + int dimension = 2; + int arrayLength = 0; + bool isCube = false; + bool isDepthTexture = false; + }; + enum class InputBufferType + { + ConstantBuffer, StorageBuffer + }; + struct InputBufferDesc + { + InputBufferType type = InputBufferType::ConstantBuffer; + int stride = 0; // stride == 0 indicates an unstructured buffer. + }; + struct InputSamplerDesc + { + bool isCompareSampler = false; + }; + class ShaderInputLayoutEntry + { + public: + ShaderInputType type; + Slang::List<unsigned int> bufferData; + InputTextureDesc textureDesc; + InputBufferDesc bufferDesc; + InputSamplerDesc samplerDesc; + int hlslRegister = -1; + int glslBinding = -1; + int glslLocation = -1; + }; + class ShaderInputLayout + { + public: + Slang::List<ShaderInputLayoutEntry> entries; + void Parse(const char * source); + }; +} + +#endif
\ No newline at end of file |
