You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add GPU-side texture format channel fixup via shader constants
D3D11 lacks native luminance texture formats and requires CPU-side
per-pixel conversion for some 32-bit channel orders. This commit adds
a constant-driven channel swizzle in both pixel shader paths (Fixed
Function and Programmatic/NV2A combiner) that handles format
differences entirely on the GPU.
New TEXFMTFIXUP per-texture-stage constant with five modes:
0 = identity (no fixup)
1 = .gbar (X_D3DFMT_B8G8R8A8 uploaded raw as R8G8B8A8_UNORM)
2 = .abgr (X_D3DFMT_R8G8B8A8 uploaded raw as R8G8B8A8_UNORM)
3 = luminance: (L,0,0,1) -> (L,L,L,1) for L8/L16 on D3D11
4 = alpha-luminance: (L,A,0,1) -> (L,L,L,A) for A8L8 on D3D11
Changes:
- FixedFunctionPixelShader.hlsli: Add TEXFMTFIXUP field to
PsTextureStageState and shared constant definitions
- FixedFunctionPixelShader.hlsl: Apply fixup after texture sampling
- CxbxPixelShaderTemplate.hlsl: Add TEXFMTFIXUP at c42, new
ApplyTexFmtFixup() helper, apply in Sample2D/3D/6F
- XbPixelShaderCompiler.cpp: Add CxbxGetTexFmtFixup() that detects
Xbox texture format per stage; set constants for both FF and
programmatic PS paths; bump PSH_XBOX_CONSTANT_MAX to 43
- HostResourceCreate.cpp: On D3D11, skip CPU conversion for
B8G8R8A8 and R8G8B8A8 — upload raw bytes as R8G8B8A8_UNORM
(the shader swizzle handles the channel reorder)
- Backend_D3D11.h: Bump CXBX_D3D11_PS_CB_COUNT to 43
GPU-side benefits:
- Luminance formats (L8, A8L8, L16) now produce correct colors
instead of red-only output (fixes Halo lightmaps, etc.)
- B8G8R8A8 and R8G8B8A8 textures skip CPU per-pixel conversion
loop entirely — raw data stays on GPU with zero CPU touch
- [branch] on uniform ensures zero-cost for the common identity case
0 commit comments