|
2 | 2 | from typing import List
|
3 | 3 |
|
4 | 4 | from . import GPUCommandEncoder, GPUComputePassEncoder, GPURenderPassEncoder
|
5 |
| -from ._api import Dict, GPUBindGroupLayout, enums, logger, structs |
| 5 | +from ._api import ( |
| 6 | + Dict, |
| 7 | + GPUBindGroupLayout, |
| 8 | + enums, |
| 9 | + logger, |
| 10 | + structs, |
| 11 | + new_struct_p, |
| 12 | + to_c_string_view, |
| 13 | +) |
6 | 14 | from ...enums import Enum
|
| 15 | +from ._helpers import get_wgpu_instance |
7 | 16 |
|
8 | 17 |
|
9 | 18 | # NOTE: these functions represent backend-specific extra API.
|
@@ -172,3 +181,48 @@ def write_timestamp(encoder, query_set, query_index):
|
172 | 181 | encoder, (GPURenderPassEncoder, GPUComputePassEncoder, GPUCommandEncoder)
|
173 | 182 | )
|
174 | 183 | encoder._write_timestamp(query_set, query_index)
|
| 184 | + |
| 185 | + |
| 186 | +def set_instance_extras( |
| 187 | + backends=0, # default all |
| 188 | + flags=0, |
| 189 | + dx12_compiler="fxc", # default, alternative "dxc" |
| 190 | + gles3_minor_version=0, |
| 191 | + fence_behavior=0, |
| 192 | + dxil_path: os.PathLike | None = None, |
| 193 | + dxc_path: os.PathLike | None = None, |
| 194 | + dxc_max_shader_model: float = 6.5, |
| 195 | +): |
| 196 | + """ |
| 197 | + Sets the global instance with extras. |
| 198 | + """ |
| 199 | + # TODO document and explain, find reference for defaults |
| 200 | + |
| 201 | + # maybe include wgpu.h enums and flags in our codegen? (especially make sure to evaluate the flags) |
| 202 | + compiler_map = { |
| 203 | + "undefined": 0, # lib.WGPUDx12Compiler_Undefined |
| 204 | + "fxc": 1, # lib.WGPUDx12Compiler_Fxc |
| 205 | + "dxc": 2, # lib.WGPUDx12Compiler_Dxc |
| 206 | + } |
| 207 | + c_dx12_compiler = compiler_map.get(dx12_compiler, 0) # default to "undefined"? |
| 208 | + # the rust conv layer does all the checking, so fallbacks are handled there. |
| 209 | + |
| 210 | + # TODO: translate to C enums/flags |
| 211 | + # H: chain: WGPUChainedStruct, backends: WGPUInstanceBackend/int, flags: WGPUInstanceFlag/int, dx12ShaderCompiler: WGPUDx12Compiler, gles3MinorVersion: WGPUGles3MinorVersion, glFenceBehaviour: WGPUGLFenceBehaviour, dxilPath: WGPUStringView, dxcPath: WGPUStringView, dxcMaxShaderModel: WGPUDxcMaxShaderModel |
| 212 | + c_extras = new_struct_p( |
| 213 | + "WGPUInstanceExtras *", |
| 214 | + # not used: chain |
| 215 | + backends=backends, |
| 216 | + flags=flags, # lib.WGPUInstanceFlag_Debug, # figure out if this works or not. |
| 217 | + dx12ShaderCompiler=c_dx12_compiler, |
| 218 | + gles3MinorVersion=gles3_minor_version, |
| 219 | + glFenceBehaviour=fence_behavior, |
| 220 | + dxilPath=to_c_string_view(dxil_path), |
| 221 | + dxcPath=to_c_string_view(dxc_path), |
| 222 | + # dxcMaxShaderModel=lib.WGPUDxcMaxShaderModel_V6_5, |
| 223 | + ) |
| 224 | + |
| 225 | + c_extras.chain.sType = ( |
| 226 | + 0x00030006 # lib.WGPUSType_InstanceExtras (but we don't import lib here?) |
| 227 | + ) |
| 228 | + get_wgpu_instance(extras=c_extras) # this sets a global |
0 commit comments