Skip to content

Commit 9e1bc1d

Browse files
WinterSnowfallK0bin
authored andcommitted
[d3d9] Expand NormalizeTextureProperties validations
1 parent 97ad37e commit 9e1bc1d

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

src/d3d9/d3d9_common_texture.cpp

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,38 @@ namespace dxvk {
178178
if (pDesc->Usage & D3DUSAGE_WRITEONLY)
179179
return D3DERR_INVALIDCALL;
180180

181+
constexpr DWORD usageRTOrDS = D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL;
182+
181183
// RENDERTARGET and DEPTHSTENCIL must be default pool
182-
constexpr DWORD incompatibleUsages = D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL;
183-
if (pDesc->Pool != D3DPOOL_DEFAULT && (pDesc->Usage & incompatibleUsages))
184+
if (pDesc->Pool != D3DPOOL_DEFAULT && (pDesc->Usage & usageRTOrDS))
185+
return D3DERR_INVALIDCALL;
186+
187+
// RENDERTARGET and DEPTHSTENCIL in D3DPOOL_DEFAULT
188+
// can not also have DYNAMIC usage
189+
if (pDesc->Pool == D3DPOOL_DEFAULT &&
190+
(pDesc->Usage & usageRTOrDS) &&
191+
(pDesc->Usage & D3DUSAGE_DYNAMIC))
192+
return D3DERR_INVALIDCALL;
193+
194+
const bool isPlainSurface = ResourceType == D3DRTYPE_SURFACE && !(pDesc->Usage & usageRTOrDS);
195+
const bool isDepthStencilFormat = IsDepthStencilFormat(pDesc->Format);
196+
197+
// With the exception of image surfaces (d3d8)
198+
// or plain offscreen surfaces (d3d9), depth stencil
199+
// formats can only be used in D3DPOOL_DEFAULT
200+
if (!isPlainSurface && pDesc->Pool != D3DPOOL_DEFAULT && isDepthStencilFormat)
201+
return D3DERR_INVALIDCALL;
202+
203+
// Depth stencil formats can not have RENDERTARGET
204+
// usage, and nothing except depth stencil formats
205+
// can have DEPTHSTENCIL usage
206+
if (( isDepthStencilFormat && (pDesc->Usage & D3DUSAGE_RENDERTARGET)) ||
207+
(!isDepthStencilFormat && (pDesc->Usage & D3DUSAGE_DEPTHSTENCIL)))
208+
return D3DERR_INVALIDCALL;
209+
210+
// Volume textures can not be used as render targets
211+
if (ResourceType == D3DRTYPE_VOLUMETEXTURE &&
212+
(pDesc->Usage & D3DUSAGE_RENDERTARGET))
184213
return D3DERR_INVALIDCALL;
185214

186215
// Volume textures in D3DPOOL_SCRATCH must not have DYNAMIC usage
@@ -202,13 +231,13 @@ namespace dxvk {
202231
pDesc->MipLevels = maxMipLevelCount;
203232

204233
if (unlikely(pDesc->Discard)) {
205-
if (!IsDepthStencilFormat(pDesc->Format))
234+
if (!isDepthStencilFormat)
206235
return D3DERR_INVALIDCALL;
207236

208237
if (pDesc->Format == D3D9Format::D32_LOCKABLE
209-
|| pDesc->Format == D3D9Format::D32F_LOCKABLE
210-
|| pDesc->Format == D3D9Format::D16_LOCKABLE
211-
|| pDesc->Format == D3D9Format::S8_LOCKABLE)
238+
|| pDesc->Format == D3D9Format::D32F_LOCKABLE
239+
|| pDesc->Format == D3D9Format::D16_LOCKABLE
240+
|| pDesc->Format == D3D9Format::S8_LOCKABLE)
212241
return D3DERR_INVALIDCALL;
213242
}
214243

src/d3d9/d3d9_device.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4070,7 +4070,7 @@ namespace dxvk {
40704070
desc.IsAttachmentOnly = TRUE;
40714071
desc.IsLockable = Lockable;
40724072

4073-
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_TEXTURE, &desc)))
4073+
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_SURFACE, &desc)))
40744074
return D3DERR_INVALIDCALL;
40754075

40764076
try {
@@ -4118,7 +4118,7 @@ namespace dxvk {
41184118
// Docs: Off-screen plain surfaces are always lockable, regardless of their pool types.
41194119
desc.IsLockable = TRUE;
41204120

4121-
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_TEXTURE, &desc)))
4121+
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_SURFACE, &desc)))
41224122
return D3DERR_INVALIDCALL;
41234123

41244124
if (pSharedHandle != nullptr && Pool != D3DPOOL_DEFAULT)
@@ -4172,7 +4172,7 @@ namespace dxvk {
41724172
desc.IsAttachmentOnly = TRUE;
41734173
desc.IsLockable = IsLockableDepthStencilFormat(desc.Format);
41744174

4175-
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_TEXTURE, &desc)))
4175+
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_SURFACE, &desc)))
41764176
return D3DERR_INVALIDCALL;
41774177

41784178
try {
@@ -8362,7 +8362,7 @@ namespace dxvk {
83628362
desc.IsAttachmentOnly = TRUE;
83638363
desc.IsLockable = IsLockableDepthStencilFormat(desc.Format);
83648364

8365-
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_TEXTURE, &desc)))
8365+
if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_SURFACE, &desc)))
83668366
return D3DERR_NOTAVAILABLE;
83678367

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

0 commit comments

Comments
 (0)