Skip to content

Commit 59422ff

Browse files
committed
[Vulkan] Add debug config flag for generating shader debug info
1 parent fba2868 commit 59422ff

8 files changed

Lines changed: 52 additions & 20 deletions

File tree

paket.dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ nuget FShade.Debug ~> 5.6.0
3030

3131
nuget Unofficial.OpenVR ~> 1.1.0
3232
nuget CommonMark.NET ~> 0.15.1
33-
nuget GLSLangSharp ~> 0.4.14
33+
nuget GLSLangSharp ~> 0.5.0
3434

3535
nuget Unofficial.LibTessDotNet ~> 2.0.2
3636
nuget Aardvark.Data.Assimp ~> 1.0.1

paket.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ NUGET
205205
FSharp.Core (>= 4.7)
206206
FuzzySharp (2.0.2)
207207
Gee.External.Capstone (2.3)
208-
GLSLangSharp (0.4.15)
209-
FSharp.Core (>= 5.0)
208+
GLSLangSharp (0.5)
209+
FSharp.Core (>= 8.0)
210210
glTF2Loader (1.1.4-alpha)
211211
NETStandard.Library (>= 1.6.1)
212212
Newtonsoft.Json (>= 10.0.3)

src/Aardvark.Rendering.Vulkan/Core/Common/Config.fs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ type DebugConfig =
123123

124124
/// Verbosity of the logger to be used to print instance and device information.
125125
PlatformInformationVerbosity : int
126+
127+
/// Generate SPIR-V debug information (required to inspect source code in Nsight Graphics).
128+
GenerateShaderDebugInfo : bool
129+
130+
/// Optimize shaders after compiling.
131+
OptimizeShaders : bool
126132
}
127133

128134
member internal x.DebugReportEnabled =
@@ -143,14 +149,16 @@ type DebugConfig =
143149
VerifyShaderCacheIntegrity = false
144150
PlatformInformationVerbosity = 4
145151
PrintShaderCode = false
146-
PrintRenderTaskRecompile = false }
152+
PrintRenderTaskRecompile = false
153+
GenerateShaderDebugInfo = false
154+
OptimizeShaders = true }
147155

148156
/// Enables validation layers, printing warnings and errors.
149157
static member Minimal =
150158
{ DebugConfig.None with
151159
DebugReport = Some DebugReportConfig.Minimal
152160
ValidationLayer = Some ValidationLayerConfig.Standard
153-
PlatformInformationVerbosity = 2}
161+
PlatformInformationVerbosity = 2 }
154162

155163
/// Enables validation layers, printing everything except debug messages.
156164
/// Also prints shader code and render task recompilation.
@@ -165,7 +173,9 @@ type DebugConfig =
165173
{ DebugConfig.Normal with
166174
DebugReport = Some DebugReportConfig.Full
167175
ValidationLayer = Some ValidationLayerConfig.Full
168-
VerifyShaderCacheIntegrity = true }
176+
VerifyShaderCacheIntegrity = true
177+
GenerateShaderDebugInfo = true
178+
OptimizeShaders = false }
169179

170180
interface IDebugConfig
171181

src/Aardvark.Rendering.Vulkan/Core/Device/Device.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type Device private (physicalDevice: PhysicalDevice, wantedExtensions: string se
7979
]
8080

8181
let wantedExtensions =
82-
if instance.DebugConfig.DebugPrintEnabled then
82+
if instance.DebugConfig.DebugPrintEnabled || instance.DebugConfig.GenerateShaderDebugInfo then
8383
List.ofSeq wantedExtensions @ [KHRShaderNonSemanticInfo.Name]
8484
else
8585
List.ofSeq wantedExtensions

src/Aardvark.Rendering.Vulkan/Resources/Raytracing/RaytracingProgram.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ module RaytracingProgram =
351351

352352
let private tryGetCacheFile (device : Device) (id : string) =
353353
device.ShaderCachePath |> Option.map (fun prefix ->
354-
let hash = ShaderProgram.FileCacheName.ofString id
354+
let hash = ShaderProgram.FileCacheName.ofEffectId device id
355355
Path.combine [prefix; hash + ".rtx"]
356356
)
357357

src/Aardvark.Rendering.Vulkan/Resources/Shaders/ComputeProgram.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ module ComputeProgram =
188188
device.GetCached(cache, shader, fun shader ->
189189
match device.ShaderCachePath with
190190
| Some shaderCachePath ->
191-
let fileName = ShaderProgram.FileCacheName.ofString shader.csId
191+
let fileName = ShaderProgram.FileCacheName.ofEffectId device shader.csId
192192
let file = Path.Combine(shaderCachePath, fileName + ".compute")
193193

194194
match tryRead file device with

src/Aardvark.Rendering.Vulkan/Resources/Shaders/ShaderModule.fs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,20 @@ module ShaderModule =
6565
let ofGLSLWithTarget (target : GLSLang.Target) (slot : FShade.ShaderSlot) (info : FShade.GLSL.GLSLShader) (device : Device) =
6666
let siface = info.iface.shaders.[slot]
6767
let defines = [slot.Conditional]
68+
let config = device.DebugConfig
6869

69-
match GLSLang.GLSLang.tryCompileWithTarget target (glslangStage slot) siface.shaderEntry defines info.code with
70+
match GLSLang.GLSLang.tryCompileWithTarget target (glslangStage slot) siface.shaderEntry config.GenerateShaderDebugInfo defines info.code with
7071
| Some binary, _ ->
71-
let binary = GLSLang.GLSLang.optimizeDefault binary
72+
let binary =
73+
if not config.OptimizeShaders then binary
74+
else GLSLang.GLSLang.optimizeDefault binary
75+
7276
let handle = device |> createRaw binary
7377
let result = new ShaderModule(device, handle, slot, binary)
7478
result
7579

7680
| None, err ->
77-
if not device.DebugConfig.PrintShaderCode then
81+
if not config.PrintShaderCode then
7882
ShaderCodeReporting.logLines "Failed to compile shader" info.code
7983

8084
let err = ShaderCodeReporting.normalizeLineEndings err

src/Aardvark.Rendering.Vulkan/Resources/Shaders/ShaderProgram.fs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,31 @@ module ShaderProgram =
339339
let hash = pickler.ComputeHash value
340340
hash.Hash |> Guid |> string
341341

342-
let ofEffectKey (key : EffectCacheKey) =
343-
let colors = key.layout.ColorAttachments |> Map.map (fun _ att -> string att.Name)
344-
let depth = key.layout.DepthStencilAttachment
345-
if key.layout.LayerCount > 1 then
346-
getHash (key.effect.Id, key.topology, colors, depth, key.layout.LayerCount, key.layout.PerLayerUniforms, FShadeConfig.depthRange)
347-
else
348-
getHash (key.effect.Id, colors, depth, FShadeConfig.depthRange)
342+
type private ShaderSignature =
343+
{ id : string
344+
debug : bool
345+
optimized : bool
346+
outputs : Map<int, string * TextureFormat>
347+
layered : Set<string>
348+
layerCount : int
349+
depthRange : Range1d }
350+
351+
let ofEffectKey (device: Device) (key: EffectCacheKey) =
352+
let signature =
353+
let outputs = key.layout.ColorAttachments |> Map.map (fun _ att -> string att.Name, att.Format)
354+
355+
{ id = key.effect.Id
356+
debug = device.DebugConfig.GenerateShaderDebugInfo
357+
optimized = device.DebugConfig.OptimizeShaders
358+
outputs = outputs
359+
layered = key.layout.PerLayerUniforms
360+
layerCount = key.layout.LayerCount
361+
depthRange = FShadeConfig.depthRange }
362+
363+
getHash signature
364+
365+
let ofEffectId (device: Device) (id: string) =
366+
getHash (id, device.DebugConfig.GenerateShaderDebugInfo, device.DebugConfig.OptimizeShaders)
349367

350368
let ofString (value : string) =
351369
getHash value
@@ -590,7 +608,7 @@ module ShaderProgram =
590608
match device.ShaderCachePath with
591609
| Some shaderCachePath ->
592610
let cacheFile =
593-
let name = FileCacheName.ofEffectKey key
611+
let name = FileCacheName.ofEffectKey device key
594612
Path.Combine(shaderCachePath, name + ".effect")
595613

596614
match tryRead None cacheFile device with

0 commit comments

Comments
 (0)