diff --git a/DirectXTex/DirectXTex.h b/DirectXTex/DirectXTex.h index aa1b086..ad49516 100644 --- a/DirectXTex/DirectXTex.h +++ b/DirectXTex/DirectXTex.h @@ -172,6 +172,8 @@ namespace DirectX DDS_FLAGS_FORCE_DX9_LEGACY = 0x40000, // Force use of legacy header for DDS writer (will fail if unable to write as such) + DDS_FLAGS_ALLOW_LARGE_FILES = 0x1000000, + // Enables the loader to read large dimension .dds files (i.e. greater than known hardware requirements) }; enum WIC_FLAGS : unsigned long diff --git a/DirectXTex/DirectXTexDDS.cpp b/DirectXTex/DirectXTexDDS.cpp index 66dfcb5..9a5d323 100644 --- a/DirectXTex/DirectXTexDDS.cpp +++ b/DirectXTex/DirectXTexDDS.cpp @@ -525,6 +525,25 @@ namespace metadata.SetAlphaMode(TEX_ALPHA_MODE_PREMULTIPLIED); } + // Check for .dds files that exceed known hardware support + if (!(flags & DDS_FLAGS_ALLOW_LARGE_FILES)) + { + // 16k is the maximum required resource size supported by Direct3D + if (metadata.width > 16384u /* D3D12_REQ_TEXTURE1D_U_DIMENSION, D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION */ + || metadata.height > 16384u /* D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION */ + || metadata.mipLevels > 15u /* D3D12_REQ_MIP_LEVELS */) + { + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + + // 2048 is the maximum required depth/array size supported by Direct3D + if (metadata.arraySize > 2048u /* D3D12_REQ_TEXTURE1D_ARRAY_AXIS_DIMENSION, D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION */ + || metadata.depth > 2048u /* D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION */) + { + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + } + return S_OK; } } diff --git a/Texassemble/texassemble.cpp b/Texassemble/texassemble.cpp index c088891..75ce6ee 100644 --- a/Texassemble/texassemble.cpp +++ b/Texassemble/texassemble.cpp @@ -1068,7 +1068,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) case CMD_V_STRIP: if (_wcsicmp(ext, L".dds") == 0) { - hr = LoadFromDDSFile(pConv->szSrc, DDS_FLAGS_NONE, &info, *image); + hr = LoadFromDDSFile(pConv->szSrc, DDS_FLAGS_ALLOW_LARGE_FILES, &info, *image); if (FAILED(hr)) { wprintf(L" FAILED (%x)\n", static_cast(hr)); @@ -1095,7 +1095,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) case CMD_ARRAY_STRIP: if (_wcsicmp(ext, L".dds") == 0) { - hr = LoadFromDDSFile(pConv->szSrc, DDS_FLAGS_NONE, &info, *image); + hr = LoadFromDDSFile(pConv->szSrc, DDS_FLAGS_ALLOW_LARGE_FILES, &info, *image); if (FAILED(hr)) { wprintf(L" FAILED (%x)\n", static_cast(hr)); @@ -1118,7 +1118,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) default: if (_wcsicmp(ext, L".dds") == 0) { - hr = LoadFromDDSFile(pConv->szSrc, DDS_FLAGS_NONE, &info, *image); + hr = LoadFromDDSFile(pConv->szSrc, DDS_FLAGS_ALLOW_LARGE_FILES, &info, *image); if (FAILED(hr)) { wprintf(L" FAILED (%x)\n", static_cast(hr)); diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 3fc8263..3a41b2a 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -1672,7 +1672,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) if (_wcsicmp(ext, L".dds") == 0) { - DDS_FLAGS ddsFlags = DDS_FLAGS_NONE; + DDS_FLAGS ddsFlags = DDS_FLAGS_ALLOW_LARGE_FILES; if (dwOptions & (DWORD64(1) << OPT_DDS_DWORD_ALIGN)) ddsFlags |= DDS_FLAGS_LEGACY_DWORD; if (dwOptions & (DWORD64(1) << OPT_EXPAND_LUMINANCE)) diff --git a/Texdiag/texdiag.cpp b/Texdiag/texdiag.cpp index dc11a05..ec9273f 100644 --- a/Texdiag/texdiag.cpp +++ b/Texdiag/texdiag.cpp @@ -592,7 +592,7 @@ namespace if (_wcsicmp(ext, L".dds") == 0) { - DDS_FLAGS ddsFlags = DDS_FLAGS_NONE; + DDS_FLAGS ddsFlags = DDS_FLAGS_ALLOW_LARGE_FILES; if (dwOptions & (1 << OPT_DDS_DWORD_ALIGN)) ddsFlags |= DDS_FLAGS_LEGACY_DWORD; if (dwOptions & (1 << OPT_EXPAND_LUMINANCE))