diff options
| author | Chris Forbes <chrisforbes@google.com> | 2016-04-27 14:00:44 +1200 |
|---|---|---|
| committer | Tobin Ehlis <tobine@google.com> | 2016-04-27 08:46:20 -0600 |
| commit | be4a81d56a0be26f1d9dc61b733eb997b50e8813 (patch) | |
| tree | 96540877a56693ae3896615176294a293d84c90b | |
| parent | 0fdb77e86a2673e042fa809171472aea4b6ac2da (diff) | |
| download | usermoji-be4a81d56a0be26f1d9dc61b733eb997b50e8813.tar.xz | |
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 <chrisforbes@google.com>
| -rw-r--r-- | layers/core_validation.cpp | 7 | ||||
| -rw-r--r-- | layers/descriptor_sets.h | 6 | ||||
| -rwxr-xr-x | vk_helper.py | 2 |
3 files changed, 8 insertions, 7 deletions
diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index 8d4a3871..b5b911fe 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<VkGraphicsPipelineCreateInfo const *>(&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<VkPipelineShaderStageCreateInfo const *>(&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<VkComputePipelineCreateInfo const *>(&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 05e28935..ecc66017 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<VkDescriptorSetLayoutBinding const *>(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<VkDescriptorSetLayoutBinding const *>(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 c9ee9cdb..a4e79488 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') |
