mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
Updated BlendFactor enum to match spec
Several of the enum names have changed recently. Update them to match the spec and mark the older ones as deprecated. BUG: chromium:1199057 Change-Id: I7a29588dd18b8fb738773c2478b173093f2aa834 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/47860 Commit-Queue: Brandon Jones <bajones@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
5c9b6a8f81
commit
22b923cc91
@@ -211,7 +211,26 @@ namespace dawn_native {
|
||||
return {};
|
||||
}
|
||||
|
||||
MaybeError ValidateBlendState(const BlendState* descriptor) {
|
||||
static constexpr wgpu::BlendFactor kFirstDeprecatedBlendFactor =
|
||||
wgpu::BlendFactor::SrcColor;
|
||||
static constexpr uint32_t kDeprecatedBlendFactorOffset = 100;
|
||||
|
||||
bool IsDeprecatedBlendFactor(wgpu::BlendFactor blendFactor) {
|
||||
return blendFactor >= kFirstDeprecatedBlendFactor;
|
||||
}
|
||||
|
||||
wgpu::BlendFactor NormalizeBlendFactor(wgpu::BlendFactor blendFactor) {
|
||||
// If the specified format is from the deprecated range return the corresponding
|
||||
// non-deprecated format.
|
||||
if (blendFactor >= kFirstDeprecatedBlendFactor) {
|
||||
uint32_t blendFactorValue = static_cast<uint32_t>(blendFactor);
|
||||
return static_cast<wgpu::BlendFactor>(blendFactorValue -
|
||||
kDeprecatedBlendFactorOffset);
|
||||
}
|
||||
return blendFactor;
|
||||
}
|
||||
|
||||
MaybeError ValidateBlendState(DeviceBase* device, const BlendState* descriptor) {
|
||||
DAWN_TRY(ValidateBlendOperation(descriptor->alpha.operation));
|
||||
DAWN_TRY(ValidateBlendFactor(descriptor->alpha.srcFactor));
|
||||
DAWN_TRY(ValidateBlendFactor(descriptor->alpha.dstFactor));
|
||||
@@ -219,10 +238,18 @@ namespace dawn_native {
|
||||
DAWN_TRY(ValidateBlendFactor(descriptor->color.srcFactor));
|
||||
DAWN_TRY(ValidateBlendFactor(descriptor->color.dstFactor));
|
||||
|
||||
if (IsDeprecatedBlendFactor(descriptor->alpha.srcFactor) ||
|
||||
IsDeprecatedBlendFactor(descriptor->alpha.dstFactor) ||
|
||||
IsDeprecatedBlendFactor(descriptor->color.srcFactor) ||
|
||||
IsDeprecatedBlendFactor(descriptor->color.dstFactor)) {
|
||||
device->EmitDeprecationWarning(
|
||||
"Blend factor enums have changed and the old enums will be removed soon.");
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
MaybeError ValidateColorTargetState(const DeviceBase* device,
|
||||
MaybeError ValidateColorTargetState(DeviceBase* device,
|
||||
const ColorTargetState* descriptor,
|
||||
bool fragmentWritten,
|
||||
wgpu::TextureComponentType fragmentOutputBaseType) {
|
||||
@@ -231,7 +258,7 @@ namespace dawn_native {
|
||||
}
|
||||
|
||||
if (descriptor->blend) {
|
||||
DAWN_TRY(ValidateBlendState(descriptor->blend));
|
||||
DAWN_TRY(ValidateBlendState(device, descriptor->blend));
|
||||
}
|
||||
|
||||
DAWN_TRY(ValidateColorWriteMask(descriptor->writeMask));
|
||||
@@ -440,6 +467,14 @@ namespace dawn_native {
|
||||
if (target->blend != nullptr) {
|
||||
mTargetBlend[i] = *target->blend;
|
||||
mTargets[i].blend = &mTargetBlend[i];
|
||||
mTargetBlend[i].alpha.srcFactor =
|
||||
NormalizeBlendFactor(mTargetBlend[i].alpha.srcFactor);
|
||||
mTargetBlend[i].alpha.dstFactor =
|
||||
NormalizeBlendFactor(mTargetBlend[i].alpha.dstFactor);
|
||||
mTargetBlend[i].color.srcFactor =
|
||||
NormalizeBlendFactor(mTargetBlend[i].color.srcFactor);
|
||||
mTargetBlend[i].color.dstFactor =
|
||||
NormalizeBlendFactor(mTargetBlend[i].color.dstFactor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,17 +151,17 @@ namespace dawn_native { namespace d3d12 {
|
||||
return D3D12_BLEND_ZERO;
|
||||
case wgpu::BlendFactor::One:
|
||||
return D3D12_BLEND_ONE;
|
||||
case wgpu::BlendFactor::SrcColor:
|
||||
case wgpu::BlendFactor::Src:
|
||||
return D3D12_BLEND_SRC_COLOR;
|
||||
case wgpu::BlendFactor::OneMinusSrcColor:
|
||||
case wgpu::BlendFactor::OneMinusSrc:
|
||||
return D3D12_BLEND_INV_SRC_COLOR;
|
||||
case wgpu::BlendFactor::SrcAlpha:
|
||||
return D3D12_BLEND_SRC_ALPHA;
|
||||
case wgpu::BlendFactor::OneMinusSrcAlpha:
|
||||
return D3D12_BLEND_INV_SRC_ALPHA;
|
||||
case wgpu::BlendFactor::DstColor:
|
||||
case wgpu::BlendFactor::Dst:
|
||||
return D3D12_BLEND_DEST_COLOR;
|
||||
case wgpu::BlendFactor::OneMinusDstColor:
|
||||
case wgpu::BlendFactor::OneMinusDst:
|
||||
return D3D12_BLEND_INV_DEST_COLOR;
|
||||
case wgpu::BlendFactor::DstAlpha:
|
||||
return D3D12_BLEND_DEST_ALPHA;
|
||||
@@ -169,10 +169,39 @@ namespace dawn_native { namespace d3d12 {
|
||||
return D3D12_BLEND_INV_DEST_ALPHA;
|
||||
case wgpu::BlendFactor::SrcAlphaSaturated:
|
||||
return D3D12_BLEND_SRC_ALPHA_SAT;
|
||||
case wgpu::BlendFactor::BlendColor:
|
||||
case wgpu::BlendFactor::Constant:
|
||||
return D3D12_BLEND_BLEND_FACTOR;
|
||||
case wgpu::BlendFactor::OneMinusBlendColor:
|
||||
case wgpu::BlendFactor::OneMinusConstant:
|
||||
return D3D12_BLEND_INV_BLEND_FACTOR;
|
||||
|
||||
// Deprecated blend factors should be normalized prior to this call.
|
||||
case wgpu::BlendFactor::SrcColor:
|
||||
case wgpu::BlendFactor::OneMinusSrcColor:
|
||||
case wgpu::BlendFactor::DstColor:
|
||||
case wgpu::BlendFactor::OneMinusDstColor:
|
||||
case wgpu::BlendFactor::BlendColor:
|
||||
case wgpu::BlendFactor::OneMinusBlendColor:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
// When a blend factor is defined for the alpha channel, any of the factors that don't
|
||||
// explicitly state that they apply to alpha should be treated as their explicitly-alpha
|
||||
// equivalents. See: https://github.com/gpuweb/gpuweb/issues/65
|
||||
D3D12_BLEND D3D12AlphaBlend(wgpu::BlendFactor factor) {
|
||||
switch (factor) {
|
||||
case wgpu::BlendFactor::Src:
|
||||
return D3D12_BLEND_SRC_ALPHA;
|
||||
case wgpu::BlendFactor::OneMinusSrc:
|
||||
return D3D12_BLEND_INV_SRC_ALPHA;
|
||||
case wgpu::BlendFactor::Dst:
|
||||
return D3D12_BLEND_DEST_ALPHA;
|
||||
case wgpu::BlendFactor::OneMinusDst:
|
||||
return D3D12_BLEND_INV_DEST_ALPHA;
|
||||
|
||||
// Other blend factors translate to the same D3D12 enum as the color blend factors.
|
||||
default:
|
||||
return D3D12Blend(factor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,8 +243,8 @@ namespace dawn_native { namespace d3d12 {
|
||||
blendDesc.SrcBlend = D3D12Blend(state->blend->color.srcFactor);
|
||||
blendDesc.DestBlend = D3D12Blend(state->blend->color.dstFactor);
|
||||
blendDesc.BlendOp = D3D12BlendOperation(state->blend->color.operation);
|
||||
blendDesc.SrcBlendAlpha = D3D12Blend(state->blend->alpha.srcFactor);
|
||||
blendDesc.DestBlendAlpha = D3D12Blend(state->blend->alpha.dstFactor);
|
||||
blendDesc.SrcBlendAlpha = D3D12AlphaBlend(state->blend->alpha.srcFactor);
|
||||
blendDesc.DestBlendAlpha = D3D12AlphaBlend(state->blend->alpha.dstFactor);
|
||||
blendDesc.BlendOpAlpha = D3D12BlendOperation(state->blend->alpha.operation);
|
||||
}
|
||||
blendDesc.RenderTargetWriteMask = D3D12RenderTargetWriteMask(state->writeMask);
|
||||
|
||||
@@ -135,17 +135,17 @@ namespace dawn_native { namespace metal {
|
||||
return MTLBlendFactorZero;
|
||||
case wgpu::BlendFactor::One:
|
||||
return MTLBlendFactorOne;
|
||||
case wgpu::BlendFactor::SrcColor:
|
||||
case wgpu::BlendFactor::Src:
|
||||
return MTLBlendFactorSourceColor;
|
||||
case wgpu::BlendFactor::OneMinusSrcColor:
|
||||
case wgpu::BlendFactor::OneMinusSrc:
|
||||
return MTLBlendFactorOneMinusSourceColor;
|
||||
case wgpu::BlendFactor::SrcAlpha:
|
||||
return MTLBlendFactorSourceAlpha;
|
||||
case wgpu::BlendFactor::OneMinusSrcAlpha:
|
||||
return MTLBlendFactorOneMinusSourceAlpha;
|
||||
case wgpu::BlendFactor::DstColor:
|
||||
case wgpu::BlendFactor::Dst:
|
||||
return MTLBlendFactorDestinationColor;
|
||||
case wgpu::BlendFactor::OneMinusDstColor:
|
||||
case wgpu::BlendFactor::OneMinusDst:
|
||||
return MTLBlendFactorOneMinusDestinationColor;
|
||||
case wgpu::BlendFactor::DstAlpha:
|
||||
return MTLBlendFactorDestinationAlpha;
|
||||
@@ -153,11 +153,20 @@ namespace dawn_native { namespace metal {
|
||||
return MTLBlendFactorOneMinusDestinationAlpha;
|
||||
case wgpu::BlendFactor::SrcAlphaSaturated:
|
||||
return MTLBlendFactorSourceAlphaSaturated;
|
||||
case wgpu::BlendFactor::BlendColor:
|
||||
case wgpu::BlendFactor::Constant:
|
||||
return alpha ? MTLBlendFactorBlendAlpha : MTLBlendFactorBlendColor;
|
||||
case wgpu::BlendFactor::OneMinusBlendColor:
|
||||
case wgpu::BlendFactor::OneMinusConstant:
|
||||
return alpha ? MTLBlendFactorOneMinusBlendAlpha
|
||||
: MTLBlendFactorOneMinusBlendColor;
|
||||
|
||||
// Deprecated blend factors should be normalized prior to this call.
|
||||
case wgpu::BlendFactor::SrcColor:
|
||||
case wgpu::BlendFactor::OneMinusSrcColor:
|
||||
case wgpu::BlendFactor::DstColor:
|
||||
case wgpu::BlendFactor::OneMinusDstColor:
|
||||
case wgpu::BlendFactor::BlendColor:
|
||||
case wgpu::BlendFactor::OneMinusBlendColor:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,17 +62,17 @@ namespace dawn_native { namespace opengl {
|
||||
return GL_ZERO;
|
||||
case wgpu::BlendFactor::One:
|
||||
return GL_ONE;
|
||||
case wgpu::BlendFactor::SrcColor:
|
||||
case wgpu::BlendFactor::Src:
|
||||
return GL_SRC_COLOR;
|
||||
case wgpu::BlendFactor::OneMinusSrcColor:
|
||||
case wgpu::BlendFactor::OneMinusSrc:
|
||||
return GL_ONE_MINUS_SRC_COLOR;
|
||||
case wgpu::BlendFactor::SrcAlpha:
|
||||
return GL_SRC_ALPHA;
|
||||
case wgpu::BlendFactor::OneMinusSrcAlpha:
|
||||
return GL_ONE_MINUS_SRC_ALPHA;
|
||||
case wgpu::BlendFactor::DstColor:
|
||||
case wgpu::BlendFactor::Dst:
|
||||
return GL_DST_COLOR;
|
||||
case wgpu::BlendFactor::OneMinusDstColor:
|
||||
case wgpu::BlendFactor::OneMinusDst:
|
||||
return GL_ONE_MINUS_DST_COLOR;
|
||||
case wgpu::BlendFactor::DstAlpha:
|
||||
return GL_DST_ALPHA;
|
||||
@@ -80,10 +80,19 @@ namespace dawn_native { namespace opengl {
|
||||
return GL_ONE_MINUS_DST_ALPHA;
|
||||
case wgpu::BlendFactor::SrcAlphaSaturated:
|
||||
return GL_SRC_ALPHA_SATURATE;
|
||||
case wgpu::BlendFactor::BlendColor:
|
||||
case wgpu::BlendFactor::Constant:
|
||||
return alpha ? GL_CONSTANT_ALPHA : GL_CONSTANT_COLOR;
|
||||
case wgpu::BlendFactor::OneMinusBlendColor:
|
||||
case wgpu::BlendFactor::OneMinusConstant:
|
||||
return alpha ? GL_ONE_MINUS_CONSTANT_ALPHA : GL_ONE_MINUS_CONSTANT_COLOR;
|
||||
|
||||
// Deprecated blend factors should be normalized prior to this call.
|
||||
case wgpu::BlendFactor::SrcColor:
|
||||
case wgpu::BlendFactor::OneMinusSrcColor:
|
||||
case wgpu::BlendFactor::DstColor:
|
||||
case wgpu::BlendFactor::OneMinusDstColor:
|
||||
case wgpu::BlendFactor::BlendColor:
|
||||
case wgpu::BlendFactor::OneMinusBlendColor:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -158,17 +158,17 @@ namespace dawn_native { namespace vulkan {
|
||||
return VK_BLEND_FACTOR_ZERO;
|
||||
case wgpu::BlendFactor::One:
|
||||
return VK_BLEND_FACTOR_ONE;
|
||||
case wgpu::BlendFactor::SrcColor:
|
||||
case wgpu::BlendFactor::Src:
|
||||
return VK_BLEND_FACTOR_SRC_COLOR;
|
||||
case wgpu::BlendFactor::OneMinusSrcColor:
|
||||
case wgpu::BlendFactor::OneMinusSrc:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR;
|
||||
case wgpu::BlendFactor::SrcAlpha:
|
||||
return VK_BLEND_FACTOR_SRC_ALPHA;
|
||||
case wgpu::BlendFactor::OneMinusSrcAlpha:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
case wgpu::BlendFactor::DstColor:
|
||||
case wgpu::BlendFactor::Dst:
|
||||
return VK_BLEND_FACTOR_DST_COLOR;
|
||||
case wgpu::BlendFactor::OneMinusDstColor:
|
||||
case wgpu::BlendFactor::OneMinusDst:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR;
|
||||
case wgpu::BlendFactor::DstAlpha:
|
||||
return VK_BLEND_FACTOR_DST_ALPHA;
|
||||
@@ -176,10 +176,19 @@ namespace dawn_native { namespace vulkan {
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
|
||||
case wgpu::BlendFactor::SrcAlphaSaturated:
|
||||
return VK_BLEND_FACTOR_SRC_ALPHA_SATURATE;
|
||||
case wgpu::BlendFactor::BlendColor:
|
||||
case wgpu::BlendFactor::Constant:
|
||||
return VK_BLEND_FACTOR_CONSTANT_COLOR;
|
||||
case wgpu::BlendFactor::OneMinusBlendColor:
|
||||
case wgpu::BlendFactor::OneMinusConstant:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR;
|
||||
|
||||
// Deprecated blend factors should be normalized prior to this call.
|
||||
case wgpu::BlendFactor::SrcColor:
|
||||
case wgpu::BlendFactor::OneMinusSrcColor:
|
||||
case wgpu::BlendFactor::DstColor:
|
||||
case wgpu::BlendFactor::OneMinusDstColor:
|
||||
case wgpu::BlendFactor::BlendColor:
|
||||
case wgpu::BlendFactor::OneMinusBlendColor:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user