Make end2end and perf tests use webgpu.h

BUG=dawn:22

Change-Id: Ief855d294779b97283a79532e9d503aab6fda751
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/12740
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2019-10-28 13:27:36 +00:00 committed by Commit Bot service account
parent 9cf62efda9
commit cab352c2f6
46 changed files with 2659 additions and 2624 deletions

View File

@ -255,8 +255,8 @@ DawnTestBase::DawnTestBase(const DawnTestParam& param) : mParam(param) {
DawnTestBase::~DawnTestBase() { DawnTestBase::~DawnTestBase() {
// We need to destroy child objects before the Device // We need to destroy child objects before the Device
mReadbackSlots.clear(); mReadbackSlots.clear();
queue = dawn::Queue(); queue = wgpu::Queue();
device = dawn::Device(); device = wgpu::Device();
mWireClient = nullptr; mWireClient = nullptr;
mWireServer = nullptr; mWireServer = nullptr;
@ -423,7 +423,7 @@ void DawnTestBase::SetUp() {
backendProcs = dawn_native::GetProcs(); backendProcs = dawn_native::GetProcs();
// Choose whether to use the backend procs and devices directly, or set up the wire. // Choose whether to use the backend procs and devices directly, or set up the wire.
DawnDevice cDevice = nullptr; WGPUDevice cDevice = nullptr;
DawnProcTable procs; DawnProcTable procs;
if (gTestEnv->UsesWire()) { if (gTestEnv->UsesWire()) {
@ -442,7 +442,7 @@ void DawnTestBase::SetUp() {
clientDesc.serializer = mC2sBuf.get(); clientDesc.serializer = mC2sBuf.get();
mWireClient.reset(new dawn_wire::WireClient(clientDesc)); mWireClient.reset(new dawn_wire::WireClient(clientDesc));
DawnDevice clientDevice = mWireClient->GetDevice(); WGPUDevice clientDevice = mWireClient->GetDevice();
DawnProcTable clientProcs = mWireClient->GetProcs(); DawnProcTable clientProcs = mWireClient->GetProcs();
mS2cBuf->SetHandler(mWireClient.get()); mS2cBuf->SetHandler(mWireClient.get());
@ -456,7 +456,7 @@ void DawnTestBase::SetUp() {
// Set up the device and queue because all tests need them, and DawnTestBase needs them too for // Set up the device and queue because all tests need them, and DawnTestBase needs them too for
// the deferred expectations. // the deferred expectations.
dawnProcSetProcs(&procs); dawnProcSetProcs(&procs);
device = dawn::Device::Acquire(cDevice); device = wgpu::Device::Acquire(cDevice);
queue = device.CreateQueue(); queue = device.CreateQueue();
device.SetUncapturedErrorCallback(OnDeviceError, this); device.SetUncapturedErrorCallback(OnDeviceError, this);
@ -491,8 +491,8 @@ dawn_native::PCIInfo DawnTestBase::GetPCIInfo() const {
} }
// static // static
void DawnTestBase::OnDeviceError(DawnErrorType type, const char* message, void* userdata) { void DawnTestBase::OnDeviceError(WGPUErrorType type, const char* message, void* userdata) {
ASSERT(type != DAWN_ERROR_TYPE_NO_ERROR); ASSERT(type != WGPUErrorType_NoError);
DawnTestBase* self = static_cast<DawnTestBase*>(userdata); DawnTestBase* self = static_cast<DawnTestBase*>(userdata);
ASSERT_TRUE(self->mExpectError) << "Got unexpected device error: " << message; ASSERT_TRUE(self->mExpectError) << "Got unexpected device error: " << message;
@ -502,7 +502,7 @@ void DawnTestBase::OnDeviceError(DawnErrorType type, const char* message, void*
std::ostringstream& DawnTestBase::AddBufferExpectation(const char* file, std::ostringstream& DawnTestBase::AddBufferExpectation(const char* file,
int line, int line,
const dawn::Buffer& buffer, const wgpu::Buffer& buffer,
uint64_t offset, uint64_t offset,
uint64_t size, uint64_t size,
detail::Expectation* expectation) { detail::Expectation* expectation) {
@ -510,10 +510,10 @@ std::ostringstream& DawnTestBase::AddBufferExpectation(const char* file,
// We need to enqueue the copy immediately because by the time we resolve the expectation, // We need to enqueue the copy immediately because by the time we resolve the expectation,
// the buffer might have been modified. // the buffer might have been modified.
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToBuffer(buffer, offset, readback.buffer, readback.offset, size); encoder.CopyBufferToBuffer(buffer, offset, readback.buffer, readback.offset, size);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
DeferredExpectation deferred; DeferredExpectation deferred;
@ -533,7 +533,7 @@ std::ostringstream& DawnTestBase::AddBufferExpectation(const char* file,
std::ostringstream& DawnTestBase::AddTextureExpectation(const char* file, std::ostringstream& DawnTestBase::AddTextureExpectation(const char* file,
int line, int line,
const dawn::Texture& texture, const wgpu::Texture& texture,
uint32_t x, uint32_t x,
uint32_t y, uint32_t y,
uint32_t width, uint32_t width,
@ -549,16 +549,16 @@ std::ostringstream& DawnTestBase::AddTextureExpectation(const char* file,
// We need to enqueue the copy immediately because by the time we resolve the expectation, // We need to enqueue the copy immediately because by the time we resolve the expectation,
// the texture might have been modified. // the texture might have been modified.
dawn::TextureCopyView textureCopyView = wgpu::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(texture, level, slice, {x, y, 0}); utils::CreateTextureCopyView(texture, level, slice, {x, y, 0});
dawn::BufferCopyView bufferCopyView = wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(readback.buffer, readback.offset, rowPitch, 0); utils::CreateBufferCopyView(readback.buffer, readback.offset, rowPitch, 0);
dawn::Extent3D copySize = {width, height, 1}; wgpu::Extent3D copySize = {width, height, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize); encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
DeferredExpectation deferred; DeferredExpectation deferred;
@ -595,9 +595,9 @@ void DawnTestBase::FlushWire() {
DawnTestBase::ReadbackReservation DawnTestBase::ReserveReadback(uint64_t readbackSize) { DawnTestBase::ReadbackReservation DawnTestBase::ReserveReadback(uint64_t readbackSize) {
// For now create a new MapRead buffer for each readback // For now create a new MapRead buffer for each readback
// TODO(cwallez@chromium.org): eventually make bigger buffers and allocate linearly? // TODO(cwallez@chromium.org): eventually make bigger buffers and allocate linearly?
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.size = readbackSize; descriptor.size = readbackSize;
descriptor.usage = dawn::BufferUsage::MapRead | dawn::BufferUsage::CopyDst; descriptor.usage = wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst;
ReadbackSlot slot; ReadbackSlot slot;
slot.bufferSize = readbackSize; slot.bufferSize = readbackSize;
@ -632,11 +632,11 @@ void DawnTestBase::MapSlotsSynchronously() {
} }
// static // static
void DawnTestBase::SlotMapReadCallback(DawnBufferMapAsyncStatus status, void DawnTestBase::SlotMapReadCallback(WGPUBufferMapAsyncStatus status,
const void* data, const void* data,
uint64_t, uint64_t,
void* userdata_) { void* userdata_) {
DAWN_ASSERT(status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS); DAWN_ASSERT(status == WGPUBufferMapAsyncStatus_Success);
auto userdata = static_cast<MapReadUserdata*>(userdata_); auto userdata = static_cast<MapReadUserdata*>(userdata_);
userdata->test->mReadbackSlots[userdata->slot].mappedData = data; userdata->test->mReadbackSlots[userdata->slot].mappedData = data;

View File

@ -16,7 +16,7 @@
#define TESTS_DAWNTEST_H_ #define TESTS_DAWNTEST_H_
#include "dawn/dawn_proc_table.h" #include "dawn/dawn_proc_table.h"
#include "dawn/dawncpp.h" #include "dawn/webgpu_cpp.h"
#include "dawn_native/DawnNative.h" #include "dawn_native/DawnNative.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
@ -180,22 +180,22 @@ class DawnTestBase {
dawn_native::PCIInfo GetPCIInfo() const; dawn_native::PCIInfo GetPCIInfo() const;
protected: protected:
dawn::Device device; wgpu::Device device;
dawn::Queue queue; wgpu::Queue queue;
DawnProcTable backendProcs = {}; DawnProcTable backendProcs = {};
DawnDevice backendDevice = nullptr; WGPUDevice backendDevice = nullptr;
// Helper methods to implement the EXPECT_ macros // Helper methods to implement the EXPECT_ macros
std::ostringstream& AddBufferExpectation(const char* file, std::ostringstream& AddBufferExpectation(const char* file,
int line, int line,
const dawn::Buffer& buffer, const wgpu::Buffer& buffer,
uint64_t offset, uint64_t offset,
uint64_t size, uint64_t size,
detail::Expectation* expectation); detail::Expectation* expectation);
std::ostringstream& AddTextureExpectation(const char* file, std::ostringstream& AddTextureExpectation(const char* file,
int line, int line,
const dawn::Texture& texture, const wgpu::Texture& texture,
uint32_t x, uint32_t x,
uint32_t y, uint32_t y,
uint32_t width, uint32_t width,
@ -227,13 +227,13 @@ class DawnTestBase {
std::unique_ptr<utils::TerribleCommandBuffer> mS2cBuf; std::unique_ptr<utils::TerribleCommandBuffer> mS2cBuf;
// Tracking for validation errors // Tracking for validation errors
static void OnDeviceError(DawnErrorType type, const char* message, void* userdata); static void OnDeviceError(WGPUErrorType type, const char* message, void* userdata);
bool mExpectError = false; bool mExpectError = false;
bool mError = false; bool mError = false;
// MapRead buffers used to get data for the expectations // MapRead buffers used to get data for the expectations
struct ReadbackSlot { struct ReadbackSlot {
dawn::Buffer buffer; wgpu::Buffer buffer;
uint64_t bufferSize; uint64_t bufferSize;
const void* mappedData = nullptr; const void* mappedData = nullptr;
}; };
@ -241,7 +241,7 @@ class DawnTestBase {
// Maps all the buffers and fill ReadbackSlot::mappedData // Maps all the buffers and fill ReadbackSlot::mappedData
void MapSlotsSynchronously(); void MapSlotsSynchronously();
static void SlotMapReadCallback(DawnBufferMapAsyncStatus status, static void SlotMapReadCallback(WGPUBufferMapAsyncStatus status,
const void* data, const void* data,
uint64_t dataLength, uint64_t dataLength,
void* userdata); void* userdata);
@ -249,7 +249,7 @@ class DawnTestBase {
// Reserve space where the data for an expectation can be copied // Reserve space where the data for an expectation can be copied
struct ReadbackReservation { struct ReadbackReservation {
dawn::Buffer buffer; wgpu::Buffer buffer;
size_t slot; size_t slot;
uint64_t offset; uint64_t offset;
}; };

View File

@ -29,10 +29,10 @@ TEST_P(BasicTests, VendorIdFilter) {
// Test Buffer::SetSubData changes the content of the buffer, but really this is the most // Test Buffer::SetSubData changes the content of the buffer, but really this is the most
// basic test possible, and tests the test harness // basic test possible, and tests the test harness
TEST_P(BasicTests, BufferSetSubData) { TEST_P(BasicTests, BufferSetSubData) {
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.size = 4; descriptor.size = 4;
descriptor.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst; descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&descriptor); wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
uint32_t value = 0x01020304; uint32_t value = 0x01020304;
buffer.SetSubData(0, sizeof(value), &value); buffer.SetSubData(0, sizeof(value), &value);
@ -43,10 +43,10 @@ TEST_P(BasicTests, BufferSetSubData) {
// Test a validation error for buffer setSubData, but really this is the most basic test possible // Test a validation error for buffer setSubData, but really this is the most basic test possible
// for ASSERT_DEVICE_ERROR // for ASSERT_DEVICE_ERROR
TEST_P(BasicTests, BufferSetSubDataError) { TEST_P(BasicTests, BufferSetSubDataError) {
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.size = 4; descriptor.size = 4;
descriptor.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst; descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&descriptor); wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
uint8_t value = 187; uint8_t value = 187;
ASSERT_DEVICE_ERROR(buffer.SetSubData(1000, sizeof(value), &value)); ASSERT_DEVICE_ERROR(buffer.SetSubData(1000, sizeof(value), &value));

View File

@ -23,10 +23,10 @@ constexpr static unsigned int kRTSize = 8;
class BindGroupTests : public DawnTest { class BindGroupTests : public DawnTest {
protected: protected:
dawn::CommandBuffer CreateSimpleComputeCommandBuffer( wgpu::CommandBuffer CreateSimpleComputeCommandBuffer(const wgpu::ComputePipeline& pipeline,
const dawn::ComputePipeline& pipeline, const dawn::BindGroup& bindGroup) { const wgpu::BindGroup& bindGroup) {
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder pass = encoder.BeginComputePass(); wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.Dispatch(1, 1, 1); pass.Dispatch(1, 1, 1);
@ -34,10 +34,10 @@ protected:
return encoder.Finish(); return encoder.Finish();
} }
dawn::PipelineLayout MakeBasicPipelineLayout( wgpu::PipelineLayout MakeBasicPipelineLayout(
dawn::Device device, wgpu::Device device,
std::vector<dawn::BindGroupLayout> bindingInitializer) const { std::vector<wgpu::BindGroupLayout> bindingInitializer) const {
dawn::PipelineLayoutDescriptor descriptor; wgpu::PipelineLayoutDescriptor descriptor;
descriptor.bindGroupLayoutCount = bindingInitializer.size(); descriptor.bindGroupLayoutCount = bindingInitializer.size();
descriptor.bindGroupLayouts = bindingInitializer.data(); descriptor.bindGroupLayouts = bindingInitializer.data();
@ -45,7 +45,7 @@ protected:
return device.CreatePipelineLayout(&descriptor); return device.CreatePipelineLayout(&descriptor);
} }
dawn::ShaderModule MakeSimpleVSModule() const { wgpu::ShaderModule MakeSimpleVSModule() const {
return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
void main() { void main() {
@ -54,7 +54,7 @@ protected:
})"); })");
} }
dawn::ShaderModule MakeFSModule(std::vector<dawn::BindingType> bindingTypes) const { wgpu::ShaderModule MakeFSModule(std::vector<wgpu::BindingType> bindingTypes) const {
ASSERT(bindingTypes.size() <= kMaxBindGroups); ASSERT(bindingTypes.size() <= kMaxBindGroups);
std::ostringstream fs; std::ostringstream fs;
@ -65,15 +65,19 @@ protected:
for (size_t i = 0; i < bindingTypes.size(); ++i) { for (size_t i = 0; i < bindingTypes.size(); ++i) {
switch (bindingTypes[i]) { switch (bindingTypes[i]) {
case dawn::BindingType::UniformBuffer: case wgpu::BindingType::UniformBuffer:
fs << "layout (std140, set = " << i << ", binding = 0) uniform UniformBuffer" << i << R"( { fs << "layout (std140, set = " << i << ", binding = 0) uniform UniformBuffer" << i
<< R"( {
vec4 color; vec4 color;
} buffer)" << i << ";\n"; } buffer)"
<< i << ";\n";
break; break;
case dawn::BindingType::StorageBuffer: case wgpu::BindingType::StorageBuffer:
fs << "layout (std430, set = " << i << ", binding = 0) buffer StorageBuffer" << i << R"( { fs << "layout (std430, set = " << i << ", binding = 0) buffer StorageBuffer" << i
<< R"( {
vec4 color; vec4 color;
} buffer)" << i << ";\n"; } buffer)"
<< i << ";\n";
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -89,27 +93,26 @@ protected:
} }
fs << "}\n"; fs << "}\n";
return utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs.str().c_str()); return utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment,
fs.str().c_str());
} }
dawn::RenderPipeline MakeTestPipeline( wgpu::RenderPipeline MakeTestPipeline(const utils::BasicRenderPass& renderPass,
const utils::BasicRenderPass& renderPass, std::vector<wgpu::BindingType> bindingTypes,
std::vector<dawn::BindingType> bindingTypes, std::vector<wgpu::BindGroupLayout> bindGroupLayouts) {
std::vector<dawn::BindGroupLayout> bindGroupLayouts) { wgpu::ShaderModule vsModule = MakeSimpleVSModule();
wgpu::ShaderModule fsModule = MakeFSModule(bindingTypes);
dawn::ShaderModule vsModule = MakeSimpleVSModule(); wgpu::PipelineLayout pipelineLayout = MakeBasicPipelineLayout(device, bindGroupLayouts);
dawn::ShaderModule fsModule = MakeFSModule(bindingTypes);
dawn::PipelineLayout pipelineLayout = MakeBasicPipelineLayout(device, bindGroupLayouts);
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device); utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
pipelineDescriptor.layout = pipelineLayout; pipelineDescriptor.layout = pipelineLayout;
pipelineDescriptor.vertexStage.module = vsModule; pipelineDescriptor.vertexStage.module = vsModule;
pipelineDescriptor.cFragmentStage.module = fsModule; pipelineDescriptor.cFragmentStage.module = fsModule;
pipelineDescriptor.cColorStates[0].format = renderPass.colorFormat; pipelineDescriptor.cColorStates[0].format = renderPass.colorFormat;
pipelineDescriptor.cColorStates[0].colorBlend.operation = dawn::BlendOperation::Add; pipelineDescriptor.cColorStates[0].colorBlend.operation = wgpu::BlendOperation::Add;
pipelineDescriptor.cColorStates[0].colorBlend.srcFactor = dawn::BlendFactor::One; pipelineDescriptor.cColorStates[0].colorBlend.srcFactor = wgpu::BlendFactor::One;
pipelineDescriptor.cColorStates[0].colorBlend.dstFactor = dawn::BlendFactor::One; pipelineDescriptor.cColorStates[0].colorBlend.dstFactor = wgpu::BlendFactor::One;
return device.CreateRenderPipeline(&pipelineDescriptor); return device.CreateRenderPipeline(&pipelineDescriptor);
} }
@ -118,11 +121,11 @@ protected:
// Test a bindgroup reused in two command buffers in the same call to queue.Submit(). // Test a bindgroup reused in two command buffers in the same call to queue.Submit().
// This test passes by not asserting or crashing. // This test passes by not asserting or crashing.
TEST_P(BindGroupTests, ReusedBindGroupSingleSubmit) { TEST_P(BindGroupTests, ReusedBindGroupSingleSubmit) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, { device, {
{0, dawn::ShaderStage::Compute, dawn::BindingType::UniformBuffer}, {0, wgpu::ShaderStage::Compute, wgpu::BindingType::UniformBuffer},
}); });
dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
const char* shader = R"( const char* shader = R"(
#version 450 #version 450
@ -133,22 +136,22 @@ TEST_P(BindGroupTests, ReusedBindGroupSingleSubmit) {
} }
)"; )";
dawn::ShaderModule module = wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, shader); utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, shader);
dawn::ComputePipelineDescriptor cpDesc; wgpu::ComputePipelineDescriptor cpDesc;
cpDesc.layout = pl; cpDesc.layout = pl;
cpDesc.computeStage.module = module; cpDesc.computeStage.module = module;
cpDesc.computeStage.entryPoint = "main"; cpDesc.computeStage.entryPoint = "main";
dawn::ComputePipeline cp = device.CreateComputePipeline(&cpDesc); wgpu::ComputePipeline cp = device.CreateComputePipeline(&cpDesc);
dawn::BufferDescriptor bufferDesc; wgpu::BufferDescriptor bufferDesc;
bufferDesc.size = sizeof(float); bufferDesc.size = sizeof(float);
bufferDesc.usage = dawn::BufferUsage::CopyDst | dawn::BufferUsage::Uniform; bufferDesc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::Uniform;
dawn::Buffer buffer = device.CreateBuffer(&bufferDesc); wgpu::Buffer buffer = device.CreateBuffer(&bufferDesc);
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, bgl, {{0, buffer, 0, sizeof(float)}}); wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, bgl, {{0, buffer, 0, sizeof(float)}});
dawn::CommandBuffer cb[2]; wgpu::CommandBuffer cb[2];
cb[0] = CreateSimpleComputeCommandBuffer(cp, bindGroup); cb[0] = CreateSimpleComputeCommandBuffer(cp, bindGroup);
cb[1] = CreateSimpleComputeCommandBuffer(cp, bindGroup); cb[1] = CreateSimpleComputeCommandBuffer(cp, bindGroup);
queue.Submit(2, cb); queue.Submit(2, cb);
@ -160,7 +163,7 @@ TEST_P(BindGroupTests, ReusedBindGroupSingleSubmit) {
TEST_P(BindGroupTests, ReusedUBO) { TEST_P(BindGroupTests, ReusedUBO) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
layout (set = 0, binding = 0) uniform vertexUniformBuffer { layout (set = 0, binding = 0) uniform vertexUniformBuffer {
@ -171,7 +174,7 @@ TEST_P(BindGroupTests, ReusedUBO) {
gl_Position = vec4(transform * pos[gl_VertexIndex], 0.f, 1.f); gl_Position = vec4(transform * pos[gl_VertexIndex], 0.f, 1.f);
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout (set = 0, binding = 1) uniform fragmentUniformBuffer { layout (set = 0, binding = 1) uniform fragmentUniformBuffer {
@ -182,12 +185,12 @@ TEST_P(BindGroupTests, ReusedUBO) {
fragColor = color; fragColor = color;
})"); })");
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, { device, {
{0, dawn::ShaderStage::Vertex, dawn::BindingType::UniformBuffer}, {0, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}, {1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer},
}); });
dawn::PipelineLayout pipelineLayout = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout pipelineLayout = utils::MakeBasicPipelineLayout(device, &bgl);
utils::ComboRenderPipelineDescriptor textureDescriptor(device); utils::ComboRenderPipelineDescriptor textureDescriptor(device);
textureDescriptor.layout = pipelineLayout; textureDescriptor.layout = pipelineLayout;
@ -195,7 +198,7 @@ TEST_P(BindGroupTests, ReusedUBO) {
textureDescriptor.cFragmentStage.module = fsModule; textureDescriptor.cFragmentStage.module = fsModule;
textureDescriptor.cColorStates[0].format = renderPass.colorFormat; textureDescriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&textureDescriptor); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&textureDescriptor);
struct Data { struct Data {
float transform[8]; float transform[8];
@ -209,21 +212,20 @@ TEST_P(BindGroupTests, ReusedUBO) {
{ 0 }, { 0 },
{ 0.f, 1.f, 0.f, 1.f }, { 0.f, 1.f, 0.f, 1.f },
}; };
dawn::Buffer buffer = wgpu::Buffer buffer =
utils::CreateBufferFromData(device, &data, sizeof(data), dawn::BufferUsage::Uniform); utils::CreateBufferFromData(device, &data, sizeof(data), wgpu::BufferUsage::Uniform);
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, bgl, { wgpu::BindGroup bindGroup = utils::MakeBindGroup(
{0, buffer, 0, sizeof(Data::transform)}, device, bgl,
{1, buffer, 256, sizeof(Data::color)} {{0, buffer, 0, sizeof(Data::transform)}, {1, buffer, 256, sizeof(Data::color)}});
});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.Draw(3, 1, 0, 0); pass.Draw(3, 1, 0, 0);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
RGBA8 filled(0, 255, 0, 255); RGBA8 filled(0, 255, 0, 255);
@ -241,7 +243,7 @@ TEST_P(BindGroupTests, ReusedUBO) {
TEST_P(BindGroupTests, UBOSamplerAndTexture) { TEST_P(BindGroupTests, UBOSamplerAndTexture) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
layout (set = 0, binding = 0) uniform vertexUniformBuffer { layout (set = 0, binding = 0) uniform vertexUniformBuffer {
@ -252,7 +254,7 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) {
gl_Position = vec4(transform * pos[gl_VertexIndex], 0.f, 1.f); gl_Position = vec4(transform * pos[gl_VertexIndex], 0.f, 1.f);
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout (set = 0, binding = 1) uniform sampler samp; layout (set = 0, binding = 1) uniform sampler samp;
@ -262,13 +264,13 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) {
fragColor = texture(sampler2D(tex, samp), gl_FragCoord.xy); fragColor = texture(sampler2D(tex, samp), gl_FragCoord.xy);
})"); })");
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, { device, {
{0, dawn::ShaderStage::Vertex, dawn::BindingType::UniformBuffer}, {0, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::Sampler}, {1, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler},
{2, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture}, {2, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture},
}); });
dawn::PipelineLayout pipelineLayout = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout pipelineLayout = utils::MakeBasicPipelineLayout(device, &bgl);
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device); utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
pipelineDescriptor.layout = pipelineLayout; pipelineDescriptor.layout = pipelineLayout;
@ -276,38 +278,38 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) {
pipelineDescriptor.cFragmentStage.module = fsModule; pipelineDescriptor.cFragmentStage.module = fsModule;
pipelineDescriptor.cColorStates[0].format = renderPass.colorFormat; pipelineDescriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&pipelineDescriptor); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&pipelineDescriptor);
constexpr float dummy = 0.0f; constexpr float dummy = 0.0f;
constexpr float transform[] = { 1.f, 0.f, dummy, dummy, 0.f, 1.f, dummy, dummy }; constexpr float transform[] = { 1.f, 0.f, dummy, dummy, 0.f, 1.f, dummy, dummy };
dawn::Buffer buffer = utils::CreateBufferFromData(device, &transform, sizeof(transform), wgpu::Buffer buffer = utils::CreateBufferFromData(device, &transform, sizeof(transform),
dawn::BufferUsage::Uniform); wgpu::BufferUsage::Uniform);
dawn::SamplerDescriptor samplerDescriptor; wgpu::SamplerDescriptor samplerDescriptor;
samplerDescriptor.minFilter = dawn::FilterMode::Nearest; samplerDescriptor.minFilter = wgpu::FilterMode::Nearest;
samplerDescriptor.magFilter = dawn::FilterMode::Nearest; samplerDescriptor.magFilter = wgpu::FilterMode::Nearest;
samplerDescriptor.mipmapFilter = dawn::FilterMode::Nearest; samplerDescriptor.mipmapFilter = wgpu::FilterMode::Nearest;
samplerDescriptor.addressModeU = dawn::AddressMode::ClampToEdge; samplerDescriptor.addressModeU = wgpu::AddressMode::ClampToEdge;
samplerDescriptor.addressModeV = dawn::AddressMode::ClampToEdge; samplerDescriptor.addressModeV = wgpu::AddressMode::ClampToEdge;
samplerDescriptor.addressModeW = dawn::AddressMode::ClampToEdge; samplerDescriptor.addressModeW = wgpu::AddressMode::ClampToEdge;
samplerDescriptor.lodMinClamp = kLodMin; samplerDescriptor.lodMinClamp = kLodMin;
samplerDescriptor.lodMaxClamp = kLodMax; samplerDescriptor.lodMaxClamp = kLodMax;
samplerDescriptor.compare = dawn::CompareFunction::Never; samplerDescriptor.compare = wgpu::CompareFunction::Never;
dawn::Sampler sampler = device.CreateSampler(&samplerDescriptor); wgpu::Sampler sampler = device.CreateSampler(&samplerDescriptor);
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kRTSize; descriptor.size.width = kRTSize;
descriptor.size.height = kRTSize; descriptor.size.height = kRTSize;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1; descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm; descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::CopyDst | dawn::TextureUsage::Sampled; descriptor.usage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled;
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
dawn::TextureView textureView = texture.CreateView(); wgpu::TextureView textureView = texture.CreateView();
int width = kRTSize, height = kRTSize; int width = kRTSize, height = kRTSize;
int widthInBytes = width * sizeof(RGBA8); int widthInBytes = width * sizeof(RGBA8);
@ -318,28 +320,25 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
data[i] = RGBA8(0, 255, 0, 255); data[i] = RGBA8(0, 255, 0, 255);
} }
dawn::Buffer stagingBuffer = wgpu::Buffer stagingBuffer =
utils::CreateBufferFromData(device, data.data(), sizeInBytes, dawn::BufferUsage::CopySrc); utils::CreateBufferFromData(device, data.data(), sizeInBytes, wgpu::BufferUsage::CopySrc);
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, bgl, { wgpu::BindGroup bindGroup = utils::MakeBindGroup(
{0, buffer, 0, sizeof(transform)}, device, bgl, {{0, buffer, 0, sizeof(transform)}, {1, sampler}, {2, textureView}});
{1, sampler},
{2, textureView}
});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::BufferCopyView bufferCopyView = wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(stagingBuffer, 0, widthInBytes, 0); utils::CreateBufferCopyView(stagingBuffer, 0, widthInBytes, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {width, height, 1}; wgpu::Extent3D copySize = {width, height, 1};
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize); encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.Draw(3, 1, 0, 0); pass.Draw(3, 1, 0, 0);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
RGBA8 filled(0, 255, 0, 255); RGBA8 filled(0, 255, 0, 255);
@ -358,7 +357,7 @@ TEST_P(BindGroupTests, MultipleBindLayouts) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
layout (set = 0, binding = 0) uniform vertexUniformBuffer1 { layout (set = 0, binding = 0) uniform vertexUniformBuffer1 {
@ -372,7 +371,7 @@ TEST_P(BindGroupTests, MultipleBindLayouts) {
gl_Position = vec4((transform1 + transform2) * pos[gl_VertexIndex], 0.f, 1.f); gl_Position = vec4((transform1 + transform2) * pos[gl_VertexIndex], 0.f, 1.f);
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout (set = 0, binding = 1) uniform fragmentUniformBuffer1 { layout (set = 0, binding = 1) uniform fragmentUniformBuffer1 {
@ -386,13 +385,13 @@ TEST_P(BindGroupTests, MultipleBindLayouts) {
fragColor = color1 + color2; fragColor = color1 + color2;
})"); })");
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(
device, { device, {
{0, dawn::ShaderStage::Vertex, dawn::BindingType::UniformBuffer}, {0, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}, {1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer},
}); });
dawn::PipelineLayout pipelineLayout = MakeBasicPipelineLayout(device, {layout, layout}); wgpu::PipelineLayout pipelineLayout = MakeBasicPipelineLayout(device, {layout, layout});
utils::ComboRenderPipelineDescriptor textureDescriptor(device); utils::ComboRenderPipelineDescriptor textureDescriptor(device);
textureDescriptor.layout = pipelineLayout; textureDescriptor.layout = pipelineLayout;
@ -400,7 +399,7 @@ TEST_P(BindGroupTests, MultipleBindLayouts) {
textureDescriptor.cFragmentStage.module = fsModule; textureDescriptor.cFragmentStage.module = fsModule;
textureDescriptor.cColorStates[0].format = renderPass.colorFormat; textureDescriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&textureDescriptor); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&textureDescriptor);
struct Data { struct Data {
float transform[8]; float transform[8];
@ -410,8 +409,8 @@ TEST_P(BindGroupTests, MultipleBindLayouts) {
ASSERT(offsetof(Data, color) == 256); ASSERT(offsetof(Data, color) == 256);
std::vector<Data> data; std::vector<Data> data;
std::vector<dawn::Buffer> buffers; std::vector<wgpu::Buffer> buffers;
std::vector<dawn::BindGroup> bindGroups; std::vector<wgpu::BindGroup> bindGroups;
data.push_back( data.push_back(
{{1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, {0}, {0.0f, 1.0f, 0.0f, 1.0f}}); {{1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, {0}, {0.0f, 1.0f, 0.0f, 1.0f}});
@ -420,23 +419,23 @@ TEST_P(BindGroupTests, MultipleBindLayouts) {
{{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, {0}, {1.0f, 0.0f, 0.0f, 1.0f}}); {{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, {0}, {1.0f, 0.0f, 0.0f, 1.0f}});
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
dawn::Buffer buffer = wgpu::Buffer buffer =
utils::CreateBufferFromData(device, &data[i], sizeof(Data), dawn::BufferUsage::Uniform); utils::CreateBufferFromData(device, &data[i], sizeof(Data), wgpu::BufferUsage::Uniform);
buffers.push_back(buffer); buffers.push_back(buffer);
bindGroups.push_back(utils::MakeBindGroup(device, layout, bindGroups.push_back(utils::MakeBindGroup(device, layout,
{{0, buffers[i], 0, sizeof(Data::transform)}, {{0, buffers[i], 0, sizeof(Data::transform)},
{1, buffers[i], 256, sizeof(Data::color)}})); {1, buffers[i], 256, sizeof(Data::color)}}));
} }
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroups[0]); pass.SetBindGroup(0, bindGroups[0]);
pass.SetBindGroup(1, bindGroups[1]); pass.SetBindGroup(1, bindGroups[1]);
pass.Draw(3, 1, 0, 0); pass.Draw(3, 1, 0, 0);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
RGBA8 filled(255, 255, 0, 255); RGBA8 filled(255, 255, 0, 255);
@ -453,24 +452,24 @@ TEST_P(BindGroupTests, MultipleBindLayouts) {
TEST_P(BindGroupTests, DrawTwiceInSamePipelineWithFourBindGroupSets) { TEST_P(BindGroupTests, DrawTwiceInSamePipelineWithFourBindGroupSets) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}}); device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}});
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
MakeTestPipeline(renderPass, MakeTestPipeline(renderPass,
{dawn::BindingType::UniformBuffer, dawn::BindingType::UniformBuffer, {wgpu::BindingType::UniformBuffer, wgpu::BindingType::UniformBuffer,
dawn::BindingType::UniformBuffer, dawn::BindingType::UniformBuffer}, wgpu::BindingType::UniformBuffer, wgpu::BindingType::UniformBuffer},
{layout, layout, layout, layout}); {layout, layout, layout, layout});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
std::array<float, 4> color = {0.25, 0, 0, 0.25}; std::array<float, 4> color = {0.25, 0, 0, 0.25};
dawn::Buffer uniformBuffer = wgpu::Buffer uniformBuffer =
utils::CreateBufferFromData(device, &color, sizeof(color), dawn::BufferUsage::Uniform); utils::CreateBufferFromData(device, &color, sizeof(color), wgpu::BufferUsage::Uniform);
dawn::BindGroup bindGroup = wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, layout, {{0, uniformBuffer, 0, sizeof(color)}}); utils::MakeBindGroup(device, layout, {{0, uniformBuffer, 0, sizeof(color)}});
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
@ -483,7 +482,7 @@ TEST_P(BindGroupTests, DrawTwiceInSamePipelineWithFourBindGroupSets) {
pass.Draw(3, 1, 0, 0); pass.Draw(3, 1, 0, 0);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
RGBA8 filled(255, 0, 0, 255); RGBA8 filled(255, 0, 0, 255);
@ -500,21 +499,21 @@ TEST_P(BindGroupTests, SetBindGroupBeforePipeline) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
// Create a bind group layout which uses a single uniform buffer. // Create a bind group layout which uses a single uniform buffer.
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}}); device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}});
// Create a pipeline that uses the uniform bind group layout. // Create a pipeline that uses the uniform bind group layout.
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
MakeTestPipeline(renderPass, {dawn::BindingType::UniformBuffer}, {layout}); MakeTestPipeline(renderPass, {wgpu::BindingType::UniformBuffer}, {layout});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
// Create a bind group with a uniform buffer and fill it with RGBAunorm(1, 0, 0, 1). // Create a bind group with a uniform buffer and fill it with RGBAunorm(1, 0, 0, 1).
std::array<float, 4> color = {1, 0, 0, 1}; std::array<float, 4> color = {1, 0, 0, 1};
dawn::Buffer uniformBuffer = wgpu::Buffer uniformBuffer =
utils::CreateBufferFromData(device, &color, sizeof(color), dawn::BufferUsage::Uniform); utils::CreateBufferFromData(device, &color, sizeof(color), wgpu::BufferUsage::Uniform);
dawn::BindGroup bindGroup = wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, layout, {{0, uniformBuffer, 0, sizeof(color)}}); utils::MakeBindGroup(device, layout, {{0, uniformBuffer, 0, sizeof(color)}});
// Set the bind group, then the pipeline, and draw. // Set the bind group, then the pipeline, and draw.
@ -524,7 +523,7 @@ TEST_P(BindGroupTests, SetBindGroupBeforePipeline) {
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
// The result should be red. // The result should be red.
@ -542,12 +541,12 @@ TEST_P(BindGroupTests, SetDynamicBindGroupBeforePipeline) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
// Create a bind group layout which uses a single dynamic uniform buffer. // Create a bind group layout which uses a single dynamic uniform buffer.
dawn::BindGroupLayout layout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer, true}}); device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer, true}});
// Create a pipeline that uses the dynamic uniform bind group layout for two bind groups. // Create a pipeline that uses the dynamic uniform bind group layout for two bind groups.
dawn::RenderPipeline pipeline = MakeTestPipeline( wgpu::RenderPipeline pipeline = MakeTestPipeline(
renderPass, {dawn::BindingType::UniformBuffer, dawn::BindingType::UniformBuffer}, renderPass, {wgpu::BindingType::UniformBuffer, wgpu::BindingType::UniformBuffer},
{layout, layout}); {layout, layout});
// Prepare data RGBAunorm(1, 0, 0, 0.5) and RGBAunorm(0, 1, 0, 0.5). They will be added in the // Prepare data RGBAunorm(1, 0, 0, 0.5) and RGBAunorm(0, 1, 0, 0.5). They will be added in the
@ -563,13 +562,13 @@ TEST_P(BindGroupTests, SetDynamicBindGroupBeforePipeline) {
// Create a bind group and uniform buffer with the color data. It will be bound at the offset // Create a bind group and uniform buffer with the color data. It will be bound at the offset
// to each color. // to each color.
dawn::Buffer uniformBuffer = wgpu::Buffer uniformBuffer =
utils::CreateBufferFromData(device, data.data(), data.size(), dawn::BufferUsage::Uniform); utils::CreateBufferFromData(device, data.data(), data.size(), wgpu::BufferUsage::Uniform);
dawn::BindGroup bindGroup = wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, layout, {{0, uniformBuffer, 0, 4 * sizeof(float)}}); utils::MakeBindGroup(device, layout, {{0, uniformBuffer, 0, 4 * sizeof(float)}});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
// Set the first dynamic bind group. // Set the first dynamic bind group.
uint64_t dynamicOffset = 0; uint64_t dynamicOffset = 0;
@ -585,7 +584,7 @@ TEST_P(BindGroupTests, SetDynamicBindGroupBeforePipeline) {
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
// The result should be RGBAunorm(1, 0, 0, 0.5) + RGBAunorm(0, 1, 0, 0.5) // The result should be RGBAunorm(1, 0, 0, 0.5) + RGBAunorm(0, 1, 0, 0.5)
@ -603,21 +602,21 @@ TEST_P(BindGroupTests, BindGroupsPersistAfterPipelineChange) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
// Create a bind group layout which uses a single dynamic uniform buffer. // Create a bind group layout which uses a single dynamic uniform buffer.
dawn::BindGroupLayout uniformLayout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout uniformLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer, true}}); device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer, true}});
// Create a bind group layout which uses a single dynamic storage buffer. // Create a bind group layout which uses a single dynamic storage buffer.
dawn::BindGroupLayout storageLayout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout storageLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::StorageBuffer, true}}); device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::StorageBuffer, true}});
// Create a pipeline which uses the uniform buffer and storage buffer bind groups. // Create a pipeline which uses the uniform buffer and storage buffer bind groups.
dawn::RenderPipeline pipeline0 = MakeTestPipeline( wgpu::RenderPipeline pipeline0 = MakeTestPipeline(
renderPass, {dawn::BindingType::UniformBuffer, dawn::BindingType::StorageBuffer}, renderPass, {wgpu::BindingType::UniformBuffer, wgpu::BindingType::StorageBuffer},
{uniformLayout, storageLayout}); {uniformLayout, storageLayout});
// Create a pipeline which uses the uniform buffer bind group twice. // Create a pipeline which uses the uniform buffer bind group twice.
dawn::RenderPipeline pipeline1 = MakeTestPipeline( wgpu::RenderPipeline pipeline1 = MakeTestPipeline(
renderPass, {dawn::BindingType::UniformBuffer, dawn::BindingType::UniformBuffer}, renderPass, {wgpu::BindingType::UniformBuffer, wgpu::BindingType::UniformBuffer},
{uniformLayout, uniformLayout}); {uniformLayout, uniformLayout});
// Prepare data RGBAunorm(1, 0, 0, 0.5) and RGBAunorm(0, 1, 0, 0.5). They will be added in the // Prepare data RGBAunorm(1, 0, 0, 0.5) and RGBAunorm(0, 1, 0, 0.5). They will be added in the
@ -633,13 +632,13 @@ TEST_P(BindGroupTests, BindGroupsPersistAfterPipelineChange) {
// Create a bind group and uniform buffer with the color data. It will be bound at the offset // Create a bind group and uniform buffer with the color data. It will be bound at the offset
// to each color. // to each color.
dawn::Buffer uniformBuffer = wgpu::Buffer uniformBuffer =
utils::CreateBufferFromData(device, data.data(), data.size(), dawn::BufferUsage::Uniform); utils::CreateBufferFromData(device, data.data(), data.size(), wgpu::BufferUsage::Uniform);
dawn::BindGroup bindGroup = wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, uniformLayout, {{0, uniformBuffer, 0, 4 * sizeof(float)}}); utils::MakeBindGroup(device, uniformLayout, {{0, uniformBuffer, 0, 4 * sizeof(float)}});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
// Set the first pipeline (uniform, storage). // Set the first pipeline (uniform, storage).
pass.SetPipeline(pipeline0); pass.SetPipeline(pipeline0);
@ -662,7 +661,7 @@ TEST_P(BindGroupTests, BindGroupsPersistAfterPipelineChange) {
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
// The result should be RGBAunorm(1, 0, 0, 0.5) + RGBAunorm(0, 1, 0, 0.5) // The result should be RGBAunorm(1, 0, 0, 0.5) + RGBAunorm(0, 1, 0, 0.5)
@ -681,21 +680,25 @@ TEST_P(BindGroupTests, DrawThenChangePipelineAndBindGroup) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
// Create a bind group layout which uses a single dynamic uniform buffer. // Create a bind group layout which uses a single dynamic uniform buffer.
dawn::BindGroupLayout uniformLayout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout uniformLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer, true}}); device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer, true}});
// Create a bind group layout which uses a single dynamic storage buffer. // Create a bind group layout which uses a single dynamic storage buffer.
dawn::BindGroupLayout storageLayout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout storageLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::StorageBuffer, true}}); device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::StorageBuffer, true}});
// Create a pipeline with pipeline layout (uniform, uniform, storage). // Create a pipeline with pipeline layout (uniform, uniform, storage).
dawn::RenderPipeline pipeline0 = MakeTestPipeline( wgpu::RenderPipeline pipeline0 =
renderPass, {dawn::BindingType::UniformBuffer, dawn::BindingType::UniformBuffer, dawn::BindingType::StorageBuffer}, MakeTestPipeline(renderPass,
{wgpu::BindingType::UniformBuffer, wgpu::BindingType::UniformBuffer,
wgpu::BindingType::StorageBuffer},
{uniformLayout, uniformLayout, storageLayout}); {uniformLayout, uniformLayout, storageLayout});
// Create a pipeline with pipeline layout (uniform, storage, storage). // Create a pipeline with pipeline layout (uniform, storage, storage).
dawn::RenderPipeline pipeline1 = MakeTestPipeline( wgpu::RenderPipeline pipeline1 =
renderPass, {dawn::BindingType::UniformBuffer, dawn::BindingType::StorageBuffer, dawn::BindingType::StorageBuffer }, MakeTestPipeline(renderPass,
{wgpu::BindingType::UniformBuffer, wgpu::BindingType::StorageBuffer,
wgpu::BindingType::StorageBuffer},
{uniformLayout, storageLayout, storageLayout}); {uniformLayout, storageLayout, storageLayout});
// Prepare color data. // Prepare color data.
@ -719,19 +722,19 @@ TEST_P(BindGroupTests, DrawThenChangePipelineAndBindGroup) {
memcpy(data.data() + color3Offset, color3.data(), sizeof(color3)); memcpy(data.data() + color3Offset, color3.data(), sizeof(color3));
// Create a uniform and storage buffer bind groups to bind the color data. // Create a uniform and storage buffer bind groups to bind the color data.
dawn::Buffer uniformBuffer = wgpu::Buffer uniformBuffer =
utils::CreateBufferFromData(device, data.data(), data.size(), dawn::BufferUsage::Uniform); utils::CreateBufferFromData(device, data.data(), data.size(), wgpu::BufferUsage::Uniform);
dawn::Buffer storageBuffer = wgpu::Buffer storageBuffer =
utils::CreateBufferFromData(device, data.data(), data.size(), dawn::BufferUsage::Storage); utils::CreateBufferFromData(device, data.data(), data.size(), wgpu::BufferUsage::Storage);
dawn::BindGroup uniformBindGroup = wgpu::BindGroup uniformBindGroup =
utils::MakeBindGroup(device, uniformLayout, {{0, uniformBuffer, 0, 4 * sizeof(float)}}); utils::MakeBindGroup(device, uniformLayout, {{0, uniformBuffer, 0, 4 * sizeof(float)}});
dawn::BindGroup storageBindGroup = wgpu::BindGroup storageBindGroup =
utils::MakeBindGroup(device, storageLayout, {{0, storageBuffer, 0, 4 * sizeof(float)}}); utils::MakeBindGroup(device, storageLayout, {{0, storageBuffer, 0, 4 * sizeof(float)}});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
// Set the pipeline to (uniform, uniform, storage) // Set the pipeline to (uniform, uniform, storage)
pass.SetPipeline(pipeline0); pass.SetPipeline(pipeline0);
@ -764,7 +767,7 @@ TEST_P(BindGroupTests, DrawThenChangePipelineAndBindGroup) {
pass.Draw(3, 1, 0, 0); pass.Draw(3, 1, 0, 0);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
RGBA8 filled(255, 255, 255, 255); RGBA8 filled(255, 255, 255, 255);
@ -781,29 +784,29 @@ TEST_P(BindGroupTests, DrawThenChangePipelineAndBindGroup) {
TEST_P(BindGroupTests, BindGroupLayoutVisibilityCanBeNone) { TEST_P(BindGroupTests, BindGroupLayoutVisibilityCanBeNone) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::BindGroupLayoutBinding binding = {0, dawn::ShaderStage::None, wgpu::BindGroupLayoutBinding binding = {0, wgpu::ShaderStage::None,
dawn::BindingType::UniformBuffer}; wgpu::BindingType::UniformBuffer};
dawn::BindGroupLayoutDescriptor descriptor; wgpu::BindGroupLayoutDescriptor descriptor;
descriptor.bindingCount = 1; descriptor.bindingCount = 1;
descriptor.bindings = &binding; descriptor.bindings = &binding;
dawn::BindGroupLayout layout = device.CreateBindGroupLayout(&descriptor); wgpu::BindGroupLayout layout = device.CreateBindGroupLayout(&descriptor);
dawn::RenderPipeline pipeline = MakeTestPipeline(renderPass, {}, {layout}); wgpu::RenderPipeline pipeline = MakeTestPipeline(renderPass, {}, {layout});
std::array<float, 4> color = {1, 0, 0, 1}; std::array<float, 4> color = {1, 0, 0, 1};
dawn::Buffer uniformBuffer = wgpu::Buffer uniformBuffer =
utils::CreateBufferFromData(device, &color, sizeof(color), dawn::BufferUsage::Uniform); utils::CreateBufferFromData(device, &color, sizeof(color), wgpu::BufferUsage::Uniform);
dawn::BindGroup bindGroup = wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, layout, {{0, uniformBuffer, 0, sizeof(color)}}); utils::MakeBindGroup(device, layout, {{0, uniformBuffer, 0, sizeof(color)}});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.Draw(3, 1, 0, 0); pass.Draw(3, 1, 0, 0);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
} }

View File

@ -18,17 +18,17 @@
class BufferMapReadTests : public DawnTest { class BufferMapReadTests : public DawnTest {
protected: protected:
static void MapReadCallback(DawnBufferMapAsyncStatus status, static void MapReadCallback(WGPUBufferMapAsyncStatus status,
const void* data, const void* data,
uint64_t, uint64_t,
void* userdata) { void* userdata) {
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status); ASSERT_EQ(WGPUBufferMapAsyncStatus_Success, status);
ASSERT_NE(nullptr, data); ASSERT_NE(nullptr, data);
static_cast<BufferMapReadTests*>(userdata)->mappedData = data; static_cast<BufferMapReadTests*>(userdata)->mappedData = data;
} }
const void* MapReadAsyncAndWait(const dawn::Buffer& buffer) { const void* MapReadAsyncAndWait(const wgpu::Buffer& buffer) {
buffer.MapReadAsync(MapReadCallback, this); buffer.MapReadAsync(MapReadCallback, this);
while (mappedData == nullptr) { while (mappedData == nullptr) {
@ -44,10 +44,10 @@ class BufferMapReadTests : public DawnTest {
// Test that the simplest map read works. // Test that the simplest map read works.
TEST_P(BufferMapReadTests, SmallReadAtZero) { TEST_P(BufferMapReadTests, SmallReadAtZero) {
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.size = 4; descriptor.size = 4;
descriptor.usage = dawn::BufferUsage::MapRead | dawn::BufferUsage::CopyDst; descriptor.usage = wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&descriptor); wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
uint32_t myData = 0x01020304; uint32_t myData = 0x01020304;
buffer.SetSubData(0, sizeof(myData), &myData); buffer.SetSubData(0, sizeof(myData), &myData);
@ -66,10 +66,10 @@ TEST_P(BufferMapReadTests, LargeRead) {
myData.push_back(i); myData.push_back(i);
} }
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.size = static_cast<uint32_t>(kDataSize * sizeof(uint32_t)); descriptor.size = static_cast<uint32_t>(kDataSize * sizeof(uint32_t));
descriptor.usage = dawn::BufferUsage::MapRead | dawn::BufferUsage::CopyDst; descriptor.usage = wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&descriptor); wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
buffer.SetSubData(0, kDataSize * sizeof(uint32_t), myData.data()); buffer.SetSubData(0, kDataSize * sizeof(uint32_t), myData.data());
@ -83,17 +83,17 @@ DAWN_INSTANTIATE_TEST(BufferMapReadTests, D3D12Backend, MetalBackend, OpenGLBack
class BufferMapWriteTests : public DawnTest { class BufferMapWriteTests : public DawnTest {
protected: protected:
static void MapWriteCallback(DawnBufferMapAsyncStatus status, static void MapWriteCallback(WGPUBufferMapAsyncStatus status,
void* data, void* data,
uint64_t, uint64_t,
void* userdata) { void* userdata) {
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status); ASSERT_EQ(WGPUBufferMapAsyncStatus_Success, status);
ASSERT_NE(nullptr, data); ASSERT_NE(nullptr, data);
static_cast<BufferMapWriteTests*>(userdata)->mappedData = data; static_cast<BufferMapWriteTests*>(userdata)->mappedData = data;
} }
void* MapWriteAsyncAndWait(const dawn::Buffer& buffer) { void* MapWriteAsyncAndWait(const wgpu::Buffer& buffer) {
buffer.MapWriteAsync(MapWriteCallback, this); buffer.MapWriteAsync(MapWriteCallback, this);
while (mappedData == nullptr) { while (mappedData == nullptr) {
@ -113,10 +113,10 @@ class BufferMapWriteTests : public DawnTest {
// Test that the simplest map write works. // Test that the simplest map write works.
TEST_P(BufferMapWriteTests, SmallWriteAtZero) { TEST_P(BufferMapWriteTests, SmallWriteAtZero) {
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.size = 4; descriptor.size = 4;
descriptor.usage = dawn::BufferUsage::MapWrite | dawn::BufferUsage::CopySrc; descriptor.usage = wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc;
dawn::Buffer buffer = device.CreateBuffer(&descriptor); wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
uint32_t myData = 2934875; uint32_t myData = 2934875;
void* mappedData = MapWriteAsyncAndWait(buffer); void* mappedData = MapWriteAsyncAndWait(buffer);
@ -134,10 +134,10 @@ TEST_P(BufferMapWriteTests, LargeWrite) {
myData.push_back(i); myData.push_back(i);
} }
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.size = static_cast<uint32_t>(kDataSize * sizeof(uint32_t)); descriptor.size = static_cast<uint32_t>(kDataSize * sizeof(uint32_t));
descriptor.usage = dawn::BufferUsage::MapWrite | dawn::BufferUsage::CopySrc; descriptor.usage = wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc;
dawn::Buffer buffer = device.CreateBuffer(&descriptor); wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
void* mappedData = MapWriteAsyncAndWait(buffer); void* mappedData = MapWriteAsyncAndWait(buffer);
memcpy(mappedData, myData.data(), kDataSize * sizeof(uint32_t)); memcpy(mappedData, myData.data(), kDataSize * sizeof(uint32_t));
@ -154,14 +154,14 @@ TEST_P(BufferMapWriteTests, ManyWrites) {
myData.push_back(i); myData.push_back(i);
} }
std::vector<dawn::Buffer> buffers; std::vector<wgpu::Buffer> buffers;
constexpr uint32_t kBuffers = 100; constexpr uint32_t kBuffers = 100;
for (uint32_t i = 0; i < kBuffers; ++i) { for (uint32_t i = 0; i < kBuffers; ++i) {
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.size = static_cast<uint32_t>(kDataSize * sizeof(uint32_t)); descriptor.size = static_cast<uint32_t>(kDataSize * sizeof(uint32_t));
descriptor.usage = dawn::BufferUsage::MapWrite | dawn::BufferUsage::CopySrc; descriptor.usage = wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc;
dawn::Buffer buffer = device.CreateBuffer(&descriptor); wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
void* mappedData = MapWriteAsyncAndWait(buffer); void* mappedData = MapWriteAsyncAndWait(buffer);
memcpy(mappedData, myData.data(), kDataSize * sizeof(uint32_t)); memcpy(mappedData, myData.data(), kDataSize * sizeof(uint32_t));
@ -182,10 +182,10 @@ class BufferSetSubDataTests : public DawnTest {
// Test the simplest set sub data: setting one u32 at offset 0. // Test the simplest set sub data: setting one u32 at offset 0.
TEST_P(BufferSetSubDataTests, SmallDataAtZero) { TEST_P(BufferSetSubDataTests, SmallDataAtZero) {
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.size = 4; descriptor.size = 4;
descriptor.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst; descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&descriptor); wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
uint32_t value = 0x01020304; uint32_t value = 0x01020304;
buffer.SetSubData(0, sizeof(value), &value); buffer.SetSubData(0, sizeof(value), &value);
@ -195,10 +195,10 @@ TEST_P(BufferSetSubDataTests, SmallDataAtZero) {
// Test that SetSubData offset works. // Test that SetSubData offset works.
TEST_P(BufferSetSubDataTests, SmallDataAtOffset) { TEST_P(BufferSetSubDataTests, SmallDataAtOffset) {
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.size = 4000; descriptor.size = 4000;
descriptor.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst; descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&descriptor); wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
constexpr uint64_t kOffset = 2000; constexpr uint64_t kOffset = 2000;
uint32_t value = 0x01020304; uint32_t value = 0x01020304;
@ -223,10 +223,10 @@ TEST_P(BufferSetSubDataTests, ManySetSubData) {
constexpr uint64_t kSize = 4000 * 1000; constexpr uint64_t kSize = 4000 * 1000;
constexpr uint32_t kElements = 500 * 500; constexpr uint32_t kElements = 500 * 500;
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.size = kSize; descriptor.size = kSize;
descriptor.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst; descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&descriptor); wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
std::vector<uint32_t> expectedData; std::vector<uint32_t> expectedData;
for (uint32_t i = 0; i < kElements; ++i) { for (uint32_t i = 0; i < kElements; ++i) {
@ -241,10 +241,10 @@ TEST_P(BufferSetSubDataTests, ManySetSubData) {
TEST_P(BufferSetSubDataTests, LargeSetSubData) { TEST_P(BufferSetSubDataTests, LargeSetSubData) {
constexpr uint64_t kSize = 4000 * 1000; constexpr uint64_t kSize = 4000 * 1000;
constexpr uint32_t kElements = 1000 * 1000; constexpr uint32_t kElements = 1000 * 1000;
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.size = kSize; descriptor.size = kSize;
descriptor.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst; descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&descriptor); wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
std::vector<uint32_t> expectedData; std::vector<uint32_t> expectedData;
for (uint32_t i = 0; i < kElements; ++i) { for (uint32_t i = 0; i < kElements; ++i) {
@ -265,17 +265,17 @@ DAWN_INSTANTIATE_TEST(BufferSetSubDataTests,
// TODO(enga): These tests should use the testing toggle to initialize resources to 1. // TODO(enga): These tests should use the testing toggle to initialize resources to 1.
class CreateBufferMappedTests : public DawnTest { class CreateBufferMappedTests : public DawnTest {
protected: protected:
static void MapReadCallback(DawnBufferMapAsyncStatus status, static void MapReadCallback(WGPUBufferMapAsyncStatus status,
const void* data, const void* data,
uint64_t, uint64_t,
void* userdata) { void* userdata) {
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status); ASSERT_EQ(WGPUBufferMapAsyncStatus_Success, status);
ASSERT_NE(nullptr, data); ASSERT_NE(nullptr, data);
static_cast<CreateBufferMappedTests*>(userdata)->mappedData = data; static_cast<CreateBufferMappedTests*>(userdata)->mappedData = data;
} }
const void* MapReadAsyncAndWait(const dawn::Buffer& buffer) { const void* MapReadAsyncAndWait(const wgpu::Buffer& buffer) {
buffer.MapReadAsync(MapReadCallback, this); buffer.MapReadAsync(MapReadCallback, this);
while (mappedData == nullptr) { while (mappedData == nullptr) {
@ -285,7 +285,7 @@ class CreateBufferMappedTests : public DawnTest {
return mappedData; return mappedData;
} }
void CheckResultStartsZeroed(const dawn::CreateBufferMappedResult& result, uint64_t size) { void CheckResultStartsZeroed(const wgpu::CreateBufferMappedResult& result, uint64_t size) {
ASSERT_EQ(result.dataLength, size); ASSERT_EQ(result.dataLength, size);
for (uint64_t i = 0; i < result.dataLength; ++i) { for (uint64_t i = 0; i < result.dataLength; ++i) {
uint8_t value = *(reinterpret_cast<uint8_t*>(result.data) + i); uint8_t value = *(reinterpret_cast<uint8_t*>(result.data) + i);
@ -293,46 +293,46 @@ class CreateBufferMappedTests : public DawnTest {
} }
} }
dawn::CreateBufferMappedResult CreateBufferMapped(dawn::BufferUsage usage, uint64_t size) { wgpu::CreateBufferMappedResult CreateBufferMapped(wgpu::BufferUsage usage, uint64_t size) {
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.nextInChain = nullptr; descriptor.nextInChain = nullptr;
descriptor.size = size; descriptor.size = size;
descriptor.usage = usage; descriptor.usage = usage;
dawn::CreateBufferMappedResult result = device.CreateBufferMapped(&descriptor); wgpu::CreateBufferMappedResult result = device.CreateBufferMapped(&descriptor);
CheckResultStartsZeroed(result, size); CheckResultStartsZeroed(result, size);
return result; return result;
} }
dawn::CreateBufferMappedResult CreateBufferMappedWithData(dawn::BufferUsage usage, wgpu::CreateBufferMappedResult CreateBufferMappedWithData(wgpu::BufferUsage usage,
const std::vector<uint32_t>& data) { const std::vector<uint32_t>& data) {
size_t byteLength = data.size() * sizeof(uint32_t); size_t byteLength = data.size() * sizeof(uint32_t);
dawn::CreateBufferMappedResult result = CreateBufferMapped(usage, byteLength); wgpu::CreateBufferMappedResult result = CreateBufferMapped(usage, byteLength);
memcpy(result.data, data.data(), byteLength); memcpy(result.data, data.data(), byteLength);
return result; return result;
} }
template <DawnBufferMapAsyncStatus expectedStatus = DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS> template <WGPUBufferMapAsyncStatus expectedStatus = WGPUBufferMapAsyncStatus_Success>
dawn::CreateBufferMappedResult CreateBufferMappedAsyncAndWait(dawn::BufferUsage usage, wgpu::CreateBufferMappedResult CreateBufferMappedAsyncAndWait(wgpu::BufferUsage usage,
uint64_t size) { uint64_t size) {
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.nextInChain = nullptr; descriptor.nextInChain = nullptr;
descriptor.size = size; descriptor.size = size;
descriptor.usage = usage; descriptor.usage = usage;
struct ResultInfo { struct ResultInfo {
dawn::CreateBufferMappedResult result; wgpu::CreateBufferMappedResult result;
bool done = false; bool done = false;
} resultInfo; } resultInfo;
device.CreateBufferMappedAsync( device.CreateBufferMappedAsync(
&descriptor, &descriptor,
[](DawnBufferMapAsyncStatus status, DawnCreateBufferMappedResult result, [](WGPUBufferMapAsyncStatus status, WGPUCreateBufferMappedResult result,
void* userdata) { void* userdata) {
ASSERT_EQ(status, expectedStatus); ASSERT_EQ(status, expectedStatus);
auto* resultInfo = reinterpret_cast<ResultInfo*>(userdata); auto* resultInfo = reinterpret_cast<ResultInfo*>(userdata);
resultInfo->result.buffer = dawn::Buffer::Acquire(result.buffer); resultInfo->result.buffer = wgpu::Buffer::Acquire(result.buffer);
resultInfo->result.data = result.data; resultInfo->result.data = result.data;
resultInfo->result.dataLength = result.dataLength; resultInfo->result.dataLength = result.dataLength;
resultInfo->done = true; resultInfo->done = true;
@ -348,11 +348,11 @@ class CreateBufferMappedTests : public DawnTest {
return resultInfo.result; return resultInfo.result;
} }
dawn::CreateBufferMappedResult CreateBufferMappedAsyncWithDataAndWait( wgpu::CreateBufferMappedResult CreateBufferMappedAsyncWithDataAndWait(
dawn::BufferUsage usage, wgpu::BufferUsage usage,
const std::vector<uint32_t>& data) { const std::vector<uint32_t>& data) {
size_t byteLength = data.size() * sizeof(uint32_t); size_t byteLength = data.size() * sizeof(uint32_t);
dawn::CreateBufferMappedResult result = CreateBufferMappedAsyncAndWait(usage, byteLength); wgpu::CreateBufferMappedResult result = CreateBufferMappedAsyncAndWait(usage, byteLength);
memcpy(result.data, data.data(), byteLength); memcpy(result.data, data.data(), byteLength);
return result; return result;
@ -365,8 +365,8 @@ class CreateBufferMappedTests : public DawnTest {
// Test that the simplest CreateBufferMapped works for MapWrite buffers. // Test that the simplest CreateBufferMapped works for MapWrite buffers.
TEST_P(CreateBufferMappedTests, MapWriteUsageSmall) { TEST_P(CreateBufferMappedTests, MapWriteUsageSmall) {
uint32_t myData = 230502; uint32_t myData = 230502;
dawn::CreateBufferMappedResult result = CreateBufferMappedWithData( wgpu::CreateBufferMappedResult result = CreateBufferMappedWithData(
dawn::BufferUsage::MapWrite | dawn::BufferUsage::CopySrc, {myData}); wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc, {myData});
result.buffer.Unmap(); result.buffer.Unmap();
EXPECT_BUFFER_U32_EQ(myData, result.buffer, 0); EXPECT_BUFFER_U32_EQ(myData, result.buffer, 0);
} }
@ -374,8 +374,8 @@ TEST_P(CreateBufferMappedTests, MapWriteUsageSmall) {
// Test that the simplest CreateBufferMapped works for MapRead buffers. // Test that the simplest CreateBufferMapped works for MapRead buffers.
TEST_P(CreateBufferMappedTests, MapReadUsageSmall) { TEST_P(CreateBufferMappedTests, MapReadUsageSmall) {
uint32_t myData = 230502; uint32_t myData = 230502;
dawn::CreateBufferMappedResult result = wgpu::CreateBufferMappedResult result =
CreateBufferMappedWithData(dawn::BufferUsage::MapRead, {myData}); CreateBufferMappedWithData(wgpu::BufferUsage::MapRead, {myData});
result.buffer.Unmap(); result.buffer.Unmap();
const void* mappedData = MapReadAsyncAndWait(result.buffer); const void* mappedData = MapReadAsyncAndWait(result.buffer);
@ -386,8 +386,8 @@ TEST_P(CreateBufferMappedTests, MapReadUsageSmall) {
// Test that the simplest CreateBufferMapped works for non-mappable buffers. // Test that the simplest CreateBufferMapped works for non-mappable buffers.
TEST_P(CreateBufferMappedTests, NonMappableUsageSmall) { TEST_P(CreateBufferMappedTests, NonMappableUsageSmall) {
uint32_t myData = 4239; uint32_t myData = 4239;
dawn::CreateBufferMappedResult result = wgpu::CreateBufferMappedResult result =
CreateBufferMappedWithData(dawn::BufferUsage::CopySrc, {myData}); CreateBufferMappedWithData(wgpu::BufferUsage::CopySrc, {myData});
result.buffer.Unmap(); result.buffer.Unmap();
EXPECT_BUFFER_U32_EQ(myData, result.buffer, 0); EXPECT_BUFFER_U32_EQ(myData, result.buffer, 0);
@ -401,8 +401,8 @@ TEST_P(CreateBufferMappedTests, MapWriteUsageLarge) {
myData.push_back(i); myData.push_back(i);
} }
dawn::CreateBufferMappedResult result = CreateBufferMappedWithData( wgpu::CreateBufferMappedResult result = CreateBufferMappedWithData(
dawn::BufferUsage::MapWrite | dawn::BufferUsage::CopySrc, {myData}); wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc, {myData});
result.buffer.Unmap(); result.buffer.Unmap();
EXPECT_BUFFER_U32_RANGE_EQ(myData.data(), result.buffer, 0, kDataSize); EXPECT_BUFFER_U32_RANGE_EQ(myData.data(), result.buffer, 0, kDataSize);
@ -416,8 +416,8 @@ TEST_P(CreateBufferMappedTests, MapReadUsageLarge) {
myData.push_back(i); myData.push_back(i);
} }
dawn::CreateBufferMappedResult result = wgpu::CreateBufferMappedResult result =
CreateBufferMappedWithData(dawn::BufferUsage::MapRead, myData); CreateBufferMappedWithData(wgpu::BufferUsage::MapRead, myData);
result.buffer.Unmap(); result.buffer.Unmap();
const void* mappedData = MapReadAsyncAndWait(result.buffer); const void* mappedData = MapReadAsyncAndWait(result.buffer);
@ -433,8 +433,8 @@ TEST_P(CreateBufferMappedTests, NonMappableUsageLarge) {
myData.push_back(i); myData.push_back(i);
} }
dawn::CreateBufferMappedResult result = wgpu::CreateBufferMappedResult result =
CreateBufferMappedWithData(dawn::BufferUsage::CopySrc, {myData}); CreateBufferMappedWithData(wgpu::BufferUsage::CopySrc, {myData});
result.buffer.Unmap(); result.buffer.Unmap();
EXPECT_BUFFER_U32_RANGE_EQ(myData.data(), result.buffer, 0, kDataSize); EXPECT_BUFFER_U32_RANGE_EQ(myData.data(), result.buffer, 0, kDataSize);
@ -444,16 +444,16 @@ TEST_P(CreateBufferMappedTests, NonMappableUsageLarge) {
TEST_P(CreateBufferMappedTests, CreateThenMapSuccess) { TEST_P(CreateBufferMappedTests, CreateThenMapSuccess) {
static uint32_t myData = 230502; static uint32_t myData = 230502;
static uint32_t myData2 = 1337; static uint32_t myData2 = 1337;
dawn::CreateBufferMappedResult result = CreateBufferMappedWithData( wgpu::CreateBufferMappedResult result = CreateBufferMappedWithData(
dawn::BufferUsage::MapWrite | dawn::BufferUsage::CopySrc, {myData}); wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc, {myData});
result.buffer.Unmap(); result.buffer.Unmap();
EXPECT_BUFFER_U32_EQ(myData, result.buffer, 0); EXPECT_BUFFER_U32_EQ(myData, result.buffer, 0);
bool done = false; bool done = false;
result.buffer.MapWriteAsync( result.buffer.MapWriteAsync(
[](DawnBufferMapAsyncStatus status, void* data, uint64_t, void* userdata) { [](WGPUBufferMapAsyncStatus status, void* data, uint64_t, void* userdata) {
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status); ASSERT_EQ(WGPUBufferMapAsyncStatus_Success, status);
ASSERT_NE(nullptr, data); ASSERT_NE(nullptr, data);
*static_cast<uint32_t*>(data) = myData2; *static_cast<uint32_t*>(data) = myData2;
@ -472,14 +472,14 @@ TEST_P(CreateBufferMappedTests, CreateThenMapSuccess) {
// Test that is is invalid to map a buffer twice when using CreateBufferMapped // Test that is is invalid to map a buffer twice when using CreateBufferMapped
TEST_P(CreateBufferMappedTests, CreateThenMapBeforeUnmapFailure) { TEST_P(CreateBufferMappedTests, CreateThenMapBeforeUnmapFailure) {
uint32_t myData = 230502; uint32_t myData = 230502;
dawn::CreateBufferMappedResult result = CreateBufferMappedWithData( wgpu::CreateBufferMappedResult result = CreateBufferMappedWithData(
dawn::BufferUsage::MapWrite | dawn::BufferUsage::CopySrc, {myData}); wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc, {myData});
ASSERT_DEVICE_ERROR([&]() { ASSERT_DEVICE_ERROR([&]() {
bool done = false; bool done = false;
result.buffer.MapWriteAsync( result.buffer.MapWriteAsync(
[](DawnBufferMapAsyncStatus status, void* data, uint64_t, void* userdata) { [](WGPUBufferMapAsyncStatus status, void* data, uint64_t, void* userdata) {
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, status); ASSERT_EQ(WGPUBufferMapAsyncStatus_Error, status);
ASSERT_EQ(nullptr, data); ASSERT_EQ(nullptr, data);
*static_cast<bool*>(userdata) = true; *static_cast<bool*>(userdata) = true;
@ -499,8 +499,8 @@ TEST_P(CreateBufferMappedTests, CreateThenMapBeforeUnmapFailure) {
// Test that the simplest CreateBufferMappedAsync works for MapWrite buffers. // Test that the simplest CreateBufferMappedAsync works for MapWrite buffers.
TEST_P(CreateBufferMappedTests, MapWriteUsageSmallAsync) { TEST_P(CreateBufferMappedTests, MapWriteUsageSmallAsync) {
uint32_t myData = 230502; uint32_t myData = 230502;
dawn::CreateBufferMappedResult result = CreateBufferMappedAsyncWithDataAndWait( wgpu::CreateBufferMappedResult result = CreateBufferMappedAsyncWithDataAndWait(
dawn::BufferUsage::MapWrite | dawn::BufferUsage::CopySrc, {myData}); wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc, {myData});
result.buffer.Unmap(); result.buffer.Unmap();
EXPECT_BUFFER_U32_EQ(myData, result.buffer, 0); EXPECT_BUFFER_U32_EQ(myData, result.buffer, 0);
} }
@ -508,8 +508,8 @@ TEST_P(CreateBufferMappedTests, MapWriteUsageSmallAsync) {
// Test that the simplest CreateBufferMappedAsync works for MapRead buffers. // Test that the simplest CreateBufferMappedAsync works for MapRead buffers.
TEST_P(CreateBufferMappedTests, MapReadUsageSmallAsync) { TEST_P(CreateBufferMappedTests, MapReadUsageSmallAsync) {
uint32_t myData = 230502; uint32_t myData = 230502;
dawn::CreateBufferMappedResult result = wgpu::CreateBufferMappedResult result =
CreateBufferMappedAsyncWithDataAndWait(dawn::BufferUsage::MapRead, {myData}); CreateBufferMappedAsyncWithDataAndWait(wgpu::BufferUsage::MapRead, {myData});
result.buffer.Unmap(); result.buffer.Unmap();
const void* mappedData = MapReadAsyncAndWait(result.buffer); const void* mappedData = MapReadAsyncAndWait(result.buffer);
@ -520,8 +520,8 @@ TEST_P(CreateBufferMappedTests, MapReadUsageSmallAsync) {
// Test that the simplest CreateBufferMappedAsync works for non-mappable buffers. // Test that the simplest CreateBufferMappedAsync works for non-mappable buffers.
TEST_P(CreateBufferMappedTests, NonMappableUsageSmallAsync) { TEST_P(CreateBufferMappedTests, NonMappableUsageSmallAsync) {
uint32_t myData = 4239; uint32_t myData = 4239;
dawn::CreateBufferMappedResult result = wgpu::CreateBufferMappedResult result =
CreateBufferMappedAsyncWithDataAndWait(dawn::BufferUsage::CopySrc, {myData}); CreateBufferMappedAsyncWithDataAndWait(wgpu::BufferUsage::CopySrc, {myData});
result.buffer.Unmap(); result.buffer.Unmap();
EXPECT_BUFFER_U32_EQ(myData, result.buffer, 0); EXPECT_BUFFER_U32_EQ(myData, result.buffer, 0);
@ -535,8 +535,8 @@ TEST_P(CreateBufferMappedTests, MapWriteUsageLargeAsync) {
myData.push_back(i); myData.push_back(i);
} }
dawn::CreateBufferMappedResult result = CreateBufferMappedAsyncWithDataAndWait( wgpu::CreateBufferMappedResult result = CreateBufferMappedAsyncWithDataAndWait(
dawn::BufferUsage::MapWrite | dawn::BufferUsage::CopySrc, {myData}); wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc, {myData});
result.buffer.Unmap(); result.buffer.Unmap();
EXPECT_BUFFER_U32_RANGE_EQ(myData.data(), result.buffer, 0, kDataSize); EXPECT_BUFFER_U32_RANGE_EQ(myData.data(), result.buffer, 0, kDataSize);
@ -550,8 +550,8 @@ TEST_P(CreateBufferMappedTests, MapReadUsageLargeAsync) {
myData.push_back(i); myData.push_back(i);
} }
dawn::CreateBufferMappedResult result = wgpu::CreateBufferMappedResult result =
CreateBufferMappedAsyncWithDataAndWait(dawn::BufferUsage::MapRead, {myData}); CreateBufferMappedAsyncWithDataAndWait(wgpu::BufferUsage::MapRead, {myData});
result.buffer.Unmap(); result.buffer.Unmap();
const void* mappedData = MapReadAsyncAndWait(result.buffer); const void* mappedData = MapReadAsyncAndWait(result.buffer);
@ -567,8 +567,8 @@ TEST_P(CreateBufferMappedTests, NonMappableUsageLargeAsync) {
myData.push_back(i); myData.push_back(i);
} }
dawn::CreateBufferMappedResult result = wgpu::CreateBufferMappedResult result =
CreateBufferMappedAsyncWithDataAndWait(dawn::BufferUsage::CopySrc, {myData}); CreateBufferMappedAsyncWithDataAndWait(wgpu::BufferUsage::CopySrc, {myData});
result.buffer.Unmap(); result.buffer.Unmap();
EXPECT_BUFFER_U32_RANGE_EQ(myData.data(), result.buffer, 0, kDataSize); EXPECT_BUFFER_U32_RANGE_EQ(myData.data(), result.buffer, 0, kDataSize);
@ -578,16 +578,16 @@ TEST_P(CreateBufferMappedTests, NonMappableUsageLargeAsync) {
TEST_P(CreateBufferMappedTests, CreateThenMapSuccessAsync) { TEST_P(CreateBufferMappedTests, CreateThenMapSuccessAsync) {
static uint32_t myData = 230502; static uint32_t myData = 230502;
static uint32_t myData2 = 1337; static uint32_t myData2 = 1337;
dawn::CreateBufferMappedResult result = CreateBufferMappedAsyncWithDataAndWait( wgpu::CreateBufferMappedResult result = CreateBufferMappedAsyncWithDataAndWait(
dawn::BufferUsage::MapWrite | dawn::BufferUsage::CopySrc, {myData}); wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc, {myData});
result.buffer.Unmap(); result.buffer.Unmap();
EXPECT_BUFFER_U32_EQ(myData, result.buffer, 0); EXPECT_BUFFER_U32_EQ(myData, result.buffer, 0);
bool done = false; bool done = false;
result.buffer.MapWriteAsync( result.buffer.MapWriteAsync(
[](DawnBufferMapAsyncStatus status, void* data, uint64_t, void* userdata) { [](WGPUBufferMapAsyncStatus status, void* data, uint64_t, void* userdata) {
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status); ASSERT_EQ(WGPUBufferMapAsyncStatus_Success, status);
ASSERT_NE(nullptr, data); ASSERT_NE(nullptr, data);
*static_cast<uint32_t*>(data) = myData2; *static_cast<uint32_t*>(data) = myData2;
@ -606,14 +606,14 @@ TEST_P(CreateBufferMappedTests, CreateThenMapSuccessAsync) {
// Test that is is invalid to map a buffer twice when using CreateBufferMappedAsync // Test that is is invalid to map a buffer twice when using CreateBufferMappedAsync
TEST_P(CreateBufferMappedTests, CreateThenMapBeforeUnmapFailureAsync) { TEST_P(CreateBufferMappedTests, CreateThenMapBeforeUnmapFailureAsync) {
uint32_t myData = 230502; uint32_t myData = 230502;
dawn::CreateBufferMappedResult result = CreateBufferMappedAsyncWithDataAndWait( wgpu::CreateBufferMappedResult result = CreateBufferMappedAsyncWithDataAndWait(
dawn::BufferUsage::MapWrite | dawn::BufferUsage::CopySrc, {myData}); wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc, {myData});
ASSERT_DEVICE_ERROR([&]() { ASSERT_DEVICE_ERROR([&]() {
bool done = false; bool done = false;
result.buffer.MapWriteAsync( result.buffer.MapWriteAsync(
[](DawnBufferMapAsyncStatus status, void* data, uint64_t, void* userdata) { [](WGPUBufferMapAsyncStatus status, void* data, uint64_t, void* userdata) {
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, status); ASSERT_EQ(WGPUBufferMapAsyncStatus_Error, status);
ASSERT_EQ(nullptr, data); ASSERT_EQ(nullptr, data);
*static_cast<bool*>(userdata) = true; *static_cast<bool*>(userdata) = true;
@ -640,9 +640,9 @@ TEST_P(CreateBufferMappedTests, LargeBufferFails) {
// 4G on some platforms. // 4G on some platforms.
DAWN_SKIP_TEST_IF(IsVulkan() && IsNvidia() && IsBackendValidationEnabled()); DAWN_SKIP_TEST_IF(IsVulkan() && IsNvidia() && IsBackendValidationEnabled());
dawn::BufferDescriptor descriptor; wgpu::BufferDescriptor descriptor;
descriptor.size = std::numeric_limits<uint64_t>::max(); descriptor.size = std::numeric_limits<uint64_t>::max();
descriptor.usage = dawn::BufferUsage::MapRead | dawn::BufferUsage::CopyDst; descriptor.usage = wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst;
ASSERT_DEVICE_ERROR(device.CreateBuffer(&descriptor)); ASSERT_DEVICE_ERROR(device.CreateBuffer(&descriptor));
} }

View File

@ -19,7 +19,7 @@
class ClipSpaceTest : public DawnTest { class ClipSpaceTest : public DawnTest {
protected: protected:
dawn::RenderPipeline CreatePipelineForTest() { wgpu::RenderPipeline CreatePipelineForTest() {
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device); utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
// Draw two triangles: // Draw two triangles:
@ -48,18 +48,18 @@ class ClipSpaceTest : public DawnTest {
pipelineDescriptor.cFragmentStage.module = pipelineDescriptor.cFragmentStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs); utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs);
pipelineDescriptor.cDepthStencilState.depthCompare = dawn::CompareFunction::LessEqual; pipelineDescriptor.cDepthStencilState.depthCompare = wgpu::CompareFunction::LessEqual;
pipelineDescriptor.depthStencilState = &pipelineDescriptor.cDepthStencilState; pipelineDescriptor.depthStencilState = &pipelineDescriptor.cDepthStencilState;
return device.CreateRenderPipeline(&pipelineDescriptor); return device.CreateRenderPipeline(&pipelineDescriptor);
} }
dawn::Texture Create2DTextureForTest(dawn::TextureFormat format) { wgpu::Texture Create2DTextureForTest(wgpu::TextureFormat format) {
dawn::TextureDescriptor textureDescriptor; wgpu::TextureDescriptor textureDescriptor;
textureDescriptor.dimension = dawn::TextureDimension::e2D; textureDescriptor.dimension = wgpu::TextureDimension::e2D;
textureDescriptor.format = format; textureDescriptor.format = format;
textureDescriptor.usage = textureDescriptor.usage =
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc; wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
textureDescriptor.arrayLayerCount = 1; textureDescriptor.arrayLayerCount = 1;
textureDescriptor.mipLevelCount = 1; textureDescriptor.mipLevelCount = 1;
textureDescriptor.sampleCount = 1; textureDescriptor.sampleCount = 1;
@ -72,27 +72,27 @@ class ClipSpaceTest : public DawnTest {
// Test that the clip space is correctly configured. // Test that the clip space is correctly configured.
TEST_P(ClipSpaceTest, ClipSpace) { TEST_P(ClipSpaceTest, ClipSpace) {
dawn::Texture colorTexture = Create2DTextureForTest(dawn::TextureFormat::RGBA8Unorm); wgpu::Texture colorTexture = Create2DTextureForTest(wgpu::TextureFormat::RGBA8Unorm);
dawn::Texture depthStencilTexture = wgpu::Texture depthStencilTexture =
Create2DTextureForTest(dawn::TextureFormat::Depth24PlusStencil8); Create2DTextureForTest(wgpu::TextureFormat::Depth24PlusStencil8);
utils::ComboRenderPassDescriptor renderPassDescriptor({colorTexture.CreateView()}, utils::ComboRenderPassDescriptor renderPassDescriptor({colorTexture.CreateView()},
depthStencilTexture.CreateView()); depthStencilTexture.CreateView());
renderPassDescriptor.cColorAttachments[0].clearColor = {0.0, 1.0, 0.0, 1.0}; renderPassDescriptor.cColorAttachments[0].clearColor = {0.0, 1.0, 0.0, 1.0};
renderPassDescriptor.cColorAttachments[0].loadOp = dawn::LoadOp::Clear; renderPassDescriptor.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
// Clear the depth stencil attachment to 0.5f, so only the bottom-right triangle should be // Clear the depth stencil attachment to 0.5f, so only the bottom-right triangle should be
// drawn. // drawn.
renderPassDescriptor.cDepthStencilAttachmentInfo.clearDepth = 0.5f; renderPassDescriptor.cDepthStencilAttachmentInfo.clearDepth = 0.5f;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Clear; renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Clear;
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder renderPass = commandEncoder.BeginRenderPass(&renderPassDescriptor); wgpu::RenderPassEncoder renderPass = commandEncoder.BeginRenderPass(&renderPassDescriptor);
renderPass.SetPipeline(CreatePipelineForTest()); renderPass.SetPipeline(CreatePipelineForTest());
renderPass.Draw(6, 1, 0, 0); renderPass.Draw(6, 1, 0, 0);
renderPass.EndPass(); renderPass.EndPass();
dawn::CommandBuffer commandBuffer = commandEncoder.Finish(); wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue(); wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer); queue.Submit(1, &commandBuffer);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(255, 0, 0, 255), colorTexture, kSize - 1, kSize - 1); EXPECT_PIXEL_RGBA8_EQ(RGBA8(255, 0, 0, 255), colorTexture, kSize - 1, kSize - 1);

View File

@ -39,7 +39,7 @@ class ColorStateTest : public DawnTest {
bindGroupLayout = utils::MakeBindGroupLayout( bindGroupLayout = utils::MakeBindGroupLayout(
device, { device, {
{0, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}, {0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer},
}); });
pipelineLayout = utils::MakeBasicPipelineLayout(device, &bindGroupLayout); pipelineLayout = utils::MakeBasicPipelineLayout(device, &bindGroupLayout);
@ -54,8 +54,8 @@ class ColorStateTest : public DawnTest {
// Set up basePipeline and testPipeline. testPipeline has the given blend state on the first // Set up basePipeline and testPipeline. testPipeline has the given blend state on the first
// attachment. basePipeline has no blending // attachment. basePipeline has no blending
void SetupSingleSourcePipelines(dawn::ColorStateDescriptor colorStateDescriptor) { void SetupSingleSourcePipelines(wgpu::ColorStateDescriptor colorStateDescriptor) {
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(set = 0, binding = 0) uniform myBlock { layout(set = 0, binding = 0) uniform myBlock {
@ -89,7 +89,7 @@ class ColorStateTest : public DawnTest {
// Create a bind group to set the colors as a uniform buffer // Create a bind group to set the colors as a uniform buffer
template <size_t N> template <size_t N>
dawn::BindGroup MakeBindGroupForColors(std::array<RGBA8, N> colors) { wgpu::BindGroup MakeBindGroupForColors(std::array<RGBA8, N> colors) {
std::array<float, 4 * N> data; std::array<float, 4 * N> data;
for (unsigned int i = 0; i < N; ++i) { for (unsigned int i = 0; i < N; ++i) {
data[4 * i + 0] = static_cast<float>(colors[i].r) / 255.f; data[4 * i + 0] = static_cast<float>(colors[i].r) / 255.f;
@ -100,20 +100,20 @@ class ColorStateTest : public DawnTest {
uint32_t bufferSize = static_cast<uint32_t>(4 * N * sizeof(float)); uint32_t bufferSize = static_cast<uint32_t>(4 * N * sizeof(float));
dawn::Buffer buffer = wgpu::Buffer buffer =
utils::CreateBufferFromData(device, &data, bufferSize, dawn::BufferUsage::Uniform); utils::CreateBufferFromData(device, &data, bufferSize, wgpu::BufferUsage::Uniform);
return utils::MakeBindGroup(device, bindGroupLayout, {{0, buffer, 0, bufferSize}}); return utils::MakeBindGroup(device, bindGroupLayout, {{0, buffer, 0, bufferSize}});
} }
// Test that after drawing a triangle with the base color, and then the given triangle spec, the // Test that after drawing a triangle with the base color, and then the given triangle spec, the
// color is as expected // color is as expected
void DoSingleSourceTest(RGBA8 base, const TriangleSpec& triangle, const RGBA8& expected) { void DoSingleSourceTest(RGBA8 base, const TriangleSpec& triangle, const RGBA8& expected) {
dawn::Color blendColor{triangle.blendFactor[0], triangle.blendFactor[1], wgpu::Color blendColor{triangle.blendFactor[0], triangle.blendFactor[1],
triangle.blendFactor[2], triangle.blendFactor[3]}; triangle.blendFactor[2], triangle.blendFactor[3]};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
// First use the base pipeline to draw a triangle with no blending // First use the base pipeline to draw a triangle with no blending
pass.SetPipeline(basePipeline); pass.SetPipeline(basePipeline);
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({{base}}))); pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({{base}})));
@ -127,7 +127,7 @@ class ColorStateTest : public DawnTest {
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(expected, renderPass.color, kRTSize / 2, kRTSize / 2); EXPECT_PIXEL_RGBA8_EQ(expected, renderPass.color, kRTSize / 2, kRTSize / 2);
@ -136,17 +136,17 @@ class ColorStateTest : public DawnTest {
// Given a vector of tests where each element is <testColor, expectedColor>, check that all // Given a vector of tests where each element is <testColor, expectedColor>, check that all
// expectations are true for the given blend operation // expectations are true for the given blend operation
void CheckBlendOperation(RGBA8 base, void CheckBlendOperation(RGBA8 base,
dawn::BlendOperation operation, wgpu::BlendOperation operation,
std::vector<std::pair<RGBA8, RGBA8>> tests) { std::vector<std::pair<RGBA8, RGBA8>> tests) {
dawn::BlendDescriptor blend; wgpu::BlendDescriptor blend;
blend.operation = operation; blend.operation = operation;
blend.srcFactor = dawn::BlendFactor::One; blend.srcFactor = wgpu::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One; blend.dstFactor = wgpu::BlendFactor::One;
dawn::ColorStateDescriptor descriptor; wgpu::ColorStateDescriptor descriptor;
descriptor.alphaBlend = blend; descriptor.alphaBlend = blend;
descriptor.colorBlend = blend; descriptor.colorBlend = blend;
descriptor.writeMask = dawn::ColorWriteMask::All; descriptor.writeMask = wgpu::ColorWriteMask::All;
SetupSingleSourcePipelines(descriptor); SetupSingleSourcePipelines(descriptor);
@ -158,25 +158,25 @@ class ColorStateTest : public DawnTest {
// Given a vector of tests where each element is <testSpec, expectedColor>, check that all // Given a vector of tests where each element is <testSpec, expectedColor>, check that all
// expectations are true for the given blend factors // expectations are true for the given blend factors
void CheckBlendFactor(RGBA8 base, void CheckBlendFactor(RGBA8 base,
dawn::BlendFactor colorSrcFactor, wgpu::BlendFactor colorSrcFactor,
dawn::BlendFactor colorDstFactor, wgpu::BlendFactor colorDstFactor,
dawn::BlendFactor alphaSrcFactor, wgpu::BlendFactor alphaSrcFactor,
dawn::BlendFactor alphaDstFactor, wgpu::BlendFactor alphaDstFactor,
std::vector<std::pair<TriangleSpec, RGBA8>> tests) { std::vector<std::pair<TriangleSpec, RGBA8>> tests) {
dawn::BlendDescriptor colorBlend; wgpu::BlendDescriptor colorBlend;
colorBlend.operation = dawn::BlendOperation::Add; colorBlend.operation = wgpu::BlendOperation::Add;
colorBlend.srcFactor = colorSrcFactor; colorBlend.srcFactor = colorSrcFactor;
colorBlend.dstFactor = colorDstFactor; colorBlend.dstFactor = colorDstFactor;
dawn::BlendDescriptor alphaBlend; wgpu::BlendDescriptor alphaBlend;
alphaBlend.operation = dawn::BlendOperation::Add; alphaBlend.operation = wgpu::BlendOperation::Add;
alphaBlend.srcFactor = alphaSrcFactor; alphaBlend.srcFactor = alphaSrcFactor;
alphaBlend.dstFactor = alphaDstFactor; alphaBlend.dstFactor = alphaDstFactor;
dawn::ColorStateDescriptor descriptor; wgpu::ColorStateDescriptor descriptor;
descriptor.colorBlend = colorBlend; descriptor.colorBlend = colorBlend;
descriptor.alphaBlend = alphaBlend; descriptor.alphaBlend = alphaBlend;
descriptor.writeMask = dawn::ColorWriteMask::All; descriptor.writeMask = wgpu::ColorWriteMask::All;
SetupSingleSourcePipelines(descriptor); SetupSingleSourcePipelines(descriptor);
@ -186,27 +186,27 @@ class ColorStateTest : public DawnTest {
} }
void CheckSrcBlendFactor(RGBA8 base, void CheckSrcBlendFactor(RGBA8 base,
dawn::BlendFactor colorFactor, wgpu::BlendFactor colorFactor,
dawn::BlendFactor alphaFactor, wgpu::BlendFactor alphaFactor,
std::vector<std::pair<TriangleSpec, RGBA8>> tests) { std::vector<std::pair<TriangleSpec, RGBA8>> tests) {
CheckBlendFactor(base, colorFactor, dawn::BlendFactor::One, alphaFactor, CheckBlendFactor(base, colorFactor, wgpu::BlendFactor::One, alphaFactor,
dawn::BlendFactor::One, tests); wgpu::BlendFactor::One, tests);
} }
void CheckDstBlendFactor(RGBA8 base, void CheckDstBlendFactor(RGBA8 base,
dawn::BlendFactor colorFactor, wgpu::BlendFactor colorFactor,
dawn::BlendFactor alphaFactor, wgpu::BlendFactor alphaFactor,
std::vector<std::pair<TriangleSpec, RGBA8>> tests) { std::vector<std::pair<TriangleSpec, RGBA8>> tests) {
CheckBlendFactor(base, dawn::BlendFactor::One, colorFactor, dawn::BlendFactor::One, CheckBlendFactor(base, wgpu::BlendFactor::One, colorFactor, wgpu::BlendFactor::One,
alphaFactor, tests); alphaFactor, tests);
} }
utils::BasicRenderPass renderPass; utils::BasicRenderPass renderPass;
dawn::RenderPipeline basePipeline; wgpu::RenderPipeline basePipeline;
dawn::RenderPipeline testPipeline; wgpu::RenderPipeline testPipeline;
dawn::ShaderModule vsModule; wgpu::ShaderModule vsModule;
dawn::BindGroupLayout bindGroupLayout; wgpu::BindGroupLayout bindGroupLayout;
dawn::PipelineLayout pipelineLayout; wgpu::PipelineLayout pipelineLayout;
}; };
namespace { namespace {
@ -291,14 +291,14 @@ namespace {
// Test compilation and usage of the fixture // Test compilation and usage of the fixture
TEST_P(ColorStateTest, Basic) { TEST_P(ColorStateTest, Basic) {
dawn::BlendDescriptor blend; wgpu::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add; blend.operation = wgpu::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One; blend.srcFactor = wgpu::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::Zero; blend.dstFactor = wgpu::BlendFactor::Zero;
dawn::ColorStateDescriptor descriptor; wgpu::ColorStateDescriptor descriptor;
descriptor.alphaBlend = blend; descriptor.alphaBlend = blend;
descriptor.colorBlend = blend; descriptor.colorBlend = blend;
descriptor.writeMask = dawn::ColorWriteMask::All; descriptor.writeMask = wgpu::ColorWriteMask::All;
SetupSingleSourcePipelines(descriptor); SetupSingleSourcePipelines(descriptor);
@ -311,7 +311,7 @@ TEST_P(ColorStateTest, BlendOperationAdd) {
std::vector<std::pair<RGBA8, RGBA8>> tests; std::vector<std::pair<RGBA8, RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests), std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, base + color); }); [&](const RGBA8& color) { return std::make_pair(color, base + color); });
CheckBlendOperation(base, dawn::BlendOperation::Add, tests); CheckBlendOperation(base, wgpu::BlendOperation::Add, tests);
} }
TEST_P(ColorStateTest, BlendOperationSubtract) { TEST_P(ColorStateTest, BlendOperationSubtract) {
@ -319,7 +319,7 @@ TEST_P(ColorStateTest, BlendOperationSubtract) {
std::vector<std::pair<RGBA8, RGBA8>> tests; std::vector<std::pair<RGBA8, RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests), std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, color - base); }); [&](const RGBA8& color) { return std::make_pair(color, color - base); });
CheckBlendOperation(base, dawn::BlendOperation::Subtract, tests); CheckBlendOperation(base, wgpu::BlendOperation::Subtract, tests);
} }
TEST_P(ColorStateTest, BlendOperationReverseSubtract) { TEST_P(ColorStateTest, BlendOperationReverseSubtract) {
@ -327,7 +327,7 @@ TEST_P(ColorStateTest, BlendOperationReverseSubtract) {
std::vector<std::pair<RGBA8, RGBA8>> tests; std::vector<std::pair<RGBA8, RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests), std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, base - color); }); [&](const RGBA8& color) { return std::make_pair(color, base - color); });
CheckBlendOperation(base, dawn::BlendOperation::ReverseSubtract, tests); CheckBlendOperation(base, wgpu::BlendOperation::ReverseSubtract, tests);
} }
TEST_P(ColorStateTest, BlendOperationMin) { TEST_P(ColorStateTest, BlendOperationMin) {
@ -335,7 +335,7 @@ TEST_P(ColorStateTest, BlendOperationMin) {
std::vector<std::pair<RGBA8, RGBA8>> tests; std::vector<std::pair<RGBA8, RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests), std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, min(base, color)); }); [&](const RGBA8& color) { return std::make_pair(color, min(base, color)); });
CheckBlendOperation(base, dawn::BlendOperation::Min, tests); CheckBlendOperation(base, wgpu::BlendOperation::Min, tests);
} }
TEST_P(ColorStateTest, BlendOperationMax) { TEST_P(ColorStateTest, BlendOperationMax) {
@ -343,7 +343,7 @@ TEST_P(ColorStateTest, BlendOperationMax) {
std::vector<std::pair<RGBA8, RGBA8>> tests; std::vector<std::pair<RGBA8, RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests), std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, max(base, color)); }); [&](const RGBA8& color) { return std::make_pair(color, max(base, color)); });
CheckBlendOperation(base, dawn::BlendOperation::Max, tests); CheckBlendOperation(base, wgpu::BlendOperation::Max, tests);
} }
// The following tests check that the Source blend factor works // The following tests check that the Source blend factor works
@ -353,7 +353,7 @@ TEST_P(ColorStateTest, SrcBlendFactorZero) {
std::transform( std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests), kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), base); }); [&](const RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), base); });
CheckSrcBlendFactor(base, dawn::BlendFactor::Zero, dawn::BlendFactor::Zero, tests); CheckSrcBlendFactor(base, wgpu::BlendFactor::Zero, wgpu::BlendFactor::Zero, tests);
} }
TEST_P(ColorStateTest, SrcBlendFactorOne) { TEST_P(ColorStateTest, SrcBlendFactorOne) {
@ -362,7 +362,7 @@ TEST_P(ColorStateTest, SrcBlendFactorOne) {
std::transform( std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests), kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), base + color); }); [&](const RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), base + color); });
CheckSrcBlendFactor(base, dawn::BlendFactor::One, dawn::BlendFactor::One, tests); CheckSrcBlendFactor(base, wgpu::BlendFactor::One, wgpu::BlendFactor::One, tests);
} }
TEST_P(ColorStateTest, SrcBlendFactorSrcColor) { TEST_P(ColorStateTest, SrcBlendFactorSrcColor) {
@ -375,7 +375,7 @@ TEST_P(ColorStateTest, SrcBlendFactorSrcColor) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac); RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckSrcBlendFactor(base, dawn::BlendFactor::SrcColor, dawn::BlendFactor::Zero, tests); CheckSrcBlendFactor(base, wgpu::BlendFactor::SrcColor, wgpu::BlendFactor::Zero, tests);
} }
TEST_P(ColorStateTest, SrcBlendFactorOneMinusSrcColor) { TEST_P(ColorStateTest, SrcBlendFactorOneMinusSrcColor) {
@ -388,7 +388,7 @@ TEST_P(ColorStateTest, SrcBlendFactorOneMinusSrcColor) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac); RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckSrcBlendFactor(base, dawn::BlendFactor::OneMinusSrcColor, dawn::BlendFactor::Zero, tests); CheckSrcBlendFactor(base, wgpu::BlendFactor::OneMinusSrcColor, wgpu::BlendFactor::Zero, tests);
} }
TEST_P(ColorStateTest, SrcBlendFactorSrcAlpha) { TEST_P(ColorStateTest, SrcBlendFactorSrcAlpha) {
@ -400,7 +400,7 @@ TEST_P(ColorStateTest, SrcBlendFactorSrcAlpha) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac); RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckSrcBlendFactor(base, dawn::BlendFactor::SrcAlpha, dawn::BlendFactor::SrcAlpha, tests); CheckSrcBlendFactor(base, wgpu::BlendFactor::SrcAlpha, wgpu::BlendFactor::SrcAlpha, tests);
} }
TEST_P(ColorStateTest, SrcBlendFactorOneMinusSrcAlpha) { TEST_P(ColorStateTest, SrcBlendFactorOneMinusSrcAlpha) {
@ -412,8 +412,8 @@ TEST_P(ColorStateTest, SrcBlendFactorOneMinusSrcAlpha) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac); RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckSrcBlendFactor(base, dawn::BlendFactor::OneMinusSrcAlpha, CheckSrcBlendFactor(base, wgpu::BlendFactor::OneMinusSrcAlpha,
dawn::BlendFactor::OneMinusSrcAlpha, tests); wgpu::BlendFactor::OneMinusSrcAlpha, tests);
} }
TEST_P(ColorStateTest, SrcBlendFactorDstColor) { TEST_P(ColorStateTest, SrcBlendFactorDstColor) {
@ -426,7 +426,7 @@ TEST_P(ColorStateTest, SrcBlendFactorDstColor) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac); RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckSrcBlendFactor(base, dawn::BlendFactor::DstColor, dawn::BlendFactor::Zero, tests); CheckSrcBlendFactor(base, wgpu::BlendFactor::DstColor, wgpu::BlendFactor::Zero, tests);
} }
TEST_P(ColorStateTest, SrcBlendFactorOneMinusDstColor) { TEST_P(ColorStateTest, SrcBlendFactorOneMinusDstColor) {
@ -439,7 +439,7 @@ TEST_P(ColorStateTest, SrcBlendFactorOneMinusDstColor) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac); RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckSrcBlendFactor(base, dawn::BlendFactor::OneMinusDstColor, dawn::BlendFactor::Zero, tests); CheckSrcBlendFactor(base, wgpu::BlendFactor::OneMinusDstColor, wgpu::BlendFactor::Zero, tests);
} }
TEST_P(ColorStateTest, SrcBlendFactorDstAlpha) { TEST_P(ColorStateTest, SrcBlendFactorDstAlpha) {
@ -451,7 +451,7 @@ TEST_P(ColorStateTest, SrcBlendFactorDstAlpha) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac); RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckSrcBlendFactor(base, dawn::BlendFactor::DstAlpha, dawn::BlendFactor::DstAlpha, tests); CheckSrcBlendFactor(base, wgpu::BlendFactor::DstAlpha, wgpu::BlendFactor::DstAlpha, tests);
} }
TEST_P(ColorStateTest, SrcBlendFactorOneMinusDstAlpha) { TEST_P(ColorStateTest, SrcBlendFactorOneMinusDstAlpha) {
@ -463,8 +463,8 @@ TEST_P(ColorStateTest, SrcBlendFactorOneMinusDstAlpha) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac); RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckSrcBlendFactor(base, dawn::BlendFactor::OneMinusDstAlpha, CheckSrcBlendFactor(base, wgpu::BlendFactor::OneMinusDstAlpha,
dawn::BlendFactor::OneMinusDstAlpha, tests); wgpu::BlendFactor::OneMinusDstAlpha, tests);
} }
TEST_P(ColorStateTest, SrcBlendFactorSrcAlphaSaturated) { TEST_P(ColorStateTest, SrcBlendFactorSrcAlphaSaturated) {
@ -477,8 +477,8 @@ TEST_P(ColorStateTest, SrcBlendFactorSrcAlphaSaturated) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac); RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckSrcBlendFactor(base, dawn::BlendFactor::SrcAlphaSaturated, CheckSrcBlendFactor(base, wgpu::BlendFactor::SrcAlphaSaturated,
dawn::BlendFactor::SrcAlphaSaturated, tests); wgpu::BlendFactor::SrcAlphaSaturated, tests);
} }
TEST_P(ColorStateTest, SrcBlendFactorBlendColor) { TEST_P(ColorStateTest, SrcBlendFactorBlendColor) {
@ -490,7 +490,7 @@ TEST_P(ColorStateTest, SrcBlendFactorBlendColor) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, triangleSpec.blendFactor); RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, triangleSpec.blendFactor);
return std::make_pair(triangleSpec, expected); return std::make_pair(triangleSpec, expected);
}); });
CheckSrcBlendFactor(base, dawn::BlendFactor::BlendColor, dawn::BlendFactor::BlendColor, tests); CheckSrcBlendFactor(base, wgpu::BlendFactor::BlendColor, wgpu::BlendFactor::BlendColor, tests);
} }
TEST_P(ColorStateTest, SrcBlendFactorOneMinusBlendColor) { TEST_P(ColorStateTest, SrcBlendFactorOneMinusBlendColor) {
@ -503,8 +503,8 @@ TEST_P(ColorStateTest, SrcBlendFactorOneMinusBlendColor) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, f); RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, f);
return std::make_pair(triangleSpec, expected); return std::make_pair(triangleSpec, expected);
}); });
CheckSrcBlendFactor(base, dawn::BlendFactor::OneMinusBlendColor, CheckSrcBlendFactor(base, wgpu::BlendFactor::OneMinusBlendColor,
dawn::BlendFactor::OneMinusBlendColor, tests); wgpu::BlendFactor::OneMinusBlendColor, tests);
} }
// The following tests check that the Destination blend factor works // The following tests check that the Destination blend factor works
@ -514,7 +514,7 @@ TEST_P(ColorStateTest, DstBlendFactorZero) {
std::transform( std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests), kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), color); }); [&](const RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), color); });
CheckDstBlendFactor(base, dawn::BlendFactor::Zero, dawn::BlendFactor::Zero, tests); CheckDstBlendFactor(base, wgpu::BlendFactor::Zero, wgpu::BlendFactor::Zero, tests);
} }
TEST_P(ColorStateTest, DstBlendFactorOne) { TEST_P(ColorStateTest, DstBlendFactorOne) {
@ -523,7 +523,7 @@ TEST_P(ColorStateTest, DstBlendFactorOne) {
std::transform( std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests), kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), base + color); }); [&](const RGBA8& color) { return std::make_pair(TriangleSpec({{color}}), base + color); });
CheckDstBlendFactor(base, dawn::BlendFactor::One, dawn::BlendFactor::One, tests); CheckDstBlendFactor(base, wgpu::BlendFactor::One, wgpu::BlendFactor::One, tests);
} }
TEST_P(ColorStateTest, DstBlendFactorSrcColor) { TEST_P(ColorStateTest, DstBlendFactorSrcColor) {
@ -536,7 +536,7 @@ TEST_P(ColorStateTest, DstBlendFactorSrcColor) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac); RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckDstBlendFactor(base, dawn::BlendFactor::SrcColor, dawn::BlendFactor::Zero, tests); CheckDstBlendFactor(base, wgpu::BlendFactor::SrcColor, wgpu::BlendFactor::Zero, tests);
} }
TEST_P(ColorStateTest, DstBlendFactorOneMinusSrcColor) { TEST_P(ColorStateTest, DstBlendFactorOneMinusSrcColor) {
@ -549,7 +549,7 @@ TEST_P(ColorStateTest, DstBlendFactorOneMinusSrcColor) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac); RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckDstBlendFactor(base, dawn::BlendFactor::OneMinusSrcColor, dawn::BlendFactor::Zero, tests); CheckDstBlendFactor(base, wgpu::BlendFactor::OneMinusSrcColor, wgpu::BlendFactor::Zero, tests);
} }
TEST_P(ColorStateTest, DstBlendFactorSrcAlpha) { TEST_P(ColorStateTest, DstBlendFactorSrcAlpha) {
@ -561,7 +561,7 @@ TEST_P(ColorStateTest, DstBlendFactorSrcAlpha) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac); RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckDstBlendFactor(base, dawn::BlendFactor::SrcAlpha, dawn::BlendFactor::SrcAlpha, tests); CheckDstBlendFactor(base, wgpu::BlendFactor::SrcAlpha, wgpu::BlendFactor::SrcAlpha, tests);
} }
TEST_P(ColorStateTest, DstBlendFactorOneMinusSrcAlpha) { TEST_P(ColorStateTest, DstBlendFactorOneMinusSrcAlpha) {
@ -573,8 +573,8 @@ TEST_P(ColorStateTest, DstBlendFactorOneMinusSrcAlpha) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac); RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckDstBlendFactor(base, dawn::BlendFactor::OneMinusSrcAlpha, CheckDstBlendFactor(base, wgpu::BlendFactor::OneMinusSrcAlpha,
dawn::BlendFactor::OneMinusSrcAlpha, tests); wgpu::BlendFactor::OneMinusSrcAlpha, tests);
} }
TEST_P(ColorStateTest, DstBlendFactorDstColor) { TEST_P(ColorStateTest, DstBlendFactorDstColor) {
@ -587,7 +587,7 @@ TEST_P(ColorStateTest, DstBlendFactorDstColor) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac); RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckDstBlendFactor(base, dawn::BlendFactor::DstColor, dawn::BlendFactor::Zero, tests); CheckDstBlendFactor(base, wgpu::BlendFactor::DstColor, wgpu::BlendFactor::Zero, tests);
} }
TEST_P(ColorStateTest, DstBlendFactorOneMinusDstColor) { TEST_P(ColorStateTest, DstBlendFactorOneMinusDstColor) {
@ -600,7 +600,7 @@ TEST_P(ColorStateTest, DstBlendFactorOneMinusDstColor) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac); RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckDstBlendFactor(base, dawn::BlendFactor::OneMinusDstColor, dawn::BlendFactor::Zero, tests); CheckDstBlendFactor(base, wgpu::BlendFactor::OneMinusDstColor, wgpu::BlendFactor::Zero, tests);
} }
TEST_P(ColorStateTest, DstBlendFactorDstAlpha) { TEST_P(ColorStateTest, DstBlendFactorDstAlpha) {
@ -612,7 +612,7 @@ TEST_P(ColorStateTest, DstBlendFactorDstAlpha) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac); RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckDstBlendFactor(base, dawn::BlendFactor::DstAlpha, dawn::BlendFactor::DstAlpha, tests); CheckDstBlendFactor(base, wgpu::BlendFactor::DstAlpha, wgpu::BlendFactor::DstAlpha, tests);
} }
TEST_P(ColorStateTest, DstBlendFactorOneMinusDstAlpha) { TEST_P(ColorStateTest, DstBlendFactorOneMinusDstAlpha) {
@ -624,8 +624,8 @@ TEST_P(ColorStateTest, DstBlendFactorOneMinusDstAlpha) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac); RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckDstBlendFactor(base, dawn::BlendFactor::OneMinusDstAlpha, CheckDstBlendFactor(base, wgpu::BlendFactor::OneMinusDstAlpha,
dawn::BlendFactor::OneMinusDstAlpha, tests); wgpu::BlendFactor::OneMinusDstAlpha, tests);
} }
TEST_P(ColorStateTest, DstBlendFactorSrcAlphaSaturated) { TEST_P(ColorStateTest, DstBlendFactorSrcAlphaSaturated) {
@ -638,8 +638,8 @@ TEST_P(ColorStateTest, DstBlendFactorSrcAlphaSaturated) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac); RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected); return std::make_pair(TriangleSpec({{color}}), expected);
}); });
CheckDstBlendFactor(base, dawn::BlendFactor::SrcAlphaSaturated, CheckDstBlendFactor(base, wgpu::BlendFactor::SrcAlphaSaturated,
dawn::BlendFactor::SrcAlphaSaturated, tests); wgpu::BlendFactor::SrcAlphaSaturated, tests);
} }
TEST_P(ColorStateTest, DstBlendFactorBlendColor) { TEST_P(ColorStateTest, DstBlendFactorBlendColor) {
@ -651,7 +651,7 @@ TEST_P(ColorStateTest, DstBlendFactorBlendColor) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, triangleSpec.blendFactor); RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, triangleSpec.blendFactor);
return std::make_pair(triangleSpec, expected); return std::make_pair(triangleSpec, expected);
}); });
CheckDstBlendFactor(base, dawn::BlendFactor::BlendColor, dawn::BlendFactor::BlendColor, tests); CheckDstBlendFactor(base, wgpu::BlendFactor::BlendColor, wgpu::BlendFactor::BlendColor, tests);
} }
TEST_P(ColorStateTest, DstBlendFactorOneMinusBlendColor) { TEST_P(ColorStateTest, DstBlendFactorOneMinusBlendColor) {
@ -664,23 +664,23 @@ TEST_P(ColorStateTest, DstBlendFactorOneMinusBlendColor) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, f); RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, f);
return std::make_pair(triangleSpec, expected); return std::make_pair(triangleSpec, expected);
}); });
CheckDstBlendFactor(base, dawn::BlendFactor::OneMinusBlendColor, CheckDstBlendFactor(base, wgpu::BlendFactor::OneMinusBlendColor,
dawn::BlendFactor::OneMinusBlendColor, tests); wgpu::BlendFactor::OneMinusBlendColor, tests);
} }
// Check that the color write mask works // Check that the color write mask works
TEST_P(ColorStateTest, ColorWriteMask) { TEST_P(ColorStateTest, ColorWriteMask) {
dawn::BlendDescriptor blend; wgpu::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add; blend.operation = wgpu::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One; blend.srcFactor = wgpu::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One; blend.dstFactor = wgpu::BlendFactor::One;
dawn::ColorStateDescriptor descriptor; wgpu::ColorStateDescriptor descriptor;
descriptor.colorBlend = blend; descriptor.colorBlend = blend;
descriptor.alphaBlend = blend; descriptor.alphaBlend = blend;
{ {
// Test single channel color write // Test single channel color write
descriptor.writeMask = dawn::ColorWriteMask::Red; descriptor.writeMask = wgpu::ColorWriteMask::Red;
SetupSingleSourcePipelines(descriptor); SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192); RGBA8 base(32, 64, 128, 192);
@ -692,7 +692,7 @@ TEST_P(ColorStateTest, ColorWriteMask) {
{ {
// Test multi channel color write // Test multi channel color write
descriptor.writeMask = dawn::ColorWriteMask::Green | dawn::ColorWriteMask::Alpha; descriptor.writeMask = wgpu::ColorWriteMask::Green | wgpu::ColorWriteMask::Alpha;
SetupSingleSourcePipelines(descriptor); SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192); RGBA8 base(32, 64, 128, 192);
@ -704,7 +704,7 @@ TEST_P(ColorStateTest, ColorWriteMask) {
{ {
// Test no channel color write // Test no channel color write
descriptor.writeMask = dawn::ColorWriteMask::None; descriptor.writeMask = wgpu::ColorWriteMask::None;
SetupSingleSourcePipelines(descriptor); SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192); RGBA8 base(32, 64, 128, 192);
@ -717,30 +717,30 @@ TEST_P(ColorStateTest, ColorWriteMask) {
// Check that the color write mask works when blending is disabled // Check that the color write mask works when blending is disabled
TEST_P(ColorStateTest, ColorWriteMaskBlendingDisabled) { TEST_P(ColorStateTest, ColorWriteMaskBlendingDisabled) {
{ {
dawn::BlendDescriptor blend; wgpu::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add; blend.operation = wgpu::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One; blend.srcFactor = wgpu::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::Zero; blend.dstFactor = wgpu::BlendFactor::Zero;
dawn::ColorStateDescriptor descriptor; wgpu::ColorStateDescriptor descriptor;
descriptor.alphaBlend = blend; descriptor.alphaBlend = blend;
descriptor.colorBlend = blend; descriptor.colorBlend = blend;
descriptor.writeMask = dawn::ColorWriteMask::Red; descriptor.writeMask = wgpu::ColorWriteMask::Red;
SetupSingleSourcePipelines(descriptor); SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192); RGBA8 base(32, 64, 128, 192);
RGBA8 expected(32, 0, 0, 0); RGBA8 expected(32, 0, 0, 0);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(testPipeline); pass.SetPipeline(testPipeline);
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({{base}}))); pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({{base}})));
pass.Draw(3, 1, 0, 0); pass.Draw(3, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(expected, renderPass.color, kRTSize / 2, kRTSize / 2); EXPECT_PIXEL_RGBA8_EQ(expected, renderPass.color, kRTSize / 2, kRTSize / 2);
} }
@ -750,19 +750,19 @@ TEST_P(ColorStateTest, ColorWriteMaskBlendingDisabled) {
TEST_P(ColorStateTest, IndependentColorState) { TEST_P(ColorStateTest, IndependentColorState) {
DAWN_SKIP_TEST_IF(IsWindows() && IsVulkan() && IsIntel()); DAWN_SKIP_TEST_IF(IsWindows() && IsVulkan() && IsIntel());
std::array<dawn::Texture, 4> renderTargets; std::array<wgpu::Texture, 4> renderTargets;
std::array<dawn::TextureView, 4> renderTargetViews; std::array<wgpu::TextureView, 4> renderTargetViews;
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kRTSize; descriptor.size.width = kRTSize;
descriptor.size.height = kRTSize; descriptor.size.height = kRTSize;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1; descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm; descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc; descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
for (uint32_t i = 0; i < 4; ++i) { for (uint32_t i = 0; i < 4; ++i) {
renderTargets[i] = device.CreateTexture(&descriptor); renderTargets[i] = device.CreateTexture(&descriptor);
@ -772,7 +772,7 @@ TEST_P(ColorStateTest, IndependentColorState) {
utils::ComboRenderPassDescriptor renderPass({renderTargetViews[0], renderTargetViews[1], utils::ComboRenderPassDescriptor renderPass({renderTargetViews[0], renderTargetViews[1],
renderTargetViews[2], renderTargetViews[3]}); renderTargetViews[2], renderTargetViews[3]});
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(set = 0, binding = 0) uniform myBlock { layout(set = 0, binding = 0) uniform myBlock {
@ -810,20 +810,20 @@ TEST_P(ColorStateTest, IndependentColorState) {
testDescriptor.colorStateCount = 4; testDescriptor.colorStateCount = 4;
// set color states // set color states
dawn::BlendDescriptor blend1; wgpu::BlendDescriptor blend1;
blend1.operation = dawn::BlendOperation::Add; blend1.operation = wgpu::BlendOperation::Add;
blend1.srcFactor = dawn::BlendFactor::One; blend1.srcFactor = wgpu::BlendFactor::One;
blend1.dstFactor = dawn::BlendFactor::One; blend1.dstFactor = wgpu::BlendFactor::One;
dawn::BlendDescriptor blend2; wgpu::BlendDescriptor blend2;
blend2.operation = dawn::BlendOperation::Subtract; blend2.operation = wgpu::BlendOperation::Subtract;
blend2.srcFactor = dawn::BlendFactor::One; blend2.srcFactor = wgpu::BlendFactor::One;
blend2.dstFactor = dawn::BlendFactor::One; blend2.dstFactor = wgpu::BlendFactor::One;
dawn::BlendDescriptor blend3; wgpu::BlendDescriptor blend3;
blend3.operation = dawn::BlendOperation::Min; blend3.operation = wgpu::BlendOperation::Min;
blend3.srcFactor = dawn::BlendFactor::One; blend3.srcFactor = wgpu::BlendFactor::One;
blend3.dstFactor = dawn::BlendFactor::One; blend3.dstFactor = wgpu::BlendFactor::One;
testDescriptor.cColorStates[0].colorBlend = blend1; testDescriptor.cColorStates[0].colorBlend = blend1;
testDescriptor.cColorStates[0].alphaBlend = blend1; testDescriptor.cColorStates[0].alphaBlend = blend1;
@ -848,9 +848,9 @@ TEST_P(ColorStateTest, IndependentColorState) {
RGBA8 expected2 = color2; RGBA8 expected2 = color2;
RGBA8 expected3 = min(color3, base); RGBA8 expected3 = min(color3, base);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
pass.SetPipeline(basePipeline); pass.SetPipeline(basePipeline);
pass.SetBindGroup( pass.SetBindGroup(
0, MakeBindGroupForColors(std::array<RGBA8, 4>({{base, base, base, base}}))); 0, MakeBindGroupForColors(std::array<RGBA8, 4>({{base, base, base, base}})));
@ -863,7 +863,7 @@ TEST_P(ColorStateTest, IndependentColorState) {
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(expected0, renderTargets[0], kRTSize / 2, kRTSize / 2) EXPECT_PIXEL_RGBA8_EQ(expected0, renderTargets[0], kRTSize / 2, kRTSize / 2)
@ -883,7 +883,7 @@ TEST_P(ColorStateTest, IndependentColorState) {
// Test that the default blend color is correctly set at the beginning of every subpass // Test that the default blend color is correctly set at the beginning of every subpass
TEST_P(ColorStateTest, DefaultBlendColor) { TEST_P(ColorStateTest, DefaultBlendColor) {
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(set = 0, binding = 0) uniform myBlock { layout(set = 0, binding = 0) uniform myBlock {
@ -911,21 +911,21 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
testDescriptor.cFragmentStage.module = fsModule; testDescriptor.cFragmentStage.module = fsModule;
testDescriptor.cColorStates[0].format = renderPass.colorFormat; testDescriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::BlendDescriptor blend; wgpu::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add; blend.operation = wgpu::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::BlendColor; blend.srcFactor = wgpu::BlendFactor::BlendColor;
blend.dstFactor = dawn::BlendFactor::One; blend.dstFactor = wgpu::BlendFactor::One;
testDescriptor.cColorStates[0].colorBlend = blend; testDescriptor.cColorStates[0].colorBlend = blend;
testDescriptor.cColorStates[0].alphaBlend = blend; testDescriptor.cColorStates[0].alphaBlend = blend;
testPipeline = device.CreateRenderPipeline(&testDescriptor); testPipeline = device.CreateRenderPipeline(&testDescriptor);
constexpr dawn::Color kWhite{1.0f, 1.0f, 1.0f, 1.0f}; constexpr wgpu::Color kWhite{1.0f, 1.0f, 1.0f, 1.0f};
// Check that the initial blend color is (0,0,0,0) // Check that the initial blend color is (0,0,0,0)
{ {
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(basePipeline); pass.SetPipeline(basePipeline);
pass.SetBindGroup(0, pass.SetBindGroup(0,
MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}}))); MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}})));
@ -937,7 +937,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, kRTSize / 2, kRTSize / 2); EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, kRTSize / 2, kRTSize / 2);
@ -945,9 +945,9 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
// Check that setting the blend color works // Check that setting the blend color works
{ {
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(basePipeline); pass.SetPipeline(basePipeline);
pass.SetBindGroup(0, pass.SetBindGroup(0,
MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}}))); MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}})));
@ -960,7 +960,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(255, 255, 255, 255), renderPass.color, kRTSize / 2, EXPECT_PIXEL_RGBA8_EQ(RGBA8(255, 255, 255, 255), renderPass.color, kRTSize / 2,
@ -969,9 +969,9 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
// Check that the blend color is not inherited between render passes // Check that the blend color is not inherited between render passes
{ {
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(basePipeline); pass.SetPipeline(basePipeline);
pass.SetBindGroup(0, pass.SetBindGroup(0,
MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}}))); MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}})));
@ -984,7 +984,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
pass.EndPass(); pass.EndPass();
} }
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(basePipeline); pass.SetPipeline(basePipeline);
pass.SetBindGroup(0, pass.SetBindGroup(0,
MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}}))); MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}})));
@ -996,7 +996,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, kRTSize / 2, kRTSize / 2); EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderPass.color, kRTSize / 2, kRTSize / 2);
@ -1007,7 +1007,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
// persisted and prevented a render pass loadOp from fully clearing the output // persisted and prevented a render pass loadOp from fully clearing the output
// attachment. // attachment.
TEST_P(ColorStateTest, ColorWriteMaskDoesNotAffectRenderPassLoadOpClear) { TEST_P(ColorStateTest, ColorWriteMaskDoesNotAffectRenderPassLoadOpClear) {
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(set = 0, binding = 0) uniform myBlock { layout(set = 0, binding = 0) uniform myBlock {
@ -1034,17 +1034,17 @@ TEST_P(ColorStateTest, ColorWriteMaskDoesNotAffectRenderPassLoadOpClear) {
testDescriptor.vertexStage.module = vsModule; testDescriptor.vertexStage.module = vsModule;
testDescriptor.cFragmentStage.module = fsModule; testDescriptor.cFragmentStage.module = fsModule;
testDescriptor.cColorStates[0].format = renderPass.colorFormat; testDescriptor.cColorStates[0].format = renderPass.colorFormat;
testDescriptor.cColorStates[0].writeMask = dawn::ColorWriteMask::Red; testDescriptor.cColorStates[0].writeMask = wgpu::ColorWriteMask::Red;
testPipeline = device.CreateRenderPipeline(&testDescriptor); testPipeline = device.CreateRenderPipeline(&testDescriptor);
RGBA8 base(32, 64, 128, 192); RGBA8 base(32, 64, 128, 192);
RGBA8 expected(0, 0, 0, 0); RGBA8 expected(0, 0, 0, 0);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
// Clear the output attachment to |base| // Clear the output attachment to |base|
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(basePipeline); pass.SetPipeline(basePipeline);
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({{base}}))); pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({{base}})));
pass.Draw(3, 1, 0, 0); pass.Draw(3, 1, 0, 0);
@ -1055,10 +1055,10 @@ TEST_P(ColorStateTest, ColorWriteMaskDoesNotAffectRenderPassLoadOpClear) {
} }
{ {
// This renderpass' loadOp should clear all channels of the output attachment // This renderpass' loadOp should clear all channels of the output attachment
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(expected, renderPass.color, kRTSize / 2, kRTSize / 2); EXPECT_PIXEL_RGBA8_EQ(expected, renderPass.color, kRTSize / 2, kRTSize / 2);

View File

@ -22,9 +22,9 @@
// The helper struct to configure the copies between buffers and textures. // The helper struct to configure the copies between buffers and textures.
struct CopyConfig { struct CopyConfig {
dawn::TextureDescriptor textureDescriptor; wgpu::TextureDescriptor textureDescriptor;
dawn::Extent3D copyExtent3D; wgpu::Extent3D copyExtent3D;
dawn::Origin3D copyOrigin3D = {0, 0, 0}; wgpu::Origin3D copyOrigin3D = {0, 0, 0};
uint32_t viewMipmapLevel = 0; uint32_t viewMipmapLevel = 0;
uint32_t viewArrayLayer = 0; uint32_t viewArrayLayer = 0;
uint32_t bufferOffset = 0; uint32_t bufferOffset = 0;
@ -37,8 +37,8 @@ class CompressedTextureBCFormatTest : public DawnTest {
void TestSetUp() override { void TestSetUp() override {
DawnTest::TestSetUp(); DawnTest::TestSetUp();
mBindGroupLayout = utils::MakeBindGroupLayout( mBindGroupLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::Sampler}, device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture}}); {1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture}});
} }
std::vector<const char*> GetRequiredExtensions() override { std::vector<const char*> GetRequiredExtensions() override {
@ -55,12 +55,12 @@ class CompressedTextureBCFormatTest : public DawnTest {
} }
// Copy the compressed texture data into the destination texture as is specified in copyConfig. // Copy the compressed texture data into the destination texture as is specified in copyConfig.
void InitializeDataInCompressedTexture(dawn::Texture bcCompressedTexture, void InitializeDataInCompressedTexture(wgpu::Texture bcCompressedTexture,
const CopyConfig& copyConfig) { const CopyConfig& copyConfig) {
ASSERT(IsBCFormatSupported()); ASSERT(IsBCFormatSupported());
// Compute the upload buffer size with rowPitchAlignment and the copy region. // Compute the upload buffer size with rowPitchAlignment and the copy region.
const dawn::Extent3D textureSize = copyConfig.textureDescriptor.size; const wgpu::Extent3D textureSize = copyConfig.textureDescriptor.size;
uint32_t actualWidthAtLevel = textureSize.width >> copyConfig.viewMipmapLevel; uint32_t actualWidthAtLevel = textureSize.width >> copyConfig.viewMipmapLevel;
uint32_t actualHeightAtLevel = textureSize.height >> copyConfig.viewMipmapLevel; uint32_t actualHeightAtLevel = textureSize.height >> copyConfig.viewMipmapLevel;
uint32_t copyWidthInBlockAtLevel = uint32_t copyWidthInBlockAtLevel =
@ -92,54 +92,54 @@ class CompressedTextureBCFormatTest : public DawnTest {
} }
// Copy texture data from a staging buffer to the destination texture. // Copy texture data from a staging buffer to the destination texture.
dawn::Buffer stagingBuffer = utils::CreateBufferFromData( wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, uploadData.data(), uploadBufferSize, dawn::BufferUsage::CopySrc); device, uploadData.data(), uploadBufferSize, wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(stagingBuffer, copyConfig.bufferOffset, utils::CreateBufferCopyView(stagingBuffer, copyConfig.bufferOffset,
copyConfig.rowPitchAlignment, copyConfig.imageHeight); copyConfig.rowPitchAlignment, copyConfig.imageHeight);
dawn::TextureCopyView textureCopyView = wgpu::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(bcCompressedTexture, copyConfig.viewMipmapLevel, utils::CreateTextureCopyView(bcCompressedTexture, copyConfig.viewMipmapLevel,
copyConfig.viewArrayLayer, copyConfig.copyOrigin3D); copyConfig.viewArrayLayer, copyConfig.copyOrigin3D);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copyConfig.copyExtent3D); encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copyConfig.copyExtent3D);
dawn::CommandBuffer copy = encoder.Finish(); wgpu::CommandBuffer copy = encoder.Finish();
queue.Submit(1, &copy); queue.Submit(1, &copy);
} }
// Create the bind group that includes a BC texture and a sampler. // Create the bind group that includes a BC texture and a sampler.
dawn::BindGroup CreateBindGroupForTest(dawn::Texture bcCompressedTexture, wgpu::BindGroup CreateBindGroupForTest(wgpu::Texture bcCompressedTexture,
dawn::TextureFormat bcFormat, wgpu::TextureFormat bcFormat,
uint32_t baseArrayLayer = 0, uint32_t baseArrayLayer = 0,
uint32_t baseMipLevel = 0) { uint32_t baseMipLevel = 0) {
ASSERT(IsBCFormatSupported()); ASSERT(IsBCFormatSupported());
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
samplerDesc.minFilter = dawn::FilterMode::Nearest; samplerDesc.minFilter = wgpu::FilterMode::Nearest;
samplerDesc.magFilter = dawn::FilterMode::Nearest; samplerDesc.magFilter = wgpu::FilterMode::Nearest;
dawn::Sampler sampler = device.CreateSampler(&samplerDesc); wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
dawn::TextureViewDescriptor textureViewDescriptor; wgpu::TextureViewDescriptor textureViewDescriptor;
textureViewDescriptor.format = bcFormat; textureViewDescriptor.format = bcFormat;
textureViewDescriptor.dimension = dawn::TextureViewDimension::e2D; textureViewDescriptor.dimension = wgpu::TextureViewDimension::e2D;
textureViewDescriptor.baseMipLevel = baseMipLevel; textureViewDescriptor.baseMipLevel = baseMipLevel;
textureViewDescriptor.baseArrayLayer = baseArrayLayer; textureViewDescriptor.baseArrayLayer = baseArrayLayer;
textureViewDescriptor.arrayLayerCount = 1; textureViewDescriptor.arrayLayerCount = 1;
textureViewDescriptor.mipLevelCount = 1; textureViewDescriptor.mipLevelCount = 1;
dawn::TextureView bcTextureView = bcCompressedTexture.CreateView(&textureViewDescriptor); wgpu::TextureView bcTextureView = bcCompressedTexture.CreateView(&textureViewDescriptor);
return utils::MakeBindGroup(device, mBindGroupLayout, {{0, sampler}, {1, bcTextureView}}); return utils::MakeBindGroup(device, mBindGroupLayout, {{0, sampler}, {1, bcTextureView}});
} }
// Create a render pipeline for sampling from a BC texture and rendering into the render target. // Create a render pipeline for sampling from a BC texture and rendering into the render target.
dawn::RenderPipeline CreateRenderPipelineForTest() { wgpu::RenderPipeline CreateRenderPipelineForTest() {
ASSERT(IsBCFormatSupported()); ASSERT(IsBCFormatSupported());
dawn::PipelineLayout pipelineLayout = wgpu::PipelineLayout pipelineLayout =
utils::MakeBasicPipelineLayout(device, &mBindGroupLayout); utils::MakeBasicPipelineLayout(device, &mBindGroupLayout);
utils::ComboRenderPipelineDescriptor renderPipelineDescriptor(device); utils::ComboRenderPipelineDescriptor renderPipelineDescriptor(device);
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
layout(location=0) out vec2 texCoord; layout(location=0) out vec2 texCoord;
@ -152,7 +152,7 @@ class CompressedTextureBCFormatTest : public DawnTest {
gl_Position = vec4(pos[gl_VertexIndex], 0.0f, 1.0f); gl_Position = vec4(pos[gl_VertexIndex], 0.0f, 1.0f);
texCoord = vec2(gl_Position.x / 2.0f, -gl_Position.y / 2.0f) + vec2(0.5f); texCoord = vec2(gl_Position.x / 2.0f, -gl_Position.y / 2.0f) + vec2(0.5f);
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(set = 0, binding = 0) uniform sampler sampler0; layout(set = 0, binding = 0) uniform sampler sampler0;
@ -172,11 +172,11 @@ class CompressedTextureBCFormatTest : public DawnTest {
} }
// Run the given render pipeline and bind group and verify the pixels in the render target. // Run the given render pipeline and bind group and verify the pixels in the render target.
void VerifyCompressedTexturePixelValues(dawn::RenderPipeline renderPipeline, void VerifyCompressedTexturePixelValues(wgpu::RenderPipeline renderPipeline,
dawn::BindGroup bindGroup, wgpu::BindGroup bindGroup,
const dawn::Extent3D& renderTargetSize, const wgpu::Extent3D& renderTargetSize,
const dawn::Origin3D& expectedOrigin, const wgpu::Origin3D& expectedOrigin,
const dawn::Extent3D& expectedExtent, const wgpu::Extent3D& expectedExtent,
const std::vector<RGBA8>& expected) { const std::vector<RGBA8>& expected) {
ASSERT(IsBCFormatSupported()); ASSERT(IsBCFormatSupported());
@ -184,16 +184,16 @@ class CompressedTextureBCFormatTest : public DawnTest {
utils::BasicRenderPass renderPass = utils::BasicRenderPass renderPass =
utils::CreateBasicRenderPass(device, renderTargetSize.width, renderTargetSize.height); utils::CreateBasicRenderPass(device, renderTargetSize.width, renderTargetSize.height);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(renderPipeline); pass.SetPipeline(renderPipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_TEXTURE_RGBA8_EQ(expected.data(), renderPass.color, expectedOrigin.x, EXPECT_TEXTURE_RGBA8_EQ(expected.data(), renderPass.color, expectedOrigin.x,
@ -206,19 +206,19 @@ class CompressedTextureBCFormatTest : public DawnTest {
void TestCopyRegionIntoBCFormatTextures(const CopyConfig& config) { void TestCopyRegionIntoBCFormatTextures(const CopyConfig& config) {
ASSERT(IsBCFormatSupported()); ASSERT(IsBCFormatSupported());
dawn::Texture bcTexture = CreateTextureWithCompressedData(config); wgpu::Texture bcTexture = CreateTextureWithCompressedData(config);
dawn::BindGroup bindGroup = wgpu::BindGroup bindGroup =
CreateBindGroupForTest(bcTexture, config.textureDescriptor.format, CreateBindGroupForTest(bcTexture, config.textureDescriptor.format,
config.viewArrayLayer, config.viewMipmapLevel); config.viewArrayLayer, config.viewMipmapLevel);
dawn::RenderPipeline renderPipeline = CreateRenderPipelineForTest(); wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest();
dawn::Extent3D virtualSizeAtLevel = GetVirtualSizeAtLevel(config); wgpu::Extent3D virtualSizeAtLevel = GetVirtualSizeAtLevel(config);
// The copy region may exceed the subresource size because of the required paddings for BC // The copy region may exceed the subresource size because of the required paddings for BC
// blocks, so we should limit the size of the expectedData to make it match the real size // blocks, so we should limit the size of the expectedData to make it match the real size
// of the render target. // of the render target.
dawn::Extent3D noPaddingExtent3D = config.copyExtent3D; wgpu::Extent3D noPaddingExtent3D = config.copyExtent3D;
if (config.copyOrigin3D.x + config.copyExtent3D.width > virtualSizeAtLevel.width) { if (config.copyOrigin3D.x + config.copyExtent3D.width > virtualSizeAtLevel.width) {
noPaddingExtent3D.width = virtualSizeAtLevel.width - config.copyOrigin3D.x; noPaddingExtent3D.width = virtualSizeAtLevel.width - config.copyOrigin3D.x;
} }
@ -233,59 +233,59 @@ class CompressedTextureBCFormatTest : public DawnTest {
} }
// Create a texture and initialize it with the pre-prepared compressed texture data. // Create a texture and initialize it with the pre-prepared compressed texture data.
dawn::Texture CreateTextureWithCompressedData(CopyConfig config) { wgpu::Texture CreateTextureWithCompressedData(CopyConfig config) {
dawn::Texture bcTexture = device.CreateTexture(&config.textureDescriptor); wgpu::Texture bcTexture = device.CreateTexture(&config.textureDescriptor);
InitializeDataInCompressedTexture(bcTexture, config); InitializeDataInCompressedTexture(bcTexture, config);
return bcTexture; return bcTexture;
} }
// Record a texture-to-texture copy command into command encoder without finishing the encoding. // Record a texture-to-texture copy command into command encoder without finishing the encoding.
void RecordTextureToTextureCopy(dawn::CommandEncoder encoder, void RecordTextureToTextureCopy(wgpu::CommandEncoder encoder,
dawn::Texture srcTexture, wgpu::Texture srcTexture,
dawn::Texture dstTexture, wgpu::Texture dstTexture,
CopyConfig srcConfig, CopyConfig srcConfig,
CopyConfig dstConfig) { CopyConfig dstConfig) {
dawn::TextureCopyView textureCopyViewSrc = wgpu::TextureCopyView textureCopyViewSrc =
utils::CreateTextureCopyView(srcTexture, srcConfig.viewMipmapLevel, utils::CreateTextureCopyView(srcTexture, srcConfig.viewMipmapLevel,
srcConfig.viewArrayLayer, srcConfig.copyOrigin3D); srcConfig.viewArrayLayer, srcConfig.copyOrigin3D);
dawn::TextureCopyView textureCopyViewDst = wgpu::TextureCopyView textureCopyViewDst =
utils::CreateTextureCopyView(dstTexture, dstConfig.viewMipmapLevel, utils::CreateTextureCopyView(dstTexture, dstConfig.viewMipmapLevel,
dstConfig.viewArrayLayer, dstConfig.copyOrigin3D); dstConfig.viewArrayLayer, dstConfig.copyOrigin3D);
encoder.CopyTextureToTexture(&textureCopyViewSrc, &textureCopyViewDst, encoder.CopyTextureToTexture(&textureCopyViewSrc, &textureCopyViewDst,
&dstConfig.copyExtent3D); &dstConfig.copyExtent3D);
} }
dawn::Texture CreateTextureFromTexture(dawn::Texture srcTexture, wgpu::Texture CreateTextureFromTexture(wgpu::Texture srcTexture,
CopyConfig srcConfig, CopyConfig srcConfig,
CopyConfig dstConfig) { CopyConfig dstConfig) {
dawn::Texture dstTexture = device.CreateTexture(&dstConfig.textureDescriptor); wgpu::Texture dstTexture = device.CreateTexture(&dstConfig.textureDescriptor);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
RecordTextureToTextureCopy(encoder, srcTexture, dstTexture, srcConfig, dstConfig); RecordTextureToTextureCopy(encoder, srcTexture, dstTexture, srcConfig, dstConfig);
dawn::CommandBuffer copy = encoder.Finish(); wgpu::CommandBuffer copy = encoder.Finish();
queue.Submit(1, &copy); queue.Submit(1, &copy);
return dstTexture; return dstTexture;
} }
// Return the BC block size in bytes. // Return the BC block size in bytes.
static uint32_t CompressedFormatBlockSizeInBytes(dawn::TextureFormat format) { static uint32_t CompressedFormatBlockSizeInBytes(wgpu::TextureFormat format) {
switch (format) { switch (format) {
case dawn::TextureFormat::BC1RGBAUnorm: case wgpu::TextureFormat::BC1RGBAUnorm:
case dawn::TextureFormat::BC1RGBAUnormSrgb: case wgpu::TextureFormat::BC1RGBAUnormSrgb:
case dawn::TextureFormat::BC4RSnorm: case wgpu::TextureFormat::BC4RSnorm:
case dawn::TextureFormat::BC4RUnorm: case wgpu::TextureFormat::BC4RUnorm:
return 8; return 8;
case dawn::TextureFormat::BC2RGBAUnorm: case wgpu::TextureFormat::BC2RGBAUnorm:
case dawn::TextureFormat::BC2RGBAUnormSrgb: case wgpu::TextureFormat::BC2RGBAUnormSrgb:
case dawn::TextureFormat::BC3RGBAUnorm: case wgpu::TextureFormat::BC3RGBAUnorm:
case dawn::TextureFormat::BC3RGBAUnormSrgb: case wgpu::TextureFormat::BC3RGBAUnormSrgb:
case dawn::TextureFormat::BC5RGSnorm: case wgpu::TextureFormat::BC5RGSnorm:
case dawn::TextureFormat::BC5RGUnorm: case wgpu::TextureFormat::BC5RGUnorm:
case dawn::TextureFormat::BC6HRGBSfloat: case wgpu::TextureFormat::BC6HRGBSfloat:
case dawn::TextureFormat::BC6HRGBUfloat: case wgpu::TextureFormat::BC6HRGBUfloat:
case dawn::TextureFormat::BC7RGBAUnorm: case wgpu::TextureFormat::BC7RGBAUnorm:
case dawn::TextureFormat::BC7RGBAUnormSrgb: case wgpu::TextureFormat::BC7RGBAUnormSrgb:
return 16; return 16;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -294,18 +294,18 @@ class CompressedTextureBCFormatTest : public DawnTest {
} }
// Return the pre-prepared one-block BC texture data. // Return the pre-prepared one-block BC texture data.
static std::vector<uint8_t> GetOneBlockBCFormatTextureData(dawn::TextureFormat bcFormat) { static std::vector<uint8_t> GetOneBlockBCFormatTextureData(wgpu::TextureFormat bcFormat) {
switch (bcFormat) { switch (bcFormat) {
// The expected data represents 4x4 pixel images with the left side dark red and the // The expected data represents 4x4 pixel images with the left side dark red and the
// right side dark green. We specify the same compressed data in both sRGB and non-sRGB // right side dark green. We specify the same compressed data in both sRGB and non-sRGB
// tests, but the rendering result should be different because for sRGB formats, the // tests, but the rendering result should be different because for sRGB formats, the
// red, green, and blue components are converted from an sRGB color space to a linear // red, green, and blue components are converted from an sRGB color space to a linear
// color space as part of filtering. // color space as part of filtering.
case dawn::TextureFormat::BC1RGBAUnorm: case wgpu::TextureFormat::BC1RGBAUnorm:
case dawn::TextureFormat::BC1RGBAUnormSrgb: case wgpu::TextureFormat::BC1RGBAUnormSrgb:
return {0x0, 0xC0, 0x60, 0x6, 0x50, 0x50, 0x50, 0x50}; return {0x0, 0xC0, 0x60, 0x6, 0x50, 0x50, 0x50, 0x50};
case dawn::TextureFormat::BC7RGBAUnorm: case wgpu::TextureFormat::BC7RGBAUnorm:
case dawn::TextureFormat::BC7RGBAUnormSrgb: case wgpu::TextureFormat::BC7RGBAUnormSrgb:
return {0x50, 0x18, 0xfc, 0xf, 0x0, 0x30, 0xe3, 0xe1, return {0x50, 0x18, 0xfc, 0xf, 0x0, 0x30, 0xe3, 0xe1,
0xe1, 0xe1, 0xc1, 0xf, 0xfc, 0xc0, 0xf, 0xfc}; 0xe1, 0xe1, 0xc1, 0xf, 0xfc, 0xc0, 0xf, 0xfc};
@ -315,34 +315,34 @@ class CompressedTextureBCFormatTest : public DawnTest {
// tests, but the rendering result should be different because for sRGB formats, the // tests, but the rendering result should be different because for sRGB formats, the
// red, green, and blue components are converted from an sRGB color space to a linear // red, green, and blue components are converted from an sRGB color space to a linear
// color space as part of filtering, and any alpha component is left unchanged. // color space as part of filtering, and any alpha component is left unchanged.
case dawn::TextureFormat::BC2RGBAUnorm: case wgpu::TextureFormat::BC2RGBAUnorm:
case dawn::TextureFormat::BC2RGBAUnormSrgb: case wgpu::TextureFormat::BC2RGBAUnormSrgb:
return {0x88, 0xFF, 0x88, 0xFF, 0x88, 0xFF, 0x88, 0xFF, return {0x88, 0xFF, 0x88, 0xFF, 0x88, 0xFF, 0x88, 0xFF,
0x0, 0xC0, 0x60, 0x6, 0x50, 0x50, 0x50, 0x50}; 0x0, 0xC0, 0x60, 0x6, 0x50, 0x50, 0x50, 0x50};
case dawn::TextureFormat::BC3RGBAUnorm: case wgpu::TextureFormat::BC3RGBAUnorm:
case dawn::TextureFormat::BC3RGBAUnormSrgb: case wgpu::TextureFormat::BC3RGBAUnormSrgb:
return {0x88, 0xFF, 0x40, 0x2, 0x24, 0x40, 0x2, 0x24, return {0x88, 0xFF, 0x40, 0x2, 0x24, 0x40, 0x2, 0x24,
0x0, 0xC0, 0x60, 0x6, 0x50, 0x50, 0x50, 0x50}; 0x0, 0xC0, 0x60, 0x6, 0x50, 0x50, 0x50, 0x50};
// The expected data represents 4x4 pixel images with the left side red and the // The expected data represents 4x4 pixel images with the left side red and the
// right side black. // right side black.
case dawn::TextureFormat::BC4RSnorm: case wgpu::TextureFormat::BC4RSnorm:
return {0x7F, 0x0, 0x40, 0x2, 0x24, 0x40, 0x2, 0x24}; return {0x7F, 0x0, 0x40, 0x2, 0x24, 0x40, 0x2, 0x24};
case dawn::TextureFormat::BC4RUnorm: case wgpu::TextureFormat::BC4RUnorm:
return {0xFF, 0x0, 0x40, 0x2, 0x24, 0x40, 0x2, 0x24}; return {0xFF, 0x0, 0x40, 0x2, 0x24, 0x40, 0x2, 0x24};
// The expected data represents 4x4 pixel images with the left side red and the right // The expected data represents 4x4 pixel images with the left side red and the right
// side green and was encoded with DirectXTex from Microsoft. // side green and was encoded with DirectXTex from Microsoft.
case dawn::TextureFormat::BC5RGSnorm: case wgpu::TextureFormat::BC5RGSnorm:
return {0x7f, 0x81, 0x40, 0x2, 0x24, 0x40, 0x2, 0x24, return {0x7f, 0x81, 0x40, 0x2, 0x24, 0x40, 0x2, 0x24,
0x7f, 0x81, 0x9, 0x90, 0x0, 0x9, 0x90, 0x0}; 0x7f, 0x81, 0x9, 0x90, 0x0, 0x9, 0x90, 0x0};
case dawn::TextureFormat::BC5RGUnorm: case wgpu::TextureFormat::BC5RGUnorm:
return {0xff, 0x0, 0x40, 0x2, 0x24, 0x40, 0x2, 0x24, return {0xff, 0x0, 0x40, 0x2, 0x24, 0x40, 0x2, 0x24,
0xff, 0x0, 0x9, 0x90, 0x0, 0x9, 0x90, 0x0}; 0xff, 0x0, 0x9, 0x90, 0x0, 0x9, 0x90, 0x0};
case dawn::TextureFormat::BC6HRGBSfloat: case wgpu::TextureFormat::BC6HRGBSfloat:
return {0xe3, 0x1f, 0x0, 0x0, 0x0, 0xe0, 0x1f, 0x0, return {0xe3, 0x1f, 0x0, 0x0, 0x0, 0xe0, 0x1f, 0x0,
0x0, 0xff, 0x0, 0xff, 0x0, 0xff, 0x0, 0xff}; 0x0, 0xff, 0x0, 0xff, 0x0, 0xff, 0x0, 0xff};
case dawn::TextureFormat::BC6HRGBUfloat: case wgpu::TextureFormat::BC6HRGBUfloat:
return {0xe3, 0x3d, 0x0, 0x0, 0x0, 0xe0, 0x3d, 0x0, return {0xe3, 0x3d, 0x0, 0x0, 0x0, 0xe0, 0x3d, 0x0,
0x0, 0xff, 0x0, 0xff, 0x0, 0xff, 0x0, 0xff}; 0x0, 0xff, 0x0, 0xff, 0x0, 0xff, 0x0, 0xff};
@ -354,8 +354,8 @@ class CompressedTextureBCFormatTest : public DawnTest {
// Return the texture data that is decoded from the result of GetOneBlockBCFormatTextureData in // Return the texture data that is decoded from the result of GetOneBlockBCFormatTextureData in
// RGBA8 formats. // RGBA8 formats.
static std::vector<RGBA8> GetExpectedData(dawn::TextureFormat bcFormat, static std::vector<RGBA8> GetExpectedData(wgpu::TextureFormat bcFormat,
const dawn::Extent3D& testRegion) { const wgpu::Extent3D& testRegion) {
constexpr RGBA8 kRed(255, 0, 0, 255); constexpr RGBA8 kRed(255, 0, 0, 255);
constexpr RGBA8 kGreen(0, 255, 0, 255); constexpr RGBA8 kGreen(0, 255, 0, 255);
constexpr RGBA8 kBlack(0, 0, 0, 255); constexpr RGBA8 kBlack(0, 0, 0, 255);
@ -368,36 +368,36 @@ class CompressedTextureBCFormatTest : public DawnTest {
constexpr uint8_t kRightAlpha = 0xFF; constexpr uint8_t kRightAlpha = 0xFF;
switch (bcFormat) { switch (bcFormat) {
case dawn::TextureFormat::BC1RGBAUnorm: case wgpu::TextureFormat::BC1RGBAUnorm:
case dawn::TextureFormat::BC7RGBAUnorm: case wgpu::TextureFormat::BC7RGBAUnorm:
return FillExpectedData(testRegion, kDarkRed, kDarkGreen); return FillExpectedData(testRegion, kDarkRed, kDarkGreen);
case dawn::TextureFormat::BC2RGBAUnorm: case wgpu::TextureFormat::BC2RGBAUnorm:
case dawn::TextureFormat::BC3RGBAUnorm: { case wgpu::TextureFormat::BC3RGBAUnorm: {
constexpr RGBA8 kLeftColor = RGBA8(kDarkRed.r, 0, 0, kLeftAlpha); constexpr RGBA8 kLeftColor = RGBA8(kDarkRed.r, 0, 0, kLeftAlpha);
constexpr RGBA8 kRightColor = RGBA8(0, kDarkGreen.g, 0, kRightAlpha); constexpr RGBA8 kRightColor = RGBA8(0, kDarkGreen.g, 0, kRightAlpha);
return FillExpectedData(testRegion, kLeftColor, kRightColor); return FillExpectedData(testRegion, kLeftColor, kRightColor);
} }
case dawn::TextureFormat::BC1RGBAUnormSrgb: case wgpu::TextureFormat::BC1RGBAUnormSrgb:
case dawn::TextureFormat::BC7RGBAUnormSrgb: case wgpu::TextureFormat::BC7RGBAUnormSrgb:
return FillExpectedData(testRegion, kDarkRedSRGB, kDarkGreenSRGB); return FillExpectedData(testRegion, kDarkRedSRGB, kDarkGreenSRGB);
case dawn::TextureFormat::BC2RGBAUnormSrgb: case wgpu::TextureFormat::BC2RGBAUnormSrgb:
case dawn::TextureFormat::BC3RGBAUnormSrgb: { case wgpu::TextureFormat::BC3RGBAUnormSrgb: {
constexpr RGBA8 kLeftColor = RGBA8(kDarkRedSRGB.r, 0, 0, kLeftAlpha); constexpr RGBA8 kLeftColor = RGBA8(kDarkRedSRGB.r, 0, 0, kLeftAlpha);
constexpr RGBA8 kRightColor = RGBA8(0, kDarkGreenSRGB.g, 0, kRightAlpha); constexpr RGBA8 kRightColor = RGBA8(0, kDarkGreenSRGB.g, 0, kRightAlpha);
return FillExpectedData(testRegion, kLeftColor, kRightColor); return FillExpectedData(testRegion, kLeftColor, kRightColor);
} }
case dawn::TextureFormat::BC4RSnorm: case wgpu::TextureFormat::BC4RSnorm:
case dawn::TextureFormat::BC4RUnorm: case wgpu::TextureFormat::BC4RUnorm:
return FillExpectedData(testRegion, kRed, kBlack); return FillExpectedData(testRegion, kRed, kBlack);
case dawn::TextureFormat::BC5RGSnorm: case wgpu::TextureFormat::BC5RGSnorm:
case dawn::TextureFormat::BC5RGUnorm: case wgpu::TextureFormat::BC5RGUnorm:
case dawn::TextureFormat::BC6HRGBSfloat: case wgpu::TextureFormat::BC6HRGBSfloat:
case dawn::TextureFormat::BC6HRGBUfloat: case wgpu::TextureFormat::BC6HRGBUfloat:
return FillExpectedData(testRegion, kRed, kGreen); return FillExpectedData(testRegion, kRed, kGreen);
default: default:
@ -406,7 +406,7 @@ class CompressedTextureBCFormatTest : public DawnTest {
} }
} }
static std::vector<RGBA8> FillExpectedData(const dawn::Extent3D& testRegion, static std::vector<RGBA8> FillExpectedData(const wgpu::Extent3D& testRegion,
RGBA8 leftColorInBlock, RGBA8 leftColorInBlock,
RGBA8 rightColorInBlock) { RGBA8 rightColorInBlock) {
ASSERT(testRegion.depth == 1); ASSERT(testRegion.depth == 1);
@ -422,13 +422,13 @@ class CompressedTextureBCFormatTest : public DawnTest {
return expectedData; return expectedData;
} }
static dawn::Extent3D GetVirtualSizeAtLevel(const CopyConfig& config) { static wgpu::Extent3D GetVirtualSizeAtLevel(const CopyConfig& config) {
return {config.textureDescriptor.size.width >> config.viewMipmapLevel, return {config.textureDescriptor.size.width >> config.viewMipmapLevel,
config.textureDescriptor.size.height >> config.viewMipmapLevel, 1}; config.textureDescriptor.size.height >> config.viewMipmapLevel, 1};
} }
static dawn::Extent3D GetPhysicalSizeAtLevel(const CopyConfig& config) { static wgpu::Extent3D GetPhysicalSizeAtLevel(const CopyConfig& config) {
dawn::Extent3D sizeAtLevel = GetVirtualSizeAtLevel(config); wgpu::Extent3D sizeAtLevel = GetVirtualSizeAtLevel(config);
sizeAtLevel.width = (sizeAtLevel.width + kBCBlockWidthInTexels - 1) / sizeAtLevel.width = (sizeAtLevel.width + kBCBlockWidthInTexels - 1) /
kBCBlockWidthInTexels * kBCBlockWidthInTexels; kBCBlockWidthInTexels * kBCBlockWidthInTexels;
sizeAtLevel.height = (sizeAtLevel.height + kBCBlockHeightInTexels - 1) / sizeAtLevel.height = (sizeAtLevel.height + kBCBlockHeightInTexels - 1) /
@ -436,23 +436,23 @@ class CompressedTextureBCFormatTest : public DawnTest {
return sizeAtLevel; return sizeAtLevel;
} }
const std::array<dawn::TextureFormat, 14> kBCFormats = { const std::array<wgpu::TextureFormat, 14> kBCFormats = {
dawn::TextureFormat::BC1RGBAUnorm, dawn::TextureFormat::BC1RGBAUnormSrgb, wgpu::TextureFormat::BC1RGBAUnorm, wgpu::TextureFormat::BC1RGBAUnormSrgb,
dawn::TextureFormat::BC2RGBAUnorm, dawn::TextureFormat::BC2RGBAUnormSrgb, wgpu::TextureFormat::BC2RGBAUnorm, wgpu::TextureFormat::BC2RGBAUnormSrgb,
dawn::TextureFormat::BC3RGBAUnorm, dawn::TextureFormat::BC3RGBAUnormSrgb, wgpu::TextureFormat::BC3RGBAUnorm, wgpu::TextureFormat::BC3RGBAUnormSrgb,
dawn::TextureFormat::BC4RSnorm, dawn::TextureFormat::BC4RUnorm, wgpu::TextureFormat::BC4RSnorm, wgpu::TextureFormat::BC4RUnorm,
dawn::TextureFormat::BC5RGSnorm, dawn::TextureFormat::BC5RGUnorm, wgpu::TextureFormat::BC5RGSnorm, wgpu::TextureFormat::BC5RGUnorm,
dawn::TextureFormat::BC6HRGBSfloat, dawn::TextureFormat::BC6HRGBUfloat, wgpu::TextureFormat::BC6HRGBSfloat, wgpu::TextureFormat::BC6HRGBUfloat,
dawn::TextureFormat::BC7RGBAUnorm, dawn::TextureFormat::BC7RGBAUnormSrgb}; wgpu::TextureFormat::BC7RGBAUnorm, wgpu::TextureFormat::BC7RGBAUnormSrgb};
// Tthe block width and height in texels are 4 for all BC formats. // Tthe block width and height in texels are 4 for all BC formats.
static constexpr uint32_t kBCBlockWidthInTexels = 4; static constexpr uint32_t kBCBlockWidthInTexels = 4;
static constexpr uint32_t kBCBlockHeightInTexels = 4; static constexpr uint32_t kBCBlockHeightInTexels = 4;
static constexpr dawn::TextureUsage kDefaultBCFormatTextureUsage = static constexpr wgpu::TextureUsage kDefaultBCFormatTextureUsage =
dawn::TextureUsage::Sampled | dawn::TextureUsage::CopyDst; wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopyDst;
dawn::BindGroupLayout mBindGroupLayout; wgpu::BindGroupLayout mBindGroupLayout;
bool mIsBCFormatSupported = false; bool mIsBCFormatSupported = false;
}; };
@ -473,7 +473,7 @@ TEST_P(CompressedTextureBCFormatTest, Basic) {
config.textureDescriptor.size = {8, 8, 1}; config.textureDescriptor.size = {8, 8, 1};
config.copyExtent3D = config.textureDescriptor.size; config.copyExtent3D = config.textureDescriptor.size;
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format; config.textureDescriptor.format = format;
TestCopyRegionIntoBCFormatTextures(config); TestCopyRegionIntoBCFormatTextures(config);
} }
@ -491,12 +491,12 @@ TEST_P(CompressedTextureBCFormatTest, CopyIntoSubRegion) {
config.textureDescriptor.usage = kDefaultBCFormatTextureUsage; config.textureDescriptor.usage = kDefaultBCFormatTextureUsage;
config.textureDescriptor.size = {8, 8, 1}; config.textureDescriptor.size = {8, 8, 1};
const dawn::Origin3D kOrigin = {4, 4, 0}; const wgpu::Origin3D kOrigin = {4, 4, 0};
const dawn::Extent3D kExtent3D = {4, 4, 1}; const wgpu::Extent3D kExtent3D = {4, 4, 1};
config.copyOrigin3D = kOrigin; config.copyOrigin3D = kOrigin;
config.copyExtent3D = kExtent3D; config.copyExtent3D = kExtent3D;
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format; config.textureDescriptor.format = format;
TestCopyRegionIntoBCFormatTextures(config); TestCopyRegionIntoBCFormatTextures(config);
} }
@ -520,7 +520,7 @@ TEST_P(CompressedTextureBCFormatTest, CopyWithZeroRowPitch) {
config.rowPitchAlignment = 0; config.rowPitchAlignment = 0;
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format; config.textureDescriptor.format = format;
config.textureDescriptor.size.width = kTextureRowPitchAlignment / config.textureDescriptor.size.width = kTextureRowPitchAlignment /
CompressedFormatBlockSizeInBytes(format) * CompressedFormatBlockSizeInBytes(format) *
@ -550,7 +550,7 @@ TEST_P(CompressedTextureBCFormatTest, CopyIntoNonZeroArrayLayer) {
config.textureDescriptor.arrayLayerCount = kArrayLayerCount; config.textureDescriptor.arrayLayerCount = kArrayLayerCount;
config.viewArrayLayer = kArrayLayerCount - 1; config.viewArrayLayer = kArrayLayerCount - 1;
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format; config.textureDescriptor.format = format;
TestCopyRegionIntoBCFormatTextures(config); TestCopyRegionIntoBCFormatTextures(config);
} }
@ -577,7 +577,7 @@ TEST_P(CompressedTextureBCFormatTest, CopyBufferIntoNonZeroMipmapLevel) {
// The actual size of the texture at mipmap level == 2 is not a multiple of 4, paddings are // The actual size of the texture at mipmap level == 2 is not a multiple of 4, paddings are
// required in the copies. // required in the copies.
const dawn::Extent3D textureSizeLevel0 = config.textureDescriptor.size; const wgpu::Extent3D textureSizeLevel0 = config.textureDescriptor.size;
const uint32_t kActualWidthAtLevel = textureSizeLevel0.width >> config.viewMipmapLevel; const uint32_t kActualWidthAtLevel = textureSizeLevel0.width >> config.viewMipmapLevel;
const uint32_t kActualHeightAtLevel = textureSizeLevel0.height >> config.viewMipmapLevel; const uint32_t kActualHeightAtLevel = textureSizeLevel0.height >> config.viewMipmapLevel;
ASSERT(kActualWidthAtLevel % kBCBlockWidthInTexels != 0); ASSERT(kActualWidthAtLevel % kBCBlockWidthInTexels != 0);
@ -590,7 +590,7 @@ TEST_P(CompressedTextureBCFormatTest, CopyBufferIntoNonZeroMipmapLevel) {
config.copyExtent3D = {kCopyWidthAtLevel, kCopyHeightAtLevel, 1}; config.copyExtent3D = {kCopyWidthAtLevel, kCopyHeightAtLevel, 1};
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format; config.textureDescriptor.format = format;
TestCopyRegionIntoBCFormatTextures(config); TestCopyRegionIntoBCFormatTextures(config);
} }
@ -621,30 +621,30 @@ TEST_P(CompressedTextureBCFormatTest, CopyWholeTextureSubResourceIntoNonZeroMipm
// The actual size of the texture at mipmap level == 2 is not a multiple of 4, paddings are // The actual size of the texture at mipmap level == 2 is not a multiple of 4, paddings are
// required in the copies. // required in the copies.
const dawn::Extent3D kVirtualSize = GetVirtualSizeAtLevel(config); const wgpu::Extent3D kVirtualSize = GetVirtualSizeAtLevel(config);
const dawn::Extent3D kPhysicalSize = GetPhysicalSizeAtLevel(config); const wgpu::Extent3D kPhysicalSize = GetPhysicalSizeAtLevel(config);
ASSERT_NE(0u, kVirtualSize.width % kBCBlockWidthInTexels); ASSERT_NE(0u, kVirtualSize.width % kBCBlockWidthInTexels);
ASSERT_NE(0u, kVirtualSize.height % kBCBlockHeightInTexels); ASSERT_NE(0u, kVirtualSize.height % kBCBlockHeightInTexels);
config.copyExtent3D = kPhysicalSize; config.copyExtent3D = kPhysicalSize;
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
// Create bcTextureSrc as the source texture and initialize it with pre-prepared BC // Create bcTextureSrc as the source texture and initialize it with pre-prepared BC
// compressed data. // compressed data.
config.textureDescriptor.format = format; config.textureDescriptor.format = format;
// Add the usage bit for both source and destination textures so that we don't need to // Add the usage bit for both source and destination textures so that we don't need to
// create two copy configs. // create two copy configs.
config.textureDescriptor.usage = config.textureDescriptor.usage =
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst | dawn::TextureUsage::Sampled; wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled;
dawn::Texture bcTextureSrc = CreateTextureWithCompressedData(config); wgpu::Texture bcTextureSrc = CreateTextureWithCompressedData(config);
// Create bcTexture and copy from the content in bcTextureSrc into it. // Create bcTexture and copy from the content in bcTextureSrc into it.
dawn::Texture bcTextureDst = CreateTextureFromTexture(bcTextureSrc, config, config); wgpu::Texture bcTextureDst = CreateTextureFromTexture(bcTextureSrc, config, config);
// Verify if we can use bcTexture as sampled textures correctly. // Verify if we can use bcTexture as sampled textures correctly.
dawn::BindGroup bindGroup = CreateBindGroupForTest( wgpu::BindGroup bindGroup = CreateBindGroupForTest(
bcTextureDst, format, config.viewArrayLayer, config.viewMipmapLevel); bcTextureDst, format, config.viewArrayLayer, config.viewMipmapLevel);
dawn::RenderPipeline renderPipeline = CreateRenderPipelineForTest(); wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest();
std::vector<RGBA8> expectedData = GetExpectedData(format, kVirtualSize); std::vector<RGBA8> expectedData = GetExpectedData(format, kVirtualSize);
VerifyCompressedTexturePixelValues(renderPipeline, bindGroup, kVirtualSize, VerifyCompressedTexturePixelValues(renderPipeline, bindGroup, kVirtualSize,
@ -669,7 +669,7 @@ TEST_P(CompressedTextureBCFormatTest, CopyIntoSubresourceWithPhysicalSizeNotEqua
srcConfig.textureDescriptor.size = {60, 60, 1}; srcConfig.textureDescriptor.size = {60, 60, 1};
srcConfig.viewMipmapLevel = srcConfig.textureDescriptor.mipLevelCount - 1; srcConfig.viewMipmapLevel = srcConfig.textureDescriptor.mipLevelCount - 1;
const dawn::Extent3D kSrcVirtualSize = GetVirtualSizeAtLevel(srcConfig); const wgpu::Extent3D kSrcVirtualSize = GetVirtualSizeAtLevel(srcConfig);
CopyConfig dstConfig; CopyConfig dstConfig;
dstConfig.textureDescriptor.size = {60, 60, 1}; dstConfig.textureDescriptor.size = {60, 60, 1};
@ -679,36 +679,36 @@ TEST_P(CompressedTextureBCFormatTest, CopyIntoSubresourceWithPhysicalSizeNotEqua
// The actual size of the texture at mipmap level == 2 is not a multiple of 4, paddings are // The actual size of the texture at mipmap level == 2 is not a multiple of 4, paddings are
// required in the copies. // required in the copies.
const dawn::Extent3D kDstVirtualSize = GetVirtualSizeAtLevel(dstConfig); const wgpu::Extent3D kDstVirtualSize = GetVirtualSizeAtLevel(dstConfig);
ASSERT_NE(0u, kDstVirtualSize.width % kBCBlockWidthInTexels); ASSERT_NE(0u, kDstVirtualSize.width % kBCBlockWidthInTexels);
ASSERT_NE(0u, kDstVirtualSize.height % kBCBlockHeightInTexels); ASSERT_NE(0u, kDstVirtualSize.height % kBCBlockHeightInTexels);
const dawn::Extent3D kDstPhysicalSize = GetPhysicalSizeAtLevel(dstConfig); const wgpu::Extent3D kDstPhysicalSize = GetPhysicalSizeAtLevel(dstConfig);
srcConfig.copyExtent3D = dstConfig.copyExtent3D = kDstPhysicalSize; srcConfig.copyExtent3D = dstConfig.copyExtent3D = kDstPhysicalSize;
ASSERT_LT(srcConfig.copyOrigin3D.x + srcConfig.copyExtent3D.width, kSrcVirtualSize.width); ASSERT_LT(srcConfig.copyOrigin3D.x + srcConfig.copyExtent3D.width, kSrcVirtualSize.width);
ASSERT_LT(srcConfig.copyOrigin3D.y + srcConfig.copyExtent3D.height, kSrcVirtualSize.height); ASSERT_LT(srcConfig.copyOrigin3D.y + srcConfig.copyExtent3D.height, kSrcVirtualSize.height);
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
// Create bcTextureSrc as the source texture and initialize it with pre-prepared BC // Create bcTextureSrc as the source texture and initialize it with pre-prepared BC
// compressed data. // compressed data.
srcConfig.textureDescriptor.format = format; srcConfig.textureDescriptor.format = format;
srcConfig.textureDescriptor.usage = srcConfig.textureDescriptor.usage =
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst; wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst;
dawn::Texture bcTextureSrc = CreateTextureWithCompressedData(srcConfig); wgpu::Texture bcTextureSrc = CreateTextureWithCompressedData(srcConfig);
dawn::TextureCopyView textureCopyViewSrc = wgpu::TextureCopyView textureCopyViewSrc =
utils::CreateTextureCopyView(bcTextureSrc, srcConfig.viewMipmapLevel, utils::CreateTextureCopyView(bcTextureSrc, srcConfig.viewMipmapLevel,
srcConfig.viewArrayLayer, srcConfig.copyOrigin3D); srcConfig.viewArrayLayer, srcConfig.copyOrigin3D);
// Create bcTexture and copy from the content in bcTextureSrc into it. // Create bcTexture and copy from the content in bcTextureSrc into it.
dstConfig.textureDescriptor.format = format; dstConfig.textureDescriptor.format = format;
dstConfig.textureDescriptor.usage = kDefaultBCFormatTextureUsage; dstConfig.textureDescriptor.usage = kDefaultBCFormatTextureUsage;
dawn::Texture bcTextureDst = CreateTextureFromTexture(bcTextureSrc, srcConfig, dstConfig); wgpu::Texture bcTextureDst = CreateTextureFromTexture(bcTextureSrc, srcConfig, dstConfig);
// Verify if we can use bcTexture as sampled textures correctly. // Verify if we can use bcTexture as sampled textures correctly.
dawn::BindGroup bindGroup = CreateBindGroupForTest( wgpu::BindGroup bindGroup = CreateBindGroupForTest(
bcTextureDst, format, dstConfig.viewArrayLayer, dstConfig.viewMipmapLevel); bcTextureDst, format, dstConfig.viewArrayLayer, dstConfig.viewMipmapLevel);
dawn::RenderPipeline renderPipeline = CreateRenderPipelineForTest(); wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest();
std::vector<RGBA8> expectedData = GetExpectedData(format, kDstVirtualSize); std::vector<RGBA8> expectedData = GetExpectedData(format, kDstVirtualSize);
VerifyCompressedTexturePixelValues(renderPipeline, bindGroup, kDstVirtualSize, VerifyCompressedTexturePixelValues(renderPipeline, bindGroup, kDstVirtualSize,
@ -737,7 +737,7 @@ TEST_P(CompressedTextureBCFormatTest, CopyFromSubresourceWithPhysicalSizeNotEqua
// The actual size of the texture at mipmap level == 2 is not a multiple of 4, paddings are // The actual size of the texture at mipmap level == 2 is not a multiple of 4, paddings are
// required in the copies. // required in the copies.
const dawn::Extent3D kSrcVirtualSize = GetVirtualSizeAtLevel(srcConfig); const wgpu::Extent3D kSrcVirtualSize = GetVirtualSizeAtLevel(srcConfig);
ASSERT_NE(0u, kSrcVirtualSize.width % kBCBlockWidthInTexels); ASSERT_NE(0u, kSrcVirtualSize.width % kBCBlockWidthInTexels);
ASSERT_NE(0u, kSrcVirtualSize.height % kBCBlockHeightInTexels); ASSERT_NE(0u, kSrcVirtualSize.height % kBCBlockHeightInTexels);
@ -745,29 +745,29 @@ TEST_P(CompressedTextureBCFormatTest, CopyFromSubresourceWithPhysicalSizeNotEqua
dstConfig.textureDescriptor.size = {16, 16, 1}; dstConfig.textureDescriptor.size = {16, 16, 1};
dstConfig.viewMipmapLevel = dstConfig.textureDescriptor.mipLevelCount - 1; dstConfig.viewMipmapLevel = dstConfig.textureDescriptor.mipLevelCount - 1;
const dawn::Extent3D kDstVirtualSize = GetVirtualSizeAtLevel(dstConfig); const wgpu::Extent3D kDstVirtualSize = GetVirtualSizeAtLevel(dstConfig);
srcConfig.copyExtent3D = dstConfig.copyExtent3D = kDstVirtualSize; srcConfig.copyExtent3D = dstConfig.copyExtent3D = kDstVirtualSize;
ASSERT_GT(srcConfig.copyOrigin3D.x + srcConfig.copyExtent3D.width, kSrcVirtualSize.width); ASSERT_GT(srcConfig.copyOrigin3D.x + srcConfig.copyExtent3D.width, kSrcVirtualSize.width);
ASSERT_GT(srcConfig.copyOrigin3D.y + srcConfig.copyExtent3D.height, kSrcVirtualSize.height); ASSERT_GT(srcConfig.copyOrigin3D.y + srcConfig.copyExtent3D.height, kSrcVirtualSize.height);
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
srcConfig.textureDescriptor.format = dstConfig.textureDescriptor.format = format; srcConfig.textureDescriptor.format = dstConfig.textureDescriptor.format = format;
srcConfig.textureDescriptor.usage = srcConfig.textureDescriptor.usage =
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst; wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst;
dstConfig.textureDescriptor.usage = kDefaultBCFormatTextureUsage; dstConfig.textureDescriptor.usage = kDefaultBCFormatTextureUsage;
// Create bcTextureSrc as the source texture and initialize it with pre-prepared BC // Create bcTextureSrc as the source texture and initialize it with pre-prepared BC
// compressed data. // compressed data.
dawn::Texture bcTextureSrc = CreateTextureWithCompressedData(srcConfig); wgpu::Texture bcTextureSrc = CreateTextureWithCompressedData(srcConfig);
// Create bcTexture and copy from the content in bcTextureSrc into it. // Create bcTexture and copy from the content in bcTextureSrc into it.
dawn::Texture bcTextureDst = CreateTextureFromTexture(bcTextureSrc, srcConfig, dstConfig); wgpu::Texture bcTextureDst = CreateTextureFromTexture(bcTextureSrc, srcConfig, dstConfig);
// Verify if we can use bcTexture as sampled textures correctly. // Verify if we can use bcTexture as sampled textures correctly.
dawn::BindGroup bindGroup = CreateBindGroupForTest( wgpu::BindGroup bindGroup = CreateBindGroupForTest(
bcTextureDst, format, dstConfig.viewArrayLayer, dstConfig.viewMipmapLevel); bcTextureDst, format, dstConfig.viewArrayLayer, dstConfig.viewMipmapLevel);
dawn::RenderPipeline renderPipeline = CreateRenderPipelineForTest(); wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest();
std::vector<RGBA8> expectedData = GetExpectedData(format, kDstVirtualSize); std::vector<RGBA8> expectedData = GetExpectedData(format, kDstVirtualSize);
VerifyCompressedTexturePixelValues(renderPipeline, bindGroup, kDstVirtualSize, VerifyCompressedTexturePixelValues(renderPipeline, bindGroup, kDstVirtualSize,
@ -799,7 +799,7 @@ TEST_P(CompressedTextureBCFormatTest, MultipleCopiesWithPhysicalSizeNotEqualToVi
dstConfigs[0].textureDescriptor.size = {16, 16, 1}; dstConfigs[0].textureDescriptor.size = {16, 16, 1};
dstConfigs[0].viewMipmapLevel = dstConfigs[0].textureDescriptor.mipLevelCount - 1; dstConfigs[0].viewMipmapLevel = dstConfigs[0].textureDescriptor.mipLevelCount - 1;
srcConfigs[0].copyExtent3D = dstConfigs[0].copyExtent3D = GetVirtualSizeAtLevel(dstConfigs[0]); srcConfigs[0].copyExtent3D = dstConfigs[0].copyExtent3D = GetVirtualSizeAtLevel(dstConfigs[0]);
const dawn::Extent3D kSrcVirtualSize0 = GetVirtualSizeAtLevel(srcConfigs[0]); const wgpu::Extent3D kSrcVirtualSize0 = GetVirtualSizeAtLevel(srcConfigs[0]);
ASSERT_NE(0u, kSrcVirtualSize0.width % kBCBlockWidthInTexels); ASSERT_NE(0u, kSrcVirtualSize0.width % kBCBlockWidthInTexels);
ASSERT_NE(0u, kSrcVirtualSize0.height % kBCBlockHeightInTexels); ASSERT_NE(0u, kSrcVirtualSize0.height % kBCBlockHeightInTexels);
@ -811,23 +811,23 @@ TEST_P(CompressedTextureBCFormatTest, MultipleCopiesWithPhysicalSizeNotEqualToVi
dstConfigs[1].viewMipmapLevel = dstConfigs[1].textureDescriptor.mipLevelCount - 1; dstConfigs[1].viewMipmapLevel = dstConfigs[1].textureDescriptor.mipLevelCount - 1;
srcConfigs[1].copyExtent3D = dstConfigs[1].copyExtent3D = GetVirtualSizeAtLevel(srcConfigs[1]); srcConfigs[1].copyExtent3D = dstConfigs[1].copyExtent3D = GetVirtualSizeAtLevel(srcConfigs[1]);
std::array<dawn::Extent3D, kTotalCopyCount> dstVirtualSizes; std::array<wgpu::Extent3D, kTotalCopyCount> dstVirtualSizes;
for (uint32_t i = 0; i < kTotalCopyCount; ++i) { for (uint32_t i = 0; i < kTotalCopyCount; ++i) {
dstVirtualSizes[i] = GetVirtualSizeAtLevel(dstConfigs[i]); dstVirtualSizes[i] = GetVirtualSizeAtLevel(dstConfigs[i]);
} }
ASSERT_NE(0u, dstVirtualSizes[1].width % kBCBlockWidthInTexels); ASSERT_NE(0u, dstVirtualSizes[1].width % kBCBlockWidthInTexels);
ASSERT_NE(0u, dstVirtualSizes[1].height % kBCBlockHeightInTexels); ASSERT_NE(0u, dstVirtualSizes[1].height % kBCBlockHeightInTexels);
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
std::array<dawn::Texture, kTotalCopyCount> bcSrcTextures; std::array<wgpu::Texture, kTotalCopyCount> bcSrcTextures;
std::array<dawn::Texture, kTotalCopyCount> bcDstTextures; std::array<wgpu::Texture, kTotalCopyCount> bcDstTextures;
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
for (uint32_t i = 0; i < kTotalCopyCount; ++i) { for (uint32_t i = 0; i < kTotalCopyCount; ++i) {
srcConfigs[i].textureDescriptor.format = dstConfigs[i].textureDescriptor.format = srcConfigs[i].textureDescriptor.format = dstConfigs[i].textureDescriptor.format =
format; format;
srcConfigs[i].textureDescriptor.usage = srcConfigs[i].textureDescriptor.usage =
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst; wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst;
dstConfigs[i].textureDescriptor.usage = kDefaultBCFormatTextureUsage; dstConfigs[i].textureDescriptor.usage = kDefaultBCFormatTextureUsage;
// Create bcSrcTextures as the source textures and initialize them with pre-prepared BC // Create bcSrcTextures as the source textures and initialize them with pre-prepared BC
@ -839,14 +839,14 @@ TEST_P(CompressedTextureBCFormatTest, MultipleCopiesWithPhysicalSizeNotEqualToVi
dstConfigs[i]); dstConfigs[i]);
} }
dawn::CommandBuffer commandBuffer = encoder.Finish(); wgpu::CommandBuffer commandBuffer = encoder.Finish();
queue.Submit(1, &commandBuffer); queue.Submit(1, &commandBuffer);
dawn::RenderPipeline renderPipeline = CreateRenderPipelineForTest(); wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest();
for (uint32_t i = 0; i < kTotalCopyCount; ++i) { for (uint32_t i = 0; i < kTotalCopyCount; ++i) {
// Verify if we can use bcDstTextures as sampled textures correctly. // Verify if we can use bcDstTextures as sampled textures correctly.
dawn::BindGroup bindGroup0 = wgpu::BindGroup bindGroup0 =
CreateBindGroupForTest(bcDstTextures[i], format, dstConfigs[i].viewArrayLayer, CreateBindGroupForTest(bcDstTextures[i], format, dstConfigs[i].viewArrayLayer,
dstConfigs[i].viewMipmapLevel); dstConfigs[i].viewMipmapLevel);
@ -877,7 +877,7 @@ TEST_P(CompressedTextureBCFormatTest, BufferOffsetAndExtentFitRowPitch) {
const uint32_t blockCountPerRow = config.textureDescriptor.size.width / kBCBlockWidthInTexels; const uint32_t blockCountPerRow = config.textureDescriptor.size.width / kBCBlockWidthInTexels;
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format; config.textureDescriptor.format = format;
const uint32_t blockSizeInBytes = CompressedFormatBlockSizeInBytes(format); const uint32_t blockSizeInBytes = CompressedFormatBlockSizeInBytes(format);
@ -908,12 +908,12 @@ TEST_P(CompressedTextureBCFormatTest, BufferOffsetExceedsSlicePitch) {
config.textureDescriptor.size = {8, 8, 1}; config.textureDescriptor.size = {8, 8, 1};
config.copyExtent3D = config.textureDescriptor.size; config.copyExtent3D = config.textureDescriptor.size;
const dawn::Extent3D textureSizeLevel0 = config.textureDescriptor.size; const wgpu::Extent3D textureSizeLevel0 = config.textureDescriptor.size;
const uint32_t blockCountPerRow = textureSizeLevel0.width / kBCBlockWidthInTexels; const uint32_t blockCountPerRow = textureSizeLevel0.width / kBCBlockWidthInTexels;
const uint32_t slicePitchInBytes = const uint32_t slicePitchInBytes =
config.rowPitchAlignment * (textureSizeLevel0.height / kBCBlockHeightInTexels); config.rowPitchAlignment * (textureSizeLevel0.height / kBCBlockHeightInTexels);
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format; config.textureDescriptor.format = format;
const uint32_t blockSizeInBytes = CompressedFormatBlockSizeInBytes(format); const uint32_t blockSizeInBytes = CompressedFormatBlockSizeInBytes(format);
@ -947,7 +947,7 @@ TEST_P(CompressedTextureBCFormatTest, CopyWithBufferOffsetAndExtentExceedRowPitc
constexpr uint32_t kExceedRowBlockCount = 1; constexpr uint32_t kExceedRowBlockCount = 1;
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format; config.textureDescriptor.format = format;
const uint32_t blockSizeInBytes = CompressedFormatBlockSizeInBytes(format); const uint32_t blockSizeInBytes = CompressedFormatBlockSizeInBytes(format);
@ -977,7 +977,7 @@ TEST_P(CompressedTextureBCFormatTest, RowPitchEqualToSlicePitch) {
const uint32_t blockCountPerRow = config.textureDescriptor.size.width / kBCBlockWidthInTexels; const uint32_t blockCountPerRow = config.textureDescriptor.size.width / kBCBlockWidthInTexels;
const uint32_t slicePitchInBytes = config.rowPitchAlignment; const uint32_t slicePitchInBytes = config.rowPitchAlignment;
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format; config.textureDescriptor.format = format;
const uint32_t blockSizeInBytes = CompressedFormatBlockSizeInBytes(format); const uint32_t blockSizeInBytes = CompressedFormatBlockSizeInBytes(format);
@ -1010,7 +1010,7 @@ TEST_P(CompressedTextureBCFormatTest, LargeImageHeight) {
config.imageHeight = config.textureDescriptor.size.height * 2; config.imageHeight = config.textureDescriptor.size.height * 2;
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format; config.textureDescriptor.format = format;
TestCopyRegionIntoBCFormatTextures(config); TestCopyRegionIntoBCFormatTextures(config);
} }
@ -1038,7 +1038,7 @@ TEST_P(CompressedTextureBCFormatTest, LargeImageHeightAndClampedCopyExtent) {
// The actual size of the texture at mipmap level == 2 is not a multiple of 4, paddings are // The actual size of the texture at mipmap level == 2 is not a multiple of 4, paddings are
// required in the copies. // required in the copies.
const dawn::Extent3D textureSizeLevel0 = config.textureDescriptor.size; const wgpu::Extent3D textureSizeLevel0 = config.textureDescriptor.size;
const uint32_t kActualWidthAtLevel = textureSizeLevel0.width >> config.viewMipmapLevel; const uint32_t kActualWidthAtLevel = textureSizeLevel0.width >> config.viewMipmapLevel;
const uint32_t kActualHeightAtLevel = textureSizeLevel0.height >> config.viewMipmapLevel; const uint32_t kActualHeightAtLevel = textureSizeLevel0.height >> config.viewMipmapLevel;
ASSERT(kActualWidthAtLevel % kBCBlockWidthInTexels != 0); ASSERT(kActualWidthAtLevel % kBCBlockWidthInTexels != 0);
@ -1053,7 +1053,7 @@ TEST_P(CompressedTextureBCFormatTest, LargeImageHeightAndClampedCopyExtent) {
config.imageHeight = kCopyHeightAtLevel * 2; config.imageHeight = kCopyHeightAtLevel * 2;
for (dawn::TextureFormat format : kBCFormats) { for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format; config.textureDescriptor.format = format;
TestCopyRegionIntoBCFormatTextures(config); TestCopyRegionIntoBCFormatTextures(config);
} }

View File

@ -30,27 +30,27 @@ class ComputeCopyStorageBufferTests : public DawnTest {
void ComputeCopyStorageBufferTests::BasicTest(const char* shader) { void ComputeCopyStorageBufferTests::BasicTest(const char* shader) {
auto bgl = utils::MakeBindGroupLayout( auto bgl = utils::MakeBindGroupLayout(
device, { device, {
{0, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}, {0, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer},
{1, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}, {1, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer},
}); });
// Set up shader and pipeline // Set up shader and pipeline
auto module = utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, shader); auto module = utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, shader);
auto pl = utils::MakeBasicPipelineLayout(device, &bgl); auto pl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::ComputePipelineDescriptor csDesc; wgpu::ComputePipelineDescriptor csDesc;
csDesc.layout = pl; csDesc.layout = pl;
csDesc.computeStage.module = module; csDesc.computeStage.module = module;
csDesc.computeStage.entryPoint = "main"; csDesc.computeStage.entryPoint = "main";
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&csDesc); wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&csDesc);
// Set up src storage buffer // Set up src storage buffer
dawn::BufferDescriptor srcDesc; wgpu::BufferDescriptor srcDesc;
srcDesc.size = kNumUints * sizeof(uint32_t); srcDesc.size = kNumUints * sizeof(uint32_t);
srcDesc.usage = srcDesc.usage =
dawn::BufferUsage::Storage | dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst; wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
dawn::Buffer src = device.CreateBuffer(&srcDesc); wgpu::Buffer src = device.CreateBuffer(&srcDesc);
std::array<uint32_t, kNumUints> expected; std::array<uint32_t, kNumUints> expected;
for (uint32_t i = 0; i < kNumUints; ++i) { for (uint32_t i = 0; i < kNumUints; ++i) {
@ -60,25 +60,26 @@ void ComputeCopyStorageBufferTests::BasicTest(const char* shader) {
EXPECT_BUFFER_U32_RANGE_EQ(expected.data(), src, 0, kNumUints); EXPECT_BUFFER_U32_RANGE_EQ(expected.data(), src, 0, kNumUints);
// Set up dst storage buffer // Set up dst storage buffer
dawn::BufferDescriptor dstDesc; wgpu::BufferDescriptor dstDesc;
dstDesc.size = kNumUints * sizeof(uint32_t); dstDesc.size = kNumUints * sizeof(uint32_t);
dstDesc.usage = dstDesc.usage =
dawn::BufferUsage::Storage | dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst; wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
dawn::Buffer dst = device.CreateBuffer(&dstDesc); wgpu::Buffer dst = device.CreateBuffer(&dstDesc);
std::array<uint32_t, kNumUints> zero{}; std::array<uint32_t, kNumUints> zero{};
dst.SetSubData(0, sizeof(zero), zero.data()); dst.SetSubData(0, sizeof(zero), zero.data());
// Set up bind group and issue dispatch // Set up bind group and issue dispatch
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, bgl, { wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, bgl,
{
{0, src, 0, kNumUints * sizeof(uint32_t)}, {0, src, 0, kNumUints * sizeof(uint32_t)},
{1, dst, 0, kNumUints * sizeof(uint32_t)}, {1, dst, 0, kNumUints * sizeof(uint32_t)},
}); });
dawn::CommandBuffer commands; wgpu::CommandBuffer commands;
{ {
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder pass = encoder.BeginComputePass(); wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.Dispatch(kInstances, 1, 1); pass.Dispatch(kInstances, 1, 1);

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "dawn/dawncpp.h"
#include "tests/DawnTest.h" #include "tests/DawnTest.h"
#include "utils/WGPUHelpers.h" #include "utils/WGPUHelpers.h"
@ -45,50 +44,50 @@ class ComputeIndirectTests : public DawnTest {
void ComputeIndirectTests::BasicTest(std::initializer_list<uint32_t> bufferList, void ComputeIndirectTests::BasicTest(std::initializer_list<uint32_t> bufferList,
uint64_t indirectOffset) { uint64_t indirectOffset) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, { device, {
{0, dawn::ShaderStage::Compute, dawn::BindingType::UniformBuffer}, {0, wgpu::ShaderStage::Compute, wgpu::BindingType::UniformBuffer},
{1, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}, {1, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer},
}); });
// Set up shader and pipeline // Set up shader and pipeline
dawn::ShaderModule module = wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, shaderSource); utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, shaderSource);
dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::ComputePipelineDescriptor csDesc; wgpu::ComputePipelineDescriptor csDesc;
csDesc.layout = pl; csDesc.layout = pl;
csDesc.computeStage.module = module; csDesc.computeStage.module = module;
csDesc.computeStage.entryPoint = "main"; csDesc.computeStage.entryPoint = "main";
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&csDesc); wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&csDesc);
// Set up dst storage buffer to contain dispatch x, y, z // Set up dst storage buffer to contain dispatch x, y, z
dawn::Buffer dst = utils::CreateBufferFromData<uint32_t>( wgpu::Buffer dst = utils::CreateBufferFromData<uint32_t>(
device, device,
dawn::BufferUsage::Storage | dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst, wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst,
{0, 0, 0}); {0, 0, 0});
std::vector<uint32_t> indirectBufferData = bufferList; std::vector<uint32_t> indirectBufferData = bufferList;
dawn::Buffer indirectBuffer = wgpu::Buffer indirectBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Indirect, bufferList); utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Indirect, bufferList);
dawn::Buffer expectedBuffer = wgpu::Buffer expectedBuffer =
utils::CreateBufferFromData(device, &indirectBufferData[indirectOffset / sizeof(uint32_t)], utils::CreateBufferFromData(device, &indirectBufferData[indirectOffset / sizeof(uint32_t)],
3 * sizeof(uint32_t), dawn::BufferUsage::Uniform); 3 * sizeof(uint32_t), wgpu::BufferUsage::Uniform);
// Set up bind group and issue dispatch // Set up bind group and issue dispatch
dawn::BindGroup bindGroup = wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, bgl, utils::MakeBindGroup(device, bgl,
{ {
{0, expectedBuffer, 0, 3 * sizeof(uint32_t)}, {0, expectedBuffer, 0, 3 * sizeof(uint32_t)},
{1, dst, 0, 3 * sizeof(uint32_t)}, {1, dst, 0, 3 * sizeof(uint32_t)},
}); });
dawn::CommandBuffer commands; wgpu::CommandBuffer commands;
{ {
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder pass = encoder.BeginComputePass(); wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.DispatchIndirect(indirectBuffer, indirectOffset); pass.DispatchIndirect(indirectBuffer, indirectOffset);

View File

@ -28,38 +28,39 @@ class ComputeSharedMemoryTests : public DawnTest {
void ComputeSharedMemoryTests::BasicTest(const char* shader) { void ComputeSharedMemoryTests::BasicTest(const char* shader) {
auto bgl = utils::MakeBindGroupLayout( auto bgl = utils::MakeBindGroupLayout(
device, { device, {
{0, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}, {0, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer},
}); });
// Set up shader and pipeline // Set up shader and pipeline
auto module = utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, shader); auto module = utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, shader);
auto pl = utils::MakeBasicPipelineLayout(device, &bgl); auto pl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::ComputePipelineDescriptor csDesc; wgpu::ComputePipelineDescriptor csDesc;
csDesc.layout = pl; csDesc.layout = pl;
csDesc.computeStage.module = module; csDesc.computeStage.module = module;
csDesc.computeStage.entryPoint = "main"; csDesc.computeStage.entryPoint = "main";
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&csDesc); wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&csDesc);
// Set up dst storage buffer // Set up dst storage buffer
dawn::BufferDescriptor dstDesc; wgpu::BufferDescriptor dstDesc;
dstDesc.size = sizeof(uint32_t); dstDesc.size = sizeof(uint32_t);
dstDesc.usage = dstDesc.usage =
dawn::BufferUsage::Storage | dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst; wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
dawn::Buffer dst = device.CreateBuffer(&dstDesc); wgpu::Buffer dst = device.CreateBuffer(&dstDesc);
const uint32_t zero = 0; const uint32_t zero = 0;
dst.SetSubData(0, sizeof(zero), &zero); dst.SetSubData(0, sizeof(zero), &zero);
// Set up bind group and issue dispatch // Set up bind group and issue dispatch
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, bgl, { wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, bgl,
{
{0, dst, 0, sizeof(uint32_t)}, {0, dst, 0, sizeof(uint32_t)},
}); });
dawn::CommandBuffer commands; wgpu::CommandBuffer commands;
{ {
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder pass = encoder.BeginComputePass(); wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.Dispatch(1, 1, 1); pass.Dispatch(1, 1, 1);

View File

@ -28,10 +28,10 @@ TEST_P(ComputeStorageBufferBarrierTests, AddIncrement) {
std::vector<uint32_t> expected(kNumValues, 0x1234 * kIterations); std::vector<uint32_t> expected(kNumValues, 0x1234 * kIterations);
uint64_t bufferSize = static_cast<uint64_t>(data.size() * sizeof(uint32_t)); uint64_t bufferSize = static_cast<uint64_t>(data.size() * sizeof(uint32_t));
dawn::Buffer buffer = utils::CreateBufferFromData( wgpu::Buffer buffer = utils::CreateBufferFromData(
device, data.data(), bufferSize, dawn::BufferUsage::Storage | dawn::BufferUsage::CopySrc); device, data.data(), bufferSize, wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc);
dawn::ShaderModule module = wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
#version 450 #version 450
#define kNumValues 100 #define kNumValues 100
@ -41,28 +41,28 @@ TEST_P(ComputeStorageBufferBarrierTests, AddIncrement) {
} }
)"); )");
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}}); device, {{0, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer}});
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, bgl, {{0, buffer, 0, bufferSize}}); wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, bgl, {{0, buffer, 0, bufferSize}});
dawn::PipelineLayout layout = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout layout = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::ComputePipelineDescriptor pipelineDesc = {}; wgpu::ComputePipelineDescriptor pipelineDesc = {};
pipelineDesc.layout = layout; pipelineDesc.layout = layout;
pipelineDesc.computeStage.module = module; pipelineDesc.computeStage.module = module;
pipelineDesc.computeStage.entryPoint = "main"; pipelineDesc.computeStage.entryPoint = "main";
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc); wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder pass = encoder.BeginComputePass(); wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
for (uint32_t i = 0; i < kIterations; ++i) { for (uint32_t i = 0; i < kIterations; ++i) {
pass.Dispatch(kNumValues, 1, 1); pass.Dispatch(kNumValues, 1, 1);
} }
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_BUFFER_U32_RANGE_EQ(expected.data(), buffer, 0, kNumValues); EXPECT_BUFFER_U32_RANGE_EQ(expected.data(), buffer, 0, kNumValues);
@ -77,13 +77,13 @@ TEST_P(ComputeStorageBufferBarrierTests, AddPingPong) {
uint64_t bufferSize = static_cast<uint64_t>(data.size() * sizeof(uint32_t)); uint64_t bufferSize = static_cast<uint64_t>(data.size() * sizeof(uint32_t));
dawn::Buffer bufferA = utils::CreateBufferFromData( wgpu::Buffer bufferA = utils::CreateBufferFromData(
device, data.data(), bufferSize, dawn::BufferUsage::Storage | dawn::BufferUsage::CopySrc); device, data.data(), bufferSize, wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc);
dawn::Buffer bufferB = utils::CreateBufferFromData( wgpu::Buffer bufferB = utils::CreateBufferFromData(
device, data.data(), bufferSize, dawn::BufferUsage::Storage | dawn::BufferUsage::CopySrc); device, data.data(), bufferSize, wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc);
dawn::ShaderModule module = wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
#version 450 #version 450
#define kNumValues 100 #define kNumValues 100
@ -95,34 +95,34 @@ TEST_P(ComputeStorageBufferBarrierTests, AddPingPong) {
} }
)"); )");
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}, device, {{0, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer},
{1, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}}); {1, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer}});
dawn::BindGroup bindGroupA = utils::MakeBindGroup(device, bgl, wgpu::BindGroup bindGroupA = utils::MakeBindGroup(device, bgl,
{ {
{0, bufferA, 0, bufferSize}, {0, bufferA, 0, bufferSize},
{1, bufferB, 0, bufferSize}, {1, bufferB, 0, bufferSize},
}); });
dawn::BindGroup bindGroupB = utils::MakeBindGroup(device, bgl, wgpu::BindGroup bindGroupB = utils::MakeBindGroup(device, bgl,
{ {
{0, bufferB, 0, bufferSize}, {0, bufferB, 0, bufferSize},
{1, bufferA, 0, bufferSize}, {1, bufferA, 0, bufferSize},
}); });
dawn::BindGroup bindGroups[2] = {bindGroupA, bindGroupB}; wgpu::BindGroup bindGroups[2] = {bindGroupA, bindGroupB};
dawn::PipelineLayout layout = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout layout = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::ComputePipelineDescriptor pipelineDesc = {}; wgpu::ComputePipelineDescriptor pipelineDesc = {};
pipelineDesc.layout = layout; pipelineDesc.layout = layout;
pipelineDesc.computeStage.module = module; pipelineDesc.computeStage.module = module;
pipelineDesc.computeStage.entryPoint = "main"; pipelineDesc.computeStage.entryPoint = "main";
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc); wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder pass = encoder.BeginComputePass(); wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
for (uint32_t i = 0; i < kIterations / 2; ++i) { for (uint32_t i = 0; i < kIterations / 2; ++i) {
@ -132,7 +132,7 @@ TEST_P(ComputeStorageBufferBarrierTests, AddPingPong) {
pass.Dispatch(kNumValues, 1, 1); pass.Dispatch(kNumValues, 1, 1);
} }
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_BUFFER_U32_RANGE_EQ(expectedA.data(), bufferA, 0, kNumValues); EXPECT_BUFFER_U32_RANGE_EQ(expectedA.data(), bufferA, 0, kNumValues);
@ -148,13 +148,15 @@ TEST_P(ComputeStorageBufferBarrierTests, UniformToStorageAddPingPong) {
uint64_t bufferSize = static_cast<uint64_t>(data.size() * sizeof(uint32_t)); uint64_t bufferSize = static_cast<uint64_t>(data.size() * sizeof(uint32_t));
dawn::Buffer bufferA = utils::CreateBufferFromData( wgpu::Buffer bufferA = utils::CreateBufferFromData(
device, data.data(), bufferSize, dawn::BufferUsage::Storage | dawn::BufferUsage::Uniform | dawn::BufferUsage::CopySrc); device, data.data(), bufferSize,
wgpu::BufferUsage::Storage | wgpu::BufferUsage::Uniform | wgpu::BufferUsage::CopySrc);
dawn::Buffer bufferB = utils::CreateBufferFromData( wgpu::Buffer bufferB = utils::CreateBufferFromData(
device, data.data(), bufferSize, dawn::BufferUsage::Storage | dawn::BufferUsage::Uniform | dawn::BufferUsage::CopySrc); device, data.data(), bufferSize,
wgpu::BufferUsage::Storage | wgpu::BufferUsage::Uniform | wgpu::BufferUsage::CopySrc);
dawn::ShaderModule module = wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
#version 450 #version 450
#define kNumValues 100 #define kNumValues 100
@ -166,43 +168,43 @@ TEST_P(ComputeStorageBufferBarrierTests, UniformToStorageAddPingPong) {
} }
)"); )");
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Compute, dawn::BindingType::UniformBuffer}, device, {{0, wgpu::ShaderStage::Compute, wgpu::BindingType::UniformBuffer},
{1, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}}); {1, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer}});
dawn::BindGroup bindGroupA = utils::MakeBindGroup(device, bgl, wgpu::BindGroup bindGroupA = utils::MakeBindGroup(device, bgl,
{ {
{0, bufferA, 0, bufferSize}, {0, bufferA, 0, bufferSize},
{1, bufferB, 0, bufferSize}, {1, bufferB, 0, bufferSize},
}); });
dawn::BindGroup bindGroupB = utils::MakeBindGroup(device, bgl, wgpu::BindGroup bindGroupB = utils::MakeBindGroup(device, bgl,
{ {
{0, bufferB, 0, bufferSize}, {0, bufferB, 0, bufferSize},
{1, bufferA, 0, bufferSize}, {1, bufferA, 0, bufferSize},
}); });
dawn::BindGroup bindGroups[2] = {bindGroupA, bindGroupB}; wgpu::BindGroup bindGroups[2] = {bindGroupA, bindGroupB};
dawn::PipelineLayout layout = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout layout = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::ComputePipelineDescriptor pipelineDesc = {}; wgpu::ComputePipelineDescriptor pipelineDesc = {};
pipelineDesc.layout = layout; pipelineDesc.layout = layout;
pipelineDesc.computeStage.module = module; pipelineDesc.computeStage.module = module;
pipelineDesc.computeStage.entryPoint = "main"; pipelineDesc.computeStage.entryPoint = "main";
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc); wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
for (uint32_t i = 0, b = 0; i < kIterations; ++i, b = 1 - b) { for (uint32_t i = 0, b = 0; i < kIterations; ++i, b = 1 - b) {
dawn::ComputePassEncoder pass = encoder.BeginComputePass(); wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroups[b]); pass.SetBindGroup(0, bindGroups[b]);
pass.Dispatch(kNumValues, 1, 1); pass.Dispatch(kNumValues, 1, 1);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_BUFFER_U32_RANGE_EQ(expectedA.data(), bufferA, 0, kNumValues); EXPECT_BUFFER_U32_RANGE_EQ(expectedA.data(), bufferA, 0, kNumValues);

View File

@ -76,17 +76,17 @@ class CopyTests_T2B : public CopyTests {
void DoTest(const TextureSpec& textureSpec, const BufferSpec& bufferSpec) { void DoTest(const TextureSpec& textureSpec, const BufferSpec& bufferSpec) {
// Create a texture that is `width` x `height` with (`level` + 1) mip levels. // Create a texture that is `width` x `height` with (`level` + 1) mip levels.
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = textureSpec.width; descriptor.size.width = textureSpec.width;
descriptor.size.height = textureSpec.height; descriptor.size.height = textureSpec.height;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayerCount = textureSpec.arraySize; descriptor.arrayLayerCount = textureSpec.arraySize;
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm; descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = textureSpec.level + 1; descriptor.mipLevelCount = textureSpec.level + 1;
descriptor.usage = dawn::TextureUsage::CopyDst | dawn::TextureUsage::CopySrc; descriptor.usage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
uint32_t width = textureSpec.width >> textureSpec.level; uint32_t width = textureSpec.width >> textureSpec.level;
uint32_t height = textureSpec.height >> textureSpec.level; uint32_t height = textureSpec.height >> textureSpec.level;
@ -94,7 +94,7 @@ class CopyTests_T2B : public CopyTests {
uint32_t texelsPerRow = rowPitch / kBytesPerTexel; uint32_t texelsPerRow = rowPitch / kBytesPerTexel;
uint32_t texelCountPerLayer = texelsPerRow * (height - 1) + width; uint32_t texelCountPerLayer = texelsPerRow * (height - 1) + width;
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
std::vector<std::vector<RGBA8>> textureArrayData(textureSpec.arraySize); std::vector<std::vector<RGBA8>> textureArrayData(textureSpec.arraySize);
for (uint32_t slice = 0; slice < textureSpec.arraySize; ++slice) { for (uint32_t slice = 0; slice < textureSpec.arraySize; ++slice) {
@ -103,25 +103,25 @@ class CopyTests_T2B : public CopyTests {
textureArrayData[slice].data()); textureArrayData[slice].data());
// Create an upload buffer and use it to populate the current slice of the texture in `level` mip level // Create an upload buffer and use it to populate the current slice of the texture in `level` mip level
dawn::Buffer uploadBuffer = utils::CreateBufferFromData( wgpu::Buffer uploadBuffer = utils::CreateBufferFromData(
device, textureArrayData[slice].data(), device, textureArrayData[slice].data(),
static_cast<uint32_t>(sizeof(RGBA8) * textureArrayData[slice].size()), static_cast<uint32_t>(sizeof(RGBA8) * textureArrayData[slice].size()),
dawn::BufferUsage::CopySrc); wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(uploadBuffer, 0, rowPitch, 0); utils::CreateBufferCopyView(uploadBuffer, 0, rowPitch, 0);
dawn::TextureCopyView textureCopyView = wgpu::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(texture, textureSpec.level, slice, {0, 0, 0}); utils::CreateTextureCopyView(texture, textureSpec.level, slice, {0, 0, 0});
dawn::Extent3D copySize = {width, height, 1}; wgpu::Extent3D copySize = {width, height, 1};
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize); encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
} }
// Create a buffer of size `size * textureSpec.arrayLayer` and populate it with empty data (0,0,0,0) // Create a buffer of size `size * textureSpec.arrayLayer` and populate it with empty data (0,0,0,0)
// Note: Prepopulating the buffer with empty data ensures that there is not random data in the expectation // Note: Prepopulating the buffer with empty data ensures that there is not random data in the expectation
// and helps ensure that the padding due to the row pitch is not modified by the copy // and helps ensure that the padding due to the row pitch is not modified by the copy
dawn::BufferDescriptor bufDescriptor; wgpu::BufferDescriptor bufDescriptor;
bufDescriptor.size = bufferSpec.size * textureSpec.arraySize; bufDescriptor.size = bufferSpec.size * textureSpec.arraySize;
bufDescriptor.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst; bufDescriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&bufDescriptor); wgpu::Buffer buffer = device.CreateBuffer(&bufDescriptor);
std::vector<RGBA8> emptyData(bufferSpec.size / kBytesPerTexel * textureSpec.arraySize); std::vector<RGBA8> emptyData(bufferSpec.size / kBytesPerTexel * textureSpec.arraySize);
buffer.SetSubData(0, static_cast<uint32_t>(emptyData.size() * sizeof(RGBA8)), buffer.SetSubData(0, static_cast<uint32_t>(emptyData.size() * sizeof(RGBA8)),
emptyData.data()); emptyData.data());
@ -129,16 +129,16 @@ class CopyTests_T2B : public CopyTests {
uint64_t bufferOffset = bufferSpec.offset; uint64_t bufferOffset = bufferSpec.offset;
for (uint32_t slice = 0; slice < textureSpec.arraySize; ++slice) { for (uint32_t slice = 0; slice < textureSpec.arraySize; ++slice) {
// Copy the region [(`x`, `y`), (`x + copyWidth, `y + copyWidth`)] from the `level` mip into the buffer at `offset + bufferSpec.size * slice` and `rowPitch` // Copy the region [(`x`, `y`), (`x + copyWidth, `y + copyWidth`)] from the `level` mip into the buffer at `offset + bufferSpec.size * slice` and `rowPitch`
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView( wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
texture, textureSpec.level, slice, {textureSpec.x, textureSpec.y, 0}); texture, textureSpec.level, slice, {textureSpec.x, textureSpec.y, 0});
dawn::BufferCopyView bufferCopyView = wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(buffer, bufferOffset, bufferSpec.rowPitch, 0); utils::CreateBufferCopyView(buffer, bufferOffset, bufferSpec.rowPitch, 0);
dawn::Extent3D copySize = {textureSpec.copyWidth, textureSpec.copyHeight, 1}; wgpu::Extent3D copySize = {textureSpec.copyWidth, textureSpec.copyHeight, 1};
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize); encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize);
bufferOffset += bufferSpec.size; bufferOffset += bufferSpec.size;
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
bufferOffset = bufferSpec.offset; bufferOffset = bufferSpec.offset;
@ -180,10 +180,10 @@ protected:
void DoTest(const TextureSpec& textureSpec, const BufferSpec& bufferSpec) { void DoTest(const TextureSpec& textureSpec, const BufferSpec& bufferSpec) {
// Create a buffer of size `size` and populate it with data // Create a buffer of size `size` and populate it with data
dawn::BufferDescriptor bufDescriptor; wgpu::BufferDescriptor bufDescriptor;
bufDescriptor.size = bufferSpec.size; bufDescriptor.size = bufferSpec.size;
bufDescriptor.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst; bufDescriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&bufDescriptor); wgpu::Buffer buffer = device.CreateBuffer(&bufDescriptor);
std::vector<RGBA8> bufferData(bufferSpec.size / kBytesPerTexel); std::vector<RGBA8> bufferData(bufferSpec.size / kBytesPerTexel);
FillBufferData(bufferData.data(), bufferData.size()); FillBufferData(bufferData.data(), bufferData.size());
@ -191,19 +191,19 @@ protected:
bufferData.data()); bufferData.data());
// Create a texture that is `width` x `height` with (`level` + 1) mip levels. // Create a texture that is `width` x `height` with (`level` + 1) mip levels.
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = textureSpec.width; descriptor.size.width = textureSpec.width;
descriptor.size.height = textureSpec.height; descriptor.size.height = textureSpec.height;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1; descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm; descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = textureSpec.level + 1; descriptor.mipLevelCount = textureSpec.level + 1;
descriptor.usage = dawn::TextureUsage::CopyDst | dawn::TextureUsage::CopySrc; descriptor.usage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
// Create an upload buffer filled with empty data and use it to populate the `level` mip of the texture // Create an upload buffer filled with empty data and use it to populate the `level` mip of the texture
// Note: Prepopulating the texture with empty data ensures that there is not random data in the expectation // Note: Prepopulating the texture with empty data ensures that there is not random data in the expectation
@ -216,28 +216,28 @@ protected:
uint32_t texelCount = texelsPerRow * (height - 1) + width; uint32_t texelCount = texelsPerRow * (height - 1) + width;
std::vector<RGBA8> emptyData(texelCount); std::vector<RGBA8> emptyData(texelCount);
dawn::Buffer uploadBuffer = utils::CreateBufferFromData( wgpu::Buffer uploadBuffer = utils::CreateBufferFromData(
device, emptyData.data(), static_cast<uint32_t>(sizeof(RGBA8) * emptyData.size()), device, emptyData.data(), static_cast<uint32_t>(sizeof(RGBA8) * emptyData.size()),
dawn::BufferUsage::CopySrc); wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(uploadBuffer, 0, rowPitch, 0); utils::CreateBufferCopyView(uploadBuffer, 0, rowPitch, 0);
dawn::TextureCopyView textureCopyView = wgpu::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(texture, textureSpec.level, 0, {0, 0, 0}); utils::CreateTextureCopyView(texture, textureSpec.level, 0, {0, 0, 0});
dawn::Extent3D copySize = {width, height, 1}; wgpu::Extent3D copySize = {width, height, 1};
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize); encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
} }
// Copy to the region [(`x`, `y`), (`x + copyWidth, `y + copyWidth`)] at the `level` mip from the buffer at the specified `offset` and `rowPitch` // Copy to the region [(`x`, `y`), (`x + copyWidth, `y + copyWidth`)] at the `level` mip from the buffer at the specified `offset` and `rowPitch`
{ {
dawn::BufferCopyView bufferCopyView = wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(buffer, bufferSpec.offset, bufferSpec.rowPitch, 0); utils::CreateBufferCopyView(buffer, bufferSpec.offset, bufferSpec.rowPitch, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView( wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
texture, textureSpec.level, 0, {textureSpec.x, textureSpec.y, 0}); texture, textureSpec.level, 0, {textureSpec.x, textureSpec.y, 0});
dawn::Extent3D copySize = {textureSpec.copyWidth, textureSpec.copyHeight, 1}; wgpu::Extent3D copySize = {textureSpec.copyWidth, textureSpec.copyHeight, 1};
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize); encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
// Pack the data used to create the buffer in the specified copy region to have the same format as the expected texture data. // Pack the data used to create the buffer in the specified copy region to have the same format as the expected texture data.
@ -272,31 +272,31 @@ class CopyTests_T2T : public CopyTests {
protected: protected:
void DoTest(const TextureSpec& srcSpec, const TextureSpec& dstSpec, const CopySize& copy) { void DoTest(const TextureSpec& srcSpec, const TextureSpec& dstSpec, const CopySize& copy) {
dawn::TextureDescriptor srcDescriptor; wgpu::TextureDescriptor srcDescriptor;
srcDescriptor.dimension = dawn::TextureDimension::e2D; srcDescriptor.dimension = wgpu::TextureDimension::e2D;
srcDescriptor.size.width = srcSpec.width; srcDescriptor.size.width = srcSpec.width;
srcDescriptor.size.height = srcSpec.height; srcDescriptor.size.height = srcSpec.height;
srcDescriptor.size.depth = 1; srcDescriptor.size.depth = 1;
srcDescriptor.arrayLayerCount = srcSpec.arraySize; srcDescriptor.arrayLayerCount = srcSpec.arraySize;
srcDescriptor.sampleCount = 1; srcDescriptor.sampleCount = 1;
srcDescriptor.format = dawn::TextureFormat::RGBA8Unorm; srcDescriptor.format = wgpu::TextureFormat::RGBA8Unorm;
srcDescriptor.mipLevelCount = srcSpec.level + 1; srcDescriptor.mipLevelCount = srcSpec.level + 1;
srcDescriptor.usage = dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst; srcDescriptor.usage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst;
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor); wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
dawn::TextureDescriptor dstDescriptor; wgpu::TextureDescriptor dstDescriptor;
dstDescriptor.dimension = dawn::TextureDimension::e2D; dstDescriptor.dimension = wgpu::TextureDimension::e2D;
dstDescriptor.size.width = dstSpec.width; dstDescriptor.size.width = dstSpec.width;
dstDescriptor.size.height = dstSpec.height; dstDescriptor.size.height = dstSpec.height;
dstDescriptor.size.depth = 1; dstDescriptor.size.depth = 1;
dstDescriptor.arrayLayerCount = dstSpec.arraySize; dstDescriptor.arrayLayerCount = dstSpec.arraySize;
dstDescriptor.sampleCount = 1; dstDescriptor.sampleCount = 1;
dstDescriptor.format = dawn::TextureFormat::RGBA8Unorm; dstDescriptor.format = wgpu::TextureFormat::RGBA8Unorm;
dstDescriptor.mipLevelCount = dstSpec.level + 1; dstDescriptor.mipLevelCount = dstSpec.level + 1;
dstDescriptor.usage = dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst; dstDescriptor.usage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst;
dawn::Texture dstTexture = device.CreateTexture(&dstDescriptor); wgpu::Texture dstTexture = device.CreateTexture(&dstDescriptor);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
// Create an upload buffer and use it to populate the current slice of the texture in // Create an upload buffer and use it to populate the current slice of the texture in
// `level` mip level // `level` mip level
@ -312,15 +312,15 @@ class CopyTests_T2T : public CopyTests {
FillTextureData(width, height, rowPitch / kBytesPerTexel, slice, FillTextureData(width, height, rowPitch / kBytesPerTexel, slice,
textureArrayData[slice].data()); textureArrayData[slice].data());
dawn::Buffer uploadBuffer = utils::CreateBufferFromData( wgpu::Buffer uploadBuffer = utils::CreateBufferFromData(
device, textureArrayData[slice].data(), device, textureArrayData[slice].data(),
static_cast<uint32_t>(sizeof(RGBA8) * textureArrayData[slice].size()), static_cast<uint32_t>(sizeof(RGBA8) * textureArrayData[slice].size()),
dawn::BufferUsage::CopySrc); wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(uploadBuffer, 0, rowPitch, 0); utils::CreateBufferCopyView(uploadBuffer, 0, rowPitch, 0);
dawn::TextureCopyView textureCopyView = wgpu::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(srcTexture, srcSpec.level, slice, {0, 0, 0}); utils::CreateTextureCopyView(srcTexture, srcSpec.level, slice, {0, 0, 0});
dawn::Extent3D bufferCopySize = {width, height, 1}; wgpu::Extent3D bufferCopySize = {width, height, 1};
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &bufferCopySize); encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &bufferCopySize);
} }
@ -337,28 +337,28 @@ class CopyTests_T2T : public CopyTests {
uint32_t dstTexelCount = dstTexelsPerRow * (dstHeight - 1) + dstWidth; uint32_t dstTexelCount = dstTexelsPerRow * (dstHeight - 1) + dstWidth;
std::vector<RGBA8> emptyData(dstTexelCount); std::vector<RGBA8> emptyData(dstTexelCount);
dawn::Buffer uploadBuffer = utils::CreateBufferFromData( wgpu::Buffer uploadBuffer = utils::CreateBufferFromData(
device, emptyData.data(), static_cast<uint32_t>(sizeof(RGBA8) * emptyData.size()), device, emptyData.data(), static_cast<uint32_t>(sizeof(RGBA8) * emptyData.size()),
dawn::BufferUsage::CopySrc); wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(uploadBuffer, 0, dstRowPitch, 0); utils::CreateBufferCopyView(uploadBuffer, 0, dstRowPitch, 0);
dawn::TextureCopyView textureCopyView = wgpu::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(dstTexture, dstSpec.level, 0, {0, 0, 0}); utils::CreateTextureCopyView(dstTexture, dstSpec.level, 0, {0, 0, 0});
dawn::Extent3D dstCopySize = {dstWidth, dstHeight, 1}; wgpu::Extent3D dstCopySize = {dstWidth, dstHeight, 1};
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &dstCopySize); encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &dstCopySize);
} }
// Perform the texture to texture copy // Perform the texture to texture copy
for (uint32_t slice = 0; slice < srcSpec.arraySize; ++slice) { for (uint32_t slice = 0; slice < srcSpec.arraySize; ++slice) {
dawn::TextureCopyView srcTextureCopyView = utils::CreateTextureCopyView( wgpu::TextureCopyView srcTextureCopyView = utils::CreateTextureCopyView(
srcTexture, srcSpec.level, slice, {srcSpec.x, srcSpec.y, 0}); srcTexture, srcSpec.level, slice, {srcSpec.x, srcSpec.y, 0});
dawn::TextureCopyView dstTextureCopyView = utils::CreateTextureCopyView( wgpu::TextureCopyView dstTextureCopyView = utils::CreateTextureCopyView(
dstTexture, dstSpec.level, slice, {dstSpec.x, dstSpec.y, 0}); dstTexture, dstSpec.level, slice, {dstSpec.x, dstSpec.y, 0});
dawn::Extent3D copySize = {copy.width, copy.height, 1}; wgpu::Extent3D copySize = {copy.width, copy.height, 1};
encoder.CopyTextureToTexture(&srcTextureCopyView, &dstTextureCopyView, &copySize); encoder.CopyTextureToTexture(&srcTextureCopyView, &dstTextureCopyView, &copySize);
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
std::vector<RGBA8> expected(rowPitch / kBytesPerTexel * (copy.height - 1) + copy.width); std::vector<RGBA8> expected(rowPitch / kBytesPerTexel * (copy.height - 1) + copy.width);

View File

@ -19,7 +19,7 @@
class CullingTest : public DawnTest { class CullingTest : public DawnTest {
protected: protected:
dawn::RenderPipeline CreatePipelineForTest(dawn::FrontFace frontFace, dawn::CullMode cullMode) { wgpu::RenderPipeline CreatePipelineForTest(wgpu::FrontFace frontFace, wgpu::CullMode cullMode) {
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device); utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
// Draw two triangles with different winding orders: // Draw two triangles with different winding orders:
@ -58,12 +58,12 @@ class CullingTest : public DawnTest {
return device.CreateRenderPipeline(&pipelineDescriptor); return device.CreateRenderPipeline(&pipelineDescriptor);
} }
dawn::Texture Create2DTextureForTest(dawn::TextureFormat format) { wgpu::Texture Create2DTextureForTest(wgpu::TextureFormat format) {
dawn::TextureDescriptor textureDescriptor; wgpu::TextureDescriptor textureDescriptor;
textureDescriptor.dimension = dawn::TextureDimension::e2D; textureDescriptor.dimension = wgpu::TextureDimension::e2D;
textureDescriptor.format = format; textureDescriptor.format = format;
textureDescriptor.usage = textureDescriptor.usage =
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc; wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
textureDescriptor.arrayLayerCount = 1; textureDescriptor.arrayLayerCount = 1;
textureDescriptor.mipLevelCount = 1; textureDescriptor.mipLevelCount = 1;
textureDescriptor.sampleCount = 1; textureDescriptor.sampleCount = 1;
@ -71,23 +71,23 @@ class CullingTest : public DawnTest {
return device.CreateTexture(&textureDescriptor); return device.CreateTexture(&textureDescriptor);
} }
void DoTest(dawn::FrontFace frontFace, void DoTest(wgpu::FrontFace frontFace,
dawn::CullMode cullMode, wgpu::CullMode cullMode,
bool isCCWTriangleCulled, bool isCCWTriangleCulled,
bool isCWTriangleCulled) { bool isCWTriangleCulled) {
dawn::Texture colorTexture = Create2DTextureForTest(dawn::TextureFormat::RGBA8Unorm); wgpu::Texture colorTexture = Create2DTextureForTest(wgpu::TextureFormat::RGBA8Unorm);
utils::ComboRenderPassDescriptor renderPassDescriptor({colorTexture.CreateView()}); utils::ComboRenderPassDescriptor renderPassDescriptor({colorTexture.CreateView()});
renderPassDescriptor.cColorAttachments[0].clearColor = {0.0, 0.0, 1.0, 1.0}; renderPassDescriptor.cColorAttachments[0].clearColor = {0.0, 0.0, 1.0, 1.0};
renderPassDescriptor.cColorAttachments[0].loadOp = dawn::LoadOp::Clear; renderPassDescriptor.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder renderPass = commandEncoder.BeginRenderPass(&renderPassDescriptor); wgpu::RenderPassEncoder renderPass = commandEncoder.BeginRenderPass(&renderPassDescriptor);
renderPass.SetPipeline(CreatePipelineForTest(frontFace, cullMode)); renderPass.SetPipeline(CreatePipelineForTest(frontFace, cullMode));
renderPass.Draw(6, 1, 0, 0); renderPass.Draw(6, 1, 0, 0);
renderPass.EndPass(); renderPass.EndPass();
dawn::CommandBuffer commandBuffer = commandEncoder.Finish(); wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue(); wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer); queue.Submit(1, &commandBuffer);
constexpr RGBA8 kTopLeftColor = RGBA8(0, 0, 0, 255); constexpr RGBA8 kTopLeftColor = RGBA8(0, 0, 0, 255);
@ -106,27 +106,27 @@ class CullingTest : public DawnTest {
}; };
TEST_P(CullingTest, CullNoneWhenCCWIsFrontFace) { TEST_P(CullingTest, CullNoneWhenCCWIsFrontFace) {
DoTest(dawn::FrontFace::CCW, dawn::CullMode::None, false, false); DoTest(wgpu::FrontFace::CCW, wgpu::CullMode::None, false, false);
} }
TEST_P(CullingTest, CullFrontFaceWhenCCWIsFrontFace) { TEST_P(CullingTest, CullFrontFaceWhenCCWIsFrontFace) {
DoTest(dawn::FrontFace::CCW, dawn::CullMode::Front, true, false); DoTest(wgpu::FrontFace::CCW, wgpu::CullMode::Front, true, false);
} }
TEST_P(CullingTest, CullBackFaceWhenCCWIsFrontFace) { TEST_P(CullingTest, CullBackFaceWhenCCWIsFrontFace) {
DoTest(dawn::FrontFace::CCW, dawn::CullMode::Back, false, true); DoTest(wgpu::FrontFace::CCW, wgpu::CullMode::Back, false, true);
} }
TEST_P(CullingTest, CullNoneWhenCWIsFrontFace) { TEST_P(CullingTest, CullNoneWhenCWIsFrontFace) {
DoTest(dawn::FrontFace::CW, dawn::CullMode::None, false, false); DoTest(wgpu::FrontFace::CW, wgpu::CullMode::None, false, false);
} }
TEST_P(CullingTest, CullFrontFaceWhenCWIsFrontFace) { TEST_P(CullingTest, CullFrontFaceWhenCWIsFrontFace) {
DoTest(dawn::FrontFace::CW, dawn::CullMode::Front, false, true); DoTest(wgpu::FrontFace::CW, wgpu::CullMode::Front, false, true);
} }
TEST_P(CullingTest, CullBackFaceWhenCWIsFrontFace) { TEST_P(CullingTest, CullBackFaceWhenCWIsFrontFace) {
DoTest(dawn::FrontFace::CW, dawn::CullMode::Back, true, false); DoTest(wgpu::FrontFace::CW, wgpu::CullMode::Back, true, false);
} }
DAWN_INSTANTIATE_TEST(CullingTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend); DAWN_INSTANTIATE_TEST(CullingTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);

View File

@ -59,15 +59,15 @@ namespace {
mD3d11Device = std::move(d3d11Device); mD3d11Device = std::move(d3d11Device);
mD3d11DeviceContext = std::move(d3d11DeviceContext); mD3d11DeviceContext = std::move(d3d11DeviceContext);
dawnDescriptor.dimension = dawn::TextureDimension::e2D; dawnDescriptor.dimension = wgpu::TextureDimension::e2D;
dawnDescriptor.format = dawn::TextureFormat::RGBA8Unorm; dawnDescriptor.format = wgpu::TextureFormat::RGBA8Unorm;
dawnDescriptor.size = {kTestWidth, kTestHeight, 1}; dawnDescriptor.size = {kTestWidth, kTestHeight, 1};
dawnDescriptor.sampleCount = 1; dawnDescriptor.sampleCount = 1;
dawnDescriptor.arrayLayerCount = 1; dawnDescriptor.arrayLayerCount = 1;
dawnDescriptor.mipLevelCount = 1; dawnDescriptor.mipLevelCount = 1;
dawnDescriptor.usage = dawn::TextureUsage::Sampled | dawn::TextureUsage::CopySrc | dawnDescriptor.usage = wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopySrc |
dawn::TextureUsage::OutputAttachment | wgpu::TextureUsage::OutputAttachment |
dawn::TextureUsage::CopyDst; wgpu::TextureUsage::CopyDst;
d3dDescriptor.Width = kTestWidth; d3dDescriptor.Width = kTestWidth;
d3dDescriptor.Height = kTestHeight; d3dDescriptor.Height = kTestHeight;
@ -84,9 +84,9 @@ namespace {
} }
protected: protected:
void WrapSharedHandle(const dawn::TextureDescriptor* dawnDescriptor, void WrapSharedHandle(const wgpu::TextureDescriptor* dawnDescriptor,
const D3D11_TEXTURE2D_DESC* d3dDescriptor, const D3D11_TEXTURE2D_DESC* d3dDescriptor,
dawn::Texture* dawnTexture, wgpu::Texture* dawnTexture,
ID3D11Texture2D** d3d11TextureOut) const { ID3D11Texture2D** d3d11TextureOut) const {
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
HRESULT hr = mD3d11Device->CreateTexture2D(d3dDescriptor, nullptr, &d3d11Texture); HRESULT hr = mD3d11Device->CreateTexture2D(d3dDescriptor, nullptr, &d3d11Texture);
@ -102,14 +102,14 @@ namespace {
&sharedHandle); &sharedHandle);
ASSERT_EQ(hr, S_OK); ASSERT_EQ(hr, S_OK);
DawnTexture texture = dawn_native::d3d12::WrapSharedHandle( WGPUTexture texture = dawn_native::d3d12::WrapSharedHandle(
device.Get(), reinterpret_cast<const DawnTextureDescriptor*>(dawnDescriptor), device.Get(), reinterpret_cast<const WGPUTextureDescriptor*>(dawnDescriptor),
sharedHandle, 0); sharedHandle, 0);
// Now that we've created all of our resources, we can close the handle // Now that we've created all of our resources, we can close the handle
// since we no longer need it. // since we no longer need it.
::CloseHandle(sharedHandle); ::CloseHandle(sharedHandle);
*dawnTexture = dawn::Texture::Acquire(texture); *dawnTexture = wgpu::Texture::Acquire(texture);
*d3d11TextureOut = d3d11Texture.Detach(); *d3d11TextureOut = d3d11Texture.Detach();
} }
@ -120,7 +120,7 @@ namespace {
ComPtr<ID3D11DeviceContext> mD3d11DeviceContext; ComPtr<ID3D11DeviceContext> mD3d11DeviceContext;
D3D11_TEXTURE2D_DESC d3dDescriptor; D3D11_TEXTURE2D_DESC d3dDescriptor;
dawn::TextureDescriptor dawnDescriptor; wgpu::TextureDescriptor dawnDescriptor;
}; };
} // anonymous namespace } // anonymous namespace
@ -134,7 +134,7 @@ class D3D12SharedHandleValidation : public D3D12ResourceTestBase {
TEST_P(D3D12SharedHandleValidation, Success) { TEST_P(D3D12SharedHandleValidation, Success) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
dawn::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture); WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture);
@ -146,7 +146,7 @@ TEST_P(D3D12SharedHandleValidation, InvalidTextureDescriptor) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
dawnDescriptor.nextInChain = this; dawnDescriptor.nextInChain = this;
dawn::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture)); ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture));
@ -158,7 +158,7 @@ TEST_P(D3D12SharedHandleValidation, InvalidMipLevelCount) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
dawnDescriptor.mipLevelCount = 2; dawnDescriptor.mipLevelCount = 2;
dawn::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture)); ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture));
@ -170,7 +170,7 @@ TEST_P(D3D12SharedHandleValidation, InvalidArrayLayerCount) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
dawnDescriptor.arrayLayerCount = 2; dawnDescriptor.arrayLayerCount = 2;
dawn::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture)); ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture));
@ -182,7 +182,7 @@ TEST_P(D3D12SharedHandleValidation, InvalidSampleCount) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
dawnDescriptor.sampleCount = 4; dawnDescriptor.sampleCount = 4;
dawn::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture)); ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture));
@ -194,7 +194,7 @@ TEST_P(D3D12SharedHandleValidation, InvalidWidth) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
dawnDescriptor.size.width = kTestWidth + 1; dawnDescriptor.size.width = kTestWidth + 1;
dawn::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture)); ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture));
@ -206,7 +206,7 @@ TEST_P(D3D12SharedHandleValidation, InvalidHeight) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
dawnDescriptor.size.height = kTestHeight + 1; dawnDescriptor.size.height = kTestHeight + 1;
dawn::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture)); ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture));
@ -216,9 +216,9 @@ TEST_P(D3D12SharedHandleValidation, InvalidHeight) {
// Test an error occurs if the descriptor format isn't compatible with the D3D12 Resource // Test an error occurs if the descriptor format isn't compatible with the D3D12 Resource
TEST_P(D3D12SharedHandleValidation, InvalidFormat) { TEST_P(D3D12SharedHandleValidation, InvalidFormat) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
dawnDescriptor.format = dawn::TextureFormat::R8Unorm; dawnDescriptor.format = wgpu::TextureFormat::R8Unorm;
dawn::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture)); ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture));
@ -230,7 +230,7 @@ TEST_P(D3D12SharedHandleValidation, InvalidNumD3DMipLevels) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
d3dDescriptor.MipLevels = 2; d3dDescriptor.MipLevels = 2;
dawn::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture)); ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture));
@ -242,7 +242,7 @@ TEST_P(D3D12SharedHandleValidation, InvalidD3DArraySize) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
d3dDescriptor.ArraySize = 2; d3dDescriptor.ArraySize = 2;
dawn::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture)); ASSERT_DEVICE_ERROR(WrapSharedHandle(&dawnDescriptor, &d3dDescriptor, &texture, &d3d11Texture));
@ -252,48 +252,48 @@ TEST_P(D3D12SharedHandleValidation, InvalidD3DArraySize) {
class D3D12SharedHandleUsageTests : public D3D12ResourceTestBase { class D3D12SharedHandleUsageTests : public D3D12ResourceTestBase {
protected: protected:
// Submits a 1x1x1 copy from source to destination // Submits a 1x1x1 copy from source to destination
void SimpleCopyTextureToTexture(dawn::Texture source, dawn::Texture destination) { void SimpleCopyTextureToTexture(wgpu::Texture source, wgpu::Texture destination) {
dawn::TextureCopyView copySrc; wgpu::TextureCopyView copySrc;
copySrc.texture = source; copySrc.texture = source;
copySrc.mipLevel = 0; copySrc.mipLevel = 0;
copySrc.arrayLayer = 0; copySrc.arrayLayer = 0;
copySrc.origin = {0, 0, 0}; copySrc.origin = {0, 0, 0};
dawn::TextureCopyView copyDst; wgpu::TextureCopyView copyDst;
copyDst.texture = destination; copyDst.texture = destination;
copyDst.mipLevel = 0; copyDst.mipLevel = 0;
copyDst.arrayLayer = 0; copyDst.arrayLayer = 0;
copyDst.origin = {0, 0, 0}; copyDst.origin = {0, 0, 0};
dawn::Extent3D copySize = {1, 1, 1}; wgpu::Extent3D copySize = {1, 1, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToTexture(&copySrc, &copyDst, &copySize); encoder.CopyTextureToTexture(&copySrc, &copyDst, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
} }
// Clear a texture on a given device // Clear a texture on a given device
void ClearImage(dawn::Texture wrappedTexture, const dawn::Color& clearColor) { void ClearImage(wgpu::Texture wrappedTexture, const wgpu::Color& clearColor) {
dawn::TextureView wrappedView = wrappedTexture.CreateView(); wgpu::TextureView wrappedView = wrappedTexture.CreateView();
// Submit a clear operation // Submit a clear operation
utils::ComboRenderPassDescriptor renderPassDescriptor({wrappedView}, {}); utils::ComboRenderPassDescriptor renderPassDescriptor({wrappedView}, {});
renderPassDescriptor.cColorAttachments[0].clearColor = clearColor; renderPassDescriptor.cColorAttachments[0].clearColor = clearColor;
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
} }
void WrapAndClearD3D11Texture(const dawn::TextureDescriptor* dawnDescriptor, void WrapAndClearD3D11Texture(const wgpu::TextureDescriptor* dawnDescriptor,
const D3D11_TEXTURE2D_DESC* d3dDescriptor, const D3D11_TEXTURE2D_DESC* d3dDescriptor,
dawn::Texture* dawnTextureOut, wgpu::Texture* dawnTextureOut,
const dawn::Color& clearColor, const wgpu::Color& clearColor,
ID3D11Texture2D** d3d11TextureOut, ID3D11Texture2D** d3d11TextureOut,
IDXGIKeyedMutex** dxgiKeyedMutexOut) const { IDXGIKeyedMutex** dxgiKeyedMutexOut) const {
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
@ -327,11 +327,11 @@ class D3D12SharedHandleUsageTests : public D3D12ResourceTestBase {
hr = dxgiKeyedMutex->ReleaseSync(1); hr = dxgiKeyedMutex->ReleaseSync(1);
ASSERT_EQ(hr, S_OK); ASSERT_EQ(hr, S_OK);
DawnTexture dawnTexture = dawn_native::d3d12::WrapSharedHandle( WGPUTexture dawnTexture = dawn_native::d3d12::WrapSharedHandle(
device.Get(), reinterpret_cast<const DawnTextureDescriptor*>(dawnDescriptor), device.Get(), reinterpret_cast<const WGPUTextureDescriptor*>(dawnDescriptor),
sharedHandle, 1); sharedHandle, 1);
*dawnTextureOut = dawn::Texture::Acquire(dawnTexture); *dawnTextureOut = wgpu::Texture::Acquire(dawnTexture);
*d3d11TextureOut = d3d11Texture.Detach(); *d3d11TextureOut = d3d11Texture.Detach();
*dxgiKeyedMutexOut = dxgiKeyedMutex.Detach(); *dxgiKeyedMutexOut = dxgiKeyedMutex.Detach();
} }
@ -339,7 +339,7 @@ class D3D12SharedHandleUsageTests : public D3D12ResourceTestBase {
void ExpectPixelRGBA8EQ(UINT64 acquireKey, void ExpectPixelRGBA8EQ(UINT64 acquireKey,
ID3D11Texture2D* d3d11Texture, ID3D11Texture2D* d3d11Texture,
IDXGIKeyedMutex* dxgiKeyedMutex, IDXGIKeyedMutex* dxgiKeyedMutex,
const dawn::Color& color) { const wgpu::Color& color) {
HRESULT hr = dxgiKeyedMutex->AcquireSync(acquireKey, INFINITE); HRESULT hr = dxgiKeyedMutex->AcquireSync(acquireKey, INFINITE);
ASSERT_EQ(hr, S_OK); ASSERT_EQ(hr, S_OK);
@ -401,15 +401,15 @@ class D3D12SharedHandleUsageTests : public D3D12ResourceTestBase {
TEST_P(D3D12SharedHandleUsageTests, ClearInD3D11CopyAndReadbackInD3D12) { TEST_P(D3D12SharedHandleUsageTests, ClearInD3D11CopyAndReadbackInD3D12) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
const dawn::Color clearColor{1.0f, 1.0f, 0.0f, 1.0f}; const wgpu::Color clearColor{1.0f, 1.0f, 0.0f, 1.0f};
dawn::Texture dawnSrcTexture; wgpu::Texture dawnSrcTexture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ComPtr<IDXGIKeyedMutex> dxgiKeyedMutex; ComPtr<IDXGIKeyedMutex> dxgiKeyedMutex;
WrapAndClearD3D11Texture(&dawnDescriptor, &d3dDescriptor, &dawnSrcTexture, clearColor, WrapAndClearD3D11Texture(&dawnDescriptor, &d3dDescriptor, &dawnSrcTexture, clearColor,
&d3d11Texture, &dxgiKeyedMutex); &d3d11Texture, &dxgiKeyedMutex);
// Create a texture on the device and copy the source texture to it. // Create a texture on the device and copy the source texture to it.
dawn::Texture dawnCopyDestTexture = device.CreateTexture(&dawnDescriptor); wgpu::Texture dawnCopyDestTexture = device.CreateTexture(&dawnDescriptor);
SimpleCopyTextureToTexture(dawnSrcTexture, dawnCopyDestTexture); SimpleCopyTextureToTexture(dawnSrcTexture, dawnCopyDestTexture);
// Readback the destination texture and ensure it contains the colors we used // Readback the destination texture and ensure it contains the colors we used
@ -424,8 +424,8 @@ TEST_P(D3D12SharedHandleUsageTests, ClearInD3D11CopyAndReadbackInD3D12) {
TEST_P(D3D12SharedHandleUsageTests, ClearInD3D11ReadbackInD3D12) { TEST_P(D3D12SharedHandleUsageTests, ClearInD3D11ReadbackInD3D12) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
const dawn::Color clearColor{1.0f, 1.0f, 0.0f, 1.0f}; const wgpu::Color clearColor{1.0f, 1.0f, 0.0f, 1.0f};
dawn::Texture dawnTexture; wgpu::Texture dawnTexture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ComPtr<IDXGIKeyedMutex> dxgiKeyedMutex; ComPtr<IDXGIKeyedMutex> dxgiKeyedMutex;
WrapAndClearD3D11Texture(&dawnDescriptor, &d3dDescriptor, &dawnTexture, clearColor, WrapAndClearD3D11Texture(&dawnDescriptor, &d3dDescriptor, &dawnTexture, clearColor,
@ -444,14 +444,14 @@ TEST_P(D3D12SharedHandleUsageTests, ClearInD3D11ReadbackInD3D12) {
TEST_P(D3D12SharedHandleUsageTests, ClearInD3D12ReadbackInD3D11) { TEST_P(D3D12SharedHandleUsageTests, ClearInD3D12ReadbackInD3D11) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
const dawn::Color d3d11ClearColor{1.0f, 1.0f, 0.0f, 1.0f}; const wgpu::Color d3d11ClearColor{1.0f, 1.0f, 0.0f, 1.0f};
dawn::Texture dawnTexture; wgpu::Texture dawnTexture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ComPtr<IDXGIKeyedMutex> dxgiKeyedMutex; ComPtr<IDXGIKeyedMutex> dxgiKeyedMutex;
WrapAndClearD3D11Texture(&dawnDescriptor, &d3dDescriptor, &dawnTexture, d3d11ClearColor, WrapAndClearD3D11Texture(&dawnDescriptor, &d3dDescriptor, &dawnTexture, d3d11ClearColor,
&d3d11Texture, &dxgiKeyedMutex); &d3d11Texture, &dxgiKeyedMutex);
const dawn::Color d3d12ClearColor{0.0f, 0.0f, 1.0f, 1.0f}; const wgpu::Color d3d12ClearColor{0.0f, 0.0f, 1.0f, 1.0f};
ClearImage(dawnTexture, d3d12ClearColor); ClearImage(dawnTexture, d3d12ClearColor);
dawnTexture.Destroy(); dawnTexture.Destroy();
@ -469,17 +469,17 @@ TEST_P(D3D12SharedHandleUsageTests, ClearInD3D12ReadbackInD3D11) {
TEST_P(D3D12SharedHandleUsageTests, ClearTwiceInD3D12ReadbackInD3D11) { TEST_P(D3D12SharedHandleUsageTests, ClearTwiceInD3D12ReadbackInD3D11) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
const dawn::Color d3d11ClearColor{1.0f, 1.0f, 0.0f, 1.0f}; const wgpu::Color d3d11ClearColor{1.0f, 1.0f, 0.0f, 1.0f};
dawn::Texture dawnTexture; wgpu::Texture dawnTexture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ComPtr<IDXGIKeyedMutex> dxgiKeyedMutex; ComPtr<IDXGIKeyedMutex> dxgiKeyedMutex;
WrapAndClearD3D11Texture(&dawnDescriptor, &d3dDescriptor, &dawnTexture, d3d11ClearColor, WrapAndClearD3D11Texture(&dawnDescriptor, &d3dDescriptor, &dawnTexture, d3d11ClearColor,
&d3d11Texture, &dxgiKeyedMutex); &d3d11Texture, &dxgiKeyedMutex);
const dawn::Color d3d12ClearColor1{0.0f, 0.0f, 1.0f, 1.0f}; const wgpu::Color d3d12ClearColor1{0.0f, 0.0f, 1.0f, 1.0f};
ClearImage(dawnTexture, d3d12ClearColor1); ClearImage(dawnTexture, d3d12ClearColor1);
const dawn::Color d3d12ClearColor2{0.0f, 1.0f, 1.0f, 1.0f}; const wgpu::Color d3d12ClearColor2{0.0f, 1.0f, 1.0f, 1.0f};
ClearImage(dawnTexture, d3d12ClearColor2); ClearImage(dawnTexture, d3d12ClearColor2);
dawnTexture.Destroy(); dawnTexture.Destroy();

View File

@ -22,23 +22,23 @@ class DebugMarkerTests : public DawnTest {};
TEST_P(DebugMarkerTests, NoFailureWithoutDebugToolAttached) { TEST_P(DebugMarkerTests, NoFailureWithoutDebugToolAttached) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 4, 4); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 4, 4);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.PushDebugGroup("Event Start"); pass.PushDebugGroup("Event Start");
pass.InsertDebugMarker("Marker"); pass.InsertDebugMarker("Marker");
pass.PopDebugGroup(); pass.PopDebugGroup();
pass.EndPass(); pass.EndPass();
} }
{ {
dawn::ComputePassEncoder pass = encoder.BeginComputePass(); wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.PushDebugGroup("Event Start"); pass.PushDebugGroup("Event Start");
pass.InsertDebugMarker("Marker"); pass.InsertDebugMarker("Marker");
pass.PopDebugGroup(); pass.PopDebugGroup();
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
} }

View File

@ -25,31 +25,31 @@ class DepthStencilStateTest : public DawnTest {
void TestSetUp() override { void TestSetUp() override {
DawnTest::TestSetUp(); DawnTest::TestSetUp();
dawn::TextureDescriptor renderTargetDescriptor; wgpu::TextureDescriptor renderTargetDescriptor;
renderTargetDescriptor.dimension = dawn::TextureDimension::e2D; renderTargetDescriptor.dimension = wgpu::TextureDimension::e2D;
renderTargetDescriptor.size.width = kRTSize; renderTargetDescriptor.size.width = kRTSize;
renderTargetDescriptor.size.height = kRTSize; renderTargetDescriptor.size.height = kRTSize;
renderTargetDescriptor.size.depth = 1; renderTargetDescriptor.size.depth = 1;
renderTargetDescriptor.arrayLayerCount = 1; renderTargetDescriptor.arrayLayerCount = 1;
renderTargetDescriptor.sampleCount = 1; renderTargetDescriptor.sampleCount = 1;
renderTargetDescriptor.format = dawn::TextureFormat::RGBA8Unorm; renderTargetDescriptor.format = wgpu::TextureFormat::RGBA8Unorm;
renderTargetDescriptor.mipLevelCount = 1; renderTargetDescriptor.mipLevelCount = 1;
renderTargetDescriptor.usage = renderTargetDescriptor.usage =
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc; wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
renderTarget = device.CreateTexture(&renderTargetDescriptor); renderTarget = device.CreateTexture(&renderTargetDescriptor);
renderTargetView = renderTarget.CreateView(); renderTargetView = renderTarget.CreateView();
dawn::TextureDescriptor depthDescriptor; wgpu::TextureDescriptor depthDescriptor;
depthDescriptor.dimension = dawn::TextureDimension::e2D; depthDescriptor.dimension = wgpu::TextureDimension::e2D;
depthDescriptor.size.width = kRTSize; depthDescriptor.size.width = kRTSize;
depthDescriptor.size.height = kRTSize; depthDescriptor.size.height = kRTSize;
depthDescriptor.size.depth = 1; depthDescriptor.size.depth = 1;
depthDescriptor.arrayLayerCount = 1; depthDescriptor.arrayLayerCount = 1;
depthDescriptor.sampleCount = 1; depthDescriptor.sampleCount = 1;
depthDescriptor.format = dawn::TextureFormat::Depth24PlusStencil8; depthDescriptor.format = wgpu::TextureFormat::Depth24PlusStencil8;
depthDescriptor.mipLevelCount = 1; depthDescriptor.mipLevelCount = 1;
depthDescriptor.usage = dawn::TextureUsage::OutputAttachment; depthDescriptor.usage = wgpu::TextureUsage::OutputAttachment;
depthTexture = device.CreateTexture(&depthDescriptor); depthTexture = device.CreateTexture(&depthDescriptor);
depthTextureView = depthTexture.CreateView(); depthTextureView = depthTexture.CreateView();
@ -83,15 +83,15 @@ class DepthStencilStateTest : public DawnTest {
bindGroupLayout = utils::MakeBindGroupLayout( bindGroupLayout = utils::MakeBindGroupLayout(
device, { device, {
{0, dawn::ShaderStage::Vertex | dawn::ShaderStage::Fragment, {0, wgpu::ShaderStage::Vertex | wgpu::ShaderStage::Fragment,
dawn::BindingType::UniformBuffer}, wgpu::BindingType::UniformBuffer},
}); });
pipelineLayout = utils::MakeBasicPipelineLayout(device, &bindGroupLayout); pipelineLayout = utils::MakeBasicPipelineLayout(device, &bindGroupLayout);
} }
struct TestSpec { struct TestSpec {
const dawn::DepthStencilStateDescriptor& depthStencilState; const wgpu::DepthStencilStateDescriptor& depthStencilState;
RGBA8 color; RGBA8 color;
float depth; float depth;
uint32_t stencil; uint32_t stencil;
@ -99,22 +99,25 @@ class DepthStencilStateTest : public DawnTest {
// Check whether a depth comparison function works as expected // Check whether a depth comparison function works as expected
// The less, equal, greater booleans denote wether the respective triangle should be visible based on the comparison function // The less, equal, greater booleans denote wether the respective triangle should be visible based on the comparison function
void CheckDepthCompareFunction(dawn::CompareFunction compareFunction, bool less, bool equal, bool greater) { void CheckDepthCompareFunction(wgpu::CompareFunction compareFunction,
dawn::StencilStateFaceDescriptor stencilFace; bool less,
stencilFace.compare = dawn::CompareFunction::Always; bool equal,
stencilFace.failOp = dawn::StencilOperation::Keep; bool greater) {
stencilFace.depthFailOp = dawn::StencilOperation::Keep; wgpu::StencilStateFaceDescriptor stencilFace;
stencilFace.passOp = dawn::StencilOperation::Keep; stencilFace.compare = wgpu::CompareFunction::Always;
stencilFace.failOp = wgpu::StencilOperation::Keep;
stencilFace.depthFailOp = wgpu::StencilOperation::Keep;
stencilFace.passOp = wgpu::StencilOperation::Keep;
dawn::DepthStencilStateDescriptor baseState; wgpu::DepthStencilStateDescriptor baseState;
baseState.depthWriteEnabled = true; baseState.depthWriteEnabled = true;
baseState.depthCompare = dawn::CompareFunction::Always; baseState.depthCompare = wgpu::CompareFunction::Always;
baseState.stencilBack = stencilFace; baseState.stencilBack = stencilFace;
baseState.stencilFront = stencilFace; baseState.stencilFront = stencilFace;
baseState.stencilReadMask = 0xff; baseState.stencilReadMask = 0xff;
baseState.stencilWriteMask = 0xff; baseState.stencilWriteMask = 0xff;
dawn::DepthStencilStateDescriptor state; wgpu::DepthStencilStateDescriptor state;
state.depthWriteEnabled = true; state.depthWriteEnabled = true;
state.depthCompare = compareFunction; state.depthCompare = compareFunction;
state.stencilBack = stencilFace; state.stencilBack = stencilFace;
@ -143,28 +146,31 @@ class DepthStencilStateTest : public DawnTest {
// Check whether a stencil comparison function works as expected // Check whether a stencil comparison function works as expected
// The less, equal, greater booleans denote wether the respective triangle should be visible based on the comparison function // The less, equal, greater booleans denote wether the respective triangle should be visible based on the comparison function
void CheckStencilCompareFunction(dawn::CompareFunction compareFunction, bool less, bool equal, bool greater) { void CheckStencilCompareFunction(wgpu::CompareFunction compareFunction,
dawn::StencilStateFaceDescriptor baseStencilFaceDescriptor; bool less,
baseStencilFaceDescriptor.compare = dawn::CompareFunction::Always; bool equal,
baseStencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; bool greater) {
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; wgpu::StencilStateFaceDescriptor baseStencilFaceDescriptor;
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace; baseStencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
dawn::DepthStencilStateDescriptor baseState; baseStencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace;
wgpu::DepthStencilStateDescriptor baseState;
baseState.depthWriteEnabled = false; baseState.depthWriteEnabled = false;
baseState.depthCompare = dawn::CompareFunction::Always; baseState.depthCompare = wgpu::CompareFunction::Always;
baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilBack = baseStencilFaceDescriptor;
baseState.stencilFront = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor;
baseState.stencilReadMask = 0xff; baseState.stencilReadMask = 0xff;
baseState.stencilWriteMask = 0xff; baseState.stencilWriteMask = 0xff;
dawn::StencilStateFaceDescriptor stencilFaceDescriptor; wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
stencilFaceDescriptor.compare = compareFunction; stencilFaceDescriptor.compare = compareFunction;
stencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.passOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep;
dawn::DepthStencilStateDescriptor state; wgpu::DepthStencilStateDescriptor state;
state.depthWriteEnabled = false; state.depthWriteEnabled = false;
state.depthCompare = dawn::CompareFunction::Always; state.depthCompare = wgpu::CompareFunction::Always;
state.stencilBack = stencilFaceDescriptor; state.stencilBack = stencilFaceDescriptor;
state.stencilFront = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor;
state.stencilReadMask = 0xff; state.stencilReadMask = 0xff;
@ -189,28 +195,31 @@ class DepthStencilStateTest : public DawnTest {
} }
// Given the provided `initialStencil` and `reference`, check that applying the `stencilOperation` produces the `expectedStencil` // Given the provided `initialStencil` and `reference`, check that applying the `stencilOperation` produces the `expectedStencil`
void CheckStencilOperation(dawn::StencilOperation stencilOperation, uint32_t initialStencil, uint32_t reference, uint32_t expectedStencil) { void CheckStencilOperation(wgpu::StencilOperation stencilOperation,
dawn::StencilStateFaceDescriptor baseStencilFaceDescriptor; uint32_t initialStencil,
baseStencilFaceDescriptor.compare = dawn::CompareFunction::Always; uint32_t reference,
baseStencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; uint32_t expectedStencil) {
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; wgpu::StencilStateFaceDescriptor baseStencilFaceDescriptor;
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace; baseStencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
dawn::DepthStencilStateDescriptor baseState; baseStencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace;
wgpu::DepthStencilStateDescriptor baseState;
baseState.depthWriteEnabled = false; baseState.depthWriteEnabled = false;
baseState.depthCompare = dawn::CompareFunction::Always; baseState.depthCompare = wgpu::CompareFunction::Always;
baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilBack = baseStencilFaceDescriptor;
baseState.stencilFront = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor;
baseState.stencilReadMask = 0xff; baseState.stencilReadMask = 0xff;
baseState.stencilWriteMask = 0xff; baseState.stencilWriteMask = 0xff;
dawn::StencilStateFaceDescriptor stencilFaceDescriptor; wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
stencilFaceDescriptor.compare = dawn::CompareFunction::Always; stencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
stencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.passOp = stencilOperation; stencilFaceDescriptor.passOp = stencilOperation;
dawn::DepthStencilStateDescriptor state; wgpu::DepthStencilStateDescriptor state;
state.depthWriteEnabled = false; state.depthWriteEnabled = false;
state.depthCompare = dawn::CompareFunction::Always; state.depthCompare = wgpu::CompareFunction::Always;
state.stencilBack = stencilFaceDescriptor; state.stencilBack = stencilFaceDescriptor;
state.stencilFront = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor;
state.stencilReadMask = 0xff; state.stencilReadMask = 0xff;
@ -227,14 +236,14 @@ class DepthStencilStateTest : public DawnTest {
// Draw a list of test specs, and check if the stencil value is equal to the expected value // Draw a list of test specs, and check if the stencil value is equal to the expected value
void CheckStencil(std::vector<TestSpec> testParams, uint32_t expectedStencil) { void CheckStencil(std::vector<TestSpec> testParams, uint32_t expectedStencil) {
dawn::StencilStateFaceDescriptor stencilFaceDescriptor; wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
stencilFaceDescriptor.compare = dawn::CompareFunction::Equal; stencilFaceDescriptor.compare = wgpu::CompareFunction::Equal;
stencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.passOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep;
dawn::DepthStencilStateDescriptor state; wgpu::DepthStencilStateDescriptor state;
state.depthWriteEnabled = false; state.depthWriteEnabled = false;
state.depthCompare = dawn::CompareFunction::Always; state.depthCompare = wgpu::CompareFunction::Always;
state.stencilBack = stencilFaceDescriptor; state.stencilBack = stencilFaceDescriptor;
state.stencilFront = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor;
state.stencilReadMask = 0xff; state.stencilReadMask = 0xff;
@ -247,7 +256,7 @@ class DepthStencilStateTest : public DawnTest {
// Each test param represents a pair of triangles with a color, depth, stencil value, and depthStencil state, one frontfacing, one backfacing // 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 // 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) { void DoTest(const std::vector<TestSpec> &testParams, const RGBA8& expectedFront, const RGBA8& expectedBack) {
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
struct TriangleData { struct TriangleData {
float color[3]; float color[3];
@ -255,7 +264,7 @@ class DepthStencilStateTest : public DawnTest {
}; };
utils::ComboRenderPassDescriptor renderPass({renderTargetView}, depthTextureView); utils::ComboRenderPassDescriptor renderPass({renderTargetView}, depthTextureView);
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
for (size_t i = 0; i < testParams.size(); ++i) { for (size_t i = 0; i < testParams.size(); ++i) {
const TestSpec& test = testParams[i]; const TestSpec& test = testParams[i];
@ -265,11 +274,12 @@ class DepthStencilStateTest : public DawnTest {
test.depth, test.depth,
}; };
// Upload a buffer for each triangle's depth and color data // Upload a buffer for each triangle's depth and color data
dawn::Buffer buffer = utils::CreateBufferFromData( wgpu::Buffer buffer = utils::CreateBufferFromData(
device, &data, sizeof(TriangleData), dawn::BufferUsage::Uniform); device, &data, sizeof(TriangleData), wgpu::BufferUsage::Uniform);
// Create a bind group for the data // Create a bind group for the data
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, bindGroupLayout, {{0, buffer, 0, sizeof(TriangleData)}}); wgpu::BindGroup bindGroup = utils::MakeBindGroup(
device, bindGroupLayout, {{0, buffer, 0, sizeof(TriangleData)}});
// Create a pipeline for the triangles with the test spec's depth stencil state // Create a pipeline for the triangles with the test spec's depth stencil state
@ -278,10 +288,10 @@ class DepthStencilStateTest : public DawnTest {
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.cDepthStencilState = test.depthStencilState; descriptor.cDepthStencilState = test.depthStencilState;
descriptor.cDepthStencilState.format = dawn::TextureFormat::Depth24PlusStencil8; descriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
descriptor.depthStencilState = &descriptor.cDepthStencilState; descriptor.depthStencilState = &descriptor.cDepthStencilState;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetStencilReference(test.stencil); // Set the stencil reference pass.SetStencilReference(test.stencil); // Set the stencil reference
@ -291,7 +301,7 @@ class DepthStencilStateTest : public DawnTest {
} }
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(expectedFront, renderTarget, kRTSize / 4, kRTSize / 2) << "Front face check failed"; EXPECT_PIXEL_RGBA8_EQ(expectedFront, renderTarget, kRTSize / 4, kRTSize / 2) << "Front face check failed";
@ -302,27 +312,27 @@ class DepthStencilStateTest : public DawnTest {
DoTest(testParams, expected, expected); DoTest(testParams, expected, expected);
} }
dawn::Texture renderTarget; wgpu::Texture renderTarget;
dawn::Texture depthTexture; wgpu::Texture depthTexture;
dawn::TextureView renderTargetView; wgpu::TextureView renderTargetView;
dawn::TextureView depthTextureView; wgpu::TextureView depthTextureView;
dawn::ShaderModule vsModule; wgpu::ShaderModule vsModule;
dawn::ShaderModule fsModule; wgpu::ShaderModule fsModule;
dawn::BindGroupLayout bindGroupLayout; wgpu::BindGroupLayout bindGroupLayout;
dawn::PipelineLayout pipelineLayout; wgpu::PipelineLayout pipelineLayout;
}; };
// Test compilation and usage of the fixture // Test compilation and usage of the fixture
TEST_P(DepthStencilStateTest, Basic) { TEST_P(DepthStencilStateTest, Basic) {
dawn::StencilStateFaceDescriptor stencilFace; wgpu::StencilStateFaceDescriptor stencilFace;
stencilFace.compare = dawn::CompareFunction::Always; stencilFace.compare = wgpu::CompareFunction::Always;
stencilFace.failOp = dawn::StencilOperation::Keep; stencilFace.failOp = wgpu::StencilOperation::Keep;
stencilFace.depthFailOp = dawn::StencilOperation::Keep; stencilFace.depthFailOp = wgpu::StencilOperation::Keep;
stencilFace.passOp = dawn::StencilOperation::Keep; stencilFace.passOp = wgpu::StencilOperation::Keep;
dawn::DepthStencilStateDescriptor state; wgpu::DepthStencilStateDescriptor state;
state.depthWriteEnabled = false; state.depthWriteEnabled = false;
state.depthCompare = dawn::CompareFunction::Always; state.depthCompare = wgpu::CompareFunction::Always;
state.stencilBack = stencilFace; state.stencilBack = stencilFace;
state.stencilFront = stencilFace; state.stencilFront = stencilFace;
state.stencilReadMask = 0xff; state.stencilReadMask = 0xff;
@ -335,15 +345,15 @@ TEST_P(DepthStencilStateTest, Basic) {
// Test defaults: depth and stencil tests disabled // Test defaults: depth and stencil tests disabled
TEST_P(DepthStencilStateTest, DepthStencilDisabled) { TEST_P(DepthStencilStateTest, DepthStencilDisabled) {
dawn::StencilStateFaceDescriptor stencilFace; wgpu::StencilStateFaceDescriptor stencilFace;
stencilFace.compare = dawn::CompareFunction::Always; stencilFace.compare = wgpu::CompareFunction::Always;
stencilFace.failOp = dawn::StencilOperation::Keep; stencilFace.failOp = wgpu::StencilOperation::Keep;
stencilFace.depthFailOp = dawn::StencilOperation::Keep; stencilFace.depthFailOp = wgpu::StencilOperation::Keep;
stencilFace.passOp = dawn::StencilOperation::Keep; stencilFace.passOp = wgpu::StencilOperation::Keep;
dawn::DepthStencilStateDescriptor state; wgpu::DepthStencilStateDescriptor state;
state.depthWriteEnabled = false; state.depthWriteEnabled = false;
state.depthCompare = dawn::CompareFunction::Always; state.depthCompare = wgpu::CompareFunction::Always;
state.stencilBack = stencilFace; state.stencilBack = stencilFace;
state.stencilFront = stencilFace; state.stencilFront = stencilFace;
state.stencilReadMask = 0xff; state.stencilReadMask = 0xff;
@ -367,64 +377,64 @@ TEST_P(DepthStencilStateTest, DepthStencilDisabled) {
// The following tests check that each depth comparison function works // The following tests check that each depth comparison function works
TEST_P(DepthStencilStateTest, DepthAlways) { TEST_P(DepthStencilStateTest, DepthAlways) {
CheckDepthCompareFunction(dawn::CompareFunction::Always , true, true, true); CheckDepthCompareFunction(wgpu::CompareFunction::Always, true, true, true);
} }
TEST_P(DepthStencilStateTest, DepthEqual) { TEST_P(DepthStencilStateTest, DepthEqual) {
CheckDepthCompareFunction(dawn::CompareFunction::Equal, false, true, false); CheckDepthCompareFunction(wgpu::CompareFunction::Equal, false, true, false);
} }
TEST_P(DepthStencilStateTest, DepthGreater) { TEST_P(DepthStencilStateTest, DepthGreater) {
CheckDepthCompareFunction(dawn::CompareFunction::Greater, false, false, true); CheckDepthCompareFunction(wgpu::CompareFunction::Greater, false, false, true);
} }
TEST_P(DepthStencilStateTest, DepthGreaterEqual) { TEST_P(DepthStencilStateTest, DepthGreaterEqual) {
CheckDepthCompareFunction(dawn::CompareFunction::GreaterEqual, false, true, true); CheckDepthCompareFunction(wgpu::CompareFunction::GreaterEqual, false, true, true);
} }
TEST_P(DepthStencilStateTest, DepthLess) { TEST_P(DepthStencilStateTest, DepthLess) {
CheckDepthCompareFunction(dawn::CompareFunction::Less, true, false, false); CheckDepthCompareFunction(wgpu::CompareFunction::Less, true, false, false);
} }
TEST_P(DepthStencilStateTest, DepthLessEqual) { TEST_P(DepthStencilStateTest, DepthLessEqual) {
CheckDepthCompareFunction(dawn::CompareFunction::LessEqual, true, true, false); CheckDepthCompareFunction(wgpu::CompareFunction::LessEqual, true, true, false);
} }
TEST_P(DepthStencilStateTest, DepthNever) { TEST_P(DepthStencilStateTest, DepthNever) {
CheckDepthCompareFunction(dawn::CompareFunction::Never, false, false, false); CheckDepthCompareFunction(wgpu::CompareFunction::Never, false, false, false);
} }
TEST_P(DepthStencilStateTest, DepthNotEqual) { TEST_P(DepthStencilStateTest, DepthNotEqual) {
CheckDepthCompareFunction(dawn::CompareFunction::NotEqual, true, false, true); CheckDepthCompareFunction(wgpu::CompareFunction::NotEqual, true, false, true);
} }
// Test that disabling depth writes works and leaves the depth buffer unchanged // Test that disabling depth writes works and leaves the depth buffer unchanged
TEST_P(DepthStencilStateTest, DepthWriteDisabled) { TEST_P(DepthStencilStateTest, DepthWriteDisabled) {
dawn::StencilStateFaceDescriptor stencilFace; wgpu::StencilStateFaceDescriptor stencilFace;
stencilFace.compare = dawn::CompareFunction::Always; stencilFace.compare = wgpu::CompareFunction::Always;
stencilFace.failOp = dawn::StencilOperation::Keep; stencilFace.failOp = wgpu::StencilOperation::Keep;
stencilFace.depthFailOp = dawn::StencilOperation::Keep; stencilFace.depthFailOp = wgpu::StencilOperation::Keep;
stencilFace.passOp = dawn::StencilOperation::Keep; stencilFace.passOp = wgpu::StencilOperation::Keep;
dawn::DepthStencilStateDescriptor baseState; wgpu::DepthStencilStateDescriptor baseState;
baseState.depthWriteEnabled = true; baseState.depthWriteEnabled = true;
baseState.depthCompare = dawn::CompareFunction::Always; baseState.depthCompare = wgpu::CompareFunction::Always;
baseState.stencilBack = stencilFace; baseState.stencilBack = stencilFace;
baseState.stencilFront = stencilFace; baseState.stencilFront = stencilFace;
baseState.stencilReadMask = 0xff; baseState.stencilReadMask = 0xff;
baseState.stencilWriteMask = 0xff; baseState.stencilWriteMask = 0xff;
dawn::DepthStencilStateDescriptor noDepthWrite; wgpu::DepthStencilStateDescriptor noDepthWrite;
noDepthWrite.depthWriteEnabled = false; noDepthWrite.depthWriteEnabled = false;
noDepthWrite.depthCompare = dawn::CompareFunction::Always; noDepthWrite.depthCompare = wgpu::CompareFunction::Always;
noDepthWrite.stencilBack = stencilFace; noDepthWrite.stencilBack = stencilFace;
noDepthWrite.stencilFront = stencilFace; noDepthWrite.stencilFront = stencilFace;
noDepthWrite.stencilReadMask = 0xff; noDepthWrite.stencilReadMask = 0xff;
noDepthWrite.stencilWriteMask = 0xff; noDepthWrite.stencilWriteMask = 0xff;
dawn::DepthStencilStateDescriptor checkState; wgpu::DepthStencilStateDescriptor checkState;
checkState.depthWriteEnabled = false; checkState.depthWriteEnabled = false;
checkState.depthCompare = dawn::CompareFunction::Equal; checkState.depthCompare = wgpu::CompareFunction::Equal;
checkState.stencilBack = stencilFace; checkState.stencilBack = stencilFace;
checkState.stencilFront = stencilFace; checkState.stencilFront = stencilFace;
checkState.stencilReadMask = 0xff; checkState.stencilReadMask = 0xff;
@ -439,97 +449,97 @@ TEST_P(DepthStencilStateTest, DepthWriteDisabled) {
// The following tests check that each stencil comparison function works // The following tests check that each stencil comparison function works
TEST_P(DepthStencilStateTest, StencilAlways) { TEST_P(DepthStencilStateTest, StencilAlways) {
CheckStencilCompareFunction(dawn::CompareFunction::Always, true, true, true); CheckStencilCompareFunction(wgpu::CompareFunction::Always, true, true, true);
} }
TEST_P(DepthStencilStateTest, StencilEqual) { TEST_P(DepthStencilStateTest, StencilEqual) {
CheckStencilCompareFunction(dawn::CompareFunction::Equal, false, true, false); CheckStencilCompareFunction(wgpu::CompareFunction::Equal, false, true, false);
} }
TEST_P(DepthStencilStateTest, StencilGreater) { TEST_P(DepthStencilStateTest, StencilGreater) {
CheckStencilCompareFunction(dawn::CompareFunction::Greater, false, false, true); CheckStencilCompareFunction(wgpu::CompareFunction::Greater, false, false, true);
} }
TEST_P(DepthStencilStateTest, StencilGreaterEqual) { TEST_P(DepthStencilStateTest, StencilGreaterEqual) {
CheckStencilCompareFunction(dawn::CompareFunction::GreaterEqual, false, true, true); CheckStencilCompareFunction(wgpu::CompareFunction::GreaterEqual, false, true, true);
} }
TEST_P(DepthStencilStateTest, StencilLess) { TEST_P(DepthStencilStateTest, StencilLess) {
CheckStencilCompareFunction(dawn::CompareFunction::Less, true, false, false); CheckStencilCompareFunction(wgpu::CompareFunction::Less, true, false, false);
} }
TEST_P(DepthStencilStateTest, StencilLessEqual) { TEST_P(DepthStencilStateTest, StencilLessEqual) {
CheckStencilCompareFunction(dawn::CompareFunction::LessEqual, true, true, false); CheckStencilCompareFunction(wgpu::CompareFunction::LessEqual, true, true, false);
} }
TEST_P(DepthStencilStateTest, StencilNever) { TEST_P(DepthStencilStateTest, StencilNever) {
CheckStencilCompareFunction(dawn::CompareFunction::Never, false, false, false); CheckStencilCompareFunction(wgpu::CompareFunction::Never, false, false, false);
} }
TEST_P(DepthStencilStateTest, StencilNotEqual) { TEST_P(DepthStencilStateTest, StencilNotEqual) {
CheckStencilCompareFunction(dawn::CompareFunction::NotEqual, true, false, true); CheckStencilCompareFunction(wgpu::CompareFunction::NotEqual, true, false, true);
} }
// The following tests check that each stencil operation works // The following tests check that each stencil operation works
TEST_P(DepthStencilStateTest, StencilKeep) { TEST_P(DepthStencilStateTest, StencilKeep) {
CheckStencilOperation(dawn::StencilOperation::Keep, 1, 3, 1); CheckStencilOperation(wgpu::StencilOperation::Keep, 1, 3, 1);
} }
TEST_P(DepthStencilStateTest, StencilZero) { TEST_P(DepthStencilStateTest, StencilZero) {
CheckStencilOperation(dawn::StencilOperation::Zero, 1, 3, 0); CheckStencilOperation(wgpu::StencilOperation::Zero, 1, 3, 0);
} }
TEST_P(DepthStencilStateTest, StencilReplace) { TEST_P(DepthStencilStateTest, StencilReplace) {
CheckStencilOperation(dawn::StencilOperation::Replace, 1, 3, 3); CheckStencilOperation(wgpu::StencilOperation::Replace, 1, 3, 3);
} }
TEST_P(DepthStencilStateTest, StencilInvert) { TEST_P(DepthStencilStateTest, StencilInvert) {
CheckStencilOperation(dawn::StencilOperation::Invert, 0xf0, 3, 0x0f); CheckStencilOperation(wgpu::StencilOperation::Invert, 0xf0, 3, 0x0f);
} }
TEST_P(DepthStencilStateTest, StencilIncrementClamp) { TEST_P(DepthStencilStateTest, StencilIncrementClamp) {
CheckStencilOperation(dawn::StencilOperation::IncrementClamp, 1, 3, 2); CheckStencilOperation(wgpu::StencilOperation::IncrementClamp, 1, 3, 2);
CheckStencilOperation(dawn::StencilOperation::IncrementClamp, 0xff, 3, 0xff); CheckStencilOperation(wgpu::StencilOperation::IncrementClamp, 0xff, 3, 0xff);
} }
TEST_P(DepthStencilStateTest, StencilIncrementWrap) { TEST_P(DepthStencilStateTest, StencilIncrementWrap) {
CheckStencilOperation(dawn::StencilOperation::IncrementWrap, 1, 3, 2); CheckStencilOperation(wgpu::StencilOperation::IncrementWrap, 1, 3, 2);
CheckStencilOperation(dawn::StencilOperation::IncrementWrap, 0xff, 3, 0); CheckStencilOperation(wgpu::StencilOperation::IncrementWrap, 0xff, 3, 0);
} }
TEST_P(DepthStencilStateTest, StencilDecrementClamp) { TEST_P(DepthStencilStateTest, StencilDecrementClamp) {
CheckStencilOperation(dawn::StencilOperation::DecrementClamp, 1, 3, 0); CheckStencilOperation(wgpu::StencilOperation::DecrementClamp, 1, 3, 0);
CheckStencilOperation(dawn::StencilOperation::DecrementClamp, 0, 3, 0); CheckStencilOperation(wgpu::StencilOperation::DecrementClamp, 0, 3, 0);
} }
TEST_P(DepthStencilStateTest, StencilDecrementWrap) { TEST_P(DepthStencilStateTest, StencilDecrementWrap) {
CheckStencilOperation(dawn::StencilOperation::DecrementWrap, 1, 3, 0); CheckStencilOperation(wgpu::StencilOperation::DecrementWrap, 1, 3, 0);
CheckStencilOperation(dawn::StencilOperation::DecrementWrap, 0, 3, 0xff); CheckStencilOperation(wgpu::StencilOperation::DecrementWrap, 0, 3, 0xff);
} }
// Check that the setting a stencil read mask works // Check that the setting a stencil read mask works
TEST_P(DepthStencilStateTest, StencilReadMask) { TEST_P(DepthStencilStateTest, StencilReadMask) {
dawn::StencilStateFaceDescriptor baseStencilFaceDescriptor; wgpu::StencilStateFaceDescriptor baseStencilFaceDescriptor;
baseStencilFaceDescriptor.compare = dawn::CompareFunction::Always; baseStencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
baseStencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; baseStencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace; baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace;
dawn::DepthStencilStateDescriptor baseState; wgpu::DepthStencilStateDescriptor baseState;
baseState.depthWriteEnabled = false; baseState.depthWriteEnabled = false;
baseState.depthCompare = dawn::CompareFunction::Always; baseState.depthCompare = wgpu::CompareFunction::Always;
baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilBack = baseStencilFaceDescriptor;
baseState.stencilFront = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor;
baseState.stencilReadMask = 0xff; baseState.stencilReadMask = 0xff;
baseState.stencilWriteMask = 0xff; baseState.stencilWriteMask = 0xff;
dawn::StencilStateFaceDescriptor stencilFaceDescriptor; wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
stencilFaceDescriptor.compare = dawn::CompareFunction::Equal; stencilFaceDescriptor.compare = wgpu::CompareFunction::Equal;
stencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.passOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep;
dawn::DepthStencilStateDescriptor state; wgpu::DepthStencilStateDescriptor state;
state.depthWriteEnabled = false; state.depthWriteEnabled = false;
state.depthCompare = dawn::CompareFunction::Always; state.depthCompare = wgpu::CompareFunction::Always;
state.stencilBack = stencilFaceDescriptor; state.stencilBack = stencilFaceDescriptor;
state.stencilFront = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor;
state.stencilReadMask = 0x2; state.stencilReadMask = 0x2;
@ -546,27 +556,27 @@ TEST_P(DepthStencilStateTest, StencilReadMask) {
// Check that setting a stencil write mask works // Check that setting a stencil write mask works
TEST_P(DepthStencilStateTest, StencilWriteMask) { TEST_P(DepthStencilStateTest, StencilWriteMask) {
dawn::StencilStateFaceDescriptor baseStencilFaceDescriptor; wgpu::StencilStateFaceDescriptor baseStencilFaceDescriptor;
baseStencilFaceDescriptor.compare = dawn::CompareFunction::Always; baseStencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
baseStencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; baseStencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace; baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace;
dawn::DepthStencilStateDescriptor baseState; wgpu::DepthStencilStateDescriptor baseState;
baseState.depthWriteEnabled = false; baseState.depthWriteEnabled = false;
baseState.depthCompare = dawn::CompareFunction::Always; baseState.depthCompare = wgpu::CompareFunction::Always;
baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilBack = baseStencilFaceDescriptor;
baseState.stencilFront = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor;
baseState.stencilReadMask = 0xff; baseState.stencilReadMask = 0xff;
baseState.stencilWriteMask = 0x1; baseState.stencilWriteMask = 0x1;
dawn::StencilStateFaceDescriptor stencilFaceDescriptor; wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
stencilFaceDescriptor.compare = dawn::CompareFunction::Equal; stencilFaceDescriptor.compare = wgpu::CompareFunction::Equal;
stencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.passOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep;
dawn::DepthStencilStateDescriptor state; wgpu::DepthStencilStateDescriptor state;
state.depthWriteEnabled = false; state.depthWriteEnabled = false;
state.depthCompare = dawn::CompareFunction::Always; state.depthCompare = wgpu::CompareFunction::Always;
state.stencilBack = stencilFaceDescriptor; state.stencilBack = stencilFaceDescriptor;
state.stencilFront = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor;
state.stencilReadMask = 0xff; state.stencilReadMask = 0xff;
@ -582,27 +592,27 @@ TEST_P(DepthStencilStateTest, StencilWriteMask) {
// Test that the stencil operation is executed on stencil fail // Test that the stencil operation is executed on stencil fail
TEST_P(DepthStencilStateTest, StencilFail) { TEST_P(DepthStencilStateTest, StencilFail) {
dawn::StencilStateFaceDescriptor baseStencilFaceDescriptor; wgpu::StencilStateFaceDescriptor baseStencilFaceDescriptor;
baseStencilFaceDescriptor.compare = dawn::CompareFunction::Always; baseStencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
baseStencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; baseStencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace; baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace;
dawn::DepthStencilStateDescriptor baseState; wgpu::DepthStencilStateDescriptor baseState;
baseState.depthWriteEnabled = false; baseState.depthWriteEnabled = false;
baseState.depthCompare = dawn::CompareFunction::Always; baseState.depthCompare = wgpu::CompareFunction::Always;
baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilBack = baseStencilFaceDescriptor;
baseState.stencilFront = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor;
baseState.stencilReadMask = 0xff; baseState.stencilReadMask = 0xff;
baseState.stencilWriteMask = 0xff; baseState.stencilWriteMask = 0xff;
dawn::StencilStateFaceDescriptor stencilFaceDescriptor; wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
stencilFaceDescriptor.compare = dawn::CompareFunction::Less; stencilFaceDescriptor.compare = wgpu::CompareFunction::Less;
stencilFaceDescriptor.failOp = dawn::StencilOperation::Replace; stencilFaceDescriptor.failOp = wgpu::StencilOperation::Replace;
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.passOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep;
dawn::DepthStencilStateDescriptor state; wgpu::DepthStencilStateDescriptor state;
state.depthWriteEnabled = false; state.depthWriteEnabled = false;
state.depthCompare = dawn::CompareFunction::Always; state.depthCompare = wgpu::CompareFunction::Always;
state.stencilBack = stencilFaceDescriptor; state.stencilBack = stencilFaceDescriptor;
state.stencilFront = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor;
state.stencilReadMask = 0xff; state.stencilReadMask = 0xff;
@ -616,27 +626,27 @@ TEST_P(DepthStencilStateTest, StencilFail) {
// Test that the stencil operation is executed on stencil pass, depth fail // Test that the stencil operation is executed on stencil pass, depth fail
TEST_P(DepthStencilStateTest, StencilDepthFail) { TEST_P(DepthStencilStateTest, StencilDepthFail) {
dawn::StencilStateFaceDescriptor baseStencilFaceDescriptor; wgpu::StencilStateFaceDescriptor baseStencilFaceDescriptor;
baseStencilFaceDescriptor.compare = dawn::CompareFunction::Always; baseStencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
baseStencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; baseStencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace; baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace;
dawn::DepthStencilStateDescriptor baseState; wgpu::DepthStencilStateDescriptor baseState;
baseState.depthWriteEnabled = true; baseState.depthWriteEnabled = true;
baseState.depthCompare = dawn::CompareFunction::Always; baseState.depthCompare = wgpu::CompareFunction::Always;
baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilBack = baseStencilFaceDescriptor;
baseState.stencilFront = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor;
baseState.stencilReadMask = 0xff; baseState.stencilReadMask = 0xff;
baseState.stencilWriteMask = 0xff; baseState.stencilWriteMask = 0xff;
dawn::StencilStateFaceDescriptor stencilFaceDescriptor; wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
stencilFaceDescriptor.compare = dawn::CompareFunction::Greater; stencilFaceDescriptor.compare = wgpu::CompareFunction::Greater;
stencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Replace; stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Replace;
stencilFaceDescriptor.passOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep;
dawn::DepthStencilStateDescriptor state; wgpu::DepthStencilStateDescriptor state;
state.depthWriteEnabled = true; state.depthWriteEnabled = true;
state.depthCompare = dawn::CompareFunction::Less; state.depthCompare = wgpu::CompareFunction::Less;
state.stencilBack = stencilFaceDescriptor; state.stencilBack = stencilFaceDescriptor;
state.stencilFront = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor;
state.stencilReadMask = 0xff; state.stencilReadMask = 0xff;
@ -650,27 +660,27 @@ TEST_P(DepthStencilStateTest, StencilDepthFail) {
// Test that the stencil operation is executed on stencil pass, depth pass // Test that the stencil operation is executed on stencil pass, depth pass
TEST_P(DepthStencilStateTest, StencilDepthPass) { TEST_P(DepthStencilStateTest, StencilDepthPass) {
dawn::StencilStateFaceDescriptor baseStencilFaceDescriptor; wgpu::StencilStateFaceDescriptor baseStencilFaceDescriptor;
baseStencilFaceDescriptor.compare = dawn::CompareFunction::Always; baseStencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
baseStencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; baseStencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace; baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace;
dawn::DepthStencilStateDescriptor baseState; wgpu::DepthStencilStateDescriptor baseState;
baseState.depthWriteEnabled = true; baseState.depthWriteEnabled = true;
baseState.depthCompare = dawn::CompareFunction::Always; baseState.depthCompare = wgpu::CompareFunction::Always;
baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilBack = baseStencilFaceDescriptor;
baseState.stencilFront = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor;
baseState.stencilReadMask = 0xff; baseState.stencilReadMask = 0xff;
baseState.stencilWriteMask = 0xff; baseState.stencilWriteMask = 0xff;
dawn::StencilStateFaceDescriptor stencilFaceDescriptor; wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
stencilFaceDescriptor.compare = dawn::CompareFunction::Greater; stencilFaceDescriptor.compare = wgpu::CompareFunction::Greater;
stencilFaceDescriptor.failOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep; stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
stencilFaceDescriptor.passOp = dawn::StencilOperation::Replace; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace;
dawn::DepthStencilStateDescriptor state; wgpu::DepthStencilStateDescriptor state;
state.depthWriteEnabled = true; state.depthWriteEnabled = true;
state.depthCompare = dawn::CompareFunction::Less; state.depthCompare = wgpu::CompareFunction::Less;
state.stencilBack = stencilFaceDescriptor; state.stencilBack = stencilFaceDescriptor;
state.stencilFront = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor;
state.stencilReadMask = 0xff; state.stencilReadMask = 0xff;

View File

@ -26,7 +26,7 @@ class DestroyTest : public DawnTest {
renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
layout(location = 0) in vec4 pos; layout(location = 0) in vec4 pos;
@ -34,7 +34,7 @@ class DestroyTest : public DawnTest {
gl_Position = pos; gl_Position = pos;
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -45,40 +45,40 @@ class DestroyTest : public DawnTest {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cVertexInput.bufferCount = 1; descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float); descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
descriptor.cVertexInput.cBuffers[0].attributeCount = 1; descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4; descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat; descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor); pipeline = device.CreateRenderPipeline(&descriptor);
vertexBuffer = utils::CreateBufferFromData<float>( vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex, device, wgpu::BufferUsage::Vertex,
{// The bottom left triangle {// The bottom left triangle
-1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f}); -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.BeginRenderPass(&renderPass.renderPassInfo).EndPass(); encoder.BeginRenderPass(&renderPass.renderPassInfo).EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
} }
utils::BasicRenderPass renderPass; utils::BasicRenderPass renderPass;
dawn::RenderPipeline pipeline; wgpu::RenderPipeline pipeline;
dawn::Buffer vertexBuffer; wgpu::Buffer vertexBuffer;
dawn::CommandBuffer CreateTriangleCommandBuffer() { wgpu::CommandBuffer CreateTriangleCommandBuffer() {
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer); pass.SetVertexBuffer(0, vertexBuffer);
pass.Draw(3, 1, 0, 0); pass.Draw(3, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
return commands; return commands;
} }
}; };
@ -87,7 +87,7 @@ class DestroyTest : public DawnTest {
TEST_P(DestroyTest, BufferDestroyBeforeSubmit) { TEST_P(DestroyTest, BufferDestroyBeforeSubmit) {
RGBA8 notFilled(0, 0, 0, 0); RGBA8 notFilled(0, 0, 0, 0);
dawn::CommandBuffer commands = CreateTriangleCommandBuffer(); wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
vertexBuffer.Destroy(); vertexBuffer.Destroy();
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands)); ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
@ -98,7 +98,7 @@ TEST_P(DestroyTest, BufferDestroyBeforeSubmit) {
TEST_P(DestroyTest, BufferDestroyAfterSubmit) { TEST_P(DestroyTest, BufferDestroyAfterSubmit) {
RGBA8 filled(0, 255, 0, 255); RGBA8 filled(0, 255, 0, 255);
dawn::CommandBuffer commands = CreateTriangleCommandBuffer(); wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3);
@ -110,7 +110,7 @@ TEST_P(DestroyTest, BufferDestroyAfterSubmit) {
TEST_P(DestroyTest, BufferSubmitDestroySubmit) { TEST_P(DestroyTest, BufferSubmitDestroySubmit) {
RGBA8 filled(0, 255, 0, 255); RGBA8 filled(0, 255, 0, 255);
dawn::CommandBuffer commands = CreateTriangleCommandBuffer(); wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3);
@ -125,7 +125,7 @@ TEST_P(DestroyTest, BufferSubmitDestroySubmit) {
// Destroy texture before submit should fail submit // Destroy texture before submit should fail submit
TEST_P(DestroyTest, TextureDestroyBeforeSubmit) { TEST_P(DestroyTest, TextureDestroyBeforeSubmit) {
dawn::CommandBuffer commands = CreateTriangleCommandBuffer(); wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
renderPass.color.Destroy(); renderPass.color.Destroy();
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands)); ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
} }
@ -134,7 +134,7 @@ TEST_P(DestroyTest, TextureDestroyBeforeSubmit) {
TEST_P(DestroyTest, TextureDestroyAfterSubmit) { TEST_P(DestroyTest, TextureDestroyAfterSubmit) {
RGBA8 filled(0, 255, 0, 255); RGBA8 filled(0, 255, 0, 255);
dawn::CommandBuffer commands = CreateTriangleCommandBuffer(); wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3);
@ -146,7 +146,7 @@ TEST_P(DestroyTest, TextureDestroyAfterSubmit) {
TEST_P(DestroyTest, TextureSubmitDestroySubmit) { TEST_P(DestroyTest, TextureSubmitDestroySubmit) {
RGBA8 filled(0, 255, 0, 255); RGBA8 filled(0, 255, 0, 255);
dawn::CommandBuffer commands = CreateTriangleCommandBuffer(); wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3);

View File

@ -26,7 +26,7 @@ class DrawIndexedIndirectTest : public DawnTest {
renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
layout(location = 0) in vec4 pos; layout(location = 0) in vec4 pos;
@ -34,7 +34,7 @@ class DrawIndexedIndirectTest : public DawnTest {
gl_Position = pos; gl_Position = pos;
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -45,17 +45,17 @@ class DrawIndexedIndirectTest : public DawnTest {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cVertexInput.bufferCount = 1; descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float); descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
descriptor.cVertexInput.cBuffers[0].attributeCount = 1; descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4; descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat; descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor); pipeline = device.CreateRenderPipeline(&descriptor);
vertexBuffer = utils::CreateBufferFromData<float>( vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex, device, wgpu::BufferUsage::Vertex,
{// First quad: the first 3 vertices represent the bottom left triangle {// First quad: the first 3 vertices represent the bottom left triangle
-1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
@ -64,28 +64,28 @@ class DrawIndexedIndirectTest : public DawnTest {
-1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f,
0.0f, 1.0f}); 0.0f, 1.0f});
indexBuffer = utils::CreateBufferFromData<uint32_t>( indexBuffer = utils::CreateBufferFromData<uint32_t>(
device, dawn::BufferUsage::Index, device, wgpu::BufferUsage::Index,
{0, 1, 2, 0, 3, 1, {0, 1, 2, 0, 3, 1,
// The indices below are added to test negatve baseVertex // The indices below are added to test negatve baseVertex
0 + 4, 1 + 4, 2 + 4, 0 + 4, 3 + 4, 1 + 4}); 0 + 4, 1 + 4, 2 + 4, 0 + 4, 3 + 4, 1 + 4});
} }
utils::BasicRenderPass renderPass; utils::BasicRenderPass renderPass;
dawn::RenderPipeline pipeline; wgpu::RenderPipeline pipeline;
dawn::Buffer vertexBuffer; wgpu::Buffer vertexBuffer;
dawn::Buffer indexBuffer; wgpu::Buffer indexBuffer;
void Test(std::initializer_list<uint32_t> bufferList, void Test(std::initializer_list<uint32_t> bufferList,
uint64_t indexOffset, uint64_t indexOffset,
uint64_t indirectOffset, uint64_t indirectOffset,
RGBA8 bottomLeftExpected, RGBA8 bottomLeftExpected,
RGBA8 topRightExpected) { RGBA8 topRightExpected) {
dawn::Buffer indirectBuffer = wgpu::Buffer indirectBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Indirect, bufferList); utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Indirect, bufferList);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer); pass.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer, indexOffset); pass.SetIndexBuffer(indexBuffer, indexOffset);
@ -93,7 +93,7 @@ class DrawIndexedIndirectTest : public DawnTest {
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3); EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3);

View File

@ -26,7 +26,7 @@ class DrawIndexedTest : public DawnTest {
renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
layout(location = 0) in vec4 pos; layout(location = 0) in vec4 pos;
@ -34,7 +34,7 @@ class DrawIndexedTest : public DawnTest {
gl_Position = pos; gl_Position = pos;
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -45,17 +45,17 @@ class DrawIndexedTest : public DawnTest {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cVertexInput.bufferCount = 1; descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float); descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
descriptor.cVertexInput.cBuffers[0].attributeCount = 1; descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4; descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat; descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor); pipeline = device.CreateRenderPipeline(&descriptor);
vertexBuffer = utils::CreateBufferFromData<float>( vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex, device, wgpu::BufferUsage::Vertex,
{// First quad: the first 3 vertices represent the bottom left triangle {// First quad: the first 3 vertices represent the bottom left triangle
-1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
@ -64,16 +64,16 @@ class DrawIndexedTest : public DawnTest {
-1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f,
-1.0f, 0.0f, 1.0f}); -1.0f, 0.0f, 1.0f});
indexBuffer = utils::CreateBufferFromData<uint32_t>( indexBuffer = utils::CreateBufferFromData<uint32_t>(
device, dawn::BufferUsage::Index, device, wgpu::BufferUsage::Index,
{0, 1, 2, 0, 3, 1, {0, 1, 2, 0, 3, 1,
// The indices below are added to test negatve baseVertex // The indices below are added to test negatve baseVertex
0 + 4, 1 + 4, 2 + 4, 0 + 4, 3 + 4, 1 + 4}); 0 + 4, 1 + 4, 2 + 4, 0 + 4, 3 + 4, 1 + 4});
} }
utils::BasicRenderPass renderPass; utils::BasicRenderPass renderPass;
dawn::RenderPipeline pipeline; wgpu::RenderPipeline pipeline;
dawn::Buffer vertexBuffer; wgpu::Buffer vertexBuffer;
dawn::Buffer indexBuffer; wgpu::Buffer indexBuffer;
void Test(uint32_t indexCount, void Test(uint32_t indexCount,
uint32_t instanceCount, uint32_t instanceCount,
@ -83,10 +83,9 @@ class DrawIndexedTest : public DawnTest {
uint64_t bufferOffset, uint64_t bufferOffset,
RGBA8 bottomLeftExpected, RGBA8 bottomLeftExpected,
RGBA8 topRightExpected) { RGBA8 topRightExpected) {
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass( wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer); pass.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer, bufferOffset); pass.SetIndexBuffer(indexBuffer, bufferOffset);
@ -94,7 +93,7 @@ class DrawIndexedTest : public DawnTest {
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3); EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3);

View File

@ -26,7 +26,7 @@ class DrawIndirectTest : public DawnTest {
renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
layout(location = 0) in vec4 pos; layout(location = 0) in vec4 pos;
@ -34,7 +34,7 @@ class DrawIndirectTest : public DawnTest {
gl_Position = pos; gl_Position = pos;
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -45,17 +45,17 @@ class DrawIndirectTest : public DawnTest {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cVertexInput.bufferCount = 1; descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float); descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
descriptor.cVertexInput.cBuffers[0].attributeCount = 1; descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4; descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat; descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor); pipeline = device.CreateRenderPipeline(&descriptor);
vertexBuffer = utils::CreateBufferFromData<float>( vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex, device, wgpu::BufferUsage::Vertex,
{// The bottom left triangle {// The bottom left triangle
-1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f,
@ -64,26 +64,26 @@ class DrawIndirectTest : public DawnTest {
} }
utils::BasicRenderPass renderPass; utils::BasicRenderPass renderPass;
dawn::RenderPipeline pipeline; wgpu::RenderPipeline pipeline;
dawn::Buffer vertexBuffer; wgpu::Buffer vertexBuffer;
void Test(std::initializer_list<uint32_t> bufferList, void Test(std::initializer_list<uint32_t> bufferList,
uint64_t indirectOffset, uint64_t indirectOffset,
RGBA8 bottomLeftExpected, RGBA8 bottomLeftExpected,
RGBA8 topRightExpected) { RGBA8 topRightExpected) {
dawn::Buffer indirectBuffer = wgpu::Buffer indirectBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Indirect, bufferList); utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Indirect, bufferList);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer); pass.SetVertexBuffer(0, vertexBuffer);
pass.DrawIndirect(indirectBuffer, indirectOffset); pass.DrawIndirect(indirectBuffer, indirectOffset);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3); EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3);

View File

@ -26,7 +26,7 @@ class DrawTest : public DawnTest {
renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
layout(location = 0) in vec4 pos; layout(location = 0) in vec4 pos;
@ -34,7 +34,7 @@ class DrawTest : public DawnTest {
gl_Position = pos; gl_Position = pos;
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -45,17 +45,17 @@ class DrawTest : public DawnTest {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cVertexInput.bufferCount = 1; descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float); descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
descriptor.cVertexInput.cBuffers[0].attributeCount = 1; descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4; descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat; descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor); pipeline = device.CreateRenderPipeline(&descriptor);
vertexBuffer = utils::CreateBufferFromData<float>( vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex, device, wgpu::BufferUsage::Vertex,
{// The bottom left triangle {// The bottom left triangle
-1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f,
@ -64,8 +64,8 @@ class DrawTest : public DawnTest {
} }
utils::BasicRenderPass renderPass; utils::BasicRenderPass renderPass;
dawn::RenderPipeline pipeline; wgpu::RenderPipeline pipeline;
dawn::Buffer vertexBuffer; wgpu::Buffer vertexBuffer;
void Test(uint32_t vertexCount, void Test(uint32_t vertexCount,
uint32_t instanceCount, uint32_t instanceCount,
@ -73,16 +73,16 @@ class DrawTest : public DawnTest {
uint32_t firstInstance, uint32_t firstInstance,
RGBA8 bottomLeftExpected, RGBA8 bottomLeftExpected,
RGBA8 topRightExpected) { RGBA8 topRightExpected) {
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer); pass.SetVertexBuffer(0, vertexBuffer);
pass.Draw(vertexCount, instanceCount, firstIndex, firstInstance); pass.Draw(vertexCount, instanceCount, firstIndex, firstInstance);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3); EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3);

View File

@ -34,19 +34,19 @@ class DynamicBufferOffsetTests : public DawnTest {
uniformData[1] = 2; uniformData[1] = 2;
mUniformBuffers[0] = utils::CreateBufferFromData(device, uniformData.data(), kBufferSize, mUniformBuffers[0] = utils::CreateBufferFromData(device, uniformData.data(), kBufferSize,
dawn::BufferUsage::Uniform); wgpu::BufferUsage::Uniform);
uniformData[uniformData.size() - 2] = 5; uniformData[uniformData.size() - 2] = 5;
uniformData[uniformData.size() - 1] = 6; uniformData[uniformData.size() - 1] = 6;
// Dynamic uniform buffer // Dynamic uniform buffer
mUniformBuffers[1] = utils::CreateBufferFromData(device, uniformData.data(), kBufferSize, mUniformBuffers[1] = utils::CreateBufferFromData(device, uniformData.data(), kBufferSize,
dawn::BufferUsage::Uniform); wgpu::BufferUsage::Uniform);
dawn::BufferDescriptor storageBufferDescriptor; wgpu::BufferDescriptor storageBufferDescriptor;
storageBufferDescriptor.size = kBufferSize; storageBufferDescriptor.size = kBufferSize;
storageBufferDescriptor.usage = storageBufferDescriptor.usage =
dawn::BufferUsage::Storage | dawn::BufferUsage::CopyDst | dawn::BufferUsage::CopySrc; wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::CopySrc;
mStorageBuffers[0] = device.CreateBuffer(&storageBufferDescriptor); mStorageBuffers[0] = device.CreateBuffer(&storageBufferDescriptor);
@ -55,14 +55,14 @@ class DynamicBufferOffsetTests : public DawnTest {
// Default bind group layout // Default bind group layout
mBindGroupLayouts[0] = utils::MakeBindGroupLayout( mBindGroupLayouts[0] = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Compute | dawn::ShaderStage::Fragment, device, {{0, wgpu::ShaderStage::Compute | wgpu::ShaderStage::Fragment,
dawn::BindingType::UniformBuffer}, wgpu::BindingType::UniformBuffer},
{1, dawn::ShaderStage::Compute | dawn::ShaderStage::Fragment, {1, wgpu::ShaderStage::Compute | wgpu::ShaderStage::Fragment,
dawn::BindingType::StorageBuffer}, wgpu::BindingType::StorageBuffer},
{3, dawn::ShaderStage::Compute | dawn::ShaderStage::Fragment, {3, wgpu::ShaderStage::Compute | wgpu::ShaderStage::Fragment,
dawn::BindingType::UniformBuffer, true}, wgpu::BindingType::UniformBuffer, true},
{4, dawn::ShaderStage::Compute | dawn::ShaderStage::Fragment, {4, wgpu::ShaderStage::Compute | wgpu::ShaderStage::Fragment,
dawn::BindingType::StorageBuffer, true}}); wgpu::BindingType::StorageBuffer, true}});
// Default bind group // Default bind group
mBindGroups[0] = utils::MakeBindGroup(device, mBindGroupLayouts[0], mBindGroups[0] = utils::MakeBindGroup(device, mBindGroupLayouts[0],
@ -73,12 +73,12 @@ class DynamicBufferOffsetTests : public DawnTest {
// Extra uniform buffer for inheriting test // Extra uniform buffer for inheriting test
mUniformBuffers[2] = utils::CreateBufferFromData(device, uniformData.data(), kBufferSize, mUniformBuffers[2] = utils::CreateBufferFromData(device, uniformData.data(), kBufferSize,
dawn::BufferUsage::Uniform); wgpu::BufferUsage::Uniform);
// Bind group layout for inheriting test // Bind group layout for inheriting test
mBindGroupLayouts[1] = utils::MakeBindGroupLayout( mBindGroupLayouts[1] = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Compute | dawn::ShaderStage::Fragment, device, {{0, wgpu::ShaderStage::Compute | wgpu::ShaderStage::Fragment,
dawn::BindingType::UniformBuffer}}); wgpu::BindingType::UniformBuffer}});
// Bind group for inheriting test // Bind group for inheriting test
mBindGroups[1] = utils::MakeBindGroup(device, mBindGroupLayouts[1], mBindGroups[1] = utils::MakeBindGroup(device, mBindGroupLayouts[1],
@ -86,14 +86,14 @@ class DynamicBufferOffsetTests : public DawnTest {
} }
// Create objects to use as resources inside test bind groups. // Create objects to use as resources inside test bind groups.
dawn::BindGroup mBindGroups[2]; wgpu::BindGroup mBindGroups[2];
dawn::BindGroupLayout mBindGroupLayouts[2]; wgpu::BindGroupLayout mBindGroupLayouts[2];
dawn::Buffer mUniformBuffers[3]; wgpu::Buffer mUniformBuffers[3];
dawn::Buffer mStorageBuffers[2]; wgpu::Buffer mStorageBuffers[2];
dawn::Texture mColorAttachment; wgpu::Texture mColorAttachment;
dawn::RenderPipeline CreateRenderPipeline(bool isInheritedPipeline = false) { wgpu::RenderPipeline CreateRenderPipeline(bool isInheritedPipeline = false) {
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
void main() { void main() {
@ -136,15 +136,15 @@ class DynamicBufferOffsetTests : public DawnTest {
fs << " fragColor = vec4(value.x / 255.0f, value.y / 255.0f, 1.0f, 1.0f);\n"; fs << " fragColor = vec4(value.x / 255.0f, value.y / 255.0f, 1.0f, 1.0f);\n";
fs << " }\n"; fs << " }\n";
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs.str().c_str()); utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs.str().c_str());
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device); utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
pipelineDescriptor.vertexStage.module = vsModule; pipelineDescriptor.vertexStage.module = vsModule;
pipelineDescriptor.cFragmentStage.module = fsModule; pipelineDescriptor.cFragmentStage.module = fsModule;
pipelineDescriptor.cColorStates[0].format = dawn::TextureFormat::RGBA8Unorm; pipelineDescriptor.cColorStates[0].format = wgpu::TextureFormat::RGBA8Unorm;
dawn::PipelineLayoutDescriptor pipelineLayoutDescriptor; wgpu::PipelineLayoutDescriptor pipelineLayoutDescriptor;
if (isInheritedPipeline) { if (isInheritedPipeline) {
pipelineLayoutDescriptor.bindGroupLayoutCount = 2; pipelineLayoutDescriptor.bindGroupLayoutCount = 2;
} else { } else {
@ -156,7 +156,7 @@ class DynamicBufferOffsetTests : public DawnTest {
return device.CreateRenderPipeline(&pipelineDescriptor); return device.CreateRenderPipeline(&pipelineDescriptor);
} }
dawn::ComputePipeline CreateComputePipeline(bool isInheritedPipeline = false) { wgpu::ComputePipeline CreateComputePipeline(bool isInheritedPipeline = false) {
// Construct compute shader source // Construct compute shader source
std::ostringstream cs; std::ostringstream cs;
std::string multipleNumber = isInheritedPipeline ? "2" : "1"; std::string multipleNumber = isInheritedPipeline ? "2" : "1";
@ -190,14 +190,14 @@ class DynamicBufferOffsetTests : public DawnTest {
<< " * (value.xy + mid.notDynamicResult.xy);\n"; << " * (value.xy + mid.notDynamicResult.xy);\n";
cs << " }\n"; cs << " }\n";
dawn::ShaderModule csModule = wgpu::ShaderModule csModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, cs.str().c_str()); utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, cs.str().c_str());
dawn::ComputePipelineDescriptor csDesc; wgpu::ComputePipelineDescriptor csDesc;
csDesc.computeStage.module = csModule; csDesc.computeStage.module = csModule;
csDesc.computeStage.entryPoint = "main"; csDesc.computeStage.entryPoint = "main";
dawn::PipelineLayoutDescriptor pipelineLayoutDescriptor; wgpu::PipelineLayoutDescriptor pipelineLayoutDescriptor;
if (isInheritedPipeline) { if (isInheritedPipeline) {
pipelineLayoutDescriptor.bindGroupLayoutCount = 2; pipelineLayoutDescriptor.bindGroupLayoutCount = 2;
} else { } else {
@ -212,18 +212,18 @@ class DynamicBufferOffsetTests : public DawnTest {
// Dynamic offsets are all zero and no effect to result. // Dynamic offsets are all zero and no effect to result.
TEST_P(DynamicBufferOffsetTests, BasicRenderPipeline) { TEST_P(DynamicBufferOffsetTests, BasicRenderPipeline) {
dawn::RenderPipeline pipeline = CreateRenderPipeline(); wgpu::RenderPipeline pipeline = CreateRenderPipeline();
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
std::array<uint64_t, 2> offsets = {0, 0}; std::array<uint64_t, 2> offsets = {0, 0};
dawn::RenderPassEncoder renderPassEncoder = wgpu::RenderPassEncoder renderPassEncoder =
commandEncoder.BeginRenderPass(&renderPass.renderPassInfo); commandEncoder.BeginRenderPass(&renderPass.renderPassInfo);
renderPassEncoder.SetPipeline(pipeline); renderPassEncoder.SetPipeline(pipeline);
renderPassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data()); renderPassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
renderPassEncoder.Draw(3, 1, 0, 0); renderPassEncoder.Draw(3, 1, 0, 0);
renderPassEncoder.EndPass(); renderPassEncoder.EndPass();
dawn::CommandBuffer commands = commandEncoder.Finish(); wgpu::CommandBuffer commands = commandEncoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
std::vector<uint32_t> expectedData = {2, 4}; std::vector<uint32_t> expectedData = {2, 4};
@ -233,19 +233,19 @@ TEST_P(DynamicBufferOffsetTests, BasicRenderPipeline) {
// Have non-zero dynamic offsets. // Have non-zero dynamic offsets.
TEST_P(DynamicBufferOffsetTests, SetDynamicOffestsRenderPipeline) { TEST_P(DynamicBufferOffsetTests, SetDynamicOffestsRenderPipeline) {
dawn::RenderPipeline pipeline = CreateRenderPipeline(); wgpu::RenderPipeline pipeline = CreateRenderPipeline();
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment, std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment,
kMinDynamicBufferOffsetAlignment}; kMinDynamicBufferOffsetAlignment};
dawn::RenderPassEncoder renderPassEncoder = wgpu::RenderPassEncoder renderPassEncoder =
commandEncoder.BeginRenderPass(&renderPass.renderPassInfo); commandEncoder.BeginRenderPass(&renderPass.renderPassInfo);
renderPassEncoder.SetPipeline(pipeline); renderPassEncoder.SetPipeline(pipeline);
renderPassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data()); renderPassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
renderPassEncoder.Draw(3, 1, 0, 0); renderPassEncoder.Draw(3, 1, 0, 0);
renderPassEncoder.EndPass(); renderPassEncoder.EndPass();
dawn::CommandBuffer commands = commandEncoder.Finish(); wgpu::CommandBuffer commands = commandEncoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
std::vector<uint32_t> expectedData = {6, 8}; std::vector<uint32_t> expectedData = {6, 8};
@ -256,17 +256,17 @@ TEST_P(DynamicBufferOffsetTests, SetDynamicOffestsRenderPipeline) {
// Dynamic offsets are all zero and no effect to result. // Dynamic offsets are all zero and no effect to result.
TEST_P(DynamicBufferOffsetTests, BasicComputePipeline) { TEST_P(DynamicBufferOffsetTests, BasicComputePipeline) {
dawn::ComputePipeline pipeline = CreateComputePipeline(); wgpu::ComputePipeline pipeline = CreateComputePipeline();
std::array<uint64_t, 2> offsets = {0, 0}; std::array<uint64_t, 2> offsets = {0, 0};
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass(); wgpu::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass();
computePassEncoder.SetPipeline(pipeline); computePassEncoder.SetPipeline(pipeline);
computePassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data()); computePassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
computePassEncoder.Dispatch(1, 1, 1); computePassEncoder.Dispatch(1, 1, 1);
computePassEncoder.EndPass(); computePassEncoder.EndPass();
dawn::CommandBuffer commands = commandEncoder.Finish(); wgpu::CommandBuffer commands = commandEncoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
std::vector<uint32_t> expectedData = {2, 4}; std::vector<uint32_t> expectedData = {2, 4};
@ -275,18 +275,18 @@ TEST_P(DynamicBufferOffsetTests, BasicComputePipeline) {
// Have non-zero dynamic offsets. // Have non-zero dynamic offsets.
TEST_P(DynamicBufferOffsetTests, SetDynamicOffestsComputePipeline) { TEST_P(DynamicBufferOffsetTests, SetDynamicOffestsComputePipeline) {
dawn::ComputePipeline pipeline = CreateComputePipeline(); wgpu::ComputePipeline pipeline = CreateComputePipeline();
std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment, std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment,
kMinDynamicBufferOffsetAlignment}; kMinDynamicBufferOffsetAlignment};
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass(); wgpu::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass();
computePassEncoder.SetPipeline(pipeline); computePassEncoder.SetPipeline(pipeline);
computePassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data()); computePassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
computePassEncoder.Dispatch(1, 1, 1); computePassEncoder.Dispatch(1, 1, 1);
computePassEncoder.EndPass(); computePassEncoder.EndPass();
dawn::CommandBuffer commands = commandEncoder.Finish(); wgpu::CommandBuffer commands = commandEncoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
std::vector<uint32_t> expectedData = {6, 8}; std::vector<uint32_t> expectedData = {6, 8};
@ -297,15 +297,15 @@ TEST_P(DynamicBufferOffsetTests, SetDynamicOffestsComputePipeline) {
// Test inherit dynamic offsets on render pipeline // Test inherit dynamic offsets on render pipeline
TEST_P(DynamicBufferOffsetTests, InheritDynamicOffestsRenderPipeline) { TEST_P(DynamicBufferOffsetTests, InheritDynamicOffestsRenderPipeline) {
// Using default pipeline and setting dynamic offsets // Using default pipeline and setting dynamic offsets
dawn::RenderPipeline pipeline = CreateRenderPipeline(); wgpu::RenderPipeline pipeline = CreateRenderPipeline();
dawn::RenderPipeline testPipeline = CreateRenderPipeline(true); wgpu::RenderPipeline testPipeline = CreateRenderPipeline(true);
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment, std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment,
kMinDynamicBufferOffsetAlignment}; kMinDynamicBufferOffsetAlignment};
dawn::RenderPassEncoder renderPassEncoder = wgpu::RenderPassEncoder renderPassEncoder =
commandEncoder.BeginRenderPass(&renderPass.renderPassInfo); commandEncoder.BeginRenderPass(&renderPass.renderPassInfo);
renderPassEncoder.SetPipeline(pipeline); renderPassEncoder.SetPipeline(pipeline);
renderPassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data()); renderPassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
@ -314,7 +314,7 @@ TEST_P(DynamicBufferOffsetTests, InheritDynamicOffestsRenderPipeline) {
renderPassEncoder.SetBindGroup(1, mBindGroups[1]); renderPassEncoder.SetBindGroup(1, mBindGroups[1]);
renderPassEncoder.Draw(3, 1, 0, 0); renderPassEncoder.Draw(3, 1, 0, 0);
renderPassEncoder.EndPass(); renderPassEncoder.EndPass();
dawn::CommandBuffer commands = commandEncoder.Finish(); wgpu::CommandBuffer commands = commandEncoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
std::vector<uint32_t> expectedData = {12, 16}; std::vector<uint32_t> expectedData = {12, 16};
@ -329,14 +329,14 @@ TEST_P(DynamicBufferOffsetTests, InheritDynamicOffestsRenderPipeline) {
// Will double check root cause after got GTX1660. // Will double check root cause after got GTX1660.
TEST_P(DynamicBufferOffsetTests, InheritDynamicOffestsComputePipeline) { TEST_P(DynamicBufferOffsetTests, InheritDynamicOffestsComputePipeline) {
DAWN_SKIP_TEST_IF(IsWindows()); DAWN_SKIP_TEST_IF(IsWindows());
dawn::ComputePipeline pipeline = CreateComputePipeline(); wgpu::ComputePipeline pipeline = CreateComputePipeline();
dawn::ComputePipeline testPipeline = CreateComputePipeline(true); wgpu::ComputePipeline testPipeline = CreateComputePipeline(true);
std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment, std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment,
kMinDynamicBufferOffsetAlignment}; kMinDynamicBufferOffsetAlignment};
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass(); wgpu::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass();
computePassEncoder.SetPipeline(pipeline); computePassEncoder.SetPipeline(pipeline);
computePassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data()); computePassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
computePassEncoder.Dispatch(1, 1, 1); computePassEncoder.Dispatch(1, 1, 1);
@ -344,7 +344,7 @@ TEST_P(DynamicBufferOffsetTests, InheritDynamicOffestsComputePipeline) {
computePassEncoder.SetBindGroup(1, mBindGroups[1]); computePassEncoder.SetBindGroup(1, mBindGroups[1]);
computePassEncoder.Dispatch(1, 1, 1); computePassEncoder.Dispatch(1, 1, 1);
computePassEncoder.EndPass(); computePassEncoder.EndPass();
dawn::CommandBuffer commands = commandEncoder.Finish(); wgpu::CommandBuffer commands = commandEncoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
std::vector<uint32_t> expectedData = {12, 16}; std::vector<uint32_t> expectedData = {12, 16};
@ -355,16 +355,16 @@ TEST_P(DynamicBufferOffsetTests, InheritDynamicOffestsComputePipeline) {
// Setting multiple dynamic offsets for the same bindgroup in one render pass. // Setting multiple dynamic offsets for the same bindgroup in one render pass.
TEST_P(DynamicBufferOffsetTests, UpdateDynamicOffestsMultipleTimesRenderPipeline) { TEST_P(DynamicBufferOffsetTests, UpdateDynamicOffestsMultipleTimesRenderPipeline) {
// Using default pipeline and setting dynamic offsets // Using default pipeline and setting dynamic offsets
dawn::RenderPipeline pipeline = CreateRenderPipeline(); wgpu::RenderPipeline pipeline = CreateRenderPipeline();
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment, std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment,
kMinDynamicBufferOffsetAlignment}; kMinDynamicBufferOffsetAlignment};
std::array<uint64_t, 2> testOffsets = {0, 0}; std::array<uint64_t, 2> testOffsets = {0, 0};
dawn::RenderPassEncoder renderPassEncoder = wgpu::RenderPassEncoder renderPassEncoder =
commandEncoder.BeginRenderPass(&renderPass.renderPassInfo); commandEncoder.BeginRenderPass(&renderPass.renderPassInfo);
renderPassEncoder.SetPipeline(pipeline); renderPassEncoder.SetPipeline(pipeline);
renderPassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data()); renderPassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
@ -372,7 +372,7 @@ TEST_P(DynamicBufferOffsetTests, UpdateDynamicOffestsMultipleTimesRenderPipeline
renderPassEncoder.SetBindGroup(0, mBindGroups[0], testOffsets.size(), testOffsets.data()); renderPassEncoder.SetBindGroup(0, mBindGroups[0], testOffsets.size(), testOffsets.data());
renderPassEncoder.Draw(3, 1, 0, 0); renderPassEncoder.Draw(3, 1, 0, 0);
renderPassEncoder.EndPass(); renderPassEncoder.EndPass();
dawn::CommandBuffer commands = commandEncoder.Finish(); wgpu::CommandBuffer commands = commandEncoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
std::vector<uint32_t> expectedData = {2, 4}; std::vector<uint32_t> expectedData = {2, 4};
@ -382,21 +382,21 @@ TEST_P(DynamicBufferOffsetTests, UpdateDynamicOffestsMultipleTimesRenderPipeline
// Setting multiple dynamic offsets for the same bindgroup in one compute pass. // Setting multiple dynamic offsets for the same bindgroup in one compute pass.
TEST_P(DynamicBufferOffsetTests, UpdateDynamicOffsetsMultipleTimesComputePipeline) { TEST_P(DynamicBufferOffsetTests, UpdateDynamicOffsetsMultipleTimesComputePipeline) {
dawn::ComputePipeline pipeline = CreateComputePipeline(); wgpu::ComputePipeline pipeline = CreateComputePipeline();
std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment, std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment,
kMinDynamicBufferOffsetAlignment}; kMinDynamicBufferOffsetAlignment};
std::array<uint64_t, 2> testOffsets = {0, 0}; std::array<uint64_t, 2> testOffsets = {0, 0};
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass(); wgpu::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass();
computePassEncoder.SetPipeline(pipeline); computePassEncoder.SetPipeline(pipeline);
computePassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data()); computePassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
computePassEncoder.Dispatch(1, 1, 1); computePassEncoder.Dispatch(1, 1, 1);
computePassEncoder.SetBindGroup(0, mBindGroups[0], testOffsets.size(), testOffsets.data()); computePassEncoder.SetBindGroup(0, mBindGroups[0], testOffsets.size(), testOffsets.data());
computePassEncoder.Dispatch(1, 1, 1); computePassEncoder.Dispatch(1, 1, 1);
computePassEncoder.EndPass(); computePassEncoder.EndPass();
dawn::CommandBuffer commands = commandEncoder.Finish(); wgpu::CommandBuffer commands = commandEncoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
std::vector<uint32_t> expectedData = {2, 4}; std::vector<uint32_t> expectedData = {2, 4};

View File

@ -22,21 +22,21 @@ using namespace testing;
class MockFenceOnCompletionCallback { class MockFenceOnCompletionCallback {
public: public:
MOCK_METHOD2(Call, void(DawnFenceCompletionStatus status, void* userdata)); MOCK_METHOD2(Call, void(WGPUFenceCompletionStatus status, void* userdata));
}; };
static std::unique_ptr<MockFenceOnCompletionCallback> mockFenceOnCompletionCallback; static std::unique_ptr<MockFenceOnCompletionCallback> mockFenceOnCompletionCallback;
static void ToMockFenceOnCompletionCallback(DawnFenceCompletionStatus status, void* userdata) { static void ToMockFenceOnCompletionCallback(WGPUFenceCompletionStatus status, void* userdata) {
mockFenceOnCompletionCallback->Call(status, userdata); mockFenceOnCompletionCallback->Call(status, userdata);
} }
class MockPopErrorScopeCallback { class MockPopErrorScopeCallback {
public: public:
MOCK_METHOD3(Call, void(DawnErrorType type, const char* message, void* userdata)); MOCK_METHOD3(Call, void(WGPUErrorType type, const char* message, void* userdata));
}; };
static std::unique_ptr<MockPopErrorScopeCallback> mockPopErrorScopeCallback; static std::unique_ptr<MockPopErrorScopeCallback> mockPopErrorScopeCallback;
static void ToMockPopErrorScopeCallback(DawnErrorType type, const char* message, void* userdata) { static void ToMockPopErrorScopeCallback(WGPUErrorType type, const char* message, void* userdata) {
mockPopErrorScopeCallback->Call(type, message, userdata); mockPopErrorScopeCallback->Call(type, message, userdata);
} }
@ -45,10 +45,10 @@ class FenceTests : public DawnTest {
struct CallbackInfo { struct CallbackInfo {
FenceTests* test; FenceTests* test;
uint64_t value; uint64_t value;
DawnFenceCompletionStatus status; WGPUFenceCompletionStatus status;
int32_t callIndex = -1; // If this is -1, the callback was not called int32_t callIndex = -1; // If this is -1, the callback was not called
void Update(DawnFenceCompletionStatus status) { void Update(WGPUFenceCompletionStatus status) {
this->callIndex = test->mCallIndex++; this->callIndex = test->mCallIndex++;
this->status = status; this->status = status;
} }
@ -72,7 +72,7 @@ class FenceTests : public DawnTest {
DawnTest::TearDown(); DawnTest::TearDown();
} }
void WaitForCompletedValue(dawn::Fence fence, uint64_t completedValue) { void WaitForCompletedValue(wgpu::Fence fence, uint64_t completedValue) {
while (fence.GetCompletedValue() < completedValue) { while (fence.GetCompletedValue() < completedValue) {
WaitABit(); WaitABit();
} }
@ -81,9 +81,9 @@ class FenceTests : public DawnTest {
// Test that signaling a fence updates the completed value // Test that signaling a fence updates the completed value
TEST_P(FenceTests, SimpleSignal) { TEST_P(FenceTests, SimpleSignal) {
dawn::FenceDescriptor descriptor; wgpu::FenceDescriptor descriptor;
descriptor.initialValue = 1u; descriptor.initialValue = 1u;
dawn::Fence fence = queue.CreateFence(&descriptor); wgpu::Fence fence = queue.CreateFence(&descriptor);
// Completed value starts at initial value // Completed value starts at initial value
EXPECT_EQ(fence.GetCompletedValue(), 1u); EXPECT_EQ(fence.GetCompletedValue(), 1u);
@ -97,9 +97,9 @@ TEST_P(FenceTests, SimpleSignal) {
// Test callbacks are called in increasing order of fence completion value // Test callbacks are called in increasing order of fence completion value
TEST_P(FenceTests, OnCompletionOrdering) { TEST_P(FenceTests, OnCompletionOrdering) {
dawn::FenceDescriptor descriptor; wgpu::FenceDescriptor descriptor;
descriptor.initialValue = 0u; descriptor.initialValue = 0u;
dawn::Fence fence = queue.CreateFence(&descriptor); wgpu::Fence fence = queue.CreateFence(&descriptor);
queue.Signal(fence, 4); queue.Signal(fence, 4);
@ -107,19 +107,19 @@ TEST_P(FenceTests, OnCompletionOrdering) {
testing::InSequence s; testing::InSequence s;
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 0)) Call(WGPUFenceCompletionStatus_Success, this + 0))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 1)) Call(WGPUFenceCompletionStatus_Success, this + 1))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 2)) Call(WGPUFenceCompletionStatus_Success, this + 2))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 3)) Call(WGPUFenceCompletionStatus_Success, this + 3))
.Times(1); .Times(1);
} }
@ -133,14 +133,14 @@ TEST_P(FenceTests, OnCompletionOrdering) {
// Test callbacks still occur if Queue::Signal happens multiple times // Test callbacks still occur if Queue::Signal happens multiple times
TEST_P(FenceTests, MultipleSignalOnCompletion) { TEST_P(FenceTests, MultipleSignalOnCompletion) {
dawn::FenceDescriptor descriptor; wgpu::FenceDescriptor descriptor;
descriptor.initialValue = 0u; descriptor.initialValue = 0u;
dawn::Fence fence = queue.CreateFence(&descriptor); wgpu::Fence fence = queue.CreateFence(&descriptor);
queue.Signal(fence, 2); queue.Signal(fence, 2);
queue.Signal(fence, 4); queue.Signal(fence, 4);
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, nullptr)) EXPECT_CALL(*mockFenceOnCompletionCallback, Call(WGPUFenceCompletionStatus_Success, nullptr))
.Times(1); .Times(1);
fence.OnCompletion(3u, ToMockFenceOnCompletionCallback, nullptr); fence.OnCompletion(3u, ToMockFenceOnCompletionCallback, nullptr);
@ -149,26 +149,22 @@ TEST_P(FenceTests, MultipleSignalOnCompletion) {
// Test all callbacks are called if they are added for the same fence value // Test all callbacks are called if they are added for the same fence value
TEST_P(FenceTests, OnCompletionMultipleCallbacks) { TEST_P(FenceTests, OnCompletionMultipleCallbacks) {
dawn::FenceDescriptor descriptor; wgpu::FenceDescriptor descriptor;
descriptor.initialValue = 0u; descriptor.initialValue = 0u;
dawn::Fence fence = queue.CreateFence(&descriptor); wgpu::Fence fence = queue.CreateFence(&descriptor);
queue.Signal(fence, 4); queue.Signal(fence, 4);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback, Call(WGPUFenceCompletionStatus_Success, this + 0))
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 0))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback, Call(WGPUFenceCompletionStatus_Success, this + 1))
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 1))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback, Call(WGPUFenceCompletionStatus_Success, this + 2))
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 2))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback, Call(WGPUFenceCompletionStatus_Success, this + 3))
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 3))
.Times(1); .Times(1);
fence.OnCompletion(4u, ToMockFenceOnCompletionCallback, this + 0); fence.OnCompletion(4u, ToMockFenceOnCompletionCallback, this + 0);
@ -182,32 +178,32 @@ TEST_P(FenceTests, OnCompletionMultipleCallbacks) {
// TODO(enga): Enable when fence is removed from fence signal tracker // TODO(enga): Enable when fence is removed from fence signal tracker
// Currently it holds a reference and is not destructed // Currently it holds a reference and is not destructed
TEST_P(FenceTests, DISABLED_DestroyBeforeOnCompletionEnd) { TEST_P(FenceTests, DISABLED_DestroyBeforeOnCompletionEnd) {
dawn::FenceDescriptor descriptor; wgpu::FenceDescriptor descriptor;
descriptor.initialValue = 0u; descriptor.initialValue = 0u;
dawn::Fence fence = queue.CreateFence(&descriptor); wgpu::Fence fence = queue.CreateFence(&descriptor);
// The fence in this block will be deleted when it goes out of scope // The fence in this block will be deleted when it goes out of scope
{ {
dawn::FenceDescriptor descriptor; wgpu::FenceDescriptor descriptor;
descriptor.initialValue = 0u; descriptor.initialValue = 0u;
dawn::Fence testFence = queue.CreateFence(&descriptor); wgpu::Fence testFence = queue.CreateFence(&descriptor);
queue.Signal(testFence, 4); queue.Signal(testFence, 4);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, this + 0)) Call(WGPUFenceCompletionStatus_Unknown, this + 0))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, this + 1)) Call(WGPUFenceCompletionStatus_Unknown, this + 1))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, this + 2)) Call(WGPUFenceCompletionStatus_Unknown, this + 2))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, this + 3)) Call(WGPUFenceCompletionStatus_Unknown, this + 3))
.Times(1); .Times(1);
testFence.OnCompletion(1u, ToMockFenceOnCompletionCallback, this + 0); testFence.OnCompletion(1u, ToMockFenceOnCompletionCallback, this + 0);
@ -224,16 +220,16 @@ TEST_P(FenceTests, DISABLED_DestroyBeforeOnCompletionEnd) {
// Regression test that validation errors that are tracked client-side are captured // Regression test that validation errors that are tracked client-side are captured
// in error scopes. // in error scopes.
TEST_P(FenceTests, ClientValidationErrorInErrorScope) { TEST_P(FenceTests, ClientValidationErrorInErrorScope) {
dawn::FenceDescriptor descriptor; wgpu::FenceDescriptor descriptor;
descriptor.initialValue = 0u; descriptor.initialValue = 0u;
dawn::Fence fence = queue.CreateFence(&descriptor); wgpu::Fence fence = queue.CreateFence(&descriptor);
queue.Signal(fence, 4); queue.Signal(fence, 4);
device.PushErrorScope(dawn::ErrorFilter::Validation); device.PushErrorScope(wgpu::ErrorFilter::Validation);
queue.Signal(fence, 2); queue.Signal(fence, 2);
EXPECT_CALL(*mockPopErrorScopeCallback, Call(DAWN_ERROR_TYPE_VALIDATION, _, this)).Times(1); EXPECT_CALL(*mockPopErrorScopeCallback, Call(WGPUErrorType_Validation, _, this)).Times(1);
device.PopErrorScope(ToMockPopErrorScopeCallback, this); device.PopErrorScope(ToMockPopErrorScopeCallback, this);
WaitForCompletedValue(fence, 4); WaitForCompletedValue(fence, 4);

View File

@ -93,13 +93,13 @@ namespace {
class IOSurfaceTestBase : public DawnTest { class IOSurfaceTestBase : public DawnTest {
public: public:
dawn::Texture WrapIOSurface(const dawn::TextureDescriptor* descriptor, wgpu::Texture WrapIOSurface(const wgpu::TextureDescriptor* descriptor,
IOSurfaceRef ioSurface, IOSurfaceRef ioSurface,
uint32_t plane) { uint32_t plane) {
DawnTexture texture = dawn_native::metal::WrapIOSurface( WGPUTexture texture = dawn_native::metal::WrapIOSurface(
device.Get(), reinterpret_cast<const DawnTextureDescriptor*>(descriptor), ioSurface, device.Get(), reinterpret_cast<const WGPUTextureDescriptor*>(descriptor), ioSurface,
plane); plane);
return dawn::Texture::Acquire(texture); return wgpu::Texture::Acquire(texture);
} }
}; };
@ -112,24 +112,24 @@ class IOSurfaceValidationTests : public IOSurfaceTestBase {
IOSurfaceValidationTests() { IOSurfaceValidationTests() {
defaultIOSurface = CreateSinglePlaneIOSurface(10, 10, 'BGRA', 4); defaultIOSurface = CreateSinglePlaneIOSurface(10, 10, 'BGRA', 4);
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.format = dawn::TextureFormat::BGRA8Unorm; descriptor.format = wgpu::TextureFormat::BGRA8Unorm;
descriptor.size = {10, 10, 1}; descriptor.size = {10, 10, 1};
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.arrayLayerCount = 1; descriptor.arrayLayerCount = 1;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::OutputAttachment; descriptor.usage = wgpu::TextureUsage::OutputAttachment;
} }
protected: protected:
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
ScopedIOSurfaceRef defaultIOSurface; ScopedIOSurfaceRef defaultIOSurface;
}; };
// Test a successful wrapping of an IOSurface in a texture // Test a successful wrapping of an IOSurface in a texture
TEST_P(IOSurfaceValidationTests, Success) { TEST_P(IOSurfaceValidationTests, Success) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
dawn::Texture texture = WrapIOSurface(&descriptor, defaultIOSurface.get(), 0); wgpu::Texture texture = WrapIOSurface(&descriptor, defaultIOSurface.get(), 0);
ASSERT_NE(texture.Get(), nullptr); ASSERT_NE(texture.Get(), nullptr);
} }
@ -138,7 +138,7 @@ TEST_P(IOSurfaceValidationTests, InvalidTextureDescriptor) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
descriptor.nextInChain = this; descriptor.nextInChain = this;
ASSERT_DEVICE_ERROR(dawn::Texture texture = ASSERT_DEVICE_ERROR(wgpu::Texture texture =
WrapIOSurface(&descriptor, defaultIOSurface.get(), 0)); WrapIOSurface(&descriptor, defaultIOSurface.get(), 0));
ASSERT_EQ(texture.Get(), nullptr); ASSERT_EQ(texture.Get(), nullptr);
} }
@ -146,7 +146,7 @@ TEST_P(IOSurfaceValidationTests, InvalidTextureDescriptor) {
// Test an error occurs if the plane is too large // Test an error occurs if the plane is too large
TEST_P(IOSurfaceValidationTests, PlaneTooLarge) { TEST_P(IOSurfaceValidationTests, PlaneTooLarge) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
ASSERT_DEVICE_ERROR(dawn::Texture texture = ASSERT_DEVICE_ERROR(wgpu::Texture texture =
WrapIOSurface(&descriptor, defaultIOSurface.get(), 1)); WrapIOSurface(&descriptor, defaultIOSurface.get(), 1));
ASSERT_EQ(texture.Get(), nullptr); ASSERT_EQ(texture.Get(), nullptr);
} }
@ -155,9 +155,9 @@ TEST_P(IOSurfaceValidationTests, PlaneTooLarge) {
// TODO(cwallez@chromium.org): Reenable when 1D or 3D textures are implemented // TODO(cwallez@chromium.org): Reenable when 1D or 3D textures are implemented
TEST_P(IOSurfaceValidationTests, DISABLED_InvalidTextureDimension) { TEST_P(IOSurfaceValidationTests, DISABLED_InvalidTextureDimension) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
ASSERT_DEVICE_ERROR(dawn::Texture texture = ASSERT_DEVICE_ERROR(wgpu::Texture texture =
WrapIOSurface(&descriptor, defaultIOSurface.get(), 0)); WrapIOSurface(&descriptor, defaultIOSurface.get(), 0));
ASSERT_EQ(texture.Get(), nullptr); ASSERT_EQ(texture.Get(), nullptr);
} }
@ -167,7 +167,7 @@ TEST_P(IOSurfaceValidationTests, InvalidMipLevelCount) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
descriptor.mipLevelCount = 2; descriptor.mipLevelCount = 2;
ASSERT_DEVICE_ERROR(dawn::Texture texture = ASSERT_DEVICE_ERROR(wgpu::Texture texture =
WrapIOSurface(&descriptor, defaultIOSurface.get(), 0)); WrapIOSurface(&descriptor, defaultIOSurface.get(), 0));
ASSERT_EQ(texture.Get(), nullptr); ASSERT_EQ(texture.Get(), nullptr);
} }
@ -177,7 +177,7 @@ TEST_P(IOSurfaceValidationTests, InvalidArrayLayerCount) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
descriptor.arrayLayerCount = 2; descriptor.arrayLayerCount = 2;
ASSERT_DEVICE_ERROR(dawn::Texture texture = ASSERT_DEVICE_ERROR(wgpu::Texture texture =
WrapIOSurface(&descriptor, defaultIOSurface.get(), 0)); WrapIOSurface(&descriptor, defaultIOSurface.get(), 0));
ASSERT_EQ(texture.Get(), nullptr); ASSERT_EQ(texture.Get(), nullptr);
} }
@ -187,7 +187,7 @@ TEST_P(IOSurfaceValidationTests, InvalidSampleCount) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
descriptor.sampleCount = 4; descriptor.sampleCount = 4;
ASSERT_DEVICE_ERROR(dawn::Texture texture = ASSERT_DEVICE_ERROR(wgpu::Texture texture =
WrapIOSurface(&descriptor, defaultIOSurface.get(), 0)); WrapIOSurface(&descriptor, defaultIOSurface.get(), 0));
ASSERT_EQ(texture.Get(), nullptr); ASSERT_EQ(texture.Get(), nullptr);
} }
@ -197,7 +197,7 @@ TEST_P(IOSurfaceValidationTests, InvalidWidth) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
descriptor.size.width = 11; descriptor.size.width = 11;
ASSERT_DEVICE_ERROR(dawn::Texture texture = ASSERT_DEVICE_ERROR(wgpu::Texture texture =
WrapIOSurface(&descriptor, defaultIOSurface.get(), 0)); WrapIOSurface(&descriptor, defaultIOSurface.get(), 0));
ASSERT_EQ(texture.Get(), nullptr); ASSERT_EQ(texture.Get(), nullptr);
} }
@ -207,7 +207,7 @@ TEST_P(IOSurfaceValidationTests, InvalidHeight) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
descriptor.size.height = 11; descriptor.size.height = 11;
ASSERT_DEVICE_ERROR(dawn::Texture texture = ASSERT_DEVICE_ERROR(wgpu::Texture texture =
WrapIOSurface(&descriptor, defaultIOSurface.get(), 0)); WrapIOSurface(&descriptor, defaultIOSurface.get(), 0));
ASSERT_EQ(texture.Get(), nullptr); ASSERT_EQ(texture.Get(), nullptr);
} }
@ -215,9 +215,9 @@ TEST_P(IOSurfaceValidationTests, InvalidHeight) {
// Test an error occurs if the descriptor format isn't compatible with the IOSurface's // Test an error occurs if the descriptor format isn't compatible with the IOSurface's
TEST_P(IOSurfaceValidationTests, InvalidFormat) { TEST_P(IOSurfaceValidationTests, InvalidFormat) {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
descriptor.format = dawn::TextureFormat::R8Unorm; descriptor.format = wgpu::TextureFormat::R8Unorm;
ASSERT_DEVICE_ERROR(dawn::Texture texture = ASSERT_DEVICE_ERROR(wgpu::Texture texture =
WrapIOSurface(&descriptor, defaultIOSurface.get(), 0)); WrapIOSurface(&descriptor, defaultIOSurface.get(), 0));
ASSERT_EQ(texture.Get(), nullptr); ASSERT_EQ(texture.Get(), nullptr);
} }
@ -228,7 +228,7 @@ class IOSurfaceUsageTests : public IOSurfaceTestBase {
public: public:
// Test that sampling a 1x1 works. // Test that sampling a 1x1 works.
void DoSampleTest(IOSurfaceRef ioSurface, void DoSampleTest(IOSurfaceRef ioSurface,
dawn::TextureFormat format, wgpu::TextureFormat format,
void* data, void* data,
size_t dataSize, size_t dataSize,
RGBA8 expectedColor) { RGBA8 expectedColor) {
@ -238,37 +238,37 @@ class IOSurfaceUsageTests : public IOSurfaceTestBase {
IOSurfaceUnlock(ioSurface, 0, nullptr); IOSurfaceUnlock(ioSurface, 0, nullptr);
// The bindgroup containing the texture view for the ioSurface as well as the sampler. // The bindgroup containing the texture view for the ioSurface as well as the sampler.
dawn::BindGroupLayout bgl; wgpu::BindGroupLayout bgl;
dawn::BindGroup bindGroup; wgpu::BindGroup bindGroup;
{ {
dawn::TextureDescriptor textureDescriptor; wgpu::TextureDescriptor textureDescriptor;
textureDescriptor.dimension = dawn::TextureDimension::e2D; textureDescriptor.dimension = wgpu::TextureDimension::e2D;
textureDescriptor.format = format; textureDescriptor.format = format;
textureDescriptor.size = {1, 1, 1}; textureDescriptor.size = {1, 1, 1};
textureDescriptor.sampleCount = 1; textureDescriptor.sampleCount = 1;
textureDescriptor.arrayLayerCount = 1; textureDescriptor.arrayLayerCount = 1;
textureDescriptor.mipLevelCount = 1; textureDescriptor.mipLevelCount = 1;
textureDescriptor.usage = dawn::TextureUsage::Sampled; textureDescriptor.usage = wgpu::TextureUsage::Sampled;
dawn::Texture wrappingTexture = WrapIOSurface(&textureDescriptor, ioSurface, 0); wgpu::Texture wrappingTexture = WrapIOSurface(&textureDescriptor, ioSurface, 0);
dawn::TextureView textureView = wrappingTexture.CreateView(); wgpu::TextureView textureView = wrappingTexture.CreateView();
dawn::SamplerDescriptor samplerDescriptor = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor samplerDescriptor = utils::GetDefaultSamplerDescriptor();
dawn::Sampler sampler = device.CreateSampler(&samplerDescriptor); wgpu::Sampler sampler = device.CreateSampler(&samplerDescriptor);
bgl = utils::MakeBindGroupLayout( bgl = utils::MakeBindGroupLayout(
device, { device, {
{0, dawn::ShaderStage::Fragment, dawn::BindingType::Sampler}, {0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture}, {1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture},
}); });
bindGroup = utils::MakeBindGroup(device, bgl, {{0, sampler}, {1, textureView}}); bindGroup = utils::MakeBindGroup(device, bgl, {{0, sampler}, {1, textureView}});
} }
// The simplest texture sampling pipeline. // The simplest texture sampling pipeline.
dawn::RenderPipeline pipeline; wgpu::RenderPipeline pipeline;
{ {
dawn::ShaderModule vs = wgpu::ShaderModule vs =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
layout (location = 0) out vec2 o_texCoord; layout (location = 0) out vec2 o_texCoord;
@ -289,7 +289,7 @@ class IOSurfaceUsageTests : public IOSurfaceTestBase {
o_texCoord = texCoord[gl_VertexIndex]; o_texCoord = texCoord[gl_VertexIndex];
} }
)"); )");
dawn::ShaderModule fs = wgpu::ShaderModule fs =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(set = 0, binding = 0) uniform sampler sampler0; layout(set = 0, binding = 0) uniform sampler sampler0;
@ -306,23 +306,23 @@ class IOSurfaceUsageTests : public IOSurfaceTestBase {
descriptor.vertexStage.module = vs; descriptor.vertexStage.module = vs;
descriptor.cFragmentStage.module = fs; descriptor.cFragmentStage.module = fs;
descriptor.layout = utils::MakeBasicPipelineLayout(device, &bgl); descriptor.layout = utils::MakeBasicPipelineLayout(device, &bgl);
descriptor.cColorStates[0].format = dawn::TextureFormat::RGBA8Unorm; descriptor.cColorStates[0].format = wgpu::TextureFormat::RGBA8Unorm;
pipeline = device.CreateRenderPipeline(&descriptor); pipeline = device.CreateRenderPipeline(&descriptor);
} }
// Submit commands samping from the ioSurface and writing the result to renderPass.color // Submit commands samping from the ioSurface and writing the result to renderPass.color
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 1, 1); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 1, 1);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(expectedColor, renderPass.color, 0, 0); EXPECT_PIXEL_RGBA8_EQ(expectedColor, renderPass.color, 0, 0);
@ -330,32 +330,32 @@ class IOSurfaceUsageTests : public IOSurfaceTestBase {
// Test that clearing using BeginRenderPass writes correct data in the ioSurface. // Test that clearing using BeginRenderPass writes correct data in the ioSurface.
void DoClearTest(IOSurfaceRef ioSurface, void DoClearTest(IOSurfaceRef ioSurface,
dawn::TextureFormat format, wgpu::TextureFormat format,
void* data, void* data,
size_t dataSize) { size_t dataSize) {
// Get a texture view for the ioSurface // Get a texture view for the ioSurface
dawn::TextureDescriptor textureDescriptor; wgpu::TextureDescriptor textureDescriptor;
textureDescriptor.dimension = dawn::TextureDimension::e2D; textureDescriptor.dimension = wgpu::TextureDimension::e2D;
textureDescriptor.format = format; textureDescriptor.format = format;
textureDescriptor.size = {1, 1, 1}; textureDescriptor.size = {1, 1, 1};
textureDescriptor.sampleCount = 1; textureDescriptor.sampleCount = 1;
textureDescriptor.arrayLayerCount = 1; textureDescriptor.arrayLayerCount = 1;
textureDescriptor.mipLevelCount = 1; textureDescriptor.mipLevelCount = 1;
textureDescriptor.usage = dawn::TextureUsage::OutputAttachment; textureDescriptor.usage = wgpu::TextureUsage::OutputAttachment;
dawn::Texture ioSurfaceTexture = WrapIOSurface(&textureDescriptor, ioSurface, 0); wgpu::Texture ioSurfaceTexture = WrapIOSurface(&textureDescriptor, ioSurface, 0);
dawn::TextureView ioSurfaceView = ioSurfaceTexture.CreateView(); wgpu::TextureView ioSurfaceView = ioSurfaceTexture.CreateView();
utils::ComboRenderPassDescriptor renderPassDescriptor({ioSurfaceView}, {}); utils::ComboRenderPassDescriptor renderPassDescriptor({ioSurfaceView}, {});
renderPassDescriptor.cColorAttachments[0].clearColor = {1 / 255.0f, 2 / 255.0f, 3 / 255.0f, renderPassDescriptor.cColorAttachments[0].clearColor = {1 / 255.0f, 2 / 255.0f, 3 / 255.0f,
4 / 255.0f}; 4 / 255.0f};
// Execute commands to clear the ioSurface // Execute commands to clear the ioSurface
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
// Wait for the commands touching the IOSurface to be scheduled // Wait for the commands touching the IOSurface to be scheduled
@ -374,7 +374,7 @@ TEST_P(IOSurfaceUsageTests, SampleFromR8IOSurface) {
ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'L008', 1); ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'L008', 1);
uint8_t data = 0x01; uint8_t data = 0x01;
DoSampleTest(ioSurface.get(), dawn::TextureFormat::R8Unorm, &data, sizeof(data), DoSampleTest(ioSurface.get(), wgpu::TextureFormat::R8Unorm, &data, sizeof(data),
RGBA8(1, 0, 0, 255)); RGBA8(1, 0, 0, 255));
} }
@ -384,7 +384,7 @@ TEST_P(IOSurfaceUsageTests, ClearR8IOSurface) {
ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'L008', 1); ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'L008', 1);
uint8_t data = 0x01; uint8_t data = 0x01;
DoClearTest(ioSurface.get(), dawn::TextureFormat::R8Unorm, &data, sizeof(data)); DoClearTest(ioSurface.get(), wgpu::TextureFormat::R8Unorm, &data, sizeof(data));
} }
// Test sampling from a RG8 IOSurface // Test sampling from a RG8 IOSurface
@ -393,7 +393,7 @@ TEST_P(IOSurfaceUsageTests, SampleFromRG8IOSurface) {
ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, '2C08', 2); ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, '2C08', 2);
uint16_t data = 0x0102; // Stored as (G, R) uint16_t data = 0x0102; // Stored as (G, R)
DoSampleTest(ioSurface.get(), dawn::TextureFormat::RG8Unorm, &data, sizeof(data), DoSampleTest(ioSurface.get(), wgpu::TextureFormat::RG8Unorm, &data, sizeof(data),
RGBA8(2, 1, 0, 255)); RGBA8(2, 1, 0, 255));
} }
@ -403,7 +403,7 @@ TEST_P(IOSurfaceUsageTests, ClearRG8IOSurface) {
ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, '2C08', 2); ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, '2C08', 2);
uint16_t data = 0x0201; uint16_t data = 0x0201;
DoClearTest(ioSurface.get(), dawn::TextureFormat::RG8Unorm, &data, sizeof(data)); DoClearTest(ioSurface.get(), wgpu::TextureFormat::RG8Unorm, &data, sizeof(data));
} }
// Test sampling from a BGRA8 IOSurface // Test sampling from a BGRA8 IOSurface
@ -412,7 +412,7 @@ TEST_P(IOSurfaceUsageTests, SampleFromBGRA8IOSurface) {
ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'BGRA', 4); ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'BGRA', 4);
uint32_t data = 0x01020304; // Stored as (A, R, G, B) uint32_t data = 0x01020304; // Stored as (A, R, G, B)
DoSampleTest(ioSurface.get(), dawn::TextureFormat::BGRA8Unorm, &data, sizeof(data), DoSampleTest(ioSurface.get(), wgpu::TextureFormat::BGRA8Unorm, &data, sizeof(data),
RGBA8(2, 3, 4, 1)); RGBA8(2, 3, 4, 1));
} }
@ -422,7 +422,7 @@ TEST_P(IOSurfaceUsageTests, ClearBGRA8IOSurface) {
ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'BGRA', 4); ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'BGRA', 4);
uint32_t data = 0x04010203; uint32_t data = 0x04010203;
DoClearTest(ioSurface.get(), dawn::TextureFormat::BGRA8Unorm, &data, sizeof(data)); DoClearTest(ioSurface.get(), wgpu::TextureFormat::BGRA8Unorm, &data, sizeof(data));
} }
// Test sampling from an RGBA8 IOSurface // Test sampling from an RGBA8 IOSurface
@ -431,7 +431,7 @@ TEST_P(IOSurfaceUsageTests, SampleFromRGBA8IOSurface) {
ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'RGBA', 4); ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'RGBA', 4);
uint32_t data = 0x01020304; // Stored as (A, B, G, R) uint32_t data = 0x01020304; // Stored as (A, B, G, R)
DoSampleTest(ioSurface.get(), dawn::TextureFormat::RGBA8Unorm, &data, sizeof(data), DoSampleTest(ioSurface.get(), wgpu::TextureFormat::RGBA8Unorm, &data, sizeof(data),
RGBA8(4, 3, 2, 1)); RGBA8(4, 3, 2, 1));
} }
@ -441,7 +441,7 @@ TEST_P(IOSurfaceUsageTests, ClearRGBA8IOSurface) {
ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'RGBA', 4); ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'RGBA', 4);
uint32_t data = 0x04030201; uint32_t data = 0x04030201;
DoClearTest(ioSurface.get(), dawn::TextureFormat::RGBA8Unorm, &data, sizeof(data)); DoClearTest(ioSurface.get(), wgpu::TextureFormat::RGBA8Unorm, &data, sizeof(data));
} }
DAWN_INSTANTIATE_TEST(IOSurfaceValidationTests, MetalBackend); DAWN_INSTANTIATE_TEST(IOSurfaceValidationTests, MetalBackend);

View File

@ -30,8 +30,8 @@ class IndexFormatTest : public DawnTest {
utils::BasicRenderPass renderPass; utils::BasicRenderPass renderPass;
dawn::RenderPipeline MakeTestPipeline(dawn::IndexFormat format) { wgpu::RenderPipeline MakeTestPipeline(wgpu::IndexFormat format) {
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
layout(location = 0) in vec4 pos; layout(location = 0) in vec4 pos;
@ -39,7 +39,7 @@ class IndexFormatTest : public DawnTest {
gl_Position = pos; gl_Position = pos;
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -50,12 +50,12 @@ class IndexFormatTest : public DawnTest {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cVertexInput.indexFormat = format; descriptor.cVertexInput.indexFormat = format;
descriptor.cVertexInput.bufferCount = 1; descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float); descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
descriptor.cVertexInput.cBuffers[0].attributeCount = 1; descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4; descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat; descriptor.cColorStates[0].format = renderPass.colorFormat;
return device.CreateRenderPipeline(&descriptor); return device.CreateRenderPipeline(&descriptor);
@ -64,19 +64,19 @@ class IndexFormatTest : public DawnTest {
// Test that the Uint32 index format is correctly interpreted // Test that the Uint32 index format is correctly interpreted
TEST_P(IndexFormatTest, Uint32) { TEST_P(IndexFormatTest, Uint32) {
dawn::RenderPipeline pipeline = MakeTestPipeline(dawn::IndexFormat::Uint32); wgpu::RenderPipeline pipeline = MakeTestPipeline(wgpu::IndexFormat::Uint32);
dawn::Buffer vertexBuffer = utils::CreateBufferFromData<float>( wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex, device, wgpu::BufferUsage::Vertex,
{-1.0f, -1.0f, 0.0f, 1.0f, // Note Vertices[0] = Vertices[1] {-1.0f, -1.0f, 0.0f, 1.0f, // Note Vertices[0] = Vertices[1]
-1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f}); -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f});
// If this is interpreted as Uint16, then it would be 0, 1, 0, ... and would draw nothing. // If this is interpreted as Uint16, then it would be 0, 1, 0, ... and would draw nothing.
dawn::Buffer indexBuffer = wgpu::Buffer indexBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Index, {1, 2, 3}); utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Index, {1, 2, 3});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer); pass.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer); pass.SetIndexBuffer(indexBuffer);
@ -84,7 +84,7 @@ TEST_P(IndexFormatTest, Uint32) {
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300); EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
@ -92,18 +92,18 @@ TEST_P(IndexFormatTest, Uint32) {
// Test that the Uint16 index format is correctly interpreted // Test that the Uint16 index format is correctly interpreted
TEST_P(IndexFormatTest, Uint16) { TEST_P(IndexFormatTest, Uint16) {
dawn::RenderPipeline pipeline = MakeTestPipeline(dawn::IndexFormat::Uint16); wgpu::RenderPipeline pipeline = MakeTestPipeline(wgpu::IndexFormat::Uint16);
dawn::Buffer vertexBuffer = utils::CreateBufferFromData<float>( wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex, device, wgpu::BufferUsage::Vertex,
{-1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f}); {-1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f});
// If this is interpreted as uint32, it will have index 1 and 2 be both 0 and render nothing // If this is interpreted as uint32, it will have index 1 and 2 be both 0 and render nothing
dawn::Buffer indexBuffer = wgpu::Buffer indexBuffer =
utils::CreateBufferFromData<uint16_t>(device, dawn::BufferUsage::Index, {1, 2, 0, 0, 0, 0}); utils::CreateBufferFromData<uint16_t>(device, wgpu::BufferUsage::Index, {1, 2, 0, 0, 0, 0});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer); pass.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer); pass.SetIndexBuffer(indexBuffer);
@ -111,7 +111,7 @@ TEST_P(IndexFormatTest, Uint16) {
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300); EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
@ -131,16 +131,16 @@ TEST_P(IndexFormatTest, Uint16) {
// Test use of primitive restart with an Uint32 index format // Test use of primitive restart with an Uint32 index format
TEST_P(IndexFormatTest, Uint32PrimitiveRestart) { TEST_P(IndexFormatTest, Uint32PrimitiveRestart) {
dawn::RenderPipeline pipeline = MakeTestPipeline(dawn::IndexFormat::Uint32); wgpu::RenderPipeline pipeline = MakeTestPipeline(wgpu::IndexFormat::Uint32);
dawn::Buffer vertexBuffer = utils::CreateBufferFromData<float>( wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex, device, wgpu::BufferUsage::Vertex,
{ {
0.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
}); });
dawn::Buffer indexBuffer = wgpu::Buffer indexBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Index, utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Index,
{ {
0, 0,
1, 1,
@ -151,9 +151,9 @@ TEST_P(IndexFormatTest, Uint32PrimitiveRestart) {
2, 2,
}); });
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer); pass.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer); pass.SetIndexBuffer(indexBuffer);
@ -161,7 +161,7 @@ TEST_P(IndexFormatTest, Uint32PrimitiveRestart) {
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 190, 190); // A EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 190, 190); // A
@ -171,16 +171,16 @@ TEST_P(IndexFormatTest, Uint32PrimitiveRestart) {
// Test use of primitive restart with an Uint16 index format // Test use of primitive restart with an Uint16 index format
TEST_P(IndexFormatTest, Uint16PrimitiveRestart) { TEST_P(IndexFormatTest, Uint16PrimitiveRestart) {
dawn::RenderPipeline pipeline = MakeTestPipeline(dawn::IndexFormat::Uint16); wgpu::RenderPipeline pipeline = MakeTestPipeline(wgpu::IndexFormat::Uint16);
dawn::Buffer vertexBuffer = utils::CreateBufferFromData<float>( wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex, device, wgpu::BufferUsage::Vertex,
{ {
0.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
}); });
dawn::Buffer indexBuffer = wgpu::Buffer indexBuffer =
utils::CreateBufferFromData<uint16_t>(device, dawn::BufferUsage::Index, utils::CreateBufferFromData<uint16_t>(device, wgpu::BufferUsage::Index,
{ {
0, 0,
1, 1,
@ -193,9 +193,9 @@ TEST_P(IndexFormatTest, Uint16PrimitiveRestart) {
0xFFFFu, 0xFFFFu,
}); });
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer); pass.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer); pass.SetIndexBuffer(indexBuffer);
@ -203,7 +203,7 @@ TEST_P(IndexFormatTest, Uint16PrimitiveRestart) {
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 190, 190); // A EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 190, 190); // A
@ -217,20 +217,20 @@ TEST_P(IndexFormatTest, Uint16PrimitiveRestart) {
TEST_P(IndexFormatTest, ChangePipelineAfterSetIndexBuffer) { TEST_P(IndexFormatTest, ChangePipelineAfterSetIndexBuffer) {
DAWN_SKIP_TEST_IF(IsD3D12() || IsVulkan()); DAWN_SKIP_TEST_IF(IsD3D12() || IsVulkan());
dawn::RenderPipeline pipeline32 = MakeTestPipeline(dawn::IndexFormat::Uint32); wgpu::RenderPipeline pipeline32 = MakeTestPipeline(wgpu::IndexFormat::Uint32);
dawn::RenderPipeline pipeline16 = MakeTestPipeline(dawn::IndexFormat::Uint16); wgpu::RenderPipeline pipeline16 = MakeTestPipeline(wgpu::IndexFormat::Uint16);
dawn::Buffer vertexBuffer = utils::CreateBufferFromData<float>( wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex, device, wgpu::BufferUsage::Vertex,
{-1.0f, -1.0f, 0.0f, 1.0f, // Note Vertices[0] = Vertices[1] {-1.0f, -1.0f, 0.0f, 1.0f, // Note Vertices[0] = Vertices[1]
-1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f}); -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f});
// If this is interpreted as Uint16, then it would be 0, 1, 0, ... and would draw nothing. // If this is interpreted as Uint16, then it would be 0, 1, 0, ... and would draw nothing.
dawn::Buffer indexBuffer = wgpu::Buffer indexBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Index, {1, 2, 3}); utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Index, {1, 2, 3});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline16); pass.SetPipeline(pipeline16);
pass.SetVertexBuffer(0, vertexBuffer); pass.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer); pass.SetIndexBuffer(indexBuffer);
@ -239,7 +239,7 @@ TEST_P(IndexFormatTest, ChangePipelineAfterSetIndexBuffer) {
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300); EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
@ -251,17 +251,17 @@ TEST_P(IndexFormatTest, ChangePipelineAfterSetIndexBuffer) {
// TODO(cwallez@chromium.org): This is currently disallowed by the validation but // TODO(cwallez@chromium.org): This is currently disallowed by the validation but
// we want to support eventually. // we want to support eventually.
TEST_P(IndexFormatTest, DISABLED_SetIndexBufferBeforeSetPipeline) { TEST_P(IndexFormatTest, DISABLED_SetIndexBufferBeforeSetPipeline) {
dawn::RenderPipeline pipeline = MakeTestPipeline(dawn::IndexFormat::Uint32); wgpu::RenderPipeline pipeline = MakeTestPipeline(wgpu::IndexFormat::Uint32);
dawn::Buffer vertexBuffer = utils::CreateBufferFromData<float>( wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex, device, wgpu::BufferUsage::Vertex,
{-1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f}); {-1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f});
dawn::Buffer indexBuffer = wgpu::Buffer indexBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Index, {0, 1, 2}); utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Index, {0, 1, 2});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetIndexBuffer(indexBuffer); pass.SetIndexBuffer(indexBuffer);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer); pass.SetVertexBuffer(0, vertexBuffer);
@ -269,7 +269,7 @@ TEST_P(IndexFormatTest, DISABLED_SetIndexBufferBeforeSetPipeline) {
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300); EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);

View File

@ -36,7 +36,7 @@ class MultisampledRenderingTest : public DawnTest {
mDepthStencilView = mDepthStencilTexture.CreateView(); mDepthStencilView = mDepthStencilTexture.CreateView();
} }
dawn::RenderPipeline CreateRenderPipelineWithOneOutputForTest(bool testDepth) { wgpu::RenderPipeline CreateRenderPipelineWithOneOutputForTest(bool testDepth) {
const char* kFsOneOutputWithDepth = const char* kFsOneOutputWithDepth =
R"(#version 450 R"(#version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -65,7 +65,7 @@ class MultisampledRenderingTest : public DawnTest {
return CreateRenderPipelineForTest(fs, 1, testDepth); return CreateRenderPipelineForTest(fs, 1, testDepth);
} }
dawn::RenderPipeline CreateRenderPipelineWithTwoOutputsForTest() { wgpu::RenderPipeline CreateRenderPipelineWithTwoOutputsForTest() {
const char* kFsTwoOutputs = const char* kFsTwoOutputs =
R"(#version 450 R"(#version 450
layout(location = 0) out vec4 fragColor1; layout(location = 0) out vec4 fragColor1;
@ -82,12 +82,12 @@ class MultisampledRenderingTest : public DawnTest {
return CreateRenderPipelineForTest(kFsTwoOutputs, 2, false); return CreateRenderPipelineForTest(kFsTwoOutputs, 2, false);
} }
dawn::Texture CreateTextureForOutputAttachment(dawn::TextureFormat format, wgpu::Texture CreateTextureForOutputAttachment(wgpu::TextureFormat format,
uint32_t sampleCount, uint32_t sampleCount,
uint32_t mipLevelCount = 1, uint32_t mipLevelCount = 1,
uint32_t arrayLayerCount = 1) { uint32_t arrayLayerCount = 1) {
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kWidth << (mipLevelCount - 1); descriptor.size.width = kWidth << (mipLevelCount - 1);
descriptor.size.height = kHeight << (mipLevelCount - 1); descriptor.size.height = kHeight << (mipLevelCount - 1);
descriptor.size.depth = 1; descriptor.size.depth = 1;
@ -95,22 +95,21 @@ class MultisampledRenderingTest : public DawnTest {
descriptor.sampleCount = sampleCount; descriptor.sampleCount = sampleCount;
descriptor.format = format; descriptor.format = format;
descriptor.mipLevelCount = mipLevelCount; descriptor.mipLevelCount = mipLevelCount;
descriptor.usage = dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc; descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
return device.CreateTexture(&descriptor); return device.CreateTexture(&descriptor);
} }
void EncodeRenderPassForTest(dawn::CommandEncoder commandEncoder, void EncodeRenderPassForTest(wgpu::CommandEncoder commandEncoder,
const dawn::RenderPassDescriptor& renderPass, const wgpu::RenderPassDescriptor& renderPass,
const dawn::RenderPipeline& pipeline, const wgpu::RenderPipeline& pipeline,
const float* uniformData, const float* uniformData,
uint32_t uniformDataSize) { uint32_t uniformDataSize) {
dawn::Buffer uniformBuffer = utils::CreateBufferFromData( wgpu::Buffer uniformBuffer = utils::CreateBufferFromData(
device, uniformData, uniformDataSize, dawn::BufferUsage::Uniform); device, uniformData, uniformDataSize, wgpu::BufferUsage::Uniform);
dawn::BindGroup bindGroup = wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, mBindGroupLayout,
utils::MakeBindGroup(device, mBindGroupLayout,
{{0, uniformBuffer, 0, uniformDataSize}}); {{0, uniformBuffer, 0, uniformDataSize}});
dawn::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(&renderPass); wgpu::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(&renderPass);
renderPassEncoder.SetPipeline(pipeline); renderPassEncoder.SetPipeline(pipeline);
renderPassEncoder.SetBindGroup(0, bindGroup); renderPassEncoder.SetBindGroup(0, bindGroup);
renderPassEncoder.Draw(3, 1, 0, 0); renderPassEncoder.Draw(3, 1, 0, 0);
@ -118,19 +117,19 @@ class MultisampledRenderingTest : public DawnTest {
} }
utils::ComboRenderPassDescriptor CreateComboRenderPassDescriptorForTest( utils::ComboRenderPassDescriptor CreateComboRenderPassDescriptorForTest(
std::initializer_list<dawn::TextureView> colorViews, std::initializer_list<wgpu::TextureView> colorViews,
std::initializer_list<dawn::TextureView> resolveTargetViews, std::initializer_list<wgpu::TextureView> resolveTargetViews,
dawn::LoadOp colorLoadOp, wgpu::LoadOp colorLoadOp,
dawn::LoadOp depthStencilLoadOp, wgpu::LoadOp depthStencilLoadOp,
bool hasDepthStencilAttachment) { bool hasDepthStencilAttachment) {
ASSERT(colorViews.size() == resolveTargetViews.size()); ASSERT(colorViews.size() == resolveTargetViews.size());
constexpr dawn::Color kClearColor = {0.0f, 0.0f, 0.0f, 0.0f}; constexpr wgpu::Color kClearColor = {0.0f, 0.0f, 0.0f, 0.0f};
constexpr float kClearDepth = 1.0f; constexpr float kClearDepth = 1.0f;
utils::ComboRenderPassDescriptor renderPass(colorViews); utils::ComboRenderPassDescriptor renderPass(colorViews);
uint32_t i = 0; uint32_t i = 0;
for (const dawn::TextureView& resolveTargetView : resolveTargetViews) { for (const wgpu::TextureView& resolveTargetView : resolveTargetViews) {
renderPass.cColorAttachments[i].loadOp = colorLoadOp; renderPass.cColorAttachments[i].loadOp = colorLoadOp;
renderPass.cColorAttachments[i].clearColor = kClearColor; renderPass.cColorAttachments[i].clearColor = kClearColor;
renderPass.cColorAttachments[i].resolveTarget = resolveTargetView; renderPass.cColorAttachments[i].resolveTarget = resolveTargetView;
@ -148,8 +147,8 @@ class MultisampledRenderingTest : public DawnTest {
return renderPass; return renderPass;
} }
void VerifyResolveTarget(const dawn::Color& inputColor, void VerifyResolveTarget(const wgpu::Color& inputColor,
dawn::Texture resolveTexture, wgpu::Texture resolveTexture,
uint32_t mipmapLevel = 0, uint32_t mipmapLevel = 0,
uint32_t arrayLayer = 0) { uint32_t arrayLayer = 0) {
constexpr float kMSAACoverage = 0.5f; constexpr float kMSAACoverage = 0.5f;
@ -171,19 +170,19 @@ class MultisampledRenderingTest : public DawnTest {
constexpr static uint32_t kWidth = 3; constexpr static uint32_t kWidth = 3;
constexpr static uint32_t kHeight = 3; constexpr static uint32_t kHeight = 3;
constexpr static uint32_t kSampleCount = 4; constexpr static uint32_t kSampleCount = 4;
constexpr static dawn::TextureFormat kColorFormat = dawn::TextureFormat::RGBA8Unorm; constexpr static wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
constexpr static dawn::TextureFormat kDepthStencilFormat = constexpr static wgpu::TextureFormat kDepthStencilFormat =
dawn::TextureFormat::Depth24PlusStencil8; wgpu::TextureFormat::Depth24PlusStencil8;
dawn::TextureView mMultisampledColorView; wgpu::TextureView mMultisampledColorView;
dawn::Texture mResolveTexture; wgpu::Texture mResolveTexture;
dawn::TextureView mResolveView; wgpu::TextureView mResolveView;
dawn::Texture mDepthStencilTexture; wgpu::Texture mDepthStencilTexture;
dawn::TextureView mDepthStencilView; wgpu::TextureView mDepthStencilView;
dawn::BindGroupLayout mBindGroupLayout; wgpu::BindGroupLayout mBindGroupLayout;
private: private:
dawn::RenderPipeline CreateRenderPipelineForTest(const char* fs, wgpu::RenderPipeline CreateRenderPipelineForTest(const char* fs,
uint32_t numColorAttachments, uint32_t numColorAttachments,
bool hasDepthStencilAttachment) { bool hasDepthStencilAttachment) {
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device); utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
@ -204,16 +203,16 @@ class MultisampledRenderingTest : public DawnTest {
mBindGroupLayout = utils::MakeBindGroupLayout( mBindGroupLayout = utils::MakeBindGroupLayout(
device, { device, {
{0, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}, {0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer},
}); });
dawn::PipelineLayout pipelineLayout = wgpu::PipelineLayout pipelineLayout =
utils::MakeBasicPipelineLayout(device, &mBindGroupLayout); utils::MakeBasicPipelineLayout(device, &mBindGroupLayout);
pipelineDescriptor.layout = pipelineLayout; pipelineDescriptor.layout = pipelineLayout;
if (hasDepthStencilAttachment) { if (hasDepthStencilAttachment) {
pipelineDescriptor.cDepthStencilState.format = kDepthStencilFormat; pipelineDescriptor.cDepthStencilState.format = kDepthStencilFormat;
pipelineDescriptor.cDepthStencilState.depthWriteEnabled = true; pipelineDescriptor.cDepthStencilState.depthWriteEnabled = true;
pipelineDescriptor.cDepthStencilState.depthCompare = dawn::CompareFunction::Less; pipelineDescriptor.cDepthStencilState.depthCompare = wgpu::CompareFunction::Less;
pipelineDescriptor.depthStencilState = &pipelineDescriptor.cDepthStencilState; pipelineDescriptor.depthStencilState = &pipelineDescriptor.cDepthStencilState;
} }
@ -231,23 +230,23 @@ class MultisampledRenderingTest : public DawnTest {
// Test using one multisampled color attachment with resolve target can render correctly. // Test using one multisampled color attachment with resolve target can render correctly.
TEST_P(MultisampledRenderingTest, ResolveInto2DTexture) { TEST_P(MultisampledRenderingTest, ResolveInto2DTexture) {
constexpr bool kTestDepth = false; constexpr bool kTestDepth = false;
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth); wgpu::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth);
constexpr dawn::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f}; constexpr wgpu::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f};
constexpr uint32_t kSize = sizeof(kGreen); constexpr uint32_t kSize = sizeof(kGreen);
// Draw a green triangle. // Draw a green triangle.
{ {
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest( utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {mResolveView}, dawn::LoadOp::Clear, dawn::LoadOp::Clear, {mMultisampledColorView}, {mResolveView}, wgpu::LoadOp::Clear, wgpu::LoadOp::Clear,
kTestDepth); kTestDepth);
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, &kGreen.r, kSize); EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, &kGreen.r, kSize);
} }
dawn::CommandBuffer commandBuffer = commandEncoder.Finish(); wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue(); wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer); queue.Submit(1, &commandBuffer);
VerifyResolveTarget(kGreen, mResolveTexture); VerifyResolveTarget(kGreen, mResolveTexture);
@ -256,17 +255,17 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DTexture) {
// Test multisampled rendering with depth test works correctly. // Test multisampled rendering with depth test works correctly.
TEST_P(MultisampledRenderingTest, MultisampledRenderingWithDepthTest) { TEST_P(MultisampledRenderingTest, MultisampledRenderingWithDepthTest) {
constexpr bool kTestDepth = true; constexpr bool kTestDepth = true;
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth); wgpu::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth);
constexpr dawn::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f}; constexpr wgpu::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f};
constexpr dawn::Color kRed = {0.8f, 0.0f, 0.0f, 0.8f}; constexpr wgpu::Color kRed = {0.8f, 0.0f, 0.0f, 0.8f};
// In first render pass we draw a green triangle with depth value == 0.2f. // In first render pass we draw a green triangle with depth value == 0.2f.
{ {
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest( utils::ComboRenderPassDescriptor renderPass =
{mMultisampledColorView}, {mResolveView}, dawn::LoadOp::Clear, dawn::LoadOp::Clear, CreateComboRenderPassDescriptorForTest({mMultisampledColorView}, {mResolveView},
true); wgpu::LoadOp::Clear, wgpu::LoadOp::Clear, true);
std::array<float, 5> kUniformData = {kGreen.r, kGreen.g, kGreen.b, kGreen.a, // Color std::array<float, 5> kUniformData = {kGreen.r, kGreen.g, kGreen.b, kGreen.a, // Color
0.2f}; // depth 0.2f}; // depth
constexpr uint32_t kSize = sizeof(kUniformData); constexpr uint32_t kSize = sizeof(kUniformData);
@ -278,7 +277,7 @@ TEST_P(MultisampledRenderingTest, MultisampledRenderingWithDepthTest) {
// the last render pass. // the last render pass.
{ {
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest( utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {mResolveView}, dawn::LoadOp::Load, dawn::LoadOp::Load, {mMultisampledColorView}, {mResolveView}, wgpu::LoadOp::Load, wgpu::LoadOp::Load,
kTestDepth); kTestDepth);
std::array<float, 8> kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color std::array<float, 8> kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color
@ -287,8 +286,8 @@ TEST_P(MultisampledRenderingTest, MultisampledRenderingWithDepthTest) {
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, kUniformData.data(), kSize); EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, kUniformData.data(), kSize);
} }
dawn::CommandBuffer commandBuffer = commandEncoder.Finish(); wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue(); wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer); queue.Submit(1, &commandBuffer);
// The color of the pixel in the middle of mResolveTexture should be green if MSAA resolve runs // The color of the pixel in the middle of mResolveTexture should be green if MSAA resolve runs
@ -300,16 +299,16 @@ TEST_P(MultisampledRenderingTest, MultisampledRenderingWithDepthTest) {
// works correctly. // works correctly.
TEST_P(MultisampledRenderingTest, ResolveInAnotherRenderPass) { TEST_P(MultisampledRenderingTest, ResolveInAnotherRenderPass) {
constexpr bool kTestDepth = false; constexpr bool kTestDepth = false;
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth); wgpu::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth);
constexpr dawn::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f}; constexpr wgpu::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f};
constexpr uint32_t kSize = sizeof(kGreen); constexpr uint32_t kSize = sizeof(kGreen);
// In first render pass we draw a green triangle and do not set the resolve target. // In first render pass we draw a green triangle and do not set the resolve target.
{ {
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest( utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {nullptr}, dawn::LoadOp::Clear, dawn::LoadOp::Clear, {mMultisampledColorView}, {nullptr}, wgpu::LoadOp::Clear, wgpu::LoadOp::Clear,
kTestDepth); kTestDepth);
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, &kGreen.r, kSize); EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, &kGreen.r, kSize);
@ -318,15 +317,15 @@ TEST_P(MultisampledRenderingTest, ResolveInAnotherRenderPass) {
// In second render pass we ony do MSAA resolve with no draw call. // In second render pass we ony do MSAA resolve with no draw call.
{ {
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest( utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {mResolveView}, dawn::LoadOp::Load, dawn::LoadOp::Load, {mMultisampledColorView}, {mResolveView}, wgpu::LoadOp::Load, wgpu::LoadOp::Load,
kTestDepth); kTestDepth);
dawn::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(&renderPass); wgpu::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(&renderPass);
renderPassEncoder.EndPass(); renderPassEncoder.EndPass();
} }
dawn::CommandBuffer commandBuffer = commandEncoder.Finish(); wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue(); wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer); queue.Submit(1, &commandBuffer);
VerifyResolveTarget(kGreen, mResolveTexture); VerifyResolveTarget(kGreen, mResolveTexture);
@ -334,16 +333,16 @@ TEST_P(MultisampledRenderingTest, ResolveInAnotherRenderPass) {
// Test doing MSAA resolve into multiple resolve targets works correctly. // Test doing MSAA resolve into multiple resolve targets works correctly.
TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargets) { TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargets) {
dawn::TextureView multisampledColorView2 = wgpu::TextureView multisampledColorView2 =
CreateTextureForOutputAttachment(kColorFormat, kSampleCount).CreateView(); CreateTextureForOutputAttachment(kColorFormat, kSampleCount).CreateView();
dawn::Texture resolveTexture2 = CreateTextureForOutputAttachment(kColorFormat, 1); wgpu::Texture resolveTexture2 = CreateTextureForOutputAttachment(kColorFormat, 1);
dawn::TextureView resolveView2 = resolveTexture2.CreateView(); wgpu::TextureView resolveView2 = resolveTexture2.CreateView();
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPipeline pipeline = CreateRenderPipelineWithTwoOutputsForTest(); wgpu::RenderPipeline pipeline = CreateRenderPipelineWithTwoOutputsForTest();
constexpr dawn::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f}; constexpr wgpu::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f};
constexpr dawn::Color kRed = {0.8f, 0.0f, 0.0f, 0.8f}; constexpr wgpu::Color kRed = {0.8f, 0.0f, 0.0f, 0.8f};
constexpr bool kTestDepth = false; constexpr bool kTestDepth = false;
// Draw a red triangle to the first color attachment, and a blue triangle to the second color // Draw a red triangle to the first color attachment, and a blue triangle to the second color
@ -351,7 +350,7 @@ TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargets) {
{ {
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest( utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView, multisampledColorView2}, {mResolveView, resolveView2}, {mMultisampledColorView, multisampledColorView2}, {mResolveView, resolveView2},
dawn::LoadOp::Clear, dawn::LoadOp::Clear, kTestDepth); wgpu::LoadOp::Clear, wgpu::LoadOp::Clear, kTestDepth);
std::array<float, 8> kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color1 std::array<float, 8> kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color1
kGreen.r, kGreen.g, kGreen.b, kGreen.a}; // color2 kGreen.r, kGreen.g, kGreen.b, kGreen.a}; // color2
@ -359,8 +358,8 @@ TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargets) {
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, kUniformData.data(), kSize); EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, kUniformData.data(), kSize);
} }
dawn::CommandBuffer commandBuffer = commandEncoder.Finish(); wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue(); wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer); queue.Submit(1, &commandBuffer);
VerifyResolveTarget(kRed, mResolveTexture); VerifyResolveTarget(kRed, mResolveTexture);
@ -370,18 +369,18 @@ TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargets) {
// Test doing MSAA resolve on one multisampled texture twice works correctly. // Test doing MSAA resolve on one multisampled texture twice works correctly.
TEST_P(MultisampledRenderingTest, ResolveOneMultisampledTextureTwice) { TEST_P(MultisampledRenderingTest, ResolveOneMultisampledTextureTwice) {
constexpr bool kTestDepth = false; constexpr bool kTestDepth = false;
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth); wgpu::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth);
constexpr dawn::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f}; constexpr wgpu::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f};
constexpr uint32_t kSize = sizeof(kGreen); constexpr uint32_t kSize = sizeof(kGreen);
dawn::Texture resolveTexture2 = CreateTextureForOutputAttachment(kColorFormat, 1); wgpu::Texture resolveTexture2 = CreateTextureForOutputAttachment(kColorFormat, 1);
// In first render pass we draw a green triangle and specify mResolveView as the resolve target. // In first render pass we draw a green triangle and specify mResolveView as the resolve target.
{ {
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest( utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {mResolveView}, dawn::LoadOp::Clear, dawn::LoadOp::Clear, {mMultisampledColorView}, {mResolveView}, wgpu::LoadOp::Clear, wgpu::LoadOp::Clear,
kTestDepth); kTestDepth);
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, &kGreen.r, kSize); EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, &kGreen.r, kSize);
@ -389,17 +388,17 @@ TEST_P(MultisampledRenderingTest, ResolveOneMultisampledTextureTwice) {
// In second render pass we do MSAA resolve into resolveTexture2. // In second render pass we do MSAA resolve into resolveTexture2.
{ {
dawn::TextureView resolveView2 = resolveTexture2.CreateView(); wgpu::TextureView resolveView2 = resolveTexture2.CreateView();
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest( utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {resolveView2}, dawn::LoadOp::Load, dawn::LoadOp::Load, {mMultisampledColorView}, {resolveView2}, wgpu::LoadOp::Load, wgpu::LoadOp::Load,
kTestDepth); kTestDepth);
dawn::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(&renderPass); wgpu::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(&renderPass);
renderPassEncoder.EndPass(); renderPassEncoder.EndPass();
} }
dawn::CommandBuffer commandBuffer = commandEncoder.Finish(); wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue(); wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer); queue.Submit(1, &commandBuffer);
VerifyResolveTarget(kGreen, mResolveTexture); VerifyResolveTarget(kGreen, mResolveTexture);
@ -410,35 +409,35 @@ TEST_P(MultisampledRenderingTest, ResolveOneMultisampledTextureTwice) {
TEST_P(MultisampledRenderingTest, ResolveIntoOneMipmapLevelOf2DTexture) { TEST_P(MultisampledRenderingTest, ResolveIntoOneMipmapLevelOf2DTexture) {
constexpr uint32_t kBaseMipLevel = 2; constexpr uint32_t kBaseMipLevel = 2;
dawn::TextureViewDescriptor textureViewDescriptor; wgpu::TextureViewDescriptor textureViewDescriptor;
textureViewDescriptor.dimension = dawn::TextureViewDimension::e2D; textureViewDescriptor.dimension = wgpu::TextureViewDimension::e2D;
textureViewDescriptor.format = kColorFormat; textureViewDescriptor.format = kColorFormat;
textureViewDescriptor.baseArrayLayer = 0; textureViewDescriptor.baseArrayLayer = 0;
textureViewDescriptor.arrayLayerCount = 1; textureViewDescriptor.arrayLayerCount = 1;
textureViewDescriptor.mipLevelCount = 1; textureViewDescriptor.mipLevelCount = 1;
textureViewDescriptor.baseMipLevel = kBaseMipLevel; textureViewDescriptor.baseMipLevel = kBaseMipLevel;
dawn::Texture resolveTexture = wgpu::Texture resolveTexture =
CreateTextureForOutputAttachment(kColorFormat, 1, kBaseMipLevel + 1, 1); CreateTextureForOutputAttachment(kColorFormat, 1, kBaseMipLevel + 1, 1);
dawn::TextureView resolveView = resolveTexture.CreateView(&textureViewDescriptor); wgpu::TextureView resolveView = resolveTexture.CreateView(&textureViewDescriptor);
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
constexpr dawn::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f}; constexpr wgpu::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f};
constexpr uint32_t kSize = sizeof(kGreen); constexpr uint32_t kSize = sizeof(kGreen);
constexpr bool kTestDepth = false; constexpr bool kTestDepth = false;
// Draw a green triangle and do MSAA resolve. // Draw a green triangle and do MSAA resolve.
{ {
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest( utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {resolveView}, dawn::LoadOp::Clear, dawn::LoadOp::Clear, {mMultisampledColorView}, {resolveView}, wgpu::LoadOp::Clear, wgpu::LoadOp::Clear,
kTestDepth); kTestDepth);
dawn::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth); wgpu::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth);
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, &kGreen.r, kSize); EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, &kGreen.r, kSize);
} }
dawn::CommandBuffer commandBuffer = commandEncoder.Finish(); wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue(); wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer); queue.Submit(1, &commandBuffer);
VerifyResolveTarget(kGreen, resolveTexture, kBaseMipLevel, 0); VerifyResolveTarget(kGreen, resolveTexture, kBaseMipLevel, 0);
@ -446,11 +445,11 @@ TEST_P(MultisampledRenderingTest, ResolveIntoOneMipmapLevelOf2DTexture) {
// Test using a level or a layer of a 2D array texture as resolve target works correctly. // Test using a level or a layer of a 2D array texture as resolve target works correctly.
TEST_P(MultisampledRenderingTest, ResolveInto2DArrayTexture) { TEST_P(MultisampledRenderingTest, ResolveInto2DArrayTexture) {
dawn::TextureView multisampledColorView2 = wgpu::TextureView multisampledColorView2 =
CreateTextureForOutputAttachment(kColorFormat, kSampleCount).CreateView(); CreateTextureForOutputAttachment(kColorFormat, kSampleCount).CreateView();
dawn::TextureViewDescriptor baseTextureViewDescriptor; wgpu::TextureViewDescriptor baseTextureViewDescriptor;
baseTextureViewDescriptor.dimension = dawn::TextureViewDimension::e2D; baseTextureViewDescriptor.dimension = wgpu::TextureViewDimension::e2D;
baseTextureViewDescriptor.format = kColorFormat; baseTextureViewDescriptor.format = kColorFormat;
baseTextureViewDescriptor.arrayLayerCount = 1; baseTextureViewDescriptor.arrayLayerCount = 1;
baseTextureViewDescriptor.mipLevelCount = 1; baseTextureViewDescriptor.mipLevelCount = 1;
@ -458,29 +457,29 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DArrayTexture) {
// Create resolveTexture1 with only 1 mipmap level. // Create resolveTexture1 with only 1 mipmap level.
constexpr uint32_t kBaseArrayLayer1 = 2; constexpr uint32_t kBaseArrayLayer1 = 2;
constexpr uint32_t kBaseMipLevel1 = 0; constexpr uint32_t kBaseMipLevel1 = 0;
dawn::Texture resolveTexture1 = wgpu::Texture resolveTexture1 =
CreateTextureForOutputAttachment(kColorFormat, 1, kBaseMipLevel1 + 1, kBaseArrayLayer1 + 1); CreateTextureForOutputAttachment(kColorFormat, 1, kBaseMipLevel1 + 1, kBaseArrayLayer1 + 1);
dawn::TextureViewDescriptor resolveViewDescriptor1 = baseTextureViewDescriptor; wgpu::TextureViewDescriptor resolveViewDescriptor1 = baseTextureViewDescriptor;
resolveViewDescriptor1.baseArrayLayer = kBaseArrayLayer1; resolveViewDescriptor1.baseArrayLayer = kBaseArrayLayer1;
resolveViewDescriptor1.baseMipLevel = kBaseMipLevel1; resolveViewDescriptor1.baseMipLevel = kBaseMipLevel1;
dawn::TextureView resolveView1 = resolveTexture1.CreateView(&resolveViewDescriptor1); wgpu::TextureView resolveView1 = resolveTexture1.CreateView(&resolveViewDescriptor1);
// Create resolveTexture2 with (kBaseMipLevel2 + 1) mipmap levels and resolve into its last // Create resolveTexture2 with (kBaseMipLevel2 + 1) mipmap levels and resolve into its last
// mipmap level. // mipmap level.
constexpr uint32_t kBaseArrayLayer2 = 5; constexpr uint32_t kBaseArrayLayer2 = 5;
constexpr uint32_t kBaseMipLevel2 = 3; constexpr uint32_t kBaseMipLevel2 = 3;
dawn::Texture resolveTexture2 = wgpu::Texture resolveTexture2 =
CreateTextureForOutputAttachment(kColorFormat, 1, kBaseMipLevel2 + 1, kBaseArrayLayer2 + 1); CreateTextureForOutputAttachment(kColorFormat, 1, kBaseMipLevel2 + 1, kBaseArrayLayer2 + 1);
dawn::TextureViewDescriptor resolveViewDescriptor2 = baseTextureViewDescriptor; wgpu::TextureViewDescriptor resolveViewDescriptor2 = baseTextureViewDescriptor;
resolveViewDescriptor2.baseArrayLayer = kBaseArrayLayer2; resolveViewDescriptor2.baseArrayLayer = kBaseArrayLayer2;
resolveViewDescriptor2.baseMipLevel = kBaseMipLevel2; resolveViewDescriptor2.baseMipLevel = kBaseMipLevel2;
dawn::TextureView resolveView2 = resolveTexture2.CreateView(&resolveViewDescriptor2); wgpu::TextureView resolveView2 = resolveTexture2.CreateView(&resolveViewDescriptor2);
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPipeline pipeline = CreateRenderPipelineWithTwoOutputsForTest(); wgpu::RenderPipeline pipeline = CreateRenderPipelineWithTwoOutputsForTest();
constexpr dawn::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f}; constexpr wgpu::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f};
constexpr dawn::Color kRed = {0.8f, 0.0f, 0.0f, 0.8f}; constexpr wgpu::Color kRed = {0.8f, 0.0f, 0.0f, 0.8f};
constexpr bool kTestDepth = false; constexpr bool kTestDepth = false;
// Draw a red triangle to the first color attachment, and a green triangle to the second color // Draw a red triangle to the first color attachment, and a green triangle to the second color
@ -488,7 +487,7 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DArrayTexture) {
{ {
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest( utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView, multisampledColorView2}, {resolveView1, resolveView2}, {mMultisampledColorView, multisampledColorView2}, {resolveView1, resolveView2},
dawn::LoadOp::Clear, dawn::LoadOp::Clear, kTestDepth); wgpu::LoadOp::Clear, wgpu::LoadOp::Clear, kTestDepth);
std::array<float, 8> kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color1 std::array<float, 8> kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color1
kGreen.r, kGreen.g, kGreen.b, kGreen.a}; // color2 kGreen.r, kGreen.g, kGreen.b, kGreen.a}; // color2
@ -496,8 +495,8 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DArrayTexture) {
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, kUniformData.data(), kSize); EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, kUniformData.data(), kSize);
} }
dawn::CommandBuffer commandBuffer = commandEncoder.Finish(); wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue(); wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer); queue.Submit(1, &commandBuffer);
VerifyResolveTarget(kRed, resolveTexture1, kBaseMipLevel1, kBaseArrayLayer1); VerifyResolveTarget(kRed, resolveTexture1, kBaseMipLevel1, kBaseArrayLayer1);

View File

@ -28,17 +28,17 @@ class NonzeroTextureCreationTests : public DawnTest {
// Test that texture clears to 1's because toggle is enabled. // Test that texture clears to 1's because toggle is enabled.
TEST_P(NonzeroTextureCreationTests, TextureCreationClearsOneBits) { TEST_P(NonzeroTextureCreationTests, TextureCreationClearsOneBits) {
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kSize; descriptor.size.width = kSize;
descriptor.size.height = kSize; descriptor.size.height = kSize;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1; descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm; descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc; descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
RGBA8 filledWithOnes(255, 255, 255, 255); RGBA8 filledWithOnes(255, 255, 255, 255);
EXPECT_PIXEL_RGBA8_EQ(filledWithOnes, texture, 0, 0); EXPECT_PIXEL_RGBA8_EQ(filledWithOnes, texture, 0, 0);
@ -48,17 +48,17 @@ TEST_P(NonzeroTextureCreationTests, TextureCreationClearsOneBits) {
TEST_P(NonzeroTextureCreationTests, MipMapClears) { TEST_P(NonzeroTextureCreationTests, MipMapClears) {
constexpr uint32_t mipLevels = 4; constexpr uint32_t mipLevels = 4;
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kSize; descriptor.size.width = kSize;
descriptor.size.height = kSize; descriptor.size.height = kSize;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1; descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm; descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = mipLevels; descriptor.mipLevelCount = mipLevels;
descriptor.usage = dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc; descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
std::vector<RGBA8> expected; std::vector<RGBA8> expected;
RGBA8 filledWithOnes(255, 255, 255, 255); RGBA8 filledWithOnes(255, 255, 255, 255);
@ -73,17 +73,17 @@ TEST_P(NonzeroTextureCreationTests, MipMapClears) {
TEST_P(NonzeroTextureCreationTests, ArrayLayerClears) { TEST_P(NonzeroTextureCreationTests, ArrayLayerClears) {
constexpr uint32_t arrayLayers = 4; constexpr uint32_t arrayLayers = 4;
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kSize; descriptor.size.width = kSize;
descriptor.size.height = kSize; descriptor.size.height = kSize;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayerCount = arrayLayers; descriptor.arrayLayerCount = arrayLayers;
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm; descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc; descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
std::vector<RGBA8> expected; std::vector<RGBA8> expected;
RGBA8 filledWithOnes(255, 255, 255, 255); RGBA8 filledWithOnes(255, 255, 255, 255);
@ -96,31 +96,31 @@ TEST_P(NonzeroTextureCreationTests, ArrayLayerClears) {
// Test that nonrenderable texture formats clear to 1's because toggle is enabled // Test that nonrenderable texture formats clear to 1's because toggle is enabled
TEST_P(NonzeroTextureCreationTests, NonrenderableTextureFormat) { TEST_P(NonzeroTextureCreationTests, NonrenderableTextureFormat) {
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kSize; descriptor.size.width = kSize;
descriptor.size.height = kSize; descriptor.size.height = kSize;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1; descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Snorm; descriptor.format = wgpu::TextureFormat::RGBA8Snorm;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::CopySrc; descriptor.usage = wgpu::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
// Set buffer with dirty data so we know it is cleared by the lazy cleared texture copy // Set buffer with dirty data so we know it is cleared by the lazy cleared texture copy
uint32_t bufferSize = 4 * kSize * kSize; uint32_t bufferSize = 4 * kSize * kSize;
std::vector<uint8_t> data(bufferSize, 100); std::vector<uint8_t> data(bufferSize, 100);
dawn::Buffer bufferDst = utils::CreateBufferFromData( wgpu::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc); device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0); wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1}; wgpu::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize); encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
std::vector<uint32_t> expected(bufferSize, 1); std::vector<uint32_t> expected(bufferSize, 1);
@ -134,31 +134,31 @@ TEST_P(NonzeroTextureCreationTests, NonRenderableTextureClearWithMultiArrayLayer
// textures does not create large enough buffers for array layers greater than 1. // textures does not create large enough buffers for array layers greater than 1.
DAWN_SKIP_TEST_IF(IsOpenGL()); DAWN_SKIP_TEST_IF(IsOpenGL());
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kSize; descriptor.size.width = kSize;
descriptor.size.height = kSize; descriptor.size.height = kSize;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayerCount = 2; descriptor.arrayLayerCount = 2;
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Snorm; descriptor.format = wgpu::TextureFormat::RGBA8Snorm;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::CopySrc; descriptor.usage = wgpu::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
// Set buffer with dirty data so we know it is cleared by the lazy cleared texture copy // Set buffer with dirty data so we know it is cleared by the lazy cleared texture copy
uint32_t bufferSize = 4 * kSize * kSize; uint32_t bufferSize = 4 * kSize * kSize;
std::vector<uint8_t> data(bufferSize, 100); std::vector<uint8_t> data(bufferSize, 100);
dawn::Buffer bufferDst = utils::CreateBufferFromData( wgpu::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc); device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0); wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 1, {0, 0, 0}); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 1, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1}; wgpu::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize); encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
std::vector<uint32_t> expectedWithZeros(bufferSize, 1); std::vector<uint32_t> expectedWithZeros(bufferSize, 1);

View File

@ -21,12 +21,12 @@ class ObjectCachingTest : public DawnTest {};
// Test that BindGroupLayouts are correctly deduplicated. // Test that BindGroupLayouts are correctly deduplicated.
TEST_P(ObjectCachingTest, BindGroupLayoutDeduplication) { TEST_P(ObjectCachingTest, BindGroupLayoutDeduplication) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}}); device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}});
dawn::BindGroupLayout sameBgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout sameBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}}); device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Vertex, dawn::BindingType::UniformBuffer}}); device, {{1, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer}});
EXPECT_NE(bgl.Get(), otherBgl.Get()); EXPECT_NE(bgl.Get(), otherBgl.Get());
EXPECT_EQ(bgl.Get() == sameBgl.Get(), !UsesWire()); EXPECT_EQ(bgl.Get() == sameBgl.Get(), !UsesWire());
@ -34,12 +34,12 @@ TEST_P(ObjectCachingTest, BindGroupLayoutDeduplication) {
// Test that two similar bind group layouts won't refer to the same one if they differ by dynamic. // Test that two similar bind group layouts won't refer to the same one if they differ by dynamic.
TEST_P(ObjectCachingTest, BindGroupLayoutDynamic) { TEST_P(ObjectCachingTest, BindGroupLayoutDynamic) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer, true}}); device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer, true}});
dawn::BindGroupLayout sameBgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout sameBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer, true}}); device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer, true}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer, false}}); device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer, false}});
EXPECT_NE(bgl.Get(), otherBgl.Get()); EXPECT_NE(bgl.Get(), otherBgl.Get());
EXPECT_EQ(bgl.Get() == sameBgl.Get(), !UsesWire()); EXPECT_EQ(bgl.Get() == sameBgl.Get(), !UsesWire());
@ -48,15 +48,15 @@ TEST_P(ObjectCachingTest, BindGroupLayoutDynamic) {
// Test that two similar bind group layouts won't refer to the same one if they differ by // Test that two similar bind group layouts won't refer to the same one if they differ by
// textureComponentType // textureComponentType
TEST_P(ObjectCachingTest, BindGroupLayoutTextureComponentType) { TEST_P(ObjectCachingTest, BindGroupLayoutTextureComponentType) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, false, device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, false,
dawn::TextureViewDimension::e2D, dawn::TextureComponentType::Float}}); wgpu::TextureViewDimension::e2D, wgpu::TextureComponentType::Float}});
dawn::BindGroupLayout sameBgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout sameBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, false, device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, false,
dawn::TextureViewDimension::e2D, dawn::TextureComponentType::Float}}); wgpu::TextureViewDimension::e2D, wgpu::TextureComponentType::Float}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, false, device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, false,
dawn::TextureViewDimension::e2D, dawn::TextureComponentType::Uint}}); wgpu::TextureViewDimension::e2D, wgpu::TextureComponentType::Uint}});
EXPECT_NE(bgl.Get(), otherBgl.Get()); EXPECT_NE(bgl.Get(), otherBgl.Get());
EXPECT_EQ(bgl.Get() == sameBgl.Get(), !UsesWire()); EXPECT_EQ(bgl.Get() == sameBgl.Get(), !UsesWire());
@ -65,15 +65,15 @@ TEST_P(ObjectCachingTest, BindGroupLayoutTextureComponentType) {
// Test that two similar bind group layouts won't refer to the same one if they differ by // Test that two similar bind group layouts won't refer to the same one if they differ by
// textureDimension // textureDimension
TEST_P(ObjectCachingTest, BindGroupLayoutTextureDimension) { TEST_P(ObjectCachingTest, BindGroupLayoutTextureDimension) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, false, device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, false,
dawn::TextureViewDimension::e2D, dawn::TextureComponentType::Float}}); wgpu::TextureViewDimension::e2D, wgpu::TextureComponentType::Float}});
dawn::BindGroupLayout sameBgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout sameBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, false, device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, false,
dawn::TextureViewDimension::e2D, dawn::TextureComponentType::Float}}); wgpu::TextureViewDimension::e2D, wgpu::TextureComponentType::Float}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, false, device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, false,
dawn::TextureViewDimension::e2DArray, dawn::TextureComponentType::Float}}); wgpu::TextureViewDimension::e2DArray, wgpu::TextureComponentType::Float}});
EXPECT_NE(bgl.Get(), otherBgl.Get()); EXPECT_NE(bgl.Get(), otherBgl.Get());
EXPECT_EQ(bgl.Get() == sameBgl.Get(), !UsesWire()); EXPECT_EQ(bgl.Get() == sameBgl.Get(), !UsesWire());
@ -82,22 +82,22 @@ TEST_P(ObjectCachingTest, BindGroupLayoutTextureDimension) {
// Test that an error object doesn't try to uncache itself // Test that an error object doesn't try to uncache itself
TEST_P(ObjectCachingTest, ErrorObjectDoesntUncache) { TEST_P(ObjectCachingTest, ErrorObjectDoesntUncache) {
ASSERT_DEVICE_ERROR( ASSERT_DEVICE_ERROR(
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}, device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer},
{0, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}})); {0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}}));
} }
// Test that PipelineLayouts are correctly deduplicated. // Test that PipelineLayouts are correctly deduplicated.
TEST_P(ObjectCachingTest, PipelineLayoutDeduplication) { TEST_P(ObjectCachingTest, PipelineLayoutDeduplication) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}}); device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Vertex, dawn::BindingType::UniformBuffer}}); device, {{1, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer}});
dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::PipelineLayout samePl = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout samePl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::PipelineLayout otherPl1 = utils::MakeBasicPipelineLayout(device, nullptr); wgpu::PipelineLayout otherPl1 = utils::MakeBasicPipelineLayout(device, nullptr);
dawn::PipelineLayout otherPl2 = utils::MakeBasicPipelineLayout(device, &otherBgl); wgpu::PipelineLayout otherPl2 = utils::MakeBasicPipelineLayout(device, &otherBgl);
EXPECT_NE(pl.Get(), otherPl1.Get()); EXPECT_NE(pl.Get(), otherPl1.Get());
EXPECT_NE(pl.Get(), otherPl2.Get()); EXPECT_NE(pl.Get(), otherPl2.Get());
@ -106,21 +106,21 @@ TEST_P(ObjectCachingTest, PipelineLayoutDeduplication) {
// Test that ShaderModules are correctly deduplicated. // Test that ShaderModules are correctly deduplicated.
TEST_P(ObjectCachingTest, ShaderModuleDeduplication) { TEST_P(ObjectCachingTest, ShaderModuleDeduplication) {
dawn::ShaderModule module = wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
void main() { void main() {
fragColor = vec4(0.0, 1.0, 0.0, 1.0); fragColor = vec4(0.0, 1.0, 0.0, 1.0);
})"); })");
dawn::ShaderModule sameModule = wgpu::ShaderModule sameModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
void main() { void main() {
fragColor = vec4(0.0, 1.0, 0.0, 1.0); fragColor = vec4(0.0, 1.0, 0.0, 1.0);
})"); })");
dawn::ShaderModule otherModule = wgpu::ShaderModule otherModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -134,19 +134,19 @@ TEST_P(ObjectCachingTest, ShaderModuleDeduplication) {
// Test that ComputePipeline are correctly deduplicated wrt. their ShaderModule // Test that ComputePipeline are correctly deduplicated wrt. their ShaderModule
TEST_P(ObjectCachingTest, ComputePipelineDeduplicationOnShaderModule) { TEST_P(ObjectCachingTest, ComputePipelineDeduplicationOnShaderModule) {
dawn::ShaderModule module = wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
#version 450 #version 450
void main() { void main() {
int i = 0; int i = 0;
})"); })");
dawn::ShaderModule sameModule = wgpu::ShaderModule sameModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
#version 450 #version 450
void main() { void main() {
int i = 0; int i = 0;
})"); })");
dawn::ShaderModule otherModule = wgpu::ShaderModule otherModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
#version 450 #version 450
void main() { void main() {
@ -155,20 +155,20 @@ TEST_P(ObjectCachingTest, ComputePipelineDeduplicationOnShaderModule) {
EXPECT_NE(module.Get(), otherModule.Get()); EXPECT_NE(module.Get(), otherModule.Get());
EXPECT_EQ(module.Get() == sameModule.Get(), !UsesWire()); EXPECT_EQ(module.Get() == sameModule.Get(), !UsesWire());
dawn::PipelineLayout layout = utils::MakeBasicPipelineLayout(device, nullptr); wgpu::PipelineLayout layout = utils::MakeBasicPipelineLayout(device, nullptr);
dawn::ComputePipelineDescriptor desc; wgpu::ComputePipelineDescriptor desc;
desc.computeStage.entryPoint = "main"; desc.computeStage.entryPoint = "main";
desc.layout = layout; desc.layout = layout;
desc.computeStage.module = module; desc.computeStage.module = module;
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&desc); wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&desc);
desc.computeStage.module = sameModule; desc.computeStage.module = sameModule;
dawn::ComputePipeline samePipeline = device.CreateComputePipeline(&desc); wgpu::ComputePipeline samePipeline = device.CreateComputePipeline(&desc);
desc.computeStage.module = otherModule; desc.computeStage.module = otherModule;
dawn::ComputePipeline otherPipeline = device.CreateComputePipeline(&desc); wgpu::ComputePipeline otherPipeline = device.CreateComputePipeline(&desc);
EXPECT_NE(pipeline.Get(), otherPipeline.Get()); EXPECT_NE(pipeline.Get(), otherPipeline.Get());
EXPECT_EQ(pipeline.Get() == samePipeline.Get(), !UsesWire()); EXPECT_EQ(pipeline.Get() == samePipeline.Get(), !UsesWire());
@ -176,19 +176,19 @@ TEST_P(ObjectCachingTest, ComputePipelineDeduplicationOnShaderModule) {
// Test that ComputePipeline are correctly deduplicated wrt. their layout // Test that ComputePipeline are correctly deduplicated wrt. their layout
TEST_P(ObjectCachingTest, ComputePipelineDeduplicationOnLayout) { TEST_P(ObjectCachingTest, ComputePipelineDeduplicationOnLayout) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}}); device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Vertex, dawn::BindingType::UniformBuffer}}); device, {{1, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer}});
dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::PipelineLayout samePl = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout samePl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::PipelineLayout otherPl = utils::MakeBasicPipelineLayout(device, nullptr); wgpu::PipelineLayout otherPl = utils::MakeBasicPipelineLayout(device, nullptr);
EXPECT_NE(pl.Get(), otherPl.Get()); EXPECT_NE(pl.Get(), otherPl.Get());
EXPECT_EQ(pl.Get() == samePl.Get(), !UsesWire()); EXPECT_EQ(pl.Get() == samePl.Get(), !UsesWire());
dawn::ComputePipelineDescriptor desc; wgpu::ComputePipelineDescriptor desc;
desc.computeStage.entryPoint = "main"; desc.computeStage.entryPoint = "main";
desc.computeStage.module = desc.computeStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
@ -198,13 +198,13 @@ TEST_P(ObjectCachingTest, ComputePipelineDeduplicationOnLayout) {
})"); })");
desc.layout = pl; desc.layout = pl;
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&desc); wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&desc);
desc.layout = samePl; desc.layout = samePl;
dawn::ComputePipeline samePipeline = device.CreateComputePipeline(&desc); wgpu::ComputePipeline samePipeline = device.CreateComputePipeline(&desc);
desc.layout = otherPl; desc.layout = otherPl;
dawn::ComputePipeline otherPipeline = device.CreateComputePipeline(&desc); wgpu::ComputePipeline otherPipeline = device.CreateComputePipeline(&desc);
EXPECT_NE(pipeline.Get(), otherPipeline.Get()); EXPECT_NE(pipeline.Get(), otherPipeline.Get());
EXPECT_EQ(pipeline.Get() == samePipeline.Get(), !UsesWire()); EXPECT_EQ(pipeline.Get() == samePipeline.Get(), !UsesWire());
@ -212,14 +212,14 @@ TEST_P(ObjectCachingTest, ComputePipelineDeduplicationOnLayout) {
// Test that RenderPipelines are correctly deduplicated wrt. their layout // Test that RenderPipelines are correctly deduplicated wrt. their layout
TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnLayout) { TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnLayout) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}}); device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Vertex, dawn::BindingType::UniformBuffer}}); device, {{1, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer}});
dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::PipelineLayout samePl = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout samePl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::PipelineLayout otherPl = utils::MakeBasicPipelineLayout(device, nullptr); wgpu::PipelineLayout otherPl = utils::MakeBasicPipelineLayout(device, nullptr);
EXPECT_NE(pl.Get(), otherPl.Get()); EXPECT_NE(pl.Get(), otherPl.Get());
EXPECT_EQ(pl.Get() == samePl.Get(), !UsesWire()); EXPECT_EQ(pl.Get() == samePl.Get(), !UsesWire());
@ -238,13 +238,13 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnLayout) {
})"); })");
desc.layout = pl; desc.layout = pl;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&desc); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&desc);
desc.layout = samePl; desc.layout = samePl;
dawn::RenderPipeline samePipeline = device.CreateRenderPipeline(&desc); wgpu::RenderPipeline samePipeline = device.CreateRenderPipeline(&desc);
desc.layout = otherPl; desc.layout = otherPl;
dawn::RenderPipeline otherPipeline = device.CreateRenderPipeline(&desc); wgpu::RenderPipeline otherPipeline = device.CreateRenderPipeline(&desc);
EXPECT_NE(pipeline.Get(), otherPipeline.Get()); EXPECT_NE(pipeline.Get(), otherPipeline.Get());
EXPECT_EQ(pipeline.Get() == samePipeline.Get(), !UsesWire()); EXPECT_EQ(pipeline.Get() == samePipeline.Get(), !UsesWire());
@ -252,19 +252,19 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnLayout) {
// Test that RenderPipelines are correctly deduplicated wrt. their vertex module // Test that RenderPipelines are correctly deduplicated wrt. their vertex module
TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnVertexModule) { TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnVertexModule) {
dawn::ShaderModule module = wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
void main() { void main() {
gl_Position = vec4(0.0); gl_Position = vec4(0.0);
})"); })");
dawn::ShaderModule sameModule = wgpu::ShaderModule sameModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
void main() { void main() {
gl_Position = vec4(0.0); gl_Position = vec4(0.0);
})"); })");
dawn::ShaderModule otherModule = wgpu::ShaderModule otherModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
void main() { void main() {
@ -282,13 +282,13 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnVertexModule) {
})"); })");
desc.vertexStage.module = module; desc.vertexStage.module = module;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&desc); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&desc);
desc.vertexStage.module = sameModule; desc.vertexStage.module = sameModule;
dawn::RenderPipeline samePipeline = device.CreateRenderPipeline(&desc); wgpu::RenderPipeline samePipeline = device.CreateRenderPipeline(&desc);
desc.vertexStage.module = otherModule; desc.vertexStage.module = otherModule;
dawn::RenderPipeline otherPipeline = device.CreateRenderPipeline(&desc); wgpu::RenderPipeline otherPipeline = device.CreateRenderPipeline(&desc);
EXPECT_NE(pipeline.Get(), otherPipeline.Get()); EXPECT_NE(pipeline.Get(), otherPipeline.Get());
EXPECT_EQ(pipeline.Get() == samePipeline.Get(), !UsesWire()); EXPECT_EQ(pipeline.Get() == samePipeline.Get(), !UsesWire());
@ -296,17 +296,17 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnVertexModule) {
// Test that RenderPipelines are correctly deduplicated wrt. their fragment module // Test that RenderPipelines are correctly deduplicated wrt. their fragment module
TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnFragmentModule) { TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnFragmentModule) {
dawn::ShaderModule module = wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
void main() { void main() {
})"); })");
dawn::ShaderModule sameModule = wgpu::ShaderModule sameModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
void main() { void main() {
})"); })");
dawn::ShaderModule otherModule = wgpu::ShaderModule otherModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
void main() { void main() {
@ -325,13 +325,13 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnFragmentModule) {
})"); })");
desc.cFragmentStage.module = module; desc.cFragmentStage.module = module;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&desc); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&desc);
desc.cFragmentStage.module = sameModule; desc.cFragmentStage.module = sameModule;
dawn::RenderPipeline samePipeline = device.CreateRenderPipeline(&desc); wgpu::RenderPipeline samePipeline = device.CreateRenderPipeline(&desc);
desc.cFragmentStage.module = otherModule; desc.cFragmentStage.module = otherModule;
dawn::RenderPipeline otherPipeline = device.CreateRenderPipeline(&desc); wgpu::RenderPipeline otherPipeline = device.CreateRenderPipeline(&desc);
EXPECT_NE(pipeline.Get(), otherPipeline.Get()); EXPECT_NE(pipeline.Get(), otherPipeline.Get());
EXPECT_EQ(pipeline.Get() == samePipeline.Get(), !UsesWire()); EXPECT_EQ(pipeline.Get() == samePipeline.Get(), !UsesWire());
@ -339,47 +339,47 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnFragmentModule) {
// Test that Samplers are correctly deduplicated. // Test that Samplers are correctly deduplicated.
TEST_P(ObjectCachingTest, SamplerDeduplication) { TEST_P(ObjectCachingTest, SamplerDeduplication) {
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
dawn::Sampler sampler = device.CreateSampler(&samplerDesc); wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
dawn::SamplerDescriptor sameSamplerDesc = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor sameSamplerDesc = utils::GetDefaultSamplerDescriptor();
dawn::Sampler sameSampler = device.CreateSampler(&sameSamplerDesc); wgpu::Sampler sameSampler = device.CreateSampler(&sameSamplerDesc);
dawn::SamplerDescriptor otherSamplerDescAddressModeU = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor otherSamplerDescAddressModeU = utils::GetDefaultSamplerDescriptor();
otherSamplerDescAddressModeU.addressModeU = dawn::AddressMode::ClampToEdge; otherSamplerDescAddressModeU.addressModeU = wgpu::AddressMode::ClampToEdge;
dawn::Sampler otherSamplerAddressModeU = device.CreateSampler(&otherSamplerDescAddressModeU); wgpu::Sampler otherSamplerAddressModeU = device.CreateSampler(&otherSamplerDescAddressModeU);
dawn::SamplerDescriptor otherSamplerDescAddressModeV = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor otherSamplerDescAddressModeV = utils::GetDefaultSamplerDescriptor();
otherSamplerDescAddressModeV.addressModeV = dawn::AddressMode::ClampToEdge; otherSamplerDescAddressModeV.addressModeV = wgpu::AddressMode::ClampToEdge;
dawn::Sampler otherSamplerAddressModeV = device.CreateSampler(&otherSamplerDescAddressModeV); wgpu::Sampler otherSamplerAddressModeV = device.CreateSampler(&otherSamplerDescAddressModeV);
dawn::SamplerDescriptor otherSamplerDescAddressModeW = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor otherSamplerDescAddressModeW = utils::GetDefaultSamplerDescriptor();
otherSamplerDescAddressModeW.addressModeW = dawn::AddressMode::ClampToEdge; otherSamplerDescAddressModeW.addressModeW = wgpu::AddressMode::ClampToEdge;
dawn::Sampler otherSamplerAddressModeW = device.CreateSampler(&otherSamplerDescAddressModeW); wgpu::Sampler otherSamplerAddressModeW = device.CreateSampler(&otherSamplerDescAddressModeW);
dawn::SamplerDescriptor otherSamplerDescMagFilter = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor otherSamplerDescMagFilter = utils::GetDefaultSamplerDescriptor();
otherSamplerDescMagFilter.magFilter = dawn::FilterMode::Nearest; otherSamplerDescMagFilter.magFilter = wgpu::FilterMode::Nearest;
dawn::Sampler otherSamplerMagFilter = device.CreateSampler(&otherSamplerDescMagFilter); wgpu::Sampler otherSamplerMagFilter = device.CreateSampler(&otherSamplerDescMagFilter);
dawn::SamplerDescriptor otherSamplerDescMinFilter = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor otherSamplerDescMinFilter = utils::GetDefaultSamplerDescriptor();
otherSamplerDescMinFilter.minFilter = dawn::FilterMode::Nearest; otherSamplerDescMinFilter.minFilter = wgpu::FilterMode::Nearest;
dawn::Sampler otherSamplerMinFilter = device.CreateSampler(&otherSamplerDescMinFilter); wgpu::Sampler otherSamplerMinFilter = device.CreateSampler(&otherSamplerDescMinFilter);
dawn::SamplerDescriptor otherSamplerDescMipmapFilter = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor otherSamplerDescMipmapFilter = utils::GetDefaultSamplerDescriptor();
otherSamplerDescMipmapFilter.mipmapFilter = dawn::FilterMode::Nearest; otherSamplerDescMipmapFilter.mipmapFilter = wgpu::FilterMode::Nearest;
dawn::Sampler otherSamplerMipmapFilter = device.CreateSampler(&otherSamplerDescMipmapFilter); wgpu::Sampler otherSamplerMipmapFilter = device.CreateSampler(&otherSamplerDescMipmapFilter);
dawn::SamplerDescriptor otherSamplerDescLodMinClamp = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor otherSamplerDescLodMinClamp = utils::GetDefaultSamplerDescriptor();
otherSamplerDescLodMinClamp.lodMinClamp += 1; otherSamplerDescLodMinClamp.lodMinClamp += 1;
dawn::Sampler otherSamplerLodMinClamp = device.CreateSampler(&otherSamplerDescLodMinClamp); wgpu::Sampler otherSamplerLodMinClamp = device.CreateSampler(&otherSamplerDescLodMinClamp);
dawn::SamplerDescriptor otherSamplerDescLodMaxClamp = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor otherSamplerDescLodMaxClamp = utils::GetDefaultSamplerDescriptor();
otherSamplerDescLodMaxClamp.lodMaxClamp += 1; otherSamplerDescLodMaxClamp.lodMaxClamp += 1;
dawn::Sampler otherSamplerLodMaxClamp = device.CreateSampler(&otherSamplerDescLodMaxClamp); wgpu::Sampler otherSamplerLodMaxClamp = device.CreateSampler(&otherSamplerDescLodMaxClamp);
dawn::SamplerDescriptor otherSamplerDescCompareFunction = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor otherSamplerDescCompareFunction = utils::GetDefaultSamplerDescriptor();
otherSamplerDescCompareFunction.compare = dawn::CompareFunction::Always; otherSamplerDescCompareFunction.compare = wgpu::CompareFunction::Always;
dawn::Sampler otherSamplerCompareFunction = wgpu::Sampler otherSamplerCompareFunction =
device.CreateSampler(&otherSamplerDescCompareFunction); device.CreateSampler(&otherSamplerDescCompareFunction);
EXPECT_NE(sampler.Get(), otherSamplerAddressModeU.Get()); EXPECT_NE(sampler.Get(), otherSamplerAddressModeU.Get());

View File

@ -24,9 +24,9 @@ class OpArrayLengthTest : public DawnTest {
DawnTest::TestSetUp(); DawnTest::TestSetUp();
// Create buffers of various size to check the length() implementation // Create buffers of various size to check the length() implementation
dawn::BufferDescriptor bufferDesc; wgpu::BufferDescriptor bufferDesc;
bufferDesc.size = 4; bufferDesc.size = 4;
bufferDesc.usage = dawn::BufferUsage::Storage; bufferDesc.usage = wgpu::BufferUsage::Storage;
mStorageBuffer4 = device.CreateBuffer(&bufferDesc); mStorageBuffer4 = device.CreateBuffer(&bufferDesc);
bufferDesc.size = 256; bufferDesc.size = 256;
@ -36,17 +36,17 @@ class OpArrayLengthTest : public DawnTest {
mStorageBuffer512 = device.CreateBuffer(&bufferDesc); mStorageBuffer512 = device.CreateBuffer(&bufferDesc);
// Put them all in a bind group for tests to bind them easily. // Put them all in a bind group for tests to bind them easily.
dawn::ShaderStage kAllStages = wgpu::ShaderStage kAllStages =
dawn::ShaderStage::Fragment | dawn::ShaderStage::Vertex | dawn::ShaderStage::Compute; wgpu::ShaderStage::Fragment | wgpu::ShaderStage::Vertex | wgpu::ShaderStage::Compute;
mBindGroupLayout = mBindGroupLayout =
utils::MakeBindGroupLayout(device, {{0, kAllStages, dawn::BindingType::StorageBuffer}, utils::MakeBindGroupLayout(device, {{0, kAllStages, wgpu::BindingType::StorageBuffer},
{1, kAllStages, dawn::BindingType::StorageBuffer}, {1, kAllStages, wgpu::BindingType::StorageBuffer},
{2, kAllStages, dawn::BindingType::StorageBuffer}}); {2, kAllStages, wgpu::BindingType::StorageBuffer}});
mBindGroup = utils::MakeBindGroup(device, mBindGroupLayout, mBindGroup = utils::MakeBindGroup(device, mBindGroupLayout,
{ {
{0, mStorageBuffer4, 0, 4}, {0, mStorageBuffer4, 0, 4},
{1, mStorageBuffer256, 0, dawn::kWholeSize}, {1, mStorageBuffer256, 0, wgpu::kWholeSize},
{2, mStorageBuffer512, 0, 512}, {2, mStorageBuffer512, 0, 512},
}); });
@ -76,12 +76,12 @@ class OpArrayLengthTest : public DawnTest {
mExpectedLengths = {1, 64, 56}; mExpectedLengths = {1, 64, 56};
} }
dawn::Buffer mStorageBuffer4; wgpu::Buffer mStorageBuffer4;
dawn::Buffer mStorageBuffer256; wgpu::Buffer mStorageBuffer256;
dawn::Buffer mStorageBuffer512; wgpu::Buffer mStorageBuffer512;
dawn::BindGroupLayout mBindGroupLayout; wgpu::BindGroupLayout mBindGroupLayout;
dawn::BindGroup mBindGroup; wgpu::BindGroup mBindGroup;
std::string mShaderInterface; std::string mShaderInterface;
std::array<uint32_t, 3> mExpectedLengths; std::array<uint32_t, 3> mExpectedLengths;
}; };
@ -93,25 +93,25 @@ TEST_P(OpArrayLengthTest, Compute) {
DAWN_SKIP_TEST_IF(IsNvidia() && IsOpenGL()); DAWN_SKIP_TEST_IF(IsNvidia() && IsOpenGL());
// Create a buffer to hold the result sizes and create a bindgroup for it. // Create a buffer to hold the result sizes and create a bindgroup for it.
dawn::BufferDescriptor bufferDesc; wgpu::BufferDescriptor bufferDesc;
bufferDesc.usage = dawn::BufferUsage::Storage | dawn::BufferUsage::CopySrc; bufferDesc.usage = wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc;
bufferDesc.size = sizeof(uint32_t) * mExpectedLengths.size(); bufferDesc.size = sizeof(uint32_t) * mExpectedLengths.size();
dawn::Buffer resultBuffer = device.CreateBuffer(&bufferDesc); wgpu::Buffer resultBuffer = device.CreateBuffer(&bufferDesc);
dawn::BindGroupLayout resultLayout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout resultLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}}); device, {{0, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer}});
dawn::BindGroup resultBindGroup = wgpu::BindGroup resultBindGroup =
utils::MakeBindGroup(device, resultLayout, {{0, resultBuffer, 0, dawn::kWholeSize}}); utils::MakeBindGroup(device, resultLayout, {{0, resultBuffer, 0, wgpu::kWholeSize}});
// Create the compute pipeline that stores the length()s in the result buffer. // Create the compute pipeline that stores the length()s in the result buffer.
dawn::BindGroupLayout bgls[] = {mBindGroupLayout, resultLayout}; wgpu::BindGroupLayout bgls[] = {mBindGroupLayout, resultLayout};
dawn::PipelineLayoutDescriptor plDesc; wgpu::PipelineLayoutDescriptor plDesc;
plDesc.bindGroupLayoutCount = 2; plDesc.bindGroupLayoutCount = 2;
plDesc.bindGroupLayouts = bgls; plDesc.bindGroupLayouts = bgls;
dawn::PipelineLayout pl = device.CreatePipelineLayout(&plDesc); wgpu::PipelineLayout pl = device.CreatePipelineLayout(&plDesc);
dawn::ComputePipelineDescriptor pipelineDesc; wgpu::ComputePipelineDescriptor pipelineDesc;
pipelineDesc.layout = pl; pipelineDesc.layout = pl;
pipelineDesc.computeStage.entryPoint = "main"; pipelineDesc.computeStage.entryPoint = "main";
pipelineDesc.computeStage.module = pipelineDesc.computeStage.module =
@ -127,18 +127,18 @@ TEST_P(OpArrayLengthTest, Compute) {
result[2] = buffer3.data.length(); result[2] = buffer3.data.length();
})") })")
.c_str()); .c_str());
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc); wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc);
// Run a single instance of the compute shader // Run a single instance of the compute shader
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder pass = encoder.BeginComputePass(); wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, mBindGroup); pass.SetBindGroup(0, mBindGroup);
pass.SetBindGroup(1, resultBindGroup); pass.SetBindGroup(1, resultBindGroup);
pass.Dispatch(1, 1, 1); pass.Dispatch(1, 1, 1);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_BUFFER_U32_RANGE_EQ(mExpectedLengths.data(), resultBuffer, 0, 3); EXPECT_BUFFER_U32_RANGE_EQ(mExpectedLengths.data(), resultBuffer, 0, 3);
@ -154,7 +154,7 @@ TEST_P(OpArrayLengthTest, Fragment) {
// Create the pipeline that computes the length of the buffers and writes it to the only render // Create the pipeline that computes the length of the buffers and writes it to the only render
// pass pixel. // pass pixel.
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
void main() { void main() {
@ -162,7 +162,7 @@ TEST_P(OpArrayLengthTest, Fragment) {
gl_PointSize = 1.0; gl_PointSize = 1.0;
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment,
(R"( (R"(
#version 450 #version 450
@ -179,22 +179,22 @@ TEST_P(OpArrayLengthTest, Fragment) {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::PointList; descriptor.primitiveTopology = wgpu::PrimitiveTopology::PointList;
descriptor.cColorStates[0].format = renderPass.colorFormat; descriptor.cColorStates[0].format = renderPass.colorFormat;
descriptor.layout = utils::MakeBasicPipelineLayout(device, &mBindGroupLayout); descriptor.layout = utils::MakeBasicPipelineLayout(device, &mBindGroupLayout);
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
// "Draw" the lengths to the texture. // "Draw" the lengths to the texture.
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, mBindGroup); pass.SetBindGroup(0, mBindGroup);
pass.Draw(1, 1, 0, 0); pass.Draw(1, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
RGBA8 expectedColor = RGBA8(mExpectedLengths[0], mExpectedLengths[1], mExpectedLengths[2], 0); RGBA8 expectedColor = RGBA8(mExpectedLengths[0], mExpectedLengths[1], mExpectedLengths[2], 0);
@ -211,7 +211,7 @@ TEST_P(OpArrayLengthTest, Vertex) {
// Create the pipeline that computes the length of the buffers and writes it to the only render // Create the pipeline that computes the length of the buffers and writes it to the only render
// pass pixel. // pass pixel.
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex,
(R"( (R"(
#version 450 #version 450
@ -228,7 +228,7 @@ TEST_P(OpArrayLengthTest, Vertex) {
})") })")
.c_str()); .c_str());
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -240,22 +240,22 @@ TEST_P(OpArrayLengthTest, Vertex) {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::PointList; descriptor.primitiveTopology = wgpu::PrimitiveTopology::PointList;
descriptor.cColorStates[0].format = renderPass.colorFormat; descriptor.cColorStates[0].format = renderPass.colorFormat;
descriptor.layout = utils::MakeBasicPipelineLayout(device, &mBindGroupLayout); descriptor.layout = utils::MakeBasicPipelineLayout(device, &mBindGroupLayout);
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
// "Draw" the lengths to the texture. // "Draw" the lengths to the texture.
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, mBindGroup); pass.SetBindGroup(0, mBindGroup);
pass.Draw(1, 1, 0, 0); pass.Draw(1, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
RGBA8 expectedColor = RGBA8(mExpectedLengths[0], mExpectedLengths[1], mExpectedLengths[2], 0); RGBA8 expectedColor = RGBA8(mExpectedLengths[0], mExpectedLengths[1], mExpectedLengths[2], 0);

View File

@ -166,7 +166,7 @@ class PrimitiveTopologyTest : public DawnTest {
})"); })");
vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices), vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices),
dawn::BufferUsage::Vertex); wgpu::BufferUsage::Vertex);
} }
struct LocationSpec { struct LocationSpec {
@ -181,7 +181,8 @@ class PrimitiveTopologyTest : public DawnTest {
} }
// Draw the vertices with the given primitive topology and check the pixel values of the test locations // Draw the vertices with the given primitive topology and check the pixel values of the test locations
void DoTest(dawn::PrimitiveTopology primitiveTopology, const std::vector<LocationSpec> &locationSpecs) { void DoTest(wgpu::PrimitiveTopology primitiveTopology,
const std::vector<LocationSpec>& locationSpecs) {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
@ -189,22 +190,21 @@ class PrimitiveTopologyTest : public DawnTest {
descriptor.cVertexInput.bufferCount = 1; descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float); descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
descriptor.cVertexInput.cBuffers[0].attributeCount = 1; descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4; descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat; descriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass( wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer); pass.SetVertexBuffer(0, vertexBuffer);
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
for (auto& locationSpec : locationSpecs) { for (auto& locationSpec : locationSpecs) {
@ -218,14 +218,15 @@ class PrimitiveTopologyTest : public DawnTest {
} }
utils::BasicRenderPass renderPass; utils::BasicRenderPass renderPass;
dawn::ShaderModule vsModule; wgpu::ShaderModule vsModule;
dawn::ShaderModule fsModule; wgpu::ShaderModule fsModule;
dawn::Buffer vertexBuffer; wgpu::Buffer vertexBuffer;
}; };
// Test Point primitive topology // Test Point primitive topology
TEST_P(PrimitiveTopologyTest, PointList) { TEST_P(PrimitiveTopologyTest, PointList) {
DoTest(dawn::PrimitiveTopology::PointList, { DoTest(wgpu::PrimitiveTopology::PointList,
{
// Check that the points are drawn // Check that the points are drawn
TestPoints(kPointTestLocations, true), TestPoints(kPointTestLocations, true),
@ -239,7 +240,8 @@ TEST_P(PrimitiveTopologyTest, PointList) {
// Test Line primitive topology // Test Line primitive topology
TEST_P(PrimitiveTopologyTest, LineList) { TEST_P(PrimitiveTopologyTest, LineList) {
DoTest(dawn::PrimitiveTopology::LineList, { DoTest(wgpu::PrimitiveTopology::LineList,
{
// Check that lines are drawn // Check that lines are drawn
TestPoints(kLineTestLocations, true), TestPoints(kLineTestLocations, true),
@ -252,7 +254,7 @@ TEST_P(PrimitiveTopologyTest, LineList) {
// Test LineStrip primitive topology // Test LineStrip primitive topology
TEST_P(PrimitiveTopologyTest, LineStrip) { TEST_P(PrimitiveTopologyTest, LineStrip) {
DoTest(dawn::PrimitiveTopology::LineStrip, { DoTest(wgpu::PrimitiveTopology::LineStrip, {
// Check that lines are drawn // Check that lines are drawn
TestPoints(kLineTestLocations, true), TestPoints(kLineTestLocations, true),
TestPoints(kLineStripTestLocations, true), TestPoints(kLineStripTestLocations, true),
@ -265,7 +267,8 @@ TEST_P(PrimitiveTopologyTest, LineStrip) {
// Test Triangle primitive topology // Test Triangle primitive topology
TEST_P(PrimitiveTopologyTest, TriangleList) { TEST_P(PrimitiveTopologyTest, TriangleList) {
DoTest(dawn::PrimitiveTopology::TriangleList, { DoTest(wgpu::PrimitiveTopology::TriangleList,
{
// Check that triangles are drawn // Check that triangles are drawn
TestPoints(kTriangleTestLocations, true), TestPoints(kTriangleTestLocations, true),
@ -276,7 +279,8 @@ TEST_P(PrimitiveTopologyTest, TriangleList) {
// Test TriangleStrip primitive topology // Test TriangleStrip primitive topology
TEST_P(PrimitiveTopologyTest, TriangleStrip) { TEST_P(PrimitiveTopologyTest, TriangleStrip) {
DoTest(dawn::PrimitiveTopology::TriangleStrip, { DoTest(wgpu::PrimitiveTopology::TriangleStrip,
{
TestPoints(kTriangleTestLocations, true), TestPoints(kTriangleTestLocations, true),
TestPoints(kTriangleStripTestLocations, true), TestPoints(kTriangleStripTestLocations, true),
}); });

View File

@ -31,7 +31,7 @@ class RenderBundleTest : public DawnTest {
renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
layout(location = 0) in vec4 pos; layout(location = 0) in vec4 pos;
@ -39,7 +39,7 @@ class RenderBundleTest : public DawnTest {
gl_Position = pos; gl_Position = pos;
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -50,43 +50,43 @@ class RenderBundleTest : public DawnTest {
fragColor = color; fragColor = color;
})"); })");
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}}); device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}});
float colors0[] = {kColors[0].r / 255.f, kColors[0].g / 255.f, kColors[0].b / 255.f, float colors0[] = {kColors[0].r / 255.f, kColors[0].g / 255.f, kColors[0].b / 255.f,
kColors[0].a / 255.f}; kColors[0].a / 255.f};
float colors1[] = {kColors[1].r / 255.f, kColors[1].g / 255.f, kColors[1].b / 255.f, float colors1[] = {kColors[1].r / 255.f, kColors[1].g / 255.f, kColors[1].b / 255.f,
kColors[1].a / 255.f}; kColors[1].a / 255.f};
dawn::Buffer buffer0 = utils::CreateBufferFromData(device, colors0, 4 * sizeof(float), wgpu::Buffer buffer0 = utils::CreateBufferFromData(device, colors0, 4 * sizeof(float),
dawn::BufferUsage::Uniform); wgpu::BufferUsage::Uniform);
dawn::Buffer buffer1 = utils::CreateBufferFromData(device, colors1, 4 * sizeof(float), wgpu::Buffer buffer1 = utils::CreateBufferFromData(device, colors1, 4 * sizeof(float),
dawn::BufferUsage::Uniform); wgpu::BufferUsage::Uniform);
bindGroups[0] = utils::MakeBindGroup(device, bgl, {{0, buffer0, 0, 4 * sizeof(float)}}); bindGroups[0] = utils::MakeBindGroup(device, bgl, {{0, buffer0, 0, 4 * sizeof(float)}});
bindGroups[1] = utils::MakeBindGroup(device, bgl, {{0, buffer1, 0, 4 * sizeof(float)}}); bindGroups[1] = utils::MakeBindGroup(device, bgl, {{0, buffer1, 0, 4 * sizeof(float)}});
dawn::PipelineLayoutDescriptor pipelineLayoutDesc; wgpu::PipelineLayoutDescriptor pipelineLayoutDesc;
pipelineLayoutDesc.bindGroupLayoutCount = 1; pipelineLayoutDesc.bindGroupLayoutCount = 1;
pipelineLayoutDesc.bindGroupLayouts = &bgl; pipelineLayoutDesc.bindGroupLayouts = &bgl;
dawn::PipelineLayout pipelineLayout = device.CreatePipelineLayout(&pipelineLayoutDesc); wgpu::PipelineLayout pipelineLayout = device.CreatePipelineLayout(&pipelineLayoutDesc);
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.layout = pipelineLayout; descriptor.layout = pipelineLayout;
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cVertexInput.bufferCount = 1; descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float); descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
descriptor.cVertexInput.cBuffers[0].attributeCount = 1; descriptor.cVertexInput.cBuffers[0].attributeCount = 1;
descriptor.cVertexInput.cAttributes[0].format = dawn::VertexFormat::Float4; descriptor.cVertexInput.cAttributes[0].format = wgpu::VertexFormat::Float4;
descriptor.cColorStates[0].format = renderPass.colorFormat; descriptor.cColorStates[0].format = renderPass.colorFormat;
pipeline = device.CreateRenderPipeline(&descriptor); pipeline = device.CreateRenderPipeline(&descriptor);
vertexBuffer = utils::CreateBufferFromData<float>( vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex, device, wgpu::BufferUsage::Vertex,
{// The bottom left triangle {// The bottom left triangle
-1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f,
@ -95,9 +95,9 @@ class RenderBundleTest : public DawnTest {
} }
utils::BasicRenderPass renderPass; utils::BasicRenderPass renderPass;
dawn::RenderPipeline pipeline; wgpu::RenderPipeline pipeline;
dawn::Buffer vertexBuffer; wgpu::Buffer vertexBuffer;
dawn::BindGroup bindGroups[2]; wgpu::BindGroup bindGroups[2];
}; };
// Basic test of RenderBundle. // Basic test of RenderBundle.
@ -106,22 +106,22 @@ TEST_P(RenderBundleTest, Basic) {
desc.colorFormatsCount = 1; desc.colorFormatsCount = 1;
desc.cColorFormats[0] = renderPass.colorFormat; desc.cColorFormats[0] = renderPass.colorFormat;
dawn::RenderBundleEncoder renderBundleEncoder = device.CreateRenderBundleEncoder(&desc); wgpu::RenderBundleEncoder renderBundleEncoder = device.CreateRenderBundleEncoder(&desc);
renderBundleEncoder.SetPipeline(pipeline); renderBundleEncoder.SetPipeline(pipeline);
renderBundleEncoder.SetVertexBuffer(0, vertexBuffer); renderBundleEncoder.SetVertexBuffer(0, vertexBuffer);
renderBundleEncoder.SetBindGroup(0, bindGroups[0]); renderBundleEncoder.SetBindGroup(0, bindGroups[0]);
renderBundleEncoder.Draw(6, 1, 0, 0); renderBundleEncoder.Draw(6, 1, 0, 0);
dawn::RenderBundle renderBundle = renderBundleEncoder.Finish(); wgpu::RenderBundle renderBundle = renderBundleEncoder.Finish();
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.ExecuteBundles(1, &renderBundle); pass.ExecuteBundles(1, &renderBundle);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(kColors[0], renderPass.color, 1, 3); EXPECT_PIXEL_RGBA8_EQ(kColors[0], renderPass.color, 1, 3);
@ -134,9 +134,9 @@ TEST_P(RenderBundleTest, MultipleBundles) {
desc.colorFormatsCount = 1; desc.colorFormatsCount = 1;
desc.cColorFormats[0] = renderPass.colorFormat; desc.cColorFormats[0] = renderPass.colorFormat;
dawn::RenderBundle renderBundles[2]; wgpu::RenderBundle renderBundles[2];
{ {
dawn::RenderBundleEncoder renderBundleEncoder = device.CreateRenderBundleEncoder(&desc); wgpu::RenderBundleEncoder renderBundleEncoder = device.CreateRenderBundleEncoder(&desc);
renderBundleEncoder.SetPipeline(pipeline); renderBundleEncoder.SetPipeline(pipeline);
renderBundleEncoder.SetVertexBuffer(0, vertexBuffer); renderBundleEncoder.SetVertexBuffer(0, vertexBuffer);
@ -146,7 +146,7 @@ TEST_P(RenderBundleTest, MultipleBundles) {
renderBundles[0] = renderBundleEncoder.Finish(); renderBundles[0] = renderBundleEncoder.Finish();
} }
{ {
dawn::RenderBundleEncoder renderBundleEncoder = device.CreateRenderBundleEncoder(&desc); wgpu::RenderBundleEncoder renderBundleEncoder = device.CreateRenderBundleEncoder(&desc);
renderBundleEncoder.SetPipeline(pipeline); renderBundleEncoder.SetPipeline(pipeline);
renderBundleEncoder.SetVertexBuffer(0, vertexBuffer); renderBundleEncoder.SetVertexBuffer(0, vertexBuffer);
@ -156,13 +156,13 @@ TEST_P(RenderBundleTest, MultipleBundles) {
renderBundles[1] = renderBundleEncoder.Finish(); renderBundles[1] = renderBundleEncoder.Finish();
} }
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.ExecuteBundles(2, renderBundles); pass.ExecuteBundles(2, renderBundles);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(kColors[0], renderPass.color, 1, 3); EXPECT_PIXEL_RGBA8_EQ(kColors[0], renderPass.color, 1, 3);
@ -175,18 +175,18 @@ TEST_P(RenderBundleTest, BundleAndRenderPassCommands) {
desc.colorFormatsCount = 1; desc.colorFormatsCount = 1;
desc.cColorFormats[0] = renderPass.colorFormat; desc.cColorFormats[0] = renderPass.colorFormat;
dawn::RenderBundleEncoder renderBundleEncoder = device.CreateRenderBundleEncoder(&desc); wgpu::RenderBundleEncoder renderBundleEncoder = device.CreateRenderBundleEncoder(&desc);
renderBundleEncoder.SetPipeline(pipeline); renderBundleEncoder.SetPipeline(pipeline);
renderBundleEncoder.SetVertexBuffer(0, vertexBuffer); renderBundleEncoder.SetVertexBuffer(0, vertexBuffer);
renderBundleEncoder.SetBindGroup(0, bindGroups[0]); renderBundleEncoder.SetBindGroup(0, bindGroups[0]);
renderBundleEncoder.Draw(3, 1, 0, 0); renderBundleEncoder.Draw(3, 1, 0, 0);
dawn::RenderBundle renderBundle = renderBundleEncoder.Finish(); wgpu::RenderBundle renderBundle = renderBundleEncoder.Finish();
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.ExecuteBundles(1, &renderBundle); pass.ExecuteBundles(1, &renderBundle);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
@ -197,7 +197,7 @@ TEST_P(RenderBundleTest, BundleAndRenderPassCommands) {
pass.ExecuteBundles(1, &renderBundle); pass.ExecuteBundles(1, &renderBundle);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(kColors[0], renderPass.color, 1, 3); EXPECT_PIXEL_RGBA8_EQ(kColors[0], renderPass.color, 1, 3);

View File

@ -24,8 +24,7 @@ constexpr static unsigned int kRTSize = 16;
class DrawQuad { class DrawQuad {
public: public:
DrawQuad() {} DrawQuad() {}
DrawQuad(dawn::Device device, const char* vsSource, const char* fsSource) DrawQuad(wgpu::Device device, const char* vsSource, const char* fsSource) : device(device) {
: device(device) {
vsModule = vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vsSource); utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vsSource);
fsModule = fsModule =
@ -34,8 +33,7 @@ class DrawQuad {
pipelineLayout = utils::MakeBasicPipelineLayout(device, nullptr); pipelineLayout = utils::MakeBasicPipelineLayout(device, nullptr);
} }
void Draw(dawn::RenderPassEncoder* pass) { void Draw(wgpu::RenderPassEncoder* pass) {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.layout = pipelineLayout; descriptor.layout = pipelineLayout;
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
@ -48,10 +46,10 @@ class DrawQuad {
} }
private: private:
dawn::Device device; wgpu::Device device;
dawn::ShaderModule vsModule = {}; wgpu::ShaderModule vsModule = {};
dawn::ShaderModule fsModule = {}; wgpu::ShaderModule fsModule = {};
dawn::PipelineLayout pipelineLayout = {}; wgpu::PipelineLayout pipelineLayout = {};
}; };
class RenderPassLoadOpTests : public DawnTest { class RenderPassLoadOpTests : public DawnTest {
@ -59,16 +57,16 @@ class RenderPassLoadOpTests : public DawnTest {
void TestSetUp() override { void TestSetUp() override {
DawnTest::TestSetUp(); DawnTest::TestSetUp();
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kRTSize; descriptor.size.width = kRTSize;
descriptor.size.height = kRTSize; descriptor.size.height = kRTSize;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1; descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm; descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc; descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
renderTarget = device.CreateTexture(&descriptor); renderTarget = device.CreateTexture(&descriptor);
renderTargetView = renderTarget.CreateView(); renderTargetView = renderTarget.CreateView();
@ -102,8 +100,8 @@ class RenderPassLoadOpTests : public DawnTest {
blueQuad = DrawQuad(device, vsSource, fsSource); blueQuad = DrawQuad(device, vsSource, fsSource);
} }
dawn::Texture renderTarget; wgpu::Texture renderTarget;
dawn::TextureView renderTargetView; wgpu::TextureView renderTargetView;
std::array<RGBA8, kRTSize * kRTSize> expectZero; std::array<RGBA8, kRTSize * kRTSize> expectZero;
std::array<RGBA8, kRTSize * kRTSize> expectGreen; std::array<RGBA8, kRTSize * kRTSize> expectGreen;
@ -136,8 +134,8 @@ TEST_P(RenderPassLoadOpTests, ColorClearThenLoadAndDraw) {
// Part 2: draw a blue quad into the right half of the render target, and check result // Part 2: draw a blue quad into the right half of the render target, and check result
utils::ComboRenderPassDescriptor renderPassLoad({renderTargetView}); utils::ComboRenderPassDescriptor renderPassLoad({renderTargetView});
renderPassLoad.cColorAttachments[0].loadOp = dawn::LoadOp::Load; renderPassLoad.cColorAttachments[0].loadOp = wgpu::LoadOp::Load;
dawn::CommandBuffer commandsLoad; wgpu::CommandBuffer commandsLoad;
{ {
auto encoder = device.CreateCommandEncoder(); auto encoder = device.CreateCommandEncoder();
auto pass = encoder.BeginRenderPass(&renderPassLoad); auto pass = encoder.BeginRenderPass(&renderPassLoad);

View File

@ -18,7 +18,7 @@
#include "utils/WGPUHelpers.h" #include "utils/WGPUHelpers.h"
constexpr uint32_t kRTSize = 16; constexpr uint32_t kRTSize = 16;
constexpr dawn::TextureFormat kFormat = dawn::TextureFormat::RGBA8Unorm; constexpr wgpu::TextureFormat kFormat = wgpu::TextureFormat::RGBA8Unorm;
class RenderPassTest : public DawnTest { class RenderPassTest : public DawnTest {
protected: protected:
@ -34,7 +34,7 @@ protected:
gl_Position = vec4(pos[gl_VertexIndex], 0.f, 1.f); gl_Position = vec4(pos[gl_VertexIndex], 0.f, 1.f);
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -45,15 +45,15 @@ protected:
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = mVSModule; descriptor.vertexStage.module = mVSModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cColorStates[0].format = kFormat; descriptor.cColorStates[0].format = kFormat;
pipeline = device.CreateRenderPipeline(&descriptor); pipeline = device.CreateRenderPipeline(&descriptor);
} }
dawn::Texture CreateDefault2DTexture() { wgpu::Texture CreateDefault2DTexture() {
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kRTSize; descriptor.size.width = kRTSize;
descriptor.size.height = kRTSize; descriptor.size.height = kRTSize;
descriptor.size.depth = 1; descriptor.size.depth = 1;
@ -61,12 +61,12 @@ protected:
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.format = kFormat; descriptor.format = kFormat;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc; descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
return device.CreateTexture(&descriptor); return device.CreateTexture(&descriptor);
} }
dawn::ShaderModule mVSModule; wgpu::ShaderModule mVSModule;
dawn::RenderPipeline pipeline; wgpu::RenderPipeline pipeline;
}; };
// Test using two different render passes in one commandBuffer works correctly. // Test using two different render passes in one commandBuffer works correctly.
@ -81,9 +81,9 @@ TEST_P(RenderPassTest, TwoRenderPassesInOneCommandBuffer) {
constexpr RGBA8 kBlue(0, 0, 255, 255); constexpr RGBA8 kBlue(0, 0, 255, 255);
dawn::Texture renderTarget1 = CreateDefault2DTexture(); wgpu::Texture renderTarget1 = CreateDefault2DTexture();
dawn::Texture renderTarget2 = CreateDefault2DTexture(); wgpu::Texture renderTarget2 = CreateDefault2DTexture();
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
// In the first render pass we clear renderTarget1 to red and draw a blue triangle in the // In the first render pass we clear renderTarget1 to red and draw a blue triangle in the
@ -91,7 +91,7 @@ TEST_P(RenderPassTest, TwoRenderPassesInOneCommandBuffer) {
utils::ComboRenderPassDescriptor renderPass({renderTarget1.CreateView()}); utils::ComboRenderPassDescriptor renderPass({renderTarget1.CreateView()});
renderPass.cColorAttachments[0].clearColor = {1.0f, 0.0f, 0.0f, 1.0f}; renderPass.cColorAttachments[0].clearColor = {1.0f, 0.0f, 0.0f, 1.0f};
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.Draw(3, 1, 0, 0); pass.Draw(3, 1, 0, 0);
pass.EndPass(); pass.EndPass();
@ -103,13 +103,13 @@ TEST_P(RenderPassTest, TwoRenderPassesInOneCommandBuffer) {
utils::ComboRenderPassDescriptor renderPass({renderTarget2.CreateView()}); utils::ComboRenderPassDescriptor renderPass({renderTarget2.CreateView()});
renderPass.cColorAttachments[0].clearColor = {0.0f, 1.0f, 0.0f, 1.0f}; renderPass.cColorAttachments[0].clearColor = {0.0f, 1.0f, 0.0f, 1.0f};
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.Draw(3, 1, 0, 0); pass.Draw(3, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(kBlue, renderTarget1, 1, kRTSize - 1); EXPECT_PIXEL_RGBA8_EQ(kBlue, renderTarget1, 1, kRTSize - 1);
@ -123,16 +123,16 @@ TEST_P(RenderPassTest, TwoRenderPassesInOneCommandBuffer) {
// fragment shader outputs in the render pipeline, the load operation is LoadOp::Load and the store // fragment shader outputs in the render pipeline, the load operation is LoadOp::Load and the store
// operation is StoreOp::Store. // operation is StoreOp::Store.
TEST_P(RenderPassTest, NoCorrespondingFragmentShaderOutputs) { TEST_P(RenderPassTest, NoCorrespondingFragmentShaderOutputs) {
dawn::Texture renderTarget = CreateDefault2DTexture(); wgpu::Texture renderTarget = CreateDefault2DTexture();
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::TextureView renderTargetView = renderTarget.CreateView(); wgpu::TextureView renderTargetView = renderTarget.CreateView();
utils::ComboRenderPassDescriptor renderPass({renderTargetView}); utils::ComboRenderPassDescriptor renderPass({renderTargetView});
renderPass.cColorAttachments[0].clearColor = {1.0f, 0.0f, 0.0f, 1.0f}; renderPass.cColorAttachments[0].clearColor = {1.0f, 0.0f, 0.0f, 1.0f};
renderPass.cColorAttachments[0].loadOp = dawn::LoadOp::Clear; renderPass.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
renderPass.cColorAttachments[0].storeOp = dawn::StoreOp::Store; renderPass.cColorAttachments[0].storeOp = wgpu::StoreOp::Store;
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
{ {
// First we draw a blue triangle in the bottom left of renderTarget. // First we draw a blue triangle in the bottom left of renderTarget.
@ -142,7 +142,7 @@ TEST_P(RenderPassTest, NoCorrespondingFragmentShaderOutputs) {
{ {
// Next we use a pipeline whose fragment shader has no outputs. // Next we use a pipeline whose fragment shader has no outputs.
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
void main() { void main() {
@ -150,10 +150,10 @@ TEST_P(RenderPassTest, NoCorrespondingFragmentShaderOutputs) {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = mVSModule; descriptor.vertexStage.module = mVSModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cColorStates[0].format = kFormat; descriptor.cColorStates[0].format = kFormat;
dawn::RenderPipeline pipelineWithNoFragmentOutput = wgpu::RenderPipeline pipelineWithNoFragmentOutput =
device.CreateRenderPipeline(&descriptor); device.CreateRenderPipeline(&descriptor);
pass.SetPipeline(pipelineWithNoFragmentOutput); pass.SetPipeline(pipelineWithNoFragmentOutput);
@ -162,7 +162,7 @@ TEST_P(RenderPassTest, NoCorrespondingFragmentShaderOutputs) {
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
constexpr RGBA8 kRed(255, 0, 0, 255); constexpr RGBA8 kRed(255, 0, 0, 255);

View File

@ -25,14 +25,26 @@ constexpr static unsigned int kRTSize = 64;
namespace { namespace {
struct AddressModeTestCase { struct AddressModeTestCase {
dawn::AddressMode mMode; wgpu::AddressMode mMode;
uint8_t mExpected2; uint8_t mExpected2;
uint8_t mExpected3; uint8_t mExpected3;
}; };
AddressModeTestCase addressModes[] = { AddressModeTestCase addressModes[] = {
{ dawn::AddressMode::Repeat, 0, 255, }, {
{ dawn::AddressMode::MirrorRepeat, 255, 0, }, wgpu::AddressMode::Repeat,
{ dawn::AddressMode::ClampToEdge, 255, 255, }, 0,
255,
},
{
wgpu::AddressMode::MirrorRepeat,
255,
0,
},
{
wgpu::AddressMode::ClampToEdge,
255,
255,
},
}; };
} }
@ -44,8 +56,8 @@ protected:
mBindGroupLayout = utils::MakeBindGroupLayout( mBindGroupLayout = utils::MakeBindGroupLayout(
device, { device, {
{0, dawn::ShaderStage::Fragment, dawn::BindingType::Sampler}, {0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture}, {1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture},
}); });
auto pipelineLayout = utils::MakeBasicPipelineLayout(device, &mBindGroupLayout); auto pipelineLayout = utils::MakeBasicPipelineLayout(device, &mBindGroupLayout);
@ -81,17 +93,17 @@ protected:
mPipeline = device.CreateRenderPipeline(&pipelineDescriptor); mPipeline = device.CreateRenderPipeline(&pipelineDescriptor);
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = 2; descriptor.size.width = 2;
descriptor.size.height = 2; descriptor.size.height = 2;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1; descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm; descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::CopyDst | dawn::TextureUsage::Sampled; descriptor.usage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled;
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
// Create a 2x2 checkerboard texture, with black in the top left and bottom right corners. // Create a 2x2 checkerboard texture, with black in the top left and bottom right corners.
const uint32_t rowPixels = kTextureRowPitchAlignment / sizeof(RGBA8); const uint32_t rowPixels = kTextureRowPitchAlignment / sizeof(RGBA8);
@ -101,53 +113,51 @@ protected:
data[0] = data[rowPixels + 1] = black; data[0] = data[rowPixels + 1] = black;
data[1] = data[rowPixels] = white; data[1] = data[rowPixels] = white;
dawn::Buffer stagingBuffer = wgpu::Buffer stagingBuffer =
utils::CreateBufferFromData(device, data, sizeof(data), dawn::BufferUsage::CopySrc); utils::CreateBufferFromData(device, data, sizeof(data), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 256, 0); wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 256, 0);
dawn::TextureCopyView textureCopyView = wgpu::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}); utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {2, 2, 1}; wgpu::Extent3D copySize = {2, 2, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize); encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
dawn::CommandBuffer copy = encoder.Finish(); wgpu::CommandBuffer copy = encoder.Finish();
queue.Submit(1, &copy); queue.Submit(1, &copy);
mTextureView = texture.CreateView(); mTextureView = texture.CreateView();
} }
void TestAddressModes(AddressModeTestCase u, AddressModeTestCase v, AddressModeTestCase w) { void TestAddressModes(AddressModeTestCase u, AddressModeTestCase v, AddressModeTestCase w) {
dawn::Sampler sampler; wgpu::Sampler sampler;
{ {
dawn::SamplerDescriptor descriptor; wgpu::SamplerDescriptor descriptor;
descriptor.minFilter = dawn::FilterMode::Nearest; descriptor.minFilter = wgpu::FilterMode::Nearest;
descriptor.magFilter = dawn::FilterMode::Nearest; descriptor.magFilter = wgpu::FilterMode::Nearest;
descriptor.mipmapFilter = dawn::FilterMode::Nearest; descriptor.mipmapFilter = wgpu::FilterMode::Nearest;
descriptor.addressModeU = u.mMode; descriptor.addressModeU = u.mMode;
descriptor.addressModeV = v.mMode; descriptor.addressModeV = v.mMode;
descriptor.addressModeW = w.mMode; descriptor.addressModeW = w.mMode;
descriptor.lodMinClamp = kLodMin; descriptor.lodMinClamp = kLodMin;
descriptor.lodMaxClamp = kLodMax; descriptor.lodMaxClamp = kLodMax;
descriptor.compare = dawn::CompareFunction::Never; descriptor.compare = wgpu::CompareFunction::Never;
sampler = device.CreateSampler(&descriptor); sampler = device.CreateSampler(&descriptor);
} }
dawn::BindGroup bindGroup = utils::MakeBindGroup(device, mBindGroupLayout, { wgpu::BindGroup bindGroup =
{0, sampler}, utils::MakeBindGroup(device, mBindGroupLayout, {{0, sampler}, {1, mTextureView}});
{1, mTextureView}
});
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&mRenderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&mRenderPass.renderPassInfo);
pass.SetPipeline(mPipeline); pass.SetPipeline(mPipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
RGBA8 expectedU2(u.mExpected2, u.mExpected2, u.mExpected2, 255); RGBA8 expectedU2(u.mExpected2, u.mExpected2, u.mExpected2, 255);
@ -168,9 +178,9 @@ protected:
} }
utils::BasicRenderPass mRenderPass; utils::BasicRenderPass mRenderPass;
dawn::BindGroupLayout mBindGroupLayout; wgpu::BindGroupLayout mBindGroupLayout;
dawn::RenderPipeline mPipeline; wgpu::RenderPipeline mPipeline;
dawn::TextureView mTextureView; wgpu::TextureView mTextureView;
}; };
// Test drawing a rect with a checkerboard texture with different address modes. // Test drawing a rect with a checkerboard texture with different address modes.

View File

@ -19,8 +19,8 @@
class ScissorTest: public DawnTest { class ScissorTest: public DawnTest {
protected: protected:
dawn::RenderPipeline CreateQuadPipeline(dawn::TextureFormat format) { wgpu::RenderPipeline CreateQuadPipeline(wgpu::TextureFormat format) {
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
const vec2 pos[6] = vec2[6]( const vec2 pos[6] = vec2[6](
@ -31,7 +31,7 @@ class ScissorTest: public DawnTest {
gl_Position = vec4(pos[gl_VertexIndex], 0.5, 1.0); gl_Position = vec4(pos[gl_VertexIndex], 0.5, 1.0);
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -51,17 +51,17 @@ class ScissorTest: public DawnTest {
// Test that by default the scissor test is disabled and the whole attachment can be drawn to. // Test that by default the scissor test is disabled and the whole attachment can be drawn to.
TEST_P(ScissorTest, DefaultsToWholeRenderTarget) { TEST_P(ScissorTest, DefaultsToWholeRenderTarget) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100);
dawn::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat); wgpu::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0); EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
@ -73,18 +73,18 @@ TEST_P(ScissorTest, DefaultsToWholeRenderTarget) {
// Test setting the scissor to something larger than the attachments. // Test setting the scissor to something larger than the attachments.
TEST_P(ScissorTest, LargerThanAttachment) { TEST_P(ScissorTest, LargerThanAttachment) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100);
dawn::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat); wgpu::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetScissorRect(0, 0, 200, 200); pass.SetScissorRect(0, 0, 200, 200);
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0); EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
@ -96,23 +96,23 @@ TEST_P(ScissorTest, LargerThanAttachment) {
// Test setting a partial scissor (not empty, not full attachment) // Test setting a partial scissor (not empty, not full attachment)
TEST_P(ScissorTest, PartialRect) { TEST_P(ScissorTest, PartialRect) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100);
dawn::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat); wgpu::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat);
constexpr uint32_t kX = 3; constexpr uint32_t kX = 3;
constexpr uint32_t kY = 7; constexpr uint32_t kY = 7;
constexpr uint32_t kW = 5; constexpr uint32_t kW = 5;
constexpr uint32_t kH = 13; constexpr uint32_t kH = 13;
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetScissorRect(kX, kY, kW, kH); pass.SetScissorRect(kX, kY, kW, kH);
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
// Test the two opposite corners of the scissor box. With one pixel inside and on outside // Test the two opposite corners of the scissor box. With one pixel inside and on outside
@ -126,24 +126,24 @@ TEST_P(ScissorTest, PartialRect) {
// Test that the scissor setting doesn't get inherited between renderpasses // Test that the scissor setting doesn't get inherited between renderpasses
TEST_P(ScissorTest, NoInheritanceBetweenRenderPass) { TEST_P(ScissorTest, NoInheritanceBetweenRenderPass) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 100, 100);
dawn::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat); wgpu::RenderPipeline pipeline = CreateQuadPipeline(renderPass.colorFormat);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
// RenderPass 1 set the scissor // RenderPass 1 set the scissor
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetScissorRect(1, 1, 1, 1); pass.SetScissorRect(1, 1, 1, 1);
pass.EndPass(); pass.EndPass();
} }
// RenderPass 2 draw a full quad, it shouldn't be scissored // RenderPass 2 draw a full quad, it shouldn't be scissored
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0); EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);

View File

@ -117,45 +117,45 @@ class TextureFormatTest : public DawnTest {
// Structure containing all the information that tests need to know about the format. // Structure containing all the information that tests need to know about the format.
struct FormatTestInfo { struct FormatTestInfo {
dawn::TextureFormat format; wgpu::TextureFormat format;
uint32_t texelByteSize; uint32_t texelByteSize;
dawn::TextureComponentType type; wgpu::TextureComponentType type;
uint32_t componentCount; uint32_t componentCount;
}; };
// Returns a reprensentation of a format that can be used to contain the "uncompressed" values // Returns a reprensentation of a format that can be used to contain the "uncompressed" values
// of the format. That the equivalent format with all channels 32bit-sized. // of the format. That the equivalent format with all channels 32bit-sized.
FormatTestInfo GetUncompressedFormatInfo(FormatTestInfo formatInfo) { FormatTestInfo GetUncompressedFormatInfo(FormatTestInfo formatInfo) {
std::array<dawn::TextureFormat, 4> floatFormats = { std::array<wgpu::TextureFormat, 4> floatFormats = {
dawn::TextureFormat::R32Float, wgpu::TextureFormat::R32Float,
dawn::TextureFormat::RG32Float, wgpu::TextureFormat::RG32Float,
dawn::TextureFormat::RGBA32Float, wgpu::TextureFormat::RGBA32Float,
dawn::TextureFormat::RGBA32Float, wgpu::TextureFormat::RGBA32Float,
}; };
std::array<dawn::TextureFormat, 4> sintFormats = { std::array<wgpu::TextureFormat, 4> sintFormats = {
dawn::TextureFormat::R32Sint, wgpu::TextureFormat::R32Sint,
dawn::TextureFormat::RG32Sint, wgpu::TextureFormat::RG32Sint,
dawn::TextureFormat::RGBA32Sint, wgpu::TextureFormat::RGBA32Sint,
dawn::TextureFormat::RGBA32Sint, wgpu::TextureFormat::RGBA32Sint,
}; };
std::array<dawn::TextureFormat, 4> uintFormats = { std::array<wgpu::TextureFormat, 4> uintFormats = {
dawn::TextureFormat::R32Uint, wgpu::TextureFormat::R32Uint,
dawn::TextureFormat::RG32Uint, wgpu::TextureFormat::RG32Uint,
dawn::TextureFormat::RGBA32Uint, wgpu::TextureFormat::RGBA32Uint,
dawn::TextureFormat::RGBA32Uint, wgpu::TextureFormat::RGBA32Uint,
}; };
std::array<uint32_t, 4> componentCounts = {1, 2, 4, 4}; std::array<uint32_t, 4> componentCounts = {1, 2, 4, 4};
ASSERT(formatInfo.componentCount > 0 && formatInfo.componentCount <= 4); ASSERT(formatInfo.componentCount > 0 && formatInfo.componentCount <= 4);
dawn::TextureFormat format; wgpu::TextureFormat format;
switch (formatInfo.type) { switch (formatInfo.type) {
case dawn::TextureComponentType::Float: case wgpu::TextureComponentType::Float:
format = floatFormats[formatInfo.componentCount - 1]; format = floatFormats[formatInfo.componentCount - 1];
break; break;
case dawn::TextureComponentType::Sint: case wgpu::TextureComponentType::Sint:
format = sintFormats[formatInfo.componentCount - 1]; format = sintFormats[formatInfo.componentCount - 1];
break; break;
case dawn::TextureComponentType::Uint: case wgpu::TextureComponentType::Uint:
format = uintFormats[formatInfo.componentCount - 1]; format = uintFormats[formatInfo.componentCount - 1];
break; break;
default: default:
@ -168,12 +168,12 @@ class TextureFormatTest : public DawnTest {
// Return a pipeline that can be used in a full-texture draw to sample from the texture in the // Return a pipeline that can be used in a full-texture draw to sample from the texture in the
// bindgroup and output its decompressed values to the render target. // bindgroup and output its decompressed values to the render target.
dawn::RenderPipeline CreateSamplePipeline(FormatTestInfo sampleFormatInfo, wgpu::RenderPipeline CreateSamplePipeline(FormatTestInfo sampleFormatInfo,
FormatTestInfo renderFormatInfo, FormatTestInfo renderFormatInfo,
dawn::BindGroupLayout bgl) { wgpu::BindGroupLayout bgl) {
utils::ComboRenderPipelineDescriptor desc(device); utils::ComboRenderPipelineDescriptor desc(device);
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
void main() { void main() {
@ -188,13 +188,13 @@ class TextureFormatTest : public DawnTest {
// Compute the prefix needed for GLSL types that handle our texture's data. // Compute the prefix needed for GLSL types that handle our texture's data.
const char* prefix = nullptr; const char* prefix = nullptr;
switch (sampleFormatInfo.type) { switch (sampleFormatInfo.type) {
case dawn::TextureComponentType::Float: case wgpu::TextureComponentType::Float:
prefix = ""; prefix = "";
break; break;
case dawn::TextureComponentType::Sint: case wgpu::TextureComponentType::Sint:
prefix = "i"; prefix = "i";
break; break;
case dawn::TextureComponentType::Uint: case wgpu::TextureComponentType::Uint:
prefix = "u"; prefix = "u";
break; break;
default: default:
@ -213,7 +213,7 @@ class TextureFormatTest : public DawnTest {
<< "sampler2D(myTexture, mySampler), ivec2(gl_FragCoord), 0);\n"; << "sampler2D(myTexture, mySampler), ivec2(gl_FragCoord), 0);\n";
fsSource << "}"; fsSource << "}";
dawn::ShaderModule fsModule = utils::CreateShaderModule( wgpu::ShaderModule fsModule = utils::CreateShaderModule(
device, utils::SingleShaderStage::Fragment, fsSource.str().c_str()); device, utils::SingleShaderStage::Fragment, fsSource.str().c_str());
desc.vertexStage.module = vsModule; desc.vertexStage.module = vsModule;
@ -244,74 +244,74 @@ class TextureFormatTest : public DawnTest {
ASSERT(expectedRenderDataSize % 4 == 0); ASSERT(expectedRenderDataSize % 4 == 0);
// Create the texture we will sample from // Create the texture we will sample from
dawn::TextureDescriptor sampleTextureDesc; wgpu::TextureDescriptor sampleTextureDesc;
sampleTextureDesc.usage = dawn::TextureUsage::CopyDst | dawn::TextureUsage::Sampled; sampleTextureDesc.usage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled;
sampleTextureDesc.size = {width, 1, 1}; sampleTextureDesc.size = {width, 1, 1};
sampleTextureDesc.format = sampleFormatInfo.format; sampleTextureDesc.format = sampleFormatInfo.format;
dawn::Texture sampleTexture = device.CreateTexture(&sampleTextureDesc); wgpu::Texture sampleTexture = device.CreateTexture(&sampleTextureDesc);
dawn::Buffer uploadBuffer = utils::CreateBufferFromData(device, sampleData, sampleDataSize, wgpu::Buffer uploadBuffer = utils::CreateBufferFromData(device, sampleData, sampleDataSize,
dawn::BufferUsage::CopySrc); wgpu::BufferUsage::CopySrc);
// Create the texture that we will render results to // Create the texture that we will render results to
ASSERT(expectedRenderDataSize == width * renderFormatInfo.texelByteSize); ASSERT(expectedRenderDataSize == width * renderFormatInfo.texelByteSize);
dawn::TextureDescriptor renderTargetDesc; wgpu::TextureDescriptor renderTargetDesc;
renderTargetDesc.usage = dawn::TextureUsage::CopySrc | dawn::TextureUsage::OutputAttachment; renderTargetDesc.usage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::OutputAttachment;
renderTargetDesc.size = {width, 1, 1}; renderTargetDesc.size = {width, 1, 1};
renderTargetDesc.format = renderFormatInfo.format; renderTargetDesc.format = renderFormatInfo.format;
dawn::Texture renderTarget = device.CreateTexture(&renderTargetDesc); wgpu::Texture renderTarget = device.CreateTexture(&renderTargetDesc);
// Create the readback buffer for the data in renderTarget // Create the readback buffer for the data in renderTarget
dawn::BufferDescriptor readbackBufferDesc; wgpu::BufferDescriptor readbackBufferDesc;
readbackBufferDesc.usage = dawn::BufferUsage::CopyDst | dawn::BufferUsage::CopySrc; readbackBufferDesc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::CopySrc;
readbackBufferDesc.size = 4 * width * sampleFormatInfo.componentCount; readbackBufferDesc.size = 4 * width * sampleFormatInfo.componentCount;
dawn::Buffer readbackBuffer = device.CreateBuffer(&readbackBufferDesc); wgpu::Buffer readbackBuffer = device.CreateBuffer(&readbackBufferDesc);
// Create the bind group layout for sampling the texture // Create the bind group layout for sampling the texture
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::Sampler}, device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, {1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false,
false, dawn::TextureViewDimension::e2D, sampleFormatInfo.type}}); false, wgpu::TextureViewDimension::e2D, sampleFormatInfo.type}});
// Prepare objects needed to sample from texture in the renderpass // Prepare objects needed to sample from texture in the renderpass
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
CreateSamplePipeline(sampleFormatInfo, renderFormatInfo, bgl); CreateSamplePipeline(sampleFormatInfo, renderFormatInfo, bgl);
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
dawn::Sampler sampler = device.CreateSampler(&samplerDesc); wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
dawn::BindGroup bindGroup = wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, bgl, {{0, sampler}, {1, sampleTexture.CreateView()}}); utils::MakeBindGroup(device, bgl, {{0, sampler}, {1, sampleTexture.CreateView()}});
// Encode commands for the test that fill texture, sample it to render to renderTarget then // Encode commands for the test that fill texture, sample it to render to renderTarget then
// copy renderTarget in a buffer so we can read it easily. // copy renderTarget in a buffer so we can read it easily.
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::BufferCopyView bufferView = utils::CreateBufferCopyView(uploadBuffer, 0, 256, 0); wgpu::BufferCopyView bufferView = utils::CreateBufferCopyView(uploadBuffer, 0, 256, 0);
dawn::TextureCopyView textureView = wgpu::TextureCopyView textureView =
utils::CreateTextureCopyView(sampleTexture, 0, 0, {0, 0, 0}); utils::CreateTextureCopyView(sampleTexture, 0, 0, {0, 0, 0});
dawn::Extent3D extent{width, 1, 1}; wgpu::Extent3D extent{width, 1, 1};
encoder.CopyBufferToTexture(&bufferView, &textureView, &extent); encoder.CopyBufferToTexture(&bufferView, &textureView, &extent);
} }
utils::ComboRenderPassDescriptor renderPassDesc({renderTarget.CreateView()}); utils::ComboRenderPassDescriptor renderPassDesc({renderTarget.CreateView()});
dawn::RenderPassEncoder renderPass = encoder.BeginRenderPass(&renderPassDesc); wgpu::RenderPassEncoder renderPass = encoder.BeginRenderPass(&renderPassDesc);
renderPass.SetPipeline(pipeline); renderPass.SetPipeline(pipeline);
renderPass.SetBindGroup(0, bindGroup); renderPass.SetBindGroup(0, bindGroup);
renderPass.Draw(3, 1, 0, 0); renderPass.Draw(3, 1, 0, 0);
renderPass.EndPass(); renderPass.EndPass();
{ {
dawn::BufferCopyView bufferView = wgpu::BufferCopyView bufferView =
utils::CreateBufferCopyView(readbackBuffer, 0, 256, 0); utils::CreateBufferCopyView(readbackBuffer, 0, 256, 0);
dawn::TextureCopyView textureView = wgpu::TextureCopyView textureView =
utils::CreateTextureCopyView(renderTarget, 0, 0, {0, 0, 0}); utils::CreateTextureCopyView(renderTarget, 0, 0, {0, 0, 0});
dawn::Extent3D extent{width, 1, 1}; wgpu::Extent3D extent{width, 1, 1};
encoder.CopyTextureToBuffer(&textureView, &bufferView, &extent); encoder.CopyTextureToBuffer(&textureView, &bufferView, &extent);
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
// For floats use a special expectation that understands how to compare NaNs and support a // For floats use a special expectation that understands how to compare NaNs and support a
@ -367,7 +367,7 @@ class TextureFormatTest : public DawnTest {
void DoUnormTest(FormatTestInfo formatInfo) { void DoUnormTest(FormatTestInfo formatInfo) {
static_assert(!std::is_signed<T>::value && std::is_integral<T>::value, ""); static_assert(!std::is_signed<T>::value && std::is_integral<T>::value, "");
ASSERT(sizeof(T) * formatInfo.componentCount == formatInfo.texelByteSize); ASSERT(sizeof(T) * formatInfo.componentCount == formatInfo.texelByteSize);
ASSERT(formatInfo.type == dawn::TextureComponentType::Float); ASSERT(formatInfo.type == wgpu::TextureComponentType::Float);
T maxValue = std::numeric_limits<T>::max(); T maxValue = std::numeric_limits<T>::max();
std::vector<T> textureData = {0, 1, maxValue, maxValue}; std::vector<T> textureData = {0, 1, maxValue, maxValue};
@ -381,7 +381,7 @@ class TextureFormatTest : public DawnTest {
void DoSnormTest(FormatTestInfo formatInfo) { void DoSnormTest(FormatTestInfo formatInfo) {
static_assert(std::is_signed<T>::value && std::is_integral<T>::value, ""); static_assert(std::is_signed<T>::value && std::is_integral<T>::value, "");
ASSERT(sizeof(T) * formatInfo.componentCount == formatInfo.texelByteSize); ASSERT(sizeof(T) * formatInfo.componentCount == formatInfo.texelByteSize);
ASSERT(formatInfo.type == dawn::TextureComponentType::Float); ASSERT(formatInfo.type == wgpu::TextureComponentType::Float);
T maxValue = std::numeric_limits<T>::max(); T maxValue = std::numeric_limits<T>::max();
T minValue = std::numeric_limits<T>::min(); T minValue = std::numeric_limits<T>::min();
@ -396,7 +396,7 @@ class TextureFormatTest : public DawnTest {
void DoUintTest(FormatTestInfo formatInfo) { void DoUintTest(FormatTestInfo formatInfo) {
static_assert(!std::is_signed<T>::value && std::is_integral<T>::value, ""); static_assert(!std::is_signed<T>::value && std::is_integral<T>::value, "");
ASSERT(sizeof(T) * formatInfo.componentCount == formatInfo.texelByteSize); ASSERT(sizeof(T) * formatInfo.componentCount == formatInfo.texelByteSize);
ASSERT(formatInfo.type == dawn::TextureComponentType::Uint); ASSERT(formatInfo.type == wgpu::TextureComponentType::Uint);
T maxValue = std::numeric_limits<T>::max(); T maxValue = std::numeric_limits<T>::max();
std::vector<T> textureData = {0, 1, maxValue, maxValue}; std::vector<T> textureData = {0, 1, maxValue, maxValue};
@ -410,7 +410,7 @@ class TextureFormatTest : public DawnTest {
void DoSintTest(FormatTestInfo formatInfo) { void DoSintTest(FormatTestInfo formatInfo) {
static_assert(std::is_signed<T>::value && std::is_integral<T>::value, ""); static_assert(std::is_signed<T>::value && std::is_integral<T>::value, "");
ASSERT(sizeof(T) * formatInfo.componentCount == formatInfo.texelByteSize); ASSERT(sizeof(T) * formatInfo.componentCount == formatInfo.texelByteSize);
ASSERT(formatInfo.type == dawn::TextureComponentType::Sint); ASSERT(formatInfo.type == wgpu::TextureComponentType::Sint);
T maxValue = std::numeric_limits<T>::max(); T maxValue = std::numeric_limits<T>::max();
T minValue = std::numeric_limits<T>::min(); T minValue = std::numeric_limits<T>::min();
@ -423,7 +423,7 @@ class TextureFormatTest : public DawnTest {
void DoFloat32Test(FormatTestInfo formatInfo) { void DoFloat32Test(FormatTestInfo formatInfo) {
ASSERT(sizeof(float) * formatInfo.componentCount == formatInfo.texelByteSize); ASSERT(sizeof(float) * formatInfo.componentCount == formatInfo.texelByteSize);
ASSERT(formatInfo.type == dawn::TextureComponentType::Float); ASSERT(formatInfo.type == wgpu::TextureComponentType::Float);
std::vector<float> textureData = {+0.0f, -0.0f, 1.0f, 1.0e-29f, std::vector<float> textureData = {+0.0f, -0.0f, 1.0f, 1.0e-29f,
1.0e29f, NAN, INFINITY, -INFINITY}; 1.0e29f, NAN, INFINITY, -INFINITY};
@ -435,7 +435,7 @@ class TextureFormatTest : public DawnTest {
void DoFloat16Test(FormatTestInfo formatInfo) { void DoFloat16Test(FormatTestInfo formatInfo) {
ASSERT(sizeof(int16_t) * formatInfo.componentCount == formatInfo.texelByteSize); ASSERT(sizeof(int16_t) * formatInfo.componentCount == formatInfo.texelByteSize);
ASSERT(formatInfo.type == dawn::TextureComponentType::Float); ASSERT(formatInfo.type == wgpu::TextureComponentType::Float);
std::vector<float> uncompressedData = {+0.0f, -0.0f, 1.0f, 1.01e-4f, std::vector<float> uncompressedData = {+0.0f, -0.0f, 1.0f, 1.01e-4f,
1.0e4f, NAN, INFINITY, -INFINITY}; 1.0e4f, NAN, INFINITY, -INFINITY};
@ -454,18 +454,18 @@ class TextureFormatTest : public DawnTest {
// Test the R8Unorm format // Test the R8Unorm format
TEST_P(TextureFormatTest, R8Unorm) { TEST_P(TextureFormatTest, R8Unorm) {
DoUnormTest<uint8_t>({dawn::TextureFormat::R8Unorm, 1, dawn::TextureComponentType::Float, 1}); DoUnormTest<uint8_t>({wgpu::TextureFormat::R8Unorm, 1, wgpu::TextureComponentType::Float, 1});
} }
// Test the RG8Unorm format // Test the RG8Unorm format
TEST_P(TextureFormatTest, RG8Unorm) { TEST_P(TextureFormatTest, RG8Unorm) {
DoUnormTest<uint8_t>({dawn::TextureFormat::RG8Unorm, 2, dawn::TextureComponentType::Float, 2}); DoUnormTest<uint8_t>({wgpu::TextureFormat::RG8Unorm, 2, wgpu::TextureComponentType::Float, 2});
} }
// Test the RGBA8Unorm format // Test the RGBA8Unorm format
TEST_P(TextureFormatTest, RGBA8Unorm) { TEST_P(TextureFormatTest, RGBA8Unorm) {
DoUnormTest<uint8_t>( DoUnormTest<uint8_t>(
{dawn::TextureFormat::RGBA8Unorm, 4, dawn::TextureComponentType::Float, 4}); {wgpu::TextureFormat::RGBA8Unorm, 4, wgpu::TextureComponentType::Float, 4});
} }
// Test the BGRA8Unorm format // Test the BGRA8Unorm format
@ -473,147 +473,147 @@ TEST_P(TextureFormatTest, BGRA8Unorm) {
uint8_t maxValue = std::numeric_limits<uint8_t>::max(); uint8_t maxValue = std::numeric_limits<uint8_t>::max();
std::vector<uint8_t> textureData = {maxValue, 1, 0, maxValue}; std::vector<uint8_t> textureData = {maxValue, 1, 0, maxValue};
std::vector<float> uncompressedData = {0.0f, 1.0f / maxValue, 1.0f, 1.0f}; std::vector<float> uncompressedData = {0.0f, 1.0f / maxValue, 1.0f, 1.0f};
DoFormatSamplingTest({dawn::TextureFormat::BGRA8Unorm, 4, dawn::TextureComponentType::Float, 4}, DoFormatSamplingTest({wgpu::TextureFormat::BGRA8Unorm, 4, wgpu::TextureComponentType::Float, 4},
textureData, uncompressedData); textureData, uncompressedData);
DoFormatRenderingTest( DoFormatRenderingTest(
{dawn::TextureFormat::BGRA8Unorm, 4, dawn::TextureComponentType::Float, 4}, {wgpu::TextureFormat::BGRA8Unorm, 4, wgpu::TextureComponentType::Float, 4},
uncompressedData, textureData); uncompressedData, textureData);
} }
// Test the R8Snorm format // Test the R8Snorm format
TEST_P(TextureFormatTest, R8Snorm) { TEST_P(TextureFormatTest, R8Snorm) {
DoSnormTest<int8_t>({dawn::TextureFormat::R8Snorm, 1, dawn::TextureComponentType::Float, 1}); DoSnormTest<int8_t>({wgpu::TextureFormat::R8Snorm, 1, wgpu::TextureComponentType::Float, 1});
} }
// Test the RG8Snorm format // Test the RG8Snorm format
TEST_P(TextureFormatTest, RG8Snorm) { TEST_P(TextureFormatTest, RG8Snorm) {
DoSnormTest<int8_t>({dawn::TextureFormat::RG8Snorm, 2, dawn::TextureComponentType::Float, 2}); DoSnormTest<int8_t>({wgpu::TextureFormat::RG8Snorm, 2, wgpu::TextureComponentType::Float, 2});
} }
// Test the RGBA8Snorm format // Test the RGBA8Snorm format
TEST_P(TextureFormatTest, RGBA8Snorm) { TEST_P(TextureFormatTest, RGBA8Snorm) {
DoSnormTest<int8_t>({dawn::TextureFormat::RGBA8Snorm, 4, dawn::TextureComponentType::Float, 4}); DoSnormTest<int8_t>({wgpu::TextureFormat::RGBA8Snorm, 4, wgpu::TextureComponentType::Float, 4});
} }
// Test the R8Uint format // Test the R8Uint format
TEST_P(TextureFormatTest, R8Uint) { TEST_P(TextureFormatTest, R8Uint) {
DoUintTest<uint8_t>({dawn::TextureFormat::R8Uint, 1, dawn::TextureComponentType::Uint, 1}); DoUintTest<uint8_t>({wgpu::TextureFormat::R8Uint, 1, wgpu::TextureComponentType::Uint, 1});
} }
// Test the RG8Uint format // Test the RG8Uint format
TEST_P(TextureFormatTest, RG8Uint) { TEST_P(TextureFormatTest, RG8Uint) {
DoUintTest<uint8_t>({dawn::TextureFormat::RG8Uint, 2, dawn::TextureComponentType::Uint, 2}); DoUintTest<uint8_t>({wgpu::TextureFormat::RG8Uint, 2, wgpu::TextureComponentType::Uint, 2});
} }
// Test the RGBA8Uint format // Test the RGBA8Uint format
TEST_P(TextureFormatTest, RGBA8Uint) { TEST_P(TextureFormatTest, RGBA8Uint) {
DoUintTest<uint8_t>({dawn::TextureFormat::RGBA8Uint, 4, dawn::TextureComponentType::Uint, 4}); DoUintTest<uint8_t>({wgpu::TextureFormat::RGBA8Uint, 4, wgpu::TextureComponentType::Uint, 4});
} }
// Test the R16Uint format // Test the R16Uint format
TEST_P(TextureFormatTest, R16Uint) { TEST_P(TextureFormatTest, R16Uint) {
DoUintTest<uint16_t>({dawn::TextureFormat::R16Uint, 2, dawn::TextureComponentType::Uint, 1}); DoUintTest<uint16_t>({wgpu::TextureFormat::R16Uint, 2, wgpu::TextureComponentType::Uint, 1});
} }
// Test the RG16Uint format // Test the RG16Uint format
TEST_P(TextureFormatTest, RG16Uint) { TEST_P(TextureFormatTest, RG16Uint) {
DoUintTest<uint16_t>({dawn::TextureFormat::RG16Uint, 4, dawn::TextureComponentType::Uint, 2}); DoUintTest<uint16_t>({wgpu::TextureFormat::RG16Uint, 4, wgpu::TextureComponentType::Uint, 2});
} }
// Test the RGBA16Uint format // Test the RGBA16Uint format
TEST_P(TextureFormatTest, RGBA16Uint) { TEST_P(TextureFormatTest, RGBA16Uint) {
DoUintTest<uint16_t>({dawn::TextureFormat::RGBA16Uint, 8, dawn::TextureComponentType::Uint, 4}); DoUintTest<uint16_t>({wgpu::TextureFormat::RGBA16Uint, 8, wgpu::TextureComponentType::Uint, 4});
} }
// Test the R32Uint format // Test the R32Uint format
TEST_P(TextureFormatTest, R32Uint) { TEST_P(TextureFormatTest, R32Uint) {
DoUintTest<uint32_t>({dawn::TextureFormat::R32Uint, 4, dawn::TextureComponentType::Uint, 1}); DoUintTest<uint32_t>({wgpu::TextureFormat::R32Uint, 4, wgpu::TextureComponentType::Uint, 1});
} }
// Test the RG32Uint format // Test the RG32Uint format
TEST_P(TextureFormatTest, RG32Uint) { TEST_P(TextureFormatTest, RG32Uint) {
DoUintTest<uint32_t>({dawn::TextureFormat::RG32Uint, 8, dawn::TextureComponentType::Uint, 2}); DoUintTest<uint32_t>({wgpu::TextureFormat::RG32Uint, 8, wgpu::TextureComponentType::Uint, 2});
} }
// Test the RGBA32Uint format // Test the RGBA32Uint format
TEST_P(TextureFormatTest, RGBA32Uint) { TEST_P(TextureFormatTest, RGBA32Uint) {
DoUintTest<uint32_t>( DoUintTest<uint32_t>(
{dawn::TextureFormat::RGBA32Uint, 16, dawn::TextureComponentType::Uint, 4}); {wgpu::TextureFormat::RGBA32Uint, 16, wgpu::TextureComponentType::Uint, 4});
} }
// Test the R8Sint format // Test the R8Sint format
TEST_P(TextureFormatTest, R8Sint) { TEST_P(TextureFormatTest, R8Sint) {
DoSintTest<int8_t>({dawn::TextureFormat::R8Sint, 1, dawn::TextureComponentType::Sint, 1}); DoSintTest<int8_t>({wgpu::TextureFormat::R8Sint, 1, wgpu::TextureComponentType::Sint, 1});
} }
// Test the RG8Sint format // Test the RG8Sint format
TEST_P(TextureFormatTest, RG8Sint) { TEST_P(TextureFormatTest, RG8Sint) {
DoSintTest<int8_t>({dawn::TextureFormat::RG8Sint, 2, dawn::TextureComponentType::Sint, 2}); DoSintTest<int8_t>({wgpu::TextureFormat::RG8Sint, 2, wgpu::TextureComponentType::Sint, 2});
} }
// Test the RGBA8Sint format // Test the RGBA8Sint format
TEST_P(TextureFormatTest, RGBA8Sint) { TEST_P(TextureFormatTest, RGBA8Sint) {
DoSintTest<int8_t>({dawn::TextureFormat::RGBA8Sint, 4, dawn::TextureComponentType::Sint, 4}); DoSintTest<int8_t>({wgpu::TextureFormat::RGBA8Sint, 4, wgpu::TextureComponentType::Sint, 4});
} }
// Test the R16Sint format // Test the R16Sint format
TEST_P(TextureFormatTest, R16Sint) { TEST_P(TextureFormatTest, R16Sint) {
DoSintTest<int16_t>({dawn::TextureFormat::R16Sint, 2, dawn::TextureComponentType::Sint, 1}); DoSintTest<int16_t>({wgpu::TextureFormat::R16Sint, 2, wgpu::TextureComponentType::Sint, 1});
} }
// Test the RG16Sint format // Test the RG16Sint format
TEST_P(TextureFormatTest, RG16Sint) { TEST_P(TextureFormatTest, RG16Sint) {
DoSintTest<int16_t>({dawn::TextureFormat::RG16Sint, 4, dawn::TextureComponentType::Sint, 2}); DoSintTest<int16_t>({wgpu::TextureFormat::RG16Sint, 4, wgpu::TextureComponentType::Sint, 2});
} }
// Test the RGBA16Sint format // Test the RGBA16Sint format
TEST_P(TextureFormatTest, RGBA16Sint) { TEST_P(TextureFormatTest, RGBA16Sint) {
DoSintTest<int16_t>({dawn::TextureFormat::RGBA16Sint, 8, dawn::TextureComponentType::Sint, 4}); DoSintTest<int16_t>({wgpu::TextureFormat::RGBA16Sint, 8, wgpu::TextureComponentType::Sint, 4});
} }
// Test the R32Sint format // Test the R32Sint format
TEST_P(TextureFormatTest, R32Sint) { TEST_P(TextureFormatTest, R32Sint) {
DoSintTest<int32_t>({dawn::TextureFormat::R32Sint, 4, dawn::TextureComponentType::Sint, 1}); DoSintTest<int32_t>({wgpu::TextureFormat::R32Sint, 4, wgpu::TextureComponentType::Sint, 1});
} }
// Test the RG32Sint format // Test the RG32Sint format
TEST_P(TextureFormatTest, RG32Sint) { TEST_P(TextureFormatTest, RG32Sint) {
DoSintTest<int32_t>({dawn::TextureFormat::RG32Sint, 8, dawn::TextureComponentType::Sint, 2}); DoSintTest<int32_t>({wgpu::TextureFormat::RG32Sint, 8, wgpu::TextureComponentType::Sint, 2});
} }
// Test the RGBA32Sint format // Test the RGBA32Sint format
TEST_P(TextureFormatTest, RGBA32Sint) { TEST_P(TextureFormatTest, RGBA32Sint) {
DoSintTest<int32_t>({dawn::TextureFormat::RGBA32Sint, 16, dawn::TextureComponentType::Sint, 4}); DoSintTest<int32_t>({wgpu::TextureFormat::RGBA32Sint, 16, wgpu::TextureComponentType::Sint, 4});
} }
// Test the R32Float format // Test the R32Float format
TEST_P(TextureFormatTest, R32Float) { TEST_P(TextureFormatTest, R32Float) {
DoFloat32Test({dawn::TextureFormat::R32Float, 4, dawn::TextureComponentType::Float, 1}); DoFloat32Test({wgpu::TextureFormat::R32Float, 4, wgpu::TextureComponentType::Float, 1});
} }
// Test the RG32Float format // Test the RG32Float format
TEST_P(TextureFormatTest, RG32Float) { TEST_P(TextureFormatTest, RG32Float) {
DoFloat32Test({dawn::TextureFormat::RG32Float, 8, dawn::TextureComponentType::Float, 2}); DoFloat32Test({wgpu::TextureFormat::RG32Float, 8, wgpu::TextureComponentType::Float, 2});
} }
// Test the RGBA32Float format // Test the RGBA32Float format
TEST_P(TextureFormatTest, RGBA32Float) { TEST_P(TextureFormatTest, RGBA32Float) {
DoFloat32Test({dawn::TextureFormat::RGBA32Float, 16, dawn::TextureComponentType::Float, 4}); DoFloat32Test({wgpu::TextureFormat::RGBA32Float, 16, wgpu::TextureComponentType::Float, 4});
} }
// Test the R16Float format // Test the R16Float format
TEST_P(TextureFormatTest, R16Float) { TEST_P(TextureFormatTest, R16Float) {
DoFloat16Test({dawn::TextureFormat::R16Float, 2, dawn::TextureComponentType::Float, 1}); DoFloat16Test({wgpu::TextureFormat::R16Float, 2, wgpu::TextureComponentType::Float, 1});
} }
// Test the RG16Float format // Test the RG16Float format
TEST_P(TextureFormatTest, RG16Float) { TEST_P(TextureFormatTest, RG16Float) {
DoFloat16Test({dawn::TextureFormat::RG16Float, 4, dawn::TextureComponentType::Float, 2}); DoFloat16Test({wgpu::TextureFormat::RG16Float, 4, wgpu::TextureComponentType::Float, 2});
} }
// Test the RGBA16Float format // Test the RGBA16Float format
TEST_P(TextureFormatTest, RGBA16Float) { TEST_P(TextureFormatTest, RGBA16Float) {
DoFloat16Test({dawn::TextureFormat::RGBA16Float, 8, dawn::TextureComponentType::Float, 4}); DoFloat16Test({wgpu::TextureFormat::RGBA16Float, 8, wgpu::TextureComponentType::Float, 4});
} }
// Test the RGBA8Unorm format // Test the RGBA8Unorm format
@ -631,10 +631,10 @@ TEST_P(TextureFormatTest, RGBA8UnormSrgb) {
} }
DoFloatFormatSamplingTest( DoFloatFormatSamplingTest(
{dawn::TextureFormat::RGBA8UnormSrgb, 4, dawn::TextureComponentType::Float, 4}, textureData, {wgpu::TextureFormat::RGBA8UnormSrgb, 4, wgpu::TextureComponentType::Float, 4}, textureData,
uncompressedData, 1.0e-3); uncompressedData, 1.0e-3);
DoFormatRenderingTest( DoFormatRenderingTest(
{dawn::TextureFormat::RGBA8UnormSrgb, 4, dawn::TextureComponentType::Float, 4}, {wgpu::TextureFormat::RGBA8UnormSrgb, 4, wgpu::TextureComponentType::Float, 4},
uncompressedData, textureData); uncompressedData, textureData);
} }
@ -658,10 +658,10 @@ TEST_P(TextureFormatTest, BGRA8UnormSrgb) {
} }
DoFloatFormatSamplingTest( DoFloatFormatSamplingTest(
{dawn::TextureFormat::BGRA8UnormSrgb, 4, dawn::TextureComponentType::Float, 4}, textureData, {wgpu::TextureFormat::BGRA8UnormSrgb, 4, wgpu::TextureComponentType::Float, 4}, textureData,
uncompressedData, 1.0e-3); uncompressedData, 1.0e-3);
DoFormatRenderingTest( DoFormatRenderingTest(
{dawn::TextureFormat::BGRA8UnormSrgb, 4, dawn::TextureComponentType::Float, 4}, {wgpu::TextureFormat::BGRA8UnormSrgb, 4, wgpu::TextureComponentType::Float, 4},
uncompressedData, textureData); uncompressedData, textureData);
} }
@ -687,10 +687,10 @@ TEST_P(TextureFormatTest, RGB10A2Unorm) {
// clang-format on // clang-format on
DoFloatFormatSamplingTest( DoFloatFormatSamplingTest(
{dawn::TextureFormat::RGB10A2Unorm, 4, dawn::TextureComponentType::Float, 4}, textureData, {wgpu::TextureFormat::RGB10A2Unorm, 4, wgpu::TextureComponentType::Float, 4}, textureData,
uncompressedData, 1.0e-5); uncompressedData, 1.0e-5);
DoFormatRenderingTest( DoFormatRenderingTest(
{dawn::TextureFormat::RGB10A2Unorm, 4, dawn::TextureComponentType::Float, 4}, {wgpu::TextureFormat::RGB10A2Unorm, 4, wgpu::TextureComponentType::Float, 4},
uncompressedData, textureData); uncompressedData, textureData);
} }
@ -734,7 +734,7 @@ TEST_P(TextureFormatTest, RG11B10Float) {
// clang-format on // clang-format on
DoFloatFormatSamplingTest( DoFloatFormatSamplingTest(
{dawn::TextureFormat::RG11B10Float, 4, dawn::TextureComponentType::Float, 4}, textureData, {wgpu::TextureFormat::RG11B10Float, 4, wgpu::TextureComponentType::Float, 4}, textureData,
uncompressedData); uncompressedData);
// This format is not renderable. // This format is not renderable.
} }

View File

@ -23,18 +23,18 @@
#include <array> #include <array>
constexpr static unsigned int kRTSize = 64; constexpr static unsigned int kRTSize = 64;
constexpr dawn::TextureFormat kDefaultFormat = dawn::TextureFormat::RGBA8Unorm; constexpr wgpu::TextureFormat kDefaultFormat = wgpu::TextureFormat::RGBA8Unorm;
constexpr uint32_t kBytesPerTexel = 4; constexpr uint32_t kBytesPerTexel = 4;
namespace { namespace {
dawn::Texture Create2DTexture(dawn::Device device, wgpu::Texture Create2DTexture(wgpu::Device device,
uint32_t width, uint32_t width,
uint32_t height, uint32_t height,
uint32_t arrayLayerCount, uint32_t arrayLayerCount,
uint32_t mipLevelCount, uint32_t mipLevelCount,
dawn::TextureUsage usage) { wgpu::TextureUsage usage) {
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = width; descriptor.size.width = width;
descriptor.size.height = height; descriptor.size.height = height;
descriptor.size.depth = 1; descriptor.size.depth = 1;
@ -46,7 +46,7 @@ namespace {
return device.CreateTexture(&descriptor); return device.CreateTexture(&descriptor);
} }
dawn::ShaderModule CreateDefaultVertexShaderModule(dawn::Device device) { wgpu::ShaderModule CreateDefaultVertexShaderModule(wgpu::Device device) {
return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
layout (location = 0) out vec2 o_texCoord; layout (location = 0) out vec2 o_texCoord;
@ -83,10 +83,10 @@ protected:
mRenderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); mRenderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::FilterMode kFilterMode = dawn::FilterMode::Nearest; wgpu::FilterMode kFilterMode = wgpu::FilterMode::Nearest;
dawn::AddressMode kAddressMode = dawn::AddressMode::ClampToEdge; wgpu::AddressMode kAddressMode = wgpu::AddressMode::ClampToEdge;
dawn::SamplerDescriptor samplerDescriptor; wgpu::SamplerDescriptor samplerDescriptor;
samplerDescriptor.minFilter = kFilterMode; samplerDescriptor.minFilter = kFilterMode;
samplerDescriptor.magFilter = kFilterMode; samplerDescriptor.magFilter = kFilterMode;
samplerDescriptor.mipmapFilter = kFilterMode; samplerDescriptor.mipmapFilter = kFilterMode;
@ -95,7 +95,7 @@ protected:
samplerDescriptor.addressModeW = kAddressMode; samplerDescriptor.addressModeW = kAddressMode;
samplerDescriptor.lodMinClamp = kLodMin; samplerDescriptor.lodMinClamp = kLodMin;
samplerDescriptor.lodMaxClamp = kLodMax; samplerDescriptor.lodMaxClamp = kLodMax;
samplerDescriptor.compare = dawn::CompareFunction::Never; samplerDescriptor.compare = wgpu::CompareFunction::Never;
mSampler = device.CreateSampler(&samplerDescriptor); mSampler = device.CreateSampler(&samplerDescriptor);
mVSModule = CreateDefaultVertexShaderModule(device); mVSModule = CreateDefaultVertexShaderModule(device);
@ -106,12 +106,12 @@ protected:
const uint32_t textureWidthLevel0 = 1 << mipLevelCount; const uint32_t textureWidthLevel0 = 1 << mipLevelCount;
const uint32_t textureHeightLevel0 = 1 << mipLevelCount; const uint32_t textureHeightLevel0 = 1 << mipLevelCount;
constexpr dawn::TextureUsage kUsage = constexpr wgpu::TextureUsage kUsage =
dawn::TextureUsage::CopyDst | dawn::TextureUsage::Sampled; wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled;
mTexture = Create2DTexture( mTexture = Create2DTexture(
device, textureWidthLevel0, textureHeightLevel0, arrayLayerCount, mipLevelCount, kUsage); device, textureWidthLevel0, textureHeightLevel0, arrayLayerCount, mipLevelCount, kUsage);
mDefaultTextureViewDescriptor.dimension = dawn::TextureViewDimension::e2DArray; mDefaultTextureViewDescriptor.dimension = wgpu::TextureViewDimension::e2DArray;
mDefaultTextureViewDescriptor.format = kDefaultFormat; mDefaultTextureViewDescriptor.format = kDefaultFormat;
mDefaultTextureViewDescriptor.baseMipLevel = 0; mDefaultTextureViewDescriptor.baseMipLevel = 0;
mDefaultTextureViewDescriptor.mipLevelCount = mipLevelCount; mDefaultTextureViewDescriptor.mipLevelCount = mipLevelCount;
@ -125,7 +125,7 @@ protected:
constexpr uint32_t kPixelsPerRowPitch = kTextureRowPitchAlignment / sizeof(RGBA8); constexpr uint32_t kPixelsPerRowPitch = kTextureRowPitchAlignment / sizeof(RGBA8);
ASSERT_LE(textureWidthLevel0, kPixelsPerRowPitch); ASSERT_LE(textureWidthLevel0, kPixelsPerRowPitch);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
for (uint32_t layer = 0; layer < arrayLayerCount; ++layer) { for (uint32_t layer = 0; layer < arrayLayerCount; ++layer) {
for (uint32_t level = 0; level < mipLevelCount; ++level) { for (uint32_t level = 0; level < mipLevelCount; ++level) {
const uint32_t texWidth = textureWidthLevel0 >> level; const uint32_t texWidth = textureWidthLevel0 >> level;
@ -135,35 +135,35 @@ protected:
constexpr uint32_t kPaddedTexWidth = kPixelsPerRowPitch; constexpr uint32_t kPaddedTexWidth = kPixelsPerRowPitch;
std::vector<RGBA8> data(kPaddedTexWidth * texHeight, RGBA8(0, 0, 0, pixelValue)); std::vector<RGBA8> data(kPaddedTexWidth * texHeight, RGBA8(0, 0, 0, pixelValue));
dawn::Buffer stagingBuffer = utils::CreateBufferFromData( wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), data.size() * sizeof(RGBA8), dawn::BufferUsage::CopySrc); device, data.data(), data.size() * sizeof(RGBA8), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(stagingBuffer, 0, kTextureRowPitchAlignment, 0); utils::CreateBufferCopyView(stagingBuffer, 0, kTextureRowPitchAlignment, 0);
dawn::TextureCopyView textureCopyView = wgpu::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(mTexture, level, layer, {0, 0, 0}); utils::CreateTextureCopyView(mTexture, level, layer, {0, 0, 0});
dawn::Extent3D copySize = {texWidth, texHeight, 1}; wgpu::Extent3D copySize = {texWidth, texHeight, 1};
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize); encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
} }
} }
dawn::CommandBuffer copy = encoder.Finish(); wgpu::CommandBuffer copy = encoder.Finish();
queue.Submit(1, &copy); queue.Submit(1, &copy);
} }
void Verify(const dawn::TextureView& textureView, void Verify(const wgpu::TextureView& textureView,
dawn::TextureViewDimension dimension, wgpu::TextureViewDimension dimension,
const char* fragmentShader, const char* fragmentShader,
int expected) { int expected) {
dawn::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
device, { device, {
{0, dawn::ShaderStage::Fragment, dawn::BindingType::Sampler}, {0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, {1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false,
false, dimension, dawn::TextureComponentType::Float}, false, dimension, wgpu::TextureComponentType::Float},
}); });
dawn::BindGroup bindGroup = wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, bindGroupLayout, {{0, mSampler}, {1, textureView}}); utils::MakeBindGroup(device, bindGroupLayout, {{0, mSampler}, {1, textureView}});
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fragmentShader); utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fragmentShader);
utils::ComboRenderPipelineDescriptor textureDescriptor(device); utils::ComboRenderPipelineDescriptor textureDescriptor(device);
@ -172,18 +172,18 @@ protected:
textureDescriptor.layout = utils::MakeBasicPipelineLayout(device, &bindGroupLayout); textureDescriptor.layout = utils::MakeBasicPipelineLayout(device, &bindGroupLayout);
textureDescriptor.cColorStates[0].format = mRenderPass.colorFormat; textureDescriptor.cColorStates[0].format = mRenderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&textureDescriptor); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&textureDescriptor);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&mRenderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&mRenderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
RGBA8 expectedPixel(0, 0, 0, expected); RGBA8 expectedPixel(0, 0, 0, expected);
@ -202,13 +202,13 @@ protected:
initTexture(textureArrayLayers, textureMipLevels); initTexture(textureArrayLayers, textureMipLevels);
dawn::TextureViewDescriptor descriptor = mDefaultTextureViewDescriptor; wgpu::TextureViewDescriptor descriptor = mDefaultTextureViewDescriptor;
descriptor.dimension = dawn::TextureViewDimension::e2D; descriptor.dimension = wgpu::TextureViewDimension::e2D;
descriptor.baseArrayLayer = textureViewBaseLayer; descriptor.baseArrayLayer = textureViewBaseLayer;
descriptor.arrayLayerCount = 1; descriptor.arrayLayerCount = 1;
descriptor.baseMipLevel = textureViewBaseMipLevel; descriptor.baseMipLevel = textureViewBaseMipLevel;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
dawn::TextureView textureView = mTexture.CreateView(&descriptor); wgpu::TextureView textureView = mTexture.CreateView(&descriptor);
const char* fragmentShader = R"( const char* fragmentShader = R"(
#version 450 #version 450
@ -224,7 +224,7 @@ protected:
)"; )";
const int expected = GenerateTestPixelValue(textureViewBaseLayer, textureViewBaseMipLevel); const int expected = GenerateTestPixelValue(textureViewBaseLayer, textureViewBaseMipLevel);
Verify(textureView, dawn::TextureViewDimension::e2D, fragmentShader, expected); Verify(textureView, wgpu::TextureViewDimension::e2D, fragmentShader, expected);
} }
void Texture2DArrayViewTest(uint32_t textureArrayLayers, void Texture2DArrayViewTest(uint32_t textureArrayLayers,
@ -241,13 +241,13 @@ protected:
initTexture(textureArrayLayers, textureMipLevels); initTexture(textureArrayLayers, textureMipLevels);
dawn::TextureViewDescriptor descriptor = mDefaultTextureViewDescriptor; wgpu::TextureViewDescriptor descriptor = mDefaultTextureViewDescriptor;
descriptor.dimension = dawn::TextureViewDimension::e2DArray; descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
descriptor.baseArrayLayer = textureViewBaseLayer; descriptor.baseArrayLayer = textureViewBaseLayer;
descriptor.arrayLayerCount = kTextureViewLayerCount; descriptor.arrayLayerCount = kTextureViewLayerCount;
descriptor.baseMipLevel = textureViewBaseMipLevel; descriptor.baseMipLevel = textureViewBaseMipLevel;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
dawn::TextureView textureView = mTexture.CreateView(&descriptor); wgpu::TextureView textureView = mTexture.CreateView(&descriptor);
const char* fragmentShader = R"( const char* fragmentShader = R"(
#version 450 #version 450
@ -268,7 +268,7 @@ protected:
for (int i = 0; i < static_cast<int>(kTextureViewLayerCount); ++i) { for (int i = 0; i < static_cast<int>(kTextureViewLayerCount); ++i) {
expected += GenerateTestPixelValue(textureViewBaseLayer + i, textureViewBaseMipLevel); expected += GenerateTestPixelValue(textureViewBaseLayer + i, textureViewBaseMipLevel);
} }
Verify(textureView, dawn::TextureViewDimension::e2DArray, fragmentShader, expected); Verify(textureView, wgpu::TextureViewDimension::e2DArray, fragmentShader, expected);
} }
std::string CreateFragmentShaderForCubeMapFace(uint32_t layer, bool isCubeMapArray) { std::string CreateFragmentShaderForCubeMapFace(uint32_t layer, bool isCubeMapArray) {
@ -320,16 +320,16 @@ protected:
ASSERT_TRUE((textureViewLayerCount == 6) || ASSERT_TRUE((textureViewLayerCount == 6) ||
(isCubeMapArray && textureViewLayerCount % 6 == 0)); (isCubeMapArray && textureViewLayerCount % 6 == 0));
dawn::TextureViewDimension dimension = (isCubeMapArray) wgpu::TextureViewDimension dimension = (isCubeMapArray)
? dawn::TextureViewDimension::CubeArray ? wgpu::TextureViewDimension::CubeArray
: dawn::TextureViewDimension::Cube; : wgpu::TextureViewDimension::Cube;
dawn::TextureViewDescriptor descriptor = mDefaultTextureViewDescriptor; wgpu::TextureViewDescriptor descriptor = mDefaultTextureViewDescriptor;
descriptor.dimension = dimension; descriptor.dimension = dimension;
descriptor.baseArrayLayer = textureViewBaseLayer; descriptor.baseArrayLayer = textureViewBaseLayer;
descriptor.arrayLayerCount = textureViewLayerCount; descriptor.arrayLayerCount = textureViewLayerCount;
dawn::TextureView cubeMapTextureView = mTexture.CreateView(&descriptor); wgpu::TextureView cubeMapTextureView = mTexture.CreateView(&descriptor);
// Check the data in the every face of the cube map (array) texture view. // Check the data in the every face of the cube map (array) texture view.
for (uint32_t layer = 0; layer < textureViewLayerCount; ++layer) { for (uint32_t layer = 0; layer < textureViewLayerCount; ++layer) {
@ -341,10 +341,10 @@ protected:
} }
} }
dawn::Sampler mSampler; wgpu::Sampler mSampler;
dawn::Texture mTexture; wgpu::Texture mTexture;
dawn::TextureViewDescriptor mDefaultTextureViewDescriptor; wgpu::TextureViewDescriptor mDefaultTextureViewDescriptor;
dawn::ShaderModule mVSModule; wgpu::ShaderModule mVSModule;
utils::BasicRenderPass mRenderPass; utils::BasicRenderPass mRenderPass;
}; };
@ -357,7 +357,7 @@ TEST_P(TextureViewSamplingTest, Default2DArrayTexture) {
constexpr uint32_t kMipLevels = 1; constexpr uint32_t kMipLevels = 1;
initTexture(kLayers, kMipLevels); initTexture(kLayers, kMipLevels);
dawn::TextureView textureView = mTexture.CreateView(); wgpu::TextureView textureView = mTexture.CreateView();
const char* fragmentShader = R"( const char* fragmentShader = R"(
#version 450 #version 450
@ -376,7 +376,7 @@ TEST_P(TextureViewSamplingTest, Default2DArrayTexture) {
const int expected = GenerateTestPixelValue(0, 0) + GenerateTestPixelValue(1, 0) + const int expected = GenerateTestPixelValue(0, 0) + GenerateTestPixelValue(1, 0) +
GenerateTestPixelValue(2, 0); GenerateTestPixelValue(2, 0);
Verify(textureView, dawn::TextureViewDimension::e2DArray, fragmentShader, expected); Verify(textureView, wgpu::TextureViewDimension::e2DArray, fragmentShader, expected);
} }
// Test sampling from a 2D texture view created on a 2D array texture. // Test sampling from a 2D texture view created on a 2D array texture.
@ -461,33 +461,33 @@ TEST_P(TextureViewSamplingTest, TextureCubeMapArrayViewSingleCubeMap) {
class TextureViewRenderingTest : public DawnTest { class TextureViewRenderingTest : public DawnTest {
protected: protected:
void TextureLayerAsColorAttachmentTest(dawn::TextureViewDimension dimension, void TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension dimension,
uint32_t layerCount, uint32_t layerCount,
uint32_t levelCount, uint32_t levelCount,
uint32_t textureViewBaseLayer, uint32_t textureViewBaseLayer,
uint32_t textureViewBaseLevel) { uint32_t textureViewBaseLevel) {
ASSERT(dimension == dawn::TextureViewDimension::e2D || ASSERT(dimension == wgpu::TextureViewDimension::e2D ||
dimension == dawn::TextureViewDimension::e2DArray); dimension == wgpu::TextureViewDimension::e2DArray);
ASSERT_LT(textureViewBaseLayer, layerCount); ASSERT_LT(textureViewBaseLayer, layerCount);
ASSERT_LT(textureViewBaseLevel, levelCount); ASSERT_LT(textureViewBaseLevel, levelCount);
const uint32_t textureWidthLevel0 = 1 << levelCount; const uint32_t textureWidthLevel0 = 1 << levelCount;
const uint32_t textureHeightLevel0 = 1 << levelCount; const uint32_t textureHeightLevel0 = 1 << levelCount;
constexpr dawn::TextureUsage kUsage = constexpr wgpu::TextureUsage kUsage =
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc; wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
dawn::Texture texture = Create2DTexture( wgpu::Texture texture = Create2DTexture(device, textureWidthLevel0, textureHeightLevel0,
device, textureWidthLevel0, textureHeightLevel0, layerCount, levelCount, kUsage); layerCount, levelCount, kUsage);
dawn::TextureViewDescriptor descriptor; wgpu::TextureViewDescriptor descriptor;
descriptor.format = kDefaultFormat; descriptor.format = kDefaultFormat;
descriptor.dimension = dimension; descriptor.dimension = dimension;
descriptor.baseArrayLayer = textureViewBaseLayer; descriptor.baseArrayLayer = textureViewBaseLayer;
descriptor.arrayLayerCount = 1; descriptor.arrayLayerCount = 1;
descriptor.baseMipLevel = textureViewBaseLevel; descriptor.baseMipLevel = textureViewBaseLevel;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
dawn::TextureView textureView = texture.CreateView(&descriptor); wgpu::TextureView textureView = texture.CreateView(&descriptor);
dawn::ShaderModule vsModule = CreateDefaultVertexShaderModule(device); wgpu::ShaderModule vsModule = CreateDefaultVertexShaderModule(device);
// Clear textureView with Red(255, 0, 0, 255) and render Green(0, 255, 0, 255) into it // Clear textureView with Red(255, 0, 0, 255) and render Green(0, 255, 0, 255) into it
utils::ComboRenderPassDescriptor renderPassInfo({textureView}); utils::ComboRenderPassDescriptor renderPassInfo({textureView});
@ -501,7 +501,7 @@ class TextureViewRenderingTest : public DawnTest {
fragColor = vec4(0.0, 1.0, 0.0, 1.0); fragColor = vec4(0.0, 1.0, 0.0, 1.0);
} }
)"; )";
dawn::ShaderModule oneColorFsModule = utils::CreateShaderModule( wgpu::ShaderModule oneColorFsModule = utils::CreateShaderModule(
device, utils::SingleShaderStage::Fragment, oneColorFragmentShader); device, utils::SingleShaderStage::Fragment, oneColorFragmentShader);
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device); utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
@ -509,17 +509,17 @@ class TextureViewRenderingTest : public DawnTest {
pipelineDescriptor.cFragmentStage.module = oneColorFsModule; pipelineDescriptor.cFragmentStage.module = oneColorFsModule;
pipelineDescriptor.cColorStates[0].format = kDefaultFormat; pipelineDescriptor.cColorStates[0].format = kDefaultFormat;
dawn::RenderPipeline oneColorPipeline = device.CreateRenderPipeline(&pipelineDescriptor); wgpu::RenderPipeline oneColorPipeline = device.CreateRenderPipeline(&pipelineDescriptor);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassInfo);
pass.SetPipeline(oneColorPipeline); pass.SetPipeline(oneColorPipeline);
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
// Check if the right pixels (Green) have been written into the right part of the texture. // Check if the right pixels (Green) have been written into the right part of the texture.
@ -545,15 +545,15 @@ TEST_P(TextureViewRenderingTest, Texture2DViewOnALevelOf2DTextureAsColorAttachme
// Rendering into the first level // Rendering into the first level
{ {
constexpr uint32_t kBaseLevel = 0; constexpr uint32_t kBaseLevel = 0;
TextureLayerAsColorAttachmentTest( TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2D, kLayers, kMipLevels,
dawn::TextureViewDimension::e2D, kLayers, kMipLevels, kBaseLayer, kBaseLevel); kBaseLayer, kBaseLevel);
} }
// Rendering into the last level // Rendering into the last level
{ {
constexpr uint32_t kBaseLevel = kMipLevels - 1; constexpr uint32_t kBaseLevel = kMipLevels - 1;
TextureLayerAsColorAttachmentTest( TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2D, kLayers, kMipLevels,
dawn::TextureViewDimension::e2D, kLayers, kMipLevels, kBaseLayer, kBaseLevel); kBaseLayer, kBaseLevel);
} }
} }
@ -566,15 +566,15 @@ TEST_P(TextureViewRenderingTest, Texture2DViewOnALayerOf2DArrayTextureAsColorAtt
// Rendering into the first layer // Rendering into the first layer
{ {
constexpr uint32_t kBaseLayer = 0; constexpr uint32_t kBaseLayer = 0;
TextureLayerAsColorAttachmentTest( TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2D, kLayers, kMipLevels,
dawn::TextureViewDimension::e2D, kLayers, kMipLevels, kBaseLayer, kBaseLevel); kBaseLayer, kBaseLevel);
} }
// Rendering into the last layer // Rendering into the last layer
{ {
constexpr uint32_t kBaseLayer = kLayers - 1; constexpr uint32_t kBaseLayer = kLayers - 1;
TextureLayerAsColorAttachmentTest( TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2D, kLayers, kMipLevels,
dawn::TextureViewDimension::e2D, kLayers, kMipLevels, kBaseLayer, kBaseLevel); kBaseLayer, kBaseLevel);
} }
} }
@ -588,15 +588,15 @@ TEST_P(TextureViewRenderingTest, Texture2DArrayViewOnALevelOf2DTextureAsColorAtt
// Rendering into the first level // Rendering into the first level
{ {
constexpr uint32_t kBaseLevel = 0; constexpr uint32_t kBaseLevel = 0;
TextureLayerAsColorAttachmentTest( TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2DArray, kLayers, kMipLevels,
dawn::TextureViewDimension::e2DArray, kLayers, kMipLevels, kBaseLayer, kBaseLevel); kBaseLayer, kBaseLevel);
} }
// Rendering into the last level // Rendering into the last level
{ {
constexpr uint32_t kBaseLevel = kMipLevels - 1; constexpr uint32_t kBaseLevel = kMipLevels - 1;
TextureLayerAsColorAttachmentTest( TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2DArray, kLayers, kMipLevels,
dawn::TextureViewDimension::e2DArray, kLayers, kMipLevels, kBaseLayer, kBaseLevel); kBaseLayer, kBaseLevel);
} }
} }
@ -609,15 +609,15 @@ TEST_P(TextureViewRenderingTest, Texture2DArrayViewOnALayerOf2DArrayTextureAsCol
// Rendering into the first layer // Rendering into the first layer
{ {
constexpr uint32_t kBaseLayer = 0; constexpr uint32_t kBaseLayer = 0;
TextureLayerAsColorAttachmentTest( TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2DArray, kLayers, kMipLevels,
dawn::TextureViewDimension::e2DArray, kLayers, kMipLevels, kBaseLayer, kBaseLevel); kBaseLayer, kBaseLevel);
} }
// Rendering into the last layer // Rendering into the last layer
{ {
constexpr uint32_t kBaseLayer = kLayers - 1; constexpr uint32_t kBaseLayer = kLayers - 1;
TextureLayerAsColorAttachmentTest( TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2DArray, kLayers, kMipLevels,
dawn::TextureViewDimension::e2DArray, kLayers, kMipLevels, kBaseLayer, kBaseLevel); kBaseLayer, kBaseLevel);
} }
} }

View File

@ -23,12 +23,12 @@ class TextureZeroInitTest : public DawnTest {
void TestSetUp() override { void TestSetUp() override {
DawnTest::TestSetUp(); DawnTest::TestSetUp();
} }
dawn::TextureDescriptor CreateTextureDescriptor(uint32_t mipLevelCount, wgpu::TextureDescriptor CreateTextureDescriptor(uint32_t mipLevelCount,
uint32_t arrayLayerCount, uint32_t arrayLayerCount,
dawn::TextureUsage usage, wgpu::TextureUsage usage,
dawn::TextureFormat format) { wgpu::TextureFormat format) {
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kSize; descriptor.size.width = kSize;
descriptor.size.height = kSize; descriptor.size.height = kSize;
descriptor.size.depth = 1; descriptor.size.depth = 1;
@ -39,18 +39,18 @@ class TextureZeroInitTest : public DawnTest {
descriptor.usage = usage; descriptor.usage = usage;
return descriptor; return descriptor;
} }
dawn::TextureViewDescriptor CreateTextureViewDescriptor(uint32_t baseMipLevel, wgpu::TextureViewDescriptor CreateTextureViewDescriptor(uint32_t baseMipLevel,
uint32_t baseArrayLayer) { uint32_t baseArrayLayer) {
dawn::TextureViewDescriptor descriptor; wgpu::TextureViewDescriptor descriptor;
descriptor.format = kColorFormat; descriptor.format = kColorFormat;
descriptor.baseArrayLayer = baseArrayLayer; descriptor.baseArrayLayer = baseArrayLayer;
descriptor.arrayLayerCount = 1; descriptor.arrayLayerCount = 1;
descriptor.baseMipLevel = baseMipLevel; descriptor.baseMipLevel = baseMipLevel;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
descriptor.dimension = dawn::TextureViewDimension::e2D; descriptor.dimension = wgpu::TextureViewDimension::e2D;
return descriptor; return descriptor;
} }
dawn::RenderPipeline CreatePipelineForTest() { wgpu::RenderPipeline CreatePipelineForTest() {
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device); utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
pipelineDescriptor.vertexStage.module = CreateBasicVertexShaderForTest(); pipelineDescriptor.vertexStage.module = CreateBasicVertexShaderForTest();
const char* fs = const char* fs =
@ -62,13 +62,13 @@ class TextureZeroInitTest : public DawnTest {
pipelineDescriptor.cFragmentStage.module = pipelineDescriptor.cFragmentStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs); utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs);
pipelineDescriptor.cDepthStencilState.depthCompare = dawn::CompareFunction::Equal; pipelineDescriptor.cDepthStencilState.depthCompare = wgpu::CompareFunction::Equal;
pipelineDescriptor.cDepthStencilState.stencilFront.compare = dawn::CompareFunction::Equal; pipelineDescriptor.cDepthStencilState.stencilFront.compare = wgpu::CompareFunction::Equal;
pipelineDescriptor.depthStencilState = &pipelineDescriptor.cDepthStencilState; pipelineDescriptor.depthStencilState = &pipelineDescriptor.cDepthStencilState;
return device.CreateRenderPipeline(&pipelineDescriptor); return device.CreateRenderPipeline(&pipelineDescriptor);
} }
dawn::ShaderModule CreateBasicVertexShaderForTest() { wgpu::ShaderModule CreateBasicVertexShaderForTest() {
return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(#version 450 return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(#version 450
const vec2 pos[6] = vec2[6](vec2(-1.0f, -1.0f), const vec2 pos[6] = vec2[6](vec2(-1.0f, -1.0f),
vec2(-1.0f, 1.0f), vec2(-1.0f, 1.0f),
@ -82,7 +82,7 @@ class TextureZeroInitTest : public DawnTest {
gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0); gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);
})"); })");
} }
dawn::ShaderModule CreateSampledTextureFragmentShaderForTest() { wgpu::ShaderModule CreateSampledTextureFragmentShaderForTest() {
return utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, return utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment,
R"(#version 450 R"(#version 450
layout(set = 0, binding = 0) uniform sampler sampler0; layout(set = 0, binding = 0) uniform sampler sampler0;
@ -97,18 +97,18 @@ class TextureZeroInitTest : public DawnTest {
// All three texture formats used (RGBA8Unorm, Depth24PlusStencil8, and RGBA8Snorm) have the // All three texture formats used (RGBA8Unorm, Depth24PlusStencil8, and RGBA8Snorm) have the
// same byte size of 4. // same byte size of 4.
constexpr static uint32_t kFormatBlockByteSize = 4; constexpr static uint32_t kFormatBlockByteSize = 4;
constexpr static dawn::TextureFormat kColorFormat = dawn::TextureFormat::RGBA8Unorm; constexpr static wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
constexpr static dawn::TextureFormat kDepthStencilFormat = constexpr static wgpu::TextureFormat kDepthStencilFormat =
dawn::TextureFormat::Depth24PlusStencil8; wgpu::TextureFormat::Depth24PlusStencil8;
constexpr static dawn::TextureFormat kNonrenderableColorFormat = constexpr static wgpu::TextureFormat kNonrenderableColorFormat =
dawn::TextureFormat::RGBA8Snorm; wgpu::TextureFormat::RGBA8Snorm;
}; };
// This tests that the code path of CopyTextureToBuffer clears correctly to Zero after first usage // This tests that the code path of CopyTextureToBuffer clears correctly to Zero after first usage
TEST_P(TextureZeroInitTest, CopyTextureToBufferSource) { TEST_P(TextureZeroInitTest, CopyTextureToBufferSource) {
dawn::TextureDescriptor descriptor = CreateTextureDescriptor( wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc, kColorFormat); 1, 1, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc, kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
// Texture's first usage is in EXPECT_PIXEL_RGBA8_EQ's call to CopyTextureToBuffer // Texture's first usage is in EXPECT_PIXEL_RGBA8_EQ's call to CopyTextureToBuffer
RGBA8 filledWithZeros(0, 0, 0, 0); RGBA8 filledWithZeros(0, 0, 0, 0);
@ -118,23 +118,23 @@ TEST_P(TextureZeroInitTest, CopyTextureToBufferSource) {
// Test that non-zero mip level clears subresource to Zero after first use // Test that non-zero mip level clears subresource to Zero after first use
// This goes through the BeginRenderPass's code path // This goes through the BeginRenderPass's code path
TEST_P(TextureZeroInitTest, RenderingMipMapClearsToZero) { TEST_P(TextureZeroInitTest, RenderingMipMapClearsToZero) {
dawn::TextureDescriptor descriptor = CreateTextureDescriptor( wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
4, 1, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc, kColorFormat); 4, 1, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc, kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
dawn::TextureViewDescriptor viewDescriptor = CreateTextureViewDescriptor(2, 0); wgpu::TextureViewDescriptor viewDescriptor = CreateTextureViewDescriptor(2, 0);
dawn::TextureView view = texture.CreateView(&viewDescriptor); wgpu::TextureView view = texture.CreateView(&viewDescriptor);
utils::BasicRenderPass renderPass = utils::BasicRenderPass(kSize, kSize, texture, kColorFormat); utils::BasicRenderPass renderPass = utils::BasicRenderPass(kSize, kSize, texture, kColorFormat);
renderPass.renderPassInfo.cColorAttachments[0].attachment = view; renderPass.renderPassInfo.cColorAttachments[0].attachment = view;
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
// Texture's first usage is in BeginRenderPass's call to RecordRenderPass // Texture's first usage is in BeginRenderPass's call to RecordRenderPass
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands)); EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
uint32_t mipSize = kSize >> 2; uint32_t mipSize = kSize >> 2;
@ -146,22 +146,22 @@ TEST_P(TextureZeroInitTest, RenderingMipMapClearsToZero) {
// Test that non-zero array layers clears subresource to Zero after first use. // Test that non-zero array layers clears subresource to Zero after first use.
// This goes through the BeginRenderPass's code path // This goes through the BeginRenderPass's code path
TEST_P(TextureZeroInitTest, RenderingArrayLayerClearsToZero) { TEST_P(TextureZeroInitTest, RenderingArrayLayerClearsToZero) {
dawn::TextureDescriptor descriptor = CreateTextureDescriptor( wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
1, 4, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc, kColorFormat); 1, 4, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc, kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
dawn::TextureViewDescriptor viewDescriptor = CreateTextureViewDescriptor(0, 2); wgpu::TextureViewDescriptor viewDescriptor = CreateTextureViewDescriptor(0, 2);
dawn::TextureView view = texture.CreateView(&viewDescriptor); wgpu::TextureView view = texture.CreateView(&viewDescriptor);
utils::BasicRenderPass renderPass = utils::BasicRenderPass(kSize, kSize, texture, kColorFormat); utils::BasicRenderPass renderPass = utils::BasicRenderPass(kSize, kSize, texture, kColorFormat);
renderPass.renderPassInfo.cColorAttachments[0].attachment = view; renderPass.renderPassInfo.cColorAttachments[0].attachment = view;
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands)); EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
std::vector<RGBA8> expected(kSize * kSize, {0, 0, 0, 0}); std::vector<RGBA8> expected(kSize * kSize, {0, 0, 0, 0});
@ -171,23 +171,23 @@ TEST_P(TextureZeroInitTest, RenderingArrayLayerClearsToZero) {
// This tests CopyBufferToTexture fully overwrites copy so lazy init is not needed. // This tests CopyBufferToTexture fully overwrites copy so lazy init is not needed.
TEST_P(TextureZeroInitTest, CopyBufferToTexture) { TEST_P(TextureZeroInitTest, CopyBufferToTexture) {
dawn::TextureDescriptor descriptor = CreateTextureDescriptor( wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
4, 1, 4, 1,
dawn::TextureUsage::CopyDst | dawn::TextureUsage::Sampled | dawn::TextureUsage::CopySrc, wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopySrc,
kColorFormat); kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize, 100); std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize, 100);
dawn::Buffer stagingBuffer = utils::CreateBufferFromData( wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc); device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0); wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1}; wgpu::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize); encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands)); EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
std::vector<RGBA8> expected(kSize * kSize, {100, 100, 100, 100}); std::vector<RGBA8> expected(kSize * kSize, {100, 100, 100, 100});
@ -198,23 +198,23 @@ TEST_P(TextureZeroInitTest, CopyBufferToTexture) {
// Test for a copy only to a subset of the subresource, lazy init is necessary to clear the other // Test for a copy only to a subset of the subresource, lazy init is necessary to clear the other
// half. // half.
TEST_P(TextureZeroInitTest, CopyBufferToTextureHalf) { TEST_P(TextureZeroInitTest, CopyBufferToTextureHalf) {
dawn::TextureDescriptor descriptor = CreateTextureDescriptor( wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
4, 1, 4, 1,
dawn::TextureUsage::CopyDst | dawn::TextureUsage::Sampled | dawn::TextureUsage::CopySrc, wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopySrc,
kColorFormat); kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize, 100); std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize, 100);
dawn::Buffer stagingBuffer = utils::CreateBufferFromData( wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc); device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0); wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize / 2, kSize, 1}; wgpu::Extent3D copySize = {kSize / 2, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize); encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands)); EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
std::vector<RGBA8> expected100((kSize / 2) * kSize, {100, 100, 100, 100}); std::vector<RGBA8> expected100((kSize / 2) * kSize, {100, 100, 100, 100});
@ -227,28 +227,28 @@ TEST_P(TextureZeroInitTest, CopyBufferToTextureHalf) {
// This tests CopyTextureToTexture fully overwrites copy so lazy init is not needed. // This tests CopyTextureToTexture fully overwrites copy so lazy init is not needed.
TEST_P(TextureZeroInitTest, CopyTextureToTexture) { TEST_P(TextureZeroInitTest, CopyTextureToTexture) {
dawn::TextureDescriptor srcDescriptor = CreateTextureDescriptor( wgpu::TextureDescriptor srcDescriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::Sampled | dawn::TextureUsage::CopySrc, kColorFormat); 1, 1, wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopySrc, kColorFormat);
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor); wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
dawn::TextureCopyView srcTextureCopyView = wgpu::TextureCopyView srcTextureCopyView =
utils::CreateTextureCopyView(srcTexture, 0, 0, {0, 0, 0}); utils::CreateTextureCopyView(srcTexture, 0, 0, {0, 0, 0});
dawn::TextureDescriptor dstDescriptor = wgpu::TextureDescriptor dstDescriptor =
CreateTextureDescriptor(1, 1, CreateTextureDescriptor(1, 1,
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopyDst | wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopyDst |
dawn::TextureUsage::CopySrc, wgpu::TextureUsage::CopySrc,
kColorFormat); kColorFormat);
dawn::Texture dstTexture = device.CreateTexture(&dstDescriptor); wgpu::Texture dstTexture = device.CreateTexture(&dstDescriptor);
dawn::TextureCopyView dstTextureCopyView = wgpu::TextureCopyView dstTextureCopyView =
utils::CreateTextureCopyView(dstTexture, 0, 0, {0, 0, 0}); utils::CreateTextureCopyView(dstTexture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1}; wgpu::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToTexture(&srcTextureCopyView, &dstTextureCopyView, &copySize); encoder.CopyTextureToTexture(&srcTextureCopyView, &dstTextureCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands)); EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
std::vector<RGBA8> expected(kSize * kSize, {0, 0, 0, 0}); std::vector<RGBA8> expected(kSize * kSize, {0, 0, 0, 0});
@ -260,44 +260,44 @@ TEST_P(TextureZeroInitTest, CopyTextureToTexture) {
// This Tests the CopyTextureToTexture's copy only to a subset of the subresource, lazy init is // This Tests the CopyTextureToTexture's copy only to a subset of the subresource, lazy init is
// necessary to clear the other half. // necessary to clear the other half.
TEST_P(TextureZeroInitTest, CopyTextureToTextureHalf) { TEST_P(TextureZeroInitTest, CopyTextureToTextureHalf) {
dawn::TextureDescriptor srcDescriptor = CreateTextureDescriptor( wgpu::TextureDescriptor srcDescriptor = CreateTextureDescriptor(
1, 1, 1, 1,
dawn::TextureUsage::Sampled | dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst, wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst,
kColorFormat); kColorFormat);
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor); wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
// fill srcTexture with 100 // fill srcTexture with 100
{ {
std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize, 100); std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize, 100);
dawn::Buffer stagingBuffer = utils::CreateBufferFromData( wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc); device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0); wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0);
dawn::TextureCopyView textureCopyView = wgpu::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(srcTexture, 0, 0, {0, 0, 0}); utils::CreateTextureCopyView(srcTexture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1}; wgpu::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize); encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
} }
dawn::TextureCopyView srcTextureCopyView = wgpu::TextureCopyView srcTextureCopyView =
utils::CreateTextureCopyView(srcTexture, 0, 0, {0, 0, 0}); utils::CreateTextureCopyView(srcTexture, 0, 0, {0, 0, 0});
dawn::TextureDescriptor dstDescriptor = wgpu::TextureDescriptor dstDescriptor =
CreateTextureDescriptor(1, 1, CreateTextureDescriptor(1, 1,
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopyDst | wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopyDst |
dawn::TextureUsage::CopySrc, wgpu::TextureUsage::CopySrc,
kColorFormat); kColorFormat);
dawn::Texture dstTexture = device.CreateTexture(&dstDescriptor); wgpu::Texture dstTexture = device.CreateTexture(&dstDescriptor);
dawn::TextureCopyView dstTextureCopyView = wgpu::TextureCopyView dstTextureCopyView =
utils::CreateTextureCopyView(dstTexture, 0, 0, {0, 0, 0}); utils::CreateTextureCopyView(dstTexture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize / 2, kSize, 1}; wgpu::Extent3D copySize = {kSize / 2, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToTexture(&srcTextureCopyView, &dstTextureCopyView, &copySize); encoder.CopyTextureToTexture(&srcTextureCopyView, &dstTextureCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands)); EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
std::vector<RGBA8> expectedWithZeros((kSize / 2) * kSize, {0, 0, 0, 0}); std::vector<RGBA8> expectedWithZeros((kSize / 2) * kSize, {0, 0, 0, 0});
@ -312,32 +312,32 @@ TEST_P(TextureZeroInitTest, CopyTextureToTextureHalf) {
// This tests the texture with depth attachment and load op load will init depth stencil texture to // This tests the texture with depth attachment and load op load will init depth stencil texture to
// 0s. // 0s.
TEST_P(TextureZeroInitTest, RenderingLoadingDepth) { TEST_P(TextureZeroInitTest, RenderingLoadingDepth) {
dawn::TextureDescriptor srcDescriptor = wgpu::TextureDescriptor srcDescriptor =
CreateTextureDescriptor(1, 1, CreateTextureDescriptor(1, 1,
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
dawn::TextureUsage::OutputAttachment, wgpu::TextureUsage::OutputAttachment,
kColorFormat); kColorFormat);
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor); wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
dawn::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor( wgpu::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc, 1, 1, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc,
kDepthStencilFormat); kDepthStencilFormat);
dawn::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor); wgpu::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor);
utils::ComboRenderPassDescriptor renderPassDescriptor({srcTexture.CreateView()}, utils::ComboRenderPassDescriptor renderPassDescriptor({srcTexture.CreateView()},
depthStencilTexture.CreateView()); depthStencilTexture.CreateView());
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Load; renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = dawn::LoadOp::Clear; renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = wgpu::LoadOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.clearStencil = 0; renderPassDescriptor.cDepthStencilAttachmentInfo.clearStencil = 0;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = dawn::StoreOp::Store; renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Store;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = dawn::StoreOp::Store; renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Store;
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
auto pass = encoder.BeginRenderPass(&renderPassDescriptor); auto pass = encoder.BeginRenderPass(&renderPassDescriptor);
pass.SetPipeline(CreatePipelineForTest()); pass.SetPipeline(CreatePipelineForTest());
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commandBuffer = encoder.Finish(); wgpu::CommandBuffer commandBuffer = encoder.Finish();
// Expect 0 lazy clears, depth stencil texture will clear using loadop // Expect 0 lazy clears, depth stencil texture will clear using loadop
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer)); EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer));
@ -349,32 +349,32 @@ TEST_P(TextureZeroInitTest, RenderingLoadingDepth) {
// This tests the texture with stencil attachment and load op load will init depth stencil texture // This tests the texture with stencil attachment and load op load will init depth stencil texture
// to 0s. // to 0s.
TEST_P(TextureZeroInitTest, RenderingLoadingStencil) { TEST_P(TextureZeroInitTest, RenderingLoadingStencil) {
dawn::TextureDescriptor srcDescriptor = wgpu::TextureDescriptor srcDescriptor =
CreateTextureDescriptor(1, 1, CreateTextureDescriptor(1, 1,
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
dawn::TextureUsage::OutputAttachment, wgpu::TextureUsage::OutputAttachment,
kColorFormat); kColorFormat);
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor); wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
dawn::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor( wgpu::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc, 1, 1, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc,
kDepthStencilFormat); kDepthStencilFormat);
dawn::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor); wgpu::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor);
utils::ComboRenderPassDescriptor renderPassDescriptor({srcTexture.CreateView()}, utils::ComboRenderPassDescriptor renderPassDescriptor({srcTexture.CreateView()},
depthStencilTexture.CreateView()); depthStencilTexture.CreateView());
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Clear; renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.clearDepth = 0.0f; renderPassDescriptor.cDepthStencilAttachmentInfo.clearDepth = 0.0f;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = dawn::LoadOp::Load; renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = wgpu::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = dawn::StoreOp::Store; renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Store;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = dawn::StoreOp::Store; renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Store;
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
auto pass = encoder.BeginRenderPass(&renderPassDescriptor); auto pass = encoder.BeginRenderPass(&renderPassDescriptor);
pass.SetPipeline(CreatePipelineForTest()); pass.SetPipeline(CreatePipelineForTest());
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commandBuffer = encoder.Finish(); wgpu::CommandBuffer commandBuffer = encoder.Finish();
// Expect 0 lazy clears, depth stencil texture will clear using loadop // Expect 0 lazy clears, depth stencil texture will clear using loadop
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer)); EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer));
@ -386,31 +386,31 @@ TEST_P(TextureZeroInitTest, RenderingLoadingStencil) {
// This tests the texture with depth stencil attachment and load op load will init depth stencil // This tests the texture with depth stencil attachment and load op load will init depth stencil
// texture to 0s. // texture to 0s.
TEST_P(TextureZeroInitTest, RenderingLoadingDepthStencil) { TEST_P(TextureZeroInitTest, RenderingLoadingDepthStencil) {
dawn::TextureDescriptor srcDescriptor = wgpu::TextureDescriptor srcDescriptor =
CreateTextureDescriptor(1, 1, CreateTextureDescriptor(1, 1,
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
dawn::TextureUsage::OutputAttachment, wgpu::TextureUsage::OutputAttachment,
kColorFormat); kColorFormat);
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor); wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
dawn::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor( wgpu::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc, 1, 1, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc,
kDepthStencilFormat); kDepthStencilFormat);
dawn::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor); wgpu::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor);
utils::ComboRenderPassDescriptor renderPassDescriptor({srcTexture.CreateView()}, utils::ComboRenderPassDescriptor renderPassDescriptor({srcTexture.CreateView()},
depthStencilTexture.CreateView()); depthStencilTexture.CreateView());
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Load; renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = dawn::LoadOp::Load; renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = wgpu::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = dawn::StoreOp::Store; renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Store;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = dawn::StoreOp::Store; renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Store;
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
auto pass = encoder.BeginRenderPass(&renderPassDescriptor); auto pass = encoder.BeginRenderPass(&renderPassDescriptor);
pass.SetPipeline(CreatePipelineForTest()); pass.SetPipeline(CreatePipelineForTest());
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commandBuffer = encoder.Finish(); wgpu::CommandBuffer commandBuffer = encoder.Finish();
// Expect 0 lazy clears, depth stencil texture will clear using loadop // Expect 0 lazy clears, depth stencil texture will clear using loadop
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer)); EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer));
@ -421,17 +421,17 @@ TEST_P(TextureZeroInitTest, RenderingLoadingDepthStencil) {
// This tests the color attachments clear to 0s // This tests the color attachments clear to 0s
TEST_P(TextureZeroInitTest, ColorAttachmentsClear) { TEST_P(TextureZeroInitTest, ColorAttachmentsClear) {
dawn::TextureDescriptor descriptor = CreateTextureDescriptor( wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc, kColorFormat); 1, 1, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc, kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
utils::BasicRenderPass renderPass = utils::BasicRenderPass(kSize, kSize, texture, kColorFormat); utils::BasicRenderPass renderPass = utils::BasicRenderPass(kSize, kSize, texture, kColorFormat);
renderPass.renderPassInfo.cColorAttachments[0].loadOp = dawn::LoadOp::Load; renderPass.renderPassInfo.cColorAttachments[0].loadOp = wgpu::LoadOp::Load;
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands)); EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
std::vector<RGBA8> expected(kSize * kSize, {0, 0, 0, 0}); std::vector<RGBA8> expected(kSize * kSize, {0, 0, 0, 0});
@ -441,20 +441,20 @@ TEST_P(TextureZeroInitTest, ColorAttachmentsClear) {
// This tests the clearing of sampled textures in render pass // This tests the clearing of sampled textures in render pass
TEST_P(TextureZeroInitTest, RenderPassSampledTextureClear) { TEST_P(TextureZeroInitTest, RenderPassSampledTextureClear) {
// Create needed resources // Create needed resources
dawn::TextureDescriptor descriptor = wgpu::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 1, dawn::TextureUsage::Sampled, kColorFormat); CreateTextureDescriptor(1, 1, wgpu::TextureUsage::Sampled, kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
dawn::TextureDescriptor renderTextureDescriptor = CreateTextureDescriptor( wgpu::TextureDescriptor renderTextureDescriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::CopySrc | dawn::TextureUsage::OutputAttachment, kColorFormat); 1, 1, wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::OutputAttachment, kColorFormat);
dawn::Texture renderTexture = device.CreateTexture(&renderTextureDescriptor); wgpu::Texture renderTexture = device.CreateTexture(&renderTextureDescriptor);
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
dawn::Sampler sampler = device.CreateSampler(&samplerDesc); wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
dawn::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::Sampler}, device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture}}); {1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture}});
// Create render pipeline // Create render pipeline
utils::ComboRenderPipelineDescriptor renderPipelineDescriptor(device); utils::ComboRenderPipelineDescriptor renderPipelineDescriptor(device);
@ -462,23 +462,23 @@ TEST_P(TextureZeroInitTest, RenderPassSampledTextureClear) {
renderPipelineDescriptor.cColorStates[0].format = kColorFormat; renderPipelineDescriptor.cColorStates[0].format = kColorFormat;
renderPipelineDescriptor.vertexStage.module = CreateBasicVertexShaderForTest(); renderPipelineDescriptor.vertexStage.module = CreateBasicVertexShaderForTest();
renderPipelineDescriptor.cFragmentStage.module = CreateSampledTextureFragmentShaderForTest(); renderPipelineDescriptor.cFragmentStage.module = CreateSampledTextureFragmentShaderForTest();
dawn::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor); wgpu::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor);
// Create bindgroup // Create bindgroup
dawn::BindGroup bindGroup = wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, bindGroupLayout, {{0, sampler}, {1, texture.CreateView()}}); utils::MakeBindGroup(device, bindGroupLayout, {{0, sampler}, {1, texture.CreateView()}});
// Encode pass and submit // Encode pass and submit
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
utils::ComboRenderPassDescriptor renderPassDesc({renderTexture.CreateView()}); utils::ComboRenderPassDescriptor renderPassDesc({renderTexture.CreateView()});
renderPassDesc.cColorAttachments[0].clearColor = {1.0, 1.0, 1.0, 1.0}; renderPassDesc.cColorAttachments[0].clearColor = {1.0, 1.0, 1.0, 1.0};
renderPassDesc.cColorAttachments[0].loadOp = dawn::LoadOp::Clear; renderPassDesc.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc);
pass.SetPipeline(renderPipeline); pass.SetPipeline(renderPipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
// Expect 1 lazy clear for sampled texture // Expect 1 lazy clear for sampled texture
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands)); EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
@ -490,34 +490,34 @@ TEST_P(TextureZeroInitTest, RenderPassSampledTextureClear) {
// This tests the clearing of sampled textures during compute pass // This tests the clearing of sampled textures during compute pass
TEST_P(TextureZeroInitTest, ComputePassSampledTextureClear) { TEST_P(TextureZeroInitTest, ComputePassSampledTextureClear) {
// Create needed resources // Create needed resources
dawn::TextureDescriptor descriptor = wgpu::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 1, dawn::TextureUsage::Sampled, kColorFormat); CreateTextureDescriptor(1, 1, wgpu::TextureUsage::Sampled, kColorFormat);
descriptor.size.width = 1; descriptor.size.width = 1;
descriptor.size.height = 1; descriptor.size.height = 1;
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
uint32_t bufferSize = kFormatBlockByteSize * sizeof(uint32_t); uint32_t bufferSize = kFormatBlockByteSize * sizeof(uint32_t);
dawn::BufferDescriptor bufferDescriptor; wgpu::BufferDescriptor bufferDescriptor;
bufferDescriptor.size = bufferSize; bufferDescriptor.size = bufferSize;
bufferDescriptor.usage = bufferDescriptor.usage =
dawn::BufferUsage::CopySrc | dawn::BufferUsage::Storage | dawn::BufferUsage::CopyDst; wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopyDst;
dawn::Buffer bufferTex = device.CreateBuffer(&bufferDescriptor); wgpu::Buffer bufferTex = device.CreateBuffer(&bufferDescriptor);
// Add data to buffer to ensure it is initialized // Add data to buffer to ensure it is initialized
uint32_t data = 100; uint32_t data = 100;
bufferTex.SetSubData(0, sizeof(data), &data); bufferTex.SetSubData(0, sizeof(data), &data);
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
dawn::Sampler sampler = device.CreateSampler(&samplerDesc); wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
dawn::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Compute, dawn::BindingType::SampledTexture}, device, {{0, wgpu::ShaderStage::Compute, wgpu::BindingType::SampledTexture},
{1, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}, {1, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer},
{2, dawn::ShaderStage::Compute, dawn::BindingType::Sampler}}); {2, wgpu::ShaderStage::Compute, wgpu::BindingType::Sampler}});
// Create compute pipeline // Create compute pipeline
dawn::ComputePipelineDescriptor computePipelineDescriptor; wgpu::ComputePipelineDescriptor computePipelineDescriptor;
computePipelineDescriptor.layout = utils::MakeBasicPipelineLayout(device, &bindGroupLayout); computePipelineDescriptor.layout = utils::MakeBasicPipelineLayout(device, &bindGroupLayout);
dawn::ProgrammableStageDescriptor computeStage; wgpu::ProgrammableStageDescriptor computeStage;
const char* cs = const char* cs =
R"(#version 450 R"(#version 450
layout(binding = 0) uniform texture2D sampleTex; layout(binding = 0) uniform texture2D sampleTex;
@ -532,22 +532,22 @@ TEST_P(TextureZeroInitTest, ComputePassSampledTextureClear) {
computePipelineDescriptor.computeStage.module = computePipelineDescriptor.computeStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, cs); utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, cs);
computePipelineDescriptor.computeStage.entryPoint = "main"; computePipelineDescriptor.computeStage.entryPoint = "main";
dawn::ComputePipeline computePipeline = wgpu::ComputePipeline computePipeline =
device.CreateComputePipeline(&computePipelineDescriptor); device.CreateComputePipeline(&computePipelineDescriptor);
// Create bindgroup // Create bindgroup
dawn::BindGroup bindGroup = utils::MakeBindGroup( wgpu::BindGroup bindGroup = utils::MakeBindGroup(
device, bindGroupLayout, device, bindGroupLayout,
{{0, texture.CreateView()}, {1, bufferTex, 0, bufferSize}, {2, sampler}}); {{0, texture.CreateView()}, {1, bufferTex, 0, bufferSize}, {2, sampler}});
// Encode the pass and submit // Encode the pass and submit
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder pass = encoder.BeginComputePass(); wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(computePipeline); pass.SetPipeline(computePipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.Dispatch(1, 1, 1); pass.Dispatch(1, 1, 1);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands)); EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
// Expect the buffer to be zeroed out by the compute pass // Expect the buffer to be zeroed out by the compute pass
@ -557,24 +557,24 @@ TEST_P(TextureZeroInitTest, ComputePassSampledTextureClear) {
// This tests that the code path of CopyTextureToBuffer clears correctly for non-renderable textures // This tests that the code path of CopyTextureToBuffer clears correctly for non-renderable textures
TEST_P(TextureZeroInitTest, NonRenderableTextureClear) { TEST_P(TextureZeroInitTest, NonRenderableTextureClear) {
dawn::TextureDescriptor descriptor = wgpu::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 1, dawn::TextureUsage::CopySrc, kNonrenderableColorFormat); CreateTextureDescriptor(1, 1, wgpu::TextureUsage::CopySrc, kNonrenderableColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
// Set buffer with dirty data so we know it is cleared by the lazy cleared texture copy // Set buffer with dirty data so we know it is cleared by the lazy cleared texture copy
uint32_t rowPitch = Align(kSize * kFormatBlockByteSize, kTextureRowPitchAlignment); uint32_t rowPitch = Align(kSize * kFormatBlockByteSize, kTextureRowPitchAlignment);
uint32_t bufferSize = rowPitch * kSize; uint32_t bufferSize = rowPitch * kSize;
std::vector<uint8_t> data(bufferSize, 100); std::vector<uint8_t> data(bufferSize, 100);
dawn::Buffer bufferDst = utils::CreateBufferFromData( wgpu::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc); device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, rowPitch, 0); wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, rowPitch, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1}; wgpu::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize); encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands)); EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
std::vector<uint32_t> expectedWithZeros(bufferSize, 0); std::vector<uint32_t> expectedWithZeros(bufferSize, 0);
@ -583,25 +583,25 @@ TEST_P(TextureZeroInitTest, NonRenderableTextureClear) {
// This tests that the code path of CopyTextureToBuffer clears correctly for non-renderable textures // This tests that the code path of CopyTextureToBuffer clears correctly for non-renderable textures
TEST_P(TextureZeroInitTest, NonRenderableTextureClearUnalignedSize) { TEST_P(TextureZeroInitTest, NonRenderableTextureClearUnalignedSize) {
dawn::TextureDescriptor descriptor = wgpu::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 1, dawn::TextureUsage::CopySrc, kNonrenderableColorFormat); CreateTextureDescriptor(1, 1, wgpu::TextureUsage::CopySrc, kNonrenderableColorFormat);
descriptor.size.width = kUnalignedSize; descriptor.size.width = kUnalignedSize;
descriptor.size.height = kUnalignedSize; descriptor.size.height = kUnalignedSize;
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
// Set buffer with dirty data so we know it is cleared by the lazy cleared texture copy // Set buffer with dirty data so we know it is cleared by the lazy cleared texture copy
uint32_t rowPitch = Align(kUnalignedSize * kFormatBlockByteSize, kTextureRowPitchAlignment); uint32_t rowPitch = Align(kUnalignedSize * kFormatBlockByteSize, kTextureRowPitchAlignment);
uint32_t bufferSize = rowPitch * kUnalignedSize; uint32_t bufferSize = rowPitch * kUnalignedSize;
std::vector<uint8_t> data(bufferSize, 100); std::vector<uint8_t> data(bufferSize, 100);
dawn::Buffer bufferDst = utils::CreateBufferFromData( wgpu::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc); device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, rowPitch, 0); wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, rowPitch, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kUnalignedSize, kUnalignedSize, 1}; wgpu::Extent3D copySize = {kUnalignedSize, kUnalignedSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize); encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands)); EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
std::vector<uint32_t> expectedWithZeros(bufferSize, 0); std::vector<uint32_t> expectedWithZeros(bufferSize, 0);
@ -615,23 +615,23 @@ TEST_P(TextureZeroInitTest, NonRenderableTextureClearWithMultiArrayLayers) {
// textures does not create large enough buffers for array layers greater than 1. // textures does not create large enough buffers for array layers greater than 1.
DAWN_SKIP_TEST_IF(IsOpenGL()); DAWN_SKIP_TEST_IF(IsOpenGL());
dawn::TextureDescriptor descriptor = wgpu::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 2, dawn::TextureUsage::CopySrc, kNonrenderableColorFormat); CreateTextureDescriptor(1, 2, wgpu::TextureUsage::CopySrc, kNonrenderableColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
// Set buffer with dirty data so we know it is cleared by the lazy cleared texture copy // Set buffer with dirty data so we know it is cleared by the lazy cleared texture copy
uint32_t bufferSize = kFormatBlockByteSize * kSize * kSize; uint32_t bufferSize = kFormatBlockByteSize * kSize * kSize;
std::vector<uint8_t> data(bufferSize, 100); std::vector<uint8_t> data(bufferSize, 100);
dawn::Buffer bufferDst = utils::CreateBufferFromData( wgpu::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc); device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0); wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 1, {0, 0, 0}); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 1, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1}; wgpu::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize); encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands)); EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
std::vector<uint32_t> expectedWithZeros(bufferSize, 0); std::vector<uint32_t> expectedWithZeros(bufferSize, 0);
@ -644,31 +644,31 @@ TEST_P(TextureZeroInitTest, NonRenderableTextureClearWithMultiArrayLayers) {
// because it will be lazy cleared by the EXPECT_TEXTURE_RGBA8_EQ call. // because it will be lazy cleared by the EXPECT_TEXTURE_RGBA8_EQ call.
TEST_P(TextureZeroInitTest, RenderPassStoreOpClear) { TEST_P(TextureZeroInitTest, RenderPassStoreOpClear) {
// Create needed resources // Create needed resources
dawn::TextureDescriptor descriptor = CreateTextureDescriptor( wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::Sampled | dawn::TextureUsage::CopyDst, kColorFormat); 1, 1, wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopyDst, kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor); wgpu::Texture texture = device.CreateTexture(&descriptor);
dawn::TextureDescriptor renderTextureDescriptor = CreateTextureDescriptor( wgpu::TextureDescriptor renderTextureDescriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::CopySrc | dawn::TextureUsage::OutputAttachment, kColorFormat); 1, 1, wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::OutputAttachment, kColorFormat);
dawn::Texture renderTexture = device.CreateTexture(&renderTextureDescriptor); wgpu::Texture renderTexture = device.CreateTexture(&renderTextureDescriptor);
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor(); wgpu::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
dawn::Sampler sampler = device.CreateSampler(&samplerDesc); wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
dawn::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::Sampler}, device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture}}); {1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture}});
// Fill the sample texture with data // Fill the sample texture with data
std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize, 1); std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize, 1);
dawn::Buffer stagingBuffer = utils::CreateBufferFromData( wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc); device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0); wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1}; wgpu::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize); encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
// Expect 0 lazy clears because the texture will be completely copied to // Expect 0 lazy clears because the texture will be completely copied to
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands)); EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
@ -678,19 +678,19 @@ TEST_P(TextureZeroInitTest, RenderPassStoreOpClear) {
renderPipelineDescriptor.vertexStage.module = CreateBasicVertexShaderForTest(); renderPipelineDescriptor.vertexStage.module = CreateBasicVertexShaderForTest();
renderPipelineDescriptor.cFragmentStage.module = CreateSampledTextureFragmentShaderForTest(); renderPipelineDescriptor.cFragmentStage.module = CreateSampledTextureFragmentShaderForTest();
renderPipelineDescriptor.cColorStates[0].format = kColorFormat; renderPipelineDescriptor.cColorStates[0].format = kColorFormat;
dawn::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor); wgpu::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor);
// Create bindgroup // Create bindgroup
dawn::BindGroup bindGroup = wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, bindGroupLayout, {{0, sampler}, {1, texture.CreateView()}}); utils::MakeBindGroup(device, bindGroupLayout, {{0, sampler}, {1, texture.CreateView()}});
// Encode pass and submit // Encode pass and submit
encoder = device.CreateCommandEncoder(); encoder = device.CreateCommandEncoder();
utils::ComboRenderPassDescriptor renderPassDesc({renderTexture.CreateView()}); utils::ComboRenderPassDescriptor renderPassDesc({renderTexture.CreateView()});
renderPassDesc.cColorAttachments[0].clearColor = {0.0, 0.0, 0.0, 0.0}; renderPassDesc.cColorAttachments[0].clearColor = {0.0, 0.0, 0.0, 0.0};
renderPassDesc.cColorAttachments[0].loadOp = dawn::LoadOp::Clear; renderPassDesc.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
renderPassDesc.cColorAttachments[0].storeOp = dawn::StoreOp::Clear; renderPassDesc.cColorAttachments[0].storeOp = wgpu::StoreOp::Clear;
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc);
pass.SetPipeline(renderPipeline); pass.SetPipeline(renderPipeline);
pass.SetBindGroup(0, bindGroup); pass.SetBindGroup(0, bindGroup);
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
@ -714,38 +714,38 @@ TEST_P(TextureZeroInitTest, RenderPassStoreOpClear) {
// Because LoadOp is Load and the subresource is uninitialized, the texture will be cleared to // Because LoadOp is Load and the subresource is uninitialized, the texture will be cleared to
// 0's This means the depth and stencil test will pass and the red square is drawn. // 0's This means the depth and stencil test will pass and the red square is drawn.
TEST_P(TextureZeroInitTest, RenderingLoadingDepthStencilStoreOpClear) { TEST_P(TextureZeroInitTest, RenderingLoadingDepthStencilStoreOpClear) {
dawn::TextureDescriptor srcDescriptor = wgpu::TextureDescriptor srcDescriptor =
CreateTextureDescriptor(1, 1, CreateTextureDescriptor(1, 1,
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
dawn::TextureUsage::OutputAttachment, wgpu::TextureUsage::OutputAttachment,
kColorFormat); kColorFormat);
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor); wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
dawn::TextureDescriptor depthStencilDescriptor = wgpu::TextureDescriptor depthStencilDescriptor =
CreateTextureDescriptor(1, 1, CreateTextureDescriptor(1, 1,
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc | wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc |
dawn::TextureUsage::CopyDst, wgpu::TextureUsage::CopyDst,
kDepthStencilFormat); kDepthStencilFormat);
dawn::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor); wgpu::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor);
// Setup the renderPass for the first pass. // Setup the renderPass for the first pass.
// We want to fail the depth and stencil test here so that nothing gets drawn and we can // We want to fail the depth and stencil test here so that nothing gets drawn and we can
// see that the subresource correctly gets set as unintialized in the second pass // see that the subresource correctly gets set as unintialized in the second pass
utils::ComboRenderPassDescriptor renderPassDescriptor({srcTexture.CreateView()}, utils::ComboRenderPassDescriptor renderPassDescriptor({srcTexture.CreateView()},
depthStencilTexture.CreateView()); depthStencilTexture.CreateView());
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Clear; renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = dawn::LoadOp::Clear; renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = wgpu::LoadOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.clearDepth = 1.0f; renderPassDescriptor.cDepthStencilAttachmentInfo.clearDepth = 1.0f;
renderPassDescriptor.cDepthStencilAttachmentInfo.clearStencil = 1u; renderPassDescriptor.cDepthStencilAttachmentInfo.clearStencil = 1u;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = dawn::StoreOp::Clear; renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = dawn::StoreOp::Clear; renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Clear;
{ {
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor);
pass.SetPipeline(CreatePipelineForTest()); pass.SetPipeline(CreatePipelineForTest());
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commandBuffer = encoder.Finish(); wgpu::CommandBuffer commandBuffer = encoder.Finish();
// Expect 0 lazy clears, depth stencil texture will clear using loadop // Expect 0 lazy clears, depth stencil texture will clear using loadop
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer)); EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer));
@ -758,14 +758,14 @@ TEST_P(TextureZeroInitTest, RenderingLoadingDepthStencilStoreOpClear) {
// Now we put the depth stencil texture back into renderpass, it should be cleared by loadop // Now we put the depth stencil texture back into renderpass, it should be cleared by loadop
// because storeOp clear sets the subresource as uninitialized // because storeOp clear sets the subresource as uninitialized
{ {
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Load; renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = dawn::LoadOp::Load; renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = wgpu::LoadOp::Load;
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor);
pass.SetPipeline(CreatePipelineForTest()); pass.SetPipeline(CreatePipelineForTest());
pass.Draw(6, 1, 0, 0); pass.Draw(6, 1, 0, 0);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commandBuffer = encoder.Finish(); wgpu::CommandBuffer commandBuffer = encoder.Finish();
// Expect 0 lazy clears, depth stencil texture will clear using loadop // Expect 0 lazy clears, depth stencil texture will clear using loadop
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer)); EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer));

View File

@ -54,141 +54,141 @@ class VertexFormatTest : public DawnTest {
utils::BasicRenderPass renderPass; utils::BasicRenderPass renderPass;
bool IsNormalizedFormat(dawn::VertexFormat format) { bool IsNormalizedFormat(wgpu::VertexFormat format) {
switch (format) { switch (format) {
case dawn::VertexFormat::UChar2Norm: case wgpu::VertexFormat::UChar2Norm:
case dawn::VertexFormat::UChar4Norm: case wgpu::VertexFormat::UChar4Norm:
case dawn::VertexFormat::Char2Norm: case wgpu::VertexFormat::Char2Norm:
case dawn::VertexFormat::Char4Norm: case wgpu::VertexFormat::Char4Norm:
case dawn::VertexFormat::UShort2Norm: case wgpu::VertexFormat::UShort2Norm:
case dawn::VertexFormat::UShort4Norm: case wgpu::VertexFormat::UShort4Norm:
case dawn::VertexFormat::Short2Norm: case wgpu::VertexFormat::Short2Norm:
case dawn::VertexFormat::Short4Norm: case wgpu::VertexFormat::Short4Norm:
return true; return true;
default: default:
return false; return false;
} }
} }
bool IsUnsignedFormat(dawn::VertexFormat format) { bool IsUnsignedFormat(wgpu::VertexFormat format) {
switch (format) { switch (format) {
case dawn::VertexFormat::UInt: case wgpu::VertexFormat::UInt:
case dawn::VertexFormat::UChar2: case wgpu::VertexFormat::UChar2:
case dawn::VertexFormat::UChar4: case wgpu::VertexFormat::UChar4:
case dawn::VertexFormat::UShort2: case wgpu::VertexFormat::UShort2:
case dawn::VertexFormat::UShort4: case wgpu::VertexFormat::UShort4:
case dawn::VertexFormat::UInt2: case wgpu::VertexFormat::UInt2:
case dawn::VertexFormat::UInt3: case wgpu::VertexFormat::UInt3:
case dawn::VertexFormat::UInt4: case wgpu::VertexFormat::UInt4:
case dawn::VertexFormat::UChar2Norm: case wgpu::VertexFormat::UChar2Norm:
case dawn::VertexFormat::UChar4Norm: case wgpu::VertexFormat::UChar4Norm:
case dawn::VertexFormat::UShort2Norm: case wgpu::VertexFormat::UShort2Norm:
case dawn::VertexFormat::UShort4Norm: case wgpu::VertexFormat::UShort4Norm:
return true; return true;
default: default:
return false; return false;
} }
} }
bool IsFloatFormat(dawn::VertexFormat format) { bool IsFloatFormat(wgpu::VertexFormat format) {
switch (format) { switch (format) {
case dawn::VertexFormat::Half2: case wgpu::VertexFormat::Half2:
case dawn::VertexFormat::Half4: case wgpu::VertexFormat::Half4:
case dawn::VertexFormat::Float: case wgpu::VertexFormat::Float:
case dawn::VertexFormat::Float2: case wgpu::VertexFormat::Float2:
case dawn::VertexFormat::Float3: case wgpu::VertexFormat::Float3:
case dawn::VertexFormat::Float4: case wgpu::VertexFormat::Float4:
return true; return true;
default: default:
return false; return false;
} }
} }
bool IsHalfFormat(dawn::VertexFormat format) { bool IsHalfFormat(wgpu::VertexFormat format) {
switch (format) { switch (format) {
case dawn::VertexFormat::Half2: case wgpu::VertexFormat::Half2:
case dawn::VertexFormat::Half4: case wgpu::VertexFormat::Half4:
return true; return true;
default: default:
return false; return false;
} }
} }
uint32_t BytesPerComponents(dawn::VertexFormat format) { uint32_t BytesPerComponents(wgpu::VertexFormat format) {
switch (format) { switch (format) {
case dawn::VertexFormat::Char2: case wgpu::VertexFormat::Char2:
case dawn::VertexFormat::Char4: case wgpu::VertexFormat::Char4:
case dawn::VertexFormat::UChar2: case wgpu::VertexFormat::UChar2:
case dawn::VertexFormat::UChar4: case wgpu::VertexFormat::UChar4:
case dawn::VertexFormat::UChar2Norm: case wgpu::VertexFormat::UChar2Norm:
case dawn::VertexFormat::UChar4Norm: case wgpu::VertexFormat::UChar4Norm:
case dawn::VertexFormat::Char2Norm: case wgpu::VertexFormat::Char2Norm:
case dawn::VertexFormat::Char4Norm: case wgpu::VertexFormat::Char4Norm:
return 1; return 1;
case dawn::VertexFormat::UShort2: case wgpu::VertexFormat::UShort2:
case dawn::VertexFormat::UShort4: case wgpu::VertexFormat::UShort4:
case dawn::VertexFormat::Short2: case wgpu::VertexFormat::Short2:
case dawn::VertexFormat::Short4: case wgpu::VertexFormat::Short4:
case dawn::VertexFormat::UShort2Norm: case wgpu::VertexFormat::UShort2Norm:
case dawn::VertexFormat::UShort4Norm: case wgpu::VertexFormat::UShort4Norm:
case dawn::VertexFormat::Short2Norm: case wgpu::VertexFormat::Short2Norm:
case dawn::VertexFormat::Short4Norm: case wgpu::VertexFormat::Short4Norm:
case dawn::VertexFormat::Half2: case wgpu::VertexFormat::Half2:
case dawn::VertexFormat::Half4: case wgpu::VertexFormat::Half4:
return 2; return 2;
case dawn::VertexFormat::UInt: case wgpu::VertexFormat::UInt:
case dawn::VertexFormat::Int: case wgpu::VertexFormat::Int:
case dawn::VertexFormat::Float: case wgpu::VertexFormat::Float:
case dawn::VertexFormat::UInt2: case wgpu::VertexFormat::UInt2:
case dawn::VertexFormat::UInt3: case wgpu::VertexFormat::UInt3:
case dawn::VertexFormat::UInt4: case wgpu::VertexFormat::UInt4:
case dawn::VertexFormat::Int2: case wgpu::VertexFormat::Int2:
case dawn::VertexFormat::Int3: case wgpu::VertexFormat::Int3:
case dawn::VertexFormat::Int4: case wgpu::VertexFormat::Int4:
case dawn::VertexFormat::Float2: case wgpu::VertexFormat::Float2:
case dawn::VertexFormat::Float3: case wgpu::VertexFormat::Float3:
case dawn::VertexFormat::Float4: case wgpu::VertexFormat::Float4:
return 4; return 4;
default: default:
DAWN_UNREACHABLE(); DAWN_UNREACHABLE();
} }
} }
uint32_t ComponentCount(dawn::VertexFormat format) { uint32_t ComponentCount(wgpu::VertexFormat format) {
switch (format) { switch (format) {
case dawn::VertexFormat::UInt: case wgpu::VertexFormat::UInt:
case dawn::VertexFormat::Int: case wgpu::VertexFormat::Int:
case dawn::VertexFormat::Float: case wgpu::VertexFormat::Float:
return 1; return 1;
case dawn::VertexFormat::UChar2: case wgpu::VertexFormat::UChar2:
case dawn::VertexFormat::UShort2: case wgpu::VertexFormat::UShort2:
case dawn::VertexFormat::UInt2: case wgpu::VertexFormat::UInt2:
case dawn::VertexFormat::Char2: case wgpu::VertexFormat::Char2:
case dawn::VertexFormat::Short2: case wgpu::VertexFormat::Short2:
case dawn::VertexFormat::Int2: case wgpu::VertexFormat::Int2:
case dawn::VertexFormat::UChar2Norm: case wgpu::VertexFormat::UChar2Norm:
case dawn::VertexFormat::Char2Norm: case wgpu::VertexFormat::Char2Norm:
case dawn::VertexFormat::UShort2Norm: case wgpu::VertexFormat::UShort2Norm:
case dawn::VertexFormat::Short2Norm: case wgpu::VertexFormat::Short2Norm:
case dawn::VertexFormat::Half2: case wgpu::VertexFormat::Half2:
case dawn::VertexFormat::Float2: case wgpu::VertexFormat::Float2:
return 2; return 2;
case dawn::VertexFormat::Int3: case wgpu::VertexFormat::Int3:
case dawn::VertexFormat::UInt3: case wgpu::VertexFormat::UInt3:
case dawn::VertexFormat::Float3: case wgpu::VertexFormat::Float3:
return 3; return 3;
case dawn::VertexFormat::UChar4: case wgpu::VertexFormat::UChar4:
case dawn::VertexFormat::UShort4: case wgpu::VertexFormat::UShort4:
case dawn::VertexFormat::UInt4: case wgpu::VertexFormat::UInt4:
case dawn::VertexFormat::Char4: case wgpu::VertexFormat::Char4:
case dawn::VertexFormat::Short4: case wgpu::VertexFormat::Short4:
case dawn::VertexFormat::Int4: case wgpu::VertexFormat::Int4:
case dawn::VertexFormat::UChar4Norm: case wgpu::VertexFormat::UChar4Norm:
case dawn::VertexFormat::Char4Norm: case wgpu::VertexFormat::Char4Norm:
case dawn::VertexFormat::UShort4Norm: case wgpu::VertexFormat::UShort4Norm:
case dawn::VertexFormat::Short4Norm: case wgpu::VertexFormat::Short4Norm:
case dawn::VertexFormat::Half4: case wgpu::VertexFormat::Half4:
case dawn::VertexFormat::Float4: case wgpu::VertexFormat::Float4:
return 4; return 4;
default: default:
DAWN_UNREACHABLE(); DAWN_UNREACHABLE();
@ -220,7 +220,7 @@ class VertexFormatTest : public DawnTest {
// The length of vertexData is fixed to 3, it aligns to triangle vertex number // The length of vertexData is fixed to 3, it aligns to triangle vertex number
template <typename T> template <typename T>
dawn::RenderPipeline MakeTestPipeline(dawn::VertexFormat format, std::vector<T>& expectedData) { wgpu::RenderPipeline MakeTestPipeline(wgpu::VertexFormat format, std::vector<T>& expectedData) {
bool isFloat = IsFloatFormat(format); bool isFloat = IsFloatFormat(format);
bool isNormalized = IsNormalizedFormat(format); bool isNormalized = IsNormalizedFormat(format);
bool isUnsigned = IsUnsignedFormat(format); bool isUnsigned = IsUnsignedFormat(format);
@ -340,10 +340,10 @@ class VertexFormatTest : public DawnTest {
vs << " }\n"; vs << " }\n";
vs << "}\n"; vs << "}\n";
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vs.str().c_str()); utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vs.str().c_str());
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) in vec4 color; layout(location = 0) in vec4 color;
@ -372,22 +372,22 @@ class VertexFormatTest : public DawnTest {
} }
template <typename VertexType, typename ExpectedType> template <typename VertexType, typename ExpectedType>
void DoVertexFormatTest(dawn::VertexFormat format, void DoVertexFormatTest(wgpu::VertexFormat format,
std::vector<VertexType> vertex, std::vector<VertexType> vertex,
std::vector<ExpectedType> expectedData) { std::vector<ExpectedType> expectedData) {
dawn::RenderPipeline pipeline = MakeTestPipeline(format, expectedData); wgpu::RenderPipeline pipeline = MakeTestPipeline(format, expectedData);
dawn::Buffer vertexBuffer = utils::CreateBufferFromData( wgpu::Buffer vertexBuffer = utils::CreateBufferFromData(
device, vertex.data(), vertex.size() * sizeof(VertexType), dawn::BufferUsage::Vertex); device, vertex.data(), vertex.size() * sizeof(VertexType), wgpu::BufferUsage::Vertex);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer); pass.SetVertexBuffer(0, vertexBuffer);
pass.Draw(3, 1, 0, 0); pass.Draw(3, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0); EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);
@ -414,7 +414,7 @@ TEST_P(VertexFormatTest, UChar2) {
std::numeric_limits<uint8_t>::max(), 0, std::numeric_limits<uint8_t>::min(), 2, 200, 201, std::numeric_limits<uint8_t>::max(), 0, std::numeric_limits<uint8_t>::min(), 2, 200, 201,
}; };
DoVertexFormatTest(dawn::VertexFormat::UChar2, vertexData, expectedData); DoVertexFormatTest(wgpu::VertexFormat::UChar2, vertexData, expectedData);
} }
TEST_P(VertexFormatTest, UChar4) { TEST_P(VertexFormatTest, UChar4) {
@ -433,7 +433,7 @@ TEST_P(VertexFormatTest, UChar4) {
203, 203,
}; };
DoVertexFormatTest(dawn::VertexFormat::UChar4, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::UChar4, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Char2) { TEST_P(VertexFormatTest, Char2) {
@ -456,7 +456,7 @@ TEST_P(VertexFormatTest, Char2) {
std::numeric_limits<int8_t>::max(), 0, std::numeric_limits<int8_t>::min(), -2, 120, -121, std::numeric_limits<int8_t>::max(), 0, std::numeric_limits<int8_t>::min(), -2, 120, -121,
}; };
DoVertexFormatTest(dawn::VertexFormat::Char2, vertexData, expectedData); DoVertexFormatTest(wgpu::VertexFormat::Char2, vertexData, expectedData);
} }
TEST_P(VertexFormatTest, Char4) { TEST_P(VertexFormatTest, Char4) {
@ -475,7 +475,7 @@ TEST_P(VertexFormatTest, Char4) {
-123, -123,
}; };
DoVertexFormatTest(dawn::VertexFormat::Char4, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Char4, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, UChar2Norm) { TEST_P(VertexFormatTest, UChar2Norm) {
@ -501,7 +501,7 @@ TEST_P(VertexFormatTest, UChar2Norm) {
200, 200,
201}; 201};
DoVertexFormatTest(dawn::VertexFormat::UChar2Norm, vertexData, expectedData); DoVertexFormatTest(wgpu::VertexFormat::UChar2Norm, vertexData, expectedData);
} }
TEST_P(VertexFormatTest, UChar4Norm) { TEST_P(VertexFormatTest, UChar4Norm) {
@ -518,7 +518,7 @@ TEST_P(VertexFormatTest, UChar4Norm) {
202, 202,
203}; 203};
DoVertexFormatTest(dawn::VertexFormat::UChar4Norm, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::UChar4Norm, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Char2Norm) { TEST_P(VertexFormatTest, Char2Norm) {
@ -546,7 +546,7 @@ TEST_P(VertexFormatTest, Char2Norm) {
-121, -121,
}; };
DoVertexFormatTest(dawn::VertexFormat::Char2Norm, vertexData, expectedData); DoVertexFormatTest(wgpu::VertexFormat::Char2Norm, vertexData, expectedData);
} }
TEST_P(VertexFormatTest, Char4Norm) { TEST_P(VertexFormatTest, Char4Norm) {
@ -563,7 +563,7 @@ TEST_P(VertexFormatTest, Char4Norm) {
102, 102,
-123}; -123};
DoVertexFormatTest(dawn::VertexFormat::Char4Norm, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Char4Norm, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, UShort2) { TEST_P(VertexFormatTest, UShort2) {
@ -574,7 +574,7 @@ TEST_P(VertexFormatTest, UShort2) {
65432, 65432,
4890}; 4890};
DoVertexFormatTest(dawn::VertexFormat::UShort2, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::UShort2, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, UShort4) { TEST_P(VertexFormatTest, UShort4) {
@ -593,7 +593,7 @@ TEST_P(VertexFormatTest, UShort4) {
3467, 3467,
}; };
DoVertexFormatTest(dawn::VertexFormat::UShort4, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::UShort4, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Short2) { TEST_P(VertexFormatTest, Short2) {
@ -604,7 +604,7 @@ TEST_P(VertexFormatTest, Short2) {
3876, 3876,
-3948}; -3948};
DoVertexFormatTest(dawn::VertexFormat::Short2, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Short2, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Short4) { TEST_P(VertexFormatTest, Short4) {
@ -623,7 +623,7 @@ TEST_P(VertexFormatTest, Short4) {
-2987, -2987,
}; };
DoVertexFormatTest(dawn::VertexFormat::Short4, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Short4, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, UShort2Norm) { TEST_P(VertexFormatTest, UShort2Norm) {
@ -634,7 +634,7 @@ TEST_P(VertexFormatTest, UShort2Norm) {
3456, 3456,
6543}; 6543};
DoVertexFormatTest(dawn::VertexFormat::UShort2Norm, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::UShort2Norm, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, UShort4Norm) { TEST_P(VertexFormatTest, UShort4Norm) {
@ -651,7 +651,7 @@ TEST_P(VertexFormatTest, UShort4Norm) {
2987, 2987,
2987}; 2987};
DoVertexFormatTest(dawn::VertexFormat::UShort4Norm, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::UShort4Norm, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Short2Norm) { TEST_P(VertexFormatTest, Short2Norm) {
@ -662,7 +662,7 @@ TEST_P(VertexFormatTest, Short2Norm) {
4987, 4987,
-6789}; -6789};
DoVertexFormatTest(dawn::VertexFormat::Short2Norm, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Short2Norm, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Short4Norm) { TEST_P(VertexFormatTest, Short4Norm) {
@ -679,37 +679,37 @@ TEST_P(VertexFormatTest, Short4Norm) {
20432, 20432,
-2083}; -2083};
DoVertexFormatTest(dawn::VertexFormat::Short4Norm, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Short4Norm, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Half2) { TEST_P(VertexFormatTest, Half2) {
std::vector<uint16_t> vertexData = std::vector<uint16_t> vertexData =
Float32ToFloat16(std::vector<float>({14.8f, -0.0f, 22.5f, 1.3f, +0.0f, -24.8f})); Float32ToFloat16(std::vector<float>({14.8f, -0.0f, 22.5f, 1.3f, +0.0f, -24.8f}));
DoVertexFormatTest(dawn::VertexFormat::Half2, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Half2, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Half4) { TEST_P(VertexFormatTest, Half4) {
std::vector<uint16_t> vertexData = Float32ToFloat16(std::vector<float>( std::vector<uint16_t> vertexData = Float32ToFloat16(std::vector<float>(
{+0.0f, -16.8f, 18.2f, -0.0f, 12.5f, 1.3f, 14.8f, -12.4f, 22.5f, -48.8f, 47.4f, -24.8f})); {+0.0f, -16.8f, 18.2f, -0.0f, 12.5f, 1.3f, 14.8f, -12.4f, 22.5f, -48.8f, 47.4f, -24.8f}));
DoVertexFormatTest(dawn::VertexFormat::Half4, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Half4, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Float) { TEST_P(VertexFormatTest, Float) {
std::vector<float> vertexData = {1.3f, +0.0f, -0.0f}; std::vector<float> vertexData = {1.3f, +0.0f, -0.0f};
DoVertexFormatTest(dawn::VertexFormat::Float, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Float, vertexData, vertexData);
vertexData = std::vector<float>{+1.0f, -1.0f, 18.23f}; vertexData = std::vector<float>{+1.0f, -1.0f, 18.23f};
DoVertexFormatTest(dawn::VertexFormat::Float, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Float, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Float2) { TEST_P(VertexFormatTest, Float2) {
std::vector<float> vertexData = {18.23f, -0.0f, +0.0f, +1.0f, 1.3f, -1.0f}; std::vector<float> vertexData = {18.23f, -0.0f, +0.0f, +1.0f, 1.3f, -1.0f};
DoVertexFormatTest(dawn::VertexFormat::Float2, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Float2, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Float3) { TEST_P(VertexFormatTest, Float3) {
@ -717,7 +717,7 @@ TEST_P(VertexFormatTest, Float3) {
+0.0f, -1.0f, -0.0f, 1.0f, 1.3f, 99.45f, 23.6f, -81.2f, 55.0f, +0.0f, -1.0f, -0.0f, 1.0f, 1.3f, 99.45f, 23.6f, -81.2f, 55.0f,
}; };
DoVertexFormatTest(dawn::VertexFormat::Float3, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Float3, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Float4) { TEST_P(VertexFormatTest, Float4) {
@ -725,7 +725,7 @@ TEST_P(VertexFormatTest, Float4) {
19.2f, -19.3f, +0.0f, 1.0f, -0.0f, 1.0f, 1.3f, -1.0f, 13.078f, 21.1965f, -1.1f, -1.2f, 19.2f, -19.3f, +0.0f, 1.0f, -0.0f, 1.0f, 1.3f, -1.0f, 13.078f, 21.1965f, -1.1f, -1.2f,
}; };
DoVertexFormatTest(dawn::VertexFormat::Float4, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Float4, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, UInt) { TEST_P(VertexFormatTest, UInt) {
@ -733,7 +733,7 @@ TEST_P(VertexFormatTest, UInt) {
std::numeric_limits<uint16_t>::max(), std::numeric_limits<uint16_t>::max(),
std::numeric_limits<uint8_t>::max()}; std::numeric_limits<uint8_t>::max()};
DoVertexFormatTest(dawn::VertexFormat::UInt, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::UInt, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, UInt2) { TEST_P(VertexFormatTest, UInt2) {
@ -741,7 +741,7 @@ TEST_P(VertexFormatTest, UInt2) {
std::numeric_limits<uint16_t>::max(), 64, std::numeric_limits<uint16_t>::max(), 64,
std::numeric_limits<uint8_t>::max(), 128}; std::numeric_limits<uint8_t>::max(), 128};
DoVertexFormatTest(dawn::VertexFormat::UInt2, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::UInt2, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, UInt3) { TEST_P(VertexFormatTest, UInt3) {
@ -749,7 +749,7 @@ TEST_P(VertexFormatTest, UInt3) {
std::numeric_limits<uint16_t>::max(), 164, 128, std::numeric_limits<uint16_t>::max(), 164, 128,
std::numeric_limits<uint8_t>::max(), 1283, 256}; std::numeric_limits<uint8_t>::max(), 1283, 256};
DoVertexFormatTest(dawn::VertexFormat::UInt3, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::UInt3, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, UInt4) { TEST_P(VertexFormatTest, UInt4) {
@ -757,7 +757,7 @@ TEST_P(VertexFormatTest, UInt4) {
std::numeric_limits<uint16_t>::max(), 164, 128, 0, std::numeric_limits<uint16_t>::max(), 164, 128, 0,
std::numeric_limits<uint8_t>::max(), 1283, 256, 4567}; std::numeric_limits<uint8_t>::max(), 1283, 256, 4567};
DoVertexFormatTest(dawn::VertexFormat::UInt4, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::UInt4, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Int) { TEST_P(VertexFormatTest, Int) {
@ -765,7 +765,7 @@ TEST_P(VertexFormatTest, Int) {
std::numeric_limits<int32_t>::min(), std::numeric_limits<int32_t>::min(),
std::numeric_limits<int8_t>::max()}; std::numeric_limits<int8_t>::max()};
DoVertexFormatTest(dawn::VertexFormat::Int, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Int, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Int2) { TEST_P(VertexFormatTest, Int2) {
@ -774,7 +774,7 @@ TEST_P(VertexFormatTest, Int2) {
std::numeric_limits<int16_t>::max(), std::numeric_limits<int16_t>::min(), std::numeric_limits<int16_t>::max(), std::numeric_limits<int16_t>::min(),
std::numeric_limits<int8_t>::max(), std::numeric_limits<int8_t>::min()}; std::numeric_limits<int8_t>::max(), std::numeric_limits<int8_t>::min()};
DoVertexFormatTest(dawn::VertexFormat::Int2, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Int2, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Int3) { TEST_P(VertexFormatTest, Int3) {
@ -783,7 +783,7 @@ TEST_P(VertexFormatTest, Int3) {
std::numeric_limits<int16_t>::max(), std::numeric_limits<int16_t>::min(), 128, std::numeric_limits<int16_t>::max(), std::numeric_limits<int16_t>::min(), 128,
std::numeric_limits<int8_t>::max(), std::numeric_limits<int8_t>::min(), 256}; std::numeric_limits<int8_t>::max(), std::numeric_limits<int8_t>::min(), 256};
DoVertexFormatTest(dawn::VertexFormat::Int3, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Int3, vertexData, vertexData);
} }
TEST_P(VertexFormatTest, Int4) { TEST_P(VertexFormatTest, Int4) {
@ -792,7 +792,7 @@ TEST_P(VertexFormatTest, Int4) {
std::numeric_limits<int16_t>::max(), std::numeric_limits<int16_t>::min(), -128, 0, std::numeric_limits<int16_t>::max(), std::numeric_limits<int16_t>::min(), -128, 0,
std::numeric_limits<int8_t>::max(), std::numeric_limits<int8_t>::min(), 256, -4567}; std::numeric_limits<int8_t>::max(), std::numeric_limits<int8_t>::min(), 256, -4567};
DoVertexFormatTest(dawn::VertexFormat::Int4, vertexData, vertexData); DoVertexFormatTest(wgpu::VertexFormat::Int4, vertexData, vertexData);
} }
DAWN_INSTANTIATE_TEST(VertexFormatTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend); DAWN_INSTANTIATE_TEST(VertexFormatTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);

View File

@ -18,8 +18,8 @@
#include "utils/ComboRenderPipelineDescriptor.h" #include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/WGPUHelpers.h" #include "utils/WGPUHelpers.h"
using dawn::InputStepMode; using wgpu::InputStepMode;
using dawn::VertexFormat; using wgpu::VertexFormat;
// Input state tests all work the same way: the test will render triangles in a grid up to 4x4. Each triangle // Input state tests all work the same way: the test will render triangles in a grid up to 4x4. Each triangle
// is position in the grid such that X will correspond to the "triangle number" and the Y to the instance number. // is position in the grid such that X will correspond to the "triangle number" and the Y to the instance number.
@ -64,7 +64,7 @@ class VertexInputTest : public DawnTest {
VertexFormat format; VertexFormat format;
InputStepMode step; InputStepMode step;
}; };
dawn::RenderPipeline MakeTestPipeline(const dawn::VertexInputDescriptor& vertexInput, wgpu::RenderPipeline MakeTestPipeline(const wgpu::VertexInputDescriptor& vertexInput,
int multiplier, int multiplier,
const std::vector<ShaderTestSpec>& testSpec) { const std::vector<ShaderTestSpec>& testSpec) {
std::ostringstream vs; std::ostringstream vs;
@ -117,9 +117,9 @@ class VertexInputTest : public DawnTest {
vs << " }\n;"; vs << " }\n;";
vs << "}\n"; vs << "}\n";
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vs.str().c_str()); utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vs.str().c_str());
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) in vec4 color; layout(location = 0) in vec4 color;
@ -177,26 +177,26 @@ class VertexInputTest : public DawnTest {
} }
template <typename T> template <typename T>
dawn::Buffer MakeVertexBuffer(std::vector<T> data) { wgpu::Buffer MakeVertexBuffer(std::vector<T> data) {
return utils::CreateBufferFromData(device, data.data(), return utils::CreateBufferFromData(device, data.data(),
static_cast<uint32_t>(data.size() * sizeof(T)), static_cast<uint32_t>(data.size() * sizeof(T)),
dawn::BufferUsage::Vertex); wgpu::BufferUsage::Vertex);
} }
struct DrawVertexBuffer { struct DrawVertexBuffer {
uint32_t location; uint32_t location;
dawn::Buffer* buffer; wgpu::Buffer* buffer;
}; };
void DoTestDraw(const dawn::RenderPipeline& pipeline, void DoTestDraw(const wgpu::RenderPipeline& pipeline,
unsigned int triangles, unsigned int triangles,
unsigned int instances, unsigned int instances,
std::vector<DrawVertexBuffer> vertexBuffers) { std::vector<DrawVertexBuffer> vertexBuffers) {
EXPECT_LE(triangles, 4u); EXPECT_LE(triangles, 4u);
EXPECT_LE(instances, 4u); EXPECT_LE(instances, 4u);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
for (const DrawVertexBuffer& buffer : vertexBuffers) { for (const DrawVertexBuffer& buffer : vertexBuffers) {
@ -206,7 +206,7 @@ class VertexInputTest : public DawnTest {
pass.Draw(triangles * 3, instances, 0, 0); pass.Draw(triangles * 3, instances, 0, 0);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
CheckResult(triangles, instances); CheckResult(triangles, instances);
@ -235,14 +235,16 @@ class VertexInputTest : public DawnTest {
TEST_P(VertexInputTest, Basic) { TEST_P(VertexInputTest, Basic) {
utils::ComboVertexInputDescriptor vertexInput = MakeVertexInput( utils::ComboVertexInputDescriptor vertexInput = MakeVertexInput(
{{4 * sizeof(float), InputStepMode::Vertex, {{0, 0, VertexFormat::Float4}}}}); {{4 * sizeof(float), InputStepMode::Vertex, {{0, 0, VertexFormat::Float4}}}});
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}}); MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
dawn::Buffer buffer0 = MakeVertexBuffer<float>({ // clang-format off
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({
0, 1, 2, 3, 0, 1, 2, 3,
1, 2, 3, 4, 1, 2, 3, 4,
2, 3, 4, 5 2, 3, 4, 5
}); });
// clang-format on
DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}}); DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}});
} }
@ -253,11 +255,14 @@ TEST_P(VertexInputTest, ZeroStride) {
utils::ComboVertexInputDescriptor vertexInput = utils::ComboVertexInputDescriptor vertexInput =
MakeVertexInput({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float4}}}}); MakeVertexInput({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float4}}}});
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
MakeTestPipeline(vertexInput, 0, {{0, VertexFormat::Float4, InputStepMode::Vertex}}); MakeTestPipeline(vertexInput, 0, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
dawn::Buffer buffer0 = MakeVertexBuffer<float>({ wgpu::Buffer buffer0 = MakeVertexBuffer<float>({
0, 1, 2, 3, 0,
1,
2,
3,
}); });
DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}}); DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}});
} }
@ -271,36 +276,30 @@ TEST_P(VertexInputTest, AttributeExpanding) {
{ {
utils::ComboVertexInputDescriptor vertexInput = utils::ComboVertexInputDescriptor vertexInput =
MakeVertexInput({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float}}}}); MakeVertexInput({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float}}}});
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
MakeTestPipeline(vertexInput, 0, {{0, VertexFormat::Float, InputStepMode::Vertex}}); MakeTestPipeline(vertexInput, 0, {{0, VertexFormat::Float, InputStepMode::Vertex}});
dawn::Buffer buffer0 = MakeVertexBuffer<float>({ wgpu::Buffer buffer0 = MakeVertexBuffer<float>({0, 1, 2, 3});
0, 1, 2, 3
});
DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}}); DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}});
} }
// RG32F case // RG32F case
{ {
utils::ComboVertexInputDescriptor vertexInput = utils::ComboVertexInputDescriptor vertexInput =
MakeVertexInput({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float2}}}}); MakeVertexInput({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float2}}}});
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
MakeTestPipeline(vertexInput, 0, {{0, VertexFormat::Float2, InputStepMode::Vertex}}); MakeTestPipeline(vertexInput, 0, {{0, VertexFormat::Float2, InputStepMode::Vertex}});
dawn::Buffer buffer0 = MakeVertexBuffer<float>({ wgpu::Buffer buffer0 = MakeVertexBuffer<float>({0, 1, 2, 3});
0, 1, 2, 3
});
DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}}); DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}});
} }
// RGB32F case // RGB32F case
{ {
utils::ComboVertexInputDescriptor vertexInput = utils::ComboVertexInputDescriptor vertexInput =
MakeVertexInput({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float3}}}}); MakeVertexInput({{0, InputStepMode::Vertex, {{0, 0, VertexFormat::Float3}}}});
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
MakeTestPipeline(vertexInput, 0, {{0, VertexFormat::Float3, InputStepMode::Vertex}}); MakeTestPipeline(vertexInput, 0, {{0, VertexFormat::Float3, InputStepMode::Vertex}});
dawn::Buffer buffer0 = MakeVertexBuffer<float>({ wgpu::Buffer buffer0 = MakeVertexBuffer<float>({0, 1, 2, 3});
0, 1, 2, 3
});
DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}}); DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}});
} }
} }
@ -312,14 +311,16 @@ TEST_P(VertexInputTest, StrideLargerThanAttributes) {
utils::ComboVertexInputDescriptor vertexInput = MakeVertexInput( utils::ComboVertexInputDescriptor vertexInput = MakeVertexInput(
{{8 * sizeof(float), InputStepMode::Vertex, {{0, 0, VertexFormat::Float4}}}}); {{8 * sizeof(float), InputStepMode::Vertex, {{0, 0, VertexFormat::Float4}}}});
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}}); MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
dawn::Buffer buffer0 = MakeVertexBuffer<float>({ // clang-format off
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({
0, 1, 2, 3, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0,
1, 2, 3, 4, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0,
2, 3, 4, 5, 0, 0, 0, 0, 2, 3, 4, 5, 0, 0, 0, 0,
}); });
// clang-format on
DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}}); DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}});
} }
@ -329,14 +330,16 @@ TEST_P(VertexInputTest, TwoAttributesAtAnOffsetVertex) {
{{8 * sizeof(float), {{8 * sizeof(float),
InputStepMode::Vertex, InputStepMode::Vertex,
{{0, 0, VertexFormat::Float4}, {1, 4 * sizeof(float), VertexFormat::Float4}}}}); {{0, 0, VertexFormat::Float4}, {1, 4 * sizeof(float), VertexFormat::Float4}}}});
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}}); MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
dawn::Buffer buffer0 = MakeVertexBuffer<float>({ // clang-format off
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({
0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5,
}); });
// clang-format on
DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}}); DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}});
} }
@ -346,14 +349,16 @@ TEST_P(VertexInputTest, TwoAttributesAtAnOffsetInstance) {
{{8 * sizeof(float), {{8 * sizeof(float),
InputStepMode::Instance, InputStepMode::Instance,
{{0, 0, VertexFormat::Float4}, {1, 4 * sizeof(float), VertexFormat::Float4}}}}); {{0, 0, VertexFormat::Float4}, {1, 4 * sizeof(float), VertexFormat::Float4}}}});
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}}); MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}});
dawn::Buffer buffer0 = MakeVertexBuffer<float>({ // clang-format off
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({
0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5,
}); });
// clang-format on
DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}}); DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{0, &buffer0}});
} }
@ -361,15 +366,17 @@ TEST_P(VertexInputTest, TwoAttributesAtAnOffsetInstance) {
TEST_P(VertexInputTest, PureInstance) { TEST_P(VertexInputTest, PureInstance) {
utils::ComboVertexInputDescriptor vertexInput = MakeVertexInput( utils::ComboVertexInputDescriptor vertexInput = MakeVertexInput(
{{4 * sizeof(float), InputStepMode::Instance, {{0, 0, VertexFormat::Float4}}}}); {{4 * sizeof(float), InputStepMode::Instance, {{0, 0, VertexFormat::Float4}}}});
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}}); MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}});
dawn::Buffer buffer0 = MakeVertexBuffer<float>({ // clang-format off
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({
0, 1, 2, 3, 0, 1, 2, 3,
1, 2, 3, 4, 1, 2, 3, 4,
2, 3, 4, 5, 2, 3, 4, 5,
3, 4, 5, 6, 3, 4, 5, 6,
}); });
// clang-format on
DoTestDraw(pipeline, 1, 4, {DrawVertexBuffer{0, &buffer0}}); DoTestDraw(pipeline, 1, 4, {DrawVertexBuffer{0, &buffer0}});
} }
@ -383,25 +390,27 @@ TEST_P(VertexInputTest, MixedEverything) {
{10 * sizeof(float), {10 * sizeof(float),
InputStepMode::Instance, InputStepMode::Instance,
{{2, 0, VertexFormat::Float3}, {3, 5 * sizeof(float), VertexFormat::Float4}}}}); {{2, 0, VertexFormat::Float3}, {3, 5 * sizeof(float), VertexFormat::Float4}}}});
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
MakeTestPipeline(vertexInput, 1, MakeTestPipeline(vertexInput, 1,
{{0, VertexFormat::Float, InputStepMode::Vertex}, {{0, VertexFormat::Float, InputStepMode::Vertex},
{1, VertexFormat::Float2, InputStepMode::Vertex}, {1, VertexFormat::Float2, InputStepMode::Vertex},
{2, VertexFormat::Float3, InputStepMode::Instance}, {2, VertexFormat::Float3, InputStepMode::Instance},
{3, VertexFormat::Float4, InputStepMode::Instance}}); {3, VertexFormat::Float4, InputStepMode::Instance}});
dawn::Buffer buffer0 = MakeVertexBuffer<float>({ // clang-format off
wgpu::Buffer buffer0 = MakeVertexBuffer<float>({
0, 1, 2, 3, 0, 0, 0, 1, 2, 3, 0, 0, 0, 1, 2, 3, 0, 0, 0, 1, 2, 3, 0, 0,
1, 2, 3, 4, 0, 0, 1, 2, 3, 4, 0, 0, 1, 2, 3, 4, 0, 0, 1, 2, 3, 4, 0, 0,
2, 3, 4, 5, 0, 0, 2, 3, 4, 5, 0, 0, 2, 3, 4, 5, 0, 0, 2, 3, 4, 5, 0, 0,
3, 4, 5, 6, 0, 0, 3, 4, 5, 6, 0, 0, 3, 4, 5, 6, 0, 0, 3, 4, 5, 6, 0, 0,
}); });
dawn::Buffer buffer1 = MakeVertexBuffer<float>({ wgpu::Buffer buffer1 = MakeVertexBuffer<float>({
0, 1, 2, 3, 0, 0, 1, 2, 3, 0, 0, 1, 2, 3, 0, 0, 1, 2, 3, 0,
1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0,
2, 3, 4, 5, 0, 2, 3, 4, 5, 0, 2, 3, 4, 5, 0, 2, 3, 4, 5, 0,
3, 4, 5, 6, 0, 3, 4, 5, 6, 0, 3, 4, 5, 6, 0, 3, 4, 5, 6, 0,
}); });
// clang-format on
DoTestDraw(pipeline, 1, 1, {{0, &buffer0}, {1, &buffer1}}); DoTestDraw(pipeline, 1, 1, {{0, &buffer0}, {1, &buffer1}});
} }
@ -411,19 +420,21 @@ TEST_P(VertexInputTest, UnusedVertexSlot) {
utils::ComboVertexInputDescriptor instanceVertexInput = MakeVertexInput( utils::ComboVertexInputDescriptor instanceVertexInput = MakeVertexInput(
{{0, InputStepMode::Vertex, {}}, {{0, InputStepMode::Vertex, {}},
{4 * sizeof(float), InputStepMode::Instance, {{0, 0, VertexFormat::Float4}}}}); {4 * sizeof(float), InputStepMode::Instance, {{0, 0, VertexFormat::Float4}}}});
dawn::RenderPipeline instancePipeline = MakeTestPipeline( wgpu::RenderPipeline instancePipeline = MakeTestPipeline(
instanceVertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}}); instanceVertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}});
dawn::Buffer buffer = MakeVertexBuffer<float>({ // clang-format off
wgpu::Buffer buffer = MakeVertexBuffer<float>({
0, 1, 2, 3, 0, 1, 2, 3,
1, 2, 3, 4, 1, 2, 3, 4,
2, 3, 4, 5, 2, 3, 4, 5,
3, 4, 5, 6, 3, 4, 5, 6,
}); });
// clang-format on
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetVertexBuffer(0, buffer); pass.SetVertexBuffer(0, buffer);
pass.SetVertexBuffer(1, buffer); pass.SetVertexBuffer(1, buffer);
@ -433,7 +444,7 @@ TEST_P(VertexInputTest, UnusedVertexSlot) {
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
CheckResult(1, 4); CheckResult(1, 4);
@ -447,26 +458,28 @@ TEST_P(VertexInputTest, MultiplePipelinesMixedVertexInput) {
// Basic input state, using slot 0 // Basic input state, using slot 0
utils::ComboVertexInputDescriptor vertexVertexInput = MakeVertexInput( utils::ComboVertexInputDescriptor vertexVertexInput = MakeVertexInput(
{{4 * sizeof(float), InputStepMode::Vertex, {{0, 0, VertexFormat::Float4}}}}); {{4 * sizeof(float), InputStepMode::Vertex, {{0, 0, VertexFormat::Float4}}}});
dawn::RenderPipeline vertexPipeline = wgpu::RenderPipeline vertexPipeline =
MakeTestPipeline(vertexVertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}}); MakeTestPipeline(vertexVertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
// Instance input state, using slot 1 // Instance input state, using slot 1
utils::ComboVertexInputDescriptor instanceVertexInput = MakeVertexInput( utils::ComboVertexInputDescriptor instanceVertexInput = MakeVertexInput(
{{0, InputStepMode::Instance, {}}, {{0, InputStepMode::Instance, {}},
{4 * sizeof(float), InputStepMode::Instance, {{0, 0, VertexFormat::Float4}}}}); {4 * sizeof(float), InputStepMode::Instance, {{0, 0, VertexFormat::Float4}}}});
dawn::RenderPipeline instancePipeline = MakeTestPipeline( wgpu::RenderPipeline instancePipeline = MakeTestPipeline(
instanceVertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}}); instanceVertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Instance}});
dawn::Buffer buffer = MakeVertexBuffer<float>({ // clang-format off
wgpu::Buffer buffer = MakeVertexBuffer<float>({
0, 1, 2, 3, 0, 1, 2, 3,
1, 2, 3, 4, 1, 2, 3, 4,
2, 3, 4, 5, 2, 3, 4, 5,
3, 4, 5, 6, 3, 4, 5, 6,
}); });
// clang-format on
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetVertexBuffer(0, buffer); pass.SetVertexBuffer(0, buffer);
pass.SetVertexBuffer(1, buffer); pass.SetVertexBuffer(1, buffer);
@ -479,7 +492,7 @@ TEST_P(VertexInputTest, MultiplePipelinesMixedVertexInput) {
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
CheckResult(1, 4); CheckResult(1, 4);
@ -500,10 +513,10 @@ TEST_P(VertexInputTest, LastAllowedVertexBuffer) {
vertexInput.cAttributes[0].offset = 0; vertexInput.cAttributes[0].offset = 0;
vertexInput.cAttributes[0].format = VertexFormat::Float4; vertexInput.cAttributes[0].format = VertexFormat::Float4;
dawn::RenderPipeline pipeline = wgpu::RenderPipeline pipeline =
MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}}); MakeTestPipeline(vertexInput, 1, {{0, VertexFormat::Float4, InputStepMode::Vertex}});
dawn::Buffer buffer0 = MakeVertexBuffer<float>({0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5}); wgpu::Buffer buffer0 = MakeVertexBuffer<float>({0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5});
DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{kMaxVertexBuffers - 1, &buffer0}}); DoTestDraw(pipeline, 1, 1, {DrawVertexBuffer{kMaxVertexBuffers - 1, &buffer0}});
} }
@ -523,7 +536,7 @@ class OptionalVertexInputTest : public DawnTest {};
TEST_P(OptionalVertexInputTest, Basic) { TEST_P(OptionalVertexInputTest, Basic) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 3, 3); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 3, 3);
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
void main() { void main() {
@ -531,7 +544,7 @@ TEST_P(OptionalVertexInputTest, Basic) {
gl_PointSize = 1.0; gl_PointSize = 1.0;
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -542,20 +555,20 @@ TEST_P(OptionalVertexInputTest, Basic) {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::PointList; descriptor.primitiveTopology = wgpu::PrimitiveTopology::PointList;
descriptor.vertexInput = nullptr; descriptor.vertexInput = nullptr;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.Draw(1, 1, 0, 0); pass.Draw(1, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 1, 1); EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 1, 1);

View File

@ -23,7 +23,7 @@ class ViewportOrientationTests : public DawnTest {};
TEST_P(ViewportOrientationTests, OriginAt0x0) { TEST_P(ViewportOrientationTests, OriginAt0x0) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 2, 2); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 2, 2);
dawn::ShaderModule vsModule = wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450 #version 450
void main() { void main() {
@ -31,7 +31,7 @@ TEST_P(ViewportOrientationTests, OriginAt0x0) {
gl_PointSize = 1.0; gl_PointSize = 1.0;
})"); })");
dawn::ShaderModule fsModule = wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450 #version 450
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
@ -42,20 +42,20 @@ TEST_P(ViewportOrientationTests, OriginAt0x0) {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::PointList; descriptor.primitiveTopology = wgpu::PrimitiveTopology::PointList;
descriptor.cColorStates[0].format = renderPass.colorFormat; descriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
pass.Draw(1, 1, 0, 0); pass.Draw(1, 1, 0, 0);
pass.EndPass(); pass.EndPass();
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0); EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 0, 0);

View File

@ -19,7 +19,7 @@
class ViewportTest : public DawnTest { class ViewportTest : public DawnTest {
protected: protected:
dawn::RenderPipeline CreatePipelineForTest(dawn::CompareFunction depthCompare) { wgpu::RenderPipeline CreatePipelineForTest(wgpu::CompareFunction depthCompare) {
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device); utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
// Draw two triangles: // Draw two triangles:
@ -63,12 +63,12 @@ class ViewportTest : public DawnTest {
return device.CreateRenderPipeline(&pipelineDescriptor); return device.CreateRenderPipeline(&pipelineDescriptor);
} }
dawn::Texture Create2DTextureForTest(dawn::TextureFormat format) { wgpu::Texture Create2DTextureForTest(wgpu::TextureFormat format) {
dawn::TextureDescriptor textureDescriptor; wgpu::TextureDescriptor textureDescriptor;
textureDescriptor.dimension = dawn::TextureDimension::e2D; textureDescriptor.dimension = wgpu::TextureDimension::e2D;
textureDescriptor.format = format; textureDescriptor.format = format;
textureDescriptor.usage = textureDescriptor.usage =
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc; wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
textureDescriptor.arrayLayerCount = 1; textureDescriptor.arrayLayerCount = 1;
textureDescriptor.mipLevelCount = 1; textureDescriptor.mipLevelCount = 1;
textureDescriptor.sampleCount = 1; textureDescriptor.sampleCount = 1;
@ -97,16 +97,16 @@ class ViewportTest : public DawnTest {
}; };
void DoTest(const TestInfo& info) { void DoTest(const TestInfo& info) {
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
// Create render targets for 2 render passes. // Create render targets for 2 render passes.
dawn::Texture colorTexture1 = Create2DTextureForTest(dawn::TextureFormat::RGBA8Unorm); wgpu::Texture colorTexture1 = Create2DTextureForTest(wgpu::TextureFormat::RGBA8Unorm);
dawn::Texture depthStencilTexture1 = wgpu::Texture depthStencilTexture1 =
Create2DTextureForTest(dawn::TextureFormat::Depth24PlusStencil8); Create2DTextureForTest(wgpu::TextureFormat::Depth24PlusStencil8);
dawn::Texture colorTexture2 = Create2DTextureForTest(dawn::TextureFormat::RGBA8Unorm); wgpu::Texture colorTexture2 = Create2DTextureForTest(wgpu::TextureFormat::RGBA8Unorm);
dawn::Texture depthStencilTexture2 = wgpu::Texture depthStencilTexture2 =
Create2DTextureForTest(dawn::TextureFormat::Depth24PlusStencil8); Create2DTextureForTest(wgpu::TextureFormat::Depth24PlusStencil8);
// Create render pass 1 // Create render pass 1
// Note that we may explicitly call SetViewport() in this pass // Note that we may explicitly call SetViewport() in this pass
@ -114,14 +114,14 @@ class ViewportTest : public DawnTest {
utils::ComboRenderPassDescriptor renderPassDescriptor1( utils::ComboRenderPassDescriptor renderPassDescriptor1(
{colorTexture1.CreateView()}, depthStencilTexture1.CreateView()); {colorTexture1.CreateView()}, depthStencilTexture1.CreateView());
renderPassDescriptor1.cColorAttachments[0].clearColor = {0.0, 0.0, 1.0, 1.0}; renderPassDescriptor1.cColorAttachments[0].clearColor = {0.0, 0.0, 1.0, 1.0};
renderPassDescriptor1.cColorAttachments[0].loadOp = dawn::LoadOp::Clear; renderPassDescriptor1.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
renderPassDescriptor1.cDepthStencilAttachmentInfo.clearDepth = info.clearDepth; renderPassDescriptor1.cDepthStencilAttachmentInfo.clearDepth = info.clearDepth;
renderPassDescriptor1.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Clear; renderPassDescriptor1.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Clear;
dawn::RenderPassEncoder renderPass1 = wgpu::RenderPassEncoder renderPass1 =
commandEncoder.BeginRenderPass(&renderPassDescriptor1); commandEncoder.BeginRenderPass(&renderPassDescriptor1);
renderPass1.SetPipeline(CreatePipelineForTest(dawn::CompareFunction::Less)); renderPass1.SetPipeline(CreatePipelineForTest(wgpu::CompareFunction::Less));
if (info.setViewport) { if (info.setViewport) {
ViewportParams viewport = info.viewport; ViewportParams viewport = info.viewport;
renderPass1.SetViewport(viewport.x, viewport.y, viewport.width, viewport.height, renderPass1.SetViewport(viewport.x, viewport.y, viewport.width, viewport.height,
@ -139,20 +139,20 @@ class ViewportTest : public DawnTest {
utils::ComboRenderPassDescriptor renderPassDescriptor2( utils::ComboRenderPassDescriptor renderPassDescriptor2(
{colorTexture2.CreateView()}, depthStencilTexture2.CreateView()); {colorTexture2.CreateView()}, depthStencilTexture2.CreateView());
renderPassDescriptor2.cColorAttachments[0].clearColor = {0.0, 0.0, 1.0, 1.0}; renderPassDescriptor2.cColorAttachments[0].clearColor = {0.0, 0.0, 1.0, 1.0};
renderPassDescriptor2.cColorAttachments[0].loadOp = dawn::LoadOp::Clear; renderPassDescriptor2.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
renderPassDescriptor2.cDepthStencilAttachmentInfo.clearDepth = 0.5; renderPassDescriptor2.cDepthStencilAttachmentInfo.clearDepth = 0.5;
renderPassDescriptor2.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Clear; renderPassDescriptor2.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Clear;
dawn::RenderPassEncoder renderPass2 = wgpu::RenderPassEncoder renderPass2 =
commandEncoder.BeginRenderPass(&renderPassDescriptor2); commandEncoder.BeginRenderPass(&renderPassDescriptor2);
renderPass2.SetPipeline(CreatePipelineForTest(dawn::CompareFunction::Greater)); renderPass2.SetPipeline(CreatePipelineForTest(wgpu::CompareFunction::Greater));
renderPass2.Draw(6, 1, 0, 0); renderPass2.Draw(6, 1, 0, 0);
renderPass2.EndPass(); renderPass2.EndPass();
} }
dawn::CommandBuffer commandBuffer = commandEncoder.Finish(); wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue(); wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer); queue.Submit(1, &commandBuffer);
constexpr RGBA8 kColor[ColorTypeCount] = { constexpr RGBA8 kColor[ColorTypeCount] = {

View File

@ -97,16 +97,16 @@ class BufferUploadPerf : public DawnPerfTestWithParams<BufferUploadParams> {
private: private:
void Step() override; void Step() override;
dawn::Buffer dst; wgpu::Buffer dst;
std::vector<uint8_t> data; std::vector<uint8_t> data;
}; };
void BufferUploadPerf::TestSetUp() { void BufferUploadPerf::TestSetUp() {
DawnPerfTestWithParams<BufferUploadParams>::TestSetUp(); DawnPerfTestWithParams<BufferUploadParams>::TestSetUp();
dawn::BufferDescriptor desc = {}; wgpu::BufferDescriptor desc = {};
desc.size = data.size(); desc.size = data.size();
desc.usage = dawn::BufferUsage::CopyDst; desc.usage = wgpu::BufferUsage::CopyDst;
dst = device.CreateBuffer(&desc); dst = device.CreateBuffer(&desc);
} }
@ -122,11 +122,11 @@ void BufferUploadPerf::Step() {
} break; } break;
case UploadMethod::CreateBufferMapped: { case UploadMethod::CreateBufferMapped: {
dawn::BufferDescriptor desc = {}; wgpu::BufferDescriptor desc = {};
desc.size = data.size(); desc.size = data.size();
desc.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::MapWrite; desc.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::MapWrite;
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
for (unsigned int i = 0; i < kNumIterations; ++i) { for (unsigned int i = 0; i < kNumIterations; ++i) {
auto result = device.CreateBufferMapped(&desc); auto result = device.CreateBufferMapped(&desc);
@ -135,7 +135,7 @@ void BufferUploadPerf::Step() {
encoder.CopyBufferToBuffer(result.buffer, 0, dst, 0, data.size()); encoder.CopyBufferToBuffer(result.buffer, 0, dst, 0, data.size());
} }
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
} break; } break;
} }

View File

@ -208,9 +208,9 @@ void DawnPerfTestBase::DoRunLoop(double maxRunTime) {
mNumStepsPerformed = 0; mNumStepsPerformed = 0;
mRunning = true; mRunning = true;
dawn::FenceDescriptor desc = {}; wgpu::FenceDescriptor desc = {};
uint64_t signaledFenceValue = 0; uint64_t signaledFenceValue = 0;
dawn::Fence fence = mTest->queue.CreateFence(&desc); wgpu::Fence fence = mTest->queue.CreateFence(&desc);
mTimer->Start(); mTimer->Start();

View File

@ -150,8 +150,8 @@ namespace {
} }
// Wraps a vulkan image from external memory // Wraps a vulkan image from external memory
dawn::Texture WrapVulkanImage(dawn::Device device, wgpu::Texture WrapVulkanImage(wgpu::Device device,
const dawn::TextureDescriptor* textureDescriptor, const wgpu::TextureDescriptor* textureDescriptor,
int memoryFd, int memoryFd,
VkDeviceSize allocationSize, VkDeviceSize allocationSize,
uint32_t memoryTypeIndex, uint32_t memoryTypeIndex,
@ -160,14 +160,14 @@ namespace {
bool expectValid = true) { bool expectValid = true) {
dawn_native::vulkan::ExternalImageDescriptorOpaqueFD descriptor; dawn_native::vulkan::ExternalImageDescriptorOpaqueFD descriptor;
descriptor.cTextureDescriptor = descriptor.cTextureDescriptor =
reinterpret_cast<const DawnTextureDescriptor*>(textureDescriptor); reinterpret_cast<const WGPUTextureDescriptor*>(textureDescriptor);
descriptor.isCleared = isCleared; descriptor.isCleared = isCleared;
descriptor.allocationSize = allocationSize; descriptor.allocationSize = allocationSize;
descriptor.memoryTypeIndex = memoryTypeIndex; descriptor.memoryTypeIndex = memoryTypeIndex;
descriptor.memoryFD = memoryFd; descriptor.memoryFD = memoryFd;
descriptor.waitFDs = waitFDs; descriptor.waitFDs = waitFDs;
DawnTexture texture = WGPUTexture texture =
dawn_native::vulkan::WrapVulkanImageOpaqueFD(device.Get(), &descriptor); dawn_native::vulkan::WrapVulkanImageOpaqueFD(device.Get(), &descriptor);
if (expectValid) { if (expectValid) {
@ -177,13 +177,13 @@ namespace {
EXPECT_EQ(texture, nullptr); EXPECT_EQ(texture, nullptr);
} }
return dawn::Texture::Acquire(texture); return wgpu::Texture::Acquire(texture);
} }
// Exports the signal from a wrapped texture and ignores it // Exports the signal from a wrapped texture and ignores it
// We have to export the signal before destroying the wrapped texture else it's an assertion // We have to export the signal before destroying the wrapped texture else it's an assertion
// failure // failure
void IgnoreSignalSemaphore(dawn::Device device, dawn::Texture wrappedTexture) { void IgnoreSignalSemaphore(wgpu::Device device, wgpu::Texture wrappedTexture) {
int fd = dawn_native::vulkan::ExportSignalSemaphoreOpaqueFD(device.Get(), int fd = dawn_native::vulkan::ExportSignalSemaphoreOpaqueFD(device.Get(),
wrappedTexture.Get()); wrappedTexture.Get());
ASSERT_NE(fd, -1); ASSERT_NE(fd, -1);
@ -207,14 +207,14 @@ class VulkanImageWrappingValidationTests : public VulkanImageWrappingTestBase {
CreateBindExportImage(deviceVk, 1, 1, VK_FORMAT_R8G8B8A8_UNORM, &defaultImage, CreateBindExportImage(deviceVk, 1, 1, VK_FORMAT_R8G8B8A8_UNORM, &defaultImage,
&defaultAllocation, &defaultAllocationSize, &defaultMemoryTypeIndex, &defaultAllocation, &defaultAllocationSize, &defaultMemoryTypeIndex,
&defaultFd); &defaultFd);
defaultDescriptor.dimension = dawn::TextureDimension::e2D; defaultDescriptor.dimension = wgpu::TextureDimension::e2D;
defaultDescriptor.format = dawn::TextureFormat::RGBA8Unorm; defaultDescriptor.format = wgpu::TextureFormat::RGBA8Unorm;
defaultDescriptor.size = {1, 1, 1}; defaultDescriptor.size = {1, 1, 1};
defaultDescriptor.sampleCount = 1; defaultDescriptor.sampleCount = 1;
defaultDescriptor.arrayLayerCount = 1; defaultDescriptor.arrayLayerCount = 1;
defaultDescriptor.mipLevelCount = 1; defaultDescriptor.mipLevelCount = 1;
defaultDescriptor.usage = dawn::TextureUsage::OutputAttachment | defaultDescriptor.usage = wgpu::TextureUsage::OutputAttachment |
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst; wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst;
} }
void TearDown() override { void TearDown() override {
@ -229,7 +229,7 @@ class VulkanImageWrappingValidationTests : public VulkanImageWrappingTestBase {
} }
protected: protected:
dawn::TextureDescriptor defaultDescriptor; wgpu::TextureDescriptor defaultDescriptor;
VkImage defaultImage; VkImage defaultImage;
VkDeviceMemory defaultAllocation; VkDeviceMemory defaultAllocation;
VkDeviceSize defaultAllocationSize; VkDeviceSize defaultAllocationSize;
@ -240,7 +240,7 @@ class VulkanImageWrappingValidationTests : public VulkanImageWrappingTestBase {
// Test no error occurs if the import is valid // Test no error occurs if the import is valid
TEST_P(VulkanImageWrappingValidationTests, SuccessfulImport) { TEST_P(VulkanImageWrappingValidationTests, SuccessfulImport) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
dawn::Texture texture = wgpu::Texture texture =
WrapVulkanImage(device, &defaultDescriptor, defaultFd, defaultAllocationSize, WrapVulkanImage(device, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}, true, true); defaultMemoryTypeIndex, {}, true, true);
EXPECT_NE(texture.Get(), nullptr); EXPECT_NE(texture.Get(), nullptr);
@ -250,7 +250,7 @@ TEST_P(VulkanImageWrappingValidationTests, SuccessfulImport) {
// Test an error occurs if the texture descriptor is missing // Test an error occurs if the texture descriptor is missing
TEST_P(VulkanImageWrappingValidationTests, MissingTextureDescriptor) { TEST_P(VulkanImageWrappingValidationTests, MissingTextureDescriptor) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
ASSERT_DEVICE_ERROR(dawn::Texture texture = ASSERT_DEVICE_ERROR(wgpu::Texture texture =
WrapVulkanImage(device, nullptr, defaultFd, defaultAllocationSize, WrapVulkanImage(device, nullptr, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}, true, false)); defaultMemoryTypeIndex, {}, true, false));
EXPECT_EQ(texture.Get(), nullptr); EXPECT_EQ(texture.Get(), nullptr);
@ -261,7 +261,7 @@ TEST_P(VulkanImageWrappingValidationTests, InvalidTextureDescriptor) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
defaultDescriptor.nextInChain = this; defaultDescriptor.nextInChain = this;
ASSERT_DEVICE_ERROR(dawn::Texture texture = WrapVulkanImage( ASSERT_DEVICE_ERROR(wgpu::Texture texture = WrapVulkanImage(
device, &defaultDescriptor, defaultFd, defaultAllocationSize, device, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}, true, false)); defaultMemoryTypeIndex, {}, true, false));
EXPECT_EQ(texture.Get(), nullptr); EXPECT_EQ(texture.Get(), nullptr);
@ -270,9 +270,9 @@ TEST_P(VulkanImageWrappingValidationTests, InvalidTextureDescriptor) {
// Test an error occurs if the descriptor dimension isn't 2D // Test an error occurs if the descriptor dimension isn't 2D
TEST_P(VulkanImageWrappingValidationTests, InvalidTextureDimension) { TEST_P(VulkanImageWrappingValidationTests, InvalidTextureDimension) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
defaultDescriptor.dimension = dawn::TextureDimension::e1D; defaultDescriptor.dimension = wgpu::TextureDimension::e1D;
ASSERT_DEVICE_ERROR(dawn::Texture texture = WrapVulkanImage( ASSERT_DEVICE_ERROR(wgpu::Texture texture = WrapVulkanImage(
device, &defaultDescriptor, defaultFd, defaultAllocationSize, device, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}, true, false)); defaultMemoryTypeIndex, {}, true, false));
EXPECT_EQ(texture.Get(), nullptr); EXPECT_EQ(texture.Get(), nullptr);
@ -283,7 +283,7 @@ TEST_P(VulkanImageWrappingValidationTests, InvalidMipLevelCount) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
defaultDescriptor.mipLevelCount = 2; defaultDescriptor.mipLevelCount = 2;
ASSERT_DEVICE_ERROR(dawn::Texture texture = WrapVulkanImage( ASSERT_DEVICE_ERROR(wgpu::Texture texture = WrapVulkanImage(
device, &defaultDescriptor, defaultFd, defaultAllocationSize, device, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}, true, false)); defaultMemoryTypeIndex, {}, true, false));
EXPECT_EQ(texture.Get(), nullptr); EXPECT_EQ(texture.Get(), nullptr);
@ -294,7 +294,7 @@ TEST_P(VulkanImageWrappingValidationTests, InvalidArrayLayerCount) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
defaultDescriptor.arrayLayerCount = 2; defaultDescriptor.arrayLayerCount = 2;
ASSERT_DEVICE_ERROR(dawn::Texture texture = WrapVulkanImage( ASSERT_DEVICE_ERROR(wgpu::Texture texture = WrapVulkanImage(
device, &defaultDescriptor, defaultFd, defaultAllocationSize, device, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}, true, false)); defaultMemoryTypeIndex, {}, true, false));
EXPECT_EQ(texture.Get(), nullptr); EXPECT_EQ(texture.Get(), nullptr);
@ -305,7 +305,7 @@ TEST_P(VulkanImageWrappingValidationTests, InvalidSampleCount) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
defaultDescriptor.sampleCount = 4; defaultDescriptor.sampleCount = 4;
ASSERT_DEVICE_ERROR(dawn::Texture texture = WrapVulkanImage( ASSERT_DEVICE_ERROR(wgpu::Texture texture = WrapVulkanImage(
device, &defaultDescriptor, defaultFd, defaultAllocationSize, device, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}, true, false)); defaultMemoryTypeIndex, {}, true, false));
EXPECT_EQ(texture.Get(), nullptr); EXPECT_EQ(texture.Get(), nullptr);
@ -314,7 +314,7 @@ TEST_P(VulkanImageWrappingValidationTests, InvalidSampleCount) {
// Test an error occurs if we try to export the signal semaphore twice // Test an error occurs if we try to export the signal semaphore twice
TEST_P(VulkanImageWrappingValidationTests, DoubleSignalSemaphoreExport) { TEST_P(VulkanImageWrappingValidationTests, DoubleSignalSemaphoreExport) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
dawn::Texture texture = wgpu::Texture texture =
WrapVulkanImage(device, &defaultDescriptor, defaultFd, defaultAllocationSize, WrapVulkanImage(device, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}, true, true); defaultMemoryTypeIndex, {}, true, true);
ASSERT_NE(texture.Get(), nullptr); ASSERT_NE(texture.Get(), nullptr);
@ -327,7 +327,7 @@ TEST_P(VulkanImageWrappingValidationTests, DoubleSignalSemaphoreExport) {
// Test an error occurs if we try to export the signal semaphore from a normal texture // Test an error occurs if we try to export the signal semaphore from a normal texture
TEST_P(VulkanImageWrappingValidationTests, NormalTextureSignalSemaphoreExport) { TEST_P(VulkanImageWrappingValidationTests, NormalTextureSignalSemaphoreExport) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
dawn::Texture texture = device.CreateTexture(&defaultDescriptor); wgpu::Texture texture = device.CreateTexture(&defaultDescriptor);
ASSERT_NE(texture.Get(), nullptr); ASSERT_NE(texture.Get(), nullptr);
ASSERT_DEVICE_ERROR( ASSERT_DEVICE_ERROR(
int fd = dawn_native::vulkan::ExportSignalSemaphoreOpaqueFD(device.Get(), texture.Get())); int fd = dawn_native::vulkan::ExportSignalSemaphoreOpaqueFD(device.Get(), texture.Get()));
@ -337,7 +337,7 @@ TEST_P(VulkanImageWrappingValidationTests, NormalTextureSignalSemaphoreExport) {
// Test an error occurs if we try to export the signal semaphore from a destroyed texture // Test an error occurs if we try to export the signal semaphore from a destroyed texture
TEST_P(VulkanImageWrappingValidationTests, DestroyedTextureSignalSemaphoreExport) { TEST_P(VulkanImageWrappingValidationTests, DestroyedTextureSignalSemaphoreExport) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
dawn::Texture texture = device.CreateTexture(&defaultDescriptor); wgpu::Texture texture = device.CreateTexture(&defaultDescriptor);
ASSERT_NE(texture.Get(), nullptr); ASSERT_NE(texture.Get(), nullptr);
texture.Destroy(); texture.Destroy();
ASSERT_DEVICE_ERROR( ASSERT_DEVICE_ERROR(
@ -362,19 +362,19 @@ class VulkanImageWrappingUsageTests : public VulkanImageWrappingTestBase {
secondDeviceVk = reinterpret_cast<dawn_native::vulkan::Device*>( secondDeviceVk = reinterpret_cast<dawn_native::vulkan::Device*>(
backendAdapter->CreateDevice(&deviceDescriptor)); backendAdapter->CreateDevice(&deviceDescriptor));
secondDevice = dawn::Device::Acquire(reinterpret_cast<DawnDevice>(secondDeviceVk)); secondDevice = wgpu::Device::Acquire(reinterpret_cast<WGPUDevice>(secondDeviceVk));
CreateBindExportImage(deviceVk, 1, 1, VK_FORMAT_R8G8B8A8_UNORM, &defaultImage, CreateBindExportImage(deviceVk, 1, 1, VK_FORMAT_R8G8B8A8_UNORM, &defaultImage,
&defaultAllocation, &defaultAllocationSize, &defaultMemoryTypeIndex, &defaultAllocation, &defaultAllocationSize, &defaultMemoryTypeIndex,
&defaultFd); &defaultFd);
defaultDescriptor.dimension = dawn::TextureDimension::e2D; defaultDescriptor.dimension = wgpu::TextureDimension::e2D;
defaultDescriptor.format = dawn::TextureFormat::RGBA8Unorm; defaultDescriptor.format = wgpu::TextureFormat::RGBA8Unorm;
defaultDescriptor.size = {1, 1, 1}; defaultDescriptor.size = {1, 1, 1};
defaultDescriptor.sampleCount = 1; defaultDescriptor.sampleCount = 1;
defaultDescriptor.arrayLayerCount = 1; defaultDescriptor.arrayLayerCount = 1;
defaultDescriptor.mipLevelCount = 1; defaultDescriptor.mipLevelCount = 1;
defaultDescriptor.usage = dawn::TextureUsage::OutputAttachment | defaultDescriptor.usage = wgpu::TextureUsage::OutputAttachment |
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst; wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst;
} }
void TearDown() override { void TearDown() override {
@ -389,13 +389,13 @@ class VulkanImageWrappingUsageTests : public VulkanImageWrappingTestBase {
} }
protected: protected:
dawn::Device secondDevice; wgpu::Device secondDevice;
dawn_native::vulkan::Device* secondDeviceVk; dawn_native::vulkan::Device* secondDeviceVk;
dawn_native::vulkan::Adapter* backendAdapter; dawn_native::vulkan::Adapter* backendAdapter;
dawn_native::DeviceDescriptor deviceDescriptor; dawn_native::DeviceDescriptor deviceDescriptor;
dawn::TextureDescriptor defaultDescriptor; wgpu::TextureDescriptor defaultDescriptor;
VkImage defaultImage; VkImage defaultImage;
VkDeviceMemory defaultAllocation; VkDeviceMemory defaultAllocation;
VkDeviceSize defaultAllocationSize; VkDeviceSize defaultAllocationSize;
@ -403,45 +403,45 @@ class VulkanImageWrappingUsageTests : public VulkanImageWrappingTestBase {
int defaultFd; int defaultFd;
// Clear a texture on a given device // Clear a texture on a given device
void ClearImage(dawn::Device device, dawn::Texture wrappedTexture, dawn::Color clearColor) { void ClearImage(wgpu::Device device, wgpu::Texture wrappedTexture, wgpu::Color clearColor) {
dawn::TextureView wrappedView = wrappedTexture.CreateView(); wgpu::TextureView wrappedView = wrappedTexture.CreateView();
// Submit a clear operation // Submit a clear operation
utils::ComboRenderPassDescriptor renderPassDescriptor({wrappedView}, {}); utils::ComboRenderPassDescriptor renderPassDescriptor({wrappedView}, {});
renderPassDescriptor.cColorAttachments[0].clearColor = clearColor; renderPassDescriptor.cColorAttachments[0].clearColor = clearColor;
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor);
pass.EndPass(); pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
dawn::Queue queue = device.CreateQueue(); wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commands); queue.Submit(1, &commands);
} }
// Submits a 1x1x1 copy from source to destination // Submits a 1x1x1 copy from source to destination
void SimpleCopyTextureToTexture(dawn::Device device, void SimpleCopyTextureToTexture(wgpu::Device device,
dawn::Queue queue, wgpu::Queue queue,
dawn::Texture source, wgpu::Texture source,
dawn::Texture destination) { wgpu::Texture destination) {
dawn::TextureCopyView copySrc; wgpu::TextureCopyView copySrc;
copySrc.texture = source; copySrc.texture = source;
copySrc.mipLevel = 0; copySrc.mipLevel = 0;
copySrc.arrayLayer = 0; copySrc.arrayLayer = 0;
copySrc.origin = {0, 0, 0}; copySrc.origin = {0, 0, 0};
dawn::TextureCopyView copyDst; wgpu::TextureCopyView copyDst;
copyDst.texture = destination; copyDst.texture = destination;
copyDst.mipLevel = 0; copyDst.mipLevel = 0;
copyDst.arrayLayer = 0; copyDst.arrayLayer = 0;
copyDst.origin = {0, 0, 0}; copyDst.origin = {0, 0, 0};
dawn::Extent3D copySize = {1, 1, 1}; wgpu::Extent3D copySize = {1, 1, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToTexture(&copySrc, &copyDst, &copySize); encoder.CopyTextureToTexture(&copySrc, &copyDst, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
} }
@ -453,7 +453,7 @@ TEST_P(VulkanImageWrappingUsageTests, ClearImageAcrossDevices) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
// Import the image on |secondDevice| // Import the image on |secondDevice|
dawn::Texture wrappedTexture = wgpu::Texture wrappedTexture =
WrapVulkanImage(secondDevice, &defaultDescriptor, defaultFd, defaultAllocationSize, WrapVulkanImage(secondDevice, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}); defaultMemoryTypeIndex, {});
@ -465,7 +465,7 @@ TEST_P(VulkanImageWrappingUsageTests, ClearImageAcrossDevices) {
// Import the image to |device|, making sure we wait on signalFd // Import the image to |device|, making sure we wait on signalFd
int memoryFd = GetMemoryFd(deviceVk, defaultAllocation); int memoryFd = GetMemoryFd(deviceVk, defaultAllocation);
dawn::Texture nextWrappedTexture = wgpu::Texture nextWrappedTexture =
WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize, WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize,
defaultMemoryTypeIndex, {signalFd}); defaultMemoryTypeIndex, {signalFd});
@ -483,13 +483,13 @@ TEST_P(VulkanImageWrappingUsageTests, ClearImageAcrossDevices) {
TEST_P(VulkanImageWrappingUsageTests, ClearImageAcrossDevicesAliased) { TEST_P(VulkanImageWrappingUsageTests, ClearImageAcrossDevicesAliased) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
// Import the image on |device // Import the image on |device
dawn::Texture wrappedTextureAlias = WrapVulkanImage( wgpu::Texture wrappedTextureAlias = WrapVulkanImage(
device, &defaultDescriptor, defaultFd, defaultAllocationSize, defaultMemoryTypeIndex, {}); device, &defaultDescriptor, defaultFd, defaultAllocationSize, defaultMemoryTypeIndex, {});
int memoryFd = GetMemoryFd(deviceVk, defaultAllocation); int memoryFd = GetMemoryFd(deviceVk, defaultAllocation);
// Import the image on |secondDevice| // Import the image on |secondDevice|
dawn::Texture wrappedTexture = wgpu::Texture wrappedTexture =
WrapVulkanImage(secondDevice, &defaultDescriptor, defaultFd, defaultAllocationSize, WrapVulkanImage(secondDevice, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}); defaultMemoryTypeIndex, {});
@ -501,7 +501,7 @@ TEST_P(VulkanImageWrappingUsageTests, ClearImageAcrossDevicesAliased) {
// Import the image to |device|, making sure we wait on signalFd // Import the image to |device|, making sure we wait on signalFd
memoryFd = GetMemoryFd(deviceVk, defaultAllocation); memoryFd = GetMemoryFd(deviceVk, defaultAllocation);
dawn::Texture nextWrappedTexture = wgpu::Texture nextWrappedTexture =
WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize, WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize,
defaultMemoryTypeIndex, {signalFd}); defaultMemoryTypeIndex, {signalFd});
@ -521,7 +521,7 @@ TEST_P(VulkanImageWrappingUsageTests, UnclearedTextureIsCleared) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
// Import the image on |secondDevice| // Import the image on |secondDevice|
dawn::Texture wrappedTexture = wgpu::Texture wrappedTexture =
WrapVulkanImage(secondDevice, &defaultDescriptor, defaultFd, defaultAllocationSize, WrapVulkanImage(secondDevice, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}); defaultMemoryTypeIndex, {});
@ -533,7 +533,7 @@ TEST_P(VulkanImageWrappingUsageTests, UnclearedTextureIsCleared) {
// Import the image to |device|, making sure we wait on signalFd // Import the image to |device|, making sure we wait on signalFd
int memoryFd = GetMemoryFd(deviceVk, defaultAllocation); int memoryFd = GetMemoryFd(deviceVk, defaultAllocation);
dawn::Texture nextWrappedTexture = wgpu::Texture nextWrappedTexture =
WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize, WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize,
defaultMemoryTypeIndex, {signalFd}, false); defaultMemoryTypeIndex, {signalFd}, false);
@ -550,7 +550,7 @@ TEST_P(VulkanImageWrappingUsageTests, CopyTextureToTextureSrcSync) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
// Import the image on |secondDevice| // Import the image on |secondDevice|
dawn::Texture wrappedTexture = wgpu::Texture wrappedTexture =
WrapVulkanImage(secondDevice, &defaultDescriptor, defaultFd, defaultAllocationSize, WrapVulkanImage(secondDevice, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}); defaultMemoryTypeIndex, {});
@ -562,12 +562,12 @@ TEST_P(VulkanImageWrappingUsageTests, CopyTextureToTextureSrcSync) {
// Import the image to |device|, making sure we wait on |signalFd| // Import the image to |device|, making sure we wait on |signalFd|
int memoryFd = GetMemoryFd(deviceVk, defaultAllocation); int memoryFd = GetMemoryFd(deviceVk, defaultAllocation);
dawn::Texture deviceWrappedTexture = wgpu::Texture deviceWrappedTexture =
WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize, WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize,
defaultMemoryTypeIndex, {signalFd}); defaultMemoryTypeIndex, {signalFd});
// Create a second texture on |device| // Create a second texture on |device|
dawn::Texture copyDstTexture = device.CreateTexture(&defaultDescriptor); wgpu::Texture copyDstTexture = device.CreateTexture(&defaultDescriptor);
// Copy |deviceWrappedTexture| into |copyDstTexture| // Copy |deviceWrappedTexture| into |copyDstTexture|
SimpleCopyTextureToTexture(device, queue, deviceWrappedTexture, copyDstTexture); SimpleCopyTextureToTexture(device, queue, deviceWrappedTexture, copyDstTexture);
@ -590,7 +590,7 @@ TEST_P(VulkanImageWrappingUsageTests, CopyTextureToTextureDstSync) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
// Import the image on |device| // Import the image on |device|
dawn::Texture wrappedTexture = WrapVulkanImage( wgpu::Texture wrappedTexture = WrapVulkanImage(
device, &defaultDescriptor, defaultFd, defaultAllocationSize, defaultMemoryTypeIndex, {}); device, &defaultDescriptor, defaultFd, defaultAllocationSize, defaultMemoryTypeIndex, {});
// Clear |wrappedTexture| on |device| // Clear |wrappedTexture| on |device|
@ -601,16 +601,16 @@ TEST_P(VulkanImageWrappingUsageTests, CopyTextureToTextureDstSync) {
// Import the image to |secondDevice|, making sure we wait on |signalFd| // Import the image to |secondDevice|, making sure we wait on |signalFd|
int memoryFd = GetMemoryFd(deviceVk, defaultAllocation); int memoryFd = GetMemoryFd(deviceVk, defaultAllocation);
dawn::Texture secondDeviceWrappedTexture = wgpu::Texture secondDeviceWrappedTexture =
WrapVulkanImage(secondDevice, &defaultDescriptor, memoryFd, defaultAllocationSize, WrapVulkanImage(secondDevice, &defaultDescriptor, memoryFd, defaultAllocationSize,
defaultMemoryTypeIndex, {signalFd}); defaultMemoryTypeIndex, {signalFd});
// Create a texture with color B on |secondDevice| // Create a texture with color B on |secondDevice|
dawn::Texture copySrcTexture = secondDevice.CreateTexture(&defaultDescriptor); wgpu::Texture copySrcTexture = secondDevice.CreateTexture(&defaultDescriptor);
ClearImage(secondDevice, copySrcTexture, {1 / 255.0f, 2 / 255.0f, 3 / 255.0f, 4 / 255.0f}); ClearImage(secondDevice, copySrcTexture, {1 / 255.0f, 2 / 255.0f, 3 / 255.0f, 4 / 255.0f});
// Copy color B on |secondDevice| // Copy color B on |secondDevice|
dawn::Queue secondDeviceQueue = secondDevice.CreateQueue(); wgpu::Queue secondDeviceQueue = secondDevice.CreateQueue();
SimpleCopyTextureToTexture(secondDevice, secondDeviceQueue, copySrcTexture, SimpleCopyTextureToTexture(secondDevice, secondDeviceQueue, copySrcTexture,
secondDeviceWrappedTexture); secondDeviceWrappedTexture);
@ -619,7 +619,7 @@ TEST_P(VulkanImageWrappingUsageTests, CopyTextureToTextureDstSync) {
secondDeviceWrappedTexture.Get()); secondDeviceWrappedTexture.Get());
memoryFd = GetMemoryFd(deviceVk, defaultAllocation); memoryFd = GetMemoryFd(deviceVk, defaultAllocation);
dawn::Texture nextWrappedTexture = wgpu::Texture nextWrappedTexture =
WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize, WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize,
defaultMemoryTypeIndex, {signalFd}); defaultMemoryTypeIndex, {signalFd});
@ -636,7 +636,7 @@ TEST_P(VulkanImageWrappingUsageTests, CopyTextureToBufferSrcSync) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
// Import the image on |secondDevice| // Import the image on |secondDevice|
dawn::Texture wrappedTexture = wgpu::Texture wrappedTexture =
WrapVulkanImage(secondDevice, &defaultDescriptor, defaultFd, defaultAllocationSize, WrapVulkanImage(secondDevice, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}); defaultMemoryTypeIndex, {});
@ -648,34 +648,34 @@ TEST_P(VulkanImageWrappingUsageTests, CopyTextureToBufferSrcSync) {
// Import the image to |device|, making sure we wait on |signalFd| // Import the image to |device|, making sure we wait on |signalFd|
int memoryFd = GetMemoryFd(deviceVk, defaultAllocation); int memoryFd = GetMemoryFd(deviceVk, defaultAllocation);
dawn::Texture deviceWrappedTexture = wgpu::Texture deviceWrappedTexture =
WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize, WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize,
defaultMemoryTypeIndex, {signalFd}); defaultMemoryTypeIndex, {signalFd});
// Create a destination buffer on |device| // Create a destination buffer on |device|
dawn::BufferDescriptor bufferDesc; wgpu::BufferDescriptor bufferDesc;
bufferDesc.size = 4; bufferDesc.size = 4;
bufferDesc.usage = dawn::BufferUsage::CopyDst | dawn::BufferUsage::CopySrc; bufferDesc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::CopySrc;
dawn::Buffer copyDstBuffer = device.CreateBuffer(&bufferDesc); wgpu::Buffer copyDstBuffer = device.CreateBuffer(&bufferDesc);
// Copy |deviceWrappedTexture| into |copyDstBuffer| // Copy |deviceWrappedTexture| into |copyDstBuffer|
dawn::TextureCopyView copySrc; wgpu::TextureCopyView copySrc;
copySrc.texture = deviceWrappedTexture; copySrc.texture = deviceWrappedTexture;
copySrc.mipLevel = 0; copySrc.mipLevel = 0;
copySrc.arrayLayer = 0; copySrc.arrayLayer = 0;
copySrc.origin = {0, 0, 0}; copySrc.origin = {0, 0, 0};
dawn::BufferCopyView copyDst; wgpu::BufferCopyView copyDst;
copyDst.buffer = copyDstBuffer; copyDst.buffer = copyDstBuffer;
copyDst.offset = 0; copyDst.offset = 0;
copyDst.rowPitch = 256; copyDst.rowPitch = 256;
copyDst.imageHeight = 0; copyDst.imageHeight = 0;
dawn::Extent3D copySize = {1, 1, 1}; wgpu::Extent3D copySize = {1, 1, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&copySrc, &copyDst, &copySize); encoder.CopyTextureToBuffer(&copySrc, &copyDst, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
// Verify |copyDstBuffer| sees changes from |secondDevice| // Verify |copyDstBuffer| sees changes from |secondDevice|
@ -697,7 +697,7 @@ TEST_P(VulkanImageWrappingUsageTests, CopyBufferToTextureDstSync) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
// Import the image on |device| // Import the image on |device|
dawn::Texture wrappedTexture = WrapVulkanImage( wgpu::Texture wrappedTexture = WrapVulkanImage(
device, &defaultDescriptor, defaultFd, defaultAllocationSize, defaultMemoryTypeIndex, {}); device, &defaultDescriptor, defaultFd, defaultAllocationSize, defaultMemoryTypeIndex, {});
// Clear |wrappedTexture| on |device| // Clear |wrappedTexture| on |device|
@ -708,35 +708,35 @@ TEST_P(VulkanImageWrappingUsageTests, CopyBufferToTextureDstSync) {
// Import the image to |secondDevice|, making sure we wait on |signalFd| // Import the image to |secondDevice|, making sure we wait on |signalFd|
int memoryFd = GetMemoryFd(deviceVk, defaultAllocation); int memoryFd = GetMemoryFd(deviceVk, defaultAllocation);
dawn::Texture secondDeviceWrappedTexture = wgpu::Texture secondDeviceWrappedTexture =
WrapVulkanImage(secondDevice, &defaultDescriptor, memoryFd, defaultAllocationSize, WrapVulkanImage(secondDevice, &defaultDescriptor, memoryFd, defaultAllocationSize,
defaultMemoryTypeIndex, {signalFd}); defaultMemoryTypeIndex, {signalFd});
// Copy color B on |secondDevice| // Copy color B on |secondDevice|
dawn::Queue secondDeviceQueue = secondDevice.CreateQueue(); wgpu::Queue secondDeviceQueue = secondDevice.CreateQueue();
// Create a buffer on |secondDevice| // Create a buffer on |secondDevice|
dawn::Buffer copySrcBuffer = wgpu::Buffer copySrcBuffer =
utils::CreateBufferFromData(secondDevice, dawn::BufferUsage::CopySrc, {0x04030201}); utils::CreateBufferFromData(secondDevice, wgpu::BufferUsage::CopySrc, {0x04030201});
// Copy |copySrcBuffer| into |secondDeviceWrappedTexture| // Copy |copySrcBuffer| into |secondDeviceWrappedTexture|
dawn::BufferCopyView copySrc; wgpu::BufferCopyView copySrc;
copySrc.buffer = copySrcBuffer; copySrc.buffer = copySrcBuffer;
copySrc.offset = 0; copySrc.offset = 0;
copySrc.rowPitch = 256; copySrc.rowPitch = 256;
copySrc.imageHeight = 0; copySrc.imageHeight = 0;
dawn::TextureCopyView copyDst; wgpu::TextureCopyView copyDst;
copyDst.texture = secondDeviceWrappedTexture; copyDst.texture = secondDeviceWrappedTexture;
copyDst.mipLevel = 0; copyDst.mipLevel = 0;
copyDst.arrayLayer = 0; copyDst.arrayLayer = 0;
copyDst.origin = {0, 0, 0}; copyDst.origin = {0, 0, 0};
dawn::Extent3D copySize = {1, 1, 1}; wgpu::Extent3D copySize = {1, 1, 1};
dawn::CommandEncoder encoder = secondDevice.CreateCommandEncoder(); wgpu::CommandEncoder encoder = secondDevice.CreateCommandEncoder();
encoder.CopyBufferToTexture(&copySrc, &copyDst, &copySize); encoder.CopyBufferToTexture(&copySrc, &copyDst, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
secondDeviceQueue.Submit(1, &commands); secondDeviceQueue.Submit(1, &commands);
// Re-import back into |device|, waiting on |secondDevice|'s signal // Re-import back into |device|, waiting on |secondDevice|'s signal
@ -744,7 +744,7 @@ TEST_P(VulkanImageWrappingUsageTests, CopyBufferToTextureDstSync) {
secondDeviceWrappedTexture.Get()); secondDeviceWrappedTexture.Get());
memoryFd = GetMemoryFd(deviceVk, defaultAllocation); memoryFd = GetMemoryFd(deviceVk, defaultAllocation);
dawn::Texture nextWrappedTexture = wgpu::Texture nextWrappedTexture =
WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize, WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize,
defaultMemoryTypeIndex, {signalFd}); defaultMemoryTypeIndex, {signalFd});
@ -762,7 +762,7 @@ TEST_P(VulkanImageWrappingUsageTests, DoubleTextureUsage) {
DAWN_SKIP_TEST_IF(UsesWire() || IsIntel()); DAWN_SKIP_TEST_IF(UsesWire() || IsIntel());
// Import the image on |secondDevice| // Import the image on |secondDevice|
dawn::Texture wrappedTexture = wgpu::Texture wrappedTexture =
WrapVulkanImage(secondDevice, &defaultDescriptor, defaultFd, defaultAllocationSize, WrapVulkanImage(secondDevice, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}); defaultMemoryTypeIndex, {});
@ -774,15 +774,15 @@ TEST_P(VulkanImageWrappingUsageTests, DoubleTextureUsage) {
// Import the image to |device|, making sure we wait on |signalFd| // Import the image to |device|, making sure we wait on |signalFd|
int memoryFd = GetMemoryFd(deviceVk, defaultAllocation); int memoryFd = GetMemoryFd(deviceVk, defaultAllocation);
dawn::Texture deviceWrappedTexture = wgpu::Texture deviceWrappedTexture =
WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize, WrapVulkanImage(device, &defaultDescriptor, memoryFd, defaultAllocationSize,
defaultMemoryTypeIndex, {signalFd}); defaultMemoryTypeIndex, {signalFd});
// Create a second texture on |device| // Create a second texture on |device|
dawn::Texture copyDstTexture = device.CreateTexture(&defaultDescriptor); wgpu::Texture copyDstTexture = device.CreateTexture(&defaultDescriptor);
// Create a third texture on |device| // Create a third texture on |device|
dawn::Texture secondCopyDstTexture = device.CreateTexture(&defaultDescriptor); wgpu::Texture secondCopyDstTexture = device.CreateTexture(&defaultDescriptor);
// Copy |deviceWrappedTexture| into |copyDstTexture| // Copy |deviceWrappedTexture| into |copyDstTexture|
SimpleCopyTextureToTexture(device, queue, deviceWrappedTexture, copyDstTexture); SimpleCopyTextureToTexture(device, queue, deviceWrappedTexture, copyDstTexture);
@ -818,11 +818,11 @@ TEST_P(VulkanImageWrappingUsageTests, ChainTextureCopy) {
// Create device 3 // Create device 3
dawn_native::vulkan::Device* thirdDeviceVk = reinterpret_cast<dawn_native::vulkan::Device*>( dawn_native::vulkan::Device* thirdDeviceVk = reinterpret_cast<dawn_native::vulkan::Device*>(
backendAdapter->CreateDevice(&deviceDescriptor)); backendAdapter->CreateDevice(&deviceDescriptor));
dawn::Device thirdDevice = dawn::Device::Acquire(reinterpret_cast<DawnDevice>(thirdDeviceVk)); wgpu::Device thirdDevice = wgpu::Device::Acquire(reinterpret_cast<WGPUDevice>(thirdDeviceVk));
// Make queue for device 2 and 3 // Make queue for device 2 and 3
dawn::Queue secondDeviceQueue = secondDevice.CreateQueue(); wgpu::Queue secondDeviceQueue = secondDevice.CreateQueue();
dawn::Queue thirdDeviceQueue = thirdDevice.CreateQueue(); wgpu::Queue thirdDeviceQueue = thirdDevice.CreateQueue();
// Allocate memory for A, B, C // Allocate memory for A, B, C
VkImage imageA; VkImage imageA;
@ -850,10 +850,10 @@ TEST_P(VulkanImageWrappingUsageTests, ChainTextureCopy) {
&allocationSizeC, &memoryTypeIndexC, &memoryFdC); &allocationSizeC, &memoryTypeIndexC, &memoryFdC);
// Import TexA, TexB on device 3 // Import TexA, TexB on device 3
dawn::Texture wrappedTexADevice3 = WrapVulkanImage(thirdDevice, &defaultDescriptor, memoryFdA, wgpu::Texture wrappedTexADevice3 = WrapVulkanImage(thirdDevice, &defaultDescriptor, memoryFdA,
allocationSizeA, memoryTypeIndexA, {}); allocationSizeA, memoryTypeIndexA, {});
dawn::Texture wrappedTexBDevice3 = WrapVulkanImage(thirdDevice, &defaultDescriptor, memoryFdB, wgpu::Texture wrappedTexBDevice3 = WrapVulkanImage(thirdDevice, &defaultDescriptor, memoryFdB,
allocationSizeB, memoryTypeIndexB, {}); allocationSizeB, memoryTypeIndexB, {});
// Clear TexA // Clear TexA
@ -869,11 +869,11 @@ TEST_P(VulkanImageWrappingUsageTests, ChainTextureCopy) {
// Import TexB, TexC on device 2 // Import TexB, TexC on device 2
memoryFdB = GetMemoryFd(secondDeviceVk, allocationB); memoryFdB = GetMemoryFd(secondDeviceVk, allocationB);
dawn::Texture wrappedTexBDevice2 = wgpu::Texture wrappedTexBDevice2 =
WrapVulkanImage(secondDevice, &defaultDescriptor, memoryFdB, allocationSizeB, WrapVulkanImage(secondDevice, &defaultDescriptor, memoryFdB, allocationSizeB,
memoryTypeIndexB, {signalFdTexBDevice3}); memoryTypeIndexB, {signalFdTexBDevice3});
dawn::Texture wrappedTexCDevice2 = WrapVulkanImage(secondDevice, &defaultDescriptor, memoryFdC, wgpu::Texture wrappedTexCDevice2 = WrapVulkanImage(secondDevice, &defaultDescriptor, memoryFdC,
allocationSizeC, memoryTypeIndexC, {}); allocationSizeC, memoryTypeIndexC, {});
// Copy B->C on device 2 // Copy B->C on device 2
@ -886,12 +886,12 @@ TEST_P(VulkanImageWrappingUsageTests, ChainTextureCopy) {
// Import TexC on device 1 // Import TexC on device 1
memoryFdC = GetMemoryFd(deviceVk, allocationC); memoryFdC = GetMemoryFd(deviceVk, allocationC);
dawn::Texture wrappedTexCDevice1 = wgpu::Texture wrappedTexCDevice1 =
WrapVulkanImage(device, &defaultDescriptor, memoryFdC, allocationSizeC, memoryTypeIndexC, WrapVulkanImage(device, &defaultDescriptor, memoryFdC, allocationSizeC, memoryTypeIndexC,
{signalFdTexCDevice2}); {signalFdTexCDevice2});
// Create TexD on device 1 // Create TexD on device 1
dawn::Texture texD = device.CreateTexture(&defaultDescriptor); wgpu::Texture texD = device.CreateTexture(&defaultDescriptor);
// Copy C->D on device 1 // Copy C->D on device 1
SimpleCopyTextureToTexture(device, queue, wrappedTexCDevice1, texD); SimpleCopyTextureToTexture(device, queue, wrappedTexCDevice1, texD);
@ -916,24 +916,24 @@ TEST_P(VulkanImageWrappingUsageTests, LargerImage) {
close(defaultFd); close(defaultFd);
dawn::TextureDescriptor descriptor; wgpu::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D; descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = 640; descriptor.size.width = 640;
descriptor.size.height = 480; descriptor.size.height = 480;
descriptor.size.depth = 1; descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1; descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1; descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::BGRA8Unorm; descriptor.format = wgpu::TextureFormat::BGRA8Unorm;
descriptor.mipLevelCount = 1; descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::CopyDst | dawn::TextureUsage::CopySrc; descriptor.usage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc;
// Fill memory with textures to trigger layout issues on AMD // Fill memory with textures to trigger layout issues on AMD
std::vector<dawn::Texture> textures; std::vector<wgpu::Texture> textures;
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
textures.push_back(device.CreateTexture(&descriptor)); textures.push_back(device.CreateTexture(&descriptor));
} }
dawn::Queue secondDeviceQueue = secondDevice.CreateQueue(); wgpu::Queue secondDeviceQueue = secondDevice.CreateQueue();
// Make an image on |secondDevice| // Make an image on |secondDevice|
VkImage imageA; VkImage imageA;
@ -945,7 +945,7 @@ TEST_P(VulkanImageWrappingUsageTests, LargerImage) {
&allocationSizeA, &memoryTypeIndexA, &memoryFdA); &allocationSizeA, &memoryTypeIndexA, &memoryFdA);
// Import the image on |secondDevice| // Import the image on |secondDevice|
dawn::Texture wrappedTexture = WrapVulkanImage(secondDevice, &descriptor, memoryFdA, wgpu::Texture wrappedTexture = WrapVulkanImage(secondDevice, &descriptor, memoryFdA,
allocationSizeA, memoryTypeIndexA, {}); allocationSizeA, memoryTypeIndexA, {});
// Draw a non-trivial picture // Draw a non-trivial picture
@ -968,16 +968,16 @@ TEST_P(VulkanImageWrappingUsageTests, LargerImage) {
// Write the picture // Write the picture
{ {
dawn::Buffer copySrcBuffer = wgpu::Buffer copySrcBuffer =
utils::CreateBufferFromData(secondDevice, data, size, dawn::BufferUsage::CopySrc); utils::CreateBufferFromData(secondDevice, data, size, wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView copySrc = utils::CreateBufferCopyView(copySrcBuffer, 0, rowPitch, 0); wgpu::BufferCopyView copySrc = utils::CreateBufferCopyView(copySrcBuffer, 0, rowPitch, 0);
dawn::TextureCopyView copyDst = wgpu::TextureCopyView copyDst =
utils::CreateTextureCopyView(wrappedTexture, 0, 0, {0, 0, 0}); utils::CreateTextureCopyView(wrappedTexture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {width, height, 1}; wgpu::Extent3D copySize = {width, height, 1};
dawn::CommandEncoder encoder = secondDevice.CreateCommandEncoder(); wgpu::CommandEncoder encoder = secondDevice.CreateCommandEncoder();
encoder.CopyBufferToTexture(&copySrc, &copyDst, &copySize); encoder.CopyBufferToTexture(&copySrc, &copyDst, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
secondDeviceQueue.Submit(1, &commands); secondDeviceQueue.Submit(1, &commands);
} }
@ -986,24 +986,24 @@ TEST_P(VulkanImageWrappingUsageTests, LargerImage) {
int memoryFd = GetMemoryFd(secondDeviceVk, allocationA); int memoryFd = GetMemoryFd(secondDeviceVk, allocationA);
// Import the image on |device| // Import the image on |device|
dawn::Texture nextWrappedTexture = WrapVulkanImage( wgpu::Texture nextWrappedTexture = WrapVulkanImage(
device, &descriptor, memoryFd, allocationSizeA, memoryTypeIndexA, {signalFd}); device, &descriptor, memoryFd, allocationSizeA, memoryTypeIndexA, {signalFd});
// Copy the image into a buffer for comparison // Copy the image into a buffer for comparison
dawn::BufferDescriptor copyDesc; wgpu::BufferDescriptor copyDesc;
copyDesc.size = size; copyDesc.size = size;
copyDesc.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst; copyDesc.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
dawn::Buffer copyDstBuffer = device.CreateBuffer(&copyDesc); wgpu::Buffer copyDstBuffer = device.CreateBuffer(&copyDesc);
{ {
dawn::TextureCopyView copySrc = wgpu::TextureCopyView copySrc =
utils::CreateTextureCopyView(nextWrappedTexture, 0, 0, {0, 0, 0}); utils::CreateTextureCopyView(nextWrappedTexture, 0, 0, {0, 0, 0});
dawn::BufferCopyView copyDst = utils::CreateBufferCopyView(copyDstBuffer, 0, rowPitch, 0); wgpu::BufferCopyView copyDst = utils::CreateBufferCopyView(copyDstBuffer, 0, rowPitch, 0);
dawn::Extent3D copySize = {width, height, 1}; wgpu::Extent3D copySize = {width, height, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&copySrc, &copyDst, &copySize); encoder.CopyTextureToBuffer(&copySrc, &copyDst, &copySize);
dawn::CommandBuffer commands = encoder.Finish(); wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands); queue.Submit(1, &commands);
} }