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() {
// We need to destroy child objects before the Device
mReadbackSlots.clear();
queue = dawn::Queue();
device = dawn::Device();
queue = wgpu::Queue();
device = wgpu::Device();
mWireClient = nullptr;
mWireServer = nullptr;
@ -423,7 +423,7 @@ void DawnTestBase::SetUp() {
backendProcs = dawn_native::GetProcs();
// Choose whether to use the backend procs and devices directly, or set up the wire.
DawnDevice cDevice = nullptr;
WGPUDevice cDevice = nullptr;
DawnProcTable procs;
if (gTestEnv->UsesWire()) {
@ -442,7 +442,7 @@ void DawnTestBase::SetUp() {
clientDesc.serializer = mC2sBuf.get();
mWireClient.reset(new dawn_wire::WireClient(clientDesc));
DawnDevice clientDevice = mWireClient->GetDevice();
WGPUDevice clientDevice = mWireClient->GetDevice();
DawnProcTable clientProcs = mWireClient->GetProcs();
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
// the deferred expectations.
dawnProcSetProcs(&procs);
device = dawn::Device::Acquire(cDevice);
device = wgpu::Device::Acquire(cDevice);
queue = device.CreateQueue();
device.SetUncapturedErrorCallback(OnDeviceError, this);
@ -491,8 +491,8 @@ dawn_native::PCIInfo DawnTestBase::GetPCIInfo() const {
}
// static
void DawnTestBase::OnDeviceError(DawnErrorType type, const char* message, void* userdata) {
ASSERT(type != DAWN_ERROR_TYPE_NO_ERROR);
void DawnTestBase::OnDeviceError(WGPUErrorType type, const char* message, void* userdata) {
ASSERT(type != WGPUErrorType_NoError);
DawnTestBase* self = static_cast<DawnTestBase*>(userdata);
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,
int line,
const dawn::Buffer& buffer,
const wgpu::Buffer& buffer,
uint64_t offset,
uint64_t size,
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,
// 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);
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
DeferredExpectation deferred;
@ -533,7 +533,7 @@ std::ostringstream& DawnTestBase::AddBufferExpectation(const char* file,
std::ostringstream& DawnTestBase::AddTextureExpectation(const char* file,
int line,
const dawn::Texture& texture,
const wgpu::Texture& texture,
uint32_t x,
uint32_t y,
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,
// the texture might have been modified.
dawn::TextureCopyView textureCopyView =
wgpu::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(texture, level, slice, {x, y, 0});
dawn::BufferCopyView bufferCopyView =
wgpu::BufferCopyView bufferCopyView =
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);
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
DeferredExpectation deferred;
@ -595,9 +595,9 @@ void DawnTestBase::FlushWire() {
DawnTestBase::ReadbackReservation DawnTestBase::ReserveReadback(uint64_t readbackSize) {
// For now create a new MapRead buffer for each readback
// TODO(cwallez@chromium.org): eventually make bigger buffers and allocate linearly?
dawn::BufferDescriptor descriptor;
wgpu::BufferDescriptor descriptor;
descriptor.size = readbackSize;
descriptor.usage = dawn::BufferUsage::MapRead | dawn::BufferUsage::CopyDst;
descriptor.usage = wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst;
ReadbackSlot slot;
slot.bufferSize = readbackSize;
@ -632,11 +632,11 @@ void DawnTestBase::MapSlotsSynchronously() {
}
// static
void DawnTestBase::SlotMapReadCallback(DawnBufferMapAsyncStatus status,
void DawnTestBase::SlotMapReadCallback(WGPUBufferMapAsyncStatus status,
const void* data,
uint64_t,
void* userdata_) {
DAWN_ASSERT(status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS);
DAWN_ASSERT(status == WGPUBufferMapAsyncStatus_Success);
auto userdata = static_cast<MapReadUserdata*>(userdata_);
userdata->test->mReadbackSlots[userdata->slot].mappedData = data;

View File

@ -16,7 +16,7 @@
#define TESTS_DAWNTEST_H_
#include "dawn/dawn_proc_table.h"
#include "dawn/dawncpp.h"
#include "dawn/webgpu_cpp.h"
#include "dawn_native/DawnNative.h"
#include <gtest/gtest.h>
@ -180,22 +180,22 @@ class DawnTestBase {
dawn_native::PCIInfo GetPCIInfo() const;
protected:
dawn::Device device;
dawn::Queue queue;
wgpu::Device device;
wgpu::Queue queue;
DawnProcTable backendProcs = {};
DawnDevice backendDevice = nullptr;
WGPUDevice backendDevice = nullptr;
// Helper methods to implement the EXPECT_ macros
std::ostringstream& AddBufferExpectation(const char* file,
int line,
const dawn::Buffer& buffer,
const wgpu::Buffer& buffer,
uint64_t offset,
uint64_t size,
detail::Expectation* expectation);
std::ostringstream& AddTextureExpectation(const char* file,
int line,
const dawn::Texture& texture,
const wgpu::Texture& texture,
uint32_t x,
uint32_t y,
uint32_t width,
@ -227,13 +227,13 @@ class DawnTestBase {
std::unique_ptr<utils::TerribleCommandBuffer> mS2cBuf;
// 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 mError = false;
// MapRead buffers used to get data for the expectations
struct ReadbackSlot {
dawn::Buffer buffer;
wgpu::Buffer buffer;
uint64_t bufferSize;
const void* mappedData = nullptr;
};
@ -241,7 +241,7 @@ class DawnTestBase {
// Maps all the buffers and fill ReadbackSlot::mappedData
void MapSlotsSynchronously();
static void SlotMapReadCallback(DawnBufferMapAsyncStatus status,
static void SlotMapReadCallback(WGPUBufferMapAsyncStatus status,
const void* data,
uint64_t dataLength,
void* userdata);
@ -249,7 +249,7 @@ class DawnTestBase {
// Reserve space where the data for an expectation can be copied
struct ReadbackReservation {
dawn::Buffer buffer;
wgpu::Buffer buffer;
size_t slot;
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
// basic test possible, and tests the test harness
TEST_P(BasicTests, BufferSetSubData) {
dawn::BufferDescriptor descriptor;
wgpu::BufferDescriptor descriptor;
descriptor.size = 4;
descriptor.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
uint32_t value = 0x01020304;
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
// for ASSERT_DEVICE_ERROR
TEST_P(BasicTests, BufferSetSubDataError) {
dawn::BufferDescriptor descriptor;
wgpu::BufferDescriptor descriptor;
descriptor.size = 4;
descriptor.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
uint8_t value = 187;
ASSERT_DEVICE_ERROR(buffer.SetSubData(1000, sizeof(value), &value));

View File

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

View File

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

View File

@ -19,7 +19,7 @@
class ClipSpaceTest : public DawnTest {
protected:
dawn::RenderPipeline CreatePipelineForTest() {
wgpu::RenderPipeline CreatePipelineForTest() {
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
// Draw two triangles:
@ -48,18 +48,18 @@ class ClipSpaceTest : public DawnTest {
pipelineDescriptor.cFragmentStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs);
pipelineDescriptor.cDepthStencilState.depthCompare = dawn::CompareFunction::LessEqual;
pipelineDescriptor.cDepthStencilState.depthCompare = wgpu::CompareFunction::LessEqual;
pipelineDescriptor.depthStencilState = &pipelineDescriptor.cDepthStencilState;
return device.CreateRenderPipeline(&pipelineDescriptor);
}
dawn::Texture Create2DTextureForTest(dawn::TextureFormat format) {
dawn::TextureDescriptor textureDescriptor;
textureDescriptor.dimension = dawn::TextureDimension::e2D;
wgpu::Texture Create2DTextureForTest(wgpu::TextureFormat format) {
wgpu::TextureDescriptor textureDescriptor;
textureDescriptor.dimension = wgpu::TextureDimension::e2D;
textureDescriptor.format = format;
textureDescriptor.usage =
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc;
wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
textureDescriptor.arrayLayerCount = 1;
textureDescriptor.mipLevelCount = 1;
textureDescriptor.sampleCount = 1;
@ -72,27 +72,27 @@ class ClipSpaceTest : public DawnTest {
// Test that the clip space is correctly configured.
TEST_P(ClipSpaceTest, ClipSpace) {
dawn::Texture colorTexture = Create2DTextureForTest(dawn::TextureFormat::RGBA8Unorm);
dawn::Texture depthStencilTexture =
Create2DTextureForTest(dawn::TextureFormat::Depth24PlusStencil8);
wgpu::Texture colorTexture = Create2DTextureForTest(wgpu::TextureFormat::RGBA8Unorm);
wgpu::Texture depthStencilTexture =
Create2DTextureForTest(wgpu::TextureFormat::Depth24PlusStencil8);
utils::ComboRenderPassDescriptor renderPassDescriptor({colorTexture.CreateView()},
depthStencilTexture.CreateView());
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
// drawn.
renderPassDescriptor.cDepthStencilAttachmentInfo.clearDepth = 0.5f;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Clear;
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder renderPass = commandEncoder.BeginRenderPass(&renderPassDescriptor);
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
wgpu::RenderPassEncoder renderPass = commandEncoder.BeginRenderPass(&renderPassDescriptor);
renderPass.SetPipeline(CreatePipelineForTest());
renderPass.Draw(6, 1, 0, 0);
renderPass.EndPass();
dawn::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue();
wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer);
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(
device, {
{0, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer},
{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer},
});
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
// attachment. basePipeline has no blending
void SetupSingleSourcePipelines(dawn::ColorStateDescriptor colorStateDescriptor) {
dawn::ShaderModule fsModule =
void SetupSingleSourcePipelines(wgpu::ColorStateDescriptor colorStateDescriptor) {
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
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
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;
for (unsigned int i = 0; i < N; ++i) {
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));
dawn::Buffer buffer =
utils::CreateBufferFromData(device, &data, bufferSize, dawn::BufferUsage::Uniform);
wgpu::Buffer buffer =
utils::CreateBufferFromData(device, &data, bufferSize, wgpu::BufferUsage::Uniform);
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
// color is as 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]};
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
pass.SetPipeline(basePipeline);
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({{base}})));
@ -127,7 +127,7 @@ class ColorStateTest : public DawnTest {
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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
// expectations are true for the given blend operation
void CheckBlendOperation(RGBA8 base,
dawn::BlendOperation operation,
wgpu::BlendOperation operation,
std::vector<std::pair<RGBA8, RGBA8>> tests) {
dawn::BlendDescriptor blend;
wgpu::BlendDescriptor blend;
blend.operation = operation;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
blend.srcFactor = wgpu::BlendFactor::One;
blend.dstFactor = wgpu::BlendFactor::One;
dawn::ColorStateDescriptor descriptor;
wgpu::ColorStateDescriptor descriptor;
descriptor.alphaBlend = blend;
descriptor.colorBlend = blend;
descriptor.writeMask = dawn::ColorWriteMask::All;
descriptor.writeMask = wgpu::ColorWriteMask::All;
SetupSingleSourcePipelines(descriptor);
@ -158,25 +158,25 @@ class ColorStateTest : public DawnTest {
// Given a vector of tests where each element is <testSpec, expectedColor>, check that all
// expectations are true for the given blend factors
void CheckBlendFactor(RGBA8 base,
dawn::BlendFactor colorSrcFactor,
dawn::BlendFactor colorDstFactor,
dawn::BlendFactor alphaSrcFactor,
dawn::BlendFactor alphaDstFactor,
wgpu::BlendFactor colorSrcFactor,
wgpu::BlendFactor colorDstFactor,
wgpu::BlendFactor alphaSrcFactor,
wgpu::BlendFactor alphaDstFactor,
std::vector<std::pair<TriangleSpec, RGBA8>> tests) {
dawn::BlendDescriptor colorBlend;
colorBlend.operation = dawn::BlendOperation::Add;
wgpu::BlendDescriptor colorBlend;
colorBlend.operation = wgpu::BlendOperation::Add;
colorBlend.srcFactor = colorSrcFactor;
colorBlend.dstFactor = colorDstFactor;
dawn::BlendDescriptor alphaBlend;
alphaBlend.operation = dawn::BlendOperation::Add;
wgpu::BlendDescriptor alphaBlend;
alphaBlend.operation = wgpu::BlendOperation::Add;
alphaBlend.srcFactor = alphaSrcFactor;
alphaBlend.dstFactor = alphaDstFactor;
dawn::ColorStateDescriptor descriptor;
wgpu::ColorStateDescriptor descriptor;
descriptor.colorBlend = colorBlend;
descriptor.alphaBlend = alphaBlend;
descriptor.writeMask = dawn::ColorWriteMask::All;
descriptor.writeMask = wgpu::ColorWriteMask::All;
SetupSingleSourcePipelines(descriptor);
@ -186,27 +186,27 @@ class ColorStateTest : public DawnTest {
}
void CheckSrcBlendFactor(RGBA8 base,
dawn::BlendFactor colorFactor,
dawn::BlendFactor alphaFactor,
wgpu::BlendFactor colorFactor,
wgpu::BlendFactor alphaFactor,
std::vector<std::pair<TriangleSpec, RGBA8>> tests) {
CheckBlendFactor(base, colorFactor, dawn::BlendFactor::One, alphaFactor,
dawn::BlendFactor::One, tests);
CheckBlendFactor(base, colorFactor, wgpu::BlendFactor::One, alphaFactor,
wgpu::BlendFactor::One, tests);
}
void CheckDstBlendFactor(RGBA8 base,
dawn::BlendFactor colorFactor,
dawn::BlendFactor alphaFactor,
wgpu::BlendFactor colorFactor,
wgpu::BlendFactor alphaFactor,
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);
}
utils::BasicRenderPass renderPass;
dawn::RenderPipeline basePipeline;
dawn::RenderPipeline testPipeline;
dawn::ShaderModule vsModule;
dawn::BindGroupLayout bindGroupLayout;
dawn::PipelineLayout pipelineLayout;
wgpu::RenderPipeline basePipeline;
wgpu::RenderPipeline testPipeline;
wgpu::ShaderModule vsModule;
wgpu::BindGroupLayout bindGroupLayout;
wgpu::PipelineLayout pipelineLayout;
};
namespace {
@ -291,14 +291,14 @@ namespace {
// Test compilation and usage of the fixture
TEST_P(ColorStateTest, Basic) {
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::Zero;
dawn::ColorStateDescriptor descriptor;
wgpu::BlendDescriptor blend;
blend.operation = wgpu::BlendOperation::Add;
blend.srcFactor = wgpu::BlendFactor::One;
blend.dstFactor = wgpu::BlendFactor::Zero;
wgpu::ColorStateDescriptor descriptor;
descriptor.alphaBlend = blend;
descriptor.colorBlend = blend;
descriptor.writeMask = dawn::ColorWriteMask::All;
descriptor.writeMask = wgpu::ColorWriteMask::All;
SetupSingleSourcePipelines(descriptor);
@ -311,7 +311,7 @@ TEST_P(ColorStateTest, BlendOperationAdd) {
std::vector<std::pair<RGBA8, RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, base + color); });
CheckBlendOperation(base, dawn::BlendOperation::Add, tests);
CheckBlendOperation(base, wgpu::BlendOperation::Add, tests);
}
TEST_P(ColorStateTest, BlendOperationSubtract) {
@ -319,7 +319,7 @@ TEST_P(ColorStateTest, BlendOperationSubtract) {
std::vector<std::pair<RGBA8, RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, color - base); });
CheckBlendOperation(base, dawn::BlendOperation::Subtract, tests);
CheckBlendOperation(base, wgpu::BlendOperation::Subtract, tests);
}
TEST_P(ColorStateTest, BlendOperationReverseSubtract) {
@ -327,7 +327,7 @@ TEST_P(ColorStateTest, BlendOperationReverseSubtract) {
std::vector<std::pair<RGBA8, RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, base - color); });
CheckBlendOperation(base, dawn::BlendOperation::ReverseSubtract, tests);
CheckBlendOperation(base, wgpu::BlendOperation::ReverseSubtract, tests);
}
TEST_P(ColorStateTest, BlendOperationMin) {
@ -335,7 +335,7 @@ TEST_P(ColorStateTest, BlendOperationMin) {
std::vector<std::pair<RGBA8, RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, min(base, color)); });
CheckBlendOperation(base, dawn::BlendOperation::Min, tests);
CheckBlendOperation(base, wgpu::BlendOperation::Min, tests);
}
TEST_P(ColorStateTest, BlendOperationMax) {
@ -343,7 +343,7 @@ TEST_P(ColorStateTest, BlendOperationMax) {
std::vector<std::pair<RGBA8, RGBA8>> tests;
std::transform(kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](const RGBA8& color) { return std::make_pair(color, max(base, color)); });
CheckBlendOperation(base, dawn::BlendOperation::Max, tests);
CheckBlendOperation(base, wgpu::BlendOperation::Max, tests);
}
// The following tests check that the Source blend factor works
@ -353,7 +353,7 @@ TEST_P(ColorStateTest, SrcBlendFactorZero) {
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](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) {
@ -362,7 +362,7 @@ TEST_P(ColorStateTest, SrcBlendFactorOne) {
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](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) {
@ -375,7 +375,7 @@ TEST_P(ColorStateTest, SrcBlendFactorSrcColor) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
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) {
@ -388,7 +388,7 @@ TEST_P(ColorStateTest, SrcBlendFactorOneMinusSrcColor) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
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) {
@ -400,7 +400,7 @@ TEST_P(ColorStateTest, SrcBlendFactorSrcAlpha) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
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) {
@ -412,8 +412,8 @@ TEST_P(ColorStateTest, SrcBlendFactorOneMinusSrcAlpha) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckSrcBlendFactor(base, dawn::BlendFactor::OneMinusSrcAlpha,
dawn::BlendFactor::OneMinusSrcAlpha, tests);
CheckSrcBlendFactor(base, wgpu::BlendFactor::OneMinusSrcAlpha,
wgpu::BlendFactor::OneMinusSrcAlpha, tests);
}
TEST_P(ColorStateTest, SrcBlendFactorDstColor) {
@ -426,7 +426,7 @@ TEST_P(ColorStateTest, SrcBlendFactorDstColor) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
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) {
@ -439,7 +439,7 @@ TEST_P(ColorStateTest, SrcBlendFactorOneMinusDstColor) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
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) {
@ -451,7 +451,7 @@ TEST_P(ColorStateTest, SrcBlendFactorDstAlpha) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
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) {
@ -463,8 +463,8 @@ TEST_P(ColorStateTest, SrcBlendFactorOneMinusDstAlpha) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckSrcBlendFactor(base, dawn::BlendFactor::OneMinusDstAlpha,
dawn::BlendFactor::OneMinusDstAlpha, tests);
CheckSrcBlendFactor(base, wgpu::BlendFactor::OneMinusDstAlpha,
wgpu::BlendFactor::OneMinusDstAlpha, tests);
}
TEST_P(ColorStateTest, SrcBlendFactorSrcAlphaSaturated) {
@ -477,8 +477,8 @@ TEST_P(ColorStateTest, SrcBlendFactorSrcAlphaSaturated) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckSrcBlendFactor(base, dawn::BlendFactor::SrcAlphaSaturated,
dawn::BlendFactor::SrcAlphaSaturated, tests);
CheckSrcBlendFactor(base, wgpu::BlendFactor::SrcAlphaSaturated,
wgpu::BlendFactor::SrcAlphaSaturated, tests);
}
TEST_P(ColorStateTest, SrcBlendFactorBlendColor) {
@ -490,7 +490,7 @@ TEST_P(ColorStateTest, SrcBlendFactorBlendColor) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, triangleSpec.blendFactor);
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) {
@ -503,8 +503,8 @@ TEST_P(ColorStateTest, SrcBlendFactorOneMinusBlendColor) {
RGBA8 expected = base + mix(RGBA8(0, 0, 0, 0), color, f);
return std::make_pair(triangleSpec, expected);
});
CheckSrcBlendFactor(base, dawn::BlendFactor::OneMinusBlendColor,
dawn::BlendFactor::OneMinusBlendColor, tests);
CheckSrcBlendFactor(base, wgpu::BlendFactor::OneMinusBlendColor,
wgpu::BlendFactor::OneMinusBlendColor, tests);
}
// The following tests check that the Destination blend factor works
@ -514,7 +514,7 @@ TEST_P(ColorStateTest, DstBlendFactorZero) {
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](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) {
@ -523,7 +523,7 @@ TEST_P(ColorStateTest, DstBlendFactorOne) {
std::transform(
kColors.begin(), kColors.end(), std::back_inserter(tests),
[&](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) {
@ -536,7 +536,7 @@ TEST_P(ColorStateTest, DstBlendFactorSrcColor) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
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) {
@ -549,7 +549,7 @@ TEST_P(ColorStateTest, DstBlendFactorOneMinusSrcColor) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
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) {
@ -561,7 +561,7 @@ TEST_P(ColorStateTest, DstBlendFactorSrcAlpha) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
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) {
@ -573,8 +573,8 @@ TEST_P(ColorStateTest, DstBlendFactorOneMinusSrcAlpha) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckDstBlendFactor(base, dawn::BlendFactor::OneMinusSrcAlpha,
dawn::BlendFactor::OneMinusSrcAlpha, tests);
CheckDstBlendFactor(base, wgpu::BlendFactor::OneMinusSrcAlpha,
wgpu::BlendFactor::OneMinusSrcAlpha, tests);
}
TEST_P(ColorStateTest, DstBlendFactorDstColor) {
@ -587,7 +587,7 @@ TEST_P(ColorStateTest, DstBlendFactorDstColor) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
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) {
@ -600,7 +600,7 @@ TEST_P(ColorStateTest, DstBlendFactorOneMinusDstColor) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
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) {
@ -612,7 +612,7 @@ TEST_P(ColorStateTest, DstBlendFactorDstAlpha) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
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) {
@ -624,8 +624,8 @@ TEST_P(ColorStateTest, DstBlendFactorOneMinusDstAlpha) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckDstBlendFactor(base, dawn::BlendFactor::OneMinusDstAlpha,
dawn::BlendFactor::OneMinusDstAlpha, tests);
CheckDstBlendFactor(base, wgpu::BlendFactor::OneMinusDstAlpha,
wgpu::BlendFactor::OneMinusDstAlpha, tests);
}
TEST_P(ColorStateTest, DstBlendFactorSrcAlphaSaturated) {
@ -638,8 +638,8 @@ TEST_P(ColorStateTest, DstBlendFactorSrcAlphaSaturated) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, fac);
return std::make_pair(TriangleSpec({{color}}), expected);
});
CheckDstBlendFactor(base, dawn::BlendFactor::SrcAlphaSaturated,
dawn::BlendFactor::SrcAlphaSaturated, tests);
CheckDstBlendFactor(base, wgpu::BlendFactor::SrcAlphaSaturated,
wgpu::BlendFactor::SrcAlphaSaturated, tests);
}
TEST_P(ColorStateTest, DstBlendFactorBlendColor) {
@ -651,7 +651,7 @@ TEST_P(ColorStateTest, DstBlendFactorBlendColor) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, triangleSpec.blendFactor);
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) {
@ -664,23 +664,23 @@ TEST_P(ColorStateTest, DstBlendFactorOneMinusBlendColor) {
RGBA8 expected = color + mix(RGBA8(0, 0, 0, 0), base, f);
return std::make_pair(triangleSpec, expected);
});
CheckDstBlendFactor(base, dawn::BlendFactor::OneMinusBlendColor,
dawn::BlendFactor::OneMinusBlendColor, tests);
CheckDstBlendFactor(base, wgpu::BlendFactor::OneMinusBlendColor,
wgpu::BlendFactor::OneMinusBlendColor, tests);
}
// Check that the color write mask works
TEST_P(ColorStateTest, ColorWriteMask) {
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::One;
wgpu::BlendDescriptor blend;
blend.operation = wgpu::BlendOperation::Add;
blend.srcFactor = wgpu::BlendFactor::One;
blend.dstFactor = wgpu::BlendFactor::One;
dawn::ColorStateDescriptor descriptor;
wgpu::ColorStateDescriptor descriptor;
descriptor.colorBlend = blend;
descriptor.alphaBlend = blend;
{
// Test single channel color write
descriptor.writeMask = dawn::ColorWriteMask::Red;
descriptor.writeMask = wgpu::ColorWriteMask::Red;
SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192);
@ -692,7 +692,7 @@ TEST_P(ColorStateTest, ColorWriteMask) {
{
// Test multi channel color write
descriptor.writeMask = dawn::ColorWriteMask::Green | dawn::ColorWriteMask::Alpha;
descriptor.writeMask = wgpu::ColorWriteMask::Green | wgpu::ColorWriteMask::Alpha;
SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192);
@ -704,7 +704,7 @@ TEST_P(ColorStateTest, ColorWriteMask) {
{
// Test no channel color write
descriptor.writeMask = dawn::ColorWriteMask::None;
descriptor.writeMask = wgpu::ColorWriteMask::None;
SetupSingleSourcePipelines(descriptor);
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
TEST_P(ColorStateTest, ColorWriteMaskBlendingDisabled) {
{
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::One;
blend.dstFactor = dawn::BlendFactor::Zero;
dawn::ColorStateDescriptor descriptor;
wgpu::BlendDescriptor blend;
blend.operation = wgpu::BlendOperation::Add;
blend.srcFactor = wgpu::BlendFactor::One;
blend.dstFactor = wgpu::BlendFactor::Zero;
wgpu::ColorStateDescriptor descriptor;
descriptor.alphaBlend = blend;
descriptor.colorBlend = blend;
descriptor.writeMask = dawn::ColorWriteMask::Red;
descriptor.writeMask = wgpu::ColorWriteMask::Red;
SetupSingleSourcePipelines(descriptor);
RGBA8 base(32, 64, 128, 192);
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.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({{base}})));
pass.Draw(3, 1, 0, 0);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(expected, renderPass.color, kRTSize / 2, kRTSize / 2);
}
@ -750,19 +750,19 @@ TEST_P(ColorStateTest, ColorWriteMaskBlendingDisabled) {
TEST_P(ColorStateTest, IndependentColorState) {
DAWN_SKIP_TEST_IF(IsWindows() && IsVulkan() && IsIntel());
std::array<dawn::Texture, 4> renderTargets;
std::array<dawn::TextureView, 4> renderTargetViews;
std::array<wgpu::Texture, 4> renderTargets;
std::array<wgpu::TextureView, 4> renderTargetViews;
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kRTSize;
descriptor.size.height = kRTSize;
descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm;
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
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) {
renderTargets[i] = device.CreateTexture(&descriptor);
@ -772,7 +772,7 @@ TEST_P(ColorStateTest, IndependentColorState) {
utils::ComboRenderPassDescriptor renderPass({renderTargetViews[0], renderTargetViews[1],
renderTargetViews[2], renderTargetViews[3]});
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(set = 0, binding = 0) uniform myBlock {
@ -810,20 +810,20 @@ TEST_P(ColorStateTest, IndependentColorState) {
testDescriptor.colorStateCount = 4;
// set color states
dawn::BlendDescriptor blend1;
blend1.operation = dawn::BlendOperation::Add;
blend1.srcFactor = dawn::BlendFactor::One;
blend1.dstFactor = dawn::BlendFactor::One;
wgpu::BlendDescriptor blend1;
blend1.operation = wgpu::BlendOperation::Add;
blend1.srcFactor = wgpu::BlendFactor::One;
blend1.dstFactor = wgpu::BlendFactor::One;
dawn::BlendDescriptor blend2;
blend2.operation = dawn::BlendOperation::Subtract;
blend2.srcFactor = dawn::BlendFactor::One;
blend2.dstFactor = dawn::BlendFactor::One;
wgpu::BlendDescriptor blend2;
blend2.operation = wgpu::BlendOperation::Subtract;
blend2.srcFactor = wgpu::BlendFactor::One;
blend2.dstFactor = wgpu::BlendFactor::One;
dawn::BlendDescriptor blend3;
blend3.operation = dawn::BlendOperation::Min;
blend3.srcFactor = dawn::BlendFactor::One;
blend3.dstFactor = dawn::BlendFactor::One;
wgpu::BlendDescriptor blend3;
blend3.operation = wgpu::BlendOperation::Min;
blend3.srcFactor = wgpu::BlendFactor::One;
blend3.dstFactor = wgpu::BlendFactor::One;
testDescriptor.cColorStates[0].colorBlend = blend1;
testDescriptor.cColorStates[0].alphaBlend = blend1;
@ -848,9 +848,9 @@ TEST_P(ColorStateTest, IndependentColorState) {
RGBA8 expected2 = color2;
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.SetBindGroup(
0, MakeBindGroupForColors(std::array<RGBA8, 4>({{base, base, base, base}})));
@ -863,7 +863,7 @@ TEST_P(ColorStateTest, IndependentColorState) {
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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_P(ColorStateTest, DefaultBlendColor) {
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(set = 0, binding = 0) uniform myBlock {
@ -911,21 +911,21 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
testDescriptor.cFragmentStage.module = fsModule;
testDescriptor.cColorStates[0].format = renderPass.colorFormat;
dawn::BlendDescriptor blend;
blend.operation = dawn::BlendOperation::Add;
blend.srcFactor = dawn::BlendFactor::BlendColor;
blend.dstFactor = dawn::BlendFactor::One;
wgpu::BlendDescriptor blend;
blend.operation = wgpu::BlendOperation::Add;
blend.srcFactor = wgpu::BlendFactor::BlendColor;
blend.dstFactor = wgpu::BlendFactor::One;
testDescriptor.cColorStates[0].colorBlend = blend;
testDescriptor.cColorStates[0].alphaBlend = blend;
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)
{
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.SetBindGroup(0,
MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}})));
@ -937,7 +937,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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
{
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.SetBindGroup(0,
MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}})));
@ -960,7 +960,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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
{
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.SetBindGroup(0,
MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}})));
@ -984,7 +984,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
pass.EndPass();
}
{
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(basePipeline);
pass.SetBindGroup(0,
MakeBindGroupForColors(std::array<RGBA8, 1>({{RGBA8(0, 0, 0, 0)}})));
@ -996,7 +996,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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
// attachment.
TEST_P(ColorStateTest, ColorWriteMaskDoesNotAffectRenderPassLoadOpClear) {
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(set = 0, binding = 0) uniform myBlock {
@ -1034,17 +1034,17 @@ TEST_P(ColorStateTest, ColorWriteMaskDoesNotAffectRenderPassLoadOpClear) {
testDescriptor.vertexStage.module = vsModule;
testDescriptor.cFragmentStage.module = fsModule;
testDescriptor.cColorStates[0].format = renderPass.colorFormat;
testDescriptor.cColorStates[0].writeMask = dawn::ColorWriteMask::Red;
testDescriptor.cColorStates[0].writeMask = wgpu::ColorWriteMask::Red;
testPipeline = device.CreateRenderPipeline(&testDescriptor);
RGBA8 base(32, 64, 128, 192);
RGBA8 expected(0, 0, 0, 0);
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{
// Clear the output attachment to |base|
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(basePipeline);
pass.SetBindGroup(0, MakeBindGroupForColors(std::array<RGBA8, 1>({{base}})));
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
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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.
struct CopyConfig {
dawn::TextureDescriptor textureDescriptor;
dawn::Extent3D copyExtent3D;
dawn::Origin3D copyOrigin3D = {0, 0, 0};
wgpu::TextureDescriptor textureDescriptor;
wgpu::Extent3D copyExtent3D;
wgpu::Origin3D copyOrigin3D = {0, 0, 0};
uint32_t viewMipmapLevel = 0;
uint32_t viewArrayLayer = 0;
uint32_t bufferOffset = 0;
@ -37,8 +37,8 @@ class CompressedTextureBCFormatTest : public DawnTest {
void TestSetUp() override {
DawnTest::TestSetUp();
mBindGroupLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::Sampler},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture}});
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler},
{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture}});
}
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.
void InitializeDataInCompressedTexture(dawn::Texture bcCompressedTexture,
void InitializeDataInCompressedTexture(wgpu::Texture bcCompressedTexture,
const CopyConfig& copyConfig) {
ASSERT(IsBCFormatSupported());
// 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 actualHeightAtLevel = textureSize.height >> copyConfig.viewMipmapLevel;
uint32_t copyWidthInBlockAtLevel =
@ -92,54 +92,54 @@ class CompressedTextureBCFormatTest : public DawnTest {
}
// Copy texture data from a staging buffer to the destination texture.
dawn::Buffer stagingBuffer = utils::CreateBufferFromData(
device, uploadData.data(), uploadBufferSize, dawn::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView =
wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, uploadData.data(), uploadBufferSize, wgpu::BufferUsage::CopySrc);
wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(stagingBuffer, copyConfig.bufferOffset,
copyConfig.rowPitchAlignment, copyConfig.imageHeight);
dawn::TextureCopyView textureCopyView =
wgpu::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(bcCompressedTexture, copyConfig.viewMipmapLevel,
copyConfig.viewArrayLayer, copyConfig.copyOrigin3D);
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copyConfig.copyExtent3D);
dawn::CommandBuffer copy = encoder.Finish();
wgpu::CommandBuffer copy = encoder.Finish();
queue.Submit(1, &copy);
}
// Create the bind group that includes a BC texture and a sampler.
dawn::BindGroup CreateBindGroupForTest(dawn::Texture bcCompressedTexture,
dawn::TextureFormat bcFormat,
wgpu::BindGroup CreateBindGroupForTest(wgpu::Texture bcCompressedTexture,
wgpu::TextureFormat bcFormat,
uint32_t baseArrayLayer = 0,
uint32_t baseMipLevel = 0) {
ASSERT(IsBCFormatSupported());
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
samplerDesc.minFilter = dawn::FilterMode::Nearest;
samplerDesc.magFilter = dawn::FilterMode::Nearest;
dawn::Sampler sampler = device.CreateSampler(&samplerDesc);
wgpu::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
samplerDesc.minFilter = wgpu::FilterMode::Nearest;
samplerDesc.magFilter = wgpu::FilterMode::Nearest;
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
dawn::TextureViewDescriptor textureViewDescriptor;
wgpu::TextureViewDescriptor textureViewDescriptor;
textureViewDescriptor.format = bcFormat;
textureViewDescriptor.dimension = dawn::TextureViewDimension::e2D;
textureViewDescriptor.dimension = wgpu::TextureViewDimension::e2D;
textureViewDescriptor.baseMipLevel = baseMipLevel;
textureViewDescriptor.baseArrayLayer = baseArrayLayer;
textureViewDescriptor.arrayLayerCount = 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}});
}
// Create a render pipeline for sampling from a BC texture and rendering into the render target.
dawn::RenderPipeline CreateRenderPipelineForTest() {
wgpu::RenderPipeline CreateRenderPipelineForTest() {
ASSERT(IsBCFormatSupported());
dawn::PipelineLayout pipelineLayout =
wgpu::PipelineLayout pipelineLayout =
utils::MakeBasicPipelineLayout(device, &mBindGroupLayout);
utils::ComboRenderPipelineDescriptor renderPipelineDescriptor(device);
dawn::ShaderModule vsModule =
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
layout(location=0) out vec2 texCoord;
@ -152,7 +152,7 @@ class CompressedTextureBCFormatTest : public DawnTest {
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);
})");
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
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.
void VerifyCompressedTexturePixelValues(dawn::RenderPipeline renderPipeline,
dawn::BindGroup bindGroup,
const dawn::Extent3D& renderTargetSize,
const dawn::Origin3D& expectedOrigin,
const dawn::Extent3D& expectedExtent,
void VerifyCompressedTexturePixelValues(wgpu::RenderPipeline renderPipeline,
wgpu::BindGroup bindGroup,
const wgpu::Extent3D& renderTargetSize,
const wgpu::Origin3D& expectedOrigin,
const wgpu::Extent3D& expectedExtent,
const std::vector<RGBA8>& expected) {
ASSERT(IsBCFormatSupported());
@ -184,16 +184,16 @@ class CompressedTextureBCFormatTest : public DawnTest {
utils::BasicRenderPass renderPass =
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.SetBindGroup(0, bindGroup);
pass.Draw(6, 1, 0, 0);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_TEXTURE_RGBA8_EQ(expected.data(), renderPass.color, expectedOrigin.x,
@ -206,19 +206,19 @@ class CompressedTextureBCFormatTest : public DawnTest {
void TestCopyRegionIntoBCFormatTextures(const CopyConfig& config) {
ASSERT(IsBCFormatSupported());
dawn::Texture bcTexture = CreateTextureWithCompressedData(config);
wgpu::Texture bcTexture = CreateTextureWithCompressedData(config);
dawn::BindGroup bindGroup =
wgpu::BindGroup bindGroup =
CreateBindGroupForTest(bcTexture, config.textureDescriptor.format,
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
// blocks, so we should limit the size of the expectedData to make it match the real size
// of the render target.
dawn::Extent3D noPaddingExtent3D = config.copyExtent3D;
wgpu::Extent3D noPaddingExtent3D = config.copyExtent3D;
if (config.copyOrigin3D.x + config.copyExtent3D.width > virtualSizeAtLevel.width) {
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.
dawn::Texture CreateTextureWithCompressedData(CopyConfig config) {
dawn::Texture bcTexture = device.CreateTexture(&config.textureDescriptor);
wgpu::Texture CreateTextureWithCompressedData(CopyConfig config) {
wgpu::Texture bcTexture = device.CreateTexture(&config.textureDescriptor);
InitializeDataInCompressedTexture(bcTexture, config);
return bcTexture;
}
// Record a texture-to-texture copy command into command encoder without finishing the encoding.
void RecordTextureToTextureCopy(dawn::CommandEncoder encoder,
dawn::Texture srcTexture,
dawn::Texture dstTexture,
void RecordTextureToTextureCopy(wgpu::CommandEncoder encoder,
wgpu::Texture srcTexture,
wgpu::Texture dstTexture,
CopyConfig srcConfig,
CopyConfig dstConfig) {
dawn::TextureCopyView textureCopyViewSrc =
wgpu::TextureCopyView textureCopyViewSrc =
utils::CreateTextureCopyView(srcTexture, srcConfig.viewMipmapLevel,
srcConfig.viewArrayLayer, srcConfig.copyOrigin3D);
dawn::TextureCopyView textureCopyViewDst =
wgpu::TextureCopyView textureCopyViewDst =
utils::CreateTextureCopyView(dstTexture, dstConfig.viewMipmapLevel,
dstConfig.viewArrayLayer, dstConfig.copyOrigin3D);
encoder.CopyTextureToTexture(&textureCopyViewSrc, &textureCopyViewDst,
&dstConfig.copyExtent3D);
}
dawn::Texture CreateTextureFromTexture(dawn::Texture srcTexture,
wgpu::Texture CreateTextureFromTexture(wgpu::Texture srcTexture,
CopyConfig srcConfig,
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);
dawn::CommandBuffer copy = encoder.Finish();
wgpu::CommandBuffer copy = encoder.Finish();
queue.Submit(1, &copy);
return dstTexture;
}
// Return the BC block size in bytes.
static uint32_t CompressedFormatBlockSizeInBytes(dawn::TextureFormat format) {
static uint32_t CompressedFormatBlockSizeInBytes(wgpu::TextureFormat format) {
switch (format) {
case dawn::TextureFormat::BC1RGBAUnorm:
case dawn::TextureFormat::BC1RGBAUnormSrgb:
case dawn::TextureFormat::BC4RSnorm:
case dawn::TextureFormat::BC4RUnorm:
case wgpu::TextureFormat::BC1RGBAUnorm:
case wgpu::TextureFormat::BC1RGBAUnormSrgb:
case wgpu::TextureFormat::BC4RSnorm:
case wgpu::TextureFormat::BC4RUnorm:
return 8;
case dawn::TextureFormat::BC2RGBAUnorm:
case dawn::TextureFormat::BC2RGBAUnormSrgb:
case dawn::TextureFormat::BC3RGBAUnorm:
case dawn::TextureFormat::BC3RGBAUnormSrgb:
case dawn::TextureFormat::BC5RGSnorm:
case dawn::TextureFormat::BC5RGUnorm:
case dawn::TextureFormat::BC6HRGBSfloat:
case dawn::TextureFormat::BC6HRGBUfloat:
case dawn::TextureFormat::BC7RGBAUnorm:
case dawn::TextureFormat::BC7RGBAUnormSrgb:
case wgpu::TextureFormat::BC2RGBAUnorm:
case wgpu::TextureFormat::BC2RGBAUnormSrgb:
case wgpu::TextureFormat::BC3RGBAUnorm:
case wgpu::TextureFormat::BC3RGBAUnormSrgb:
case wgpu::TextureFormat::BC5RGSnorm:
case wgpu::TextureFormat::BC5RGUnorm:
case wgpu::TextureFormat::BC6HRGBSfloat:
case wgpu::TextureFormat::BC6HRGBUfloat:
case wgpu::TextureFormat::BC7RGBAUnorm:
case wgpu::TextureFormat::BC7RGBAUnormSrgb:
return 16;
default:
UNREACHABLE();
@ -294,18 +294,18 @@ class CompressedTextureBCFormatTest : public DawnTest {
}
// 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) {
// 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
// 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
// color space as part of filtering.
case dawn::TextureFormat::BC1RGBAUnorm:
case dawn::TextureFormat::BC1RGBAUnormSrgb:
case wgpu::TextureFormat::BC1RGBAUnorm:
case wgpu::TextureFormat::BC1RGBAUnormSrgb:
return {0x0, 0xC0, 0x60, 0x6, 0x50, 0x50, 0x50, 0x50};
case dawn::TextureFormat::BC7RGBAUnorm:
case dawn::TextureFormat::BC7RGBAUnormSrgb:
case wgpu::TextureFormat::BC7RGBAUnorm:
case wgpu::TextureFormat::BC7RGBAUnormSrgb:
return {0x50, 0x18, 0xfc, 0xf, 0x0, 0x30, 0xe3, 0xe1,
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
// 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.
case dawn::TextureFormat::BC2RGBAUnorm:
case dawn::TextureFormat::BC2RGBAUnormSrgb:
case wgpu::TextureFormat::BC2RGBAUnorm:
case wgpu::TextureFormat::BC2RGBAUnormSrgb:
return {0x88, 0xFF, 0x88, 0xFF, 0x88, 0xFF, 0x88, 0xFF,
0x0, 0xC0, 0x60, 0x6, 0x50, 0x50, 0x50, 0x50};
case dawn::TextureFormat::BC3RGBAUnorm:
case dawn::TextureFormat::BC3RGBAUnormSrgb:
case wgpu::TextureFormat::BC3RGBAUnorm:
case wgpu::TextureFormat::BC3RGBAUnormSrgb:
return {0x88, 0xFF, 0x40, 0x2, 0x24, 0x40, 0x2, 0x24,
0x0, 0xC0, 0x60, 0x6, 0x50, 0x50, 0x50, 0x50};
// The expected data represents 4x4 pixel images with the left side red and the
// right side black.
case dawn::TextureFormat::BC4RSnorm:
case wgpu::TextureFormat::BC4RSnorm:
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};
// The expected data represents 4x4 pixel images with the left side red and the right
// 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,
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,
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,
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,
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
// RGBA8 formats.
static std::vector<RGBA8> GetExpectedData(dawn::TextureFormat bcFormat,
const dawn::Extent3D& testRegion) {
static std::vector<RGBA8> GetExpectedData(wgpu::TextureFormat bcFormat,
const wgpu::Extent3D& testRegion) {
constexpr RGBA8 kRed(255, 0, 0, 255);
constexpr RGBA8 kGreen(0, 255, 0, 255);
constexpr RGBA8 kBlack(0, 0, 0, 255);
@ -368,36 +368,36 @@ class CompressedTextureBCFormatTest : public DawnTest {
constexpr uint8_t kRightAlpha = 0xFF;
switch (bcFormat) {
case dawn::TextureFormat::BC1RGBAUnorm:
case dawn::TextureFormat::BC7RGBAUnorm:
case wgpu::TextureFormat::BC1RGBAUnorm:
case wgpu::TextureFormat::BC7RGBAUnorm:
return FillExpectedData(testRegion, kDarkRed, kDarkGreen);
case dawn::TextureFormat::BC2RGBAUnorm:
case dawn::TextureFormat::BC3RGBAUnorm: {
case wgpu::TextureFormat::BC2RGBAUnorm:
case wgpu::TextureFormat::BC3RGBAUnorm: {
constexpr RGBA8 kLeftColor = RGBA8(kDarkRed.r, 0, 0, kLeftAlpha);
constexpr RGBA8 kRightColor = RGBA8(0, kDarkGreen.g, 0, kRightAlpha);
return FillExpectedData(testRegion, kLeftColor, kRightColor);
}
case dawn::TextureFormat::BC1RGBAUnormSrgb:
case dawn::TextureFormat::BC7RGBAUnormSrgb:
case wgpu::TextureFormat::BC1RGBAUnormSrgb:
case wgpu::TextureFormat::BC7RGBAUnormSrgb:
return FillExpectedData(testRegion, kDarkRedSRGB, kDarkGreenSRGB);
case dawn::TextureFormat::BC2RGBAUnormSrgb:
case dawn::TextureFormat::BC3RGBAUnormSrgb: {
case wgpu::TextureFormat::BC2RGBAUnormSrgb:
case wgpu::TextureFormat::BC3RGBAUnormSrgb: {
constexpr RGBA8 kLeftColor = RGBA8(kDarkRedSRGB.r, 0, 0, kLeftAlpha);
constexpr RGBA8 kRightColor = RGBA8(0, kDarkGreenSRGB.g, 0, kRightAlpha);
return FillExpectedData(testRegion, kLeftColor, kRightColor);
}
case dawn::TextureFormat::BC4RSnorm:
case dawn::TextureFormat::BC4RUnorm:
case wgpu::TextureFormat::BC4RSnorm:
case wgpu::TextureFormat::BC4RUnorm:
return FillExpectedData(testRegion, kRed, kBlack);
case dawn::TextureFormat::BC5RGSnorm:
case dawn::TextureFormat::BC5RGUnorm:
case dawn::TextureFormat::BC6HRGBSfloat:
case dawn::TextureFormat::BC6HRGBUfloat:
case wgpu::TextureFormat::BC5RGSnorm:
case wgpu::TextureFormat::BC5RGUnorm:
case wgpu::TextureFormat::BC6HRGBSfloat:
case wgpu::TextureFormat::BC6HRGBUfloat:
return FillExpectedData(testRegion, kRed, kGreen);
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 rightColorInBlock) {
ASSERT(testRegion.depth == 1);
@ -422,13 +422,13 @@ class CompressedTextureBCFormatTest : public DawnTest {
return expectedData;
}
static dawn::Extent3D GetVirtualSizeAtLevel(const CopyConfig& config) {
static wgpu::Extent3D GetVirtualSizeAtLevel(const CopyConfig& config) {
return {config.textureDescriptor.size.width >> config.viewMipmapLevel,
config.textureDescriptor.size.height >> config.viewMipmapLevel, 1};
}
static dawn::Extent3D GetPhysicalSizeAtLevel(const CopyConfig& config) {
dawn::Extent3D sizeAtLevel = GetVirtualSizeAtLevel(config);
static wgpu::Extent3D GetPhysicalSizeAtLevel(const CopyConfig& config) {
wgpu::Extent3D sizeAtLevel = GetVirtualSizeAtLevel(config);
sizeAtLevel.width = (sizeAtLevel.width + kBCBlockWidthInTexels - 1) /
kBCBlockWidthInTexels * kBCBlockWidthInTexels;
sizeAtLevel.height = (sizeAtLevel.height + kBCBlockHeightInTexels - 1) /
@ -436,23 +436,23 @@ class CompressedTextureBCFormatTest : public DawnTest {
return sizeAtLevel;
}
const std::array<dawn::TextureFormat, 14> kBCFormats = {
dawn::TextureFormat::BC1RGBAUnorm, dawn::TextureFormat::BC1RGBAUnormSrgb,
dawn::TextureFormat::BC2RGBAUnorm, dawn::TextureFormat::BC2RGBAUnormSrgb,
dawn::TextureFormat::BC3RGBAUnorm, dawn::TextureFormat::BC3RGBAUnormSrgb,
dawn::TextureFormat::BC4RSnorm, dawn::TextureFormat::BC4RUnorm,
dawn::TextureFormat::BC5RGSnorm, dawn::TextureFormat::BC5RGUnorm,
dawn::TextureFormat::BC6HRGBSfloat, dawn::TextureFormat::BC6HRGBUfloat,
dawn::TextureFormat::BC7RGBAUnorm, dawn::TextureFormat::BC7RGBAUnormSrgb};
const std::array<wgpu::TextureFormat, 14> kBCFormats = {
wgpu::TextureFormat::BC1RGBAUnorm, wgpu::TextureFormat::BC1RGBAUnormSrgb,
wgpu::TextureFormat::BC2RGBAUnorm, wgpu::TextureFormat::BC2RGBAUnormSrgb,
wgpu::TextureFormat::BC3RGBAUnorm, wgpu::TextureFormat::BC3RGBAUnormSrgb,
wgpu::TextureFormat::BC4RSnorm, wgpu::TextureFormat::BC4RUnorm,
wgpu::TextureFormat::BC5RGSnorm, wgpu::TextureFormat::BC5RGUnorm,
wgpu::TextureFormat::BC6HRGBSfloat, wgpu::TextureFormat::BC6HRGBUfloat,
wgpu::TextureFormat::BC7RGBAUnorm, wgpu::TextureFormat::BC7RGBAUnormSrgb};
// Tthe block width and height in texels are 4 for all BC formats.
static constexpr uint32_t kBCBlockWidthInTexels = 4;
static constexpr uint32_t kBCBlockHeightInTexels = 4;
static constexpr dawn::TextureUsage kDefaultBCFormatTextureUsage =
dawn::TextureUsage::Sampled | dawn::TextureUsage::CopyDst;
static constexpr wgpu::TextureUsage kDefaultBCFormatTextureUsage =
wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopyDst;
dawn::BindGroupLayout mBindGroupLayout;
wgpu::BindGroupLayout mBindGroupLayout;
bool mIsBCFormatSupported = false;
};
@ -473,7 +473,7 @@ TEST_P(CompressedTextureBCFormatTest, Basic) {
config.textureDescriptor.size = {8, 8, 1};
config.copyExtent3D = config.textureDescriptor.size;
for (dawn::TextureFormat format : kBCFormats) {
for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format;
TestCopyRegionIntoBCFormatTextures(config);
}
@ -491,12 +491,12 @@ TEST_P(CompressedTextureBCFormatTest, CopyIntoSubRegion) {
config.textureDescriptor.usage = kDefaultBCFormatTextureUsage;
config.textureDescriptor.size = {8, 8, 1};
const dawn::Origin3D kOrigin = {4, 4, 0};
const dawn::Extent3D kExtent3D = {4, 4, 1};
const wgpu::Origin3D kOrigin = {4, 4, 0};
const wgpu::Extent3D kExtent3D = {4, 4, 1};
config.copyOrigin3D = kOrigin;
config.copyExtent3D = kExtent3D;
for (dawn::TextureFormat format : kBCFormats) {
for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format;
TestCopyRegionIntoBCFormatTextures(config);
}
@ -520,7 +520,7 @@ TEST_P(CompressedTextureBCFormatTest, CopyWithZeroRowPitch) {
config.rowPitchAlignment = 0;
for (dawn::TextureFormat format : kBCFormats) {
for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format;
config.textureDescriptor.size.width = kTextureRowPitchAlignment /
CompressedFormatBlockSizeInBytes(format) *
@ -550,7 +550,7 @@ TEST_P(CompressedTextureBCFormatTest, CopyIntoNonZeroArrayLayer) {
config.textureDescriptor.arrayLayerCount = kArrayLayerCount;
config.viewArrayLayer = kArrayLayerCount - 1;
for (dawn::TextureFormat format : kBCFormats) {
for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format;
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
// 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 kActualHeightAtLevel = textureSizeLevel0.height >> config.viewMipmapLevel;
ASSERT(kActualWidthAtLevel % kBCBlockWidthInTexels != 0);
@ -590,7 +590,7 @@ TEST_P(CompressedTextureBCFormatTest, CopyBufferIntoNonZeroMipmapLevel) {
config.copyExtent3D = {kCopyWidthAtLevel, kCopyHeightAtLevel, 1};
for (dawn::TextureFormat format : kBCFormats) {
for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format;
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
// required in the copies.
const dawn::Extent3D kVirtualSize = GetVirtualSizeAtLevel(config);
const dawn::Extent3D kPhysicalSize = GetPhysicalSizeAtLevel(config);
const wgpu::Extent3D kVirtualSize = GetVirtualSizeAtLevel(config);
const wgpu::Extent3D kPhysicalSize = GetPhysicalSizeAtLevel(config);
ASSERT_NE(0u, kVirtualSize.width % kBCBlockWidthInTexels);
ASSERT_NE(0u, kVirtualSize.height % kBCBlockHeightInTexels);
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
// compressed data.
config.textureDescriptor.format = format;
// Add the usage bit for both source and destination textures so that we don't need to
// create two copy configs.
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.
dawn::Texture bcTextureDst = CreateTextureFromTexture(bcTextureSrc, config, config);
wgpu::Texture bcTextureDst = CreateTextureFromTexture(bcTextureSrc, config, config);
// Verify if we can use bcTexture as sampled textures correctly.
dawn::BindGroup bindGroup = CreateBindGroupForTest(
wgpu::BindGroup bindGroup = CreateBindGroupForTest(
bcTextureDst, format, config.viewArrayLayer, config.viewMipmapLevel);
dawn::RenderPipeline renderPipeline = CreateRenderPipelineForTest();
wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest();
std::vector<RGBA8> expectedData = GetExpectedData(format, kVirtualSize);
VerifyCompressedTexturePixelValues(renderPipeline, bindGroup, kVirtualSize,
@ -669,7 +669,7 @@ TEST_P(CompressedTextureBCFormatTest, CopyIntoSubresourceWithPhysicalSizeNotEqua
srcConfig.textureDescriptor.size = {60, 60, 1};
srcConfig.viewMipmapLevel = srcConfig.textureDescriptor.mipLevelCount - 1;
const dawn::Extent3D kSrcVirtualSize = GetVirtualSizeAtLevel(srcConfig);
const wgpu::Extent3D kSrcVirtualSize = GetVirtualSizeAtLevel(srcConfig);
CopyConfig dstConfig;
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
// 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.height % kBCBlockHeightInTexels);
const dawn::Extent3D kDstPhysicalSize = GetPhysicalSizeAtLevel(dstConfig);
const wgpu::Extent3D kDstPhysicalSize = GetPhysicalSizeAtLevel(dstConfig);
srcConfig.copyExtent3D = dstConfig.copyExtent3D = kDstPhysicalSize;
ASSERT_LT(srcConfig.copyOrigin3D.x + srcConfig.copyExtent3D.width, kSrcVirtualSize.width);
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
// compressed data.
srcConfig.textureDescriptor.format = format;
srcConfig.textureDescriptor.usage =
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst;
dawn::Texture bcTextureSrc = CreateTextureWithCompressedData(srcConfig);
dawn::TextureCopyView textureCopyViewSrc =
wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst;
wgpu::Texture bcTextureSrc = CreateTextureWithCompressedData(srcConfig);
wgpu::TextureCopyView textureCopyViewSrc =
utils::CreateTextureCopyView(bcTextureSrc, srcConfig.viewMipmapLevel,
srcConfig.viewArrayLayer, srcConfig.copyOrigin3D);
// Create bcTexture and copy from the content in bcTextureSrc into it.
dstConfig.textureDescriptor.format = format;
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.
dawn::BindGroup bindGroup = CreateBindGroupForTest(
wgpu::BindGroup bindGroup = CreateBindGroupForTest(
bcTextureDst, format, dstConfig.viewArrayLayer, dstConfig.viewMipmapLevel);
dawn::RenderPipeline renderPipeline = CreateRenderPipelineForTest();
wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest();
std::vector<RGBA8> expectedData = GetExpectedData(format, 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
// 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.height % kBCBlockHeightInTexels);
@ -745,29 +745,29 @@ TEST_P(CompressedTextureBCFormatTest, CopyFromSubresourceWithPhysicalSizeNotEqua
dstConfig.textureDescriptor.size = {16, 16, 1};
dstConfig.viewMipmapLevel = dstConfig.textureDescriptor.mipLevelCount - 1;
const dawn::Extent3D kDstVirtualSize = GetVirtualSizeAtLevel(dstConfig);
const wgpu::Extent3D kDstVirtualSize = GetVirtualSizeAtLevel(dstConfig);
srcConfig.copyExtent3D = dstConfig.copyExtent3D = kDstVirtualSize;
ASSERT_GT(srcConfig.copyOrigin3D.x + srcConfig.copyExtent3D.width, kSrcVirtualSize.width);
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.usage =
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst;
wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst;
dstConfig.textureDescriptor.usage = kDefaultBCFormatTextureUsage;
// Create bcTextureSrc as the source texture and initialize it with pre-prepared BC
// compressed data.
dawn::Texture bcTextureSrc = CreateTextureWithCompressedData(srcConfig);
wgpu::Texture bcTextureSrc = CreateTextureWithCompressedData(srcConfig);
// 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.
dawn::BindGroup bindGroup = CreateBindGroupForTest(
wgpu::BindGroup bindGroup = CreateBindGroupForTest(
bcTextureDst, format, dstConfig.viewArrayLayer, dstConfig.viewMipmapLevel);
dawn::RenderPipeline renderPipeline = CreateRenderPipelineForTest();
wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest();
std::vector<RGBA8> expectedData = GetExpectedData(format, kDstVirtualSize);
VerifyCompressedTexturePixelValues(renderPipeline, bindGroup, kDstVirtualSize,
@ -799,7 +799,7 @@ TEST_P(CompressedTextureBCFormatTest, MultipleCopiesWithPhysicalSizeNotEqualToVi
dstConfigs[0].textureDescriptor.size = {16, 16, 1};
dstConfigs[0].viewMipmapLevel = dstConfigs[0].textureDescriptor.mipLevelCount - 1;
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.height % kBCBlockHeightInTexels);
@ -811,23 +811,23 @@ TEST_P(CompressedTextureBCFormatTest, MultipleCopiesWithPhysicalSizeNotEqualToVi
dstConfigs[1].viewMipmapLevel = dstConfigs[1].textureDescriptor.mipLevelCount - 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) {
dstVirtualSizes[i] = GetVirtualSizeAtLevel(dstConfigs[i]);
}
ASSERT_NE(0u, dstVirtualSizes[1].width % kBCBlockWidthInTexels);
ASSERT_NE(0u, dstVirtualSizes[1].height % kBCBlockHeightInTexels);
for (dawn::TextureFormat format : kBCFormats) {
std::array<dawn::Texture, kTotalCopyCount> bcSrcTextures;
std::array<dawn::Texture, kTotalCopyCount> bcDstTextures;
for (wgpu::TextureFormat format : kBCFormats) {
std::array<wgpu::Texture, kTotalCopyCount> bcSrcTextures;
std::array<wgpu::Texture, kTotalCopyCount> bcDstTextures;
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
for (uint32_t i = 0; i < kTotalCopyCount; ++i) {
srcConfigs[i].textureDescriptor.format = dstConfigs[i].textureDescriptor.format =
format;
srcConfigs[i].textureDescriptor.usage =
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst;
wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst;
dstConfigs[i].textureDescriptor.usage = kDefaultBCFormatTextureUsage;
// Create bcSrcTextures as the source textures and initialize them with pre-prepared BC
@ -839,14 +839,14 @@ TEST_P(CompressedTextureBCFormatTest, MultipleCopiesWithPhysicalSizeNotEqualToVi
dstConfigs[i]);
}
dawn::CommandBuffer commandBuffer = encoder.Finish();
wgpu::CommandBuffer commandBuffer = encoder.Finish();
queue.Submit(1, &commandBuffer);
dawn::RenderPipeline renderPipeline = CreateRenderPipelineForTest();
wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest();
for (uint32_t i = 0; i < kTotalCopyCount; ++i) {
// Verify if we can use bcDstTextures as sampled textures correctly.
dawn::BindGroup bindGroup0 =
wgpu::BindGroup bindGroup0 =
CreateBindGroupForTest(bcDstTextures[i], format, dstConfigs[i].viewArrayLayer,
dstConfigs[i].viewMipmapLevel);
@ -877,7 +877,7 @@ TEST_P(CompressedTextureBCFormatTest, BufferOffsetAndExtentFitRowPitch) {
const uint32_t blockCountPerRow = config.textureDescriptor.size.width / kBCBlockWidthInTexels;
for (dawn::TextureFormat format : kBCFormats) {
for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format;
const uint32_t blockSizeInBytes = CompressedFormatBlockSizeInBytes(format);
@ -908,12 +908,12 @@ TEST_P(CompressedTextureBCFormatTest, BufferOffsetExceedsSlicePitch) {
config.textureDescriptor.size = {8, 8, 1};
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 slicePitchInBytes =
config.rowPitchAlignment * (textureSizeLevel0.height / kBCBlockHeightInTexels);
for (dawn::TextureFormat format : kBCFormats) {
for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format;
const uint32_t blockSizeInBytes = CompressedFormatBlockSizeInBytes(format);
@ -947,7 +947,7 @@ TEST_P(CompressedTextureBCFormatTest, CopyWithBufferOffsetAndExtentExceedRowPitc
constexpr uint32_t kExceedRowBlockCount = 1;
for (dawn::TextureFormat format : kBCFormats) {
for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = 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 slicePitchInBytes = config.rowPitchAlignment;
for (dawn::TextureFormat format : kBCFormats) {
for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format;
const uint32_t blockSizeInBytes = CompressedFormatBlockSizeInBytes(format);
@ -1010,7 +1010,7 @@ TEST_P(CompressedTextureBCFormatTest, LargeImageHeight) {
config.imageHeight = config.textureDescriptor.size.height * 2;
for (dawn::TextureFormat format : kBCFormats) {
for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format;
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
// 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 kActualHeightAtLevel = textureSizeLevel0.height >> config.viewMipmapLevel;
ASSERT(kActualWidthAtLevel % kBCBlockWidthInTexels != 0);
@ -1053,7 +1053,7 @@ TEST_P(CompressedTextureBCFormatTest, LargeImageHeightAndClampedCopyExtent) {
config.imageHeight = kCopyHeightAtLevel * 2;
for (dawn::TextureFormat format : kBCFormats) {
for (wgpu::TextureFormat format : kBCFormats) {
config.textureDescriptor.format = format;
TestCopyRegionIntoBCFormatTextures(config);
}

View File

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

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dawn/dawncpp.h"
#include "tests/DawnTest.h"
#include "utils/WGPUHelpers.h"
@ -45,50 +44,50 @@ class ComputeIndirectTests : public DawnTest {
void ComputeIndirectTests::BasicTest(std::initializer_list<uint32_t> bufferList,
uint64_t indirectOffset) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {
{0, dawn::ShaderStage::Compute, dawn::BindingType::UniformBuffer},
{1, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer},
{0, wgpu::ShaderStage::Compute, wgpu::BindingType::UniformBuffer},
{1, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer},
});
// Set up shader and pipeline
dawn::ShaderModule module =
wgpu::ShaderModule module =
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.computeStage.module = module;
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
dawn::Buffer dst = utils::CreateBufferFromData<uint32_t>(
wgpu::Buffer dst = utils::CreateBufferFromData<uint32_t>(
device,
dawn::BufferUsage::Storage | dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst,
wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst,
{0, 0, 0});
std::vector<uint32_t> indirectBufferData = bufferList;
dawn::Buffer indirectBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Indirect, bufferList);
wgpu::Buffer indirectBuffer =
utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Indirect, bufferList);
dawn::Buffer expectedBuffer =
wgpu::Buffer expectedBuffer =
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
dawn::BindGroup bindGroup =
wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, bgl,
{
{0, expectedBuffer, 0, 3 * sizeof(uint32_t)},
{1, dst, 0, 3 * sizeof(uint32_t)},
});
dawn::CommandBuffer commands;
wgpu::CommandBuffer commands;
{
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder pass = encoder.BeginComputePass();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup);
pass.DispatchIndirect(indirectBuffer, indirectOffset);

View File

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

View File

@ -28,10 +28,10 @@ TEST_P(ComputeStorageBufferBarrierTests, AddIncrement) {
std::vector<uint32_t> expected(kNumValues, 0x1234 * kIterations);
uint64_t bufferSize = static_cast<uint64_t>(data.size() * sizeof(uint32_t));
dawn::Buffer buffer = utils::CreateBufferFromData(
device, data.data(), bufferSize, dawn::BufferUsage::Storage | dawn::BufferUsage::CopySrc);
wgpu::Buffer buffer = utils::CreateBufferFromData(
device, data.data(), bufferSize, wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc);
dawn::ShaderModule module =
wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
#version 450
#define kNumValues 100
@ -41,28 +41,28 @@ TEST_P(ComputeStorageBufferBarrierTests, AddIncrement) {
}
)");
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}});
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
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.computeStage.module = module;
pipelineDesc.computeStage.entryPoint = "main";
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc);
wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc);
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder pass = encoder.BeginComputePass();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup);
for (uint32_t i = 0; i < kIterations; ++i) {
pass.Dispatch(kNumValues, 1, 1);
}
pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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));
dawn::Buffer bufferA = utils::CreateBufferFromData(
device, data.data(), bufferSize, dawn::BufferUsage::Storage | dawn::BufferUsage::CopySrc);
wgpu::Buffer bufferA = utils::CreateBufferFromData(
device, data.data(), bufferSize, wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc);
dawn::Buffer bufferB = utils::CreateBufferFromData(
device, data.data(), bufferSize, dawn::BufferUsage::Storage | dawn::BufferUsage::CopySrc);
wgpu::Buffer bufferB = utils::CreateBufferFromData(
device, data.data(), bufferSize, wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc);
dawn::ShaderModule module =
wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
#version 450
#define kNumValues 100
@ -95,34 +95,34 @@ TEST_P(ComputeStorageBufferBarrierTests, AddPingPong) {
}
)");
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer},
{1, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}});
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Compute, wgpu::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},
{1, bufferB, 0, bufferSize},
});
dawn::BindGroup bindGroupB = utils::MakeBindGroup(device, bgl,
wgpu::BindGroup bindGroupB = utils::MakeBindGroup(device, bgl,
{
{0, bufferB, 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.computeStage.module = module;
pipelineDesc.computeStage.entryPoint = "main";
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc);
wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc);
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder pass = encoder.BeginComputePass();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(pipeline);
for (uint32_t i = 0; i < kIterations / 2; ++i) {
@ -132,7 +132,7 @@ TEST_P(ComputeStorageBufferBarrierTests, AddPingPong) {
pass.Dispatch(kNumValues, 1, 1);
}
pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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));
dawn::Buffer bufferA = utils::CreateBufferFromData(
device, data.data(), bufferSize, dawn::BufferUsage::Storage | dawn::BufferUsage::Uniform | dawn::BufferUsage::CopySrc);
wgpu::Buffer bufferA = utils::CreateBufferFromData(
device, data.data(), bufferSize,
wgpu::BufferUsage::Storage | wgpu::BufferUsage::Uniform | wgpu::BufferUsage::CopySrc);
dawn::Buffer bufferB = utils::CreateBufferFromData(
device, data.data(), bufferSize, dawn::BufferUsage::Storage | dawn::BufferUsage::Uniform | dawn::BufferUsage::CopySrc);
wgpu::Buffer bufferB = utils::CreateBufferFromData(
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"(
#version 450
#define kNumValues 100
@ -166,43 +168,43 @@ TEST_P(ComputeStorageBufferBarrierTests, UniformToStorageAddPingPong) {
}
)");
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Compute, dawn::BindingType::UniformBuffer},
{1, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}});
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Compute, wgpu::BindingType::UniformBuffer},
{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},
{1, bufferB, 0, bufferSize},
});
dawn::BindGroup bindGroupB = utils::MakeBindGroup(device, bgl,
wgpu::BindGroup bindGroupB = utils::MakeBindGroup(device, bgl,
{
{0, bufferB, 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.computeStage.module = module;
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) {
dawn::ComputePassEncoder pass = encoder.BeginComputePass();
wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroups[b]);
pass.Dispatch(kNumValues, 1, 1);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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) {
// Create a texture that is `width` x `height` with (`level` + 1) mip levels.
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = textureSpec.width;
descriptor.size.height = textureSpec.height;
descriptor.size.depth = 1;
descriptor.arrayLayerCount = textureSpec.arraySize;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm;
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = textureSpec.level + 1;
descriptor.usage = dawn::TextureUsage::CopyDst | dawn::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor);
descriptor.usage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc;
wgpu::Texture texture = device.CreateTexture(&descriptor);
uint32_t width = textureSpec.width >> 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 texelCountPerLayer = texelsPerRow * (height - 1) + width;
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
std::vector<std::vector<RGBA8>> textureArrayData(textureSpec.arraySize);
for (uint32_t slice = 0; slice < textureSpec.arraySize; ++slice) {
@ -103,25 +103,25 @@ class CopyTests_T2B : public CopyTests {
textureArrayData[slice].data());
// 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(),
static_cast<uint32_t>(sizeof(RGBA8) * textureArrayData[slice].size()),
dawn::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView =
wgpu::BufferUsage::CopySrc);
wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(uploadBuffer, 0, rowPitch, 0);
dawn::TextureCopyView textureCopyView =
wgpu::TextureCopyView textureCopyView =
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);
}
// 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
// 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.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&bufDescriptor);
bufDescriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
wgpu::Buffer buffer = device.CreateBuffer(&bufDescriptor);
std::vector<RGBA8> emptyData(bufferSpec.size / kBytesPerTexel * textureSpec.arraySize);
buffer.SetSubData(0, static_cast<uint32_t>(emptyData.size() * sizeof(RGBA8)),
emptyData.data());
@ -129,16 +129,16 @@ class CopyTests_T2B : public CopyTests {
uint64_t bufferOffset = bufferSpec.offset;
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`
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
texture, textureSpec.level, slice, {textureSpec.x, textureSpec.y, 0});
dawn::BufferCopyView bufferCopyView =
wgpu::BufferCopyView bufferCopyView =
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);
bufferOffset += bufferSpec.size;
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
bufferOffset = bufferSpec.offset;
@ -180,10 +180,10 @@ protected:
void DoTest(const TextureSpec& textureSpec, const BufferSpec& bufferSpec) {
// Create a buffer of size `size` and populate it with data
dawn::BufferDescriptor bufDescriptor;
wgpu::BufferDescriptor bufDescriptor;
bufDescriptor.size = bufferSpec.size;
bufDescriptor.usage = dawn::BufferUsage::CopySrc | dawn::BufferUsage::CopyDst;
dawn::Buffer buffer = device.CreateBuffer(&bufDescriptor);
bufDescriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
wgpu::Buffer buffer = device.CreateBuffer(&bufDescriptor);
std::vector<RGBA8> bufferData(bufferSpec.size / kBytesPerTexel);
FillBufferData(bufferData.data(), bufferData.size());
@ -191,19 +191,19 @@ protected:
bufferData.data());
// Create a texture that is `width` x `height` with (`level` + 1) mip levels.
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = textureSpec.width;
descriptor.size.height = textureSpec.height;
descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm;
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = textureSpec.level + 1;
descriptor.usage = dawn::TextureUsage::CopyDst | dawn::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor);
descriptor.usage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc;
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
// 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;
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()),
dawn::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView =
wgpu::BufferUsage::CopySrc);
wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(uploadBuffer, 0, rowPitch, 0);
dawn::TextureCopyView textureCopyView =
wgpu::TextureCopyView textureCopyView =
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);
}
// 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);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
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);
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
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.
@ -272,31 +272,31 @@ class CopyTests_T2T : public CopyTests {
protected:
void DoTest(const TextureSpec& srcSpec, const TextureSpec& dstSpec, const CopySize& copy) {
dawn::TextureDescriptor srcDescriptor;
srcDescriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureDescriptor srcDescriptor;
srcDescriptor.dimension = wgpu::TextureDimension::e2D;
srcDescriptor.size.width = srcSpec.width;
srcDescriptor.size.height = srcSpec.height;
srcDescriptor.size.depth = 1;
srcDescriptor.arrayLayerCount = srcSpec.arraySize;
srcDescriptor.sampleCount = 1;
srcDescriptor.format = dawn::TextureFormat::RGBA8Unorm;
srcDescriptor.format = wgpu::TextureFormat::RGBA8Unorm;
srcDescriptor.mipLevelCount = srcSpec.level + 1;
srcDescriptor.usage = dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst;
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor);
srcDescriptor.usage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst;
wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
dawn::TextureDescriptor dstDescriptor;
dstDescriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureDescriptor dstDescriptor;
dstDescriptor.dimension = wgpu::TextureDimension::e2D;
dstDescriptor.size.width = dstSpec.width;
dstDescriptor.size.height = dstSpec.height;
dstDescriptor.size.depth = 1;
dstDescriptor.arrayLayerCount = dstSpec.arraySize;
dstDescriptor.sampleCount = 1;
dstDescriptor.format = dawn::TextureFormat::RGBA8Unorm;
dstDescriptor.format = wgpu::TextureFormat::RGBA8Unorm;
dstDescriptor.mipLevelCount = dstSpec.level + 1;
dstDescriptor.usage = dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst;
dawn::Texture dstTexture = device.CreateTexture(&dstDescriptor);
dstDescriptor.usage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst;
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
// `level` mip level
@ -312,15 +312,15 @@ class CopyTests_T2T : public CopyTests {
FillTextureData(width, height, rowPitch / kBytesPerTexel, slice,
textureArrayData[slice].data());
dawn::Buffer uploadBuffer = utils::CreateBufferFromData(
wgpu::Buffer uploadBuffer = utils::CreateBufferFromData(
device, textureArrayData[slice].data(),
static_cast<uint32_t>(sizeof(RGBA8) * textureArrayData[slice].size()),
dawn::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView =
wgpu::BufferUsage::CopySrc);
wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(uploadBuffer, 0, rowPitch, 0);
dawn::TextureCopyView textureCopyView =
wgpu::TextureCopyView textureCopyView =
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);
}
@ -337,28 +337,28 @@ class CopyTests_T2T : public CopyTests {
uint32_t dstTexelCount = dstTexelsPerRow * (dstHeight - 1) + dstWidth;
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()),
dawn::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView =
wgpu::BufferUsage::CopySrc);
wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(uploadBuffer, 0, dstRowPitch, 0);
dawn::TextureCopyView textureCopyView =
wgpu::TextureCopyView textureCopyView =
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);
}
// Perform the texture to texture copy
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});
dawn::TextureCopyView dstTextureCopyView = utils::CreateTextureCopyView(
wgpu::TextureCopyView dstTextureCopyView = utils::CreateTextureCopyView(
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);
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
std::vector<RGBA8> expected(rowPitch / kBytesPerTexel * (copy.height - 1) + copy.width);

View File

@ -19,7 +19,7 @@
class CullingTest : public DawnTest {
protected:
dawn::RenderPipeline CreatePipelineForTest(dawn::FrontFace frontFace, dawn::CullMode cullMode) {
wgpu::RenderPipeline CreatePipelineForTest(wgpu::FrontFace frontFace, wgpu::CullMode cullMode) {
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
// Draw two triangles with different winding orders:
@ -58,12 +58,12 @@ class CullingTest : public DawnTest {
return device.CreateRenderPipeline(&pipelineDescriptor);
}
dawn::Texture Create2DTextureForTest(dawn::TextureFormat format) {
dawn::TextureDescriptor textureDescriptor;
textureDescriptor.dimension = dawn::TextureDimension::e2D;
wgpu::Texture Create2DTextureForTest(wgpu::TextureFormat format) {
wgpu::TextureDescriptor textureDescriptor;
textureDescriptor.dimension = wgpu::TextureDimension::e2D;
textureDescriptor.format = format;
textureDescriptor.usage =
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc;
wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
textureDescriptor.arrayLayerCount = 1;
textureDescriptor.mipLevelCount = 1;
textureDescriptor.sampleCount = 1;
@ -71,23 +71,23 @@ class CullingTest : public DawnTest {
return device.CreateTexture(&textureDescriptor);
}
void DoTest(dawn::FrontFace frontFace,
dawn::CullMode cullMode,
void DoTest(wgpu::FrontFace frontFace,
wgpu::CullMode cullMode,
bool isCCWTriangleCulled,
bool isCWTriangleCulled) {
dawn::Texture colorTexture = Create2DTextureForTest(dawn::TextureFormat::RGBA8Unorm);
wgpu::Texture colorTexture = Create2DTextureForTest(wgpu::TextureFormat::RGBA8Unorm);
utils::ComboRenderPassDescriptor renderPassDescriptor({colorTexture.CreateView()});
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();
dawn::RenderPassEncoder renderPass = commandEncoder.BeginRenderPass(&renderPassDescriptor);
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
wgpu::RenderPassEncoder renderPass = commandEncoder.BeginRenderPass(&renderPassDescriptor);
renderPass.SetPipeline(CreatePipelineForTest(frontFace, cullMode));
renderPass.Draw(6, 1, 0, 0);
renderPass.EndPass();
dawn::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue();
wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer);
constexpr RGBA8 kTopLeftColor = RGBA8(0, 0, 0, 255);
@ -106,27 +106,27 @@ class CullingTest : public DawnTest {
};
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) {
DoTest(dawn::FrontFace::CCW, dawn::CullMode::Front, true, false);
DoTest(wgpu::FrontFace::CCW, wgpu::CullMode::Front, true, false);
}
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) {
DoTest(dawn::FrontFace::CW, dawn::CullMode::None, false, false);
DoTest(wgpu::FrontFace::CW, wgpu::CullMode::None, false, false);
}
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) {
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);

View File

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

View File

@ -22,23 +22,23 @@ class DebugMarkerTests : public DawnTest {};
TEST_P(DebugMarkerTests, NoFailureWithoutDebugToolAttached) {
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.InsertDebugMarker("Marker");
pass.PopDebugGroup();
pass.EndPass();
}
{
dawn::ComputePassEncoder pass = encoder.BeginComputePass();
wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.PushDebugGroup("Event Start");
pass.InsertDebugMarker("Marker");
pass.PopDebugGroup();
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
}

View File

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

View File

@ -26,7 +26,7 @@ class DestroyTest : public DawnTest {
renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::ShaderModule vsModule =
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
layout(location = 0) in vec4 pos;
@ -34,7 +34,7 @@ class DestroyTest : public DawnTest {
gl_Position = pos;
})");
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
@ -45,40 +45,40 @@ class DestroyTest : public DawnTest {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
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;
pipeline = device.CreateRenderPipeline(&descriptor);
vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex,
device, wgpu::BufferUsage::Vertex,
{// 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});
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.BeginRenderPass(&renderPass.renderPassInfo).EndPass();
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
}
utils::BasicRenderPass renderPass;
dawn::RenderPipeline pipeline;
dawn::Buffer vertexBuffer;
wgpu::RenderPipeline pipeline;
wgpu::Buffer vertexBuffer;
dawn::CommandBuffer CreateTriangleCommandBuffer() {
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandBuffer CreateTriangleCommandBuffer() {
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer);
pass.Draw(3, 1, 0, 0);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
return commands;
}
};
@ -87,7 +87,7 @@ class DestroyTest : public DawnTest {
TEST_P(DestroyTest, BufferDestroyBeforeSubmit) {
RGBA8 notFilled(0, 0, 0, 0);
dawn::CommandBuffer commands = CreateTriangleCommandBuffer();
wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
vertexBuffer.Destroy();
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
@ -98,7 +98,7 @@ TEST_P(DestroyTest, BufferDestroyBeforeSubmit) {
TEST_P(DestroyTest, BufferDestroyAfterSubmit) {
RGBA8 filled(0, 255, 0, 255);
dawn::CommandBuffer commands = CreateTriangleCommandBuffer();
wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3);
@ -110,7 +110,7 @@ TEST_P(DestroyTest, BufferDestroyAfterSubmit) {
TEST_P(DestroyTest, BufferSubmitDestroySubmit) {
RGBA8 filled(0, 255, 0, 255);
dawn::CommandBuffer commands = CreateTriangleCommandBuffer();
wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3);
@ -125,7 +125,7 @@ TEST_P(DestroyTest, BufferSubmitDestroySubmit) {
// Destroy texture before submit should fail submit
TEST_P(DestroyTest, TextureDestroyBeforeSubmit) {
dawn::CommandBuffer commands = CreateTriangleCommandBuffer();
wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
renderPass.color.Destroy();
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
}
@ -134,7 +134,7 @@ TEST_P(DestroyTest, TextureDestroyBeforeSubmit) {
TEST_P(DestroyTest, TextureDestroyAfterSubmit) {
RGBA8 filled(0, 255, 0, 255);
dawn::CommandBuffer commands = CreateTriangleCommandBuffer();
wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, 1, 3);
@ -146,7 +146,7 @@ TEST_P(DestroyTest, TextureDestroyAfterSubmit) {
TEST_P(DestroyTest, TextureSubmitDestroySubmit) {
RGBA8 filled(0, 255, 0, 255);
dawn::CommandBuffer commands = CreateTriangleCommandBuffer();
wgpu::CommandBuffer commands = CreateTriangleCommandBuffer();
queue.Submit(1, &commands);
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);
dawn::ShaderModule vsModule =
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
layout(location = 0) in vec4 pos;
@ -34,7 +34,7 @@ class DrawIndexedIndirectTest : public DawnTest {
gl_Position = pos;
})");
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
@ -45,17 +45,17 @@ class DrawIndexedIndirectTest : public DawnTest {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
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;
pipeline = device.CreateRenderPipeline(&descriptor);
vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex,
device, wgpu::BufferUsage::Vertex,
{// 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,
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,
0.0f, 1.0f});
indexBuffer = utils::CreateBufferFromData<uint32_t>(
device, dawn::BufferUsage::Index,
device, wgpu::BufferUsage::Index,
{0, 1, 2, 0, 3, 1,
// The indices below are added to test negatve baseVertex
0 + 4, 1 + 4, 2 + 4, 0 + 4, 3 + 4, 1 + 4});
}
utils::BasicRenderPass renderPass;
dawn::RenderPipeline pipeline;
dawn::Buffer vertexBuffer;
dawn::Buffer indexBuffer;
wgpu::RenderPipeline pipeline;
wgpu::Buffer vertexBuffer;
wgpu::Buffer indexBuffer;
void Test(std::initializer_list<uint32_t> bufferList,
uint64_t indexOffset,
uint64_t indirectOffset,
RGBA8 bottomLeftExpected,
RGBA8 topRightExpected) {
dawn::Buffer indirectBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Indirect, bufferList);
wgpu::Buffer indirectBuffer =
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.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer, indexOffset);
@ -93,7 +93,7 @@ class DrawIndexedIndirectTest : public DawnTest {
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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);
dawn::ShaderModule vsModule =
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
layout(location = 0) in vec4 pos;
@ -34,7 +34,7 @@ class DrawIndexedTest : public DawnTest {
gl_Position = pos;
})");
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
@ -45,17 +45,17 @@ class DrawIndexedTest : public DawnTest {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
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;
pipeline = device.CreateRenderPipeline(&descriptor);
vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex,
device, wgpu::BufferUsage::Vertex,
{// 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, 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, 0.0f, 1.0f});
indexBuffer = utils::CreateBufferFromData<uint32_t>(
device, dawn::BufferUsage::Index,
device, wgpu::BufferUsage::Index,
{0, 1, 2, 0, 3, 1,
// The indices below are added to test negatve baseVertex
0 + 4, 1 + 4, 2 + 4, 0 + 4, 3 + 4, 1 + 4});
}
utils::BasicRenderPass renderPass;
dawn::RenderPipeline pipeline;
dawn::Buffer vertexBuffer;
dawn::Buffer indexBuffer;
wgpu::RenderPipeline pipeline;
wgpu::Buffer vertexBuffer;
wgpu::Buffer indexBuffer;
void Test(uint32_t indexCount,
uint32_t instanceCount,
@ -83,10 +83,9 @@ class DrawIndexedTest : public DawnTest {
uint64_t bufferOffset,
RGBA8 bottomLeftExpected,
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.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer, bufferOffset);
@ -94,7 +93,7 @@ class DrawIndexedTest : public DawnTest {
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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);
dawn::ShaderModule vsModule =
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
layout(location = 0) in vec4 pos;
@ -34,7 +34,7 @@ class DrawIndirectTest : public DawnTest {
gl_Position = pos;
})");
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
@ -45,17 +45,17 @@ class DrawIndirectTest : public DawnTest {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
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;
pipeline = device.CreateRenderPipeline(&descriptor);
vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex,
device, wgpu::BufferUsage::Vertex,
{// 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,
@ -64,26 +64,26 @@ class DrawIndirectTest : public DawnTest {
}
utils::BasicRenderPass renderPass;
dawn::RenderPipeline pipeline;
dawn::Buffer vertexBuffer;
wgpu::RenderPipeline pipeline;
wgpu::Buffer vertexBuffer;
void Test(std::initializer_list<uint32_t> bufferList,
uint64_t indirectOffset,
RGBA8 bottomLeftExpected,
RGBA8 topRightExpected) {
dawn::Buffer indirectBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Indirect, bufferList);
wgpu::Buffer indirectBuffer =
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.SetVertexBuffer(0, vertexBuffer);
pass.DrawIndirect(indirectBuffer, indirectOffset);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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);
dawn::ShaderModule vsModule =
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
layout(location = 0) in vec4 pos;
@ -34,7 +34,7 @@ class DrawTest : public DawnTest {
gl_Position = pos;
})");
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
@ -45,17 +45,17 @@ class DrawTest : public DawnTest {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
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;
pipeline = device.CreateRenderPipeline(&descriptor);
vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex,
device, wgpu::BufferUsage::Vertex,
{// 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,
@ -64,8 +64,8 @@ class DrawTest : public DawnTest {
}
utils::BasicRenderPass renderPass;
dawn::RenderPipeline pipeline;
dawn::Buffer vertexBuffer;
wgpu::RenderPipeline pipeline;
wgpu::Buffer vertexBuffer;
void Test(uint32_t vertexCount,
uint32_t instanceCount,
@ -73,16 +73,16 @@ class DrawTest : public DawnTest {
uint32_t firstInstance,
RGBA8 bottomLeftExpected,
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.SetVertexBuffer(0, vertexBuffer);
pass.Draw(vertexCount, instanceCount, firstIndex, firstInstance);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3);

View File

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

View File

@ -22,21 +22,21 @@ using namespace testing;
class MockFenceOnCompletionCallback {
public:
MOCK_METHOD2(Call, void(DawnFenceCompletionStatus status, void* userdata));
MOCK_METHOD2(Call, void(WGPUFenceCompletionStatus status, void* userdata));
};
static std::unique_ptr<MockFenceOnCompletionCallback> mockFenceOnCompletionCallback;
static void ToMockFenceOnCompletionCallback(DawnFenceCompletionStatus status, void* userdata) {
static void ToMockFenceOnCompletionCallback(WGPUFenceCompletionStatus status, void* userdata) {
mockFenceOnCompletionCallback->Call(status, userdata);
}
class MockPopErrorScopeCallback {
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 void ToMockPopErrorScopeCallback(DawnErrorType type, const char* message, void* userdata) {
static void ToMockPopErrorScopeCallback(WGPUErrorType type, const char* message, void* userdata) {
mockPopErrorScopeCallback->Call(type, message, userdata);
}
@ -45,10 +45,10 @@ class FenceTests : public DawnTest {
struct CallbackInfo {
FenceTests* test;
uint64_t value;
DawnFenceCompletionStatus status;
WGPUFenceCompletionStatus status;
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->status = status;
}
@ -72,7 +72,7 @@ class FenceTests : public DawnTest {
DawnTest::TearDown();
}
void WaitForCompletedValue(dawn::Fence fence, uint64_t completedValue) {
void WaitForCompletedValue(wgpu::Fence fence, uint64_t completedValue) {
while (fence.GetCompletedValue() < completedValue) {
WaitABit();
}
@ -81,9 +81,9 @@ class FenceTests : public DawnTest {
// Test that signaling a fence updates the completed value
TEST_P(FenceTests, SimpleSignal) {
dawn::FenceDescriptor descriptor;
wgpu::FenceDescriptor descriptor;
descriptor.initialValue = 1u;
dawn::Fence fence = queue.CreateFence(&descriptor);
wgpu::Fence fence = queue.CreateFence(&descriptor);
// Completed value starts at initial value
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_P(FenceTests, OnCompletionOrdering) {
dawn::FenceDescriptor descriptor;
wgpu::FenceDescriptor descriptor;
descriptor.initialValue = 0u;
dawn::Fence fence = queue.CreateFence(&descriptor);
wgpu::Fence fence = queue.CreateFence(&descriptor);
queue.Signal(fence, 4);
@ -107,19 +107,19 @@ TEST_P(FenceTests, OnCompletionOrdering) {
testing::InSequence s;
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 0))
Call(WGPUFenceCompletionStatus_Success, this + 0))
.Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 1))
Call(WGPUFenceCompletionStatus_Success, this + 1))
.Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 2))
Call(WGPUFenceCompletionStatus_Success, this + 2))
.Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 3))
Call(WGPUFenceCompletionStatus_Success, this + 3))
.Times(1);
}
@ -133,14 +133,14 @@ TEST_P(FenceTests, OnCompletionOrdering) {
// Test callbacks still occur if Queue::Signal happens multiple times
TEST_P(FenceTests, MultipleSignalOnCompletion) {
dawn::FenceDescriptor descriptor;
wgpu::FenceDescriptor descriptor;
descriptor.initialValue = 0u;
dawn::Fence fence = queue.CreateFence(&descriptor);
wgpu::Fence fence = queue.CreateFence(&descriptor);
queue.Signal(fence, 2);
queue.Signal(fence, 4);
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, nullptr))
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(WGPUFenceCompletionStatus_Success, nullptr))
.Times(1);
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_P(FenceTests, OnCompletionMultipleCallbacks) {
dawn::FenceDescriptor descriptor;
wgpu::FenceDescriptor descriptor;
descriptor.initialValue = 0u;
dawn::Fence fence = queue.CreateFence(&descriptor);
wgpu::Fence fence = queue.CreateFence(&descriptor);
queue.Signal(fence, 4);
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 0))
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(WGPUFenceCompletionStatus_Success, this + 0))
.Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 1))
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(WGPUFenceCompletionStatus_Success, this + 1))
.Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 2))
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(WGPUFenceCompletionStatus_Success, this + 2))
.Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 3))
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(WGPUFenceCompletionStatus_Success, this + 3))
.Times(1);
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
// Currently it holds a reference and is not destructed
TEST_P(FenceTests, DISABLED_DestroyBeforeOnCompletionEnd) {
dawn::FenceDescriptor descriptor;
wgpu::FenceDescriptor descriptor;
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
{
dawn::FenceDescriptor descriptor;
wgpu::FenceDescriptor descriptor;
descriptor.initialValue = 0u;
dawn::Fence testFence = queue.CreateFence(&descriptor);
wgpu::Fence testFence = queue.CreateFence(&descriptor);
queue.Signal(testFence, 4);
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, this + 0))
Call(WGPUFenceCompletionStatus_Unknown, this + 0))
.Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, this + 1))
Call(WGPUFenceCompletionStatus_Unknown, this + 1))
.Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, this + 2))
Call(WGPUFenceCompletionStatus_Unknown, this + 2))
.Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, this + 3))
Call(WGPUFenceCompletionStatus_Unknown, this + 3))
.Times(1);
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
// in error scopes.
TEST_P(FenceTests, ClientValidationErrorInErrorScope) {
dawn::FenceDescriptor descriptor;
wgpu::FenceDescriptor descriptor;
descriptor.initialValue = 0u;
dawn::Fence fence = queue.CreateFence(&descriptor);
wgpu::Fence fence = queue.CreateFence(&descriptor);
queue.Signal(fence, 4);
device.PushErrorScope(dawn::ErrorFilter::Validation);
device.PushErrorScope(wgpu::ErrorFilter::Validation);
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);
WaitForCompletedValue(fence, 4);

View File

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

View File

@ -30,8 +30,8 @@ class IndexFormatTest : public DawnTest {
utils::BasicRenderPass renderPass;
dawn::RenderPipeline MakeTestPipeline(dawn::IndexFormat format) {
dawn::ShaderModule vsModule =
wgpu::RenderPipeline MakeTestPipeline(wgpu::IndexFormat format) {
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
layout(location = 0) in vec4 pos;
@ -39,7 +39,7 @@ class IndexFormatTest : public DawnTest {
gl_Position = pos;
})");
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
@ -50,12 +50,12 @@ class IndexFormatTest : public DawnTest {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cVertexInput.indexFormat = format;
descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
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;
return device.CreateRenderPipeline(&descriptor);
@ -64,19 +64,19 @@ class IndexFormatTest : public DawnTest {
// Test that the Uint32 index format is correctly interpreted
TEST_P(IndexFormatTest, Uint32) {
dawn::RenderPipeline pipeline = MakeTestPipeline(dawn::IndexFormat::Uint32);
wgpu::RenderPipeline pipeline = MakeTestPipeline(wgpu::IndexFormat::Uint32);
dawn::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex,
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
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, 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.
dawn::Buffer indexBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Index, {1, 2, 3});
wgpu::Buffer indexBuffer =
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.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer);
@ -84,7 +84,7 @@ TEST_P(IndexFormatTest, Uint32) {
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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_P(IndexFormatTest, Uint16) {
dawn::RenderPipeline pipeline = MakeTestPipeline(dawn::IndexFormat::Uint16);
wgpu::RenderPipeline pipeline = MakeTestPipeline(wgpu::IndexFormat::Uint16);
dawn::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex,
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
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});
// If this is interpreted as uint32, it will have index 1 and 2 be both 0 and render nothing
dawn::Buffer indexBuffer =
utils::CreateBufferFromData<uint16_t>(device, dawn::BufferUsage::Index, {1, 2, 0, 0, 0, 0});
wgpu::Buffer indexBuffer =
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.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer);
@ -111,7 +111,7 @@ TEST_P(IndexFormatTest, Uint16) {
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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_P(IndexFormatTest, Uint32PrimitiveRestart) {
dawn::RenderPipeline pipeline = MakeTestPipeline(dawn::IndexFormat::Uint32);
wgpu::RenderPipeline pipeline = MakeTestPipeline(wgpu::IndexFormat::Uint32);
dawn::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex,
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
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, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
});
dawn::Buffer indexBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Index,
wgpu::Buffer indexBuffer =
utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Index,
{
0,
1,
@ -151,9 +151,9 @@ TEST_P(IndexFormatTest, Uint32PrimitiveRestart) {
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.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer);
@ -161,7 +161,7 @@ TEST_P(IndexFormatTest, Uint32PrimitiveRestart) {
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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_P(IndexFormatTest, Uint16PrimitiveRestart) {
dawn::RenderPipeline pipeline = MakeTestPipeline(dawn::IndexFormat::Uint16);
wgpu::RenderPipeline pipeline = MakeTestPipeline(wgpu::IndexFormat::Uint16);
dawn::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex,
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
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, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
});
dawn::Buffer indexBuffer =
utils::CreateBufferFromData<uint16_t>(device, dawn::BufferUsage::Index,
wgpu::Buffer indexBuffer =
utils::CreateBufferFromData<uint16_t>(device, wgpu::BufferUsage::Index,
{
0,
1,
@ -193,9 +193,9 @@ TEST_P(IndexFormatTest, Uint16PrimitiveRestart) {
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.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer);
@ -203,7 +203,7 @@ TEST_P(IndexFormatTest, Uint16PrimitiveRestart) {
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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) {
DAWN_SKIP_TEST_IF(IsD3D12() || IsVulkan());
dawn::RenderPipeline pipeline32 = MakeTestPipeline(dawn::IndexFormat::Uint32);
dawn::RenderPipeline pipeline16 = MakeTestPipeline(dawn::IndexFormat::Uint16);
wgpu::RenderPipeline pipeline32 = MakeTestPipeline(wgpu::IndexFormat::Uint32);
wgpu::RenderPipeline pipeline16 = MakeTestPipeline(wgpu::IndexFormat::Uint16);
dawn::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
device, dawn::BufferUsage::Vertex,
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
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, 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.
dawn::Buffer indexBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Index, {1, 2, 3});
wgpu::Buffer indexBuffer =
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.SetVertexBuffer(0, vertexBuffer);
pass.SetIndexBuffer(indexBuffer);
@ -239,7 +239,7 @@ TEST_P(IndexFormatTest, ChangePipelineAfterSetIndexBuffer) {
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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
// we want to support eventually.
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>(
device, dawn::BufferUsage::Vertex,
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
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});
dawn::Buffer indexBuffer =
utils::CreateBufferFromData<uint32_t>(device, dawn::BufferUsage::Index, {0, 1, 2});
wgpu::Buffer indexBuffer =
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.SetPipeline(pipeline);
pass.SetVertexBuffer(0, vertexBuffer);
@ -269,7 +269,7 @@ TEST_P(IndexFormatTest, DISABLED_SetIndexBufferBeforeSetPipeline) {
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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();
}
dawn::RenderPipeline CreateRenderPipelineWithOneOutputForTest(bool testDepth) {
wgpu::RenderPipeline CreateRenderPipelineWithOneOutputForTest(bool testDepth) {
const char* kFsOneOutputWithDepth =
R"(#version 450
layout(location = 0) out vec4 fragColor;
@ -65,7 +65,7 @@ class MultisampledRenderingTest : public DawnTest {
return CreateRenderPipelineForTest(fs, 1, testDepth);
}
dawn::RenderPipeline CreateRenderPipelineWithTwoOutputsForTest() {
wgpu::RenderPipeline CreateRenderPipelineWithTwoOutputsForTest() {
const char* kFsTwoOutputs =
R"(#version 450
layout(location = 0) out vec4 fragColor1;
@ -82,12 +82,12 @@ class MultisampledRenderingTest : public DawnTest {
return CreateRenderPipelineForTest(kFsTwoOutputs, 2, false);
}
dawn::Texture CreateTextureForOutputAttachment(dawn::TextureFormat format,
wgpu::Texture CreateTextureForOutputAttachment(wgpu::TextureFormat format,
uint32_t sampleCount,
uint32_t mipLevelCount = 1,
uint32_t arrayLayerCount = 1) {
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kWidth << (mipLevelCount - 1);
descriptor.size.height = kHeight << (mipLevelCount - 1);
descriptor.size.depth = 1;
@ -95,22 +95,21 @@ class MultisampledRenderingTest : public DawnTest {
descriptor.sampleCount = sampleCount;
descriptor.format = format;
descriptor.mipLevelCount = mipLevelCount;
descriptor.usage = dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc;
descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
return device.CreateTexture(&descriptor);
}
void EncodeRenderPassForTest(dawn::CommandEncoder commandEncoder,
const dawn::RenderPassDescriptor& renderPass,
const dawn::RenderPipeline& pipeline,
void EncodeRenderPassForTest(wgpu::CommandEncoder commandEncoder,
const wgpu::RenderPassDescriptor& renderPass,
const wgpu::RenderPipeline& pipeline,
const float* uniformData,
uint32_t uniformDataSize) {
dawn::Buffer uniformBuffer = utils::CreateBufferFromData(
device, uniformData, uniformDataSize, dawn::BufferUsage::Uniform);
dawn::BindGroup bindGroup =
utils::MakeBindGroup(device, mBindGroupLayout,
{{0, uniformBuffer, 0, uniformDataSize}});
wgpu::Buffer uniformBuffer = utils::CreateBufferFromData(
device, uniformData, uniformDataSize, wgpu::BufferUsage::Uniform);
wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, mBindGroupLayout,
{{0, uniformBuffer, 0, uniformDataSize}});
dawn::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(&renderPass);
wgpu::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(&renderPass);
renderPassEncoder.SetPipeline(pipeline);
renderPassEncoder.SetBindGroup(0, bindGroup);
renderPassEncoder.Draw(3, 1, 0, 0);
@ -118,19 +117,19 @@ class MultisampledRenderingTest : public DawnTest {
}
utils::ComboRenderPassDescriptor CreateComboRenderPassDescriptorForTest(
std::initializer_list<dawn::TextureView> colorViews,
std::initializer_list<dawn::TextureView> resolveTargetViews,
dawn::LoadOp colorLoadOp,
dawn::LoadOp depthStencilLoadOp,
std::initializer_list<wgpu::TextureView> colorViews,
std::initializer_list<wgpu::TextureView> resolveTargetViews,
wgpu::LoadOp colorLoadOp,
wgpu::LoadOp depthStencilLoadOp,
bool hasDepthStencilAttachment) {
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;
utils::ComboRenderPassDescriptor renderPass(colorViews);
uint32_t i = 0;
for (const dawn::TextureView& resolveTargetView : resolveTargetViews) {
for (const wgpu::TextureView& resolveTargetView : resolveTargetViews) {
renderPass.cColorAttachments[i].loadOp = colorLoadOp;
renderPass.cColorAttachments[i].clearColor = kClearColor;
renderPass.cColorAttachments[i].resolveTarget = resolveTargetView;
@ -148,8 +147,8 @@ class MultisampledRenderingTest : public DawnTest {
return renderPass;
}
void VerifyResolveTarget(const dawn::Color& inputColor,
dawn::Texture resolveTexture,
void VerifyResolveTarget(const wgpu::Color& inputColor,
wgpu::Texture resolveTexture,
uint32_t mipmapLevel = 0,
uint32_t arrayLayer = 0) {
constexpr float kMSAACoverage = 0.5f;
@ -171,19 +170,19 @@ class MultisampledRenderingTest : public DawnTest {
constexpr static uint32_t kWidth = 3;
constexpr static uint32_t kHeight = 3;
constexpr static uint32_t kSampleCount = 4;
constexpr static dawn::TextureFormat kColorFormat = dawn::TextureFormat::RGBA8Unorm;
constexpr static dawn::TextureFormat kDepthStencilFormat =
dawn::TextureFormat::Depth24PlusStencil8;
constexpr static wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
constexpr static wgpu::TextureFormat kDepthStencilFormat =
wgpu::TextureFormat::Depth24PlusStencil8;
dawn::TextureView mMultisampledColorView;
dawn::Texture mResolveTexture;
dawn::TextureView mResolveView;
dawn::Texture mDepthStencilTexture;
dawn::TextureView mDepthStencilView;
dawn::BindGroupLayout mBindGroupLayout;
wgpu::TextureView mMultisampledColorView;
wgpu::Texture mResolveTexture;
wgpu::TextureView mResolveView;
wgpu::Texture mDepthStencilTexture;
wgpu::TextureView mDepthStencilView;
wgpu::BindGroupLayout mBindGroupLayout;
private:
dawn::RenderPipeline CreateRenderPipelineForTest(const char* fs,
wgpu::RenderPipeline CreateRenderPipelineForTest(const char* fs,
uint32_t numColorAttachments,
bool hasDepthStencilAttachment) {
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
@ -204,16 +203,16 @@ class MultisampledRenderingTest : public DawnTest {
mBindGroupLayout = utils::MakeBindGroupLayout(
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);
pipelineDescriptor.layout = pipelineLayout;
if (hasDepthStencilAttachment) {
pipelineDescriptor.cDepthStencilState.format = kDepthStencilFormat;
pipelineDescriptor.cDepthStencilState.depthWriteEnabled = true;
pipelineDescriptor.cDepthStencilState.depthCompare = dawn::CompareFunction::Less;
pipelineDescriptor.cDepthStencilState.depthCompare = wgpu::CompareFunction::Less;
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_P(MultisampledRenderingTest, ResolveInto2DTexture) {
constexpr bool kTestDepth = false;
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth);
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
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);
// Draw a green triangle.
{
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {mResolveView}, dawn::LoadOp::Clear, dawn::LoadOp::Clear,
{mMultisampledColorView}, {mResolveView}, wgpu::LoadOp::Clear, wgpu::LoadOp::Clear,
kTestDepth);
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, &kGreen.r, kSize);
}
dawn::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue();
wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer);
VerifyResolveTarget(kGreen, mResolveTexture);
@ -256,17 +255,17 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DTexture) {
// Test multisampled rendering with depth test works correctly.
TEST_P(MultisampledRenderingTest, MultisampledRenderingWithDepthTest) {
constexpr bool kTestDepth = true;
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth);
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
wgpu::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth);
constexpr dawn::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 kGreen = {0.0f, 0.8f, 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.
{
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {mResolveView}, dawn::LoadOp::Clear, dawn::LoadOp::Clear,
true);
utils::ComboRenderPassDescriptor renderPass =
CreateComboRenderPassDescriptorForTest({mMultisampledColorView}, {mResolveView},
wgpu::LoadOp::Clear, wgpu::LoadOp::Clear, true);
std::array<float, 5> kUniformData = {kGreen.r, kGreen.g, kGreen.b, kGreen.a, // Color
0.2f}; // depth
constexpr uint32_t kSize = sizeof(kUniformData);
@ -278,7 +277,7 @@ TEST_P(MultisampledRenderingTest, MultisampledRenderingWithDepthTest) {
// the last render pass.
{
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {mResolveView}, dawn::LoadOp::Load, dawn::LoadOp::Load,
{mMultisampledColorView}, {mResolveView}, wgpu::LoadOp::Load, wgpu::LoadOp::Load,
kTestDepth);
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);
}
dawn::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue();
wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer);
// 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.
TEST_P(MultisampledRenderingTest, ResolveInAnotherRenderPass) {
constexpr bool kTestDepth = false;
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth);
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
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);
// In first render pass we draw a green triangle and do not set the resolve target.
{
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {nullptr}, dawn::LoadOp::Clear, dawn::LoadOp::Clear,
{mMultisampledColorView}, {nullptr}, wgpu::LoadOp::Clear, wgpu::LoadOp::Clear,
kTestDepth);
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.
{
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {mResolveView}, dawn::LoadOp::Load, dawn::LoadOp::Load,
{mMultisampledColorView}, {mResolveView}, wgpu::LoadOp::Load, wgpu::LoadOp::Load,
kTestDepth);
dawn::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(&renderPass);
wgpu::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(&renderPass);
renderPassEncoder.EndPass();
}
dawn::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue();
wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer);
VerifyResolveTarget(kGreen, mResolveTexture);
@ -334,16 +333,16 @@ TEST_P(MultisampledRenderingTest, ResolveInAnotherRenderPass) {
// Test doing MSAA resolve into multiple resolve targets works correctly.
TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargets) {
dawn::TextureView multisampledColorView2 =
wgpu::TextureView multisampledColorView2 =
CreateTextureForOutputAttachment(kColorFormat, kSampleCount).CreateView();
dawn::Texture resolveTexture2 = CreateTextureForOutputAttachment(kColorFormat, 1);
dawn::TextureView resolveView2 = resolveTexture2.CreateView();
wgpu::Texture resolveTexture2 = CreateTextureForOutputAttachment(kColorFormat, 1);
wgpu::TextureView resolveView2 = resolveTexture2.CreateView();
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPipeline pipeline = CreateRenderPipelineWithTwoOutputsForTest();
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
wgpu::RenderPipeline pipeline = CreateRenderPipelineWithTwoOutputsForTest();
constexpr dawn::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 kGreen = {0.0f, 0.8f, 0.0f, 0.8f};
constexpr wgpu::Color kRed = {0.8f, 0.0f, 0.0f, 0.8f};
constexpr bool kTestDepth = false;
// 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(
{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
kGreen.r, kGreen.g, kGreen.b, kGreen.a}; // color2
@ -359,8 +358,8 @@ TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargets) {
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, kUniformData.data(), kSize);
}
dawn::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue();
wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer);
VerifyResolveTarget(kRed, mResolveTexture);
@ -370,18 +369,18 @@ TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargets) {
// Test doing MSAA resolve on one multisampled texture twice works correctly.
TEST_P(MultisampledRenderingTest, ResolveOneMultisampledTextureTwice) {
constexpr bool kTestDepth = false;
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth);
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
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);
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.
{
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {mResolveView}, dawn::LoadOp::Clear, dawn::LoadOp::Clear,
{mMultisampledColorView}, {mResolveView}, wgpu::LoadOp::Clear, wgpu::LoadOp::Clear,
kTestDepth);
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.
{
dawn::TextureView resolveView2 = resolveTexture2.CreateView();
wgpu::TextureView resolveView2 = resolveTexture2.CreateView();
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {resolveView2}, dawn::LoadOp::Load, dawn::LoadOp::Load,
{mMultisampledColorView}, {resolveView2}, wgpu::LoadOp::Load, wgpu::LoadOp::Load,
kTestDepth);
dawn::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(&renderPass);
wgpu::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(&renderPass);
renderPassEncoder.EndPass();
}
dawn::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue();
wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer);
VerifyResolveTarget(kGreen, mResolveTexture);
@ -410,35 +409,35 @@ TEST_P(MultisampledRenderingTest, ResolveOneMultisampledTextureTwice) {
TEST_P(MultisampledRenderingTest, ResolveIntoOneMipmapLevelOf2DTexture) {
constexpr uint32_t kBaseMipLevel = 2;
dawn::TextureViewDescriptor textureViewDescriptor;
textureViewDescriptor.dimension = dawn::TextureViewDimension::e2D;
wgpu::TextureViewDescriptor textureViewDescriptor;
textureViewDescriptor.dimension = wgpu::TextureViewDimension::e2D;
textureViewDescriptor.format = kColorFormat;
textureViewDescriptor.baseArrayLayer = 0;
textureViewDescriptor.arrayLayerCount = 1;
textureViewDescriptor.mipLevelCount = 1;
textureViewDescriptor.baseMipLevel = kBaseMipLevel;
dawn::Texture resolveTexture =
wgpu::Texture resolveTexture =
CreateTextureForOutputAttachment(kColorFormat, 1, kBaseMipLevel + 1, 1);
dawn::TextureView resolveView = resolveTexture.CreateView(&textureViewDescriptor);
wgpu::TextureView resolveView = resolveTexture.CreateView(&textureViewDescriptor);
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
constexpr dawn::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f};
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
constexpr wgpu::Color kGreen = {0.0f, 0.8f, 0.0f, 0.8f};
constexpr uint32_t kSize = sizeof(kGreen);
constexpr bool kTestDepth = false;
// Draw a green triangle and do MSAA resolve.
{
utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest(
{mMultisampledColorView}, {resolveView}, dawn::LoadOp::Clear, dawn::LoadOp::Clear,
{mMultisampledColorView}, {resolveView}, wgpu::LoadOp::Clear, wgpu::LoadOp::Clear,
kTestDepth);
dawn::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth);
wgpu::RenderPipeline pipeline = CreateRenderPipelineWithOneOutputForTest(kTestDepth);
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, &kGreen.r, kSize);
}
dawn::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue();
wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer);
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_P(MultisampledRenderingTest, ResolveInto2DArrayTexture) {
dawn::TextureView multisampledColorView2 =
wgpu::TextureView multisampledColorView2 =
CreateTextureForOutputAttachment(kColorFormat, kSampleCount).CreateView();
dawn::TextureViewDescriptor baseTextureViewDescriptor;
baseTextureViewDescriptor.dimension = dawn::TextureViewDimension::e2D;
wgpu::TextureViewDescriptor baseTextureViewDescriptor;
baseTextureViewDescriptor.dimension = wgpu::TextureViewDimension::e2D;
baseTextureViewDescriptor.format = kColorFormat;
baseTextureViewDescriptor.arrayLayerCount = 1;
baseTextureViewDescriptor.mipLevelCount = 1;
@ -458,29 +457,29 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DArrayTexture) {
// Create resolveTexture1 with only 1 mipmap level.
constexpr uint32_t kBaseArrayLayer1 = 2;
constexpr uint32_t kBaseMipLevel1 = 0;
dawn::Texture resolveTexture1 =
wgpu::Texture resolveTexture1 =
CreateTextureForOutputAttachment(kColorFormat, 1, kBaseMipLevel1 + 1, kBaseArrayLayer1 + 1);
dawn::TextureViewDescriptor resolveViewDescriptor1 = baseTextureViewDescriptor;
wgpu::TextureViewDescriptor resolveViewDescriptor1 = baseTextureViewDescriptor;
resolveViewDescriptor1.baseArrayLayer = kBaseArrayLayer1;
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
// mipmap level.
constexpr uint32_t kBaseArrayLayer2 = 5;
constexpr uint32_t kBaseMipLevel2 = 3;
dawn::Texture resolveTexture2 =
wgpu::Texture resolveTexture2 =
CreateTextureForOutputAttachment(kColorFormat, 1, kBaseMipLevel2 + 1, kBaseArrayLayer2 + 1);
dawn::TextureViewDescriptor resolveViewDescriptor2 = baseTextureViewDescriptor;
wgpu::TextureViewDescriptor resolveViewDescriptor2 = baseTextureViewDescriptor;
resolveViewDescriptor2.baseArrayLayer = kBaseArrayLayer2;
resolveViewDescriptor2.baseMipLevel = kBaseMipLevel2;
dawn::TextureView resolveView2 = resolveTexture2.CreateView(&resolveViewDescriptor2);
wgpu::TextureView resolveView2 = resolveTexture2.CreateView(&resolveViewDescriptor2);
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
dawn::RenderPipeline pipeline = CreateRenderPipelineWithTwoOutputsForTest();
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
wgpu::RenderPipeline pipeline = CreateRenderPipelineWithTwoOutputsForTest();
constexpr dawn::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 kGreen = {0.0f, 0.8f, 0.0f, 0.8f};
constexpr wgpu::Color kRed = {0.8f, 0.0f, 0.0f, 0.8f};
constexpr bool kTestDepth = false;
// 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(
{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
kGreen.r, kGreen.g, kGreen.b, kGreen.a}; // color2
@ -496,8 +495,8 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DArrayTexture) {
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, kUniformData.data(), kSize);
}
dawn::CommandBuffer commandBuffer = commandEncoder.Finish();
dawn::Queue queue = device.CreateQueue();
wgpu::CommandBuffer commandBuffer = commandEncoder.Finish();
wgpu::Queue queue = device.CreateQueue();
queue.Submit(1, &commandBuffer);
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_P(NonzeroTextureCreationTests, TextureCreationClearsOneBits) {
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kSize;
descriptor.size.height = kSize;
descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm;
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor);
descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
wgpu::Texture texture = device.CreateTexture(&descriptor);
RGBA8 filledWithOnes(255, 255, 255, 255);
EXPECT_PIXEL_RGBA8_EQ(filledWithOnes, texture, 0, 0);
@ -48,17 +48,17 @@ TEST_P(NonzeroTextureCreationTests, TextureCreationClearsOneBits) {
TEST_P(NonzeroTextureCreationTests, MipMapClears) {
constexpr uint32_t mipLevels = 4;
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kSize;
descriptor.size.height = kSize;
descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm;
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = mipLevels;
descriptor.usage = dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor);
descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
wgpu::Texture texture = device.CreateTexture(&descriptor);
std::vector<RGBA8> expected;
RGBA8 filledWithOnes(255, 255, 255, 255);
@ -73,17 +73,17 @@ TEST_P(NonzeroTextureCreationTests, MipMapClears) {
TEST_P(NonzeroTextureCreationTests, ArrayLayerClears) {
constexpr uint32_t arrayLayers = 4;
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kSize;
descriptor.size.height = kSize;
descriptor.size.depth = 1;
descriptor.arrayLayerCount = arrayLayers;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm;
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor);
descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
wgpu::Texture texture = device.CreateTexture(&descriptor);
std::vector<RGBA8> expected;
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_P(NonzeroTextureCreationTests, NonrenderableTextureFormat) {
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kSize;
descriptor.size.height = kSize;
descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Snorm;
descriptor.format = wgpu::TextureFormat::RGBA8Snorm;
descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor);
descriptor.usage = wgpu::TextureUsage::CopySrc;
wgpu::Texture texture = device.CreateTexture(&descriptor);
// Set buffer with dirty data so we know it is cleared by the lazy cleared texture copy
uint32_t bufferSize = 4 * kSize * kSize;
std::vector<uint8_t> data(bufferSize, 100);
dawn::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc);
wgpu::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1};
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0);
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
wgpu::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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.
DAWN_SKIP_TEST_IF(IsOpenGL());
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kSize;
descriptor.size.height = kSize;
descriptor.size.depth = 1;
descriptor.arrayLayerCount = 2;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Snorm;
descriptor.format = wgpu::TextureFormat::RGBA8Snorm;
descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::CopySrc;
dawn::Texture texture = device.CreateTexture(&descriptor);
descriptor.usage = wgpu::TextureUsage::CopySrc;
wgpu::Texture texture = device.CreateTexture(&descriptor);
// Set buffer with dirty data so we know it is cleared by the lazy cleared texture copy
uint32_t bufferSize = 4 * kSize * kSize;
std::vector<uint8_t> data(bufferSize, 100);
dawn::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc);
wgpu::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 1, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1};
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0);
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 1, {0, 0, 0});
wgpu::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
std::vector<uint32_t> expectedWithZeros(bufferSize, 1);

View File

@ -21,12 +21,12 @@ class ObjectCachingTest : public DawnTest {};
// Test that BindGroupLayouts are correctly deduplicated.
TEST_P(ObjectCachingTest, BindGroupLayoutDeduplication) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}});
dawn::BindGroupLayout sameBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Vertex, dawn::BindingType::UniformBuffer}});
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}});
wgpu::BindGroupLayout sameBgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}});
wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer}});
EXPECT_NE(bgl.Get(), otherBgl.Get());
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_P(ObjectCachingTest, BindGroupLayoutDynamic) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer, true}});
dawn::BindGroupLayout sameBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer, true}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer, false}});
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer, true}});
wgpu::BindGroupLayout sameBgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer, true}});
wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer, false}});
EXPECT_NE(bgl.Get(), otherBgl.Get());
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
// textureComponentType
TEST_P(ObjectCachingTest, BindGroupLayoutTextureComponentType) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, false,
dawn::TextureViewDimension::e2D, dawn::TextureComponentType::Float}});
dawn::BindGroupLayout sameBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, false,
dawn::TextureViewDimension::e2D, dawn::TextureComponentType::Float}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, false,
dawn::TextureViewDimension::e2D, dawn::TextureComponentType::Uint}});
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, false,
wgpu::TextureViewDimension::e2D, wgpu::TextureComponentType::Float}});
wgpu::BindGroupLayout sameBgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, false,
wgpu::TextureViewDimension::e2D, wgpu::TextureComponentType::Float}});
wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, false,
wgpu::TextureViewDimension::e2D, wgpu::TextureComponentType::Uint}});
EXPECT_NE(bgl.Get(), otherBgl.Get());
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
// textureDimension
TEST_P(ObjectCachingTest, BindGroupLayoutTextureDimension) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, false,
dawn::TextureViewDimension::e2D, dawn::TextureComponentType::Float}});
dawn::BindGroupLayout sameBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, false,
dawn::TextureViewDimension::e2D, dawn::TextureComponentType::Float}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false, false,
dawn::TextureViewDimension::e2DArray, dawn::TextureComponentType::Float}});
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, false,
wgpu::TextureViewDimension::e2D, wgpu::TextureComponentType::Float}});
wgpu::BindGroupLayout sameBgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, false,
wgpu::TextureViewDimension::e2D, wgpu::TextureComponentType::Float}});
wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, false,
wgpu::TextureViewDimension::e2DArray, wgpu::TextureComponentType::Float}});
EXPECT_NE(bgl.Get(), otherBgl.Get());
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_P(ObjectCachingTest, ErrorObjectDoesntUncache) {
ASSERT_DEVICE_ERROR(
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer},
{0, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}}));
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer},
{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}}));
}
// Test that PipelineLayouts are correctly deduplicated.
TEST_P(ObjectCachingTest, PipelineLayoutDeduplication) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Vertex, dawn::BindingType::UniformBuffer}});
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}});
wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer}});
dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::PipelineLayout samePl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::PipelineLayout otherPl1 = utils::MakeBasicPipelineLayout(device, nullptr);
dawn::PipelineLayout otherPl2 = utils::MakeBasicPipelineLayout(device, &otherBgl);
wgpu::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
wgpu::PipelineLayout samePl = utils::MakeBasicPipelineLayout(device, &bgl);
wgpu::PipelineLayout otherPl1 = utils::MakeBasicPipelineLayout(device, nullptr);
wgpu::PipelineLayout otherPl2 = utils::MakeBasicPipelineLayout(device, &otherBgl);
EXPECT_NE(pl.Get(), otherPl1.Get());
EXPECT_NE(pl.Get(), otherPl2.Get());
@ -106,21 +106,21 @@ TEST_P(ObjectCachingTest, PipelineLayoutDeduplication) {
// Test that ShaderModules are correctly deduplicated.
TEST_P(ObjectCachingTest, ShaderModuleDeduplication) {
dawn::ShaderModule module =
wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(0.0, 1.0, 0.0, 1.0);
})");
dawn::ShaderModule sameModule =
wgpu::ShaderModule sameModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(0.0, 1.0, 0.0, 1.0);
})");
dawn::ShaderModule otherModule =
wgpu::ShaderModule otherModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
@ -134,19 +134,19 @@ TEST_P(ObjectCachingTest, ShaderModuleDeduplication) {
// Test that ComputePipeline are correctly deduplicated wrt. their ShaderModule
TEST_P(ObjectCachingTest, ComputePipelineDeduplicationOnShaderModule) {
dawn::ShaderModule module =
wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
#version 450
void main() {
int i = 0;
})");
dawn::ShaderModule sameModule =
wgpu::ShaderModule sameModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
#version 450
void main() {
int i = 0;
})");
dawn::ShaderModule otherModule =
wgpu::ShaderModule otherModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
#version 450
void main() {
@ -155,20 +155,20 @@ TEST_P(ObjectCachingTest, ComputePipelineDeduplicationOnShaderModule) {
EXPECT_NE(module.Get(), otherModule.Get());
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.layout = layout;
desc.computeStage.module = module;
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&desc);
wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&desc);
desc.computeStage.module = sameModule;
dawn::ComputePipeline samePipeline = device.CreateComputePipeline(&desc);
wgpu::ComputePipeline samePipeline = device.CreateComputePipeline(&desc);
desc.computeStage.module = otherModule;
dawn::ComputePipeline otherPipeline = device.CreateComputePipeline(&desc);
wgpu::ComputePipeline otherPipeline = device.CreateComputePipeline(&desc);
EXPECT_NE(pipeline.Get(), otherPipeline.Get());
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_P(ObjectCachingTest, ComputePipelineDeduplicationOnLayout) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Vertex, dawn::BindingType::UniformBuffer}});
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}});
wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer}});
dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::PipelineLayout samePl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::PipelineLayout otherPl = utils::MakeBasicPipelineLayout(device, nullptr);
wgpu::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
wgpu::PipelineLayout samePl = utils::MakeBasicPipelineLayout(device, &bgl);
wgpu::PipelineLayout otherPl = utils::MakeBasicPipelineLayout(device, nullptr);
EXPECT_NE(pl.Get(), otherPl.Get());
EXPECT_EQ(pl.Get() == samePl.Get(), !UsesWire());
dawn::ComputePipelineDescriptor desc;
wgpu::ComputePipelineDescriptor desc;
desc.computeStage.entryPoint = "main";
desc.computeStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
@ -198,13 +198,13 @@ TEST_P(ObjectCachingTest, ComputePipelineDeduplicationOnLayout) {
})");
desc.layout = pl;
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&desc);
wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&desc);
desc.layout = samePl;
dawn::ComputePipeline samePipeline = device.CreateComputePipeline(&desc);
wgpu::ComputePipeline samePipeline = device.CreateComputePipeline(&desc);
desc.layout = otherPl;
dawn::ComputePipeline otherPipeline = device.CreateComputePipeline(&desc);
wgpu::ComputePipeline otherPipeline = device.CreateComputePipeline(&desc);
EXPECT_NE(pipeline.Get(), otherPipeline.Get());
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_P(ObjectCachingTest, RenderPipelineDeduplicationOnLayout) {
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Fragment, dawn::BindingType::UniformBuffer}});
dawn::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, dawn::ShaderStage::Vertex, dawn::BindingType::UniformBuffer}});
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer}});
wgpu::BindGroupLayout otherBgl = utils::MakeBindGroupLayout(
device, {{1, wgpu::ShaderStage::Vertex, wgpu::BindingType::UniformBuffer}});
dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::PipelineLayout samePl = utils::MakeBasicPipelineLayout(device, &bgl);
dawn::PipelineLayout otherPl = utils::MakeBasicPipelineLayout(device, nullptr);
wgpu::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
wgpu::PipelineLayout samePl = utils::MakeBasicPipelineLayout(device, &bgl);
wgpu::PipelineLayout otherPl = utils::MakeBasicPipelineLayout(device, nullptr);
EXPECT_NE(pl.Get(), otherPl.Get());
EXPECT_EQ(pl.Get() == samePl.Get(), !UsesWire());
@ -238,13 +238,13 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnLayout) {
})");
desc.layout = pl;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&desc);
wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&desc);
desc.layout = samePl;
dawn::RenderPipeline samePipeline = device.CreateRenderPipeline(&desc);
wgpu::RenderPipeline samePipeline = device.CreateRenderPipeline(&desc);
desc.layout = otherPl;
dawn::RenderPipeline otherPipeline = device.CreateRenderPipeline(&desc);
wgpu::RenderPipeline otherPipeline = device.CreateRenderPipeline(&desc);
EXPECT_NE(pipeline.Get(), otherPipeline.Get());
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_P(ObjectCachingTest, RenderPipelineDeduplicationOnVertexModule) {
dawn::ShaderModule module =
wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
void main() {
gl_Position = vec4(0.0);
})");
dawn::ShaderModule sameModule =
wgpu::ShaderModule sameModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
void main() {
gl_Position = vec4(0.0);
})");
dawn::ShaderModule otherModule =
wgpu::ShaderModule otherModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
void main() {
@ -282,13 +282,13 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnVertexModule) {
})");
desc.vertexStage.module = module;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&desc);
wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&desc);
desc.vertexStage.module = sameModule;
dawn::RenderPipeline samePipeline = device.CreateRenderPipeline(&desc);
wgpu::RenderPipeline samePipeline = device.CreateRenderPipeline(&desc);
desc.vertexStage.module = otherModule;
dawn::RenderPipeline otherPipeline = device.CreateRenderPipeline(&desc);
wgpu::RenderPipeline otherPipeline = device.CreateRenderPipeline(&desc);
EXPECT_NE(pipeline.Get(), otherPipeline.Get());
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_P(ObjectCachingTest, RenderPipelineDeduplicationOnFragmentModule) {
dawn::ShaderModule module =
wgpu::ShaderModule module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
void main() {
})");
dawn::ShaderModule sameModule =
wgpu::ShaderModule sameModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
void main() {
})");
dawn::ShaderModule otherModule =
wgpu::ShaderModule otherModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
void main() {
@ -325,13 +325,13 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnFragmentModule) {
})");
desc.cFragmentStage.module = module;
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&desc);
wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&desc);
desc.cFragmentStage.module = sameModule;
dawn::RenderPipeline samePipeline = device.CreateRenderPipeline(&desc);
wgpu::RenderPipeline samePipeline = device.CreateRenderPipeline(&desc);
desc.cFragmentStage.module = otherModule;
dawn::RenderPipeline otherPipeline = device.CreateRenderPipeline(&desc);
wgpu::RenderPipeline otherPipeline = device.CreateRenderPipeline(&desc);
EXPECT_NE(pipeline.Get(), otherPipeline.Get());
EXPECT_EQ(pipeline.Get() == samePipeline.Get(), !UsesWire());
@ -339,47 +339,47 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnFragmentModule) {
// Test that Samplers are correctly deduplicated.
TEST_P(ObjectCachingTest, SamplerDeduplication) {
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
dawn::Sampler sampler = device.CreateSampler(&samplerDesc);
wgpu::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
dawn::SamplerDescriptor sameSamplerDesc = utils::GetDefaultSamplerDescriptor();
dawn::Sampler sameSampler = device.CreateSampler(&sameSamplerDesc);
wgpu::SamplerDescriptor sameSamplerDesc = utils::GetDefaultSamplerDescriptor();
wgpu::Sampler sameSampler = device.CreateSampler(&sameSamplerDesc);
dawn::SamplerDescriptor otherSamplerDescAddressModeU = utils::GetDefaultSamplerDescriptor();
otherSamplerDescAddressModeU.addressModeU = dawn::AddressMode::ClampToEdge;
dawn::Sampler otherSamplerAddressModeU = device.CreateSampler(&otherSamplerDescAddressModeU);
wgpu::SamplerDescriptor otherSamplerDescAddressModeU = utils::GetDefaultSamplerDescriptor();
otherSamplerDescAddressModeU.addressModeU = wgpu::AddressMode::ClampToEdge;
wgpu::Sampler otherSamplerAddressModeU = device.CreateSampler(&otherSamplerDescAddressModeU);
dawn::SamplerDescriptor otherSamplerDescAddressModeV = utils::GetDefaultSamplerDescriptor();
otherSamplerDescAddressModeV.addressModeV = dawn::AddressMode::ClampToEdge;
dawn::Sampler otherSamplerAddressModeV = device.CreateSampler(&otherSamplerDescAddressModeV);
wgpu::SamplerDescriptor otherSamplerDescAddressModeV = utils::GetDefaultSamplerDescriptor();
otherSamplerDescAddressModeV.addressModeV = wgpu::AddressMode::ClampToEdge;
wgpu::Sampler otherSamplerAddressModeV = device.CreateSampler(&otherSamplerDescAddressModeV);
dawn::SamplerDescriptor otherSamplerDescAddressModeW = utils::GetDefaultSamplerDescriptor();
otherSamplerDescAddressModeW.addressModeW = dawn::AddressMode::ClampToEdge;
dawn::Sampler otherSamplerAddressModeW = device.CreateSampler(&otherSamplerDescAddressModeW);
wgpu::SamplerDescriptor otherSamplerDescAddressModeW = utils::GetDefaultSamplerDescriptor();
otherSamplerDescAddressModeW.addressModeW = wgpu::AddressMode::ClampToEdge;
wgpu::Sampler otherSamplerAddressModeW = device.CreateSampler(&otherSamplerDescAddressModeW);
dawn::SamplerDescriptor otherSamplerDescMagFilter = utils::GetDefaultSamplerDescriptor();
otherSamplerDescMagFilter.magFilter = dawn::FilterMode::Nearest;
dawn::Sampler otherSamplerMagFilter = device.CreateSampler(&otherSamplerDescMagFilter);
wgpu::SamplerDescriptor otherSamplerDescMagFilter = utils::GetDefaultSamplerDescriptor();
otherSamplerDescMagFilter.magFilter = wgpu::FilterMode::Nearest;
wgpu::Sampler otherSamplerMagFilter = device.CreateSampler(&otherSamplerDescMagFilter);
dawn::SamplerDescriptor otherSamplerDescMinFilter = utils::GetDefaultSamplerDescriptor();
otherSamplerDescMinFilter.minFilter = dawn::FilterMode::Nearest;
dawn::Sampler otherSamplerMinFilter = device.CreateSampler(&otherSamplerDescMinFilter);
wgpu::SamplerDescriptor otherSamplerDescMinFilter = utils::GetDefaultSamplerDescriptor();
otherSamplerDescMinFilter.minFilter = wgpu::FilterMode::Nearest;
wgpu::Sampler otherSamplerMinFilter = device.CreateSampler(&otherSamplerDescMinFilter);
dawn::SamplerDescriptor otherSamplerDescMipmapFilter = utils::GetDefaultSamplerDescriptor();
otherSamplerDescMipmapFilter.mipmapFilter = dawn::FilterMode::Nearest;
dawn::Sampler otherSamplerMipmapFilter = device.CreateSampler(&otherSamplerDescMipmapFilter);
wgpu::SamplerDescriptor otherSamplerDescMipmapFilter = utils::GetDefaultSamplerDescriptor();
otherSamplerDescMipmapFilter.mipmapFilter = wgpu::FilterMode::Nearest;
wgpu::Sampler otherSamplerMipmapFilter = device.CreateSampler(&otherSamplerDescMipmapFilter);
dawn::SamplerDescriptor otherSamplerDescLodMinClamp = utils::GetDefaultSamplerDescriptor();
wgpu::SamplerDescriptor otherSamplerDescLodMinClamp = utils::GetDefaultSamplerDescriptor();
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;
dawn::Sampler otherSamplerLodMaxClamp = device.CreateSampler(&otherSamplerDescLodMaxClamp);
wgpu::Sampler otherSamplerLodMaxClamp = device.CreateSampler(&otherSamplerDescLodMaxClamp);
dawn::SamplerDescriptor otherSamplerDescCompareFunction = utils::GetDefaultSamplerDescriptor();
otherSamplerDescCompareFunction.compare = dawn::CompareFunction::Always;
dawn::Sampler otherSamplerCompareFunction =
wgpu::SamplerDescriptor otherSamplerDescCompareFunction = utils::GetDefaultSamplerDescriptor();
otherSamplerDescCompareFunction.compare = wgpu::CompareFunction::Always;
wgpu::Sampler otherSamplerCompareFunction =
device.CreateSampler(&otherSamplerDescCompareFunction);
EXPECT_NE(sampler.Get(), otherSamplerAddressModeU.Get());

View File

@ -24,9 +24,9 @@ class OpArrayLengthTest : public DawnTest {
DawnTest::TestSetUp();
// Create buffers of various size to check the length() implementation
dawn::BufferDescriptor bufferDesc;
wgpu::BufferDescriptor bufferDesc;
bufferDesc.size = 4;
bufferDesc.usage = dawn::BufferUsage::Storage;
bufferDesc.usage = wgpu::BufferUsage::Storage;
mStorageBuffer4 = device.CreateBuffer(&bufferDesc);
bufferDesc.size = 256;
@ -36,17 +36,17 @@ class OpArrayLengthTest : public DawnTest {
mStorageBuffer512 = device.CreateBuffer(&bufferDesc);
// Put them all in a bind group for tests to bind them easily.
dawn::ShaderStage kAllStages =
dawn::ShaderStage::Fragment | dawn::ShaderStage::Vertex | dawn::ShaderStage::Compute;
wgpu::ShaderStage kAllStages =
wgpu::ShaderStage::Fragment | wgpu::ShaderStage::Vertex | wgpu::ShaderStage::Compute;
mBindGroupLayout =
utils::MakeBindGroupLayout(device, {{0, kAllStages, dawn::BindingType::StorageBuffer},
{1, kAllStages, dawn::BindingType::StorageBuffer},
{2, kAllStages, dawn::BindingType::StorageBuffer}});
utils::MakeBindGroupLayout(device, {{0, kAllStages, wgpu::BindingType::StorageBuffer},
{1, kAllStages, wgpu::BindingType::StorageBuffer},
{2, kAllStages, wgpu::BindingType::StorageBuffer}});
mBindGroup = utils::MakeBindGroup(device, mBindGroupLayout,
{
{0, mStorageBuffer4, 0, 4},
{1, mStorageBuffer256, 0, dawn::kWholeSize},
{1, mStorageBuffer256, 0, wgpu::kWholeSize},
{2, mStorageBuffer512, 0, 512},
});
@ -76,12 +76,12 @@ class OpArrayLengthTest : public DawnTest {
mExpectedLengths = {1, 64, 56};
}
dawn::Buffer mStorageBuffer4;
dawn::Buffer mStorageBuffer256;
dawn::Buffer mStorageBuffer512;
wgpu::Buffer mStorageBuffer4;
wgpu::Buffer mStorageBuffer256;
wgpu::Buffer mStorageBuffer512;
dawn::BindGroupLayout mBindGroupLayout;
dawn::BindGroup mBindGroup;
wgpu::BindGroupLayout mBindGroupLayout;
wgpu::BindGroup mBindGroup;
std::string mShaderInterface;
std::array<uint32_t, 3> mExpectedLengths;
};
@ -93,25 +93,25 @@ TEST_P(OpArrayLengthTest, Compute) {
DAWN_SKIP_TEST_IF(IsNvidia() && IsOpenGL());
// Create a buffer to hold the result sizes and create a bindgroup for it.
dawn::BufferDescriptor bufferDesc;
bufferDesc.usage = dawn::BufferUsage::Storage | dawn::BufferUsage::CopySrc;
wgpu::BufferDescriptor bufferDesc;
bufferDesc.usage = wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc;
bufferDesc.size = sizeof(uint32_t) * mExpectedLengths.size();
dawn::Buffer resultBuffer = device.CreateBuffer(&bufferDesc);
wgpu::Buffer resultBuffer = device.CreateBuffer(&bufferDesc);
dawn::BindGroupLayout resultLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer}});
wgpu::BindGroupLayout resultLayout = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer}});
dawn::BindGroup resultBindGroup =
utils::MakeBindGroup(device, resultLayout, {{0, resultBuffer, 0, dawn::kWholeSize}});
wgpu::BindGroup resultBindGroup =
utils::MakeBindGroup(device, resultLayout, {{0, resultBuffer, 0, wgpu::kWholeSize}});
// Create the compute pipeline that stores the length()s in the result buffer.
dawn::BindGroupLayout bgls[] = {mBindGroupLayout, resultLayout};
dawn::PipelineLayoutDescriptor plDesc;
wgpu::BindGroupLayout bgls[] = {mBindGroupLayout, resultLayout};
wgpu::PipelineLayoutDescriptor plDesc;
plDesc.bindGroupLayoutCount = 2;
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.computeStage.entryPoint = "main";
pipelineDesc.computeStage.module =
@ -127,18 +127,18 @@ TEST_P(OpArrayLengthTest, Compute) {
result[2] = buffer3.data.length();
})")
.c_str());
dawn::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc);
wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc);
// Run a single instance of the compute shader
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder pass = encoder.BeginComputePass();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(pipeline);
pass.SetBindGroup(0, mBindGroup);
pass.SetBindGroup(1, resultBindGroup);
pass.Dispatch(1, 1, 1);
pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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
// pass pixel.
dawn::ShaderModule vsModule =
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
void main() {
@ -162,7 +162,7 @@ TEST_P(OpArrayLengthTest, Fragment) {
gl_PointSize = 1.0;
})");
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment,
(R"(
#version 450
@ -179,22 +179,22 @@ TEST_P(OpArrayLengthTest, Fragment) {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::PointList;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::PointList;
descriptor.cColorStates[0].format = renderPass.colorFormat;
descriptor.layout = utils::MakeBasicPipelineLayout(device, &mBindGroupLayout);
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
// "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.SetBindGroup(0, mBindGroup);
pass.Draw(1, 1, 0, 0);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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
// pass pixel.
dawn::ShaderModule vsModule =
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex,
(R"(
#version 450
@ -228,7 +228,7 @@ TEST_P(OpArrayLengthTest, Vertex) {
})")
.c_str());
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
@ -240,22 +240,22 @@ TEST_P(OpArrayLengthTest, Vertex) {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::PointList;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::PointList;
descriptor.cColorStates[0].format = renderPass.colorFormat;
descriptor.layout = utils::MakeBasicPipelineLayout(device, &mBindGroupLayout);
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
// "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.SetBindGroup(0, mBindGroup);
pass.Draw(1, 1, 0, 0);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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),
dawn::BufferUsage::Vertex);
wgpu::BufferUsage::Vertex);
}
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
void DoTest(dawn::PrimitiveTopology primitiveTopology, const std::vector<LocationSpec> &locationSpecs) {
void DoTest(wgpu::PrimitiveTopology primitiveTopology,
const std::vector<LocationSpec>& locationSpecs) {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
@ -189,22 +190,21 @@ class PrimitiveTopologyTest : public DawnTest {
descriptor.cVertexInput.bufferCount = 1;
descriptor.cVertexInput.cBuffers[0].stride = 4 * sizeof(float);
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;
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.SetVertexBuffer(0, vertexBuffer);
pass.Draw(6, 1, 0, 0);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
for (auto& locationSpec : locationSpecs) {
@ -218,68 +218,72 @@ class PrimitiveTopologyTest : public DawnTest {
}
utils::BasicRenderPass renderPass;
dawn::ShaderModule vsModule;
dawn::ShaderModule fsModule;
dawn::Buffer vertexBuffer;
wgpu::ShaderModule vsModule;
wgpu::ShaderModule fsModule;
wgpu::Buffer vertexBuffer;
};
// Test Point primitive topology
TEST_P(PrimitiveTopologyTest, PointList) {
DoTest(dawn::PrimitiveTopology::PointList, {
// Check that the points are drawn
TestPoints(kPointTestLocations, true),
DoTest(wgpu::PrimitiveTopology::PointList,
{
// Check that the points are drawn
TestPoints(kPointTestLocations, true),
// Check that line and triangle locations are untouched
TestPoints(kLineTestLocations, false),
TestPoints(kLineStripTestLocations, false),
TestPoints(kTriangleTestLocations, false),
TestPoints(kTriangleStripTestLocations, false),
});
// Check that line and triangle locations are untouched
TestPoints(kLineTestLocations, false),
TestPoints(kLineStripTestLocations, false),
TestPoints(kTriangleTestLocations, false),
TestPoints(kTriangleStripTestLocations, false),
});
}
// Test Line primitive topology
TEST_P(PrimitiveTopologyTest, LineList) {
DoTest(dawn::PrimitiveTopology::LineList, {
// Check that lines are drawn
TestPoints(kLineTestLocations, true),
DoTest(wgpu::PrimitiveTopology::LineList,
{
// Check that lines are drawn
TestPoints(kLineTestLocations, true),
// Check that line strip and triangle locations are untouched
TestPoints(kLineStripTestLocations, false),
TestPoints(kTriangleTestLocations, false),
TestPoints(kTriangleStripTestLocations, false),
});
// Check that line strip and triangle locations are untouched
TestPoints(kLineStripTestLocations, false),
TestPoints(kTriangleTestLocations, false),
TestPoints(kTriangleStripTestLocations, false),
});
}
// Test LineStrip primitive topology
TEST_P(PrimitiveTopologyTest, LineStrip) {
DoTest(dawn::PrimitiveTopology::LineStrip, {
// Check that lines are drawn
TestPoints(kLineTestLocations, true),
TestPoints(kLineStripTestLocations, true),
DoTest(wgpu::PrimitiveTopology::LineStrip, {
// Check that lines are drawn
TestPoints(kLineTestLocations, true),
TestPoints(kLineStripTestLocations, true),
// Check that triangle locations are untouched
TestPoints(kTriangleTestLocations, false),
TestPoints(kTriangleStripTestLocations, false),
});
// Check that triangle locations are untouched
TestPoints(kTriangleTestLocations, false),
TestPoints(kTriangleStripTestLocations, false),
});
}
// Test Triangle primitive topology
TEST_P(PrimitiveTopologyTest, TriangleList) {
DoTest(dawn::PrimitiveTopology::TriangleList, {
// Check that triangles are drawn
TestPoints(kTriangleTestLocations, true),
DoTest(wgpu::PrimitiveTopology::TriangleList,
{
// Check that triangles are drawn
TestPoints(kTriangleTestLocations, true),
// Check that triangle strip locations are untouched
TestPoints(kTriangleStripTestLocations, false),
});
// Check that triangle strip locations are untouched
TestPoints(kTriangleStripTestLocations, false),
});
}
// Test TriangleStrip primitive topology
TEST_P(PrimitiveTopologyTest, TriangleStrip) {
DoTest(dawn::PrimitiveTopology::TriangleStrip, {
TestPoints(kTriangleTestLocations, true),
TestPoints(kTriangleStripTestLocations, true),
});
DoTest(wgpu::PrimitiveTopology::TriangleStrip,
{
TestPoints(kTriangleTestLocations, true),
TestPoints(kTriangleStripTestLocations, true),
});
}
DAWN_INSTANTIATE_TEST(PrimitiveTopologyTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);

View File

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

View File

@ -24,18 +24,16 @@ constexpr static unsigned int kRTSize = 16;
class DrawQuad {
public:
DrawQuad() {}
DrawQuad(dawn::Device device, const char* vsSource, const char* fsSource)
: device(device) {
DrawQuad(wgpu::Device device, const char* vsSource, const char* fsSource) : device(device) {
vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vsSource);
fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fsSource);
pipelineLayout = utils::MakeBasicPipelineLayout(device, nullptr);
}
void Draw(dawn::RenderPassEncoder* pass) {
}
void Draw(wgpu::RenderPassEncoder* pass) {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.layout = pipelineLayout;
descriptor.vertexStage.module = vsModule;
@ -48,10 +46,10 @@ class DrawQuad {
}
private:
dawn::Device device;
dawn::ShaderModule vsModule = {};
dawn::ShaderModule fsModule = {};
dawn::PipelineLayout pipelineLayout = {};
wgpu::Device device;
wgpu::ShaderModule vsModule = {};
wgpu::ShaderModule fsModule = {};
wgpu::PipelineLayout pipelineLayout = {};
};
class RenderPassLoadOpTests : public DawnTest {
@ -59,16 +57,16 @@ class RenderPassLoadOpTests : public DawnTest {
void TestSetUp() override {
DawnTest::TestSetUp();
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kRTSize;
descriptor.size.height = kRTSize;
descriptor.size.depth = 1;
descriptor.arrayLayerCount = 1;
descriptor.sampleCount = 1;
descriptor.format = dawn::TextureFormat::RGBA8Unorm;
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc;
descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
renderTarget = device.CreateTexture(&descriptor);
renderTargetView = renderTarget.CreateView();
@ -102,8 +100,8 @@ class RenderPassLoadOpTests : public DawnTest {
blueQuad = DrawQuad(device, vsSource, fsSource);
}
dawn::Texture renderTarget;
dawn::TextureView renderTargetView;
wgpu::Texture renderTarget;
wgpu::TextureView renderTargetView;
std::array<RGBA8, kRTSize * kRTSize> expectZero;
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
utils::ComboRenderPassDescriptor renderPassLoad({renderTargetView});
renderPassLoad.cColorAttachments[0].loadOp = dawn::LoadOp::Load;
dawn::CommandBuffer commandsLoad;
renderPassLoad.cColorAttachments[0].loadOp = wgpu::LoadOp::Load;
wgpu::CommandBuffer commandsLoad;
{
auto encoder = device.CreateCommandEncoder();
auto pass = encoder.BeginRenderPass(&renderPassLoad);

View File

@ -18,7 +18,7 @@
#include "utils/WGPUHelpers.h"
constexpr uint32_t kRTSize = 16;
constexpr dawn::TextureFormat kFormat = dawn::TextureFormat::RGBA8Unorm;
constexpr wgpu::TextureFormat kFormat = wgpu::TextureFormat::RGBA8Unorm;
class RenderPassTest : public DawnTest {
protected:
@ -34,7 +34,7 @@ protected:
gl_Position = vec4(pos[gl_VertexIndex], 0.f, 1.f);
})");
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
@ -45,15 +45,15 @@ protected:
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = mVSModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cColorStates[0].format = kFormat;
pipeline = device.CreateRenderPipeline(&descriptor);
}
dawn::Texture CreateDefault2DTexture() {
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;
wgpu::Texture CreateDefault2DTexture() {
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kRTSize;
descriptor.size.height = kRTSize;
descriptor.size.depth = 1;
@ -61,12 +61,12 @@ protected:
descriptor.sampleCount = 1;
descriptor.format = kFormat;
descriptor.mipLevelCount = 1;
descriptor.usage = dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc;
descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
return device.CreateTexture(&descriptor);
}
dawn::ShaderModule mVSModule;
dawn::RenderPipeline pipeline;
wgpu::ShaderModule mVSModule;
wgpu::RenderPipeline pipeline;
};
// 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);
dawn::Texture renderTarget1 = CreateDefault2DTexture();
dawn::Texture renderTarget2 = CreateDefault2DTexture();
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::Texture renderTarget1 = CreateDefault2DTexture();
wgpu::Texture renderTarget2 = CreateDefault2DTexture();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{
// 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()});
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.Draw(3, 1, 0, 0);
pass.EndPass();
@ -103,13 +103,13 @@ TEST_P(RenderPassTest, TwoRenderPassesInOneCommandBuffer) {
utils::ComboRenderPassDescriptor renderPass({renderTarget2.CreateView()});
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.Draw(3, 1, 0, 0);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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
// operation is StoreOp::Store.
TEST_P(RenderPassTest, NoCorrespondingFragmentShaderOutputs) {
dawn::Texture renderTarget = CreateDefault2DTexture();
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::Texture renderTarget = CreateDefault2DTexture();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::TextureView renderTargetView = renderTarget.CreateView();
wgpu::TextureView renderTargetView = renderTarget.CreateView();
utils::ComboRenderPassDescriptor renderPass({renderTargetView});
renderPass.cColorAttachments[0].clearColor = {1.0f, 0.0f, 0.0f, 1.0f};
renderPass.cColorAttachments[0].loadOp = dawn::LoadOp::Clear;
renderPass.cColorAttachments[0].storeOp = dawn::StoreOp::Store;
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
renderPass.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
renderPass.cColorAttachments[0].storeOp = wgpu::StoreOp::Store;
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
{
// 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.
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
void main() {
@ -150,10 +150,10 @@ TEST_P(RenderPassTest, NoCorrespondingFragmentShaderOutputs) {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = mVSModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
descriptor.cColorStates[0].format = kFormat;
dawn::RenderPipeline pipelineWithNoFragmentOutput =
wgpu::RenderPipeline pipelineWithNoFragmentOutput =
device.CreateRenderPipeline(&descriptor);
pass.SetPipeline(pipelineWithNoFragmentOutput);
@ -162,7 +162,7 @@ TEST_P(RenderPassTest, NoCorrespondingFragmentShaderOutputs) {
pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
constexpr RGBA8 kRed(255, 0, 0, 255);

View File

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

View File

@ -19,8 +19,8 @@
class ScissorTest: public DawnTest {
protected:
dawn::RenderPipeline CreateQuadPipeline(dawn::TextureFormat format) {
dawn::ShaderModule vsModule =
wgpu::RenderPipeline CreateQuadPipeline(wgpu::TextureFormat format) {
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
const vec2 pos[6] = vec2[6](
@ -31,7 +31,7 @@ class ScissorTest: public DawnTest {
gl_Position = vec4(pos[gl_VertexIndex], 0.5, 1.0);
})");
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
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_P(ScissorTest, DefaultsToWholeRenderTarget) {
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.Draw(6, 1, 0, 0);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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_P(ScissorTest, LargerThanAttachment) {
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.SetScissorRect(0, 0, 200, 200);
pass.Draw(6, 1, 0, 0);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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_P(ScissorTest, PartialRect) {
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 kY = 7;
constexpr uint32_t kW = 5;
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.SetScissorRect(kX, kY, kW, kH);
pass.Draw(6, 1, 0, 0);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
// 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_P(ScissorTest, NoInheritanceBetweenRenderPass) {
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
{
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.SetScissorRect(1, 1, 1, 1);
pass.EndPass();
}
// 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.Draw(6, 1, 0, 0);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
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.
struct FormatTestInfo {
dawn::TextureFormat format;
wgpu::TextureFormat format;
uint32_t texelByteSize;
dawn::TextureComponentType type;
wgpu::TextureComponentType type;
uint32_t componentCount;
};
// 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.
FormatTestInfo GetUncompressedFormatInfo(FormatTestInfo formatInfo) {
std::array<dawn::TextureFormat, 4> floatFormats = {
dawn::TextureFormat::R32Float,
dawn::TextureFormat::RG32Float,
dawn::TextureFormat::RGBA32Float,
dawn::TextureFormat::RGBA32Float,
std::array<wgpu::TextureFormat, 4> floatFormats = {
wgpu::TextureFormat::R32Float,
wgpu::TextureFormat::RG32Float,
wgpu::TextureFormat::RGBA32Float,
wgpu::TextureFormat::RGBA32Float,
};
std::array<dawn::TextureFormat, 4> sintFormats = {
dawn::TextureFormat::R32Sint,
dawn::TextureFormat::RG32Sint,
dawn::TextureFormat::RGBA32Sint,
dawn::TextureFormat::RGBA32Sint,
std::array<wgpu::TextureFormat, 4> sintFormats = {
wgpu::TextureFormat::R32Sint,
wgpu::TextureFormat::RG32Sint,
wgpu::TextureFormat::RGBA32Sint,
wgpu::TextureFormat::RGBA32Sint,
};
std::array<dawn::TextureFormat, 4> uintFormats = {
dawn::TextureFormat::R32Uint,
dawn::TextureFormat::RG32Uint,
dawn::TextureFormat::RGBA32Uint,
dawn::TextureFormat::RGBA32Uint,
std::array<wgpu::TextureFormat, 4> uintFormats = {
wgpu::TextureFormat::R32Uint,
wgpu::TextureFormat::RG32Uint,
wgpu::TextureFormat::RGBA32Uint,
wgpu::TextureFormat::RGBA32Uint,
};
std::array<uint32_t, 4> componentCounts = {1, 2, 4, 4};
ASSERT(formatInfo.componentCount > 0 && formatInfo.componentCount <= 4);
dawn::TextureFormat format;
wgpu::TextureFormat format;
switch (formatInfo.type) {
case dawn::TextureComponentType::Float:
case wgpu::TextureComponentType::Float:
format = floatFormats[formatInfo.componentCount - 1];
break;
case dawn::TextureComponentType::Sint:
case wgpu::TextureComponentType::Sint:
format = sintFormats[formatInfo.componentCount - 1];
break;
case dawn::TextureComponentType::Uint:
case wgpu::TextureComponentType::Uint:
format = uintFormats[formatInfo.componentCount - 1];
break;
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
// bindgroup and output its decompressed values to the render target.
dawn::RenderPipeline CreateSamplePipeline(FormatTestInfo sampleFormatInfo,
wgpu::RenderPipeline CreateSamplePipeline(FormatTestInfo sampleFormatInfo,
FormatTestInfo renderFormatInfo,
dawn::BindGroupLayout bgl) {
wgpu::BindGroupLayout bgl) {
utils::ComboRenderPipelineDescriptor desc(device);
dawn::ShaderModule vsModule =
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
void main() {
@ -188,13 +188,13 @@ class TextureFormatTest : public DawnTest {
// Compute the prefix needed for GLSL types that handle our texture's data.
const char* prefix = nullptr;
switch (sampleFormatInfo.type) {
case dawn::TextureComponentType::Float:
case wgpu::TextureComponentType::Float:
prefix = "";
break;
case dawn::TextureComponentType::Sint:
case wgpu::TextureComponentType::Sint:
prefix = "i";
break;
case dawn::TextureComponentType::Uint:
case wgpu::TextureComponentType::Uint:
prefix = "u";
break;
default:
@ -213,7 +213,7 @@ class TextureFormatTest : public DawnTest {
<< "sampler2D(myTexture, mySampler), ivec2(gl_FragCoord), 0);\n";
fsSource << "}";
dawn::ShaderModule fsModule = utils::CreateShaderModule(
wgpu::ShaderModule fsModule = utils::CreateShaderModule(
device, utils::SingleShaderStage::Fragment, fsSource.str().c_str());
desc.vertexStage.module = vsModule;
@ -244,74 +244,74 @@ class TextureFormatTest : public DawnTest {
ASSERT(expectedRenderDataSize % 4 == 0);
// Create the texture we will sample from
dawn::TextureDescriptor sampleTextureDesc;
sampleTextureDesc.usage = dawn::TextureUsage::CopyDst | dawn::TextureUsage::Sampled;
wgpu::TextureDescriptor sampleTextureDesc;
sampleTextureDesc.usage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled;
sampleTextureDesc.size = {width, 1, 1};
sampleTextureDesc.format = sampleFormatInfo.format;
dawn::Texture sampleTexture = device.CreateTexture(&sampleTextureDesc);
wgpu::Texture sampleTexture = device.CreateTexture(&sampleTextureDesc);
dawn::Buffer uploadBuffer = utils::CreateBufferFromData(device, sampleData, sampleDataSize,
dawn::BufferUsage::CopySrc);
wgpu::Buffer uploadBuffer = utils::CreateBufferFromData(device, sampleData, sampleDataSize,
wgpu::BufferUsage::CopySrc);
// Create the texture that we will render results to
ASSERT(expectedRenderDataSize == width * renderFormatInfo.texelByteSize);
dawn::TextureDescriptor renderTargetDesc;
renderTargetDesc.usage = dawn::TextureUsage::CopySrc | dawn::TextureUsage::OutputAttachment;
wgpu::TextureDescriptor renderTargetDesc;
renderTargetDesc.usage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::OutputAttachment;
renderTargetDesc.size = {width, 1, 1};
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
dawn::BufferDescriptor readbackBufferDesc;
readbackBufferDesc.usage = dawn::BufferUsage::CopyDst | dawn::BufferUsage::CopySrc;
wgpu::BufferDescriptor readbackBufferDesc;
readbackBufferDesc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::CopySrc;
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
dawn::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::Sampler},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false,
false, dawn::TextureViewDimension::e2D, sampleFormatInfo.type}});
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler},
{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false,
false, wgpu::TextureViewDimension::e2D, sampleFormatInfo.type}});
// Prepare objects needed to sample from texture in the renderpass
dawn::RenderPipeline pipeline =
wgpu::RenderPipeline pipeline =
CreateSamplePipeline(sampleFormatInfo, renderFormatInfo, bgl);
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
dawn::Sampler sampler = device.CreateSampler(&samplerDesc);
dawn::BindGroup bindGroup =
wgpu::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, bgl, {{0, sampler}, {1, sampleTexture.CreateView()}});
// 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.
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{
dawn::BufferCopyView bufferView = utils::CreateBufferCopyView(uploadBuffer, 0, 256, 0);
dawn::TextureCopyView textureView =
wgpu::BufferCopyView bufferView = utils::CreateBufferCopyView(uploadBuffer, 0, 256, 0);
wgpu::TextureCopyView textureView =
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);
}
utils::ComboRenderPassDescriptor renderPassDesc({renderTarget.CreateView()});
dawn::RenderPassEncoder renderPass = encoder.BeginRenderPass(&renderPassDesc);
wgpu::RenderPassEncoder renderPass = encoder.BeginRenderPass(&renderPassDesc);
renderPass.SetPipeline(pipeline);
renderPass.SetBindGroup(0, bindGroup);
renderPass.Draw(3, 1, 0, 0);
renderPass.EndPass();
{
dawn::BufferCopyView bufferView =
wgpu::BufferCopyView bufferView =
utils::CreateBufferCopyView(readbackBuffer, 0, 256, 0);
dawn::TextureCopyView textureView =
wgpu::TextureCopyView textureView =
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);
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
// 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) {
static_assert(!std::is_signed<T>::value && std::is_integral<T>::value, "");
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();
std::vector<T> textureData = {0, 1, maxValue, maxValue};
@ -381,7 +381,7 @@ class TextureFormatTest : public DawnTest {
void DoSnormTest(FormatTestInfo formatInfo) {
static_assert(std::is_signed<T>::value && std::is_integral<T>::value, "");
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 minValue = std::numeric_limits<T>::min();
@ -396,7 +396,7 @@ class TextureFormatTest : public DawnTest {
void DoUintTest(FormatTestInfo formatInfo) {
static_assert(!std::is_signed<T>::value && std::is_integral<T>::value, "");
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();
std::vector<T> textureData = {0, 1, maxValue, maxValue};
@ -410,7 +410,7 @@ class TextureFormatTest : public DawnTest {
void DoSintTest(FormatTestInfo formatInfo) {
static_assert(std::is_signed<T>::value && std::is_integral<T>::value, "");
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 minValue = std::numeric_limits<T>::min();
@ -423,7 +423,7 @@ class TextureFormatTest : public DawnTest {
void DoFloat32Test(FormatTestInfo formatInfo) {
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,
1.0e29f, NAN, INFINITY, -INFINITY};
@ -435,7 +435,7 @@ class TextureFormatTest : public DawnTest {
void DoFloat16Test(FormatTestInfo formatInfo) {
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,
1.0e4f, NAN, INFINITY, -INFINITY};
@ -454,18 +454,18 @@ class TextureFormatTest : public DawnTest {
// Test the R8Unorm format
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_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_P(TextureFormatTest, RGBA8Unorm) {
DoUnormTest<uint8_t>(
{dawn::TextureFormat::RGBA8Unorm, 4, dawn::TextureComponentType::Float, 4});
{wgpu::TextureFormat::RGBA8Unorm, 4, wgpu::TextureComponentType::Float, 4});
}
// Test the BGRA8Unorm format
@ -473,147 +473,147 @@ TEST_P(TextureFormatTest, BGRA8Unorm) {
uint8_t maxValue = std::numeric_limits<uint8_t>::max();
std::vector<uint8_t> textureData = {maxValue, 1, 0, maxValue};
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);
DoFormatRenderingTest(
{dawn::TextureFormat::BGRA8Unorm, 4, dawn::TextureComponentType::Float, 4},
{wgpu::TextureFormat::BGRA8Unorm, 4, wgpu::TextureComponentType::Float, 4},
uncompressedData, textureData);
}
// Test the R8Snorm format
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_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_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_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_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_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_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_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_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_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_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_P(TextureFormatTest, RGBA32Uint) {
DoUintTest<uint32_t>(
{dawn::TextureFormat::RGBA32Uint, 16, dawn::TextureComponentType::Uint, 4});
{wgpu::TextureFormat::RGBA32Uint, 16, wgpu::TextureComponentType::Uint, 4});
}
// Test the R8Sint format
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_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_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_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_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_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_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_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_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_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_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_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_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_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_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
@ -631,10 +631,10 @@ TEST_P(TextureFormatTest, RGBA8UnormSrgb) {
}
DoFloatFormatSamplingTest(
{dawn::TextureFormat::RGBA8UnormSrgb, 4, dawn::TextureComponentType::Float, 4}, textureData,
{wgpu::TextureFormat::RGBA8UnormSrgb, 4, wgpu::TextureComponentType::Float, 4}, textureData,
uncompressedData, 1.0e-3);
DoFormatRenderingTest(
{dawn::TextureFormat::RGBA8UnormSrgb, 4, dawn::TextureComponentType::Float, 4},
{wgpu::TextureFormat::RGBA8UnormSrgb, 4, wgpu::TextureComponentType::Float, 4},
uncompressedData, textureData);
}
@ -658,10 +658,10 @@ TEST_P(TextureFormatTest, BGRA8UnormSrgb) {
}
DoFloatFormatSamplingTest(
{dawn::TextureFormat::BGRA8UnormSrgb, 4, dawn::TextureComponentType::Float, 4}, textureData,
{wgpu::TextureFormat::BGRA8UnormSrgb, 4, wgpu::TextureComponentType::Float, 4}, textureData,
uncompressedData, 1.0e-3);
DoFormatRenderingTest(
{dawn::TextureFormat::BGRA8UnormSrgb, 4, dawn::TextureComponentType::Float, 4},
{wgpu::TextureFormat::BGRA8UnormSrgb, 4, wgpu::TextureComponentType::Float, 4},
uncompressedData, textureData);
}
@ -687,10 +687,10 @@ TEST_P(TextureFormatTest, RGB10A2Unorm) {
// clang-format on
DoFloatFormatSamplingTest(
{dawn::TextureFormat::RGB10A2Unorm, 4, dawn::TextureComponentType::Float, 4}, textureData,
{wgpu::TextureFormat::RGB10A2Unorm, 4, wgpu::TextureComponentType::Float, 4}, textureData,
uncompressedData, 1.0e-5);
DoFormatRenderingTest(
{dawn::TextureFormat::RGB10A2Unorm, 4, dawn::TextureComponentType::Float, 4},
{wgpu::TextureFormat::RGB10A2Unorm, 4, wgpu::TextureComponentType::Float, 4},
uncompressedData, textureData);
}
@ -734,7 +734,7 @@ TEST_P(TextureFormatTest, RG11B10Float) {
// clang-format on
DoFloatFormatSamplingTest(
{dawn::TextureFormat::RG11B10Float, 4, dawn::TextureComponentType::Float, 4}, textureData,
{wgpu::TextureFormat::RG11B10Float, 4, wgpu::TextureComponentType::Float, 4}, textureData,
uncompressedData);
// This format is not renderable.
}

View File

@ -23,18 +23,18 @@
#include <array>
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;
namespace {
dawn::Texture Create2DTexture(dawn::Device device,
wgpu::Texture Create2DTexture(wgpu::Device device,
uint32_t width,
uint32_t height,
uint32_t arrayLayerCount,
uint32_t mipLevelCount,
dawn::TextureUsage usage) {
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureUsage usage) {
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = width;
descriptor.size.height = height;
descriptor.size.depth = 1;
@ -46,7 +46,7 @@ namespace {
return device.CreateTexture(&descriptor);
}
dawn::ShaderModule CreateDefaultVertexShaderModule(dawn::Device device) {
wgpu::ShaderModule CreateDefaultVertexShaderModule(wgpu::Device device) {
return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
layout (location = 0) out vec2 o_texCoord;
@ -83,10 +83,10 @@ protected:
mRenderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::FilterMode kFilterMode = dawn::FilterMode::Nearest;
dawn::AddressMode kAddressMode = dawn::AddressMode::ClampToEdge;
wgpu::FilterMode kFilterMode = wgpu::FilterMode::Nearest;
wgpu::AddressMode kAddressMode = wgpu::AddressMode::ClampToEdge;
dawn::SamplerDescriptor samplerDescriptor;
wgpu::SamplerDescriptor samplerDescriptor;
samplerDescriptor.minFilter = kFilterMode;
samplerDescriptor.magFilter = kFilterMode;
samplerDescriptor.mipmapFilter = kFilterMode;
@ -95,7 +95,7 @@ protected:
samplerDescriptor.addressModeW = kAddressMode;
samplerDescriptor.lodMinClamp = kLodMin;
samplerDescriptor.lodMaxClamp = kLodMax;
samplerDescriptor.compare = dawn::CompareFunction::Never;
samplerDescriptor.compare = wgpu::CompareFunction::Never;
mSampler = device.CreateSampler(&samplerDescriptor);
mVSModule = CreateDefaultVertexShaderModule(device);
@ -106,12 +106,12 @@ protected:
const uint32_t textureWidthLevel0 = 1 << mipLevelCount;
const uint32_t textureHeightLevel0 = 1 << mipLevelCount;
constexpr dawn::TextureUsage kUsage =
dawn::TextureUsage::CopyDst | dawn::TextureUsage::Sampled;
constexpr wgpu::TextureUsage kUsage =
wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled;
mTexture = Create2DTexture(
device, textureWidthLevel0, textureHeightLevel0, arrayLayerCount, mipLevelCount, kUsage);
mDefaultTextureViewDescriptor.dimension = dawn::TextureViewDimension::e2DArray;
mDefaultTextureViewDescriptor.dimension = wgpu::TextureViewDimension::e2DArray;
mDefaultTextureViewDescriptor.format = kDefaultFormat;
mDefaultTextureViewDescriptor.baseMipLevel = 0;
mDefaultTextureViewDescriptor.mipLevelCount = mipLevelCount;
@ -125,7 +125,7 @@ protected:
constexpr uint32_t kPixelsPerRowPitch = kTextureRowPitchAlignment / sizeof(RGBA8);
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 level = 0; level < mipLevelCount; ++level) {
const uint32_t texWidth = textureWidthLevel0 >> level;
@ -135,35 +135,35 @@ protected:
constexpr uint32_t kPaddedTexWidth = kPixelsPerRowPitch;
std::vector<RGBA8> data(kPaddedTexWidth * texHeight, RGBA8(0, 0, 0, pixelValue));
dawn::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), data.size() * sizeof(RGBA8), dawn::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView =
wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), data.size() * sizeof(RGBA8), wgpu::BufferUsage::CopySrc);
wgpu::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(stagingBuffer, 0, kTextureRowPitchAlignment, 0);
dawn::TextureCopyView textureCopyView =
wgpu::TextureCopyView textureCopyView =
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);
}
}
dawn::CommandBuffer copy = encoder.Finish();
wgpu::CommandBuffer copy = encoder.Finish();
queue.Submit(1, &copy);
}
void Verify(const dawn::TextureView& textureView,
dawn::TextureViewDimension dimension,
void Verify(const wgpu::TextureView& textureView,
wgpu::TextureViewDimension dimension,
const char* fragmentShader,
int expected) {
dawn::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
wgpu::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
device, {
{0, dawn::ShaderStage::Fragment, dawn::BindingType::Sampler},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture, false,
false, dimension, dawn::TextureComponentType::Float},
{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler},
{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false,
false, dimension, wgpu::TextureComponentType::Float},
});
dawn::BindGroup bindGroup =
wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, bindGroupLayout, {{0, mSampler}, {1, textureView}});
dawn::ShaderModule fsModule =
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fragmentShader);
utils::ComboRenderPipelineDescriptor textureDescriptor(device);
@ -172,18 +172,18 @@ protected:
textureDescriptor.layout = utils::MakeBasicPipelineLayout(device, &bindGroupLayout);
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.SetBindGroup(0, bindGroup);
pass.Draw(6, 1, 0, 0);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
RGBA8 expectedPixel(0, 0, 0, expected);
@ -202,13 +202,13 @@ protected:
initTexture(textureArrayLayers, textureMipLevels);
dawn::TextureViewDescriptor descriptor = mDefaultTextureViewDescriptor;
descriptor.dimension = dawn::TextureViewDimension::e2D;
wgpu::TextureViewDescriptor descriptor = mDefaultTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::e2D;
descriptor.baseArrayLayer = textureViewBaseLayer;
descriptor.arrayLayerCount = 1;
descriptor.baseMipLevel = textureViewBaseMipLevel;
descriptor.mipLevelCount = 1;
dawn::TextureView textureView = mTexture.CreateView(&descriptor);
wgpu::TextureView textureView = mTexture.CreateView(&descriptor);
const char* fragmentShader = R"(
#version 450
@ -224,7 +224,7 @@ protected:
)";
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,
@ -241,13 +241,13 @@ protected:
initTexture(textureArrayLayers, textureMipLevels);
dawn::TextureViewDescriptor descriptor = mDefaultTextureViewDescriptor;
descriptor.dimension = dawn::TextureViewDimension::e2DArray;
wgpu::TextureViewDescriptor descriptor = mDefaultTextureViewDescriptor;
descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
descriptor.baseArrayLayer = textureViewBaseLayer;
descriptor.arrayLayerCount = kTextureViewLayerCount;
descriptor.baseMipLevel = textureViewBaseMipLevel;
descriptor.mipLevelCount = 1;
dawn::TextureView textureView = mTexture.CreateView(&descriptor);
wgpu::TextureView textureView = mTexture.CreateView(&descriptor);
const char* fragmentShader = R"(
#version 450
@ -268,7 +268,7 @@ protected:
for (int i = 0; i < static_cast<int>(kTextureViewLayerCount); ++i) {
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) {
@ -320,16 +320,16 @@ protected:
ASSERT_TRUE((textureViewLayerCount == 6) ||
(isCubeMapArray && textureViewLayerCount % 6 == 0));
dawn::TextureViewDimension dimension = (isCubeMapArray)
? dawn::TextureViewDimension::CubeArray
: dawn::TextureViewDimension::Cube;
wgpu::TextureViewDimension dimension = (isCubeMapArray)
? wgpu::TextureViewDimension::CubeArray
: wgpu::TextureViewDimension::Cube;
dawn::TextureViewDescriptor descriptor = mDefaultTextureViewDescriptor;
wgpu::TextureViewDescriptor descriptor = mDefaultTextureViewDescriptor;
descriptor.dimension = dimension;
descriptor.baseArrayLayer = textureViewBaseLayer;
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.
for (uint32_t layer = 0; layer < textureViewLayerCount; ++layer) {
@ -341,10 +341,10 @@ protected:
}
}
dawn::Sampler mSampler;
dawn::Texture mTexture;
dawn::TextureViewDescriptor mDefaultTextureViewDescriptor;
dawn::ShaderModule mVSModule;
wgpu::Sampler mSampler;
wgpu::Texture mTexture;
wgpu::TextureViewDescriptor mDefaultTextureViewDescriptor;
wgpu::ShaderModule mVSModule;
utils::BasicRenderPass mRenderPass;
};
@ -357,7 +357,7 @@ TEST_P(TextureViewSamplingTest, Default2DArrayTexture) {
constexpr uint32_t kMipLevels = 1;
initTexture(kLayers, kMipLevels);
dawn::TextureView textureView = mTexture.CreateView();
wgpu::TextureView textureView = mTexture.CreateView();
const char* fragmentShader = R"(
#version 450
@ -376,7 +376,7 @@ TEST_P(TextureViewSamplingTest, Default2DArrayTexture) {
const int expected = GenerateTestPixelValue(0, 0) + GenerateTestPixelValue(1, 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.
@ -461,33 +461,33 @@ TEST_P(TextureViewSamplingTest, TextureCubeMapArrayViewSingleCubeMap) {
class TextureViewRenderingTest : public DawnTest {
protected:
void TextureLayerAsColorAttachmentTest(dawn::TextureViewDimension dimension,
void TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension dimension,
uint32_t layerCount,
uint32_t levelCount,
uint32_t textureViewBaseLayer,
uint32_t textureViewBaseLevel) {
ASSERT(dimension == dawn::TextureViewDimension::e2D ||
dimension == dawn::TextureViewDimension::e2DArray);
ASSERT(dimension == wgpu::TextureViewDimension::e2D ||
dimension == wgpu::TextureViewDimension::e2DArray);
ASSERT_LT(textureViewBaseLayer, layerCount);
ASSERT_LT(textureViewBaseLevel, levelCount);
const uint32_t textureWidthLevel0 = 1 << levelCount;
const uint32_t textureHeightLevel0 = 1 << levelCount;
constexpr dawn::TextureUsage kUsage =
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc;
dawn::Texture texture = Create2DTexture(
device, textureWidthLevel0, textureHeightLevel0, layerCount, levelCount, kUsage);
constexpr wgpu::TextureUsage kUsage =
wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
wgpu::Texture texture = Create2DTexture(device, textureWidthLevel0, textureHeightLevel0,
layerCount, levelCount, kUsage);
dawn::TextureViewDescriptor descriptor;
wgpu::TextureViewDescriptor descriptor;
descriptor.format = kDefaultFormat;
descriptor.dimension = dimension;
descriptor.baseArrayLayer = textureViewBaseLayer;
descriptor.arrayLayerCount = 1;
descriptor.baseMipLevel = textureViewBaseLevel;
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
utils::ComboRenderPassDescriptor renderPassInfo({textureView});
@ -501,7 +501,7 @@ class TextureViewRenderingTest : public DawnTest {
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);
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
@ -509,17 +509,17 @@ class TextureViewRenderingTest : public DawnTest {
pipelineDescriptor.cFragmentStage.module = oneColorFsModule;
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.Draw(6, 1, 0, 0);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
// 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
{
constexpr uint32_t kBaseLevel = 0;
TextureLayerAsColorAttachmentTest(
dawn::TextureViewDimension::e2D, kLayers, kMipLevels, kBaseLayer, kBaseLevel);
TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2D, kLayers, kMipLevels,
kBaseLayer, kBaseLevel);
}
// Rendering into the last level
{
constexpr uint32_t kBaseLevel = kMipLevels - 1;
TextureLayerAsColorAttachmentTest(
dawn::TextureViewDimension::e2D, kLayers, kMipLevels, kBaseLayer, kBaseLevel);
TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2D, kLayers, kMipLevels,
kBaseLayer, kBaseLevel);
}
}
@ -566,15 +566,15 @@ TEST_P(TextureViewRenderingTest, Texture2DViewOnALayerOf2DArrayTextureAsColorAtt
// Rendering into the first layer
{
constexpr uint32_t kBaseLayer = 0;
TextureLayerAsColorAttachmentTest(
dawn::TextureViewDimension::e2D, kLayers, kMipLevels, kBaseLayer, kBaseLevel);
TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2D, kLayers, kMipLevels,
kBaseLayer, kBaseLevel);
}
// Rendering into the last layer
{
constexpr uint32_t kBaseLayer = kLayers - 1;
TextureLayerAsColorAttachmentTest(
dawn::TextureViewDimension::e2D, kLayers, kMipLevels, kBaseLayer, kBaseLevel);
TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2D, kLayers, kMipLevels,
kBaseLayer, kBaseLevel);
}
}
@ -588,15 +588,15 @@ TEST_P(TextureViewRenderingTest, Texture2DArrayViewOnALevelOf2DTextureAsColorAtt
// Rendering into the first level
{
constexpr uint32_t kBaseLevel = 0;
TextureLayerAsColorAttachmentTest(
dawn::TextureViewDimension::e2DArray, kLayers, kMipLevels, kBaseLayer, kBaseLevel);
TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2DArray, kLayers, kMipLevels,
kBaseLayer, kBaseLevel);
}
// Rendering into the last level
{
constexpr uint32_t kBaseLevel = kMipLevels - 1;
TextureLayerAsColorAttachmentTest(
dawn::TextureViewDimension::e2DArray, kLayers, kMipLevels, kBaseLayer, kBaseLevel);
TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2DArray, kLayers, kMipLevels,
kBaseLayer, kBaseLevel);
}
}
@ -609,15 +609,15 @@ TEST_P(TextureViewRenderingTest, Texture2DArrayViewOnALayerOf2DArrayTextureAsCol
// Rendering into the first layer
{
constexpr uint32_t kBaseLayer = 0;
TextureLayerAsColorAttachmentTest(
dawn::TextureViewDimension::e2DArray, kLayers, kMipLevels, kBaseLayer, kBaseLevel);
TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2DArray, kLayers, kMipLevels,
kBaseLayer, kBaseLevel);
}
// Rendering into the last layer
{
constexpr uint32_t kBaseLayer = kLayers - 1;
TextureLayerAsColorAttachmentTest(
dawn::TextureViewDimension::e2DArray, kLayers, kMipLevels, kBaseLayer, kBaseLevel);
TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2DArray, kLayers, kMipLevels,
kBaseLayer, kBaseLevel);
}
}

View File

@ -23,12 +23,12 @@ class TextureZeroInitTest : public DawnTest {
void TestSetUp() override {
DawnTest::TestSetUp();
}
dawn::TextureDescriptor CreateTextureDescriptor(uint32_t mipLevelCount,
wgpu::TextureDescriptor CreateTextureDescriptor(uint32_t mipLevelCount,
uint32_t arrayLayerCount,
dawn::TextureUsage usage,
dawn::TextureFormat format) {
dawn::TextureDescriptor descriptor;
descriptor.dimension = dawn::TextureDimension::e2D;
wgpu::TextureUsage usage,
wgpu::TextureFormat format) {
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = kSize;
descriptor.size.height = kSize;
descriptor.size.depth = 1;
@ -39,18 +39,18 @@ class TextureZeroInitTest : public DawnTest {
descriptor.usage = usage;
return descriptor;
}
dawn::TextureViewDescriptor CreateTextureViewDescriptor(uint32_t baseMipLevel,
wgpu::TextureViewDescriptor CreateTextureViewDescriptor(uint32_t baseMipLevel,
uint32_t baseArrayLayer) {
dawn::TextureViewDescriptor descriptor;
wgpu::TextureViewDescriptor descriptor;
descriptor.format = kColorFormat;
descriptor.baseArrayLayer = baseArrayLayer;
descriptor.arrayLayerCount = 1;
descriptor.baseMipLevel = baseMipLevel;
descriptor.mipLevelCount = 1;
descriptor.dimension = dawn::TextureViewDimension::e2D;
descriptor.dimension = wgpu::TextureViewDimension::e2D;
return descriptor;
}
dawn::RenderPipeline CreatePipelineForTest() {
wgpu::RenderPipeline CreatePipelineForTest() {
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
pipelineDescriptor.vertexStage.module = CreateBasicVertexShaderForTest();
const char* fs =
@ -62,13 +62,13 @@ class TextureZeroInitTest : public DawnTest {
pipelineDescriptor.cFragmentStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs);
pipelineDescriptor.cDepthStencilState.depthCompare = dawn::CompareFunction::Equal;
pipelineDescriptor.cDepthStencilState.stencilFront.compare = dawn::CompareFunction::Equal;
pipelineDescriptor.cDepthStencilState.depthCompare = wgpu::CompareFunction::Equal;
pipelineDescriptor.cDepthStencilState.stencilFront.compare = wgpu::CompareFunction::Equal;
pipelineDescriptor.depthStencilState = &pipelineDescriptor.cDepthStencilState;
return device.CreateRenderPipeline(&pipelineDescriptor);
}
dawn::ShaderModule CreateBasicVertexShaderForTest() {
wgpu::ShaderModule CreateBasicVertexShaderForTest() {
return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(#version 450
const vec2 pos[6] = vec2[6](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);
})");
}
dawn::ShaderModule CreateSampledTextureFragmentShaderForTest() {
wgpu::ShaderModule CreateSampledTextureFragmentShaderForTest() {
return utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment,
R"(#version 450
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
// same byte size of 4.
constexpr static uint32_t kFormatBlockByteSize = 4;
constexpr static dawn::TextureFormat kColorFormat = dawn::TextureFormat::RGBA8Unorm;
constexpr static dawn::TextureFormat kDepthStencilFormat =
dawn::TextureFormat::Depth24PlusStencil8;
constexpr static dawn::TextureFormat kNonrenderableColorFormat =
dawn::TextureFormat::RGBA8Snorm;
constexpr static wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
constexpr static wgpu::TextureFormat kDepthStencilFormat =
wgpu::TextureFormat::Depth24PlusStencil8;
constexpr static wgpu::TextureFormat kNonrenderableColorFormat =
wgpu::TextureFormat::RGBA8Snorm;
};
// This tests that the code path of CopyTextureToBuffer clears correctly to Zero after first usage
TEST_P(TextureZeroInitTest, CopyTextureToBufferSource) {
dawn::TextureDescriptor descriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc, kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
1, 1, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc, kColorFormat);
wgpu::Texture texture = device.CreateTexture(&descriptor);
// Texture's first usage is in EXPECT_PIXEL_RGBA8_EQ's call to CopyTextureToBuffer
RGBA8 filledWithZeros(0, 0, 0, 0);
@ -118,23 +118,23 @@ TEST_P(TextureZeroInitTest, CopyTextureToBufferSource) {
// Test that non-zero mip level clears subresource to Zero after first use
// This goes through the BeginRenderPass's code path
TEST_P(TextureZeroInitTest, RenderingMipMapClearsToZero) {
dawn::TextureDescriptor descriptor = CreateTextureDescriptor(
4, 1, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc, kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
4, 1, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc, kColorFormat);
wgpu::Texture texture = device.CreateTexture(&descriptor);
dawn::TextureViewDescriptor viewDescriptor = CreateTextureViewDescriptor(2, 0);
dawn::TextureView view = texture.CreateView(&viewDescriptor);
wgpu::TextureViewDescriptor viewDescriptor = CreateTextureViewDescriptor(2, 0);
wgpu::TextureView view = texture.CreateView(&viewDescriptor);
utils::BasicRenderPass renderPass = utils::BasicRenderPass(kSize, kSize, texture, kColorFormat);
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
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.EndPass();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
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.
// This goes through the BeginRenderPass's code path
TEST_P(TextureZeroInitTest, RenderingArrayLayerClearsToZero) {
dawn::TextureDescriptor descriptor = CreateTextureDescriptor(
1, 4, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc, kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
1, 4, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc, kColorFormat);
wgpu::Texture texture = device.CreateTexture(&descriptor);
dawn::TextureViewDescriptor viewDescriptor = CreateTextureViewDescriptor(0, 2);
dawn::TextureView view = texture.CreateView(&viewDescriptor);
wgpu::TextureViewDescriptor viewDescriptor = CreateTextureViewDescriptor(0, 2);
wgpu::TextureView view = texture.CreateView(&viewDescriptor);
utils::BasicRenderPass renderPass = utils::BasicRenderPass(kSize, kSize, texture, kColorFormat);
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();
}
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
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.
TEST_P(TextureZeroInitTest, CopyBufferToTexture) {
dawn::TextureDescriptor descriptor = CreateTextureDescriptor(
wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
4, 1,
dawn::TextureUsage::CopyDst | dawn::TextureUsage::Sampled | dawn::TextureUsage::CopySrc,
wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopySrc,
kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor);
wgpu::Texture texture = device.CreateTexture(&descriptor);
std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize, 100);
dawn::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc);
wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1};
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0);
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
wgpu::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
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
// half.
TEST_P(TextureZeroInitTest, CopyBufferToTextureHalf) {
dawn::TextureDescriptor descriptor = CreateTextureDescriptor(
wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
4, 1,
dawn::TextureUsage::CopyDst | dawn::TextureUsage::Sampled | dawn::TextureUsage::CopySrc,
wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopySrc,
kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor);
wgpu::Texture texture = device.CreateTexture(&descriptor);
std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize, 100);
dawn::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc);
wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize / 2, kSize, 1};
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0);
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
wgpu::Extent3D copySize = {kSize / 2, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
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.
TEST_P(TextureZeroInitTest, CopyTextureToTexture) {
dawn::TextureDescriptor srcDescriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::Sampled | dawn::TextureUsage::CopySrc, kColorFormat);
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor);
wgpu::TextureDescriptor srcDescriptor = CreateTextureDescriptor(
1, 1, wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopySrc, kColorFormat);
wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
dawn::TextureCopyView srcTextureCopyView =
wgpu::TextureCopyView srcTextureCopyView =
utils::CreateTextureCopyView(srcTexture, 0, 0, {0, 0, 0});
dawn::TextureDescriptor dstDescriptor =
wgpu::TextureDescriptor dstDescriptor =
CreateTextureDescriptor(1, 1,
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopyDst |
dawn::TextureUsage::CopySrc,
wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopyDst |
wgpu::TextureUsage::CopySrc,
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});
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);
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
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
// necessary to clear the other half.
TEST_P(TextureZeroInitTest, CopyTextureToTextureHalf) {
dawn::TextureDescriptor srcDescriptor = CreateTextureDescriptor(
wgpu::TextureDescriptor srcDescriptor = CreateTextureDescriptor(
1, 1,
dawn::TextureUsage::Sampled | dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst,
wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst,
kColorFormat);
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor);
wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
// fill srcTexture with 100
{
std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize, 100);
dawn::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0);
dawn::TextureCopyView textureCopyView =
wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0);
wgpu::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(srcTexture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::Extent3D copySize = {kSize, kSize, 1};
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
}
dawn::TextureCopyView srcTextureCopyView =
wgpu::TextureCopyView srcTextureCopyView =
utils::CreateTextureCopyView(srcTexture, 0, 0, {0, 0, 0});
dawn::TextureDescriptor dstDescriptor =
wgpu::TextureDescriptor dstDescriptor =
CreateTextureDescriptor(1, 1,
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopyDst |
dawn::TextureUsage::CopySrc,
wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopyDst |
wgpu::TextureUsage::CopySrc,
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});
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);
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
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
// 0s.
TEST_P(TextureZeroInitTest, RenderingLoadingDepth) {
dawn::TextureDescriptor srcDescriptor =
wgpu::TextureDescriptor srcDescriptor =
CreateTextureDescriptor(1, 1,
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst |
dawn::TextureUsage::OutputAttachment,
wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
wgpu::TextureUsage::OutputAttachment,
kColorFormat);
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor);
wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
dawn::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc,
wgpu::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor(
1, 1, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc,
kDepthStencilFormat);
dawn::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor);
wgpu::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor);
utils::ComboRenderPassDescriptor renderPassDescriptor({srcTexture.CreateView()},
depthStencilTexture.CreateView());
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = dawn::LoadOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = wgpu::LoadOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.clearStencil = 0;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = dawn::StoreOp::Store;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = dawn::StoreOp::Store;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Store;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Store;
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
auto pass = encoder.BeginRenderPass(&renderPassDescriptor);
pass.SetPipeline(CreatePipelineForTest());
pass.Draw(6, 1, 0, 0);
pass.EndPass();
dawn::CommandBuffer commandBuffer = encoder.Finish();
wgpu::CommandBuffer commandBuffer = encoder.Finish();
// Expect 0 lazy clears, depth stencil texture will clear using loadop
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
// to 0s.
TEST_P(TextureZeroInitTest, RenderingLoadingStencil) {
dawn::TextureDescriptor srcDescriptor =
wgpu::TextureDescriptor srcDescriptor =
CreateTextureDescriptor(1, 1,
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst |
dawn::TextureUsage::OutputAttachment,
wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
wgpu::TextureUsage::OutputAttachment,
kColorFormat);
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor);
wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
dawn::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc,
wgpu::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor(
1, 1, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc,
kDepthStencilFormat);
dawn::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor);
wgpu::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor);
utils::ComboRenderPassDescriptor renderPassDescriptor({srcTexture.CreateView()},
depthStencilTexture.CreateView());
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.clearDepth = 0.0f;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = dawn::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = dawn::StoreOp::Store;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = dawn::StoreOp::Store;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = wgpu::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Store;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Store;
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
auto pass = encoder.BeginRenderPass(&renderPassDescriptor);
pass.SetPipeline(CreatePipelineForTest());
pass.Draw(6, 1, 0, 0);
pass.EndPass();
dawn::CommandBuffer commandBuffer = encoder.Finish();
wgpu::CommandBuffer commandBuffer = encoder.Finish();
// Expect 0 lazy clears, depth stencil texture will clear using loadop
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
// texture to 0s.
TEST_P(TextureZeroInitTest, RenderingLoadingDepthStencil) {
dawn::TextureDescriptor srcDescriptor =
wgpu::TextureDescriptor srcDescriptor =
CreateTextureDescriptor(1, 1,
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst |
dawn::TextureUsage::OutputAttachment,
wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
wgpu::TextureUsage::OutputAttachment,
kColorFormat);
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor);
wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
dawn::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc,
wgpu::TextureDescriptor depthStencilDescriptor = CreateTextureDescriptor(
1, 1, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc,
kDepthStencilFormat);
dawn::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor);
wgpu::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor);
utils::ComboRenderPassDescriptor renderPassDescriptor({srcTexture.CreateView()},
depthStencilTexture.CreateView());
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = dawn::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = dawn::StoreOp::Store;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = dawn::StoreOp::Store;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = wgpu::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Store;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Store;
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
auto pass = encoder.BeginRenderPass(&renderPassDescriptor);
pass.SetPipeline(CreatePipelineForTest());
pass.Draw(6, 1, 0, 0);
pass.EndPass();
dawn::CommandBuffer commandBuffer = encoder.Finish();
wgpu::CommandBuffer commandBuffer = encoder.Finish();
// Expect 0 lazy clears, depth stencil texture will clear using loadop
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer));
@ -421,17 +421,17 @@ TEST_P(TextureZeroInitTest, RenderingLoadingDepthStencil) {
// This tests the color attachments clear to 0s
TEST_P(TextureZeroInitTest, ColorAttachmentsClear) {
dawn::TextureDescriptor descriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc, kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
1, 1, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc, kColorFormat);
wgpu::Texture texture = device.CreateTexture(&descriptor);
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();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
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
TEST_P(TextureZeroInitTest, RenderPassSampledTextureClear) {
// Create needed resources
dawn::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 1, dawn::TextureUsage::Sampled, kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 1, wgpu::TextureUsage::Sampled, kColorFormat);
wgpu::Texture texture = device.CreateTexture(&descriptor);
dawn::TextureDescriptor renderTextureDescriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::CopySrc | dawn::TextureUsage::OutputAttachment, kColorFormat);
dawn::Texture renderTexture = device.CreateTexture(&renderTextureDescriptor);
wgpu::TextureDescriptor renderTextureDescriptor = CreateTextureDescriptor(
1, 1, wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::OutputAttachment, kColorFormat);
wgpu::Texture renderTexture = device.CreateTexture(&renderTextureDescriptor);
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
dawn::Sampler sampler = device.CreateSampler(&samplerDesc);
wgpu::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
dawn::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::Sampler},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture}});
wgpu::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler},
{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture}});
// Create render pipeline
utils::ComboRenderPipelineDescriptor renderPipelineDescriptor(device);
@ -462,23 +462,23 @@ TEST_P(TextureZeroInitTest, RenderPassSampledTextureClear) {
renderPipelineDescriptor.cColorStates[0].format = kColorFormat;
renderPipelineDescriptor.vertexStage.module = CreateBasicVertexShaderForTest();
renderPipelineDescriptor.cFragmentStage.module = CreateSampledTextureFragmentShaderForTest();
dawn::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor);
wgpu::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor);
// Create bindgroup
dawn::BindGroup bindGroup =
wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, bindGroupLayout, {{0, sampler}, {1, texture.CreateView()}});
// Encode pass and submit
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
utils::ComboRenderPassDescriptor renderPassDesc({renderTexture.CreateView()});
renderPassDesc.cColorAttachments[0].clearColor = {1.0, 1.0, 1.0, 1.0};
renderPassDesc.cColorAttachments[0].loadOp = dawn::LoadOp::Clear;
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc);
renderPassDesc.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc);
pass.SetPipeline(renderPipeline);
pass.SetBindGroup(0, bindGroup);
pass.Draw(6, 1, 0, 0);
pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
// Expect 1 lazy clear for sampled texture
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
TEST_P(TextureZeroInitTest, ComputePassSampledTextureClear) {
// Create needed resources
dawn::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 1, dawn::TextureUsage::Sampled, kColorFormat);
wgpu::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 1, wgpu::TextureUsage::Sampled, kColorFormat);
descriptor.size.width = 1;
descriptor.size.height = 1;
dawn::Texture texture = device.CreateTexture(&descriptor);
wgpu::Texture texture = device.CreateTexture(&descriptor);
uint32_t bufferSize = kFormatBlockByteSize * sizeof(uint32_t);
dawn::BufferDescriptor bufferDescriptor;
wgpu::BufferDescriptor bufferDescriptor;
bufferDescriptor.size = bufferSize;
bufferDescriptor.usage =
dawn::BufferUsage::CopySrc | dawn::BufferUsage::Storage | dawn::BufferUsage::CopyDst;
dawn::Buffer bufferTex = device.CreateBuffer(&bufferDescriptor);
wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopyDst;
wgpu::Buffer bufferTex = device.CreateBuffer(&bufferDescriptor);
// Add data to buffer to ensure it is initialized
uint32_t data = 100;
bufferTex.SetSubData(0, sizeof(data), &data);
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
dawn::Sampler sampler = device.CreateSampler(&samplerDesc);
wgpu::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
dawn::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Compute, dawn::BindingType::SampledTexture},
{1, dawn::ShaderStage::Compute, dawn::BindingType::StorageBuffer},
{2, dawn::ShaderStage::Compute, dawn::BindingType::Sampler}});
wgpu::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Compute, wgpu::BindingType::SampledTexture},
{1, wgpu::ShaderStage::Compute, wgpu::BindingType::StorageBuffer},
{2, wgpu::ShaderStage::Compute, wgpu::BindingType::Sampler}});
// Create compute pipeline
dawn::ComputePipelineDescriptor computePipelineDescriptor;
wgpu::ComputePipelineDescriptor computePipelineDescriptor;
computePipelineDescriptor.layout = utils::MakeBasicPipelineLayout(device, &bindGroupLayout);
dawn::ProgrammableStageDescriptor computeStage;
wgpu::ProgrammableStageDescriptor computeStage;
const char* cs =
R"(#version 450
layout(binding = 0) uniform texture2D sampleTex;
@ -532,22 +532,22 @@ TEST_P(TextureZeroInitTest, ComputePassSampledTextureClear) {
computePipelineDescriptor.computeStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, cs);
computePipelineDescriptor.computeStage.entryPoint = "main";
dawn::ComputePipeline computePipeline =
wgpu::ComputePipeline computePipeline =
device.CreateComputePipeline(&computePipelineDescriptor);
// Create bindgroup
dawn::BindGroup bindGroup = utils::MakeBindGroup(
wgpu::BindGroup bindGroup = utils::MakeBindGroup(
device, bindGroupLayout,
{{0, texture.CreateView()}, {1, bufferTex, 0, bufferSize}, {2, sampler}});
// Encode the pass and submit
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::ComputePassEncoder pass = encoder.BeginComputePass();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(computePipeline);
pass.SetBindGroup(0, bindGroup);
pass.Dispatch(1, 1, 1);
pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
// 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
TEST_P(TextureZeroInitTest, NonRenderableTextureClear) {
dawn::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 1, dawn::TextureUsage::CopySrc, kNonrenderableColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 1, wgpu::TextureUsage::CopySrc, kNonrenderableColorFormat);
wgpu::Texture texture = device.CreateTexture(&descriptor);
// 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 bufferSize = rowPitch * kSize;
std::vector<uint8_t> data(bufferSize, 100);
dawn::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc);
wgpu::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, rowPitch, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1};
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, rowPitch, 0);
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
wgpu::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
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
TEST_P(TextureZeroInitTest, NonRenderableTextureClearUnalignedSize) {
dawn::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 1, dawn::TextureUsage::CopySrc, kNonrenderableColorFormat);
wgpu::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 1, wgpu::TextureUsage::CopySrc, kNonrenderableColorFormat);
descriptor.size.width = 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
uint32_t rowPitch = Align(kUnalignedSize * kFormatBlockByteSize, kTextureRowPitchAlignment);
uint32_t bufferSize = rowPitch * kUnalignedSize;
std::vector<uint8_t> data(bufferSize, 100);
dawn::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, rowPitch, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kUnalignedSize, kUnalignedSize, 1};
wgpu::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, rowPitch, 0);
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
wgpu::Extent3D copySize = {kUnalignedSize, kUnalignedSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
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.
DAWN_SKIP_TEST_IF(IsOpenGL());
dawn::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 2, dawn::TextureUsage::CopySrc, kNonrenderableColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureDescriptor descriptor =
CreateTextureDescriptor(1, 2, wgpu::TextureUsage::CopySrc, kNonrenderableColorFormat);
wgpu::Texture texture = device.CreateTexture(&descriptor);
// Set buffer with dirty data so we know it is cleared by the lazy cleared texture copy
uint32_t bufferSize = kFormatBlockByteSize * kSize * kSize;
std::vector<uint8_t> data(bufferSize, 100);
dawn::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc);
wgpu::Buffer bufferDst = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 1, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1};
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0);
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 1, {0, 0, 0});
wgpu::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize);
dawn::CommandBuffer commands = encoder.Finish();
wgpu::CommandBuffer commands = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commands));
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.
TEST_P(TextureZeroInitTest, RenderPassStoreOpClear) {
// Create needed resources
dawn::TextureDescriptor descriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::Sampled | dawn::TextureUsage::CopyDst, kColorFormat);
dawn::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
1, 1, wgpu::TextureUsage::Sampled | wgpu::TextureUsage::CopyDst, kColorFormat);
wgpu::Texture texture = device.CreateTexture(&descriptor);
dawn::TextureDescriptor renderTextureDescriptor = CreateTextureDescriptor(
1, 1, dawn::TextureUsage::CopySrc | dawn::TextureUsage::OutputAttachment, kColorFormat);
dawn::Texture renderTexture = device.CreateTexture(&renderTextureDescriptor);
wgpu::TextureDescriptor renderTextureDescriptor = CreateTextureDescriptor(
1, 1, wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::OutputAttachment, kColorFormat);
wgpu::Texture renderTexture = device.CreateTexture(&renderTextureDescriptor);
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
dawn::Sampler sampler = device.CreateSampler(&samplerDesc);
wgpu::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
dawn::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
device, {{0, dawn::ShaderStage::Fragment, dawn::BindingType::Sampler},
{1, dawn::ShaderStage::Fragment, dawn::BindingType::SampledTexture}});
wgpu::BindGroupLayout bindGroupLayout = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler},
{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture}});
// Fill the sample texture with data
std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize, 1);
dawn::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), dawn::BufferUsage::CopySrc);
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {kSize, kSize, 1};
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0);
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
wgpu::Extent3D copySize = {kSize, kSize, 1};
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
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_LAZY_CLEAR(0u, queue.Submit(1, &commands));
@ -678,19 +678,19 @@ TEST_P(TextureZeroInitTest, RenderPassStoreOpClear) {
renderPipelineDescriptor.vertexStage.module = CreateBasicVertexShaderForTest();
renderPipelineDescriptor.cFragmentStage.module = CreateSampledTextureFragmentShaderForTest();
renderPipelineDescriptor.cColorStates[0].format = kColorFormat;
dawn::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor);
wgpu::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor);
// Create bindgroup
dawn::BindGroup bindGroup =
wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, bindGroupLayout, {{0, sampler}, {1, texture.CreateView()}});
// Encode pass and submit
encoder = device.CreateCommandEncoder();
utils::ComboRenderPassDescriptor renderPassDesc({renderTexture.CreateView()});
renderPassDesc.cColorAttachments[0].clearColor = {0.0, 0.0, 0.0, 0.0};
renderPassDesc.cColorAttachments[0].loadOp = dawn::LoadOp::Clear;
renderPassDesc.cColorAttachments[0].storeOp = dawn::StoreOp::Clear;
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc);
renderPassDesc.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
renderPassDesc.cColorAttachments[0].storeOp = wgpu::StoreOp::Clear;
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc);
pass.SetPipeline(renderPipeline);
pass.SetBindGroup(0, bindGroup);
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
// 0's This means the depth and stencil test will pass and the red square is drawn.
TEST_P(TextureZeroInitTest, RenderingLoadingDepthStencilStoreOpClear) {
dawn::TextureDescriptor srcDescriptor =
wgpu::TextureDescriptor srcDescriptor =
CreateTextureDescriptor(1, 1,
dawn::TextureUsage::CopySrc | dawn::TextureUsage::CopyDst |
dawn::TextureUsage::OutputAttachment,
wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
wgpu::TextureUsage::OutputAttachment,
kColorFormat);
dawn::Texture srcTexture = device.CreateTexture(&srcDescriptor);
wgpu::Texture srcTexture = device.CreateTexture(&srcDescriptor);
dawn::TextureDescriptor depthStencilDescriptor =
wgpu::TextureDescriptor depthStencilDescriptor =
CreateTextureDescriptor(1, 1,
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc |
dawn::TextureUsage::CopyDst,
wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc |
wgpu::TextureUsage::CopyDst,
kDepthStencilFormat);
dawn::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor);
wgpu::Texture depthStencilTexture = device.CreateTexture(&depthStencilDescriptor);
// 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
// see that the subresource correctly gets set as unintialized in the second pass
utils::ComboRenderPassDescriptor renderPassDescriptor({srcTexture.CreateView()},
depthStencilTexture.CreateView());
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = dawn::LoadOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = wgpu::LoadOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.clearDepth = 1.0f;
renderPassDescriptor.cDepthStencilAttachmentInfo.clearStencil = 1u;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = dawn::StoreOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = dawn::StoreOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Clear;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Clear;
{
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor);
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor);
pass.SetPipeline(CreatePipelineForTest());
pass.Draw(6, 1, 0, 0);
pass.EndPass();
dawn::CommandBuffer commandBuffer = encoder.Finish();
wgpu::CommandBuffer commandBuffer = encoder.Finish();
// Expect 0 lazy clears, depth stencil texture will clear using loadop
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
// because storeOp clear sets the subresource as uninitialized
{
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = dawn::LoadOp::Load;
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor);
renderPassDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Load;
renderPassDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = wgpu::LoadOp::Load;
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor);
pass.SetPipeline(CreatePipelineForTest());
pass.Draw(6, 1, 0, 0);
pass.EndPass();
dawn::CommandBuffer commandBuffer = encoder.Finish();
wgpu::CommandBuffer commandBuffer = encoder.Finish();
// Expect 0 lazy clears, depth stencil texture will clear using loadop
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commandBuffer));

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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