mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-07 07:03:42 +00:00
Format: src/backend/opengl
This commit is contained in:
parent
1aa4d5604f
commit
c7807abf04
@ -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,10 +79,13 @@ 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),
|
||||||
|
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::Green,
|
||||||
info.colorWriteMask & nxt::ColorWriteMask::Blue,
|
info.colorWriteMask & nxt::ColorWriteMask::Blue,
|
||||||
info.colorWriteMask & nxt::ColorWriteMask::Alpha);
|
info.colorWriteMask & nxt::ColorWriteMask::Alpha);
|
||||||
@ -92,5 +94,4 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
@ -19,8 +19,7 @@
|
|||||||
|
|
||||||
#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:
|
||||||
@ -29,7 +28,6 @@ namespace opengl {
|
|||||||
void ApplyNow(uint32_t attachment);
|
void ApplyNow(uint32_t attachment);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
|
||||||
#endif // BACKEND_OPENGL_BLENDSTATED3D12_H_
|
#endif // BACKEND_OPENGL_BLENDSTATED3D12_H_
|
||||||
|
@ -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
|
||||||
}
|
|
||||||
|
@ -19,8 +19,7 @@
|
|||||||
|
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
|
|
||||||
namespace backend {
|
namespace backend { namespace opengl {
|
||||||
namespace opengl {
|
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
|
|
||||||
@ -34,7 +33,8 @@ namespace opengl {
|
|||||||
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;
|
||||||
};
|
};
|
||||||
@ -44,7 +44,6 @@ namespace opengl {
|
|||||||
BufferView(BufferViewBuilder* builder);
|
BufferView(BufferViewBuilder* builder);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
|
||||||
#endif // BACKEND_OPENGL_BUFFERGL_H_
|
#endif // BACKEND_OPENGL_BUFFERGL_H_
|
||||||
|
@ -27,8 +27,7 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
namespace backend {
|
namespace backend { namespace opengl {
|
||||||
namespace opengl {
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -55,12 +54,12 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push constants are implemented using OpenGL uniforms, however they aren't part of the global
|
// Push constants are implemented using OpenGL uniforms, however they aren't part of the
|
||||||
// OpenGL state but are part of the program state instead. This means that we have to reapply
|
// global OpenGL state but are part of the program state instead. This means that we have to
|
||||||
// push constants on pipeline change.
|
// reapply push constants on pipeline change.
|
||||||
//
|
//
|
||||||
// This structure tracks the current values of push constants as well as dirty bits for push constants
|
// This structure tracks the current values of push constants as well as dirty bits for push
|
||||||
// that should be applied before the next draw or dispatch.
|
// constants that should be applied before the next draw or dispatch.
|
||||||
class PushConstantTracker {
|
class PushConstantTracker {
|
||||||
public:
|
public:
|
||||||
void OnBeginPass() {
|
void OnBeginPass() {
|
||||||
@ -71,8 +70,10 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnSetPushConstants(nxt::ShaderStageBit stages, uint32_t count,
|
void OnSetPushConstants(nxt::ShaderStageBit stages,
|
||||||
uint32_t offset, const uint32_t* data) {
|
uint32_t count,
|
||||||
|
uint32_t offset,
|
||||||
|
const uint32_t* data) {
|
||||||
for (auto stage : IterateStages(stages)) {
|
for (auto stage : IterateStages(stages)) {
|
||||||
memcpy(&mValues[stage][offset], data, count * sizeof(uint32_t));
|
memcpy(&mValues[stage][offset], data, count * sizeof(uint32_t));
|
||||||
|
|
||||||
@ -93,17 +94,21 @@ namespace opengl {
|
|||||||
const auto& pushConstants = pipeline->GetPushConstants(stage);
|
const auto& pushConstants = pipeline->GetPushConstants(stage);
|
||||||
const auto& glPushConstants = glPipeline->GetGLPushConstants(stage);
|
const auto& glPushConstants = glPipeline->GetGLPushConstants(stage);
|
||||||
|
|
||||||
for (uint32_t constant : IterateBitSet(mDirtyBits[stage] & pushConstants.mask)) {
|
for (uint32_t constant :
|
||||||
|
IterateBitSet(mDirtyBits[stage] & pushConstants.mask)) {
|
||||||
GLint location = glPushConstants[constant];
|
GLint location = glPushConstants[constant];
|
||||||
switch (pushConstants.types[constant]) {
|
switch (pushConstants.types[constant]) {
|
||||||
case PushConstantType::Int:
|
case PushConstantType::Int:
|
||||||
glUniform1i(location, *reinterpret_cast<GLint*>(&mValues[stage][constant]));
|
glUniform1i(location,
|
||||||
|
*reinterpret_cast<GLint*>(&mValues[stage][constant]));
|
||||||
break;
|
break;
|
||||||
case PushConstantType::UInt:
|
case PushConstantType::UInt:
|
||||||
glUniform1ui(location, *reinterpret_cast<GLuint*>(&mValues[stage][constant]));
|
glUniform1ui(location,
|
||||||
|
*reinterpret_cast<GLuint*>(&mValues[stage][constant]));
|
||||||
break;
|
break;
|
||||||
case PushConstantType::Float:
|
case PushConstantType::Float:
|
||||||
glUniform1f(location, *reinterpret_cast<GLfloat*>(&mValues[stage][constant]));
|
glUniform1f(location,
|
||||||
|
*reinterpret_cast<GLfloat*>(&mValues[stage][constant]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,9 +122,9 @@ namespace opengl {
|
|||||||
PerStage<std::bitset<kMaxPushConstants>> mDirtyBits;
|
PerStage<std::bitset<kMaxPushConstants>> mDirtyBits;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Vertex buffers and index buffers are implemented as part of an OpenGL VAO that corresponds to an
|
// Vertex buffers and index buffers are implemented as part of an OpenGL VAO that
|
||||||
// InputState. On the contrary in NXT they are part of the global state. This means that we have to
|
// corresponds to an InputState. On the contrary in NXT they are part of the global state.
|
||||||
// re-apply these buffers on an InputState change.
|
// This means that we have to re-apply these buffers on an InputState change.
|
||||||
class InputBufferTracker {
|
class InputBufferTracker {
|
||||||
public:
|
public:
|
||||||
void OnBeginPass() {
|
void OnBeginPass() {
|
||||||
@ -133,7 +138,10 @@ namespace opengl {
|
|||||||
mIndexBuffer = ToBackend(buffer);
|
mIndexBuffer = ToBackend(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnSetVertexBuffers(uint32_t startSlot, uint32_t count, Ref<BufferBase>* buffers, uint32_t* offsets) {
|
void OnSetVertexBuffers(uint32_t startSlot,
|
||||||
|
uint32_t count,
|
||||||
|
Ref<BufferBase>* buffers,
|
||||||
|
uint32_t* offsets) {
|
||||||
for (uint32_t i = 0; i < count; ++i) {
|
for (uint32_t i = 0; i < count; ++i) {
|
||||||
uint32_t slot = startSlot + i;
|
uint32_t slot = startSlot + i;
|
||||||
mVertexBuffers[slot] = ToBackend(buffers[i].Get());
|
mVertexBuffers[slot] = ToBackend(buffers[i].Get());
|
||||||
@ -163,8 +171,10 @@ namespace opengl {
|
|||||||
mIndexBufferDirty = false;
|
mIndexBufferDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t slot : IterateBitSet(mDirtyVertexBuffers & mLastInputState->GetInputsSetMask())) {
|
for (uint32_t slot :
|
||||||
for (uint32_t location : IterateBitSet(mLastInputState->GetAttributesUsingInput(slot))) {
|
IterateBitSet(mDirtyVertexBuffers & mLastInputState->GetInputsSetMask())) {
|
||||||
|
for (uint32_t location :
|
||||||
|
IterateBitSet(mLastInputState->GetAttributesUsingInput(slot))) {
|
||||||
auto attribute = mLastInputState->GetAttribute(location);
|
auto attribute = mLastInputState->GetAttribute(location);
|
||||||
|
|
||||||
GLuint buffer = mVertexBuffers[slot]->GetHandle();
|
GLuint buffer = mVertexBuffers[slot]->GetHandle();
|
||||||
@ -176,9 +186,9 @@ namespace opengl {
|
|||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||||
glVertexAttribPointer(
|
glVertexAttribPointer(
|
||||||
location, components, formatType, GL_FALSE,
|
location, components, formatType, GL_FALSE, input.stride,
|
||||||
input.stride,
|
reinterpret_cast<void*>(
|
||||||
reinterpret_cast<void*>(static_cast<intptr_t>(offset + attribute.offset)));
|
static_cast<intptr_t>(offset + attribute.offset)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +206,7 @@ namespace opengl {
|
|||||||
InputState* mLastInputState = nullptr;
|
InputState* mLastInputState = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
CommandBuffer::CommandBuffer(CommandBufferBuilder* builder)
|
CommandBuffer::CommandBuffer(CommandBufferBuilder* builder)
|
||||||
: CommandBufferBase(builder), mCommands(builder->AcquireCommands()) {
|
: CommandBufferBase(builder), mCommands(builder->AcquireCommands()) {
|
||||||
@ -224,26 +234,21 @@ namespace opengl {
|
|||||||
uint32_t currentSubpass = 0;
|
uint32_t currentSubpass = 0;
|
||||||
GLuint currentFBO = 0;
|
GLuint currentFBO = 0;
|
||||||
|
|
||||||
while(mCommands.NextCommandId(&type)) {
|
while (mCommands.NextCommandId(&type)) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Command::BeginComputePass:
|
case Command::BeginComputePass: {
|
||||||
{
|
|
||||||
mCommands.NextCommand<BeginComputePassCmd>();
|
mCommands.NextCommand<BeginComputePassCmd>();
|
||||||
pushConstants.OnBeginPass();
|
pushConstants.OnBeginPass();
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::BeginRenderPass:
|
case Command::BeginRenderPass: {
|
||||||
{
|
|
||||||
auto* cmd = mCommands.NextCommand<BeginRenderPassCmd>();
|
auto* cmd = mCommands.NextCommand<BeginRenderPassCmd>();
|
||||||
currentRenderPass = ToBackend(cmd->renderPass.Get());
|
currentRenderPass = ToBackend(cmd->renderPass.Get());
|
||||||
currentFramebuffer = ToBackend(cmd->framebuffer.Get());
|
currentFramebuffer = ToBackend(cmd->framebuffer.Get());
|
||||||
currentSubpass = 0;
|
currentSubpass = 0;
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::BeginRenderSubpass:
|
case Command::BeginRenderSubpass: {
|
||||||
{
|
|
||||||
mCommands.NextCommand<BeginRenderSubpassCmd>();
|
mCommands.NextCommand<BeginRenderSubpassCmd>();
|
||||||
pushConstants.OnBeginPass();
|
pushConstants.OnBeginPass();
|
||||||
inputBuffers.OnBeginPass();
|
inputBuffers.OnBeginPass();
|
||||||
@ -278,15 +283,15 @@ namespace opengl {
|
|||||||
GLuint texture = ToBackend(textureView->GetTexture())->GetHandle();
|
GLuint texture = ToBackend(textureView->GetTexture())->GetHandle();
|
||||||
|
|
||||||
// Attach color buffers.
|
// Attach color buffers.
|
||||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + location,
|
||||||
GL_COLOR_ATTACHMENT0 + location,
|
|
||||||
GL_TEXTURE_2D, texture, 0);
|
GL_TEXTURE_2D, texture, 0);
|
||||||
drawBuffers[location] = GL_COLOR_ATTACHMENT0 + location;
|
drawBuffers[location] = GL_COLOR_ATTACHMENT0 + location;
|
||||||
attachmentCount = location + 1;
|
attachmentCount = location + 1;
|
||||||
|
|
||||||
// TODO(kainino@chromium.org): the color clears (later in
|
// TODO(kainino@chromium.org): the color clears (later in
|
||||||
// this function) may be undefined for other texture formats.
|
// this function) may be undefined for other texture formats.
|
||||||
ASSERT(textureView->GetTexture()->GetFormat() == nxt::TextureFormat::R8G8B8A8Unorm);
|
ASSERT(textureView->GetTexture()->GetFormat() ==
|
||||||
|
nxt::TextureFormat::R8G8B8A8Unorm);
|
||||||
}
|
}
|
||||||
glDrawBuffers(attachmentCount, drawBuffers.data());
|
glDrawBuffers(attachmentCount, drawBuffers.data());
|
||||||
|
|
||||||
@ -299,7 +304,8 @@ namespace opengl {
|
|||||||
|
|
||||||
// Attach depth/stencil buffer.
|
// Attach depth/stencil buffer.
|
||||||
GLenum glAttachment = 0;
|
GLenum glAttachment = 0;
|
||||||
// TODO(kainino@chromium.org): it may be valid to just always use GL_DEPTH_STENCIL_ATTACHMENT here.
|
// TODO(kainino@chromium.org): it may be valid to just always use
|
||||||
|
// GL_DEPTH_STENCIL_ATTACHMENT here.
|
||||||
if (TextureFormatHasDepth(format)) {
|
if (TextureFormatHasDepth(format)) {
|
||||||
if (TextureFormatHasStencil(format)) {
|
if (TextureFormatHasStencil(format)) {
|
||||||
glAttachment = GL_DEPTH_STENCIL_ATTACHMENT;
|
glAttachment = GL_DEPTH_STENCIL_ATTACHMENT;
|
||||||
@ -310,7 +316,8 @@ namespace opengl {
|
|||||||
glAttachment = GL_STENCIL_ATTACHMENT;
|
glAttachment = GL_STENCIL_ATTACHMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, glAttachment, GL_TEXTURE_2D, texture, 0);
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, glAttachment, GL_TEXTURE_2D,
|
||||||
|
texture, 0);
|
||||||
|
|
||||||
// TODO(kainino@chromium.org): the depth/stencil clears (later in
|
// TODO(kainino@chromium.org): the depth/stencil clears (later in
|
||||||
// this function) may be undefined for other texture formats.
|
// this function) may be undefined for other texture formats.
|
||||||
@ -321,7 +328,8 @@ namespace opengl {
|
|||||||
|
|
||||||
for (unsigned int location : IterateBitSet(subpass.colorAttachmentsSet)) {
|
for (unsigned int location : IterateBitSet(subpass.colorAttachmentsSet)) {
|
||||||
uint32_t attachmentSlot = subpass.colorAttachments[location];
|
uint32_t attachmentSlot = subpass.colorAttachments[location];
|
||||||
const auto& attachmentInfo = currentRenderPass->GetAttachmentInfo(attachmentSlot);
|
const auto& attachmentInfo =
|
||||||
|
currentRenderPass->GetAttachmentInfo(attachmentSlot);
|
||||||
|
|
||||||
// Only perform load op on first use
|
// Only perform load op on first use
|
||||||
if (attachmentInfo.firstSubpass == currentSubpass) {
|
if (attachmentInfo.firstSubpass == currentSubpass) {
|
||||||
@ -335,15 +343,18 @@ namespace opengl {
|
|||||||
|
|
||||||
if (subpass.depthStencilAttachmentSet) {
|
if (subpass.depthStencilAttachmentSet) {
|
||||||
uint32_t attachmentSlot = subpass.depthStencilAttachment;
|
uint32_t attachmentSlot = subpass.depthStencilAttachment;
|
||||||
const auto& attachmentInfo = currentRenderPass->GetAttachmentInfo(attachmentSlot);
|
const auto& attachmentInfo =
|
||||||
|
currentRenderPass->GetAttachmentInfo(attachmentSlot);
|
||||||
|
|
||||||
// Only perform load op on first use
|
// Only perform load op on first use
|
||||||
if (attachmentInfo.firstSubpass == currentSubpass) {
|
if (attachmentInfo.firstSubpass == currentSubpass) {
|
||||||
// Load op - depth/stencil
|
// Load op - depth/stencil
|
||||||
const auto& clear = currentFramebuffer->GetClearDepthStencil(subpass.depthStencilAttachment);
|
const auto& clear = currentFramebuffer->GetClearDepthStencil(
|
||||||
|
subpass.depthStencilAttachment);
|
||||||
bool doDepthClear = TextureFormatHasDepth(attachmentInfo.format) &&
|
bool doDepthClear = TextureFormatHasDepth(attachmentInfo.format) &&
|
||||||
(attachmentInfo.depthLoadOp == nxt::LoadOp::Clear);
|
(attachmentInfo.depthLoadOp == nxt::LoadOp::Clear);
|
||||||
bool doStencilClear = TextureFormatHasStencil(attachmentInfo.format) &&
|
bool doStencilClear =
|
||||||
|
TextureFormatHasStencil(attachmentInfo.format) &&
|
||||||
(attachmentInfo.stencilLoadOp == nxt::LoadOp::Clear);
|
(attachmentInfo.stencilLoadOp == nxt::LoadOp::Clear);
|
||||||
if (doDepthClear && doStencilClear) {
|
if (doDepthClear && doStencilClear) {
|
||||||
glClearBufferfi(GL_DEPTH_STENCIL, 0, clear.depth, clear.stencil);
|
glClearBufferfi(GL_DEPTH_STENCIL, 0, clear.depth, clear.stencil);
|
||||||
@ -357,27 +368,25 @@ namespace opengl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
glBlendColor(0, 0, 0, 0);
|
glBlendColor(0, 0, 0, 0);
|
||||||
glViewport(0, 0, currentFramebuffer->GetWidth(), currentFramebuffer->GetHeight());
|
glViewport(0, 0, currentFramebuffer->GetWidth(),
|
||||||
}
|
currentFramebuffer->GetHeight());
|
||||||
break;
|
} break;
|
||||||
|
|
||||||
case Command::CopyBufferToBuffer:
|
case Command::CopyBufferToBuffer: {
|
||||||
{
|
|
||||||
CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
|
CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
|
||||||
auto& src = copy->source;
|
auto& src = copy->source;
|
||||||
auto& dst = copy->destination;
|
auto& dst = copy->destination;
|
||||||
|
|
||||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, ToBackend(src.buffer)->GetHandle());
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, ToBackend(src.buffer)->GetHandle());
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, ToBackend(dst.buffer)->GetHandle());
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, ToBackend(dst.buffer)->GetHandle());
|
||||||
glCopyBufferSubData(GL_PIXEL_PACK_BUFFER, GL_PIXEL_UNPACK_BUFFER, src.offset, dst.offset, copy->size);
|
glCopyBufferSubData(GL_PIXEL_PACK_BUFFER, GL_PIXEL_UNPACK_BUFFER, src.offset,
|
||||||
|
dst.offset, copy->size);
|
||||||
|
|
||||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::CopyBufferToTexture:
|
case Command::CopyBufferToTexture: {
|
||||||
{
|
|
||||||
CopyBufferToTextureCmd* copy = mCommands.NextCommand<CopyBufferToTextureCmd>();
|
CopyBufferToTextureCmd* copy = mCommands.NextCommand<CopyBufferToTextureCmd>();
|
||||||
auto& src = copy->source;
|
auto& src = copy->source;
|
||||||
auto& dst = copy->destination;
|
auto& dst = copy->destination;
|
||||||
@ -391,17 +400,16 @@ namespace opengl {
|
|||||||
glBindTexture(target, texture->GetHandle());
|
glBindTexture(target, texture->GetHandle());
|
||||||
|
|
||||||
ASSERT(texture->GetDimension() == nxt::TextureDimension::e2D);
|
ASSERT(texture->GetDimension() == nxt::TextureDimension::e2D);
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, copy->rowPitch / TextureFormatPixelSize(texture->GetFormat()));
|
glPixelStorei(GL_UNPACK_ROW_LENGTH,
|
||||||
|
copy->rowPitch / TextureFormatPixelSize(texture->GetFormat()));
|
||||||
glTexSubImage2D(target, dst.level, dst.x, dst.y, dst.width, dst.height,
|
glTexSubImage2D(target, dst.level, dst.x, dst.y, dst.width, dst.height,
|
||||||
format.format, format.type,
|
format.format, format.type,
|
||||||
reinterpret_cast<void*>(static_cast<uintptr_t>(src.offset)));
|
reinterpret_cast<void*>(static_cast<uintptr_t>(src.offset)));
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::CopyTextureToBuffer:
|
case Command::CopyTextureToBuffer: {
|
||||||
{
|
|
||||||
CopyTextureToBufferCmd* copy = mCommands.NextCommand<CopyTextureToBufferCmd>();
|
CopyTextureToBufferCmd* copy = mCommands.NextCommand<CopyTextureToBufferCmd>();
|
||||||
auto& src = copy->source;
|
auto& src = copy->source;
|
||||||
auto& dst = copy->destination;
|
auto& dst = copy->destination;
|
||||||
@ -422,46 +430,44 @@ namespace opengl {
|
|||||||
texture->GetHandle(), src.level);
|
texture->GetHandle(), src.level);
|
||||||
|
|
||||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer->GetHandle());
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer->GetHandle());
|
||||||
glPixelStorei(GL_PACK_ROW_LENGTH, copy->rowPitch / TextureFormatPixelSize(texture->GetFormat()));
|
glPixelStorei(GL_PACK_ROW_LENGTH,
|
||||||
|
copy->rowPitch / TextureFormatPixelSize(texture->GetFormat()));
|
||||||
ASSERT(src.depth == 1 && src.z == 0);
|
ASSERT(src.depth == 1 && src.z == 0);
|
||||||
void* offset = reinterpret_cast<void*>(static_cast<uintptr_t>(dst.offset));
|
void* offset = reinterpret_cast<void*>(static_cast<uintptr_t>(dst.offset));
|
||||||
glReadPixels(src.x, src.y, src.width, src.height, format.format, format.type, offset);
|
glReadPixels(src.x, src.y, src.width, src.height, format.format, format.type,
|
||||||
|
offset);
|
||||||
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||||
|
|
||||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||||
glDeleteFramebuffers(1, &readFBO);
|
glDeleteFramebuffers(1, &readFBO);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::Dispatch:
|
case Command::Dispatch: {
|
||||||
{
|
|
||||||
DispatchCmd* dispatch = mCommands.NextCommand<DispatchCmd>();
|
DispatchCmd* dispatch = mCommands.NextCommand<DispatchCmd>();
|
||||||
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
||||||
glDispatchCompute(dispatch->x, dispatch->y, dispatch->z);
|
glDispatchCompute(dispatch->x, dispatch->y, dispatch->z);
|
||||||
// TODO(cwallez@chromium.org): add barriers to the API
|
// TODO(cwallez@chromium.org): add barriers to the API
|
||||||
glMemoryBarrier(GL_ALL_BARRIER_BITS);
|
glMemoryBarrier(GL_ALL_BARRIER_BITS);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::DrawArrays:
|
case Command::DrawArrays: {
|
||||||
{
|
|
||||||
DrawArraysCmd* draw = mCommands.NextCommand<DrawArraysCmd>();
|
DrawArraysCmd* draw = mCommands.NextCommand<DrawArraysCmd>();
|
||||||
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
||||||
inputBuffers.Apply();
|
inputBuffers.Apply();
|
||||||
|
|
||||||
if (draw->firstInstance > 0) {
|
if (draw->firstInstance > 0) {
|
||||||
glDrawArraysInstancedBaseInstance(lastRenderPipeline->GetGLPrimitiveTopology(),
|
glDrawArraysInstancedBaseInstance(
|
||||||
draw->firstVertex, draw->vertexCount, draw->instanceCount, draw->firstInstance);
|
lastRenderPipeline->GetGLPrimitiveTopology(), draw->firstVertex,
|
||||||
|
draw->vertexCount, draw->instanceCount, draw->firstInstance);
|
||||||
} else {
|
} else {
|
||||||
// This branch is only needed on OpenGL < 4.2
|
// This branch is only needed on OpenGL < 4.2
|
||||||
glDrawArraysInstanced(lastRenderPipeline->GetGLPrimitiveTopology(),
|
glDrawArraysInstanced(lastRenderPipeline->GetGLPrimitiveTopology(),
|
||||||
draw->firstVertex, draw->vertexCount, draw->instanceCount);
|
draw->firstVertex, draw->vertexCount,
|
||||||
|
draw->instanceCount);
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::DrawElements:
|
case Command::DrawElements: {
|
||||||
{
|
|
||||||
DrawElementsCmd* draw = mCommands.NextCommand<DrawElementsCmd>();
|
DrawElementsCmd* draw = mCommands.NextCommand<DrawElementsCmd>();
|
||||||
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
||||||
inputBuffers.Apply();
|
inputBuffers.Apply();
|
||||||
@ -471,53 +477,47 @@ namespace opengl {
|
|||||||
GLenum formatType = IndexFormatType(indexFormat);
|
GLenum formatType = IndexFormatType(indexFormat);
|
||||||
|
|
||||||
if (draw->firstInstance > 0) {
|
if (draw->firstInstance > 0) {
|
||||||
glDrawElementsInstancedBaseInstance(lastRenderPipeline->GetGLPrimitiveTopology(),
|
glDrawElementsInstancedBaseInstance(
|
||||||
draw->indexCount, formatType,
|
lastRenderPipeline->GetGLPrimitiveTopology(), draw->indexCount,
|
||||||
reinterpret_cast<void*>(draw->firstIndex * formatSize + indexBufferOffset),
|
formatType,
|
||||||
|
reinterpret_cast<void*>(draw->firstIndex * formatSize +
|
||||||
|
indexBufferOffset),
|
||||||
draw->instanceCount, draw->firstInstance);
|
draw->instanceCount, draw->firstInstance);
|
||||||
} else {
|
} else {
|
||||||
// This branch is only needed on OpenGL < 4.2
|
// This branch is only needed on OpenGL < 4.2
|
||||||
glDrawElementsInstanced(lastRenderPipeline->GetGLPrimitiveTopology(),
|
glDrawElementsInstanced(
|
||||||
draw->indexCount, formatType,
|
lastRenderPipeline->GetGLPrimitiveTopology(), draw->indexCount,
|
||||||
reinterpret_cast<void*>(draw->firstIndex * formatSize + indexBufferOffset),
|
formatType,
|
||||||
|
reinterpret_cast<void*>(draw->firstIndex * formatSize +
|
||||||
|
indexBufferOffset),
|
||||||
draw->instanceCount);
|
draw->instanceCount);
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::EndComputePass:
|
case Command::EndComputePass: {
|
||||||
{
|
|
||||||
mCommands.NextCommand<EndComputePassCmd>();
|
mCommands.NextCommand<EndComputePassCmd>();
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::EndRenderPass:
|
case Command::EndRenderPass: {
|
||||||
{
|
|
||||||
mCommands.NextCommand<EndRenderPassCmd>();
|
mCommands.NextCommand<EndRenderPassCmd>();
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::EndRenderSubpass:
|
case Command::EndRenderSubpass: {
|
||||||
{
|
|
||||||
mCommands.NextCommand<EndRenderSubpassCmd>();
|
mCommands.NextCommand<EndRenderSubpassCmd>();
|
||||||
glDeleteFramebuffers(1, ¤tFBO);
|
glDeleteFramebuffers(1, ¤tFBO);
|
||||||
currentFBO = 0;
|
currentFBO = 0;
|
||||||
currentSubpass += 1;
|
currentSubpass += 1;
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::SetComputePipeline:
|
case Command::SetComputePipeline: {
|
||||||
{
|
|
||||||
SetComputePipelineCmd* cmd = mCommands.NextCommand<SetComputePipelineCmd>();
|
SetComputePipelineCmd* cmd = mCommands.NextCommand<SetComputePipelineCmd>();
|
||||||
ToBackend(cmd->pipeline)->ApplyNow();
|
ToBackend(cmd->pipeline)->ApplyNow();
|
||||||
lastGLPipeline = ToBackend(cmd->pipeline).Get();
|
lastGLPipeline = ToBackend(cmd->pipeline).Get();
|
||||||
lastPipeline = ToBackend(cmd->pipeline).Get();
|
lastPipeline = ToBackend(cmd->pipeline).Get();
|
||||||
pushConstants.OnSetPipeline(lastPipeline);
|
pushConstants.OnSetPipeline(lastPipeline);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::SetRenderPipeline:
|
case Command::SetRenderPipeline: {
|
||||||
{
|
|
||||||
SetRenderPipelineCmd* cmd = mCommands.NextCommand<SetRenderPipelineCmd>();
|
SetRenderPipelineCmd* cmd = mCommands.NextCommand<SetRenderPipelineCmd>();
|
||||||
ToBackend(cmd->pipeline)->ApplyNow(persistentPipelineState);
|
ToBackend(cmd->pipeline)->ApplyNow(persistentPipelineState);
|
||||||
lastRenderPipeline = ToBackend(cmd->pipeline).Get();
|
lastRenderPipeline = ToBackend(cmd->pipeline).Get();
|
||||||
@ -526,124 +526,110 @@ namespace opengl {
|
|||||||
|
|
||||||
pushConstants.OnSetPipeline(lastPipeline);
|
pushConstants.OnSetPipeline(lastPipeline);
|
||||||
inputBuffers.OnSetPipeline(lastRenderPipeline);
|
inputBuffers.OnSetPipeline(lastRenderPipeline);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::SetPushConstants:
|
case Command::SetPushConstants: {
|
||||||
{
|
|
||||||
SetPushConstantsCmd* cmd = mCommands.NextCommand<SetPushConstantsCmd>();
|
SetPushConstantsCmd* cmd = mCommands.NextCommand<SetPushConstantsCmd>();
|
||||||
uint32_t* data = mCommands.NextData<uint32_t>(cmd->count);
|
uint32_t* data = mCommands.NextData<uint32_t>(cmd->count);
|
||||||
pushConstants.OnSetPushConstants(cmd->stages, cmd->count, cmd->offset, data);
|
pushConstants.OnSetPushConstants(cmd->stages, cmd->count, cmd->offset, data);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::SetStencilReference:
|
case Command::SetStencilReference: {
|
||||||
{
|
|
||||||
SetStencilReferenceCmd* cmd = mCommands.NextCommand<SetStencilReferenceCmd>();
|
SetStencilReferenceCmd* cmd = mCommands.NextCommand<SetStencilReferenceCmd>();
|
||||||
persistentPipelineState.SetStencilReference(cmd->reference);
|
persistentPipelineState.SetStencilReference(cmd->reference);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::SetBlendColor:
|
case Command::SetBlendColor: {
|
||||||
{
|
|
||||||
SetBlendColorCmd* cmd = mCommands.NextCommand<SetBlendColorCmd>();
|
SetBlendColorCmd* cmd = mCommands.NextCommand<SetBlendColorCmd>();
|
||||||
glBlendColor(cmd->r, cmd->g, cmd->b, cmd->a);
|
glBlendColor(cmd->r, cmd->g, cmd->b, cmd->a);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::SetBindGroup:
|
case Command::SetBindGroup: {
|
||||||
{
|
|
||||||
SetBindGroupCmd* cmd = mCommands.NextCommand<SetBindGroupCmd>();
|
SetBindGroupCmd* cmd = mCommands.NextCommand<SetBindGroupCmd>();
|
||||||
size_t groupIndex = cmd->index;
|
size_t groupIndex = cmd->index;
|
||||||
BindGroup* group = ToBackend(cmd->group.Get());
|
BindGroup* group = ToBackend(cmd->group.Get());
|
||||||
|
|
||||||
const auto& indices = ToBackend(lastPipeline->GetLayout())->GetBindingIndexInfo()[groupIndex];
|
const auto& indices =
|
||||||
|
ToBackend(lastPipeline->GetLayout())->GetBindingIndexInfo()[groupIndex];
|
||||||
const auto& layout = group->GetLayout()->GetBindingInfo();
|
const auto& layout = group->GetLayout()->GetBindingInfo();
|
||||||
|
|
||||||
for (uint32_t binding : IterateBitSet(layout.mask)) {
|
for (uint32_t binding : IterateBitSet(layout.mask)) {
|
||||||
switch (layout.types[binding]) {
|
switch (layout.types[binding]) {
|
||||||
case nxt::BindingType::UniformBuffer:
|
case nxt::BindingType::UniformBuffer: {
|
||||||
{
|
BufferView* view =
|
||||||
BufferView* view = ToBackend(group->GetBindingAsBufferView(binding));
|
ToBackend(group->GetBindingAsBufferView(binding));
|
||||||
GLuint buffer = ToBackend(view->GetBuffer())->GetHandle();
|
GLuint buffer = ToBackend(view->GetBuffer())->GetHandle();
|
||||||
GLuint uboIndex = indices[binding];
|
GLuint uboIndex = indices[binding];
|
||||||
|
|
||||||
glBindBufferRange(GL_UNIFORM_BUFFER, uboIndex, buffer, view->GetOffset(), view->GetSize());
|
glBindBufferRange(GL_UNIFORM_BUFFER, uboIndex, buffer,
|
||||||
}
|
view->GetOffset(), view->GetSize());
|
||||||
break;
|
} break;
|
||||||
|
|
||||||
case nxt::BindingType::Sampler:
|
case nxt::BindingType::Sampler: {
|
||||||
{
|
GLuint sampler =
|
||||||
GLuint sampler = ToBackend(group->GetBindingAsSampler(binding))->GetHandle();
|
ToBackend(group->GetBindingAsSampler(binding))->GetHandle();
|
||||||
GLuint samplerIndex = indices[binding];
|
GLuint samplerIndex = indices[binding];
|
||||||
|
|
||||||
for (auto unit : lastGLPipeline->GetTextureUnitsForSampler(samplerIndex)) {
|
for (auto unit :
|
||||||
|
lastGLPipeline->GetTextureUnitsForSampler(samplerIndex)) {
|
||||||
glBindSampler(unit, sampler);
|
glBindSampler(unit, sampler);
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case nxt::BindingType::SampledTexture:
|
case nxt::BindingType::SampledTexture: {
|
||||||
{
|
TextureView* view =
|
||||||
TextureView* view = ToBackend(group->GetBindingAsTextureView(binding));
|
ToBackend(group->GetBindingAsTextureView(binding));
|
||||||
Texture* texture = ToBackend(view->GetTexture());
|
Texture* texture = ToBackend(view->GetTexture());
|
||||||
GLuint handle = texture->GetHandle();
|
GLuint handle = texture->GetHandle();
|
||||||
GLenum target = texture->GetGLTarget();
|
GLenum target = texture->GetGLTarget();
|
||||||
GLuint textureIndex = indices[binding];
|
GLuint textureIndex = indices[binding];
|
||||||
|
|
||||||
for (auto unit : lastGLPipeline->GetTextureUnitsForTexture(textureIndex)) {
|
for (auto unit :
|
||||||
|
lastGLPipeline->GetTextureUnitsForTexture(textureIndex)) {
|
||||||
glActiveTexture(GL_TEXTURE0 + unit);
|
glActiveTexture(GL_TEXTURE0 + unit);
|
||||||
glBindTexture(target, handle);
|
glBindTexture(target, handle);
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case nxt::BindingType::StorageBuffer:
|
case nxt::BindingType::StorageBuffer: {
|
||||||
{
|
BufferView* view =
|
||||||
BufferView* view = ToBackend(group->GetBindingAsBufferView(binding));
|
ToBackend(group->GetBindingAsBufferView(binding));
|
||||||
GLuint buffer = ToBackend(view->GetBuffer())->GetHandle();
|
GLuint buffer = ToBackend(view->GetBuffer())->GetHandle();
|
||||||
GLuint ssboIndex = indices[binding];
|
GLuint ssboIndex = indices[binding];
|
||||||
|
|
||||||
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, ssboIndex, buffer, view->GetOffset(), view->GetSize());
|
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, ssboIndex, buffer,
|
||||||
}
|
view->GetOffset(), view->GetSize());
|
||||||
break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::SetIndexBuffer:
|
case Command::SetIndexBuffer: {
|
||||||
{
|
|
||||||
SetIndexBufferCmd* cmd = mCommands.NextCommand<SetIndexBufferCmd>();
|
SetIndexBufferCmd* cmd = mCommands.NextCommand<SetIndexBufferCmd>();
|
||||||
indexBufferOffset = cmd->offset;
|
indexBufferOffset = cmd->offset;
|
||||||
inputBuffers.OnSetIndexBuffer(cmd->buffer.Get());
|
inputBuffers.OnSetIndexBuffer(cmd->buffer.Get());
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::SetVertexBuffers:
|
case Command::SetVertexBuffers: {
|
||||||
{
|
|
||||||
SetVertexBuffersCmd* cmd = mCommands.NextCommand<SetVertexBuffersCmd>();
|
SetVertexBuffersCmd* cmd = mCommands.NextCommand<SetVertexBuffersCmd>();
|
||||||
auto buffers = mCommands.NextData<Ref<BufferBase>>(cmd->count);
|
auto buffers = mCommands.NextData<Ref<BufferBase>>(cmd->count);
|
||||||
auto offsets = mCommands.NextData<uint32_t>(cmd->count);
|
auto offsets = mCommands.NextData<uint32_t>(cmd->count);
|
||||||
inputBuffers.OnSetVertexBuffers(cmd->startSlot, cmd->count, buffers, offsets);
|
inputBuffers.OnSetVertexBuffers(cmd->startSlot, cmd->count, buffers, offsets);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::TransitionBufferUsage:
|
case Command::TransitionBufferUsage: {
|
||||||
{
|
TransitionBufferUsageCmd* cmd =
|
||||||
TransitionBufferUsageCmd* cmd = mCommands.NextCommand<TransitionBufferUsageCmd>();
|
mCommands.NextCommand<TransitionBufferUsageCmd>();
|
||||||
|
|
||||||
cmd->buffer->UpdateUsageInternal(cmd->usage);
|
cmd->buffer->UpdateUsageInternal(cmd->usage);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case Command::TransitionTextureUsage:
|
case Command::TransitionTextureUsage: {
|
||||||
{
|
TransitionTextureUsageCmd* cmd =
|
||||||
TransitionTextureUsageCmd* cmd = mCommands.NextCommand<TransitionTextureUsageCmd>();
|
mCommands.NextCommand<TransitionTextureUsageCmd>();
|
||||||
|
|
||||||
cmd->texture->UpdateUsageInternal(cmd->usage);
|
cmd->texture->UpdateUsageInternal(cmd->usage);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,5 +638,4 @@ namespace opengl {
|
|||||||
glBindSampler(0, 0);
|
glBindSampler(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
@ -18,8 +18,7 @@
|
|||||||
#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;
|
||||||
|
|
||||||
@ -34,7 +33,6 @@ namespace opengl {
|
|||||||
CommandIterator mCommands;
|
CommandIterator mCommands;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
|
||||||
#endif // BACKEND_OPENGL_COMMANDBUFFERGL_H_
|
#endif // BACKEND_OPENGL_COMMANDBUFFERGL_H_
|
||||||
|
@ -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
|
||||||
}
|
|
||||||
|
@ -21,8 +21,7 @@
|
|||||||
|
|
||||||
#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:
|
||||||
@ -31,7 +30,6 @@ namespace opengl {
|
|||||||
void ApplyNow();
|
void ApplyNow();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
|
||||||
#endif // BACKEND_OPENGL_COMPUTEPIPELINEGL_H_
|
#endif // BACKEND_OPENGL_COMPUTEPIPELINEGL_H_
|
||||||
|
@ -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),
|
||||||
glStencilOpSeparate(GL_FRONT,
|
|
||||||
OpenGLStencilOperation(stencilInfo.front.stencilFail),
|
|
||||||
OpenGLStencilOperation(stencilInfo.front.depthFail),
|
OpenGLStencilOperation(stencilInfo.front.depthFail),
|
||||||
OpenGLStencilOperation(stencilInfo.front.depthStencilPass)
|
OpenGLStencilOperation(stencilInfo.front.depthStencilPass));
|
||||||
);
|
|
||||||
|
|
||||||
glStencilMask(stencilInfo.writeMask);
|
glStencilMask(stencilInfo.writeMask);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
@ -17,8 +17,7 @@
|
|||||||
|
|
||||||
#include "backend/DepthStencilState.h"
|
#include "backend/DepthStencilState.h"
|
||||||
|
|
||||||
namespace backend {
|
namespace backend { namespace opengl {
|
||||||
namespace opengl {
|
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class PersistentPipelineState;
|
class PersistentPipelineState;
|
||||||
@ -27,10 +26,9 @@ namespace opengl {
|
|||||||
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_
|
||||||
|
@ -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"
|
||||||
|
@ -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
|
||||||
}
|
|
||||||
|
@ -19,8 +19,7 @@
|
|||||||
|
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
|
|
||||||
namespace backend {
|
namespace backend { namespace opengl {
|
||||||
namespace opengl {
|
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
|
|
||||||
@ -36,7 +35,6 @@ namespace opengl {
|
|||||||
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_
|
||||||
|
@ -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
|
||||||
}
|
|
||||||
|
@ -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,7 +78,7 @@ 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);
|
||||||
}
|
}
|
||||||
@ -130,7 +129,7 @@ namespace opengl {
|
|||||||
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 {
|
||||||
@ -138,7 +137,6 @@ namespace opengl {
|
|||||||
RenderPass(RenderPassBuilder* builder);
|
RenderPass(RenderPassBuilder* builder);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
|
||||||
#endif // BACKEND_OPENGL_OPENGLBACKEND_H_
|
#endif // BACKEND_OPENGL_OPENGLBACKEND_H_
|
||||||
|
@ -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,
|
|
||||||
mStencilReference,
|
|
||||||
mStencilReadMask);
|
mStencilReadMask);
|
||||||
glStencilFuncSeparate(GL_FRONT,
|
glStencilFuncSeparate(GL_FRONT, mStencilFrontCompareFunction, mStencilReference,
|
||||||
mStencilFrontCompareFunction,
|
|
||||||
mStencilReference,
|
|
||||||
mStencilReadMask);
|
mStencilReadMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
@ -19,13 +19,14 @@
|
|||||||
|
|
||||||
#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,
|
||||||
|
GLenum stencilFrontCompareFunction,
|
||||||
|
uint32_t stencilReadMask);
|
||||||
void SetStencilReference(uint32_t stencilReference);
|
void SetStencilReference(uint32_t stencilReference);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -37,7 +38,6 @@ namespace opengl {
|
|||||||
GLuint mStencilReference = 0;
|
GLuint mStencilReference = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
|
||||||
#endif // BACKEND_OPENGL_PERSISTENTPIPELINESTATE_H_
|
#endif // BACKEND_OPENGL_PERSISTENTPIPELINESTATE_H_
|
||||||
|
@ -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
|
||||||
}
|
|
||||||
|
@ -21,8 +21,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace backend {
|
namespace backend { namespace opengl {
|
||||||
namespace opengl {
|
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class PersistentPipelineState;
|
class PersistentPipelineState;
|
||||||
@ -33,7 +32,8 @@ namespace opengl {
|
|||||||
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;
|
||||||
@ -49,7 +49,6 @@ namespace opengl {
|
|||||||
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_
|
||||||
|
@ -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
|
||||||
}
|
|
||||||
|
@ -19,8 +19,7 @@
|
|||||||
|
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
|
|
||||||
namespace backend {
|
namespace backend { namespace opengl {
|
||||||
namespace opengl {
|
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
|
|
||||||
@ -28,7 +27,8 @@ namespace opengl {
|
|||||||
public:
|
public:
|
||||||
PipelineLayout(PipelineLayoutBuilder* builder);
|
PipelineLayout(PipelineLayoutBuilder* builder);
|
||||||
|
|
||||||
using BindingIndexInfo = std::array<std::array<GLuint, kMaxBindingsPerGroup>, kMaxBindGroups>;
|
using BindingIndexInfo =
|
||||||
|
std::array<std::array<GLuint, kMaxBindingsPerGroup>, kMaxBindGroups>;
|
||||||
const BindingIndexInfo& GetBindingIndexInfo() const;
|
const BindingIndexInfo& GetBindingIndexInfo() const;
|
||||||
|
|
||||||
GLuint GetTextureUnitsUsed() const;
|
GLuint GetTextureUnitsUsed() const;
|
||||||
@ -41,7 +41,6 @@ namespace opengl {
|
|||||||
size_t mNumSampledTextures;
|
size_t mNumSampledTextures;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
|
||||||
#endif // BACKEND_OPENGL_PIPELINELAYOUTGL_H_
|
#endif // BACKEND_OPENGL_PIPELINELAYOUTGL_H_
|
||||||
|
@ -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
|
||||||
}
|
|
||||||
|
@ -23,8 +23,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace backend {
|
namespace backend { namespace opengl {
|
||||||
namespace opengl {
|
|
||||||
|
|
||||||
class PersistentPipelineState;
|
class PersistentPipelineState;
|
||||||
|
|
||||||
@ -34,13 +33,12 @@ namespace opengl {
|
|||||||
|
|
||||||
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_
|
||||||
|
@ -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
|
||||||
}
|
|
||||||
|
@ -19,8 +19,7 @@
|
|||||||
|
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
|
|
||||||
namespace backend {
|
namespace backend { namespace opengl {
|
||||||
namespace opengl {
|
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
|
|
||||||
@ -34,7 +33,6 @@ namespace opengl {
|
|||||||
GLuint mHandle;
|
GLuint mHandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
|
||||||
#endif // BACKEND_OPENGL_SAMPLERGL_H_
|
#endif // BACKEND_OPENGL_SAMPLERGL_H_
|
||||||
|
@ -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
|
||||||
}
|
|
||||||
|
@ -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,14 +29,14 @@ 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:
|
||||||
@ -53,7 +52,6 @@ namespace opengl {
|
|||||||
std::string mGlslSource;
|
std::string mGlslSource;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
|
||||||
#endif // BACKEND_OPENGL_SHADERMODULEGL_H_
|
#endif // BACKEND_OPENGL_SHADERMODULEGL_H_
|
||||||
|
@ -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
|
||||||
}
|
|
||||||
|
@ -19,8 +19,7 @@
|
|||||||
|
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
|
|
||||||
namespace backend {
|
namespace backend { namespace opengl {
|
||||||
namespace opengl {
|
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
|
|
||||||
@ -33,7 +32,6 @@ namespace opengl {
|
|||||||
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
|
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
|
|
||||||
#endif // BACKEND_OPENGL_SWAPCHAINGL_H_
|
#endif // BACKEND_OPENGL_SWAPCHAINGL_H_
|
||||||
|
@ -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
|
||||||
}
|
|
||||||
|
@ -19,8 +19,7 @@
|
|||||||
|
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
|
|
||||||
namespace backend {
|
namespace backend { namespace opengl {
|
||||||
namespace opengl {
|
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
|
|
||||||
@ -40,7 +39,8 @@ namespace opengl {
|
|||||||
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;
|
||||||
@ -52,8 +52,6 @@ namespace opengl {
|
|||||||
TextureView(TextureViewBuilder* builder);
|
TextureView(TextureViewBuilder* builder);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}} // namespace backend::opengl
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // BACKEND_OPENGL_TEXTUREGL_H_
|
#endif // BACKEND_OPENGL_TEXTUREGL_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user