Descriptorize Buffer
We still keep a dummy BufferBuilder object around so that it can be used for the builder error callback tests of the wire. Change-Id: If0c502bb8b62ee3ed61815e34e9b6ee6c03a65ef
This commit is contained in:
parent
0202250464
commit
82b6573d54
24
dawn.json
24
dawn.json
|
@ -212,18 +212,13 @@
|
|||
]
|
||||
},
|
||||
"buffer builder": {
|
||||
"_comment": "This builder is kept for testing only",
|
||||
"category": "object",
|
||||
"methods": [
|
||||
{
|
||||
"name": "get result",
|
||||
"returns": "buffer"
|
||||
},
|
||||
{
|
||||
"name": "set allowed usage",
|
||||
"args": [
|
||||
{"name": "usage", "type": "buffer usage bit"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "set size",
|
||||
"args": [
|
||||
|
@ -232,6 +227,14 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"buffer descriptor": {
|
||||
"category": "structure",
|
||||
"extensible": true,
|
||||
"members": [
|
||||
{"name": "usage", "type": "buffer usage bit"},
|
||||
{"name": "size", "type": "uint32_t"}
|
||||
]
|
||||
},
|
||||
"buffer map read callback": {
|
||||
"category": "natively defined"
|
||||
},
|
||||
|
@ -537,7 +540,14 @@
|
|||
"returns": "blend state builder"
|
||||
},
|
||||
{
|
||||
"name": "create buffer builder",
|
||||
"name": "create buffer",
|
||||
"returns": "buffer",
|
||||
"args": [
|
||||
{"name": "descriptor", "type": "buffer descriptor", "annotation": "const*"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "create buffer builder for testing",
|
||||
"returns": "buffer builder"
|
||||
},
|
||||
{
|
||||
|
|
|
@ -80,10 +80,10 @@ void initBuffers() {
|
|||
}
|
||||
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
particleBuffers[i] = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferDst | dawn::BufferUsageBit::Vertex | dawn::BufferUsageBit::Storage)
|
||||
.SetSize(sizeof(Particle) * kNumParticles)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = sizeof(Particle) * kNumParticles;
|
||||
descriptor.usage = dawn::BufferUsageBit::TransferDst | dawn::BufferUsageBit::Vertex | dawn::BufferUsageBit::Storage;
|
||||
particleBuffers[i] = device.CreateBuffer(&descriptor);
|
||||
|
||||
particleBuffers[i].SetSubData(0,
|
||||
sizeof(Particle) * kNumParticles,
|
||||
|
|
|
@ -169,10 +169,10 @@ void init() {
|
|||
|
||||
dawn::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl);
|
||||
|
||||
cameraBuffer = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferDst | dawn::BufferUsageBit::Uniform)
|
||||
.SetSize(sizeof(CameraData))
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor cameraBufDesc;
|
||||
cameraBufDesc.size = sizeof(CameraData);
|
||||
cameraBufDesc.usage = dawn::BufferUsageBit::TransferDst | dawn::BufferUsageBit::Uniform;
|
||||
cameraBuffer = device.CreateBuffer(&cameraBufDesc);
|
||||
|
||||
glm::mat4 transform(1.0);
|
||||
transformBuffer[0] = utils::CreateBufferFromData(device, &transform, sizeof(glm::mat4), dawn::BufferUsageBit::Uniform);
|
||||
|
|
|
@ -123,10 +123,10 @@ namespace {
|
|||
// Initialization
|
||||
namespace {
|
||||
void initBuffers() {
|
||||
defaultBuffer = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Vertex | dawn::BufferUsageBit::Index)
|
||||
.SetSize(256)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 256;
|
||||
descriptor.usage = dawn::BufferUsageBit::Vertex | dawn::BufferUsageBit::Index;
|
||||
defaultBuffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
for (const auto& bv : scene.bufferViews) {
|
||||
const auto& iBufferViewID = bv.first;
|
||||
|
|
|
@ -108,3 +108,6 @@ void ProcTableAsClass::CallMapWriteCallback(dawnBuffer buffer, dawnBufferMapAsyn
|
|||
return reinterpret_cast<{{as_cType(type.name)}}>(mObjects.back().get());
|
||||
}
|
||||
{% endfor %}
|
||||
|
||||
MockProcTable::MockProcTable() {
|
||||
}
|
||||
|
|
|
@ -90,6 +90,8 @@ class ProcTableAsClass {
|
|||
|
||||
class MockProcTable : public ProcTableAsClass {
|
||||
public:
|
||||
MockProcTable();
|
||||
|
||||
{% for type in by_category["object"] %}
|
||||
{% for method in type.methods if len(method.arguments) < 10 %}
|
||||
MOCK_METHOD{{len(method.arguments) + 1}}(
|
||||
|
|
|
@ -16,16 +16,38 @@
|
|||
|
||||
#include "common/Assert.h"
|
||||
#include "dawn_native/Device.h"
|
||||
#include "dawn_native/ValidationUtils_autogen.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <utility>
|
||||
|
||||
namespace dawn_native {
|
||||
|
||||
MaybeError ValidateBufferDescriptor(DeviceBase*, const BufferDescriptor* descriptor) {
|
||||
DAWN_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr");
|
||||
DAWN_TRY(ValidateBufferUsageBit(descriptor->usage));
|
||||
|
||||
dawn::BufferUsageBit usage = descriptor->usage;
|
||||
|
||||
const dawn::BufferUsageBit kMapWriteAllowedUsages =
|
||||
dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferSrc;
|
||||
if (usage & dawn::BufferUsageBit::MapWrite && (usage & kMapWriteAllowedUsages) != usage) {
|
||||
DAWN_RETURN_ERROR("Only TransferSrc is allowed with MapWrite");
|
||||
}
|
||||
|
||||
const dawn::BufferUsageBit kMapReadAllowedUsages =
|
||||
dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst;
|
||||
if (usage & dawn::BufferUsageBit::MapRead && (usage & kMapReadAllowedUsages) != usage) {
|
||||
DAWN_RETURN_ERROR("Only TransferDst is allowed with MapRead");
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// Buffer
|
||||
|
||||
BufferBase::BufferBase(BufferBuilder* builder)
|
||||
: mDevice(builder->mDevice), mSize(builder->mSize), mUsage(builder->mAllowedUsage) {
|
||||
BufferBase::BufferBase(DeviceBase* device, const BufferDescriptor* descriptor)
|
||||
: mDevice(device), mSize(descriptor->size), mUsage(descriptor->usage) {
|
||||
}
|
||||
|
||||
BufferBase::~BufferBase() {
|
||||
|
@ -181,62 +203,6 @@ namespace dawn_native {
|
|||
return {};
|
||||
}
|
||||
|
||||
// BufferBuilder
|
||||
|
||||
enum BufferSetProperties {
|
||||
BUFFER_PROPERTY_ALLOWED_USAGE = 0x1,
|
||||
BUFFER_PROPERTY_SIZE = 0x2,
|
||||
};
|
||||
|
||||
BufferBuilder::BufferBuilder(DeviceBase* device) : Builder(device) {
|
||||
}
|
||||
|
||||
BufferBase* BufferBuilder::GetResultImpl() {
|
||||
constexpr int allProperties = BUFFER_PROPERTY_ALLOWED_USAGE | BUFFER_PROPERTY_SIZE;
|
||||
if ((mPropertiesSet & allProperties) != allProperties) {
|
||||
HandleError("Buffer missing properties");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const dawn::BufferUsageBit kMapWriteAllowedUsages =
|
||||
dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferSrc;
|
||||
if (mAllowedUsage & dawn::BufferUsageBit::MapWrite &&
|
||||
(mAllowedUsage & kMapWriteAllowedUsages) != mAllowedUsage) {
|
||||
HandleError("Only TransferSrc is allowed with MapWrite");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const dawn::BufferUsageBit kMapReadAllowedUsages =
|
||||
dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst;
|
||||
if (mAllowedUsage & dawn::BufferUsageBit::MapRead &&
|
||||
(mAllowedUsage & kMapReadAllowedUsages) != mAllowedUsage) {
|
||||
HandleError("Only TransferDst is allowed with MapRead");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return mDevice->CreateBuffer(this);
|
||||
}
|
||||
|
||||
void BufferBuilder::SetAllowedUsage(dawn::BufferUsageBit usage) {
|
||||
if ((mPropertiesSet & BUFFER_PROPERTY_ALLOWED_USAGE) != 0) {
|
||||
HandleError("Buffer allowedUsage property set multiple times");
|
||||
return;
|
||||
}
|
||||
|
||||
mAllowedUsage = usage;
|
||||
mPropertiesSet |= BUFFER_PROPERTY_ALLOWED_USAGE;
|
||||
}
|
||||
|
||||
void BufferBuilder::SetSize(uint32_t size) {
|
||||
if ((mPropertiesSet & BUFFER_PROPERTY_SIZE) != 0) {
|
||||
HandleError("Buffer size property set multiple times");
|
||||
return;
|
||||
}
|
||||
|
||||
mSize = size;
|
||||
mPropertiesSet |= BUFFER_PROPERTY_SIZE;
|
||||
}
|
||||
|
||||
// BufferViewBase
|
||||
|
||||
BufferViewBase::BufferViewBase(BufferViewBuilder* builder)
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
namespace dawn_native {
|
||||
|
||||
MaybeError ValidateBufferDescriptor(DeviceBase* device, const BufferDescriptor* descriptor);
|
||||
|
||||
static constexpr dawn::BufferUsageBit kReadOnlyBufferUsages =
|
||||
dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferSrc |
|
||||
dawn::BufferUsageBit::Index | dawn::BufferUsageBit::Vertex | dawn::BufferUsageBit::Uniform;
|
||||
|
@ -34,7 +36,7 @@ namespace dawn_native {
|
|||
|
||||
class BufferBase : public RefCounted {
|
||||
public:
|
||||
BufferBase(BufferBuilder* builder);
|
||||
BufferBase(DeviceBase* device, const BufferDescriptor* descriptor);
|
||||
~BufferBase();
|
||||
|
||||
uint32_t GetSize() const;
|
||||
|
@ -85,24 +87,6 @@ namespace dawn_native {
|
|||
bool mIsMapped = false;
|
||||
};
|
||||
|
||||
class BufferBuilder : public Builder<BufferBase> {
|
||||
public:
|
||||
BufferBuilder(DeviceBase* device);
|
||||
|
||||
// Dawn API
|
||||
void SetAllowedUsage(dawn::BufferUsageBit usage);
|
||||
void SetSize(uint32_t size);
|
||||
|
||||
private:
|
||||
friend class BufferBase;
|
||||
|
||||
BufferBase* GetResultImpl() override;
|
||||
|
||||
uint32_t mSize;
|
||||
dawn::BufferUsageBit mAllowedUsage = dawn::BufferUsageBit::None;
|
||||
int mPropertiesSet = 0;
|
||||
};
|
||||
|
||||
class BufferViewBase : public RefCounted {
|
||||
public:
|
||||
BufferViewBase(BufferViewBuilder* builder);
|
||||
|
@ -135,6 +119,18 @@ namespace dawn_native {
|
|||
int mPropertiesSet = 0;
|
||||
};
|
||||
|
||||
// This builder class is kept around purely for testing but should not be used.
|
||||
class BufferBuilder : public Builder<BufferViewBase> {
|
||||
public:
|
||||
BufferBuilder(DeviceBase* device) : Builder(device) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
void SetSize(uint32_t) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dawn_native
|
||||
|
||||
#endif // DAWNNATIVE_BUFFER_H_
|
||||
|
|
|
@ -111,8 +111,14 @@ namespace dawn_native {
|
|||
BlendStateBuilder* DeviceBase::CreateBlendStateBuilder() {
|
||||
return new BlendStateBuilder(this);
|
||||
}
|
||||
BufferBuilder* DeviceBase::CreateBufferBuilder() {
|
||||
return new BufferBuilder(this);
|
||||
BufferBase* DeviceBase::CreateBuffer(const BufferDescriptor* descriptor) {
|
||||
BufferBase* result = nullptr;
|
||||
|
||||
if (ConsumedError(CreateBufferInternal(&result, descriptor))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
CommandBufferBuilder* DeviceBase::CreateCommandBufferBuilder() {
|
||||
return new CommandBufferBuilder(this);
|
||||
|
@ -205,6 +211,13 @@ namespace dawn_native {
|
|||
return {};
|
||||
}
|
||||
|
||||
MaybeError DeviceBase::CreateBufferInternal(BufferBase** result,
|
||||
const BufferDescriptor* descriptor) {
|
||||
DAWN_TRY(ValidateBufferDescriptor(this, descriptor));
|
||||
DAWN_TRY_ASSIGN(*result, CreateBufferImpl(descriptor));
|
||||
return {};
|
||||
}
|
||||
|
||||
MaybeError DeviceBase::CreatePipelineLayoutInternal(
|
||||
PipelineLayoutBase** result,
|
||||
const PipelineLayoutDescriptor* descriptor) {
|
||||
|
|
|
@ -45,7 +45,6 @@ namespace dawn_native {
|
|||
|
||||
virtual BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) = 0;
|
||||
virtual BlendStateBase* CreateBlendState(BlendStateBuilder* builder) = 0;
|
||||
virtual BufferBase* CreateBuffer(BufferBuilder* builder) = 0;
|
||||
virtual BufferViewBase* CreateBufferView(BufferViewBuilder* builder) = 0;
|
||||
virtual CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) = 0;
|
||||
virtual ComputePipelineBase* CreateComputePipeline(ComputePipelineBuilder* builder) = 0;
|
||||
|
@ -83,7 +82,7 @@ namespace dawn_native {
|
|||
BindGroupBuilder* CreateBindGroupBuilder();
|
||||
BindGroupLayoutBase* CreateBindGroupLayout(const BindGroupLayoutDescriptor* descriptor);
|
||||
BlendStateBuilder* CreateBlendStateBuilder();
|
||||
BufferBuilder* CreateBufferBuilder();
|
||||
BufferBase* CreateBuffer(const BufferDescriptor* descriptor);
|
||||
CommandBufferBuilder* CreateCommandBufferBuilder();
|
||||
ComputePipelineBuilder* CreateComputePipelineBuilder();
|
||||
DepthStencilStateBuilder* CreateDepthStencilStateBuilder();
|
||||
|
@ -102,9 +101,14 @@ namespace dawn_native {
|
|||
void Reference();
|
||||
void Release();
|
||||
|
||||
BufferBuilder* CreateBufferBuilderForTesting() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
|
||||
const BindGroupLayoutDescriptor* descriptor) = 0;
|
||||
virtual ResultOrError<BufferBase*> CreateBufferImpl(const BufferDescriptor* descriptor) = 0;
|
||||
virtual ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
|
||||
const PipelineLayoutDescriptor* descriptor) = 0;
|
||||
virtual ResultOrError<QueueBase*> CreateQueueImpl() = 0;
|
||||
|
@ -115,6 +119,7 @@ namespace dawn_native {
|
|||
|
||||
MaybeError CreateBindGroupLayoutInternal(BindGroupLayoutBase** result,
|
||||
const BindGroupLayoutDescriptor* descriptor);
|
||||
MaybeError CreateBufferInternal(BufferBase** result, const BufferDescriptor* descriptor);
|
||||
MaybeError CreatePipelineLayoutInternal(PipelineLayoutBase** result,
|
||||
const PipelineLayoutDescriptor* descriptor);
|
||||
MaybeError CreateQueueInternal(QueueBase** result);
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
|
||||
namespace dawn_native {
|
||||
|
||||
MaybeError ValidateShaderModuleDescriptor(DeviceBase*, const ShaderModuleDescriptor* descriptor) {
|
||||
MaybeError ValidateShaderModuleDescriptor(DeviceBase*,
|
||||
const ShaderModuleDescriptor* descriptor) {
|
||||
DAWN_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr");
|
||||
// TODO(cwallez@chromium.org): Use spirv-val to check the module is well-formed
|
||||
return {};
|
||||
|
|
|
@ -67,7 +67,8 @@ namespace dawn_native { namespace d3d12 {
|
|||
}
|
||||
} // namespace
|
||||
|
||||
Buffer::Buffer(BufferBuilder* builder) : BufferBase(builder) {
|
||||
Buffer::Buffer(Device* device, const BufferDescriptor* descriptor)
|
||||
: BufferBase(device, descriptor) {
|
||||
D3D12_RESOURCE_DESC resourceDescriptor;
|
||||
resourceDescriptor.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||
resourceDescriptor.Alignment = 0;
|
||||
|
@ -100,9 +101,8 @@ namespace dawn_native { namespace d3d12 {
|
|||
mLastUsage = dawn::BufferUsageBit::TransferSrc;
|
||||
}
|
||||
|
||||
mResource = ToBackend(GetDevice())
|
||||
->GetResourceAllocator()
|
||||
->Allocate(heapType, resourceDescriptor, bufferUsage);
|
||||
mResource =
|
||||
device->GetResourceAllocator()->Allocate(heapType, resourceDescriptor, bufferUsage);
|
||||
}
|
||||
|
||||
Buffer::~Buffer() {
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace dawn_native { namespace d3d12 {
|
|||
|
||||
class Buffer : public BufferBase {
|
||||
public:
|
||||
Buffer(BufferBuilder* builder);
|
||||
Buffer(Device* device, const BufferDescriptor* descriptor);
|
||||
~Buffer();
|
||||
|
||||
uint32_t GetD3D12Size() const;
|
||||
|
|
|
@ -269,8 +269,8 @@ namespace dawn_native { namespace d3d12 {
|
|||
BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) {
|
||||
return new BlendState(builder);
|
||||
}
|
||||
BufferBase* Device::CreateBuffer(BufferBuilder* builder) {
|
||||
return new Buffer(builder);
|
||||
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
return new Buffer(this, descriptor);
|
||||
}
|
||||
BufferViewBase* Device::CreateBufferView(BufferViewBuilder* builder) {
|
||||
return new BufferView(builder);
|
||||
|
|
|
@ -40,7 +40,6 @@ namespace dawn_native { namespace d3d12 {
|
|||
|
||||
BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) override;
|
||||
BlendStateBase* CreateBlendState(BlendStateBuilder* builder) override;
|
||||
BufferBase* CreateBuffer(BufferBuilder* builder) override;
|
||||
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
|
||||
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
|
||||
ComputePipelineBase* CreateComputePipeline(ComputePipelineBuilder* builder) override;
|
||||
|
@ -78,6 +77,7 @@ namespace dawn_native { namespace d3d12 {
|
|||
private:
|
||||
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
|
||||
const BindGroupLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<BufferBase*> CreateBufferImpl(const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
|
||||
const PipelineLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<QueueBase*> CreateQueueImpl() override;
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace dawn_native { namespace metal {
|
|||
|
||||
class Buffer : public BufferBase {
|
||||
public:
|
||||
Buffer(BufferBuilder* builder);
|
||||
Buffer(Device* device, const BufferDescriptor* descriptor);
|
||||
~Buffer();
|
||||
|
||||
id<MTLBuffer> GetMTLBuffer();
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
namespace dawn_native { namespace metal {
|
||||
|
||||
Buffer::Buffer(BufferBuilder* builder) : BufferBase(builder) {
|
||||
Buffer::Buffer(Device* device, const BufferDescriptor* descriptor)
|
||||
: BufferBase(device, descriptor) {
|
||||
MTLResourceOptions storageMode;
|
||||
if (GetUsage() & (dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::MapWrite)) {
|
||||
storageMode = MTLResourceStorageModeShared;
|
||||
|
@ -27,8 +28,7 @@ namespace dawn_native { namespace metal {
|
|||
storageMode = MTLResourceStorageModePrivate;
|
||||
}
|
||||
|
||||
mMtlBuffer = [ToBackend(GetDevice())->GetMTLDevice() newBufferWithLength:GetSize()
|
||||
options:storageMode];
|
||||
mMtlBuffer = [device->GetMTLDevice() newBufferWithLength:GetSize() options:storageMode];
|
||||
}
|
||||
|
||||
Buffer::~Buffer() {
|
||||
|
|
|
@ -37,7 +37,6 @@ namespace dawn_native { namespace metal {
|
|||
|
||||
BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) override;
|
||||
BlendStateBase* CreateBlendState(BlendStateBuilder* builder) override;
|
||||
BufferBase* CreateBuffer(BufferBuilder* builder) override;
|
||||
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
|
||||
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
|
||||
ComputePipelineBase* CreateComputePipeline(ComputePipelineBuilder* builder) override;
|
||||
|
@ -64,6 +63,7 @@ namespace dawn_native { namespace metal {
|
|||
private:
|
||||
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
|
||||
const BindGroupLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<BufferBase*> CreateBufferImpl(const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
|
||||
const PipelineLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<QueueBase*> CreateQueueImpl() override;
|
||||
|
|
|
@ -88,8 +88,8 @@ namespace dawn_native { namespace metal {
|
|||
BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) {
|
||||
return new BlendState(builder);
|
||||
}
|
||||
BufferBase* Device::CreateBuffer(BufferBuilder* builder) {
|
||||
return new Buffer(builder);
|
||||
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
return new Buffer(this, descriptor);
|
||||
}
|
||||
BufferViewBase* Device::CreateBufferView(BufferViewBuilder* builder) {
|
||||
return new BufferView(builder);
|
||||
|
|
|
@ -43,8 +43,8 @@ namespace dawn_native { namespace null {
|
|||
BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) {
|
||||
return new BlendState(builder);
|
||||
}
|
||||
BufferBase* Device::CreateBuffer(BufferBuilder* builder) {
|
||||
return new Buffer(builder);
|
||||
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
return new Buffer(this, descriptor);
|
||||
}
|
||||
BufferViewBase* Device::CreateBufferView(BufferViewBuilder* builder) {
|
||||
return new BufferView(builder);
|
||||
|
@ -120,7 +120,8 @@ namespace dawn_native { namespace null {
|
|||
bool isWrite;
|
||||
};
|
||||
|
||||
Buffer::Buffer(BufferBuilder* builder) : BufferBase(builder) {
|
||||
Buffer::Buffer(Device* device, const BufferDescriptor* descriptor)
|
||||
: BufferBase(device, descriptor) {
|
||||
if (GetUsage() & (dawn::BufferUsageBit::TransferDst | dawn::BufferUsageBit::MapRead |
|
||||
dawn::BufferUsageBit::MapWrite)) {
|
||||
mBackingData = std::unique_ptr<char[]>(new char[GetSize()]);
|
||||
|
|
|
@ -97,7 +97,6 @@ namespace dawn_native { namespace null {
|
|||
|
||||
BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) override;
|
||||
BlendStateBase* CreateBlendState(BlendStateBuilder* builder) override;
|
||||
BufferBase* CreateBuffer(BufferBuilder* builder) override;
|
||||
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
|
||||
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
|
||||
ComputePipelineBase* CreateComputePipeline(ComputePipelineBuilder* builder) override;
|
||||
|
@ -118,6 +117,7 @@ namespace dawn_native { namespace null {
|
|||
private:
|
||||
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
|
||||
const BindGroupLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<BufferBase*> CreateBufferImpl(const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
|
||||
const PipelineLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<QueueBase*> CreateQueueImpl() override;
|
||||
|
@ -130,7 +130,7 @@ namespace dawn_native { namespace null {
|
|||
|
||||
class Buffer : public BufferBase {
|
||||
public:
|
||||
Buffer(BufferBuilder* builder);
|
||||
Buffer(Device* device, const BufferDescriptor* descriptor);
|
||||
~Buffer();
|
||||
|
||||
void MapReadOperationCompleted(uint32_t serial, void* ptr, bool isWrite);
|
||||
|
|
|
@ -14,11 +14,14 @@
|
|||
|
||||
#include "dawn_native/opengl/BufferGL.h"
|
||||
|
||||
#include "dawn_native/opengl/DeviceGL.h"
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
|
||||
// Buffer
|
||||
|
||||
Buffer::Buffer(BufferBuilder* builder) : BufferBase(builder) {
|
||||
Buffer::Buffer(Device* device, const BufferDescriptor* descriptor)
|
||||
: BufferBase(device, descriptor) {
|
||||
glGenBuffers(1, &mBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, GetSize(), nullptr, GL_STATIC_DRAW);
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace dawn_native { namespace opengl {
|
|||
|
||||
class Buffer : public BufferBase {
|
||||
public:
|
||||
Buffer(BufferBuilder* builder);
|
||||
Buffer(Device* device, const BufferDescriptor* descriptor);
|
||||
|
||||
GLuint GetHandle() const;
|
||||
|
||||
|
|
|
@ -56,8 +56,8 @@ namespace dawn_native { namespace opengl {
|
|||
BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) {
|
||||
return new BlendState(builder);
|
||||
}
|
||||
BufferBase* Device::CreateBuffer(BufferBuilder* builder) {
|
||||
return new Buffer(builder);
|
||||
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
return new Buffer(this, descriptor);
|
||||
}
|
||||
BufferViewBase* Device::CreateBufferView(BufferViewBuilder* builder) {
|
||||
return new BufferView(builder);
|
||||
|
|
|
@ -34,7 +34,6 @@ namespace dawn_native { namespace opengl {
|
|||
public:
|
||||
BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) override;
|
||||
BlendStateBase* CreateBlendState(BlendStateBuilder* builder) override;
|
||||
BufferBase* CreateBuffer(BufferBuilder* builder) override;
|
||||
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
|
||||
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
|
||||
ComputePipelineBase* CreateComputePipeline(ComputePipelineBuilder* builder) override;
|
||||
|
@ -52,6 +51,7 @@ namespace dawn_native { namespace opengl {
|
|||
private:
|
||||
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
|
||||
const BindGroupLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<BufferBase*> CreateBufferImpl(const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
|
||||
const PipelineLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<QueueBase*> CreateQueueImpl() override;
|
||||
|
|
|
@ -103,9 +103,8 @@ namespace dawn_native { namespace vulkan {
|
|||
|
||||
} // namespace
|
||||
|
||||
Buffer::Buffer(BufferBuilder* builder) : BufferBase(builder) {
|
||||
Device* device = ToBackend(GetDevice());
|
||||
|
||||
Buffer::Buffer(Device* device, const BufferDescriptor* descriptor)
|
||||
: BufferBase(device, descriptor) {
|
||||
VkBufferCreateInfo createInfo;
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||
createInfo.pNext = nullptr;
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace dawn_native { namespace vulkan {
|
|||
|
||||
class Buffer : public BufferBase {
|
||||
public:
|
||||
Buffer(BufferBuilder* builder);
|
||||
Buffer(Device* device, const BufferDescriptor* descriptor);
|
||||
~Buffer();
|
||||
|
||||
void OnMapReadCommandSerialFinished(uint32_t mapSerial, const void* data);
|
||||
|
|
|
@ -227,8 +227,8 @@ namespace dawn_native { namespace vulkan {
|
|||
BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) {
|
||||
return new BlendState(builder);
|
||||
}
|
||||
BufferBase* Device::CreateBuffer(BufferBuilder* builder) {
|
||||
return new Buffer(builder);
|
||||
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
return new Buffer(this, descriptor);
|
||||
}
|
||||
BufferViewBase* Device::CreateBufferView(BufferViewBuilder* builder) {
|
||||
return new BufferView(builder);
|
||||
|
|
|
@ -65,7 +65,6 @@ namespace dawn_native { namespace vulkan {
|
|||
// Dawn API
|
||||
BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) override;
|
||||
BlendStateBase* CreateBlendState(BlendStateBuilder* builder) override;
|
||||
BufferBase* CreateBuffer(BufferBuilder* builder) override;
|
||||
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
|
||||
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
|
||||
ComputePipelineBase* CreateComputePipeline(ComputePipelineBuilder* builder) override;
|
||||
|
@ -83,6 +82,7 @@ namespace dawn_native { namespace vulkan {
|
|||
private:
|
||||
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
|
||||
const BindGroupLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<BufferBase*> CreateBufferImpl(const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
|
||||
const PipelineLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<QueueBase*> CreateQueueImpl() override;
|
||||
|
|
|
@ -303,13 +303,13 @@ void DawnTest::FlushWire() {
|
|||
DawnTest::ReadbackReservation DawnTest::ReserveReadback(uint32_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;
|
||||
descriptor.size = readbackSize;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst;
|
||||
|
||||
ReadbackSlot slot;
|
||||
slot.bufferSize = readbackSize;
|
||||
slot.buffer =
|
||||
device.CreateBufferBuilder()
|
||||
.SetSize(readbackSize)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
slot.buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
ReadbackReservation reservation;
|
||||
reservation.buffer = slot.buffer.Clone();
|
||||
|
|
|
@ -22,10 +22,10 @@ class BasicTests : public DawnTest {
|
|||
// 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::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(4)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4;
|
||||
descriptor.usage = dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
uint8_t value = 187;
|
||||
buffer.SetSubData(0, sizeof(value), &value);
|
||||
|
|
|
@ -43,10 +43,10 @@ class BufferMapReadTests : public DawnTest {
|
|||
|
||||
// Test that the simplest map read (one u8 at offset 0) works.
|
||||
TEST_P(BufferMapReadTests, SmallReadAtZero) {
|
||||
dawn::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(1)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 1;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
uint8_t myData = 187;
|
||||
buffer.SetSubData(0, sizeof(myData), &myData);
|
||||
|
@ -59,10 +59,10 @@ TEST_P(BufferMapReadTests, SmallReadAtZero) {
|
|||
|
||||
// Test mapping a buffer at an offset.
|
||||
TEST_P(BufferMapReadTests, SmallReadAtOffset) {
|
||||
dawn::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(4000)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4000;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
uint8_t myData = 234;
|
||||
buffer.SetSubData(2048, sizeof(myData), &myData);
|
||||
|
@ -75,10 +75,10 @@ TEST_P(BufferMapReadTests, SmallReadAtOffset) {
|
|||
|
||||
// Test mapping a buffer at an offset that's not uint32-aligned.
|
||||
TEST_P(BufferMapReadTests, SmallReadAtUnalignedOffset) {
|
||||
dawn::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(4000)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4000;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
uint8_t myData = 213;
|
||||
buffer.SetSubData(3, 1, &myData);
|
||||
|
@ -97,10 +97,10 @@ TEST_P(BufferMapReadTests, LargeRead) {
|
|||
myData.push_back(i);
|
||||
}
|
||||
|
||||
dawn::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(static_cast<uint32_t>(kDataSize * sizeof(uint32_t)))
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = static_cast<uint32_t>(kDataSize * sizeof(uint32_t));
|
||||
descriptor.usage = dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
buffer.SetSubData(0, kDataSize * sizeof(uint32_t), reinterpret_cast<uint8_t*>(myData.data()));
|
||||
|
||||
|
@ -139,10 +139,10 @@ class BufferMapWriteTests : public DawnTest {
|
|||
|
||||
// Test that the simplest map write (one u32 at offset 0) works.
|
||||
TEST_P(BufferMapWriteTests, SmallWriteAtZero) {
|
||||
dawn::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(4)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferSrc)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferSrc;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
uint32_t myData = 2934875;
|
||||
void* mappedData = MapWriteAsyncAndWait(buffer, 0, 4);
|
||||
|
@ -154,10 +154,10 @@ TEST_P(BufferMapWriteTests, SmallWriteAtZero) {
|
|||
|
||||
// Test mapping a buffer at an offset.
|
||||
TEST_P(BufferMapWriteTests, SmallWriteAtOffset) {
|
||||
dawn::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(4000)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferSrc)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4000;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferSrc;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
uint32_t myData = 2934875;
|
||||
void* mappedData = MapWriteAsyncAndWait(buffer, 2048, 4);
|
||||
|
@ -175,10 +175,10 @@ TEST_P(BufferMapWriteTests, LargeWrite) {
|
|||
myData.push_back(i);
|
||||
}
|
||||
|
||||
dawn::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(static_cast<uint32_t>(kDataSize * sizeof(uint32_t)))
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferSrc)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = static_cast<uint32_t>(kDataSize * sizeof(uint32_t));
|
||||
descriptor.usage = dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferSrc;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
void* mappedData = MapWriteAsyncAndWait(buffer, 0, kDataSize * sizeof(uint32_t));
|
||||
memcpy(mappedData, myData.data(), kDataSize * sizeof(uint32_t));
|
||||
|
@ -194,10 +194,10 @@ class BufferSetSubDataTests : public DawnTest {
|
|||
|
||||
// Test the simplest set sub data: setting one u8 at offset 0.
|
||||
TEST_P(BufferSetSubDataTests, SmallDataAtZero) {
|
||||
dawn::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(1)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 1;
|
||||
descriptor.usage = dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
uint8_t value = 171;
|
||||
buffer.SetSubData(0, sizeof(value), &value);
|
||||
|
@ -207,10 +207,10 @@ TEST_P(BufferSetSubDataTests, SmallDataAtZero) {
|
|||
|
||||
// Test that SetSubData offset works.
|
||||
TEST_P(BufferSetSubDataTests, SmallDataAtOffset) {
|
||||
dawn::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(4000)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4000;
|
||||
descriptor.usage = dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
constexpr uint32_t kOffset = 2000;
|
||||
uint8_t value = 231;
|
||||
|
@ -230,10 +230,10 @@ TEST_P(BufferSetSubDataTests, ManySetSubData) {
|
|||
|
||||
constexpr uint32_t kSize = 4000 * 1000;
|
||||
constexpr uint32_t kElements = 1000 * 1000;
|
||||
dawn::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(kSize)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = kSize;
|
||||
descriptor.usage = dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
std::vector<uint32_t> expectedData;
|
||||
for (uint32_t i = 0; i < kElements; ++i) {
|
||||
|
@ -248,10 +248,10 @@ TEST_P(BufferSetSubDataTests, ManySetSubData) {
|
|||
TEST_P(BufferSetSubDataTests, LargeSetSubData) {
|
||||
constexpr uint32_t kSize = 4000 * 1000;
|
||||
constexpr uint32_t kElements = 1000 * 1000;
|
||||
dawn::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(kSize)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = kSize;
|
||||
descriptor.usage = dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
std::vector<uint32_t> expectedData;
|
||||
for (uint32_t i = 0; i < kElements; ++i) {
|
||||
|
|
|
@ -43,12 +43,12 @@ void ComputeCopyStorageBufferTests::BasicTest(const char* shader) {
|
|||
.GetResult();
|
||||
|
||||
// Set up src storage buffer
|
||||
auto src =
|
||||
device.CreateBufferBuilder()
|
||||
.SetSize(kNumUints * sizeof(uint32_t))
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Storage | dawn::BufferUsageBit::TransferSrc |
|
||||
dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor srcDesc;
|
||||
srcDesc.size = kNumUints * sizeof(uint32_t);
|
||||
srcDesc.usage = dawn::BufferUsageBit::Storage | dawn::BufferUsageBit::TransferSrc |
|
||||
dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer src = device.CreateBuffer(&srcDesc);
|
||||
|
||||
std::array<uint32_t, kNumUints> expected;
|
||||
for (uint32_t i = 0; i < kNumUints; ++i) {
|
||||
expected[i] = (i + 1u) * 0x11111111u;
|
||||
|
@ -59,12 +59,12 @@ void ComputeCopyStorageBufferTests::BasicTest(const char* shader) {
|
|||
src.CreateBufferViewBuilder().SetExtent(0, kNumUints * sizeof(uint32_t)).GetResult();
|
||||
|
||||
// Set up dst storage buffer
|
||||
auto dst =
|
||||
device.CreateBufferBuilder()
|
||||
.SetSize(kNumUints * sizeof(uint32_t))
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Storage | dawn::BufferUsageBit::TransferSrc |
|
||||
dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor dstDesc;
|
||||
dstDesc.size = kNumUints * sizeof(uint32_t);
|
||||
dstDesc.usage = dawn::BufferUsageBit::Storage | dawn::BufferUsageBit::TransferSrc |
|
||||
dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer dst = device.CreateBuffer(&dstDesc);
|
||||
|
||||
std::array<uint32_t, kNumUints> zero{};
|
||||
dst.SetSubData(0, sizeof(zero), reinterpret_cast<const uint8_t*>(zero.data()));
|
||||
auto dstView =
|
||||
|
|
|
@ -100,10 +100,11 @@ class CopyTests_T2B : public CopyTests {
|
|||
// Create a buffer of size `size` 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::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(bufferSpec.size)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor bufDescriptor;
|
||||
bufDescriptor.size = bufferSpec.size;
|
||||
bufDescriptor.usage = dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&bufDescriptor);
|
||||
|
||||
std::vector<RGBA8> emptyData(bufferSpec.size / kBytesPerTexel);
|
||||
buffer.SetSubData(0, static_cast<uint32_t>(emptyData.size() * sizeof(RGBA8)), reinterpret_cast<const uint8_t*>(emptyData.data()));
|
||||
|
||||
|
@ -147,10 +148,11 @@ protected:
|
|||
|
||||
void DoTest(const TextureSpec& textureSpec, const BufferSpec& bufferSpec) {
|
||||
// Create a buffer of size `size` and populate it with data
|
||||
dawn::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetSize(bufferSpec.size)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor bufDescriptor;
|
||||
bufDescriptor.size = bufferSpec.size;
|
||||
bufDescriptor.usage = dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&bufDescriptor);
|
||||
|
||||
std::vector<RGBA8> bufferData(bufferSpec.size / kBytesPerTexel);
|
||||
FillBufferData(bufferData.data(), bufferData.size());
|
||||
buffer.SetSubData(0, static_cast<uint32_t>(bufferData.size() * sizeof(RGBA8)), reinterpret_cast<const uint8_t*>(bufferData.data()));
|
||||
|
|
|
@ -30,17 +30,14 @@ class PushConstantTest: public DawnTest {
|
|||
dawn::Buffer resultBuffer;
|
||||
};
|
||||
TestBindings MakeTestBindings(bool extraBuffer) {
|
||||
dawn::Buffer buf1 = device.CreateBufferBuilder()
|
||||
.SetSize(4)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Storage | dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
uint32_t one = 1;
|
||||
buf1.SetSubData(0, sizeof(one), reinterpret_cast<uint8_t*>(&one));
|
||||
|
||||
dawn::Buffer buf2 = device.CreateBufferBuilder()
|
||||
.SetSize(4)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Storage)
|
||||
.GetResult();
|
||||
dawn::Buffer buf1 = utils::CreateBufferFromData(device, &one, 4, dawn::BufferUsageBit::Storage |
|
||||
dawn::BufferUsageBit::TransferSrc |
|
||||
dawn::BufferUsageBit::TransferDst);
|
||||
dawn::BufferDescriptor buf2Desc;
|
||||
buf2Desc.size = 4;
|
||||
buf2Desc.usage = dawn::BufferUsageBit::Storage;
|
||||
dawn::Buffer buf2 = device.CreateBuffer(&buf2Desc);
|
||||
|
||||
dawn::ShaderStageBit kAllStages = dawn::ShaderStageBit::Compute | dawn::ShaderStageBit::Fragment | dawn::ShaderStageBit::Vertex;
|
||||
constexpr dawn::ShaderStageBit kNoStages{};
|
||||
|
|
|
@ -476,7 +476,7 @@ TEST_F(WireTests, CallsSkippedAfterBuilderError) {
|
|||
dawnCommandBufferBuilder cmdBufBuilder = dawnDeviceCreateCommandBufferBuilder(device);
|
||||
dawnCommandBufferBuilderSetErrorCallback(cmdBufBuilder, ToMockBuilderErrorCallback, 1, 2);
|
||||
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilder(device);
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 3, 4);
|
||||
dawnBuffer buffer = dawnBufferBuilderGetResult(bufferBuilder); // Hey look an error!
|
||||
|
||||
|
@ -490,7 +490,7 @@ TEST_F(WireTests, CallsSkippedAfterBuilderError) {
|
|||
.WillOnce(Return(apiCmdBufBuilder));
|
||||
|
||||
dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilder(apiDevice))
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
|
||||
.WillOnce(Return(apiBufferBuilder));
|
||||
|
||||
// Hey look an error!
|
||||
|
@ -514,12 +514,12 @@ TEST_F(WireTests, CallsSkippedAfterBuilderError) {
|
|||
|
||||
// Test that we get a success builder error status when no error happens
|
||||
TEST_F(WireTests, SuccessCallbackOnBuilderSuccess) {
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilder(device);
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 1, 2);
|
||||
dawnBufferBuilderGetResult(bufferBuilder);
|
||||
|
||||
dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilder(apiDevice))
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
|
||||
.WillOnce(Return(apiBufferBuilder));
|
||||
|
||||
dawnBuffer apiBuffer = api.GetNewBuffer();
|
||||
|
@ -541,7 +541,7 @@ TEST_F(WireTests, SuccessCallbackOnBuilderSuccess) {
|
|||
TEST_F(WireTests, UnknownBuilderErrorStatusCallback) {
|
||||
// The builder is destroyed before the object is built
|
||||
{
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilder(device);
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 1, 2);
|
||||
|
||||
EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_UNKNOWN, _ , 1 ,2)).Times(1);
|
||||
|
@ -551,7 +551,7 @@ TEST_F(WireTests, UnknownBuilderErrorStatusCallback) {
|
|||
|
||||
// If the builder has been consumed, it doesn't fire the callback with unknown
|
||||
{
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilder(device);
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 3, 4);
|
||||
dawnBufferBuilderGetResult(bufferBuilder);
|
||||
|
||||
|
@ -563,7 +563,7 @@ TEST_F(WireTests, UnknownBuilderErrorStatusCallback) {
|
|||
// If the builder has been consumed, and the object is destroyed before the result comes from the server,
|
||||
// then the callback is fired with unknown
|
||||
{
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilder(device);
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 5, 6);
|
||||
dawnBuffer buffer = dawnBufferBuilderGetResult(bufferBuilder);
|
||||
|
||||
|
@ -577,11 +577,11 @@ TEST_F(WireTests, UnknownBuilderErrorStatusCallback) {
|
|||
TEST_F(WireTests, SuccessCallbackNotForwardedToDevice) {
|
||||
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, 0);
|
||||
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilder(device);
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
dawnBufferBuilderGetResult(bufferBuilder);
|
||||
|
||||
dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilder(apiDevice))
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
|
||||
.WillOnce(Return(apiBufferBuilder));
|
||||
|
||||
dawnBuffer apiBuffer = api.GetNewBuffer();
|
||||
|
@ -600,11 +600,11 @@ TEST_F(WireTests, ErrorCallbackForwardedToDevice) {
|
|||
uint64_t userdata = 30495;
|
||||
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
|
||||
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilder(device);
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
dawnBufferBuilderGetResult(bufferBuilder);
|
||||
|
||||
dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilder(apiDevice))
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
|
||||
.WillOnce(Return(apiBufferBuilder));
|
||||
|
||||
EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
|
||||
|
@ -649,10 +649,10 @@ TEST_F(WireSetCallbackTests, BuilderErrorCallback) {
|
|||
uint64_t userdata2 = 982734239028;
|
||||
|
||||
// Create the buffer builder, the callback is set immediately on the server side
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilder(device);
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
|
||||
|
||||
dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilder(apiDevice))
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
|
||||
.WillOnce(Return(apiBufferBuilder));
|
||||
|
||||
EXPECT_CALL(api, OnBuilderSetErrorCallback(apiBufferBuilder, _, _, _))
|
||||
|
@ -692,28 +692,24 @@ class WireBufferMappingTests : public WireTestsBase {
|
|||
WireTestsBase::SetUp();
|
||||
|
||||
{
|
||||
dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilder(device);
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilder(apiDevice))
|
||||
.WillOnce(Return(apiBufferBuilder))
|
||||
.RetiresOnSaturation();
|
||||
dawnBufferDescriptor descriptor;
|
||||
descriptor.nextInChain = nullptr;
|
||||
|
||||
apiBuffer = api.GetNewBuffer();
|
||||
buffer = dawnBufferBuilderGetResult(bufferBuilder);
|
||||
EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
|
||||
buffer = dawnDeviceCreateBuffer(device, &descriptor);
|
||||
|
||||
EXPECT_CALL(api, DeviceCreateBuffer(apiDevice, _))
|
||||
.WillOnce(Return(apiBuffer))
|
||||
.RetiresOnSaturation();
|
||||
FlushClient();
|
||||
}
|
||||
{
|
||||
dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
|
||||
dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilder(device);
|
||||
EXPECT_CALL(api, DeviceCreateBufferBuilder(apiDevice))
|
||||
.WillOnce(Return(apiBufferBuilder))
|
||||
.RetiresOnSaturation();
|
||||
dawnBufferDescriptor descriptor;
|
||||
descriptor.nextInChain = nullptr;
|
||||
|
||||
errorBuffer = dawnBufferBuilderGetResult(bufferBuilder);
|
||||
EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
|
||||
errorBuffer = dawnDeviceCreateBuffer(device, &descriptor);
|
||||
|
||||
EXPECT_CALL(api, DeviceCreateBuffer(apiDevice, _))
|
||||
.WillOnce(Return(nullptr))
|
||||
.RetiresOnSaturation();
|
||||
FlushClient();
|
||||
|
|
|
@ -24,10 +24,13 @@ TEST_F(BindGroupValidationTest, BufferViewOffset) {
|
|||
{0, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer},
|
||||
});
|
||||
|
||||
auto buffer = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Uniform)
|
||||
.SetSize(512)
|
||||
.GetResult();
|
||||
dawn::Buffer buffer;
|
||||
{
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 512;
|
||||
descriptor.usage = dawn::BufferUsageBit::Uniform;
|
||||
buffer = device.CreateBuffer(&descriptor);
|
||||
}
|
||||
|
||||
// Check that offset 0 is valid
|
||||
{
|
||||
|
|
|
@ -43,22 +43,25 @@ static void ToMockBufferMapWriteCallback(dawnBufferMapAsyncStatus status, void*
|
|||
class BufferValidationTest : public ValidationTest {
|
||||
protected:
|
||||
dawn::Buffer CreateMapReadBuffer(uint32_t size) {
|
||||
return device.CreateBufferBuilder()
|
||||
.SetSize(size)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapRead)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = size;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapRead;
|
||||
|
||||
return device.CreateBuffer(&descriptor);
|
||||
}
|
||||
dawn::Buffer CreateMapWriteBuffer(uint32_t size) {
|
||||
return device.CreateBufferBuilder()
|
||||
.SetSize(size)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapWrite)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = size;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapWrite;
|
||||
|
||||
return device.CreateBuffer(&descriptor);
|
||||
}
|
||||
dawn::Buffer CreateSetSubDataBuffer(uint32_t size) {
|
||||
return device.CreateBufferBuilder()
|
||||
.SetSize(size)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = size;
|
||||
descriptor.usage = dawn::BufferUsageBit::TransferDst;
|
||||
|
||||
return device.CreateBuffer(&descriptor);
|
||||
}
|
||||
|
||||
dawn::Queue queue;
|
||||
|
@ -84,48 +87,11 @@ class BufferValidationTest : public ValidationTest {
|
|||
TEST_F(BufferValidationTest, CreationSuccess) {
|
||||
// Success
|
||||
{
|
||||
dawn::Buffer buf = AssertWillBeSuccess(device.CreateBufferBuilder())
|
||||
.SetSize(4)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Uniform)
|
||||
.GetResult();
|
||||
}
|
||||
}
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4;
|
||||
descriptor.usage = dawn::BufferUsageBit::Uniform;
|
||||
|
||||
// Test failure when specifying properties multiple times
|
||||
TEST_F(BufferValidationTest, CreationDuplicates) {
|
||||
// When size is specified multiple times
|
||||
{
|
||||
dawn::Buffer buf = AssertWillBeError(device.CreateBufferBuilder())
|
||||
.SetSize(4)
|
||||
.SetSize(3)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Uniform)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// When allowed usage is specified multiple times
|
||||
{
|
||||
dawn::Buffer buf = AssertWillBeError(device.CreateBufferBuilder())
|
||||
.SetSize(4)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Vertex)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Uniform)
|
||||
.GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
// Test failure when required properties are missing
|
||||
TEST_F(BufferValidationTest, CreationMissingProperties) {
|
||||
// When allowed usage is missing
|
||||
{
|
||||
dawn::Buffer buf = AssertWillBeError(device.CreateBufferBuilder())
|
||||
.SetSize(4)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// When size is missing
|
||||
{
|
||||
dawn::Buffer buf = AssertWillBeError(device.CreateBufferBuilder())
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Vertex)
|
||||
.GetResult();
|
||||
device.CreateBuffer(&descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,34 +99,38 @@ TEST_F(BufferValidationTest, CreationMissingProperties) {
|
|||
TEST_F(BufferValidationTest, CreationMapUsageRestrictions) {
|
||||
// MapRead with TransferDst is ok
|
||||
{
|
||||
dawn::Buffer buf = AssertWillBeSuccess(device.CreateBufferBuilder(), "1")
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst)
|
||||
.SetSize(4)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst;
|
||||
|
||||
device.CreateBuffer(&descriptor);
|
||||
}
|
||||
|
||||
// MapRead with something else is an error
|
||||
{
|
||||
dawn::Buffer buf = AssertWillBeError(device.CreateBufferBuilder(), "2")
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::Uniform)
|
||||
.SetSize(4)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::Uniform;
|
||||
|
||||
ASSERT_DEVICE_ERROR(device.CreateBuffer(&descriptor));
|
||||
}
|
||||
|
||||
// MapWrite with TransferSrc is ok
|
||||
{
|
||||
dawn::Buffer buf = AssertWillBeSuccess(device.CreateBufferBuilder(), "3")
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferSrc)
|
||||
.SetSize(4)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferSrc;
|
||||
|
||||
device.CreateBuffer(&descriptor);
|
||||
}
|
||||
|
||||
// MapWrite with something else is an error
|
||||
{
|
||||
dawn::Buffer buf = AssertWillBeError(device.CreateBufferBuilder(), "4")
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::Uniform)
|
||||
.SetSize(4)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::Uniform;
|
||||
|
||||
ASSERT_DEVICE_ERROR(device.CreateBuffer(&descriptor));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,10 +186,11 @@ TEST_F(BufferValidationTest, MapWriteOutOfRange) {
|
|||
|
||||
// Test map reading a buffer with wrong current usage
|
||||
TEST_F(BufferValidationTest, MapReadWrongUsage) {
|
||||
dawn::Buffer buf = device.CreateBufferBuilder()
|
||||
.SetSize(4)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferDst)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4;
|
||||
descriptor.usage = dawn::BufferUsageBit::TransferDst;
|
||||
|
||||
dawn::Buffer buf = device.CreateBuffer(&descriptor);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40600;
|
||||
EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
|
@ -230,10 +201,11 @@ TEST_F(BufferValidationTest, MapReadWrongUsage) {
|
|||
|
||||
// Test map writing a buffer with wrong current usage
|
||||
TEST_F(BufferValidationTest, MapWriteWrongUsage) {
|
||||
dawn::Buffer buf = device.CreateBufferBuilder()
|
||||
.SetSize(4)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferSrc)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4;
|
||||
descriptor.usage = dawn::BufferUsageBit::TransferSrc;
|
||||
|
||||
dawn::Buffer buf = device.CreateBuffer(&descriptor);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40600;
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
|
@ -468,10 +440,11 @@ TEST_F(BufferValidationTest, SetSubDataOutOfBounds) {
|
|||
|
||||
// Test error case for SetSubData with the wrong usage
|
||||
TEST_F(BufferValidationTest, SetSubDataWrongUsage) {
|
||||
dawn::Buffer buf = device.CreateBufferBuilder()
|
||||
.SetSize(1)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Vertex)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4;
|
||||
descriptor.usage = dawn::BufferUsageBit::Vertex;
|
||||
|
||||
dawn::Buffer buf = device.CreateBuffer(&descriptor);
|
||||
|
||||
uint8_t foo = 0;
|
||||
ASSERT_DEVICE_ERROR(buf.SetSubData(0, sizeof(foo), &foo));
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
|
||||
class CopyCommandTest : public ValidationTest {
|
||||
protected:
|
||||
dawn::Buffer CreateFrozenBuffer(uint32_t size, dawn::BufferUsageBit usage) {
|
||||
dawn::Buffer buf = AssertWillBeSuccess(device.CreateBufferBuilder())
|
||||
.SetSize(size)
|
||||
.SetAllowedUsage(usage)
|
||||
.GetResult();
|
||||
return buf;
|
||||
dawn::Buffer CreateBuffer(uint32_t size, dawn::BufferUsageBit usage) {
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = size;
|
||||
descriptor.usage = usage;
|
||||
|
||||
return device.CreateBuffer(&descriptor);
|
||||
}
|
||||
|
||||
dawn::Texture Create2DTexture(uint32_t width, uint32_t height, uint32_t levels,
|
||||
|
@ -51,8 +51,8 @@ class CopyCommandTest_B2B : public CopyCommandTest {
|
|||
|
||||
// Test a successfull B2B copy
|
||||
TEST_F(CopyCommandTest_B2B, Success) {
|
||||
dawn::Buffer source = CreateFrozenBuffer(16, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer destination = CreateFrozenBuffer(16, dawn::BufferUsageBit::TransferDst);
|
||||
dawn::Buffer source = CreateBuffer(16, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer destination = CreateBuffer(16, dawn::BufferUsageBit::TransferDst);
|
||||
|
||||
// Copy different copies, including some that touch the OOB condition
|
||||
{
|
||||
|
@ -75,8 +75,8 @@ TEST_F(CopyCommandTest_B2B, Success) {
|
|||
|
||||
// Test B2B copies with OOB
|
||||
TEST_F(CopyCommandTest_B2B, OutOfBounds) {
|
||||
dawn::Buffer source = CreateFrozenBuffer(16, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer destination = CreateFrozenBuffer(16, dawn::BufferUsageBit::TransferDst);
|
||||
dawn::Buffer source = CreateBuffer(16, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer destination = CreateBuffer(16, dawn::BufferUsageBit::TransferDst);
|
||||
|
||||
// OOB on the source
|
||||
{
|
||||
|
@ -95,9 +95,9 @@ TEST_F(CopyCommandTest_B2B, OutOfBounds) {
|
|||
|
||||
// Test B2B copies with incorrect buffer usage
|
||||
TEST_F(CopyCommandTest_B2B, BadUsage) {
|
||||
dawn::Buffer source = CreateFrozenBuffer(16, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer destination = CreateFrozenBuffer(16, dawn::BufferUsageBit::TransferDst);
|
||||
dawn::Buffer vertex = CreateFrozenBuffer(16, dawn::BufferUsageBit::Vertex);
|
||||
dawn::Buffer source = CreateBuffer(16, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer destination = CreateBuffer(16, dawn::BufferUsageBit::TransferDst);
|
||||
dawn::Buffer vertex = CreateBuffer(16, dawn::BufferUsageBit::Vertex);
|
||||
|
||||
// Source with incorrect usage
|
||||
{
|
||||
|
@ -120,7 +120,7 @@ class CopyCommandTest_B2T : public CopyCommandTest {
|
|||
// Test a successfull B2T copy
|
||||
TEST_F(CopyCommandTest_B2T, Success) {
|
||||
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);
|
||||
dawn::Buffer source = CreateFrozenBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer source = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Texture destination = Create2DTexture(16, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferDst);
|
||||
|
||||
|
@ -166,7 +166,7 @@ TEST_F(CopyCommandTest_B2T, Success) {
|
|||
// Test OOB conditions on the buffer
|
||||
TEST_F(CopyCommandTest_B2T, OutOfBoundsOnBuffer) {
|
||||
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);
|
||||
dawn::Buffer source = CreateFrozenBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer source = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Texture destination = Create2DTexture(16, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferDst);
|
||||
|
||||
|
@ -196,7 +196,7 @@ TEST_F(CopyCommandTest_B2T, OutOfBoundsOnBuffer) {
|
|||
{
|
||||
uint32_t sourceBufferSize = BufferSizeForTextureCopy(7, 3, 1);
|
||||
ASSERT_TRUE(256 * 3 > sourceBufferSize) << "row pitch * height should overflow buffer";
|
||||
dawn::Buffer sourceBuffer = CreateFrozenBuffer(sourceBufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer sourceBuffer = CreateBuffer(sourceBufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::CommandBuffer commands = AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
||||
.CopyBufferToTexture(sourceBuffer, 0, 256, destination, 0, 0, 0, 7, 3, 1, 0)
|
||||
.GetResult();
|
||||
|
@ -206,7 +206,7 @@ TEST_F(CopyCommandTest_B2T, OutOfBoundsOnBuffer) {
|
|||
// Test OOB conditions on the texture
|
||||
TEST_F(CopyCommandTest_B2T, OutOfBoundsOnTexture) {
|
||||
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);
|
||||
dawn::Buffer source = CreateFrozenBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer source = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Texture destination = Create2DTexture(16, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferDst);
|
||||
|
||||
|
@ -241,7 +241,7 @@ TEST_F(CopyCommandTest_B2T, OutOfBoundsOnTexture) {
|
|||
|
||||
// Test that we force Z=0 and Depth=1 on copies to 2D textures
|
||||
TEST_F(CopyCommandTest_B2T, ZDepthConstraintFor2DTextures) {
|
||||
dawn::Buffer source = CreateFrozenBuffer(16 * 4, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer source = CreateBuffer(16 * 4, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Texture destination = Create2DTexture(16, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferDst);
|
||||
|
||||
|
@ -262,8 +262,8 @@ TEST_F(CopyCommandTest_B2T, ZDepthConstraintFor2DTextures) {
|
|||
|
||||
// Test B2T copies with incorrect buffer usage
|
||||
TEST_F(CopyCommandTest_B2T, IncorrectUsage) {
|
||||
dawn::Buffer source = CreateFrozenBuffer(16 * 4, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer vertex = CreateFrozenBuffer(16 * 4, dawn::BufferUsageBit::Vertex);
|
||||
dawn::Buffer source = CreateBuffer(16 * 4, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer vertex = CreateBuffer(16 * 4, dawn::BufferUsageBit::Vertex);
|
||||
dawn::Texture destination = Create2DTexture(16, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferDst);
|
||||
dawn::Texture sampled = Create2DTexture(16, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
|
@ -286,7 +286,7 @@ TEST_F(CopyCommandTest_B2T, IncorrectUsage) {
|
|||
|
||||
TEST_F(CopyCommandTest_B2T, IncorrectRowPitch) {
|
||||
uint32_t bufferSize = BufferSizeForTextureCopy(128, 16, 1);
|
||||
dawn::Buffer source = CreateFrozenBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer source = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Texture destination = Create2DTexture(128, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferDst);
|
||||
|
||||
|
@ -315,7 +315,7 @@ TEST_F(CopyCommandTest_B2T, IncorrectRowPitch) {
|
|||
// Test B2T copies with incorrect buffer offset usage
|
||||
TEST_F(CopyCommandTest_B2T, IncorrectBufferOffset) {
|
||||
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);
|
||||
dawn::Buffer source = CreateFrozenBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer source = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Texture destination = Create2DTexture(16, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferDst);
|
||||
|
||||
|
@ -351,7 +351,7 @@ TEST_F(CopyCommandTest_T2B, Success) {
|
|||
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);
|
||||
dawn::Texture source = Create2DTexture(16, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferSrc);
|
||||
dawn::Buffer destination = CreateFrozenBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
dawn::Buffer destination = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
|
||||
// Different copies, including some that touch the OOB condition
|
||||
{
|
||||
|
@ -397,7 +397,7 @@ TEST_F(CopyCommandTest_T2B, OutOfBoundsOnTexture) {
|
|||
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);
|
||||
dawn::Texture source = Create2DTexture(16, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferSrc);
|
||||
dawn::Buffer destination = CreateFrozenBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
dawn::Buffer destination = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
|
||||
// OOB on the texture because x + width overflows
|
||||
{
|
||||
|
@ -433,7 +433,7 @@ TEST_F(CopyCommandTest_T2B, OutOfBoundsOnBuffer) {
|
|||
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);
|
||||
dawn::Texture source = Create2DTexture(16, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferSrc);
|
||||
dawn::Buffer destination = CreateFrozenBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
dawn::Buffer destination = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
|
||||
// OOB on the buffer because we copy too many pixels
|
||||
{
|
||||
|
@ -461,7 +461,7 @@ TEST_F(CopyCommandTest_T2B, OutOfBoundsOnBuffer) {
|
|||
{
|
||||
uint32_t destinationBufferSize = BufferSizeForTextureCopy(7, 3, 1);
|
||||
ASSERT_TRUE(256 * 3 > destinationBufferSize) << "row pitch * height should overflow buffer";
|
||||
dawn::Buffer destinationBuffer = CreateFrozenBuffer(destinationBufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
dawn::Buffer destinationBuffer = CreateBuffer(destinationBufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
dawn::CommandBuffer commands = AssertWillBeSuccess(device.CreateCommandBufferBuilder())
|
||||
.CopyTextureToBuffer(source, 0, 0, 0, 7, 3, 1, 0, destinationBuffer, 0, 256)
|
||||
.GetResult();
|
||||
|
@ -473,7 +473,7 @@ TEST_F(CopyCommandTest_T2B, ZDepthConstraintFor2DTextures) {
|
|||
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);
|
||||
dawn::Texture source = Create2DTexture(16, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferSrc);
|
||||
dawn::Buffer destination = CreateFrozenBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
dawn::Buffer destination = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
|
||||
// Z=1 on an empty copy still errors
|
||||
{
|
||||
|
@ -497,8 +497,8 @@ TEST_F(CopyCommandTest_T2B, IncorrectUsage) {
|
|||
dawn::TextureUsageBit::TransferSrc);
|
||||
dawn::Texture sampled = Create2DTexture(16, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::Sampled);
|
||||
dawn::Buffer destination = CreateFrozenBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
dawn::Buffer vertex = CreateFrozenBuffer(bufferSize, dawn::BufferUsageBit::Vertex);
|
||||
dawn::Buffer destination = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
dawn::Buffer vertex = CreateBuffer(bufferSize, dawn::BufferUsageBit::Vertex);
|
||||
|
||||
// Incorrect source usage
|
||||
{
|
||||
|
@ -519,7 +519,7 @@ TEST_F(CopyCommandTest_T2B, IncorrectRowPitch) {
|
|||
uint32_t bufferSize = BufferSizeForTextureCopy(128, 16, 1);
|
||||
dawn::Texture source = Create2DTexture(128, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferDst);
|
||||
dawn::Buffer destination = CreateFrozenBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Buffer destination = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
|
||||
// Default row pitch is not 256-byte aligned
|
||||
{
|
||||
|
@ -548,7 +548,7 @@ TEST_F(CopyCommandTest_T2B, IncorrectBufferOffset) {
|
|||
uint32_t bufferSize = BufferSizeForTextureCopy(128, 16, 1);
|
||||
dawn::Texture source = Create2DTexture(128, 16, 5, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferSrc);
|
||||
dawn::Buffer destination = CreateFrozenBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
dawn::Buffer destination = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
|
||||
// Correct usage
|
||||
{
|
||||
|
|
|
@ -37,10 +37,11 @@ class VertexBufferValidationTest : public ValidationTest {
|
|||
std::array<dawn::Buffer, N> MakeVertexBuffers() {
|
||||
std::array<dawn::Buffer, N> buffers;
|
||||
for (auto& buffer : buffers) {
|
||||
buffer = device.CreateBufferBuilder()
|
||||
.SetSize(256)
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::Vertex)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 256;
|
||||
descriptor.usage = dawn::BufferUsageBit::Vertex;
|
||||
|
||||
buffer = device.CreateBuffer(&descriptor);
|
||||
}
|
||||
return buffers;
|
||||
}
|
||||
|
|
|
@ -98,10 +98,11 @@ namespace utils {
|
|||
const void* data,
|
||||
uint32_t size,
|
||||
dawn::BufferUsageBit usage) {
|
||||
dawn::Buffer buffer = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(dawn::BufferUsageBit::TransferDst | usage)
|
||||
.SetSize(size)
|
||||
.GetResult();
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = size;
|
||||
descriptor.usage = usage | dawn::BufferUsageBit::TransferDst;
|
||||
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
buffer.SetSubData(0, size, reinterpret_cast<const uint8_t*>(data));
|
||||
return buffer;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue