Refactor TransitionUsage to use abstract TransitionUsageImpl

This commit is contained in:
Austin Eng 2017-06-12 18:31:10 -04:00 committed by Austin Eng
parent 39c901d3dc
commit 459537491b
15 changed files with 71 additions and 12 deletions

View File

@ -145,7 +145,7 @@ namespace backend {
return IsUsagePossible(allowedUsage, usage);
}
void BufferBase::TransitionUsageImpl(nxt::BufferUsageBit usage) {
void BufferBase::UpdateUsageInternal(nxt::BufferUsageBit usage) {
assert(IsTransitionPossible(usage));
currentUsage = usage;
}
@ -155,7 +155,8 @@ namespace backend {
device->HandleError("Buffer frozen or usage not allowed");
return;
}
TransitionUsageImpl(usage);
TransitionUsageImpl(currentUsage, usage);
currentUsage = usage;
}
void BufferBase::FreezeUsage(nxt::BufferUsageBit usage) {
@ -164,6 +165,7 @@ namespace backend {
return;
}
allowedUsage = usage;
TransitionUsageImpl(currentUsage, usage);
currentUsage = usage;
frozen = true;
}

View File

@ -35,7 +35,7 @@ namespace backend {
bool IsTransitionPossible(nxt::BufferUsageBit usage) const;
bool IsFrozen() const;
bool HasFrozenUsage(nxt::BufferUsageBit usage) const;
void TransitionUsageImpl(nxt::BufferUsageBit usage);
void UpdateUsageInternal(nxt::BufferUsageBit usage);
DeviceBase* GetDevice();
@ -54,6 +54,7 @@ namespace backend {
virtual void SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) = 0;
virtual void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) = 0;
virtual void UnmapImpl() = 0;
virtual void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) = 0;
DeviceBase* device;
uint32_t size;

View File

@ -87,7 +87,7 @@ namespace backend {
return IsUsagePossible(allowedUsage, usage);
}
void TextureBase::TransitionUsageImpl(nxt::TextureUsageBit usage) {
void TextureBase::UpdateUsageInternal(nxt::TextureUsageBit usage) {
assert(IsTransitionPossible(usage));
currentUsage = usage;
}
@ -97,7 +97,8 @@ namespace backend {
device->HandleError("Texture frozen or usage not allowed");
return;
}
TransitionUsageImpl(usage);
TransitionUsageImpl(currentUsage, usage);
currentUsage = usage;
}
void TextureBase::FreezeUsage(nxt::TextureUsageBit usage) {
@ -106,6 +107,7 @@ namespace backend {
return;
}
allowedUsage = usage;
TransitionUsageImpl(currentUsage, usage);
currentUsage = usage;
frozen = true;
}

View File

@ -41,7 +41,7 @@ namespace backend {
bool HasFrozenUsage(nxt::TextureUsageBit usage) const;
static bool IsUsagePossible(nxt::TextureUsageBit allowedUsage, nxt::TextureUsageBit usage);
bool IsTransitionPossible(nxt::TextureUsageBit usage) const;
void TransitionUsageImpl(nxt::TextureUsageBit usage);
void UpdateUsageInternal(nxt::TextureUsageBit usage);
DeviceBase* GetDevice();
@ -51,6 +51,8 @@ namespace backend {
void FreezeUsage(nxt::TextureUsageBit usage);
private:
virtual void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) = 0;
DeviceBase* device;
nxt::TextureDimension dimension;

View File

@ -156,6 +156,9 @@ namespace d3d12 {
// TODO(cwallez@chromium.org): Implement Map Read for the null backend
}
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) {
}
// BufferView
BufferView::BufferView(Device* device, BufferViewBuilder* builder)
@ -198,6 +201,9 @@ namespace d3d12 {
: TextureBase(builder), device(device) {
}
void Texture::TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) {
}
// TextureView
TextureView::TextureView(Device* device, TextureViewBuilder* builder)

View File

@ -145,6 +145,7 @@ namespace d3d12 {
void SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) override;
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
void UnmapImpl() override;
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override;
Device* device;
};
@ -202,6 +203,8 @@ namespace d3d12 {
Texture(Device* device, TextureBuilder* builder);
private:
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override;
Device* device;
};

View File

@ -162,6 +162,7 @@ namespace metal {
void SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) override;
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
void UnmapImpl() override;
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override;
Device* device;
std::mutex mutex;
@ -309,6 +310,8 @@ namespace metal {
id<MTLTexture> GetMTLTexture();
private:
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override;
Device* device;
id<MTLTexture> mtlTexture = nil;
};

View File

@ -233,6 +233,9 @@ namespace metal {
// TODO(cwallez@chromium.org): Implement Map Read for the metal backend
}
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) {
}
// BufferView
BufferView::BufferView(Device* device, BufferViewBuilder* builder)
@ -669,7 +672,7 @@ namespace metal {
{
TransitionBufferUsageCmd* cmd = commands.NextCommand<TransitionBufferUsageCmd>();
cmd->buffer->TransitionUsageImpl(cmd->usage);
cmd->buffer->UpdateUsageInternal(cmd->usage);
}
break;
@ -677,7 +680,7 @@ namespace metal {
{
TransitionTextureUsageCmd* cmd = commands.NextCommand<TransitionTextureUsageCmd>();
cmd->texture->TransitionUsageImpl(cmd->usage);
cmd->texture->UpdateUsageInternal(cmd->usage);
}
break;
;
@ -1156,6 +1159,9 @@ namespace metal {
return mtlTexture;
}
void Texture::TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) {
}
// TextureView
TextureView::TextureView(Device* device, TextureViewBuilder* builder)

View File

@ -83,7 +83,7 @@ namespace null {
return module;
}
TextureBase* Device::CreateTexture(TextureBuilder* builder) {
return new TextureBase(builder);
return new Texture(builder);
}
TextureViewBase* Device::CreateTextureView(TextureViewBuilder* builder) {
return new TextureViewBase(builder);
@ -149,6 +149,9 @@ namespace null {
void Buffer::UnmapImpl() {
}
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) {
}
// Queue
Queue::Queue(QueueBuilder* builder)
@ -168,5 +171,17 @@ namespace null {
operations.clear();
}
// Texture
Texture::Texture(TextureBuilder* builder)
: TextureBase(builder) {
}
Texture::~Texture() {
}
void Texture::TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) {
}
}
}

View File

@ -52,7 +52,7 @@ namespace null {
using RenderPass = RenderPassBase;
using Sampler = SamplerBase;
using ShaderModule = ShaderModuleBase;
using Texture = TextureBase;
class Texture;
using TextureView = TextureViewBase;
struct NullBackendTraits {
@ -129,6 +129,7 @@ namespace null {
void SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) override;
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
void UnmapImpl() override;
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override;
std::unique_ptr<char[]> backingData;
};
@ -142,6 +143,15 @@ namespace null {
void Submit(uint32_t numCommands, CommandBuffer* const * commands);
};
class Texture : public TextureBase {
public:
Texture(TextureBuilder* buidler);
~Texture();
private:
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override;
};
}
}

View File

@ -325,7 +325,7 @@ namespace opengl {
{
TransitionBufferUsageCmd* cmd = commands.NextCommand<TransitionBufferUsageCmd>();
cmd->buffer->TransitionUsageImpl(cmd->usage);
cmd->buffer->UpdateUsageInternal(cmd->usage);
}
break;
@ -333,7 +333,7 @@ namespace opengl {
{
TransitionTextureUsageCmd* cmd = commands.NextCommand<TransitionTextureUsageCmd>();
cmd->texture->TransitionUsageImpl(cmd->usage);
cmd->texture->UpdateUsageInternal(cmd->usage);
}
break;
}

View File

@ -141,6 +141,9 @@ namespace opengl {
// TODO(cwallez@chromium.org): Implement Map Read for the GL backend
}
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) {
}
// BufferView
BufferView::BufferView(Device* device, BufferViewBuilder* builder)

View File

@ -128,6 +128,7 @@ namespace opengl {
void SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) override;
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
void UnmapImpl() override;
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override;
Device* device;
GLuint buffer = 0;

View File

@ -76,6 +76,9 @@ namespace opengl {
return GetGLFormatInfo(GetFormat());
}
void Texture::TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) {
}
// TextureView
TextureView::TextureView(Device* device, TextureViewBuilder* builder)

View File

@ -39,6 +39,8 @@ namespace opengl {
TextureFormatInfo GetGLFormat() const;
private:
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override;
Device* device;
GLuint handle;
GLenum target;