Skip to content

Commit 249a0a2

Browse files
authored
add DXC and debug examples (#760)
* add download script * add basic example * basic debug example * ruff format * diable examples correctly * renderdoc launcher script * add more links * write docs * fix duplicate * fix typo * simplify check * label cube example * support more os * add debug markers * improve intro docstring * avoid env var * include troubleshooting help * simply bind groups in cube example * cat related typo * remove canvas type hint * ruff format
1 parent 0580939 commit 249a0a2

File tree

5 files changed

+403
-60
lines changed

5 files changed

+403
-60
lines changed

docs/backends.rst

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ It also works out of the box, because the wgpu-native DLL is shipped with wgpu-p
4545
The wgpu_native backend provides a few extra functionalities:
4646

4747
.. py:function:: wgpu.backends.wgpu_native.request_device_sync(adapter, trace_path, *, label="", required_features, required_limits, default_queue)
48+
4849
An alternative to :func:`wgpu.GPUAdapter.request_adapter`, that streams a trace
4950
of all low level calls to disk, so the visualization can be replayed (also on other systems),
5051
investigated, and debugged.
@@ -166,9 +167,9 @@ they reduce driver overhead on the CPU.
166167

167168
The first two require that you enable the feature ``"multi-draw-indirect"``.
168169

169-
.. py:function:: wgpu.backends.wgpu_native.multi_draw_indirect(render_pass_encoder, buffer, *, offset=0, count):
170+
.. py:function:: wgpu.backends.wgpu_native.multi_draw_indirect(render_pass_encoder, buffer, *, offset=0, count)
170171
171-
Equivalent to::
172+
Equivalent to::
172173
for i in range(count):
173174
render_pass_encoder.draw_indirect(buffer, offset + i * 16)
174175

@@ -179,9 +180,9 @@ The first two require that you enable the feature ``"multi-draw-indirect"``.
179180
Must be a multiple of 4.
180181
:param count: The number of draw operations to perform.
181182

182-
.. py:function:: wgpu.backends.wgpu_native.multi_draw_indexed_indirect(render_pass_encoder, buffer, *, offset=0, count):
183+
.. py:function:: wgpu.backends.wgpu_native.multi_draw_indexed_indirect(render_pass_encoder, buffer, *, offset=0, count)
183184
184-
Equivalent to::
185+
Equivalent to::
185186

186187
for i in range(count):
187188
render_pass_encoder.draw_indexed_indirect(buffer, offset + i * 2-)
@@ -199,9 +200,9 @@ They are identical to the previous two, except that the ``count`` argument is re
199200
three arguments. The value at ``count_buffer_offset`` in ``count_buffer`` is treated as
200201
an unsigned 32-bit integer. The ``count`` is the minimum of this value and ``max_count``.
201202

202-
.. py:function:: wgpu.backends.wgpu_native.multi_draw_indirect_count(render_pass_encoder, buffer, *, offset=0, count_buffer, count_offset=0, max_count):
203+
.. py:function:: wgpu.backends.wgpu_native.multi_draw_indirect_count(render_pass_encoder, buffer, *, offset=0, count_buffer, count_offset=0, max_count)
203204
204-
Equivalent to::
205+
Equivalent to::
205206

206207
count = min(<u32 at count_buffer_offset in count_buffer>, max_count)
207208
for i in range(count):
@@ -217,9 +218,9 @@ an unsigned 32-bit integer. The ``count`` is the minimum of this value and ``max
217218
Must be a multiple of 4.
218219
:param max_count: The maximum number of draw operations to perform.
219220

220-
.. py:function:: wgpu.backends.wgpu_native.multi_draw_indexed_indirect_count(render_pass_encoder, buffer, *, offset=0, count_buffer, count_offset=0, max_count):
221+
.. py:function:: wgpu.backends.wgpu_native.multi_draw_indexed_indirect_count(render_pass_encoder, buffer, *, offset=0, count_buffer, count_offset=0, max_count)
221222
222-
Equivalent to::
223+
Equivalent to::
223224

224225
count = min(<u32 at count_buffer_offset in count_buffer>, max_count)
225226
for i in range(count):
@@ -246,13 +247,13 @@ both enabled.
246247

247248
When ``write_timestamp`` is called with a render pass or compute pass as its first
248249
argument, a timestamp is written to the indicated query set at the indicated index at
249-
that point in thie queue. This usage requires
250+
that point in this queue. This usage requires
250251
that the features ``"timestamp-query"`` and ``"timestamp-query-inside-passes"`` are
251252
both enabled.
252253

253-
.. py:function:: wgpu.backends.wgpu_native.write_timestamp(encoder, query_set, query_index):
254+
.. py:function:: wgpu.backends.wgpu_native.write_timestamp(encoder, query_set, query_index)
254255
255-
Writes a timestamp to the timestamp query set and the indicated index.
256+
Writes a timestamp to the timestamp query set and the indicated index.
256257

257258
:param encoder: The ComputePassEncoder, RenderPassEncoder, or CommandEncoder.
258259
:param query_set: The timestamp query set into which to save the result.
@@ -293,7 +294,7 @@ the number of statistics chosen.
293294
The statistics are always output to the query set in the order above, even if they are
294295
given in a different order in the list.
295296

296-
.. py:function:: wgpu.backends.wgpu_native.create_statistics_query_set(device, count, statistics):
297+
.. py:function:: wgpu.backends.wgpu_native.create_statistics_query_set(device, count, statistics)
297298
298299
Create a query set that could hold count entries for the specified statistics.
299300
The statistics are specified as a list of strings.
@@ -302,20 +303,50 @@ given in a different order in the list.
302303
:param count: Number of entries that go into the query set.
303304
:param statistics: A sequence of strings giving the desired statistics.
304305

305-
.. py:function:: wgpu.backends.wgpu_native.begin_pipeline_statistics_query(encoder, query_set, index):
306+
.. py:function:: wgpu.backends.wgpu_native.begin_pipeline_statistics_query(encoder, query_set, index)
306307
307308
Start collecting statistics.
308309

309310
:param encoder: The ComputePassEncoder or RenderPassEncoder.
310311
:param query_set: The query set into which to save the result.
311312
:param index: The index of the query set into which to write the result.
312313

313-
.. py:function:: wgpu.backends.wgpu_native.begin_pipeline_statistics_query(encoder, query_set, index):
314+
.. py:function:: wgpu.backends.wgpu_native.end_pipeline_statistics_query(encoder, query_set, index)
314315
315316
Stop collecting statistics and write them into the query set.
316317

317318
:param encoder: The ComputePassEncoder or RenderPassEncoder.
318319

320+
.. py:function:: wgpu.backends.wgpu_native.set_instance_extras(backends, flags, dx12_compiler, gles3_minor_version, fence_behavior, dxil_path, dxc_path, dxc_max_shader_model)
321+
322+
Sets the global instance with extras. Needs to be called before instance is created (in enumerate_adapters or request_adapter).
323+
324+
:param backends: bitflags as list[str], which backends to enable on the instance level. Defaults to ``["All"]``. Can be any combination of ``["Vulkan", "GL", "Metal", "DX12", "BrowserWebGPU"]`` or the premade combinations ``["All", "Primary", "secondary"]``. Note that your device needs to support these backends, for detailed information see https://docs.rs/wgpu/latest/wgpu/struct.Backends.html
325+
:param flags: bitflags as list[str], debug flags for the compiler. Defaults to ``["Default"]``, can be any combination of ``["Debug", "Validation", "DiscardHalLabels"]``.
326+
:param dx12_compiler: enum/str, either "Fxc", "Dxc" or "Undefined". Defaults to "Fxc" same as "Undefined". Dxc requires additional library files.
327+
:param gles3_minor_version: enum/int 0, 1 or 2. Defaults to "Atomic" (handled by driver).
328+
:param fence_behavior: enum/int, "Normal" or "AutoFinish", Default to "Normal".
329+
:param dxil_path: str, path to dxil.dll, defaults to ``None``. None looks in the resource directory.
330+
:param dxc_path: str, path to dxcompiler.dll, defaults to ``None``. None looks in the resource directory.
331+
:param dxc_max_shader_model: float between 6.0 and 6.7, Maximum shader model the given dll supports. Defaults to 6.5.
332+
333+
Use like the following before the instance is created, which happens during request_adapter or enumerate_adapters.
334+
335+
.. code-block:: py
336+
337+
import wgpu
338+
from wgpu.backends.wgpu_native.extras import set_instance_extras
339+
set_instance_extras(
340+
backends=["Vulkan"],
341+
flags=["Debug"],
342+
)
343+
344+
# ...
345+
346+
for a in wgpu.gpu.enumerate_adapters_sync():
347+
print(a.summary)
348+
349+
For additional usage examples look at `extras_dxc.py` and `extras_debug.py` in the examples directory.
319350

320351
The js_webgpu backend
321352
---------------------

0 commit comments

Comments
 (0)