From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx10_43/texture.c | 1 + dlls/d3dx11_43/texture.c | 1 + dlls/d3dx9_36/d3dx_helpers.c | 21 ++++++++- dlls/d3dx9_36/d3dx_helpers.h | 10 ++++- dlls/d3dx9_36/tests/surface.c | 82 ++++++++++++++++------------------- dlls/d3dx9_36/util.c | 2 + 6 files changed, 70 insertions(+), 47 deletions(-)
diff --git a/dlls/d3dx10_43/texture.c b/dlls/d3dx10_43/texture.c index ab488dcfa2f..9d0d6063a0b 100644 --- a/dlls/d3dx10_43/texture.c +++ b/dlls/d3dx10_43/texture.c @@ -90,6 +90,7 @@ static DXGI_FORMAT dxgi_format_from_legacy_dds_d3dx_pixel_format_id(enum d3dx_pi /* These formats are known and explicitly unsupported on d3dx10+. */ case D3DX_PIXEL_FORMAT_U8V8W8Q8_SNORM: case D3DX_PIXEL_FORMAT_U8V8_SNORM: + case D3DX_PIXEL_FORMAT_U8V8_SNORM_Cx: case D3DX_PIXEL_FORMAT_U16V16_SNORM: case D3DX_PIXEL_FORMAT_U8V8_SNORM_L8X8_UNORM: case D3DX_PIXEL_FORMAT_U10V10W10_SNORM_A2_UNORM: diff --git a/dlls/d3dx11_43/texture.c b/dlls/d3dx11_43/texture.c index cbf3b630f58..b7c9761ad18 100644 --- a/dlls/d3dx11_43/texture.c +++ b/dlls/d3dx11_43/texture.c @@ -85,6 +85,7 @@ static DXGI_FORMAT dxgi_format_from_legacy_dds_d3dx_pixel_format_id(enum d3dx_pi /* These formats are known and explicitly unsupported on d3dx10+. */ case D3DX_PIXEL_FORMAT_U8V8W8Q8_SNORM: case D3DX_PIXEL_FORMAT_U8V8_SNORM: + case D3DX_PIXEL_FORMAT_U8V8_SNORM_Cx: case D3DX_PIXEL_FORMAT_U16V16_SNORM: case D3DX_PIXEL_FORMAT_U8V8_SNORM_L8X8_UNORM: case D3DX_PIXEL_FORMAT_U10V10W10_SNORM_A2_UNORM: diff --git a/dlls/d3dx9_36/d3dx_helpers.c b/dlls/d3dx9_36/d3dx_helpers.c index 60394ca1d9b..4c70a328e40 100644 --- a/dlls/d3dx9_36/d3dx_helpers.c +++ b/dlls/d3dx9_36/d3dx_helpers.c @@ -113,6 +113,7 @@ static const struct pixel_format_desc formats[] = {D3DX_PIXEL_FORMAT_U8V8W8Q8_SNORM, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, CTYPE_SNORM, CTYPE_SNORM, 0 }, {D3DX_PIXEL_FORMAT_U16V16W16Q16_SNORM, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, CTYPE_SNORM, CTYPE_SNORM, 0 }, {D3DX_PIXEL_FORMAT_U8V8_SNORM, { 0, 8, 8, 0}, { 0, 0, 8, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_SNORM, 0 }, + {D3DX_PIXEL_FORMAT_U8V8_SNORM_Cx, { 0, 8, 8, 0}, { 0, 0, 8, 0}, 2, 1, 1, 2, CTYPE_EMPTY, CTYPE_SHILO, 0 }, {D3DX_PIXEL_FORMAT_U16V16_SNORM, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, CTYPE_EMPTY, CTYPE_SNORM, 0 }, {D3DX_PIXEL_FORMAT_U8V8_SNORM_L8X8_UNORM, { 8, 8, 8, 0}, {16, 0, 8, 0}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_SNORM, 0 }, {D3DX_PIXEL_FORMAT_U10V10W10_SNORM_A2_UNORM, { 2, 10, 10, 10}, {30, 0, 10, 20}, 4, 1, 1, 4, CTYPE_UNORM, CTYPE_SNORM, 0 }, @@ -240,6 +241,7 @@ static const struct { { 32, DDS_PF_FOURCC, 0x72 }, D3DX_PIXEL_FORMAT_R32_FLOAT }, { { 32, DDS_PF_FOURCC, 0x73 }, D3DX_PIXEL_FORMAT_R32G32_FLOAT }, { { 32, DDS_PF_FOURCC, 0x74 }, D3DX_PIXEL_FORMAT_R32G32B32A32_FLOAT }, + { { 32, DDS_PF_FOURCC, 0x75 }, D3DX_PIXEL_FORMAT_U8V8_SNORM_Cx }, /* DDS_PF_RGB. */ { { 32, DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0x00 }, D3DX_PIXEL_FORMAT_B2G3R3_UNORM }, { { 32, DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0x0000 }, D3DX_PIXEL_FORMAT_B5G6R5_UNORM }, @@ -781,7 +783,8 @@ static enum d3dx_pixel_format_id d3dx_get_closest_d3dx_pixel_format_id(const enu continue; if (rgb_only && curfmt->rgb_type == CTYPE_EMPTY) continue; - if (fmt->rgb_type == CTYPE_SNORM && curfmt->rgb_type != CTYPE_SNORM) + if ((fmt->rgb_type == CTYPE_SNORM && curfmt->rgb_type != CTYPE_SNORM) + || (fmt->rgb_type == CTYPE_SHILO && curfmt->rgb_type != CTYPE_SHILO)) continue;
cur_rgb_channels = !!curfmt->bits[1] + !!curfmt->bits[2] + !!curfmt->bits[3]; @@ -2069,6 +2072,7 @@ static enum range get_range_for_component_type(enum component_type type) switch (type) { case CTYPE_SNORM: + case CTYPE_SHILO: return RANGE_SNORM;
case CTYPE_LUMA: @@ -2127,6 +2131,7 @@ void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *sr *dst_component = (float)tmp / mask; break;
+ case CTYPE_SHILO: case CTYPE_SNORM: { const uint32_t sign_bit = (1u << (format->bits[c] - 1)); @@ -2152,6 +2157,17 @@ void format_to_d3dx_color(const struct pixel_format_desc *format, const BYTE *sr assert(format->bits[1]); *dst_component = dst->value.x; } + else if (dst_ctype == CTYPE_SHILO) + { + float cx_val; + + assert(format->bits[1] && format->bits[2] && c == 3); + cx_val = 1.0f - powf(dst->value.x, 2.0f) - powf(dst->value.y, 2.0f); + if (cx_val <= 0.0f || cx_val > 1.0f) + *dst_component = 0.0f; + else + *dst_component = sqrtf(cx_val); + } else { *dst_component = 1.0f; @@ -2222,8 +2238,9 @@ void format_from_d3dx_color(const struct pixel_format_desc *format, const struct break; }
- /* We shouldn't be trying to output to CTYPE_INDEX. */ + /* We shouldn't be trying to output to CTYPE_INDEX or CTYPE_SHILO. */ case CTYPE_INDEX: + case CTYPE_SHILO: assert(0); break;
diff --git a/dlls/d3dx9_36/d3dx_helpers.h b/dlls/d3dx9_36/d3dx_helpers.h index 8263d832bfa..a840f99b46e 100644 --- a/dlls/d3dx9_36/d3dx_helpers.h +++ b/dlls/d3dx9_36/d3dx_helpers.h @@ -220,6 +220,7 @@ enum d3dx_pixel_format_id D3DX_PIXEL_FORMAT_U8V8W8Q8_SNORM, D3DX_PIXEL_FORMAT_U16V16W16Q16_SNORM, D3DX_PIXEL_FORMAT_U8V8_SNORM, + D3DX_PIXEL_FORMAT_U8V8_SNORM_Cx, D3DX_PIXEL_FORMAT_U16V16_SNORM, D3DX_PIXEL_FORMAT_U8V8_SNORM_L8X8_UNORM, D3DX_PIXEL_FORMAT_U10V10W10_SNORM_A2_UNORM, @@ -248,6 +249,7 @@ enum component_type CTYPE_FLOAT, CTYPE_LUMA, CTYPE_INDEX, + CTYPE_SHILO, /* Signed HILO. */ };
enum format_flag @@ -351,6 +353,11 @@ static inline BOOL is_packed_format(const struct pixel_format_desc *format) return !!(format->flags & FMT_FLAG_PACKED); }
+static inline BOOL is_signed_hilo_format(const struct pixel_format_desc *format) +{ + return format->rgb_type == CTYPE_SHILO; +} + static inline BOOL format_types_match(const struct pixel_format_desc *src, const struct pixel_format_desc *dst) { if ((src->a_type && dst->a_type) && (src->a_type != dst->a_type)) @@ -382,7 +389,8 @@ static inline BOOL is_conversion_from_supported(const struct pixel_format_desc *
static inline BOOL is_conversion_to_supported(const struct pixel_format_desc *format) { - return !is_index_format(format) && !is_packed_format(format) && !is_unknown_format(format); + return !is_index_format(format) && !is_packed_format(format) && !is_signed_hilo_format(format) + && !is_unknown_format(format); }
const struct pixel_format_desc *get_d3dx_pixel_format_info(enum d3dx_pixel_format_id format); diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 0245ab70f62..15d92a596f2 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -1001,7 +1001,7 @@ static void test_D3DXGetImageInfo(void) check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_R32F, 0, 0, 0, 0, 0, D3DFMT_R32F); check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_G32R32F, 0, 0, 0, 0, 0, D3DFMT_G32R32F); check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_A32B32G32R32F, 0, 0, 0, 0, 0, D3DFMT_A32B32G32R32F); - todo_wine check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_CxV8U8, 0, 0, 0, 0, 0, D3DFMT_CxV8U8); + check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_CxV8U8, 0, 0, 0, 0, 0, D3DFMT_CxV8U8); check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5); check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5); check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4); @@ -2958,18 +2958,15 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) /* D3DFMT_CxV8U8. */ hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_cxv8u8, D3DFMT_CxV8U8, 4, NULL, &rect, D3DX_FILTER_NONE, 0); - todo_wine ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - { - hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); - ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); - check_pixel_4bpp(&lockrect, 0, 0, 0xffffff80); - check_pixel_4bpp(&lockrect, 1, 0, 0xff000080); - check_pixel_4bpp(&lockrect, 0, 1, 0xff8080ff); - check_pixel_4bpp(&lockrect, 1, 1, 0xffed80c1); - hr = IDirect3DSurface9_UnlockRect(surf); - ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); - } + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); + check_pixel_4bpp(&lockrect, 0, 0, 0xffffff80); + check_pixel_4bpp(&lockrect, 1, 0, 0xff000080); + check_pixel_4bpp(&lockrect, 0, 1, 0xff8080ff); + check_pixel_4bpp(&lockrect, 1, 1, 0xffed80c1); + hr = IDirect3DSurface9_UnlockRect(surf); + ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a32b32g32r32f, D3DFMT_A32B32G32R32F, 32, NULL, &rect, D3DX_FILTER_NONE, 0); @@ -3578,19 +3575,17 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) /* D3DFMT_CxV8U8. */ hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_cxv8u8, D3DFMT_CxV8U8, 4, NULL, &rect, D3DX_FILTER_NONE, 0); - todo_wine ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - { - /* The calculated Cx value goes into the blue channel. */ - hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); - ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); - check_pixel_float4(&lockrect, 0, 0, 1.0f, 1.0f, 0.0f, 1.0f, 0, FALSE); - check_pixel_float4(&lockrect, 1, 0, -1.0f, -1.0f, 0.0f, 1.0f, 0, FALSE); - check_pixel_float4(&lockrect, 0, 1, 0.0f, 0.0f, 1.0f, 1.0f, 0, FALSE); - check_pixel_float4(&lockrect, 1, 1, 8.58267725e-001, 0.0f, 5.13202250e-001, 1.0f, 0, FALSE); - hr = IDirect3DSurface9_UnlockRect(surf); - ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); - } + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + + /* The calculated Cx value goes into the blue channel. */ + hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); + check_pixel_float4(&lockrect, 0, 0, 1.0f, 1.0f, 0.0f, 1.0f, 0, FALSE); + check_pixel_float4(&lockrect, 1, 0, -1.0f, -1.0f, 0.0f, 1.0f, 0, FALSE); + check_pixel_float4(&lockrect, 0, 1, 0.0f, 0.0f, 1.0f, 1.0f, 0, FALSE); + check_pixel_float4(&lockrect, 1, 1, 8.58267725e-001, 0.0f, 5.13202250e-001, 1.0f, 0, FALSE); + hr = IDirect3DSurface9_UnlockRect(surf); + ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
check_release((IUnknown*)surf, 0); } @@ -3710,18 +3705,17 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device) /* Add CxV8U8 test here. */ hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_cxv8u8, D3DFMT_CxV8U8, 4, NULL, &rect, D3DX_FILTER_NONE, 0); - todo_wine ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - { - hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); - ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); - check_pixel_4bpp(&lockrect, 0, 0, 0x00ff7f7f); - check_pixel_4bpp(&lockrect, 1, 0, 0x00ff8282); - check_pixel_4bpp(&lockrect, 0, 1, 0x00ff0000); - check_pixel_4bpp(&lockrect, 1, 1, 0x00ff006d); - hr = IDirect3DSurface9_UnlockRect(surf); - ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); - } + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + + hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr); + check_pixel_4bpp(&lockrect, 0, 0, 0x00ff7f7f); + check_pixel_4bpp(&lockrect, 1, 0, 0x00ff8282); + check_pixel_4bpp(&lockrect, 0, 1, 0x00ff0000); + check_pixel_4bpp(&lockrect, 1, 1, 0x00ff006d); + hr = IDirect3DSurface9_UnlockRect(surf); + ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr); + check_release((IUnknown*)surf, 1); check_release((IUnknown*)tex, 0); } @@ -4155,7 +4149,7 @@ static void test_save_surface_to_dds(IDirect3DDevice9 *device) { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_CxV8U8, 0, 0, 0, 0, 0 }, DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT, 4, 4, 0, 0, 0, DDSCAPS_TEXTURE, 0, DDS_FILE_HEADER_SIZE + (4 * 2 * 4) - }, .todo_hr = TRUE + } }, }; struct @@ -4828,12 +4822,12 @@ static void test_save_surface_iffs(IDirect3DDevice9 *device) }, }, { D3DFMT_CxV8U8, NULL, 0x00, - { { D3DERR_INVALIDCALL, .todo_hr = TRUE }, - { D3DERR_INVALIDCALL, .todo_hr = TRUE }, - { D3DERR_INVALIDCALL, .todo_hr = TRUE }, - { D3DERR_INVALIDCALL, .todo_hr = TRUE }, - { D3DERR_INVALIDCALL, .todo_hr = TRUE }, + { { D3DERR_INVALIDCALL }, + { D3DERR_INVALIDCALL }, + { D3DERR_INVALIDCALL }, + { D3DERR_INVALIDCALL }, { D3DERR_INVALIDCALL, .todo_hr = TRUE }, + { D3DERR_INVALIDCALL }, { D3DERR_INVALIDCALL, .todo_hr = TRUE }, { D3DERR_INVALIDCALL, .todo_hr = TRUE }, }, diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c index dd2162d9f6e..7f1fc24e1cd 100644 --- a/dlls/d3dx9_36/util.c +++ b/dlls/d3dx9_36/util.c @@ -62,6 +62,7 @@ D3DFORMAT d3dformat_from_d3dx_pixel_format_id(enum d3dx_pixel_format_id format) case D3DX_PIXEL_FORMAT_P8_UINT_A8_UNORM: return D3DFMT_A8P8; case D3DX_PIXEL_FORMAT_U8V8W8Q8_SNORM: return D3DFMT_Q8W8V8U8; case D3DX_PIXEL_FORMAT_U8V8_SNORM: return D3DFMT_V8U8; + case D3DX_PIXEL_FORMAT_U8V8_SNORM_Cx: return D3DFMT_CxV8U8; case D3DX_PIXEL_FORMAT_U16V16_SNORM: return D3DFMT_V16U16; case D3DX_PIXEL_FORMAT_U8V8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8; case D3DX_PIXEL_FORMAT_U10V10W10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10; @@ -121,6 +122,7 @@ enum d3dx_pixel_format_id d3dx_pixel_format_id_from_d3dformat(D3DFORMAT format) case D3DFMT_A8P8: return D3DX_PIXEL_FORMAT_P8_UINT_A8_UNORM; case D3DFMT_Q8W8V8U8: return D3DX_PIXEL_FORMAT_U8V8W8Q8_SNORM; case D3DFMT_V8U8: return D3DX_PIXEL_FORMAT_U8V8_SNORM; + case D3DFMT_CxV8U8: return D3DX_PIXEL_FORMAT_U8V8_SNORM_Cx; case D3DFMT_V16U16: return D3DX_PIXEL_FORMAT_U16V16_SNORM; case D3DFMT_X8L8V8U8: return D3DX_PIXEL_FORMAT_U8V8_SNORM_L8X8_UNORM; case D3DFMT_A2W10V10U10: return D3DX_PIXEL_FORMAT_U10V10W10_SNORM_A2_UNORM;