Split some structs out of DawnTest.h into their own file.

This allows them to be fully defined before being referenced, which
fixes compile errors in C++20.

Bug: chromium:1284275
Change-Id: I3c0f874406247c04d53710431931f82c3deaff3c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99080
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Peter Kasting <pkasting@google.com>
Auto-Submit: Peter Kasting <pkasting@google.com>
This commit is contained in:
Peter Kasting 2022-08-15 18:55:41 +00:00 committed by Dawn LUCI CQ
parent 3632062811
commit c935b497e6
60 changed files with 1197 additions and 1093 deletions

View File

@ -0,0 +1,130 @@
// Copyright 2022 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dawn/tests/AdapterTestConfig.h"
#include <initializer_list>
#include <ostream>
#include <string>
#include <vector>
#include "dawn/common/Assert.h"
#include "dawn/webgpu_cpp.h"
BackendTestConfig::BackendTestConfig(wgpu::BackendType backendType,
std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds)
: backendType(backendType),
forceEnabledWorkarounds(forceEnabledWorkarounds),
forceDisabledWorkarounds(forceDisabledWorkarounds) {}
BackendTestConfig D3D12Backend(std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds) {
return BackendTestConfig(wgpu::BackendType::D3D12, forceEnabledWorkarounds,
forceDisabledWorkarounds);
}
BackendTestConfig MetalBackend(std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds) {
return BackendTestConfig(wgpu::BackendType::Metal, forceEnabledWorkarounds,
forceDisabledWorkarounds);
}
BackendTestConfig NullBackend(std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds) {
return BackendTestConfig(wgpu::BackendType::Null, forceEnabledWorkarounds,
forceDisabledWorkarounds);
}
BackendTestConfig OpenGLBackend(std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds) {
return BackendTestConfig(wgpu::BackendType::OpenGL, forceEnabledWorkarounds,
forceDisabledWorkarounds);
}
BackendTestConfig OpenGLESBackend(std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds) {
return BackendTestConfig(wgpu::BackendType::OpenGLES, forceEnabledWorkarounds,
forceDisabledWorkarounds);
}
BackendTestConfig VulkanBackend(std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds) {
return BackendTestConfig(wgpu::BackendType::Vulkan, forceEnabledWorkarounds,
forceDisabledWorkarounds);
}
TestAdapterProperties::TestAdapterProperties(const wgpu::AdapterProperties& properties,
bool selected)
: wgpu::AdapterProperties(properties), adapterName(properties.name), selected(selected) {}
std::string TestAdapterProperties::ParamName() const {
switch (backendType) {
case wgpu::BackendType::D3D12:
return "D3D12";
case wgpu::BackendType::Metal:
return "Metal";
case wgpu::BackendType::Null:
return "Null";
case wgpu::BackendType::OpenGL:
return "OpenGL";
case wgpu::BackendType::OpenGLES:
return "OpenGLES";
case wgpu::BackendType::Vulkan:
return "Vulkan";
default:
UNREACHABLE();
}
}
std::string TestAdapterProperties::AdapterTypeName() const {
switch (adapterType) {
case wgpu::AdapterType::DiscreteGPU:
return "Discrete GPU";
case wgpu::AdapterType::IntegratedGPU:
return "Integrated GPU";
case wgpu::AdapterType::CPU:
return "CPU";
case wgpu::AdapterType::Unknown:
return "Unknown";
default:
UNREACHABLE();
}
}
AdapterTestParam::AdapterTestParam(const BackendTestConfig& config,
const TestAdapterProperties& adapterProperties)
: adapterProperties(adapterProperties),
forceEnabledWorkarounds(config.forceEnabledWorkarounds),
forceDisabledWorkarounds(config.forceDisabledWorkarounds) {}
std::ostream& operator<<(std::ostream& os, const AdapterTestParam& param) {
os << param.adapterProperties.ParamName() << " " << param.adapterProperties.adapterName;
// In a Windows Remote Desktop session there are two adapters named "Microsoft Basic Render
// Driver" with different adapter types. We must differentiate them to avoid any tests using the
// same name.
if (param.adapterProperties.deviceID == 0x008C) {
std::string adapterType = param.adapterProperties.AdapterTypeName();
os << " " << adapterType;
}
for (const char* forceEnabledWorkaround : param.forceEnabledWorkarounds) {
os << "; e:" << forceEnabledWorkaround;
}
for (const char* forceDisabledWorkaround : param.forceDisabledWorkarounds) {
os << "; d:" << forceDisabledWorkaround;
}
return os;
}

View File

@ -0,0 +1,80 @@
// Copyright 2022 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_DAWN_TESTS_ADAPTERTESTCONFIG_H_
#define SRC_DAWN_TESTS_ADAPTERTESTCONFIG_H_
#include <stdint.h>
#include <initializer_list>
#include <ostream>
#include <string>
#include <vector>
#include "dawn/webgpu_cpp.h"
struct BackendTestConfig {
BackendTestConfig(wgpu::BackendType backendType,
std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
wgpu::BackendType backendType;
std::vector<const char*> forceEnabledWorkarounds;
std::vector<const char*> forceDisabledWorkarounds;
};
struct TestAdapterProperties : wgpu::AdapterProperties {
TestAdapterProperties(const wgpu::AdapterProperties& properties, bool selected);
std::string adapterName;
bool selected;
std::string ParamName() const;
std::string AdapterTypeName() const;
private:
// This may be temporary, so it is copied into |adapterName| and made private.
using wgpu::AdapterProperties::name;
};
struct AdapterTestParam {
AdapterTestParam(const BackendTestConfig& config,
const TestAdapterProperties& adapterProperties);
TestAdapterProperties adapterProperties;
std::vector<const char*> forceEnabledWorkarounds;
std::vector<const char*> forceDisabledWorkarounds;
};
std::ostream& operator<<(std::ostream& os, const AdapterTestParam& param);
BackendTestConfig D3D12Backend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
BackendTestConfig MetalBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
BackendTestConfig NullBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
BackendTestConfig OpenGLBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
BackendTestConfig OpenGLESBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
BackendTestConfig VulkanBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
#endif // SRC_DAWN_TESTS_ADAPTERTESTCONFIG_H_

View File

@ -375,6 +375,8 @@ source_set("test_infra_sources") {
}
sources = [
"AdapterTestConfig.cpp",
"AdapterTestConfig.h",
"DawnTest.cpp",
"DawnTest.h",
"MockCallback.h",

View File

@ -50,40 +50,6 @@
namespace {
std::string ParamName(wgpu::BackendType type) {
switch (type) {
case wgpu::BackendType::D3D12:
return "D3D12";
case wgpu::BackendType::Metal:
return "Metal";
case wgpu::BackendType::Null:
return "Null";
case wgpu::BackendType::OpenGL:
return "OpenGL";
case wgpu::BackendType::OpenGLES:
return "OpenGLES";
case wgpu::BackendType::Vulkan:
return "Vulkan";
default:
UNREACHABLE();
}
}
const char* AdapterTypeName(wgpu::AdapterType type) {
switch (type) {
case wgpu::AdapterType::DiscreteGPU:
return "Discrete GPU";
case wgpu::AdapterType::IntegratedGPU:
return "Integrated GPU";
case wgpu::AdapterType::CPU:
return "CPU";
case wgpu::AdapterType::Unknown:
return "Unknown";
default:
UNREACHABLE();
}
}
struct MapReadUserdata {
DawnTestBase* test;
size_t slot;
@ -109,88 +75,6 @@ void printBuffer(testing::AssertionResult& result, const T* buffer, const size_t
} // anonymous namespace
const RGBA8 RGBA8::kZero = RGBA8(0, 0, 0, 0);
const RGBA8 RGBA8::kBlack = RGBA8(0, 0, 0, 255);
const RGBA8 RGBA8::kRed = RGBA8(255, 0, 0, 255);
const RGBA8 RGBA8::kGreen = RGBA8(0, 255, 0, 255);
const RGBA8 RGBA8::kBlue = RGBA8(0, 0, 255, 255);
const RGBA8 RGBA8::kYellow = RGBA8(255, 255, 0, 255);
const RGBA8 RGBA8::kWhite = RGBA8(255, 255, 255, 255);
BackendTestConfig::BackendTestConfig(wgpu::BackendType backendType,
std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds)
: backendType(backendType),
forceEnabledWorkarounds(forceEnabledWorkarounds),
forceDisabledWorkarounds(forceDisabledWorkarounds) {}
BackendTestConfig D3D12Backend(std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds) {
return BackendTestConfig(wgpu::BackendType::D3D12, forceEnabledWorkarounds,
forceDisabledWorkarounds);
}
BackendTestConfig MetalBackend(std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds) {
return BackendTestConfig(wgpu::BackendType::Metal, forceEnabledWorkarounds,
forceDisabledWorkarounds);
}
BackendTestConfig NullBackend(std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds) {
return BackendTestConfig(wgpu::BackendType::Null, forceEnabledWorkarounds,
forceDisabledWorkarounds);
}
BackendTestConfig OpenGLBackend(std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds) {
return BackendTestConfig(wgpu::BackendType::OpenGL, forceEnabledWorkarounds,
forceDisabledWorkarounds);
}
BackendTestConfig OpenGLESBackend(std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds) {
return BackendTestConfig(wgpu::BackendType::OpenGLES, forceEnabledWorkarounds,
forceDisabledWorkarounds);
}
BackendTestConfig VulkanBackend(std::initializer_list<const char*> forceEnabledWorkarounds,
std::initializer_list<const char*> forceDisabledWorkarounds) {
return BackendTestConfig(wgpu::BackendType::Vulkan, forceEnabledWorkarounds,
forceDisabledWorkarounds);
}
TestAdapterProperties::TestAdapterProperties(const wgpu::AdapterProperties& properties,
bool selected)
: wgpu::AdapterProperties(properties), adapterName(properties.name), selected(selected) {}
AdapterTestParam::AdapterTestParam(const BackendTestConfig& config,
const TestAdapterProperties& adapterProperties)
: adapterProperties(adapterProperties),
forceEnabledWorkarounds(config.forceEnabledWorkarounds),
forceDisabledWorkarounds(config.forceDisabledWorkarounds) {}
std::ostream& operator<<(std::ostream& os, const AdapterTestParam& param) {
os << ParamName(param.adapterProperties.backendType) << " "
<< param.adapterProperties.adapterName;
// In a Windows Remote Desktop session there are two adapters named "Microsoft Basic Render
// Driver" with different adapter types. We must differentiate them to avoid any tests using the
// same name.
if (param.adapterProperties.deviceID == 0x008C) {
std::string adapterType = AdapterTypeName(param.adapterProperties.adapterType);
os << " " << adapterType;
}
for (const char* forceEnabledWorkaround : param.forceEnabledWorkarounds) {
os << "; e:" << forceEnabledWorkaround;
}
for (const char* forceDisabledWorkaround : param.forceDisabledWorkarounds) {
os << "; d:" << forceDisabledWorkaround;
}
return os;
}
DawnTestBase::PrintToStringParamName::PrintToStringParamName(const char* test) : mTest(test) {}
std::string DawnTestBase::PrintToStringParamName::SanitizeParamName(std::string paramName,
@ -607,8 +491,8 @@ void DawnTestEnvironment::PrintTestConfigurationAndAdapterInfo(
<< " - \"" << properties.adapterName << "\" - \"" << properties.driverDescription
<< "\"\n"
<< " type: " << AdapterTypeName(properties.adapterType)
<< ", backend: " << ParamName(properties.backendType) << "\n"
<< " type: " << properties.AdapterTypeName()
<< ", backend: " << properties.ParamName() << "\n"
<< " vendorId: 0x" << vendorId.str() << ", deviceId: 0x" << deviceId.str()
<< (properties.selected ? " [Selected]" : "") << "\n";
@ -1610,27 +1494,22 @@ void DawnTestBase::ResolveDeferredExpectationsNow() {
}
}
bool RGBA8::operator==(const RGBA8& other) const {
bool utils::RGBA8::operator==(const utils::RGBA8& other) const {
return r == other.r && g == other.g && b == other.b && a == other.a;
}
bool RGBA8::operator!=(const RGBA8& other) const {
bool utils::RGBA8::operator!=(const utils::RGBA8& other) const {
return !(*this == other);
}
bool RGBA8::operator<=(const RGBA8& other) const {
bool utils::RGBA8::operator<=(const utils::RGBA8& other) const {
return (r <= other.r && g <= other.g && b <= other.b && a <= other.a);
}
bool RGBA8::operator>=(const RGBA8& other) const {
bool utils::RGBA8::operator>=(const utils::RGBA8& other) const {
return (r >= other.r && g >= other.g && b >= other.b && a >= other.a);
}
std::ostream& operator<<(std::ostream& stream, const RGBA8& color) {
return stream << "RGBA8(" << static_cast<int>(color.r) << ", " << static_cast<int>(color.g)
<< ", " << static_cast<int>(color.b) << ", " << static_cast<int>(color.a) << ")";
}
namespace detail {
std::vector<AdapterTestParam> GetAvailableAdapterTestParamsForBackends(
const BackendTestConfig* params,
@ -1723,7 +1602,7 @@ template class ExpectEq<uint8_t>;
template class ExpectEq<uint16_t>;
template class ExpectEq<uint32_t>;
template class ExpectEq<uint64_t>;
template class ExpectEq<RGBA8>;
template class ExpectEq<utils::RGBA8>;
template class ExpectEq<float>;
template class ExpectEq<float, uint16_t>;
@ -1780,5 +1659,5 @@ testing::AssertionResult ExpectBetweenColors<T>::Check(const void* data, size_t
return testing::AssertionSuccess();
}
template class ExpectBetweenColors<RGBA8>;
template class ExpectBetweenColors<utils::RGBA8>;
} // namespace detail

View File

@ -28,10 +28,12 @@
#include "dawn/dawn_proc_table.h"
#include "dawn/native/DawnNative.h"
#include "dawn/platform/DawnPlatform.h"
#include "dawn/tests/AdapterTestConfig.h"
#include "dawn/tests/MockCallback.h"
#include "dawn/tests/ParamGenerator.h"
#include "dawn/tests/ToggleParser.h"
#include "dawn/utils/ScopedAutoreleasePool.h"
#include "dawn/utils/TestUtils.h"
#include "dawn/utils/TextureUtils.h"
#include "dawn/webgpu_cpp.h"
#include "dawn/webgpu_cpp_print.h"
@ -120,76 +122,6 @@
#define ASSERT_DEVICE_ERROR(statement) ASSERT_DEVICE_ERROR_MSG(statement, testing::_)
struct RGBA8 {
constexpr RGBA8() : RGBA8(0, 0, 0, 0) {}
constexpr RGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a) : r(r), g(g), b(b), a(a) {}
bool operator==(const RGBA8& other) const;
bool operator!=(const RGBA8& other) const;
bool operator<=(const RGBA8& other) const;
bool operator>=(const RGBA8& other) const;
uint8_t r, g, b, a;
static const RGBA8 kZero;
static const RGBA8 kBlack;
static const RGBA8 kRed;
static const RGBA8 kGreen;
static const RGBA8 kBlue;
static const RGBA8 kYellow;
static const RGBA8 kWhite;
};
std::ostream& operator<<(std::ostream& stream, const RGBA8& color);
struct BackendTestConfig {
BackendTestConfig(wgpu::BackendType backendType,
std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
wgpu::BackendType backendType;
std::vector<const char*> forceEnabledWorkarounds;
std::vector<const char*> forceDisabledWorkarounds;
};
struct TestAdapterProperties : wgpu::AdapterProperties {
TestAdapterProperties(const wgpu::AdapterProperties& properties, bool selected);
std::string adapterName;
bool selected;
private:
// This may be temporary, so it is copied into |adapterName| and made private.
using wgpu::AdapterProperties::name;
};
struct AdapterTestParam {
AdapterTestParam(const BackendTestConfig& config,
const TestAdapterProperties& adapterProperties);
TestAdapterProperties adapterProperties;
std::vector<const char*> forceEnabledWorkarounds;
std::vector<const char*> forceDisabledWorkarounds;
};
std::ostream& operator<<(std::ostream& os, const AdapterTestParam& param);
BackendTestConfig D3D12Backend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
BackendTestConfig MetalBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
BackendTestConfig NullBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
BackendTestConfig OpenGLBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
BackendTestConfig OpenGLESBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
BackendTestConfig VulkanBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
std::initializer_list<const char*> forceDisabledWorkarounds = {});
struct GLFWwindow;
namespace utils {
@ -774,7 +706,7 @@ extern template class ExpectEq<uint8_t>;
extern template class ExpectEq<int16_t>;
extern template class ExpectEq<uint32_t>;
extern template class ExpectEq<uint64_t>;
extern template class ExpectEq<RGBA8>;
extern template class ExpectEq<utils::RGBA8>;
extern template class ExpectEq<float>;
extern template class ExpectEq<float, uint16_t>;
@ -796,7 +728,7 @@ class ExpectBetweenColors : public Expectation {
// A color is considered between color0 and color1 when all channel values are within range of
// each counterparts. It doesn't matter which value is higher or lower. Essentially color =
// lerp(color0, color1, t) where t is [0,1]. But I don't want to be too strict here.
extern template class ExpectBetweenColors<RGBA8>;
extern template class ExpectBetweenColors<utils::RGBA8>;
class CustomTextureExpectation : public Expectation {
public:

View File

@ -19,6 +19,8 @@
#include <utility>
#include <vector>
#include "dawn/tests/AdapterTestConfig.h"
// ParamStruct is a custom struct which ParamStruct will yield when iterating.
// The types Params... should be the same as the types passed to the constructor
// of ParamStruct.
@ -116,9 +118,6 @@ class ParamGenerator {
bool mIsEmpty;
};
struct BackendTestConfig;
struct AdapterTestParam;
namespace detail {
std::vector<AdapterTestParam> GetAvailableAdapterTestParamsForBackends(
const BackendTestConfig* params,

View File

@ -228,8 +228,8 @@ TEST_P(BindGroupTests, ReusedUBO) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
uint32_t min = 1, max = kRTSize - 3;
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min);
@ -304,13 +304,13 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) {
wgpu::TextureView textureView = texture.CreateView();
uint32_t width = kRTSize, height = kRTSize;
uint32_t widthInBytes = width * sizeof(RGBA8);
uint32_t widthInBytes = width * sizeof(utils::RGBA8);
widthInBytes = (widthInBytes + 255) & ~255;
uint32_t sizeInBytes = widthInBytes * height;
uint32_t size = sizeInBytes / sizeof(RGBA8);
std::vector<RGBA8> data = std::vector<RGBA8>(size);
uint32_t size = sizeInBytes / sizeof(utils::RGBA8);
std::vector<utils::RGBA8> data = std::vector<utils::RGBA8>(size);
for (uint32_t i = 0; i < size; i++) {
data[i] = RGBA8(0, 255, 0, 255);
data[i] = utils::RGBA8(0, 255, 0, 255);
}
wgpu::Buffer stagingBuffer =
utils::CreateBufferFromData(device, data.data(), sizeInBytes, wgpu::BufferUsage::CopySrc);
@ -334,8 +334,8 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
uint32_t min = 1, max = kRTSize - 3;
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min);
@ -422,8 +422,8 @@ TEST_P(BindGroupTests, MultipleBindLayouts) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
RGBA8 filled(255, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(255, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
uint32_t min = 1, max = kRTSize - 3;
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min);
@ -590,8 +590,8 @@ TEST_P(BindGroupTests, DrawTwiceInSamePipelineWithFourBindGroupSets) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
RGBA8 filled(255, 0, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(255, 0, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
uint32_t min = 1, max = kRTSize - 3;
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min);
@ -632,8 +632,8 @@ TEST_P(BindGroupTests, SetBindGroupBeforePipeline) {
queue.Submit(1, &commands);
// The result should be red.
RGBA8 filled(255, 0, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(255, 0, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
uint32_t min = 1, max = kRTSize - 3;
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min);
@ -693,8 +693,8 @@ TEST_P(BindGroupTests, SetDynamicBindGroupBeforePipeline) {
queue.Submit(1, &commands);
// The result should be RGBAunorm(1, 0, 0, 0.5) + RGBAunorm(0, 1, 0, 0.5)
RGBA8 filled(255, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(255, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
uint32_t min = 1, max = kRTSize - 3;
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min);
@ -770,8 +770,8 @@ TEST_P(BindGroupTests, BindGroupsPersistAfterPipelineChange) {
queue.Submit(1, &commands);
// The result should be RGBAunorm(1, 0, 0, 0.5) + RGBAunorm(0, 1, 0, 0.5)
RGBA8 filled(255, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(255, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
uint32_t min = 1, max = kRTSize - 3;
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min);
@ -878,8 +878,8 @@ TEST_P(BindGroupTests, DrawThenChangePipelineAndBindGroup) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
RGBA8 filled(255, 255, 255, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(255, 255, 255, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
uint32_t min = 1, max = kRTSize - 3;
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min);
@ -980,8 +980,8 @@ TEST_P(BindGroupTests, DrawThenChangePipelineTwiceAndBindGroup) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
RGBA8 filled(255, 255, 255, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(255, 255, 255, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
uint32_t min = 1, max = kRTSize - 3;
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min);
@ -1278,7 +1278,8 @@ TEST_P(BindGroupTests, ArbitraryBindingNumbers) {
wgpu::Buffer blue =
utils::CreateBufferFromData(device, wgpu::BufferUsage::Uniform, {0.0f, 0.0f, 0.251f, 0.0f});
auto DoTest = [&](wgpu::Buffer color1, wgpu::Buffer color2, wgpu::Buffer color3, RGBA8 filled) {
auto DoTest = [&](wgpu::Buffer color1, wgpu::Buffer color2, wgpu::Buffer color3,
utils::RGBA8 filled) {
auto DoTestInner = [&](wgpu::BindGroup bindGroup) {
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
@ -1309,25 +1310,25 @@ TEST_P(BindGroupTests, ArbitraryBindingNumbers) {
};
// first color is normal, second is 2x, third is 3x.
DoTest(black, black, black, RGBA8(0, 0, 0, 0));
DoTest(black, black, black, utils::RGBA8(0, 0, 0, 0));
// Check the first binding maps to the first slot. We know this because the colors are
// multiplied 1x.
DoTest(red, black, black, RGBA8(64, 0, 0, 0));
DoTest(green, black, black, RGBA8(0, 64, 0, 0));
DoTest(blue, black, black, RGBA8(0, 0, 64, 0));
DoTest(red, black, black, utils::RGBA8(64, 0, 0, 0));
DoTest(green, black, black, utils::RGBA8(0, 64, 0, 0));
DoTest(blue, black, black, utils::RGBA8(0, 0, 64, 0));
// Use multiple bindings and check the second color maps to the second slot.
// We know this because the second slot is multiplied 2x.
DoTest(green, blue, black, RGBA8(0, 64, 128, 0));
DoTest(blue, green, black, RGBA8(0, 128, 64, 0));
DoTest(red, green, black, RGBA8(64, 128, 0, 0));
DoTest(green, blue, black, utils::RGBA8(0, 64, 128, 0));
DoTest(blue, green, black, utils::RGBA8(0, 128, 64, 0));
DoTest(red, green, black, utils::RGBA8(64, 128, 0, 0));
// Use multiple bindings and check the third color maps to the third slot.
// We know this because the third slot is multiplied 4x.
DoTest(black, blue, red, RGBA8(255, 0, 128, 0));
DoTest(blue, black, green, RGBA8(0, 255, 64, 0));
DoTest(red, black, blue, RGBA8(64, 0, 255, 0));
DoTest(black, blue, red, utils::RGBA8(255, 0, 128, 0));
DoTest(blue, black, green, utils::RGBA8(0, 255, 64, 0));
DoTest(red, black, blue, utils::RGBA8(64, 0, 255, 0));
}
// This is a regression test for crbug.com/dawn/355 which tests that destruction of a bind group
@ -1427,7 +1428,7 @@ TEST_P(BindGroupTests, ReadonlyStorage) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 0, 0);
}
// Test that creating a large bind group, with each binding type at the max count, works and can be

View File

@ -199,7 +199,7 @@ class BufferZeroInitTest : public DawnTest {
EXPECT_LAZY_CLEAR(0u, EXPECT_BUFFER_U32_RANGE_EQ(expectedBufferData.data(), buffer, 0,
expectedBufferData.size()));
constexpr RGBA8 kExpectedColor = {0, 255, 0, 255};
constexpr utils::RGBA8 kExpectedColor = {0, 255, 0, 255};
EXPECT_PIXEL_RGBA8_EQ(kExpectedColor, outputTexture, 0u, 0u);
}
@ -243,7 +243,7 @@ class BufferZeroInitTest : public DawnTest {
EXPECT_LAZY_CLEAR(0u, EXPECT_BUFFER_U32_RANGE_EQ(expectedBufferData.data(), buffer, 0,
expectedBufferData.size()));
const RGBA8 kExpectedPixelValue = {0, 255, 0, 255};
const utils::RGBA8 kExpectedPixelValue = {0, 255, 0, 255};
EXPECT_PIXEL_RGBA8_EQ(kExpectedPixelValue, colorAttachment, 0, 0);
}
@ -1231,7 +1231,7 @@ TEST_P(BufferZeroInitTest, PaddingInitialized) {
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer));
constexpr RGBA8 kExpectedPixelValue = {0, 255, 0, 255};
constexpr utils::RGBA8 kExpectedPixelValue = {0, 255, 0, 255};
EXPECT_PIXEL_RGBA8_EQ(kExpectedPixelValue, colorAttachment, 0, 0);
}
}

View File

@ -88,8 +88,8 @@ TEST_P(ClipSpaceTest, ClipSpace) {
wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
queue.Submit(1, &commandBuffer);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, colorTexture, kSize - 1, kSize - 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, colorTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kRed, colorTexture, kSize - 1, kSize - 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, colorTexture, 0, 0);
}
DAWN_INSTANTIATE_TEST(ClipSpaceTest,

View File

@ -54,7 +54,7 @@ class ColorStateTest : public DawnTest {
}
struct TriangleSpec {
RGBA8 color;
utils::RGBA8 color;
std::array<float, 4> blendFactor = {};
};
@ -93,7 +93,7 @@ class ColorStateTest : public DawnTest {
// Create a bind group to set the colors as a uniform buffer
template <size_t N>
wgpu::BindGroup MakeBindGroupForColors(std::array<RGBA8, N> colors) {
wgpu::BindGroup MakeBindGroupForColors(std::array<utils::RGBA8, N> colors) {
std::array<float, 4 * N> data;
for (unsigned int i = 0; i < N; ++i) {
data[4 * i + 0] = static_cast<float>(colors[i].r) / 255.f;
@ -112,7 +112,9 @@ class ColorStateTest : public DawnTest {
// Test that after drawing a triangle with the base color, and then the given triangle spec, the
// color is as expected
void DoSingleSourceTest(RGBA8 base, const TriangleSpec& triangle, const RGBA8& expected) {
void DoSingleSourceTest(utils::RGBA8 base,
const TriangleSpec& triangle,
const utils::RGBA8& expected) {
wgpu::Color blendConstant{triangle.blendFactor[0], triangle.blendFactor[1],
triangle.blendFactor[2], triangle.blendFactor[3]};
@ -121,12 +123,13 @@ class ColorStateTest : public DawnTest {
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
// First use the base pipeline to draw a triangle with no blending
pass.SetPipeline(basePipeline);
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({{base}})));
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<utils::RGBA8, 1>({{base}})));
pass.Draw(3);
// Then use the test pipeline to draw the test triangle with blending
pass.SetPipeline(testPipeline);
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({{triangle.color}})));
pass.SetBindGroup(
0, MakeBindGroupForColors(std::array<utils::RGBA8, 1>({{triangle.color}})));
pass.SetBlendConstant(&blendConstant);
pass.Draw(3);
pass.End();
@ -140,9 +143,9 @@ class ColorStateTest : public DawnTest {
// Given a vector of tests where each element is <testColor, expectedColor>, check that all
// expectations are true for the given blend operation
void CheckBlendOperation(RGBA8 base,
void CheckBlendOperation(utils::RGBA8 base,
wgpu::BlendOperation operation,
std::vector<std::pair<RGBA8, RGBA8>> tests) {
std::vector<std::pair<utils::RGBA8, utils::RGBA8>> tests) {
wgpu::BlendComponent blendComponent;
blendComponent.operation = operation;
blendComponent.srcFactor = wgpu::BlendFactor::One;
@ -165,12 +168,12 @@ class ColorStateTest : public DawnTest {
// Given a vector of tests where each element is <testSpec, expectedColor>, check that all
// expectations are true for the given blend factors
void CheckBlendFactor(RGBA8 base,
void CheckBlendFactor(utils::RGBA8 base,
wgpu::BlendFactor colorSrcFactor,
wgpu::BlendFactor colorDstFactor,
wgpu::BlendFactor alphaSrcFactor,
wgpu::BlendFactor alphaDstFactor,
std::vector<std::pair<TriangleSpec, RGBA8>> tests) {
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests) {
wgpu::BlendComponent colorBlend;
colorBlend.operation = wgpu::BlendOperation::Add;
colorBlend.srcFactor = colorSrcFactor;
@ -196,18 +199,18 @@ class ColorStateTest : public DawnTest {
}
}
void CheckSrcBlendFactor(RGBA8 base,
void CheckSrcBlendFactor(utils::RGBA8 base,
wgpu::BlendFactor colorFactor,
wgpu::BlendFactor alphaFactor,
std::vector<std::pair<TriangleSpec, RGBA8>> tests) {
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests) {
CheckBlendFactor(base, colorFactor, wgpu::BlendFactor::One, alphaFactor,
wgpu::BlendFactor::One, tests);
}
void CheckDstBlendFactor(RGBA8 base,
void CheckDstBlendFactor(utils::RGBA8 base,
wgpu::BlendFactor colorFactor,
wgpu::BlendFactor alphaFactor,
std::vector<std::pair<TriangleSpec, RGBA8>> tests) {
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests) {
CheckBlendFactor(base, wgpu::BlendFactor::One, colorFactor, wgpu::BlendFactor::One,
alphaFactor, tests);
}
@ -221,7 +224,7 @@ class ColorStateTest : public DawnTest {
namespace {
// Add two colors and clamp
constexpr RGBA8 operator+(const RGBA8& col1, const RGBA8& col2) {
constexpr utils::RGBA8 operator+(const utils::RGBA8& col1, const utils::RGBA8& col2) {
int r = static_cast<int>(col1.r) + static_cast<int>(col2.r);
int g = static_cast<int>(col1.g) + static_cast<int>(col2.g);
int b = static_cast<int>(col1.b) + static_cast<int>(col2.b);
@ -231,12 +234,12 @@ constexpr RGBA8 operator+(const RGBA8& col1, const RGBA8& col2) {
b = (b > 255 ? 255 : (b < 0 ? 0 : b));
a = (a > 255 ? 255 : (a < 0 ? 0 : a));
return RGBA8(static_cast<uint8_t>(r), static_cast<uint8_t>(g), static_cast<uint8_t>(b),
static_cast<uint8_t>(a));
return utils::RGBA8(static_cast<uint8_t>(r), static_cast<uint8_t>(g), static_cast<uint8_t>(b),
static_cast<uint8_t>(a));
}
// Subtract two colors and clamp
constexpr RGBA8 operator-(const RGBA8& col1, const RGBA8& col2) {
constexpr utils::RGBA8 operator-(const utils::RGBA8& col1, const utils::RGBA8& col2) {
int r = static_cast<int>(col1.r) - static_cast<int>(col2.r);
int g = static_cast<int>(col1.g) - static_cast<int>(col2.g);
int b = static_cast<int>(col1.b) - static_cast<int>(col2.b);
@ -246,35 +249,35 @@ constexpr RGBA8 operator-(const RGBA8& col1, const RGBA8& col2) {
b = (b > 255 ? 255 : (b < 0 ? 0 : b));
a = (a > 255 ? 255 : (a < 0 ? 0 : a));
return RGBA8(static_cast<uint8_t>(r), static_cast<uint8_t>(g), static_cast<uint8_t>(b),
static_cast<uint8_t>(a));
return utils::RGBA8(static_cast<uint8_t>(r), static_cast<uint8_t>(g), static_cast<uint8_t>(b),
static_cast<uint8_t>(a));
}
// Get the component-wise minimum of two colors
RGBA8 min(const RGBA8& col1, const RGBA8& col2) {
return RGBA8(std::min(col1.r, col2.r), std::min(col1.g, col2.g), std::min(col1.b, col2.b),
std::min(col1.a, col2.a));
utils::RGBA8 min(const utils::RGBA8& col1, const utils::RGBA8& col2) {
return utils::RGBA8(std::min(col1.r, col2.r), std::min(col1.g, col2.g),
std::min(col1.b, col2.b), std::min(col1.a, col2.a));
}
// Get the component-wise maximum of two colors
RGBA8 max(const RGBA8& col1, const RGBA8& col2) {
return RGBA8(std::max(col1.r, col2.r), std::max(col1.g, col2.g), std::max(col1.b, col2.b),
std::max(col1.a, col2.a));
utils::RGBA8 max(const utils::RGBA8& col1, const utils::RGBA8& col2) {
return utils::RGBA8(std::max(col1.r, col2.r), std::max(col1.g, col2.g),
std::max(col1.b, col2.b), std::max(col1.a, col2.a));
}
// Blend two RGBA8 color values parameterized by the provided factors in the range [0.f, 1.f]
RGBA8 mix(const RGBA8& col1, const RGBA8& col2, std::array<float, 4> fac) {
utils::RGBA8 mix(const utils::RGBA8& col1, const utils::RGBA8& col2, std::array<float, 4> fac) {
float r = static_cast<float>(col1.r) * (1.f - fac[0]) + static_cast<float>(col2.r) * fac[0];
float g = static_cast<float>(col1.g) * (1.f - fac[1]) + static_cast<float>(col2.g) * fac[1];
float b = static_cast<float>(col1.b) * (1.f - fac[2]) + static_cast<float>(col2.b) * fac[2];
float a = static_cast<float>(col1.a) * (1.f - fac[3]) + static_cast<float>(col2.a) * fac[3];
return RGBA8({static_cast<uint8_t>(std::round(r)), static_cast<uint8_t>(std::round(g)),
static_cast<uint8_t>(std::round(b)), static_cast<uint8_t>(std::round(a))});
return utils::RGBA8({static_cast<uint8_t>(std::round(r)), static_cast<uint8_t>(std::round(g)),
static_cast<uint8_t>(std::round(b)), static_cast<uint8_t>(std::round(a))});
}
// Blend two RGBA8 color values parameterized by the provided RGBA8 factor
RGBA8 mix(const RGBA8& col1, const RGBA8& col2, const RGBA8& fac) {
utils::RGBA8 mix(const utils::RGBA8& col1, const utils::RGBA8& col2, const utils::RGBA8& fac) {
std::array<float, 4> f = {{
static_cast<float>(fac.r) / 255.f,
static_cast<float>(fac.g) / 255.f,
@ -284,18 +287,18 @@ RGBA8 mix(const RGBA8& col1, const RGBA8& col2, const RGBA8& fac) {
return mix(col1, col2, f);
}
constexpr std::array<RGBA8, 8> kColors = {{
constexpr std::array<utils::RGBA8, 8> kColors = {{
// check operations over multiple channels
RGBA8(64, 0, 0, 0),
RGBA8(0, 64, 0, 0),
RGBA8(64, 0, 32, 0),
RGBA8(0, 64, 32, 0),
RGBA8(128, 0, 128, 128),
RGBA8(0, 128, 128, 128),
utils::RGBA8(64, 0, 0, 0),
utils::RGBA8(0, 64, 0, 0),
utils::RGBA8(64, 0, 32, 0),
utils::RGBA8(0, 64, 32, 0),
utils::RGBA8(128, 0, 128, 128),
utils::RGBA8(0, 128, 128, 128),
// check cases that may cause overflow
RGBA8(0, 0, 0, 0),
RGBA8(255, 255, 255, 255),
utils::RGBA8(0, 0, 0, 0),
utils::RGBA8(255, 255, 255, 255),
}};
} // namespace
@ -316,114 +319,119 @@ TEST_P(ColorStateTest, Basic) {
SetupSingleSourcePipelines(descriptor);
DoSingleSourceTest(RGBA8(0, 0, 0, 0), {RGBA8(255, 0, 0, 0)}, RGBA8(255, 0, 0, 0));
DoSingleSourceTest(utils::RGBA8(0, 0, 0, 0), {utils::RGBA8(255, 0, 0, 0)},
utils::RGBA8(255, 0, 0, 0));
}
// The following tests check test that the blend operation works
TEST_P(ColorStateTest, BlendOperationAdd) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<RGBA8, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<utils::RGBA8, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, base + color); });
[&](const utils::RGBA8& color) { return std::make_pair(color, base + color); });
CheckBlendOperation(base, wgpu::BlendOperation::Add, tests);
}
TEST_P(ColorStateTest, BlendOperationSubtract) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<RGBA8, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<utils::RGBA8, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, color - base); });
[&](const utils::RGBA8& color) { return std::make_pair(color, color - base); });
CheckBlendOperation(base, wgpu::BlendOperation::Subtract, tests);
}
TEST_P(ColorStateTest, BlendOperationReverseSubtract) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<RGBA8, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<utils::RGBA8, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, base - color); });
[&](const utils::RGBA8& color) { return std::make_pair(color, base - color); });
CheckBlendOperation(base, wgpu::BlendOperation::ReverseSubtract, tests);
}
TEST_P(ColorStateTest, BlendOperationMin) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<RGBA8, RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, min(base, color)); });
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<utils::RGBA8, utils::RGBA8>> tests;
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const utils::RGBA8& color) { return std::make_pair(color, min(base, color)); });
CheckBlendOperation(base, wgpu::BlendOperation::Min, tests);
}
TEST_P(ColorStateTest, BlendOperationMax) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<RGBA8, RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, max(base, color)); });
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<utils::RGBA8, utils::RGBA8>> tests;
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const utils::RGBA8& color) { return std::make_pair(color, max(base, color)); });
CheckBlendOperation(base, wgpu::BlendOperation::Max, tests);
}
// The following tests check that the Source blend factor works
TEST_P(ColorStateTest, SrcBlendFactorZero) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), base); });
[&](const utils::RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), base); });
CheckSrcBlendFactor(base, wgpu::BlendFactor::Zero, wgpu::BlendFactor::Zero, tests);
}
TEST_P(ColorStateTest, SrcBlendFactorOne) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), base + color); });
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const utils::RGBA8& color) {
return std::make_pair(TriangleSpec({{color}}), base + color);
});
CheckSrcBlendFactor(base, wgpu::BlendFactor::One, wgpu::BlendFactor::One, tests);
}
TEST_P(ColorStateTest, SrcBlendFactorSrc) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
RGBA8 fac = color;
[&](const utils::RGBA8& color) {
utils::RGBA8 fac = color;
fac.a = 0;
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
utils::RGBA8 expected = base + mix(utils::RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckSrcBlendFactor(base, wgpu::BlendFactor::Src, wgpu::BlendFactor::Zero, tests);
}
TEST_P(ColorStateTest, SrcBlendFactorOneMinusSrc) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
RGBA8 fac = RGBA8(255, 255, 255, 255) - color;
[&](const utils::RGBA8& color) {
utils::RGBA8 fac = utils::RGBA8(255, 255, 255, 255) - color;
fac.a = 0;
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
utils::RGBA8 expected = base + mix(utils::RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckSrcBlendFactor(base, wgpu::BlendFactor::OneMinusSrc, wgpu::BlendFactor::Zero, tests);
}
TEST_P(ColorStateTest, SrcBlendFactorSrcAlpha) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
RGBA8 fac(color.a, color.a, color.a, color.a);
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
[&](const utils::RGBA8& color) {
utils::RGBA8 fac(color.a, color.a, color.a, color.a);
utils::RGBA8 expected = base + mix(utils::RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckSrcBlendFactor(base, wgpu::BlendFactor::SrcAlpha, wgpu::BlendFactor::SrcAlpha, tests);
}
TEST_P(ColorStateTest, SrcBlendFactorOneMinusSrcAlpha) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests), [&](const RGBA8& color) {
RGBA8 fac = RGBA8(255, 255, 255, 255) - RGBA8(color.a, color.a, color.a, color.a);
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
kColors.begin(), kColors.end(), std::back_inserter(tests), [&](const utils::RGBA8& color) {
utils::RGBA8 fac =
utils::RGBA8(255, 255, 255, 255) - utils::RGBA8(color.a, color.a, color.a, color.a);
utils::RGBA8 expected = base + mix(utils::RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckSrcBlendFactor(base, wgpu::BlendFactor::OneMinusSrcAlpha,
@ -431,50 +439,51 @@ TEST_P(ColorStateTest, SrcBlendFactorOneMinusSrcAlpha) {
}
TEST_P(ColorStateTest, SrcBlendFactorDst) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
RGBA8 fac = base;
[&](const utils::RGBA8& color) {
utils::RGBA8 fac = base;
fac.a = 0;
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
utils::RGBA8 expected = base + mix(utils::RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckSrcBlendFactor(base, wgpu::BlendFactor::Dst, wgpu::BlendFactor::Zero, tests);
}
TEST_P(ColorStateTest, SrcBlendFactorOneMinusDst) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
RGBA8 fac = RGBA8(255, 255, 255, 255) - base;
[&](const utils::RGBA8& color) {
utils::RGBA8 fac = utils::RGBA8(255, 255, 255, 255) - base;
fac.a = 0;
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
utils::RGBA8 expected = base + mix(utils::RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckSrcBlendFactor(base, wgpu::BlendFactor::OneMinusDst, wgpu::BlendFactor::Zero, tests);
}
TEST_P(ColorStateTest, SrcBlendFactorDstAlpha) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
RGBA8 fac(base.a, base.a, base.a, base.a);
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
[&](const utils::RGBA8& color) {
utils::RGBA8 fac(base.a, base.a, base.a, base.a);
utils::RGBA8 expected = base + mix(utils::RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckSrcBlendFactor(base, wgpu::BlendFactor::DstAlpha, wgpu::BlendFactor::DstAlpha, tests);
}
TEST_P(ColorStateTest, SrcBlendFactorOneMinusDstAlpha) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests), [&](const RGBA8& color) {
RGBA8 fac = RGBA8(255, 255, 255, 255) - RGBA8(base.a, base.a, base.a, base.a);
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
kColors.begin(), kColors.end(), std::back_inserter(tests), [&](const utils::RGBA8& color) {
utils::RGBA8 fac =
utils::RGBA8(255, 255, 255, 255) - utils::RGBA8(base.a, base.a, base.a, base.a);
utils::RGBA8 expected = base + mix(utils::RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckSrcBlendFactor(base, wgpu::BlendFactor::OneMinusDstAlpha,
@ -482,13 +491,13 @@ TEST_P(ColorStateTest, SrcBlendFactorOneMinusDstAlpha) {
}
TEST_P(ColorStateTest, SrcBlendFactorSrcAlphaSaturated) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
[&](const utils::RGBA8& color) {
uint8_t f = std::min(color.a, static_cast<uint8_t>(255 - base.a));
RGBA8 fac(f, f, f, 255);
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
utils::RGBA8 fac(f, f, f, 255);
utils::RGBA8 expected = base + mix(utils::RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckSrcBlendFactor(base, wgpu::BlendFactor::SrcAlphaSaturated,
@ -496,25 +505,26 @@ TEST_P(ColorStateTest, SrcBlendFactorSrcAlphaSaturated) {
}
TEST_P(ColorStateTest, SrcBlendFactorConstant) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests), [&](const RGBA8& color) {
auto triangleSpec = TriangleSpec({{color}, {{0.2f, 0.4f, 0.6f, 0.8f}}});
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, triangleSpec.blendFactor);
return std::make_pair(triangleSpec, expected);
});
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const utils::RGBA8& color) {
auto triangleSpec = TriangleSpec({{color}, {{0.2f, 0.4f, 0.6f, 0.8f}}});
utils::RGBA8 expected =
base + mix(utils::RGBA8(0, 0, 0, 0), color, triangleSpec.blendFactor);
return std::make_pair(triangleSpec, expected);
});
CheckSrcBlendFactor(base, wgpu::BlendFactor::Constant, wgpu::BlendFactor::Constant, tests);
}
TEST_P(ColorStateTest, SrcBlendFactorOneMinusConstant) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
[&](const utils::RGBA8& color) {
auto triangleSpec = TriangleSpec({{color}, {{0.2f, 0.4f, 0.6f, 0.8f}}});
std::array<float, 4> f = {{0.8f, 0.6f, 0.4f, 0.2f}};
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, f);
utils::RGBA8 expected = base + mix(utils::RGBA8(0, 0, 0, 0), color, f);
return std::make_pair(triangleSpec, expected);
});
CheckSrcBlendFactor(base, wgpu::BlendFactor::OneMinusConstant,
@ -523,68 +533,70 @@ TEST_P(ColorStateTest, SrcBlendFactorOneMinusConstant) {
// The following tests check that the Destination blend factor works
TEST_P(ColorStateTest, DstBlendFactorZero) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), color); });
[&](const utils::RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), color); });
CheckDstBlendFactor(base, wgpu::BlendFactor::Zero, wgpu::BlendFactor::Zero, tests);
}
TEST_P(ColorStateTest, DstBlendFactorOne) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), base + color); });
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const utils::RGBA8& color) {
return std::make_pair(TriangleSpec({{color}}), base + color);
});
CheckDstBlendFactor(base, wgpu::BlendFactor::One, wgpu::BlendFactor::One, tests);
}
TEST_P(ColorStateTest, DstBlendFactorSrc) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
RGBA8 fac = color;
[&](const utils::RGBA8& color) {
utils::RGBA8 fac = color;
fac.a = 0;
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
utils::RGBA8 expected = color + mix(utils::RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckDstBlendFactor(base, wgpu::BlendFactor::Src, wgpu::BlendFactor::Zero, tests);
}
TEST_P(ColorStateTest, DstBlendFactorOneMinusSrc) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
RGBA8 fac = RGBA8(255, 255, 255, 255) - color;
[&](const utils::RGBA8& color) {
utils::RGBA8 fac = utils::RGBA8(255, 255, 255, 255) - color;
fac.a = 0;
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
utils::RGBA8 expected = color + mix(utils::RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckDstBlendFactor(base, wgpu::BlendFactor::OneMinusSrc, wgpu::BlendFactor::Zero, tests);
}
TEST_P(ColorStateTest, DstBlendFactorSrcAlpha) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
RGBA8 fac(color.a, color.a, color.a, color.a);
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
[&](const utils::RGBA8& color) {
utils::RGBA8 fac(color.a, color.a, color.a, color.a);
utils::RGBA8 expected = color + mix(utils::RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckDstBlendFactor(base, wgpu::BlendFactor::SrcAlpha, wgpu::BlendFactor::SrcAlpha, tests);
}
TEST_P(ColorStateTest, DstBlendFactorOneMinusSrcAlpha) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests), [&](const RGBA8& color) {
RGBA8 fac = RGBA8(255, 255, 255, 255) - RGBA8(color.a, color.a, color.a, color.a);
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
kColors.begin(), kColors.end(), std::back_inserter(tests), [&](const utils::RGBA8& color) {
utils::RGBA8 fac =
utils::RGBA8(255, 255, 255, 255) - utils::RGBA8(color.a, color.a, color.a, color.a);
utils::RGBA8 expected = color + mix(utils::RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckDstBlendFactor(base, wgpu::BlendFactor::OneMinusSrcAlpha,
@ -592,50 +604,51 @@ TEST_P(ColorStateTest, DstBlendFactorOneMinusSrcAlpha) {
}
TEST_P(ColorStateTest, DstBlendFactorDst) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
RGBA8 fac = base;
[&](const utils::RGBA8& color) {
utils::RGBA8 fac = base;
fac.a = 0;
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
utils::RGBA8 expected = color + mix(utils::RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckDstBlendFactor(base, wgpu::BlendFactor::Dst, wgpu::BlendFactor::Zero, tests);
}
TEST_P(ColorStateTest, DstBlendFactorOneMinusDst) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
RGBA8 fac = RGBA8(255, 255, 255, 255) - base;
[&](const utils::RGBA8& color) {
utils::RGBA8 fac = utils::RGBA8(255, 255, 255, 255) - base;
fac.a = 0;
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
utils::RGBA8 expected = color + mix(utils::RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckDstBlendFactor(base, wgpu::BlendFactor::OneMinusDst, wgpu::BlendFactor::Zero, tests);
}
TEST_P(ColorStateTest, DstBlendFactorDstAlpha) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
RGBA8 fac(base.a, base.a, base.a, base.a);
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
[&](const utils::RGBA8& color) {
utils::RGBA8 fac(base.a, base.a, base.a, base.a);
utils::RGBA8 expected = color + mix(utils::RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckDstBlendFactor(base, wgpu::BlendFactor::DstAlpha, wgpu::BlendFactor::DstAlpha, tests);
}
TEST_P(ColorStateTest, DstBlendFactorOneMinusDstAlpha) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests), [&](const RGBA8& color) {
RGBA8 fac = RGBA8(255, 255, 255, 255) - RGBA8(base.a, base.a, base.a, base.a);
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
kColors.begin(), kColors.end(), std::back_inserter(tests), [&](const utils::RGBA8& color) {
utils::RGBA8 fac =
utils::RGBA8(255, 255, 255, 255) - utils::RGBA8(base.a, base.a, base.a, base.a);
utils::RGBA8 expected = color + mix(utils::RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckDstBlendFactor(base, wgpu::BlendFactor::OneMinusDstAlpha,
@ -643,13 +656,13 @@ TEST_P(ColorStateTest, DstBlendFactorOneMinusDstAlpha) {
}
TEST_P(ColorStateTest, DstBlendFactorSrcAlphaSaturated) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
[&](const utils::RGBA8& color) {
uint8_t f = std::min(color.a, static_cast<uint8_t>(255 - base.a));
RGBA8 fac(f, f, f, 255);
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
utils::RGBA8 fac(f, f, f, 255);
utils::RGBA8 expected = color + mix(utils::RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckDstBlendFactor(base, wgpu::BlendFactor::SrcAlphaSaturated,
@ -657,25 +670,26 @@ TEST_P(ColorStateTest, DstBlendFactorSrcAlphaSaturated) {
}
TEST_P(ColorStateTest, DstBlendFactorConstant) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests), [&](const RGBA8& color) {
auto triangleSpec = TriangleSpec({{color}, {{0.2f, 0.4f, 0.6f, 0.8f}}});
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, triangleSpec.blendFactor);
return std::make_pair(triangleSpec, expected);
});
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const utils::RGBA8& color) {
auto triangleSpec = TriangleSpec({{color}, {{0.2f, 0.4f, 0.6f, 0.8f}}});
utils::RGBA8 expected =
color + mix(utils::RGBA8(0, 0, 0, 0), base, triangleSpec.blendFactor);
return std::make_pair(triangleSpec, expected);
});
CheckDstBlendFactor(base, wgpu::BlendFactor::Constant, wgpu::BlendFactor::Constant, tests);
}
TEST_P(ColorStateTest, DstBlendFactorOneMinusConstant) {
RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, RGBA8>> tests;
utils::RGBA8 base(32, 64, 128, 192);
std::vector<std::pair<TriangleSpec, utils::RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) {
[&](const utils::RGBA8& color) {
auto triangleSpec = TriangleSpec({{color}, {{0.2f, 0.4f, 0.6f, 0.8f}}});
std::array<float, 4> f = {{0.8f, 0.6f, 0.4f, 0.2f}};
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, f);
utils::RGBA8 expected = color + mix(utils::RGBA8(0, 0, 0, 0), base, f);
return std::make_pair(triangleSpec, expected);
});
CheckDstBlendFactor(base, wgpu::BlendFactor::OneMinusConstant,
@ -700,9 +714,9 @@ TEST_P(ColorStateTest, ColorWriteMask) {
descriptor.writeMask = wgpu::ColorWriteMask::Red;
SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192);
utils::RGBA8 base(32, 64, 128, 192);
for (auto& color : kColors) {
RGBA8 expected = base + RGBA8(color.r, 0, 0, 0);
utils::RGBA8 expected = base + utils::RGBA8(color.r, 0, 0, 0);
DoSingleSourceTest(base, {color}, expected);
}
}
@ -712,9 +726,9 @@ TEST_P(ColorStateTest, ColorWriteMask) {
descriptor.writeMask = wgpu::ColorWriteMask::Green | wgpu::ColorWriteMask::Alpha;
SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192);
utils::RGBA8 base(32, 64, 128, 192);
for (auto& color : kColors) {
RGBA8 expected = base + RGBA8(0, color.g, 0, color.a);
utils::RGBA8 expected = base + utils::RGBA8(0, color.g, 0, color.a);
DoSingleSourceTest(base, {color}, expected);
}
}
@ -724,7 +738,7 @@ TEST_P(ColorStateTest, ColorWriteMask) {
descriptor.writeMask = wgpu::ColorWriteMask::None;
SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192);
utils::RGBA8 base(32, 64, 128, 192);
for (auto& color : kColors) {
DoSingleSourceTest(base, {color}, base);
}
@ -748,14 +762,14 @@ TEST_P(ColorStateTest, ColorWriteMaskBlendingDisabled) {
descriptor.writeMask = wgpu::ColorWriteMask::Red;
SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192);
RGBA8 expected(32, 0, 0, 0);
utils::RGBA8 base(32, 64, 128, 192);
utils::RGBA8 expected(32, 0, 0, 0);
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(testPipeline);
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({{base}})));
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<utils::RGBA8, 1>({{base}})));
pass.Draw(3);
pass.End();
}
@ -869,28 +883,28 @@ TEST_P(ColorStateTest, IndependentColorState) {
testPipeline = device.CreateRenderPipeline(&testDescriptor);
for (unsigned int c = 0; c < kColors.size(); ++c) {
RGBA8 base = kColors[((c + 31) * 29) % kColors.size()];
RGBA8 color0 = kColors[((c + 19) * 13) % kColors.size()];
RGBA8 color1 = kColors[((c + 11) * 43) % kColors.size()];
RGBA8 color2 = kColors[((c + 7) * 3) % kColors.size()];
RGBA8 color3 = kColors[((c + 13) * 71) % kColors.size()];
utils::RGBA8 base = kColors[((c + 31) * 29) % kColors.size()];
utils::RGBA8 color0 = kColors[((c + 19) * 13) % kColors.size()];
utils::RGBA8 color1 = kColors[((c + 11) * 43) % kColors.size()];
utils::RGBA8 color2 = kColors[((c + 7) * 3) % kColors.size()];
utils::RGBA8 color3 = kColors[((c + 13) * 71) % kColors.size()];
RGBA8 expected0 = color0 + base;
RGBA8 expected1 = color1 - base;
RGBA8 expected2 = color2;
RGBA8 expected3 = min(color3, base);
utils::RGBA8 expected0 = color0 + base;
utils::RGBA8 expected1 = color1 - base;
utils::RGBA8 expected2 = color2;
utils::RGBA8 expected3 = min(color3, base);
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
pass.SetPipeline(basePipeline);
pass.SetBindGroup(
0, MakeBindGroupForColors(std::array<RGBA8, 4>({{base, base, base, base}})));
0, MakeBindGroupForColors(std::array<utils::RGBA8, 4>({{base, base, base, base}})));
pass.Draw(3);
pass.SetPipeline(testPipeline);
pass.SetBindGroup(0, MakeBindGroupForColors(
std::array<RGBA8, 4>({{color0, color1, color2, color3}})));
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<utils::RGBA8, 4>(
{{color0, color1, color2, color3}})));
pass.Draw(3);
pass.End();
}
@ -961,12 +975,12 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
{
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(basePipeline);
pass.SetBindGroup(0,
MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}})));
pass.SetBindGroup(0, MakeBindGroupForColors(
std::array<utils::RGBA8, 1>({{utils::RGBA8(0, 0, 0, 0)}})));
pass.Draw(3);
pass.SetPipeline(testPipeline);
pass.SetBindGroup(
0, MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(255, 255, 255, 255)}})));
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<utils::RGBA8, 1>(
{{utils::RGBA8(255, 255, 255, 255)}})));
pass.Draw(3);
pass.End();
}
@ -974,7 +988,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, kRTSize / 2, kRTSize / 2);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 0, 0, 0), renderPass.color, kRTSize / 2, kRTSize / 2);
}
// Check that setting the blend color works
@ -983,13 +997,13 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
{
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(basePipeline);
pass.SetBindGroup(0,
MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}})));
pass.SetBindGroup(0, MakeBindGroupForColors(
std::array<utils::RGBA8, 1>({{utils::RGBA8(0, 0, 0, 0)}})));
pass.Draw(3);
pass.SetPipeline(testPipeline);
pass.SetBlendConstant(&kWhite);
pass.SetBindGroup(
0, MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(255, 255, 255, 255)}})));
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<utils::RGBA8, 1>(
{{utils::RGBA8(255, 255, 255, 255)}})));
pass.Draw(3);
pass.End();
}
@ -997,7 +1011,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(255, 255, 255, 255), renderPass.color, kRTSize / 2,
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(255, 255, 255, 255), renderPass.color, kRTSize / 2,
kRTSize / 2);
}
@ -1007,25 +1021,25 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
{
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(basePipeline);
pass.SetBindGroup(0,
MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}})));
pass.SetBindGroup(0, MakeBindGroupForColors(
std::array<utils::RGBA8, 1>({{utils::RGBA8(0, 0, 0, 0)}})));
pass.Draw(3);
pass.SetPipeline(testPipeline);
pass.SetBlendConstant(&kWhite);
pass.SetBindGroup(
0, MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(255, 255, 255, 255)}})));
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<utils::RGBA8, 1>(
{{utils::RGBA8(255, 255, 255, 255)}})));
pass.Draw(3);
pass.End();
}
{
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(basePipeline);
pass.SetBindGroup(0,
MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}})));
pass.SetBindGroup(0, MakeBindGroupForColors(
std::array<utils::RGBA8, 1>({{utils::RGBA8(0, 0, 0, 0)}})));
pass.Draw(3);
pass.SetPipeline(testPipeline);
pass.SetBindGroup(
0, MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(255, 255, 255, 255)}})));
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<utils::RGBA8, 1>(
{{utils::RGBA8(255, 255, 255, 255)}})));
pass.Draw(3);
pass.End();
}
@ -1033,7 +1047,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, kRTSize / 2, kRTSize / 2);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 0, 0, 0), renderPass.color, kRTSize / 2, kRTSize / 2);
}
}
@ -1070,15 +1084,15 @@ TEST_P(ColorStateTest, ColorWriteMaskDoesNotAffectRenderPassLoadOpClear) {
testPipeline = device.CreateRenderPipeline(&testDescriptor);
RGBA8 base(32, 64, 128, 192);
RGBA8 expected(0, 0, 0, 0);
utils::RGBA8 base(32, 64, 128, 192);
utils::RGBA8 expected(0, 0, 0, 0);
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{
// Clear the render attachment to |base|
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(basePipeline);
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({{base}})));
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<utils::RGBA8, 1>({{base}})));
pass.Draw(3);
// Set a pipeline that will dirty the color write mask
@ -1155,8 +1169,8 @@ TEST_P(ColorStateTest, SparseAttachmentsDifferentColorMask) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kWhite, attachment1, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, attachment3, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kWhite, attachment1, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, attachment3, 0, 0);
}
DAWN_INSTANTIATE_TEST(ColorStateTest,

View File

@ -201,7 +201,7 @@ class CompressedTextureFormatTest : public DawnTestWithParams<CompressedTextureF
const wgpu::Extent3D& renderTargetSize,
const wgpu::Origin3D& expectedOrigin,
const wgpu::Extent3D& expectedExtent,
const std::vector<RGBA8>& expected) {
const std::vector<utils::RGBA8>& expected) {
ASSERT(IsFormatSupported());
utils::BasicRenderPass renderPass =
@ -250,7 +250,7 @@ class CompressedTextureFormatTest : public DawnTestWithParams<CompressedTextureF
}
noPaddingExtent3D.depthOrArrayLayers = 1u;
std::vector<RGBA8> expectedData = GetExpectedData(noPaddingExtent3D);
std::vector<utils::RGBA8> expectedData = GetExpectedData(noPaddingExtent3D);
wgpu::Origin3D firstLayerCopyOrigin = {config.copyOrigin3D.x, config.copyOrigin3D.y, 0};
for (uint32_t layer = config.copyOrigin3D.z;
@ -447,24 +447,24 @@ class CompressedTextureFormatTest : public DawnTestWithParams<CompressedTextureF
// Return the texture data that is decoded from the result of GetOneBlockFormatTextureData
// in RGBA8 formats. Since some compression methods may be lossy, we may use different colors
// to test different formats.
std::vector<RGBA8> GetExpectedData(const wgpu::Extent3D& testRegion) {
std::vector<utils::RGBA8> GetExpectedData(const wgpu::Extent3D& testRegion) {
constexpr uint8_t kLeftAlpha = 0x88;
constexpr uint8_t kRightAlpha = 0xFF;
constexpr RGBA8 kBCDarkRed(198, 0, 0, 255);
constexpr RGBA8 kBCDarkGreen(0, 207, 0, 255);
constexpr RGBA8 kBCDarkRedSRGB(144, 0, 0, 255);
constexpr RGBA8 kBCDarkGreenSRGB(0, 159, 0, 255);
constexpr utils::RGBA8 kBCDarkRed(198, 0, 0, 255);
constexpr utils::RGBA8 kBCDarkGreen(0, 207, 0, 255);
constexpr utils::RGBA8 kBCDarkRedSRGB(144, 0, 0, 255);
constexpr utils::RGBA8 kBCDarkGreenSRGB(0, 159, 0, 255);
constexpr RGBA8 kETC2DarkRed(204, 0, 0, 255);
constexpr RGBA8 kETC2DarkGreen(0, 204, 0, 255);
constexpr RGBA8 kETC2DarkRedSRGB(154, 0, 0, 255);
constexpr RGBA8 kETC2DarkGreenSRGB(0, 154, 0, 255);
constexpr utils::RGBA8 kETC2DarkRed(204, 0, 0, 255);
constexpr utils::RGBA8 kETC2DarkGreen(0, 204, 0, 255);
constexpr utils::RGBA8 kETC2DarkRedSRGB(154, 0, 0, 255);
constexpr utils::RGBA8 kETC2DarkGreenSRGB(0, 154, 0, 255);
constexpr RGBA8 kASTCDarkRed(244, 0, 0, 128);
constexpr RGBA8 kASTCDarkGreen(0, 244, 0, 255);
constexpr RGBA8 kASTCDarkRedSRGB(231, 0, 0, 128);
constexpr RGBA8 kASTCDarkGreenSRGB(0, 231, 0, 255);
constexpr utils::RGBA8 kASTCDarkRed(244, 0, 0, 128);
constexpr utils::RGBA8 kASTCDarkGreen(0, 244, 0, 255);
constexpr utils::RGBA8 kASTCDarkRedSRGB(231, 0, 0, 128);
constexpr utils::RGBA8 kASTCDarkGreenSRGB(0, 231, 0, 255);
switch (GetParam().mTextureFormat) {
case wgpu::TextureFormat::BC1RGBAUnorm:
@ -473,8 +473,9 @@ class CompressedTextureFormatTest : public DawnTestWithParams<CompressedTextureF
case wgpu::TextureFormat::BC2RGBAUnorm:
case wgpu::TextureFormat::BC3RGBAUnorm: {
constexpr RGBA8 kLeftColor = RGBA8(kBCDarkRed.r, 0, 0, kLeftAlpha);
constexpr RGBA8 kRightColor = RGBA8(0, kBCDarkGreen.g, 0, kRightAlpha);
constexpr utils::RGBA8 kLeftColor = utils::RGBA8(kBCDarkRed.r, 0, 0, kLeftAlpha);
constexpr utils::RGBA8 kRightColor =
utils::RGBA8(0, kBCDarkGreen.g, 0, kRightAlpha);
return FillExpectedData(testRegion, kLeftColor, kRightColor);
}
@ -484,20 +485,22 @@ class CompressedTextureFormatTest : public DawnTestWithParams<CompressedTextureF
case wgpu::TextureFormat::BC2RGBAUnormSrgb:
case wgpu::TextureFormat::BC3RGBAUnormSrgb: {
constexpr RGBA8 kLeftColor = RGBA8(kBCDarkRedSRGB.r, 0, 0, kLeftAlpha);
constexpr RGBA8 kRightColor = RGBA8(0, kBCDarkGreenSRGB.g, 0, kRightAlpha);
constexpr utils::RGBA8 kLeftColor =
utils::RGBA8(kBCDarkRedSRGB.r, 0, 0, kLeftAlpha);
constexpr utils::RGBA8 kRightColor =
utils::RGBA8(0, kBCDarkGreenSRGB.g, 0, kRightAlpha);
return FillExpectedData(testRegion, kLeftColor, kRightColor);
}
case wgpu::TextureFormat::BC4RSnorm:
case wgpu::TextureFormat::BC4RUnorm:
return FillExpectedData(testRegion, RGBA8::kRed, RGBA8::kBlack);
return FillExpectedData(testRegion, utils::RGBA8::kRed, utils::RGBA8::kBlack);
case wgpu::TextureFormat::BC5RGSnorm:
case wgpu::TextureFormat::BC5RGUnorm:
case wgpu::TextureFormat::BC6HRGBFloat:
case wgpu::TextureFormat::BC6HRGBUfloat:
return FillExpectedData(testRegion, RGBA8::kRed, RGBA8::kGreen);
return FillExpectedData(testRegion, utils::RGBA8::kRed, utils::RGBA8::kGreen);
case wgpu::TextureFormat::ETC2RGB8Unorm:
case wgpu::TextureFormat::ETC2RGB8A1Unorm:
@ -508,24 +511,27 @@ class CompressedTextureFormatTest : public DawnTestWithParams<CompressedTextureF
return FillExpectedData(testRegion, kETC2DarkRedSRGB, kETC2DarkGreenSRGB);
case wgpu::TextureFormat::ETC2RGBA8Unorm: {
constexpr RGBA8 kLeftColor = RGBA8(kETC2DarkRed.r, 0, 0, kLeftAlpha);
constexpr RGBA8 kRightColor = RGBA8(0, kETC2DarkGreen.g, 0, kRightAlpha);
constexpr utils::RGBA8 kLeftColor = utils::RGBA8(kETC2DarkRed.r, 0, 0, kLeftAlpha);
constexpr utils::RGBA8 kRightColor =
utils::RGBA8(0, kETC2DarkGreen.g, 0, kRightAlpha);
return FillExpectedData(testRegion, kLeftColor, kRightColor);
}
case wgpu::TextureFormat::ETC2RGBA8UnormSrgb: {
constexpr RGBA8 kLeftColor = RGBA8(kETC2DarkRedSRGB.r, 0, 0, kLeftAlpha);
constexpr RGBA8 kRightColor = RGBA8(0, kETC2DarkGreenSRGB.g, 0, kRightAlpha);
constexpr utils::RGBA8 kLeftColor =
utils::RGBA8(kETC2DarkRedSRGB.r, 0, 0, kLeftAlpha);
constexpr utils::RGBA8 kRightColor =
utils::RGBA8(0, kETC2DarkGreenSRGB.g, 0, kRightAlpha);
return FillExpectedData(testRegion, kLeftColor, kRightColor);
}
case wgpu::TextureFormat::EACR11Unorm:
case wgpu::TextureFormat::EACR11Snorm:
return FillExpectedData(testRegion, RGBA8::kRed, RGBA8::kBlack);
return FillExpectedData(testRegion, utils::RGBA8::kRed, utils::RGBA8::kBlack);
case wgpu::TextureFormat::EACRG11Unorm:
case wgpu::TextureFormat::EACRG11Snorm:
return FillExpectedData(testRegion, RGBA8::kRed, RGBA8::kGreen);
return FillExpectedData(testRegion, utils::RGBA8::kRed, utils::RGBA8::kGreen);
case wgpu::TextureFormat::ASTC4x4Unorm:
case wgpu::TextureFormat::ASTC5x4Unorm:
@ -565,12 +571,13 @@ class CompressedTextureFormatTest : public DawnTestWithParams<CompressedTextureF
}
}
std::vector<RGBA8> FillExpectedData(const wgpu::Extent3D& testRegion,
RGBA8 leftColorInBlock,
RGBA8 rightColorInBlock) {
std::vector<utils::RGBA8> FillExpectedData(const wgpu::Extent3D& testRegion,
utils::RGBA8 leftColorInBlock,
utils::RGBA8 rightColorInBlock) {
ASSERT(testRegion.depthOrArrayLayers == 1);
std::vector<RGBA8> expectedData(testRegion.width * testRegion.height, leftColorInBlock);
std::vector<utils::RGBA8> expectedData(testRegion.width * testRegion.height,
leftColorInBlock);
for (uint32_t y = 0; y < testRegion.height; ++y) {
for (uint32_t x = 0; x < testRegion.width; ++x) {
if (x % BlockWidthInTexels() >= BlockWidthInTexels() / 2) {
@ -760,7 +767,7 @@ TEST_P(CompressedTextureFormatTest, CopyWholeTextureSubResourceIntoNonZeroMipmap
CreateBindGroupForTest(renderPipeline.GetBindGroupLayout(0), textureDst,
config.copyOrigin3D.z, config.viewMipmapLevel);
std::vector<RGBA8> expectedData = GetExpectedData(kVirtualSize);
std::vector<utils::RGBA8> expectedData = GetExpectedData(kVirtualSize);
VerifyCompressedTexturePixelValues(renderPipeline, bindGroup, kVirtualSize, config.copyOrigin3D,
kVirtualSize, expectedData);
}
@ -800,7 +807,7 @@ TEST_P(CompressedTextureFormatTest, CopyIntoSubresourceWithPhysicalSizeNotEqualT
CreateBindGroupForTest(renderPipeline.GetBindGroupLayout(0), textureDst,
dstConfig.copyOrigin3D.z, dstConfig.viewMipmapLevel);
std::vector<RGBA8> expectedData = GetExpectedData(kDstVirtualSize);
std::vector<utils::RGBA8> expectedData = GetExpectedData(kDstVirtualSize);
VerifyCompressedTexturePixelValues(renderPipeline, bindGroup, kDstVirtualSize,
dstConfig.copyOrigin3D, kDstVirtualSize, expectedData);
}
@ -841,7 +848,7 @@ TEST_P(CompressedTextureFormatTest, CopyFromSubresourceWithPhysicalSizeNotEqualT
CreateBindGroupForTest(renderPipeline.GetBindGroupLayout(0), textureDst,
dstConfig.copyOrigin3D.z, dstConfig.viewMipmapLevel);
std::vector<RGBA8> expectedData = GetExpectedData(kDstVirtualSize);
std::vector<utils::RGBA8> expectedData = GetExpectedData(kDstVirtualSize);
VerifyCompressedTexturePixelValues(renderPipeline, bindGroup, kDstVirtualSize,
dstConfig.copyOrigin3D, kDstVirtualSize, expectedData);
}
@ -900,7 +907,7 @@ TEST_P(CompressedTextureFormatTest, MultipleCopiesWithPhysicalSizeNotEqualToVirt
CreateBindGroupForTest(renderPipeline.GetBindGroupLayout(0), dstTextures[i],
dstConfigs[i].copyOrigin3D.z, dstConfigs[i].viewMipmapLevel);
std::vector<RGBA8> expectedData = GetExpectedData(dstVirtualSizes[i]);
std::vector<utils::RGBA8> expectedData = GetExpectedData(dstVirtualSizes[i]);
VerifyCompressedTexturePixelValues(renderPipeline, bindGroup0, dstVirtualSizes[i],
dstConfigs[i].copyOrigin3D, dstVirtualSizes[i],
expectedData);
@ -954,7 +961,7 @@ TEST_P(CompressedTextureFormatTest, CopyWithMultipleLayerAndPhysicalSizeNotEqual
const wgpu::Extent3D kExpectedDataRegionPerLayer = {kDstVirtualSize.width,
kDstVirtualSize.height, 1u};
std::vector<RGBA8> kExpectedDataPerLayer = GetExpectedData(kExpectedDataRegionPerLayer);
std::vector<utils::RGBA8> kExpectedDataPerLayer = GetExpectedData(kExpectedDataRegionPerLayer);
const wgpu::Origin3D kCopyOriginPerLayer = {dstConfig.copyOrigin3D.x, dstConfig.copyOrigin3D.y,
0};
for (uint32_t copyLayer = 0; copyLayer < kArrayLayerCount; ++copyLayer) {

View File

@ -63,18 +63,18 @@ class CopyTests {
// TODO(crbug.com/dawn/818): remove this function when all the tests in this file support
// testing arbitrary formats.
static std::vector<RGBA8> GetExpectedTextureDataRGBA8(
static std::vector<utils::RGBA8> GetExpectedTextureDataRGBA8(
const utils::TextureDataCopyLayout& layout) {
std::vector<RGBA8> textureData(layout.texelBlockCount);
std::vector<utils::RGBA8> textureData(layout.texelBlockCount);
for (uint32_t layer = 0; layer < layout.mipSize.depthOrArrayLayers; ++layer) {
const uint32_t texelIndexOffsetPerSlice = layout.texelBlocksPerImage * layer;
for (uint32_t y = 0; y < layout.mipSize.height; ++y) {
for (uint32_t x = 0; x < layout.mipSize.width; ++x) {
uint32_t i = x + y * layout.texelBlocksPerRow;
textureData[texelIndexOffsetPerSlice + i] =
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>(y / 256));
utils::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>(y / 256));
}
}
}
@ -157,7 +157,7 @@ class CopyTests_T2B : public CopyTests, public DawnTest {
textureSpec.format, textureSpec.textureSize, textureSpec.copyLevel, dimension);
// Initialize the source texture
std::vector<RGBA8> textureArrayData = GetExpectedTextureDataRGBA8(copyLayout);
std::vector<utils::RGBA8> textureArrayData = GetExpectedTextureDataRGBA8(copyLayout);
{
wgpu::ImageCopyTexture imageCopyTexture =
utils::CreateImageCopyTexture(texture, textureSpec.copyLevel, {0, 0, 0});
@ -203,11 +203,11 @@ class CopyTests_T2B : public CopyTests, public DawnTest {
const uint32_t texelCountInCopyRegion = utils::GetTexelCountInCopyRegion(
bufferSpec.bytesPerRow, bufferSpec.rowsPerImage, copySizePerLayer, textureSpec.format);
const uint32_t maxArrayLayer = textureSpec.copyOrigin.z + copyLayer;
std::vector<RGBA8> expected(texelCountInCopyRegion);
std::vector<utils::RGBA8> expected(texelCountInCopyRegion);
for (uint32_t layer = textureSpec.copyOrigin.z; layer < maxArrayLayer; ++layer) {
// Copy the data used to create the upload buffer in the specified copy region to have
// the same format as the expected buffer data.
std::fill(expected.begin(), expected.end(), RGBA8());
std::fill(expected.begin(), expected.end(), utils::RGBA8());
const uint32_t texelIndexOffset = copyLayout.texelBlocksPerImage * layer;
const uint32_t expectedTexelArrayDataStartIndex =
texelIndexOffset + (textureSpec.copyOrigin.x +
@ -238,10 +238,11 @@ class CopyTests_T2B : public CopyTests, public DawnTest {
class CopyTests_B2T : public CopyTests, public DawnTest {
protected:
static void FillBufferData(RGBA8* data, size_t count) {
static void FillBufferData(utils::RGBA8* data, size_t count) {
for (size_t i = 0; i < count; ++i) {
data[i] = RGBA8(static_cast<uint8_t>(i % 256), static_cast<uint8_t>((i / 256) % 256),
static_cast<uint8_t>((i / 256 / 256) % 256), 255);
data[i] =
utils::RGBA8(static_cast<uint8_t>(i % 256), static_cast<uint8_t>((i / 256) % 256),
static_cast<uint8_t>((i / 256 / 256) % 256), 255);
}
}
@ -253,7 +254,7 @@ class CopyTests_B2T : public CopyTests, public DawnTest {
ASSERT_EQ(kDefaultFormat, textureSpec.format);
// Create a buffer of size `size` and populate it with data
const uint32_t bytesPerTexel = utils::GetTexelBlockSizeInBytes(textureSpec.format);
std::vector<RGBA8> bufferData(bufferSpec.size / bytesPerTexel);
std::vector<utils::RGBA8> bufferData(bufferSpec.size / bytesPerTexel);
FillBufferData(bufferData.data(), bufferData.size());
wgpu::Buffer buffer =
utils::CreateBufferFromData(device, bufferData.data(), bufferSpec.size,
@ -301,7 +302,7 @@ class CopyTests_B2T : public CopyTests, public DawnTest {
for (uint32_t layer = 0; layer < copyLayer; ++layer) {
// Copy and pack the data used to create the buffer in the specified copy region to have
// the same format as the expected texture data.
std::vector<RGBA8> expected(texelCountPerLayer);
std::vector<utils::RGBA8> expected(texelCountPerLayer);
CopyTextureData(bytesPerTexel, bufferData.data() + bufferOffset / bytesPerTexel,
copySize.width, copySize.height, copyDepth, bufferSpec.bytesPerRow,
bufferSpec.rowsPerImage, expected.data(),

View File

@ -166,13 +166,13 @@ class CopyTextureForBrowserTests : public Parent {
};
// Source texture contains red pixels and dst texture contains green pixels at start.
static std::vector<RGBA8> GetTextureData(
static std::vector<utils::RGBA8> GetTextureData(
const utils::TextureDataCopyLayout& layout,
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::vector<RGBA8> textureData(layout.texelBlockCount);
std::vector<utils::RGBA8> textureData(layout.texelBlockCount);
for (uint32_t layer = 0; layer < layout.mipSize.depthOrArrayLayers; ++layer) {
const uint32_t sliceOffset = layout.texelBlocksPerImage * layer;
for (uint32_t y = 0; y < layout.mipSize.height; ++y) {
@ -185,7 +185,7 @@ class CopyTextureForBrowserTests : public Parent {
dstAlphaMode == wgpu::AlphaMode::Premultiplied) {
// We expect each channel in dst
// texture will equal to the alpha channel value.
textureData[sliceOffset + rowOffset + x] = RGBA8(
textureData[sliceOffset + rowOffset + x] = utils::RGBA8(
static_cast<uint8_t>(255), static_cast<uint8_t>(255),
static_cast<uint8_t>(255), static_cast<uint8_t>(alpha[x % 4]));
} else if (srcAlphaMode == wgpu::AlphaMode::Premultiplied &&
@ -193,21 +193,21 @@ class CopyTextureForBrowserTests : public Parent {
// We expect each channel in dst
// texture will equal to 1.0.
textureData[sliceOffset + rowOffset + x] =
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]));
utils::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]));
} else {
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));
textureData[sliceOffset + rowOffset + x] = utils::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
// copy not cross bound.
textureData[sliceOffset + rowOffset + x] =
RGBA8(static_cast<uint8_t>(0), static_cast<uint8_t>(255),
static_cast<uint8_t>(0), static_cast<uint8_t>(255));
utils::RGBA8(static_cast<uint8_t>(0), static_cast<uint8_t>(255),
static_cast<uint8_t>(0), static_cast<uint8_t>(255));
}
}
}
@ -499,14 +499,14 @@ class CopyTextureForBrowserTests : public Parent {
copySize.depthOrArrayLayers},
srcSpec.level);
std::vector<RGBA8> srcTextureArrayCopyData = GetTextureData(
std::vector<utils::RGBA8> srcTextureArrayCopyData = GetTextureData(
srcCopyLayout, TextureCopyRole::SOURCE, options.srcAlphaMode, options.dstAlphaMode);
wgpu::TextureUsage srcUsage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
wgpu::TextureUsage::TextureBinding;
wgpu::Texture srcTexture =
CreateAndInitTexture(srcSpec, srcUsage, srcCopyLayout, srcTextureArrayCopyData.data(),
srcTextureArrayCopyData.size() * sizeof(RGBA8));
srcTextureArrayCopyData.size() * sizeof(utils::RGBA8));
bool testSubRectCopy = srcSpec.copyOrigin.x > 0 || srcSpec.copyOrigin.y > 0 ||
dstSpec.copyOrigin.x > 0 || dstSpec.copyOrigin.y > 0 ||
@ -530,11 +530,11 @@ class CopyTextureForBrowserTests : public Parent {
copySize.depthOrArrayLayers},
dstSpec.level);
const std::vector<RGBA8> dstTextureArrayCopyData =
const std::vector<utils::RGBA8> dstTextureArrayCopyData =
GetTextureData(dstCopyLayout, TextureCopyRole::DEST);
dstTexture = CreateAndInitTexture(dstSpec, dstUsage, dstCopyLayout,
dstTextureArrayCopyData.data(),
dstTextureArrayCopyData.size() * sizeof(RGBA8));
dstTexture = CreateAndInitTexture(
dstSpec, dstUsage, dstCopyLayout, dstTextureArrayCopyData.data(),
dstTextureArrayCopyData.size() * sizeof(utils::RGBA8));
} else {
dstTexture = CreateTexture(dstSpec, dstUsage);
}
@ -588,25 +588,25 @@ class CopyTextureForBrowser_Formats
// Create and init source texture.
// This fixed source texture data is for color conversion tests.
// The source data can fill a texture in default width and height.
std::vector<RGBA8> srcRGBA8UnormTextureArrayCopyData{
std::vector<utils::RGBA8> srcRGBA8UnormTextureArrayCopyData{
// Take RGBA8Unorm as example:
// R channel has different values
RGBA8(0, 255, 255, 255), // r = 0.0
RGBA8(102, 255, 255, 255), // r = 0.4
RGBA8(153, 255, 255, 255), // r = 0.6
utils::RGBA8(0, 255, 255, 255), // r = 0.0
utils::RGBA8(102, 255, 255, 255), // r = 0.4
utils::RGBA8(153, 255, 255, 255), // r = 0.6
// G channel has different values
RGBA8(255, 0, 255, 255), // g = 0.0
RGBA8(255, 102, 255, 255), // g = 0.4
RGBA8(255, 153, 255, 255), // g = 0.6
utils::RGBA8(255, 0, 255, 255), // g = 0.0
utils::RGBA8(255, 102, 255, 255), // g = 0.4
utils::RGBA8(255, 153, 255, 255), // g = 0.6
// B channel has different values
RGBA8(255, 255, 0, 255), // b = 0.0
RGBA8(255, 255, 102, 255), // b = 0.4
RGBA8(255, 255, 153, 255), // b = 0.6
utils::RGBA8(255, 255, 0, 255), // b = 0.0
utils::RGBA8(255, 255, 102, 255), // b = 0.4
utils::RGBA8(255, 255, 153, 255), // b = 0.6
// A channel set to 0
RGBA8(255, 255, 255, 0) // a = 0
utils::RGBA8(255, 255, 255, 0) // a = 0
};
std::vector<uint16_t> srcRGBA16FloatTextureArrayCopyData{
@ -659,7 +659,7 @@ class CopyTextureForBrowser_Formats
case wgpu::TextureFormat::BGRA8Unorm:
return CreateAndInitTexture(
srcSpec, srcUsage, srcCopyLayout, srcRGBA8UnormTextureArrayCopyData.data(),
srcRGBA8UnormTextureArrayCopyData.size() * sizeof(RGBA8));
srcRGBA8UnormTextureArrayCopyData.size() * sizeof(utils::RGBA8));
case wgpu::TextureFormat::RGBA16Float:
return CreateAndInitTexture(
srcSpec, srcUsage, srcCopyLayout, srcRGBA16FloatTextureArrayCopyData.data(),
@ -813,45 +813,45 @@ class CopyTextureForBrowser_ColorSpace
}
// TODO(crbug.com/dawn/1140): Generate source data automatically.
std::vector<RGBA8> GetSourceData(wgpu::AlphaMode srcTextureAlphaMode) {
std::vector<utils::RGBA8> GetSourceData(wgpu::AlphaMode srcTextureAlphaMode) {
if (srcTextureAlphaMode == wgpu::AlphaMode::Premultiplied) {
return std::vector<RGBA8>{
RGBA8(0, 102, 102, 102), // a = 0.4
RGBA8(102, 0, 0, 102), // a = 0.4
RGBA8(153, 0, 0, 153), // a = 0.6
RGBA8(255, 0, 0, 255), // a = 1.0
return std::vector<utils::RGBA8>{
utils::RGBA8(0, 102, 102, 102), // a = 0.4
utils::RGBA8(102, 0, 0, 102), // a = 0.4
utils::RGBA8(153, 0, 0, 153), // a = 0.6
utils::RGBA8(255, 0, 0, 255), // a = 1.0
RGBA8(153, 0, 153, 153), // a = 0.6
RGBA8(0, 102, 0, 102), // a = 0.4
RGBA8(0, 153, 0, 153), // a = 0.6
RGBA8(0, 255, 0, 255), // a = 1.0
utils::RGBA8(153, 0, 153, 153), // a = 0.6
utils::RGBA8(0, 102, 0, 102), // a = 0.4
utils::RGBA8(0, 153, 0, 153), // a = 0.6
utils::RGBA8(0, 255, 0, 255), // a = 1.0
RGBA8(255, 255, 0, 255), // a = 1.0
RGBA8(0, 0, 102, 102), // a = 0.4
RGBA8(0, 0, 153, 153), // a = 0.6
RGBA8(0, 0, 255, 255), // a = 1.0
utils::RGBA8(255, 255, 0, 255), // a = 1.0
utils::RGBA8(0, 0, 102, 102), // a = 0.4
utils::RGBA8(0, 0, 153, 153), // a = 0.6
utils::RGBA8(0, 0, 255, 255), // a = 1.0
};
}
return std::vector<RGBA8>{
return std::vector<utils::RGBA8>{
// Take RGBA8Unorm as example:
// R channel has different values
RGBA8(0, 255, 255, 255), // r = 0.0
RGBA8(102, 0, 0, 255), // r = 0.4
RGBA8(153, 0, 0, 255), // r = 0.6
RGBA8(255, 0, 0, 255), // r = 1.0
utils::RGBA8(0, 255, 255, 255), // r = 0.0
utils::RGBA8(102, 0, 0, 255), // r = 0.4
utils::RGBA8(153, 0, 0, 255), // r = 0.6
utils::RGBA8(255, 0, 0, 255), // r = 1.0
// G channel has different values
RGBA8(255, 0, 255, 255), // g = 0.0
RGBA8(0, 102, 0, 255), // g = 0.4
RGBA8(0, 153, 0, 255), // g = 0.6
RGBA8(0, 255, 0, 255), // g = 1.0
utils::RGBA8(255, 0, 255, 255), // g = 0.0
utils::RGBA8(0, 102, 0, 255), // g = 0.4
utils::RGBA8(0, 153, 0, 255), // g = 0.6
utils::RGBA8(0, 255, 0, 255), // g = 1.0
// B channel has different values
RGBA8(255, 255, 0, 255), // b = 0.0
RGBA8(0, 0, 102, 255), // b = 0.4
RGBA8(0, 0, 153, 255), // b = 0.6
RGBA8(0, 0, 255, 255), // b = 1.0
utils::RGBA8(255, 255, 0, 255), // b = 0.0
utils::RGBA8(0, 0, 102, 255), // b = 0.4
utils::RGBA8(0, 0, 153, 255), // b = 0.6
utils::RGBA8(0, 0, 255, 255), // b = 1.0
};
}
@ -1021,7 +1021,7 @@ class CopyTextureForBrowser_ColorSpace
options.dstTransferFunctionParameters = dstColorSpaceInfo.gammaEncodingParams.data();
options.dstAlphaMode = GetParam().mDstAlphaMode;
std::vector<RGBA8> sourceTextureData = GetSourceData(options.srcAlphaMode);
std::vector<utils::RGBA8> sourceTextureData = GetSourceData(options.srcAlphaMode);
const wgpu::Extent3D& copySize = {kWidth, kHeight};
const utils::TextureDataCopyLayout srcCopyLayout =
@ -1034,7 +1034,7 @@ class CopyTextureForBrowser_ColorSpace
wgpu::TextureUsage::TextureBinding;
wgpu::Texture srcTexture = this->CreateAndInitTexture(
srcTextureSpec, srcUsage, srcCopyLayout, sourceTextureData.data(),
sourceTextureData.size() * sizeof(RGBA8));
sourceTextureData.size() * sizeof(utils::RGBA8));
// Create dst texture.
wgpu::Texture dstTexture = this->CreateTexture(

View File

@ -101,7 +101,7 @@ class CreatePipelineAsyncTest : public DawnTest {
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), outputTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 255, 0, 255), outputTexture, 0, 0);
}
void ValidateCreateRenderPipelineAsync() { ValidateCreateRenderPipelineAsync(&task); }
@ -311,7 +311,7 @@ TEST_P(CreatePipelineAsyncTest, ReleaseEntryPointsAfterCreateRenderPipelineAsync
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), outputTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 255, 0, 255), outputTexture, 0, 0);
}
// Verify CreateRenderPipelineAsync() works as expected when there is any error that happens during
@ -703,7 +703,7 @@ TEST_P(CreatePipelineAsyncTest, CreateRenderPipelineAsyncWithVertexBufferLayouts
// The color attachment will have the expected color when the vertex attribute values are
// fetched correctly.
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 255, 0, 255), renderTarget, 0, 0);
}
// Verify calling CreateRenderPipelineAsync() with valid depthStencilState works on all backends.
@ -776,7 +776,7 @@ TEST_P(CreatePipelineAsyncTest, CreateRenderPipelineAsyncWithDepthStencilState)
// The color in the color attachment should not be changed after the draw call as no pixel can
// pass the stencil test.
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 255, 0, 255), renderTarget, 0, 0);
}
// Verify calling CreateRenderPipelineAsync() with multisample.Count > 1 works on all backends.
@ -842,7 +842,7 @@ TEST_P(CreatePipelineAsyncTest, CreateRenderPipelineWithMultisampleState) {
queue.Submit(1, &commands);
// The color in resolveTarget should be the expected color (0, 1, 0, 1).
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), resolveTarget, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 255, 0, 255), resolveTarget, 0, 0);
}
// Verify calling CreateRenderPipelineAsync() with valid BlendState works on all backends.
@ -946,8 +946,8 @@ TEST_P(CreatePipelineAsyncTest, CreateRenderPipelineAsyncWithBlendState) {
// When the blend states are all set correctly, the color of renderTargets[0] should be
// (0.6, 0, 0, 0.6) = colorAttachment0.clearValue + (0.4, 0.0, 0.0, 0.4), and the color of
// renderTargets[1] should be (0.8, 0, 0, 0.8) = (1, 0, 0, 1) - colorAttachment1.clearValue.
RGBA8 expected0 = {153, 0, 0, 153};
RGBA8 expected1 = {0, 204, 0, 204};
utils::RGBA8 expected0 = {153, 0, 0, 153};
utils::RGBA8 expected1 = {0, 204, 0, 204};
EXPECT_PIXEL_RGBA8_EQ(expected0, renderTargets[0], 0, 0);
EXPECT_PIXEL_RGBA8_EQ(expected1, renderTargets[1], 0, 0);
}

View File

@ -86,14 +86,15 @@ class CullingTest : public DawnTest {
wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
queue.Submit(1, &commandBuffer);
const RGBA8 kBackgroundColor = RGBA8::kBlue;
const RGBA8 kTopLeftColor = RGBA8::kBlack;
constexpr RGBA8 kBottomRightColor = RGBA8(3, 3, 0, 255);
const utils::RGBA8 kBackgroundColor = utils::RGBA8::kBlue;
const utils::RGBA8 kTopLeftColor = utils::RGBA8::kBlack;
constexpr utils::RGBA8 kBottomRightColor = utils::RGBA8(3, 3, 0, 255);
RGBA8 kCCWTriangleTopLeftColor = isCCWTriangleCulled ? kBackgroundColor : kTopLeftColor;
utils::RGBA8 kCCWTriangleTopLeftColor =
isCCWTriangleCulled ? kBackgroundColor : kTopLeftColor;
EXPECT_PIXEL_RGBA8_EQ(kCCWTriangleTopLeftColor, colorTexture, 0, 0);
RGBA8 kCWTriangleBottomRightColor =
utils::RGBA8 kCWTriangleBottomRightColor =
isCWTriangleCulled ? kBackgroundColor : kBottomRightColor;
EXPECT_PIXEL_RGBA8_EQ(kCWTriangleBottomRightColor, colorTexture, kSize - 1, kSize - 1);
}

View File

@ -581,9 +581,9 @@ TEST_P(D3D12SharedHandleUsageTests, ClearInD3D11CopyAndReadbackInD3D12) {
// Readback the destination texture and ensure it contains the colors we used
// to clear the source texture on the D3D device.
EXPECT_PIXEL_RGBA8_EQ(
RGBA8(clearColor.r * 255u, clearColor.g * 255u, clearColor.b * 255u, clearColor.a * 255u),
dawnCopyDestTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(clearColor.r * 255u, clearColor.g * 255u,
clearColor.b * 255u, clearColor.a * 255u),
dawnCopyDestTexture, 0, 0);
}
// 1. Create and clear a D3D11 texture
@ -600,9 +600,9 @@ TEST_P(D3D12SharedHandleUsageTests, ClearInD3D11ReadbackInD3D12) {
// Readback the destination texture and ensure it contains the colors we used
// to clear the source texture on the D3D device.
EXPECT_PIXEL_RGBA8_EQ(
RGBA8(clearColor.r * 255, clearColor.g * 255, clearColor.b * 255, clearColor.a * 255),
dawnTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(clearColor.r * 255, clearColor.g * 255, clearColor.b * 255,
clearColor.a * 255),
dawnTexture, 0, 0);
}
// 1. Create and clear a D3D11 texture
@ -690,7 +690,7 @@ TEST_P(D3D12SharedHandleUsageTests, UninitializedTextureIsCleared) {
// Readback the destination texture and ensure it contains the colors we used
// to clear the source texture on the D3D device.
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), dawnTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 0, 0, 0), dawnTexture, 0, 0);
}
// 1. Create an external image from the DX11 texture.
@ -710,7 +710,7 @@ TEST_P(D3D12SharedHandleUsageTests, ReuseExternalImage) {
ASSERT_NE(texture.Get(), nullptr);
ClearImage(texture.Get(), solidRed, device);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0xFF, 0, 0, 0xFF), texture.Get(), 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0xFF, 0, 0, 0xFF), texture.Get(), 0, 0);
}
// Once finished with the first texture, destroy it so we may re-acquire the external image
@ -727,7 +727,7 @@ TEST_P(D3D12SharedHandleUsageTests, ReuseExternalImage) {
texture = wgpu::Texture::Acquire(externalImage->ProduceTexture(&externalAccessDesc));
// Check again that the new texture is still red
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0xFF, 0, 0, 0xFF), texture.Get(), 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0xFF, 0, 0, 0xFF), texture.Get(), 0, 0);
// Clear the new texture to blue
{
@ -735,7 +735,7 @@ TEST_P(D3D12SharedHandleUsageTests, ReuseExternalImage) {
ASSERT_NE(texture.Get(), nullptr);
ClearImage(texture.Get(), solidBlue, device);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0xFF, 0xFF), texture.Get(), 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 0, 0xFF, 0xFF), texture.Get(), 0, 0);
}
texture.Destroy();
@ -755,7 +755,7 @@ TEST_P(D3D12SharedHandleUsageTests, ConcurrentExternalImageReadAccess) {
ASSERT_NE(texture.Get(), nullptr);
ClearImage(texture.Get(), solidRed, device);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0xFF, 0, 0, 0xFF), texture.Get(), 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0xFF, 0, 0, 0xFF), texture.Get(), 0, 0);
}
texture.Destroy();
@ -774,8 +774,8 @@ TEST_P(D3D12SharedHandleUsageTests, ConcurrentExternalImageReadAccess) {
wgpu::Texture::Acquire(externalImage->ProduceTexture(&externalAccessDesc));
// Check again that the new textures are also red.
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0xFF, 0, 0, 0xFF), texture1.Get(), 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0xFF, 0, 0, 0xFF), texture2.Get(), 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0xFF, 0, 0, 0xFF), texture1.Get(), 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0xFF, 0, 0, 0xFF), texture2.Get(), 0, 0);
texture1.Destroy();
texture2.Destroy();

View File

@ -345,9 +345,9 @@ TEST_P(DepthBiasTests, PositiveBiasOn24bit) {
// Only the bottom left quad has colors. 0.5 quad > 0.4 clear.
// TODO(crbug.com/dawn/820): Switch to depth sampling once feature has been enabled.
std::vector<RGBA8> expected = {
RGBA8::kRed, RGBA8::kRed, //
RGBA8::kRed, RGBA8::kRed, //
std::vector<utils::RGBA8> expected = {
utils::RGBA8::kRed, utils::RGBA8::kRed, //
utils::RGBA8::kRed, utils::RGBA8::kRed, //
};
EXPECT_TEXTURE_EQ(expected.data(), mRenderTarget, {0, 0}, {kRTSize, kRTSize});
@ -366,9 +366,9 @@ TEST_P(DepthBiasTests, PositiveBiasOn24bitWithClamp) {
// Since we cleared with a depth of 0.4 and clamped bias at 0.4, the depth test will fail. 0.25
// + 0.125 < 0.4 clear.
// TODO(crbug.com/dawn/820): Switch to depth sampling once feature has been enabled.
std::vector<RGBA8> zero = {
RGBA8::kZero, RGBA8::kZero, //
RGBA8::kZero, RGBA8::kZero, //
std::vector<utils::RGBA8> zero = {
utils::RGBA8::kZero, utils::RGBA8::kZero, //
utils::RGBA8::kZero, utils::RGBA8::kZero, //
};
EXPECT_TEXTURE_EQ(zero.data(), mRenderTarget, {0, 0}, {kRTSize, kRTSize});
@ -381,9 +381,9 @@ TEST_P(DepthBiasTests, PositiveSlopeBiasOn24bit) {
// Only the top half of the quad has a depth > 0.4 clear
// TODO(crbug.com/dawn/820): Switch to depth sampling once feature has been enabled.
std::vector<RGBA8> expected = {
RGBA8::kRed, RGBA8::kRed, //
RGBA8::kZero, RGBA8::kZero, //
std::vector<utils::RGBA8> expected = {
utils::RGBA8::kRed, utils::RGBA8::kRed, //
utils::RGBA8::kZero, utils::RGBA8::kZero, //
};
EXPECT_TEXTURE_EQ(expected.data(), mRenderTarget, {0, 0}, {kRTSize, kRTSize});

View File

@ -89,7 +89,7 @@ class DepthStencilStateTest : public DawnTest {
struct TestSpec {
const wgpu::DepthStencilState& depthStencil;
RGBA8 color;
utils::RGBA8 color;
float depth;
uint32_t stencil;
wgpu::FrontFace frontFace = wgpu::FrontFace::CCW;
@ -125,10 +125,10 @@ class DepthStencilStateTest : public DawnTest {
state.stencilReadMask = 0xff;
state.stencilWriteMask = 0xff;
RGBA8 baseColor = RGBA8(255, 255, 255, 255);
RGBA8 lessColor = RGBA8(255, 0, 0, 255);
RGBA8 equalColor = RGBA8(0, 255, 0, 255);
RGBA8 greaterColor = RGBA8(0, 0, 255, 255);
utils::RGBA8 baseColor = utils::RGBA8(255, 255, 255, 255);
utils::RGBA8 lessColor = utils::RGBA8(255, 0, 0, 255);
utils::RGBA8 equalColor = utils::RGBA8(0, 255, 0, 255);
utils::RGBA8 greaterColor = utils::RGBA8(0, 0, 255, 255);
// Base triangle at depth 0.5, depth always, depth write enabled
TestSpec base = {baseState, baseColor, 0.5f, 0u};
@ -179,10 +179,10 @@ class DepthStencilStateTest : public DawnTest {
state.stencilReadMask = 0xff;
state.stencilWriteMask = 0xff;
RGBA8 baseColor = RGBA8(255, 255, 255, 255);
RGBA8 lessColor = RGBA8(255, 0, 0, 255);
RGBA8 equalColor = RGBA8(0, 255, 0, 255);
RGBA8 greaterColor = RGBA8(0, 0, 255, 255);
utils::RGBA8 baseColor = utils::RGBA8(255, 255, 255, 255);
utils::RGBA8 lessColor = utils::RGBA8(255, 0, 0, 255);
utils::RGBA8 equalColor = utils::RGBA8(0, 255, 0, 255);
utils::RGBA8 greaterColor = utils::RGBA8(0, 0, 255, 255);
// Base triangle with stencil reference 1
TestSpec base = {baseState, baseColor, 0.0f, 1u};
@ -235,10 +235,10 @@ class DepthStencilStateTest : public DawnTest {
CheckStencil(
{
// Wipe the stencil buffer with the initialStencil value
{baseState, RGBA8(255, 255, 255, 255), 0.f, initialStencil},
{baseState, utils::RGBA8(255, 255, 255, 255), 0.f, initialStencil},
// Draw a triangle with the provided stencil operation and reference
{state, RGBA8(255, 0, 0, 255), 0.f, reference},
{state, utils::RGBA8(255, 0, 0, 255), 0.f, reference},
},
expectedStencil);
}
@ -258,16 +258,16 @@ class DepthStencilStateTest : public DawnTest {
state.stencilReadMask = 0xff;
state.stencilWriteMask = 0xff;
testParams.push_back({state, RGBA8(0, 255, 0, 255), 0, expectedStencil});
DoTest(testParams, RGBA8(0, 255, 0, 255));
testParams.push_back({state, utils::RGBA8(0, 255, 0, 255), 0, expectedStencil});
DoTest(testParams, utils::RGBA8(0, 255, 0, 255));
}
// Each test param represents a pair of triangles with a color, depth, stencil value, and
// depthStencil state, one frontfacing, one backfacing Draw the triangles in order and check the
// expected colors for the frontfaces and backfaces
void DoTest(const std::vector<TestSpec>& testParams,
const RGBA8& expectedFront,
const RGBA8& expectedBack,
const utils::RGBA8& expectedFront,
const utils::RGBA8& expectedBack,
bool isSingleEncoderMultiplePass = false) {
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
@ -355,7 +355,7 @@ class DepthStencilStateTest : public DawnTest {
}
void DoTest(const std::vector<TestSpec>& testParams,
const RGBA8& expected,
const utils::RGBA8& expected,
bool isSingleEncoderMultiplePass = false) {
DoTest(testParams, expected, expected, isSingleEncoderMultiplePass);
}
@ -386,9 +386,9 @@ TEST_P(DepthStencilStateTest, Basic) {
DoTest(
{
{state, RGBA8(0, 255, 0, 255), 0.5f, 0u},
{state, utils::RGBA8(0, 255, 0, 255), 0.5f, 0u},
},
RGBA8(0, 255, 0, 255));
utils::RGBA8(0, 255, 0, 255));
}
// Test defaults: depth and stencil tests disabled
@ -408,9 +408,9 @@ TEST_P(DepthStencilStateTest, DepthStencilDisabled) {
state.stencilWriteMask = 0xff;
TestSpec specs[3] = {
{state, RGBA8(255, 0, 0, 255), 0.0f, 0u},
{state, RGBA8(0, 255, 0, 255), 0.5f, 0u},
{state, RGBA8(0, 0, 255, 255), 1.0f, 0u},
{state, utils::RGBA8(255, 0, 0, 255), 0.0f, 0u},
{state, utils::RGBA8(0, 255, 0, 255), 0.5f, 0u},
{state, utils::RGBA8(0, 0, 255, 255), 1.0f, 0u},
};
// Test that for all combinations, the last triangle drawn is the one visible
@ -490,15 +490,15 @@ TEST_P(DepthStencilStateTest, DepthWriteDisabled) {
DoTest(
{
{baseState, RGBA8(255, 255, 255, 255), 1.f,
{baseState, utils::RGBA8(255, 255, 255, 255), 1.f,
0u}, // Draw a base triangle with depth enabled
{noDepthWrite, RGBA8(0, 0, 0, 255), 0.f,
{noDepthWrite, utils::RGBA8(0, 0, 0, 255), 0.f,
0u}, // Draw a second triangle without depth enabled
{checkState, RGBA8(0, 255, 0, 255), 1.f,
{checkState, utils::RGBA8(0, 255, 0, 255), 1.f,
0u}, // Draw a third triangle which should occlude the second even though it is behind
// it
},
RGBA8(0, 255, 0, 255));
utils::RGBA8(0, 255, 0, 255));
}
// The following tests check that each stencil comparison function works
@ -599,9 +599,9 @@ TEST_P(DepthStencilStateTest, StencilReadMask) {
state.stencilReadMask = 0x2;
state.stencilWriteMask = 0xff;
RGBA8 baseColor = RGBA8(255, 255, 255, 255);
RGBA8 red = RGBA8(255, 0, 0, 255);
RGBA8 green = RGBA8(0, 255, 0, 255);
utils::RGBA8 baseColor = utils::RGBA8(255, 255, 255, 255);
utils::RGBA8 red = utils::RGBA8(255, 0, 0, 255);
utils::RGBA8 green = utils::RGBA8(0, 255, 0, 255);
TestSpec base = {baseState, baseColor, 0.5f, 3u}; // Base triangle to set the stencil to 3
DoTest({base, {state, red, 0.f, 1u}}, baseColor); // Triangle with stencil reference 1 and read
@ -638,8 +638,8 @@ TEST_P(DepthStencilStateTest, StencilWriteMask) {
state.stencilReadMask = 0xff;
state.stencilWriteMask = 0xff;
RGBA8 baseColor = RGBA8(255, 255, 255, 255);
RGBA8 green = RGBA8(0, 255, 0, 255);
utils::RGBA8 baseColor = utils::RGBA8(255, 255, 255, 255);
utils::RGBA8 green = utils::RGBA8(0, 255, 0, 255);
TestSpec base = {baseState, baseColor, 0.5f,
3u}; // Base triangle with stencil reference 3 and mask 1 to set the stencil 1
@ -679,8 +679,9 @@ TEST_P(DepthStencilStateTest, StencilFail) {
CheckStencil(
{
{baseState, RGBA8(255, 255, 255, 255), 1.f, 1}, // Triangle to set stencil value to 1
{state, RGBA8(0, 0, 0, 255), 0.f,
{baseState, utils::RGBA8(255, 255, 255, 255), 1.f,
1}, // Triangle to set stencil value to 1
{state, utils::RGBA8(0, 0, 0, 255), 0.f,
2} // Triangle with stencil reference 2 fails the Less comparison function
},
2); // Replace the stencil on failure, so it should be 2
@ -714,9 +715,9 @@ TEST_P(DepthStencilStateTest, StencilDepthFail) {
state.stencilReadMask = 0xff;
state.stencilWriteMask = 0xff;
CheckStencil({{baseState, RGBA8(255, 255, 255, 255), 0.f,
CheckStencil({{baseState, utils::RGBA8(255, 255, 255, 255), 0.f,
1}, // Triangle to set stencil value to 1. Depth is 0
{state, RGBA8(0, 0, 0, 255), 1.f,
{state, utils::RGBA8(0, 0, 0, 255), 1.f,
2}}, // Triangle with stencil reference 2 passes the Greater comparison
// function. At depth 1, it fails the Less depth test
2); // Replace the stencil on stencil pass, depth failure, so it should be 2
@ -750,9 +751,9 @@ TEST_P(DepthStencilStateTest, StencilDepthPass) {
state.stencilReadMask = 0xff;
state.stencilWriteMask = 0xff;
CheckStencil({{baseState, RGBA8(255, 255, 255, 255), 1.f,
CheckStencil({{baseState, utils::RGBA8(255, 255, 255, 255), 1.f,
1}, // Triangle to set stencil value to 1. Depth is 0
{state, RGBA8(0, 0, 0, 255), 0.f,
{state, utils::RGBA8(0, 0, 0, 255), 0.f,
2}}, // Triangle with stencil reference 2 passes the Greater comparison
// function. At depth 0, it pass the Less depth test
2); // Replace the stencil on stencil pass, depth pass, so it should be 2
@ -784,8 +785,10 @@ TEST_P(DepthStencilStateTest, StencilFrontAndBackFace) {
state.stencilBack.compare = wgpu::CompareFunction::Never;
// The front facing triangle passes the stencil comparison but the back facing one doesn't.
DoTest({{state, RGBA8::kRed, 0.f, 0u, wgpu::FrontFace::CCW}}, RGBA8::kRed, RGBA8::kZero);
DoTest({{state, RGBA8::kRed, 0.f, 0u, wgpu::FrontFace::CW}}, RGBA8::kZero, RGBA8::kRed);
DoTest({{state, utils::RGBA8::kRed, 0.f, 0u, wgpu::FrontFace::CCW}}, utils::RGBA8::kRed,
utils::RGBA8::kZero);
DoTest({{state, utils::RGBA8::kRed, 0.f, 0u, wgpu::FrontFace::CW}}, utils::RGBA8::kZero,
utils::RGBA8::kRed);
}
// Test that the depth reference of a new render pass is initialized to default value 0
@ -808,11 +811,11 @@ TEST_P(DepthStencilStateTest, StencilReferenceInitialized) {
// Only set the stencil reference in the first pass, and test that for other pass it should
// be default value rather than inherited
std::vector<TestSpec> testParams = {
{stencilAlwaysReplaceState, RGBA8::kRed, 0.f, 0x1, wgpu::FrontFace::CCW, true},
{stencilEqualKeepState, RGBA8::kGreen, 0.f, 0x0, wgpu::FrontFace::CCW, false}};
{stencilAlwaysReplaceState, utils::RGBA8::kRed, 0.f, 0x1, wgpu::FrontFace::CCW, true},
{stencilEqualKeepState, utils::RGBA8::kGreen, 0.f, 0x0, wgpu::FrontFace::CCW, false}};
// Since the stencil reference is not inherited, second draw won't pass the stencil test
DoTest(testParams, RGBA8::kZero, RGBA8::kZero, true);
DoTest(testParams, utils::RGBA8::kZero, utils::RGBA8::kZero, true);
}
// Test that stencil reference is initialized as zero for new render pass
@ -820,12 +823,13 @@ TEST_P(DepthStencilStateTest, StencilReferenceInitialized) {
// First pass sets the stencil to 0x1, the second pass sets the stencil to its default
// value, and the third pass tests if the stencil is zero
std::vector<TestSpec> testParams = {
{stencilAlwaysReplaceState, RGBA8::kRed, 0.f, 0x1, wgpu::FrontFace::CCW, true},
{stencilAlwaysReplaceState, RGBA8::kGreen, 0.f, 0x1, wgpu::FrontFace::CCW, false},
{stencilEqualKeepState, RGBA8::kBlue, 0.f, 0x0, wgpu::FrontFace::CCW, true}};
{stencilAlwaysReplaceState, utils::RGBA8::kRed, 0.f, 0x1, wgpu::FrontFace::CCW, true},
{stencilAlwaysReplaceState, utils::RGBA8::kGreen, 0.f, 0x1, wgpu::FrontFace::CCW,
false},
{stencilEqualKeepState, utils::RGBA8::kBlue, 0.f, 0x0, wgpu::FrontFace::CCW, true}};
// The third draw should pass the stencil test since the second pass set it to default zero
DoTest(testParams, RGBA8::kBlue, RGBA8::kBlue, true);
DoTest(testParams, utils::RGBA8::kBlue, utils::RGBA8::kBlue, true);
}
}

View File

@ -84,7 +84,7 @@ class DestroyTest : public DawnTest {
// Destroy before submit will result in error, and nothing drawn
TEST_P(DestroyTest, BufferDestroyBeforeSubmit) {
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 notFilled(0, 0, 0, 0);
wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
vertexBuffer.Destroy();
@ -95,7 +95,7 @@ TEST_P(DestroyTest, BufferDestroyBeforeSubmit) {
// Destroy after submit will draw successfully
TEST_P(DestroyTest, BufferDestroyAfterSubmit) {
RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 filled(0, 255, 0, 255);
wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
queue.Submit(1, &commands);
@ -107,7 +107,7 @@ TEST_P(DestroyTest, BufferDestroyAfterSubmit) {
// First submit succeeds, draws triangle, second submit fails
// after destroy is called on the buffer, pixel does not change
TEST_P(DestroyTest, BufferSubmitDestroySubmit) {
RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 filled(0, 255, 0, 255);
wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
queue.Submit(1, &commands);
@ -131,7 +131,7 @@ TEST_P(DestroyTest, TextureDestroyBeforeSubmit) {
// Destroy after submit will draw successfully
TEST_P(DestroyTest, TextureDestroyAfterSubmit) {
RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 filled(0, 255, 0, 255);
wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
queue.Submit(1, &commands);
@ -143,7 +143,7 @@ TEST_P(DestroyTest, TextureDestroyAfterSubmit) {
// First submit succeeds, draws triangle, second submit fails
// after destroy is called on the texture
TEST_P(DestroyTest, TextureSubmitDestroySubmit) {
RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 filled(0, 255, 0, 255);
wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
queue.Submit(1, &commands);

View File

@ -103,7 +103,9 @@ class DrawIndexedIndirectTest : public DawnTest {
return encoder.Finish();
}
void TestDraw(wgpu::CommandBuffer commands, RGBA8 bottomLeftExpected, RGBA8 topRightExpected) {
void TestDraw(wgpu::CommandBuffer commands,
utils::RGBA8 bottomLeftExpected,
utils::RGBA8 topRightExpected) {
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3);
@ -113,8 +115,8 @@ class DrawIndexedIndirectTest : public DawnTest {
void Test(std::initializer_list<uint32_t> bufferList,
uint64_t indexOffset,
uint64_t indirectOffset,
RGBA8 bottomLeftExpected,
RGBA8 topRightExpected) {
utils::RGBA8 bottomLeftExpected,
utils::RGBA8 topRightExpected) {
wgpu::Buffer indexBuffer =
CreateIndexBuffer({0, 1, 2, 0, 3, 1,
// The indices below are added to test negatve baseVertex
@ -133,8 +135,8 @@ TEST_P(DrawIndexedIndirectTest, Uint32) {
// the offsets that Tint/GLSL produces.
DAWN_SUPPRESS_TEST_IF(IsIntel() && IsOpenGL() && IsLinux());
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
// Test a draw with no indices.
Test({0, 0, 0, 0, 0}, 0, 0, notFilled, notFilled);
@ -164,8 +166,8 @@ TEST_P(DrawIndexedIndirectTest, BaseVertex) {
// the offsets that Tint/GLSL produces.
DAWN_SUPPRESS_TEST_IF(IsIntel() && IsOpenGL() && IsLinux());
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
// Test a draw with only the first 3 indices of the second quad (top right triangle)
Test({3, 1, 0, 4, 0}, 0, 0, notFilled, filled);
@ -197,8 +199,8 @@ TEST_P(DrawIndexedIndirectTest, IndirectOffset) {
// the offsets that Tint/GLSL produces.
DAWN_SUPPRESS_TEST_IF(IsIntel() && IsOpenGL() && IsLinux());
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
// Test an offset draw call, with indirect buffer containing 2 calls:
// 1) first 3 indices of the second quad (top right triangle)
@ -222,8 +224,8 @@ TEST_P(DrawIndexedIndirectTest, BasicValidation) {
// It doesn't make sense to test invalid inputs when validation is disabled.
DAWN_SUPPRESS_TEST_IF(HasToggleEnabled("skip_validation"));
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
wgpu::Buffer indexBuffer = CreateIndexBuffer({0, 1, 2, 0, 3, 1});
@ -249,8 +251,8 @@ TEST_P(DrawIndexedIndirectTest, ValidateWithOffsets) {
// It doesn't make sense to test invalid inputs when validation is disabled.
DAWN_SUPPRESS_TEST_IF(HasToggleEnabled("skip_validation"));
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
wgpu::Buffer indexBuffer = CreateIndexBuffer({0, 1, 2, 0, 3, 1, 0, 1, 2});
@ -281,8 +283,8 @@ TEST_P(DrawIndexedIndirectTest, ValidateMultiplePasses) {
// It doesn't make sense to test invalid inputs when validation is disabled.
DAWN_SUPPRESS_TEST_IF(HasToggleEnabled("skip_validation"));
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
wgpu::Buffer indexBuffer = CreateIndexBuffer({0, 1, 2, 0, 3, 1, 0, 1, 2});
@ -309,8 +311,8 @@ TEST_P(DrawIndexedIndirectTest, ValidateMultipleDraws) {
// It doesn't make sense to test invalid inputs when validation is disabled.
DAWN_SUPPRESS_TEST_IF(HasToggleEnabled("skip_validation"));
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
// Validate multiple draw calls using the same index and indirect buffers as input, but with
// different indirect offsets.
@ -409,8 +411,8 @@ TEST_P(DrawIndexedIndirectTest, ValidateEncodeMultipleThenSubmitInOrder) {
// It doesn't make sense to test invalid inputs when validation is disabled.
DAWN_SUPPRESS_TEST_IF(HasToggleEnabled("skip_validation"));
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
wgpu::Buffer indexBuffer = CreateIndexBuffer({0, 1, 2, 0, 3, 1, 0, 1, 2});
@ -447,8 +449,8 @@ TEST_P(DrawIndexedIndirectTest, ValidateEncodeMultipleThenSubmitAtOnce) {
// It doesn't make sense to test invalid inputs when validation is disabled.
DAWN_SUPPRESS_TEST_IF(HasToggleEnabled("skip_validation"));
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
wgpu::Buffer indexBuffer = CreateIndexBuffer({0, 1, 2, 0, 3, 1, 0, 1, 2});
@ -475,8 +477,8 @@ TEST_P(DrawIndexedIndirectTest, ValidateEncodeMultipleThenSubmitOutOfOrder) {
// It doesn't make sense to test invalid inputs when validation is disabled.
DAWN_SUPPRESS_TEST_IF(HasToggleEnabled("skip_validation"));
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
wgpu::Buffer indexBuffer = CreateIndexBuffer({0, 1, 2, 0, 3, 1, 0, 1, 2});
@ -509,8 +511,8 @@ TEST_P(DrawIndexedIndirectTest, ValidateWithBundlesInSamePass) {
// It doesn't make sense to test invalid inputs when validation is disabled.
DAWN_SUPPRESS_TEST_IF(HasToggleEnabled("skip_validation"));
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
wgpu::Buffer indirectBuffer =
CreateIndirectBuffer({3, 1, 3, 0, 0, 10, 1, 0, 0, 0, 3, 1, 6, 0, 0});
@ -564,8 +566,8 @@ TEST_P(DrawIndexedIndirectTest, ValidateWithBundlesInDifferentPasses) {
// It doesn't make sense to test invalid inputs when validation is disabled.
DAWN_SUPPRESS_TEST_IF(HasToggleEnabled("skip_validation"));
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
wgpu::Buffer indirectBuffer =
CreateIndirectBuffer({3, 1, 3, 0, 0, 10, 1, 0, 0, 0, 3, 1, 6, 0, 0});
@ -636,8 +638,8 @@ TEST_P(DrawIndexedIndirectTest, ValidateReusedBundleWithChangingParams) {
// It doesn't make sense to test invalid inputs when validation is disabled.
DAWN_SUPPRESS_TEST_IF(HasToggleEnabled("skip_validation"));
RGBA8 filled(0, 255, 0, 255);
// RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
// utils::RGBA8 notFilled(0, 0, 0, 0);
wgpu::Buffer indirectBuffer = CreateIndirectBuffer({0, 0, 0, 0, 0});
wgpu::Buffer indexBuffer = CreateIndexBuffer({0, 1, 2, 0, 3, 1});

View File

@ -80,8 +80,8 @@ class DrawIndexedTest : public DawnTest {
int32_t baseVertex,
uint32_t firstInstance,
uint64_t bufferOffset,
RGBA8 bottomLeftExpected,
RGBA8 topRightExpected) {
utils::RGBA8 bottomLeftExpected,
utils::RGBA8 topRightExpected) {
// Regular draw with a reasonable index buffer
TestImplementation(indexCount, instanceCount, firstIndex, baseVertex, firstInstance,
bufferOffset, indexBuffer, bottomLeftExpected, topRightExpected);
@ -89,8 +89,8 @@ class DrawIndexedTest : public DawnTest {
void TestZeroSizedIndexBufferDraw(uint32_t indexCount,
uint32_t firstIndex,
RGBA8 bottomLeftExpected,
RGBA8 topRightExpected) {
utils::RGBA8 bottomLeftExpected,
utils::RGBA8 topRightExpected) {
TestImplementation(indexCount, 1, firstIndex, 0, 0, 0, zeroSizedIndexBuffer,
bottomLeftExpected, topRightExpected);
}
@ -102,8 +102,8 @@ class DrawIndexedTest : public DawnTest {
uint32_t firstInstance,
uint64_t bufferOffset,
const wgpu::Buffer& curIndexBuffer,
RGBA8 bottomLeftExpected,
RGBA8 topRightExpected) {
utils::RGBA8 bottomLeftExpected,
utils::RGBA8 topRightExpected) {
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
@ -124,8 +124,8 @@ class DrawIndexedTest : public DawnTest {
// The most basic DrawIndexed triangle draw.
TEST_P(DrawIndexedTest, Uint32) {
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
// Test a draw with no indices.
Test(0, 0, 0, 0, 0, 0, notFilled, notFilled);
@ -140,8 +140,8 @@ TEST_P(DrawIndexedTest, Uint32) {
// Test the parameter 'baseVertex' of DrawIndexed() works.
TEST_P(DrawIndexedTest, BaseVertex) {
DAWN_TEST_UNSUPPORTED_IF(HasToggleEnabled("disable_base_vertex"));
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
// Test a draw with only the first 3 indices of the second quad (top right triangle)
Test(3, 1, 0, 4, 0, 0, notFilled, filled);

View File

@ -65,8 +65,8 @@ class DrawIndirectTest : public DawnTest {
void Test(std::initializer_list<uint32_t> bufferList,
uint64_t indirectOffset,
RGBA8 bottomLeftExpected,
RGBA8 topRightExpected) {
utils::RGBA8 bottomLeftExpected,
utils::RGBA8 topRightExpected) {
wgpu::Buffer indirectBuffer =
utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Indirect, bufferList);
@ -93,8 +93,8 @@ TEST_P(DrawIndirectTest, Uint32) {
// the offsets that Tint/GLSL produces.
DAWN_SUPPRESS_TEST_IF(IsIntel() && IsOpenGL() && IsLinux());
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
// Test a draw with no indices.
Test({0, 0, 0, 0}, 0, notFilled, notFilled);
@ -114,8 +114,8 @@ TEST_P(DrawIndirectTest, IndirectOffset) {
// the offsets that Tint/GLSL produces.
DAWN_SUPPRESS_TEST_IF(IsIntel() && IsOpenGL() && IsLinux());
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
// Test an offset draw call, with indirect buffer containing 2 calls:
// 1) only the first 3 indices (bottom left triangle)

View File

@ -66,8 +66,8 @@ class DrawTest : public DawnTest {
uint32_t instanceCount,
uint32_t firstIndex,
uint32_t firstInstance,
RGBA8 bottomLeftExpected,
RGBA8 topRightExpected) {
utils::RGBA8 bottomLeftExpected,
utils::RGBA8 topRightExpected) {
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
@ -87,8 +87,8 @@ class DrawTest : public DawnTest {
// The basic triangle draw.
TEST_P(DrawTest, Uint32) {
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
// Test a draw with no indices.
Test(0, 0, 0, 0, notFilled, notFilled);

View File

@ -227,7 +227,7 @@ TEST_P(DynamicBufferOffsetTests, BasicRenderPipeline) {
queue.Submit(1, &commands);
std::vector<uint32_t> expectedData = {2, 4};
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 2, 255, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(1, 2, 255, 255), renderPass.color, 0, 0);
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mStorageBuffers[1], 0, expectedData.size());
}
@ -249,7 +249,7 @@ TEST_P(DynamicBufferOffsetTests, SetDynamicOffsetsRenderPipeline) {
queue.Submit(1, &commands);
std::vector<uint32_t> expectedData = {6, 8};
EXPECT_PIXEL_RGBA8_EQ(RGBA8(5, 6, 255, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(5, 6, 255, 255), renderPass.color, 0, 0);
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mStorageBuffers[1],
mMinUniformBufferOffsetAlignment, expectedData.size());
}
@ -318,7 +318,7 @@ TEST_P(DynamicBufferOffsetTests, InheritDynamicOffsetsRenderPipeline) {
queue.Submit(1, &commands);
std::vector<uint32_t> expectedData = {12, 16};
EXPECT_PIXEL_RGBA8_EQ(RGBA8(5, 6, 255, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(5, 6, 255, 255), renderPass.color, 0, 0);
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mStorageBuffers[1],
mMinUniformBufferOffsetAlignment, expectedData.size());
}
@ -376,7 +376,7 @@ TEST_P(DynamicBufferOffsetTests, UpdateDynamicOffsetsMultipleTimesRenderPipeline
queue.Submit(1, &commands);
std::vector<uint32_t> expectedData = {2, 4};
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 2, 255, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(1, 2, 255, 255), renderPass.color, 0, 0);
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mStorageBuffers[1], 0, expectedData.size());
}

View File

@ -55,7 +55,7 @@ TEST_P(EntryPointTests, FragAndVertexSameModule) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kRed, renderPass.color, 0, 0);
}
// Test creating two compute pipelines from the same module.

View File

@ -160,7 +160,7 @@ TEST_P(ExternalTextureTests, SampleExternalTexture) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderTexture, 0, 0);
}
TEST_P(ExternalTextureTests, SampleMultiplanarExternalTexture) {
@ -206,15 +206,15 @@ TEST_P(ExternalTextureTests, SampleMultiplanarExternalTexture) {
double y;
double u;
double v;
RGBA8 rgba;
utils::RGBA8 rgba;
};
// Conversion expectations for BT.709 YUV source and sRGB destination.
std::array<ConversionExpectation, 7> expectations = {
{{0.0, .5, .5, RGBA8::kBlack},
{0.2126, 0.4172, 1.0, RGBA8::kRed},
{0.7152, 0.1402, 0.0175, RGBA8::kGreen},
{0.0722, 1.0, 0.4937, RGBA8::kBlue},
{{0.0, .5, .5, utils::RGBA8::kBlack},
{0.2126, 0.4172, 1.0, utils::RGBA8::kRed},
{0.7152, 0.1402, 0.0175, utils::RGBA8::kGreen},
{0.0722, 1.0, 0.4937, utils::RGBA8::kBlue},
{0.6382, 0.3232, 0.6644, {246, 169, 90, 255}},
{0.5423, 0.5323, 0.4222, {120, 162, 169, 255}},
{0.2345, 0.4383, 0.6342, {126, 53, 33, 255}}}};

View File

@ -144,7 +144,7 @@ TEST_P(GpuMemorySyncTests, RenderPass) {
queue.Submit(1, &commands);
// Verify the result.
EXPECT_PIXEL_RGBA8_EQ(RGBA8(iteration, 0, 0, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(iteration, 0, 0, 255), renderPass.color, 0, 0);
}
// Write into a storage buffer in a render pass. Then read that data in a compute
@ -210,7 +210,7 @@ TEST_P(GpuMemorySyncTests, ComputePassToRenderPass) {
queue.Submit(1, &commands);
// Verify the result.
EXPECT_PIXEL_RGBA8_EQ(RGBA8(2, 0, 0, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(2, 0, 0, 255), renderPass.color, 0, 0);
}
DAWN_INSTANTIATE_TEST(GpuMemorySyncTests,
@ -310,7 +310,7 @@ TEST_P(StorageToUniformSyncTests, ReadAfterWriteWithSameCommandBuffer) {
queue.Submit(1, &commands);
// Verify the rendering result.
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kRed, renderPass.color, 0, 0);
}
// Write into a storage buffer in compute pass in a command buffer. Then read that data in a render
@ -345,7 +345,7 @@ TEST_P(StorageToUniformSyncTests, ReadAfterWriteWithDifferentCommandBuffers) {
queue.Submit(2, cb);
// Verify the rendering result.
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kRed, renderPass.color, 0, 0);
}
// Write into a storage buffer in compute pass in a command buffer. Then read that data in a render
@ -381,7 +381,7 @@ TEST_P(StorageToUniformSyncTests, ReadAfterWriteWithDifferentQueueSubmits) {
queue.Submit(1, &cb[1]);
// Verify the rendering result.
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kRed, renderPass.color, 0, 0);
}
DAWN_INSTANTIATE_TEST(StorageToUniformSyncTests,
@ -521,10 +521,10 @@ TEST_P(MultipleWriteThenMultipleReadTests, SeparateBuffers) {
// Verify the rendering result.
uint32_t min = 1, max = kRTSize - 3;
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kYellow, renderPass.color, min, min);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kYellow, renderPass.color, max, min);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kYellow, renderPass.color, min, max);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kYellow, renderPass.color, max, max);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kYellow, renderPass.color, min, min);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kYellow, renderPass.color, max, min);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kYellow, renderPass.color, min, max);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kYellow, renderPass.color, max, max);
}
// Write into a storage buffer in compute pass. Then read that data in buffer in a render pass. The
@ -639,10 +639,10 @@ TEST_P(MultipleWriteThenMultipleReadTests, OneBuffer) {
// Verify the rendering result.
uint32_t min = 1, max = kRTSize - 3;
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kYellow, renderPass.color, min, min);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kYellow, renderPass.color, max, min);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kYellow, renderPass.color, min, max);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kYellow, renderPass.color, max, max);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kYellow, renderPass.color, min, min);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kYellow, renderPass.color, max, min);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kYellow, renderPass.color, min, max);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kYellow, renderPass.color, max, max);
}
DAWN_INSTANTIATE_TEST(MultipleWriteThenMultipleReadTests,

View File

@ -214,7 +214,7 @@ class IOSurfaceUsageTests : public IOSurfaceTestBase {
wgpu::TextureFormat format,
void* data,
size_t dataSize,
RGBA8 expectedColor) {
utils::RGBA8 expectedColor) {
// Write the data to the IOSurface
IOSurfaceLock(ioSurface, 0, nullptr);
memcpy(IOSurfaceGetBaseAddress(ioSurface), data, dataSize);
@ -355,7 +355,7 @@ TEST_P(IOSurfaceUsageTests, SampleFromR8IOSurface) {
uint8_t data = 0x01;
DoSampleTest(ioSurface.get(), wgpu::TextureFormat::R8Unorm, &data, sizeof(data),
RGBA8(1, 0, 0, 255));
utils::RGBA8(1, 0, 0, 255));
}
// Test clearing a R8 IOSurface
@ -376,7 +376,7 @@ TEST_P(IOSurfaceUsageTests, SampleFromRG8IOSurface) {
uint16_t data = 0x0102; // Stored as (G, R)
DoSampleTest(ioSurface.get(), wgpu::TextureFormat::RG8Unorm, &data, sizeof(data),
RGBA8(2, 1, 0, 255));
utils::RGBA8(2, 1, 0, 255));
}
// Test clearing a RG8 IOSurface
@ -396,7 +396,7 @@ TEST_P(IOSurfaceUsageTests, SampleFromBGRA8IOSurface) {
uint32_t data = 0x01020304; // Stored as (A, R, G, B)
DoSampleTest(ioSurface.get(), wgpu::TextureFormat::BGRA8Unorm, &data, sizeof(data),
RGBA8(2, 3, 4, 1));
utils::RGBA8(2, 3, 4, 1));
}
// Test clearing a BGRA8 IOSurface
@ -415,7 +415,7 @@ TEST_P(IOSurfaceUsageTests, SampleFromRGBA8IOSurface) {
uint32_t data = 0x01020304; // Stored as (A, B, G, R)
DoSampleTest(ioSurface.get(), wgpu::TextureFormat::RGBA8Unorm, &data, sizeof(data),
RGBA8(4, 3, 2, 1));
utils::RGBA8(4, 3, 2, 1));
}
// Test clearing an RGBA8 IOSurface
@ -448,7 +448,7 @@ TEST_P(IOSurfaceUsageTests, UninitializedTextureIsCleared) {
// wrap ioSurface and ensure color is not visible when isInitialized set to false
wgpu::Texture ioSurfaceTexture = WrapIOSurface(&textureDescriptor, ioSurface.get(), false);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), ioSurfaceTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 0, 0, 0), ioSurfaceTexture, 0, 0);
}
DAWN_INSTANTIATE_TEST(IOSurfaceValidationTests, MetalBackend());

View File

@ -92,7 +92,7 @@ TEST_P(IndexFormatTest, Uint32) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 100, 300);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 100, 300);
}
// Test that the Uint16 index format is correctly interpreted
@ -119,7 +119,7 @@ TEST_P(IndexFormatTest, Uint16) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 100, 300);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 100, 300);
}
// Test that the index format used is the format of the last set pipeline. This is to
@ -151,7 +151,7 @@ TEST_P(IndexFormatTest, ChangePipelineAfterSetIndexBuffer) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 100, 300);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 100, 300);
}
// Test that setting the index buffer before the pipeline works, this is important
@ -179,7 +179,7 @@ TEST_P(IndexFormatTest, SetIndexBufferBeforeSetPipeline) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
}
// Test that index buffers of multiple formats can be used with a pipeline that
@ -209,7 +209,7 @@ TEST_P(IndexFormatTest, SetIndexBufferDifferentFormats) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
encoder = device.CreateCommandEncoder();
{
@ -224,7 +224,7 @@ TEST_P(IndexFormatTest, SetIndexBufferDifferentFormats) {
commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
}
// Tests for primitive restart use vertices like in the drawing and draw the following
@ -286,9 +286,9 @@ TEST_P(TriangleStripPrimitiveRestartTests, Uint32PrimitiveRestart) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 50, 350); // A
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 350, 50); // B
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 198, 200); // C
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 50, 350); // A
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 350, 50); // B
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, 198, 200); // C
}
// Same as the above test, but uses an OOB index to emulate primitive restart being disabled,
@ -321,9 +321,9 @@ TEST_P(TriangleStripPrimitiveRestartTests, Uint32WithoutPrimitiveRestart) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 50, 350); // A
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 350, 50); // B
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 198, 200); // C
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 50, 350); // A
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 350, 50); // B
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 198, 200); // C
}
// Test use of primitive restart with an Uint16 index format
@ -357,9 +357,9 @@ TEST_P(TriangleStripPrimitiveRestartTests, Uint16PrimitiveRestart) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 50, 350); // A
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 350, 50); // B
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 198, 200); // C
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 50, 350); // A
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 350, 50); // B
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, 198, 200); // C
}
// Tests for primitive restart use vertices like in the drawing and draw the following
@ -411,9 +411,9 @@ TEST_P(LineStripPrimitiveRestartTests, Uint32PrimitiveRestart) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 399, 199); // 1
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 199, 199); // 2
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 300, 199); // A
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 399, 199); // 1
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 199, 199); // 2
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, 300, 199); // A
}
// Same as the above test, but uses an OOB index to emulate primitive restart being disabled,
@ -440,9 +440,9 @@ TEST_P(LineStripPrimitiveRestartTests, Uint32WithoutPrimitiveRestart) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 399, 199); // 1
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 199, 199); // 2
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 300, 199); // A
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 399, 199); // 1
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 199, 199); // 2
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 300, 199); // A
}
TEST_P(LineStripPrimitiveRestartTests, Uint16PrimitiveRestart) {
@ -467,9 +467,9 @@ TEST_P(LineStripPrimitiveRestartTests, Uint16PrimitiveRestart) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 399, 199); // 1
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 199, 199); // 2
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 300, 199); // A
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 399, 199); // 1
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 199, 199); // 2
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, 300, 199); // A
}
DAWN_INSTANTIATE_TEST(IndexFormatTest,

View File

@ -189,7 +189,7 @@ class MultisampledRenderingTest : public DawnTest {
constexpr uint32_t kMiddleX = (kWidth - 1) / 2;
constexpr uint32_t kMiddleY = (kHeight - 1) / 2;
RGBA8 expectedColor = ExpectedMSAAColor(inputColor, msaaCoverage);
utils::RGBA8 expectedColor = ExpectedMSAAColor(inputColor, msaaCoverage);
EXPECT_TEXTURE_EQ(&expectedColor, resolveTexture, {kMiddleX, kMiddleY, arrayLayer}, {1, 1},
mipmapLevel);
}
@ -274,8 +274,8 @@ class MultisampledRenderingTest : public DawnTest {
return pipeline;
}
RGBA8 ExpectedMSAAColor(const wgpu::Color color, const double msaaCoverage) {
RGBA8 result;
utils::RGBA8 ExpectedMSAAColor(const wgpu::Color color, const double msaaCoverage) {
utils::RGBA8 result;
result.r = static_cast<uint8_t>(std::min(255.0, 256 * color.r * msaaCoverage));
result.g = static_cast<uint8_t>(std::min(255.0, 256 * color.g * msaaCoverage));
result.b = static_cast<uint8_t>(std::min(255.0, 256 * color.b * msaaCoverage));
@ -778,7 +778,7 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DTextureWithSampleMaskAndShaderOut
wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
queue.Submit(1, &commandBuffer);
RGBA8 expectedColor = ExpectedMSAAColor(kGreen, kMSAACoverage);
utils::RGBA8 expectedColor = ExpectedMSAAColor(kGreen, kMSAACoverage);
EXPECT_TEXTURE_EQ(&expectedColor, mResolveTexture, {1, 0}, {1, 1});
}
@ -887,7 +887,7 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DTextureWithAlphaToCoverage) {
msaaCoverage = 1.0f;
}
RGBA8 expectedColor = ExpectedMSAAColor(kGreen, msaaCoverage);
utils::RGBA8 expectedColor = ExpectedMSAAColor(kGreen, msaaCoverage);
EXPECT_TEXTURE_EQ(&expectedColor, mResolveTexture, {1, 0}, {1, 1});
}
}
@ -939,8 +939,8 @@ TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargetsWithAlphaToCo
// Alpha to coverage affects both the color outputs, but the mask is computed
// using only the first one.
RGBA8 expectedRed = ExpectedMSAAColor(kRed, kMSAACoverage);
RGBA8 expectedGreen = ExpectedMSAAColor(kGreen, kMSAACoverage);
utils::RGBA8 expectedRed = ExpectedMSAAColor(kRed, kMSAACoverage);
utils::RGBA8 expectedGreen = ExpectedMSAAColor(kGreen, kMSAACoverage);
EXPECT_TEXTURE_EQ(&expectedRed, mResolveTexture, {1, 0}, {1, 1});
EXPECT_TEXTURE_EQ(&expectedGreen, resolveTexture2, {1, 0}, {1, 1});
}
@ -1001,7 +1001,7 @@ TEST_P(MultisampledRenderingTest, MultisampledRenderingWithDepthTestAndAlphaToCo
constexpr wgpu::Color kHalfGreenHalfRed = {(kGreen.r + kRed.r) / 2.0, (kGreen.g + kRed.g) / 2.0,
(kGreen.b + kRed.b) / 2.0,
(kGreen.a + kRed.a) / 2.0};
RGBA8 expectedColor = ExpectedMSAAColor(kHalfGreenHalfRed, 1.0f);
utils::RGBA8 expectedColor = ExpectedMSAAColor(kHalfGreenHalfRed, 1.0f);
EXPECT_TEXTURE_EQ(&expectedColor, mResolveTexture, {1, 0}, {1, 1});
}
@ -1046,7 +1046,7 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DTextureWithAlphaToCoverageAndSamp
wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
queue.Submit(1, &commandBuffer);
RGBA8 expectedColor = ExpectedMSAAColor(kGreen, kMSAACoverage * alpha);
utils::RGBA8 expectedColor = ExpectedMSAAColor(kGreen, kMSAACoverage * alpha);
EXPECT_TEXTURE_EQ(&expectedColor, mResolveTexture, {1, 0}, {1, 1});
}
}

View File

@ -204,7 +204,8 @@ TEST_P(OpArrayLengthTest, Fragment) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
RGBA8 expectedColor = RGBA8(mExpectedLengths[0], mExpectedLengths[1], mExpectedLengths[2], 0);
utils::RGBA8 expectedColor =
utils::RGBA8(mExpectedLengths[0], mExpectedLengths[1], mExpectedLengths[2], 0);
EXPECT_PIXEL_RGBA8_EQ(expectedColor, renderPass.color, 0, 0);
}
@ -268,7 +269,8 @@ TEST_P(OpArrayLengthTest, Vertex) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
RGBA8 expectedColor = RGBA8(mExpectedLengths[0], mExpectedLengths[1], mExpectedLengths[2], 0);
utils::RGBA8 expectedColor =
utils::RGBA8(mExpectedLengths[0], mExpectedLengths[1], mExpectedLengths[2], 0);
EXPECT_PIXEL_RGBA8_EQ(expectedColor, renderPass.color, 0, 0);
}

View File

@ -78,14 +78,14 @@ class DepthClippingTest : public DawnTest {
struct TestSpec {
wgpu::PrimitiveDepthClipControl* depthClipControl;
RGBA8 color;
utils::RGBA8 color;
float depth;
};
// Each test param represents a pair of triangles with a color, depth, stencil value, and
// depthStencil state, one frontfacing, one backfacing Draw the triangles in order and check the
// expected colors for the frontfaces and backfaces
void DoTest(const std::vector<TestSpec>& testParams, const RGBA8& expected) {
void DoTest(const std::vector<TestSpec>& testParams, const utils::RGBA8& expected) {
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
struct TriangleData {
@ -153,20 +153,20 @@ TEST_P(DepthClippingTest, UnclippedBeyondFarPlane) {
{
// Draw a red triangle at depth 1.
{
nullptr, /* depthClipControl */
RGBA8(255, 0, 0, 255), /* color */
1.f, /* depth */
nullptr, /* depthClipControl */
utils::RGBA8(255, 0, 0, 255), /* color */
1.f, /* depth */
},
// Draw a green triangle at depth 2 which should not be clipped.
{
&depthClipControl, /* depthClipControl */
RGBA8(0, 255, 0, 255), /* color */
2.f, /* depth */
&depthClipControl, /* depthClipControl */
utils::RGBA8(0, 255, 0, 255), /* color */
2.f, /* depth */
},
},
// The resulting fragment should be green even though the green triangle is
// outside the clip volume.
RGBA8(0, 255, 0, 255));
utils::RGBA8(0, 255, 0, 255));
}
// Test that fragments beyond the far plane are clipped if unclippedDepth is false
@ -178,20 +178,20 @@ TEST_P(DepthClippingTest, ClippedBeyondFarPlane) {
{
// Draw a red triangle at depth 1.
{
nullptr, /* depthClipControl */
RGBA8(255, 0, 0, 255), /* color */
1.f, /* depth */
nullptr, /* depthClipControl */
utils::RGBA8(255, 0, 0, 255), /* color */
1.f, /* depth */
},
// Draw a green triangle at depth 2 which should be clipped.
{
&depthClipControl, /* depthClipControl */
RGBA8(0, 255, 0, 255), /* color */
2.f, /* depth */
&depthClipControl, /* depthClipControl */
utils::RGBA8(0, 255, 0, 255), /* color */
2.f, /* depth */
},
},
// The resulting fragment should be red since the green triangle is
// outside the clip volume.
RGBA8(255, 0, 0, 255));
utils::RGBA8(255, 0, 0, 255));
}
// Test that fragments beyond the far plane are clipped if unclippedDepth is not specified
@ -200,20 +200,20 @@ TEST_P(DepthClippingTest, ClippedBeyondFarPlaneFeatureUnused) {
{
// Draw a red triangle at depth 1.
{
nullptr, /* depthClipControl */
RGBA8(255, 0, 0, 255), /* color */
1.f, /* depth */
nullptr, /* depthClipControl */
utils::RGBA8(255, 0, 0, 255), /* color */
1.f, /* depth */
},
// Draw a green triangle at depth 2 which should be clipped.
{
nullptr, /* depthClipControl */
RGBA8(0, 255, 0, 255), /* color */
2.f, /* depth */
nullptr, /* depthClipControl */
utils::RGBA8(0, 255, 0, 255), /* color */
2.f, /* depth */
},
},
// The resulting fragment should be red since the green triangle is
// outside the clip volume.
RGBA8(255, 0, 0, 255));
utils::RGBA8(255, 0, 0, 255));
}
// Test that fragments beyond the near plane are not clipped if unclippedDepth is true
@ -225,20 +225,20 @@ TEST_P(DepthClippingTest, UnclippedBeyondNearPlane) {
{
// Draw a red triangle at depth 0.
{
nullptr, /* depthClipControl */
RGBA8(255, 0, 0, 255), /* color */
0.f, /* depth */
nullptr, /* depthClipControl */
utils::RGBA8(255, 0, 0, 255), /* color */
0.f, /* depth */
},
// Draw a green triangle at depth -1 which should not be clipped.
{
&depthClipControl, /* depthClipControl */
RGBA8(0, 255, 0, 255), /* color */
-1.f, /* depth */
&depthClipControl, /* depthClipControl */
utils::RGBA8(0, 255, 0, 255), /* color */
-1.f, /* depth */
},
},
// The resulting fragment should be green even though the green triangle is
// outside the clip volume.
RGBA8(0, 255, 0, 255));
utils::RGBA8(0, 255, 0, 255));
}
// Test that fragments beyond the near plane are clipped if unclippedDepth is false
@ -250,20 +250,20 @@ TEST_P(DepthClippingTest, ClippedBeyondNearPlane) {
{
// Draw a red triangle at depth 0.
{
nullptr, /* depthClipControl */
RGBA8(255, 0, 0, 255), /* color */
0.f, /* depth */
nullptr, /* depthClipControl */
utils::RGBA8(255, 0, 0, 255), /* color */
0.f, /* depth */
},
// Draw a green triangle at depth -1 which should be clipped.
{
&depthClipControl, /* depthClipControl */
RGBA8(0, 255, 0, 255), /* color */
-1.f, /* depth */
&depthClipControl, /* depthClipControl */
utils::RGBA8(0, 255, 0, 255), /* color */
-1.f, /* depth */
},
},
// The resulting fragment should be red because the green triangle is
// outside the clip volume.
RGBA8(255, 0, 0, 255));
utils::RGBA8(255, 0, 0, 255));
}
// Test that fragments beyond the near plane are clipped if unclippedDepth is not specified
@ -272,20 +272,20 @@ TEST_P(DepthClippingTest, ClippedBeyondNearPlaneFeatureUnused) {
{
// Draw a red triangle at depth 0.
{
nullptr, /* depthClipControl */
RGBA8(255, 0, 0, 255), /* color */
0.f, /* depth */
nullptr, /* depthClipControl */
utils::RGBA8(255, 0, 0, 255), /* color */
0.f, /* depth */
},
// Draw a green triangle at depth -1 which should be clipped.
{
nullptr, /* depthClipControl */
RGBA8(0, 255, 0, 255), /* color */
-1.f, /* depth */
nullptr, /* depthClipControl */
utils::RGBA8(0, 255, 0, 255), /* color */
-1.f, /* depth */
},
},
// The resulting fragment should be red because the green triangle is
// outside the clip volume.
RGBA8(255, 0, 0, 255));
utils::RGBA8(255, 0, 0, 255));
}
// Test that fragments are properly clipped or clamped if multiple render pipelines are used
@ -301,16 +301,16 @@ TEST_P(DepthClippingTest, MultipleRenderPipelines) {
{
// Draw green with no clipping
{
&depthClipControl1, RGBA8(0, 255, 0, 255), /* color */
2.f, /* depth */
&depthClipControl1, utils::RGBA8(0, 255, 0, 255), /* color */
2.f, /* depth */
},
// Draw red with clipping
{
&depthClipControl2, RGBA8(255, 0, 0, 255), /* color */
2.f, /* depth */
&depthClipControl2, utils::RGBA8(255, 0, 0, 255), /* color */
2.f, /* depth */
},
},
RGBA8(0, 255, 0, 255)); // Result should be green
utils::RGBA8(0, 255, 0, 255)); // Result should be green
}
// Test that fragments are not clipped if unclippedDepth is true and that their
@ -351,7 +351,8 @@ TEST_P(DepthClippingTest, UnclippedNotClamped) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_BETWEEN(RGBA8(127, 0, 0, 255), RGBA8(128, 0, 0, 255), renderTarget, 0, 0)
EXPECT_PIXEL_RGBA8_BETWEEN(utils::RGBA8(127, 0, 0, 255), utils::RGBA8(128, 0, 0, 255),
renderTarget, 0, 0)
<< "Pixel check failed";
}

View File

@ -218,7 +218,8 @@ class PrimitiveTopologyTest : public DawnTest {
for (size_t i = 0; i < locationSpec.count; ++i) {
// If this pixel is included, check that it is green. Otherwise, check that it is
// black
RGBA8 color = locationSpec.include ? RGBA8::kGreen : RGBA8::kZero;
utils::RGBA8 color =
locationSpec.include ? utils::RGBA8::kGreen : utils::RGBA8::kZero;
EXPECT_PIXEL_RGBA8_EQ(color, renderPass.color, locationSpec.locations[i].x,
locationSpec.locations[i].y)
<< "Expected (" << locationSpec.locations[i].x << ", "

View File

@ -234,7 +234,7 @@ class QueueWriteTextureTests : public DawnTest {
uint32_t width,
uint32_t height,
uint32_t srcBytesPerRow,
RGBA8* dstData,
utils::RGBA8* dstData,
uint32_t dstTexelPerRow,
uint32_t texelBlockSize) {
for (uint64_t y = 0; y < height; ++y) {
@ -299,7 +299,7 @@ class QueueWriteTextureTests : public DawnTest {
for (uint32_t slice = textureSpec.copyOrigin.z; slice < maxArrayLayer; ++slice) {
// Pack the data in the specified copy region to have the same
// format as the expected texture data.
std::vector<RGBA8> expected(texelCountLastLayer);
std::vector<utils::RGBA8> expected(texelCountLastLayer);
PackTextureData(data.data() + dataOffset, copySize.width, copySize.height,
dataSpec.bytesPerRow, expected.data(), copySize.width, bytesPerTexel);

View File

@ -224,11 +224,11 @@ TEST_P(ReadOnlyDepthAttachmentTests, SampleFromAttachment) {
// The top part is not rendered by the pipeline. Its color is the default clear color for
// color attachment.
const std::vector<RGBA8> kExpectedTopColors(kSize * kSize / 2, {0, 0, 0, 0});
const std::vector<utils::RGBA8> kExpectedTopColors(kSize * kSize / 2, {0, 0, 0, 0});
// The bottom part is rendered, whose red channel is sampled from depth attachment, which
// is initialized into 0.2.
const std::vector<RGBA8> kExpectedBottomColors(kSize * kSize / 2,
{static_cast<uint8_t>(0.2 * 255), 0, 0, 0});
const std::vector<utils::RGBA8> kExpectedBottomColors(
kSize * kSize / 2, {static_cast<uint8_t>(0.2 * 255), 0, 0, 0});
EXPECT_TEXTURE_EQ(kExpectedTopColors.data(), colorTexture, {0, 0}, {kSize, kSize / 2});
EXPECT_TEXTURE_EQ(kExpectedBottomColors.data(), colorTexture, {0, kSize / 2},
{kSize, kSize / 2});
@ -248,9 +248,9 @@ TEST_P(ReadOnlyDepthAttachmentTests, NotSampleFromAttachment) {
// The top part is not rendered by the pipeline. Its color is the default clear color for
// color attachment.
const std::vector<RGBA8> kExpectedTopColors(kSize * kSize / 2, {0, 0, 0, 0});
const std::vector<utils::RGBA8> kExpectedTopColors(kSize * kSize / 2, {0, 0, 0, 0});
// The bottom part is rendered. Its color is set to blue.
const std::vector<RGBA8> kExpectedBottomColors(kSize * kSize / 2, {0, 0, 255, 0});
const std::vector<utils::RGBA8> kExpectedBottomColors(kSize * kSize / 2, {0, 0, 255, 0});
EXPECT_TEXTURE_EQ(kExpectedTopColors.data(), colorTexture, {0, 0}, {kSize, kSize / 2});
EXPECT_TEXTURE_EQ(kExpectedBottomColors.data(), colorTexture, {0, kSize / 2},
{kSize, kSize / 2});
@ -277,14 +277,14 @@ TEST_P(ReadOnlyStencilAttachmentTests, SampleFromAttachment) {
// stencilRefValue < stencilValue (stencilInitValue), so stencil test passes. The pipeline
// samples from stencil buffer and writes into color buffer.
DoTest(wgpu::TextureAspect::StencilOnly, stencilFormat, colorTexture, &values, true);
const std::vector<RGBA8> kSampledColors(kSize * kSize, {3, 0, 0, 0});
const std::vector<utils::RGBA8> kSampledColors(kSize * kSize, {3, 0, 0, 0});
EXPECT_TEXTURE_EQ(kSampledColors.data(), colorTexture, {0, 0}, {kSize, kSize});
values.stencilInitValue = 1;
// stencilRefValue > stencilValue (stencilInitValue), so stencil test fails. The pipeline
// doesn't change color buffer. Sampled data from stencil buffer is discarded.
DoTest(wgpu::TextureAspect::StencilOnly, stencilFormat, colorTexture, &values, true);
const std::vector<RGBA8> kInitColors(kSize * kSize, {0, 0, 0, 0});
const std::vector<utils::RGBA8> kInitColors(kSize * kSize, {0, 0, 0, 0});
EXPECT_TEXTURE_EQ(kInitColors.data(), colorTexture, {0, 0}, {kSize, kSize});
}
@ -301,14 +301,14 @@ TEST_P(ReadOnlyStencilAttachmentTests, NotSampleFromAttachment) {
// stencilRefValue < stencilValue (stencilInitValue), so stencil test passes. The pipeline
// draw solid blue into color buffer.
DoTest(wgpu::TextureAspect::StencilOnly, stencilFormat, colorTexture, &values, false);
const std::vector<RGBA8> kSampledColors(kSize * kSize, {0, 0, 255, 0});
const std::vector<utils::RGBA8> kSampledColors(kSize * kSize, {0, 0, 255, 0});
EXPECT_TEXTURE_EQ(kSampledColors.data(), colorTexture, {0, 0}, {kSize, kSize});
values.stencilInitValue = 1;
// stencilRefValue > stencilValue (stencilInitValue), so stencil test fails. The pipeline
// doesn't change color buffer. drawing data is discarded.
DoTest(wgpu::TextureAspect::StencilOnly, stencilFormat, colorTexture, &values, false);
const std::vector<RGBA8> kInitColors(kSize * kSize, {0, 0, 0, 0});
const std::vector<utils::RGBA8> kInitColors(kSize * kSize, {0, 0, 0, 0});
EXPECT_TEXTURE_EQ(kInitColors.data(), colorTexture, {0, 0}, {kSize, kSize});
}

View File

@ -72,7 +72,7 @@ TEST_P(RenderAttachmentTest, MoreFragmentOutputsThanAttachments) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderTarget, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kRed, renderTarget, 0, 0);
}
DAWN_INSTANTIATE_TEST(RenderAttachmentTest,

View File

@ -19,7 +19,7 @@
#include "dawn/utils/WGPUHelpers.h"
constexpr uint32_t kRTSize = 4;
const RGBA8 kColors[2] = {RGBA8::kGreen, RGBA8::kBlue};
const utils::RGBA8 kColors[2] = {utils::RGBA8::kGreen, utils::RGBA8::kBlue};
// RenderBundleTest tests simple usage of RenderBundles to draw. The implementaiton
// of RenderBundle is shared significantly with render pass execution which is

View File

@ -70,11 +70,11 @@ class RenderPassLoadOpTests : public DawnTest {
renderTargetView = renderTarget.CreateView();
std::fill(expectZero.begin(), expectZero.end(), RGBA8::kZero);
std::fill(expectZero.begin(), expectZero.end(), utils::RGBA8::kZero);
std::fill(expectGreen.begin(), expectGreen.end(), RGBA8::kGreen);
std::fill(expectGreen.begin(), expectGreen.end(), utils::RGBA8::kGreen);
std::fill(expectBlue.begin(), expectBlue.end(), RGBA8::kBlue);
std::fill(expectBlue.begin(), expectBlue.end(), utils::RGBA8::kBlue);
// draws a blue quad on the right half of the screen
const char* vsSource = R"(
@ -140,9 +140,9 @@ class RenderPassLoadOpTests : public DawnTest {
wgpu::Texture renderTarget;
wgpu::TextureView renderTargetView;
std::array<RGBA8, kRTSize * kRTSize> expectZero;
std::array<RGBA8, kRTSize * kRTSize> expectGreen;
std::array<RGBA8, kRTSize * kRTSize> expectBlue;
std::array<utils::RGBA8, kRTSize * kRTSize> expectZero;
std::array<utils::RGBA8, kRTSize * kRTSize> expectGreen;
std::array<utils::RGBA8, kRTSize * kRTSize> expectBlue;
DrawQuad blueQuad = {};
};

View File

@ -107,11 +107,11 @@ TEST_P(RenderPassTest, TwoRenderPassesInOneCommandBuffer) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kBlue, renderTarget1, 1, kRTSize - 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderTarget1, kRTSize - 1, 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kBlue, renderTarget1, 1, kRTSize - 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kRed, renderTarget1, kRTSize - 1, 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kBlue, renderTarget2, 1, kRTSize - 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderTarget2, kRTSize - 1, 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kBlue, renderTarget2, 1, kRTSize - 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderTarget2, kRTSize - 1, 1);
}
// Verify that the content in the color attachment will not be changed if there is no corresponding
@ -159,8 +159,8 @@ TEST_P(RenderPassTest, NoCorrespondingFragmentShaderOutputs) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kBlue, renderTarget, 1, kRTSize - 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderTarget, kRTSize - 1, 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kBlue, renderTarget, 1, kRTSize - 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kRed, renderTarget, kRTSize - 1, 1);
}
class RenderPassTest_RegressionDawn1071 : public RenderPassTest {};

View File

@ -28,7 +28,8 @@ namespace {
// each mipmap of the texture is having a different color
// so we can check if the sampler anisotropic filtering is fetching
// from the correct miplevel
const std::array<RGBA8, 3> colors = {RGBA8::kRed, RGBA8::kGreen, RGBA8::kBlue};
const std::array<utils::RGBA8, 3> colors = {utils::RGBA8::kRed, utils::RGBA8::kGreen,
utils::RGBA8::kBlue};
} // namespace
class SamplerFilterAnisotropicTest : public DawnTest {
@ -111,7 +112,7 @@ class SamplerFilterAnisotropicTest : public DawnTest {
descriptor.usage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::TextureBinding;
wgpu::Texture texture = device.CreateTexture(&descriptor);
const uint32_t rowPixels = kTextureBytesPerRowAlignment / sizeof(RGBA8);
const uint32_t rowPixels = kTextureBytesPerRowAlignment / sizeof(utils::RGBA8);
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
@ -120,11 +121,12 @@ class SamplerFilterAnisotropicTest : public DawnTest {
const uint32_t texWidth = textureWidthLevel0 >> level;
const uint32_t texHeight = textureHeightLevel0 >> level;
const RGBA8 color = colors[level];
const utils::RGBA8 color = colors[level];
std::vector<RGBA8> data(rowPixels * texHeight, color);
wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), data.size() * sizeof(RGBA8), wgpu::BufferUsage::CopySrc);
std::vector<utils::RGBA8> data(rowPixels * texHeight, color);
wgpu::Buffer stagingBuffer =
utils::CreateBufferFromData(device, data.data(), data.size() * sizeof(utils::RGBA8),
wgpu::BufferUsage::CopySrc);
wgpu::ImageCopyBuffer imageCopyBuffer =
utils::CreateImageCopyBuffer(stagingBuffer, 0, kTextureBytesPerRowAlignment);
wgpu::ImageCopyTexture imageCopyTexture =

View File

@ -97,13 +97,14 @@ class SamplerTest : public DawnTest {
wgpu::Texture texture = device.CreateTexture(&descriptor);
// Create a 2x2 checkerboard texture, with black in the top left and bottom right corners.
const uint32_t rowPixels = kTextureBytesPerRowAlignment / sizeof(RGBA8);
std::array<RGBA8, rowPixels * 2> pixels;
pixels[0] = pixels[rowPixels + 1] = RGBA8::kBlack;
pixels[1] = pixels[rowPixels] = RGBA8::kWhite;
const uint32_t rowPixels = kTextureBytesPerRowAlignment / sizeof(utils::RGBA8);
std::array<utils::RGBA8, rowPixels * 2> pixels;
pixels[0] = pixels[rowPixels + 1] = utils::RGBA8::kBlack;
pixels[1] = pixels[rowPixels] = utils::RGBA8::kWhite;
wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, pixels.data(), pixels.size() * sizeof(RGBA8), wgpu::BufferUsage::CopySrc);
wgpu::Buffer stagingBuffer =
utils::CreateBufferFromData(device, pixels.data(), pixels.size() * sizeof(utils::RGBA8),
wgpu::BufferUsage::CopySrc);
wgpu::ImageCopyBuffer imageCopyBuffer = utils::CreateImageCopyBuffer(stagingBuffer, 0, 256);
wgpu::ImageCopyTexture imageCopyTexture =
utils::CreateImageCopyTexture(texture, 0, {0, 0, 0});
@ -146,14 +147,14 @@ class SamplerTest : public DawnTest {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
RGBA8 expectedU2(u.mExpected2, u.mExpected2, u.mExpected2, 255);
RGBA8 expectedU3(u.mExpected3, u.mExpected3, u.mExpected3, 255);
RGBA8 expectedV2(v.mExpected2, v.mExpected2, v.mExpected2, 255);
RGBA8 expectedV3(v.mExpected3, v.mExpected3, v.mExpected3, 255);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kBlack, mRenderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kWhite, mRenderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kWhite, mRenderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kBlack, mRenderPass.color, 1, 1);
utils::RGBA8 expectedU2(u.mExpected2, u.mExpected2, u.mExpected2, 255);
utils::RGBA8 expectedU3(u.mExpected3, u.mExpected3, u.mExpected3, 255);
utils::RGBA8 expectedV2(v.mExpected2, v.mExpected2, v.mExpected2, 255);
utils::RGBA8 expectedV3(v.mExpected3, v.mExpected3, v.mExpected3, 255);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kBlack, mRenderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kWhite, mRenderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kWhite, mRenderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kBlack, mRenderPass.color, 1, 1);
EXPECT_PIXEL_RGBA8_EQ(expectedU2, mRenderPass.color, 2, 0);
EXPECT_PIXEL_RGBA8_EQ(expectedU3, mRenderPass.color, 3, 0);
EXPECT_PIXEL_RGBA8_EQ(expectedV2, mRenderPass.color, 0, 2);

View File

@ -63,10 +63,10 @@ TEST_P(ScissorTest, DefaultsToWholeRenderTarget) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 99);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 99, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 99, 99);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 0, 99);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 99, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 99, 99);
}
// Test setting a partial scissor (not empty, not full attachment)
@ -92,11 +92,11 @@ TEST_P(ScissorTest, PartialRect) {
queue.Submit(1, &commands);
// Test the two opposite corners of the scissor box. With one pixel inside and on outside
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, kX - 1, kY - 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, kX, kY);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, kX - 1, kY - 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, kX, kY);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, kX + kW, kY + kH);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, kX + kW - 1, kY + kH - 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, kX + kW, kY + kH);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, kX + kW - 1, kY + kH - 1);
}
// Test setting an empty scissor
@ -117,10 +117,10 @@ TEST_P(ScissorTest, EmptyRect) {
queue.Submit(1, &commands);
// Test that no pixel was written.
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 1, 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, 1, 1);
}
// Test that the scissor setting doesn't get inherited between renderpasses
TEST_P(ScissorTest, NoInheritanceBetweenRenderPass) {
@ -145,10 +145,10 @@ TEST_P(ScissorTest, NoInheritanceBetweenRenderPass) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 99);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 99, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 99, 99);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 0, 99);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 99, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 99, 99);
}
DAWN_INSTANTIATE_TEST(ScissorTest,

View File

@ -733,7 +733,7 @@ fn main(@builtin(vertex_index) VertexIndex : u32)
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(255, 255, 255, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(255, 255, 255, 255), renderPass.color, 0, 0);
}
// This is a regression test for crbug.com/dawn:1363 where the BindingRemapper transform was run

View File

@ -142,8 +142,9 @@ class StorageTextureTests : public DawnTest {
// 8-bit (normalized/non-normalized signed/unsigned integer) 4-component formats
case wgpu::TextureFormat::RGBA8Unorm:
case wgpu::TextureFormat::RGBA8Uint: {
RGBA8* valuePtr = static_cast<RGBA8*>(pixelValuePtr);
*valuePtr = RGBA8(pixelValue, pixelValue * 2, pixelValue * 3, pixelValue * 4);
utils::RGBA8* valuePtr = static_cast<utils::RGBA8*>(pixelValuePtr);
*valuePtr =
utils::RGBA8(pixelValue, pixelValue * 2, pixelValue * 3, pixelValue * 4);
break;
}
@ -488,7 +489,7 @@ fn IsEqualTo(pixel : vec4<f32>, expected : vec4<f32>) -> bool {
queue.Submit(1, &commandBuffer);
// Check if the contents in the output texture are all as expected (green).
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, outputTexture, 0, 0)
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, outputTexture, 0, 0)
<< "\nVertex Shader:\n"
<< vertexShader << "\n\nFragment Shader:\n"
<< fragmentShader;

View File

@ -39,7 +39,7 @@ class SubresourceRenderAttachmentTest : public DawnTest {
renderTargetViewDesc.mipLevelCount = 1;
wgpu::TextureView renderTargetView = renderTarget.CreateView(&renderTargetViewDesc);
RGBA8 expectedColor(0, 255, 0, 255);
utils::RGBA8 expectedColor(0, 255, 0, 255);
float expectedDepth = 0.3f;
uint8_t expectedStencil = 7;
@ -81,7 +81,8 @@ class SubresourceRenderAttachmentTest : public DawnTest {
const uint32_t renderTargetSize = textureSize >> baseMipLevel;
switch (type) {
case Type::Color: {
std::vector<RGBA8> expected(renderTargetSize * renderTargetSize, expectedColor);
std::vector<utils::RGBA8> expected(renderTargetSize * renderTargetSize,
expectedColor);
EXPECT_TEXTURE_EQ(expected.data(), renderTarget, {0, 0, baseArrayLayer},
{renderTargetSize, renderTargetSize}, baseMipLevel);
break;

View File

@ -77,12 +77,12 @@ TEST_P(Texture3DTests, Sampling) {
utils::RequiredBytesInCopy(bytesPerRow, copySize.height, copySize, kFormat);
const uint32_t bytesPerTexel = utils::GetTexelBlockSizeInBytes(kFormat);
uint32_t size = sizeInBytes / bytesPerTexel;
std::vector<RGBA8> data = std::vector<RGBA8>(size);
std::vector<utils::RGBA8> data = std::vector<utils::RGBA8>(size);
for (uint32_t z = 0; z < copySize.depthOrArrayLayers; ++z) {
for (uint32_t y = 0; y < copySize.height; ++y) {
for (uint32_t x = 0; x < copySize.width; ++x) {
uint32_t i = (z * copySize.height + y) * bytesPerRow / bytesPerTexel + x;
data[i] = RGBA8(x, y, z, 255);
data[i] = utils::RGBA8(x, y, z, 255);
}
}
}
@ -112,7 +112,7 @@ TEST_P(Texture3DTests, Sampling) {
// in shader, so the expected color at coordinate(x, y) should be (x, y, 1, 255).
for (uint32_t i = 0; i < kRTSize; ++i) {
for (uint32_t j = 0; j < kRTSize; ++j) {
EXPECT_PIXEL_RGBA8_EQ(RGBA8(i, j, 1, 255), renderPass.color, i, j);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(i, j, 1, 255), renderPass.color, i, j);
}
}
}

View File

@ -156,8 +156,8 @@ TEST_P(TextureSubresourceTest, MipmapLevelsTest) {
// Verify that pixel at bottom-left corner is red, while pixel at top-right corner is background
// black in render view (mip level 1).
RGBA8 topRight = RGBA8::kBlack;
RGBA8 bottomLeft = RGBA8::kRed;
utils::RGBA8 topRight = utils::RGBA8::kBlack;
utils::RGBA8 bottomLeft = utils::RGBA8::kRed;
EXPECT_TEXTURE_EQ(&topRight, texture, {kSize / 2 - 1, 0}, {1, 1}, 1);
EXPECT_TEXTURE_EQ(&bottomLeft, texture, {0, kSize / 2 - 1}, {1, 1}, 1);
}
@ -182,8 +182,8 @@ TEST_P(TextureSubresourceTest, ArrayLayersTest) {
// Verify that pixel at bottom-left corner is red, while pixel at top-right corner is background
// black in render view (array layer 1).
RGBA8 topRight = RGBA8::kBlack;
RGBA8 bottomLeft = RGBA8::kRed;
utils::RGBA8 topRight = utils::RGBA8::kBlack;
utils::RGBA8 bottomLeft = utils::RGBA8::kRed;
EXPECT_TEXTURE_EQ(&topRight, texture, {kSize - 1, 0, 1}, {1, 1});
EXPECT_TEXTURE_EQ(&bottomLeft, texture, {0, kSize - 1, 1}, {1, 1});
}

View File

@ -140,9 +140,9 @@ class TextureViewSamplingTest : public DawnTest {
// Create a texture with pixel = (0, 0, 0, level * 10 + layer + 1) at level `level` and
// layer `layer`.
static_assert((kTextureBytesPerRowAlignment % sizeof(RGBA8)) == 0,
static_assert((kTextureBytesPerRowAlignment % sizeof(utils::RGBA8)) == 0,
"Texture bytes per row alignment must be a multiple of sizeof(RGBA8).");
constexpr uint32_t kPixelsPerRowPitch = kTextureBytesPerRowAlignment / sizeof(RGBA8);
constexpr uint32_t kPixelsPerRowPitch = kTextureBytesPerRowAlignment / sizeof(utils::RGBA8);
ASSERT_LE(textureWidthLevel0, kPixelsPerRowPitch);
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
@ -154,9 +154,11 @@ class TextureViewSamplingTest : public DawnTest {
const int pixelValue = GenerateTestPixelValue(layer, level);
constexpr uint32_t kPaddedTexWidth = kPixelsPerRowPitch;
std::vector<RGBA8> data(kPaddedTexWidth * texHeight, RGBA8(0, 0, 0, pixelValue));
std::vector<utils::RGBA8> data(kPaddedTexWidth * texHeight,
utils::RGBA8(0, 0, 0, pixelValue));
wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), data.size() * sizeof(RGBA8), wgpu::BufferUsage::CopySrc);
device, data.data(), data.size() * sizeof(utils::RGBA8),
wgpu::BufferUsage::CopySrc);
wgpu::ImageCopyBuffer imageCopyBuffer =
utils::CreateImageCopyBuffer(stagingBuffer, 0, kTextureBytesPerRowAlignment);
wgpu::ImageCopyTexture imageCopyTexture =
@ -194,7 +196,7 @@ class TextureViewSamplingTest : public DawnTest {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
RGBA8 expectedPixel(0, 0, 0, expected);
utils::RGBA8 expectedPixel(0, 0, 0, expected);
EXPECT_PIXEL_RGBA8_EQ(expectedPixel, mRenderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(expectedPixel, mRenderPass.color, mRenderPass.width - 1,
mRenderPass.height - 1);
@ -453,17 +455,17 @@ TEST_P(TextureViewSamplingTest, SRGBReinterpretation) {
wgpu::ImageCopyTexture dst = {};
dst.texture = texture;
std::array<RGBA8, 4> rgbaTextureData = {
RGBA8(180, 0, 0, 255),
RGBA8(0, 84, 0, 127),
RGBA8(0, 0, 62, 100),
RGBA8(62, 180, 84, 90),
std::array<utils::RGBA8, 4> rgbaTextureData = {
utils::RGBA8(180, 0, 0, 255),
utils::RGBA8(0, 84, 0, 127),
utils::RGBA8(0, 0, 62, 100),
utils::RGBA8(62, 180, 84, 90),
};
wgpu::TextureDataLayout dataLayout = {};
dataLayout.bytesPerRow = textureDesc.size.width * sizeof(RGBA8);
dataLayout.bytesPerRow = textureDesc.size.width * sizeof(utils::RGBA8);
queue.WriteTexture(&dst, rgbaTextureData.data(), rgbaTextureData.size() * sizeof(RGBA8),
queue.WriteTexture(&dst, rgbaTextureData.data(), rgbaTextureData.size() * sizeof(utils::RGBA8),
&dataLayout, &textureDesc.size);
wgpu::TextureView textureView = texture.CreateView(&viewDesc);
@ -512,18 +514,18 @@ TEST_P(TextureViewSamplingTest, SRGBReinterpretation) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(116, 0, 0, 255), //
RGBA8(117, 0, 0, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(0, 23, 0, 127), //
RGBA8(0, 24, 0, 127), renderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(0, 0, 12, 100), //
RGBA8(0, 0, 13, 100), renderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(12, 116, 23, 90), //
RGBA8(13, 117, 24, 90), renderPass.color, 1, 1);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(116, 0, 0, 255), //
utils::RGBA8(117, 0, 0, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(0, 23, 0, 127), //
utils::RGBA8(0, 24, 0, 127), renderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(0, 0, 12, 100), //
utils::RGBA8(0, 0, 13, 100), renderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(12, 116, 23, 90), //
utils::RGBA8(13, 117, 24, 90), renderPass.color, 1, 1);
}
// Test sampling from a cube map texture view that covers a whole 2D array texture.
@ -636,8 +638,8 @@ class TextureViewRenderingTest : public DawnTest {
Align(kBytesPerTexel * textureWidthLevel0, kTextureBytesPerRowAlignment);
uint32_t expectedDataSize =
bytesPerRow / kBytesPerTexel * (textureWidthLevel0 - 1) + textureHeightLevel0;
constexpr RGBA8 kExpectedPixel(0, 255, 0, 255);
std::vector<RGBA8> expected(expectedDataSize, kExpectedPixel);
constexpr utils::RGBA8 kExpectedPixel(0, 255, 0, 255);
std::vector<utils::RGBA8> expected(expectedDataSize, kExpectedPixel);
EXPECT_TEXTURE_EQ(expected.data(), texture, {0, 0, textureViewBaseLayer},
{textureViewWidth, textureViewHeight}, textureViewBaseLevel);
}
@ -780,11 +782,11 @@ TEST_P(TextureViewRenderingTest, SRGBReinterpretationRenderAttachment) {
wgpu::Texture sampledTexture = device.CreateTexture(&textureDesc);
// Initial non-SRGB data to upload to |sampledTexture|.
std::array<RGBA8, 4> rgbaTextureData = {
RGBA8(117, 0, 0, 255),
RGBA8(0, 23, 0, 127),
RGBA8(0, 0, 12, 100),
RGBA8(13, 117, 24, 90),
std::array<utils::RGBA8, 4> rgbaTextureData = {
utils::RGBA8(117, 0, 0, 255),
utils::RGBA8(0, 23, 0, 127),
utils::RGBA8(0, 0, 12, 100),
utils::RGBA8(13, 117, 24, 90),
};
wgpu::ImageCopyTexture dst = {};
@ -792,8 +794,8 @@ TEST_P(TextureViewRenderingTest, SRGBReinterpretationRenderAttachment) {
// Upload |rgbaTextureData| into |sampledTexture|.
dst.texture = sampledTexture;
dataLayout.bytesPerRow = textureDesc.size.width * sizeof(RGBA8);
queue.WriteTexture(&dst, rgbaTextureData.data(), rgbaTextureData.size() * sizeof(RGBA8),
dataLayout.bytesPerRow = textureDesc.size.width * sizeof(utils::RGBA8);
queue.WriteTexture(&dst, rgbaTextureData.data(), rgbaTextureData.size() * sizeof(utils::RGBA8),
&dataLayout, &textureDesc.size);
// View both the attachment as SRGB.
@ -846,18 +848,18 @@ TEST_P(TextureViewRenderingTest, SRGBReinterpretationRenderAttachment) {
// Check the results. This is the sRGB encoding for the same non-SRGB colors
// represented by |initialData|.
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(180, 0, 0, 255), //
RGBA8(181, 0, 0, 255), texture, 0, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(0, 85, 0, 127), //
RGBA8(0, 86, 0, 127), texture, 1, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(0, 0, 61, 100), //
RGBA8(0, 0, 62, 100), texture, 0, 1);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(64, 180, 86, 90), //
RGBA8(15, 181, 87, 90), texture, 1, 1);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(180, 0, 0, 255), //
utils::RGBA8(181, 0, 0, 255), texture, 0, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(0, 85, 0, 127), //
utils::RGBA8(0, 86, 0, 127), texture, 1, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(0, 0, 61, 100), //
utils::RGBA8(0, 0, 62, 100), texture, 0, 1);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(64, 180, 86, 90), //
utils::RGBA8(15, 181, 87, 90), texture, 1, 1);
}
// Test that an RGBA8 texture may be interpreted as RGBA8UnormSrgb and resolved to.
@ -893,11 +895,11 @@ TEST_P(TextureViewRenderingTest, SRGBReinterpretionResolveAttachment) {
wgpu::Texture sampledTexture = device.CreateTexture(&textureDesc);
// Initial non-SRGB data to upload to |sampledTexture|.
std::array<RGBA8, 4> rgbaTextureData = {
RGBA8(117, 0, 0, 255),
RGBA8(0, 23, 0, 127),
RGBA8(0, 0, 12, 100),
RGBA8(13, 117, 24, 90),
std::array<utils::RGBA8, 4> rgbaTextureData = {
utils::RGBA8(117, 0, 0, 255),
utils::RGBA8(0, 23, 0, 127),
utils::RGBA8(0, 0, 12, 100),
utils::RGBA8(13, 117, 24, 90),
};
wgpu::ImageCopyTexture dst = {};
@ -905,8 +907,8 @@ TEST_P(TextureViewRenderingTest, SRGBReinterpretionResolveAttachment) {
// Upload |rgbaTextureData| into |sampledTexture|.
dst.texture = sampledTexture;
dataLayout.bytesPerRow = textureDesc.size.width * sizeof(RGBA8);
queue.WriteTexture(&dst, rgbaTextureData.data(), rgbaTextureData.size() * sizeof(RGBA8),
dataLayout.bytesPerRow = textureDesc.size.width * sizeof(utils::RGBA8);
queue.WriteTexture(&dst, rgbaTextureData.data(), rgbaTextureData.size() * sizeof(utils::RGBA8),
&dataLayout, &textureDesc.size);
// View both the multisampled texture and the resolve texture as SRGB.
@ -962,18 +964,18 @@ TEST_P(TextureViewRenderingTest, SRGBReinterpretionResolveAttachment) {
// Check the results. This is the sRGB encoding for the same non-SRGB colors
// represented by |initialData|.
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(180, 0, 0, 255), //
RGBA8(181, 0, 0, 255), resolveTexture, 0, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(0, 85, 0, 127), //
RGBA8(0, 86, 0, 127), resolveTexture, 1, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(0, 0, 61, 100), //
RGBA8(0, 0, 62, 100), resolveTexture, 0, 1);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(64, 180, 86, 90), //
RGBA8(15, 181, 87, 90), resolveTexture, 1, 1);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(180, 0, 0, 255), //
utils::RGBA8(181, 0, 0, 255), resolveTexture, 0, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(0, 85, 0, 127), //
utils::RGBA8(0, 86, 0, 127), resolveTexture, 1, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(0, 0, 61, 100), //
utils::RGBA8(0, 0, 62, 100), resolveTexture, 0, 1);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(64, 180, 86, 90), //
utils::RGBA8(15, 181, 87, 90), resolveTexture, 1, 1);
}
DAWN_INSTANTIATE_TEST(TextureViewSamplingTest,
@ -1058,7 +1060,8 @@ TEST_P(TextureView1DTest, Sampling) {
texDesc.size = {4, 1, 1};
wgpu::Texture tex = device.CreateTexture(&texDesc);
std::array<RGBA8, 4> data = {RGBA8::kGreen, RGBA8::kRed, RGBA8::kBlue, RGBA8::kWhite};
std::array<utils::RGBA8, 4> data = {utils::RGBA8::kGreen, utils::RGBA8::kRed,
utils::RGBA8::kBlue, utils::RGBA8::kWhite};
wgpu::ImageCopyTexture target = utils::CreateImageCopyTexture(tex, 0, {});
wgpu::TextureDataLayout layout = utils::CreateTextureDataLayout(0, wgpu::kCopyStrideUndefined);
queue.WriteTexture(&target, &data, sizeof(data), &layout, &texDesc.size);

View File

@ -134,7 +134,7 @@ TEST_P(TextureZeroInitTest, CopyTextureToBufferSource) {
wgpu::Texture texture = device.CreateTexture(&descriptor);
// Texture's first usage is in EXPECT_PIXEL_RGBA8_EQ's call to CopyTextureToBuffer
RGBA8 filledWithZeros(0, 0, 0, 0);
utils::RGBA8 filledWithZeros(0, 0, 0, 0);
EXPECT_LAZY_CLEAR(1u, EXPECT_PIXEL_RGBA8_EQ(filledWithZeros, texture, 0, 0));
// Expect texture subresource initialized to be true
@ -176,7 +176,7 @@ TEST_P(TextureZeroInitTest, CopyMultipleTextureArrayLayersToBufferSource) {
EXPECT_TRUE(
dawn::native::IsTextureSubresourceInitialized(texture.Get(), 0, 1, 0, kArrayLayers));
const std::vector<RGBA8> kExpectedAllZero(kSize * kSize, {0, 0, 0, 0});
const std::vector<utils::RGBA8> kExpectedAllZero(kSize * kSize, {0, 0, 0, 0});
for (uint32_t layer = 0; layer < kArrayLayers; ++layer) {
EXPECT_TEXTURE_EQ(kExpectedAllZero.data(), texture, {0, 0, layer}, {kSize, kSize});
}
@ -217,7 +217,7 @@ TEST_P(TextureZeroInitTest, RenderingMipMapClearsToZero) {
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
uint32_t mipSize = kSize >> 2;
std::vector<RGBA8> expected(mipSize * mipSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expected(mipSize * mipSize, {0, 0, 0, 0});
EXPECT_TEXTURE_EQ(expected.data(), renderPass.color, {0, 0, baseArrayLayer}, {mipSize, mipSize},
baseMipLevel);
@ -260,7 +260,7 @@ TEST_P(TextureZeroInitTest, RenderingArrayLayerClearsToZero) {
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
std::vector<RGBA8> expected(kSize * kSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expected(kSize * kSize, {0, 0, 0, 0});
EXPECT_TEXTURE_EQ(expected.data(), renderPass.color, {0, 0, baseArrayLayer}, {kSize, kSize},
baseMipLevel);
@ -293,7 +293,7 @@ TEST_P(TextureZeroInitTest, CopyBufferToTexture) {
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
std::vector<RGBA8> expected(kSize * kSize, {100, 100, 100, 100});
std::vector<utils::RGBA8> expected(kSize * kSize, {100, 100, 100, 100});
EXPECT_TEXTURE_EQ(expected.data(), texture, {0, 0}, {kSize, kSize});
@ -325,8 +325,8 @@ TEST_P(TextureZeroInitTest, CopyBufferToTextureHalf) {
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
std::vector<RGBA8> expected100((kSize / 2) * kSize, {100, 100, 100, 100});
std::vector<RGBA8> expectedZeros((kSize / 2) * kSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expected100((kSize / 2) * kSize, {100, 100, 100, 100});
std::vector<utils::RGBA8> expectedZeros((kSize / 2) * kSize, {0, 0, 0, 0});
// first half filled with 100, by the buffer data
EXPECT_TEXTURE_EQ(expected100.data(), texture, {0, 0}, {kSize / 2, kSize});
// second half should be cleared
@ -367,7 +367,7 @@ TEST_P(TextureZeroInitTest, CopyBufferToTextureMultipleArrayLayers) {
EXPECT_TRUE(dawn::native::IsTextureSubresourceInitialized(texture.Get(), 0, 1, kBaseArrayLayer,
kCopyLayerCount));
const std::vector<RGBA8> expected100(kSize * kSize, {100, 100, 100, 100});
const std::vector<utils::RGBA8> expected100(kSize * kSize, {100, 100, 100, 100});
for (uint32_t layer = kBaseArrayLayer; layer < kBaseArrayLayer + kCopyLayerCount; ++layer) {
EXPECT_TEXTURE_EQ(expected100.data(), texture, {0, 0, layer}, {kSize, kSize});
}
@ -399,7 +399,7 @@ TEST_P(TextureZeroInitTest, CopyTextureToTexture) {
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
std::vector<RGBA8> expected(kSize * kSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expected(kSize * kSize, {0, 0, 0, 0});
EXPECT_TEXTURE_EQ(expected.data(), srcTexture, {0, 0}, {kSize, kSize});
EXPECT_TEXTURE_EQ(expected.data(), dstTexture, {0, 0}, {kSize, kSize});
@ -454,8 +454,8 @@ TEST_P(TextureZeroInitTest, CopyTextureToTextureHalf) {
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
std::vector<RGBA8> expectedWithZeros((kSize / 2) * kSize, {0, 0, 0, 0});
std::vector<RGBA8> expectedWith100(kSize * kSize, {100, 100, 100, 100});
std::vector<utils::RGBA8> expectedWithZeros((kSize / 2) * kSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expectedWith100(kSize * kSize, {100, 100, 100, 100});
EXPECT_TEXTURE_EQ(expectedWith100.data(), srcTexture, {0, 0}, {kSize, kSize});
EXPECT_TEXTURE_EQ(expectedWith100.data(), dstTexture, {0, 0}, {kSize / 2, kSize});
@ -504,7 +504,7 @@ TEST_P(TextureZeroInitTest, RenderingLoadingDepth) {
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer));
// Expect the texture to be red because depth test passed.
std::vector<RGBA8> expected(kSize * kSize, {255, 0, 0, 255});
std::vector<utils::RGBA8> expected(kSize * kSize, {255, 0, 0, 255});
EXPECT_TEXTURE_EQ(expected.data(), srcTexture, {0, 0}, {kSize, kSize});
// Expect texture subresource initialized to be true
@ -549,7 +549,7 @@ TEST_P(TextureZeroInitTest, RenderingLoadingStencil) {
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer));
// Expect the texture to be red because stencil test passed.
std::vector<RGBA8> expected(kSize * kSize, {255, 0, 0, 255});
std::vector<utils::RGBA8> expected(kSize * kSize, {255, 0, 0, 255});
EXPECT_TEXTURE_EQ(expected.data(), srcTexture, {0, 0}, {kSize, kSize});
// Expect texture subresource initialized to be true
@ -591,7 +591,7 @@ TEST_P(TextureZeroInitTest, RenderingLoadingDepthStencil) {
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer));
// Expect the texture to be red because both depth and stencil tests passed.
std::vector<RGBA8> expected(kSize * kSize, {255, 0, 0, 255});
std::vector<utils::RGBA8> expected(kSize * kSize, {255, 0, 0, 255});
EXPECT_TEXTURE_EQ(expected.data(), srcTexture, {0, 0}, {kSize, kSize});
// Expect texture subresource initialized to be true
@ -661,7 +661,7 @@ TEST_P(TextureZeroInitTest, IndependentDepthStencilLoadAfterDiscard) {
// Expect the texture to be red because the depth and stencil tests passed. Depth was 0
// and stencil was 2.
std::vector<RGBA8> expected(kSize * kSize, {255, 0, 0, 255});
std::vector<utils::RGBA8> expected(kSize * kSize, {255, 0, 0, 255});
EXPECT_TEXTURE_EQ(expected.data(), colorTexture, {0, 0}, {kSize, kSize});
}
@ -735,7 +735,7 @@ TEST_P(TextureZeroInitTest, IndependentDepthStencilLoadAfterDiscard) {
// Expect the texture to be red because both the depth a stencil tests passed.
// Depth was 0.7 and stencil was 0
std::vector<RGBA8> expected(kSize * kSize, {255, 0, 0, 255});
std::vector<utils::RGBA8> expected(kSize * kSize, {255, 0, 0, 255});
EXPECT_TEXTURE_EQ(expected.data(), colorTexture, {0, 0}, {kSize, kSize});
}
@ -833,7 +833,7 @@ TEST_P(TextureZeroInitTest, IndependentDepthStencilCopyAfterDiscard) {
// Expect the texture to be red because both the depth a stencil tests passed.
// Depth was 0.3 and stencil was 0
std::vector<RGBA8> expected(kSize * kSize, {255, 0, 0, 255});
std::vector<utils::RGBA8> expected(kSize * kSize, {255, 0, 0, 255});
EXPECT_TEXTURE_EQ(expected.data(), colorTexture, {0, 0}, {kSize, kSize});
}
}
@ -853,7 +853,7 @@ TEST_P(TextureZeroInitTest, ColorAttachmentsClear) {
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
std::vector<RGBA8> expected(kSize * kSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expected(kSize * kSize, {0, 0, 0, 0});
EXPECT_TEXTURE_EQ(expected.data(), renderPass.color, {0, 0}, {kSize, kSize});
// Expect texture subresource initialized to be true
@ -898,7 +898,7 @@ TEST_P(TextureZeroInitTest, RenderPassSampledTextureClear) {
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
// Expect the rendered texture to be cleared
std::vector<RGBA8> expectedWithZeros(kSize * kSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expectedWithZeros(kSize * kSize, {0, 0, 0, 0});
EXPECT_TEXTURE_EQ(expectedWithZeros.data(), renderTexture, {0, 0}, {kSize, kSize});
// Expect texture subresource initialized to be true
@ -955,8 +955,8 @@ TEST_P(TextureZeroInitTest, TextureBothSampledAndAttachmentClear) {
// Expect both subresources to be zero: the sampled one with lazy-clearing and the attachment
// because it sampled the lazy-cleared sampled subresource.
EXPECT_TEXTURE_EQ(&RGBA8::kZero, texture, {0, 0, 0}, {1, 1});
EXPECT_TEXTURE_EQ(&RGBA8::kZero, texture, {0, 0, 1}, {1, 1});
EXPECT_TEXTURE_EQ(&utils::RGBA8::kZero, texture, {0, 0, 0}, {1, 1});
EXPECT_TEXTURE_EQ(&utils::RGBA8::kZero, texture, {0, 0, 1}, {1, 1});
// The whole texture is now initialized.
EXPECT_EQ(true, dawn::native::IsTextureSubresourceInitialized(texture.Get(), 0, 1, 0, 2));
@ -1182,7 +1182,7 @@ TEST_P(TextureZeroInitTest, RenderPassStoreOpClear) {
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
// Expect the rendered texture to be cleared
std::vector<RGBA8> expectedWithZeros(kSize * kSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expectedWithZeros(kSize * kSize, {0, 0, 0, 0});
EXPECT_LAZY_CLEAR(
1u, EXPECT_TEXTURE_EQ(expectedWithZeros.data(), renderTexture, {0, 0}, {kSize, kSize}));
@ -1236,7 +1236,7 @@ TEST_P(TextureZeroInitTest, RenderingLoadingDepthStencilStoreOpClear) {
// The depth stencil test should fail and not draw because the depth stencil texture is
// cleared to 1's by using loadOp clear and set values from descriptor.
std::vector<RGBA8> expectedBlack(kSize * kSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expectedBlack(kSize * kSize, {0, 0, 0, 0});
EXPECT_TEXTURE_EQ(expectedBlack.data(), srcTexture, {0, 0}, {kSize, kSize});
// Expect texture subresource initialized to be false since storeop is clear, sets
@ -1261,7 +1261,7 @@ TEST_P(TextureZeroInitTest, RenderingLoadingDepthStencilStoreOpClear) {
// Now the depth stencil test should pass since depth stencil texture is cleared to 0's by
// loadop load and uninitialized subresource, so we should have a red square
std::vector<RGBA8> expectedRed(kSize * kSize, {255, 0, 0, 255});
std::vector<utils::RGBA8> expectedRed(kSize * kSize, {255, 0, 0, 255});
EXPECT_TEXTURE_EQ(expectedRed.data(), srcTexture, {0, 0}, {kSize, kSize});
// Expect texture subresource initialized to be false since storeop is clear, sets
@ -1330,7 +1330,7 @@ TEST_P(TextureZeroInitTest, PreservesInitializedMip) {
// Expect the rendered texture to be cleared since we copied from the uninitialized first
// mip.
std::vector<RGBA8> expectedWithZeros(kSize * kSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expectedWithZeros(kSize * kSize, {0, 0, 0, 0});
EXPECT_LAZY_CLEAR(
1u, EXPECT_TEXTURE_EQ(expectedWithZeros.data(), renderTexture, {0, 0}, {kSize, kSize}, 0));
@ -1339,7 +1339,7 @@ TEST_P(TextureZeroInitTest, PreservesInitializedMip) {
0u, EXPECT_TEXTURE_EQ(expectedWithZeros.data(), sampleTexture, {0, 0}, {kSize, kSize}, 0));
// Expect the second mip to still be filled with 2.
std::vector<RGBA8> expectedWithTwos(mipSize * mipSize, {2, 2, 2, 2});
std::vector<utils::RGBA8> expectedWithTwos(mipSize * mipSize, {2, 2, 2, 2});
EXPECT_LAZY_CLEAR(0u, EXPECT_TEXTURE_EQ(expectedWithTwos.data(), sampleTexture, {0, 0},
{mipSize, mipSize}, 1));
@ -1411,7 +1411,7 @@ TEST_P(TextureZeroInitTest, PreservesInitializedArrayLayer) {
// Expect the rendered texture to be cleared since we copied from the uninitialized first
// array layer.
std::vector<RGBA8> expectedWithZeros(kSize * kSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expectedWithZeros(kSize * kSize, {0, 0, 0, 0});
EXPECT_LAZY_CLEAR(
1u, EXPECT_TEXTURE_EQ(expectedWithZeros.data(), renderTexture, {0, 0, 0}, {kSize, kSize}));
@ -1420,7 +1420,7 @@ TEST_P(TextureZeroInitTest, PreservesInitializedArrayLayer) {
0u, EXPECT_TEXTURE_EQ(expectedWithZeros.data(), sampleTexture, {0, 0, 0}, {kSize, kSize}));
// Expect the second array layer to still be filled with 2.
std::vector<RGBA8> expectedWithTwos(kSize * kSize, {2, 2, 2, 2});
std::vector<utils::RGBA8> expectedWithTwos(kSize * kSize, {2, 2, 2, 2});
EXPECT_LAZY_CLEAR(
0u, EXPECT_TEXTURE_EQ(expectedWithTwos.data(), sampleTexture, {0, 0, 1}, {kSize, kSize}));
@ -1484,15 +1484,15 @@ TEST_P(TextureZeroInitTest, WriteWholeTexture) {
textureDataLayout.bytesPerRow = kSize * kFormatBlockByteSize;
textureDataLayout.rowsPerImage = kSize;
std::vector<RGBA8> data(
std::vector<utils::RGBA8> data(
utils::RequiredBytesInCopy(textureDataLayout.bytesPerRow, textureDataLayout.rowsPerImage,
copySize, kColorFormat) /
sizeof(RGBA8),
sizeof(utils::RGBA8),
{100, 100, 100, 100});
// The write overwrites the whole texture so we don't need to do lazy initialization.
EXPECT_LAZY_CLEAR(
0u, queue.WriteTexture(&imageCopyTexture, data.data(), data.size() * sizeof(RGBA8),
0u, queue.WriteTexture(&imageCopyTexture, data.data(), data.size() * sizeof(utils::RGBA8),
&textureDataLayout, &copySize));
// Expect texture initialized to be true
@ -1519,20 +1519,20 @@ TEST_P(TextureZeroInitTest, WriteTextureHalf) {
textureDataLayout.bytesPerRow = kSize * kFormatBlockByteSize / 2;
textureDataLayout.rowsPerImage = kSize;
std::vector<RGBA8> data(
std::vector<utils::RGBA8> data(
utils::RequiredBytesInCopy(textureDataLayout.bytesPerRow, textureDataLayout.rowsPerImage,
copySize, kColorFormat) /
sizeof(RGBA8),
sizeof(utils::RGBA8),
{100, 100, 100, 100});
EXPECT_LAZY_CLEAR(
1u, queue.WriteTexture(&imageCopyTexture, data.data(), data.size() * sizeof(RGBA8),
1u, queue.WriteTexture(&imageCopyTexture, data.data(), data.size() * sizeof(utils::RGBA8),
&textureDataLayout, &copySize));
// Expect texture initialized to be true
EXPECT_EQ(true, dawn::native::IsTextureSubresourceInitialized(texture.Get(), 0, 1, 0, 1));
std::vector<RGBA8> expectedZeros((kSize / 2) * kSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expectedZeros((kSize / 2) * kSize, {0, 0, 0, 0});
// first half filled with 100, by the data
EXPECT_TEXTURE_EQ(data.data(), texture, {0, 0}, {kSize / 2, kSize});
// second half should be cleared
@ -1558,16 +1558,16 @@ TEST_P(TextureZeroInitTest, WriteWholeTextureArray) {
textureDataLayout.bytesPerRow = kSize * kFormatBlockByteSize;
textureDataLayout.rowsPerImage = kSize;
std::vector<RGBA8> data(
std::vector<utils::RGBA8> data(
utils::RequiredBytesInCopy(textureDataLayout.bytesPerRow, textureDataLayout.rowsPerImage,
copySize, kColorFormat) /
sizeof(RGBA8),
sizeof(utils::RGBA8),
{100, 100, 100, 100});
// The write overwrites the whole subresources so we don't need to do lazy initialization on
// them.
EXPECT_LAZY_CLEAR(
0u, queue.WriteTexture(&imageCopyTexture, data.data(), data.size() * sizeof(RGBA8),
0u, queue.WriteTexture(&imageCopyTexture, data.data(), data.size() * sizeof(utils::RGBA8),
&textureDataLayout, &copySize));
// Expect texture subresource initialized to be true
@ -1601,21 +1601,21 @@ TEST_P(TextureZeroInitTest, WriteTextureArrayHalf) {
textureDataLayout.bytesPerRow = kSize * kFormatBlockByteSize / 2;
textureDataLayout.rowsPerImage = kSize;
std::vector<RGBA8> data(
std::vector<utils::RGBA8> data(
utils::RequiredBytesInCopy(textureDataLayout.bytesPerRow, textureDataLayout.rowsPerImage,
copySize, kColorFormat) /
sizeof(RGBA8),
sizeof(utils::RGBA8),
{100, 100, 100, 100});
EXPECT_LAZY_CLEAR(
1u, queue.WriteTexture(&imageCopyTexture, data.data(), data.size() * sizeof(RGBA8),
1u, queue.WriteTexture(&imageCopyTexture, data.data(), data.size() * sizeof(utils::RGBA8),
&textureDataLayout, &copySize));
// Expect texture subresource initialized to be true
EXPECT_EQ(true, dawn::native::IsTextureSubresourceInitialized(
texture.Get(), 0, 1, kBaseArrayLayer, kCopyLayerCount));
std::vector<RGBA8> expectedZeros((kSize / 2) * kSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expectedZeros((kSize / 2) * kSize, {0, 0, 0, 0});
for (uint32_t layer = kBaseArrayLayer; layer < kBaseArrayLayer + kCopyLayerCount; ++layer) {
// first half filled with 100, by the data
EXPECT_TEXTURE_EQ(data.data(), texture, {0, 0, layer}, {kSize / 2, kSize});
@ -1642,15 +1642,15 @@ TEST_P(TextureZeroInitTest, WriteWholeTextureAtMipLevel) {
textureDataLayout.bytesPerRow = kMipSize * kFormatBlockByteSize;
textureDataLayout.rowsPerImage = kMipSize;
std::vector<RGBA8> data(
std::vector<utils::RGBA8> data(
utils::RequiredBytesInCopy(textureDataLayout.bytesPerRow, textureDataLayout.rowsPerImage,
copySize, kColorFormat) /
sizeof(RGBA8),
sizeof(utils::RGBA8),
{100, 100, 100, 100});
// The write overwrites the whole texture so we don't need to do lazy initialization.
EXPECT_LAZY_CLEAR(
0u, queue.WriteTexture(&imageCopyTexture, data.data(), data.size() * sizeof(RGBA8),
0u, queue.WriteTexture(&imageCopyTexture, data.data(), data.size() * sizeof(utils::RGBA8),
&textureDataLayout, &copySize));
// Expect texture initialized to be true
@ -1681,21 +1681,21 @@ TEST_P(TextureZeroInitTest, WriteTextureHalfAtMipLevel) {
textureDataLayout.bytesPerRow = kMipSize * kFormatBlockByteSize / 2;
textureDataLayout.rowsPerImage = kMipSize;
std::vector<RGBA8> data(
std::vector<utils::RGBA8> data(
utils::RequiredBytesInCopy(textureDataLayout.bytesPerRow, textureDataLayout.rowsPerImage,
copySize, kColorFormat) /
sizeof(RGBA8),
sizeof(utils::RGBA8),
{100, 100, 100, 100});
EXPECT_LAZY_CLEAR(
1u, queue.WriteTexture(&imageCopyTexture, data.data(), data.size() * sizeof(RGBA8),
1u, queue.WriteTexture(&imageCopyTexture, data.data(), data.size() * sizeof(utils::RGBA8),
&textureDataLayout, &copySize));
// Expect texture initialized to be true
EXPECT_EQ(true,
dawn::native::IsTextureSubresourceInitialized(texture.Get(), kMipLevel, 1, 0, 1));
std::vector<RGBA8> expectedZeros((kMipSize / 2) * kMipSize, {0, 0, 0, 0});
std::vector<utils::RGBA8> expectedZeros((kMipSize / 2) * kMipSize, {0, 0, 0, 0});
// first half filled with 100, by the data
EXPECT_TEXTURE_EQ(data.data(), texture, {0, 0}, {kMipSize / 2, kMipSize}, kMipLevel);
// second half should be cleared
@ -1823,8 +1823,8 @@ class CompressedTextureZeroInitTest : public TextureZeroInitTest {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
std::vector<RGBA8> expected(nonPaddedCopyExtent.width * nonPaddedCopyExtent.height,
{0x00, 0x20, 0x08, 0xFF});
std::vector<utils::RGBA8> expected(nonPaddedCopyExtent.width * nonPaddedCopyExtent.height,
{0x00, 0x20, 0x08, 0xFF});
EXPECT_TEXTURE_EQ(expected.data(), renderPass.color, {0, 0},
{nonPaddedCopyExtent.width, nonPaddedCopyExtent.height});
EXPECT_TRUE(dawn::native::IsTextureSubresourceInitialized(bcTexture.Get(), viewMipmapLevel,
@ -1832,8 +1832,8 @@ class CompressedTextureZeroInitTest : public TextureZeroInitTest {
// If we only copied to half the texture, check the other half is initialized to black
if (halfCopyTest) {
std::vector<RGBA8> expectBlack(nonPaddedCopyExtent.width * nonPaddedCopyExtent.height,
{0x00, 0x00, 0x00, 0xFF});
std::vector<utils::RGBA8> expectBlack(
nonPaddedCopyExtent.width * nonPaddedCopyExtent.height, {0x00, 0x00, 0x00, 0xFF});
EXPECT_TEXTURE_EQ(expectBlack.data(), renderPass.color, {copyExtent3D.width, 0},
{nonPaddedCopyExtent.width, nonPaddedCopyExtent.height});
}

View File

@ -405,7 +405,7 @@ class VertexFormatTest : public DawnTest {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 0, 0);
}
};

View File

@ -163,8 +163,8 @@ class VertexOnlyRenderPipelineTest : public DawnTest {
wgpu::TextureView depthStencilView;
wgpu::Texture renderTargetColor;
// Render result
const RGBA8 filled = RGBA8(0, 255, 0, 255);
const RGBA8 notFilled = RGBA8(0, 0, 0, 0);
const utils::RGBA8 filled = utils::RGBA8(0, 255, 0, 255);
const utils::RGBA8 notFilled = utils::RGBA8(0, 0, 0, 0);
// Render pass
utils::ComboRenderPassDescriptor renderPassDescNoColor{};
utils::ComboRenderPassDescriptor renderPassDescWithColor{};
@ -181,7 +181,7 @@ class VertexOnlyRenderPipelineTest : public DawnTest {
TEST_P(VertexOnlyRenderPipelineTest, Stencil) {
auto doStencilTest = [&](const wgpu::RenderPassDescriptor* renderPass,
const wgpu::RenderPipeline& pipeline,
const RGBA8& colorExpect) -> void {
const utils::RGBA8& colorExpect) -> void {
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
ClearAttachment(encoder);
@ -218,7 +218,7 @@ TEST_P(VertexOnlyRenderPipelineTest, Stencil) {
TEST_P(VertexOnlyRenderPipelineTest, Depth) {
auto doStencilTest = [&](const wgpu::RenderPassDescriptor* renderPass,
const wgpu::RenderPipeline& pipeline,
const RGBA8& colorExpect) -> void {
const utils::RGBA8& colorExpect) -> void {
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
ClearAttachment(encoder);

View File

@ -236,9 +236,9 @@ class VertexStateTest : public DawnTest {
unsigned int x = kRTCellOffset + kRTCellSize * triangle;
unsigned int y = kRTCellOffset + kRTCellSize * instance;
if (triangle < triangles && instance < instances) {
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, x, y);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, x, y);
} else {
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, x, y);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, x, y);
}
}
}
@ -642,7 +642,7 @@ TEST_P(VertexStateTest, OverlappingVertexAttributes) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 1, 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 1, 1);
}
DAWN_INSTANTIATE_TEST(VertexStateTest,
@ -688,7 +688,7 @@ TEST_P(OptionalVertexStateTest, Basic) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 1, 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 1, 1);
}
DAWN_INSTANTIATE_TEST(OptionalVertexStateTest,

View File

@ -24,10 +24,10 @@ VideoViewsTestBackend::PlatformTexture::~PlatformTexture() = default;
VideoViewsTestBackend::~VideoViewsTestBackend() = default;
constexpr std::array<RGBA8, 2> VideoViewsTests::kYellowYUVColor;
constexpr std::array<RGBA8, 2> VideoViewsTests::kWhiteYUVColor;
constexpr std::array<RGBA8, 2> VideoViewsTests::kBlueYUVColor;
constexpr std::array<RGBA8, 2> VideoViewsTests::kRedYUVColor;
constexpr std::array<utils::RGBA8, 2> VideoViewsTests::kYellowYUVColor;
constexpr std::array<utils::RGBA8, 2> VideoViewsTests::kWhiteYUVColor;
constexpr std::array<utils::RGBA8, 2> VideoViewsTests::kBlueYUVColor;
constexpr std::array<utils::RGBA8, 2> VideoViewsTests::kRedYUVColor;
void VideoViewsTests::SetUp() {
DawnTest::SetUp();
@ -390,22 +390,24 @@ TEST_P(VideoViewsTests, NV12SampleYUVtoRGB) {
queue.Submit(1, &commands);
// Test four corners of the checkerboard image (YUV color space).
RGBA8 yellowYUV(kYellowYUVColor[kYUVLumaPlaneIndex].r, kYellowYUVColor[kYUVChromaPlaneIndex].r,
kYellowYUVColor[kYUVChromaPlaneIndex].g, 0xFF);
utils::RGBA8 yellowYUV(kYellowYUVColor[kYUVLumaPlaneIndex].r,
kYellowYUVColor[kYUVChromaPlaneIndex].r,
kYellowYUVColor[kYUVChromaPlaneIndex].g, 0xFF);
EXPECT_PIXEL_RGBA8_EQ(yellowYUV, renderPass.color, 0, 0); // top left
RGBA8 redYUV(kRedYUVColor[kYUVLumaPlaneIndex].r, kRedYUVColor[kYUVChromaPlaneIndex].r,
kRedYUVColor[kYUVChromaPlaneIndex].g, 0xFF);
utils::RGBA8 redYUV(kRedYUVColor[kYUVLumaPlaneIndex].r, kRedYUVColor[kYUVChromaPlaneIndex].r,
kRedYUVColor[kYUVChromaPlaneIndex].g, 0xFF);
EXPECT_PIXEL_RGBA8_EQ(redYUV, renderPass.color, kYUVImageDataWidthInTexels - 1,
kYUVImageDataHeightInTexels - 1); // bottom right
RGBA8 blueYUV(kBlueYUVColor[kYUVLumaPlaneIndex].r, kBlueYUVColor[kYUVChromaPlaneIndex].r,
kBlueYUVColor[kYUVChromaPlaneIndex].g, 0xFF);
utils::RGBA8 blueYUV(kBlueYUVColor[kYUVLumaPlaneIndex].r, kBlueYUVColor[kYUVChromaPlaneIndex].r,
kBlueYUVColor[kYUVChromaPlaneIndex].g, 0xFF);
EXPECT_PIXEL_RGBA8_EQ(blueYUV, renderPass.color, kYUVImageDataWidthInTexels - 1,
0); // top right
RGBA8 whiteYUV(kWhiteYUVColor[kYUVLumaPlaneIndex].r, kWhiteYUVColor[kYUVChromaPlaneIndex].r,
kWhiteYUVColor[kYUVChromaPlaneIndex].g, 0xFF);
utils::RGBA8 whiteYUV(kWhiteYUVColor[kYUVLumaPlaneIndex].r,
kWhiteYUVColor[kYUVChromaPlaneIndex].r,
kWhiteYUVColor[kYUVChromaPlaneIndex].g, 0xFF);
EXPECT_PIXEL_RGBA8_EQ(whiteYUV, renderPass.color, 0,
kYUVImageDataHeightInTexels - 1); // bottom left
mBackend->DestroyVideoTextureForTest(std::move(platformTexture));

View File

@ -63,17 +63,21 @@ class VideoViewsTests : public DawnTest {
// RGB colors converted into YUV (per plane), for testing.
// RGB colors are mapped to the BT.601 definition of luma.
// https://docs.microsoft.com/en-us/windows/win32/medfound/about-yuv-video
static constexpr std::array<RGBA8, 2> kYellowYUVColor = {RGBA8{210, 0, 0, 0xFF}, // Y
RGBA8{16, 146, 0, 0xFF}}; // UV
static constexpr std::array<utils::RGBA8, 2> kYellowYUVColor = {
utils::RGBA8{210, 0, 0, 0xFF}, // Y
utils::RGBA8{16, 146, 0, 0xFF}}; // UV
static constexpr std::array<RGBA8, 2> kWhiteYUVColor = {RGBA8{235, 0, 0, 0xFF}, // Y
RGBA8{128, 128, 0, 0xFF}}; // UV
static constexpr std::array<utils::RGBA8, 2> kWhiteYUVColor = {
utils::RGBA8{235, 0, 0, 0xFF}, // Y
utils::RGBA8{128, 128, 0, 0xFF}}; // UV
static constexpr std::array<RGBA8, 2> kBlueYUVColor = {RGBA8{41, 0, 0, 0xFF}, // Y
RGBA8{240, 110, 0, 0xFF}}; // UV
static constexpr std::array<utils::RGBA8, 2> kBlueYUVColor = {
utils::RGBA8{41, 0, 0, 0xFF}, // Y
utils::RGBA8{240, 110, 0, 0xFF}}; // UV
static constexpr std::array<RGBA8, 2> kRedYUVColor = {RGBA8{81, 0, 0, 0xFF}, // Y
RGBA8{90, 240, 0, 0xFF}}; // UV
static constexpr std::array<utils::RGBA8, 2> kRedYUVColor = {
utils::RGBA8{81, 0, 0, 0xFF}, // Y
utils::RGBA8{90, 240, 0, 0xFF}}; // UV
static std::vector<uint8_t> GetTestTextureData(wgpu::TextureFormat format, bool isCheckerboard);
static uint32_t NumPlanes(wgpu::TextureFormat format);

View File

@ -52,10 +52,10 @@ TEST_P(ViewportOrientationTests, OriginAt0x0) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 1, 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, 1, 1);
}
DAWN_INSTANTIATE_TEST(ViewportOrientationTests,

View File

@ -81,9 +81,9 @@ class ViewportTest : public DawnTest {
for (uint32_t checkX = 0; checkX < kWidth; checkX++) {
for (uint32_t checkY = 0; checkY < kHeight; checkY++) {
if (checkX >= x && checkX < x + width && checkY >= y && checkY < y + height) {
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kWhite, rp.color, checkX, checkY);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kWhite, rp.color, checkX, checkY);
} else {
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, rp.color, checkX, checkY);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, rp.color, checkX, checkY);
}
}
}
@ -210,7 +210,7 @@ TEST_P(ViewportTest, EmptyViewport) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kZero, renderPass.color, 0, 0);
};
// Test with a 0x0, 0xN and nx0 viewport.

View File

@ -550,7 +550,7 @@ TEST_P(D3D12DescriptorHeapTests, EncodeUBOOverflowMultipleSubmit) {
queue.Submit(1, &commands);
}
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 0, 0);
// Encode a heap worth of descriptors.
{
@ -592,7 +592,7 @@ TEST_P(D3D12DescriptorHeapTests, EncodeUBOOverflowMultipleSubmit) {
queue.Submit(1, &commands);
}
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kRed, renderPass.color, 0, 0);
}
// Verify encoding a heaps worth of bindgroups plus one more then reuse the first
@ -653,7 +653,7 @@ TEST_P(D3D12DescriptorHeapTests, EncodeReuseUBOOverflow) {
queue.Submit(1, &commands);
// Make sure the first bindgroup was encoded correctly.
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kRed, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kRed, renderPass.color, 0, 0);
}
// Verify encoding a heaps worth of bindgroups plus one more in the first submit then reuse the
@ -735,7 +735,7 @@ TEST_P(D3D12DescriptorHeapTests, EncodeReuseUBOMultipleSubmits) {
}
// Make sure the first bindgroup was re-encoded correctly.
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderPass.color, 0, 0);
}
// Verify encoding many sampler and ubo worth of bindgroups.
@ -773,7 +773,7 @@ TEST_P(D3D12DescriptorHeapTests, EncodeManyUBOAndSamplers) {
wgpu::CommandBuffer commandBuffer = encoder.Finish();
queue.Submit(1, &commandBuffer);
RGBA8 filled(0, 255, 0, 255);
utils::RGBA8 filled(0, 255, 0, 255);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 0, 0);
}
@ -884,8 +884,8 @@ TEST_P(D3D12DescriptorHeapTests, EncodeManyUBOAndSamplers) {
queue.Submit(1, &commands);
// Final accumulated color is result of sampled + UBO color.
RGBA8 filled(255, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
utils::RGBA8 filled(255, 255, 0, 255);
utils::RGBA8 notFilled(0, 0, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(notFilled, renderPass.color, kRTSize - 1, 0);

View File

@ -322,7 +322,7 @@ TEST_P(VulkanImageWrappingUsageTests, ClearImageAcrossDevices) {
exportInfo.releasedOldLayout, exportInfo.releasedNewLayout);
// Verify |device| sees the changes from |secondDevice|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 2, 3, 4), nextWrappedTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(1, 2, 3, 4), nextWrappedTexture, 0, 0);
IgnoreSignalSemaphore(nextWrappedTexture);
}
@ -348,7 +348,7 @@ TEST_P(VulkanImageWrappingUsageTests, UninitializedTextureIsCleared) {
exportInfo.releasedOldLayout, exportInfo.releasedNewLayout, false);
// Verify |device| doesn't see the changes from |secondDevice|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), nextWrappedTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 0, 0, 0), nextWrappedTexture, 0, 0);
IgnoreSignalSemaphore(nextWrappedTexture);
}
@ -382,7 +382,7 @@ TEST_P(VulkanImageWrappingUsageTests, CopyTextureToTextureSrcSync) {
SimpleCopyTextureToTexture(device, queue, deviceWrappedTexture, copyDstTexture);
// Verify |copyDstTexture| sees changes from |secondDevice|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 2, 3, 4), copyDstTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(1, 2, 3, 4), copyDstTexture, 0, 0);
IgnoreSignalSemaphore(deviceWrappedTexture);
}
@ -433,7 +433,7 @@ TEST_P(VulkanImageWrappingUsageTests, CopyTextureToTextureDstSync) {
secondExportInfo.releasedOldLayout, secondExportInfo.releasedNewLayout);
// Verify |nextWrappedTexture| contains the color from our copy
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 2, 3, 4), nextWrappedTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(1, 2, 3, 4), nextWrappedTexture, 0, 0);
IgnoreSignalSemaphore(nextWrappedTexture);
}
@ -540,7 +540,7 @@ TEST_P(VulkanImageWrappingUsageTests, CopyBufferToTextureDstSync) {
secondExportInfo.releasedOldLayout, secondExportInfo.releasedNewLayout);
// Verify |nextWrappedTexture| contains the color from our copy
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 2, 3, 4), nextWrappedTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(1, 2, 3, 4), nextWrappedTexture, 0, 0);
IgnoreSignalSemaphore(nextWrappedTexture);
}
@ -581,10 +581,10 @@ TEST_P(VulkanImageWrappingUsageTests, DoubleTextureUsage) {
SimpleCopyTextureToTexture(device, queue, deviceWrappedTexture, secondCopyDstTexture);
// Verify |copyDstTexture| sees changes from |secondDevice|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 2, 3, 4), copyDstTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(1, 2, 3, 4), copyDstTexture, 0, 0);
// Verify |secondCopyDstTexture| sees changes from |secondDevice|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 2, 3, 4), secondCopyDstTexture, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(1, 2, 3, 4), secondCopyDstTexture, 0, 0);
IgnoreSignalSemaphore(deviceWrappedTexture);
}
@ -669,7 +669,7 @@ TEST_P(VulkanImageWrappingUsageTests, ChainTextureCopy) {
SimpleCopyTextureToTexture(device, queue, wrappedTexCDevice1, texD);
// Verify D matches clear color
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 2, 3, 4), texD, 0, 0);
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(1, 2, 3, 4), texD, 0, 0);
IgnoreSignalSemaphore(wrappedTexCDevice1);
}
@ -793,17 +793,17 @@ TEST_P(VulkanImageWrappingUsageTests, SRGBReinterpretation) {
wgpu::ImageCopyTexture dst = {};
dst.texture = texture;
std::array<RGBA8, 4> rgbaTextureData = {
RGBA8(180, 0, 0, 255),
RGBA8(0, 84, 0, 127),
RGBA8(0, 0, 62, 100),
RGBA8(62, 180, 84, 90),
std::array<utils::RGBA8, 4> rgbaTextureData = {
utils::RGBA8(180, 0, 0, 255),
utils::RGBA8(0, 84, 0, 127),
utils::RGBA8(0, 0, 62, 100),
utils::RGBA8(62, 180, 84, 90),
};
wgpu::TextureDataLayout dataLayout = {};
dataLayout.bytesPerRow = textureDesc.size.width * sizeof(RGBA8);
dataLayout.bytesPerRow = textureDesc.size.width * sizeof(utils::RGBA8);
queue.WriteTexture(&dst, rgbaTextureData.data(), rgbaTextureData.size() * sizeof(RGBA8),
queue.WriteTexture(&dst, rgbaTextureData.data(), rgbaTextureData.size() * sizeof(utils::RGBA8),
&dataLayout, &textureDesc.size);
wgpu::TextureView textureView = texture.CreateView(&viewDesc);
@ -852,18 +852,18 @@ TEST_P(VulkanImageWrappingUsageTests, SRGBReinterpretation) {
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(116, 0, 0, 255), //
RGBA8(117, 0, 0, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(0, 23, 0, 127), //
RGBA8(0, 24, 0, 127), renderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(0, 0, 12, 100), //
RGBA8(0, 0, 13, 100), renderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_BETWEEN( //
RGBA8(12, 116, 23, 90), //
RGBA8(13, 117, 24, 90), renderPass.color, 1, 1);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(116, 0, 0, 255), //
utils::RGBA8(117, 0, 0, 255), renderPass.color, 0, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(0, 23, 0, 127), //
utils::RGBA8(0, 24, 0, 127), renderPass.color, 1, 0);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(0, 0, 12, 100), //
utils::RGBA8(0, 0, 13, 100), renderPass.color, 0, 1);
EXPECT_PIXEL_RGBA8_BETWEEN( //
utils::RGBA8(12, 116, 23, 90), //
utils::RGBA8(13, 117, 24, 90), renderPass.color, 1, 1);
IgnoreSignalSemaphore(texture);
}

View File

@ -13,6 +13,7 @@
// limitations under the License.
#include <algorithm>
#include <ostream>
#include <vector>
#include "dawn/common/Assert.h"
@ -24,6 +25,19 @@
namespace utils {
const RGBA8 RGBA8::kZero = RGBA8(0, 0, 0, 0);
const RGBA8 RGBA8::kBlack = RGBA8(0, 0, 0, 255);
const RGBA8 RGBA8::kRed = RGBA8(255, 0, 0, 255);
const RGBA8 RGBA8::kGreen = RGBA8(0, 255, 0, 255);
const RGBA8 RGBA8::kBlue = RGBA8(0, 0, 255, 255);
const RGBA8 RGBA8::kYellow = RGBA8(255, 255, 0, 255);
const RGBA8 RGBA8::kWhite = RGBA8(255, 255, 255, 255);
std::ostream& operator<<(std::ostream& stream, const RGBA8& color) {
return stream << "RGBA8(" << static_cast<int>(color.r) << ", " << static_cast<int>(color.g)
<< ", " << static_cast<int>(color.b) << ", " << static_cast<int>(color.a) << ")";
}
uint32_t GetMinimumBytesPerRow(wgpu::TextureFormat format, uint32_t width) {
const uint32_t bytesPerBlock = utils::GetTexelBlockSizeInBytes(format);
const uint32_t blockWidth = utils::GetTextureFormatBlockWidth(format);

View File

@ -19,6 +19,26 @@
namespace utils {
struct RGBA8 {
constexpr RGBA8() : RGBA8(0, 0, 0, 0) {}
constexpr RGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a) : r(r), g(g), b(b), a(a) {}
bool operator==(const RGBA8& other) const;
bool operator!=(const RGBA8& other) const;
bool operator<=(const RGBA8& other) const;
bool operator>=(const RGBA8& other) const;
uint8_t r, g, b, a;
static const RGBA8 kZero;
static const RGBA8 kBlack;
static const RGBA8 kRed;
static const RGBA8 kGreen;
static const RGBA8 kBlue;
static const RGBA8 kYellow;
static const RGBA8 kWhite;
};
std::ostream& operator<<(std::ostream& stream, const RGBA8& color);
struct TextureDataCopyLayout {
uint64_t byteLength;
uint64_t texelBlockCount;