Make autogenerated validation produce device or builder errors

This commit is contained in:
Corentin Wallez
2017-05-10 15:30:05 +02:00
committed by Corentin Wallez
parent f79df0c62d
commit 36cf2dd54b
13 changed files with 69 additions and 29 deletions

View File

@@ -34,6 +34,10 @@ namespace backend {
return new BufferViewBuilder(device, this);
}
DeviceBase* BufferBase::GetDevice() {
return device;
}
uint32_t BufferBase::GetSize() const {
return size;
}

View File

@@ -36,6 +36,8 @@ namespace backend {
bool HasFrozenUsage(nxt::BufferUsageBit usage) const;
void TransitionUsageImpl(nxt::BufferUsageBit usage);
DeviceBase* GetDevice();
// NXT API
BufferViewBuilder* CreateBufferViewBuilder();
void SetSubData(uint32_t start, uint32_t count, const uint32_t* data);

View File

@@ -22,6 +22,10 @@ namespace backend {
return !consumed && !gotStatus;
}
DeviceBase* BuilderBase::GetDevice() {
return device;
}
void BuilderBase::HandleError(const char* message) {
SetStatus(nxt::BuilderErrorStatus::Error, message);
}

View File

@@ -42,6 +42,7 @@ namespace backend {
// Used by the auto-generated validation to prevent usage of the builder
// after GetResult or an error.
bool CanBeUsed() const;
DeviceBase* GetDevice();
// Set the status of the builder to an error.
void HandleError(const char* message);

View File

@@ -61,6 +61,10 @@ namespace backend {
this->errorUserdata = userdata;
}
DeviceBase* DeviceBase::GetDevice() {
return this;
}
BindGroupLayoutBase* DeviceBase::GetOrCreateBindGroupLayout(const BindGroupLayoutBase* blueprint, BindGroupLayoutBuilder* builder) {
// The blueprint is only used to search in the cache and is not modified. However cached
// objects can be modified, and unordered_set cannot search for a const pointer in a non

View File

@@ -32,6 +32,9 @@ namespace backend {
void HandleError(const char* message);
void SetErrorCallback(nxt::DeviceErrorCallback callback, nxt::CallbackUserdata userdata);
// Used by autogenerated code, returns itself
DeviceBase* GetDevice();
virtual BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) = 0;
virtual BindGroupLayoutBase* CreateBindGroupLayout(BindGroupLayoutBuilder* builder) = 0;
virtual BufferBase* CreateBuffer(BufferBuilder* builder) = 0;

View File

@@ -21,6 +21,13 @@ namespace backend {
// QueueBase
QueueBase::QueueBase(QueueBuilder* builder) : device(builder->device) {
}
DeviceBase* QueueBase::GetDevice() {
return device;
}
bool QueueBase::ValidateSubmitCommand(CommandBufferBase* command) {
return command->ValidateResourceUsagesImmediate();
}

View File

@@ -24,10 +24,11 @@
namespace backend {
class QueueBase : public RefCounted {
private:
bool ValidateSubmitCommand(CommandBufferBase* command);
public:
QueueBase(QueueBuilder* builder);
DeviceBase* GetDevice();
template<typename T>
bool ValidateSubmit(uint32_t numCommands, T* const * commands) {
static_assert(std::is_base_of<CommandBufferBase, T>::value, "invalid command buffer type");
@@ -39,6 +40,11 @@ namespace backend {
}
return true;
}
private:
bool ValidateSubmitCommand(CommandBufferBase* command);
DeviceBase* device;
};
class QueueBuilder : public Builder<QueueBase> {
@@ -46,6 +52,7 @@ namespace backend {
QueueBuilder(DeviceBase* device);
private:
friend class QueueBase;
QueueBase* GetResultImpl() override;
};

View File

@@ -33,6 +33,10 @@ namespace backend {
allowedUsage(builder->allowedUsage), currentUsage(builder->currentUsage) {
}
DeviceBase* TextureBase::GetDevice() {
return device;
}
nxt::TextureDimension TextureBase::GetDimension() const {
return dimension;
}

View File

@@ -43,6 +43,8 @@ namespace backend {
bool IsTransitionPossible(nxt::TextureUsageBit usage) const;
void TransitionUsageImpl(nxt::TextureUsageBit usage);
DeviceBase* GetDevice();
// NXT API
TextureViewBuilder* CreateTextureViewBuilder();
void TransitionUsage(nxt::TextureUsageBit usage);

View File

@@ -803,7 +803,7 @@ namespace metal {
// Queue
Queue::Queue(Device* device, QueueBuilder* builder)
: device(device) {
: QueueBase(builder), device(device) {
commandQueue = [device->GetMTLDevice() newCommandQueue];
}

View File

@@ -167,7 +167,8 @@ namespace opengl {
// Queue
Queue::Queue(Device* device, QueueBuilder* builder) : device(device) {
Queue::Queue(Device* device, QueueBuilder* builder)
: QueueBase(builder), device(device) {
}
void Queue::Submit(uint32_t numCommands, CommandBuffer* const * commands) {