mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-08-04 11:15:46 +00:00
Member rename: src/backend/opengl
This commit is contained in:
parent
b0c75a5b68
commit
7ee1610f38
@ -23,17 +23,17 @@ namespace opengl {
|
||||
|
||||
Buffer::Buffer(BufferBuilder* builder)
|
||||
: BufferBase(builder) {
|
||||
glGenBuffers(1, &buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glGenBuffers(1, &mBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, GetSize(), nullptr, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
GLuint Buffer::GetHandle() const {
|
||||
return buffer;
|
||||
return mBuffer;
|
||||
}
|
||||
|
||||
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, start * sizeof(uint32_t), count * sizeof(uint32_t), data);
|
||||
}
|
||||
|
||||
@ -41,13 +41,13 @@ namespace opengl {
|
||||
// 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?
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
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);
|
||||
}
|
||||
|
||||
void Buffer::UnmapImpl() {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace opengl {
|
||||
void UnmapImpl() override;
|
||||
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override;
|
||||
|
||||
GLuint buffer = 0;
|
||||
GLuint mBuffer = 0;
|
||||
};
|
||||
|
||||
class BufferView : public BufferViewBase {
|
||||
|
@ -61,145 +61,149 @@ namespace opengl {
|
||||
//
|
||||
// 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.
|
||||
struct PushConstantTracker {
|
||||
PerStage<std::array<uint32_t, kMaxPushConstants>> values;
|
||||
PerStage<std::bitset<kMaxPushConstants>> dirtyBits;
|
||||
|
||||
void OnBeginPass() {
|
||||
for (auto stage : IterateStages(kAllStages)) {
|
||||
values[stage].fill(0);
|
||||
// No need to set dirty bits as a pipeline will be set before the next operation
|
||||
// using push constants.
|
||||
}
|
||||
}
|
||||
|
||||
void OnSetPushConstants(nxt::ShaderStageBit stages, uint32_t count,
|
||||
uint32_t offset, const uint32_t* data) {
|
||||
for (auto stage : IterateStages(stages)) {
|
||||
memcpy(&values[stage][offset], data, count * sizeof(uint32_t));
|
||||
|
||||
// Use 64 bit masks and make sure there are no shift UB
|
||||
static_assert(kMaxPushConstants <= 8 * sizeof(unsigned long long) - 1, "");
|
||||
dirtyBits[stage] |= ((1ull << count) - 1ull) << offset;
|
||||
}
|
||||
}
|
||||
|
||||
void OnSetPipeline(PipelineBase* pipeline) {
|
||||
for (auto stage : IterateStages(kAllStages)) {
|
||||
dirtyBits[stage] = pipeline->GetPushConstants(stage).mask;
|
||||
}
|
||||
}
|
||||
|
||||
void Apply(PipelineBase* pipeline, PipelineGL* glPipeline) {
|
||||
for (auto stage : IterateStages(kAllStages)) {
|
||||
const auto& pushConstants = pipeline->GetPushConstants(stage);
|
||||
const auto& glPushConstants = glPipeline->GetGLPushConstants(stage);
|
||||
|
||||
for (uint32_t constant : IterateBitSet(dirtyBits[stage] & pushConstants.mask)) {
|
||||
GLint location = glPushConstants[constant];
|
||||
switch (pushConstants.types[constant]) {
|
||||
case PushConstantType::Int:
|
||||
glUniform1i(location, *reinterpret_cast<GLint*>(&values[stage][constant]));
|
||||
break;
|
||||
case PushConstantType::UInt:
|
||||
glUniform1ui(location, *reinterpret_cast<GLuint*>(&values[stage][constant]));
|
||||
break;
|
||||
case PushConstantType::Float:
|
||||
glUniform1f(location, *reinterpret_cast<GLfloat*>(&values[stage][constant]));
|
||||
break;
|
||||
}
|
||||
class PushConstantTracker {
|
||||
public:
|
||||
void OnBeginPass() {
|
||||
for (auto stage : IterateStages(kAllStages)) {
|
||||
mValues[stage].fill(0);
|
||||
// No need to set dirty bits as a pipeline will be set before the next operation
|
||||
// using push constants.
|
||||
}
|
||||
|
||||
dirtyBits[stage].reset();
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
// Use 64 bit masks and make sure there are no shift UB
|
||||
static_assert(kMaxPushConstants <= 8 * sizeof(unsigned long long) - 1, "");
|
||||
mDirtyBits[stage] |= ((1ull << count) - 1ull) << offset;
|
||||
}
|
||||
}
|
||||
|
||||
void OnSetPipeline(PipelineBase* pipeline) {
|
||||
for (auto stage : IterateStages(kAllStages)) {
|
||||
mDirtyBits[stage] = pipeline->GetPushConstants(stage).mask;
|
||||
}
|
||||
}
|
||||
|
||||
void Apply(PipelineBase* pipeline, PipelineGL* glPipeline) {
|
||||
for (auto stage : IterateStages(kAllStages)) {
|
||||
const auto& pushConstants = pipeline->GetPushConstants(stage);
|
||||
const auto& glPushConstants = glPipeline->GetGLPushConstants(stage);
|
||||
|
||||
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]));
|
||||
break;
|
||||
case PushConstantType::UInt:
|
||||
glUniform1ui(location, *reinterpret_cast<GLuint*>(&mValues[stage][constant]));
|
||||
break;
|
||||
case PushConstantType::Float:
|
||||
glUniform1f(location, *reinterpret_cast<GLfloat*>(&mValues[stage][constant]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mDirtyBits[stage].reset();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
PerStage<std::array<uint32_t, kMaxPushConstants>> mValues;
|
||||
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.
|
||||
struct InputBufferTracker {
|
||||
bool indexBufferDirty = false;
|
||||
Buffer* indexBuffer = nullptr;
|
||||
|
||||
std::bitset<kMaxVertexInputs> dirtyVertexBuffers;
|
||||
std::array<Buffer*, kMaxVertexInputs> vertexBuffers;
|
||||
std::array<uint32_t, kMaxVertexInputs> vertexBufferOffsets;
|
||||
|
||||
InputState* lastInputState = nullptr;
|
||||
|
||||
void OnBeginPass() {
|
||||
// We don't know what happened between this pass and the last one, just reset the
|
||||
// input state so everything gets reapplied.
|
||||
lastInputState = nullptr;
|
||||
}
|
||||
|
||||
void OnSetIndexBuffer(BufferBase* buffer) {
|
||||
indexBufferDirty = true;
|
||||
indexBuffer = ToBackend(buffer);
|
||||
}
|
||||
|
||||
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;
|
||||
vertexBuffers[slot] = ToBackend(buffers[i].Get());
|
||||
vertexBufferOffsets[slot] = offsets[i];
|
||||
class InputBufferTracker {
|
||||
public:
|
||||
void OnBeginPass() {
|
||||
// We don't know what happened between this pass and the last one, just reset the
|
||||
// input state so everything gets reapplied.
|
||||
mLastInputState = nullptr;
|
||||
}
|
||||
|
||||
// Use 64 bit masks and make sure there are no shift UB
|
||||
static_assert(kMaxVertexInputs <= 8 * sizeof(unsigned long long) - 1, "");
|
||||
dirtyVertexBuffers |= ((1ull << count) - 1ull) << startSlot;
|
||||
}
|
||||
|
||||
void OnSetPipeline(RenderPipelineBase* pipeline) {
|
||||
InputStateBase* inputState = pipeline->GetInputState();
|
||||
if (lastInputState == inputState) {
|
||||
return;
|
||||
void OnSetIndexBuffer(BufferBase* buffer) {
|
||||
mIndexBufferDirty = true;
|
||||
mIndexBuffer = ToBackend(buffer);
|
||||
}
|
||||
|
||||
indexBufferDirty = true;
|
||||
dirtyVertexBuffers |= inputState->GetInputsSetMask();
|
||||
|
||||
lastInputState = ToBackend(inputState);
|
||||
}
|
||||
|
||||
void Apply() {
|
||||
if (indexBufferDirty && indexBuffer != nullptr) {
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer->GetHandle());
|
||||
indexBufferDirty = false;
|
||||
}
|
||||
|
||||
for (uint32_t slot : IterateBitSet(dirtyVertexBuffers & lastInputState->GetInputsSetMask())) {
|
||||
for (uint32_t location : IterateBitSet(lastInputState->GetAttributesUsingInput(slot))) {
|
||||
auto attribute = lastInputState->GetAttribute(location);
|
||||
|
||||
GLuint buffer = vertexBuffers[slot]->GetHandle();
|
||||
uint32_t offset = vertexBufferOffsets[slot];
|
||||
|
||||
auto input = lastInputState->GetInput(slot);
|
||||
auto components = VertexFormatNumComponents(attribute.format);
|
||||
auto formatType = VertexFormatType(attribute.format);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glVertexAttribPointer(
|
||||
location, components, formatType, GL_FALSE,
|
||||
input.stride,
|
||||
reinterpret_cast<void*>(static_cast<intptr_t>(offset + attribute.offset)));
|
||||
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());
|
||||
mVertexBufferOffsets[slot] = offsets[i];
|
||||
}
|
||||
|
||||
// Use 64 bit masks and make sure there are no shift UB
|
||||
static_assert(kMaxVertexInputs <= 8 * sizeof(unsigned long long) - 1, "");
|
||||
mDirtyVertexBuffers |= ((1ull << count) - 1ull) << startSlot;
|
||||
}
|
||||
|
||||
dirtyVertexBuffers.reset();
|
||||
}
|
||||
void OnSetPipeline(RenderPipelineBase* pipeline) {
|
||||
InputStateBase* inputState = pipeline->GetInputState();
|
||||
if (mLastInputState == inputState) {
|
||||
return;
|
||||
}
|
||||
|
||||
mIndexBufferDirty = true;
|
||||
mDirtyVertexBuffers |= inputState->GetInputsSetMask();
|
||||
|
||||
mLastInputState = ToBackend(inputState);
|
||||
}
|
||||
|
||||
void Apply() {
|
||||
if (mIndexBufferDirty && mIndexBuffer != nullptr) {
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer->GetHandle());
|
||||
mIndexBufferDirty = false;
|
||||
}
|
||||
|
||||
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();
|
||||
uint32_t offset = mVertexBufferOffsets[slot];
|
||||
|
||||
auto input = mLastInputState->GetInput(slot);
|
||||
auto components = VertexFormatNumComponents(attribute.format);
|
||||
auto formatType = VertexFormatType(attribute.format);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glVertexAttribPointer(
|
||||
location, components, formatType, GL_FALSE,
|
||||
input.stride,
|
||||
reinterpret_cast<void*>(static_cast<intptr_t>(offset + attribute.offset)));
|
||||
}
|
||||
}
|
||||
|
||||
mDirtyVertexBuffers.reset();
|
||||
}
|
||||
|
||||
private:
|
||||
bool mIndexBufferDirty = false;
|
||||
Buffer* mIndexBuffer = nullptr;
|
||||
|
||||
std::bitset<kMaxVertexInputs> mDirtyVertexBuffers;
|
||||
std::array<Buffer*, kMaxVertexInputs> mVertexBuffers;
|
||||
std::array<uint32_t, kMaxVertexInputs> mVertexBufferOffsets;
|
||||
|
||||
InputState* mLastInputState = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
CommandBuffer::CommandBuffer(CommandBufferBuilder* builder)
|
||||
: CommandBufferBase(builder), commands(builder->AcquireCommands()) {
|
||||
: CommandBufferBase(builder), mCommands(builder->AcquireCommands()) {
|
||||
}
|
||||
|
||||
CommandBuffer::~CommandBuffer() {
|
||||
FreeCommands(&commands);
|
||||
FreeCommands(&mCommands);
|
||||
}
|
||||
|
||||
void CommandBuffer::Execute() {
|
||||
@ -220,18 +224,18 @@ namespace opengl {
|
||||
uint32_t currentSubpass = 0;
|
||||
GLuint currentFBO = 0;
|
||||
|
||||
while(commands.NextCommandId(&type)) {
|
||||
while(mCommands.NextCommandId(&type)) {
|
||||
switch (type) {
|
||||
case Command::BeginComputePass:
|
||||
{
|
||||
commands.NextCommand<BeginComputePassCmd>();
|
||||
mCommands.NextCommand<BeginComputePassCmd>();
|
||||
pushConstants.OnBeginPass();
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::BeginRenderPass:
|
||||
{
|
||||
auto* cmd = commands.NextCommand<BeginRenderPassCmd>();
|
||||
auto* cmd = mCommands.NextCommand<BeginRenderPassCmd>();
|
||||
currentRenderPass = ToBackend(cmd->renderPass.Get());
|
||||
currentFramebuffer = ToBackend(cmd->framebuffer.Get());
|
||||
currentSubpass = 0;
|
||||
@ -240,7 +244,7 @@ namespace opengl {
|
||||
|
||||
case Command::BeginRenderSubpass:
|
||||
{
|
||||
commands.NextCommand<BeginRenderSubpassCmd>();
|
||||
mCommands.NextCommand<BeginRenderSubpassCmd>();
|
||||
pushConstants.OnBeginPass();
|
||||
inputBuffers.OnBeginPass();
|
||||
|
||||
@ -359,7 +363,7 @@ namespace opengl {
|
||||
|
||||
case Command::CopyBufferToBuffer:
|
||||
{
|
||||
CopyBufferToBufferCmd* copy = commands.NextCommand<CopyBufferToBufferCmd>();
|
||||
CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
|
||||
auto& src = copy->source;
|
||||
auto& dst = copy->destination;
|
||||
|
||||
@ -374,7 +378,7 @@ namespace opengl {
|
||||
|
||||
case Command::CopyBufferToTexture:
|
||||
{
|
||||
CopyBufferToTextureCmd* copy = commands.NextCommand<CopyBufferToTextureCmd>();
|
||||
CopyBufferToTextureCmd* copy = mCommands.NextCommand<CopyBufferToTextureCmd>();
|
||||
auto& src = copy->source;
|
||||
auto& dst = copy->destination;
|
||||
Buffer* buffer = ToBackend(src.buffer.Get());
|
||||
@ -398,7 +402,7 @@ namespace opengl {
|
||||
|
||||
case Command::CopyTextureToBuffer:
|
||||
{
|
||||
CopyTextureToBufferCmd* copy = commands.NextCommand<CopyTextureToBufferCmd>();
|
||||
CopyTextureToBufferCmd* copy = mCommands.NextCommand<CopyTextureToBufferCmd>();
|
||||
auto& src = copy->source;
|
||||
auto& dst = copy->destination;
|
||||
Texture* texture = ToBackend(src.texture.Get());
|
||||
@ -431,7 +435,7 @@ namespace opengl {
|
||||
|
||||
case Command::Dispatch:
|
||||
{
|
||||
DispatchCmd* dispatch = commands.NextCommand<DispatchCmd>();
|
||||
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
|
||||
@ -441,7 +445,7 @@ namespace opengl {
|
||||
|
||||
case Command::DrawArrays:
|
||||
{
|
||||
DrawArraysCmd* draw = commands.NextCommand<DrawArraysCmd>();
|
||||
DrawArraysCmd* draw = mCommands.NextCommand<DrawArraysCmd>();
|
||||
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
||||
inputBuffers.Apply();
|
||||
|
||||
@ -458,7 +462,7 @@ namespace opengl {
|
||||
|
||||
case Command::DrawElements:
|
||||
{
|
||||
DrawElementsCmd* draw = commands.NextCommand<DrawElementsCmd>();
|
||||
DrawElementsCmd* draw = mCommands.NextCommand<DrawElementsCmd>();
|
||||
pushConstants.Apply(lastPipeline, lastGLPipeline);
|
||||
inputBuffers.Apply();
|
||||
|
||||
@ -483,19 +487,19 @@ namespace opengl {
|
||||
|
||||
case Command::EndComputePass:
|
||||
{
|
||||
commands.NextCommand<EndComputePassCmd>();
|
||||
mCommands.NextCommand<EndComputePassCmd>();
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::EndRenderPass:
|
||||
{
|
||||
commands.NextCommand<EndRenderPassCmd>();
|
||||
mCommands.NextCommand<EndRenderPassCmd>();
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::EndRenderSubpass:
|
||||
{
|
||||
commands.NextCommand<EndRenderSubpassCmd>();
|
||||
mCommands.NextCommand<EndRenderSubpassCmd>();
|
||||
glDeleteFramebuffers(1, ¤tFBO);
|
||||
currentFBO = 0;
|
||||
currentSubpass += 1;
|
||||
@ -504,7 +508,7 @@ namespace opengl {
|
||||
|
||||
case Command::SetComputePipeline:
|
||||
{
|
||||
SetComputePipelineCmd* cmd = commands.NextCommand<SetComputePipelineCmd>();
|
||||
SetComputePipelineCmd* cmd = mCommands.NextCommand<SetComputePipelineCmd>();
|
||||
ToBackend(cmd->pipeline)->ApplyNow();
|
||||
lastGLPipeline = ToBackend(cmd->pipeline).Get();
|
||||
lastPipeline = ToBackend(cmd->pipeline).Get();
|
||||
@ -514,7 +518,7 @@ namespace opengl {
|
||||
|
||||
case Command::SetRenderPipeline:
|
||||
{
|
||||
SetRenderPipelineCmd* cmd = commands.NextCommand<SetRenderPipelineCmd>();
|
||||
SetRenderPipelineCmd* cmd = mCommands.NextCommand<SetRenderPipelineCmd>();
|
||||
ToBackend(cmd->pipeline)->ApplyNow(persistentPipelineState);
|
||||
lastRenderPipeline = ToBackend(cmd->pipeline).Get();
|
||||
lastGLPipeline = ToBackend(cmd->pipeline).Get();
|
||||
@ -527,29 +531,29 @@ namespace opengl {
|
||||
|
||||
case Command::SetPushConstants:
|
||||
{
|
||||
SetPushConstantsCmd* cmd = commands.NextCommand<SetPushConstantsCmd>();
|
||||
uint32_t* data = commands.NextData<uint32_t>(cmd->count);
|
||||
SetPushConstantsCmd* cmd = mCommands.NextCommand<SetPushConstantsCmd>();
|
||||
uint32_t* data = mCommands.NextData<uint32_t>(cmd->count);
|
||||
pushConstants.OnSetPushConstants(cmd->stages, cmd->count, cmd->offset, data);
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::SetStencilReference:
|
||||
{
|
||||
SetStencilReferenceCmd* cmd = commands.NextCommand<SetStencilReferenceCmd>();
|
||||
SetStencilReferenceCmd* cmd = mCommands.NextCommand<SetStencilReferenceCmd>();
|
||||
persistentPipelineState.SetStencilReference(cmd->reference);
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::SetBlendColor:
|
||||
{
|
||||
SetBlendColorCmd* cmd = commands.NextCommand<SetBlendColorCmd>();
|
||||
SetBlendColorCmd* cmd = mCommands.NextCommand<SetBlendColorCmd>();
|
||||
glBlendColor(cmd->r, cmd->g, cmd->b, cmd->a);
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::SetBindGroup:
|
||||
{
|
||||
SetBindGroupCmd* cmd = commands.NextCommand<SetBindGroupCmd>();
|
||||
SetBindGroupCmd* cmd = mCommands.NextCommand<SetBindGroupCmd>();
|
||||
size_t groupIndex = cmd->index;
|
||||
BindGroup* group = ToBackend(cmd->group.Get());
|
||||
|
||||
@ -610,7 +614,7 @@ namespace opengl {
|
||||
|
||||
case Command::SetIndexBuffer:
|
||||
{
|
||||
SetIndexBufferCmd* cmd = commands.NextCommand<SetIndexBufferCmd>();
|
||||
SetIndexBufferCmd* cmd = mCommands.NextCommand<SetIndexBufferCmd>();
|
||||
indexBufferOffset = cmd->offset;
|
||||
inputBuffers.OnSetIndexBuffer(cmd->buffer.Get());
|
||||
}
|
||||
@ -618,16 +622,16 @@ namespace opengl {
|
||||
|
||||
case Command::SetVertexBuffers:
|
||||
{
|
||||
SetVertexBuffersCmd* cmd = commands.NextCommand<SetVertexBuffersCmd>();
|
||||
auto buffers = commands.NextData<Ref<BufferBase>>(cmd->count);
|
||||
auto offsets = commands.NextData<uint32_t>(cmd->count);
|
||||
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;
|
||||
|
||||
case Command::TransitionBufferUsage:
|
||||
{
|
||||
TransitionBufferUsageCmd* cmd = commands.NextCommand<TransitionBufferUsageCmd>();
|
||||
TransitionBufferUsageCmd* cmd = mCommands.NextCommand<TransitionBufferUsageCmd>();
|
||||
|
||||
cmd->buffer->UpdateUsageInternal(cmd->usage);
|
||||
}
|
||||
@ -635,7 +639,7 @@ namespace opengl {
|
||||
|
||||
case Command::TransitionTextureUsage:
|
||||
{
|
||||
TransitionTextureUsageCmd* cmd = commands.NextCommand<TransitionTextureUsageCmd>();
|
||||
TransitionTextureUsageCmd* cmd = mCommands.NextCommand<TransitionTextureUsageCmd>();
|
||||
|
||||
cmd->texture->UpdateUsageInternal(cmd->usage);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace opengl {
|
||||
void Execute();
|
||||
|
||||
private:
|
||||
CommandIterator commands;
|
||||
CommandIterator mCommands;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ namespace opengl {
|
||||
|
||||
InputState::InputState(InputStateBuilder* builder)
|
||||
: InputStateBase(builder) {
|
||||
glGenVertexArrays(1, &vertexArrayObject);
|
||||
glBindVertexArray(vertexArrayObject);
|
||||
glGenVertexArrays(1, &mVertexArrayObject);
|
||||
glBindVertexArray(mVertexArrayObject);
|
||||
auto& attributesSetMask = GetAttributesSetMask();
|
||||
for (uint32_t location = 0; location < attributesSetMask.size(); ++location) {
|
||||
if (!attributesSetMask[location]) {
|
||||
@ -58,7 +58,7 @@ namespace opengl {
|
||||
}
|
||||
|
||||
GLuint InputState::GetVAO() {
|
||||
return vertexArrayObject;
|
||||
return mVertexArrayObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ namespace opengl {
|
||||
GLuint GetVAO();
|
||||
|
||||
private:
|
||||
GLuint vertexArrayObject;
|
||||
GLuint mVertexArrayObject;
|
||||
std::array<std::bitset<kMaxVertexAttributes>, kMaxVertexInputs> attributesUsingInput;
|
||||
};
|
||||
|
||||
|
@ -24,36 +24,36 @@ namespace opengl {
|
||||
}
|
||||
|
||||
void PersistentPipelineState::SetStencilFuncsAndMask(GLenum stencilBackCompareFunction, GLenum stencilFrontCompareFunction, uint32_t stencilReadMask) {
|
||||
if (this->stencilBackCompareFunction == stencilBackCompareFunction &&
|
||||
this->stencilFrontCompareFunction == stencilFrontCompareFunction &&
|
||||
this->stencilReadMask == stencilReadMask) {
|
||||
if (mStencilBackCompareFunction == stencilBackCompareFunction &&
|
||||
mStencilFrontCompareFunction == stencilFrontCompareFunction &&
|
||||
mStencilReadMask == stencilReadMask) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->stencilBackCompareFunction = stencilBackCompareFunction;
|
||||
this->stencilFrontCompareFunction = stencilFrontCompareFunction;
|
||||
this->stencilReadMask = stencilReadMask;
|
||||
mStencilBackCompareFunction = stencilBackCompareFunction;
|
||||
mStencilFrontCompareFunction = stencilFrontCompareFunction;
|
||||
mStencilReadMask = stencilReadMask;
|
||||
CallGLStencilFunc();
|
||||
}
|
||||
|
||||
void PersistentPipelineState::SetStencilReference(uint32_t stencilReference) {
|
||||
if (this->stencilReference == stencilReference) {
|
||||
if (mStencilReference == stencilReference) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->stencilReference = stencilReference;
|
||||
mStencilReference = stencilReference;
|
||||
CallGLStencilFunc();
|
||||
}
|
||||
|
||||
void PersistentPipelineState::CallGLStencilFunc() {
|
||||
glStencilFuncSeparate(GL_BACK,
|
||||
stencilBackCompareFunction,
|
||||
stencilReference,
|
||||
stencilReadMask);
|
||||
mStencilBackCompareFunction,
|
||||
mStencilReference,
|
||||
mStencilReadMask);
|
||||
glStencilFuncSeparate(GL_FRONT,
|
||||
stencilFrontCompareFunction,
|
||||
stencilReference,
|
||||
stencilReadMask);
|
||||
mStencilFrontCompareFunction,
|
||||
mStencilReference,
|
||||
mStencilReadMask);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,10 +31,10 @@ namespace opengl {
|
||||
private:
|
||||
void CallGLStencilFunc();
|
||||
|
||||
GLenum stencilBackCompareFunction = GL_ALWAYS;
|
||||
GLenum stencilFrontCompareFunction = GL_ALWAYS;
|
||||
GLuint stencilReadMask = 0xffffffff;
|
||||
GLuint stencilReference = 0;
|
||||
GLenum mStencilBackCompareFunction = GL_ALWAYS;
|
||||
GLenum mStencilFrontCompareFunction = GL_ALWAYS;
|
||||
GLuint mStencilReadMask = 0xffffffff;
|
||||
GLuint mStencilReference = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -87,26 +87,26 @@ namespace opengl {
|
||||
}
|
||||
};
|
||||
|
||||
program = glCreateProgram();
|
||||
mProgram = glCreateProgram();
|
||||
|
||||
for (auto stage : IterateStages(parent->GetStageMask())) {
|
||||
const ShaderModule* module = ToBackend(builder->GetStageInfo(stage).module.Get());
|
||||
|
||||
GLuint shader = CreateShader(GLShaderType(stage), module->GetSource());
|
||||
glAttachShader(program, shader);
|
||||
glAttachShader(mProgram, shader);
|
||||
}
|
||||
|
||||
glLinkProgram(program);
|
||||
glLinkProgram(mProgram);
|
||||
|
||||
GLint linkStatus = GL_FALSE;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
|
||||
glGetProgramiv(mProgram, GL_LINK_STATUS, &linkStatus);
|
||||
if (linkStatus == GL_FALSE) {
|
||||
GLint infoLogLength = 0;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
glGetProgramiv(mProgram, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
|
||||
if (infoLogLength > 1) {
|
||||
std::vector<char> buffer(infoLogLength);
|
||||
glGetProgramInfoLog(program, infoLogLength, nullptr, &buffer[0]);
|
||||
glGetProgramInfoLog(mProgram, infoLogLength, nullptr, &buffer[0]);
|
||||
std::cout << "Program link failed:\n";
|
||||
std::cout << buffer.data() << std::endl;
|
||||
}
|
||||
@ -114,10 +114,10 @@ namespace opengl {
|
||||
|
||||
for (auto stage : IterateStages(parent->GetStageMask())) {
|
||||
const ShaderModule* module = ToBackend(builder->GetStageInfo(stage).module.Get());
|
||||
FillPushConstants(module, &glPushConstants[stage], program);
|
||||
FillPushConstants(module, &mGlPushConstants[stage], mProgram);
|
||||
}
|
||||
|
||||
glUseProgram(program);
|
||||
glUseProgram(mProgram);
|
||||
|
||||
// The uniforms are part of the program state so we can pre-bind buffer units, texture units etc.
|
||||
const auto& layout = ToBackend(parent->GetLayout());
|
||||
@ -135,15 +135,15 @@ namespace opengl {
|
||||
switch (groupInfo.types[binding]) {
|
||||
case nxt::BindingType::UniformBuffer:
|
||||
{
|
||||
GLint location = glGetUniformBlockIndex(program, name.c_str());
|
||||
glUniformBlockBinding(program, location, indices[group][binding]);
|
||||
GLint location = glGetUniformBlockIndex(mProgram, name.c_str());
|
||||
glUniformBlockBinding(mProgram, location, indices[group][binding]);
|
||||
}
|
||||
break;
|
||||
|
||||
case nxt::BindingType::StorageBuffer:
|
||||
{
|
||||
GLuint location = glGetProgramResourceIndex(program, GL_SHADER_STORAGE_BLOCK, name.c_str());
|
||||
glShaderStorageBlockBinding(program, location, indices[group][binding]);
|
||||
GLuint location = glGetProgramResourceIndex(mProgram, GL_SHADER_STORAGE_BLOCK, name.c_str());
|
||||
glShaderStorageBlockBinding(mProgram, location, indices[group][binding]);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -167,20 +167,20 @@ namespace opengl {
|
||||
}
|
||||
}
|
||||
|
||||
unitsForSamplers.resize(layout->GetNumSamplers());
|
||||
unitsForTextures.resize(layout->GetNumSampledTextures());
|
||||
mUnitsForSamplers.resize(layout->GetNumSamplers());
|
||||
mUnitsForTextures.resize(layout->GetNumSampledTextures());
|
||||
|
||||
GLuint textureUnit = layout->GetTextureUnitsUsed();
|
||||
for (const auto& combined : combinedSamplersSet) {
|
||||
std::string name = combined.GetName();
|
||||
GLint location = glGetUniformLocation(program, name.c_str());
|
||||
GLint location = glGetUniformLocation(mProgram, name.c_str());
|
||||
glUniform1i(location, textureUnit);
|
||||
|
||||
GLuint samplerIndex = indices[combined.samplerLocation.group][combined.samplerLocation.binding];
|
||||
unitsForSamplers[samplerIndex].push_back(textureUnit);
|
||||
mUnitsForSamplers[samplerIndex].push_back(textureUnit);
|
||||
|
||||
GLuint textureIndex = indices[combined.textureLocation.group][combined.textureLocation.binding];
|
||||
unitsForTextures[textureIndex].push_back(textureUnit);
|
||||
mUnitsForTextures[textureIndex].push_back(textureUnit);
|
||||
|
||||
textureUnit ++;
|
||||
}
|
||||
@ -188,25 +188,25 @@ namespace opengl {
|
||||
}
|
||||
|
||||
const PipelineGL::GLPushConstantInfo& PipelineGL::GetGLPushConstants(nxt::ShaderStage stage) const {
|
||||
return glPushConstants[stage];
|
||||
return mGlPushConstants[stage];
|
||||
}
|
||||
|
||||
const std::vector<GLuint>& PipelineGL::GetTextureUnitsForSampler(GLuint index) const {
|
||||
ASSERT(index < unitsForSamplers.size());
|
||||
return unitsForSamplers[index];
|
||||
ASSERT(index < mUnitsForSamplers.size());
|
||||
return mUnitsForSamplers[index];
|
||||
}
|
||||
|
||||
const std::vector<GLuint>& PipelineGL::GetTextureUnitsForTexture(GLuint index) const {
|
||||
ASSERT(index < unitsForSamplers.size());
|
||||
return unitsForTextures[index];
|
||||
ASSERT(index < mUnitsForSamplers.size());
|
||||
return mUnitsForTextures[index];
|
||||
}
|
||||
|
||||
GLuint PipelineGL::GetProgramHandle() const {
|
||||
return program;
|
||||
return mProgram;
|
||||
}
|
||||
|
||||
void PipelineGL::ApplyNow() {
|
||||
glUseProgram(program);
|
||||
glUseProgram(mProgram);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,10 +43,10 @@ namespace opengl {
|
||||
void ApplyNow();
|
||||
|
||||
private:
|
||||
GLuint program;
|
||||
PerStage<GLPushConstantInfo> glPushConstants;
|
||||
std::vector<std::vector<GLuint>> unitsForSamplers;
|
||||
std::vector<std::vector<GLuint>> unitsForTextures;
|
||||
GLuint mProgram;
|
||||
PerStage<GLPushConstantInfo> mGlPushConstants;
|
||||
std::vector<std::vector<GLuint>> mUnitsForSamplers;
|
||||
std::vector<std::vector<GLuint>> mUnitsForTextures;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -36,32 +36,32 @@ namespace opengl {
|
||||
|
||||
switch (groupInfo.types[binding]) {
|
||||
case nxt::BindingType::UniformBuffer:
|
||||
indexInfo[group][binding] = uboIndex;
|
||||
mIndexInfo[group][binding] = uboIndex;
|
||||
uboIndex ++;
|
||||
break;
|
||||
case nxt::BindingType::Sampler:
|
||||
indexInfo[group][binding] = samplerIndex;
|
||||
mIndexInfo[group][binding] = samplerIndex;
|
||||
samplerIndex ++;
|
||||
break;
|
||||
case nxt::BindingType::SampledTexture:
|
||||
indexInfo[group][binding] = sampledTextureIndex;
|
||||
mIndexInfo[group][binding] = sampledTextureIndex;
|
||||
sampledTextureIndex ++;
|
||||
break;
|
||||
|
||||
case nxt::BindingType::StorageBuffer:
|
||||
indexInfo[group][binding] = ssboIndex;
|
||||
mIndexInfo[group][binding] = ssboIndex;
|
||||
ssboIndex ++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numSamplers = samplerIndex;
|
||||
numSampledTextures = sampledTextureIndex;
|
||||
mNumSamplers = samplerIndex;
|
||||
mNumSampledTextures = sampledTextureIndex;
|
||||
}
|
||||
|
||||
const PipelineLayout::BindingIndexInfo& PipelineLayout::GetBindingIndexInfo() const {
|
||||
return indexInfo;
|
||||
return mIndexInfo;
|
||||
}
|
||||
|
||||
GLuint PipelineLayout::GetTextureUnitsUsed() const {
|
||||
@ -69,11 +69,11 @@ namespace opengl {
|
||||
}
|
||||
|
||||
size_t PipelineLayout::GetNumSamplers() const {
|
||||
return numSamplers;
|
||||
return mNumSamplers;
|
||||
}
|
||||
|
||||
size_t PipelineLayout::GetNumSampledTextures() const {
|
||||
return numSampledTextures;
|
||||
return mNumSampledTextures;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ namespace opengl {
|
||||
size_t GetNumSampledTextures() const;
|
||||
|
||||
private:
|
||||
BindingIndexInfo indexInfo;
|
||||
size_t numSamplers;
|
||||
size_t numSampledTextures;
|
||||
BindingIndexInfo mIndexInfo;
|
||||
size_t mNumSamplers;
|
||||
size_t mNumSampledTextures;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -44,11 +44,11 @@ namespace opengl {
|
||||
|
||||
RenderPipeline::RenderPipeline(RenderPipelineBuilder* builder)
|
||||
: RenderPipelineBase(builder), PipelineGL(this, builder),
|
||||
glPrimitiveTopology(GLPrimitiveTopology(GetPrimitiveTopology())) {
|
||||
mGlPrimitiveTopology(GLPrimitiveTopology(GetPrimitiveTopology())) {
|
||||
}
|
||||
|
||||
GLenum RenderPipeline::GetGLPrimitiveTopology() const {
|
||||
return glPrimitiveTopology;
|
||||
return mGlPrimitiveTopology;
|
||||
}
|
||||
|
||||
void RenderPipeline::ApplyNow(PersistentPipelineState &persistentPipelineState) {
|
||||
|
@ -37,7 +37,7 @@ namespace opengl {
|
||||
void ApplyNow(PersistentPipelineState &persistentPipelineState);
|
||||
|
||||
private:
|
||||
GLenum glPrimitiveTopology;
|
||||
GLenum mGlPrimitiveTopology;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -59,13 +59,13 @@ namespace opengl {
|
||||
|
||||
Sampler::Sampler(SamplerBuilder* builder)
|
||||
: SamplerBase(builder) {
|
||||
glGenSamplers(1, &handle);
|
||||
glSamplerParameteri(handle, GL_TEXTURE_MAG_FILTER, MagFilterMode(builder->GetMagFilter()));
|
||||
glSamplerParameteri(handle, GL_TEXTURE_MIN_FILTER, MinFilterMode(builder->GetMinFilter(), builder->GetMipMapFilter()));
|
||||
glGenSamplers(1, &mHandle);
|
||||
glSamplerParameteri(mHandle, GL_TEXTURE_MAG_FILTER, MagFilterMode(builder->GetMagFilter()));
|
||||
glSamplerParameteri(mHandle, GL_TEXTURE_MIN_FILTER, MinFilterMode(builder->GetMinFilter(), builder->GetMipMapFilter()));
|
||||
}
|
||||
|
||||
GLuint Sampler::GetHandle() const {
|
||||
return handle;
|
||||
return mHandle;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace opengl {
|
||||
GLuint GetHandle() const;
|
||||
|
||||
private:
|
||||
GLuint handle;
|
||||
GLuint mHandle;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -92,9 +92,9 @@ namespace opengl {
|
||||
compiler.build_combined_image_samplers();
|
||||
|
||||
for (const auto& combined : compiler.get_combined_image_samplers()) {
|
||||
combinedInfo.emplace_back();
|
||||
mCombinedInfo.emplace_back();
|
||||
|
||||
auto& info = combinedInfo.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);
|
||||
@ -116,15 +116,15 @@ namespace opengl {
|
||||
}
|
||||
}
|
||||
|
||||
glslSource = compiler.compile();
|
||||
mGlslSource = compiler.compile();
|
||||
}
|
||||
|
||||
const char* ShaderModule::GetSource() const {
|
||||
return reinterpret_cast<const char*>(glslSource.data());
|
||||
return reinterpret_cast<const char*>(mGlslSource.data());
|
||||
}
|
||||
|
||||
const ShaderModule::CombinedSamplerInfo& ShaderModule::GetCombinedSamplerInfo() const {
|
||||
return combinedInfo;
|
||||
return mCombinedInfo;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ namespace opengl {
|
||||
const CombinedSamplerInfo& GetCombinedSamplerInfo() const;
|
||||
|
||||
private:
|
||||
CombinedSamplerInfo combinedInfo;
|
||||
std::string glslSource;
|
||||
CombinedSamplerInfo mCombinedInfo;
|
||||
std::string mGlslSource;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -64,8 +64,8 @@ namespace opengl {
|
||||
}
|
||||
|
||||
Texture::Texture(TextureBuilder* builder, GLuint handle)
|
||||
: TextureBase(builder), handle(handle) {
|
||||
target = TargetForDimension(GetDimension());
|
||||
: TextureBase(builder), mHandle(handle) {
|
||||
mTarget = TargetForDimension(GetDimension());
|
||||
|
||||
uint32_t width = GetWidth();
|
||||
uint32_t height = GetHeight();
|
||||
@ -73,17 +73,17 @@ namespace opengl {
|
||||
|
||||
auto formatInfo = GetGLFormatInfo(GetFormat());
|
||||
|
||||
glBindTexture(target, handle);
|
||||
glBindTexture(mTarget, handle);
|
||||
|
||||
for (uint32_t i = 0; i < levels; ++i) {
|
||||
glTexImage2D(target, 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);
|
||||
}
|
||||
|
||||
// The texture is not complete if it uses mipmapping and not all levels up to
|
||||
// MAX_LEVEL have been defined.
|
||||
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels - 1);
|
||||
glTexParameteri(mTarget, GL_TEXTURE_MAX_LEVEL, levels - 1);
|
||||
}
|
||||
|
||||
Texture::~Texture() {
|
||||
@ -91,11 +91,11 @@ namespace opengl {
|
||||
}
|
||||
|
||||
GLuint Texture::GetHandle() const {
|
||||
return handle;
|
||||
return mHandle;
|
||||
}
|
||||
|
||||
GLenum Texture::GetGLTarget() const {
|
||||
return target;
|
||||
return mTarget;
|
||||
}
|
||||
|
||||
TextureFormatInfo Texture::GetGLFormat() const {
|
||||
|
@ -43,8 +43,8 @@ namespace opengl {
|
||||
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override;
|
||||
|
||||
private:
|
||||
GLuint handle;
|
||||
GLenum target;
|
||||
GLuint mHandle;
|
||||
GLenum mTarget;
|
||||
};
|
||||
|
||||
class TextureView : public TextureViewBase {
|
||||
|
Loading…
x
Reference in New Issue
Block a user