1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
/* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Copyright (C) 2015-2024 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "stateless/stateless_validation.h"
#include <vulkan/utility/vk_format_utils.h>
#include "utils/image_utils.h"
#include "utils/math_utils.h"
#include "containers/range.h"
namespace stateless {
bool Device::manual_PreCallValidateAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
const Context &context) const {
bool skip = false;
const auto &error_obj = context.error_obj;
if (!pAllocateInfo) {
return skip;
}
const Location allocate_info_loc = error_obj.location.dot(Field::pAllocateInfo);
auto chained_prio_struct = vku::FindStructInPNextChain<VkMemoryPriorityAllocateInfoEXT>(pAllocateInfo->pNext);
if (chained_prio_struct && (chained_prio_struct->priority < 0.0f || chained_prio_struct->priority > 1.0f)) {
skip |= LogError("VUID-VkMemoryPriorityAllocateInfoEXT-priority-02602", device,
allocate_info_loc.pNext(Struct::VkMemoryPriorityAllocateInfoEXT, Field::priority), "is %f",
chained_prio_struct->priority);
}
auto flags_info = vku::FindStructInPNextChain<VkMemoryAllocateFlagsInfo>(pAllocateInfo->pNext);
const VkMemoryAllocateFlags flags = flags_info ? flags_info->flags : 0;
skip |= ValidateAllocateMemoryExternal(device, *pAllocateInfo, flags, allocate_info_loc);
if (flags) {
const Location flags_loc = allocate_info_loc.pNext(Struct::VkMemoryAllocateFlagsInfo, Field::flags);
if ((flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT) && !enabled_features.bufferDeviceAddressCaptureReplay) {
skip |= LogError("VUID-VkMemoryAllocateInfo-flags-03330", device, flags_loc,
"has VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT set, but "
"bufferDeviceAddressCaptureReplay feature is not enabled.");
}
if ((flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT) && !enabled_features.bufferDeviceAddress) {
skip |= LogError("VUID-VkMemoryAllocateInfo-flags-03331", device, flags_loc,
"has VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT set, but bufferDeviceAddress feature is not enabled.");
}
}
return skip;
}
bool Device::ValidateDeviceImageMemoryRequirements(VkDevice device, const VkDeviceImageMemoryRequirements &memory_requirements,
const Location &loc) const {
bool skip = false;
const auto &create_info = *(memory_requirements.pCreateInfo);
if (vku::FindStructInPNextChain<VkImageSwapchainCreateInfoKHR>(create_info.pNext)) {
skip |= LogError("VUID-VkDeviceImageMemoryRequirements-pCreateInfo-06416", device,
loc.dot(Field::pCreateInfo).dot(Field::pNext), "chain contains VkImageSwapchainCreateInfoKHR.\n%s",
PrintPNextChain(Struct::VkImageCreateInfo, create_info.pNext).c_str());
}
if (vku::FindStructInPNextChain<VkImageDrmFormatModifierExplicitCreateInfoEXT>(create_info.pNext)) {
skip |= LogError("VUID-VkDeviceImageMemoryRequirements-pCreateInfo-06776", device,
loc.dot(Field::pCreateInfo).dot(Field::pNext),
"chain contains VkImageDrmFormatModifierExplicitCreateInfoEXT.\n%s",
PrintPNextChain(Struct::VkImageCreateInfo, create_info.pNext).c_str());
}
if (vkuFormatIsMultiplane(create_info.format) && (create_info.flags & VK_IMAGE_CREATE_DISJOINT_BIT) != 0) {
if (memory_requirements.planeAspect == VK_IMAGE_ASPECT_NONE) {
skip |= LogError("VUID-VkDeviceImageMemoryRequirements-pCreateInfo-06417", device, loc.dot(Field::planeAspect),
"is VK_IMAGE_ASPECT_NONE with a multi-planar format and disjoint flag.");
} else if ((create_info.tiling == VK_IMAGE_TILING_LINEAR || create_info.tiling == VK_IMAGE_TILING_OPTIMAL) &&
!IsOnlyOneValidPlaneAspect(create_info.format, memory_requirements.planeAspect)) {
skip |= LogError("VUID-VkDeviceImageMemoryRequirements-pCreateInfo-06419", device, loc.dot(Field::planeAspect),
"is %s but is invalid for %s.", string_VkImageAspectFlags(memory_requirements.planeAspect).c_str(),
string_VkFormat(create_info.format));
}
}
const uint64_t external_format = GetExternalFormat(memory_requirements.pCreateInfo->pNext);
if (external_format != 0) {
skip |= LogError("VUID-VkDeviceImageMemoryRequirements-pNext-06996", device, loc.dot(Field::pCreateInfo),
"pNext chain contains VkExternalFormatANDROID with externalFormat %" PRIu64 ".", external_format);
}
return skip;
}
bool Device::manual_PreCallValidateGetDeviceImageMemoryRequirements(VkDevice device, const VkDeviceImageMemoryRequirements *pInfo,
VkMemoryRequirements2 *pMemoryRequirements,
const Context &context) const {
bool skip = false;
const auto &error_obj = context.error_obj;
skip |= ValidateDeviceImageMemoryRequirements(device, *pInfo, error_obj.location.dot(Field::pInfo));
return skip;
}
bool Device::manual_PreCallValidateGetDeviceImageSparseMemoryRequirements(
VkDevice device, const VkDeviceImageMemoryRequirements *pInfo, uint32_t *pSparseMemoryRequirementCount,
VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements, const Context &context) const {
bool skip = false;
const auto &error_obj = context.error_obj;
skip |= ValidateDeviceImageMemoryRequirements(device, *pInfo, error_obj.location.dot(Field::pInfo));
return skip;
}
bool Device::manual_PreCallValidateCmdDecompressMemoryEXT(VkCommandBuffer commandBuffer,
const VkDecompressMemoryInfoEXT* pDecompressMemoryInfoEXT,
const Context& context) const {
bool skip = false;
const auto& error_obj = context.error_obj;
if (!enabled_features.memoryDecompression) {
skip |= LogError("VUID-vkCmdDecompressMemoryEXT-memoryDecompression-11761", commandBuffer, error_obj.location,
"The memoryDecompression feature must be enabled.");
}
const auto& props = phys_dev_ext_props.memory_decompression_props;
if ((pDecompressMemoryInfoEXT->decompressionMethod & props.decompressionMethods) == 0) {
skip |= LogError("VUID-VkDecompressMemoryInfoEXT-decompressionMethod-11763", commandBuffer,
error_obj.location.dot(Field::decompressionMethod),
"(0x%" PRIx64 ") is not a supported decompression method bit (supported mask: 0x%" PRIx64 ").",
pDecompressMemoryInfoEXT->decompressionMethod, props.decompressionMethods);
}
if (pDecompressMemoryInfoEXT->decompressionMethod & VK_MEMORY_DECOMPRESSION_METHOD_GDEFLATE_1_0_BIT_EXT) {
const Location memory_info_loc = error_obj.location.dot(Field::pDecompressMemoryInfoEXT);
for (uint32_t i = 0; i < pDecompressMemoryInfoEXT->regionCount; ++i) {
const Location region_loc = memory_info_loc.dot(Field::pRegions, i);
const VkDecompressMemoryRegionEXT mem_region = pDecompressMemoryInfoEXT->pRegions[i];
if (mem_region.decompressedSize > 65536) {
skip |= LogError("VUID-VkDecompressMemoryInfoEXT-decompressionMethod-11762", commandBuffer,
region_loc.dot(Field::decompressedSize),
"(%" PRIu64 ") must be less than or equal to 65536 bytes.", mem_region.decompressedSize);
}
if (mem_region.compressedSize == 0) {
skip |= LogError("VUID-VkDecompressMemoryRegionEXT-compressedSize-11795", commandBuffer,
region_loc.dot(Field::compressedSize), "must not be zero.");
}
if (mem_region.decompressedSize == 0) {
skip |= LogError("VUID-VkDecompressMemoryRegionEXT-decompressedSize-11796", commandBuffer,
region_loc.dot(Field::decompressedSize), "must not be zero.");
}
if (mem_region.srcAddress & 0x3) {
skip |=
LogError("VUID-VkDecompressMemoryRegionEXT-srcAddress-07685", commandBuffer, region_loc.dot(Field::srcAddress),
"(0x%" PRIx64 ") is not 4-byte aligned.", mem_region.srcAddress);
}
if (mem_region.dstAddress & 0x3) {
skip |=
LogError("VUID-VkDecompressMemoryRegionEXT-dstAddress-07687", commandBuffer, region_loc.dot(Field::dstAddress),
"(0x%" PRIx64 ") is not 4-byte aligned.", mem_region.dstAddress);
}
const vvl::range<VkDeviceAddress> src_range{mem_region.srcAddress, mem_region.srcAddress + mem_region.compressedSize};
const vvl::range<VkDeviceAddress> dst_range{mem_region.dstAddress, mem_region.dstAddress + mem_region.decompressedSize};
if (src_range.intersects(dst_range)) {
skip |= LogError("VUID-VkDecompressMemoryRegionEXT-srcAddress-07691", commandBuffer,
region_loc.dot(Field::srcAddress), "range %s overlaps with dstAddress range %s.",
string_range_hex(src_range).c_str(), string_range_hex(dst_range).c_str());
}
}
}
if (!IsPowerOfTwo(pDecompressMemoryInfoEXT->decompressionMethod)) {
skip |= LogError("VUID-VkDecompressMemoryInfoEXT-decompressionMethod-07690", commandBuffer,
error_obj.location.dot(Field::pDecompressMemoryInfoEXT).dot(Field::decompressionMethod),
"(0x%" PRIx64 ") must have a single bit set.", pDecompressMemoryInfoEXT->decompressionMethod);
}
return skip;
}
bool Device::manual_PreCallValidateCmdDecompressMemoryIndirectCountEXT(
VkCommandBuffer commandBuffer, VkMemoryDecompressionMethodFlagsEXT decompressionMethod, VkDeviceAddress indirectCommandsAddress,
VkDeviceAddress indirectCommandsCountAddress, uint32_t maxDecompressionCount, uint32_t stride, const Context& context) const {
bool skip = false;
const auto& error_obj = context.error_obj;
if (!enabled_features.memoryDecompression) {
skip |= LogError("VUID-vkCmdDecompressMemoryIndirectCountEXT-None-07692", commandBuffer, error_obj.location,
"The memoryDecompression feature must be enabled.");
}
const auto& props = phys_dev_ext_props.memory_decompression_props;
if ((decompressionMethod & props.decompressionMethods) == 0) {
skip |= LogError("VUID-vkCmdDecompressMemoryIndirectCountEXT-decompressionMethod-11810", commandBuffer,
error_obj.location.dot(Field::decompressionMethod),
"(0x%" PRIx64 ") is not a supported decompression method bit (supported mask: 0x%" PRIx64 ").",
decompressionMethod, props.decompressionMethods);
}
if (!IsPowerOfTwo(decompressionMethod)) {
skip |= LogError("VUID-vkCmdDecompressMemoryIndirectCountEXT-decompressionMethod-07690", commandBuffer,
error_obj.location.dot(Field::decompressionMethod), "(0x%" PRIx64 ") must have a single bit set.",
decompressionMethod);
}
if (indirectCommandsAddress % 4 != 0) {
skip |= LogError("VUID-vkCmdDecompressMemoryIndirectCountEXT-indirectCommandsAddress-07695", commandBuffer,
error_obj.location.dot(Field::indirectCommandsAddress), "(0x%" PRIx64 ") must be a multiple of 4.",
indirectCommandsAddress);
}
if (indirectCommandsCountAddress % 4 != 0) {
skip |= LogError("VUID-vkCmdDecompressMemoryIndirectCountEXT-indirectCommandsCountAddress-07698", commandBuffer,
error_obj.location.dot(Field::indirectCommandsCountAddress), "(0x%" PRIx64 ") must be a multiple of 4.",
indirectCommandsCountAddress);
}
if (stride % 4 != 0 || stride < sizeof(VkDecompressMemoryRegionEXT)) {
skip |= LogError(
"VUID-vkCmdDecompressMemoryIndirectCountEXT-stride-11767", commandBuffer, error_obj.location.dot(Field::stride),
"(%" PRIu32
") must be a multiple of 4 and must be greater than or equal to size of VkDecompressMemoryRegionEXT (%" PRIu64 ").",
stride, static_cast<uint64_t>(sizeof(VkDecompressMemoryRegionEXT)));
}
if (maxDecompressionCount > props.maxDecompressionIndirectCount) {
skip |= LogError("VUID-vkCmdDecompressMemoryIndirectCountEXT-maxDecompressionCount-11768", commandBuffer,
error_obj.location.dot(Field::maxDecompressionCount),
"(%" PRIu32
") must be less than or equal to "
"VkPhysicalDeviceMemoryDecompressionPropertiesEXT::maxDecompressionIndirectCount (%" PRIu64 ").",
maxDecompressionCount, props.maxDecompressionIndirectCount);
}
return skip;
}
bool Device::manual_PreCallValidateQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
VkFence fence, const Context &context) const {
bool skip = false;
const auto &error_obj = context.error_obj;
for (uint32_t bind_info_i = 0; bind_info_i < bindInfoCount; ++bind_info_i) {
const VkBindSparseInfo &bind_info = pBindInfo[bind_info_i];
for (uint32_t image_bind_i = 0; image_bind_i < bind_info.imageBindCount; ++image_bind_i) {
const VkSparseImageMemoryBindInfo &image_bind = bind_info.pImageBinds[image_bind_i];
for (uint32_t bind_i = 0; bind_i < image_bind.bindCount; ++bind_i) {
const VkSparseImageMemoryBind &bind = image_bind.pBinds[bind_i];
if (bind.extent.width == 0) {
const LogObjectList objlist(queue, image_bind.image);
skip |= LogError("VUID-VkSparseImageMemoryBind-extent-09388", objlist,
error_obj.location.dot(Field::pBindInfo, bind_info_i)
.dot(Field::pImageBinds, image_bind_i)
.dot(Field::pBinds, bind_i)
.dot(Field::extent)
.dot(Field::width),
"is zero.");
}
if (bind.extent.height == 0) {
const LogObjectList objlist(queue, image_bind.image);
skip |= LogError("VUID-VkSparseImageMemoryBind-extent-09389", objlist,
error_obj.location.dot(Field::pBindInfo, bind_info_i)
.dot(Field::pImageBinds, image_bind_i)
.dot(Field::pBinds, bind_i)
.dot(Field::extent)
.dot(Field::height),
"is zero.");
}
if (bind.extent.depth == 0) {
const LogObjectList objlist(queue, image_bind.image);
skip |= LogError("VUID-VkSparseImageMemoryBind-extent-09390", objlist,
error_obj.location.dot(Field::pBindInfo, bind_info_i)
.dot(Field::pImageBinds, image_bind_i)
.dot(Field::pBinds, bind_i)
.dot(Field::extent)
.dot(Field::depth),
"is zero.");
}
}
}
}
return skip;
}
bool Device::manual_PreCallValidateSetDeviceMemoryPriorityEXT(VkDevice device, VkDeviceMemory memory, float priority,
const Context &context) const {
bool skip = false;
const auto &error_obj = context.error_obj;
if (!IsBetweenInclusive(priority, 0.0F, 1.0F)) {
skip |= LogError("VUID-vkSetDeviceMemoryPriorityEXT-priority-06258", device, error_obj.location.dot(Field::priority),
"is %f.", priority);
}
return skip;
}
} // namespace stateless
|