Skip to content

Commit bb8d9f0

Browse files
committed
[Vulkan] Add format feature check for render pass creation
1 parent 690a2b0 commit bb8d9f0

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- [GL] Fixed blend modes not being toggled properly per attachment
22
- [Vulkan] Fixed VK_ERROR_OUT_OF_POOL_MEMORY error on some platforms when using raytracing
3+
- [Vulkan] Added check for format features when creating a render pass
34

45
### 5.5.16
56
- now using `glEnablei/glDisablei` for BlendModes.

src/Aardvark.Rendering.Vulkan/Resources/Pipeline/RenderPass.fs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ open Aardvark.Base
44
open Aardvark.Rendering
55
open Aardvark.Rendering.Vulkan
66
open System.Runtime.CompilerServices
7-
open Microsoft.FSharp.NativeInterop
8-
9-
#nowarn "9"
10-
// #nowarn "51"
11-
127

138
type RenderPass =
149
class
@@ -63,14 +58,14 @@ module RenderPass =
6358
[<AutoOpen>]
6459
module private Utilities =
6560

66-
let rec tryFindFormat (device : Device) (fmt : VkFormat) =
67-
match device.PhysicalDevice.GetFormatFeatures(VkImageTiling.Optimal, fmt) with
68-
| VkFormatFeatureFlags.None ->
69-
match fmt.NextBetter with
70-
| Some better -> tryFindFormat device better
71-
| None -> None
72-
| _ ->
73-
Some fmt
61+
type Device with
62+
member x.TryFindFormat (format: VkFormat, features: VkFormatFeatureFlags) =
63+
let flags = x.PhysicalDevice.GetFormatFeatures(VkImageTiling.Optimal, format)
64+
if flags.HasFlag features then Some format
65+
else
66+
match format.NextBetter with
67+
| Some better -> x.TryFindFormat(better, features)
68+
| None -> None
7469

7570
let getLoadStoreOp flag =
7671
if flag then
@@ -116,10 +111,15 @@ module RenderPass =
116111
colorAttachments
117112
|> Map.toArray
118113
|> Array.mapi (fun index (slot, att) ->
114+
let format =
115+
match device.TryFindFormat(VkFormat.ofTextureFormat att.Format, VkFormatFeatureFlags.ColorAttachmentBit) with
116+
| Some fmt -> fmt
117+
| _ -> failf $"Format {att.Format} cannot be used for color attachments ({att.Name})"
118+
119119
let description =
120120
VkAttachmentDescription(
121121
VkAttachmentDescriptionFlags.None,
122-
VkFormat.ofTextureFormat att.Format,
122+
format,
123123
unbox<VkSampleCountFlags> samples,
124124
VkAttachmentLoadOp.Load, VkAttachmentStoreOp.Store,
125125
VkAttachmentLoadOp.DontCare, VkAttachmentStoreOp.DontCare,
@@ -136,9 +136,9 @@ module RenderPass =
136136
let depth =
137137
depthStencilAttachment |> Option.map (fun fmt ->
138138
let format =
139-
match tryFindFormat device <| VkFormat.ofTextureFormat fmt with
139+
match device.TryFindFormat(VkFormat.ofTextureFormat fmt, VkFormatFeatureFlags.DepthStencilAttachmentBit) with
140140
| Some fmt -> fmt
141-
| None -> failf "could not get supported format for %A" fmt
141+
| None -> failf $"Format {fmt} cannot be used for depth-stencil attachments"
142142

143143
let depthLoadOp, depthStoreOp = getLoadStoreOp <| VkFormat.hasDepth format
144144
let stencilLoadOp, stencilStoreOp = getLoadStoreOp <| VkFormat.hasStencil format

0 commit comments

Comments
 (0)