Skip to content

Commit

Permalink
Rework GL buffer structs
Browse files Browse the repository at this point in the history
  • Loading branch information
sguionni committed Dec 4, 2024
1 parent d215b44 commit 5c18612
Show file tree
Hide file tree
Showing 11 changed files with 376 additions and 352 deletions.
8 changes: 4 additions & 4 deletions app/bench/src/user_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ namespace VTX::Bench
}

size_t idSystem = 0;
int toDelete = -1;
int toDelete = -1;

for ( auto & proxySystem : p_scene->getProxiesSystems() )
{
Expand Down Expand Up @@ -580,9 +580,9 @@ namespace VTX::Bench
ImNodes::EndInputAttribute();
ImNodes::PopAttributeFlag();
}
else if ( std::holds_alternative<Data>( input.desc ) )
else if ( std::holds_alternative<BufferDraw>( input.desc ) )
{
// const Data & data = std::get<Data>( input.desc );
// const BufferDraw & data = std::get<BufferDraw>( input.desc );
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 1, 1, 0, 1 ) );
ImGui::Text( input.name.c_str() );
ImGui::PopStyleColor();
Expand All @@ -607,7 +607,7 @@ namespace VTX::Bench
for ( const Program & program : pass->programs )
{
// Uniforms.
for ( const Uniform & uniform : program.uniforms )
for ( const BufferDataValue & uniform : program.data )
{
std::string key = pass->name + program.name + uniform.name;
bool isEditable = isBuilt && isInRenderQueue;
Expand Down
12 changes: 6 additions & 6 deletions app/bench/src/user_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ namespace VTX::Bench

template<typename T>
void _drawWidget(
Renderer::Renderer * const p_renderer,
const Renderer::Uniform & p_uniform,
const std::string & p_key,
const bool p_isEditable
Renderer::Renderer * const p_renderer,
const Renderer::BufferDataValue & p_uniform,
const std::string & p_key,
const bool p_isEditable
) const
{
using namespace Renderer;
const StructUniformValue<T> descValue = std::get<StructUniformValue<T>>( p_uniform.value );
const BufferValue<T> descValue = std::get<BufferValue<T>>( p_uniform.value );

static std::map<std::string, T> values;
if ( values.find( p_key ) == values.end() )
Expand Down Expand Up @@ -96,7 +96,7 @@ namespace VTX::Bench
}
else if ( descValue.minMax.has_value() )
{
const typename StructUniformValue<T>::MinMax & minMax = descValue.minMax.value();
const typename BufferValue<T>::MinMax & minMax = descValue.minMax.value();

if constexpr ( std::is_integral<T>::value )
{
Expand Down
50 changes: 25 additions & 25 deletions lib/renderer/include/renderer/context/concept_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,35 @@ namespace VTX::Renderer::Context
concept Concept
= std::is_base_of<BaseContext, C>::value
&& requires(
C p_context,
const size_t p_width,
const size_t p_height,
const size_t p_x,
const size_t p_y,
const RenderQueue & p_renderQueue,
const Links & p_links,
const Handle p_output,
const SharedUniforms & p_uniforms,
const std::string & p_key,
const std::any & p_value,
const std::vector<std::any> & p_data,
const size_t p_size,
const size_t p_index,
const size_t p_offset,
const Util::Chrono::Task & p_task,
Instructions & p_instructions,
InstructionsDurationRanges & p_instructionsDurationRanges,
StructInfos & p_infos,
std::vector<uchar> & p_image,
const std::string & p_pass,
const E_CHAN_OUT p_channel,
std::any & p_textureData,
const ComputePass & p_computePass
C p_context,
const size_t p_width,
const size_t p_height,
const size_t p_x,
const size_t p_y,
const RenderQueue & p_renderQueue,
const Links & p_links,
const Handle p_output,
const std::vector<BufferData> & p_globalData,
const std::string & p_key,
const std::any & p_value,
const std::vector<std::any> & p_data,
const size_t p_size,
const size_t p_index,
const size_t p_offset,
const Util::Chrono::Task & p_task,
Instructions & p_instructions,
InstructionsDurationRanges & p_instructionsDurationRanges,
StructInfos & p_infos,
std::vector<uchar> & p_image,
const std::string & p_pass,
const E_CHAN_OUT p_channel,
std::any & p_textureData,
const ComputePass & p_computePass

) {
{
p_context.build(
p_renderQueue, p_links, p_output, p_uniforms, p_instructions, p_instructionsDurationRanges
p_renderQueue, p_links, p_output, p_globalData, p_instructions, p_instructionsDurationRanges
)
} -> std::same_as<void>;
{ p_context.resize( p_renderQueue, p_width, p_height ) } -> std::same_as<void>;
Expand Down
11 changes: 8 additions & 3 deletions lib/renderer/include/renderer/context/gl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ namespace VTX::Renderer::Context::GL
}
}

inline void set( const GLsizei p_size, const bool p_immutable = false, const GLbitfield p_flags = 0 )
inline void set(
const GLsizei p_size,
const void * const data = nullptr,
const bool p_immutable = false,
const GLbitfield p_flags = 0
)
{
assert( glIsBuffer( _id ) );
assert( p_size > 0 );
Expand All @@ -136,11 +141,11 @@ namespace VTX::Renderer::Context::GL
_size = p_size;
if ( p_immutable )
{
glNamedBufferStorage( _id, _size, nullptr, p_flags );
glNamedBufferStorage( _id, _size, data, p_flags );
}
else
{
glNamedBufferData( _id, _size, nullptr, p_flags );
glNamedBufferData( _id, _size, data, p_flags );
}
}

Expand Down
51 changes: 27 additions & 24 deletions lib/renderer/include/renderer/context/opengl_45.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ namespace VTX::Renderer::Context
* @param p_renderQueue the list of passes to render, ordered by the scheduler.
* @param p_links the connections between passes.
* @param p_output the output framebuffer.
* @param p_uniforms the global GPU variables.
* @param p_globalData the global GPU variables.
* @param p_outInstructions the generated instruction list.
* @param p_outInstructionsDurationRanges the generated instruction list grouped by category.
*/
void build(
const RenderQueue & p_renderQueue,
const Links & p_links,
const Handle p_output,
const SharedUniforms & p_uniforms,
Instructions & p_outInstructions,
InstructionsDurationRanges & p_outInstructionsDurationRanges
const RenderQueue & p_renderQueue,
const Links & p_links,
const Handle p_output,
const std::vector<BufferData> & p_globalData,
Instructions & p_outInstructions,
InstructionsDurationRanges & p_outInstructionsDurationRanges
);

void resize( const RenderQueue & p_renderQueue, const size_t p_width, const size_t p_height );
Expand Down Expand Up @@ -80,7 +80,7 @@ namespace VTX::Renderer::Context
if ( _buffers[ p_key ]->size() != size )
{
VTX_TRACE( "Resizing buffer {} : {} -> {}", p_key, _buffers[ p_key ]->size(), size );
_buffers[ p_key ]->set( GLsizei( size ), 0, GL_STATIC_DRAW );
_buffers[ p_key ]->set( GLsizei( size ), nullptr, 0, GL_STATIC_DRAW );
}
}

Expand Down Expand Up @@ -173,7 +173,7 @@ namespace VTX::Renderer::Context
}

void compute( const ComputePass & p_pass );
void clearComputeBuffers( std::optional<std::vector<ComputePass::Data *>> p_buffers = std::nullopt );
void clearComputeBuffers( std::optional<std::vector<ComputePass::BufferDraw *>> p_buffers = std::nullopt );

private:
/////////////////// TODO: use collection util class
Expand Down Expand Up @@ -224,7 +224,7 @@ namespace VTX::Renderer::Context
CollectionPtr<GL::Program> _programs;
Collection<_StructUniformEntry> _uniforms;

std::map<ComputePass::Data * const, std::unique_ptr<GL::Buffer>> _computeBuffers;
std::map<ComputePass::BufferDraw * const, std::unique_ptr<GL::Buffer>> _computeBuffers;

// Output.
Handle _output;
Expand All @@ -234,7 +234,7 @@ namespace VTX::Renderer::Context

// Keys.
const std::string _KEY_EBO_SUFFIX = "Idx";
inline Key _getKey( const SharedUniform & p_uniform ) const { return p_uniform.name; }
inline Key _getKey( const BufferData & p_uniform ) const { return p_uniform.name; }
inline Key _getKey( const Pass & p_pass ) const { return p_pass.name; }
inline Key _getKey( const Pass * const p_pass, const Program & p_program ) const
{
Expand All @@ -252,12 +252,15 @@ namespace VTX::Renderer::Context
{
return p_input.name + ( p_isIndice ? _KEY_EBO_SUFFIX : "" );
}
inline Key _getKey( const Input & p_input, const Data::Entry & p_entry ) const
inline Key _getKey( const Input & p_input, const BufferDraw::Entry & p_entry ) const
{
return p_input.name + p_entry.name;
}
inline Key _getKey( const Pass * const p_pass, const Program * const p_program, const Uniform & p_uniform )
const
inline Key _getKey(
const Pass * const p_pass,
const Program * const p_program,
const BufferDataValue & p_uniform
) const
{
return ( p_pass ? p_pass->name : "" ) + ( p_program ? p_program->name : "" ) + p_uniform.name;
}
Expand Down Expand Up @@ -289,25 +292,25 @@ namespace VTX::Renderer::Context
Vec2i _getTextureSize( const Attachment & ) const;

void _createUniforms(
GL::Buffer * const p_ubo,
const Uniforms & p_uniforms,
std::vector<Key> & p_uniformKeys,
const Program * const p_descProgram = nullptr,
const Pass * const p_descPassPtr = nullptr
GL::Buffer * const p_ubo,
const BufferDataValues & p_uniforms,
std::vector<Key> & p_uniformKeys,
const Program * const p_descProgram = nullptr,
const Pass * const p_descPassPtr = nullptr

);

template<typename T>
void _setUniformDefaultValue(
const Uniform & p_descUniform,
const Program * const p_descProgram = nullptr,
const Pass * const p_descPass = nullptr
const BufferDataValue & p_descUniform,
const Program * const p_descProgram = nullptr,
const Pass * const p_descPass = nullptr
)
{
assert( std::holds_alternative<StructUniformValue<T>>( p_descUniform.value ) );
assert( std::holds_alternative<BufferValue<T>>( p_descUniform.value ) );

std::string key = _getKey( p_descPass, p_descProgram, p_descUniform );
setValue<T>( std::get<StructUniformValue<T>>( p_descUniform.value ).value, key );
setValue<T>( std::get<BufferValue<T>>( p_descUniform.value ).value, key );
}

void _purgeResources(
Expand Down
Loading

0 comments on commit 5c18612

Please sign in to comment.