]> git.tdb.fi Git - libs/gl.git/commitdiff
Make StructureBuilder return const references to the pointers
authorMikko Rasa <tdb@tdb.fi>
Sat, 19 Mar 2022 22:45:57 +0000 (00:45 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 19 Mar 2022 22:45:57 +0000 (00:45 +0200)
source/backends/vulkan/commands_backend.cpp
source/backends/vulkan/pipelinestate_backend.cpp
source/backends/vulkan/program_backend.cpp
source/backends/vulkan/structurebuilder.cpp
source/backends/vulkan/structurebuilder.h
source/backends/vulkan/vertexsetup_backend.cpp

index 2698d43173a819bcf153ee2488e1502f1979707a..fd95d152925e6fed3cb2866a473a0f1f2338491b 100644 (file)
@@ -110,8 +110,8 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value
        begin_buffer(render_pass);
 
        StructureBuilder sb(pass_begin_info, 2);
-       VkRenderPassBeginInfo *&begin_info = sb.add<VkRenderPassBeginInfo>(1);
-       VkClearValue *&vk_clear_values = sb.add<VkClearValue>(FrameFormat::MAX_ATTACHMENTS);
+       VkRenderPassBeginInfo *const &begin_info = sb.add<VkRenderPassBeginInfo>(1);
+       VkClearValue *const &vk_clear_values = sb.add<VkClearValue>(FrameFormat::MAX_ATTACHMENTS);
 
        begin_info->sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
        begin_info->renderPass = handle_cast<::VkRenderPass>(render_pass);
index 7deae24c9b09b59ada978489feb1bdfd6b1637a9..87e03242d329ae90fb66d5346cefe9a4af4e195e 100644 (file)
@@ -160,16 +160,16 @@ void VulkanPipelineState::fill_creation_info(vector<char> &buffer) const
        }
 
        StructureBuilder sb(buffer, 10);
-       VkGraphicsPipelineCreateInfo *&pipeline_info = sb.add<VkGraphicsPipelineCreateInfo>();
-       VkPipelineInputAssemblyStateCreateInfo *&input_assembly_info = sb.add<VkPipelineInputAssemblyStateCreateInfo>();
-       VkPipelineViewportStateCreateInfo *&viewport_info = sb.add<VkPipelineViewportStateCreateInfo>();
-       VkPipelineRasterizationStateCreateInfo *&raster_info = sb.add<VkPipelineRasterizationStateCreateInfo>();
-       VkPipelineMultisampleStateCreateInfo *&multisample_info = sb.add<VkPipelineMultisampleStateCreateInfo>();
-       VkPipelineDepthStencilStateCreateInfo *&depth_stencil_info = sb.add<VkPipelineDepthStencilStateCreateInfo>();
-       VkPipelineColorBlendStateCreateInfo *&blend_info = sb.add<VkPipelineColorBlendStateCreateInfo>();
-       VkPipelineColorBlendAttachmentState *&blend_attachments = sb.add<VkPipelineColorBlendAttachmentState>(n_color_attachments);
-       VkPipelineDynamicStateCreateInfo *&dynamic_info = sb.add<VkPipelineDynamicStateCreateInfo>();
-       VkDynamicState *&dynamic_states = sb.add<VkDynamicState>(2);
+       VkGraphicsPipelineCreateInfo *const &pipeline_info = sb.add<VkGraphicsPipelineCreateInfo>();
+       VkPipelineInputAssemblyStateCreateInfo *const &input_assembly_info = sb.add<VkPipelineInputAssemblyStateCreateInfo>();
+       VkPipelineViewportStateCreateInfo *const &viewport_info = sb.add<VkPipelineViewportStateCreateInfo>();
+       VkPipelineRasterizationStateCreateInfo *const &raster_info = sb.add<VkPipelineRasterizationStateCreateInfo>();
+       VkPipelineMultisampleStateCreateInfo *const &multisample_info = sb.add<VkPipelineMultisampleStateCreateInfo>();
+       VkPipelineDepthStencilStateCreateInfo *const &depth_stencil_info = sb.add<VkPipelineDepthStencilStateCreateInfo>();
+       VkPipelineColorBlendStateCreateInfo *const &blend_info = sb.add<VkPipelineColorBlendStateCreateInfo>();
+       VkPipelineColorBlendAttachmentState *const &blend_attachments = sb.add<VkPipelineColorBlendAttachmentState>(n_color_attachments);
+       VkPipelineDynamicStateCreateInfo *const &dynamic_info = sb.add<VkPipelineDynamicStateCreateInfo>();
+       VkDynamicState *const &dynamic_states = sb.add<VkDynamicState>(2);
 
        input_assembly_info->sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
        input_assembly_info->topology = static_cast<VkPrimitiveTopology>(get_vulkan_primitive_type(self.primitive_type));
@@ -336,9 +336,9 @@ unsigned VulkanPipelineState::fill_descriptor_writes(unsigned index, unsigned fr
        unsigned n_writes = n_buffers+n_images;
 
        StructureBuilder sb(buffer, 3);
-       VkWriteDescriptorSet *&writes = sb.add<VkWriteDescriptorSet>(n_writes);
-       VkDescriptorBufferInfo *&buffers = sb.add<VkDescriptorBufferInfo>(n_buffers);
-       VkDescriptorImageInfo *&images = sb.add<VkDescriptorImageInfo>(n_images);
+       VkWriteDescriptorSet *const &writes = sb.add<VkWriteDescriptorSet>(n_writes);
+       VkDescriptorBufferInfo *const &buffers = sb.add<VkDescriptorBufferInfo>(n_buffers);
+       VkDescriptorImageInfo *const &images = sb.add<VkDescriptorImageInfo>(n_images);
 
        VkWriteDescriptorSet *write_ptr = writes;
        VkDescriptorBufferInfo *buffer_ptr = buffers;
index a2c40ad3fec3feb0492a49f8f3296ed8d6c1eb2b..9402226b1e68917bf00273bd10ae31ff519d3f4c 100644 (file)
@@ -59,11 +59,11 @@ void VulkanProgram::add_spirv_stages(const SpirVModule &mod, const map<string, i
                entry_names_size += e.name.size()+1;
 
        StructureBuilder sb(creation_info, 5);
-       VkPipelineShaderStageCreateInfo *&stage_infos = sb.add<VkPipelineShaderStageCreateInfo>(n_stages);
-       char *&name_table = sb.add<char>(entry_names_size);
-       VkSpecializationInfo *&spec_info = sb.add<VkSpecializationInfo>();
-       VkSpecializationMapEntry *&spec_map = sb.add<VkSpecializationMapEntry>(spec_values.size());
-       int *&spec_data = sb.add<int>(spec_values.size());
+       VkPipelineShaderStageCreateInfo *const &stage_infos = sb.add<VkPipelineShaderStageCreateInfo>(n_stages);
+       char *const &name_table = sb.add<char>(entry_names_size);
+       VkSpecializationInfo *const &spec_info = sb.add<VkSpecializationInfo>();
+       VkSpecializationMapEntry *const &spec_map = sb.add<VkSpecializationMapEntry>(spec_values.size());
+       int *const &spec_data = sb.add<int>(spec_values.size());
 
        unsigned i = 0;
        for(const SpirVModule::Constant &c: mod.get_spec_constants())
index 44a97c85992db2436797c78bc8a3631750ff1100..dd3d27ff18e521a67d5d818f7d6d26c4e354e79c 100644 (file)
@@ -13,7 +13,7 @@ StructureBuilder::StructureBuilder(vector<char> &s, unsigned max_parts):
        parts.reserve(max_parts);
 }
 
-void *&StructureBuilder::add(std::size_t size, std::size_t align)
+void *const &StructureBuilder::add(std::size_t size, std::size_t align)
 {
        if(parts.size()>=parts.capacity())
                throw invalid_operation("StructureBuilder::add");
index f59153fd7ca5f0b4037163dd385e6595e42fa279..1cb1e8ce54b39dcce23407b423437b3c6ee00469 100644 (file)
@@ -23,11 +23,11 @@ public:
        StructureBuilder(std::vector<char> &, unsigned);
 
        template<typename T>
-       T *&add(std::size_t count = 1)
-       { return reinterpret_cast<T *&>(add(sizeof(T)*count, alignof(T))); }
+       T *const &add(std::size_t count = 1)
+       { return reinterpret_cast<T *const &>(add(sizeof(T)*count, alignof(T))); }
 
 private:
-       void *&add(std::size_t, std::size_t);
+       void *const &add(std::size_t, std::size_t);
 };
 
 } // namespace GL
index 9579fd402af5eca57e21a279072822082253cdc0..1ac823b55742559031c7dacd27b0ff1d98feda2e 100644 (file)
@@ -28,9 +28,9 @@ void VulkanVertexSetup::update(unsigned) const
                n_attribs += !is_padding(a);
 
        StructureBuilder sb(creation_info, 3);
-       VkPipelineVertexInputStateCreateInfo *&input_state = sb.add<VkPipelineVertexInputStateCreateInfo>();
-       VkVertexInputBindingDescription *&bindings = sb.add<VkVertexInputBindingDescription>(n_bindings);
-       VkVertexInputAttributeDescription *&attribs = sb.add<VkVertexInputAttributeDescription>(n_attribs);
+       VkPipelineVertexInputStateCreateInfo *const &input_state = sb.add<VkPipelineVertexInputStateCreateInfo>();
+       VkVertexInputBindingDescription *const &bindings = sb.add<VkVertexInputBindingDescription>(n_bindings);
+       VkVertexInputAttributeDescription *const &attribs = sb.add<VkVertexInputAttributeDescription>(n_attribs);
 
        bindings[0].binding = 0;
        bindings[0].stride = self.vertex_format.stride();