From 16ef8d493c26a4e35f6257b7a4679a6e2c39c98f Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 22 Oct 2016 13:17:30 -0400 Subject: [PATCH 1/2] vogl_program_state: extract the shaders using a uniform buffer --- src/voglcommon/vogl_program_state.cpp | 18 +++++++++++++++++- src/voglcommon/vogl_program_state.h | 12 ++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/voglcommon/vogl_program_state.cpp b/src/voglcommon/vogl_program_state.cpp index 3a0f7bac..0baaa412 100644 --- a/src/voglcommon/vogl_program_state.cpp +++ b/src/voglcommon/vogl_program_state.cpp @@ -261,7 +261,23 @@ bool vogl_program_state::snapshot_uniform_blocks(const vogl_context_info &contex GL_ENTRYPOINT(glGetActiveUniformBlockiv)(m_snapshot_handle, uniform_block_index, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &state.m_uniform_block_active_uniforms); VOGL_CHECK_GL_ERROR; - // TODO: Get and store referenced flags: GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER, GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER, or GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER, etc. +#define GET_REFERENCED_BY(name, flag_name) do { \ + GLint referenced; \ + GL_ENTRYPOINT(glGetActiveUniformBlockiv)(m_snapshot_handle, uniform_block_index, GL_UNIFORM_BLOCK_REFERENCED_BY_ ## name ## _SHADER, &referenced); \ + VOGL_CHECK_GL_ERROR; \ + if (referenced) \ + state.m_referenced_by |= cBufferReferencedBy ## flag_name; \ + } while (0) + + GET_REFERENCED_BY(VERTEX, Vertex); + GET_REFERENCED_BY(TESS_CONTROL, TesselationControl); + GET_REFERENCED_BY(TESS_EVALUATION, TesselationEvaluation); + GET_REFERENCED_BY(GEOMETRY, Geometry); + GET_REFERENCED_BY(FRAGMENT, Fragment); + if (context_info.get_version() >= VOGL_GL_VERSION_4_3) + GET_REFERENCED_BY(COMPUTE, Compute); + +#undef GET_REFERENCED_BY m_uniform_blocks.push_back(state); } diff --git a/src/voglcommon/vogl_program_state.h b/src/voglcommon/vogl_program_state.h index bb6756ab..5dbcf0c1 100644 --- a/src/voglcommon/vogl_program_state.h +++ b/src/voglcommon/vogl_program_state.h @@ -85,6 +85,15 @@ struct vogl_program_uniform_state typedef vogl::vector vogl_uniform_state_vec; +enum vogl_referenced_by_flags { + cBufferReferencedByVertex = 1, + cBufferReferencedByTesselationControl = 2, + cBufferReferencedByTesselationEvaluation = 4, + cBufferReferencedByGeometry = 8, + cBufferReferencedByFragment = 16, + cBufferReferencedByCompute = 32, +}; + struct vogl_program_uniform_block_state { GLuint m_uniform_block_index; @@ -92,6 +101,7 @@ struct vogl_program_uniform_block_state GLint m_uniform_block_binding_point; GLint m_uniform_block_data_size; GLint m_uniform_block_active_uniforms; + int m_referenced_by; void clear() { @@ -100,6 +110,7 @@ struct vogl_program_uniform_block_state m_uniform_block_binding_point = 0; m_uniform_block_data_size = 0; m_uniform_block_active_uniforms = 0; + m_referenced_by = 0; } inline bool operator==(const vogl_program_uniform_block_state &rhs) const @@ -112,6 +123,7 @@ struct vogl_program_uniform_block_state CMP(m_uniform_block_binding_point) CMP(m_uniform_block_data_size) CMP(m_uniform_block_active_uniforms) + CMP(m_referenced_by) #undef CMP return true; } From ceeb5b8e48ac4f537f7a605c5dfb71f9f063123a Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 22 Oct 2016 13:17:59 -0400 Subject: [PATCH 2/2] vogleditor_qprogramexplorer: show uniform buffers in the program editor --- .../vogleditor_qprogramexplorer.cpp | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/vogleditor/vogleditor_qprogramexplorer.cpp b/src/vogleditor/vogleditor_qprogramexplorer.cpp index 1a9698b3..9e5236c2 100644 --- a/src/vogleditor/vogleditor_qprogramexplorer.cpp +++ b/src/vogleditor/vogleditor_qprogramexplorer.cpp @@ -559,6 +559,37 @@ void vogleditor_QProgramExplorer::update_uniforms_for_program(vogl_program_state } // end uniform element index } + const vogl_uniform_block_state_vec &uniformBlockVec = pProgramState->get_uniform_block_state_vec(); + for (uint i = 0; i < uniformBlockVec.size(); i++) + { + QString varName = QString("%1").arg(uniformBlockVec[i].m_name.c_str()); + + ui->uniformTableWidget->insertRow(rowIndex); + + QStringList references; + int referenced_by = uniformBlockVec[i].m_referenced_by; + + if (referenced_by & cBufferReferencedByVertex) + references.append("vertex"); + if (referenced_by & cBufferReferencedByTesselationControl) + references.append("tesselation control"); + if (referenced_by & cBufferReferencedByTesselationEvaluation) + references.append("tesselation evaluation"); + if (referenced_by & cBufferReferencedByGeometry) + references.append("geometry"); + if (referenced_by & cBufferReferencedByFragment) + references.append("fragment"); + if (referenced_by & cBufferReferencedByCompute) + references.append("compute"); + + ui->uniformTableWidget->setItem(rowIndex, vogleditor_utc_location, new QTableWidgetItem(QString("%1").arg(i))); + ui->uniformTableWidget->setItem(rowIndex, vogleditor_utc_name, new QTableWidgetItem(varName)); + ui->uniformTableWidget->setItem(rowIndex, vogleditor_utc_value, new QTableWidgetItem(references.join(", "))); + ui->uniformTableWidget->setItem(rowIndex, vogleditor_utc_type, new QTableWidgetItem(QString("%1 bytes").arg(uniformBlockVec[i].m_uniform_block_data_size))); + + rowIndex++; + } + // resize columns so that they are properly sized, but still allow the user to resize them more if needed ui->uniformTableWidget->horizontalHeader()->setSectionResizeMode(vogleditor_utc_location, QHeaderView::ResizeToContents); uint tmpWidth = ui->uniformTableWidget->horizontalHeader()->sectionSize(vogleditor_utc_location);