Skip to content

Commit

Permalink
[d3d9] Do not support cube textures with depth formats
Browse files Browse the repository at this point in the history
  • Loading branch information
doitsujin committed May 8, 2024
1 parent b2789ab commit 57d8793
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/d3d9/d3d9_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ namespace dxvk {
if (mapping.FormatSrgb == VK_FORMAT_UNDEFINED && srgb)
return D3DERR_NOTAVAILABLE;

if (RType == D3DRTYPE_CUBETEXTURE && mapping.Aspect != VK_IMAGE_ASPECT_COLOR_BIT)
return D3DERR_NOTAVAILABLE;

if (RType == D3DRTYPE_VERTEXBUFFER || RType == D3DRTYPE_INDEXBUFFER)
return D3D_OK;

Expand Down
6 changes: 6 additions & 0 deletions src/d3d9/d3d9_common_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ namespace dxvk {

HRESULT D3D9CommonTexture::NormalizeTextureProperties(
D3D9DeviceEx* pDevice,
D3DRESOURCETYPE ResourceType,
D3D9_COMMON_TEXTURE_DESC* pDesc) {
auto* options = pDevice->GetOptions();

Expand All @@ -131,6 +132,11 @@ namespace dxvk {
options->disableA8RT)
return D3DERR_INVALIDCALL;

// Cube textures with depth formats are not supported on any native
// driver, and allowing them triggers a broken code path in Gothic 3.
if (ResourceType == D3DRTYPE_CUBETEXTURE && mapping.Aspect != VK_IMAGE_ASPECT_COLOR_BIT)
return D3DERR_INVALIDCALL;

// If the mapping is invalid then lets return invalid
// Some edge cases:
// NULL format does not map to anything, but should succeed
Expand Down
3 changes: 3 additions & 0 deletions src/d3d9/d3d9_common_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,14 @@ namespace dxvk {
* Fills in undefined values and validates the texture
* parameters. Any error returned by this method should
* be forwarded to the application.
* \param [in] pDevice D3D9 device
* \param [in] ResourceType Resource type
* \param [in,out] pDesc Texture description
* \returns \c S_OK if the parameters are valid
*/
static HRESULT NormalizeTextureProperties(
D3D9DeviceEx* pDevice,
D3DRESOURCETYPE ResourceType,
D3D9_COMMON_TEXTURE_DESC* pDesc);

/**
Expand Down
14 changes: 7 additions & 7 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ namespace dxvk {
|| (Usage & D3DUSAGE_DYNAMIC)
|| IsVendorFormat(EnumerateFormat(Format));

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_TEXTURE, &desc)))
return D3DERR_INVALIDCALL;

try {
Expand Down Expand Up @@ -664,7 +664,7 @@ namespace dxvk {
|| (Usage & D3DUSAGE_DYNAMIC)
|| IsVendorFormat(EnumerateFormat(Format));

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_VOLUMETEXTURE, &desc)))
return D3DERR_INVALIDCALL;

try {
Expand Down Expand Up @@ -721,7 +721,7 @@ namespace dxvk {
|| (Usage & D3DUSAGE_DYNAMIC)
|| IsVendorFormat(EnumerateFormat(Format));

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_CUBETEXTURE, &desc)))
return D3DERR_INVALIDCALL;

try {
Expand Down Expand Up @@ -3798,7 +3798,7 @@ namespace dxvk {
desc.IsAttachmentOnly = TRUE;
desc.IsLockable = Lockable;

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_TEXTURE, &desc)))
return D3DERR_INVALIDCALL;

try {
Expand Down Expand Up @@ -3846,7 +3846,7 @@ namespace dxvk {
// Docs: Off-screen plain surfaces are always lockable, regardless of their pool types.
desc.IsLockable = TRUE;

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_TEXTURE, &desc)))
return D3DERR_INVALIDCALL;

if (pSharedHandle != nullptr && Pool != D3DPOOL_DEFAULT)
Expand Down Expand Up @@ -3901,7 +3901,7 @@ namespace dxvk {
// Docs don't say anything, so just assume it's lockable.
desc.IsLockable = TRUE;

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_TEXTURE, &desc)))
return D3DERR_INVALIDCALL;

try {
Expand Down Expand Up @@ -7891,7 +7891,7 @@ namespace dxvk {
// Docs: Also note that - unlike textures - swap chain back buffers, render targets [..] can be locked
desc.IsLockable = TRUE;

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_TEXTURE, &desc)))
return D3DERR_NOTAVAILABLE;

m_autoDepthStencil = new D3D9Surface(this, &desc, nullptr, nullptr);
Expand Down

0 comments on commit 57d8793

Please sign in to comment.