diff options
| author | Yong He <yonghe@outlook.com> | 2021-02-04 13:50:51 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-04 13:50:51 -0800 |
| commit | c40f10b704b8bd5a744cc9b3964344585436b1ac (patch) | |
| tree | 1c9608f3cc32949d88fe04f3512cd3147fc3fe1f /tools/gfx/d3d12/render-d3d12.cpp | |
| parent | 7f266f1ea7a51213069282296a905650fd405c3f (diff) | |
[gfx] Shader-object driven shader compilation. (#1688)
Diffstat (limited to 'tools/gfx/d3d12/render-d3d12.cpp')
| -rw-r--r-- | tools/gfx/d3d12/render-d3d12.cpp | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp index 407f0dbf2..de7cbd2e2 100644 --- a/tools/gfx/d3d12/render-d3d12.cpp +++ b/tools/gfx/d3d12/render-d3d12.cpp @@ -140,8 +140,7 @@ public: setViewports(UInt count, Viewport const* viewports) override; virtual SLANG_NO_THROW void SLANG_MCALL setScissorRects(UInt count, ScissorRect const* rects) override; - virtual SLANG_NO_THROW void SLANG_MCALL - setPipelineState(PipelineType pipelineType, IPipelineState* state) override; + virtual SLANG_NO_THROW void SLANG_MCALL setPipelineState(IPipelineState* state) override; virtual SLANG_NO_THROW void SLANG_MCALL draw(UInt vertexCount, UInt startVertex) override; virtual SLANG_NO_THROW void SLANG_MCALL drawIndexed(UInt indexCount, UInt startIndex, UInt baseVertex) override; @@ -152,7 +151,10 @@ public: { return RendererType::DirectX12; } - + virtual PipelineStateBase* getCurrentPipeline() override + { + return m_currentPipelineState; + } ~D3D12Renderer(); protected: @@ -540,20 +542,25 @@ protected: D3D12DescriptorHeap m_cpuViewHeap; ///< Cbv, Srv, Uav D3D12DescriptorHeap m_cpuSamplerHeap; ///< Heap for samplers - class PipelineStateImpl : public IPipelineState, public RefObject + class PipelineStateImpl : public PipelineStateBase { public: - SLANG_REF_OBJECT_IUNKNOWN_ALL - IPipelineState* getInterface(const Guid& guid) - { - if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_IPipelineState) - return static_cast<IPipelineState*>(this); - return nullptr; - } - public: - PipelineType m_pipelineType; RefPtr<PipelineLayoutImpl> m_pipelineLayout; ComPtr<ID3D12PipelineState> m_pipelineState; + void init(const GraphicsPipelineStateDesc& inDesc) + { + PipelineStateDesc pipelineDesc; + pipelineDesc.type = PipelineType::Graphics; + pipelineDesc.graphics = inDesc; + initializeBase(pipelineDesc); + } + void init(const ComputePipelineStateDesc& inDesc) + { + PipelineStateDesc pipelineDesc; + pipelineDesc.type = PipelineType::Compute; + pipelineDesc.compute = inDesc; + initializeBase(pipelineDesc); + } }; struct BoundVertexBuffer @@ -760,10 +767,11 @@ protected: bool m_nvapi = false; }; -SlangResult SLANG_MCALL createD3D12Renderer(IRenderer** outRenderer) +SlangResult SLANG_MCALL createD3D12Renderer(const IRenderer::Desc* desc, void* windowHandle, IRenderer** outRenderer) { - *outRenderer = new D3D12Renderer(); - (*outRenderer)->addRef(); + RefPtr<D3D12Renderer> result = new D3D12Renderer(); + SLANG_RETURN_ON_FAIL(result->initialize(*desc, windowHandle)); + *outRenderer = result.detach(); return SLANG_OK; } @@ -1160,7 +1168,7 @@ Result D3D12Renderer::_bindRenderState(PipelineStateImpl* pipelineStateImpl, ID3 { // TODO: we should only set some of this state as needed... - auto pipelineTypeIndex = (int) pipelineStateImpl->m_pipelineType; + auto pipelineTypeIndex = (int) pipelineStateImpl->desc.type; auto pipelineLayout = pipelineStateImpl->m_pipelineLayout; submitter->setRootSignature(pipelineLayout->m_rootSignature); @@ -1350,6 +1358,8 @@ Result D3D12Renderer::initialize(const Desc& desc, void* inWindowHandle) { SLANG_RETURN_ON_FAIL(slangContext.initialize(desc.slang, SLANG_DXBC, "sm_5_1")); + SLANG_RETURN_ON_FAIL(GraphicsAPIRenderer::initialize(desc, inWindowHandle)); + m_hwnd = (HWND)inWindowHandle; // Rather than statically link against D3D, we load it dynamically. @@ -2692,7 +2702,7 @@ void D3D12Renderer::setScissorRects(UInt count, ScissorRect const* rects) m_commandList->RSSetScissorRects(UINT(count), dxRects); } -void D3D12Renderer::setPipelineState(PipelineType pipelineType, IPipelineState* state) +void D3D12Renderer::setPipelineState(IPipelineState* state) { m_currentPipelineState = (PipelineStateImpl*)state; } @@ -2702,7 +2712,7 @@ void D3D12Renderer::draw(UInt vertexCount, UInt startVertex) ID3D12GraphicsCommandList* commandList = m_commandList; auto pipelineState = m_currentPipelineState.Ptr(); - if (!pipelineState || (pipelineState->m_pipelineType != PipelineType::Graphics)) + if (!pipelineState || (pipelineState->desc.type != PipelineType::Graphics)) { assert(!"No graphics pipeline state set"); return; @@ -3715,9 +3725,9 @@ Result D3D12Renderer::createGraphicsPipelineState(const GraphicsPipelineStateDes SLANG_RETURN_ON_FAIL(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(pipelineState.writeRef()))); RefPtr<PipelineStateImpl> pipelineStateImpl = new PipelineStateImpl(); - pipelineStateImpl->m_pipelineType = PipelineType::Graphics; pipelineStateImpl->m_pipelineLayout = pipelineLayoutImpl; pipelineStateImpl->m_pipelineState = pipelineState; + pipelineStateImpl->init(desc); *outState = pipelineStateImpl.detach(); return SLANG_OK; } @@ -3768,9 +3778,9 @@ Result D3D12Renderer::createComputePipelineState(const ComputePipelineStateDesc& } RefPtr<PipelineStateImpl> pipelineStateImpl = new PipelineStateImpl(); - pipelineStateImpl->m_pipelineType = PipelineType::Compute; pipelineStateImpl->m_pipelineLayout = pipelineLayoutImpl; pipelineStateImpl->m_pipelineState = pipelineState; + pipelineStateImpl->init(desc); *outState = pipelineStateImpl.detach(); return SLANG_OK; } |
