Skip to content

Commit

Permalink
[Vulkan] Avoid enabling features of disabled extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed May 13, 2024
1 parent b647753 commit 6332233
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/Aardvark.Rendering.Vulkan/Core/Device.fs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ type Device internal(dev : PhysicalDevice, wantedExtensions : list<string>) as t
// TODO: Do we really want to enable all available features?
// Does this have real performance implications?
use pNext =
DeviceFeatures.toNativeChain dev.Features
dev.GetFeatures (fun e -> extensions |> Array.contains e)
|> DeviceFeatures.toNativeChain
|> if isGroup then VkStructChain.add groupInfo else id

let! pInfo =
Expand Down
46 changes: 26 additions & 20 deletions src/Aardvark.Rendering.Vulkan/Core/Platform.fs
Original file line number Diff line number Diff line change
Expand Up @@ -487,32 +487,36 @@ and PhysicalDevice internal(instance : Instance, handle : VkPhysicalDevice) =
let hasExtension (name : string) =
globalExtensions |> Array.exists (fun e -> e.name = name)

let features =
let queryFeatures =
let inline readOrEmpty (ptr : nativeptr< ^a>) =
if NativePtr.isNull ptr then
((^a) : (static member Empty : ^a) ())
else
!!ptr

let f, pm, ycbcr, s16, vp, sdp, idx, rtp, acc, rq, bda =
use chain = new VkStructChain()
let pMem = chain.Add<VkPhysicalDeviceProtectedMemoryFeatures>()
let pYcbcr = chain.Add<VkPhysicalDeviceSamplerYcbcrConversionFeatures>()
let p16bit = chain.Add<VkPhysicalDevice16BitStorageFeatures>()
let pVarPtrs = chain.Add<VkPhysicalDeviceVariablePointersFeatures>()
let pDrawParams = chain.Add<VkPhysicalDeviceShaderDrawParametersFeatures>()
let pIdx = if hasExtension EXTDescriptorIndexing.Name then chain.Add<VkPhysicalDeviceDescriptorIndexingFeaturesEXT>() else NativePtr.zero
let pRTP = if hasExtension KHRRayTracingPipeline.Name then chain.Add<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>() else NativePtr.zero
let pAcc = if hasExtension KHRAccelerationStructure.Name then chain.Add<VkPhysicalDeviceAccelerationStructureFeaturesKHR>() else NativePtr.zero
let pRQ = if hasExtension KHRRayQuery.Name then chain.Add<VkPhysicalDeviceRayQueryFeaturesKHR>() else NativePtr.zero
let pDevAddr = if hasExtension KHRBufferDeviceAddress.Name then chain.Add<VkPhysicalDeviceBufferDeviceAddressFeaturesKHR>() else NativePtr.zero
let pFeatures = chain.Add<VkPhysicalDeviceFeatures2>()

VkRaw.vkGetPhysicalDeviceFeatures2(handle, VkStructChain.toNativePtr chain)
(!!pFeatures).features, !!pMem, !!pYcbcr, !!p16bit, !!pVarPtrs, !!pDrawParams, readOrEmpty pIdx,
readOrEmpty pRTP, readOrEmpty pAcc, readOrEmpty pRQ, readOrEmpty pDevAddr

DeviceFeatures.create pm ycbcr s16 vp sdp idx rtp acc rq bda f
fun (hasExtension: string -> bool) ->
let f, pm, ycbcr, s16, vp, sdp, idx, rtp, acc, rq, bda =
use chain = new VkStructChain()
let pMem = chain.Add<VkPhysicalDeviceProtectedMemoryFeatures>()
let pYcbcr = chain.Add<VkPhysicalDeviceSamplerYcbcrConversionFeatures>()
let p16bit = chain.Add<VkPhysicalDevice16BitStorageFeatures>()
let pVarPtrs = chain.Add<VkPhysicalDeviceVariablePointersFeatures>()
let pDrawParams = chain.Add<VkPhysicalDeviceShaderDrawParametersFeatures>()
let pIdx = if hasExtension EXTDescriptorIndexing.Name then chain.Add<VkPhysicalDeviceDescriptorIndexingFeaturesEXT>() else NativePtr.zero
let pRTP = if hasExtension KHRRayTracingPipeline.Name then chain.Add<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>() else NativePtr.zero
let pAcc = if hasExtension KHRAccelerationStructure.Name then chain.Add<VkPhysicalDeviceAccelerationStructureFeaturesKHR>() else NativePtr.zero
let pRQ = if hasExtension KHRRayQuery.Name then chain.Add<VkPhysicalDeviceRayQueryFeaturesKHR>() else NativePtr.zero
let pDevAddr = if hasExtension KHRBufferDeviceAddress.Name then chain.Add<VkPhysicalDeviceBufferDeviceAddressFeaturesKHR>() else NativePtr.zero
let pFeatures = chain.Add<VkPhysicalDeviceFeatures2>()

VkRaw.vkGetPhysicalDeviceFeatures2(handle, VkStructChain.toNativePtr chain)
(!!pFeatures).features, !!pMem, !!pYcbcr, !!p16bit, !!pVarPtrs, !!pDrawParams, readOrEmpty pIdx,
readOrEmpty pRTP, readOrEmpty pAcc, readOrEmpty pRQ, readOrEmpty pDevAddr

DeviceFeatures.create pm ycbcr s16 vp sdp idx rtp acc rq bda f

let features =
queryFeatures hasExtension

let properties, raytracingProperties =
use chain = new VkStructChain()
Expand Down Expand Up @@ -749,6 +753,8 @@ and PhysicalDevice internal(instance : Instance, handle : VkPhysicalDevice) =
member x.Features : DeviceFeatures = features
member x.Limits : DeviceLimits = limits

member internal x.GetFeatures(hasExtension: string -> bool) = queryFeatures hasExtension

abstract member DeviceMask : uint32
default x.DeviceMask = deviceMask

Expand Down

0 comments on commit 6332233

Please sign in to comment.