port: EterImageLib Image/TGAImage/DXTCImage verbatim (+ d3d.h ddraw shim)

-fno-strict-aliasing on the port targets: 40250 relies on MSVC's lack of
type-based alias analysis (DXTCImage reads Color8888 through DWORD*).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-30 13:31:21 +09:00
co-authored by Claude Opus 5.5
parent 32c5a09d6e
commit 75ea2703c6
10 changed files with 2758 additions and 152 deletions
+6
View File
@@ -43,6 +43,9 @@ endif()
set(MT_PORT_WARNING_FLAGS)
if(NOT MSVC)
set(MT_PORT_WARNING_FLAGS -Wno-unknown-pragmas -Wno-format-security)
# MSVC does no type-based alias analysis and 40250 relies on it (DXTCImage reads a Color8888 through a
# DWORD*; clang -O2 then loads the colour before it is written).
list(APPEND MT_PORT_WARNING_FLAGS -fno-strict-aliasing)
endif()
target_compile_options(port_logic PUBLIC ${MT_PORT_WARNING_FLAGS})
# 40250 headers keep `#pragma comment(lib, "d3d8.lib")` etc. verbatim; clang turns them into ELF
@@ -208,6 +211,9 @@ if(BUILD_TESTING AND CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME)
add_executable(port_input_test ${PROJECT_SOURCE_DIR}/tests/port/port_input_test.cpp)
target_link_libraries(port_input_test PRIVATE port_platform)
add_test(NAME port.input COMMAND $<TARGET_FILE:port_input_test>)
add_executable(port_eter_image_test ${PROJECT_SOURCE_DIR}/tests/port/port_eter_image_test.cpp)
target_link_libraries(port_eter_image_test PRIVATE port_platform)
add_test(NAME port.eter_image COMMAND $<TARGET_FILE:port_eter_image_test>)
# MilesLib: the 40250 sound managers over the Miles emulation (platform/MilesLib/MilesAil.cpp).
add_executable(port_miles_test ${PROJECT_SOURCE_DIR}/tests/port/port_miles_test.cpp)
+122
View File
@@ -0,0 +1,122 @@
#pragma once
// Shim for the DirectX 7 <d3d.h> on non-Windows targets: the <ddraw.h> surface description 40250
// EterImageLib/DXTCImage.cpp copies straight out of a .dds file (the 124 bytes after the "DDS " magic).
//
// PORT: lpSurface is a pointer in <ddraw.h>, 4 bytes in the 32-bit client; it is a DWORD here so the
// structure keeps the on-disk layout on 64-bit targets.
#include "../win32/windows.h"
#define DDSD_CAPS 0x00000001l
#define DDSD_HEIGHT 0x00000002l
#define DDSD_WIDTH 0x00000004l
#define DDSD_PITCH 0x00000008l
#define DDSD_PIXELFORMAT 0x00001000l
#define DDSD_MIPMAPCOUNT 0x00020000l
#define DDSD_LINEARSIZE 0x00080000l
#define DDPF_ALPHAPIXELS 0x00000001l
#define DDPF_FOURCC 0x00000004l
#define DDPF_RGB 0x00000040l
#define DDPF_ALPHAPREMULT 0x00008000l
typedef struct _DDCOLORKEY
{
DWORD dwColorSpaceLowValue;
DWORD dwColorSpaceHighValue;
} DDCOLORKEY;
typedef struct _DDPIXELFORMAT
{
DWORD dwSize;
DWORD dwFlags;
DWORD dwFourCC;
union
{
DWORD dwRGBBitCount;
DWORD dwYUVBitCount;
DWORD dwZBufferBitDepth;
DWORD dwAlphaBitDepth;
DWORD dwLuminanceBitCount;
DWORD dwBumpBitCount;
DWORD dwPrivateFormatBitCount;
};
union
{
DWORD dwRBitMask;
DWORD dwYBitMask;
DWORD dwStencilBitDepth;
DWORD dwLuminanceBitMask;
DWORD dwBumpDuBitMask;
DWORD dwOperations;
};
union
{
DWORD dwGBitMask;
DWORD dwUBitMask;
DWORD dwZBitMask;
DWORD dwBumpDvBitMask;
};
union
{
DWORD dwBBitMask;
DWORD dwVBitMask;
DWORD dwStencilBitMask;
DWORD dwBumpLuminanceBitMask;
};
union
{
DWORD dwRGBAlphaBitMask;
DWORD dwYUVAlphaBitMask;
DWORD dwLuminanceAlphaBitMask;
DWORD dwRGBZBitMask;
DWORD dwYUVZBitMask;
};
} DDPIXELFORMAT;
typedef struct _DDSCAPS2
{
DWORD dwCaps;
DWORD dwCaps2;
DWORD dwCaps3;
DWORD dwCaps4;
} DDSCAPS2;
typedef struct _DDSURFACEDESC2
{
DWORD dwSize;
DWORD dwFlags;
DWORD dwHeight;
DWORD dwWidth;
union
{
LONG lPitch;
DWORD dwLinearSize;
};
union
{
DWORD dwBackBufferCount;
DWORD dwDepth;
};
union
{
DWORD dwMipMapCount;
DWORD dwRefreshRate;
DWORD dwSrcVBHandle;
};
DWORD dwAlphaBitDepth;
DWORD dwReserved;
DWORD lpSurface;
union
{
DDCOLORKEY ddckCKDestOverlay;
DWORD dwEmptyFaceColor;
};
DDCOLORKEY ddckCKDestBlt;
DDCOLORKEY ddckCKSrcOverlay;
DDCOLORKEY ddckCKSrcBlt;
DDPIXELFORMAT ddpfPixelFormat;
DDSCAPS2 ddsCaps;
DWORD dwTextureStage;
} DDSURFACEDESC2, *LPDDSURFACEDESC2;
static_assert(sizeof(DDPIXELFORMAT) == 32 && sizeof(DDSURFACEDESC2) == 124, "the .dds header layout");