Skip to content

Commit

Permalink
[Vulkan] Fix conservative raster validation error
Browse files Browse the repository at this point in the history
VK_EXT_conservative_rasterization must be enabled for conservative
rasterization to work properly. Likewise, the pNext chain of
VkPipelineRasterizationStateCreateInfo should not contain a
struct of that extension if it is not used.
  • Loading branch information
hyazinthh committed Apr 18, 2024
1 parent 664499b commit e7ed442
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/Aardvark.Rendering.Vulkan/Core/Platform.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module Instance =
let ShaderSubgroupVote = EXTShaderSubgroupVote.Name
let ShaderSubgroupBallot = EXTShaderSubgroupBallot.Name

let ConservativeRasterization = EXTConservativeRasterization.Name

let Debug = [
EXTDebugReport.Name
EXTDebugUtils.Name
Expand Down
26 changes: 16 additions & 10 deletions src/Aardvark.Rendering.Vulkan/Management/ResourceManager.fs
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,8 @@ module Resources =
inherit AbstractPointerResourceWithEquality<VkPipelineRasterizationStateCreateInfo>(owner, key)

override x.Free(info : VkPipelineRasterizationStateCreateInfo) =
Marshal.FreeHGlobal info.pNext
if info.pNext <> 0n then
Marshal.FreeHGlobal info.pNext

override x.Compute(user, token, renderToken) =
let depthClamp = depthClamp.GetValue(user, token, renderToken)
Expand All @@ -977,18 +978,23 @@ module Resources =
let conservativeRaster = conservativeRaster.GetValue(user, token, renderToken)
let state = RasterizerState.create conservativeRaster depthClamp bias cull front fill

let conservativeRaster =
VkPipelineRasterizationConservativeStateCreateInfoEXT(
VkPipelineRasterizationConservativeStateCreateFlagsEXT.None,
(if conservativeRaster then VkConservativeRasterizationModeEXT.Overestimate else VkConservativeRasterizationModeEXT.Disabled),
0.0f
)
let pConservativeRaster =
if conservativeRaster then
let info =
VkPipelineRasterizationConservativeStateCreateInfoEXT(
VkPipelineRasterizationConservativeStateCreateFlagsEXT.None,
VkConservativeRasterizationModeEXT.Overestimate,
0.0f
)

let pConservativeRaster = NativePtr.alloc<VkPipelineRasterizationConservativeStateCreateInfoEXT> 1
conservativeRaster |> NativePtr.write pConservativeRaster
let ptr = NativePtr.alloc<VkPipelineRasterizationConservativeStateCreateInfoEXT> 1
info |> NativePtr.write ptr
NativePtr.toNativeInt ptr
else
0n

VkPipelineRasterizationStateCreateInfo(
NativePtr.toNativeInt pConservativeRaster,
pConservativeRaster,
VkPipelineRasterizationStateCreateFlags.None,
(if state.depthClampEnable then 1u else 0u),
(if state.rasterizerDiscardEnable then 1u else 0u),
Expand Down
1 change: 1 addition & 0 deletions src/Aardvark.Rendering.Vulkan/Runtime/Headless.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type HeadlessVulkanApplication(debug : IDebugConfig, instanceExtensions : list<s
yield Instance.Extensions.ShaderSubgroupVote
yield Instance.Extensions.ShaderSubgroupBallot
yield Instance.Extensions.GetPhysicalDeviceProperties2
yield Instance.Extensions.ConservativeRasterization

yield! Instance.Extensions.Raytracing
yield! Instance.Extensions.Sharing
Expand Down
8 changes: 4 additions & 4 deletions src/Aardvark.SceneGraph/Pools/ManagedTracePool.fs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ and ManagedTracePool(runtime : IRuntime, signature : TraceObjectSignature,
member x.GetVertexAttribute(semantic : Symbol) =
match x.TryGetVertexAttribute semantic with
| Some attr -> attr
| None _ -> failf "could not find vertex attribute '%A'" semantic
| None -> failf "could not find vertex attribute '%A'" semantic

member x.TryGetFaceAttribute(semantic : Symbol) =
faceAttributeBuffers |> Map.tryFind semantic
Expand All @@ -781,7 +781,7 @@ and ManagedTracePool(runtime : IRuntime, signature : TraceObjectSignature,
member x.GetFaceAttribute(semantic : Symbol) =
match x.TryGetFaceAttribute semantic with
| Some attr -> attr
| None _ -> failf "could not find face attribute '%A'" semantic
| None -> failf "could not find face attribute '%A'" semantic

member x.TryGetGeometryAttribute(semantic : Symbol) =
geometryAttributeBuffers |> Map.tryFind semantic
Expand All @@ -790,7 +790,7 @@ and ManagedTracePool(runtime : IRuntime, signature : TraceObjectSignature,
member x.GetGeometryAttribute(semantic : Symbol) =
match x.TryGetGeometryAttribute semantic with
| Some attr -> attr
| None _ -> failf "could not find geometry attribute '%A'" semantic
| None -> failf "could not find geometry attribute '%A'" semantic

member x.TryGetInstanceAttribute(semantic : Symbol) =
instanceAttributeBuffers |> Map.tryFind semantic
Expand All @@ -799,7 +799,7 @@ and ManagedTracePool(runtime : IRuntime, signature : TraceObjectSignature,
member x.GetInstanceAttribute(semantic : Symbol) =
match x.TryGetInstanceAttribute semantic with
| Some attr -> attr
| None _ -> failf "could not find instance attribute '%A'" semantic
| None -> failf "could not find instance attribute '%A'" semantic

member x.Dispose() =
lock x (fun _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type VulkanApplication(debug : IDebugConfig, chooseDevice : list<PhysicalDevice>
yield Instance.Extensions.ShaderSubgroupVote
yield Instance.Extensions.ShaderSubgroupBallot
yield Instance.Extensions.GetPhysicalDeviceProperties2
yield Instance.Extensions.ConservativeRasterization

yield! Instance.Extensions.Raytracing
yield! Instance.Extensions.Sharing
Expand Down

0 comments on commit e7ed442

Please sign in to comment.