address comments

Signed-off-by: John <jonawals@amazon.com>
This commit is contained in:
jiaweig
2021-06-25 14:17:17 -07:00
committed by John
parent c246aa074d
commit 1e8465f1cc
4 changed files with 22 additions and 8 deletions
@@ -787,21 +787,25 @@ namespace AZ
return *m_nullDescriptorManager;
}
VkBufferUsageFlags Device::ValidateBufferUsageFlagsByFeatures(const VkBufferUsageFlags& bufferUsageFlags) const
VkBufferUsageFlags Device::GetBufferUsageFlagBitsUnderRestrictions(RHI::BufferBindFlags bindFlags) const
{
VkBufferUsageFlags bufferUsageFlags = GetBufferUsageFlagBits(bindFlags);
const auto& physicalDevice = static_cast<const PhysicalDevice&>(GetPhysicalDevice());
VkBufferUsageFlags result = bufferUsageFlags;
// VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT require bufferDeviceAddress enabled.
if (!physicalDevice.GetPhysicalDeviceBufferDeviceAddressFeatures().bufferDeviceAddress)
{
result &= ~VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
bufferUsageFlags &= ~VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
}
// VK_KHR_acceleration_structure provides VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR
// Otherwise unrecognized flag.
if (!physicalDevice.IsOptionalDeviceExtensionSupported(OptionalDeviceExtension::AccelerationStructure))
{
result &= ~VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR;
bufferUsageFlags &= ~VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR;
}
return result;
return bufferUsageFlags;
}
VkBuffer Device::CreateBufferResouce(const RHI::BufferDescriptor& descriptor) const
@@ -814,8 +818,7 @@ namespace AZ
createInfo.pNext = nullptr;
createInfo.flags = 0;
createInfo.size = descriptor.m_byteCount;
createInfo.usage = GetBufferUsageFlagBits(descriptor.m_bindFlags);
createInfo.usage = ValidateBufferUsageFlagsByFeatures(createInfo.usage);
createInfo.usage = GetBufferUsageFlagBitsUnderRestrictions(descriptor.m_bindFlags);
// Trying to guess here if the buffers are going to be used as attachments. Maybe it would be better to add an explicit flag in the descriptor.
createInfo.sharingMode =
RHI::CheckBitsAny(
@@ -149,7 +149,9 @@ namespace AZ
template <typename ObjectType, typename... Args>
RHI::Ptr<ObjectType> AcquireObjectFromCache(ObjectCache<ObjectType>& cache, const size_t hash, Args... args);
VkBufferUsageFlags ValidateBufferUsageFlagsByFeatures(const VkBufferUsageFlags& bufferUsageFlags) const;
//! Get the vulkan buffer usage flags from buffer bind flags.
//! Flags will be corrected if required features or extensions are not enabled.
VkBufferUsageFlags GetBufferUsageFlagBitsUnderRestrictions(RHI::BufferBindFlags bindFlags) const;
VkDevice m_nativeDevice = VK_NULL_HANDLE;
VkPhysicalDeviceFeatures m_enabledDeviceFeatures{};
@@ -266,12 +266,20 @@ namespace AZ
VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME
} };
uint32_t optionalExtensionCount = sizeof(optionalExtensions) / sizeof(VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME);
AZ_Assert(optionalExtensionCount == static_cast<uint32_t>(OptionalDeviceExtension::Count), "The order and size must match the enum OptionalDeviceExtensions.");
// Optional device extensions are filtered based on what the device support.
// It returns in the same order as in the original list.
StringList deviceExtensions = GetDeviceExtensionNames();
RawStringList filteredOptionalExtensions = FilterList(optionalExtensions, deviceExtensions);
// Mark the supported optional extensions in the bitset for faster look up compared to string search.
uint32_t originalIndex = 0;
for (const auto& extension : filteredOptionalExtensions)
{
AZ_Assert(originalIndex < optionalExtensionCount, "Out of range index. Check FilterList algorithm if list is returned in the original order.");
while (strcmp(extension, optionalExtensions[originalIndex]) != 0)
{
++originalIndex;
@@ -92,6 +92,7 @@ namespace AZ
StringList GetDeviceExtensionNames(const char* layerName = nullptr) const;
bool IsFormatSupported(RHI::Format format, VkImageTiling tiling, VkFormatFeatureFlags features) const;
void LoadSupportedFeatures();
//! Filter optional extensions based on what the physics device support.
RawStringList FilterSupportedOptionalExtensions();
void CompileMemoryStatistics(RHI::MemoryStatisticsBuilder& builder) const;