Remove AlphaOp
CopyTextureForBrowserOptions deprecated AlphaOp after supporting color space conversion. AlphaMode for src and dst is the replacement. Bug: dawn:1140 Change-Id: Id507bd7525d74be8a12d212b92cc22f0c7bc94b7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/73141 Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Shaobo Yan <shaobo.yan@intel.com>
This commit is contained in:
parent
d3c8f6b8ec
commit
36e86ee778
10
dawn.json
10
dawn.json
|
@ -855,15 +855,6 @@
|
||||||
{"name": "compute", "type": "programmable stage descriptor"}
|
{"name": "compute", "type": "programmable stage descriptor"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"alpha op": {
|
|
||||||
"category": "enum",
|
|
||||||
"tags": ["deprecated"],
|
|
||||||
"values": [
|
|
||||||
{"value": 0, "name": "dont change"},
|
|
||||||
{"value": 1, "name": "premultiply"},
|
|
||||||
{"value": 2, "name": "unpremultiply"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"alpha mode": {
|
"alpha mode": {
|
||||||
"category": "enum",
|
"category": "enum",
|
||||||
"tags": ["dawn"],
|
"tags": ["dawn"],
|
||||||
|
@ -879,7 +870,6 @@
|
||||||
"_TODO": "support number as length input",
|
"_TODO": "support number as length input",
|
||||||
"members": [
|
"members": [
|
||||||
{"name": "flip y", "type": "bool", "default": "false"},
|
{"name": "flip y", "type": "bool", "default": "false"},
|
||||||
{"name": "alpha op", "type": "alpha op", "default": "dont change", "tags": ["deprecated"]},
|
|
||||||
{"name": "needs color space conversion", "type": "bool", "default": "false"},
|
{"name": "needs color space conversion", "type": "bool", "default": "false"},
|
||||||
{"name": "src alpha mode", "type": "alpha mode", "default": "unpremultiplied"},
|
{"name": "src alpha mode", "type": "alpha mode", "default": "unpremultiplied"},
|
||||||
{"name": "src transfer function parameters", "type": "float", "annotation": "const*",
|
{"name": "src transfer function parameters", "type": "float", "annotation": "const*",
|
||||||
|
|
|
@ -348,8 +348,6 @@ namespace dawn_native {
|
||||||
|
|
||||||
DAWN_INVALID_IF(options->nextInChain != nullptr, "nextInChain must be nullptr");
|
DAWN_INVALID_IF(options->nextInChain != nullptr, "nextInChain must be nullptr");
|
||||||
|
|
||||||
// TODO(crbug.com/dawn/1140): Remove alphaOp and wgpu::AlphaState::DontChange.
|
|
||||||
DAWN_TRY(ValidateAlphaOp(options->alphaOp));
|
|
||||||
DAWN_TRY(ValidateAlphaMode(options->srcAlphaMode));
|
DAWN_TRY(ValidateAlphaMode(options->srcAlphaMode));
|
||||||
DAWN_TRY(ValidateAlphaMode(options->dstAlphaMode));
|
DAWN_TRY(ValidateAlphaMode(options->dstAlphaMode));
|
||||||
|
|
||||||
|
@ -472,19 +470,6 @@ namespace dawn_native {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->alphaOp != wgpu::AlphaOp::DontChange) {
|
|
||||||
dawn::WarningLog() << "CopyTextureForBrowserOption.alphaOp has been deprecated.";
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(crbugs.com/dawn/1140): AlphaOp will be deprecated
|
|
||||||
if (options->alphaOp == wgpu::AlphaOp::Premultiply) {
|
|
||||||
stepsMask |= kPremultiplyStep;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options->alphaOp == wgpu::AlphaOp::Unpremultiply) {
|
|
||||||
stepsMask |= kUnpremultiplyStep;
|
|
||||||
}
|
|
||||||
|
|
||||||
uniformData.stepsMask = stepsMask;
|
uniformData.stepsMask = stepsMask;
|
||||||
|
|
||||||
Ref<BufferBase> uniformBuffer;
|
Ref<BufferBase> uniformBuffer;
|
||||||
|
|
|
@ -33,9 +33,6 @@ namespace {
|
||||||
DisplayP3 = 0x01,
|
DisplayP3 = 0x01,
|
||||||
};
|
};
|
||||||
|
|
||||||
using Alpha = wgpu::AlphaOp;
|
|
||||||
DAWN_TEST_PARAM_STRUCT(AlphaTestParams, Alpha);
|
|
||||||
|
|
||||||
using SrcFormat = wgpu::TextureFormat;
|
using SrcFormat = wgpu::TextureFormat;
|
||||||
using DstFormat = wgpu::TextureFormat;
|
using DstFormat = wgpu::TextureFormat;
|
||||||
using SrcOrigin = wgpu::Origin3D;
|
using SrcOrigin = wgpu::Origin3D;
|
||||||
|
@ -62,6 +59,7 @@ namespace {
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DAWN_TEST_PARAM_STRUCT(AlphaTestParams, SrcAlphaMode, DstAlphaMode);
|
||||||
DAWN_TEST_PARAM_STRUCT(FormatTestParams, SrcFormat, DstFormat);
|
DAWN_TEST_PARAM_STRUCT(FormatTestParams, SrcFormat, DstFormat);
|
||||||
DAWN_TEST_PARAM_STRUCT(SubRectTestParams, SrcOrigin, DstOrigin, CopySize, FlipY);
|
DAWN_TEST_PARAM_STRUCT(SubRectTestParams, SrcOrigin, DstOrigin, CopySize, FlipY);
|
||||||
DAWN_TEST_PARAM_STRUCT(ColorSpaceTestParams,
|
DAWN_TEST_PARAM_STRUCT(ColorSpaceTestParams,
|
||||||
|
@ -167,9 +165,11 @@ class CopyTextureForBrowserTests : public Parent {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Source texture contains red pixels and dst texture contains green pixels at start.
|
// Source texture contains red pixels and dst texture contains green pixels at start.
|
||||||
static std::vector<RGBA8> GetTextureData(const utils::TextureDataCopyLayout& layout,
|
static std::vector<RGBA8> GetTextureData(
|
||||||
TextureCopyRole textureRole,
|
const utils::TextureDataCopyLayout& layout,
|
||||||
wgpu::AlphaOp alphaOp = wgpu::AlphaOp::DontChange) {
|
TextureCopyRole textureRole,
|
||||||
|
wgpu::AlphaMode srcAlphaMode = wgpu::AlphaMode::Premultiplied,
|
||||||
|
wgpu::AlphaMode dstAlphaMode = wgpu::AlphaMode::Unpremultiplied) {
|
||||||
std::array<uint8_t, 4> alpha = {0, 102, 153, 255}; // 0.0, 0.4, 0.6, 1.0
|
std::array<uint8_t, 4> alpha = {0, 102, 153, 255}; // 0.0, 0.4, 0.6, 1.0
|
||||||
std::vector<RGBA8> textureData(layout.texelBlockCount);
|
std::vector<RGBA8> textureData(layout.texelBlockCount);
|
||||||
for (uint32_t layer = 0; layer < layout.mipSize.depthOrArrayLayers; ++layer) {
|
for (uint32_t layer = 0; layer < layout.mipSize.depthOrArrayLayers; ++layer) {
|
||||||
|
@ -180,32 +180,30 @@ class CopyTextureForBrowserTests : public Parent {
|
||||||
// Source textures will have variable pixel data to cover cases like
|
// Source textures will have variable pixel data to cover cases like
|
||||||
// flipY.
|
// flipY.
|
||||||
if (textureRole == TextureCopyRole::SOURCE) {
|
if (textureRole == TextureCopyRole::SOURCE) {
|
||||||
switch (alphaOp) {
|
if (srcAlphaMode != dstAlphaMode) {
|
||||||
case wgpu::AlphaOp::DontChange:
|
if (dstAlphaMode == wgpu::AlphaMode::Premultiplied) {
|
||||||
textureData[sliceOffset + rowOffset + x] = RGBA8(
|
|
||||||
static_cast<uint8_t>((x + layer * x) % 256),
|
|
||||||
static_cast<uint8_t>((y + layer * y) % 256),
|
|
||||||
static_cast<uint8_t>(x % 256), static_cast<uint8_t>(x % 256));
|
|
||||||
break;
|
|
||||||
case wgpu::AlphaOp::Premultiply:
|
|
||||||
// For premultiply alpha test cases, we expect each channel in dst
|
// For premultiply alpha test cases, we expect each channel in dst
|
||||||
// texture will equal to the alpha channel value.
|
// texture will equal to the alpha channel value.
|
||||||
|
ASSERT(srcAlphaMode == wgpu::AlphaMode::Unpremultiplied);
|
||||||
textureData[sliceOffset + rowOffset + x] = RGBA8(
|
textureData[sliceOffset + rowOffset + x] = RGBA8(
|
||||||
static_cast<uint8_t>(255), static_cast<uint8_t>(255),
|
static_cast<uint8_t>(255), static_cast<uint8_t>(255),
|
||||||
static_cast<uint8_t>(255), static_cast<uint8_t>(alpha[x % 4]));
|
static_cast<uint8_t>(255), static_cast<uint8_t>(alpha[x % 4]));
|
||||||
break;
|
} else {
|
||||||
case wgpu::AlphaOp::Unpremultiply:
|
|
||||||
// For unpremultiply alpha test cases, we expect each channel in dst
|
// For unpremultiply alpha test cases, we expect each channel in dst
|
||||||
// texture will equal to 1.0.
|
// texture will equal to 1.0.
|
||||||
|
ASSERT(srcAlphaMode == wgpu::AlphaMode::Premultiplied);
|
||||||
textureData[sliceOffset + rowOffset + x] =
|
textureData[sliceOffset + rowOffset + x] =
|
||||||
RGBA8(static_cast<uint8_t>(alpha[x % 4]),
|
RGBA8(static_cast<uint8_t>(alpha[x % 4]),
|
||||||
static_cast<uint8_t>(alpha[x % 4]),
|
static_cast<uint8_t>(alpha[x % 4]),
|
||||||
static_cast<uint8_t>(alpha[x % 4]),
|
static_cast<uint8_t>(alpha[x % 4]),
|
||||||
static_cast<uint8_t>(alpha[x % 4]));
|
static_cast<uint8_t>(alpha[x % 4]));
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
} else {
|
||||||
break;
|
textureData[sliceOffset + rowOffset + x] =
|
||||||
|
RGBA8(static_cast<uint8_t>((x + layer * x) % 256),
|
||||||
|
static_cast<uint8_t>((y + layer * y) % 256),
|
||||||
|
static_cast<uint8_t>(x % 256), static_cast<uint8_t>(x % 256));
|
||||||
}
|
}
|
||||||
} else { // Dst textures will have be init as `green` to ensure subrect
|
} else { // Dst textures will have be init as `green` to ensure subrect
|
||||||
// copy not cross bound.
|
// copy not cross bound.
|
||||||
|
@ -232,8 +230,9 @@ class CopyTextureForBrowserTests : public Parent {
|
||||||
0,
|
0,
|
||||||
0, // uvec2, subrect copy dst origin
|
0, // uvec2, subrect copy dst origin
|
||||||
0,
|
0,
|
||||||
0, // uvec2, subrect copy size
|
0, // uvec2, subrect copy size
|
||||||
static_cast<uint32_t>(wgpu::AlphaOp::DontChange), // AlphaOp: DontChange
|
0, // srcAlphaMode, wgpu::AlphaMode::Premultiplied
|
||||||
|
0 // dstAlphaMode, wgpu::AlphaMode::Premultiplied
|
||||||
};
|
};
|
||||||
|
|
||||||
wgpu::BufferDescriptor uniformBufferDesc = {};
|
wgpu::BufferDescriptor uniformBufferDesc = {};
|
||||||
|
@ -253,7 +252,8 @@ class CopyTextureForBrowserTests : public Parent {
|
||||||
srcCopyOrigin : vec2<u32>;
|
srcCopyOrigin : vec2<u32>;
|
||||||
dstCopyOrigin : vec2<u32>;
|
dstCopyOrigin : vec2<u32>;
|
||||||
copySize : vec2<u32>;
|
copySize : vec2<u32>;
|
||||||
alphaOp : u32;
|
srcAlphaMode : u32;
|
||||||
|
dstAlphaMode : u32;
|
||||||
};
|
};
|
||||||
struct OutputBuf {
|
struct OutputBuf {
|
||||||
result : array<u32>;
|
result : array<u32>;
|
||||||
|
@ -297,25 +297,19 @@ class CopyTextureForBrowserTests : public Parent {
|
||||||
|
|
||||||
// Expect the dst texture channels should be all equal to alpha value
|
// Expect the dst texture channels should be all equal to alpha value
|
||||||
// after premultiply.
|
// after premultiply.
|
||||||
// TODO(crbug.com/1217153): if wgsl support `constexpr` and allow it
|
let premultiplied = 0u;
|
||||||
// to be case selector, Replace 0u/1u/2u with a constexpr variable with
|
let unpremultiplied = 1u;
|
||||||
// meaningful name.
|
if (uniforms.srcAlphaMode != uniforms.dstAlphaMode) {
|
||||||
switch(uniforms.alphaOp) {
|
if (uniforms.dstAlphaMode == premultiplied) {
|
||||||
case 0u: { // AlphaOp: DontChange
|
// srcAlphaMode == unpremultiplied
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 1u: { // AlphaOp: Premultiply
|
|
||||||
srcColor = vec4<f32>(srcColor.rgb * srcColor.a, srcColor.a);
|
srcColor = vec4<f32>(srcColor.rgb * srcColor.a, srcColor.a);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case 2u: { // AlphaOp: Unpremultiply
|
|
||||||
|
if (uniforms.dstAlphaMode == unpremultiplied) {
|
||||||
|
// srcAlphaMode == premultiplied
|
||||||
if (srcColor.a != 0.0) {
|
if (srcColor.a != 0.0) {
|
||||||
srcColor = vec4<f32>(srcColor.rgb / srcColor.a, srcColor.a);
|
srcColor = vec4<f32>(srcColor.rgb / srcColor.a, srcColor.a);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,9 +437,9 @@ class CopyTextureForBrowserTests : public Parent {
|
||||||
dstSpec.copyOrigin.x,
|
dstSpec.copyOrigin.x,
|
||||||
dstSpec.copyOrigin.y, // dst texture copy origin
|
dstSpec.copyOrigin.y, // dst texture copy origin
|
||||||
copySize.width,
|
copySize.width,
|
||||||
copySize.height, // copy size
|
copySize.height, // copy size
|
||||||
static_cast<uint32_t>(options.alphaOp) // alphaOp
|
static_cast<uint32_t>(options.srcAlphaMode),
|
||||||
};
|
static_cast<uint32_t>(options.dstAlphaMode)};
|
||||||
|
|
||||||
this->device.GetQueue().WriteBuffer(uniformBuffer, 0, uniformBufferData,
|
this->device.GetQueue().WriteBuffer(uniformBuffer, 0, uniformBufferData,
|
||||||
sizeof(uniformBufferData));
|
sizeof(uniformBufferData));
|
||||||
|
@ -506,8 +500,8 @@ class CopyTextureForBrowserTests : public Parent {
|
||||||
copySize.depthOrArrayLayers},
|
copySize.depthOrArrayLayers},
|
||||||
srcSpec.level);
|
srcSpec.level);
|
||||||
|
|
||||||
std::vector<RGBA8> srcTextureArrayCopyData =
|
std::vector<RGBA8> srcTextureArrayCopyData = GetTextureData(
|
||||||
GetTextureData(srcCopyLayout, TextureCopyRole::SOURCE, options.alphaOp);
|
srcCopyLayout, TextureCopyRole::SOURCE, options.srcAlphaMode, options.dstAlphaMode);
|
||||||
|
|
||||||
wgpu::TextureUsage srcUsage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
|
wgpu::TextureUsage srcUsage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
|
||||||
wgpu::TextureUsage::TextureBinding;
|
wgpu::TextureUsage::TextureBinding;
|
||||||
|
@ -659,10 +653,10 @@ class CopyTextureForBrowser_SubRects
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CopyTextureForBrowser_AlphaOps
|
class CopyTextureForBrowser_AlphaMode
|
||||||
: public CopyTextureForBrowserTests<DawnTestWithParams<AlphaTestParams>> {
|
: public CopyTextureForBrowserTests<DawnTestWithParams<AlphaTestParams>> {
|
||||||
protected:
|
protected:
|
||||||
void DoAlphaOpTest() {
|
void DoAlphaModeTest() {
|
||||||
constexpr uint32_t kWidth = 10;
|
constexpr uint32_t kWidth = 10;
|
||||||
constexpr uint32_t kHeight = 10;
|
constexpr uint32_t kHeight = 10;
|
||||||
|
|
||||||
|
@ -670,7 +664,8 @@ class CopyTextureForBrowser_AlphaOps
|
||||||
textureSpec.textureSize = {kWidth, kHeight};
|
textureSpec.textureSize = {kWidth, kHeight};
|
||||||
|
|
||||||
wgpu::CopyTextureForBrowserOptions options = {};
|
wgpu::CopyTextureForBrowserOptions options = {};
|
||||||
options.alphaOp = GetParam().mAlpha;
|
options.srcAlphaMode = GetParam().mSrcAlphaMode;
|
||||||
|
options.dstAlphaMode = GetParam().mDstAlphaMode;
|
||||||
|
|
||||||
DoTest(textureSpec, textureSpec, {kWidth, kHeight}, options);
|
DoTest(textureSpec, textureSpec, {kWidth, kHeight}, options);
|
||||||
}
|
}
|
||||||
|
@ -1079,9 +1074,9 @@ DAWN_INSTANTIATE_TEST_P(CopyTextureForBrowser_SubRects,
|
||||||
std::vector<wgpu::Extent3D>({{1, 1}, {2, 1}, {1, 2}, {2, 2}}),
|
std::vector<wgpu::Extent3D>({{1, 1}, {2, 1}, {1, 2}, {2, 2}}),
|
||||||
std::vector<bool>({true, false}));
|
std::vector<bool>({true, false}));
|
||||||
|
|
||||||
// Verify |CopyTextureForBrowser| doing alphaOp.
|
// Verify |CopyTextureForBrowser| doing alpha changes.
|
||||||
// Test alpha ops: DontChange, Premultiply, Unpremultiply.
|
// Test srcAlphaMode and dstAlphaMode: Premultiplied, Unpremultiplied.
|
||||||
TEST_P(CopyTextureForBrowser_AlphaOps, alphaOp) {
|
TEST_P(CopyTextureForBrowser_AlphaMode, alphaMode) {
|
||||||
// Skip OpenGLES backend because it fails on using RGBA8Unorm as
|
// Skip OpenGLES backend because it fails on using RGBA8Unorm as
|
||||||
// source texture format.
|
// source texture format.
|
||||||
// TODO(crbug.com/dawn/1232): Program link error on OpenGLES backend
|
// TODO(crbug.com/dawn/1232): Program link error on OpenGLES backend
|
||||||
|
@ -1091,14 +1086,16 @@ TEST_P(CopyTextureForBrowser_AlphaOps, alphaOp) {
|
||||||
// Tests skip due to crbug.com/dawn/1104.
|
// Tests skip due to crbug.com/dawn/1104.
|
||||||
DAWN_SUPPRESS_TEST_IF(IsWARP());
|
DAWN_SUPPRESS_TEST_IF(IsWARP());
|
||||||
|
|
||||||
DoAlphaOpTest();
|
DoAlphaModeTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
DAWN_INSTANTIATE_TEST_P(
|
DAWN_INSTANTIATE_TEST_P(CopyTextureForBrowser_AlphaMode,
|
||||||
CopyTextureForBrowser_AlphaOps,
|
{D3D12Backend(), MetalBackend(), OpenGLBackend(), OpenGLESBackend(),
|
||||||
{D3D12Backend(), MetalBackend(), OpenGLBackend(), OpenGLESBackend(), VulkanBackend()},
|
VulkanBackend()},
|
||||||
std::vector<wgpu::AlphaOp>({wgpu::AlphaOp::DontChange, wgpu::AlphaOp::Premultiply,
|
std::vector<wgpu::AlphaMode>({wgpu::AlphaMode::Premultiplied,
|
||||||
wgpu::AlphaOp::Unpremultiply}));
|
wgpu::AlphaMode::Unpremultiplied}),
|
||||||
|
std::vector<wgpu::AlphaMode>({wgpu::AlphaMode::Premultiplied,
|
||||||
|
wgpu::AlphaMode::Unpremultiplied}));
|
||||||
|
|
||||||
// Verify |CopyTextureForBrowser| doing color space conversion.
|
// Verify |CopyTextureForBrowser| doing color space conversion.
|
||||||
TEST_P(CopyTextureForBrowser_ColorSpace, colorSpaceConversion) {
|
TEST_P(CopyTextureForBrowser_ColorSpace, colorSpaceConversion) {
|
||||||
|
|
Loading…
Reference in New Issue