Pārlūkot izejas kodu

sokol_gfx.h d3d11: add sg_desc.d3d11_shader_debugging bool flag (#1101)

Fixes #1043
Andre Weissflog 1 gadu atpakaļ
vecāks
revīzija
189843bf4f
2 mainītis faili ar 28 papildinājumiem un 1 dzēšanām
  1. 14 0
      CHANGELOG.md
  2. 14 1
      sokol_gfx.h

+ 14 - 0
CHANGELOG.md

@@ -1,5 +1,19 @@
 ## Updates
 ## Updates
 
 
+### 01-Sep-2024
+
+- sokol_gfx.h d3d11: added a new configuration flag `d3d11_shader_debugging`
+  to the `sg_desc` struct. When this is true, D3D11 shaders which are provided
+  as HLSL source code will be compiled with debug information and no optimization
+  which allows shader debugging in tools like RenderDoc. If you use `sokol-shdc`
+  to build shaders, just omit the `--bytecode / -b` cmdline option to get
+  HLSL source code instead of bytecode, if you use the `fips` build system
+  wrapper (like the `sokol-samples` project), just replace the cmake macro
+  `sokol_shader()` with `sokol_shader_debuggable()`.
+
+  For details see issue https://github.com/floooh/sokol/issues/1043
+  and PR: https://github.com/floooh/sokol/pull/1101.
+
 ### 31-Aug-2024
 ### 31-Aug-2024
 
 
 - Some cleanup work in the WebGPU backend bindgroups cache which fixes
 - Some cleanup work in the WebGPU backend bindgroups cache which fixes

+ 14 - 1
sokol_gfx.h

@@ -3889,6 +3889,12 @@ typedef enum sg_log_item {
             before sg_setup() is called
             before sg_setup() is called
         .environment.d3d11.device_context
         .environment.d3d11.device_context
             a pointer to the ID3D11DeviceContext object
             a pointer to the ID3D11DeviceContext object
+        .d3d11_shader_debugging
+            set this to true to compile shaders which are provided as HLSL source
+            code with debug information and without optimization, this allows
+            shader debugging in tools like RenderDoc, to output source code
+            instead of byte code from sokol-shdc, omit the `--binary` cmdline
+            option
 
 
     WebGPU specific:
     WebGPU specific:
         .wgpu_disable_bindgroups_cache
         .wgpu_disable_bindgroups_cache
@@ -4001,6 +4007,7 @@ typedef struct sg_desc {
     int uniform_buffer_size;
     int uniform_buffer_size;
     int max_commit_listeners;
     int max_commit_listeners;
     bool disable_validation;    // disable validation layer even in debug mode, useful for tests
     bool disable_validation;    // disable validation layer even in debug mode, useful for tests
+    bool d3d11_shader_debugging;    // if true, HLSL shaders are compiled with D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION
     bool mtl_force_managed_storage_mode; // for debugging: use Metal managed storage mode for resources even with UMA
     bool mtl_force_managed_storage_mode; // for debugging: use Metal managed storage mode for resources even with UMA
     bool mtl_use_command_buffer_with_retained_references;    // Metal: use a managed MTLCommandBuffer which ref-counts used resources
     bool mtl_use_command_buffer_with_retained_references;    // Metal: use a managed MTLCommandBuffer which ref-counts used resources
     bool wgpu_disable_bindgroups_cache;  // set to true to disable the WebGPU backend BindGroup cache
     bool wgpu_disable_bindgroups_cache;  // set to true to disable the WebGPU backend BindGroup cache
@@ -10712,6 +10719,12 @@ _SOKOL_PRIVATE ID3DBlob* _sg_d3d11_compile_shader(const sg_shader_stage_desc* st
         return NULL;
         return NULL;
     }
     }
     SOKOL_ASSERT(stage_desc->d3d11_target);
     SOKOL_ASSERT(stage_desc->d3d11_target);
+    UINT flags1 = D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR;
+    if (_sg.desc.d3d11_shader_debugging) {
+        flags1 |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
+    } else {
+        flags1 |= D3DCOMPILE_OPTIMIZATION_LEVEL3;
+    }
     ID3DBlob* output = NULL;
     ID3DBlob* output = NULL;
     ID3DBlob* errors_or_warnings = NULL;
     ID3DBlob* errors_or_warnings = NULL;
     HRESULT hr = _sg.d3d11.D3DCompile_func(
     HRESULT hr = _sg.d3d11.D3DCompile_func(
@@ -10722,7 +10735,7 @@ _SOKOL_PRIVATE ID3DBlob* _sg_d3d11_compile_shader(const sg_shader_stage_desc* st
         NULL,                           // pInclude
         NULL,                           // pInclude
         stage_desc->entry ? stage_desc->entry : "main",     // pEntryPoint
         stage_desc->entry ? stage_desc->entry : "main",     // pEntryPoint
         stage_desc->d3d11_target,       // pTarget
         stage_desc->d3d11_target,       // pTarget
-        D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR | D3DCOMPILE_OPTIMIZATION_LEVEL3,   // Flags1
+        flags1,     // Flags1
         0,          // Flags2
         0,          // Flags2
         &output,    // ppCode
         &output,    // ppCode
         &errors_or_warnings);   // ppErrorMsgs
         &errors_or_warnings);   // ppErrorMsgs