Add GPUContext::SetBlendFactor

This commit is contained in:
Wojtek Figat
2023-02-01 11:07:48 +01:00
parent ab51ecddb4
commit 45a30990ba
9 changed files with 83 additions and 92 deletions

View File

@@ -103,6 +103,7 @@ void GPUContextDX11::FrameBegin()
CurrentPS = nullptr;
CurrentCS = nullptr;
CurrentPrimitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
CurrentBlendFactor = Float4::One;
// Bind static samplers
ID3D11SamplerState* samplers[] =
@@ -267,6 +268,13 @@ void GPUContextDX11::SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPU
}
}
void GPUContextDX11::SetBlendFactor(const Float4& value)
{
CurrentBlendFactor = value;
if (CurrentBlendState)
_context->OMSetBlendState(CurrentBlendState, CurrentBlendFactor.Raw, D3D11_DEFAULT_SAMPLE_MASK);
}
void GPUContextDX11::ResetSR()
{
_srDirtyFlag = false;
@@ -560,8 +568,7 @@ void GPUContextDX11::SetState(GPUPipelineState* state)
if (CurrentBlendState != blendState)
{
CurrentBlendState = blendState;
FLOAT blendFactor[4] = { 1, 1, 1, 1 };
_context->OMSetBlendState(blendState, blendFactor, D3D11_DEFAULT_SAMPLE_MASK);
_context->OMSetBlendState(blendState, CurrentBlendFactor.Raw, D3D11_DEFAULT_SAMPLE_MASK);
}
if (CurrentVS != vs)
{

View File

@@ -61,6 +61,7 @@ private:
GPUShaderProgramPSDX11* CurrentPS;
GPUShaderProgramCSDX11* CurrentCS;
D3D11_PRIMITIVE_TOPOLOGY CurrentPrimitiveTopology;
Float4 CurrentBlendFactor;
public:
@@ -115,6 +116,7 @@ public:
void SetRenderTarget(GPUTextureView* rt) override;
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) override;
void SetBlendFactor(const Float4& value) override;
void ResetSR() override;
void ResetUA() override;
void ResetCB() override;

View File

@@ -845,6 +845,11 @@ void GPUContextDX12::SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPU
}
}
void GPUContextDX12::SetBlendFactor(const Float4& value)
{
_commandList->OMSetBlendFactor(value.Raw);
}
void GPUContextDX12::ResetSR()
{
for (int32 slot = 0; slot < GPU_MAX_SR_BINDED; slot++)

View File

@@ -166,6 +166,7 @@ public:
void SetRenderTarget(GPUTextureView* rt) override;
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) override;
void SetBlendFactor(const Float4& value) override;
void ResetSR() override;
void ResetUA() override;
void ResetCB() override;

View File

@@ -84,6 +84,10 @@ public:
{
}
void SetBlendFactor(const Float4& value) override
{
}
void ResetSR() override
{
}

View File

@@ -966,6 +966,12 @@ void GPUContextVulkan::SetRenderTarget(GPUTextureView* depthBuffer, const Span<G
}
}
void GPUContextVulkan::SetBlendFactor(const Float4& value)
{
const auto cmdBuffer = _cmdBufferManager->GetCmdBuffer();
vkCmdSetBlendConstants(cmdBuffer->GetHandle(), value.Raw);
}
void GPUContextVulkan::ResetSR()
{
Platform::MemoryClear(_srHandles, sizeof(_srHandles));

View File

@@ -184,6 +184,7 @@ public:
void SetRenderTarget(GPUTextureView* rt) override;
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) override;
void SetBlendFactor(const Float4& value) override;
void ResetSR() override;
void ResetUA() override;
void ResetCB() override;