Skip to content

Commit

Permalink
[D3D11] Also made Domain shader a separate implementation.
Browse files Browse the repository at this point in the history
D3D11DomainShader (aka tessellation-evaluation shader) has a separate implementation nopw, just like D3D11VertexShader.
This provides the same proxy geometry shader when this shader stage is used for stream-output.
  • Loading branch information
LukasBanana committed Oct 9, 2024
1 parent b1e3378 commit 5ec2b8b
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 19 deletions.
14 changes: 10 additions & 4 deletions sources/Renderer/Direct3D11/D3D11RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "RenderState/D3D11ComputePSO.h"

#include "Shader/D3D11CommonShader.h"
#include "Shader/D3D11DomainShader.h"
#include "Shader/D3D11VertexShader.h"

#include <LLGL/Backend/Direct3D11/NativeHandle.h>
Expand Down Expand Up @@ -416,10 +417,15 @@ void D3D11RenderSystem::Release(RenderTarget& renderTarget)
Shader* D3D11RenderSystem::CreateShader(const ShaderDescriptor& shaderDesc)
{
RenderSystem::AssertCreateShader(shaderDesc);
if (shaderDesc.type == ShaderType::Vertex)
return shaders_.emplace<D3D11VertexShader>(device_.Get(), shaderDesc);
else
return shaders_.emplace<D3D11CommonShader>(device_.Get(), shaderDesc);
switch (shaderDesc.type)
{
case ShaderType::Vertex:
return shaders_.emplace<D3D11VertexShader>(device_.Get(), shaderDesc);
case ShaderType::TessEvaluation:
return shaders_.emplace<D3D11DomainShader>(device_.Get(), shaderDesc);
default:
return shaders_.emplace<D3D11CommonShader>(device_.Get(), shaderDesc);
}
}

void D3D11RenderSystem::Release(Shader& shader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "D3D11PipelineLayout.h"
#include "../D3D11Types.h"
#include "../D3D11ObjectUtils.h"
#include "../Shader/D3D11DomainShader.h"
#include "../Shader/D3D11VertexShader.h"
#include "../../CheckedCast.h"
#include "../../PipelineStateUtils.h"
Expand Down Expand Up @@ -65,6 +66,13 @@ D3D11GraphicsPSOBase::D3D11GraphicsPSOBase(const GraphicsPipelineDescriptor& des
else
ResetReport("cannot create D3D graphics PSO without vertex shader", true);

/* Override proxy geometry shader if the domain shader has one */
if (auto* domainShaderD3D = LLGL_CAST(const D3D11DomainShader*, desc.tessEvaluationShader))
{
if (domainShaderD3D->GetProxyGeometryShader())
gs_ = domainShaderD3D->GetProxyGeometryShader();
}

GetD3DNativeShaders(desc);

/* Store dynamic pipeline states */
Expand Down
33 changes: 33 additions & 0 deletions sources/Renderer/Direct3D11/Shader/D3D11DomainShader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* D3D11DomainShader.cpp
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#include "D3D11DomainShader.h"


namespace LLGL
{


D3D11DomainShader::D3D11DomainShader(ID3D11Device* device, const ShaderDescriptor& desc) :
D3D11Shader { desc.type }
{
if (BuildShader(device, desc))
{
/* Build optional proxy geometry shader if there are any output attributes */
if (!desc.vertex.outputAttribs.empty())
BuildProxyGeometryShader(device, desc, proxyGeomtryShader_);
}
if (desc.debugName != nullptr)
SetDebugName(desc.debugName);
}


} // /namespace LLGL



// ================================================================================
48 changes: 48 additions & 0 deletions sources/Renderer/Direct3D11/Shader/D3D11DomainShader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* D3D11DomainShader.h
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#ifndef LLGL_D3D11_DOMAIN_SHADER_H
#define LLGL_D3D11_DOMAIN_SHADER_H


#include "D3D11Shader.h"


namespace LLGL
{


// The domain shader has its own implementation to store additional information,
// optional proxy geometry-shader for stream-outputs that is.
class D3D11DomainShader final : public D3D11Shader
{

public:

D3D11DomainShader(ID3D11Device* device, const ShaderDescriptor& desc);

// Returns the proxy geometry shader for stream-output if there is one.
inline const ComPtr<ID3D11GeometryShader>& GetProxyGeometryShader() const
{
return proxyGeomtryShader_;
}

private:

ComPtr<ID3D11GeometryShader> proxyGeomtryShader_;

};


} // /namespace LLGL


#endif



// ================================================================================
23 changes: 23 additions & 0 deletions sources/Renderer/Direct3D11/Shader/D3D11Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,29 @@ bool D3D11Shader::BuildShader(ID3D11Device* device, const ShaderDescriptor& shad
return LoadBinary(device, shaderDesc);
}

bool D3D11Shader::BuildProxyGeometryShader(ID3D11Device* device, const ShaderDescriptor& shaderDesc, ComPtr<ID3D11GeometryShader>& outProxyGeomtryShader)
{
/*
Pass vertex shader bytecode into ID3D11Device::CreateGeometryShaderWithStreamOutput().
This can also be the output of D3DGetOutputSignatureBlob(), but we already have the compiled shader bytecode, which is also supported.
*/
ComPtr<ID3D11DeviceChild> geometryShader = D3D11Shader::CreateNativeShaderFromBlob(
device,
ShaderType::Geometry,
GetByteCode(),
shaderDesc.vertex.outputAttribs.size(),
shaderDesc.vertex.outputAttribs.data()
);

if (geometryShader)
{
geometryShader.As<ID3D11GeometryShader>(&outProxyGeomtryShader);
return true;
}

return false;
}


/*
* ======= Private: =======
Expand Down
1 change: 1 addition & 0 deletions sources/Renderer/Direct3D11/Shader/D3D11Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class D3D11Shader : public Shader
protected:

bool BuildShader(ID3D11Device* device, const ShaderDescriptor& shaderDesc);
bool BuildProxyGeometryShader(ID3D11Device* device, const ShaderDescriptor& shaderDesc, ComPtr<ID3D11GeometryShader>& outProxyGeomtryShader);

private:

Expand Down
15 changes: 1 addition & 14 deletions sources/Renderer/Direct3D11/Shader/D3D11VertexShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,7 @@ D3D11VertexShader::D3D11VertexShader(ID3D11Device* device, const ShaderDescripto

/* Build optional proxy geometry shader if there are any output attributes */
if (!desc.vertex.outputAttribs.empty())
{
/*
Pass vertex shader bytecode into ID3D11Device::CreateGeometryShaderWithStreamOutput().
This can also be the output of D3DGetOutputSignatureBlob(), but we already have the compiled shader bytecode, which is also supported.
*/
ComPtr<ID3D11DeviceChild> geometryShader = D3D11Shader::CreateNativeShaderFromBlob(
device,
ShaderType::Geometry,
GetByteCode(),
desc.vertex.outputAttribs.size(),
desc.vertex.outputAttribs.data()
);
geometryShader.As<ID3D11GeometryShader>(&proxyGeomtryShader_);
}
BuildProxyGeometryShader(device, desc, proxyGeomtryShader_);
}
if (desc.debugName != nullptr)
SetDebugName(desc.debugName);
Expand Down
2 changes: 1 addition & 1 deletion sources/Renderer/Direct3D11/Shader/D3D11VertexShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace LLGL


// The vertex shader has its own implementation to store additional information,
// input-layout and an optional proxyt geometry-shader for stream-outputs that is.
// input-layout and an optional proxy geometry-shader for stream-outputs that is.
class D3D11VertexShader final : public D3D11Shader
{

Expand Down

0 comments on commit 5ec2b8b

Please sign in to comment.