From be4a81d56a0be26f1d9dc61b733eb997b50e8813 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 27 Apr 2016 14:00:44 +1200 Subject: [PATCH] layers: Emit safe_*::ptr() members to eliminate some cast noise These casts were annoying noise, and uncheckable. Move them into the generator where we know the one type that makes sense. Drop spurious reinterpret_cast of stage create info to itself -- it's all raw types once the root pCreateInfo is unwrapped. Signed-off-by: Chris Forbes --- layers/core_validation.cpp | 7 +++---- layers/descriptor_sets.h | 6 +++--- vk_helper.py | 2 ++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index 8d4a387..b5b911f 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -2501,7 +2501,7 @@ static bool validate_pipeline_shader_stage(layer_data *dev_data, VkPipelineShade // Validate that the shaders used by the given pipeline and store the active_slots // that are actually used by the pipeline into pPipeline->active_slots static bool validate_and_capture_pipeline_shader_state(layer_data *my_data, PIPELINE_NODE *pPipeline) { - auto pCreateInfo = reinterpret_cast(&pPipeline->graphicsPipelineCI); + auto pCreateInfo = pPipeline->graphicsPipelineCI.ptr(); int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT); int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT); @@ -2515,8 +2515,7 @@ static bool validate_and_capture_pipeline_shader_state(layer_data *my_data, PIPE auto pipelineLayout = pCreateInfo->layout != VK_NULL_HANDLE ? &my_data->pipelineLayoutMap[pCreateInfo->layout] : nullptr; for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) { - VkPipelineShaderStageCreateInfo const *pStage = - reinterpret_cast(&pCreateInfo->pStages[i]); + auto pStage = &pCreateInfo->pStages[i]; auto stage_id = get_shader_stage_id(pStage->stage); pass &= validate_pipeline_shader_stage(my_data, pStage, pPipeline, pipelineLayout, &shaders[stage_id], &entrypoints[stage_id]); @@ -2562,7 +2561,7 @@ static bool validate_and_capture_pipeline_shader_state(layer_data *my_data, PIPE } static bool validate_compute_pipeline(layer_data *my_data, PIPELINE_NODE *pPipeline) { - auto pCreateInfo = reinterpret_cast(&pPipeline->computePipelineCI); + auto pCreateInfo = pPipeline->computePipelineCI.ptr(); auto pipelineLayout = pCreateInfo->layout != VK_NULL_HANDLE ? &my_data->pipelineLayoutMap[pCreateInfo->layout] : nullptr; diff --git a/layers/descriptor_sets.h b/layers/descriptor_sets.h index 05e2893..ecc6601 100644 --- a/layers/descriptor_sets.h +++ b/layers/descriptor_sets.h @@ -163,12 +163,12 @@ DescriptorSetLayout::~DescriptorSetLayout() { VkDescriptorSetLayoutBinding const *DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromBinding(const uint32_t binding) { if (!binding_to_index_map_.count(binding)) return nullptr; - return reinterpret_cast(bindings_[binding_to_index_map_[binding]]); + return bindings_[binding_to_index_map_[binding]]->ptr(); } VkDescriptorSetLayoutBinding const *DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromIndex(const uint32_t index) { if (index >= bindings_.size()) return nullptr; - return reinterpret_cast(bindings_[index]); + return bindings_[index]->ptr(); } // Return descriptorCount for given binding, 0 if index is unavailable uint32_t DescriptorSetLayout::GetDescriptorCountFromBinding(const uint32_t binding) { @@ -271,4 +271,4 @@ bool DescriptorSetLayout::IsCompatible(DescriptorSetLayout *rh_ds_layout, string } return true; } -#endif // CORE_VALIDATION_DESCRIPTOR_SETS_H_ \ No newline at end of file +#endif // CORE_VALIDATION_DESCRIPTOR_SETS_H_ diff --git a/vk_helper.py b/vk_helper.py index c9ee9cd..a4e7948 100755 --- a/vk_helper.py +++ b/vk_helper.py @@ -1602,6 +1602,8 @@ class StructWrapperGen: ss_decls.append(" %s();" % (ss_name)) ss_decls.append(" ~%s();" % (ss_name)) ss_decls.append(" void initialize(const %s* pInStruct);" % (s)) + ss_decls.append(" %s *ptr() { return reinterpret_cast<%s *>(this); }" % (s, s)) + ss_decls.append(" %s const *ptr() const { return reinterpret_cast<%s const *>(this); }" % (s, s)) ss_decls.append("};") if s in ifdef_dict: ss_decls.append('#endif') -- 2.7.4