From 170f13b9c2a2ca17d13e848b037d273abd9efcf5 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 18 Oct 2020 18:50:01 -0700 Subject: PSO creation refactoring (API240075) --- DiligentCore | 2 +- DiligentFX | 2 +- DiligentSamples | 2 +- DiligentTools | 2 +- Projects/Asteroids/src/asteroids_DE.cpp | 88 ++++++++++++---------- .../PluginSource/src/SamplePlugin.cpp | 44 +++++------ unityplugin/GhostCubeScene/src/GhostCubeScene.cpp | 23 +++--- 7 files changed, 86 insertions(+), 77 deletions(-) diff --git a/DiligentCore b/DiligentCore index b3fec8b..ff88c05 160000 --- a/DiligentCore +++ b/DiligentCore @@ -1 +1 @@ -Subproject commit b3fec8bd40e80115086281bce74774617aa95e23 +Subproject commit ff88c0507d8e8d4571b00adb421557bca1f4ed48 diff --git a/DiligentFX b/DiligentFX index 202c54b..0210497 160000 --- a/DiligentFX +++ b/DiligentFX @@ -1 +1 @@ -Subproject commit 202c54b91d96ae8910574b253758bf0699ae57cf +Subproject commit 0210497f58607308685ca3c6e0afe7980d614b5d diff --git a/DiligentSamples b/DiligentSamples index fba172e..8fc7c7c 160000 --- a/DiligentSamples +++ b/DiligentSamples @@ -1 +1 @@ -Subproject commit fba172ebb923b53d8633693a7aae315690cc8bed +Subproject commit 8fc7c7c9f6a7f01ba384731dc814b8782684c76b diff --git a/DiligentTools b/DiligentTools index 8a8c9c1..17ce088 160000 --- a/DiligentTools +++ b/DiligentTools @@ -1 +1 @@ -Subproject commit 8a8c9c12289ad2b0fe2044f3e38ef436b7716260 +Subproject commit 17ce0880a5a53f62e84c950d0bc542db2bf33b80 diff --git a/Projects/Asteroids/src/asteroids_DE.cpp b/Projects/Asteroids/src/asteroids_DE.cpp index 9c15e47..80a8338 100644 --- a/Projects/Asteroids/src/asteroids_DE.cpp +++ b/Projects/Asteroids/src/asteroids_DE.cpp @@ -298,8 +298,9 @@ Asteroids::Asteroids(const Settings& settings, AsteroidsSimulation* asteroids, G // create pipeline state { - PipelineStateCreateInfo PSOCreateInfo; - PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc; + GraphicsPipelineStateCreateInfo PSOCreateInfo; + PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc; + GraphicsPipelineDesc& GraphicsPipeline = PSOCreateInfo.GraphicsPipeline; // clang-format off LayoutElement inputDesc[] = @@ -310,11 +311,11 @@ Asteroids::Asteroids(const Settings& settings, AsteroidsSimulation* asteroids, G }; // clang-format on - PSODesc.GraphicsPipeline.InputLayout.LayoutElements = inputDesc; + GraphicsPipeline.InputLayout.LayoutElements = inputDesc; // In bindless mode we will use instance ID buffer as the third input - PSODesc.GraphicsPipeline.InputLayout.NumElements = (m_BindingMode == BindingMode::Bindless) ? 3 : 2; + GraphicsPipeline.InputLayout.NumElements = (m_BindingMode == BindingMode::Bindless) ? 3 : 2; - PSODesc.GraphicsPipeline.DepthStencilDesc.DepthFunc = COMPARISON_FUNC_GREATER_EQUAL; + GraphicsPipeline.DepthStencilDesc.DepthFunc = COMPARISON_FUNC_GREATER_EQUAL; RefCntAutoPtr vs, ps; { @@ -379,15 +380,16 @@ Asteroids::Asteroids(const Settings& settings, AsteroidsSimulation* asteroids, G PSODesc.ResourceLayout.Variables = Variables.data(); PSODesc.ResourceLayout.NumVariables = static_cast(Variables.size()); - PSODesc.GraphicsPipeline.RTVFormats[0] = mSwapChain->GetDesc().ColorBufferFormat; - PSODesc.GraphicsPipeline.NumRenderTargets = 1; - PSODesc.GraphicsPipeline.DSVFormat = mSwapChain->GetDesc().DepthBufferFormat; - PSODesc.GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - PSODesc.Name = "Asteroids PSO"; + GraphicsPipeline.RTVFormats[0] = mSwapChain->GetDesc().ColorBufferFormat; + GraphicsPipeline.NumRenderTargets = 1; + GraphicsPipeline.DSVFormat = mSwapChain->GetDesc().DepthBufferFormat; + GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - PSODesc.GraphicsPipeline.pVS = vs; - PSODesc.GraphicsPipeline.pPS = ps; - mDevice->CreatePipelineState(PSOCreateInfo, &mAsteroidsPSO); + PSODesc.Name = "Asteroids PSO"; + + PSOCreateInfo.pVS = vs; + PSOCreateInfo.pPS = ps; + mDevice->CreateGraphicsPipelineState(PSOCreateInfo, &mAsteroidsPSO); mAsteroidsPSO->GetStaticVariableByName(SHADER_TYPE_VERTEX, "DrawConstantBuffer")->Set(mDrawConstantBuffer); Uint32 NumSRBs = 0; @@ -466,8 +468,9 @@ Asteroids::Asteroids(const Settings& settings, AsteroidsSimulation* asteroids, G attribs.Desc.ShaderType = SHADER_TYPE_PIXEL; mDevice->CreateShader(attribs, &ps); - PipelineStateCreateInfo PSOCreateInfo; - PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc; + GraphicsPipelineStateCreateInfo PSOCreateInfo; + PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc; + GraphicsPipelineDesc& GraphicsPipeline = PSOCreateInfo.GraphicsPipeline; PSODesc.ResourceLayout.DefaultVariableType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; @@ -484,20 +487,22 @@ Asteroids::Asteroids(const Settings& settings, AsteroidsSimulation* asteroids, G PSODesc.ResourceLayout.StaticSamplers = &ssdesc; PSODesc.ResourceLayout.NumStaticSamplers = 1; - PSODesc.Name = "Skybox PSO"; - PSODesc.GraphicsPipeline.InputLayout.LayoutElements = inputDesc; - PSODesc.GraphicsPipeline.InputLayout.NumElements = _countof(inputDesc); + PSODesc.Name = "Skybox PSO"; + + GraphicsPipeline.InputLayout.LayoutElements = inputDesc; + GraphicsPipeline.InputLayout.NumElements = _countof(inputDesc); + + GraphicsPipeline.DepthStencilDesc.DepthFunc = COMPARISON_FUNC_GREATER_EQUAL; - PSODesc.GraphicsPipeline.DepthStencilDesc.DepthFunc = COMPARISON_FUNC_GREATER_EQUAL; - PSODesc.GraphicsPipeline.pVS = vs; - PSODesc.GraphicsPipeline.pPS = ps; + PSOCreateInfo.pVS = vs; + PSOCreateInfo.pPS = ps; - PSODesc.GraphicsPipeline.RTVFormats[0] = mSwapChain->GetDesc().ColorBufferFormat; - PSODesc.GraphicsPipeline.NumRenderTargets = 1; - PSODesc.GraphicsPipeline.DSVFormat = mSwapChain->GetDesc().DepthBufferFormat; - PSODesc.GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + GraphicsPipeline.RTVFormats[0] = mSwapChain->GetDesc().ColorBufferFormat; + GraphicsPipeline.NumRenderTargets = 1; + GraphicsPipeline.DSVFormat = mSwapChain->GetDesc().DepthBufferFormat; + GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - mDevice->CreatePipelineState(PSOCreateInfo, &mSkyboxPSO); + mDevice->CreateGraphicsPipelineState(PSOCreateInfo, &mSkyboxPSO); mSkyboxPSO->GetStaticVariableByName(SHADER_TYPE_VERTEX, "SkyboxConstantBuffer")->Set(mSkyboxConstantBuffer); mSkyboxPSO->GetStaticVariableByName(SHADER_TYPE_PIXEL, "Skybox")->Set(mSkyboxSRV); mSkyboxPSO->CreateShaderResourceBinding(&mSkyboxSRB, true); @@ -524,8 +529,9 @@ Asteroids::Asteroids(const Settings& settings, AsteroidsSimulation* asteroids, G // Sprites and fonts { - PipelineStateCreateInfo PSOCreateInfo; - PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc; + GraphicsPipelineStateCreateInfo PSOCreateInfo; + PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc; + GraphicsPipelineDesc& GraphicsPipeline = PSOCreateInfo.GraphicsPipeline; // clang-format off LayoutElement inputDesc[] = @@ -535,10 +541,10 @@ Asteroids::Asteroids(const Settings& settings, AsteroidsSimulation* asteroids, G }; // clang-format on - PSODesc.GraphicsPipeline.InputLayout.LayoutElements = inputDesc; - PSODesc.GraphicsPipeline.InputLayout.NumElements = _countof(inputDesc); + GraphicsPipeline.InputLayout.LayoutElements = inputDesc; + GraphicsPipeline.InputLayout.NumElements = _countof(inputDesc); - auto& BlendState = PSODesc.GraphicsPipeline.BlendDesc; + auto& BlendState = GraphicsPipeline.BlendDesc; { // Premultiplied over blend BlendState.RenderTargets[0].BlendEnable = TRUE; @@ -547,12 +553,12 @@ Asteroids::Asteroids(const Settings& settings, AsteroidsSimulation* asteroids, G BlendState.RenderTargets[0].DestBlend = BLEND_FACTOR_INV_SRC_ALPHA; } - PSODesc.GraphicsPipeline.DepthStencilDesc.DepthEnable = false; + GraphicsPipeline.DepthStencilDesc.DepthEnable = false; - PSODesc.GraphicsPipeline.RTVFormats[0] = mSwapChain->GetDesc().ColorBufferFormat; - PSODesc.GraphicsPipeline.NumRenderTargets = 1; - PSODesc.GraphicsPipeline.DSVFormat = mSwapChain->GetDesc().DepthBufferFormat; - PSODesc.GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + GraphicsPipeline.RTVFormats[0] = mSwapChain->GetDesc().ColorBufferFormat; + GraphicsPipeline.NumRenderTargets = 1; + GraphicsPipeline.DSVFormat = mSwapChain->GetDesc().DepthBufferFormat; + GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; RefCntAutoPtr sprite_vs, sprite_ps, font_ps; { @@ -593,15 +599,15 @@ Asteroids::Asteroids(const Settings& settings, AsteroidsSimulation* asteroids, G PSODesc.Name = "Sprite PSO"; PSODesc.ResourceLayout.DefaultVariableType = SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC; - PSODesc.GraphicsPipeline.pVS = sprite_vs; - PSODesc.GraphicsPipeline.pPS = sprite_ps; - mDevice->CreatePipelineState(PSOCreateInfo, &mSpritePSO); + PSOCreateInfo.pVS = sprite_vs; + PSOCreateInfo.pPS = sprite_ps; + mDevice->CreateGraphicsPipelineState(PSOCreateInfo, &mSpritePSO); mSpritePSO->CreateShaderResourceBinding(&mSpriteSRB, true); PSODesc.Name = "Font PSO"; PSODesc.ResourceLayout.DefaultVariableType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; - PSODesc.GraphicsPipeline.pPS = font_ps; - mDevice->CreatePipelineState(PSOCreateInfo, &mFontPSO); + PSOCreateInfo.pPS = font_ps; + mDevice->CreateGraphicsPipelineState(PSOCreateInfo, &mFontPSO); mFontPSO->GetStaticVariableByName(SHADER_TYPE_PIXEL, "Tex")->Set(mFontTextureSRV); mFontPSO->CreateShaderResourceBinding(&mFontSRB, true); } diff --git a/unityplugin/GhostCubePlugin/PluginSource/src/SamplePlugin.cpp b/unityplugin/GhostCubePlugin/PluginSource/src/SamplePlugin.cpp index ed7da87..a9a5f24 100644 --- a/unityplugin/GhostCubePlugin/PluginSource/src/SamplePlugin.cpp +++ b/unityplugin/GhostCubePlugin/PluginSource/src/SamplePlugin.cpp @@ -43,24 +43,26 @@ SamplePlugin::SamplePlugin(Diligent::IRenderDevice *pDevice, bool UseReverseZ, T { auto deviceType = pDevice->GetDeviceCaps().DevType; { - PipelineStateCreateInfo PSOCreateInfo; - PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc; + GraphicsPipelineStateCreateInfo PSOCreateInfo; + PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc; + GraphicsPipelineDesc& GraphicsPipeline = PSOCreateInfo.GraphicsPipeline; PSODesc.PipelineType = PIPELINE_TYPE_GRAPHICS; - PSODesc.Name = "Render sample cube PSO"; - PSODesc.GraphicsPipeline.NumRenderTargets = 1; - PSODesc.GraphicsPipeline.RTVFormats[0] = RTVFormat; - PSODesc.GraphicsPipeline.DSVFormat = DSVFormat; - PSODesc.GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - PSODesc.GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_BACK; - PSODesc.GraphicsPipeline.RasterizerDesc.FrontCounterClockwise = deviceType == RENDER_DEVICE_TYPE_D3D11 || deviceType == RENDER_DEVICE_TYPE_D3D12 ? true : false; - PSODesc.GraphicsPipeline.DepthStencilDesc.DepthFunc = UseReverseZ ? COMPARISON_FUNC_GREATER_EQUAL : COMPARISON_FUNC_LESS_EQUAL; - - PSODesc.GraphicsPipeline.BlendDesc.RenderTargets[0].BlendEnable = True; - PSODesc.GraphicsPipeline.BlendDesc.RenderTargets[0].SrcBlend = BLEND_FACTOR_SRC_ALPHA; - PSODesc.GraphicsPipeline.BlendDesc.RenderTargets[0].DestBlend = BLEND_FACTOR_INV_SRC_ALPHA; - PSODesc.GraphicsPipeline.BlendDesc.RenderTargets[0].SrcBlendAlpha = BLEND_FACTOR_ZERO; - PSODesc.GraphicsPipeline.BlendDesc.RenderTargets[0].DestBlendAlpha = BLEND_FACTOR_ONE; + PSODesc.Name = "Render sample cube PSO"; + + GraphicsPipeline.NumRenderTargets = 1; + GraphicsPipeline.RTVFormats[0] = RTVFormat; + GraphicsPipeline.DSVFormat = DSVFormat; + GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_BACK; + GraphicsPipeline.RasterizerDesc.FrontCounterClockwise = deviceType == RENDER_DEVICE_TYPE_D3D11 || deviceType == RENDER_DEVICE_TYPE_D3D12 ? true : false; + GraphicsPipeline.DepthStencilDesc.DepthFunc = UseReverseZ ? COMPARISON_FUNC_GREATER_EQUAL : COMPARISON_FUNC_LESS_EQUAL; + + GraphicsPipeline.BlendDesc.RenderTargets[0].BlendEnable = True; + GraphicsPipeline.BlendDesc.RenderTargets[0].SrcBlend = BLEND_FACTOR_SRC_ALPHA; + GraphicsPipeline.BlendDesc.RenderTargets[0].DestBlend = BLEND_FACTOR_INV_SRC_ALPHA; + GraphicsPipeline.BlendDesc.RenderTargets[0].SrcBlendAlpha = BLEND_FACTOR_ZERO; + GraphicsPipeline.BlendDesc.RenderTargets[0].DestBlendAlpha = BLEND_FACTOR_ONE; ShaderCreateInfo ShaderCI; ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL; @@ -93,11 +95,11 @@ SamplePlugin::SamplePlugin(Diligent::IRenderDevice *pDevice, bool UseReverseZ, T }; PSODesc.ResourceLayout.DefaultVariableType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; - PSODesc.GraphicsPipeline.pVS = pVS; - PSODesc.GraphicsPipeline.pPS = pPS; - PSODesc.GraphicsPipeline.InputLayout.LayoutElements = LayoutElems; - PSODesc.GraphicsPipeline.InputLayout.NumElements = _countof(LayoutElems); - pDevice->CreatePipelineState(PSOCreateInfo, &m_PSO); + PSOCreateInfo.pVS = pVS; + PSOCreateInfo.pPS = pPS; + GraphicsPipeline.InputLayout.LayoutElements = LayoutElems; + GraphicsPipeline.InputLayout.NumElements = _countof(LayoutElems); + pDevice->CreateGraphicsPipelineState(PSOCreateInfo, &m_PSO); m_PSO->GetStaticVariableByName(SHADER_TYPE_VERTEX, "Constants")->Set(m_VSConstants); m_PSO->CreateShaderResourceBinding(&m_SRB, true); } diff --git a/unityplugin/GhostCubeScene/src/GhostCubeScene.cpp b/unityplugin/GhostCubeScene/src/GhostCubeScene.cpp index 3b63cdf..8586090 100644 --- a/unityplugin/GhostCubeScene/src/GhostCubeScene.cpp +++ b/unityplugin/GhostCubeScene/src/GhostCubeScene.cpp @@ -86,18 +86,19 @@ void GhostCubeScene::OnGraphicsInitialized() const auto &SCDesc = m_DiligentGraphics->GetSwapChain()->GetDesc(); auto UseReverseZ = m_DiligentGraphics->UsesReverseZ(); - PipelineStateCreateInfo PSOCreateInfo; - PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc; + GraphicsPipelineStateCreateInfo PSOCreateInfo; + PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc; + GraphicsPipelineDesc& GraphicsPipeline = PSOCreateInfo.GraphicsPipeline; PSODesc.PipelineType = PIPELINE_TYPE_GRAPHICS; PSODesc.Name = "Mirror PSO"; - PSODesc.GraphicsPipeline.NumRenderTargets = 1; + GraphicsPipeline.NumRenderTargets = 1; - PSODesc.GraphicsPipeline.RTVFormats[0] = SCDesc.ColorBufferFormat; - PSODesc.GraphicsPipeline.DSVFormat = SCDesc.DepthBufferFormat; - PSODesc.GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; - PSODesc.GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_BACK; - PSODesc.GraphicsPipeline.DepthStencilDesc.DepthFunc = UseReverseZ ? COMPARISON_FUNC_GREATER_EQUAL : COMPARISON_FUNC_LESS_EQUAL; + GraphicsPipeline.RTVFormats[0] = SCDesc.ColorBufferFormat; + GraphicsPipeline.DSVFormat = SCDesc.DepthBufferFormat; + GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; + GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_BACK; + GraphicsPipeline.DepthStencilDesc.DepthFunc = UseReverseZ ? COMPARISON_FUNC_GREATER_EQUAL : COMPARISON_FUNC_LESS_EQUAL; ShaderCreateInfo ShaderCI; RefCntAutoPtr pShaderSourceFactory; @@ -135,9 +136,9 @@ void GhostCubeScene::OnGraphicsInitialized() PSODesc.ResourceLayout.StaticSamplers = StaticSamplers; PSODesc.ResourceLayout.NumStaticSamplers = _countof(StaticSamplers); - PSODesc.GraphicsPipeline.pVS = pVS; - PSODesc.GraphicsPipeline.pPS = pPS; - pDevice->CreatePipelineState(PSOCreateInfo, &m_pMirrorPSO); + PSOCreateInfo.pVS = pVS; + PSOCreateInfo.pPS = pPS; + pDevice->CreateGraphicsPipelineState(PSOCreateInfo, &m_pMirrorPSO); m_pMirrorPSO->GetStaticVariableByName(SHADER_TYPE_VERTEX, "Constants")->Set(m_pMirrorVSConstants); m_pMirrorPSO->GetStaticVariableByName(SHADER_TYPE_PIXEL, "g_tex2Reflection")->Set(m_pRenderTarget->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE)); m_pMirrorPSO->CreateShaderResourceBinding(&m_pMirrorSRB, true); -- cgit v1.2.3