Skip to content

Commit

Permalink
layers: Use GetCurrentPipeline where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Jun 21, 2024
1 parent ac936eb commit b7c5f45
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 55 deletions.
7 changes: 2 additions & 5 deletions layers/best_practices/bp_drawdispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ void BestPractices::RecordCmdDrawType(VkCommandBuffer cmd_buffer, uint32_t draw_
cb_state->render_pass_state.drawTouchAttachments = false;
}

const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
const auto* pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
const auto* pipeline_state = cb_state->GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS);
if (pipeline_state && pipeline_state->vertex_input_state && !pipeline_state->vertex_input_state->binding_descriptions.empty()) {
cb_state->uses_vertex_buffer = true;
}
Expand Down Expand Up @@ -224,9 +223,7 @@ bool BestPractices::ValidateIndexBufferArm(const bp_state::CommandBuffer& cmd_st
const void* ib_mem = ib_mem_state->p_driver_data;
bool primitive_restart_enable = false;

const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
const auto& last_bound = cmd_state.lastBound[lv_bind_point];
const auto* pipeline_state = last_bound.pipeline_state;
const auto* pipeline_state = cmd_state.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS);
ASSERT_AND_RETURN_SKIP(pipeline_state);

const auto* ia_state = pipeline_state->InputAssemblyState();
Expand Down
36 changes: 15 additions & 21 deletions layers/core_checks/cc_cmd_buffer_dynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,10 @@ bool CoreChecks::ValidateDynamicStateIsSet(const CBDynamicFlags& state_status_cb

// Makes sure the vkCmdSet* call was called correctly prior to a draw
// deprecated for ValidateGraphicsDynamicStateSetStatus()
bool CoreChecks::ValidateGraphicsDynamicStatePipelineSetStatus(const LastBound& last_bound_state,
bool CoreChecks::ValidateGraphicsDynamicStatePipelineSetStatus(const LastBound& last_bound_state, const vvl::Pipeline& pipeline,
const vvl::DrawDispatchVuid& vuid) const {
bool skip = false;
const vvl::CommandBuffer& cb_state = last_bound_state.cb_state;
const vvl::Pipeline& pipeline = *last_bound_state.pipeline_state;
const Location loc = vuid.loc(); // because we need to pass it around a lot
const LogObjectList objlist(cb_state.Handle(), pipeline.Handle());

Expand Down Expand Up @@ -480,10 +479,10 @@ bool CoreChecks::ValidateGraphicsDynamicStatePipelineSetStatus(const LastBound&
return skip;
}

bool CoreChecks::ValidateGraphicsDynamicStateValue(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const {
bool CoreChecks::ValidateGraphicsDynamicStateValue(const LastBound& last_bound_state, const vvl::Pipeline& pipeline,
const vvl::DrawDispatchVuid& vuid) const {
bool skip = false;
const vvl::CommandBuffer& cb_state = last_bound_state.cb_state;
const vvl::Pipeline& pipeline = *last_bound_state.pipeline_state;
const LogObjectList objlist(cb_state.Handle(), pipeline.Handle());

// vkCmdSetDiscardRectangleEXT needs to be set on each rectangle
Expand Down Expand Up @@ -616,14 +615,10 @@ bool CoreChecks::ValidateGraphicsDynamicStateValue(const LastBound& last_bound_s
}

if (!pipeline.IsDynamic(CB_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT) &&
pipeline.IsDynamic(CB_DYNAMIC_STATE_RASTERIZATION_SAMPLES_EXT) && pipeline.MultisampleState()) {
const auto sample_locations =
vku::FindStructInPNextChain<VkPipelineSampleLocationsStateCreateInfoEXT>(pipeline.MultisampleState()->pNext);
if (sample_locations &&
((!pipeline.IsDynamic(CB_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE_EXT) && sample_locations->sampleLocationsEnable) ||
(pipeline.IsDynamic(CB_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE_EXT) &&
cb_state.IsDynamicStateSet(CB_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE_EXT) &&
cb_state.dynamic_state_value.sample_locations_enable))) {
pipeline.IsDynamic(CB_DYNAMIC_STATE_RASTERIZATION_SAMPLES_EXT) && pipeline.MultisampleState() &&
last_bound_state.IsSampleLocationsEnable()) {
if (const auto sample_locations =
vku::FindStructInPNextChain<VkPipelineSampleLocationsStateCreateInfoEXT>(pipeline.MultisampleState()->pNext)) {
VkMultisamplePropertiesEXT multisample_prop = vku::InitStructHelper();
DispatchGetPhysicalDeviceMultisamplePropertiesEXT(physical_device, cb_state.dynamic_state_value.rasterization_samples,
&multisample_prop);
Expand Down Expand Up @@ -860,11 +855,10 @@ bool CoreChecks::ValidateGraphicsDynamicStateValue(const LastBound& last_bound_s
return skip;
}

bool CoreChecks::ValidateGraphicsDynamicStateViewportScissor(const LastBound& last_bound_state,
bool CoreChecks::ValidateGraphicsDynamicStateViewportScissor(const LastBound& last_bound_state, const vvl::Pipeline& pipeline,
const vvl::DrawDispatchVuid& vuid) const {
bool skip = false;
const vvl::CommandBuffer& cb_state = last_bound_state.cb_state;
const vvl::Pipeline& pipeline = *last_bound_state.pipeline_state;
const LogObjectList objlist(cb_state.Handle(), pipeline.Handle());

// If Viewport or scissors are dynamic, verify that dynamic count matches PSO count.
Expand Down Expand Up @@ -961,7 +955,7 @@ bool CoreChecks::ValidateDrawDynamicState(const LastBound& last_bound_state, con

const auto pipeline_state = last_bound_state.pipeline_state;
if (pipeline_state) {
skip |= ValidateDrawDynamicStatePipeline(last_bound_state, vuid);
skip |= ValidateDrawDynamicStatePipeline(last_bound_state, *pipeline_state, vuid);
} else {
skip |= ValidateDrawDynamicStateShaderObject(last_bound_state, vuid);
}
Expand Down Expand Up @@ -1181,14 +1175,15 @@ bool CoreChecks::ValidateDrawDynamicState(const LastBound& last_bound_state, con
return skip;
}

bool CoreChecks::ValidateDrawDynamicStatePipeline(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const {
bool CoreChecks::ValidateDrawDynamicStatePipeline(const LastBound& last_bound_state, const vvl::Pipeline& pipeline,
const vvl::DrawDispatchVuid& vuid) const {
bool skip = false;
skip |= ValidateGraphicsDynamicStatePipelineSetStatus(last_bound_state, vuid);
skip |= ValidateGraphicsDynamicStatePipelineSetStatus(last_bound_state, pipeline, vuid);
// Dynamic state was not set, will produce garbage when trying to read to values
if (skip) return skip;
// Once we know for sure state was set, check value is valid
skip |= ValidateGraphicsDynamicStateValue(last_bound_state, vuid);
skip |= ValidateGraphicsDynamicStateViewportScissor(last_bound_state, vuid);
skip |= ValidateGraphicsDynamicStateValue(last_bound_state, pipeline, vuid);
skip |= ValidateGraphicsDynamicStateViewportScissor(last_bound_state, pipeline, vuid);
return skip;
}

Expand Down Expand Up @@ -1671,11 +1666,10 @@ bool CoreChecks::ValidateDrawDynamicStateShaderObject(const LastBound& last_boun
return skip;
}

bool CoreChecks::ValidateTraceRaysDynamicStateSetStatus(const LastBound& last_bound_state,
bool CoreChecks::ValidateTraceRaysDynamicStateSetStatus(const LastBound& last_bound_state, const vvl::Pipeline& pipeline,
const vvl::DrawDispatchVuid& vuid) const {
bool skip = false;
const vvl::CommandBuffer& cb_state = last_bound_state.cb_state;
const vvl::Pipeline& pipeline = *last_bound_state.pipeline_state;

if (pipeline.IsDynamic(CB_DYNAMIC_STATE_RAY_TRACING_PIPELINE_STACK_SIZE_KHR)) {
if (!cb_state.dynamic_state_status.rtx_stack_size_cb) {
Expand Down
28 changes: 13 additions & 15 deletions layers/core_checks/cc_drawdispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool CoreChecks::ValidateCmdDrawInstance(const vvl::CommandBuffer &cb_state, uin
const Location &loc) const {
bool skip = false;
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(loc.function);
const auto *pipeline_state = cb_state.lastBound[VK_PIPELINE_BIND_POINT_GRAPHICS].pipeline_state;
const auto *pipeline_state = cb_state.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS);

// Verify maxMultiviewInstanceIndex
if (cb_state.activeRenderPass && enabled_features.multiview &&
Expand Down Expand Up @@ -105,7 +105,7 @@ bool CoreChecks::ValidateVTGShaderStages(const vvl::CommandBuffer &cb_state, con
bool skip = false;
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(loc.function);

const auto *pipeline_state = cb_state.lastBound[VK_PIPELINE_BIND_POINT_GRAPHICS].pipeline_state;
const auto *pipeline_state = cb_state.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS);
if (pipeline_state && pipeline_state->active_shaders & (VK_SHADER_STAGE_TASK_BIT_EXT | VK_SHADER_STAGE_MESH_BIT_EXT)) {
skip |= LogError(
vuid.invalid_mesh_shader_stages_06481, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), loc,
Expand All @@ -120,7 +120,7 @@ bool CoreChecks::ValidateMeshShaderStage(const vvl::CommandBuffer &cb_state, con
bool skip = false;
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(loc.function);

const auto *pipeline_state = cb_state.lastBound[VK_PIPELINE_BIND_POINT_GRAPHICS].pipeline_state;
const auto *pipeline_state = cb_state.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS);
if (pipeline_state && !(pipeline_state->active_shaders & VK_SHADER_STAGE_MESH_BIT_EXT)) {
skip |= LogError(vuid.missing_mesh_shader_stages_07080, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), loc,
"The current pipeline bound to VK_PIPELINE_BIND_POINT_GRAPHICS must contain a shader stage using the "
Expand Down Expand Up @@ -846,13 +846,10 @@ bool CoreChecks::ValidateCmdTraceRaysKHR(const Location &loc, const vvl::Command
const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable) const {
bool skip = false;
const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
const vvl::Pipeline *pipeline_state = cb_state.lastBound[lv_bind_point].pipeline_state;
const vvl::Pipeline *pipeline_state = cb_state.GetCurrentPipeline(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
if (!pipeline_state) return skip; // possible wasn't bound correctly, check caught elsewhere
const bool is_indirect = loc.function == Func::vkCmdTraceRaysIndirectKHR;

if (!pipeline_state || (pipeline_state && !pipeline_state->VkHandle())) {
return skip;
}
if (pHitShaderBindingTable) {
const Location table_loc = loc.dot(Field::pHitShaderBindingTable);
if (pipeline_state->create_flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_INTERSECTION_SHADERS_BIT_KHR) {
Expand Down Expand Up @@ -919,14 +916,13 @@ bool CoreChecks::ValidateCmdTraceRaysKHR(const Location &loc, const vvl::Command
skip |= ValidateRaytracingShaderBindingTable(cb_state.VkHandle(), table_loc, vuid_single_device_memory,
vuid_binding_table_flag, *pMissShaderBindingTable);
if (pMissShaderBindingTable->deviceAddress == 0) {
if (const auto *pipe = cb_state.lastBound[lv_bind_point].pipeline_state;
pipe && pipe->create_flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_MISS_SHADERS_BIT_KHR) {
if (pipeline_state->create_flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_MISS_SHADERS_BIT_KHR) {
const char *vuid =
is_indirect ? "VUID-vkCmdTraceRaysIndirectKHR-flags-03511" : "VUID-vkCmdTraceRaysKHR-flags-03511";
skip |=
LogError(vuid, cb_state.Handle(), loc.dot(Field::pMissShaderBindingTable),
"is 0 but last bound ray tracing pipeline (%s) was created with flags (%s).",
FormatHandle(pipe->Handle()).c_str(), string_VkPipelineCreateFlags2KHR(pipe->create_flags).c_str());
skip |= LogError(vuid, cb_state.Handle(), loc.dot(Field::pMissShaderBindingTable),
"is 0 but last bound ray tracing pipeline (%s) was created with flags (%s).",
FormatHandle(pipeline_state->Handle()).c_str(),
string_VkPipelineCreateFlags2KHR(pipeline_state->create_flags).c_str());
}
}
}
Expand Down Expand Up @@ -1543,7 +1539,9 @@ bool CoreChecks::ValidateActionState(const vvl::CommandBuffer &cb_state, const V
}

} else if (bind_point == VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR) {
skip |= ValidateTraceRaysDynamicStateSetStatus(last_bound_state, vuid);
if (pipeline) {
skip |= ValidateTraceRaysDynamicStateSetStatus(last_bound_state, *pipeline, vuid);
}
if (!cb_state.unprotected) {
skip |= LogError(vuid.ray_query_protected_cb_03635, cb_state.GetObjectList(bind_point), loc,
"called in a protected command buffer.");
Expand Down
5 changes: 2 additions & 3 deletions layers/core_checks/cc_pipeline_compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ bool CoreChecks::PreCallValidateCreateComputePipelines(VkDevice device, VkPipeli
skip |= ValidateDeviceQueueSupport(error_obj.location);
for (uint32_t i = 0; i < count; i++) {
const vvl::Pipeline *pipeline = pipeline_states[i].get();
if (!pipeline) {
continue;
}
ASSERT_AND_CONTINUE(pipeline);

const Location create_info_loc = error_obj.location.dot(Field::pCreateInfos, i);
const Location stage_info = create_info_loc.dot(Field::stage);
const auto &stage_state = pipeline->stage_states[0];
Expand Down
10 changes: 4 additions & 6 deletions layers/core_checks/cc_pipeline_ray_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ bool CoreChecks::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkP
skip |= ValidateDeviceQueueSupport(error_obj.location);
for (uint32_t i = 0; i < count; i++) {
const vvl::Pipeline *pipeline = pipeline_states[i].get();
if (!pipeline) {
continue;
}
ASSERT_AND_CONTINUE(pipeline);

const Location create_info_loc = error_obj.location.dot(Field::pCreateInfos, i);
const auto &create_info = pipeline->RayTracingCreateInfo();
if (pipeline->create_flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
Expand Down Expand Up @@ -226,9 +225,8 @@ bool CoreChecks::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, Vk

for (uint32_t i = 0; i < count; i++) {
const vvl::Pipeline *pipeline = pipeline_states[i].get();
if (!pipeline) {
continue;
}
ASSERT_AND_CONTINUE(pipeline);

const Location create_info_loc = error_obj.location.dot(Field::pCreateInfos, i);
const auto &create_info = pipeline->RayTracingCreateInfo();
if (pipeline->create_flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
Expand Down
15 changes: 10 additions & 5 deletions layers/core_checks/core_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,22 @@ class CoreChecks : public ValidationStateTracker {
bool ValidateDynamicStateIsSet(const LastBound& last_bound_state, const CBDynamicFlags& state_status_cb,
CBDynamicState dynamic_state, const vvl::DrawDispatchVuid& vuid) const;
bool ValidateGraphicsDynamicStateSetStatus(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const;
bool ValidateGraphicsDynamicStatePipelineSetStatus(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const;
bool ValidateGraphicsDynamicStateValue(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const;
bool ValidateGraphicsDynamicStateViewportScissor(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const;
bool ValidateGraphicsDynamicStatePipelineSetStatus(const LastBound& last_bound_state, const vvl::Pipeline& pipeline,
const vvl::DrawDispatchVuid& vuid) const;
bool ValidateGraphicsDynamicStateValue(const LastBound& last_bound_state, const vvl::Pipeline& pipeline,
const vvl::DrawDispatchVuid& vuid) const;
bool ValidateGraphicsDynamicStateViewportScissor(const LastBound& last_bound_state, const vvl::Pipeline& pipeline,
const vvl::DrawDispatchVuid& vuid) const;
bool ValidateDrawDynamicState(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const;
bool ValidateDrawDynamicStatePipeline(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const;
bool ValidateDrawDynamicStatePipeline(const LastBound& last_bound_state, const vvl::Pipeline& pipeline,
const vvl::DrawDispatchVuid& vuid) const;
bool ValidateDrawDynamicStateShaderObject(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const;
bool ValidateDrawRenderingAttachmentLocation(const vvl::CommandBuffer& cb_state, const vvl::Pipeline& pipeline_state,
const vvl::DrawDispatchVuid& vuid) const;
bool ValidateDrawRenderingInputAttachmentIndex(const vvl::CommandBuffer& cb_state, const vvl::Pipeline& pipeline_state,
const vvl::DrawDispatchVuid& vuid) const;
bool ValidateTraceRaysDynamicStateSetStatus(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const;
bool ValidateTraceRaysDynamicStateSetStatus(const LastBound& last_bound_state, const vvl::Pipeline& pipeline,
const vvl::DrawDispatchVuid& vuid) const;
bool ValidateDrawPrimitivesGeneratedQuery(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const;
bool ValidateDrawProtectedMemory(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const;
bool ValidateDrawDualSourceBlend(const LastBound& last_bound_state, const vvl::DrawDispatchVuid& vuid) const;
Expand Down

0 comments on commit b7c5f45

Please sign in to comment.