From 44c15342f53e83d8eff0ce664f2263ec22b6d451 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Tue, 21 Jan 2014 00:31:24 -0800 Subject: [PATCH] Swizzling some textures. --- src/xenia/gpu/d3d11/d3d11_graphics_driver.cc | 19 +++++++++++++++- src/xenia/gpu/xenos/xenos.h | 24 ++++++++++++++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/xenia/gpu/d3d11/d3d11_graphics_driver.cc b/src/xenia/gpu/d3d11/d3d11_graphics_driver.cc index 6051ca5da..7daaaa8a2 100644 --- a/src/xenia/gpu/d3d11/d3d11_graphics_driver.cc +++ b/src/xenia/gpu/d3d11/d3d11_graphics_driver.cc @@ -1111,7 +1111,24 @@ D3D11GraphicsDriver::TextureInfo D3D11GraphicsDriver::GetTextureInfo( info.pitch = 1; break; case FMT_8_8_8_8: - info.format = DXGI_FORMAT_B8G8R8A8_UNORM; + switch (fetch.swizzle) { + case XE_GPU_SWIZZLE_RGBA: + info.format = DXGI_FORMAT_R8G8B8A8_UNORM; + break; + case XE_GPU_SWIZZLE_BGRA: + info.format = DXGI_FORMAT_B8G8R8A8_UNORM; + break; + case XE_GPU_SWIZZLE_RGB1: + info.format = DXGI_FORMAT_R8G8B8A8_UNORM; // ? + break; + case XE_GPU_SWIZZLE_BGR1: + info.format = DXGI_FORMAT_B8G8R8X8_UNORM; + break; + default: + XELOGW("D3D11: unhandled swizzle for FMT_8_8_8_8"); + info.format = DXGI_FORMAT_R8G8B8A8_UNORM; + break; + } info.block_size = 1; info.pitch = 4; break; diff --git a/src/xenia/gpu/xenos/xenos.h b/src/xenia/gpu/xenos/xenos.h index f47ddba4f..679ef7b4f 100644 --- a/src/xenia/gpu/xenos/xenos.h +++ b/src/xenia/gpu/xenos/xenos.h @@ -50,6 +50,25 @@ typedef enum { XE_GPU_ENDIAN_16IN32 = 0x3, } XE_GPU_ENDIAN; +#define XE_GPU_MAKE_SWIZZLE(x, y, z, w) \ + (((XE_GPU_SWIZZLE_##x) << 0) | ((XE_GPU_SWIZZLE_##y) << 3) | ((XE_GPU_SWIZZLE_##z) << 6) | ((XE_GPU_SWIZZLE_##w) << 9)) +typedef enum { + XE_GPU_SWIZZLE_X = 0, + XE_GPU_SWIZZLE_R = 0, + XE_GPU_SWIZZLE_Y = 1, + XE_GPU_SWIZZLE_G = 1, + XE_GPU_SWIZZLE_Z = 2, + XE_GPU_SWIZZLE_B = 2, + XE_GPU_SWIZZLE_W = 3, + XE_GPU_SWIZZLE_A = 3, + XE_GPU_SWIZZLE_0 = 4, + XE_GPU_SWIZZLE_1 = 5, + XE_GPU_SWIZZLE_RGBA = XE_GPU_MAKE_SWIZZLE(R, G, B, A), + XE_GPU_SWIZZLE_BGRA = XE_GPU_MAKE_SWIZZLE(B, G, R, A), + XE_GPU_SWIZZLE_RGB1 = XE_GPU_MAKE_SWIZZLE(R, G, B, 1), + XE_GPU_SWIZZLE_BGR1 = XE_GPU_MAKE_SWIZZLE(B, G, R, 1), +} XE_GPU_SWIZZLE; + XEFORCEINLINE uint32_t GpuSwap(uint32_t value, XE_GPU_ENDIAN endianness) { switch (endianness) { default: @@ -147,10 +166,7 @@ XEPACKEDUNION(xe_gpu_texture_fetch_t, { } size_3d; }; uint32_t unk3_0 : 1; // dword_3 - uint32_t swiz_x : 3; - uint32_t swiz_y : 3; - uint32_t swiz_z : 3; - uint32_t swiz_w : 3; + uint32_t swizzle : 12; // xyzw, 3b each (XE_GPU_SWIZZLE) uint32_t unk3_1 : 6; uint32_t mag_filter : 2; uint32_t min_filter : 2;