Add GPUContext::SetStencilRef to stencil reference value
This commit is contained in:
@@ -321,6 +321,12 @@ public:
|
||||
/// <param name="value">Blend factors, one for each RGBA component.</param>
|
||||
API_FUNCTION() virtual void SetBlendFactor(const Float4& value) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the reference value for depth stencil tests.
|
||||
/// </summary>
|
||||
/// <param name="value">Reference value to perform against when doing a depth-stencil test.</param>
|
||||
API_FUNCTION() virtual void SetStencilRef(uint32 value) = 0;
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Unbinds all shader resource slots and flushes the change with the driver (used to prevent driver detection of resource hazards, eg. when down-scaling the texture).
|
||||
|
||||
@@ -103,6 +103,7 @@ void GPUContextDX11::FrameBegin()
|
||||
CurrentPS = nullptr;
|
||||
CurrentCS = nullptr;
|
||||
CurrentPrimitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
|
||||
CurrentStencilRef = 0;
|
||||
CurrentBlendFactor = Float4::One;
|
||||
|
||||
// Bind static samplers
|
||||
@@ -275,6 +276,12 @@ void GPUContextDX11::SetBlendFactor(const Float4& value)
|
||||
_context->OMSetBlendState(CurrentBlendState, CurrentBlendFactor.Raw, D3D11_DEFAULT_SAMPLE_MASK);
|
||||
}
|
||||
|
||||
void GPUContextDX11::SetStencilRef(uint32 value)
|
||||
{
|
||||
if (CurrentStencilRef != value)
|
||||
_context->OMSetDepthStencilState(CurrentDepthStencilState, CurrentStencilRef);
|
||||
}
|
||||
|
||||
void GPUContextDX11::ResetSR()
|
||||
{
|
||||
_srDirtyFlag = false;
|
||||
@@ -559,7 +566,7 @@ void GPUContextDX11::SetState(GPUPipelineState* state)
|
||||
if (CurrentDepthStencilState != depthStencilState)
|
||||
{
|
||||
CurrentDepthStencilState = depthStencilState;
|
||||
_context->OMSetDepthStencilState(depthStencilState, 0);
|
||||
_context->OMSetDepthStencilState(depthStencilState, CurrentStencilRef);
|
||||
}
|
||||
if (CurrentRasterizerState != rasterizerState)
|
||||
{
|
||||
|
||||
@@ -61,6 +61,7 @@ private:
|
||||
GPUShaderProgramPSDX11* CurrentPS;
|
||||
GPUShaderProgramCSDX11* CurrentCS;
|
||||
D3D11_PRIMITIVE_TOPOLOGY CurrentPrimitiveTopology;
|
||||
uint32 CurrentStencilRef;
|
||||
Float4 CurrentBlendFactor;
|
||||
|
||||
public:
|
||||
@@ -117,6 +118,7 @@ public:
|
||||
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
|
||||
void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) override;
|
||||
void SetBlendFactor(const Float4& value) override;
|
||||
void SetStencilRef(uint32 value) override;
|
||||
void ResetSR() override;
|
||||
void ResetUA() override;
|
||||
void ResetCB() override;
|
||||
|
||||
@@ -222,6 +222,7 @@ void GPUContextDX12::Reset()
|
||||
_rtDepth = nullptr;
|
||||
_srMaskDirtyGraphics = 0;
|
||||
_srMaskDirtyCompute = 0;
|
||||
_stencilRef = 0;
|
||||
_psDirtyFlag = false;
|
||||
_isCompute = false;
|
||||
_currentCompute = nullptr;
|
||||
@@ -850,6 +851,15 @@ void GPUContextDX12::SetBlendFactor(const Float4& value)
|
||||
_commandList->OMSetBlendFactor(value.Raw);
|
||||
}
|
||||
|
||||
void GPUContextDX12::SetStencilRef(uint32 value)
|
||||
{
|
||||
if (_stencilRef != value)
|
||||
{
|
||||
_stencilRef = value;
|
||||
_commandList->OMSetStencilRef(value);
|
||||
}
|
||||
}
|
||||
|
||||
void GPUContextDX12::ResetSR()
|
||||
{
|
||||
for (int32 slot = 0; slot < GPU_MAX_SR_BINDED; slot++)
|
||||
|
||||
@@ -47,6 +47,7 @@ private:
|
||||
|
||||
uint32 _srMaskDirtyGraphics;
|
||||
uint32 _srMaskDirtyCompute;
|
||||
uint32 _stencilRef;
|
||||
|
||||
int32 _isCompute : 1;
|
||||
int32 _rtDirtyFlag : 1;
|
||||
@@ -167,6 +168,7 @@ public:
|
||||
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
|
||||
void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) override;
|
||||
void SetBlendFactor(const Float4& value) override;
|
||||
void SetStencilRef(uint32 value) override;
|
||||
void ResetSR() override;
|
||||
void ResetUA() override;
|
||||
void ResetCB() override;
|
||||
|
||||
@@ -88,6 +88,10 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void SetStencilRef(uint32 value) override
|
||||
{
|
||||
}
|
||||
|
||||
void ResetSR() override
|
||||
{
|
||||
}
|
||||
|
||||
@@ -727,6 +727,7 @@ void GPUContextVulkan::FrameBegin()
|
||||
_cbDirtyFlag = 0;
|
||||
_rtCount = 0;
|
||||
_vbCount = 0;
|
||||
_stencilRef = 0;
|
||||
_renderPass = nullptr;
|
||||
_currentState = nullptr;
|
||||
_rtDepth = nullptr;
|
||||
@@ -972,6 +973,16 @@ void GPUContextVulkan::SetBlendFactor(const Float4& value)
|
||||
vkCmdSetBlendConstants(cmdBuffer->GetHandle(), value.Raw);
|
||||
}
|
||||
|
||||
void GPUContextVulkan::SetStencilRef(uint32 value)
|
||||
{
|
||||
if (_stencilRef != value)
|
||||
{
|
||||
_stencilRef = value;
|
||||
const auto cmdBuffer = _cmdBufferManager->GetCmdBuffer();
|
||||
vkCmdSetStencilReference(cmdBuffer->GetHandle(), VK_STENCIL_FRONT_AND_BACK, _stencilRef);
|
||||
}
|
||||
}
|
||||
|
||||
void GPUContextVulkan::ResetSR()
|
||||
{
|
||||
Platform::MemoryClear(_srHandles, sizeof(_srHandles));
|
||||
|
||||
@@ -97,6 +97,7 @@ private:
|
||||
|
||||
int32 _rtCount;
|
||||
int32 _vbCount;
|
||||
uint32 _stencilRef;
|
||||
|
||||
RenderPassVulkan* _renderPass;
|
||||
GPUPipelineStateVulkan* _currentState;
|
||||
@@ -185,6 +186,7 @@ public:
|
||||
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
|
||||
void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) override;
|
||||
void SetBlendFactor(const Float4& value) override;
|
||||
void SetStencilRef(uint32 value) override;
|
||||
void ResetSR() override;
|
||||
void ResetUA() override;
|
||||
void ResetCB() override;
|
||||
|
||||
@@ -274,7 +274,7 @@ bool GPUPipelineStateVulkan::Init(const Description& desc)
|
||||
_descDynamic.pDynamicStates = _dynamicStates;
|
||||
_dynamicStates[_descDynamic.dynamicStateCount++] = VK_DYNAMIC_STATE_VIEWPORT;
|
||||
_dynamicStates[_descDynamic.dynamicStateCount++] = VK_DYNAMIC_STATE_SCISSOR;
|
||||
//_dynamicStates[_descDynamic.dynamicStateCount++] = VK_DYNAMIC_STATE_STENCIL_REFERENCE;
|
||||
_dynamicStates[_descDynamic.dynamicStateCount++] = VK_DYNAMIC_STATE_STENCIL_REFERENCE;
|
||||
static_assert(ARRAY_COUNT(_dynamicStates) <= 3, "Invalid dynamic states array.");
|
||||
_desc.pDynamicState = &_descDynamic;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user