diff --git a/GPU/D3D11/GPU_D3D11.cpp b/GPU/D3D11/GPU_D3D11.cpp index b3df469c68..f6dc4f09a9 100644 --- a/GPU/D3D11/GPU_D3D11.cpp +++ b/GPU/D3D11/GPU_D3D11.cpp @@ -511,6 +511,11 @@ void GPU_D3D11::CheckGPUFeatures() { features |= GPU_SUPPORTS_LARGE_VIEWPORTS; features |= GPU_SUPPORTS_DUALSOURCE_BLEND; features |= GPU_SUPPORTS_ANY_COPY_IMAGE; + + if (draw_->GetDataFormatSupport(Draw::DataFormat::A4B4G4R4_UNORM_PACK16) & Draw::FMT_TEXTURE) { + features |= GPU_SUPPORTS_4BIT_FORMAT; + } + if (draw_->GetDeviceCaps().logicOpSupported) { // This requires a little bit more code in statemapping, and passing in a device1_ object. // features |= GPU_SUPPORTS_LOGIC_OP; diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index d839a0671c..d03fe5c9cc 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -473,6 +473,7 @@ void GPU_DX9::UpdateCmdInfo() { void GPU_DX9::CheckGPUFeatures() { u32 features = 0; + features |= GPU_SUPPORTS_4BIT_FORMAT; features |= GPU_SUPPORTS_BLEND_MINMAX; features |= GPU_SUPPORTS_TEXTURE_LOD_CONTROL; features |= GPU_PREFER_CPU_DOWNLOAD; diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index fc3454ec7d..4d125a1f20 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -505,6 +505,9 @@ GPU_GLES::~GPU_GLES() { // Take the raw GL extension and versioning data and turn into feature flags. void GPU_GLES::CheckGPUFeatures() { u32 features = 0; + + features |= GPU_SUPPORTS_4BIT_FORMAT; + if (gl_extensions.ARB_blend_func_extended || gl_extensions.EXT_blend_func_extended) { if (gl_extensions.gpuVendor == GPU_VENDOR_INTEL || !gl_extensions.VersionGEThan(3, 0, 0)) { // Don't use this extension to off on sub 3.0 OpenGL versions as it does not seem reliable diff --git a/GPU/GPUState.h b/GPU/GPUState.h index 1ca8f435bf..cd198f86e7 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -459,6 +459,7 @@ enum { GPU_SUPPORTS_INSTANCE_RENDERING = FLAG_BIT(10), GPU_SUPPORTS_VERTEX_TEXTURE_FETCH = FLAG_BIT(11), GPU_SUPPORTS_TEXTURE_FLOAT = FLAG_BIT(12), + GPU_SUPPORTS_4BIT_FORMAT = FLAG_BIT(13), GPU_SUPPORTS_LARGE_VIEWPORTS = FLAG_BIT(16), GPU_SUPPORTS_ACCURATE_DEPTH = FLAG_BIT(17), GPU_SUPPORTS_VAO = FLAG_BIT(18), diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index d3f0cf5b77..f68623dcc3 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -462,6 +462,7 @@ GPU_Vulkan::~GPU_Vulkan() { void GPU_Vulkan::CheckGPUFeatures() { gstate_c.featureFlags = 0; + gstate_c.featureFlags |= GPU_SUPPORTS_4BIT_FORMAT; if (vulkan_->GetFeaturesEnabled().wideLines) { gstate_c.featureFlags |= GPU_SUPPORTS_WIDE_LINES; } diff --git a/ext/native/gfx_es2/draw_text.cpp b/ext/native/gfx_es2/draw_text.cpp index 29a1e72e8c..7454364f8e 100644 --- a/ext/native/gfx_es2/draw_text.cpp +++ b/ext/native/gfx_es2/draw_text.cpp @@ -282,10 +282,10 @@ void TextDrawer::DrawString(DrawBuffer &target, const char *str, float x, float DataFormat texFormat; // For our purposes these are equivalent, so just choose the supported one. D3D can emulate them. - if (draw_->GetDataFormatSupport(Draw::DataFormat::B4G4R4A4_UNORM_PACK16) & FMT_TEXTURE) + if (draw_->GetDataFormatSupport(Draw::DataFormat::A4B4G4R4_UNORM_PACK16) & FMT_TEXTURE) + texFormat = Draw::DataFormat::A4B4G4R4_UNORM_PACK16; + else if (draw_->GetDataFormatSupport(Draw::DataFormat::B4G4R4A4_UNORM_PACK16) & FMT_TEXTURE) texFormat = Draw::DataFormat::B4G4R4A4_UNORM_PACK16; - else if (draw_->GetDataFormatSupport(Draw::DataFormat::R4G4B4A4_UNORM_PACK16) & FMT_TEXTURE) - texFormat = Draw::DataFormat::R4G4B4A4_UNORM_PACK16; else texFormat = Draw::DataFormat::R8G8B8A8_UNORM; @@ -304,8 +304,7 @@ void TextDrawer::DrawString(DrawBuffer &target, const char *str, float x, float } } desc.initData.push_back((uint8_t *)bitmapData32); - } - else { + } else if (texFormat == Draw::DataFormat::B4G4R4A4_UNORM_PACK16) { bitmapData16 = new uint16_t[entry->bmWidth * entry->bmHeight]; for (int y = 0; y < entry->bmHeight; y++) { for (int x = 0; x < entry->bmWidth; x++) { @@ -314,6 +313,15 @@ void TextDrawer::DrawString(DrawBuffer &target, const char *str, float x, float } } desc.initData.push_back((uint8_t *)bitmapData16); + } else { + bitmapData16 = new uint16_t[entry->bmWidth * entry->bmHeight]; + for (int y = 0; y < entry->bmHeight; y++) { + for (int x = 0; x < entry->bmWidth; x++) { + uint8_t bAlpha = (uint8_t)((ctx_->pBitmapBits[MAX_TEXT_WIDTH * y + x] & 0xff) >> 4); + bitmapData16[entry->bmWidth * y + x] = (bAlpha << 12) | 0x0fff; + } + } + desc.initData.push_back((uint8_t *)bitmapData16); } desc.type = TextureType::LINEAR2D; diff --git a/ext/native/thin3d/thin3d_d3d11.cpp b/ext/native/thin3d/thin3d_d3d11.cpp index ef9b55f180..f5989d7a27 100644 --- a/ext/native/thin3d/thin3d_d3d11.cpp +++ b/ext/native/thin3d/thin3d_d3d11.cpp @@ -123,6 +123,7 @@ private: ID3D11Device *device_; ID3D11DeviceContext *context_; IDXGISwapChain *swapChain_ = nullptr; + bool b4g4r4a4Supported_ = false; ID3D11Texture2D *bbRenderTargetTex_ = nullptr; ID3D11RenderTargetView *bbRenderTargetView_ = nullptr; @@ -197,6 +198,13 @@ D3D11DrawContext::D3D11DrawContext(ID3D11Device *device, ID3D11DeviceContext *co caps_.logicOpSupported = true; } } + + UINT support; + result = device_->CheckFormatSupport(DXGI_FORMAT_B4G4R4A4_UNORM, &support); + if (SUCCEEDED(result)) { + b4g4r4a4Supported_ = true; + } + int width; int height; GetRes(hWnd_, width, height); @@ -362,6 +370,9 @@ static DXGI_FORMAT dataFormatToD3D11(DataFormat format) { case DataFormat::R32G32_FLOAT: return DXGI_FORMAT_R32G32_FLOAT; case DataFormat::R32G32B32_FLOAT: return DXGI_FORMAT_R32G32B32_FLOAT; case DataFormat::R32G32B32A32_FLOAT: return DXGI_FORMAT_R32G32B32A32_FLOAT; + case DataFormat::A4B4G4R4_UNORM_PACK16: return DXGI_FORMAT_B4G4R4A4_UNORM; + case DataFormat::A1R5G5B5_UNORM_PACK16: return DXGI_FORMAT_B5G5R5A1_UNORM; + case DataFormat::R5G6B5_UNORM_PACK16: return DXGI_FORMAT_B5G6R5_UNORM; case DataFormat::R8G8B8A8_UNORM: return DXGI_FORMAT_R8G8B8A8_UNORM; case DataFormat::R8G8B8A8_UNORM_SRGB: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; case DataFormat::B8G8R8A8_UNORM: return DXGI_FORMAT_B8G8R8A8_UNORM; @@ -1008,10 +1019,12 @@ uint32_t D3D11DrawContext::GetDataFormatSupport(DataFormat fmt) const { case DataFormat::B8G8R8A8_UNORM: return FMT_RENDERTARGET | FMT_TEXTURE; - // D3D11 has no support for 4-bit component formats. - case DataFormat::B4G4R4A4_UNORM_PACK16: - case DataFormat::R4G4B4A4_UNORM_PACK16: + // D3D11 has no support for 4-bit component formats, except this one and only on Windows 8. case DataFormat::A4B4G4R4_UNORM_PACK16: + return b4g4r4a4Supported_ ? FMT_TEXTURE : 0; + + case DataFormat::R4G4B4A4_UNORM_PACK16: + case DataFormat::B4G4R4A4_UNORM_PACK16: return 0; case DataFormat::R8G8B8A8_UNORM: diff --git a/ext/native/thin3d/thin3d_d3d9.cpp b/ext/native/thin3d/thin3d_d3d9.cpp index 2e75610290..a9785acf2d 100644 --- a/ext/native/thin3d/thin3d_d3d9.cpp +++ b/ext/native/thin3d/thin3d_d3d9.cpp @@ -409,7 +409,7 @@ void D3D9Texture::SetImageData(int x, int y, int z, int width, int height, int d break; case DataFormat::A4B4G4R4_UNORM_PACK16: // Native - memcpy(dest, source, j * sizeof(uint16_t)); + memcpy(dest, source, width * sizeof(uint16_t)); break; case DataFormat::R8G8B8A8_UNORM: