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

View File

@ -19,17 +19,15 @@
#include "glad/glad.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
class BlendState : public BlendStateBase {
public:
BlendState(BlendStateBuilder* builder);
public:
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"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
// Buffer
Buffer::Buffer(BufferBuilder* builder)
: BufferBase(builder) {
Buffer::Buffer(BufferBuilder* builder) : BufferBase(builder) {
glGenBuffers(1, &mBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
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) {
// 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.
// 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);
void* data = glMapBufferRange(GL_ARRAY_BUFFER, start, count, GL_MAP_READ_BIT);
CallMapReadCallback(serial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, data);
@ -56,9 +55,7 @@ namespace opengl {
// BufferView
BufferView::BufferView(BufferViewBuilder* builder)
: BufferViewBase(builder) {
BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) {
}
}
}
}} // namespace backend::opengl

View File

@ -19,32 +19,31 @@
#include "glad/glad.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
class Device;
class Buffer : public BufferBase {
public:
Buffer(BufferBuilder* builder);
public:
Buffer(BufferBuilder* builder);
GLuint GetHandle() const;
GLuint GetHandle() const;
private:
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;
private:
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;
GLuint mBuffer = 0;
GLuint mBuffer = 0;
};
class BufferView : public BufferViewBase {
public:
BufferView(BufferViewBuilder* builder);
public:
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/CommandBuffer.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
class Device;
class CommandBuffer : public CommandBufferBase {
public:
CommandBuffer(CommandBufferBuilder* builder);
~CommandBuffer();
public:
CommandBuffer(CommandBufferBuilder* builder);
~CommandBuffer();
void Execute();
void Execute();
private:
CommandIterator mCommands;
private:
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"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
ComputePipeline::ComputePipeline(ComputePipelineBuilder* builder)
: ComputePipelineBase(builder), PipelineGL(this, builder) {
@ -25,5 +24,4 @@ namespace opengl {
PipelineGL::ApplyNow();
}
}
}
}} // namespace backend::opengl

View File

@ -21,17 +21,15 @@
#include "glad/glad.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
class ComputePipeline : public ComputePipelineBase, public PipelineGL {
public:
ComputePipeline(ComputePipelineBuilder* builder);
public:
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 "common/Assert.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
namespace {
GLuint OpenGLCompareFunction(nxt::CompareFunction compareFunction) {
@ -67,17 +66,18 @@ namespace opengl {
UNREACHABLE();
}
}
}
} // namespace
DepthStencilState::DepthStencilState(DepthStencilStateBuilder* builder)
: DepthStencilStateBase(builder) {
}
void DepthStencilState::ApplyNow(PersistentPipelineState &persistentPipelineState) const {
void DepthStencilState::ApplyNow(PersistentPipelineState& persistentPipelineState) const {
auto& depthInfo = GetDepth();
// 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);
} else {
glEnable(GL_DEPTH_TEST);
@ -101,22 +101,17 @@ namespace opengl {
GLenum backCompareFunction = OpenGLCompareFunction(stencilInfo.back.compareFunction);
GLenum frontCompareFunction = OpenGLCompareFunction(stencilInfo.front.compareFunction);
persistentPipelineState.SetStencilFuncsAndMask(backCompareFunction, frontCompareFunction, stencilInfo.readMask);
persistentPipelineState.SetStencilFuncsAndMask(backCompareFunction, frontCompareFunction,
stencilInfo.readMask);
glStencilOpSeparate(GL_BACK,
OpenGLStencilOperation(stencilInfo.back.stencilFail),
OpenGLStencilOperation(stencilInfo.back.depthFail),
OpenGLStencilOperation(stencilInfo.back.depthStencilPass)
);
glStencilOpSeparate(GL_FRONT,
OpenGLStencilOperation(stencilInfo.front.stencilFail),
OpenGLStencilOperation(stencilInfo.front.depthFail),
OpenGLStencilOperation(stencilInfo.front.depthStencilPass)
);
glStencilOpSeparate(GL_BACK, OpenGLStencilOperation(stencilInfo.back.stencilFail),
OpenGLStencilOperation(stencilInfo.back.depthFail),
OpenGLStencilOperation(stencilInfo.back.depthStencilPass));
glStencilOpSeparate(GL_FRONT, OpenGLStencilOperation(stencilInfo.front.stencilFail),
OpenGLStencilOperation(stencilInfo.front.depthFail),
OpenGLStencilOperation(stencilInfo.front.depthStencilPass));
glStencilMask(stencilInfo.writeMask);
}
}
}
}} // namespace backend::opengl

View File

@ -17,20 +17,18 @@
#include "backend/DepthStencilState.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
class Device;
class PersistentPipelineState;
class DepthStencilState : public DepthStencilStateBase {
public:
DepthStencilState(DepthStencilStateBuilder* builder);
public:
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
// limitations under the License.
#include "backend/opengl/OpenGLBackend.h"
#include "backend/opengl/BlendStateGL.h"
#include "backend/opengl/BufferGL.h"
#include "backend/opengl/CommandBufferGL.h"
#include "backend/opengl/ComputePipelineGL.h"
#include "backend/opengl/DepthStencilStateGL.h"
#include "backend/opengl/InputStateGL.h"
#include "backend/opengl/OpenGLBackend.h"
#include "backend/opengl/PersistentPipelineStateGL.h"
#include "backend/opengl/PipelineLayoutGL.h"
#include "backend/opengl/RenderPipelineGL.h"

View File

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

View File

@ -19,24 +19,22 @@
#include "glad/glad.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
class Device;
class InputState : public InputStateBase {
public:
InputState(InputStateBuilder* builder);
public:
InputState(InputStateBuilder* builder);
std::bitset<kMaxVertexAttributes> GetAttributesUsingInput(uint32_t slot) const;
GLuint GetVAO();
std::bitset<kMaxVertexAttributes> GetAttributesUsingInput(uint32_t slot) const;
GLuint GetVAO();
private:
GLuint mVertexArrayObject;
std::array<std::bitset<kMaxVertexAttributes>, kMaxVertexInputs> attributesUsingInput;
private:
GLuint mVertexArrayObject;
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/PipelineLayoutGL.h"
#include "backend/opengl/RenderPipelineGL.h"
#include "backend/opengl/SamplerGL.h"
#include "backend/opengl/ShaderModuleGL.h"
#include "backend/opengl/SwapChainGL.h"
#include "backend/opengl/SamplerGL.h"
#include "backend/opengl/TextureGL.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
nxtProcTable GetNonValidatingProcs();
nxtProcTable GetValidatingProcs();
@ -109,8 +108,7 @@ namespace opengl {
// Bind Group
BindGroup::BindGroup(BindGroupBuilder* builder)
: BindGroupBase(builder) {
BindGroup::BindGroup(BindGroupBuilder* builder) : BindGroupBase(builder) {
}
// Bind Group Layout
@ -121,17 +119,15 @@ namespace opengl {
// Framebuffer
Framebuffer::Framebuffer(FramebufferBuilder* builder)
: FramebufferBase(builder) {
Framebuffer::Framebuffer(FramebufferBuilder* builder) : FramebufferBase(builder) {
}
// Queue
Queue::Queue(QueueBuilder* builder)
: QueueBase(builder) {
Queue::Queue(QueueBuilder* 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) {
commands[i]->Execute();
}
@ -139,9 +135,7 @@ namespace opengl {
// RenderPass
RenderPass::RenderPass(RenderPassBuilder* builder)
: RenderPassBase(builder) {
RenderPass::RenderPass(RenderPassBuilder* builder) : RenderPassBase(builder) {
}
}
}
}} // namespace backend::opengl

View File

@ -17,12 +17,12 @@
#include "nxt/nxtcpp.h"
#include "backend/Buffer.h"
#include "backend/BlendState.h"
#include "backend/BindGroup.h"
#include "backend/BindGroupLayout.h"
#include "backend/Device.h"
#include "backend/BlendState.h"
#include "backend/Buffer.h"
#include "backend/DepthStencilState.h"
#include "backend/Device.h"
#include "backend/Framebuffer.h"
#include "backend/InputState.h"
#include "backend/Queue.h"
@ -31,8 +31,7 @@
#include "glad/glad.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
class BindGroup;
class BindGroupLayout;
@ -79,66 +78,65 @@ namespace opengl {
using TextureViewType = TextureView;
};
template<typename T>
template <typename T>
auto ToBackend(T&& common) -> decltype(ToBackendBase<OpenGLBackendTraits>(common)) {
return ToBackendBase<OpenGLBackendTraits>(common);
}
// Definition of backend types
class Device : public DeviceBase {
public:
BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) override;
BindGroupLayoutBase* CreateBindGroupLayout(BindGroupLayoutBuilder* 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;
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
FramebufferBase* CreateFramebuffer(FramebufferBuilder* builder) override;
PipelineLayoutBase* CreatePipelineLayout(PipelineLayoutBuilder* builder) override;
QueueBase* CreateQueue(QueueBuilder* builder) override;
RenderPassBase* CreateRenderPass(RenderPassBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
SamplerBase* CreateSampler(SamplerBuilder* builder) override;
ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) override;
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
TextureBase* CreateTexture(TextureBuilder* builder) override;
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
public:
BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) override;
BindGroupLayoutBase* CreateBindGroupLayout(BindGroupLayoutBuilder* 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;
DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) override;
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
FramebufferBase* CreateFramebuffer(FramebufferBuilder* builder) override;
PipelineLayoutBase* CreatePipelineLayout(PipelineLayoutBuilder* builder) override;
QueueBase* CreateQueue(QueueBuilder* builder) override;
RenderPassBase* CreateRenderPass(RenderPassBuilder* builder) override;
RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) override;
SamplerBase* CreateSampler(SamplerBuilder* builder) override;
ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) override;
SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) override;
TextureBase* CreateTexture(TextureBuilder* builder) override;
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
void TickImpl() override;
void TickImpl() override;
};
class BindGroup : public BindGroupBase {
public:
BindGroup(BindGroupBuilder* builder);
public:
BindGroup(BindGroupBuilder* builder);
};
class BindGroupLayout : public BindGroupLayoutBase {
public:
BindGroupLayout(BindGroupLayoutBuilder* builder);
public:
BindGroupLayout(BindGroupLayoutBuilder* builder);
};
class Framebuffer : public FramebufferBase {
public:
Framebuffer(FramebufferBuilder* builder);
public:
Framebuffer(FramebufferBuilder* builder);
};
class Queue : public QueueBase {
public:
Queue(QueueBuilder* builder);
public:
Queue(QueueBuilder* builder);
// NXT API
void Submit(uint32_t numCommands, CommandBuffer* const * commands);
// NXT API
void Submit(uint32_t numCommands, CommandBuffer* const* commands);
};
class RenderPass : public RenderPassBase {
public:
RenderPass(RenderPassBuilder* builder);
public:
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"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
void PersistentPipelineState::SetDefaultState() {
CallGLStencilFunc();
}
void PersistentPipelineState::SetStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask) {
void PersistentPipelineState::SetStencilFuncsAndMask(GLenum stencilBackCompareFunction,
GLenum stencilFrontCompareFunction,
uint32_t stencilReadMask) {
if (mStencilBackCompareFunction == stencilBackCompareFunction &&
mStencilFrontCompareFunction == stencilFrontCompareFunction &&
mStencilReadMask == stencilReadMask) {
@ -46,15 +47,10 @@ namespace opengl {
}
void PersistentPipelineState::CallGLStencilFunc() {
glStencilFuncSeparate(GL_BACK,
mStencilBackCompareFunction,
mStencilReference,
mStencilReadMask);
glStencilFuncSeparate(GL_FRONT,
mStencilFrontCompareFunction,
mStencilReference,
mStencilReadMask);
glStencilFuncSeparate(GL_BACK, mStencilBackCompareFunction, mStencilReference,
mStencilReadMask);
glStencilFuncSeparate(GL_FRONT, mStencilFrontCompareFunction, mStencilReference,
mStencilReadMask);
}
}
}
}} // namespace backend::opengl

View File

@ -19,25 +19,25 @@
#include "glad/glad.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
class PersistentPipelineState {
public:
void SetDefaultState();
void SetStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask);
void SetStencilReference(uint32_t stencilReference);
public:
void SetDefaultState();
void SetStencilFuncsAndMask(GLenum stencilBackCompareFunction,
GLenum stencilFrontCompareFunction,
uint32_t stencilReadMask);
void SetStencilReference(uint32_t stencilReference);
private:
void CallGLStencilFunc();
private:
void CallGLStencilFunc();
GLenum mStencilBackCompareFunction = GL_ALWAYS;
GLenum mStencilFrontCompareFunction = GL_ALWAYS;
GLuint mStencilReadMask = 0xffffffff;
GLuint mStencilReference = 0;
GLenum mStencilBackCompareFunction = GL_ALWAYS;
GLenum mStencilFrontCompareFunction = GL_ALWAYS;
GLuint mStencilReadMask = 0xffffffff;
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 <set>
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
namespace {
@ -40,7 +39,7 @@ namespace opengl {
}
}
}
} // namespace
PipelineGL::PipelineGL(PipelineBase* parent, PipelineBuilder* builder) {
auto CreateShader = [](GLenum type, const char* source) -> GLuint {
@ -65,7 +64,8 @@ namespace opengl {
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();
for (uint32_t i = 0; i < moduleInfo.names.size(); i++) {
(*info)[i] = -1;
@ -119,7 +119,8 @@ namespace opengl {
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& indices = layout->GetBindingIndexInfo();
@ -133,25 +134,22 @@ namespace opengl {
std::string name = GetBindingName(group, binding);
switch (groupInfo.types[binding]) {
case nxt::BindingType::UniformBuffer:
{
GLint location = glGetUniformBlockIndex(mProgram, name.c_str());
glUniformBlockBinding(mProgram, location, indices[group][binding]);
}
break;
case nxt::BindingType::UniformBuffer: {
GLint location = glGetUniformBlockIndex(mProgram, name.c_str());
glUniformBlockBinding(mProgram, location, indices[group][binding]);
} break;
case nxt::BindingType::StorageBuffer:
{
GLuint location = glGetProgramResourceIndex(mProgram, GL_SHADER_STORAGE_BLOCK, name.c_str());
glShaderStorageBlockBinding(mProgram, location, indices[group][binding]);
}
break;
case nxt::BindingType::StorageBuffer: {
GLuint location = glGetProgramResourceIndex(
mProgram, GL_SHADER_STORAGE_BLOCK, name.c_str());
glShaderStorageBlockBinding(mProgram, location, indices[group][binding]);
} break;
case nxt::BindingType::Sampler:
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;
}
}
}
@ -176,18 +174,21 @@ namespace opengl {
GLint location = glGetUniformLocation(mProgram, name.c_str());
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);
GLuint textureIndex = indices[combined.textureLocation.group][combined.textureLocation.binding];
GLuint textureIndex =
indices[combined.textureLocation.group][combined.textureLocation.binding];
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];
}
@ -209,5 +210,4 @@ namespace opengl {
glUseProgram(mProgram);
}
}
}
}} // namespace backend::opengl

View File

@ -21,35 +21,34 @@
#include <vector>
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
class Device;
class PersistentPipelineState;
class ShaderModule;
class PipelineGL {
public:
PipelineGL(PipelineBase* parent, PipelineBuilder* builder);
public:
PipelineGL(PipelineBase* parent, PipelineBuilder* builder);
using GLPushConstantInfo = std::array<GLint, kMaxPushConstants>;
using BindingLocations = std::array<std::array<GLint, kMaxBindingsPerGroup>, kMaxBindGroups>;
using GLPushConstantInfo = std::array<GLint, kMaxPushConstants>;
using BindingLocations =
std::array<std::array<GLint, kMaxBindingsPerGroup>, kMaxBindGroups>;
const GLPushConstantInfo& GetGLPushConstants(nxt::ShaderStage stage) const;
const std::vector<GLuint>& GetTextureUnitsForSampler(GLuint index) const;
const std::vector<GLuint>& GetTextureUnitsForTexture(GLuint index) const;
GLuint GetProgramHandle() const;
const GLPushConstantInfo& GetGLPushConstants(nxt::ShaderStage stage) const;
const std::vector<GLuint>& GetTextureUnitsForSampler(GLuint index) const;
const std::vector<GLuint>& GetTextureUnitsForTexture(GLuint index) const;
GLuint GetProgramHandle() const;
void ApplyNow();
void ApplyNow();
private:
GLuint mProgram;
PerStage<GLPushConstantInfo> mGlPushConstants;
std::vector<std::vector<GLuint>> mUnitsForSamplers;
std::vector<std::vector<GLuint>> mUnitsForTextures;
private:
GLuint mProgram;
PerStage<GLPushConstantInfo> mGlPushConstants;
std::vector<std::vector<GLuint>> mUnitsForSamplers;
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"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
PipelineLayout::PipelineLayout(PipelineLayoutBuilder* builder)
: PipelineLayoutBase(builder) {
PipelineLayout::PipelineLayout(PipelineLayoutBuilder* builder) : PipelineLayoutBase(builder) {
GLuint uboIndex = 0;
GLuint samplerIndex = 0;
GLuint sampledTextureIndex = 0;
@ -37,20 +35,20 @@ namespace opengl {
switch (groupInfo.types[binding]) {
case nxt::BindingType::UniformBuffer:
mIndexInfo[group][binding] = uboIndex;
uboIndex ++;
uboIndex++;
break;
case nxt::BindingType::Sampler:
mIndexInfo[group][binding] = samplerIndex;
samplerIndex ++;
samplerIndex++;
break;
case nxt::BindingType::SampledTexture:
mIndexInfo[group][binding] = sampledTextureIndex;
sampledTextureIndex ++;
sampledTextureIndex++;
break;
case nxt::BindingType::StorageBuffer:
mIndexInfo[group][binding] = ssboIndex;
ssboIndex ++;
ssboIndex++;
break;
}
}
@ -76,5 +74,4 @@ namespace opengl {
return mNumSampledTextures;
}
}
}
}} // namespace backend::opengl

View File

@ -19,29 +19,28 @@
#include "glad/glad.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
class Device;
class PipelineLayout : public PipelineLayoutBase {
public:
PipelineLayout(PipelineLayoutBuilder* builder);
public:
PipelineLayout(PipelineLayoutBuilder* builder);
using BindingIndexInfo = std::array<std::array<GLuint, kMaxBindingsPerGroup>, kMaxBindGroups>;
const BindingIndexInfo& GetBindingIndexInfo() const;
using BindingIndexInfo =
std::array<std::array<GLuint, kMaxBindingsPerGroup>, kMaxBindGroups>;
const BindingIndexInfo& GetBindingIndexInfo() const;
GLuint GetTextureUnitsUsed() const;
size_t GetNumSamplers() const;
size_t GetNumSampledTextures() const;
GLuint GetTextureUnitsUsed() const;
size_t GetNumSamplers() const;
size_t GetNumSampledTextures() const;
private:
BindingIndexInfo mIndexInfo;
size_t mNumSamplers;
size_t mNumSampledTextures;
private:
BindingIndexInfo mIndexInfo;
size_t mNumSamplers;
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/PersistentPipelineStateGL.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
namespace {
GLenum GLPrimitiveTopology(nxt::PrimitiveTopology primitiveTopology) {
@ -40,10 +39,11 @@ namespace opengl {
UNREACHABLE();
}
}
}
} // namespace
RenderPipeline::RenderPipeline(RenderPipelineBuilder* builder)
: RenderPipelineBase(builder), PipelineGL(this, builder),
: RenderPipelineBase(builder),
PipelineGL(this, builder),
mGlPrimitiveTopology(GLPrimitiveTopology(GetPrimitiveTopology())) {
}
@ -51,7 +51,7 @@ namespace opengl {
return mGlPrimitiveTopology;
}
void RenderPipeline::ApplyNow(PersistentPipelineState &persistentPipelineState) {
void RenderPipeline::ApplyNow(PersistentPipelineState& persistentPipelineState) {
PipelineGL::ApplyNow();
auto inputState = ToBackend(GetInputState());
@ -68,5 +68,4 @@ namespace opengl {
}
}
}
}
}} // namespace backend::opengl

View File

@ -23,24 +23,22 @@
#include <vector>
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
class PersistentPipelineState;
class RenderPipeline : public RenderPipelineBase, public PipelineGL {
public:
RenderPipeline(RenderPipelineBuilder* builder);
public:
RenderPipeline(RenderPipelineBuilder* builder);
GLenum GetGLPrimitiveTopology() const;
GLenum GetGLPrimitiveTopology() const;
void ApplyNow(PersistentPipelineState &persistentPipelineState);
void ApplyNow(PersistentPipelineState& persistentPipelineState);
private:
GLenum mGlPrimitiveTopology;
private:
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"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
namespace {
GLenum MagFilterMode(nxt::FilterMode filter) {
@ -55,18 +54,17 @@ namespace opengl {
UNREACHABLE();
}
}
}
} // namespace
Sampler::Sampler(SamplerBuilder* builder)
: SamplerBase(builder) {
Sampler::Sampler(SamplerBuilder* builder) : SamplerBase(builder) {
glGenSamplers(1, &mHandle);
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 {
return mHandle;
}
}
}
}} // namespace backend::opengl

View File

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

View File

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

View File

@ -19,8 +19,7 @@
#include "glad/glad.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
class Device;
@ -30,30 +29,29 @@ namespace opengl {
uint32_t group;
uint32_t binding;
};
bool operator < (const BindingLocation& a, const BindingLocation& b);
bool operator<(const BindingLocation& a, const BindingLocation& b);
struct CombinedSampler {
BindingLocation samplerLocation;
BindingLocation textureLocation;
std::string GetName() const;
};
bool operator < (const CombinedSampler& a, const CombinedSampler& b);
bool operator<(const CombinedSampler& a, const CombinedSampler& b);
class ShaderModule : public ShaderModuleBase {
public:
ShaderModule(ShaderModuleBuilder* builder);
public:
ShaderModule(ShaderModuleBuilder* builder);
using CombinedSamplerInfo = std::vector<CombinedSampler>;
using CombinedSamplerInfo = std::vector<CombinedSampler>;
const char* GetSource() const;
const CombinedSamplerInfo& GetCombinedSamplerInfo() const;
const char* GetSource() const;
const CombinedSamplerInfo& GetCombinedSamplerInfo() const;
private:
CombinedSamplerInfo mCombinedInfo;
std::string mGlslSource;
private:
CombinedSamplerInfo mCombinedInfo;
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>
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
SwapChain::SwapChain(SwapChainBuilder* builder)
: SwapChainBase(builder) {
SwapChain::SwapChain(SwapChainBuilder* builder) : SwapChainBase(builder) {
const auto& im = GetImplementation();
im.Init(im.userData, nullptr);
}
@ -43,5 +41,4 @@ namespace opengl {
return new Texture(builder, nativeTexture);
}
}
}
}} // namespace backend::opengl

View File

@ -19,21 +19,19 @@
#include "glad/glad.h"
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
class Device;
class SwapChain : public SwapChainBase {
public:
SwapChain(SwapChainBuilder* builder);
~SwapChain();
public:
SwapChain(SwapChainBuilder* builder);
~SwapChain();
protected:
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
protected:
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 <vector>
namespace backend {
namespace opengl {
namespace backend { namespace opengl {
namespace {
@ -43,7 +42,8 @@ namespace opengl {
// This doesn't have an enum for the internal format in OpenGL.
return {GL_NONE, GL_BGRA, GL_UNSIGNED_BYTE};
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:
UNREACHABLE();
}
@ -55,12 +55,11 @@ namespace opengl {
return handle;
}
}
} // namespace
// Texture
Texture::Texture(TextureBuilder* builder)
: Texture(builder, GenTexture()) {
Texture::Texture(TextureBuilder* builder) : Texture(builder, GenTexture()) {
}
Texture::Texture(TextureBuilder* builder, GLuint handle)
@ -76,7 +75,8 @@ namespace opengl {
glBindTexture(mTarget, handle);
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);
height = std::max(uint32_t(1), height / 2);
}
@ -87,7 +87,8 @@ namespace opengl {
}
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 {
@ -107,9 +108,7 @@ namespace opengl {
// TextureView
TextureView::TextureView(TextureViewBuilder* builder)
: TextureViewBase(builder) {
TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) {
}
}
}
}} // namespace backend::opengl

View File

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