From: Mikko Rasa Date: Sat, 19 Mar 2022 22:45:57 +0000 (+0200) Subject: Make StructureBuilder return const references to the pointers X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f6cb2d0e13b78007a5c57b06c270b7386130d4b4;p=libs%2Fgl.git Make StructureBuilder return const references to the pointers --- diff --git a/source/backends/vulkan/commands_backend.cpp b/source/backends/vulkan/commands_backend.cpp index 2698d431..fd95d152 100644 --- a/source/backends/vulkan/commands_backend.cpp +++ b/source/backends/vulkan/commands_backend.cpp @@ -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(1); - VkClearValue *&vk_clear_values = sb.add(FrameFormat::MAX_ATTACHMENTS); + VkRenderPassBeginInfo *const &begin_info = sb.add(1); + VkClearValue *const &vk_clear_values = sb.add(FrameFormat::MAX_ATTACHMENTS); begin_info->sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; begin_info->renderPass = handle_cast<::VkRenderPass>(render_pass); diff --git a/source/backends/vulkan/pipelinestate_backend.cpp b/source/backends/vulkan/pipelinestate_backend.cpp index 7deae24c..87e03242 100644 --- a/source/backends/vulkan/pipelinestate_backend.cpp +++ b/source/backends/vulkan/pipelinestate_backend.cpp @@ -160,16 +160,16 @@ void VulkanPipelineState::fill_creation_info(vector &buffer) const } StructureBuilder sb(buffer, 10); - VkGraphicsPipelineCreateInfo *&pipeline_info = sb.add(); - VkPipelineInputAssemblyStateCreateInfo *&input_assembly_info = sb.add(); - VkPipelineViewportStateCreateInfo *&viewport_info = sb.add(); - VkPipelineRasterizationStateCreateInfo *&raster_info = sb.add(); - VkPipelineMultisampleStateCreateInfo *&multisample_info = sb.add(); - VkPipelineDepthStencilStateCreateInfo *&depth_stencil_info = sb.add(); - VkPipelineColorBlendStateCreateInfo *&blend_info = sb.add(); - VkPipelineColorBlendAttachmentState *&blend_attachments = sb.add(n_color_attachments); - VkPipelineDynamicStateCreateInfo *&dynamic_info = sb.add(); - VkDynamicState *&dynamic_states = sb.add(2); + VkGraphicsPipelineCreateInfo *const &pipeline_info = sb.add(); + VkPipelineInputAssemblyStateCreateInfo *const &input_assembly_info = sb.add(); + VkPipelineViewportStateCreateInfo *const &viewport_info = sb.add(); + VkPipelineRasterizationStateCreateInfo *const &raster_info = sb.add(); + VkPipelineMultisampleStateCreateInfo *const &multisample_info = sb.add(); + VkPipelineDepthStencilStateCreateInfo *const &depth_stencil_info = sb.add(); + VkPipelineColorBlendStateCreateInfo *const &blend_info = sb.add(); + VkPipelineColorBlendAttachmentState *const &blend_attachments = sb.add(n_color_attachments); + VkPipelineDynamicStateCreateInfo *const &dynamic_info = sb.add(); + VkDynamicState *const &dynamic_states = sb.add(2); input_assembly_info->sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; input_assembly_info->topology = static_cast(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(n_writes); - VkDescriptorBufferInfo *&buffers = sb.add(n_buffers); - VkDescriptorImageInfo *&images = sb.add(n_images); + VkWriteDescriptorSet *const &writes = sb.add(n_writes); + VkDescriptorBufferInfo *const &buffers = sb.add(n_buffers); + VkDescriptorImageInfo *const &images = sb.add(n_images); VkWriteDescriptorSet *write_ptr = writes; VkDescriptorBufferInfo *buffer_ptr = buffers; diff --git a/source/backends/vulkan/program_backend.cpp b/source/backends/vulkan/program_backend.cpp index a2c40ad3..9402226b 100644 --- a/source/backends/vulkan/program_backend.cpp +++ b/source/backends/vulkan/program_backend.cpp @@ -59,11 +59,11 @@ void VulkanProgram::add_spirv_stages(const SpirVModule &mod, const map(n_stages); - char *&name_table = sb.add(entry_names_size); - VkSpecializationInfo *&spec_info = sb.add(); - VkSpecializationMapEntry *&spec_map = sb.add(spec_values.size()); - int *&spec_data = sb.add(spec_values.size()); + VkPipelineShaderStageCreateInfo *const &stage_infos = sb.add(n_stages); + char *const &name_table = sb.add(entry_names_size); + VkSpecializationInfo *const &spec_info = sb.add(); + VkSpecializationMapEntry *const &spec_map = sb.add(spec_values.size()); + int *const &spec_data = sb.add(spec_values.size()); unsigned i = 0; for(const SpirVModule::Constant &c: mod.get_spec_constants()) diff --git a/source/backends/vulkan/structurebuilder.cpp b/source/backends/vulkan/structurebuilder.cpp index 44a97c85..dd3d27ff 100644 --- a/source/backends/vulkan/structurebuilder.cpp +++ b/source/backends/vulkan/structurebuilder.cpp @@ -13,7 +13,7 @@ StructureBuilder::StructureBuilder(vector &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"); diff --git a/source/backends/vulkan/structurebuilder.h b/source/backends/vulkan/structurebuilder.h index f59153fd..1cb1e8ce 100644 --- a/source/backends/vulkan/structurebuilder.h +++ b/source/backends/vulkan/structurebuilder.h @@ -23,11 +23,11 @@ public: StructureBuilder(std::vector &, unsigned); template - T *&add(std::size_t count = 1) - { return reinterpret_cast(add(sizeof(T)*count, alignof(T))); } + T *const &add(std::size_t count = 1) + { return reinterpret_cast(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 diff --git a/source/backends/vulkan/vertexsetup_backend.cpp b/source/backends/vulkan/vertexsetup_backend.cpp index 9579fd40..1ac823b5 100644 --- a/source/backends/vulkan/vertexsetup_backend.cpp +++ b/source/backends/vulkan/vertexsetup_backend.cpp @@ -28,9 +28,9 @@ void VulkanVertexSetup::update(unsigned) const n_attribs += !is_padding(a); StructureBuilder sb(creation_info, 3); - VkPipelineVertexInputStateCreateInfo *&input_state = sb.add(); - VkVertexInputBindingDescription *&bindings = sb.add(n_bindings); - VkVertexInputAttributeDescription *&attribs = sb.add(n_attribs); + VkPipelineVertexInputStateCreateInfo *const &input_state = sb.add(); + VkVertexInputBindingDescription *const &bindings = sb.add(n_bindings); + VkVertexInputAttributeDescription *const &attribs = sb.add(n_attribs); bindings[0].binding = 0; bindings[0].stride = self.vertex_format.stride();