From 5c18612f4becf91ee36780025f2a61dce276acb7 Mon Sep 17 00:00:00 2001 From: sguionni Date: Wed, 4 Dec 2024 21:14:22 +0100 Subject: [PATCH] Rework GL buffer structs --- app/bench/src/user_interface.cpp | 8 +- app/bench/src/user_interface.hpp | 12 +- .../renderer/context/concept_context.hpp | 50 ++-- .../include/renderer/context/gl/buffer.hpp | 11 +- .../include/renderer/context/opengl_45.hpp | 51 ++-- lib/renderer/include/renderer/descriptors.hpp | 124 ++++----- lib/renderer/include/renderer/enums.hpp | 31 +++ lib/renderer/include/renderer/passes.hpp | 242 ++++++++---------- .../include/renderer/render_graph.hpp | 12 +- .../src/renderer/context/opengl_45.cpp | 90 +++---- lib/renderer/src/renderer/renderer.cpp | 97 ++++--- 11 files changed, 376 insertions(+), 352 deletions(-) diff --git a/app/bench/src/user_interface.cpp b/app/bench/src/user_interface.cpp index 43d9e034a..4c9e243e4 100644 --- a/app/bench/src/user_interface.cpp +++ b/app/bench/src/user_interface.cpp @@ -412,7 +412,7 @@ namespace VTX::Bench } size_t idSystem = 0; - int toDelete = -1; + int toDelete = -1; for ( auto & proxySystem : p_scene->getProxiesSystems() ) { @@ -580,9 +580,9 @@ namespace VTX::Bench ImNodes::EndInputAttribute(); ImNodes::PopAttributeFlag(); } - else if ( std::holds_alternative( input.desc ) ) + else if ( std::holds_alternative( input.desc ) ) { - // const Data & data = std::get( input.desc ); + // const BufferDraw & data = std::get( input.desc ); ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 1, 1, 0, 1 ) ); ImGui::Text( input.name.c_str() ); ImGui::PopStyleColor(); @@ -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; diff --git a/app/bench/src/user_interface.hpp b/app/bench/src/user_interface.hpp index 9c9b66914..9c45c7b9c 100644 --- a/app/bench/src/user_interface.hpp +++ b/app/bench/src/user_interface.hpp @@ -56,14 +56,14 @@ namespace VTX::Bench template 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 descValue = std::get>( p_uniform.value ); + const BufferValue descValue = std::get>( p_uniform.value ); static std::map values; if ( values.find( p_key ) == values.end() ) @@ -96,7 +96,7 @@ namespace VTX::Bench } else if ( descValue.minMax.has_value() ) { - const typename StructUniformValue::MinMax & minMax = descValue.minMax.value(); + const typename BufferValue::MinMax & minMax = descValue.minMax.value(); if constexpr ( std::is_integral::value ) { diff --git a/lib/renderer/include/renderer/context/concept_context.hpp b/lib/renderer/include/renderer/context/concept_context.hpp index 3ce30f5fe..c0a066cc7 100644 --- a/lib/renderer/include/renderer/context/concept_context.hpp +++ b/lib/renderer/include/renderer/context/concept_context.hpp @@ -26,35 +26,35 @@ namespace VTX::Renderer::Context concept Concept = std::is_base_of::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 & 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 & 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 & p_globalData, + const std::string & p_key, + const std::any & p_value, + const std::vector & 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 & 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; { p_context.resize( p_renderQueue, p_width, p_height ) } -> std::same_as; diff --git a/lib/renderer/include/renderer/context/gl/buffer.hpp b/lib/renderer/include/renderer/context/gl/buffer.hpp index 2b48b5cdc..f2e84c1fa 100644 --- a/lib/renderer/include/renderer/context/gl/buffer.hpp +++ b/lib/renderer/include/renderer/context/gl/buffer.hpp @@ -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 ); @@ -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 ); } } diff --git a/lib/renderer/include/renderer/context/opengl_45.hpp b/lib/renderer/include/renderer/context/opengl_45.hpp index 6f461135a..6e1d32149 100644 --- a/lib/renderer/include/renderer/context/opengl_45.hpp +++ b/lib/renderer/include/renderer/context/opengl_45.hpp @@ -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 & p_globalData, + Instructions & p_outInstructions, + InstructionsDurationRanges & p_outInstructionsDurationRanges ); void resize( const RenderQueue & p_renderQueue, const size_t p_width, const size_t p_height ); @@ -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 ); } } @@ -173,7 +173,7 @@ namespace VTX::Renderer::Context } void compute( const ComputePass & p_pass ); - void clearComputeBuffers( std::optional> p_buffers = std::nullopt ); + void clearComputeBuffers( std::optional> p_buffers = std::nullopt ); private: /////////////////// TODO: use collection util class @@ -224,7 +224,7 @@ namespace VTX::Renderer::Context CollectionPtr _programs; Collection<_StructUniformEntry> _uniforms; - std::map> _computeBuffers; + std::map> _computeBuffers; // Output. Handle _output; @@ -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 { @@ -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; } @@ -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 & 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 & p_uniformKeys, + const Program * const p_descProgram = nullptr, + const Pass * const p_descPassPtr = nullptr ); template 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>( p_descUniform.value ) ); + assert( std::holds_alternative>( p_descUniform.value ) ); std::string key = _getKey( p_descPass, p_descProgram, p_descUniform ); - setValue( std::get>( p_descUniform.value ).value, key ); + setValue( std::get>( p_descUniform.value ).value, key ); } void _purgeResources( diff --git a/lib/renderer/include/renderer/descriptors.hpp b/lib/renderer/include/renderer/descriptors.hpp index cbca6b384..a4cc4ef41 100644 --- a/lib/renderer/include/renderer/descriptors.hpp +++ b/lib/renderer/include/renderer/descriptors.hpp @@ -30,37 +30,19 @@ namespace VTX::Renderer void * data = nullptr; }; - struct Data + struct BufferDraw { struct Entry { std::string name; E_TYPE nativeType; size_t components; - // TODO: handle more buffer types. }; std::vector entries; }; - struct Storage - { - }; - - using Handle = uint; - using IO = std::variant; - - struct Input - { - std::string name; - IO desc; - }; - - struct Output : public Input - { - }; - template - struct StructUniformValue + struct BufferValue { T value; @@ -73,28 +55,62 @@ namespace VTX::Renderer std::optional minMax; }; - using UniformValue = std::variant< - StructUniformValue, - StructUniformValue, - StructUniformValue, - StructUniformValue, - StructUniformValue, - StructUniformValue, - StructUniformValue, - StructUniformValue, - StructUniformValue, - StructUniformValue, - StructUniformValue, - StructUniformValue, - StructUniformValue, - StructUniformValue, - StructUniformValue>; - - struct Uniform + using BufferDataValueVariant = std::variant< + BufferValue, + BufferValue, + BufferValue, + BufferValue, + BufferValue, + BufferValue, + BufferValue, + BufferValue, + BufferValue, + BufferValue, + BufferValue, + BufferValue, + BufferValue, + BufferValue, + BufferValue>; + + struct BufferDataValue + { + std::string name; + E_TYPE type; + BufferDataValueVariant value; + }; + + using BufferDataValues = std::vector; + + struct BufferData + { + std::string name; + char binding; + BufferDataValues values; + bool isLarge = false; // If max size >64 Ko + bool isImmutable = false; // TODO: use variant of flags enums. + + /* + struct BufferDraw + { + size_t size; + void * data; + uint binding; + bool overwrite = false; // TODO: force data? + }; + */ + }; + + using Handle = uint; + using IO = std::variant; + + struct Input + { + std::string name; + IO desc; + }; + + struct Output : public Input { - std::string name; - E_TYPE type; - UniformValue value; }; using NeedRenderFunc = std::function; @@ -116,23 +132,13 @@ namespace VTX::Renderer using Files = std::variant>; - using Uniforms = std::vector; - - struct SharedUniform - { - std::string name; - Uniforms uniforms; - char binding; - bool isDynamic = false; // For larger data. - }; - - using SharedUniforms = std::vector; + using BufferDataList = std::vector; struct Program { std::string name; Files shaders; - Uniforms uniforms; + BufferDataValues data; std::optional draw; std::string toInject; std::string suffix; @@ -159,7 +165,8 @@ namespace VTX::Renderer { Program program; - struct Data + // TODO: merge with uniform to use same buffer descriptor? + struct BufferDraw { size_t size; void * data; @@ -167,8 +174,8 @@ namespace VTX::Renderer bool overwrite = false; // TODO: force data? }; - std::vector data; - std::variant size; + std::vector data; + std::variant size; }; struct Link @@ -205,9 +212,10 @@ namespace VTX::Renderer // TODO: check compatibility. return true; } - bool operator()( const Storage & p_left, const Storage & p_right ) const { return false; } - bool operator()( const Data & p_left, const Data & p_right ) const { return false; } + bool operator()( const BufferDraw & p_left, const BufferDraw & p_right ) const { return false; } + + bool operator()( const BufferData & p_left, const BufferData & p_right ) const { return false; } template bool operator()( const T & p_left, const U & p_right ) const diff --git a/lib/renderer/include/renderer/enums.hpp b/lib/renderer/include/renderer/enums.hpp index 43c2729c3..3ce76a728 100644 --- a/lib/renderer/include/renderer/enums.hpp +++ b/lib/renderer/include/renderer/enums.hpp @@ -73,6 +73,37 @@ namespace VTX::Renderer READ_WRITE, }; + enum struct E_MUTABLE_USAGE + { + STATIC_DRAW, + STATIC_READ, + STATIC_COPY, + DYNAMIC_DRAW, + DYNAMIC_READ, + DYNAMIC_COPY, + // STREAM_DRAW, + // STREAM_READ, + // STREAM_COPY, + }; + + enum struct E_TARGET + { + UNIFORM_BUFFER, + SHADER_STORAGE_BUFFER + }; + + enum struct E_IMMUTABLE_FLAG + { + DYNAMIC_STORAGE_BIT, // Allors update subdata? + MAP_READ, // Allows mapping for reading. + MAP_WRITE, // Allows mapping for writing. + + // TODO: check. + // MAP_PERSISTENT, + // MAP_COHERENT, + // CLIENT_STORAGE_BIT + }; + enum struct E_SETTING { CLEAR diff --git a/lib/renderer/include/renderer/passes.hpp b/lib/renderer/include/renderer/passes.hpp index 5ee10c04d..e9cff1a87 100644 --- a/lib/renderer/include/renderer/passes.hpp +++ b/lib/renderer/include/renderer/passes.hpp @@ -20,9 +20,9 @@ namespace VTX::Renderer inline const Attachment imageR16F { E_FORMAT::R16F }; inline const Attachment imageR8 { E_FORMAT::R8 }; - // Data. + // BufferDraw. // TODO: compress all. - inline const Data dataSpheresCylinders { { + inline const BufferDraw dataSpheresCylinders { { { "Positions", E_TYPE::FLOAT, 3 }, { "Colors", E_TYPE::UBYTE, 1 }, { "Radii", E_TYPE::FLOAT, 1 }, // TODO: move to ubo or hardcode? @@ -32,7 +32,7 @@ namespace VTX::Renderer { "Representations", E_TYPE::UBYTE, 1 }, } }; - inline const Data dataRibbons { { + inline const BufferDraw dataRibbons { { { "Positions", E_TYPE::FLOAT, 4 }, { "Directions", E_TYPE::FLOAT, 3 }, { "Types", E_TYPE::UBYTE, 1 }, @@ -43,7 +43,7 @@ namespace VTX::Renderer { "Representations", E_TYPE::UBYTE, 1 }, } }; - inline const Data dataTriangles { { + inline const BufferDraw dataTriangles { { { "Positions", E_TYPE::FLOAT, 3 }, { "Normales", E_TYPE::FLOAT, 3 }, { "Colors", E_TYPE::UBYTE, 1 }, @@ -53,7 +53,7 @@ namespace VTX::Renderer { "Representations", E_TYPE::UBYTE, 1 }, } }; - inline const Data dataVoxels { { { "Mins", E_TYPE::FLOAT, 3 }, { "Maxs", E_TYPE::FLOAT, 3 } } }; + inline const BufferDraw dataVoxels { { { "Mins", E_TYPE::FLOAT, 3 }, { "Maxs", E_TYPE::FLOAT, 3 } } }; // Passes. @@ -68,10 +68,11 @@ namespace VTX::Renderer { E_CHAN_OUT::COLOR_1, { "Color", imageRGBA16F } }, { E_CHAN_OUT::COLOR_2, { "Picking", imageRG32UI } }, { E_CHAN_OUT::DEPTH, { "Depth", imageD32F } } }, - Programs { { "Sphere", "sphere", Uniforms {}, Draw { "SpheresCylinders", E_PRIMITIVE::POINTS } }, - { "Cylinder", "cylinder", Uniforms {}, Draw { "SpheresCylinders", E_PRIMITIVE::LINES, true } }, - { "Ribbon", "ribbon", Uniforms {}, Draw { "Ribbons", E_PRIMITIVE::PATCHES, true } }, - { "Voxel", "voxel", Uniforms {}, Draw { "Voxels", E_PRIMITIVE::POINTS } } }, + Programs { + { "Sphere", "sphere", BufferDataValues {}, Draw { "SpheresCylinders", E_PRIMITIVE::POINTS } }, + { "Cylinder", "cylinder", BufferDataValues {}, Draw { "SpheresCylinders", E_PRIMITIVE::LINES, true } }, + { "Ribbon", "ribbon", BufferDataValues {}, Draw { "Ribbons", E_PRIMITIVE::PATCHES, true } }, + { "Voxel", "voxel", BufferDataValues {}, Draw { "Voxels", E_PRIMITIVE::POINTS } } }, { E_SETTING::CLEAR } }; @@ -122,13 +123,11 @@ namespace VTX::Renderer Programs { { "SSAO", std::vector { "default.vert", "ssao.frag" }, - Uniforms { - - { { "Intensity", - E_TYPE::FLOAT, - StructUniformValue { - SSAO_INTENSITY_DEFAULT, - StructUniformValue::MinMax { SSAO_INTENSITY_MIN, SSAO_INTENSITY_MAX } } } } } } } + BufferDataValues { { { "Intensity", + E_TYPE::FLOAT, + BufferValue { SSAO_INTENSITY_DEFAULT, + BufferValue::MinMax { SSAO_INTENSITY_MIN, + SSAO_INTENSITY_MAX } } } } } } } }; // Blur. @@ -138,14 +137,12 @@ namespace VTX::Renderer Outputs { { E_CHAN_OUT::COLOR_0, { "", imageR16F } } }, Programs { { "Blur", std::vector { "default.vert", "blur.frag" }, - Uniforms { - - { { "Direction", E_TYPE::VEC2I, StructUniformValue { Vec2i( 1, 0 ) } }, - { "Size", - E_TYPE::FLOAT, - StructUniformValue { - BLUR_SIZE_DEFAULT, - StructUniformValue::MinMax { BLUR_SIZE_MIN, BLUR_SIZE_MAX } } } } } } } + BufferDataValues { { { "Direction", E_TYPE::VEC2I, BufferValue { Vec2i( 1, 0 ) } }, + { "Size", + E_TYPE::FLOAT, + BufferValue { + BLUR_SIZE_DEFAULT, + BufferValue::MinMax { BLUR_SIZE_MIN, BLUR_SIZE_MAX } } } } } } } }; // Shading. @@ -169,50 +166,39 @@ namespace VTX::Renderer Programs { { "Shading", std::vector { "default.vert", "shading.frag" }, - Uniforms { - - { - { "Background color", - E_TYPE::COLOR4, - StructUniformValue { COLOR_BACKGROUND_DEFAULT } }, - { "Light color", E_TYPE::COLOR4, StructUniformValue { COLOR_LIGHT_DEFAULT } }, - { "Fog color", E_TYPE::COLOR4, StructUniformValue { COLOR_FOG_DEFAULT } }, - { "Mode", - E_TYPE::UINT, - StructUniformValue { - uint( SHADING_MODE_DEFAULT ), - StructUniformValue::MinMax { uint( E_SHADING::DIFFUSE ), - uint( E_SHADING::COUNT ) - 1 } } }, - { "Specular factor", - E_TYPE::FLOAT, - StructUniformValue { - SPECULAR_FACTOR_DEFAULT, - StructUniformValue::MinMax { SPECULAR_FACTOR_MIN, SPECULAR_FACTOR_MAX } } }, - { "Shininess", - E_TYPE::FLOAT, - StructUniformValue { - SHININESS_DEFAULT, - StructUniformValue::MinMax { SHININESS_MIN, SHININESS_MAX } } }, - { "Toon steps", - E_TYPE::UINT, - StructUniformValue { - TOON_STEPS_DEFAULT, - StructUniformValue::MinMax { TOON_STEPS_MIN, TOON_STEPS_MAX } } }, - { "Fog near", - E_TYPE::FLOAT, - StructUniformValue { - FOG_NEAR_DEFAULT, - StructUniformValue::MinMax { FOG_NEAR_MIN, FOG_NEAR_MAX } } }, - { "Fog far", - E_TYPE::FLOAT, - StructUniformValue { FOG_FAR_DEFAULT, - StructUniformValue::MinMax { FOG_FAR_MIN, FOG_FAR_MAX } } }, - { "Fog density", - E_TYPE::FLOAT, - StructUniformValue { - FOG_DENSITY_DEFAULT, - StructUniformValue::MinMax { FOG_DENSITY_MIN, FOG_DENSITY_MAX } } }, - } } } } + BufferDataValues { { + { "Background color", E_TYPE::COLOR4, BufferValue { COLOR_BACKGROUND_DEFAULT } }, + { "Light color", E_TYPE::COLOR4, BufferValue { COLOR_LIGHT_DEFAULT } }, + { "Fog color", E_TYPE::COLOR4, BufferValue { COLOR_FOG_DEFAULT } }, + { "Mode", + E_TYPE::UINT, + BufferValue { + uint( SHADING_MODE_DEFAULT ), + BufferValue::MinMax { uint( E_SHADING::DIFFUSE ), uint( E_SHADING::COUNT ) - 1 } } }, + { "Specular factor", + E_TYPE::FLOAT, + BufferValue { SPECULAR_FACTOR_DEFAULT, + BufferValue::MinMax { SPECULAR_FACTOR_MIN, SPECULAR_FACTOR_MAX } } }, + { "Shininess", + E_TYPE::FLOAT, + BufferValue { SHININESS_DEFAULT, + BufferValue::MinMax { SHININESS_MIN, SHININESS_MAX } } }, + { "Toon steps", + E_TYPE::UINT, + BufferValue { TOON_STEPS_DEFAULT, + BufferValue::MinMax { TOON_STEPS_MIN, TOON_STEPS_MAX } } }, + { "Fog near", + E_TYPE::FLOAT, + BufferValue { FOG_NEAR_DEFAULT, + BufferValue::MinMax { FOG_NEAR_MIN, FOG_NEAR_MAX } } }, + { "Fog far", + E_TYPE::FLOAT, + BufferValue { FOG_FAR_DEFAULT, BufferValue::MinMax { FOG_FAR_MIN, FOG_FAR_MAX } } }, + { "Fog density", + E_TYPE::FLOAT, + BufferValue { FOG_DENSITY_DEFAULT, + BufferValue::MinMax { FOG_DENSITY_MIN, FOG_DENSITY_MAX } } }, + } } } } }; // Outline. @@ -223,18 +209,17 @@ namespace VTX::Renderer Programs { { "Outline", std::vector { "default.vert", "outline.frag" }, - Uniforms { - { { "Color", E_TYPE::COLOR4, StructUniformValue { COLOR_WHITE } }, - { "Sensitivity", - E_TYPE::FLOAT, - StructUniformValue { - OUTLINE_SENSITIVITY_DEFAULT, - StructUniformValue::MinMax { OUTLINE_SENSITIVITY_MIN, OUTLINE_SENSITIVITY_MAX } } }, - { "Thickness", - E_TYPE::UINT, - StructUniformValue { - OUTLINE_THICKNESS_DEFAULT, - StructUniformValue::MinMax { OUTLINE_THICKNESS_MIN, OUTLINE_THICKNESS_MAX } } } } } } } + BufferDataValues { { { "Color", E_TYPE::COLOR4, BufferValue { COLOR_WHITE } }, + { "Sensitivity", + E_TYPE::FLOAT, + BufferValue { OUTLINE_SENSITIVITY_DEFAULT, + BufferValue::MinMax { OUTLINE_SENSITIVITY_MIN, + OUTLINE_SENSITIVITY_MAX } } }, + { "Thickness", + E_TYPE::UINT, + BufferValue { OUTLINE_THICKNESS_DEFAULT, + BufferValue::MinMax { OUTLINE_THICKNESS_MIN, + OUTLINE_THICKNESS_MAX } } } } } } } }; // Glow. @@ -244,13 +229,12 @@ namespace VTX::Renderer Outputs { { E_CHAN_OUT::COLOR_0, { "", imageRGBA16F } } }, Programs { { "Gow", std::vector { "default.vert", "glow.frag" }, - Uniforms { { { "Color", E_TYPE::COLOR4, StructUniformValue { COLOR_WHITE } }, - { "Sensitivity", - E_TYPE::FLOAT, - StructUniformValue { 0.f, StructUniformValue::MinMax { 0.f, 1.f } } }, - { "Size", - E_TYPE::UINT, - StructUniformValue { 1, StructUniformValue::MinMax { 1, 5 } } } } } } } + BufferDataValues { + { { "Color", E_TYPE::COLOR4, BufferValue { COLOR_WHITE } }, + { "Sensitivity", + E_TYPE::FLOAT, + BufferValue { 0.f, BufferValue::MinMax { 0.f, 1.f } } }, + { "Size", E_TYPE::UINT, BufferValue { 1, BufferValue::MinMax { 1, 5 } } } } } } } }; // Selection. @@ -260,11 +244,11 @@ namespace VTX::Renderer { E_CHAN_IN::_1, { "Color", imageRGBA16F } }, { E_CHAN_IN::_2, { "Depth", imageR32F } } }, Outputs { { E_CHAN_OUT::COLOR_0, { "", imageRGBA16F } } }, - Programs { { "Selection", - std::vector { "default.vert", "selection.frag" }, - Uniforms { { { "Color", - E_TYPE::COLOR4, - StructUniformValue { COLOR_SELECTION_DEFAULT } } } } } } + Programs { + { "Selection", + std::vector { "default.vert", "selection.frag" }, + BufferDataValues { + { { "Color", E_TYPE::COLOR4, BufferValue { COLOR_SELECTION_DEFAULT } } } } } } }; // FXAA. @@ -280,10 +264,9 @@ namespace VTX::Renderer Outputs { { E_CHAN_OUT::COLOR_0, { "", imageRGBA16F } } }, Programs { { "Pixelize", std::vector { "default.vert", "pixelize.frag" }, - Uniforms { { { "Size", - E_TYPE::UINT, - StructUniformValue { 5, StructUniformValue::MinMax { 1, 15 } } }, - { "Background", E_TYPE::BOOL, StructUniformValue { true } } } } } } + BufferDataValues { + { { "Size", E_TYPE::UINT, BufferValue { 5, BufferValue::MinMax { 1, 15 } } }, + { "Background", E_TYPE::BOOL, BufferValue { true } } } } } } }; // CRT. @@ -294,27 +277,25 @@ namespace VTX::Renderer Programs { { "CRT", std::vector { "default.vert", "crt.frag" }, - Uniforms { + BufferDataValues { - { { "Curvature", E_TYPE::VEC2F, StructUniformValue { Vec2f( 3.f, 3.f ) } }, - { "Ratio", - E_TYPE::FLOAT, - StructUniformValue { 0.25f, StructUniformValue::MinMax { 0.1f, 1.f } } }, + { { "Curvature", E_TYPE::VEC2F, BufferValue { Vec2f( 3.f, 3.f ) } }, + { "Ratio", E_TYPE::FLOAT, BufferValue { 0.25f, BufferValue::MinMax { 0.1f, 1.f } } }, { "Graniness X", E_TYPE::FLOAT, - StructUniformValue { 0.5f, StructUniformValue::MinMax { 0.f, 5.f } } }, + BufferValue { 0.5f, BufferValue::MinMax { 0.f, 5.f } } }, { "Graniness Y", E_TYPE::FLOAT, - StructUniformValue { 0.5f, StructUniformValue::MinMax { 0.f, 5.f } } }, + BufferValue { 0.5f, BufferValue::MinMax { 0.f, 5.f } } }, { "Vignette roundness", E_TYPE::FLOAT, - StructUniformValue { 100.f, StructUniformValue::MinMax { 1.f, 1000.f } } }, + BufferValue { 100.f, BufferValue::MinMax { 1.f, 1000.f } } }, { "Vignette intensity", E_TYPE::FLOAT, - StructUniformValue { 0.5f, StructUniformValue::MinMax { 0.f, 5.f } } }, + BufferValue { 0.5f, BufferValue::MinMax { 0.f, 5.f } } }, { "Brightness", E_TYPE::FLOAT, - StructUniformValue { 1.2f, StructUniformValue::MinMax { 1.f, 10.f } } } } } } } + BufferValue { 1.2f, BufferValue::MinMax { 1.f, 10.f } } } } } } } }; // Chromatic aberration. @@ -322,21 +303,19 @@ namespace VTX::Renderer "Chromatic aberration", Inputs { { E_CHAN_IN::_0, { "", imageRGBA16F } } }, Outputs { { E_CHAN_OUT::COLOR_0, { "", imageRGBA16F } } }, - Programs { - { "Chromatic aberration", - std::vector { "default.vert", "chromatic_aberration.frag" }, - Uniforms { + Programs { { "Chromatic aberration", + std::vector { "default.vert", "chromatic_aberration.frag" }, + BufferDataValues { - { { "Red", - E_TYPE::FLOAT, - StructUniformValue { 0.009f, StructUniformValue::MinMax { -0.05f, 0.05f } } }, - { "Green", - E_TYPE::FLOAT, - StructUniformValue { 0.006f, StructUniformValue::MinMax { -0.05f, 0.05f } } }, - { "Blue", - E_TYPE::FLOAT, - StructUniformValue { -0.006f, - StructUniformValue::MinMax { -0.05f, 0.05f } } } } } } } + { { "Red", + E_TYPE::FLOAT, + BufferValue { 0.009f, BufferValue::MinMax { -0.05f, 0.05f } } }, + { "Green", + E_TYPE::FLOAT, + BufferValue { 0.006f, BufferValue::MinMax { -0.05f, 0.05f } } }, + { "Blue", + E_TYPE::FLOAT, + BufferValue { -0.006f, BufferValue::MinMax { -0.05f, 0.05f } } } } } } } }; // Colorize. @@ -347,7 +326,7 @@ namespace VTX::Renderer Programs { { "Colorize", std::vector { "default.vert", "colorize.frag" }, - Uniforms { { { "Color", E_TYPE::COLOR4, StructUniformValue { COLOR_YELLOW } } } } } } + BufferDataValues { { { "Color", E_TYPE::COLOR4, BufferValue { COLOR_YELLOW } } } } } } }; // Debug. @@ -355,17 +334,16 @@ namespace VTX::Renderer "Debug", Inputs { { E_CHAN_IN::_0, { "", imageRGBA16F } } }, Outputs { { E_CHAN_OUT::COLOR_0, { "", imageRGBA16F } } }, - Programs { - { "Debug", - std::vector { "default.vert", "debug.frag" }, - Uniforms { - - { { "Color", E_TYPE::COLOR4, StructUniformValue { COLOR_YELLOW } }, - { "Color2", E_TYPE::COLOR4, StructUniformValue { COLOR_BLUE } }, - { "Test", E_TYPE::FLOAT, StructUniformValue { 5646.f } }, - { "Factor", - E_TYPE::FLOAT, - StructUniformValue { 5.f, StructUniformValue::MinMax { 0.f, 10.f } } } } } } } + Programs { { "Debug", + std::vector { "default.vert", "debug.frag" }, + BufferDataValues { + + { { "Color", E_TYPE::COLOR4, BufferValue { COLOR_YELLOW } }, + { "Color2", E_TYPE::COLOR4, BufferValue { COLOR_BLUE } }, + { "Test", E_TYPE::FLOAT, BufferValue { 5646.f } }, + { "Factor", + E_TYPE::FLOAT, + BufferValue { 5.f, BufferValue::MinMax { 0.f, 10.f } } } } } } } }; /* diff --git a/lib/renderer/include/renderer/render_graph.hpp b/lib/renderer/include/renderer/render_graph.hpp index eca0c4b1d..83bc07d9d 100644 --- a/lib/renderer/include/renderer/render_graph.hpp +++ b/lib/renderer/include/renderer/render_graph.hpp @@ -168,7 +168,7 @@ namespace VTX::Renderer { VTX_DEBUG( "{}", "Generating instructions..." ); _context->build( - _renderQueue, _links, p_output, _uniforms, p_outInstructions, p_outInstructionsDurationRanges + _renderQueue, _links, p_output, _globalData, p_outInstructions, p_outInstructionsDurationRanges ); VTX_DEBUG( "{}", "Generating instructions... done" ); } @@ -190,17 +190,17 @@ namespace VTX::Renderer _context.reset( nullptr ); } - inline void addUniforms( const SharedUniform & p_uniforms ) { _uniforms.emplace_back( p_uniforms ); } + inline void addGlobalData( const BufferData & p_globalData ) { _globalData.emplace_back( p_globalData ); } private: S _scheduler; RenderQueue _renderQueue; std::unique_ptr _context; - const Output * _output; - Passes _passes; - SharedUniforms _uniforms; - Links _links; + const Output * _output; + Passes _passes; + std::vector _globalData; + Links _links; }; } // namespace VTX::Renderer diff --git a/lib/renderer/src/renderer/context/opengl_45.cpp b/lib/renderer/src/renderer/context/opengl_45.cpp index af94f0dbf..ed914f138 100644 --- a/lib/renderer/src/renderer/context/opengl_45.cpp +++ b/lib/renderer/src/renderer/context/opengl_45.cpp @@ -70,12 +70,12 @@ namespace VTX::Renderer::Context } void OpenGL45::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 & p_globalData, + Instructions & p_outInstructions, + InstructionsDurationRanges & p_outInstructionsDurationRanges ) { // Store created items to free no more used later. @@ -84,7 +84,7 @@ namespace VTX::Renderer::Context std::vector framebuffers; std::vector textures; std::vector programs; - std::vector uniforms; + std::vector data; vertexArrays.push_back( _KEY_QUAD ); buffers.push_back( _KEY_QUAD ); @@ -104,28 +104,31 @@ namespace VTX::Renderer::Context _output = p_output; // Create shared buffers. - if ( not p_uniforms.empty() ) + if ( not p_globalData.empty() ) { p_outInstructionsDurationRanges.emplace_back( InstructionsDurationRange { "Start", p_outInstructions.size() } ); - for ( const SharedUniform & uniform : p_uniforms ) + // TODO: _createBufferData function. + for ( const BufferData & bufferData : p_globalData ) { - const Key keyBuffer = _getKey( uniform ); + const Key keyBuffer = _getKey( bufferData ); buffers.push_back( keyBuffer ); if ( not _buffers.contains( keyBuffer ) ) { _buffers.emplace( keyBuffer, std::make_unique() ); } - _createUniforms( _buffers[ keyBuffer ].get(), uniform.uniforms, uniforms ); + _createUniforms( _buffers[ keyBuffer ].get(), bufferData.values, data ); assert( _buffers.contains( keyBuffer ) ); - GL::Buffer * const buffer = _buffers[ keyBuffer ].get(); - GLenum bufferType = uniform.isDynamic ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER; - uint binding = uniform.binding; - p_outInstructions.emplace_back( [ buffer, bufferType, binding ]() - { buffer->bind( bufferType, binding ); } ); + GL::Buffer * const buffer = _buffers[ keyBuffer ].get(); + uint binding = bufferData.binding; + const bool isLarge = bufferData.isLarge; + p_outInstructions.emplace_back( + [ buffer, isLarge, binding ]() + { buffer->bind( isLarge ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER, binding ); } + ); } p_outInstructionsDurationRanges.back().last = p_outInstructions.size() - 1; @@ -184,7 +187,7 @@ namespace VTX::Renderer::Context } // Uniforms. - if ( not descProgram.uniforms.empty() ) + if ( not descProgram.data.empty() ) { const Key keyBuffer = _getKey( descPassPtr, descProgram ); buffers.push_back( keyBuffer ); @@ -193,9 +196,7 @@ namespace VTX::Renderer::Context { _buffers.emplace( keyBuffer, std::make_unique() ); } - _createUniforms( - _buffers[ keyBuffer ].get(), descProgram.uniforms, uniforms, &descProgram, descPassPtr - ); + _createUniforms( _buffers[ keyBuffer ].get(), descProgram.data, data, &descProgram, descPassPtr ); } } @@ -307,7 +308,7 @@ namespace VTX::Renderer::Context { const Key keyProgram = _getKey( descPassPtr, descProgram ); - if ( not descProgram.uniforms.empty() ) + if ( not descProgram.data.empty() ) { assert( _buffers.contains( keyProgram ) ); @@ -405,7 +406,7 @@ namespace VTX::Renderer::Context ); } - if ( not descProgram.uniforms.empty() ) + if ( not descProgram.data.empty() ) { assert( _buffers.contains( keyProgram ) ); GL::Buffer * ubo = _buffers[ keyProgram ].get(); @@ -447,7 +448,7 @@ namespace VTX::Renderer::Context p_outInstructionsDurationRanges.emplace_back( InstructionsDurationRange { "End", p_outInstructions.size() } ); // Unbind shared buffers. - for ( const SharedUniform & uniform : p_uniforms ) + for ( const BufferData & uniform : p_globalData ) { const Key k = _getKey( uniform ); assert( _buffers.contains( k ) ); @@ -458,7 +459,7 @@ namespace VTX::Renderer::Context p_outInstructionsDurationRanges.back().last = p_outInstructions.size() - 1; // Purge unused resources. - _purgeResources( vertexArrays, buffers, framebuffers, textures, programs, uniforms ); + _purgeResources( vertexArrays, buffers, framebuffers, textures, programs, data ); } void OpenGL45::resize( const RenderQueue & p_renderQueue, const size_t p_width, const size_t p_height ) @@ -567,7 +568,7 @@ namespace VTX::Renderer::Context void OpenGL45::compute( const ComputePass & p_pass ) { return; - // TODO: Create program and uniforms (refacto build). + // TODO: Create program and data (refacto build). const Program & descProgram = p_pass.program; std::string definesToInject = "#define LOCAL_SIZE_X " + std::to_string( LOCAL_SIZE_X ) + "\n" @@ -578,11 +579,11 @@ namespace VTX::Renderer::Context = _programManager->createProgram( descProgram.name, descProgram.shaders, definesToInject ); // Create and bind buffers. - for ( ComputePass::Data * const data : p_pass.data ) + for ( ComputePass::BufferDraw * const data : p_pass.data ) { if ( not _computeBuffers.contains( data ) ) { - _computeBuffers.emplace( data, std::make_unique( GLsizei( data->size ), data->data ) ); + _computeBuffers.emplace( data, std::make_unique( GLsizei( data->size ), data->data, 1 ) ); } _computeBuffers[ data ]->bind( GL_SHADER_STORAGE_BUFFER, data->binding ); @@ -617,17 +618,17 @@ namespace VTX::Renderer::Context glMemoryBarrier( GL_SHADER_STORAGE_BARRIER_BIT ); // Unbind buffers. - for ( ComputePass::Data * const data : p_pass.data ) + for ( ComputePass::BufferDraw * const data : p_pass.data ) { _computeBuffers[ data ]->unbind(); } } - void OpenGL45::clearComputeBuffers( std::optional> p_buffers ) + void OpenGL45::clearComputeBuffers( std::optional> p_buffers ) { if ( p_buffers.has_value() ) { - for ( ComputePass::Data * const data : p_buffers.value() ) + for ( ComputePass::BufferDraw * const data : p_buffers.value() ) { _computeBuffers.erase( data ); } @@ -664,9 +665,9 @@ namespace VTX::Renderer::Context } } // Create vao if data provided. - else if ( std::holds_alternative( descIO ) ) + else if ( std::holds_alternative( descIO ) ) { - const Data & data = std::get( descIO ); + const BufferDraw & data = std::get( descIO ); // Create vao. const Key keyVao = _getKey( input ); @@ -691,7 +692,7 @@ namespace VTX::Renderer::Context vaoData->bindElementBuffer( *eboData ); GLuint chan = 0; - for ( const Data::Entry & entry : data.entries ) + for ( const BufferDraw::Entry & entry : data.entries ) { const Key keyData = _getKey( input, entry ); p_buffers.push_back( keyData ); @@ -866,17 +867,17 @@ namespace VTX::Renderer::Context } void OpenGL45::_createUniforms( - GL::Buffer * const p_ubo, - const Uniforms & p_uniforms, - std::vector & p_uniformKeys, - const Program * const p_descProgram, - const Pass * const p_descPass + GL::Buffer * const p_ubo, + const BufferDataValues & p_uniforms, + std::vector & p_uniformKeys, + const Program * const p_descProgram, + const Pass * const p_descPass ) { // Create uniform entries. size_t offset = 0; - for ( const Uniform & descUniform : p_uniforms ) + for ( const BufferDataValue & descUniform : p_uniforms ) { size_t size = _mapTypeSizes[ descUniform.type ]; std::string key = _getKey( p_descPass, p_descProgram, descUniform ); @@ -919,17 +920,17 @@ namespace VTX::Renderer::Context return; } - for ( const Uniform & descUniform : p_uniforms ) + for ( const BufferDataValue & descUniform : p_uniforms ) { std::string key = _getKey( p_descPass, p_descProgram, descUniform ); _uniforms[ key ]->totalSize = totalSize; } // Init ubo. - p_ubo->set( GLsizei( totalSize ), 0, GL_STATIC_DRAW ); + p_ubo->set( GLsizei( totalSize ), nullptr, 0, GL_STATIC_DRAW ); // Fill default values. - for ( const Uniform & descUniform : p_uniforms ) + for ( const BufferDataValue & descUniform : p_uniforms ) { switch ( descUniform.type ) { @@ -961,7 +962,7 @@ namespace VTX::Renderer::Context const std::vector & framebuffers, const std::vector & textures, const std::vector & programs, - const std::vector & uniforms + const std::vector & data ) { std::erase_if( @@ -996,8 +997,7 @@ namespace VTX::Renderer::Context std::erase_if( _uniforms, - [ &uniforms ]( const auto & p ) - { return std::find( uniforms.begin(), uniforms.end(), p.first ) == uniforms.end(); } + [ &data ]( const auto & p ) { return std::find( data.begin(), data.end(), p.first ) == data.end(); } ); } diff --git a/lib/renderer/src/renderer/renderer.cpp b/lib/renderer/src/renderer/renderer.cpp index d97e4c8ac..864d00ca9 100644 --- a/lib/renderer/src/renderer/renderer.cpp +++ b/lib/renderer/src/renderer/renderer.cpp @@ -17,41 +17,41 @@ namespace VTX::Renderer // Passes. _refreshGraph(); - // Shared uniforms. - _renderGraph->addUniforms( + // Shared data. + _renderGraph->addGlobalData( { "Camera", - { { "Matrix view", E_TYPE::MAT4F, StructUniformValue { MAT4F_ID } }, - { "Matrix projection", E_TYPE::MAT4F, StructUniformValue { MAT4F_ID } }, - { "Camera position", E_TYPE::VEC3F, StructUniformValue { VEC3F_ZERO } }, + 15, + { { "Matrix view", E_TYPE::MAT4F, BufferValue { MAT4F_ID } }, + { "Matrix projection", E_TYPE::MAT4F, BufferValue { MAT4F_ID } }, + { "Camera position", E_TYPE::VEC3F, BufferValue { VEC3F_ZERO } }, { "Camera clip infos", // { _near * _far, _far, _far - _near, _near } E_TYPE::VEC4F, - StructUniformValue { VEC4F_ZERO } }, - { "Resolution", E_TYPE::VEC2I, StructUniformValue { Vec2i { p_width, p_height } } }, - { "Mouse position", E_TYPE::VEC2I, StructUniformValue { Vec2i { 0, 0 } } }, - { "Is perspective", E_TYPE::UINT, StructUniformValue { 1 } } }, - 15 } + BufferValue { VEC4F_ZERO } }, + { "Resolution", E_TYPE::VEC2I, BufferValue { Vec2i { p_width, p_height } } }, + { "Mouse position", E_TYPE::VEC2I, BufferValue { Vec2i { 0, 0 } } }, + { "Is perspective", E_TYPE::UINT, BufferValue { 1 } } } } ); - _renderGraph->addUniforms( - { "Color layout", { { "Colors", E_TYPE::COLOR4, StructUniformValue {} } }, 14, true } + _renderGraph->addGlobalData( + { "Color layout", 14, { { "Colors", E_TYPE::COLOR4, BufferValue {} } }, true } ); - _renderGraph->addUniforms( { "Models", - { { "Matrix model view", E_TYPE::MAT4F, StructUniformValue { MAT4F_ID } }, - { "Matrix normal", E_TYPE::MAT4F, StructUniformValue { MAT4F_ID } } }, - 13, - true } ); - - _renderGraph->addUniforms( { "Representations", - { { "Sphere radius fixed", E_TYPE::FLOAT, StructUniformValue {} }, - { "Sphere radius add", E_TYPE::FLOAT, StructUniformValue {} }, - { "Is sphere radius fixed", E_TYPE::UINT, StructUniformValue {} }, - { "Cylinder radius", E_TYPE::FLOAT, StructUniformValue {} }, - - { "Cylinder color blending", E_TYPE::UINT, StructUniformValue {} }, - { "Ribbon color blending", E_TYPE::UINT, StructUniformValue {} } }, - 12, - true } ); + _renderGraph->addGlobalData( { "Models", + 13, + { { "Matrix model view", E_TYPE::MAT4F, BufferValue { MAT4F_ID } }, + { "Matrix normal", E_TYPE::MAT4F, BufferValue { MAT4F_ID } } }, + true } ); + + _renderGraph->addGlobalData( { "Representations", + 12, + { { "Sphere radius fixed", E_TYPE::FLOAT, BufferValue {} }, + { "Sphere radius add", E_TYPE::FLOAT, BufferValue {} }, + { "Is sphere radius fixed", E_TYPE::UINT, BufferValue {} }, + { "Cylinder radius", E_TYPE::FLOAT, BufferValue {} }, + + { "Cylinder color blending", E_TYPE::UINT, BufferValue {} }, + { "Ribbon color blending", E_TYPE::UINT, BufferValue {} } }, + true } ); } // TODO: not the best way to do it. @@ -104,9 +104,9 @@ namespace VTX::Renderer blurX = _renderGraph->addPass( descPassBlur ); blurY = _renderGraph->addPass( descPassBlur ); - blurX->name = "BlurX"; - blurY->name = "BlurY"; - blurY->programs[ 0 ].uniforms[ 0 ].value = StructUniformValue { Vec2i( 0, 1 ) }; + blurX->name = "BlurX"; + blurY->name = "BlurY"; + blurY->programs[ 0 ].data[ 0 ].value = BufferValue { Vec2i( 0, 1 ) }; _renderGraph->addLink( geo, ssao, E_CHAN_OUT::COLOR_0, E_CHAN_IN::_0 ); _renderGraph->addLink( depth, ssao, E_CHAN_OUT::COLOR_0, E_CHAN_IN::_2 ); @@ -243,14 +243,14 @@ namespace VTX::Renderer ///////////////////// COMPUTE uint size = 10000; - ComputePass::Data bufferReadOnly { size * sizeof( Vec4f ), nullptr, 1 }; - ComputePass::Data bufferWriteOnly { size * sizeof( Vec4f ), nullptr, 2 }; - ComputePass::Data bufferReadWrite { size * sizeof( Vec4f ), nullptr, 3 }; + ComputePass::BufferDraw bufferReadOnly { size * sizeof( Vec4f ), nullptr, 1 }; + ComputePass::BufferDraw bufferWriteOnly { size * sizeof( Vec4f ), nullptr, 2 }; + ComputePass::BufferDraw bufferReadWrite { size * sizeof( Vec4f ), nullptr, 3 }; auto computePass = ComputePass { Program { "ComputeDebug", std::vector { "compute/debug.comp" }, - Uniforms { { { "Intensity", E_TYPE::UINT, StructUniformValue { size } } } } }, + BufferDataValues { { { "Intensity", E_TYPE::UINT, BufferValue { size } } } } }, { &bufferReadOnly, &bufferWriteOnly, &bufferReadWrite }, size }; @@ -392,9 +392,7 @@ namespace VTX::Renderer p_proxy.onAtomPositions += [ this, &p_proxy ]() { Cache::SphereCylinder & cacheSC = _cacheSpheresCylinders[ &p_proxy ]; - _context->setSub( - *p_proxy.atomPositions, "SpheresCylindersPositions", cacheSC.rangeSpheres.getFirst() - ); + _context->setSub( *p_proxy.atomPositions, "SpheresCylindersPositions", cacheSC.rangeSpheres.getFirst() ); }; // Colors. @@ -1481,22 +1479,23 @@ namespace VTX::Renderer int nearestAtom; }; - ComputePass::Data bufferSesGridData { gridSES.getCellCount() * sizeof( SESGridData ), nullptr, 0 }; - ComputePass::Data bufferAtomGridDataSorted { atomGridDataSorted.size() * sizeof( Range ), - atomGridDataSorted.data(), - 1 }; - ComputePass::Data bufferAtomIndexSorted { atomIndexSorted.size() * sizeof( uint ), - atomIndexSorted.data(), - 2 }; - ComputePass::Data bufferAtomPosition { atomPositionsVdW.size() * sizeof( Vec4f ), - atomPositionsVdW.data(), - 3 }; + ComputePass::BufferDraw bufferSesGridData { gridSES.getCellCount() * sizeof( SESGridData ), nullptr, 0 }; + ComputePass::BufferDraw bufferAtomGridDataSorted { atomGridDataSorted.size() * sizeof( Range ), + atomGridDataSorted.data(), + 1 }; + ComputePass::BufferDraw bufferAtomIndexSorted { atomIndexSorted.size() * sizeof( uint ), + atomIndexSorted.data(), + 2 }; + ComputePass::BufferDraw bufferAtomPosition { atomPositionsVdW.size() * sizeof( Vec4f ), + atomPositionsVdW.data(), + 3 }; const size_t sizeCreateSDF = bufferSesGridData.size + bufferAtomGridDataSorted.size + bufferAtomIndexSorted.size + bufferAtomPosition.size; auto computePass = ComputePass { - Program { "CreateSDF", std::vector { "ses/create_sdf.comp" }, Uniforms { /* TODO */ } }, + Program { + "CreateSDF", std::vector { "ses/create_sdf.comp" }, BufferDataValues { /* TODO */ } }, { &bufferSesGridData, &bufferAtomGridDataSorted, &bufferAtomIndexSorted, &bufferAtomPosition }, sizeCreateSDF };