d3d11

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package d3d11 is the Direct3D 11 backend of the GPU renderer: a gpu.Device that executes internal/render/gpu frames on a D3D11 device and a presenter that shows them in a window through a DXGI flip-model swap chain.

It calls Direct3D through COM without cgo: d3d11.dll, dxgi.dll and d3dcompiler_47.dll are loaded from the system directory on first use, and interface methods are called through their vtables with syscall.SyscallN. The quad shader (internal/render/gpu/gen.QuadHLSL) is compiled at run time with D3DCompile, so no shader compiler is needed at build time.

The device prefers a hardware adapter and falls back to WARP, the software rasterizer shipped with Windows, so virtual machines, remote desktop sessions and CI runners get a working device too. Setting the environment variable TANGO_D3D_WARP=1 skips the hardware adapter, to reproduce the software device on a machine with a GPU; the package's own tests run on WARP unless TANGO_D3D_HARDWARE=1. Setting TANGO_D3D_DEBUG=1 creates the device with the Direct3D debug layer when it is installed (Windows' optional "Graphics Tools" feature; otherwise the device is created without it and that is logged once) and logs the shader compiler's warnings once per entry point.

The backend exists on windows/amd64 and windows/arm64. Everywhere else NewDevice and NewPresenter fail with ErrUnsupported.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupported is returned on platforms without Direct3D 11
	// (anything but windows/amd64 and windows/arm64).
	ErrUnsupported = errors.New("d3d11: Direct3D 11 is not available on this platform")
	// ErrNoDevice is wrapped by the error returned when no Direct3D 11
	// device could be created: d3d11.dll is missing, or neither a hardware
	// adapter nor WARP provides feature level 10_0. Use the CPU renderer.
	ErrNoDevice = errors.New("d3d11: no Direct3D 11 device")
	// ErrClosed is returned by calls on a device or presenter after Close.
	ErrClosed = errors.New("d3d11: use after Close")
	// ErrDeviceLost is gpu.ErrDeviceLost (the same value): it is wrapped
	// by the errors Device.Execute (so the Renderer's Render) returns once
	// the GPU is unusable: the device was removed, reset or hung, or
	// several frames in a row failed. It is permanent for that Device;
	// switch to the CPU renderer.
	ErrDeviceLost = gpu.ErrDeviceLost
	// ErrTargetTooLarge is gpu.ErrTargetTooLarge (the same value): it is
	// wrapped by the error Device.Execute returns for a frame whose render
	// target, or a texture it samples, exceeds the device's 2D texture
	// limit (16384 from feature level 11_0 on, 8192 on 10_x). Nothing is
	// allocated or submitted and the frame is not a GPU failure.
	ErrTargetTooLarge = gpu.ErrTargetTooLarge
)

Functions

func NewPresenter

func NewPresenter(hwnd uintptr) (r paint.Renderer, present func(size image.Point, scale float32) error, err error)

NewPresenter attaches a GPU renderer to the window hwnd through a DXGI swap chain (on Windows r also implements Close() error). On this platform it returns an error wrapping ErrUnsupported.

Types

type Device

type Device struct{}

Device is the Direct3D 11 device; on this platform it cannot be created.

func NewDevice

func NewDevice() (*Device, error)

NewDevice always fails with ErrUnsupported on this platform.

func (*Device) Close

func (d *Device) Close()

Close releases the device.

func (*Device) Execute

func (d *Device) Execute(f *gpu.Frame) error

Execute implements gpu.Device.

func (*Device) ReadPixels

func (d *Device) ReadPixels() (*image.RGBA, error)

ReadPixels reads back the render target.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL