From 6332233c7d32bee102a7033a308adac7c9303b18 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 13 May 2024 17:33:23 +0200 Subject: [PATCH] [Vulkan] Avoid enabling features of disabled extensions --- src/Aardvark.Rendering.Vulkan/Core/Device.fs | 3 +- .../Core/Platform.fs | 46 +++++++++++-------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/Aardvark.Rendering.Vulkan/Core/Device.fs b/src/Aardvark.Rendering.Vulkan/Core/Device.fs index 42045ebb..f9f89ac4 100644 --- a/src/Aardvark.Rendering.Vulkan/Core/Device.fs +++ b/src/Aardvark.Rendering.Vulkan/Core/Device.fs @@ -268,7 +268,8 @@ type Device internal(dev : PhysicalDevice, wantedExtensions : list) 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 = diff --git a/src/Aardvark.Rendering.Vulkan/Core/Platform.fs b/src/Aardvark.Rendering.Vulkan/Core/Platform.fs index e326b3ac..a7c9405c 100644 --- a/src/Aardvark.Rendering.Vulkan/Core/Platform.fs +++ b/src/Aardvark.Rendering.Vulkan/Core/Platform.fs @@ -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() - let pYcbcr = chain.Add() - let p16bit = chain.Add() - let pVarPtrs = chain.Add() - let pDrawParams = chain.Add() - let pIdx = if hasExtension EXTDescriptorIndexing.Name then chain.Add() else NativePtr.zero - let pRTP = if hasExtension KHRRayTracingPipeline.Name then chain.Add() else NativePtr.zero - let pAcc = if hasExtension KHRAccelerationStructure.Name then chain.Add() else NativePtr.zero - let pRQ = if hasExtension KHRRayQuery.Name then chain.Add() else NativePtr.zero - let pDevAddr = if hasExtension KHRBufferDeviceAddress.Name then chain.Add() else NativePtr.zero - let pFeatures = chain.Add() - - 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() + let pYcbcr = chain.Add() + let p16bit = chain.Add() + let pVarPtrs = chain.Add() + let pDrawParams = chain.Add() + let pIdx = if hasExtension EXTDescriptorIndexing.Name then chain.Add() else NativePtr.zero + let pRTP = if hasExtension KHRRayTracingPipeline.Name then chain.Add() else NativePtr.zero + let pAcc = if hasExtension KHRAccelerationStructure.Name then chain.Add() else NativePtr.zero + let pRQ = if hasExtension KHRRayQuery.Name then chain.Add() else NativePtr.zero + let pDevAddr = if hasExtension KHRBufferDeviceAddress.Name then chain.Add() else NativePtr.zero + let pFeatures = chain.Add() + + 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() @@ -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