@@ -4,11 +4,6 @@ open Aardvark.Base
4
4
open Aardvark.Rendering
5
5
open Aardvark.Rendering .Vulkan
6
6
open System.Runtime .CompilerServices
7
- open Microsoft.FSharp .NativeInterop
8
-
9
- #nowarn " 9"
10
- // #nowarn "51"
11
-
12
7
13
8
type RenderPass =
14
9
class
@@ -63,14 +58,14 @@ module RenderPass =
63
58
[<AutoOpen>]
64
59
module private Utilities =
65
60
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
74
69
75
70
let getLoadStoreOp flag =
76
71
if flag then
@@ -116,10 +111,15 @@ module RenderPass =
116
111
colorAttachments
117
112
|> Map.toArray
118
113
|> 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
+
119
119
let description =
120
120
VkAttachmentDescription(
121
121
VkAttachmentDescriptionFlags.None,
122
- VkFormat.ofTextureFormat att.Format ,
122
+ format ,
123
123
unbox< VkSampleCountFlags> samples,
124
124
VkAttachmentLoadOp.Load, VkAttachmentStoreOp.Store,
125
125
VkAttachmentLoadOp.DontCare, VkAttachmentStoreOp.DontCare,
@@ -136,9 +136,9 @@ module RenderPass =
136
136
let depth =
137
137
depthStencilAttachment |> Option.map ( fun fmt ->
138
138
let format =
139
- match tryFindFormat device <| VkFormat.ofTextureFormat fmt with
139
+ match device.TryFindFormat ( VkFormat.ofTextureFormat fmt, VkFormatFeatureFlags.DepthStencilAttachmentBit ) with
140
140
| 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 "
142
142
143
143
let depthLoadOp , depthStoreOp = getLoadStoreOp <| VkFormat.hasDepth format
144
144
let stencilLoadOp , stencilStoreOp = getLoadStoreOp <| VkFormat.hasStencil format
0 commit comments