|
|
|
@ -72,9 +72,16 @@ namespace Vulkan { |
|
|
|
return flags; |
|
|
|
} |
|
|
|
|
|
|
|
[[nodiscard]] VkBufferUsageFlags ImportedDescriptorAddressUsage(const Device &device) { |
|
|
|
return ImportedDescriptorUsage(device) | |
|
|
|
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT; |
|
|
|
[[nodiscard]] VkBufferUsageFlags ImportedWindowUsage(const Device &device, |
|
|
|
bool with_address, bool with_counter) { |
|
|
|
VkBufferUsageFlags flags = ImportedDescriptorUsage(device); |
|
|
|
if (with_address) { |
|
|
|
flags |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT; |
|
|
|
} |
|
|
|
if (with_counter) { |
|
|
|
flags |= VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_COUNTER_BUFFER_BIT_EXT; |
|
|
|
} |
|
|
|
return flags; |
|
|
|
} |
|
|
|
|
|
|
|
// Helpers translating MemoryUsage to flags/usage
|
|
|
|
@ -302,22 +309,31 @@ namespace Vulkan { |
|
|
|
bool HostMemoryImport::CreateDescriptorCapableWindowBuffer( |
|
|
|
const void *external_info, VkDeviceSize length, u32 external_type_bits, |
|
|
|
VkDeviceSize capacity, VkBuffer *out_buffer, u32 *out_type_mask, |
|
|
|
bool *out_descriptor_capable, bool *out_address_capable, bool allow_address) const { |
|
|
|
if (allow_address && device.IsBufferDeviceAddressSupported() && |
|
|
|
TryCreateWindowBuffer(external_info, length, external_type_bits, capacity, |
|
|
|
ImportedDescriptorAddressUsage(device), out_buffer, |
|
|
|
out_type_mask)) { |
|
|
|
bool *out_descriptor_capable, bool *out_address_capable, bool *out_counter_capable, |
|
|
|
bool allow_address) const { |
|
|
|
const bool address_wanted = allow_address && device.IsBufferDeviceAddressSupported(); |
|
|
|
const bool counter_wanted = device.IsExtTransformFeedbackSupported(); |
|
|
|
const auto try_descriptor = [&](bool with_address, bool with_counter) { |
|
|
|
if ((with_address && !address_wanted) || (with_counter && !counter_wanted)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (!TryCreateWindowBuffer(external_info, length, external_type_bits, capacity, |
|
|
|
ImportedWindowUsage(device, with_address, with_counter), |
|
|
|
out_buffer, out_type_mask)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
*out_descriptor_capable = true; |
|
|
|
*out_address_capable = true; |
|
|
|
*out_address_capable = with_address; |
|
|
|
*out_counter_capable = with_counter; |
|
|
|
return true; |
|
|
|
} |
|
|
|
*out_address_capable = false; |
|
|
|
if (TryCreateWindowBuffer(external_info, length, external_type_bits, capacity, |
|
|
|
ImportedDescriptorUsage(device), out_buffer, out_type_mask)) { |
|
|
|
*out_descriptor_capable = true; |
|
|
|
}; |
|
|
|
if (try_descriptor(true, true) || try_descriptor(true, false) || |
|
|
|
try_descriptor(false, true) || try_descriptor(false, false)) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
*out_descriptor_capable = false; |
|
|
|
*out_address_capable = false; |
|
|
|
*out_counter_capable = false; |
|
|
|
return TryCreateWindowBuffer(external_info, length, external_type_bits, capacity, |
|
|
|
ImportedTransferUsage, out_buffer, out_type_mask); |
|
|
|
} |
|
|
|
@ -458,6 +474,7 @@ namespace Vulkan { |
|
|
|
base_offset = hardware_buffer_base; |
|
|
|
bool every_window_descriptor_capable = true; |
|
|
|
bool every_window_address_capable = true; |
|
|
|
bool every_window_counter_capable = true; |
|
|
|
for (size_t i = 0; i < hardware_buffers.size(); ++i) { |
|
|
|
const size_t offset = hardware_buffer_base + i * hardware_buffer_window; |
|
|
|
if (offset >= size) { |
|
|
|
@ -486,6 +503,7 @@ namespace Vulkan { |
|
|
|
Window window{}; |
|
|
|
bool descriptor_capable = false; |
|
|
|
bool address_capable = false; |
|
|
|
bool counter_capable = false; |
|
|
|
const auto build_window = [&](bool allow_address) { |
|
|
|
VkBuffer new_buffer{}; |
|
|
|
u32 type_mask = 0; |
|
|
|
@ -493,7 +511,8 @@ namespace Vulkan { |
|
|
|
ahb_props.memoryTypeBits, |
|
|
|
ahb_props.allocationSize, &new_buffer, |
|
|
|
&type_mask, &descriptor_capable, |
|
|
|
&address_capable, allow_address)) { |
|
|
|
&address_capable, &counter_capable, |
|
|
|
allow_address)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
const auto type_index = FindImportMemoryType(memory_props, type_mask); |
|
|
|
@ -554,10 +573,12 @@ namespace Vulkan { |
|
|
|
windows.push_back(std::move(window)); |
|
|
|
every_window_descriptor_capable &= descriptor_capable; |
|
|
|
every_window_address_capable &= address_capable; |
|
|
|
every_window_counter_capable &= counter_capable; |
|
|
|
imported_size += static_cast<size_t>(window_len); |
|
|
|
} |
|
|
|
direct_descriptors = !windows.empty() && every_window_descriptor_capable; |
|
|
|
direct_addresses = direct_descriptors && every_window_address_capable; |
|
|
|
direct_counter_buffers = direct_descriptors && every_window_counter_capable; |
|
|
|
if (windows.empty()) { |
|
|
|
window_size = 0; |
|
|
|
base_offset = 0; |
|
|
|
|