diff --git a/src/backend/opengl/BufferGL.cpp b/src/backend/opengl/BufferGL.cpp index 9a0f5dbdd6..0086dba4ba 100644 --- a/src/backend/opengl/BufferGL.cpp +++ b/src/backend/opengl/BufferGL.cpp @@ -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); } diff --git a/src/backend/opengl/BufferGL.h b/src/backend/opengl/BufferGL.h index bcbc2f7f11..fb589c7a77 100644 --- a/src/backend/opengl/BufferGL.h +++ b/src/backend/opengl/BufferGL.h @@ -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 { diff --git a/src/backend/opengl/CommandBufferGL.cpp b/src/backend/opengl/CommandBufferGL.cpp index 8379ecaa2c..32eead8024 100644 --- a/src/backend/opengl/CommandBufferGL.cpp +++ b/src/backend/opengl/CommandBufferGL.cpp @@ -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> values; - PerStage> 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(&values[stage][constant])); - break; - case PushConstantType::UInt: - glUniform1ui(location, *reinterpret_cast(&values[stage][constant])); - break; - case PushConstantType::Float: - glUniform1f(location, *reinterpret_cast(&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(&mValues[stage][constant])); + break; + case PushConstantType::UInt: + glUniform1ui(location, *reinterpret_cast(&mValues[stage][constant])); + break; + case PushConstantType::Float: + glUniform1f(location, *reinterpret_cast(&mValues[stage][constant])); + break; + } + } + + mDirtyBits[stage].reset(); + } + } + + private: + PerStage> mValues; + PerStage> 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 dirtyVertexBuffers; - std::array vertexBuffers; - std::array 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* 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(static_cast(offset + attribute.offset))); + void OnSetVertexBuffers(uint32_t startSlot, uint32_t count, Ref* 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(static_cast(offset + attribute.offset))); + } + } + + mDirtyVertexBuffers.reset(); + } + + private: + bool mIndexBufferDirty = false; + Buffer* mIndexBuffer = nullptr; + + std::bitset mDirtyVertexBuffers; + std::array mVertexBuffers; + std::array 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(); + mCommands.NextCommand(); pushConstants.OnBeginPass(); } break; case Command::BeginRenderPass: { - auto* cmd = commands.NextCommand(); + auto* cmd = mCommands.NextCommand(); currentRenderPass = ToBackend(cmd->renderPass.Get()); currentFramebuffer = ToBackend(cmd->framebuffer.Get()); currentSubpass = 0; @@ -240,7 +244,7 @@ namespace opengl { case Command::BeginRenderSubpass: { - commands.NextCommand(); + mCommands.NextCommand(); pushConstants.OnBeginPass(); inputBuffers.OnBeginPass(); @@ -359,7 +363,7 @@ namespace opengl { case Command::CopyBufferToBuffer: { - CopyBufferToBufferCmd* copy = commands.NextCommand(); + CopyBufferToBufferCmd* copy = mCommands.NextCommand(); auto& src = copy->source; auto& dst = copy->destination; @@ -374,7 +378,7 @@ namespace opengl { case Command::CopyBufferToTexture: { - CopyBufferToTextureCmd* copy = commands.NextCommand(); + CopyBufferToTextureCmd* copy = mCommands.NextCommand(); 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* copy = mCommands.NextCommand(); 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* dispatch = mCommands.NextCommand(); 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* draw = mCommands.NextCommand(); pushConstants.Apply(lastPipeline, lastGLPipeline); inputBuffers.Apply(); @@ -458,7 +462,7 @@ namespace opengl { case Command::DrawElements: { - DrawElementsCmd* draw = commands.NextCommand(); + DrawElementsCmd* draw = mCommands.NextCommand(); pushConstants.Apply(lastPipeline, lastGLPipeline); inputBuffers.Apply(); @@ -483,19 +487,19 @@ namespace opengl { case Command::EndComputePass: { - commands.NextCommand(); + mCommands.NextCommand(); } break; case Command::EndRenderPass: { - commands.NextCommand(); + mCommands.NextCommand(); } break; case Command::EndRenderSubpass: { - commands.NextCommand(); + mCommands.NextCommand(); glDeleteFramebuffers(1, ¤tFBO); currentFBO = 0; currentSubpass += 1; @@ -504,7 +508,7 @@ namespace opengl { case Command::SetComputePipeline: { - SetComputePipelineCmd* cmd = commands.NextCommand(); + SetComputePipelineCmd* cmd = mCommands.NextCommand(); 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* cmd = mCommands.NextCommand(); 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(); - uint32_t* data = commands.NextData(cmd->count); + SetPushConstantsCmd* cmd = mCommands.NextCommand(); + uint32_t* data = mCommands.NextData(cmd->count); pushConstants.OnSetPushConstants(cmd->stages, cmd->count, cmd->offset, data); } break; case Command::SetStencilReference: { - SetStencilReferenceCmd* cmd = commands.NextCommand(); + SetStencilReferenceCmd* cmd = mCommands.NextCommand(); persistentPipelineState.SetStencilReference(cmd->reference); } break; case Command::SetBlendColor: { - SetBlendColorCmd* cmd = commands.NextCommand(); + SetBlendColorCmd* cmd = mCommands.NextCommand(); glBlendColor(cmd->r, cmd->g, cmd->b, cmd->a); } break; case Command::SetBindGroup: { - SetBindGroupCmd* cmd = commands.NextCommand(); + SetBindGroupCmd* cmd = mCommands.NextCommand(); 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* cmd = mCommands.NextCommand(); indexBufferOffset = cmd->offset; inputBuffers.OnSetIndexBuffer(cmd->buffer.Get()); } @@ -618,16 +622,16 @@ namespace opengl { case Command::SetVertexBuffers: { - SetVertexBuffersCmd* cmd = commands.NextCommand(); - auto buffers = commands.NextData>(cmd->count); - auto offsets = commands.NextData(cmd->count); + SetVertexBuffersCmd* cmd = mCommands.NextCommand(); + auto buffers = mCommands.NextData>(cmd->count); + auto offsets = mCommands.NextData(cmd->count); inputBuffers.OnSetVertexBuffers(cmd->startSlot, cmd->count, buffers, offsets); } break; case Command::TransitionBufferUsage: { - TransitionBufferUsageCmd* cmd = commands.NextCommand(); + TransitionBufferUsageCmd* cmd = mCommands.NextCommand(); cmd->buffer->UpdateUsageInternal(cmd->usage); } @@ -635,7 +639,7 @@ namespace opengl { case Command::TransitionTextureUsage: { - TransitionTextureUsageCmd* cmd = commands.NextCommand(); + TransitionTextureUsageCmd* cmd = mCommands.NextCommand(); cmd->texture->UpdateUsageInternal(cmd->usage); } diff --git a/src/backend/opengl/CommandBufferGL.h b/src/backend/opengl/CommandBufferGL.h index 79891deec6..dcbe06f6fa 100644 --- a/src/backend/opengl/CommandBufferGL.h +++ b/src/backend/opengl/CommandBufferGL.h @@ -31,7 +31,7 @@ namespace opengl { void Execute(); private: - CommandIterator commands; + CommandIterator mCommands; }; } diff --git a/src/backend/opengl/InputStateGL.cpp b/src/backend/opengl/InputStateGL.cpp index d7aaaffe45..957d1d0fd7 100644 --- a/src/backend/opengl/InputStateGL.cpp +++ b/src/backend/opengl/InputStateGL.cpp @@ -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; } } diff --git a/src/backend/opengl/InputStateGL.h b/src/backend/opengl/InputStateGL.h index 098f151539..e3401ad378 100644 --- a/src/backend/opengl/InputStateGL.h +++ b/src/backend/opengl/InputStateGL.h @@ -32,7 +32,7 @@ namespace opengl { GLuint GetVAO(); private: - GLuint vertexArrayObject; + GLuint mVertexArrayObject; std::array, kMaxVertexInputs> attributesUsingInput; }; diff --git a/src/backend/opengl/PersistentPipelineStateGL.cpp b/src/backend/opengl/PersistentPipelineStateGL.cpp index bb81e75122..bec9bfa0c4 100644 --- a/src/backend/opengl/PersistentPipelineStateGL.cpp +++ b/src/backend/opengl/PersistentPipelineStateGL.cpp @@ -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); } } diff --git a/src/backend/opengl/PersistentPipelineStateGL.h b/src/backend/opengl/PersistentPipelineStateGL.h index c0b0a3077c..ef6eddff0e 100644 --- a/src/backend/opengl/PersistentPipelineStateGL.h +++ b/src/backend/opengl/PersistentPipelineStateGL.h @@ -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; }; } diff --git a/src/backend/opengl/PipelineGL.cpp b/src/backend/opengl/PipelineGL.cpp index 9623f8ae46..26e06a6699 100644 --- a/src/backend/opengl/PipelineGL.cpp +++ b/src/backend/opengl/PipelineGL.cpp @@ -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 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& PipelineGL::GetTextureUnitsForSampler(GLuint index) const { - ASSERT(index < unitsForSamplers.size()); - return unitsForSamplers[index]; + ASSERT(index < mUnitsForSamplers.size()); + return mUnitsForSamplers[index]; } const std::vector& 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); } } diff --git a/src/backend/opengl/PipelineGL.h b/src/backend/opengl/PipelineGL.h index f6fe63cd25..1f1d09bcdf 100644 --- a/src/backend/opengl/PipelineGL.h +++ b/src/backend/opengl/PipelineGL.h @@ -43,10 +43,10 @@ namespace opengl { void ApplyNow(); private: - GLuint program; - PerStage glPushConstants; - std::vector> unitsForSamplers; - std::vector> unitsForTextures; + GLuint mProgram; + PerStage mGlPushConstants; + std::vector> mUnitsForSamplers; + std::vector> mUnitsForTextures; }; } diff --git a/src/backend/opengl/PipelineLayoutGL.cpp b/src/backend/opengl/PipelineLayoutGL.cpp index cff8413ac5..7a2acd1503 100644 --- a/src/backend/opengl/PipelineLayoutGL.cpp +++ b/src/backend/opengl/PipelineLayoutGL.cpp @@ -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; } } diff --git a/src/backend/opengl/PipelineLayoutGL.h b/src/backend/opengl/PipelineLayoutGL.h index 3ebfe0e891..2fdea3572d 100644 --- a/src/backend/opengl/PipelineLayoutGL.h +++ b/src/backend/opengl/PipelineLayoutGL.h @@ -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; }; } diff --git a/src/backend/opengl/RenderPipelineGL.cpp b/src/backend/opengl/RenderPipelineGL.cpp index a36a0a5159..7684f76bd7 100644 --- a/src/backend/opengl/RenderPipelineGL.cpp +++ b/src/backend/opengl/RenderPipelineGL.cpp @@ -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) { diff --git a/src/backend/opengl/RenderPipelineGL.h b/src/backend/opengl/RenderPipelineGL.h index e16ce25924..a45f06d348 100644 --- a/src/backend/opengl/RenderPipelineGL.h +++ b/src/backend/opengl/RenderPipelineGL.h @@ -37,7 +37,7 @@ namespace opengl { void ApplyNow(PersistentPipelineState &persistentPipelineState); private: - GLenum glPrimitiveTopology; + GLenum mGlPrimitiveTopology; }; } diff --git a/src/backend/opengl/SamplerGL.cpp b/src/backend/opengl/SamplerGL.cpp index 742603f202..b06c12f8aa 100644 --- a/src/backend/opengl/SamplerGL.cpp +++ b/src/backend/opengl/SamplerGL.cpp @@ -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; } } diff --git a/src/backend/opengl/SamplerGL.h b/src/backend/opengl/SamplerGL.h index 86c729d874..1c56381022 100644 --- a/src/backend/opengl/SamplerGL.h +++ b/src/backend/opengl/SamplerGL.h @@ -31,7 +31,7 @@ namespace opengl { GLuint GetHandle() const; private: - GLuint handle; + GLuint mHandle; }; } diff --git a/src/backend/opengl/ShaderModuleGL.cpp b/src/backend/opengl/ShaderModuleGL.cpp index e998ee582e..654ac0c1f5 100644 --- a/src/backend/opengl/ShaderModuleGL.cpp +++ b/src/backend/opengl/ShaderModuleGL.cpp @@ -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(glslSource.data()); + return reinterpret_cast(mGlslSource.data()); } const ShaderModule::CombinedSamplerInfo& ShaderModule::GetCombinedSamplerInfo() const { - return combinedInfo; + return mCombinedInfo; } } diff --git a/src/backend/opengl/ShaderModuleGL.h b/src/backend/opengl/ShaderModuleGL.h index 8d8f0d6748..ccb2deb6d4 100644 --- a/src/backend/opengl/ShaderModuleGL.h +++ b/src/backend/opengl/ShaderModuleGL.h @@ -49,8 +49,8 @@ namespace opengl { const CombinedSamplerInfo& GetCombinedSamplerInfo() const; private: - CombinedSamplerInfo combinedInfo; - std::string glslSource; + CombinedSamplerInfo mCombinedInfo; + std::string mGlslSource; }; } diff --git a/src/backend/opengl/TextureGL.cpp b/src/backend/opengl/TextureGL.cpp index 74addc4b00..d50efe2278 100644 --- a/src/backend/opengl/TextureGL.cpp +++ b/src/backend/opengl/TextureGL.cpp @@ -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 { diff --git a/src/backend/opengl/TextureGL.h b/src/backend/opengl/TextureGL.h index c53dc76517..648c5a11c0 100644 --- a/src/backend/opengl/TextureGL.h +++ b/src/backend/opengl/TextureGL.h @@ -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 {