AlpyneDreams / d8vk

Direct3D 8 to Vulkan translation for DXVK! Merged into dxvk: https://github.com/doitsujin/dxvk
zlib License
485 stars 8 forks source link

[d3d8] Use D3DPOOL_SCRATCH in CreateImageSurface #206

Closed WinterSnowfall closed 4 months ago

WinterSnowfall commented 9 months ago

Fixes #89 and fixes points (1.) and (2.) from #205.

Some games expect us to successfully create image surfaces for them even when they supply unsupported formats like P8 or R8G8B8. This only works with D3DPOOL_SCRATCH according to spec, and it's also what dxvk validates inside of CreateOffscreenPlainSurfaceEx().

We don't actually need to fully support them in order for the above games to work properly at least. #182 will still need P8 support, since it uses that on CreateTexture().

The only problem is we don't currently handle D3DPOOL_SCRATCH at all in CopyRects(), so this has the potential to explode and break more than it fixes. We should merge this change only after sorting out that bit ideally.

WinterSnowfall commented 8 months ago

I've sweetened it a bit by using D3DPOOL_SCRATCH only in case of unsupported surface formats (when CreateImageSurface would typically fail without this PR). We should still consider handling D3DPOOL_SCRATCH in CopyRects, but it's far less likely anything will blow up now.

Edit: Apparently, according to spec, CreateImageSurface() should use D3DPOOL_SYSTEMMEM, but I doubt this actually happens in practice. Modern drivers also don't support any of the above mentioned formats and yet most of the problematic games work fine on native d3d8. All things considered, it is perhaps a generally good idea to keep using D3DPOOL_SYSTEMMEM for the formats we do support, since some games might rely on this particularity.

Edit 2: I've confirmed CreateImageSurface() never fails on native Nvidia (thanks to @K0bin), so my initial assumptions were correct.