Skip to content

Commit

Permalink
layers: Rename shouty MEM_STATE
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Jan 10, 2025
1 parent b77227b commit 7812057
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 139 deletions.
8 changes: 4 additions & 4 deletions docs/fine_grained_locking.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Copyright 2021-2024 LunarG, Inc. -->
<!-- Copyright 2021-2025 LunarG, Inc. -->
[![Khronos Vulkan][1]][2]

[1]: https://vulkan.lunarg.com/img/Vulkan_100px_Dec16.png "https://www.khronos.org/vulkan/"
Expand Down Expand Up @@ -541,12 +541,12 @@ The `p_driver_data` pointer is only used by Best Practices validation, but it is


```
struct MEM_BINDING {
std::shared_ptr<vvl::DeviceMemory> mem_state;
struct MemoryBinding {
std::shared_ptr<vvl::DeviceMemory> memory_state;
VkDeviceSize offset;
VkDeviceSize size;
};
using BoundMemoryMap = small_unordered_map<VkDeviceMemory, MEM_BINDING, 1>;
using BoundMemoryMap = small_unordered_map<VkDeviceMemory, MemoryBinding, 1>;
BoundMemoryMap bound_memory_;
```

Expand Down
24 changes: 12 additions & 12 deletions layers/best_practices/bp_device_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,17 @@ bool BestPractices::PreCallValidateFreeMemory(VkDevice device, VkDeviceMemory me
bool BestPractices::ValidateBindBufferMemory(VkBuffer buffer, VkDeviceMemory memory, const Location& loc) const {
bool skip = false;
auto buffer_state = Get<vvl::Buffer>(buffer);
auto mem_state = Get<vvl::DeviceMemory>(memory);
ASSERT_AND_RETURN_SKIP(mem_state && buffer_state);
auto memory_state = Get<vvl::DeviceMemory>(memory);
ASSERT_AND_RETURN_SKIP(memory_state && buffer_state);

if (mem_state->allocate_info.allocationSize == buffer_state->create_info.size &&
mem_state->allocate_info.allocationSize < kMinDedicatedAllocationSize) {
if (memory_state->allocate_info.allocationSize == buffer_state->create_info.size &&
memory_state->allocate_info.allocationSize < kMinDedicatedAllocationSize) {
skip |= LogPerformanceWarning("BestPractices-vkBindBufferMemory-small-dedicated-allocation", device, loc,
"Trying to bind %s to a memory block which is fully consumed by the buffer. "
"The required size of the allocation is %" PRIu64
", but smaller buffers like this should be sub-allocated from "
"larger memory blocks. (Current threshold is %" PRIu64 " bytes.)",
FormatHandle(buffer).c_str(), mem_state->allocate_info.allocationSize,
FormatHandle(buffer).c_str(), memory_state->allocate_info.allocationSize,
kMinDedicatedAllocationSize);
}

Expand Down Expand Up @@ -206,17 +206,17 @@ bool BestPractices::PreCallValidateBindBufferMemory2KHR(VkDevice device, uint32_
bool BestPractices::ValidateBindImageMemory(VkImage image, VkDeviceMemory memory, const Location& loc) const {
bool skip = false;
auto image_state = Get<vvl::Image>(image);
auto mem_state = Get<vvl::DeviceMemory>(memory);
ASSERT_AND_RETURN_SKIP(mem_state && image_state);
auto memory_state = Get<vvl::DeviceMemory>(memory);
ASSERT_AND_RETURN_SKIP(memory_state && image_state);

if (mem_state->allocate_info.allocationSize == image_state->requirements[0].size &&
mem_state->allocate_info.allocationSize < kMinDedicatedAllocationSize) {
if (memory_state->allocate_info.allocationSize == image_state->requirements[0].size &&
memory_state->allocate_info.allocationSize < kMinDedicatedAllocationSize) {
skip |= LogPerformanceWarning("BestPractices-vkBindImageMemory-small-dedicated-allocation", device, loc,
"Trying to bind %s to a memory block which is fully consumed by the image. "
"The required size of the allocation is %" PRIu64
", but smaller images like this should be sub-allocated from "
"larger memory blocks. (Current threshold is %" PRIu64 " bytes.)",
FormatHandle(image).c_str(), mem_state->allocate_info.allocationSize,
FormatHandle(image).c_str(), memory_state->allocate_info.allocationSize,
kMinDedicatedAllocationSize);
}

Expand All @@ -238,15 +238,15 @@ bool BestPractices::ValidateBindImageMemory(VkImage image, VkDeviceMemory memory
}
}

uint32_t allocated_properties = phys_dev_mem_props.memoryTypes[mem_state->allocate_info.memoryTypeIndex].propertyFlags;
uint32_t allocated_properties = phys_dev_mem_props.memoryTypes[memory_state->allocate_info.memoryTypeIndex].propertyFlags;

if (supports_lazy && (allocated_properties & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) == 0) {
skip |= LogPerformanceWarning(
"BestPractices-vkBindImageMemory-non-lazy-transient-image", device, loc,
"ttempting to bind memory type %u to VkImage which was created with TRANSIENT_ATTACHMENT_BIT,"
"but this memory type is not LAZILY_ALLOCATED_BIT. You should use memory type %u here instead to save "
"%" PRIu64 " bytes of physical memory.",
mem_state->allocate_info.memoryTypeIndex, suggested_type, image_state->requirements[0].size);
memory_state->allocate_info.memoryTypeIndex, suggested_type, image_state->requirements[0].size);
}
}

Expand Down
8 changes: 4 additions & 4 deletions layers/best_practices/bp_drawdispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ bool BestPractices::ValidateIndexBufferArm(const bp_state::CommandBuffer& cb_sta
}

const VkIndexType ib_type = cb_state.index_buffer_binding.index_type;
const auto ib_mem_state = ib_state->MemState();
if (!ib_mem_state) return skip;
const auto ib_memory_state = ib_state->MemoryState();
if (!ib_memory_state) return skip;

const void* ib_mem = ib_mem_state->p_driver_data;
const void* ib_mem = ib_memory_state->p_driver_data;

const auto& last_bound_state = cb_state.lastBound[ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS)];
const bool primitive_restart_enable = last_bound_state.IsPrimitiveRestartEnable();
Expand All @@ -233,7 +233,7 @@ bool BestPractices::ValidateIndexBufferArm(const bp_state::CommandBuffer& cb_sta
if (ib_mem) {
const uint32_t scan_stride = GetIndexAlignment(ib_type);
// Check if all indices are within the memory allocation size, if robustness is enabled they might not be
if ((firstIndex + indexCount) * scan_stride > ib_mem_state->allocate_info.allocationSize) {
if ((firstIndex + indexCount) * scan_stride > ib_memory_state->allocate_info.allocationSize) {
return skip;
}
const uint8_t* scan_begin = static_cast<const uint8_t*>(ib_mem) + firstIndex * scan_stride;
Expand Down
11 changes: 6 additions & 5 deletions layers/core_checks/cc_buffer_address.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 LunarG, Inc.
/* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -113,9 +113,10 @@ class BufferAddressValidation {
std::string* out_error_msg) {
if (!buffer_state->sparse && !buffer_state->IsMemoryBound()) {
if (out_error_msg) {
if (const auto mem_state = buffer_state->MemState(); mem_state && mem_state->Destroyed()) {
const auto memory_state = buffer_state->MemoryState();
if (memory_state && memory_state->Destroyed()) {
*out_error_msg +=
"buffer is bound to memory (" + validator.FormatHandle(mem_state->Handle()) + ") but it has been freed";
"buffer is bound to memory (" + validator.FormatHandle(memory_state->Handle()) + ") but it has been freed";
} else {
*out_error_msg += "buffer has not been bound to memory";
}
Expand Down
2 changes: 1 addition & 1 deletion layers/core_checks/cc_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2188,7 +2188,7 @@ bool CoreChecks::VerifyWriteUpdateContents(const vvl::DescriptorSet &dst_set, co
// nullDescriptor feature allows this to be VK_NULL_HANDLE
if (auto as_state = Get<vvl::AccelerationStructureNV>(as)) {
skip |= VerifyBoundMemoryIsValid(
as_state->MemState(), LogObjectList(as), as_state->Handle(),
as_state->MemoryState(), LogObjectList(as), as_state->Handle(),
write_loc.pNext(Struct::VkWriteDescriptorSetAccelerationStructureNV, Field::pAccelerationStructures, di),
kVUIDUndefined);
}
Expand Down
Loading

0 comments on commit 7812057

Please sign in to comment.