Skip to content

Commit 6db5239

Browse files
[d3d9] Expand NormalizeTextureProperties validations
1 parent 31ecdd4 commit 6db5239

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

src/d3d9/d3d9_common_texture.cpp

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

181-
// RENDERTARGET and DEPTHSTENCIL must be default pool
182-
constexpr DWORD incompatibleUsages = D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL;
183-
if (pDesc->Pool != D3DPOOL_DEFAULT && (pDesc->Usage & incompatibleUsages))
181+
constexpr DWORD usageRTOrDS = D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL;
182+
const bool isPlainSurface = ResourceType == D3DRTYPE_SURFACE && !(pDesc->Usage & usageRTOrDS);
183+
const bool isDepthStencilFormat = IsDepthStencilFormat(pDesc->Format);
184+
185+
// Below validations apply to everything except plain offscreen surfaces
186+
if (!isPlainSurface) {
187+
// RENDERTARGET and DEPTHSTENCIL must be default pool
188+
if (pDesc->Pool != D3DPOOL_DEFAULT && (pDesc->Usage & usageRTOrDS))
189+
return D3DERR_INVALIDCALL;
190+
191+
// RENDERTARGET and DEPTHSTENCIL in D3DPOOL_DEFAULT can not have DYNAMIC usage
192+
if (pDesc->Pool == D3DPOOL_DEFAULT &&
193+
(pDesc->Usage & usageRTOrDS) &&
194+
(pDesc->Usage & D3DUSAGE_DYNAMIC))
195+
return D3DERR_INVALIDCALL;
196+
197+
// Depth stencil formats can only be used with D3DPOOL_DEFAULT
198+
if (pDesc->Pool != D3DPOOL_DEFAULT && isDepthStencilFormat)
199+
return D3DERR_INVALIDCALL;
200+
201+
// Depth stencil formats can not have RENDERTARGET usage and
202+
// nothing except depth stencil formats can have DEPTHSTENCIL usage
203+
if (( isDepthStencilFormat && (pDesc->Usage & D3DUSAGE_RENDERTARGET)) ||
204+
(!isDepthStencilFormat && (pDesc->Usage & D3DUSAGE_DEPTHSTENCIL)))
205+
return D3DERR_INVALIDCALL;
206+
}
207+
208+
// Volume textures can not be used as render targets
209+
if (ResourceType == D3DRTYPE_VOLUMETEXTURE &&
210+
(pDesc->Usage & D3DUSAGE_RENDERTARGET))
184211
return D3DERR_INVALIDCALL;
185212

186213
// Volume textures in D3DPOOL_SCRATCH must not have DYNAMIC usage
@@ -202,13 +229,13 @@ namespace dxvk {
202229
pDesc->MipLevels = maxMipLevelCount;
203230

204231
if (unlikely(pDesc->Discard)) {
205-
if (!IsDepthStencilFormat(pDesc->Format))
232+
if (!isDepthStencilFormat)
206233
return D3DERR_INVALIDCALL;
207234

208235
if (pDesc->Format == D3D9Format::D32_LOCKABLE
209-
|| pDesc->Format == D3D9Format::D32F_LOCKABLE
210-
|| pDesc->Format == D3D9Format::D16_LOCKABLE
211-
|| pDesc->Format == D3D9Format::S8_LOCKABLE)
236+
|| pDesc->Format == D3D9Format::D32F_LOCKABLE
237+
|| pDesc->Format == D3D9Format::D16_LOCKABLE
238+
|| pDesc->Format == D3D9Format::S8_LOCKABLE)
212239
return D3DERR_INVALIDCALL;
213240
}
214241

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)