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