app/internal/d3d11: detect hardware floating point support

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-02-29 10:39:29 +01:00
parent 050f43d60a
commit b3a3c34088
2 changed files with 35 additions and 5 deletions
+15 -1
View File
@@ -20,6 +20,7 @@ type Device struct {
dev *_ID3D11Device
ctx *_ID3D11DeviceContext
featLvl uint32
floatFormat uint32
depthStates map[depthState]*_ID3D11DepthStencilState
blendStates map[blendState]*_ID3D11BlendState
}
@@ -116,8 +117,21 @@ func NewDevice() (*Device, error) {
dev := &Device{dev: d3ddev, ctx: d3dctx, featLvl: featLvl}
if featLvl < _D3D_FEATURE_LEVEL_9_1 {
_IUnknownRelease(unsafe.Pointer(d3ddev), d3ddev.vtbl.Release)
_IUnknownRelease(unsafe.Pointer(d3dctx), d3dctx.vtbl.Release)
return nil, fmt.Errorf("d3d11: feature level too low: %d", featLvl)
}
format := uint32(_DXGI_FORMAT_R16_FLOAT)
need := uint32(_D3D11_FORMAT_SUPPORT_TEXTURE2D | _D3D11_FORMAT_SUPPORT_RENDER_TARGET)
if use, _ := d3ddev.CheckFormatSupport(format); use&need == 0 {
// Fall back to a d3d 9.2 format.
format = _DXGI_FORMAT_R32_FLOAT
if use, _ = d3ddev.CheckFormatSupport(format); use&need == 0 {
_IUnknownRelease(unsafe.Pointer(d3ddev), d3ddev.vtbl.Release)
_IUnknownRelease(unsafe.Pointer(d3dctx), d3dctx.vtbl.Release)
return nil, fmt.Errorf("d3d11: no available floating point formats")
}
}
dev.floatFormat = format
dev.depthStates = make(map[depthState]*_ID3D11DepthStencilState)
dev.blendStates = make(map[blendState]*_ID3D11BlendState)
return dev, nil
@@ -257,7 +271,7 @@ func (b *Backend) NewTexture(format backend.TextureFormat, width, height int, mi
var d3dfmt uint32
switch format {
case backend.TextureFormatFloat:
d3dfmt = _DXGI_FORMAT_R16_FLOAT
d3dfmt = b.dev.floatFormat
case backend.TextureFormatSRGB:
d3dfmt = _DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
default: