layers: Emit safe_*::ptr() members to eliminate some cast noise
authorChris Forbes <chrisforbes@google.com>
Wed, 27 Apr 2016 02:00:44 +0000 (14:00 +1200)
committerTobin Ehlis <tobine@google.com>
Wed, 27 Apr 2016 14:46:20 +0000 (08:46 -0600)
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>
layers/core_validation.cpp
layers/descriptor_sets.h
vk_helper.py

index 8d4a387..b5b911f 100644 (file)
@@ -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;
 
index 05e2893..ecc6601 100644 (file)
@@ -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_
index c9ee9cd..a4e7948 100755 (executable)
@@ -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')