Update for latest version of DDS.h (#242)

This commit is contained in:
Chuck Walbourn 2024-08-19 16:30:06 -07:00 коммит произвёл GitHub
Родитель 615e1050f6
Коммит 17388e5ab7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
11 изменённых файлов: 137 добавлений и 63 удалений

Просмотреть файл

@ -135,6 +135,12 @@ namespace
mMutex{}
{ }
DeviceResources(const DeviceResources&) = delete;
DeviceResources& operator=(const DeviceResources&) = delete;
DeviceResources(DeviceResources&&) = default;
DeviceResources& operator=(DeviceResources&&) = default;
ID3D12RootSignature* GetRootSignature(int slot, const D3D12_ROOT_SIGNATURE_DESC& desc)
{
assert(slot >= 0 && slot < RootSignatureCount);

Просмотреть файл

@ -39,17 +39,18 @@ namespace DirectX
uint32_t ABitMask;
};
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
#define DDS_RGB 0x00000040 // DDPF_RGB
#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS
#define DDS_ALPHAPIXELS 0x00000001 // DDPF_ALPHAPIXELS
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
#define DDS_PAL8 0x00000020 // DDPF_PALETTEINDEXED8
#define DDS_PAL8A 0x00000021 // DDPF_PALETTEINDEXED8 | DDPF_ALPHAPIXELS
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
// DDS_BUMPLUMINANCE 0x00040000
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
#define DDS_RGB 0x00000040 // DDPF_RGB
#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS
#define DDS_ALPHAPIXELS 0x00000001 // DDPF_ALPHAPIXELS
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
#define DDS_PAL8 0x00000020 // DDPF_PALETTEINDEXED8
#define DDS_PAL8A 0x00000021 // DDPF_PALETTEINDEXED8 | DDPF_ALPHAPIXELS
#define DDS_BUMPLUMINANCE 0x00040000 // DDPF_BUMPLUMINANCE
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
#define DDS_BUMPDUDVA 0x00080001 // DDPF_BUMPDUDV | DDPF_ALPHAPIXELS
#ifndef MAKEFOURCC
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
@ -187,10 +188,13 @@ namespace DirectX
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A2B10G10R10 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 };
// We do not support the following legacy Direct3D 9 formats:
// DDSPF_A2W10V10U10 = { sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 };
// DDSPF_L6V5U5 = { sizeof(DDS_PIXELFORMAT), DDS_BUMPLUMINANCE, 0, 16, 0x001f, 0x03e0, 0xfc00, 0 };
// DDSPF_X8L8V8U8 = { sizeof(DDS_PIXELFORMAT), DDS_BUMPLUMINANCE, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0 };
// The following legacy Direct3D 9 formats use 'mixed' signed & unsigned channels so requires special handling
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A2W10V10U10 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDVA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 };
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_L6V5U5 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPLUMINANCE, 0, 16, 0x001f, 0x03e0, 0xfc00, 0 };
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_X8L8V8U8 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPLUMINANCE, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0 };
// This indicates the DDS_HEADER_DXT10 extension is present (the format is in dxgiFormat)
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_DX10 =
@ -288,4 +292,39 @@ namespace DirectX
static_assert(sizeof(DDS_HEADER) == 124, "DDS Header size mismatch");
static_assert(sizeof(DDS_HEADER_DXT10) == 20, "DDS DX10 Extended Header size mismatch");
constexpr size_t DDS_MIN_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER);
constexpr size_t DDS_DX10_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10);
static_assert(DDS_DX10_HEADER_SIZE > DDS_MIN_HEADER_SIZE, "DDS DX10 Header should be larger than standard header");
} // namespace
namespace Xbox
{
DDSGLOBALCONST DirectX::DDS_PIXELFORMAT DDSPF_XBOX =
{ sizeof(DirectX::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)
static_assert(sizeof(DDS_HEADER_XBOX) == 36, "DDS XBOX Header size mismatch");
static_assert(sizeof(DDS_HEADER_XBOX) > sizeof(DirectX::DDS_HEADER_DXT10), "DDS XBOX Header should be larger than DX10 header");
constexpr size_t DDS_XBOX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DirectX::DDS_HEADER) + sizeof(DDS_HEADER_XBOX);
constexpr uint32_t XBOX_TILEMODE_SCARLETT = 0x1000000;
} // namespace

Просмотреть файл

@ -89,6 +89,12 @@ namespace
{
}
DeviceResources(const DeviceResources&) = delete;
DeviceResources& operator=(const DeviceResources&) = delete;
DeviceResources(DeviceResources&&) = default;
DeviceResources& operator=(DeviceResources&&) = default;
ID3D12RootSignature* GetRootSignature(const D3D12_ROOT_SIGNATURE_DESC& desc)
{
return DemandCreate(mRootSignature, mMutex, [&](ID3D12RootSignature** pResult) noexcept -> HRESULT

Просмотреть файл

@ -75,6 +75,12 @@ public:
mSamplerDescriptors = std::make_unique<DescriptorHeap>(samplerDescriptors);
}
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
std::shared_ptr<IEffect> CreateEffect(
const EffectInfo& info,
const EffectPipelineStateDescription& opaquePipelineState,

Просмотреть файл

@ -69,6 +69,12 @@ public:
SetDebugObjectName(mTextureDescriptorHeap.Heap(), L"EffectTextureFactory");
}
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
size_t CreateTexture(_In_z_ const wchar_t* name, int descriptorSlot);
void ReleaseCache();

Просмотреть файл

@ -334,7 +334,7 @@ namespace DirectX
return E_FAIL;
}
if (ddsDataSize < (sizeof(uint32_t) + sizeof(DDS_HEADER)))
if (ddsDataSize < DDS_MIN_HEADER_SIZE)
{
return E_FAIL;
}
@ -361,7 +361,7 @@ namespace DirectX
(MAKEFOURCC('D', 'X', '1', '0') == hdr->ddspf.fourCC))
{
// Must be long enough for both headers and magic value
if (ddsDataSize < (sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10)))
if (ddsDataSize < DDS_DX10_HEADER_SIZE)
{
return E_FAIL;
}
@ -371,8 +371,7 @@ namespace DirectX
// setup the pointers in the process request
*header = hdr;
auto offset = sizeof(uint32_t)
+ sizeof(DDS_HEADER)
auto offset = DDS_MIN_HEADER_SIZE
+ (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0u);
*bitData = ddsData + offset;
*bitSize = ddsDataSize - offset;
@ -429,7 +428,7 @@ namespace DirectX
}
// Need at least enough data to fill the header and magic number to be a valid DDS
if (fileInfo.EndOfFile.LowPart < (sizeof(uint32_t) + sizeof(DDS_HEADER)))
if (fileInfo.EndOfFile.LowPart < DDS_MIN_HEADER_SIZE)
{
return E_FAIL;
}
@ -484,7 +483,7 @@ namespace DirectX
(MAKEFOURCC('D', 'X', '1', '0') == hdr->ddspf.fourCC))
{
// Must be long enough for both headers and magic value
if (fileInfo.EndOfFile.LowPart < (sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10)))
if (fileInfo.EndOfFile.LowPart < DDS_DX10_HEADER_SIZE)
{
ddsData.reset();
return E_FAIL;
@ -495,7 +494,7 @@ namespace DirectX
// setup the pointers in the process request
*header = hdr;
auto offset = sizeof(uint32_t) + sizeof(DDS_HEADER)
auto offset = DDS_MIN_HEADER_SIZE
+ (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0u);
*bitData = ddsData.get() + offset;
*bitSize = fileInfo.EndOfFile.LowPart - offset;

Просмотреть файл

@ -94,6 +94,12 @@ public:
mSamplerDescriptors = std::make_unique<DescriptorHeap>(samplerDescriptors);
}
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
std::shared_ptr<IEffect> CreateEffect(
const EffectInfo& info,
const EffectPipelineStateDescription& opaquePipelineState,

Просмотреть файл

@ -291,13 +291,12 @@ HRESULT DirectX::SaveDDSTextureToFile(
auto_delete_file delonfail(hFile.get());
// Setup header
constexpr size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10);
uint8_t fileHeader[MAX_HEADER_SIZE] = {};
uint8_t fileHeader[DDS_DX10_HEADER_SIZE] = {};
*reinterpret_cast<uint32_t*>(&fileHeader[0]) = DDS_MAGIC;
auto header = reinterpret_cast<DDS_HEADER*>(&fileHeader[0] + sizeof(uint32_t));
size_t headerSize = sizeof(uint32_t) + sizeof(DDS_HEADER);
size_t headerSize = DDS_MIN_HEADER_SIZE;
header->size = sizeof(DDS_HEADER);
header->flags = DDS_HEADER_FLAGS_TEXTURE | DDS_HEADER_FLAGS_MIPMAP;
header->height = desc.Height;
@ -355,7 +354,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
memcpy(&header->ddspf, &DDSPF_DX10, sizeof(DDS_PIXELFORMAT));
headerSize += sizeof(DDS_HEADER_DXT10);
extHeader = reinterpret_cast<DDS_HEADER_DXT10*>(fileHeader + sizeof(uint32_t) + sizeof(DDS_HEADER));
extHeader = reinterpret_cast<DDS_HEADER_DXT10*>(fileHeader + DDS_MIN_HEADER_SIZE);
extHeader->dxgiFormat = desc.Format;
extHeader->resourceDimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
extHeader->arraySize = 1;
@ -795,7 +794,9 @@ HRESULT DirectX::SaveWICTextureToFile(
else
{
// No conversion required
hr = frame->WritePixels(desc.Height, static_cast<UINT>(dstRowPitch), static_cast<UINT>(imageSize), static_cast<BYTE*>(pMappedMemory));
hr = frame->WritePixels(desc.Height,
static_cast<UINT>(dstRowPitch), static_cast<UINT>(imageSize),
static_cast<BYTE*>(pMappedMemory));
}
pStaging->Unmap(0, &writeRange);

Просмотреть файл

@ -227,6 +227,12 @@ namespace
{
}
DeviceResources(const DeviceResources&) = delete;
DeviceResources& operator=(const DeviceResources&) = delete;
DeviceResources(DeviceResources&&) = default;
DeviceResources& operator=(DeviceResources&&) = default;
ID3D12RootSignature* GetRootSignature(const D3D12_ROOT_SIGNATURE_DESC& desc)
{
return DemandCreate(mRootSignature, mMutex, [&](ID3D12RootSignature** pResult) noexcept -> HRESULT

Просмотреть файл

@ -45,33 +45,6 @@ namespace
#endif
);
//--------------------------------------------------------------------------------------
// DDS file structure definitions
//
// See DDS.h in the 'Texconv' sample and the 'DirectXTex' library
//--------------------------------------------------------------------------------------
#pragma pack(push,1)
struct DDS_HEADER_XBOX
// Must match structure defined in xtexconv tool
{
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
};
constexpr uint32_t XBOX_TILEMODE_SCARLETT = 0x1000000;
static_assert(sizeof(DDS_HEADER_XBOX) == 36, "DDS XBOX Header size mismatch");
#pragma pack(pop)
//--------------------------------------------------------------------------------------
HRESULT LoadTextureDataFromFile(_In_z_ const wchar_t* fileName,
std::unique_ptr<uint8_t[]>& ddsData,
@ -109,7 +82,7 @@ namespace
}
// Need at least enough data to fill the 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;
}
@ -163,14 +136,14 @@ namespace
}
// Must be long enough for both headers and magic value
if (fileInfo.EndOfFile.LowPart < (sizeof(DDS_HEADER) + sizeof(uint32_t) + sizeof(DDS_HEADER_XBOX)))
if (fileInfo.EndOfFile.LowPart < DDS_XBOX_HEADER_SIZE)
{
return E_FAIL;
}
// setup the pointers in the process request
*header = hdr;
auto offset = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_XBOX);
auto offset = DDS_XBOX_HEADER_SIZE;
*bitData = ddsData.get() + offset;
*bitSize = fileInfo.EndOfFile.LowPart - offset;
@ -504,7 +477,7 @@ HRESULT Xbox::CreateDDSTextureFromMemory(
}
// Validate DDS file in memory
if (ddsDataSize < (sizeof(uint32_t) + sizeof(DDS_HEADER)))
if (ddsDataSize < DDS_MIN_HEADER_SIZE)
{
return E_FAIL;
}
@ -515,7 +488,7 @@ HRESULT Xbox::CreateDDSTextureFromMemory(
return E_FAIL;
}
auto header = reinterpret_cast<const DDS_HEADER*>( ddsData + sizeof( uint32_t ) );
auto header = reinterpret_cast<const DDS_HEADER*>(ddsData + sizeof( uint32_t ));
// Verify header to validate DDS file
if (header->size != sizeof(DDS_HEADER) ||
@ -533,12 +506,12 @@ HRESULT Xbox::CreateDDSTextureFromMemory(
}
// Must be long enough for both headers and magic value
if (ddsDataSize < (sizeof(DDS_HEADER) + sizeof(uint32_t) + sizeof(DDS_HEADER_XBOX)))
if (ddsDataSize < DDS_XBOX_HEADER_SIZE)
{
return E_FAIL;
}
auto offset = sizeof( uint32_t ) + sizeof( DDS_HEADER ) + sizeof( DDS_HEADER_XBOX );
auto offset = DDS_XBOX_HEADER_SIZE;
HRESULT hr = CreateTextureFromDDS( d3dDevice, header,
ddsData + offset, ddsDataSize - offset, forceSRGB,

Просмотреть файл

@ -85,18 +85,40 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|IntelLLVM")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
list(APPEND COMPILER_SWITCHES /Zc:__cplusplus /Zc:inline /fp:fast /Qdiag-disable:161)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
list(APPEND COMPILER_SWITCHES /sdl /permissive- /JMC- /Zc:__cplusplus /Zc:inline /fp:fast)
list(APPEND COMPILER_SWITCHES /sdl /Zc:inline /fp:fast)
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION)
message(STATUS "Building using Whole Program Optimization")
list(APPEND COMPILER_SWITCHES $<$<NOT:$<CONFIG:Debug>>:/Gy /Gw>)
endif()
if(OpenMP_CXX_FOUND)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.10)
list(APPEND COMPILER_SWITCHES /permissive-)
endif()
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.11)
AND (OpenMP_CXX_FOUND
OR (XBOX_CONSOLE_TARGET STREQUAL "durango")))
# OpenMP in MSVC is not compatible with /permissive- unless you disable two-phase lookup
list(APPEND COMPILER_SWITCHES /Zc:twoPhase-)
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.14)
list(APPEND COMPILER_SWITCHES /Zc:__cplusplus)
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.15)
list(APPEND COMPILER_SWITCHES /JMC-)
endif()
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.20)
AND (XBOX_CONSOLE_TARGET STREQUAL "durango"))
list(APPEND COMPILER_SWITCHES /d2FH4-)
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION)
list(APPEND LINKER_SWITCHES -d2:-FH4-)
endif()
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.24)
list(APPEND COMPILER_SWITCHES /ZH:SHA_256)
endif()
@ -114,6 +136,10 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
list(APPEND COMPILER_SWITCHES /Zc:lambda)
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.29)
list(APPEND COMPILER_SWITCHES /external:W4)
endif()
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.31)
AND (XBOX_CONSOLE_TARGET STREQUAL "durango"))
list(APPEND COMPILER_SWITCHES /Zc:static_assert-)