Skip to content

Commit

Permalink
Xbox auxiliary EncodeDDSHeader helper exposed as public function (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn authored Aug 19, 2024
1 parent 059ce81 commit 1c47191
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 239 deletions.
2 changes: 1 addition & 1 deletion Auxiliary/DirectXTexEXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
52 changes: 29 additions & 23 deletions Auxiliary/DirectXTexXbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion Auxiliary/DirectXTexXboxD3D11X.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXTexD3D11X.cpp
//
//
// DirectXTex Auxilary functions for creating resouces from XboxImage containers
// via the CreatePlacement APIs
//
Expand Down
2 changes: 1 addition & 1 deletion Auxiliary/DirectXTexXboxD3D12X.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------
// DirectXTexD3D12X.cpp
//
//
// DirectXTex Auxilary functions for creating resouces from XboxImage containers
// via the CreatePlacedResourceX API
//
Expand Down
Loading

0 comments on commit 1c47191

Please sign in to comment.