Add rasterizer and blend state to d3d pipeline state.

Change-Id: Iad34a99622cc1f356827377de74b61f339968d61
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/280408
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
Greg Daniel 2020-03-31 09:14:57 -04:00 committed by Skia Commit-Bot
parent 8cbedf9855
commit 0a335515bf
6 changed files with 118 additions and 12 deletions

View File

@ -112,6 +112,12 @@ static constexpr bool GrBlendCoeffRefsConstant(const GrBlendCoeff coeff) {
return coeff == kConstC_GrBlendCoeff || coeff == kIConstC_GrBlendCoeff; return coeff == kConstC_GrBlendCoeff || coeff == kIConstC_GrBlendCoeff;
} }
static constexpr bool GrBlendShouldDisable(GrBlendEquation equation, GrBlendCoeff srcCoeff,
GrBlendCoeff dstCoeff) {
return (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquation == equation) &&
kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff;
}
/** /**
* Advanced blend equations can always tweak alpha for coverage. (See GrCustomXfermode.cpp) * Advanced blend equations can always tweak alpha for coverage. (See GrCustomXfermode.cpp)
* *

View File

@ -9,6 +9,7 @@
#include "include/private/SkTemplates.h" #include "include/private/SkTemplates.h"
#include "src/gpu/GrProgramInfo.h" #include "src/gpu/GrProgramInfo.h"
#include "src/gpu/d3d/GrD3DGpu.h"
static DXGI_FORMAT attrib_type_to_format(GrVertexAttribType type) { static DXGI_FORMAT attrib_type_to_format(GrVertexAttribType type) {
switch (type) { switch (type) {
@ -107,7 +108,106 @@ static void setup_vertex_input_layout(const GrPrimitiveProcessor& primProc,
SkASSERT(instanceAttributeOffset == primProc.vertexStride()); SkASSERT(instanceAttributeOffset == primProc.vertexStride());
} }
std::unique_ptr<GrD3DPipelineState> GrD3DPipelineState::Make(const GrProgramInfo& programInfo) { static D3D12_BLEND blend_coeff_to_d3d_blend(GrBlendCoeff coeff) {
switch (coeff) {
case kZero_GrBlendCoeff:
return D3D12_BLEND_ZERO;
case kOne_GrBlendCoeff:
return D3D12_BLEND_ONE;
case kSC_GrBlendCoeff:
return D3D12_BLEND_SRC_COLOR;
case kISC_GrBlendCoeff:
return D3D12_BLEND_INV_SRC_COLOR;
case kDC_GrBlendCoeff:
return D3D12_BLEND_DEST_COLOR;
case kIDC_GrBlendCoeff:
return D3D12_BLEND_INV_DEST_COLOR;
case kSA_GrBlendCoeff:
return D3D12_BLEND_SRC_ALPHA;
case kISA_GrBlendCoeff:
return D3D12_BLEND_INV_SRC_ALPHA;
case kDA_GrBlendCoeff:
return D3D12_BLEND_DEST_ALPHA;
case kIDA_GrBlendCoeff:
return D3D12_BLEND_INV_DEST_ALPHA;
case kConstC_GrBlendCoeff:
return D3D12_BLEND_BLEND_FACTOR;
case kIConstC_GrBlendCoeff:
return D3D12_BLEND_INV_BLEND_FACTOR;
case kS2C_GrBlendCoeff:
return D3D12_BLEND_SRC1_COLOR;
case kIS2C_GrBlendCoeff:
return D3D12_BLEND_INV_SRC1_COLOR;
case kS2A_GrBlendCoeff:
return D3D12_BLEND_SRC1_ALPHA;
case kIS2A_GrBlendCoeff:
return D3D12_BLEND_INV_SRC1_ALPHA;
case kIllegal_GrBlendCoeff:
return D3D12_BLEND_ZERO;
}
SkUNREACHABLE;
}
static D3D12_BLEND_OP blend_equation_to_d3d_op(GrBlendEquation equation) {
switch (equation) {
case kAdd_GrBlendEquation:
return D3D12_BLEND_OP_ADD;
case kSubtract_GrBlendEquation:
return D3D12_BLEND_OP_SUBTRACT;
case kReverseSubtract_GrBlendEquation:
return D3D12_BLEND_OP_REV_SUBTRACT;
default:
SkUNREACHABLE;
}
}
static void fill_in_blend_state(const GrPipeline& pipeline, D3D12_BLEND_DESC* blendDesc) {
blendDesc->AlphaToCoverageEnable = false;
blendDesc->IndependentBlendEnable = false;
const GrXferProcessor::BlendInfo& blendInfo = pipeline.getXferProcessor().getBlendInfo();
GrBlendEquation equation = blendInfo.fEquation;
GrBlendCoeff srcCoeff = blendInfo.fSrcBlend;
GrBlendCoeff dstCoeff = blendInfo.fDstBlend;
bool blendOff = GrBlendShouldDisable(equation, srcCoeff, dstCoeff);
auto& rtBlend = blendDesc->RenderTarget[0];
rtBlend.BlendEnable = !blendOff;
if (!blendOff) {
rtBlend.SrcBlend = blend_coeff_to_d3d_blend(srcCoeff);
rtBlend.DestBlend = blend_coeff_to_d3d_blend(dstCoeff);
rtBlend.BlendOp = blend_equation_to_d3d_op(equation);
rtBlend.SrcBlendAlpha = blend_coeff_to_d3d_blend(srcCoeff);
rtBlend.DestBlendAlpha = blend_coeff_to_d3d_blend(dstCoeff);
rtBlend.BlendOpAlpha = blend_equation_to_d3d_op(equation);
}
if (!blendInfo.fWriteColor) {
rtBlend.RenderTargetWriteMask = 0;
} else {
rtBlend.RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
}
}
static void fill_in_rasterizer_state(const GrPipeline& pipeline, const GrCaps* caps,
D3D12_RASTERIZER_DESC* rasterizer) {
rasterizer->FillMode = (caps->wireframeMode() || pipeline.isWireframe()) ?
D3D12_FILL_MODE_WIREFRAME : D3D12_FILL_MODE_SOLID;
rasterizer->CullMode = D3D12_CULL_MODE_NONE;
rasterizer->FrontCounterClockwise = true;
rasterizer->DepthBias = 0;
rasterizer->DepthBiasClamp = 0.0f;
rasterizer->SlopeScaledDepthBias = 0.0f;
rasterizer->DepthClipEnable = false;
rasterizer->MultisampleEnable = pipeline.isHWAntialiasState();
rasterizer->AntialiasedLineEnable = false;
rasterizer->ForcedSampleCount = 0;
rasterizer->ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
}
std::unique_ptr<GrD3DPipelineState> GrD3DPipelineState::Make(GrD3DGpu* gpu,
const GrProgramInfo& programInfo) {
D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {}; D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
unsigned int totalAttributeCnt = programInfo.primProc().numVertexAttributes() + unsigned int totalAttributeCnt = programInfo.primProc().numVertexAttributes() +
@ -116,13 +216,16 @@ std::unique_ptr<GrD3DPipelineState> GrD3DPipelineState::Make(const GrProgramInfo
setup_vertex_input_layout(programInfo.primProc(), inputElements.get()); setup_vertex_input_layout(programInfo.primProc(), inputElements.get());
psoDesc.InputLayout = { inputElements.get(), totalAttributeCnt }; psoDesc.InputLayout = { inputElements.get(), totalAttributeCnt };
fill_in_blend_state(programInfo.pipeline(), &psoDesc.BlendState);
fill_in_rasterizer_state(programInfo.pipeline(), gpu->caps(), &psoDesc.RasterizerState);
// TODO: fill in the rest of the descriptor. // TODO: fill in the rest of the descriptor.
#if 0 #if 0
psoDesc.pRootSignature = m_rootSignature.Get(); psoDesc.pRootSignature = m_rootSignature.Get();
psoDesc.VS = { reinterpret_cast<UINT8*>(vertexShader->GetBufferPointer()), vertexShader->GetBufferSize() }; psoDesc.VS = { reinterpret_cast<UINT8*>(vertexShader->GetBufferPointer()), vertexShader->GetBufferSize() };
psoDesc.PS = { reinterpret_cast<UINT8*>(pixelShader->GetBufferPointer()), pixelShader->GetBufferSize() }; psoDesc.PS = { reinterpret_cast<UINT8*>(pixelShader->GetBufferPointer()), pixelShader->GetBufferSize() };
psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
psoDesc.DepthStencilState.DepthEnable = FALSE; psoDesc.DepthStencilState.DepthEnable = FALSE;
psoDesc.DepthStencilState.StencilEnable = FALSE; psoDesc.DepthStencilState.StencilEnable = FALSE;
psoDesc.SampleMask = UINT_MAX; psoDesc.SampleMask = UINT_MAX;

View File

@ -12,11 +12,12 @@
#include "src/gpu/d3d/GrD3D12.h" #include "src/gpu/d3d/GrD3D12.h"
#include <memory> #include <memory>
class GrD3DGpu;
class GrProgramInfo; class GrProgramInfo;
class GrD3DPipelineState { class GrD3DPipelineState {
public: public:
static std::unique_ptr<GrD3DPipelineState> Make(const GrProgramInfo&); static std::unique_ptr<GrD3DPipelineState> Make(GrD3DGpu* gpu, const GrProgramInfo&);
private: private:
GrD3DPipelineState(gr_cp<ID3D12PipelineState> pipelineState); GrD3DPipelineState(gr_cp<ID3D12PipelineState> pipelineState);

View File

@ -2493,10 +2493,8 @@ void GrGLGpu::flushBlendAndColorWrite(
// Any optimization to disable blending should have already been applied and // Any optimization to disable blending should have already been applied and
// tweaked the equation to "add" or "subtract", and the coeffs to (1, 0). // tweaked the equation to "add" or "subtract", and the coeffs to (1, 0).
bool blendOff = bool blendOff = GrBlendShouldDisable(equation, srcCoeff, dstCoeff) ||
((kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquation == equation) && !blendInfo.fWriteColor;
kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff) ||
!blendInfo.fWriteColor;
if (blendOff) { if (blendOff) {
if (kNo_TriState != fHWBlendState.fEnabled) { if (kNo_TriState != fHWBlendState.fEnabled) {

View File

@ -346,8 +346,7 @@ static MTLRenderPipelineColorAttachmentDescriptor* create_color_attachment(
GrBlendEquation equation = blendInfo.fEquation; GrBlendEquation equation = blendInfo.fEquation;
GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; GrBlendCoeff srcCoeff = blendInfo.fSrcBlend;
GrBlendCoeff dstCoeff = blendInfo.fDstBlend; GrBlendCoeff dstCoeff = blendInfo.fDstBlend;
bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquation == equation) && bool blendOff = GrBlendShouldDisable(equation, srcCoeff, dstCoeff);
kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff;
mtlColorAttachment.blendingEnabled = !blendOff; mtlColorAttachment.blendingEnabled = !blendOff;
if (!blendOff) { if (!blendOff) {

View File

@ -427,8 +427,7 @@ static void setup_color_blend_state(const GrPipeline& pipeline,
GrBlendEquation equation = blendInfo.fEquation; GrBlendEquation equation = blendInfo.fEquation;
GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; GrBlendCoeff srcCoeff = blendInfo.fSrcBlend;
GrBlendCoeff dstCoeff = blendInfo.fDstBlend; GrBlendCoeff dstCoeff = blendInfo.fDstBlend;
bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquation == equation) && bool blendOff = GrBlendShouldDisable(equation, srcCoeff, dstCoeff);
kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff;
memset(attachmentState, 0, sizeof(VkPipelineColorBlendAttachmentState)); memset(attachmentState, 0, sizeof(VkPipelineColorBlendAttachmentState));
attachmentState->blendEnable = !blendOff; attachmentState->blendEnable = !blendOff;