diff options
Diffstat (limited to 'tools/render-test/main.cpp')
| -rw-r--r-- | tools/render-test/main.cpp | 117 |
1 files changed, 78 insertions, 39 deletions
diff --git a/tools/render-test/main.cpp b/tools/render-test/main.cpp index 935b9bc98..4734c2c8f 100644 --- a/tools/render-test/main.cpp +++ b/tools/render-test/main.cpp @@ -29,6 +29,8 @@ namespace renderer_test { +using Slang::Result; + int gWindowWidth = 1024; int gWindowHeight = 768; @@ -45,7 +47,7 @@ struct Vertex float uv[2]; }; -static const Vertex kVertexData[] = +static const Vertex kVertexData[] = { { { 0, 0, 0.5 }, {1, 0, 0} , {0, 0} }, { { 0, 1, 0.5 }, {0, 0, 1} , {1, 0} }, @@ -61,15 +63,15 @@ class RenderTestApp // At initialization time, we are going to load and compile our Slang shader // code, and then create the API objects we need for rendering. - Result initialize(Renderer* renderer, ShaderCompiler* shaderCompiler); + Result initialize(Renderer* renderer, ShaderCompiler* shaderCompiler); void runCompute(); void renderFrame(); void finalize(); - BindingState* getBindingState() const { return m_bindingState; } + BindingStateImpl* getBindingState() const { return m_bindingState; } Result writeBindingOutput(const char* fileName); - + Result writeScreen(const char* filename); protected: @@ -85,7 +87,8 @@ class RenderTestApp RefPtr<InputLayout> m_inputLayout; RefPtr<BufferResource> m_vertexBuffer; RefPtr<ShaderProgram> m_shaderProgram; - RefPtr<BindingState> m_bindingState; + RefPtr<PipelineState> m_pipelineState; + RefPtr<BindingStateImpl> m_bindingState; ShaderInputLayout m_shaderInputLayout; ///< The binding layout int m_numAddedConstantBuffers; ///< Constant buffers can be added to the binding directly. Will be added at the end. @@ -117,22 +120,26 @@ SlangResult RenderTestApp::initialize(Renderer* renderer, ShaderCompiler* shader } { - BindingState::Desc bindingStateDesc; - SLANG_RETURN_ON_FAIL(ShaderRendererUtil::createBindingStateDesc(m_shaderInputLayout, m_renderer, bindingStateDesc)); - - //! Hack -> if bindings are specified, just set up the constant buffer binding - // Should probably be more sophisticated than this - with 'dynamic' constant buffer/s binding always being specified - // in the test file - - if ((gOptions.shaderType == Options::ShaderProgramType::Graphics || gOptions.shaderType == Options::ShaderProgramType::GraphicsCompute) - && bindingStateDesc.findBindingIndex(Resource::BindFlag::ConstantBuffer, 0) < 0) + //! Hack -> if doing a graphics test, add an extra binding for our dynamic constant buffer + // + // TODO: Should probably be more sophisticated than this - with 'dynamic' constant buffer/s binding always being specified + // in the test file + RefPtr<BufferResource> addedConstantBuffer; + switch(gOptions.shaderType) { - bindingStateDesc.addResource(BindingType::Buffer, m_constantBuffer, BindingState::RegisterRange::makeSingle(0) ); + default: + break; + case Options::ShaderProgramType::Graphics: + case Options::ShaderProgramType::GraphicsCompute: + addedConstantBuffer = m_constantBuffer; m_numAddedConstantBuffers++; + break; } - m_bindingState = m_renderer->createBindingState(bindingStateDesc); + BindingStateImpl* bindingState = nullptr; + SLANG_RETURN_ON_FAIL(ShaderRendererUtil::createBindingState(m_shaderInputLayout, m_renderer, addedConstantBuffer, &bindingState)); + m_bindingState = bindingState; } // Do other initialization that doesn't depend on the source language. @@ -156,6 +163,38 @@ SlangResult RenderTestApp::initialize(Renderer* renderer, ShaderCompiler* shader if(!m_vertexBuffer) return SLANG_FAIL; + { + switch(gOptions.shaderType) + { + default: + assert(!"unexpected test shader type"); + return SLANG_FAIL; + + case Options::ShaderProgramType::Compute: + { + ComputePipelineStateDesc desc; + desc.pipelineLayout = m_bindingState->pipelineLayout; + desc.program = m_shaderProgram; + + m_pipelineState = renderer->createComputePipelineState(desc); + } + break; + + case Options::ShaderProgramType::Graphics: + case Options::ShaderProgramType::GraphicsCompute: + { + GraphicsPipelineStateDesc desc; + desc.pipelineLayout = m_bindingState->pipelineLayout; + desc.program = m_shaderProgram; + desc.inputLayout = m_inputLayout; + desc.renderTargetCount = m_bindingState->m_numRenderTargets; + + m_pipelineState = renderer->createGraphicsPipelineState(desc); + } + break; + } + } + return SLANG_OK; } @@ -182,6 +221,16 @@ Result RenderTestApp::initializeShaders(ShaderCompiler* shaderCompiler) fclose(sourceFile); sourceText[sourceSize] = 0; + switch( gOptions.shaderType ) + { + default: + m_shaderInputLayout.numRenderTargets = 1; + break; + + case Options::ShaderProgramType::Compute: + m_shaderInputLayout.numRenderTargets = 0; + break; + } m_shaderInputLayout.Parse(sourceText); ShaderCompileRequest::SourceInfo sourceInfo; @@ -220,31 +269,27 @@ void RenderTestApp::renderFrame() { const ProjectionStyle projectionStyle = RendererUtil::getProjectionStyle(m_renderer->getRendererType()); RendererUtil::getIdentityProjection(projectionStyle, (float*)mappedData); - + m_renderer->unmap(m_constantBuffer); } - // Input Assembler (IA) + auto pipelineType = PipelineType::Graphics; - m_renderer->setInputLayout(m_inputLayout); - m_renderer->setPrimitiveTopology(PrimitiveTopology::TriangleList); + m_renderer->setPipelineState(pipelineType, m_pipelineState); + m_renderer->setPrimitiveTopology(PrimitiveTopology::TriangleList); m_renderer->setVertexBuffer(0, m_vertexBuffer, sizeof(Vertex)); - // Vertex Shader (VS) - // Pixel Shader (PS) - - m_renderer->setShaderProgram(m_shaderProgram); - m_renderer->setBindingState(m_bindingState); - // + m_bindingState->apply(m_renderer, pipelineType); m_renderer->draw(3); } void RenderTestApp::runCompute() { - m_renderer->setShaderProgram(m_shaderProgram); - m_renderer->setBindingState(m_bindingState); + auto pipelineType = PipelineType::Compute; + m_renderer->setPipelineState(pipelineType, m_pipelineState); + m_bindingState->apply(m_renderer, pipelineType); m_renderer->dispatchCompute(1, 1, 1); } @@ -265,18 +310,12 @@ Result RenderTestApp::writeBindingOutput(const char* fileName) return SLANG_FAIL; } - const BindingState::Desc& bindingStateDesc = m_bindingState->getDesc(); - // Must be the same amount of entries - assert(bindingStateDesc.m_bindings.Count() == m_shaderInputLayout.entries.Count() + m_numAddedConstantBuffers); - - const int numBindings = int(m_shaderInputLayout.entries.Count()); - - for (int i = 0; i < numBindings; ++i) + for(auto binding : m_bindingState->outputBindings) { + auto i = binding.entryIndex; const auto& layoutBinding = m_shaderInputLayout.entries[i]; - const auto& binding = bindingStateDesc.m_bindings[i]; - if (layoutBinding.isOutput) + assert(layoutBinding.isOutput); { if (binding.resource && binding.resource->isBuffer()) { @@ -524,11 +563,11 @@ SlangResult innerMain(int argc, char** argv) else { Result res = app.writeScreen(gOptions.outputPath); - + if (SLANG_FAILED(res)) { fprintf(stderr, "ERROR: failed to write screen capture to file\n"); - return res; + return res; } } return SLANG_OK; |
