Format: src/backend/opengl

This commit is contained in:
Corentin Wallez 2017-11-24 14:16:15 -05:00 committed by Corentin Wallez
parent 1aa4d5604f
commit c7807abf04
31 changed files with 821 additions and 891 deletions

View File

@ -17,8 +17,7 @@
#include "backend/opengl/OpenGLBackend.h" #include "backend/opengl/OpenGLBackend.h"
#include "common/Assert.h" #include "common/Assert.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
namespace { namespace {
GLenum GLBlendFactor(nxt::BlendFactor factor, bool alpha) { GLenum GLBlendFactor(nxt::BlendFactor factor, bool alpha) {
@ -70,7 +69,7 @@ namespace opengl {
UNREACHABLE(); UNREACHABLE();
} }
} }
} } // namespace
BlendState::BlendState(BlendStateBuilder* builder) : BlendStateBase(builder) { BlendState::BlendState(BlendStateBuilder* builder) : BlendStateBase(builder) {
} }
@ -80,17 +79,19 @@ namespace opengl {
if (info.blendEnabled) { if (info.blendEnabled) {
glEnablei(GL_BLEND, attachment); glEnablei(GL_BLEND, attachment);
glBlendEquationSeparatei(attachment, GLBlendMode(info.colorBlend.operation), GLBlendMode(info.alphaBlend.operation)); glBlendEquationSeparatei(attachment, GLBlendMode(info.colorBlend.operation),
glBlendFuncSeparatei(attachment, GLBlendFactor(info.colorBlend.srcFactor, false), GLBlendFactor(info.colorBlend.dstFactor, false), GLBlendFactor(info.alphaBlend.srcFactor, true), GLBlendFactor(info.alphaBlend.dstFactor, true)); GLBlendMode(info.alphaBlend.operation));
glColorMaski(attachment, glBlendFuncSeparatei(attachment, GLBlendFactor(info.colorBlend.srcFactor, false),
info.colorWriteMask & nxt::ColorWriteMask::Red, GLBlendFactor(info.colorBlend.dstFactor, false),
info.colorWriteMask & nxt::ColorWriteMask::Green, GLBlendFactor(info.alphaBlend.srcFactor, true),
info.colorWriteMask & nxt::ColorWriteMask::Blue, GLBlendFactor(info.alphaBlend.dstFactor, true));
info.colorWriteMask & nxt::ColorWriteMask::Alpha); glColorMaski(attachment, info.colorWriteMask & nxt::ColorWriteMask::Red,
info.colorWriteMask & nxt::ColorWriteMask::Green,
info.colorWriteMask & nxt::ColorWriteMask::Blue,
info.colorWriteMask & nxt::ColorWriteMask::Alpha);
} else { } else {
glDisablei(GL_BLEND, attachment); glDisablei(GL_BLEND, attachment);
} }
} }
} }} // namespace backend::opengl
}

View File

@ -19,17 +19,15 @@
#include "glad/glad.h" #include "glad/glad.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class BlendState : public BlendStateBase { class BlendState : public BlendStateBase {
public: public:
BlendState(BlendStateBuilder* builder); BlendState(BlendStateBuilder* builder);
void ApplyNow(uint32_t attachment); void ApplyNow(uint32_t attachment);
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_BLENDSTATED3D12_H_ #endif // BACKEND_OPENGL_BLENDSTATED3D12_H_

View File

@ -16,13 +16,11 @@
#include "backend/opengl/OpenGLBackend.h" #include "backend/opengl/OpenGLBackend.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
// Buffer // Buffer
Buffer::Buffer(BufferBuilder* builder) Buffer::Buffer(BufferBuilder* builder) : BufferBase(builder) {
: BufferBase(builder) {
glGenBuffers(1, &mBuffer); glGenBuffers(1, &mBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mBuffer); glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
glBufferData(GL_ARRAY_BUFFER, GetSize(), nullptr, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, GetSize(), nullptr, GL_STATIC_DRAW);
@ -40,7 +38,8 @@ namespace opengl {
void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) { void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
// TODO(cwallez@chromium.org): this does GPU->CPU synchronization, we could require a high // TODO(cwallez@chromium.org): this does GPU->CPU synchronization, we could require a high
// version of OpenGL that would let us map the buffer unsynchronized. // version of OpenGL that would let us map the buffer unsynchronized.
// TODO(cwallez@chromium.org): this crashes on Mac NVIDIA, use GetBufferSubData there instead? // TODO(cwallez@chromium.org): this crashes on Mac NVIDIA, use GetBufferSubData there
// instead?
glBindBuffer(GL_ARRAY_BUFFER, mBuffer); glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
void* data = glMapBufferRange(GL_ARRAY_BUFFER, start, count, GL_MAP_READ_BIT); void* data = glMapBufferRange(GL_ARRAY_BUFFER, start, count, GL_MAP_READ_BIT);
CallMapReadCallback(serial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, data); CallMapReadCallback(serial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, data);
@ -56,9 +55,7 @@ namespace opengl {
// BufferView // BufferView
BufferView::BufferView(BufferViewBuilder* builder) BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) {
: BufferViewBase(builder) {
} }
} }} // namespace backend::opengl
}

View File

@ -19,32 +19,31 @@
#include "glad/glad.h" #include "glad/glad.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class Device; class Device;
class Buffer : public BufferBase { class Buffer : public BufferBase {
public: public:
Buffer(BufferBuilder* builder); Buffer(BufferBuilder* builder);
GLuint GetHandle() const; GLuint GetHandle() const;
private: private:
void SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) override; 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 MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
void UnmapImpl() override; void UnmapImpl() override;
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override; void TransitionUsageImpl(nxt::BufferUsageBit currentUsage,
nxt::BufferUsageBit targetUsage) override;
GLuint mBuffer = 0; GLuint mBuffer = 0;
}; };
class BufferView : public BufferViewBase { class BufferView : public BufferViewBase {
public: public:
BufferView(BufferViewBuilder* builder); BufferView(BufferViewBuilder* builder);
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_BUFFERGL_H_ #endif // BACKEND_OPENGL_BUFFERGL_H_

File diff suppressed because it is too large Load Diff

View File

@ -18,23 +18,21 @@
#include "backend/CommandAllocator.h" #include "backend/CommandAllocator.h"
#include "backend/CommandBuffer.h" #include "backend/CommandBuffer.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class Device; class Device;
class CommandBuffer : public CommandBufferBase { class CommandBuffer : public CommandBufferBase {
public: public:
CommandBuffer(CommandBufferBuilder* builder); CommandBuffer(CommandBufferBuilder* builder);
~CommandBuffer(); ~CommandBuffer();
void Execute(); void Execute();
private: private:
CommandIterator mCommands; CommandIterator mCommands;
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_COMMANDBUFFERGL_H_ #endif // BACKEND_OPENGL_COMMANDBUFFERGL_H_

View File

@ -14,8 +14,7 @@
#include "backend/opengl/ComputePipelineGL.h" #include "backend/opengl/ComputePipelineGL.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
ComputePipeline::ComputePipeline(ComputePipelineBuilder* builder) ComputePipeline::ComputePipeline(ComputePipelineBuilder* builder)
: ComputePipelineBase(builder), PipelineGL(this, builder) { : ComputePipelineBase(builder), PipelineGL(this, builder) {
@ -25,5 +24,4 @@ namespace opengl {
PipelineGL::ApplyNow(); PipelineGL::ApplyNow();
} }
} }} // namespace backend::opengl
}

View File

@ -21,17 +21,15 @@
#include "glad/glad.h" #include "glad/glad.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class ComputePipeline : public ComputePipelineBase, public PipelineGL { class ComputePipeline : public ComputePipelineBase, public PipelineGL {
public: public:
ComputePipeline(ComputePipelineBuilder* builder); ComputePipeline(ComputePipelineBuilder* builder);
void ApplyNow(); void ApplyNow();
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_COMPUTEPIPELINEGL_H_ #endif // BACKEND_OPENGL_COMPUTEPIPELINEGL_H_

View File

@ -18,8 +18,7 @@
#include "backend/opengl/PersistentPipelineStateGL.h" #include "backend/opengl/PersistentPipelineStateGL.h"
#include "common/Assert.h" #include "common/Assert.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
namespace { namespace {
GLuint OpenGLCompareFunction(nxt::CompareFunction compareFunction) { GLuint OpenGLCompareFunction(nxt::CompareFunction compareFunction) {
@ -67,17 +66,18 @@ namespace opengl {
UNREACHABLE(); UNREACHABLE();
} }
} }
} } // namespace
DepthStencilState::DepthStencilState(DepthStencilStateBuilder* builder) DepthStencilState::DepthStencilState(DepthStencilStateBuilder* builder)
: DepthStencilStateBase(builder) { : DepthStencilStateBase(builder) {
} }
void DepthStencilState::ApplyNow(PersistentPipelineState &persistentPipelineState) const { void DepthStencilState::ApplyNow(PersistentPipelineState& persistentPipelineState) const {
auto& depthInfo = GetDepth(); auto& depthInfo = GetDepth();
// Depth writes only occur if depth is enabled // Depth writes only occur if depth is enabled
if (depthInfo.compareFunction == nxt::CompareFunction::Always && !depthInfo.depthWriteEnabled) { if (depthInfo.compareFunction == nxt::CompareFunction::Always &&
!depthInfo.depthWriteEnabled) {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} else { } else {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -101,22 +101,17 @@ namespace opengl {
GLenum backCompareFunction = OpenGLCompareFunction(stencilInfo.back.compareFunction); GLenum backCompareFunction = OpenGLCompareFunction(stencilInfo.back.compareFunction);
GLenum frontCompareFunction = OpenGLCompareFunction(stencilInfo.front.compareFunction); GLenum frontCompareFunction = OpenGLCompareFunction(stencilInfo.front.compareFunction);
persistentPipelineState.SetStencilFuncsAndMask(backCompareFunction, frontCompareFunction, stencilInfo.readMask); persistentPipelineState.SetStencilFuncsAndMask(backCompareFunction, frontCompareFunction,
stencilInfo.readMask);
glStencilOpSeparate(GL_BACK, glStencilOpSeparate(GL_BACK, OpenGLStencilOperation(stencilInfo.back.stencilFail),
OpenGLStencilOperation(stencilInfo.back.stencilFail), OpenGLStencilOperation(stencilInfo.back.depthFail),
OpenGLStencilOperation(stencilInfo.back.depthFail), OpenGLStencilOperation(stencilInfo.back.depthStencilPass));
OpenGLStencilOperation(stencilInfo.back.depthStencilPass) glStencilOpSeparate(GL_FRONT, OpenGLStencilOperation(stencilInfo.front.stencilFail),
); OpenGLStencilOperation(stencilInfo.front.depthFail),
glStencilOpSeparate(GL_FRONT, OpenGLStencilOperation(stencilInfo.front.depthStencilPass));
OpenGLStencilOperation(stencilInfo.front.stencilFail),
OpenGLStencilOperation(stencilInfo.front.depthFail),
OpenGLStencilOperation(stencilInfo.front.depthStencilPass)
);
glStencilMask(stencilInfo.writeMask); glStencilMask(stencilInfo.writeMask);
} }
} }} // namespace backend::opengl
}

View File

@ -17,20 +17,18 @@
#include "backend/DepthStencilState.h" #include "backend/DepthStencilState.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class Device; class Device;
class PersistentPipelineState; class PersistentPipelineState;
class DepthStencilState : public DepthStencilStateBase { class DepthStencilState : public DepthStencilStateBase {
public: public:
DepthStencilState(DepthStencilStateBuilder* builder); DepthStencilState(DepthStencilStateBuilder* builder);
void ApplyNow(PersistentPipelineState &persistentPipelineState) const; void ApplyNow(PersistentPipelineState& persistentPipelineState) const;
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_DEPTHSTENCILSTATEGL_H_ #endif // BACKEND_OPENGL_DEPTHSTENCILSTATEGL_H_

View File

@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "backend/opengl/OpenGLBackend.h"
#include "backend/opengl/BlendStateGL.h" #include "backend/opengl/BlendStateGL.h"
#include "backend/opengl/BufferGL.h" #include "backend/opengl/BufferGL.h"
#include "backend/opengl/CommandBufferGL.h" #include "backend/opengl/CommandBufferGL.h"
#include "backend/opengl/ComputePipelineGL.h" #include "backend/opengl/ComputePipelineGL.h"
#include "backend/opengl/DepthStencilStateGL.h" #include "backend/opengl/DepthStencilStateGL.h"
#include "backend/opengl/InputStateGL.h" #include "backend/opengl/InputStateGL.h"
#include "backend/opengl/OpenGLBackend.h"
#include "backend/opengl/PersistentPipelineStateGL.h" #include "backend/opengl/PersistentPipelineStateGL.h"
#include "backend/opengl/PipelineLayoutGL.h" #include "backend/opengl/PipelineLayoutGL.h"
#include "backend/opengl/RenderPipelineGL.h" #include "backend/opengl/RenderPipelineGL.h"

View File

@ -17,11 +17,9 @@
#include "backend/opengl/OpenGLBackend.h" #include "backend/opengl/OpenGLBackend.h"
#include "common/Assert.h" #include "common/Assert.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
InputState::InputState(InputStateBuilder* builder) InputState::InputState(InputStateBuilder* builder) : InputStateBase(builder) {
: InputStateBase(builder) {
glGenVertexArrays(1, &mVertexArrayObject); glGenVertexArrays(1, &mVertexArrayObject);
glBindVertexArray(mVertexArrayObject); glBindVertexArray(mVertexArrayObject);
auto& attributesSetMask = GetAttributesSetMask(); auto& attributesSetMask = GetAttributesSetMask();
@ -61,5 +59,4 @@ namespace opengl {
return mVertexArrayObject; return mVertexArrayObject;
} }
} }} // namespace backend::opengl
}

View File

@ -19,24 +19,22 @@
#include "glad/glad.h" #include "glad/glad.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class Device; class Device;
class InputState : public InputStateBase { class InputState : public InputStateBase {
public: public:
InputState(InputStateBuilder* builder); InputState(InputStateBuilder* builder);
std::bitset<kMaxVertexAttributes> GetAttributesUsingInput(uint32_t slot) const; std::bitset<kMaxVertexAttributes> GetAttributesUsingInput(uint32_t slot) const;
GLuint GetVAO(); GLuint GetVAO();
private: private:
GLuint mVertexArrayObject; GLuint mVertexArrayObject;
std::array<std::bitset<kMaxVertexAttributes>, kMaxVertexInputs> attributesUsingInput; std::array<std::bitset<kMaxVertexAttributes>, kMaxVertexInputs> attributesUsingInput;
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_INPUTSTATEGL_H_ #endif // BACKEND_OPENGL_INPUTSTATEGL_H_

View File

@ -22,13 +22,12 @@
#include "backend/opengl/InputStateGL.h" #include "backend/opengl/InputStateGL.h"
#include "backend/opengl/PipelineLayoutGL.h" #include "backend/opengl/PipelineLayoutGL.h"
#include "backend/opengl/RenderPipelineGL.h" #include "backend/opengl/RenderPipelineGL.h"
#include "backend/opengl/SamplerGL.h"
#include "backend/opengl/ShaderModuleGL.h" #include "backend/opengl/ShaderModuleGL.h"
#include "backend/opengl/SwapChainGL.h" #include "backend/opengl/SwapChainGL.h"
#include "backend/opengl/SamplerGL.h"
#include "backend/opengl/TextureGL.h" #include "backend/opengl/TextureGL.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
nxtProcTable GetNonValidatingProcs(); nxtProcTable GetNonValidatingProcs();
nxtProcTable GetValidatingProcs(); nxtProcTable GetValidatingProcs();
@ -109,8 +108,7 @@ namespace opengl {
// Bind Group // Bind Group
BindGroup::BindGroup(BindGroupBuilder* builder) BindGroup::BindGroup(BindGroupBuilder* builder) : BindGroupBase(builder) {
: BindGroupBase(builder) {
} }
// Bind Group Layout // Bind Group Layout
@ -121,17 +119,15 @@ namespace opengl {
// Framebuffer // Framebuffer
Framebuffer::Framebuffer(FramebufferBuilder* builder) Framebuffer::Framebuffer(FramebufferBuilder* builder) : FramebufferBase(builder) {
: FramebufferBase(builder) {
} }
// Queue // Queue
Queue::Queue(QueueBuilder* builder) Queue::Queue(QueueBuilder* builder) : QueueBase(builder) {
: QueueBase(builder) {
} }
void Queue::Submit(uint32_t numCommands, CommandBuffer* const * commands) { void Queue::Submit(uint32_t numCommands, CommandBuffer* const* commands) {
for (uint32_t i = 0; i < numCommands; ++i) { for (uint32_t i = 0; i < numCommands; ++i) {
commands[i]->Execute(); commands[i]->Execute();
} }
@ -139,9 +135,7 @@ namespace opengl {
// RenderPass // RenderPass
RenderPass::RenderPass(RenderPassBuilder* builder) RenderPass::RenderPass(RenderPassBuilder* builder) : RenderPassBase(builder) {
: RenderPassBase(builder) {
} }
} }} // namespace backend::opengl
}

View File

@ -17,12 +17,12 @@
#include "nxt/nxtcpp.h" #include "nxt/nxtcpp.h"
#include "backend/Buffer.h"
#include "backend/BlendState.h"
#include "backend/BindGroup.h" #include "backend/BindGroup.h"
#include "backend/BindGroupLayout.h" #include "backend/BindGroupLayout.h"
#include "backend/Device.h" #include "backend/BlendState.h"
#include "backend/Buffer.h"
#include "backend/DepthStencilState.h" #include "backend/DepthStencilState.h"
#include "backend/Device.h"
#include "backend/Framebuffer.h" #include "backend/Framebuffer.h"
#include "backend/InputState.h" #include "backend/InputState.h"
#include "backend/Queue.h" #include "backend/Queue.h"
@ -31,8 +31,7 @@
#include "glad/glad.h" #include "glad/glad.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class BindGroup; class BindGroup;
class BindGroupLayout; class BindGroupLayout;
@ -79,66 +78,65 @@ namespace opengl {
using TextureViewType = TextureView; using TextureViewType = TextureView;
}; };
template<typename T> template <typename T>
auto ToBackend(T&& common) -> decltype(ToBackendBase<OpenGLBackendTraits>(common)) { auto ToBackend(T&& common) -> decltype(ToBackendBase<OpenGLBackendTraits>(common)) {
return ToBackendBase<OpenGLBackendTraits>(common); return ToBackendBase<OpenGLBackendTraits>(common);
} }
// Definition of backend types // Definition of backend types
class Device : public DeviceBase { class Device : public DeviceBase {
public: public:
BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) override; BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) override;
BindGroupLayoutBase* CreateBindGroupLayout(BindGroupLayoutBuilder* builder) override; BindGroupLayoutBase* CreateBindGroupLayout(BindGroupLayoutBuilder* builder) override;
BlendStateBase* CreateBlendState(BlendStateBuilder* builder) override; BlendStateBase* CreateBlendState(BlendStateBuilder* builder) override;
BufferBase* CreateBuffer(BufferBuilder* builder) override; BufferBase* CreateBuffer(BufferBuilder* builder) override;
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override; BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override; CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
ComputePipelineBase* CreateComputePipeline(ComputePipelineBuilder* builder) override; ComputePipelineBase* CreateComputePipeline(ComputePipelineBuilder* builder) override;
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override; DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
InputStateBase* CreateInputState(InputStateBuilder* builder) override; InputStateBase* CreateInputState(InputStateBuilder* builder) override;
FramebufferBase* CreateFramebuffer(FramebufferBuilder* builder) override; FramebufferBase* CreateFramebuffer(FramebufferBuilder* builder) override;
PipelineLayoutBase* CreatePipelineLayout(PipelineLayoutBuilder* builder) override; PipelineLayoutBase* CreatePipelineLayout(PipelineLayoutBuilder* builder) override;
QueueBase* CreateQueue(QueueBuilder* builder) override; QueueBase* CreateQueue(QueueBuilder* builder) override;
RenderPassBase* CreateRenderPass(RenderPassBuilder* builder) override; RenderPassBase* CreateRenderPass(RenderPassBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override; RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
SamplerBase* CreateSampler(SamplerBuilder* builder) override; SamplerBase* CreateSampler(SamplerBuilder* builder) override;
ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) override; ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) override;
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override; SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
TextureBase* CreateTexture(TextureBuilder* builder) override; TextureBase* CreateTexture(TextureBuilder* builder) override;
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override; TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
void TickImpl() override; void TickImpl() override;
}; };
class BindGroup : public BindGroupBase { class BindGroup : public BindGroupBase {
public: public:
BindGroup(BindGroupBuilder* builder); BindGroup(BindGroupBuilder* builder);
}; };
class BindGroupLayout : public BindGroupLayoutBase { class BindGroupLayout : public BindGroupLayoutBase {
public: public:
BindGroupLayout(BindGroupLayoutBuilder* builder); BindGroupLayout(BindGroupLayoutBuilder* builder);
}; };
class Framebuffer : public FramebufferBase { class Framebuffer : public FramebufferBase {
public: public:
Framebuffer(FramebufferBuilder* builder); Framebuffer(FramebufferBuilder* builder);
}; };
class Queue : public QueueBase { class Queue : public QueueBase {
public: public:
Queue(QueueBuilder* builder); Queue(QueueBuilder* builder);
// NXT API // NXT API
void Submit(uint32_t numCommands, CommandBuffer* const * commands); void Submit(uint32_t numCommands, CommandBuffer* const* commands);
}; };
class RenderPass : public RenderPassBase { class RenderPass : public RenderPassBase {
public: public:
RenderPass(RenderPassBuilder* builder); RenderPass(RenderPassBuilder* builder);
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_OPENGLBACKEND_H_ #endif // BACKEND_OPENGL_OPENGLBACKEND_H_

View File

@ -16,14 +16,15 @@
#include "backend/opengl/OpenGLBackend.h" #include "backend/opengl/OpenGLBackend.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
void PersistentPipelineState::SetDefaultState() { void PersistentPipelineState::SetDefaultState() {
CallGLStencilFunc(); CallGLStencilFunc();
} }
void PersistentPipelineState::SetStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask) { void PersistentPipelineState::SetStencilFuncsAndMask(GLenum stencilBackCompareFunction,
GLenum stencilFrontCompareFunction,
uint32_t stencilReadMask) {
if (mStencilBackCompareFunction == stencilBackCompareFunction && if (mStencilBackCompareFunction == stencilBackCompareFunction &&
mStencilFrontCompareFunction == stencilFrontCompareFunction && mStencilFrontCompareFunction == stencilFrontCompareFunction &&
mStencilReadMask == stencilReadMask) { mStencilReadMask == stencilReadMask) {
@ -46,15 +47,10 @@ namespace opengl {
} }
void PersistentPipelineState::CallGLStencilFunc() { void PersistentPipelineState::CallGLStencilFunc() {
glStencilFuncSeparate(GL_BACK, glStencilFuncSeparate(GL_BACK, mStencilBackCompareFunction, mStencilReference,
mStencilBackCompareFunction, mStencilReadMask);
mStencilReference, glStencilFuncSeparate(GL_FRONT, mStencilFrontCompareFunction, mStencilReference,
mStencilReadMask); mStencilReadMask);
glStencilFuncSeparate(GL_FRONT,
mStencilFrontCompareFunction,
mStencilReference,
mStencilReadMask);
} }
} }} // namespace backend::opengl
}

View File

@ -19,25 +19,25 @@
#include "glad/glad.h" #include "glad/glad.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class PersistentPipelineState { class PersistentPipelineState {
public: public:
void SetDefaultState(); void SetDefaultState();
void SetStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask); void SetStencilFuncsAndMask(GLenum stencilBackCompareFunction,
void SetStencilReference(uint32_t stencilReference); GLenum stencilFrontCompareFunction,
uint32_t stencilReadMask);
void SetStencilReference(uint32_t stencilReference);
private: private:
void CallGLStencilFunc(); void CallGLStencilFunc();
GLenum mStencilBackCompareFunction = GL_ALWAYS; GLenum mStencilBackCompareFunction = GL_ALWAYS;
GLenum mStencilFrontCompareFunction = GL_ALWAYS; GLenum mStencilFrontCompareFunction = GL_ALWAYS;
GLuint mStencilReadMask = 0xffffffff; GLuint mStencilReadMask = 0xffffffff;
GLuint mStencilReference = 0; GLuint mStencilReference = 0;
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_PERSISTENTPIPELINESTATE_H_ #endif // BACKEND_OPENGL_PERSISTENTPIPELINESTATE_H_

View File

@ -22,8 +22,7 @@
#include <iostream> #include <iostream>
#include <set> #include <set>
namespace backend { namespace backend { namespace opengl {
namespace opengl {
namespace { namespace {
@ -40,7 +39,7 @@ namespace opengl {
} }
} }
} } // namespace
PipelineGL::PipelineGL(PipelineBase* parent, PipelineBuilder* builder) { PipelineGL::PipelineGL(PipelineBase* parent, PipelineBuilder* builder) {
auto CreateShader = [](GLenum type, const char* source) -> GLuint { auto CreateShader = [](GLenum type, const char* source) -> GLuint {
@ -65,7 +64,8 @@ namespace opengl {
return shader; return shader;
}; };
auto FillPushConstants = [](const ShaderModule* module, GLPushConstantInfo* info, GLuint program) { auto FillPushConstants = [](const ShaderModule* module, GLPushConstantInfo* info,
GLuint program) {
const auto& moduleInfo = module->GetPushConstants(); const auto& moduleInfo = module->GetPushConstants();
for (uint32_t i = 0; i < moduleInfo.names.size(); i++) { for (uint32_t i = 0; i < moduleInfo.names.size(); i++) {
(*info)[i] = -1; (*info)[i] = -1;
@ -119,7 +119,8 @@ namespace opengl {
glUseProgram(mProgram); glUseProgram(mProgram);
// The uniforms are part of the program state so we can pre-bind buffer units, texture units etc. // The uniforms are part of the program state so we can pre-bind buffer units, texture units
// etc.
const auto& layout = ToBackend(parent->GetLayout()); const auto& layout = ToBackend(parent->GetLayout());
const auto& indices = layout->GetBindingIndexInfo(); const auto& indices = layout->GetBindingIndexInfo();
@ -133,25 +134,22 @@ namespace opengl {
std::string name = GetBindingName(group, binding); std::string name = GetBindingName(group, binding);
switch (groupInfo.types[binding]) { switch (groupInfo.types[binding]) {
case nxt::BindingType::UniformBuffer: case nxt::BindingType::UniformBuffer: {
{ GLint location = glGetUniformBlockIndex(mProgram, name.c_str());
GLint location = glGetUniformBlockIndex(mProgram, name.c_str()); glUniformBlockBinding(mProgram, location, indices[group][binding]);
glUniformBlockBinding(mProgram, location, indices[group][binding]); } break;
}
break;
case nxt::BindingType::StorageBuffer: case nxt::BindingType::StorageBuffer: {
{ GLuint location = glGetProgramResourceIndex(
GLuint location = glGetProgramResourceIndex(mProgram, GL_SHADER_STORAGE_BLOCK, name.c_str()); mProgram, GL_SHADER_STORAGE_BLOCK, name.c_str());
glShaderStorageBlockBinding(mProgram, location, indices[group][binding]); glShaderStorageBlockBinding(mProgram, location, indices[group][binding]);
} } break;
break;
case nxt::BindingType::Sampler: case nxt::BindingType::Sampler:
case nxt::BindingType::SampledTexture: case nxt::BindingType::SampledTexture:
// These binding types are handled in the separate sampler and texture emulation // These binding types are handled in the separate sampler and texture
// emulation
break; break;
} }
} }
} }
@ -176,18 +174,21 @@ namespace opengl {
GLint location = glGetUniformLocation(mProgram, name.c_str()); GLint location = glGetUniformLocation(mProgram, name.c_str());
glUniform1i(location, textureUnit); glUniform1i(location, textureUnit);
GLuint samplerIndex = indices[combined.samplerLocation.group][combined.samplerLocation.binding]; GLuint samplerIndex =
indices[combined.samplerLocation.group][combined.samplerLocation.binding];
mUnitsForSamplers[samplerIndex].push_back(textureUnit); mUnitsForSamplers[samplerIndex].push_back(textureUnit);
GLuint textureIndex = indices[combined.textureLocation.group][combined.textureLocation.binding]; GLuint textureIndex =
indices[combined.textureLocation.group][combined.textureLocation.binding];
mUnitsForTextures[textureIndex].push_back(textureUnit); mUnitsForTextures[textureIndex].push_back(textureUnit);
textureUnit ++; textureUnit++;
} }
} }
} }
const PipelineGL::GLPushConstantInfo& PipelineGL::GetGLPushConstants(nxt::ShaderStage stage) const { const PipelineGL::GLPushConstantInfo& PipelineGL::GetGLPushConstants(
nxt::ShaderStage stage) const {
return mGlPushConstants[stage]; return mGlPushConstants[stage];
} }
@ -209,5 +210,4 @@ namespace opengl {
glUseProgram(mProgram); glUseProgram(mProgram);
} }
} }} // namespace backend::opengl
}

View File

@ -21,35 +21,34 @@
#include <vector> #include <vector>
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class Device; class Device;
class PersistentPipelineState; class PersistentPipelineState;
class ShaderModule; class ShaderModule;
class PipelineGL { class PipelineGL {
public: public:
PipelineGL(PipelineBase* parent, PipelineBuilder* builder); PipelineGL(PipelineBase* parent, PipelineBuilder* builder);
using GLPushConstantInfo = std::array<GLint, kMaxPushConstants>; using GLPushConstantInfo = std::array<GLint, kMaxPushConstants>;
using BindingLocations = std::array<std::array<GLint, kMaxBindingsPerGroup>, kMaxBindGroups>; using BindingLocations =
std::array<std::array<GLint, kMaxBindingsPerGroup>, kMaxBindGroups>;
const GLPushConstantInfo& GetGLPushConstants(nxt::ShaderStage stage) const; const GLPushConstantInfo& GetGLPushConstants(nxt::ShaderStage stage) const;
const std::vector<GLuint>& GetTextureUnitsForSampler(GLuint index) const; const std::vector<GLuint>& GetTextureUnitsForSampler(GLuint index) const;
const std::vector<GLuint>& GetTextureUnitsForTexture(GLuint index) const; const std::vector<GLuint>& GetTextureUnitsForTexture(GLuint index) const;
GLuint GetProgramHandle() const; GLuint GetProgramHandle() const;
void ApplyNow(); void ApplyNow();
private: private:
GLuint mProgram; GLuint mProgram;
PerStage<GLPushConstantInfo> mGlPushConstants; PerStage<GLPushConstantInfo> mGlPushConstants;
std::vector<std::vector<GLuint>> mUnitsForSamplers; std::vector<std::vector<GLuint>> mUnitsForSamplers;
std::vector<std::vector<GLuint>> mUnitsForTextures; std::vector<std::vector<GLuint>> mUnitsForTextures;
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_PIPELINEGL_H_ #endif // BACKEND_OPENGL_PIPELINEGL_H_

View File

@ -16,11 +16,9 @@
#include "backend/opengl/OpenGLBackend.h" #include "backend/opengl/OpenGLBackend.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
PipelineLayout::PipelineLayout(PipelineLayoutBuilder* builder) PipelineLayout::PipelineLayout(PipelineLayoutBuilder* builder) : PipelineLayoutBase(builder) {
: PipelineLayoutBase(builder) {
GLuint uboIndex = 0; GLuint uboIndex = 0;
GLuint samplerIndex = 0; GLuint samplerIndex = 0;
GLuint sampledTextureIndex = 0; GLuint sampledTextureIndex = 0;
@ -37,20 +35,20 @@ namespace opengl {
switch (groupInfo.types[binding]) { switch (groupInfo.types[binding]) {
case nxt::BindingType::UniformBuffer: case nxt::BindingType::UniformBuffer:
mIndexInfo[group][binding] = uboIndex; mIndexInfo[group][binding] = uboIndex;
uboIndex ++; uboIndex++;
break; break;
case nxt::BindingType::Sampler: case nxt::BindingType::Sampler:
mIndexInfo[group][binding] = samplerIndex; mIndexInfo[group][binding] = samplerIndex;
samplerIndex ++; samplerIndex++;
break; break;
case nxt::BindingType::SampledTexture: case nxt::BindingType::SampledTexture:
mIndexInfo[group][binding] = sampledTextureIndex; mIndexInfo[group][binding] = sampledTextureIndex;
sampledTextureIndex ++; sampledTextureIndex++;
break; break;
case nxt::BindingType::StorageBuffer: case nxt::BindingType::StorageBuffer:
mIndexInfo[group][binding] = ssboIndex; mIndexInfo[group][binding] = ssboIndex;
ssboIndex ++; ssboIndex++;
break; break;
} }
} }
@ -76,5 +74,4 @@ namespace opengl {
return mNumSampledTextures; return mNumSampledTextures;
} }
} }} // namespace backend::opengl
}

View File

@ -19,29 +19,28 @@
#include "glad/glad.h" #include "glad/glad.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class Device; class Device;
class PipelineLayout : public PipelineLayoutBase { class PipelineLayout : public PipelineLayoutBase {
public: public:
PipelineLayout(PipelineLayoutBuilder* builder); PipelineLayout(PipelineLayoutBuilder* builder);
using BindingIndexInfo = std::array<std::array<GLuint, kMaxBindingsPerGroup>, kMaxBindGroups>; using BindingIndexInfo =
const BindingIndexInfo& GetBindingIndexInfo() const; std::array<std::array<GLuint, kMaxBindingsPerGroup>, kMaxBindGroups>;
const BindingIndexInfo& GetBindingIndexInfo() const;
GLuint GetTextureUnitsUsed() const; GLuint GetTextureUnitsUsed() const;
size_t GetNumSamplers() const; size_t GetNumSamplers() const;
size_t GetNumSampledTextures() const; size_t GetNumSampledTextures() const;
private: private:
BindingIndexInfo mIndexInfo; BindingIndexInfo mIndexInfo;
size_t mNumSamplers; size_t mNumSamplers;
size_t mNumSampledTextures; size_t mNumSampledTextures;
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_PIPELINELAYOUTGL_H_ #endif // BACKEND_OPENGL_PIPELINELAYOUTGL_H_

View File

@ -20,8 +20,7 @@
#include "backend/opengl/OpenGLBackend.h" #include "backend/opengl/OpenGLBackend.h"
#include "backend/opengl/PersistentPipelineStateGL.h" #include "backend/opengl/PersistentPipelineStateGL.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
namespace { namespace {
GLenum GLPrimitiveTopology(nxt::PrimitiveTopology primitiveTopology) { GLenum GLPrimitiveTopology(nxt::PrimitiveTopology primitiveTopology) {
@ -40,10 +39,11 @@ namespace opengl {
UNREACHABLE(); UNREACHABLE();
} }
} }
} } // namespace
RenderPipeline::RenderPipeline(RenderPipelineBuilder* builder) RenderPipeline::RenderPipeline(RenderPipelineBuilder* builder)
: RenderPipelineBase(builder), PipelineGL(this, builder), : RenderPipelineBase(builder),
PipelineGL(this, builder),
mGlPrimitiveTopology(GLPrimitiveTopology(GetPrimitiveTopology())) { mGlPrimitiveTopology(GLPrimitiveTopology(GetPrimitiveTopology())) {
} }
@ -51,7 +51,7 @@ namespace opengl {
return mGlPrimitiveTopology; return mGlPrimitiveTopology;
} }
void RenderPipeline::ApplyNow(PersistentPipelineState &persistentPipelineState) { void RenderPipeline::ApplyNow(PersistentPipelineState& persistentPipelineState) {
PipelineGL::ApplyNow(); PipelineGL::ApplyNow();
auto inputState = ToBackend(GetInputState()); auto inputState = ToBackend(GetInputState());
@ -68,5 +68,4 @@ namespace opengl {
} }
} }
} }} // namespace backend::opengl
}

View File

@ -23,24 +23,22 @@
#include <vector> #include <vector>
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class PersistentPipelineState; class PersistentPipelineState;
class RenderPipeline : public RenderPipelineBase, public PipelineGL { class RenderPipeline : public RenderPipelineBase, public PipelineGL {
public: public:
RenderPipeline(RenderPipelineBuilder* builder); RenderPipeline(RenderPipelineBuilder* builder);
GLenum GetGLPrimitiveTopology() const; GLenum GetGLPrimitiveTopology() const;
void ApplyNow(PersistentPipelineState &persistentPipelineState); void ApplyNow(PersistentPipelineState& persistentPipelineState);
private: private:
GLenum mGlPrimitiveTopology; GLenum mGlPrimitiveTopology;
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_RENDERPIPELINEGL_H_ #endif // BACKEND_OPENGL_RENDERPIPELINEGL_H_

View File

@ -16,8 +16,7 @@
#include "common/Assert.h" #include "common/Assert.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
namespace { namespace {
GLenum MagFilterMode(nxt::FilterMode filter) { GLenum MagFilterMode(nxt::FilterMode filter) {
@ -55,18 +54,17 @@ namespace opengl {
UNREACHABLE(); UNREACHABLE();
} }
} }
} } // namespace
Sampler::Sampler(SamplerBuilder* builder) Sampler::Sampler(SamplerBuilder* builder) : SamplerBase(builder) {
: SamplerBase(builder) {
glGenSamplers(1, &mHandle); glGenSamplers(1, &mHandle);
glSamplerParameteri(mHandle, GL_TEXTURE_MAG_FILTER, MagFilterMode(builder->GetMagFilter())); glSamplerParameteri(mHandle, GL_TEXTURE_MAG_FILTER, MagFilterMode(builder->GetMagFilter()));
glSamplerParameteri(mHandle, GL_TEXTURE_MIN_FILTER, MinFilterMode(builder->GetMinFilter(), builder->GetMipMapFilter())); glSamplerParameteri(mHandle, GL_TEXTURE_MIN_FILTER,
MinFilterMode(builder->GetMinFilter(), builder->GetMipMapFilter()));
} }
GLuint Sampler::GetHandle() const { GLuint Sampler::GetHandle() const {
return mHandle; return mHandle;
} }
} }} // namespace backend::opengl
}

View File

@ -19,22 +19,20 @@
#include "glad/glad.h" #include "glad/glad.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class Device; class Device;
class Sampler : public SamplerBase { class Sampler : public SamplerBase {
public: public:
Sampler(SamplerBuilder* builder); Sampler(SamplerBuilder* builder);
GLuint GetHandle() const; GLuint GetHandle() const;
private: private:
GLuint mHandle; GLuint mHandle;
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_SAMPLERGL_H_ #endif // BACKEND_OPENGL_SAMPLERGL_H_

View File

@ -21,8 +21,7 @@
#include <sstream> #include <sstream>
namespace backend { namespace backend { namespace opengl {
namespace opengl {
std::string GetBindingName(uint32_t group, uint32_t binding) { std::string GetBindingName(uint32_t group, uint32_t binding) {
std::ostringstream o; std::ostringstream o;
@ -30,12 +29,13 @@ namespace opengl {
return o.str(); return o.str();
} }
bool operator < (const BindingLocation& a, const BindingLocation& b) { bool operator<(const BindingLocation& a, const BindingLocation& b) {
return std::tie(a.group, a.binding) < std::tie(b.group, b.binding); return std::tie(a.group, a.binding) < std::tie(b.group, b.binding);
} }
bool operator < (const CombinedSampler& a, const CombinedSampler& b) { bool operator<(const CombinedSampler& a, const CombinedSampler& b) {
return std::tie(a.samplerLocation, a.textureLocation) < std::tie(b.samplerLocation, b.textureLocation); return std::tie(a.samplerLocation, a.textureLocation) <
std::tie(b.samplerLocation, b.textureLocation);
} }
std::string CombinedSampler::GetName() const { std::string CombinedSampler::GetName() const {
@ -46,8 +46,7 @@ namespace opengl {
return o.str(); return o.str();
} }
ShaderModule::ShaderModule(ShaderModuleBuilder* builder) ShaderModule::ShaderModule(ShaderModuleBuilder* builder) : ShaderModuleBase(builder) {
: ShaderModuleBase(builder) {
spirv_cross::CompilerGLSL compiler(builder->AcquireSpirv()); spirv_cross::CompilerGLSL compiler(builder->AcquireSpirv());
spirv_cross::CompilerGLSL::Options options; spirv_cross::CompilerGLSL::Options options;
@ -60,8 +59,8 @@ namespace opengl {
options.vertex.flip_vert_y = true; options.vertex.flip_vert_y = true;
compiler.set_options(options); compiler.set_options(options);
// Rename the push constant block to be prefixed with the shader stage type so that uniform names // Rename the push constant block to be prefixed with the shader stage type so that uniform
// don't match between the FS and the VS. // names don't match between the FS and the VS.
const auto& resources = compiler.get_shader_resources(); const auto& resources = compiler.get_shader_resources();
if (resources.push_constant_buffers.size() > 0) { if (resources.push_constant_buffers.size() > 0) {
const char* prefix = nullptr; const char* prefix = nullptr;
@ -95,10 +94,14 @@ namespace opengl {
mCombinedInfo.emplace_back(); mCombinedInfo.emplace_back();
auto& info = mCombinedInfo.back(); auto& info = mCombinedInfo.back();
info.samplerLocation.group = compiler.get_decoration(combined.sampler_id, spv::DecorationDescriptorSet); info.samplerLocation.group =
info.samplerLocation.binding = compiler.get_decoration(combined.sampler_id, spv::DecorationBinding); compiler.get_decoration(combined.sampler_id, spv::DecorationDescriptorSet);
info.textureLocation.group = compiler.get_decoration(combined.image_id, spv::DecorationDescriptorSet); info.samplerLocation.binding =
info.textureLocation.binding = compiler.get_decoration(combined.image_id, spv::DecorationBinding); compiler.get_decoration(combined.sampler_id, spv::DecorationBinding);
info.textureLocation.group =
compiler.get_decoration(combined.image_id, spv::DecorationDescriptorSet);
info.textureLocation.binding =
compiler.get_decoration(combined.image_id, spv::DecorationBinding);
compiler.set_name(combined.combined_id, info.GetName()); compiler.set_name(combined.combined_id, info.GetName());
} }
@ -127,5 +130,4 @@ namespace opengl {
return mCombinedInfo; return mCombinedInfo;
} }
} }} // namespace backend::opengl
}

View File

@ -19,8 +19,7 @@
#include "glad/glad.h" #include "glad/glad.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class Device; class Device;
@ -30,30 +29,29 @@ namespace opengl {
uint32_t group; uint32_t group;
uint32_t binding; uint32_t binding;
}; };
bool operator < (const BindingLocation& a, const BindingLocation& b); bool operator<(const BindingLocation& a, const BindingLocation& b);
struct CombinedSampler { struct CombinedSampler {
BindingLocation samplerLocation; BindingLocation samplerLocation;
BindingLocation textureLocation; BindingLocation textureLocation;
std::string GetName() const; std::string GetName() const;
}; };
bool operator < (const CombinedSampler& a, const CombinedSampler& b); bool operator<(const CombinedSampler& a, const CombinedSampler& b);
class ShaderModule : public ShaderModuleBase { class ShaderModule : public ShaderModuleBase {
public: public:
ShaderModule(ShaderModuleBuilder* builder); ShaderModule(ShaderModuleBuilder* builder);
using CombinedSamplerInfo = std::vector<CombinedSampler>; using CombinedSamplerInfo = std::vector<CombinedSampler>;
const char* GetSource() const; const char* GetSource() const;
const CombinedSamplerInfo& GetCombinedSamplerInfo() const; const CombinedSamplerInfo& GetCombinedSamplerInfo() const;
private: private:
CombinedSamplerInfo mCombinedInfo; CombinedSamplerInfo mCombinedInfo;
std::string mGlslSource; std::string mGlslSource;
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_SHADERMODULEGL_H_ #endif // BACKEND_OPENGL_SHADERMODULEGL_H_

View File

@ -19,11 +19,9 @@
#include <nxt/nxt_wsi.h> #include <nxt/nxt_wsi.h>
namespace backend { namespace backend { namespace opengl {
namespace opengl {
SwapChain::SwapChain(SwapChainBuilder* builder) SwapChain::SwapChain(SwapChainBuilder* builder) : SwapChainBase(builder) {
: SwapChainBase(builder) {
const auto& im = GetImplementation(); const auto& im = GetImplementation();
im.Init(im.userData, nullptr); im.Init(im.userData, nullptr);
} }
@ -43,5 +41,4 @@ namespace opengl {
return new Texture(builder, nativeTexture); return new Texture(builder, nativeTexture);
} }
} }} // namespace backend::opengl
}

View File

@ -19,21 +19,19 @@
#include "glad/glad.h" #include "glad/glad.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class Device; class Device;
class SwapChain : public SwapChainBase { class SwapChain : public SwapChainBase {
public: public:
SwapChain(SwapChainBuilder* builder); SwapChain(SwapChainBuilder* builder);
~SwapChain(); ~SwapChain();
protected: protected:
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override; TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
}; };
} }} // namespace backend::opengl
}
#endif // BACKEND_OPENGL_SWAPCHAINGL_H_ #endif // BACKEND_OPENGL_SWAPCHAINGL_H_

View File

@ -19,8 +19,7 @@
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
namespace backend { namespace backend { namespace opengl {
namespace opengl {
namespace { namespace {
@ -43,7 +42,8 @@ namespace opengl {
// This doesn't have an enum for the internal format in OpenGL. // This doesn't have an enum for the internal format in OpenGL.
return {GL_NONE, GL_BGRA, GL_UNSIGNED_BYTE}; return {GL_NONE, GL_BGRA, GL_UNSIGNED_BYTE};
case nxt::TextureFormat::D32FloatS8Uint: case nxt::TextureFormat::D32FloatS8Uint:
return {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV}; return {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL,
GL_FLOAT_32_UNSIGNED_INT_24_8_REV};
default: default:
UNREACHABLE(); UNREACHABLE();
} }
@ -55,12 +55,11 @@ namespace opengl {
return handle; return handle;
} }
} } // namespace
// Texture // Texture
Texture::Texture(TextureBuilder* builder) Texture::Texture(TextureBuilder* builder) : Texture(builder, GenTexture()) {
: Texture(builder, GenTexture()) {
} }
Texture::Texture(TextureBuilder* builder, GLuint handle) Texture::Texture(TextureBuilder* builder, GLuint handle)
@ -76,7 +75,8 @@ namespace opengl {
glBindTexture(mTarget, handle); glBindTexture(mTarget, handle);
for (uint32_t i = 0; i < levels; ++i) { for (uint32_t i = 0; i < levels; ++i) {
glTexImage2D(mTarget, i, formatInfo.internalFormat, width, height, 0, formatInfo.format, formatInfo.type, nullptr); glTexImage2D(mTarget, i, formatInfo.internalFormat, width, height, 0, formatInfo.format,
formatInfo.type, nullptr);
width = std::max(uint32_t(1), width / 2); width = std::max(uint32_t(1), width / 2);
height = std::max(uint32_t(1), height / 2); height = std::max(uint32_t(1), height / 2);
} }
@ -87,7 +87,8 @@ namespace opengl {
} }
Texture::~Texture() { Texture::~Texture() {
// TODO(kainino@chromium.org): delete texture (but only when not using the native texture constructor?) // TODO(kainino@chromium.org): delete texture (but only when not using the native texture
// constructor?)
} }
GLuint Texture::GetHandle() const { GLuint Texture::GetHandle() const {
@ -107,9 +108,7 @@ namespace opengl {
// TextureView // TextureView
TextureView::TextureView(TextureViewBuilder* builder) TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) {
: TextureViewBase(builder) {
} }
} }} // namespace backend::opengl
}

View File

@ -19,8 +19,7 @@
#include "glad/glad.h" #include "glad/glad.h"
namespace backend { namespace backend { namespace opengl {
namespace opengl {
class Device; class Device;
@ -31,29 +30,28 @@ namespace opengl {
}; };
class Texture : public TextureBase { class Texture : public TextureBase {
public: public:
Texture(TextureBuilder* builder); Texture(TextureBuilder* builder);
Texture(TextureBuilder* builder, GLuint handle); Texture(TextureBuilder* builder, GLuint handle);
~Texture(); ~Texture();
GLuint GetHandle() const; GLuint GetHandle() const;
GLenum GetGLTarget() const; GLenum GetGLTarget() const;
TextureFormatInfo GetGLFormat() const; TextureFormatInfo GetGLFormat() const;
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override; void TransitionUsageImpl(nxt::TextureUsageBit currentUsage,
nxt::TextureUsageBit targetUsage) override;
private: private:
GLuint mHandle; GLuint mHandle;
GLenum mTarget; GLenum mTarget;
}; };
class TextureView : public TextureViewBase { class TextureView : public TextureViewBase {
public: public:
TextureView(TextureViewBuilder* builder); TextureView(TextureViewBuilder* builder);
}; };
}} // namespace backend::opengl
} #endif // BACKEND_OPENGL_TEXTUREGL_H_
}
#endif // BACKEND_OPENGL_TEXTUREGL_H_