mirror of
https://github.com/microsoft/DirectXTex.git
synced 2026-02-04 04:16:12 +01:00
Xbox auxiliary EncodeDDSHeader helper exposed as public function (#497)
Some checks failed
MSBuild / build (Debug, ARM64, 2019) (push) Has been cancelled
CodeQL / Analyze (C/C++) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Debug, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Debug, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Debug-Clang, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Debug-Clang, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Release, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Release, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Release-Clang, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Release-Clang, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_arm64, arm64-Debug, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_arm64, arm64-Release, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_arm64, arm64ec-Debug, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_arm64, arm64ec-Release, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Debug, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Debug, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Debug-Clang, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Debug-Clang, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Release, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Release, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Release-Clang, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Release-Clang, windows-2022) (push) Has been cancelled
MSBuild / build (Debug, ARM64, 2022) (push) Has been cancelled
MSBuild / build (Debug, x64, 2019) (push) Has been cancelled
MSBuild / build (Debug, x64, 2022) (push) Has been cancelled
MSBuild / build (Debug, x86, 2019) (push) Has been cancelled
MSBuild / build (Debug, x86, 2022) (push) Has been cancelled
MSBuild / build (Release, ARM64, 2019) (push) Has been cancelled
MSBuild / build (Release, ARM64, 2022) (push) Has been cancelled
MSBuild / build (Release, x64, 2019) (push) Has been cancelled
MSBuild / build (Release, x64, 2022) (push) Has been cancelled
MSBuild / build (Release, x86, 2019) (push) Has been cancelled
MSBuild / build (Release, x86, 2022) (push) Has been cancelled
Microsoft C++ Code Analysis / Analyze (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Debug, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Debug, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Debug-Clang, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Debug-Clang, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Release, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Release, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Release-Clang, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Release-Clang, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_arm64, arm64-Debug, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_arm64, arm64-Release, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_arm64, arm64ec-Debug, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_arm64, arm64ec-Release, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Debug, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Debug, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Debug-Clang, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Debug-Clang, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Release, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Release, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Release-Clang, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Release-Clang, windows-2022) (push) Has been cancelled
Some checks failed
MSBuild / build (Debug, ARM64, 2019) (push) Has been cancelled
CodeQL / Analyze (C/C++) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Debug, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Debug, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Debug-Clang, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Debug-Clang, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Release, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Release, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Release-Clang, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64, x64-Release-Clang, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_arm64, arm64-Debug, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_arm64, arm64-Release, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_arm64, arm64ec-Debug, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_arm64, arm64ec-Release, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Debug, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Debug, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Debug-Clang, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Debug-Clang, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Release, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Release, windows-2022) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Release-Clang, windows-2019) (push) Has been cancelled
CMake (Windows) / build (amd64_x86, x86-Release-Clang, windows-2022) (push) Has been cancelled
MSBuild / build (Debug, ARM64, 2022) (push) Has been cancelled
MSBuild / build (Debug, x64, 2019) (push) Has been cancelled
MSBuild / build (Debug, x64, 2022) (push) Has been cancelled
MSBuild / build (Debug, x86, 2019) (push) Has been cancelled
MSBuild / build (Debug, x86, 2022) (push) Has been cancelled
MSBuild / build (Release, ARM64, 2019) (push) Has been cancelled
MSBuild / build (Release, ARM64, 2022) (push) Has been cancelled
MSBuild / build (Release, x64, 2019) (push) Has been cancelled
MSBuild / build (Release, x64, 2022) (push) Has been cancelled
MSBuild / build (Release, x86, 2019) (push) Has been cancelled
MSBuild / build (Release, x86, 2022) (push) Has been cancelled
Microsoft C++ Code Analysis / Analyze (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Debug, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Debug, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Debug-Clang, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Debug-Clang, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Release, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Release, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Release-Clang, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64, x64-Release-Clang, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_arm64, arm64-Debug, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_arm64, arm64-Release, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_arm64, arm64ec-Debug, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_arm64, arm64ec-Release, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Debug, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Debug, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Debug-Clang, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Debug-Clang, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Release, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Release, windows-2022) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Release-Clang, windows-2019) (push) Has been cancelled
CTest (Windows) / build (amd64_x86, x86-Release-Clang, windows-2022) (push) Has been cancelled
This commit is contained in:
@@ -410,7 +410,7 @@ HRESULT DirectX::LoadFromEXRFile(const wchar_t* szFile, TexMetadata* metadata, S
|
||||
|
||||
hr = image.Initialize2D(DXGI_FORMAT_R16G16B16A16_FLOAT,
|
||||
static_cast<size_t>(width), static_cast<size_t>(height), arraySize, 1u);
|
||||
|
||||
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
|
||||
@@ -69,12 +69,12 @@ namespace Xbox
|
||||
XboxImage(const XboxImage&) = delete;
|
||||
XboxImage& operator=(const XboxImage&) = delete;
|
||||
|
||||
HRESULT Initialize(_In_ const XG_TEXTURE1D_DESC& desc, _In_ const XG_RESOURCE_LAYOUT& layout, _In_ uint32_t miscFlags2 = 0);
|
||||
HRESULT Initialize(_In_ const XG_TEXTURE2D_DESC& desc, _In_ const XG_RESOURCE_LAYOUT& layout, _In_ uint32_t miscFlags2 = 0);
|
||||
HRESULT Initialize(_In_ const XG_TEXTURE3D_DESC& desc, _In_ const XG_RESOURCE_LAYOUT& layout, _In_ uint32_t miscFlags2 = 0);
|
||||
HRESULT Initialize(_In_ const DirectX::TexMetadata& mdata, _In_ XboxTileMode tm, _In_ uint32_t size, _In_ uint32_t alignment);
|
||||
HRESULT __cdecl Initialize(_In_ const XG_TEXTURE1D_DESC& desc, _In_ const XG_RESOURCE_LAYOUT& layout, _In_ uint32_t miscFlags2 = 0);
|
||||
HRESULT __cdecl Initialize(_In_ const XG_TEXTURE2D_DESC& desc, _In_ const XG_RESOURCE_LAYOUT& layout, _In_ uint32_t miscFlags2 = 0);
|
||||
HRESULT __cdecl Initialize(_In_ const XG_TEXTURE3D_DESC& desc, _In_ const XG_RESOURCE_LAYOUT& layout, _In_ uint32_t miscFlags2 = 0);
|
||||
HRESULT __cdecl Initialize(_In_ const DirectX::TexMetadata& mdata, _In_ XboxTileMode tm, _In_ uint32_t size, _In_ uint32_t alignment);
|
||||
|
||||
void Release();
|
||||
void __cdecl Release();
|
||||
|
||||
const DirectX::TexMetadata& GetMetadata() const { return metadata; }
|
||||
XboxTileMode GetTileMode() const { return tilemode; }
|
||||
@@ -94,65 +94,65 @@ namespace Xbox
|
||||
//---------------------------------------------------------------------------------
|
||||
// Image I/O
|
||||
|
||||
HRESULT GetMetadataFromDDSMemory(
|
||||
HRESULT __cdecl GetMetadataFromDDSMemory(
|
||||
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
|
||||
_Out_ DirectX::TexMetadata& metadata, _Out_ bool& isXbox);
|
||||
HRESULT GetMetadataFromDDSFile(
|
||||
HRESULT __cdecl GetMetadataFromDDSFile(
|
||||
_In_z_ const wchar_t* szFile, _Out_ DirectX::TexMetadata& metadata, _Out_ bool& isXbox);
|
||||
|
||||
HRESULT GetMetadataFromDDSMemoryEx(
|
||||
HRESULT __cdecl GetMetadataFromDDSMemoryEx(
|
||||
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
|
||||
_Out_ DirectX::TexMetadata& metadata, _Out_ bool& isXbox,
|
||||
_Out_opt_ DirectX::DDSMetaData* ddPixelFormat);
|
||||
HRESULT GetMetadataFromDDSFileEx(
|
||||
HRESULT __cdecl GetMetadataFromDDSFileEx(
|
||||
_In_z_ const wchar_t* szFile, _Out_ DirectX::TexMetadata& metadata, _Out_ bool& isXbox,
|
||||
_Out_opt_ DirectX::DDSMetaData* ddPixelFormat);
|
||||
|
||||
HRESULT LoadFromDDSMemory(
|
||||
HRESULT __cdecl LoadFromDDSMemory(
|
||||
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
|
||||
_Out_opt_ DirectX::TexMetadata* metadata, _Out_ XboxImage& image);
|
||||
HRESULT LoadFromDDSFile(
|
||||
HRESULT __cdecl LoadFromDDSFile(
|
||||
_In_z_ const wchar_t* szFile,
|
||||
_Out_opt_ DirectX::TexMetadata* metadata, _Out_ XboxImage& image);
|
||||
|
||||
HRESULT LoadFromDDSMemoryEx(
|
||||
HRESULT __cdecl LoadFromDDSMemoryEx(
|
||||
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
|
||||
_Out_opt_ DirectX::TexMetadata* metadata,
|
||||
_Out_opt_ DirectX::DDSMetaData* ddPixelFormat,
|
||||
_Out_ XboxImage& image);
|
||||
HRESULT LoadFromDDSFileEx(
|
||||
HRESULT __cdecl LoadFromDDSFileEx(
|
||||
_In_z_ const wchar_t* szFile,
|
||||
_Out_opt_ DirectX::TexMetadata* metadata,
|
||||
_Out_opt_ DirectX::DDSMetaData* ddPixelFormat,
|
||||
_Out_ XboxImage& image);
|
||||
|
||||
HRESULT SaveToDDSMemory(_In_ const XboxImage& xbox, _Out_ DirectX::Blob& blob);
|
||||
HRESULT SaveToDDSFile(_In_ const XboxImage& xbox, _In_z_ const wchar_t* szFile);
|
||||
HRESULT __cdecl SaveToDDSMemory(_In_ const XboxImage& xbox, _Out_ DirectX::Blob& blob);
|
||||
HRESULT __cdecl SaveToDDSFile(_In_ const XboxImage& xbox, _In_z_ const wchar_t* szFile);
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
// Xbox Texture Tiling / Detiling (requires XG DLL to be present at runtime)
|
||||
|
||||
HRESULT Tile(_In_ const DirectX::Image& srcImage, _Out_ XboxImage& xbox, _In_ XboxTileMode mode = c_XboxTileModeInvalid);
|
||||
HRESULT Tile(
|
||||
HRESULT __cdecl Tile(_In_ const DirectX::Image& srcImage, _Out_ XboxImage& xbox, _In_ XboxTileMode mode = c_XboxTileModeInvalid);
|
||||
HRESULT __cdecl Tile(
|
||||
_In_ const DirectX::Image* srcImages, _In_ size_t nimages, _In_ const DirectX::TexMetadata& metadata,
|
||||
_Out_ XboxImage& xbox, _In_ XboxTileMode mode = c_XboxTileModeInvalid);
|
||||
|
||||
HRESULT Detile(_In_ const XboxImage& xbox, _Out_ DirectX::ScratchImage& image);
|
||||
HRESULT __cdecl Detile(_In_ const XboxImage& xbox, _Out_ DirectX::ScratchImage& image);
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
// Direct3D 11.X functions
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE) && defined(__d3d11_x_h__)
|
||||
|
||||
HRESULT CreateTexture(
|
||||
HRESULT __cdecl CreateTexture(
|
||||
_In_ ID3D11DeviceX* d3dDevice,
|
||||
_In_ const XboxImage& xbox, _Outptr_opt_ ID3D11Resource** ppResource, _Outptr_ void** grfxMemory);
|
||||
|
||||
HRESULT CreateShaderResourceView(
|
||||
HRESULT __cdecl CreateShaderResourceView(
|
||||
_In_ ID3D11DeviceX* d3dDevice,
|
||||
_In_ const XboxImage& xbox, _Outptr_opt_ ID3D11ShaderResourceView** ppSRV, _Outptr_ void** grfxMemory);
|
||||
|
||||
void FreeTextureMemory(_In_ ID3D11DeviceX* d3dDevice, _In_opt_ void* grfxMemory);
|
||||
void __cdecl FreeTextureMemory(_In_ ID3D11DeviceX* d3dDevice, _In_opt_ void* grfxMemory);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -161,12 +161,18 @@ namespace Xbox
|
||||
|
||||
#if ((defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)) && (defined(__d3d12_x_h__) || defined(__XBOX_D3D12_X__))
|
||||
|
||||
HRESULT CreateTexture(
|
||||
HRESULT __cdecl CreateTexture(
|
||||
_In_ ID3D12Device* d3dDevice,
|
||||
_In_ const XboxImage& xbox, _Outptr_opt_ ID3D12Resource** ppResource, _Outptr_ void** grfxMemory);
|
||||
|
||||
void FreeTextureMemory(_In_ ID3D12Device* d3dDevice, _In_opt_ void* grfxMemory);
|
||||
void __cdecl FreeTextureMemory(_In_ ID3D12Device* d3dDevice, _In_opt_ void* grfxMemory);
|
||||
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
// DDS helper functions
|
||||
HRESULT __cdecl EncodeDDSHeader(
|
||||
const XboxImage& xbox,
|
||||
_Out_writes_bytes_(maxsize) void* pDestination, _In_ size_t maxsize) noexcept;
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
// DirectXTexD3D11X.cpp
|
||||
//
|
||||
//
|
||||
// DirectXTex Auxilary functions for creating resouces from XboxImage containers
|
||||
// via the CreatePlacement APIs
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
// DirectXTexD3D12X.cpp
|
||||
//
|
||||
//
|
||||
// DirectXTex Auxilary functions for creating resouces from XboxImage containers
|
||||
// via the CreatePlacedResourceX API
|
||||
//
|
||||
|
||||
@@ -23,34 +23,6 @@ using namespace Xbox;
|
||||
|
||||
namespace
|
||||
{
|
||||
const DDS_PIXELFORMAT DDSPF_XBOX =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('X','B','O','X'), 0, 0, 0, 0, 0 };
|
||||
|
||||
#pragma pack(push,1)
|
||||
|
||||
struct DDS_HEADER_XBOX
|
||||
// Must match structure in XboxDDSTextureLoader module
|
||||
{
|
||||
DXGI_FORMAT dxgiFormat;
|
||||
uint32_t resourceDimension;
|
||||
uint32_t miscFlag; // see DDS_RESOURCE_MISC_FLAG
|
||||
uint32_t arraySize;
|
||||
uint32_t miscFlags2; // see DDS_MISC_FLAGS2
|
||||
uint32_t tileMode; // see XG_TILE_MODE / XG_SWIZZLE_MODE
|
||||
uint32_t baseAlignment;
|
||||
uint32_t dataSize;
|
||||
uint32_t xdkVer; // matching _XDK_VER / _GXDK_VER
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
constexpr uint32_t XBOX_TILEMODE_SCARLETT = 0x1000000;
|
||||
|
||||
static_assert(sizeof(DDS_HEADER_XBOX) == 36, "DDS XBOX Header size mismatch");
|
||||
static_assert(sizeof(DDS_HEADER_XBOX) >= sizeof(DDS_HEADER_DXT10), "DDS XBOX Header should be larger than DX10 header");
|
||||
|
||||
constexpr size_t XBOX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_XBOX);
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
// Decodes DDS header using XBOX extended header (variant of DX10 header)
|
||||
//-------------------------------------------------------------------------------------
|
||||
@@ -86,7 +58,7 @@ namespace
|
||||
*ddPixelFormat = {};
|
||||
}
|
||||
|
||||
if (size < (sizeof(DDS_HEADER) + sizeof(uint32_t)))
|
||||
if (size < DDS_MIN_HEADER_SIZE)
|
||||
{
|
||||
return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
|
||||
}
|
||||
@@ -120,13 +92,13 @@ namespace
|
||||
}
|
||||
|
||||
// Buffer must be big enough for both headers and magic value
|
||||
if (size < XBOX_HEADER_SIZE)
|
||||
if (size < DDS_XBOX_HEADER_SIZE)
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
auto xboxext = reinterpret_cast<const DDS_HEADER_XBOX*>(
|
||||
reinterpret_cast<const uint8_t*>(pSource) + sizeof(uint32_t) + sizeof(DDS_HEADER));
|
||||
reinterpret_cast<const uint8_t*>(pSource) + DDS_MIN_HEADER_SIZE);
|
||||
|
||||
metadata.arraySize = xboxext->arraySize;
|
||||
if (metadata.arraySize == 0)
|
||||
@@ -244,159 +216,6 @@ namespace
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
// Encodes DDS file header (magic value, header, XBOX extended header)
|
||||
//-------------------------------------------------------------------------------------
|
||||
HRESULT EncodeDDSHeader(
|
||||
const XboxImage& xbox,
|
||||
_Out_writes_(maxsize) void* pDestination,
|
||||
size_t maxsize)
|
||||
{
|
||||
if (!pDestination)
|
||||
return E_POINTER;
|
||||
|
||||
if (maxsize < XBOX_HEADER_SIZE)
|
||||
return E_NOT_SUFFICIENT_BUFFER;
|
||||
|
||||
*reinterpret_cast<uint32_t*>(pDestination) = DDS_MAGIC;
|
||||
|
||||
auto header = reinterpret_cast<DDS_HEADER*>(reinterpret_cast<uint8_t*>(pDestination) + sizeof(uint32_t));
|
||||
|
||||
memset(header, 0, sizeof(DDS_HEADER));
|
||||
header->size = sizeof(DDS_HEADER);
|
||||
header->flags = DDS_HEADER_FLAGS_TEXTURE;
|
||||
header->caps = DDS_SURFACE_FLAGS_TEXTURE;
|
||||
|
||||
auto& metadata = xbox.GetMetadata();
|
||||
|
||||
if (metadata.mipLevels > 0)
|
||||
{
|
||||
header->flags |= DDS_HEADER_FLAGS_MIPMAP;
|
||||
|
||||
if (metadata.mipLevels > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
header->mipMapCount = static_cast<uint32_t>(metadata.mipLevels);
|
||||
|
||||
if (header->mipMapCount > 1)
|
||||
header->caps |= DDS_SURFACE_FLAGS_MIPMAP;
|
||||
}
|
||||
|
||||
switch (metadata.dimension)
|
||||
{
|
||||
case TEX_DIMENSION_TEXTURE1D:
|
||||
if (metadata.width > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
header->width = static_cast<uint32_t>(metadata.width);
|
||||
header->height = header->depth = 1;
|
||||
break;
|
||||
|
||||
case TEX_DIMENSION_TEXTURE2D:
|
||||
if (metadata.height > UINT32_MAX
|
||||
|| metadata.width > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
header->height = static_cast<uint32_t>(metadata.height);
|
||||
header->width = static_cast<uint32_t>(metadata.width);
|
||||
header->depth = 1;
|
||||
|
||||
if (metadata.IsCubemap())
|
||||
{
|
||||
header->caps |= DDS_SURFACE_FLAGS_CUBEMAP;
|
||||
header->caps2 |= DDS_CUBEMAP_ALLFACES;
|
||||
}
|
||||
break;
|
||||
|
||||
case TEX_DIMENSION_TEXTURE3D:
|
||||
if (metadata.height > UINT32_MAX
|
||||
|| metadata.width > UINT32_MAX
|
||||
|| metadata.depth > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
header->flags |= DDS_HEADER_FLAGS_VOLUME;
|
||||
header->caps2 |= DDS_FLAGS_VOLUME;
|
||||
header->height = static_cast<uint32_t>(metadata.height);
|
||||
header->width = static_cast<uint32_t>(metadata.width);
|
||||
header->depth = static_cast<uint32_t>(metadata.depth);
|
||||
break;
|
||||
|
||||
default:
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
size_t rowPitch, slicePitch;
|
||||
ComputePitch(metadata.format, metadata.width, metadata.height, rowPitch, slicePitch, CP_FLAGS_NONE);
|
||||
|
||||
if (slicePitch > UINT32_MAX
|
||||
|| rowPitch > UINT32_MAX)
|
||||
return E_FAIL;
|
||||
|
||||
if (IsCompressed(metadata.format))
|
||||
{
|
||||
header->flags |= DDS_HEADER_FLAGS_LINEARSIZE;
|
||||
header->pitchOrLinearSize = static_cast<uint32_t>(slicePitch);
|
||||
}
|
||||
else
|
||||
{
|
||||
header->flags |= DDS_HEADER_FLAGS_PITCH;
|
||||
header->pitchOrLinearSize = static_cast<uint32_t>(rowPitch);
|
||||
}
|
||||
|
||||
memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_XBOX, sizeof(DDS_PIXELFORMAT));
|
||||
|
||||
// Setup XBOX extended header
|
||||
auto xboxext = reinterpret_cast<DDS_HEADER_XBOX*>(reinterpret_cast<uint8_t*>(header) + sizeof(DDS_HEADER));
|
||||
|
||||
memset(xboxext, 0, sizeof(DDS_HEADER_XBOX));
|
||||
xboxext->dxgiFormat = metadata.format;
|
||||
xboxext->resourceDimension = metadata.dimension;
|
||||
|
||||
if (metadata.arraySize > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
static_assert(static_cast<int>(TEX_MISC_TEXTURECUBE) == static_cast<int>(DDS_RESOURCE_MISC_TEXTURECUBE), "DDS header mismatch");
|
||||
xboxext->miscFlag = metadata.miscFlags & ~static_cast<uint32_t>(TEX_MISC_TEXTURECUBE);
|
||||
|
||||
if (metadata.miscFlags & TEX_MISC_TEXTURECUBE)
|
||||
{
|
||||
xboxext->miscFlag |= TEX_MISC_TEXTURECUBE;
|
||||
assert((metadata.arraySize % 6) == 0);
|
||||
xboxext->arraySize = static_cast<UINT>(metadata.arraySize / 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
xboxext->arraySize = static_cast<UINT>(metadata.arraySize);
|
||||
}
|
||||
|
||||
static_assert(static_cast<int>(TEX_MISC2_ALPHA_MODE_MASK) == static_cast<int>(DDS_MISC_FLAGS2_ALPHA_MODE_MASK), "DDS header mismatch");
|
||||
|
||||
static_assert(static_cast<int>(TEX_ALPHA_MODE_UNKNOWN) == static_cast<int>(DDS_ALPHA_MODE_UNKNOWN), "DDS header mismatch");
|
||||
static_assert(static_cast<int>(TEX_ALPHA_MODE_STRAIGHT) == static_cast<int>(DDS_ALPHA_MODE_STRAIGHT), "DDS header mismatch");
|
||||
static_assert(static_cast<int>(TEX_ALPHA_MODE_PREMULTIPLIED) == static_cast<int>(DDS_ALPHA_MODE_PREMULTIPLIED), "DDS header mismatch");
|
||||
static_assert(static_cast<int>(TEX_ALPHA_MODE_OPAQUE) == static_cast<int>(DDS_ALPHA_MODE_OPAQUE), "DDS header mismatch");
|
||||
static_assert(static_cast<int>(TEX_ALPHA_MODE_CUSTOM) == static_cast<int>(DDS_ALPHA_MODE_CUSTOM), "DDS header mismatch");
|
||||
|
||||
xboxext->miscFlags2 = metadata.miscFlags2;
|
||||
|
||||
#if defined(_GAMING_XBOX_SCARLETT) || defined(_USE_SCARLETT)
|
||||
xboxext->tileMode = static_cast<uint32_t>(xbox.GetTileMode()) | XBOX_TILEMODE_SCARLETT;
|
||||
#else
|
||||
xboxext->tileMode = static_cast<uint32_t>(xbox.GetTileMode());
|
||||
#endif
|
||||
|
||||
xboxext->baseAlignment = xbox.GetAlignment();
|
||||
xboxext->dataSize = xbox.GetSize();
|
||||
#ifdef _GXDK_VER
|
||||
xboxext->xdkVer = _GXDK_VER;
|
||||
#elif defined(_XDK_VER)
|
||||
xboxext->xdkVer = _XDK_VER;
|
||||
#endif
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -404,6 +223,160 @@ namespace
|
||||
// Entry-points
|
||||
//=====================================================================================
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
// Encodes DDS file header (magic value, header, XBOX extended header)
|
||||
//-------------------------------------------------------------------------------------
|
||||
_Use_decl_annotations_
|
||||
HRESULT Xbox::EncodeDDSHeader(
|
||||
const XboxImage& xbox,
|
||||
void* pDestination,
|
||||
size_t maxsize) noexcept
|
||||
{
|
||||
if (!pDestination)
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (maxsize < DDS_XBOX_HEADER_SIZE)
|
||||
return E_NOT_SUFFICIENT_BUFFER;
|
||||
|
||||
*reinterpret_cast<uint32_t*>(pDestination) = DDS_MAGIC;
|
||||
|
||||
auto header = reinterpret_cast<DDS_HEADER*>(reinterpret_cast<uint8_t*>(pDestination) + sizeof(uint32_t));
|
||||
|
||||
memset(header, 0, sizeof(DDS_HEADER));
|
||||
header->size = sizeof(DDS_HEADER);
|
||||
header->flags = DDS_HEADER_FLAGS_TEXTURE;
|
||||
header->caps = DDS_SURFACE_FLAGS_TEXTURE;
|
||||
|
||||
auto& metadata = xbox.GetMetadata();
|
||||
|
||||
if (metadata.mipLevels > 0)
|
||||
{
|
||||
header->flags |= DDS_HEADER_FLAGS_MIPMAP;
|
||||
|
||||
if (metadata.mipLevels > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
header->mipMapCount = static_cast<uint32_t>(metadata.mipLevels);
|
||||
|
||||
if (header->mipMapCount > 1)
|
||||
header->caps |= DDS_SURFACE_FLAGS_MIPMAP;
|
||||
}
|
||||
|
||||
switch (metadata.dimension)
|
||||
{
|
||||
case TEX_DIMENSION_TEXTURE1D:
|
||||
if (metadata.width > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
header->width = static_cast<uint32_t>(metadata.width);
|
||||
header->height = header->depth = 1;
|
||||
break;
|
||||
|
||||
case TEX_DIMENSION_TEXTURE2D:
|
||||
if (metadata.height > UINT32_MAX
|
||||
|| metadata.width > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
header->height = static_cast<uint32_t>(metadata.height);
|
||||
header->width = static_cast<uint32_t>(metadata.width);
|
||||
header->depth = 1;
|
||||
|
||||
if (metadata.IsCubemap())
|
||||
{
|
||||
header->caps |= DDS_SURFACE_FLAGS_CUBEMAP;
|
||||
header->caps2 |= DDS_CUBEMAP_ALLFACES;
|
||||
}
|
||||
break;
|
||||
|
||||
case TEX_DIMENSION_TEXTURE3D:
|
||||
if (metadata.height > UINT32_MAX
|
||||
|| metadata.width > UINT32_MAX
|
||||
|| metadata.depth > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
header->flags |= DDS_HEADER_FLAGS_VOLUME;
|
||||
header->caps2 |= DDS_FLAGS_VOLUME;
|
||||
header->height = static_cast<uint32_t>(metadata.height);
|
||||
header->width = static_cast<uint32_t>(metadata.width);
|
||||
header->depth = static_cast<uint32_t>(metadata.depth);
|
||||
break;
|
||||
|
||||
default:
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
size_t rowPitch, slicePitch;
|
||||
ComputePitch(metadata.format, metadata.width, metadata.height, rowPitch, slicePitch, CP_FLAGS_NONE);
|
||||
|
||||
if (slicePitch > UINT32_MAX
|
||||
|| rowPitch > UINT32_MAX)
|
||||
return E_FAIL;
|
||||
|
||||
if (IsCompressed(metadata.format))
|
||||
{
|
||||
header->flags |= DDS_HEADER_FLAGS_LINEARSIZE;
|
||||
header->pitchOrLinearSize = static_cast<uint32_t>(slicePitch);
|
||||
}
|
||||
else
|
||||
{
|
||||
header->flags |= DDS_HEADER_FLAGS_PITCH;
|
||||
header->pitchOrLinearSize = static_cast<uint32_t>(rowPitch);
|
||||
}
|
||||
|
||||
memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_XBOX, sizeof(DDS_PIXELFORMAT));
|
||||
|
||||
// Setup XBOX extended header
|
||||
auto xboxext = reinterpret_cast<DDS_HEADER_XBOX*>(reinterpret_cast<uint8_t*>(header) + sizeof(DDS_HEADER));
|
||||
|
||||
memset(xboxext, 0, sizeof(DDS_HEADER_XBOX));
|
||||
xboxext->dxgiFormat = metadata.format;
|
||||
xboxext->resourceDimension = metadata.dimension;
|
||||
|
||||
if (metadata.arraySize > UINT32_MAX)
|
||||
return E_INVALIDARG;
|
||||
|
||||
static_assert(static_cast<int>(TEX_MISC_TEXTURECUBE) == static_cast<int>(DDS_RESOURCE_MISC_TEXTURECUBE), "DDS header mismatch");
|
||||
xboxext->miscFlag = metadata.miscFlags & ~static_cast<uint32_t>(TEX_MISC_TEXTURECUBE);
|
||||
|
||||
if (metadata.miscFlags & TEX_MISC_TEXTURECUBE)
|
||||
{
|
||||
xboxext->miscFlag |= TEX_MISC_TEXTURECUBE;
|
||||
assert((metadata.arraySize % 6) == 0);
|
||||
xboxext->arraySize = static_cast<UINT>(metadata.arraySize / 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
xboxext->arraySize = static_cast<UINT>(metadata.arraySize);
|
||||
}
|
||||
|
||||
static_assert(static_cast<int>(TEX_MISC2_ALPHA_MODE_MASK) == static_cast<int>(DDS_MISC_FLAGS2_ALPHA_MODE_MASK), "DDS header mismatch");
|
||||
|
||||
static_assert(static_cast<int>(TEX_ALPHA_MODE_UNKNOWN) == static_cast<int>(DDS_ALPHA_MODE_UNKNOWN), "DDS header mismatch");
|
||||
static_assert(static_cast<int>(TEX_ALPHA_MODE_STRAIGHT) == static_cast<int>(DDS_ALPHA_MODE_STRAIGHT), "DDS header mismatch");
|
||||
static_assert(static_cast<int>(TEX_ALPHA_MODE_PREMULTIPLIED) == static_cast<int>(DDS_ALPHA_MODE_PREMULTIPLIED), "DDS header mismatch");
|
||||
static_assert(static_cast<int>(TEX_ALPHA_MODE_OPAQUE) == static_cast<int>(DDS_ALPHA_MODE_OPAQUE), "DDS header mismatch");
|
||||
static_assert(static_cast<int>(TEX_ALPHA_MODE_CUSTOM) == static_cast<int>(DDS_ALPHA_MODE_CUSTOM), "DDS header mismatch");
|
||||
|
||||
xboxext->miscFlags2 = metadata.miscFlags2;
|
||||
|
||||
#if defined(_GAMING_XBOX_SCARLETT) || defined(_USE_SCARLETT)
|
||||
xboxext->tileMode = static_cast<uint32_t>(xbox.GetTileMode()) | XBOX_TILEMODE_SCARLETT;
|
||||
#else
|
||||
xboxext->tileMode = static_cast<uint32_t>(xbox.GetTileMode());
|
||||
#endif
|
||||
|
||||
xboxext->baseAlignment = xbox.GetAlignment();
|
||||
xboxext->dataSize = xbox.GetSize();
|
||||
#ifdef _GXDK_VER
|
||||
xboxext->xdkVer = _GXDK_VER;
|
||||
#elif defined(_XDK_VER)
|
||||
xboxext->xdkVer = _XDK_VER;
|
||||
#endif
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
// Obtain metadata from DDS file in memory/on disk
|
||||
//-------------------------------------------------------------------------------------
|
||||
@@ -491,16 +464,16 @@ HRESULT Xbox::GetMetadataFromDDSFileEx(
|
||||
}
|
||||
|
||||
// Need at least enough data to fill the standard header and magic number to be a valid DDS
|
||||
if (fileInfo.EndOfFile.LowPart < (sizeof(DDS_HEADER) + sizeof(uint32_t)))
|
||||
if (fileInfo.EndOfFile.LowPart < DDS_MIN_HEADER_SIZE)
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
// Read the header in (including extended header if present)
|
||||
uint8_t header[XBOX_HEADER_SIZE] = {};
|
||||
uint8_t header[DDS_XBOX_HEADER_SIZE] = {};
|
||||
|
||||
DWORD bytesRead = 0;
|
||||
if (!ReadFile(hFile.get(), header, XBOX_HEADER_SIZE, &bytesRead, nullptr))
|
||||
if (!ReadFile(hFile.get(), header, DDS_XBOX_HEADER_SIZE, &bytesRead, nullptr))
|
||||
{
|
||||
return HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
@@ -566,13 +539,13 @@ HRESULT Xbox::LoadFromDDSMemoryEx(
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (size <= XBOX_HEADER_SIZE)
|
||||
if (size <= DDS_XBOX_HEADER_SIZE)
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
// Copy tiled data
|
||||
const size_t remaining = size - XBOX_HEADER_SIZE;
|
||||
const size_t remaining = size - DDS_XBOX_HEADER_SIZE;
|
||||
|
||||
if (remaining < dataSize)
|
||||
{
|
||||
@@ -585,7 +558,7 @@ HRESULT Xbox::LoadFromDDSMemoryEx(
|
||||
|
||||
assert(xbox.GetPointer() != nullptr);
|
||||
|
||||
memcpy(xbox.GetPointer(), reinterpret_cast<const uint8_t*>(pSource) + XBOX_HEADER_SIZE, dataSize);
|
||||
memcpy(xbox.GetPointer(), reinterpret_cast<const uint8_t*>(pSource) + DDS_XBOX_HEADER_SIZE, dataSize);
|
||||
|
||||
if (metadata)
|
||||
memcpy(metadata, &mdata, sizeof(TexMetadata));
|
||||
@@ -644,16 +617,16 @@ HRESULT Xbox::LoadFromDDSFileEx(
|
||||
}
|
||||
|
||||
// Need at least enough data to fill the standard header and magic number to be a valid DDS
|
||||
if (fileInfo.EndOfFile.LowPart < (sizeof(DDS_HEADER) + sizeof(uint32_t)))
|
||||
if (fileInfo.EndOfFile.LowPart < DDS_MIN_HEADER_SIZE)
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
// Read the header in (including extended header if present)
|
||||
uint8_t header[XBOX_HEADER_SIZE] = {};
|
||||
uint8_t header[DDS_XBOX_HEADER_SIZE] = {};
|
||||
|
||||
DWORD bytesRead = 0;
|
||||
if (!ReadFile(hFile.get(), header, XBOX_HEADER_SIZE, &bytesRead, nullptr))
|
||||
if (!ReadFile(hFile.get(), header, DDS_XBOX_HEADER_SIZE, &bytesRead, nullptr))
|
||||
{
|
||||
return HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
@@ -677,7 +650,7 @@ HRESULT Xbox::LoadFromDDSFileEx(
|
||||
}
|
||||
|
||||
// Read tiled data
|
||||
const DWORD remaining = fileInfo.EndOfFile.LowPart - XBOX_HEADER_SIZE;
|
||||
const DWORD remaining = fileInfo.EndOfFile.LowPart - DDS_XBOX_HEADER_SIZE;
|
||||
if (remaining == 0)
|
||||
return E_FAIL;
|
||||
|
||||
@@ -716,7 +689,7 @@ HRESULT Xbox::SaveToDDSMemory(const XboxImage& xbox, Blob& blob)
|
||||
|
||||
blob.Release();
|
||||
|
||||
HRESULT hr = blob.Initialize(XBOX_HEADER_SIZE + xbox.GetSize());
|
||||
HRESULT hr = blob.Initialize(DDS_XBOX_HEADER_SIZE + xbox.GetSize());
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
@@ -724,7 +697,7 @@ HRESULT Xbox::SaveToDDSMemory(const XboxImage& xbox, Blob& blob)
|
||||
auto pDestination = reinterpret_cast<uint8_t*>(blob.GetBufferPointer());
|
||||
assert(pDestination);
|
||||
|
||||
hr = EncodeDDSHeader(xbox, pDestination, XBOX_HEADER_SIZE);
|
||||
hr = EncodeDDSHeader(xbox, pDestination, DDS_XBOX_HEADER_SIZE);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
blob.Release();
|
||||
@@ -732,8 +705,8 @@ HRESULT Xbox::SaveToDDSMemory(const XboxImage& xbox, Blob& blob)
|
||||
}
|
||||
|
||||
// Copy tiled data
|
||||
const size_t remaining = blob.GetBufferSize() - XBOX_HEADER_SIZE;
|
||||
pDestination += XBOX_HEADER_SIZE;
|
||||
const size_t remaining = blob.GetBufferSize() - DDS_XBOX_HEADER_SIZE;
|
||||
pDestination += DDS_XBOX_HEADER_SIZE;
|
||||
|
||||
if (!remaining)
|
||||
{
|
||||
@@ -763,8 +736,8 @@ HRESULT Xbox::SaveToDDSFile(const XboxImage& xbox, const wchar_t* szFile)
|
||||
return E_INVALIDARG;
|
||||
|
||||
// Create DDS Header
|
||||
uint8_t header[XBOX_HEADER_SIZE] = {};
|
||||
HRESULT hr = EncodeDDSHeader(xbox, header, XBOX_HEADER_SIZE);
|
||||
uint8_t header[DDS_XBOX_HEADER_SIZE] = {};
|
||||
HRESULT hr = EncodeDDSHeader(xbox, header, DDS_XBOX_HEADER_SIZE);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
@@ -782,12 +755,12 @@ HRESULT Xbox::SaveToDDSFile(const XboxImage& xbox, const wchar_t* szFile)
|
||||
}
|
||||
|
||||
DWORD bytesWritten;
|
||||
if (!WriteFile(hFile.get(), header, static_cast<DWORD>(XBOX_HEADER_SIZE), &bytesWritten, nullptr))
|
||||
if (!WriteFile(hFile.get(), header, static_cast<DWORD>(DDS_XBOX_HEADER_SIZE), &bytesWritten, nullptr))
|
||||
{
|
||||
return HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
|
||||
if (bytesWritten != XBOX_HEADER_SIZE)
|
||||
if (bytesWritten != DDS_XBOX_HEADER_SIZE)
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user