Skip to content

Commit

Permalink
layers: Improve profile error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Jan 10, 2025
1 parent 24ef01e commit ddb902c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 22 deletions.
61 changes: 44 additions & 17 deletions layers/core_checks/cc_video.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2022-2024 The Khronos Group Inc.
* Copyright (c) 2022-2024 RasterGrid Kft.
/* Copyright (c) 2022-2025 The Khronos Group Inc.
* Copyright (c) 2022-2025 RasterGrid Kft.
* Modifications Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -108,12 +108,33 @@ bool CoreChecks::IsBufferCompatibleWithVideoSession(const vvl::Buffer &buffer_st
buffer_state.supported_video_profiles.find(vs_state.profile) != buffer_state.supported_video_profiles.end();
}

bool CoreChecks::IsImageCompatibleWithVideoSession(const vvl::Image &image_state, const vvl::VideoSession &vs_state) const {
bool CoreChecks::IsImageCompatibleWithVideoSession(const vvl::Image &image_state, const vvl::VideoSession &vs_state,
std::string &error_message) const {
std::ostringstream ss;
bool is_compatible = false;
if (image_state.create_info.flags & VK_IMAGE_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR) {
return IsSupportedVideoFormat(image_state.create_info, vs_state.create_info.pVideoProfile);
is_compatible = IsSupportedVideoFormat(image_state.create_info, vs_state.create_info.pVideoProfile);
} else {
return image_state.supported_video_profiles.find(vs_state.profile) != image_state.supported_video_profiles.end();
is_compatible = image_state.supported_video_profiles.find(vs_state.profile) != image_state.supported_video_profiles.end();
}

if (!is_compatible) {
ss << "The image was create ";
if (image_state.create_info.flags & VK_IMAGE_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR) {
ss << "with ";
} else {
ss << "without ";
}
ss << "VK_IMAGE_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR and could not find an profile for the image supported with the "
"profile:\n";
if (image_state.create_info.flags & VK_IMAGE_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR) {
ss << string_VkVideoProfileInfoKHR(*vs_state.create_info.pVideoProfile);
} else {
ss << vs_state.profile->Describe();
}
error_message = ss.str();
}
return is_compatible;
}

void CoreChecks::EnqueueVerifyVideoSessionInitialized(vvl::CommandBuffer &cb_state, vvl::VideoSession &vs_state,
Expand Down Expand Up @@ -2979,13 +3000,14 @@ bool CoreChecks::ValidateVideoEncodeQuantizationMapInfo(const vvl::CommandBuffer
VK_IMAGE_LAYOUT_VIDEO_ENCODE_QUANTIZATION_MAP_KHR, loc.dot(Field::quantizationMap),
"VUID-vkCmdEncodeVideoKHR-pNext-10314", &hit_error);

if (!IsImageCompatibleWithVideoSession(*iv_state->image_state, *vs_state)) {
std::string error_message;
if (!IsImageCompatibleWithVideoSession(*iv_state->image_state, *vs_state, error_message)) {
const LogObjectList objlist(cb_state.Handle(), vs_state->Handle(), iv_state->Handle());
skip |= LogError("VUID-vkCmdEncodeVideoKHR-pEncodeInfo-10310", objlist, loc.dot(Field::quantizationMap),
"(%s created from %s) is not compatible with the video profile the bound "
"video session %s was created with.",
"video session %s was created with.\n%s",
FormatHandle(iv_state->Handle()).c_str(), FormatHandle(iv_state->image_state->Handle()).c_str(),
FormatHandle(vs_state->Handle()).c_str());
FormatHandle(vs_state->Handle()).c_str(), error_message.c_str());
}
}

Expand Down Expand Up @@ -4373,15 +4395,16 @@ bool CoreChecks::PreCallValidateCmdBeginVideoCodingKHR(VkCommandBuffer commandBu
skip |= ValidateUnprotectedImage(*cb_state, *reference_resource.image_state, reference_image_view_loc,
"VUID-vkCmdBeginVideoCodingKHR-commandBuffer-07236");

if (!IsImageCompatibleWithVideoSession(*reference_resource.image_state, *vs_state)) {
std::string error_message;
if (!IsImageCompatibleWithVideoSession(*reference_resource.image_state, *vs_state, error_message)) {
const LogObjectList objlist(commandBuffer, pBeginInfo->videoSession,
reference_resource.image_view_state->Handle(),
reference_resource.image_state->Handle());
skip |= LogError("VUID-VkVideoBeginCodingInfoKHR-pPictureResource-07240", objlist, reference_image_view_loc,
"(%s created from %s) is not compatible with the video profile %s was created with.",
"(%s created from %s) is not compatible with the video profile %s was created with.\n%s",
FormatHandle(reference_resource.image_view_state->Handle()).c_str(),
FormatHandle(reference_resource.image_state->Handle()).c_str(),
FormatHandle(pBeginInfo->videoSession).c_str());
FormatHandle(pBeginInfo->videoSession).c_str(), error_message.c_str());
}

if (reference_resource.image_view_state->create_info.format != vs_state->create_info.referencePictureFormat) {
Expand Down Expand Up @@ -4866,14 +4889,16 @@ bool CoreChecks::PreCallValidateCmdDecodeVideoKHR(VkCommandBuffer commandBuffer,
skip |= ValidateUnprotectedImage(*cb_state, *dst_resource.image_state, dst_image_view_loc,
"VUID-vkCmdDecodeVideoKHR-commandBuffer-07148");

if (!IsImageCompatibleWithVideoSession(*dst_resource.image_state, *vs_state)) {
std::string error_message;
if (!IsImageCompatibleWithVideoSession(*dst_resource.image_state, *vs_state, error_message)) {
const LogObjectList objlist(commandBuffer, vs_state->Handle(), dst_resource.image_view_state->Handle(),
dst_resource.image_state->Handle());
skip |= LogError("VUID-vkCmdDecodeVideoKHR-pDecodeInfo-07142", objlist, dst_image_view_loc,
"(%s created from %s) is not compatible with the video profile the bound "
"video session %s was created with.",
"video session %s was created with.\n%s",
FormatHandle(pDecodeInfo->dstPictureResource.imageViewBinding).c_str(),
FormatHandle(dst_resource.image_state->Handle()).c_str(), FormatHandle(*vs_state).c_str());
FormatHandle(dst_resource.image_state->Handle()).c_str(), FormatHandle(*vs_state).c_str(),
error_message.c_str());
}

if (dst_resource.image_view_state->create_info.format != vs_state->create_info.pictureFormat) {
Expand Down Expand Up @@ -5381,14 +5406,16 @@ bool CoreChecks::PreCallValidateCmdEncodeVideoKHR(VkCommandBuffer commandBuffer,
skip |= ValidateProtectedImage(*cb_state, *src_resource.image_state, src_image_view_loc,
"VUID-vkCmdEncodeVideoKHR-commandBuffer-08211");

if (!IsImageCompatibleWithVideoSession(*src_resource.image_state, *vs_state)) {
std::string error_message;
if (!IsImageCompatibleWithVideoSession(*src_resource.image_state, *vs_state, error_message)) {
const LogObjectList objlist(commandBuffer, vs_state->Handle(), src_resource.image_view_state->Handle(),
src_resource.image_state->Handle());
skip |= LogError("VUID-vkCmdEncodeVideoKHR-pEncodeInfo-08206", objlist, src_image_view_loc,
"(%s created from %s) is not compatible with the video profile the bound "
"video session %s was created with.",
"video session %s was created with.\n%s",
FormatHandle(pEncodeInfo->srcPictureResource.imageViewBinding).c_str(),
FormatHandle(src_resource.image_state->Handle()).c_str(), FormatHandle(*vs_state).c_str());
FormatHandle(src_resource.image_state->Handle()).c_str(), FormatHandle(*vs_state).c_str(),
error_message.c_str());
}

if (src_resource.image_view_state->create_info.format != vs_state->create_info.pictureFormat) {
Expand Down
3 changes: 2 additions & 1 deletion layers/core_checks/core_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ class CoreChecks : public ValidationStateTracker {
bool IsSupportedVideoFormat(const VkImageCreateInfo& image_ci, const VkVideoProfileInfoKHR* profile) const;
bool IsVideoFormatSupported(VkFormat format, VkImageUsageFlags image_usage, const VkVideoProfileInfoKHR* profile) const;
bool IsBufferCompatibleWithVideoSession(const vvl::Buffer& buffer_state, const vvl::VideoSession& vs_state) const;
bool IsImageCompatibleWithVideoSession(const vvl::Image& image_state, const vvl::VideoSession& vs_state) const;
bool IsImageCompatibleWithVideoSession(const vvl::Image& image_state, const vvl::VideoSession& vs_state,
std::string& error_message) const;
void EnqueueVerifyVideoSessionInitialized(vvl::CommandBuffer& cb_state, vvl::VideoSession& vs_state, const Location& loc,
const char* vuid);
void EnqueueVerifyVideoInlineQueryUnavailable(vvl::CommandBuffer& cb_state, const VkVideoInlineQueryInfoKHR& query_info,
Expand Down
9 changes: 9 additions & 0 deletions layers/error_message/error_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,12 @@
}

[[maybe_unused]] static std::string string_VkBool32(VkBool32 value) { return value ? "VK_TRUE" : "VK_FALSE"; }

[[maybe_unused]] static std::string string_VkVideoProfileInfoKHR(const VkVideoProfileInfoKHR &profile) {
std::stringstream ss;
ss << "videoCodecOperation = " << string_VkVideoCodecOperationFlagBitsKHR(profile.videoCodecOperation) << '\n';
ss << "chromaSubsampling = " << string_VkVideoChromaSubsamplingFlagsKHR(profile.chromaSubsampling) << '\n';
ss << "lumaBitDepth = " << string_VkVideoComponentBitDepthFlagsKHR(profile.lumaBitDepth) << '\n';
ss << "chromaBitDepth = " << string_VkVideoComponentBitDepthFlagsKHR(profile.chromaBitDepth);
return ss.str();
}
22 changes: 20 additions & 2 deletions layers/state_tracker/video_session_state.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2022-2024 The Khronos Group Inc.
* Copyright (c) 2022-2024 RasterGrid Kft.
/* Copyright (c) 2022-2025 The Khronos Group Inc.
* Copyright (c) 2022-2025 RasterGrid Kft.
* Modifications Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,6 +18,7 @@
#include "state_tracker/image_state.h"
#include "state_tracker/state_tracker.h"
#include "generated/dispatch_functions.h"
#include "error_message/error_strings.h"

#include <sstream>

Expand All @@ -41,6 +42,23 @@ VideoProfileDesc::~VideoProfileDesc() {
}
}

std::string VideoProfileDesc::Describe() const {
std::stringstream ss;
ss << string_VkVideoProfileInfoKHR(profile_.base) << '\n';
if (profile_.is_decode) {
ss << "VkVideoDecodeUsageInfoKHR::videoUsageHints = "
<< string_VkVideoDecodeUsageFlagsKHR(profile_.decode_usage.videoUsageHints) << '\n';
} else if (profile_.is_encode) {
ss << "VkVideoEncodeUsageInfoKHR::videoUsageHints = "
<< string_VkVideoEncodeUsageFlagsKHR(profile_.encode_usage.videoUsageHints) << '\n';
ss << "VkVideoEncodeUsageInfoKHR::videoContentHints = "
<< string_VkVideoEncodeContentFlagsKHR(profile_.encode_usage.videoContentHints) << '\n';
ss << "VkVideoEncodeUsageInfoKHR::tuningMode = " << string_VkVideoEncodeTuningModeKHR(profile_.encode_usage.tuningMode)
<< '\n';
}
return ss.str();
}

bool VideoProfileDesc::InitProfile(VkVideoProfileInfoKHR const *profile) {
if (profile) {
profile_.base = *profile;
Expand Down
5 changes: 3 additions & 2 deletions layers/state_tracker/video_session_state.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2022-2024 The Khronos Group Inc.
* Copyright (c) 2022-2024 RasterGrid Kft.
/* Copyright (c) 2022-2025 The Khronos Group Inc.
* Copyright (c) 2022-2025 RasterGrid Kft.
* Modifications Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -104,6 +104,7 @@ class VideoProfileDesc : public std::enable_shared_from_this<VideoProfileDesc> {
VideoProfileDesc(VkPhysicalDevice physical_device, VkVideoProfileInfoKHR const *profile);
~VideoProfileDesc();

std::string Describe() const;
const Profile &GetProfile() const { return profile_; }
const Capabilities &GetCapabilities() const { return capabilities_; }

Expand Down

0 comments on commit ddb902c

Please sign in to comment.