Documentation
¶
Overview ¶
Package d3d12 is the Direct3D 12 backend of the explicit renderer (D25, SPEC §9.8): the third explicit.Device, after vulkan and webgpu, for Windows. Every call into Windows is made with the standard library's syscall, through internal/platform/windows/win32.
The shaders (step 28.7): the HLSL that cmd/glutter-gen shaders made from the WGSL (explicit.Shader.HLSL) is compiled by D3DCompile from d3dcompiler_47.dll into DXBC, shader model 5.1 (vs_5_1 and ps_5_1), when a pipeline first needs it, and the bytecode is kept in the shader cache (SPEC §9.7). D3DReflect reads the registers back from the bytecode, which is the contract with the root signatures of step 28.9: binding B of group G is at register(<class>B, spaceG).
- compiler.go and hlslcache.go are plain Go: the compile flags, the cache key and the file check, and the Compiler that asks the cache first. They are tested on Linux with a stand-in for D3DCompile.
- compile_windows.go (CompilerDLL) calls d3dcompiler_47.dll; reflect_windows.go reads the registers. Their Go mirrors of the structures are in types.go with no OS tag, and layout_test.go checks them against the mingw-w64 headers.
The device (SPEC §9.8, "Decided in step 28.8") is Open, which returns a Device, an explicit.Device offscreen: the choice of the adapter, the device at feature level 11_0, the queue and the fence, the two frame slots, committed buffers, textures and samplers, uploads through a staging ring, the read back of textures, and the state tracker that batches the barriers. Step 28.9 adds the pipelines and the draws: NewPipeline (a root signature planned from the bindings of the two entry points, the bytecode through the shader cache, the pipeline state, and a pipeline library where the device has one), NewBindGroup (the descriptors copied into the shader-visible heaps of the frame slot, in blocks), and the encoder's passes with their barriers, root arguments, vertex and index buffers, scissor and draws. Step 28.10 adds the swap chain (NewSwapchain: a flip-model swap chain for the HWND of a window, two buffers, resized with ResizeBuffers after the GPU is idle, presented with dirty rectangles and a sync interval of 0), which the engine's Windows renderers draw windows with (SPEC §9.6, §9.8).
- adapter.go, errors.go, check.go, states.go, memory.go, mapping.go, rootsig.go, blocks.go, debug.go and present.go are plain Go, tested on Linux: the adapter choice, the table of HRESULTs, the state tracker, the staging ring, the layout of a copy, the descriptor numbers, the mapping of formats, samplers, blends, vertex formats and load operations, the planner of root signatures, the allocator of descriptor blocks, the reading of a message of the debug layer, and the formats of the swap chain and the dirty rectangles of a present. types.go and vtables.go have the Go mirrors of the structures of DXGI and Direct3D 12, the positions of the methods of their interfaces and their IDs, all checked against the mingw-w64 headers by layout_test.go.
- dll_windows.go, device_windows.go, memory_windows.go, resources_windows.go, fence_windows.go, frames_windows.go, descriptors_windows.go, rootsig_windows.go, pipeline_windows.go, bindgroup_windows.go, encoder_windows.go and swapchain_windows.go call Windows through syscall, and are tested under Wine (the *_wine_test.go files, the glutter_wine tag): among them the parity test, which draws every proof scene through the explicit renderer and compares it with the software renderer.
Flutter: no counterpart. Flutter's Windows embedder draws through ANGLE.
Index ¶
- Constants
- func CacheKey(hlsl, entry, target string, flags uint32, compilerVersion string) string
- func CompileFlags(getenv func(string) string) uint32
- func LibraryKey(vendor, device, revision uint32, driver uint64) string
- func ValidDXBC(data []byte) bool
- type AdapterInfo
- type Backend
- type BlobCache
- type CompileResult
- type Compiler
- type CompilerStats
- type ShaderDesc
- type ShaderInputBindDesc
- type SignatureParameterDesc
Constants ¶
const ( // CompileDebug is D3DCOMPILE_DEBUG: debugging information in the bytecode. // // Flutter: no counterpart CompileDebug uint32 = 1 << 0 // CompileSkipOptimization is D3DCOMPILE_SKIP_OPTIMIZATION. // // Flutter: no counterpart CompileSkipOptimization uint32 = 1 << 2 // CompileOptimizationLevel3 is D3DCOMPILE_OPTIMIZATION_LEVEL3: the highest optimization. // // Flutter: no counterpart CompileOptimizationLevel3 uint32 = 1 << 15 )
The flags of D3DCompile that the backend uses (d3dcompiler.h; the layout test checks them).
const ( // TargetVertex is the target of a vertex entry point. // // Flutter: no counterpart TargetVertex = "vs_5_1" // TargetPixel is the target of a fragment entry point. // // Flutter: no counterpart TargetPixel = "ps_5_1" // TargetCompute is the target of a compute entry point (step 30.2). // // Flutter: no counterpart TargetCompute = "cs_5_1" )
The compile targets of the backend: shader model 5.1, vertex, pixel and compute (SPEC §9.8).
const ( // TagD3D12CallFailed is the tag of the error for a method of Direct3D 12 or DXGI that returned a // failed HRESULT that has no tag of its own; the metadata are "method" and "hresult". TagD3D12CallFailed = "D3D12CallFailed" // TagD3D12SwapchainFailed is the tag of the error for a swap chain that cannot be made: the surface is not // a window of Windows, DXGI accepted no format, or a resize left it without buffers (SPEC §9.8); the // metadata are the "window" and, for a refused format, "refused" with each format and the answer. TagD3D12SwapchainFailed = "D3D12SwapchainFailed" )
The tags of the errors that this file makes (rm4n0s/errors, R5).
const ( // SITConstantBuffer is D3D_SIT_CBUFFER. // // Flutter: no counterpart SITConstantBuffer uint32 = 0 // SITTexture is D3D_SIT_TEXTURE. // // Flutter: no counterpart SITTexture uint32 = 2 // SITSampler is D3D_SIT_SAMPLER. // // Flutter: no counterpart SITSampler uint32 = 3 )
The kinds of resource that D3D_SHADER_INPUT_TYPE names.
const AdapterEnvVar = "GLUTTER_D3D12_ADAPTER"
AdapterEnvVar is the environment variable that picks the adapter: an index, a part of the name (any case) or "warp" (SPEC §9.8, like GLUTTER_VULKAN_DEVICE in §9.4).
Flutter: no counterpart
const DebugEnvVar = "GLUTTER_D3D12_DEBUG"
DebugEnvVar is the environment variable that turns on the Direct3D debug layer (28.8) and the debug flags of the compiler when it is "1" (SPEC §9.8).
Flutter: no counterpart
const ( // TagD3D12NoAdapter is the tag of the error for an adapter choice that has no candidate, and for // a list of candidates none of which exists; the metadata are "adapters" and "selector". TagD3D12NoAdapter = "D3D12NoAdapter" )
The tags of the errors that this file makes (rm4n0s/errors, R5).
const ( // TagD3D12ShaderCompileFailed is the tag of the error for HLSL that D3DCompile refuses; the // metadata are "entry", "target", "hresult" and "messages" (the compiler's text, with the line // and column of each error). It is an internal bug: the HLSL is generated (SPEC §9.8). TagD3D12ShaderCompileFailed = "D3D12ShaderCompileFailed" )
The tags of the errors that this file makes (rm4n0s/errors, R5).
Variables ¶
This section is empty.
Functions ¶
func CacheKey ¶
CacheKey is the key of the bytecode that D3DCompile makes from the HLSL: the hash of the text, the entry point, the target ("vs_5_1" or "ps_5_1"), the compile flags and the file version of d3dcompiler_47.dll, so that a new compiler never reads the bytecode of an old one (SPEC §9.7). Each part is length-prefixed, so no two different parts make the same key.
Flutter: no counterpart
func CompileFlags ¶
CompileFlags returns the flags for D3DCompile (SPEC §9.8): optimization level 3 in a release build, and debugging information with no optimization when GLUTTER_D3D12_DEBUG is "1".
Flutter: no counterpart
func LibraryKey ¶
LibraryKey is the key under which the shader cache keeps the serialized pipeline library of an adapter: its vendor, device, revision and the version of its driver, so that a new driver or another adapter never reads a blob that is not for it (SPEC §9.8 "Pipelines").
Flutter: no counterpart
func ValidDXBC ¶
ValidDXBC says whether the data is a DXBC container as far as its header tells: the magic "DXBC", room for the header, and a total size that is the length of the data. A file of the cache that fails this (cut short, or something else) is not used: the shader is compiled again and the new bytecode replaces the file (SPEC §9.7).
Flutter: no counterpart
Types ¶
type AdapterInfo ¶
type AdapterInfo struct {
// Index is the position in the order that DXGI listed the adapters in.
Index int
// Name is the description of the adapter.
Name string
// VendorID, DeviceID and Revision are the fields of those names.
VendorID, DeviceID, Revision uint32
// Software is DXGI_ADAPTER_FLAG_SOFTWARE: the Microsoft Basic Render Driver, which is not a
// hardware adapter and is used only as WARP (SPEC §9.8).
Software bool
// DedicatedVideoMemory is the memory of the GPU in bytes.
DedicatedVideoMemory uint64
}
AdapterInfo is what the choice of an adapter needs to know about one adapter of DXGI.
Flutter: no counterpart
type Backend ¶
type Backend interface {
// Version is the file version of the compiler ("10.0.19041.1"), part of the cache key; empty
// when it cannot be known, and then nothing is cached.
Version() string
// Compile compiles the entry point of the HLSL for the target. It returns the bytecode, the
// compiler's messages (warnings on success, errors and warnings on failure) and the HRESULT
// of D3DCompile, negative when the compile failed.
Compile(hlsl, entry, target string, flags uint32) (dxbc []byte, messages string, hresult int32)
}
Backend turns HLSL into DXBC: D3DCompile of d3dcompiler_47.dll (CompilerDLL), or a stand-in in a test.
Flutter: no counterpart
type BlobCache ¶
type BlobCache interface {
// Load returns what is stored under the key, and false when there is nothing.
Load(key string) ([]byte, bool)
// Store keeps the data under the key, replacing what was there.
Store(key string, data []byte)
}
BlobCache is where the bytecode is kept between runs: *shadercache.Cache is one (SPEC §9.7). A nil BlobCache is no cache.
Flutter: no counterpart
type CompileResult ¶
type CompileResult struct {
// DXBC is the bytecode.
DXBC []byte
// Messages are the compiler's warnings; empty when the bytecode came from the cache.
Messages string
// FromCache says that the bytecode was read from the cache and D3DCompile did not run.
FromCache bool
}
CompileResult is what Compiler.Compile makes.
Flutter: no counterpart
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler compiles entry points of the generated HLSL to DXBC, reading the cache first and storing what it compiled. It is used from one goroutine, the renderer's.
Flutter: no counterpart
func NewCompiler ¶
NewCompiler makes a Compiler over the backend. cache may be nil: there is no cache directory, which is not an error. A backend that does not know its version caches nothing.
Flutter: no counterpart
func (*Compiler) Compile ¶
func (c *Compiler) Compile(hlsl, entry, target string, flags uint32) (CompileResult, error)
Compile returns the bytecode of the entry point: from the cache when the file is there and has a DXBC header, else from D3DCompile, and then it is stored. A compile that fails is D3D12ShaderCompileFailed, with the compiler's messages (an internal bug: the HLSL comes from the generator), and nothing is stored.
Flutter: no counterpart
func (*Compiler) Stats ¶
func (c *Compiler) Stats() CompilerStats
Stats returns the counts so far.
Flutter: no counterpart
type CompilerStats ¶
type CompilerStats struct {
// Compiled is the number of shaders D3DCompile ran for, failures included.
Compiled int
// FromCache is the number of shaders read from the cache.
FromCache int
// Refused is the number of cache files that did not have a DXBC header and were dropped.
Refused int
}
CompilerStats counts what a Compiler did, for the startup report (SPEC §9.7) and for tests.
Flutter: no counterpart
type ShaderDesc ¶
type ShaderDesc struct {
Version uint32 `c:"Version"`
Creator uintptr `c:"Creator"`
Flags uint32 `c:"Flags"`
ConstantBuffers uint32 `c:"ConstantBuffers"`
BoundResources uint32 `c:"BoundResources"`
InputParameters uint32 `c:"InputParameters"`
OutputParameters uint32 `c:"OutputParameters"`
InstructionCount uint32 `c:"InstructionCount"`
TempRegisterCount uint32 `c:"TempRegisterCount"`
TempArrayCount uint32 `c:"TempArrayCount"`
DefCount uint32 `c:"DefCount"`
DclCount uint32 `c:"DclCount"`
TextureNormalInstructions uint32 `c:"TextureNormalInstructions"`
TextureLoadInstructions uint32 `c:"TextureLoadInstructions"`
TextureCompInstructions uint32 `c:"TextureCompInstructions"`
TextureBiasInstructions uint32 `c:"TextureBiasInstructions"`
TextureGradientInstrs uint32 `c:"TextureGradientInstructions"`
FloatInstructionCount uint32 `c:"FloatInstructionCount"`
IntInstructionCount uint32 `c:"IntInstructionCount"`
UintInstructionCount uint32 `c:"UintInstructionCount"`
StaticFlowControlCount uint32 `c:"StaticFlowControlCount"`
DynamicFlowControlCount uint32 `c:"DynamicFlowControlCount"`
MacroInstructionCount uint32 `c:"MacroInstructionCount"`
ArrayInstructionCount uint32 `c:"ArrayInstructionCount"`
CutInstructionCount uint32 `c:"CutInstructionCount"`
EmitInstructionCount uint32 `c:"EmitInstructionCount"`
GSOutputTopology uint32 `c:"GSOutputTopology"`
GSMaxOutputVertexCount uint32 `c:"GSMaxOutputVertexCount"`
InputPrimitive uint32 `c:"InputPrimitive"`
PatchConstantParameters uint32 `c:"PatchConstantParameters"`
GSInstanceCount uint32 `c:"cGSInstanceCount"`
ControlPoints uint32 `c:"cControlPoints"`
HSOutputPrimitive uint32 `c:"HSOutputPrimitive"`
HSPartitioning uint32 `c:"HSPartitioning"`
TessellatorDomain uint32 `c:"TessellatorDomain"`
BarrierInstructions uint32 `c:"cBarrierInstructions"`
InterlockedInstructions uint32 `c:"cInterlockedInstructions"`
TextureStoreInstructions uint32 `c:"cTextureStoreInstructions"`
}
ShaderDesc is the Go mirror of D3D12_SHADER_DESC (ID3D12ShaderReflection::GetDesc).
Flutter: no counterpart
type ShaderInputBindDesc ¶
type ShaderInputBindDesc struct {
Name uintptr `c:"Name"`
Type uint32 `c:"Type"`
BindPoint uint32 `c:"BindPoint"`
BindCount uint32 `c:"BindCount"`
Flags uint32 `c:"uFlags"`
ReturnType uint32 `c:"ReturnType"`
Dimension uint32 `c:"Dimension"`
NumSamples uint32 `c:"NumSamples"`
Space uint32 `c:"Space"`
ID uint32 `c:"uID"`
}
ShaderInputBindDesc is the Go mirror of D3D12_SHADER_INPUT_BIND_DESC (ID3D12ShaderReflection::GetResourceBindingDesc): one resource that the shader binds.
Flutter: no counterpart
type SignatureParameterDesc ¶
type SignatureParameterDesc struct {
SemanticName uintptr `c:"SemanticName"`
SemanticIndex uint32 `c:"SemanticIndex"`
Register uint32 `c:"Register"`
SystemValue uint32 `c:"SystemValueType"`
ComponentType uint32 `c:"ComponentType"`
Mask uint8 `c:"Mask"`
ReadWriteMask uint8 `c:"ReadWriteMask"`
Stream uint32 `c:"Stream"`
MinPrecision uint32 `c:"MinPrecision"`
// contains filtered or unexported fields
}
SignatureParameterDesc is the Go mirror of D3D12_SIGNATURE_PARAMETER_DESC (ID3D12ShaderReflection::GetInputParameterDesc): one input or output of a shader stage.
Flutter: no counterpart