Remove unnecessary Device forwarding.

This commit is contained in:
Corentin Wallez 2017-06-27 11:10:29 -04:00 committed by Corentin Wallez
parent 59d55dc3ac
commit 2dd73fbc1d
22 changed files with 90 additions and 135 deletions

View File

@ -26,7 +26,7 @@ namespace backend {
// PipelineBase
PipelineBase::PipelineBase(PipelineBuilder* builder)
: device(builder->device), stageMask(builder->stageMask), layout(std::move(builder->layout)),
: stageMask(builder->stageMask), layout(std::move(builder->layout)),
renderPass(std::move(builder->renderPass)), subpass(builder->subpass),
inputState(std::move(builder->inputState)), depthStencilState(std::move(builder->depthStencilState)) {

View File

@ -53,8 +53,6 @@ namespace backend {
bool IsCompute() const;
private:
DeviceBase* device;
nxt::ShaderStageBit stageMask;
Ref<PipelineLayoutBase> layout;
Ref<RenderPassBase> renderPass;

View File

@ -26,7 +26,7 @@ namespace metal {
class CommandBuffer : public CommandBufferBase {
public:
CommandBuffer(Device* device, CommandBufferBuilder* builder);
CommandBuffer(CommandBufferBuilder* builder);
~CommandBuffer();
void FillCommands(id<MTLCommandBuffer> commandBuffer);

View File

@ -119,8 +119,9 @@ namespace metal {
};
}
CommandBuffer::CommandBuffer(Device* device, CommandBufferBuilder* builder)
: CommandBufferBase(builder), device(device), commands(builder->AcquireCommands()) {
CommandBuffer::CommandBuffer(CommandBufferBuilder* builder)
: CommandBufferBase(builder), device(ToBackend(builder->GetDevice())),
commands(builder->AcquireCommands()) {
}
CommandBuffer::~CommandBuffer() {

View File

@ -139,32 +139,23 @@ namespace metal {
class BindGroup : public BindGroupBase {
public:
BindGroup(Device* device, BindGroupBuilder* builder);
private:
Device* device;
BindGroup(BindGroupBuilder* builder);
};
class BindGroupLayout : public BindGroupLayoutBase {
public:
BindGroupLayout(Device* device, BindGroupLayoutBuilder* builder);
private:
Device* device;
BindGroupLayout(BindGroupLayoutBuilder* builder);
};
class Framebuffer : public FramebufferBase {
public:
Framebuffer(Device* device, FramebufferBuilder* builder);
Framebuffer(FramebufferBuilder* builder);
~Framebuffer();
private:
Device* device;
};
class Queue : public QueueBase {
public:
Queue(Device* device, QueueBuilder* builder);
Queue(QueueBuilder* builder);
~Queue();
id<MTLCommandQueue> GetMTLCommandQueue();
@ -173,17 +164,13 @@ namespace metal {
void Submit(uint32_t numCommands, CommandBuffer* const * commands);
private:
Device* device;
id<MTLCommandQueue> commandQueue = nil;
};
class RenderPass : public RenderPassBase {
public:
RenderPass(Device* device, RenderPassBuilder* builder);
RenderPass(RenderPassBuilder* builder);
~RenderPass();
private:
Device* device;
};
}

View File

@ -82,10 +82,10 @@ namespace metal {
}
BindGroupBase* Device::CreateBindGroup(BindGroupBuilder* builder) {
return new BindGroup(this, builder);
return new BindGroup(builder);
}
BindGroupLayoutBase* Device::CreateBindGroupLayout(BindGroupLayoutBuilder* builder) {
return new BindGroupLayout(this, builder);
return new BindGroupLayout(builder);
}
BufferBase* Device::CreateBuffer(BufferBuilder* builder) {
return new Buffer(builder);
@ -94,7 +94,7 @@ namespace metal {
return new BufferView(builder);
}
CommandBufferBase* Device::CreateCommandBuffer(CommandBufferBuilder* builder) {
return new CommandBuffer(this, builder);
return new CommandBuffer(builder);
}
DepthStencilStateBase* Device::CreateDepthStencilState(DepthStencilStateBuilder* builder) {
return new DepthStencilState(builder);
@ -103,7 +103,7 @@ namespace metal {
return new InputState(builder);
}
FramebufferBase* Device::CreateFramebuffer(FramebufferBuilder* builder) {
return new Framebuffer(this, builder);
return new Framebuffer(builder);
}
PipelineBase* Device::CreatePipeline(PipelineBuilder* builder) {
return new Pipeline(builder);
@ -112,10 +112,10 @@ namespace metal {
return new PipelineLayout(builder);
}
QueueBase* Device::CreateQueue(QueueBuilder* builder) {
return new Queue(this, builder);
return new Queue(builder);
}
RenderPassBase* Device::CreateRenderPass(RenderPassBuilder* builder) {
return new RenderPass(this, builder);
return new RenderPass(builder);
}
SamplerBase* Device::CreateSampler(SamplerBuilder* builder) {
return new Sampler(builder);
@ -251,20 +251,20 @@ namespace metal {
// Bind Group
BindGroup::BindGroup(Device* device, BindGroupBuilder* builder)
: BindGroupBase(builder), device(device) {
BindGroup::BindGroup(BindGroupBuilder* builder)
: BindGroupBase(builder) {
}
// Bind Group Layout
BindGroupLayout::BindGroupLayout(Device* device, BindGroupLayoutBuilder* builder)
: BindGroupLayoutBase(builder), device(device) {
BindGroupLayout::BindGroupLayout(BindGroupLayoutBuilder* builder)
: BindGroupLayoutBase(builder) {
}
// Framebuffer
Framebuffer::Framebuffer(Device* device, FramebufferBuilder* builder)
: FramebufferBase(builder), device(device) {
Framebuffer::Framebuffer(FramebufferBuilder* builder)
: FramebufferBase(builder) {
}
Framebuffer::~Framebuffer() {
@ -272,8 +272,9 @@ namespace metal {
// Queue
Queue::Queue(Device* device, QueueBuilder* builder)
: QueueBase(builder), device(device) {
Queue::Queue(QueueBuilder* builder)
: QueueBase(builder) {
Device* device = ToBackend(builder->GetDevice());
commandQueue = [device->GetMTLDevice() newCommandQueue];
}
@ -299,8 +300,8 @@ namespace metal {
// RenderPass
RenderPass::RenderPass(Device* device, RenderPassBuilder* builder)
: RenderPassBase(builder), device(device) {
RenderPass::RenderPass(RenderPassBuilder* builder)
: RenderPassBase(builder) {
}
RenderPass::~RenderPass() {

View File

@ -27,8 +27,8 @@
namespace backend {
namespace opengl {
CommandBuffer::CommandBuffer(Device* device, CommandBufferBuilder* builder)
: CommandBufferBase(builder), device(device), commands(builder->AcquireCommands()) {
CommandBuffer::CommandBuffer(CommandBufferBuilder* builder)
: CommandBufferBase(builder), commands(builder->AcquireCommands()) {
}
CommandBuffer::~CommandBuffer() {

View File

@ -25,13 +25,12 @@ namespace opengl {
class CommandBuffer : public CommandBufferBase {
public:
CommandBuffer(Device* device, CommandBufferBuilder* builder);
CommandBuffer(CommandBufferBuilder* builder);
~CommandBuffer();
void Execute();
private:
Device* device;
CommandIterator commands;
};

View File

@ -64,8 +64,8 @@ namespace opengl {
}
}
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder)
: DepthStencilStateBase(builder), device(device) {
DepthStencilState::DepthStencilState(DepthStencilStateBuilder* builder)
: DepthStencilStateBase(builder) {
}
void DepthStencilState::ApplyNow(PersistentPipelineState &persistentPipelineState) const {

View File

@ -25,12 +25,9 @@ namespace opengl {
class DepthStencilState : public DepthStencilStateBase {
public:
DepthStencilState(Device* device, DepthStencilStateBuilder* builder);
DepthStencilState(DepthStencilStateBuilder* builder);
void ApplyNow(PersistentPipelineState &persistentPipelineState) const;
private:
Device* device;
};
}

View File

@ -49,52 +49,52 @@ namespace opengl {
// Device
BindGroupBase* Device::CreateBindGroup(BindGroupBuilder* builder) {
return new BindGroup(this, builder);
return new BindGroup(builder);
}
BindGroupLayoutBase* Device::CreateBindGroupLayout(BindGroupLayoutBuilder* builder) {
return new BindGroupLayout(this, builder);
return new BindGroupLayout(builder);
}
BufferBase* Device::CreateBuffer(BufferBuilder* builder) {
return new Buffer(this, builder);
return new Buffer(builder);
}
BufferViewBase* Device::CreateBufferView(BufferViewBuilder* builder) {
return new BufferView(this, builder);
return new BufferView(builder);
}
CommandBufferBase* Device::CreateCommandBuffer(CommandBufferBuilder* builder) {
return new CommandBuffer(this, builder);
return new CommandBuffer(builder);
}
DepthStencilStateBase* Device::CreateDepthStencilState(DepthStencilStateBuilder* builder) {
return new DepthStencilState(this, builder);
return new DepthStencilState(builder);
}
InputStateBase* Device::CreateInputState(InputStateBuilder* builder) {
return new InputState(this, builder);
return new InputState(builder);
}
FramebufferBase* Device::CreateFramebuffer(FramebufferBuilder* builder) {
return new Framebuffer(this, builder);
return new Framebuffer(builder);
}
PipelineBase* Device::CreatePipeline(PipelineBuilder* builder) {
return new Pipeline(this, builder);
return new Pipeline(builder);
}
PipelineLayoutBase* Device::CreatePipelineLayout(PipelineLayoutBuilder* builder) {
return new PipelineLayout(this, builder);
return new PipelineLayout(builder);
}
QueueBase* Device::CreateQueue(QueueBuilder* builder) {
return new Queue(this, builder);
return new Queue(builder);
}
RenderPassBase* Device::CreateRenderPass(RenderPassBuilder* builder) {
return new RenderPass(this, builder);
return new RenderPass(builder);
}
SamplerBase* Device::CreateSampler(SamplerBuilder* builder) {
return new Sampler(this, builder);
return new Sampler(builder);
}
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {
return new ShaderModule(this, builder);
return new ShaderModule(builder);
}
TextureBase* Device::CreateTexture(TextureBuilder* builder) {
return new Texture(this, builder);
return new Texture(builder);
}
TextureViewBase* Device::CreateTextureView(TextureViewBuilder* builder) {
return new TextureView(this, builder);
return new TextureView(builder);
}
void Device::TickImpl() {
@ -108,20 +108,20 @@ namespace opengl {
// Bind Group
BindGroup::BindGroup(Device* device, BindGroupBuilder* builder)
: BindGroupBase(builder), device(device) {
BindGroup::BindGroup(BindGroupBuilder* builder)
: BindGroupBase(builder) {
}
// Bind Group Layout
BindGroupLayout::BindGroupLayout(Device* device, BindGroupLayoutBuilder* builder)
: BindGroupLayoutBase(builder), device(device) {
BindGroupLayout::BindGroupLayout(BindGroupLayoutBuilder* builder)
: BindGroupLayoutBase(builder) {
}
// Buffer
Buffer::Buffer(Device* device, BufferBuilder* builder)
: BufferBase(builder), device(device) {
Buffer::Buffer(BufferBuilder* builder)
: BufferBase(builder) {
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, GetSize(), nullptr, GL_STATIC_DRAW);
@ -149,14 +149,14 @@ namespace opengl {
// BufferView
BufferView::BufferView(Device* device, BufferViewBuilder* builder)
: BufferViewBase(builder), device(device) {
BufferView::BufferView(BufferViewBuilder* builder)
: BufferViewBase(builder) {
}
// InputState
InputState::InputState(Device* device, InputStateBuilder* builder)
: InputStateBase(builder), device(device) {
InputState::InputState(InputStateBuilder* builder)
: InputStateBase(builder) {
glGenVertexArrays(1, &vertexArrayObject);
glBindVertexArray(vertexArrayObject);
auto& attributesSetMask = GetAttributesSetMask();
@ -193,14 +193,14 @@ namespace opengl {
// Framebuffer
Framebuffer::Framebuffer(Device* device, FramebufferBuilder* builder)
: FramebufferBase(builder), device(device) {
Framebuffer::Framebuffer(FramebufferBuilder* builder)
: FramebufferBase(builder) {
}
// Queue
Queue::Queue(Device* device, QueueBuilder* builder)
: QueueBase(builder), device(device) {
Queue::Queue(QueueBuilder* builder)
: QueueBase(builder) {
}
void Queue::Submit(uint32_t numCommands, CommandBuffer* const * commands) {
@ -211,8 +211,8 @@ namespace opengl {
// RenderPass
RenderPass::RenderPass(Device* device, RenderPassBuilder* builder)
: RenderPassBase(builder), device(device) {
RenderPass::RenderPass(RenderPassBuilder* builder)
: RenderPassBase(builder) {
}
}

View File

@ -106,23 +106,17 @@ namespace opengl {
class BindGroup : public BindGroupBase {
public:
BindGroup(Device* device, BindGroupBuilder* builder);
private:
Device* device;
BindGroup(BindGroupBuilder* builder);
};
class BindGroupLayout : public BindGroupLayoutBase {
public:
BindGroupLayout(Device* device, BindGroupLayoutBuilder* builder);
private:
Device* device;
BindGroupLayout(BindGroupLayoutBuilder* builder);
};
class Buffer : public BufferBase {
public:
Buffer(Device* device, BufferBuilder* builder);
Buffer(BufferBuilder* builder);
GLuint GetHandle() const;
@ -132,53 +126,39 @@ namespace opengl {
void UnmapImpl() override;
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override;
Device* device;
GLuint buffer = 0;
};
class BufferView : public BufferViewBase {
public:
BufferView(Device* device, BufferViewBuilder* builder);
private:
Device* device;
BufferView(BufferViewBuilder* builder);
};
class Framebuffer : public FramebufferBase {
public:
Framebuffer(Device* device, FramebufferBuilder* builder);
private:
Device* device;
Framebuffer(FramebufferBuilder* builder);
};
class InputState : public InputStateBase {
public:
InputState(Device* device, InputStateBuilder* builder);
InputState(InputStateBuilder* builder);
GLuint GetVAO();
private:
Device* device;
GLuint vertexArrayObject;
};
class Queue : public QueueBase {
public:
Queue(Device* device, QueueBuilder* builder);
Queue(QueueBuilder* builder);
// NXT API
void Submit(uint32_t numCommands, CommandBuffer* const * commands);
private:
Device* device;
};
class RenderPass : public RenderPassBase {
public:
RenderPass(Device* device, RenderPassBuilder* builder);
private:
Device* device;
RenderPass(RenderPassBuilder* builder);
};
}

View File

@ -41,7 +41,7 @@ namespace opengl {
}
Pipeline::Pipeline(Device* device, PipelineBuilder* builder) : PipelineBase(builder), device(device) {
Pipeline::Pipeline(PipelineBuilder* builder) : PipelineBase(builder) {
auto CreateShader = [](GLenum type, const char* source) -> GLuint {
GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &source, nullptr);

View File

@ -30,7 +30,7 @@ namespace opengl {
class Pipeline : public PipelineBase {
public:
Pipeline(Device* device, PipelineBuilder* builder);
Pipeline(PipelineBuilder* builder);
using GLPushConstantInfo = std::array<GLint, kMaxPushConstants>;
using BindingLocations = std::array<std::array<GLint, kMaxBindingsPerGroup>, kMaxBindGroups>;
@ -47,7 +47,6 @@ namespace opengl {
PerStage<GLPushConstantInfo> glPushConstants;
std::vector<std::vector<GLuint>> unitsForSamplers;
std::vector<std::vector<GLuint>> unitsForTextures;
Device* device;
};
}

View File

@ -19,8 +19,8 @@
namespace backend {
namespace opengl {
PipelineLayout::PipelineLayout(Device* device, PipelineLayoutBuilder* builder)
: PipelineLayoutBase(builder), device(device) {
PipelineLayout::PipelineLayout(PipelineLayoutBuilder* builder)
: PipelineLayoutBase(builder) {
GLuint uboIndex = 0;
GLuint samplerIndex = 0;
GLuint sampledTextureIndex = 0;

View File

@ -26,7 +26,7 @@ namespace opengl {
class PipelineLayout : public PipelineLayoutBase {
public:
PipelineLayout(Device* device, PipelineLayoutBuilder* builder);
PipelineLayout(PipelineLayoutBuilder* builder);
using BindingIndexInfo = std::array<std::array<GLuint, kMaxBindingsPerGroup>, kMaxBindGroups>;
const BindingIndexInfo& GetBindingIndexInfo() const;
@ -36,7 +36,6 @@ namespace opengl {
size_t GetNumSampledTextures() const;
private:
Device* device;
BindingIndexInfo indexInfo;
size_t numSamplers;
size_t numSampledTextures;

View File

@ -47,8 +47,8 @@ namespace opengl {
}
}
Sampler::Sampler(Device* device, SamplerBuilder* builder)
: SamplerBase(builder), device(device) {
Sampler::Sampler(SamplerBuilder* builder)
: SamplerBase(builder) {
glGenSamplers(1, &handle);
glSamplerParameteri(handle, GL_TEXTURE_MAG_FILTER, MagFilterMode(builder->GetMagFilter()));
glSamplerParameteri(handle, GL_TEXTURE_MIN_FILTER, MinFilterMode(builder->GetMinFilter(), builder->GetMipMapFilter()));

View File

@ -26,12 +26,11 @@ namespace opengl {
class Sampler : public SamplerBase {
public:
Sampler(Device* device, SamplerBuilder* builder);
Sampler(SamplerBuilder* builder);
GLuint GetHandle() const;
private:
Device* device;
GLuint handle;
};

View File

@ -43,8 +43,8 @@ namespace opengl {
return o.str();
}
ShaderModule::ShaderModule(Device* device, ShaderModuleBuilder* builder)
: ShaderModuleBase(builder), device(device) {
ShaderModule::ShaderModule(ShaderModuleBuilder* builder)
: ShaderModuleBase(builder) {
spirv_cross::CompilerGLSL compiler(builder->AcquireSpirv());
spirv_cross::CompilerGLSL::Options options;

View File

@ -41,7 +41,7 @@ namespace opengl {
class ShaderModule : public ShaderModuleBase {
public:
ShaderModule(Device* device, ShaderModuleBuilder* builder);
ShaderModule(ShaderModuleBuilder* builder);
using CombinedSamplerInfo = std::vector<CombinedSampler>;
@ -49,7 +49,6 @@ namespace opengl {
const CombinedSamplerInfo& GetCombinedSamplerInfo() const;
private:
Device* device;
CombinedSamplerInfo combinedInfo;
std::string glslSource;
};

View File

@ -40,8 +40,8 @@ namespace opengl {
// Texture
Texture::Texture(Device* device, TextureBuilder* builder)
: TextureBase(builder), device(device) {
Texture::Texture(TextureBuilder* builder)
: TextureBase(builder) {
target = TargetForDimension(GetDimension());
uint32_t width = GetWidth();
@ -81,8 +81,8 @@ namespace opengl {
// TextureView
TextureView::TextureView(Device* device, TextureViewBuilder* builder)
: TextureViewBase(builder), device(device) {
TextureView::TextureView(TextureViewBuilder* builder)
: TextureViewBase(builder) {
}
}

View File

@ -32,7 +32,7 @@ namespace opengl {
class Texture : public TextureBase {
public:
Texture(Device* device, TextureBuilder* builder);
Texture(TextureBuilder* builder);
GLuint GetHandle() const;
GLenum GetGLTarget() const;
@ -41,17 +41,13 @@ namespace opengl {
private:
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override;
Device* device;
GLuint handle;
GLenum target;
};
class TextureView : public TextureViewBase {
public:
TextureView(Device* device, TextureViewBuilder* builder);
private:
Device* device;
TextureView(TextureViewBuilder* builder);
};