diff options
Diffstat (limited to 'tools/gfx/vulkan/vk-device.cpp')
| -rw-r--r-- | tools/gfx/vulkan/vk-device.cpp | 90 |
1 files changed, 39 insertions, 51 deletions
diff --git a/tools/gfx/vulkan/vk-device.cpp b/tools/gfx/vulkan/vk-device.cpp index b9dbb264f..b9ae23b15 100644 --- a/tools/gfx/vulkan/vk-device.cpp +++ b/tools/gfx/vulkan/vk-device.cpp @@ -124,6 +124,15 @@ Result DeviceImpl::getNativeDeviceHandles(InteropHandles* outHandles) return SLANG_OK; } +template<typename T> +static bool _hasAnySetBits(const T& val, size_t offset) +{ + const uint8_t* ptr = reinterpret_cast<const uint8_t*>(&val); + for (size_t i = offset; i < sizeof(val); i++) + if (ptr[i]) return true; + return false; +} + Result DeviceImpl::initVulkanInstanceAndDevice( const InteropHandle* handles, bool useValidationLayer) { @@ -380,10 +389,6 @@ Result DeviceImpl::initVulkanInstanceAndDevice( extendedFeatures.inlineUniformBlockFeatures.pNext = deviceFeatures2.pNext; deviceFeatures2.pNext = &extendedFeatures.inlineUniformBlockFeatures; - // Buffer device address features - extendedFeatures.bufferDeviceAddressFeatures.pNext = deviceFeatures2.pNext; - deviceFeatures2.pNext = &extendedFeatures.bufferDeviceAddressFeatures; - // Ray query features extendedFeatures.rayQueryFeatures.pNext = deviceFeatures2.pNext; deviceFeatures2.pNext = &extendedFeatures.rayQueryFeatures; @@ -396,30 +401,14 @@ Result DeviceImpl::initVulkanInstanceAndDevice( extendedFeatures.accelerationStructureFeatures.pNext = deviceFeatures2.pNext; deviceFeatures2.pNext = &extendedFeatures.accelerationStructureFeatures; - // Subgroup features - extendedFeatures.shaderSubgroupExtendedTypeFeatures.pNext = deviceFeatures2.pNext; - deviceFeatures2.pNext = &extendedFeatures.shaderSubgroupExtendedTypeFeatures; - // Extended dynamic states extendedFeatures.extendedDynamicStateFeatures.pNext = deviceFeatures2.pNext; deviceFeatures2.pNext = &extendedFeatures.extendedDynamicStateFeatures; - // Timeline Semaphore - extendedFeatures.timelineFeatures.pNext = deviceFeatures2.pNext; - deviceFeatures2.pNext = &extendedFeatures.timelineFeatures; - - // Float16 - extendedFeatures.float16Features.pNext = deviceFeatures2.pNext; - deviceFeatures2.pNext = &extendedFeatures.float16Features; - // 16-bit storage extendedFeatures.storage16BitFeatures.pNext = deviceFeatures2.pNext; deviceFeatures2.pNext = &extendedFeatures.storage16BitFeatures; - // Atomic64 - extendedFeatures.atomicInt64Features.pNext = deviceFeatures2.pNext; - deviceFeatures2.pNext = &extendedFeatures.atomicInt64Features; - // robustness2 features extendedFeatures.robustness2Features.pNext = deviceFeatures2.pNext; deviceFeatures2.pNext = &extendedFeatures.robustness2Features; @@ -435,6 +424,12 @@ Result DeviceImpl::initVulkanInstanceAndDevice( extendedFeatures.atomicFloatFeatures.pNext = deviceFeatures2.pNext; deviceFeatures2.pNext = &extendedFeatures.atomicFloatFeatures; + if (VK_MAKE_VERSION(majorVersion, minorVersion, 0) >= VK_API_VERSION_1_2) + { + extendedFeatures.vulkan12Features.pNext = deviceFeatures2.pNext; + deviceFeatures2.pNext = &extendedFeatures.vulkan12Features; + } + m_api.vkGetPhysicalDeviceFeatures2(m_api.m_physicalDevice, &deviceFeatures2); if (deviceFeatures2.features.shaderResourceMinLod) @@ -454,15 +449,8 @@ Result DeviceImpl::initVulkanInstanceAndDevice( m_features.add("int16"); } // If we have float16 features then enable - if (extendedFeatures.float16Features.shaderFloat16) + if (extendedFeatures.vulkan12Features.shaderFloat16) { - // Link into the creation features - extendedFeatures.float16Features.pNext = (void*)deviceCreateInfo.pNext; - deviceCreateInfo.pNext = &extendedFeatures.float16Features; - - // Add the Float16 extension - deviceExtensions.add(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME); - // We have half support m_features.add("half"); } @@ -480,13 +468,8 @@ Result DeviceImpl::initVulkanInstanceAndDevice( m_features.add("16-bit-storage"); } - if (extendedFeatures.atomicInt64Features.shaderBufferInt64Atomics) + if (extendedFeatures.vulkan12Features.shaderBufferInt64Atomics) { - // Link into the creation features - extendedFeatures.atomicInt64Features.pNext = (void*)deviceCreateInfo.pNext; - deviceCreateInfo.pNext = &extendedFeatures.atomicInt64Features; - - deviceExtensions.add(VK_KHR_SHADER_ATOMIC_INT64_EXTENSION_NAME); m_features.add("atomic-int64"); } @@ -500,12 +483,8 @@ Result DeviceImpl::initVulkanInstanceAndDevice( m_features.add("atomic-float"); } - if (extendedFeatures.timelineFeatures.timelineSemaphore) + if (extendedFeatures.vulkan12Features.timelineSemaphore) { - // Link into the creation features - extendedFeatures.timelineFeatures.pNext = (void*)deviceCreateInfo.pNext; - deviceCreateInfo.pNext = &extendedFeatures.timelineFeatures; - deviceExtensions.add(VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME); m_features.add("timeline-semaphore"); } @@ -518,12 +497,8 @@ Result DeviceImpl::initVulkanInstanceAndDevice( m_features.add("extended-dynamic-states"); } - if (extendedFeatures.shaderSubgroupExtendedTypeFeatures.shaderSubgroupExtendedTypes) + if (extendedFeatures.vulkan12Features.shaderSubgroupExtendedTypes) { - extendedFeatures.shaderSubgroupExtendedTypeFeatures.pNext = - (void*)deviceCreateInfo.pNext; - deviceCreateInfo.pNext = &extendedFeatures.shaderSubgroupExtendedTypeFeatures; - deviceExtensions.add(VK_KHR_SHADER_SUBGROUP_EXTENDED_TYPES_EXTENSION_NAME); m_features.add("shader-subgroup-extended-types"); } @@ -554,12 +529,8 @@ Result DeviceImpl::initVulkanInstanceAndDevice( m_features.add("sm_6_6"); } - if (extendedFeatures.bufferDeviceAddressFeatures.bufferDeviceAddress) + if (extendedFeatures.vulkan12Features.bufferDeviceAddress) { - extendedFeatures.bufferDeviceAddressFeatures.pNext = (void*)deviceCreateInfo.pNext; - deviceCreateInfo.pNext = &extendedFeatures.bufferDeviceAddressFeatures; - deviceExtensions.add(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME); - m_features.add("buffer-device-address"); } @@ -589,6 +560,14 @@ Result DeviceImpl::initVulkanInstanceAndDevice( m_features.add("realtime-clock"); } + if (_hasAnySetBits( + extendedFeatures.vulkan12Features, + offsetof(VkPhysicalDeviceVulkan12Features, pNext) + sizeof(void*))) + { + extendedFeatures.vulkan12Features.pNext = (void*)deviceCreateInfo.pNext; + deviceCreateInfo.pNext = &extendedFeatures.vulkan12Features; + } + VkPhysicalDeviceProperties2 extendedProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 }; VkPhysicalDeviceRayTracingPipelinePropertiesKHR rtProps = { @@ -1505,14 +1484,23 @@ Result DeviceImpl::createTextureResource( Result DeviceImpl::createBufferResource( const IBufferResource::Desc& descIn, const void* initData, IBufferResource** outResource) { + return createBufferResourceImpl(descIn, 0, initData, outResource); +} + +Result DeviceImpl::createBufferResourceImpl( + const IBufferResource::Desc& descIn, + VkBufferUsageFlags additionalUsageFlag, + const void* initData, + IBufferResource** outResource) +{ BufferResource::Desc desc = fixupBufferDesc(descIn); const Size bufferSize = desc.sizeInBytes; VkMemoryPropertyFlags reqMemoryProperties = 0; - VkBufferUsageFlags usage = _calcBufferUsageFlags(desc.allowedStates); - if (m_api.m_extendedFeatures.bufferDeviceAddressFeatures.bufferDeviceAddress) + VkBufferUsageFlags usage = _calcBufferUsageFlags(desc.allowedStates) | additionalUsageFlag; + if (m_api.m_extendedFeatures.vulkan12Features.bufferDeviceAddress) { usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT; } |
