Skip to content

Commit ab7b272

Browse files
committed
D3D11: Fix UAV creation failure for P8/format-convert textures
Textures created for GPU palette expansion and format conversion were using DXGI_FORMAT_R8G8B8A8_UNORM, which does not allow R32_UINT UAV reinterpretation. This caused CreateUnorderedAccessView to fail, falling back to the slow CPU path on every upload. Fix: create these textures as R8G8B8A8_TYPELESS (same typeless family as R32_UINT), and resolve to R8G8B8A8_UNORM when creating SRVs for sampling in HostSync and the blit path.
1 parent 85238c0 commit ab7b272

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/core/hle/D3D8/Rendering/Backend/Backend_D3D11.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ HRESULT CxbxD3D11Blt(
786786
// Create temporary SRV for source
787787
ID3D11ShaderResourceView* pSRV = nullptr;
788788
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
789-
srvDesc.Format = srcDesc.Format;
789+
srvDesc.Format = (srcDesc.Format == DXGI_FORMAT_R8G8B8A8_TYPELESS) ? DXGI_FORMAT_R8G8B8A8_UNORM : srcDesc.Format;
790790
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
791791
srvDesc.Texture2D.MipLevels = 1;
792792
HRESULT hr = g_pD3DDevice->CreateShaderResourceView(pSrc, &srvDesc, &pSRV);

src/core/hle/D3D8/Rendering/HostResourceCreate.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,16 @@ static HRESULT CreateGpuPixelContainerResource(
324324
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
325325
desc.CPUAccessFlags = 0;
326326
} else if (bSwizzled && X_Format == xbox::X_D3DFMT_P8) {
327-
// P8 textures use DEFAULT + UAV for GPU palette expand CS
328-
// Use R8G8B8A8_UNORM (not B8G8R8A8) for R32_UINT UAV compatibility
329-
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
327+
// P8 textures use DEFAULT + UAV for GPU palette expand CS.
328+
// Typeless allows R32_UINT UAV reinterpretation; SRV uses R8G8B8A8_UNORM.
329+
desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
330330
desc.Usage = D3D11_USAGE_DEFAULT;
331331
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
332332
desc.CPUAccessFlags = 0;
333333
} else if (bConvertTextureFormat && CxbxGetFormatConvertType(X_Format) != 0) {
334-
// Format-convertible textures use DEFAULT + UAV for GPU CS format conversion
335-
// Output is always R8G8B8A8_UNORM (CS writes packed RGBA via R32_UINT UAV)
336-
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
334+
// Format-convertible textures use DEFAULT + UAV for GPU CS format conversion.
335+
// Typeless allows R32_UINT UAV reinterpretation; SRV uses R8G8B8A8_UNORM.
336+
desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
337337
desc.Usage = D3D11_USAGE_DEFAULT;
338338
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
339339
desc.CPUAccessFlags = 0;

src/core/hle/D3D8/Rendering/HostSync.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,12 @@ static void CxbxBindTextureSRV(int stage, ID3D11Resource* pHostBaseTexture, bool
344344
case D3D11_RESOURCE_DIMENSION_TEXTURE2D: {
345345
D3D11_TEXTURE2D_DESC texDesc = {};
346346
((ID3D11Texture2D*)pHostBaseTexture)->GetDesc(&texDesc);
347-
srvDesc.Format = IsDepthFormat(texDesc.Format) ? GetDepthSRVFormat(texDesc.Format) : texDesc.Format;
347+
if (IsDepthFormat(texDesc.Format))
348+
srvDesc.Format = GetDepthSRVFormat(texDesc.Format);
349+
else if (texDesc.Format == DXGI_FORMAT_R8G8B8A8_TYPELESS)
350+
srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
351+
else
352+
srvDesc.Format = texDesc.Format;
348353
if (texDesc.ArraySize == 6) {
349354
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
350355
srvDesc.TextureCube.MipLevels = texDesc.MipLevels;

0 commit comments

Comments
 (0)