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:
parent
90d5154b5f
commit
96b09d29b2
|
@ -726,7 +726,7 @@ MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass,
|
|||
case Command::SetRenderPipeline: {
|
||||
SetRenderPipelineCmd* cmd = iter->NextCommand<SetRenderPipelineCmd>();
|
||||
|
||||
lastPipeline = ToBackend(cmd->pipeline).Get();
|
||||
lastPipeline = ToBackend(cmd->pipeline.Get());
|
||||
lastPipeline->ApplyNow(commandContext, blendColor, stencilReference);
|
||||
bindGroupTracker.OnSetPipeline(lastPipeline);
|
||||
|
||||
|
@ -802,6 +802,9 @@ MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass,
|
|||
case Command::SetStencilReference: {
|
||||
SetStencilReferenceCmd* cmd = mCommands.NextCommand<SetStencilReferenceCmd>();
|
||||
stencilReference = cmd->reference;
|
||||
if (lastPipeline) {
|
||||
lastPipeline->ApplyDepthStencilState(commandContext, stencilReference);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -832,6 +835,9 @@ MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass,
|
|||
case Command::SetBlendConstant: {
|
||||
SetBlendConstantCmd* cmd = mCommands.NextCommand<SetBlendConstantCmd>();
|
||||
blendColor = ConvertToFloatColor(cmd->color);
|
||||
if (lastPipeline) {
|
||||
lastPipeline->ApplyBlendState(commandContext, blendColor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -200,7 +200,20 @@ void RenderPipeline::ApplyNow(CommandRecordingContext* commandContext,
|
|||
d3dDeviceContext1->RSSetState(mRasterizerState.Get());
|
||||
d3dDeviceContext1->VSSetShader(mVertexShader.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());
|
||||
}
|
||||
|
||||
void RenderPipeline::ApplyDepthStencilState(CommandRecordingContext* commandContext,
|
||||
uint32_t stencilReference) {
|
||||
ID3D11DeviceContext1* d3dDeviceContext1 = commandContext->GetD3D11DeviceContext1();
|
||||
d3dDeviceContext1->OMSetDepthStencilState(mDepthStencilState.Get(), stencilReference);
|
||||
}
|
||||
|
||||
|
@ -292,16 +305,27 @@ MaybeError RenderPipeline::InitializeBlendState() {
|
|||
D3D11_RENDER_TARGET_BLEND_DESC& rtBlendDesc =
|
||||
blendDesc.RenderTarget[static_cast<uint8_t>(i)];
|
||||
const ColorTargetState* descriptor = GetColorTargetState(ColorAttachmentIndex(i));
|
||||
if (descriptor->blend) {
|
||||
rtBlendDesc.BlendEnable = TRUE;
|
||||
rtBlendDesc.BlendEnable = descriptor->blend != nullptr;
|
||||
if (rtBlendDesc.BlendEnable) {
|
||||
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.BlendOp = D3DBlendOperation(descriptor->blend->color.operation);
|
||||
rtBlendDesc.SrcBlendAlpha = D3DBlendFactor(descriptor->blend->alpha.srcFactor);
|
||||
rtBlendDesc.DestBlendAlpha = D3DBlendFactor(descriptor->blend->alpha.dstFactor);
|
||||
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),
|
||||
|
|
|
@ -39,6 +39,9 @@ class RenderPipeline final : public RenderPipelineBase {
|
|||
void ApplyNow(CommandRecordingContext* commandContext,
|
||||
const std::array<float, 4>& blendColor,
|
||||
uint32_t stencilReference);
|
||||
void ApplyBlendState(CommandRecordingContext* commandContext,
|
||||
const std::array<float, 4>& blendColor);
|
||||
void ApplyDepthStencilState(CommandRecordingContext* commandContext, uint32_t stencilReference);
|
||||
|
||||
bool GetUsesVertexOrInstanceIndex() const;
|
||||
|
||||
|
|
|
@ -1189,6 +1189,7 @@ TEST_P(ColorStateTest, SrcBlendFactorDstAlphaDstBlendFactorZero) {
|
|||
}
|
||||
|
||||
DAWN_INSTANTIATE_TEST(ColorStateTest,
|
||||
D3D11Backend(),
|
||||
D3D12Backend(),
|
||||
MetalBackend(),
|
||||
OpenGLBackend(),
|
||||
|
|
|
@ -46,6 +46,7 @@ TEST_P(CommandEncoderTests, WriteBuffer) {
|
|||
}
|
||||
|
||||
DAWN_INSTANTIATE_TEST(CommandEncoderTests,
|
||||
D3D11Backend(),
|
||||
D3D12Backend(),
|
||||
MetalBackend(),
|
||||
OpenGLBackend(),
|
||||
|
|
Loading…
Reference in New Issue