Skip to content

Commit

Permalink
[d3d8] Use D3DPOOL_SCRATCH in CreateImageSurface
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall committed Mar 5, 2024
1 parent 1a039a4 commit c6abbbf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/d3d8/d3d8_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,15 @@ namespace dxvk {
}

HRESULT STDMETHODCALLTYPE D3D8Device::CreateImageSurface(UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
// TODO: Use D3DPOOL_SCRATCH globally, not only for unsupported texture formats (depends on CopyRects support)
d3d9::D3DPOOL pool = isUnsupportedTextureFormat(Format) ? d3d9::D3DPOOL_SCRATCH : d3d9::D3DPOOL_SYSTEMMEM;

Com<d3d9::IDirect3DSurface9> pSurf = nullptr;
HRESULT res = GetD3D9()->CreateOffscreenPlainSurface(
Width,
Height,
d3d9::D3DFORMAT(Format),
// FIXME: D3DPOOL_SCRATCH is said to be dx8 compatible, but currently won't work with CopyRects
d3d9::D3DPOOL_SYSTEMMEM,
pool,
&pSurf,
NULL);

Expand Down
14 changes: 14 additions & 0 deletions src/d3d8/d3d8_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ namespace dxvk {
return isDXT(D3DFORMAT(fmt));
}

inline constexpr bool isUnsupportedTextureFormat(D3DFORMAT fmt) {
// mirror what dxvk doesn't support in terms of d3d9 texture formats
return fmt == D3DFMT_R8G8B8
|| fmt == D3DFMT_R3G3B2
|| fmt == D3DFMT_A8R3G3B2
|| fmt == D3DFMT_A8P8
|| fmt == D3DFMT_P8
|| fmt == D3DFMT_L6V5U5
|| fmt == D3DFMT_X8L8V8U8
|| fmt == D3DFMT_A2B10G10R10;
// not included in the d3d8 spec
//|| fmt == D3DFMT_CXV8U8;
}

inline constexpr bool isSupportedDepthStencilFormat(D3DFORMAT fmt) {
// native d3d8 doesn't support D3DFMT_D32, D3DFMT_D15S1 or D3DFMT_D24X4S4
return fmt == D3DFMT_D16_LOCKABLE
Expand Down

0 comments on commit c6abbbf

Please sign in to comment.