d3d11: enable ColorStateTests and CommandEncoderTests

Bug: dawn:1705
Change-Id: I2d477ea3d9a42332f21c61c9b2b1d2ac48d8e631
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/128760
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Peng Huang 2023-04-25 10:58:29 +00:00 committed by Dawn LUCI CQ
parent 90d5154b5f
commit 96b09d29b2
5 changed files with 39 additions and 4 deletions

View File

@ -726,7 +726,7 @@ MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass,
case Command::SetRenderPipeline: { case Command::SetRenderPipeline: {
SetRenderPipelineCmd* cmd = iter->NextCommand<SetRenderPipelineCmd>(); SetRenderPipelineCmd* cmd = iter->NextCommand<SetRenderPipelineCmd>();
lastPipeline = ToBackend(cmd->pipeline).Get(); lastPipeline = ToBackend(cmd->pipeline.Get());
lastPipeline->ApplyNow(commandContext, blendColor, stencilReference); lastPipeline->ApplyNow(commandContext, blendColor, stencilReference);
bindGroupTracker.OnSetPipeline(lastPipeline); bindGroupTracker.OnSetPipeline(lastPipeline);
@ -802,6 +802,9 @@ MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass,
case Command::SetStencilReference: { case Command::SetStencilReference: {
SetStencilReferenceCmd* cmd = mCommands.NextCommand<SetStencilReferenceCmd>(); SetStencilReferenceCmd* cmd = mCommands.NextCommand<SetStencilReferenceCmd>();
stencilReference = cmd->reference; stencilReference = cmd->reference;
if (lastPipeline) {
lastPipeline->ApplyDepthStencilState(commandContext, stencilReference);
}
return {}; return {};
} }
@ -832,6 +835,9 @@ MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass,
case Command::SetBlendConstant: { case Command::SetBlendConstant: {
SetBlendConstantCmd* cmd = mCommands.NextCommand<SetBlendConstantCmd>(); SetBlendConstantCmd* cmd = mCommands.NextCommand<SetBlendConstantCmd>();
blendColor = ConvertToFloatColor(cmd->color); blendColor = ConvertToFloatColor(cmd->color);
if (lastPipeline) {
lastPipeline->ApplyBlendState(commandContext, blendColor);
}
break; break;
} }

View File

@ -200,7 +200,20 @@ void RenderPipeline::ApplyNow(CommandRecordingContext* commandContext,
d3dDeviceContext1->RSSetState(mRasterizerState.Get()); d3dDeviceContext1->RSSetState(mRasterizerState.Get());
d3dDeviceContext1->VSSetShader(mVertexShader.Get(), nullptr, 0); d3dDeviceContext1->VSSetShader(mVertexShader.Get(), nullptr, 0);
d3dDeviceContext1->PSSetShader(mPixelShader.Get(), nullptr, 0); d3dDeviceContext1->PSSetShader(mPixelShader.Get(), nullptr, 0);
ApplyBlendState(commandContext, blendColor);
ApplyDepthStencilState(commandContext, stencilReference);
}
void RenderPipeline::ApplyBlendState(CommandRecordingContext* commandContext,
const std::array<float, 4>& blendColor) {
ID3D11DeviceContext1* d3dDeviceContext1 = commandContext->GetD3D11DeviceContext1();
d3dDeviceContext1->OMSetBlendState(mBlendState.Get(), blendColor.data(), GetSampleMask()); d3dDeviceContext1->OMSetBlendState(mBlendState.Get(), blendColor.data(), GetSampleMask());
}
void RenderPipeline::ApplyDepthStencilState(CommandRecordingContext* commandContext,
uint32_t stencilReference) {
ID3D11DeviceContext1* d3dDeviceContext1 = commandContext->GetD3D11DeviceContext1();
d3dDeviceContext1->OMSetDepthStencilState(mDepthStencilState.Get(), stencilReference); d3dDeviceContext1->OMSetDepthStencilState(mDepthStencilState.Get(), stencilReference);
} }
@ -292,16 +305,27 @@ MaybeError RenderPipeline::InitializeBlendState() {
D3D11_RENDER_TARGET_BLEND_DESC& rtBlendDesc = D3D11_RENDER_TARGET_BLEND_DESC& rtBlendDesc =
blendDesc.RenderTarget[static_cast<uint8_t>(i)]; blendDesc.RenderTarget[static_cast<uint8_t>(i)];
const ColorTargetState* descriptor = GetColorTargetState(ColorAttachmentIndex(i)); const ColorTargetState* descriptor = GetColorTargetState(ColorAttachmentIndex(i));
if (descriptor->blend) { rtBlendDesc.BlendEnable = descriptor->blend != nullptr;
rtBlendDesc.BlendEnable = TRUE; if (rtBlendDesc.BlendEnable) {
rtBlendDesc.SrcBlend = D3DBlendFactor(descriptor->blend->color.srcFactor); rtBlendDesc.SrcBlend = D3DBlendFactor(descriptor->blend->color.srcFactor);
if (device->GetValidInternalFormat(descriptor->format).componentCount < 4 &&
rtBlendDesc.SrcBlend == D3D11_BLEND_DEST_ALPHA) {
// According to the D3D SPEC, the default value for missing components in an element
// format is "0" for any component except A, which gets "1". So here
// D3D11_BLEND_DEST_ALPHA should have same effect as D3D11_BLEND_ONE.
// Note that this replacement can be an optimization as using D3D11_BLEND_ONE means
// the GPU hardware no longer needs to get pixels from the destination texture. It
// can also be served as a workaround against an Intel driver issue about alpha
// blending (see http://crbug.com/dawn/1579 for more details).
rtBlendDesc.SrcBlend = D3D11_BLEND_ONE;
}
rtBlendDesc.DestBlend = D3DBlendFactor(descriptor->blend->color.dstFactor); rtBlendDesc.DestBlend = D3DBlendFactor(descriptor->blend->color.dstFactor);
rtBlendDesc.BlendOp = D3DBlendOperation(descriptor->blend->color.operation); rtBlendDesc.BlendOp = D3DBlendOperation(descriptor->blend->color.operation);
rtBlendDesc.SrcBlendAlpha = D3DBlendFactor(descriptor->blend->alpha.srcFactor); rtBlendDesc.SrcBlendAlpha = D3DBlendFactor(descriptor->blend->alpha.srcFactor);
rtBlendDesc.DestBlendAlpha = D3DBlendFactor(descriptor->blend->alpha.dstFactor); rtBlendDesc.DestBlendAlpha = D3DBlendFactor(descriptor->blend->alpha.dstFactor);
rtBlendDesc.BlendOpAlpha = D3DBlendOperation(descriptor->blend->alpha.operation); rtBlendDesc.BlendOpAlpha = D3DBlendOperation(descriptor->blend->alpha.operation);
rtBlendDesc.RenderTargetWriteMask = D3DColorWriteMask(descriptor->writeMask);
} }
rtBlendDesc.RenderTargetWriteMask = D3DColorWriteMask(descriptor->writeMask);
} }
DAWN_TRY(CheckHRESULT(device->GetD3D11Device()->CreateBlendState(&blendDesc, &mBlendState), DAWN_TRY(CheckHRESULT(device->GetD3D11Device()->CreateBlendState(&blendDesc, &mBlendState),

View File

@ -39,6 +39,9 @@ class RenderPipeline final : public RenderPipelineBase {
void ApplyNow(CommandRecordingContext* commandContext, void ApplyNow(CommandRecordingContext* commandContext,
const std::array<float, 4>& blendColor, const std::array<float, 4>& blendColor,
uint32_t stencilReference); uint32_t stencilReference);
void ApplyBlendState(CommandRecordingContext* commandContext,
const std::array<float, 4>& blendColor);
void ApplyDepthStencilState(CommandRecordingContext* commandContext, uint32_t stencilReference);
bool GetUsesVertexOrInstanceIndex() const; bool GetUsesVertexOrInstanceIndex() const;

View File

@ -1189,6 +1189,7 @@ TEST_P(ColorStateTest, SrcBlendFactorDstAlphaDstBlendFactorZero) {
} }
DAWN_INSTANTIATE_TEST(ColorStateTest, DAWN_INSTANTIATE_TEST(ColorStateTest,
D3D11Backend(),
D3D12Backend(), D3D12Backend(),
MetalBackend(), MetalBackend(),
OpenGLBackend(), OpenGLBackend(),

View File

@ -46,6 +46,7 @@ TEST_P(CommandEncoderTests, WriteBuffer) {
} }
DAWN_INSTANTIATE_TEST(CommandEncoderTests, DAWN_INSTANTIATE_TEST(CommandEncoderTests,
D3D11Backend(),
D3D12Backend(), D3D12Backend(),
MetalBackend(), MetalBackend(),
OpenGLBackend(), OpenGLBackend(),