Skip to content

Commit

Permalink
Updated for DirectXTex November 2021 release
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Nov 8, 2021
1 parent 0095b8a commit 9654b6e
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 93 deletions.
2 changes: 1 addition & 1 deletion Kits/DirectXTex/BC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace
uint32_t cSteps,
uint32_t flags) noexcept
{
static const float fEpsilon = (0.25f / 64.0f) * (0.25f / 64.0f);
constexpr float fEpsilon = (0.25f / 64.0f) * (0.25f / 64.0f);
static const float pC3[] = { 2.0f / 2.0f, 1.0f / 2.0f, 0.0f / 2.0f };
static const float pD3[] = { 0.0f / 2.0f, 1.0f / 2.0f, 2.0f / 2.0f };
static const float pC4[] = { 3.0f / 3.0f, 2.0f / 3.0f, 1.0f / 3.0f, 0.0f / 3.0f };
Expand Down
14 changes: 7 additions & 7 deletions Kits/DirectXTex/BCDirectCompute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ using Microsoft::WRL::ComPtr;

namespace
{
#include "Shaders\Compiled\BC7Encode_EncodeBlockCS.inc"
#include "Shaders\Compiled\BC7Encode_TryMode02CS.inc"
#include "Shaders\Compiled\BC7Encode_TryMode137CS.inc"
#include "Shaders\Compiled\BC7Encode_TryMode456CS.inc"
#include "Shaders\Compiled\BC6HEncode_EncodeBlockCS.inc"
#include "Shaders\Compiled\BC6HEncode_TryModeG10CS.inc"
#include "Shaders\Compiled\BC6HEncode_TryModeLE10CS.inc"
#include "BC7Encode_EncodeBlockCS.inc"
#include "BC7Encode_TryMode02CS.inc"
#include "BC7Encode_TryMode137CS.inc"
#include "BC7Encode_TryMode456CS.inc"
#include "BC6HEncode_EncodeBlockCS.inc"
#include "BC6HEncode_TryModeG10CS.inc"
#include "BC6HEncode_TryModeLE10CS.inc"

struct BufferBC6HBC7
{
Expand Down
2 changes: 1 addition & 1 deletion Kits/DirectXTex/DirectXTex.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct IWICImagingFactory;
struct IWICMetadataQueryReader;
#endif

#define DIRECTX_TEX_VERSION 193
#define DIRECTX_TEX_VERSION 195


namespace DirectX
Expand Down
4 changes: 2 additions & 2 deletions Kits/DirectXTex/DirectXTexConvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ namespace
DirectX::XMFLOAT3A tmp;
DirectX::XMStoreFloat3A(&tmp, V);

static const float maxf9 = float(0x1FF << 7);
static const float minf9 = float(1.f / (1 << 16));
constexpr float maxf9 = float(0x1FF << 7);
constexpr float minf9 = float(1.f / (1 << 16));

float x = (tmp.x >= 0.f) ? ((tmp.x > maxf9) ? maxf9 : tmp.x) : 0.f;
float y = (tmp.y >= 0.f) ? ((tmp.y > maxf9) ? maxf9 : tmp.y) : 0.f;
Expand Down
2 changes: 1 addition & 1 deletion Kits/DirectXTex/DirectXTexResize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ namespace
assert(srcImage.format == destImage.format);

// Allocate temporary space (2 scanlines)
auto scanline = make_AlignedArrayXMVECTOR(srcImage.width + destImage.width);
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(srcImage.width) + destImage.width);
if (!scanline)
return E_OUTOFMEMORY;

Expand Down
26 changes: 13 additions & 13 deletions Kits/DirectXTex/DirectXTexWIC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ namespace
return E_NOTIMPL;
}

HRESULT STDMETHODCALLTYPE Revert(void) override
HRESULT STDMETHODCALLTYPE Revert() override
{
return E_NOTIMPL;
}
Expand Down Expand Up @@ -635,7 +635,7 @@ namespace
}
#endif

(void)PropVariantClear(&value);
std::ignore = PropVariantClear(&value);

if (sRGB)
metadata.format = MakeSRGB(metadata.format);
Expand Down Expand Up @@ -889,65 +889,65 @@ namespace
if (memcmp(&containerFormat, &GUID_ContainerFormatPng, sizeof(GUID)) == 0)
{
// Set Software name
(void)metawriter->SetMetadataByName(L"/tEXt/{str=Software}", &value);
std::ignore = metawriter->SetMetadataByName(L"/tEXt/{str=Software}", &value);

// Set sRGB chunk
if (sRGB)
{
value.vt = VT_UI1;
value.bVal = 0;
(void)metawriter->SetMetadataByName(L"/sRGB/RenderingIntent", &value);
std::ignore = metawriter->SetMetadataByName(L"/sRGB/RenderingIntent", &value);
}
else
{
// add gAMA chunk with gamma 1.0
value.vt = VT_UI4;
value.uintVal = 100000; // gama value * 100,000 -- i.e. gamma 1.0
(void)metawriter->SetMetadataByName(L"/gAMA/ImageGamma", &value);
std::ignore = metawriter->SetMetadataByName(L"/gAMA/ImageGamma", &value);

// remove sRGB chunk which is added by default.
(void)metawriter->RemoveMetadataByName(L"/sRGB/RenderingIntent");
std::ignore = metawriter->RemoveMetadataByName(L"/sRGB/RenderingIntent");
}
}
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
else if (memcmp(&containerFormat, &GUID_ContainerFormatJpeg, sizeof(GUID)) == 0)
{
// Set Software name
(void)metawriter->SetMetadataByName(L"/app1/ifd/{ushort=305}", &value);
std::ignore = metawriter->SetMetadataByName(L"/app1/ifd/{ushort=305}", &value);

if (sRGB)
{
// Set EXIF Colorspace of sRGB
value.vt = VT_UI2;
value.uiVal = 1;
(void)metawriter->SetMetadataByName(L"/app1/ifd/exif/{ushort=40961}", &value);
std::ignore = metawriter->SetMetadataByName(L"/app1/ifd/exif/{ushort=40961}", &value);
}
}
else if (memcmp(&containerFormat, &GUID_ContainerFormatTiff, sizeof(GUID)) == 0)
{
// Set Software name
(void)metawriter->SetMetadataByName(L"/ifd/{ushort=305}", &value);
std::ignore = metawriter->SetMetadataByName(L"/ifd/{ushort=305}", &value);

if (sRGB)
{
// Set EXIF Colorspace of sRGB
value.vt = VT_UI2;
value.uiVal = 1;
(void)metawriter->SetMetadataByName(L"/ifd/exif/{ushort=40961}", &value);
std::ignore = metawriter->SetMetadataByName(L"/ifd/exif/{ushort=40961}", &value);
}
}
#else
else
{
// Set Software name
(void)metawriter->SetMetadataByName(L"System.ApplicationName", &value);
std::ignore = metawriter->SetMetadataByName(L"System.ApplicationName", &value);

if (sRGB)
{
// Set EXIF Colorspace of sRGB
value.vt = VT_UI2;
value.uiVal = 1;
(void)metawriter->SetMetadataByName(L"System.Image.ColorSpace", &value);
std::ignore = metawriter->SetMetadataByName(L"System.Image.ColorSpace", &value);
}
}
#endif
Expand Down Expand Up @@ -1109,7 +1109,7 @@ namespace
VARIANT varValue;
varValue.vt = VT_BOOL;
varValue.boolVal = VARIANT_TRUE;
(void)props->Write(1, &option, &varValue);
std::ignore = props->Write(1, &option, &varValue);
}

if (setCustomProps)
Expand Down
4 changes: 2 additions & 2 deletions Kits/DirectXTex/DirectXTexXboxDDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ namespace

#pragma pack(pop)

static const uint32_t XBOX_TILEMODE_SCARLETT = 0x1000000;
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");

static const size_t XBOX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_XBOX);
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)
Expand Down
3 changes: 3 additions & 0 deletions Kits/DirectXTex/DirectXTex_XboxOneXDK_PC_2015.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;_DEBUG;_LIB;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0601;_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)Shaders\Compiled;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<SDLCheck>true</SDLCheck>
</ClCompile>
Expand Down Expand Up @@ -111,6 +112,7 @@
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;NDEBUG;_LIB;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0601;_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)Shaders\Compiled;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<SDLCheck>true</SDLCheck>
</ClCompile>
Expand Down Expand Up @@ -141,6 +143,7 @@
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;NDEBUG;PROFILE;_LIB;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0601;_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)Shaders\Compiled;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ProgramDataBaseFileName>$(IntDir)$(TargetName).pdb</ProgramDataBaseFileName>
<SDLCheck>true</SDLCheck>
</ClCompile>
Expand Down
11 changes: 11 additions & 0 deletions Kits/DirectXTex/DirectXTexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,15 @@
#endif

#ifdef _GAMING_XBOX_SCARLETT
#pragma warning(push)
#pragma warning(disable: 5204 5249)
#include <d3d12_xs.h>
#pragma warning(pop)
#elif defined(_GAMING_XBOX)
#pragma warning(push)
#pragma warning(disable: 5204)
#include <d3d12_x.h>
#pragma warning(pop)
#elif defined(_XBOX_ONE) && defined(_TITLE)
#include <d3d12_x.h>
#include <d3d11_x.h>
Expand Down Expand Up @@ -124,6 +130,7 @@
#include <iterator>
#include <memory>
#include <new>
#include <tuple>

#ifndef WIN32
#include <fstream>
Expand All @@ -144,7 +151,11 @@
#include <malloc.h>

#ifdef WIN32
#ifdef NTDDI_WIN10_FE
#include <ole2.h>
#else
#include <Ole2.h>
#endif
#include <wincodec.h>
#include <wrl\client.h>
#else
Expand Down
20 changes: 16 additions & 4 deletions Kits/DirectXTex/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
![DirectX Logo](https://github.com/Microsoft/DirectXTex/wiki/X_jpg.jpg)
![DirectX Logo](https://raw.githubusercontent.com/wiki/Microsoft/DirectXTex/X_jpg.jpg)

# DirectXTex texture processing library (Xbox variant)

http://go.microsoft.com/fwlink/?LinkId=248926

Copyright (c) Microsoft Corporation.

**June 9, 2021**
**November 8, 2021**

This package contains DirectXTex, a shared source library for reading and writing ``.DDS`` files, and performing various texture content processing operations including resizing, format conversion, mip-map generation, block compression for Direct3D runtime texture resources, and height-map to normal-map conversion. This library makes use of the Windows Image Component (WIC) APIs. It also includes ``.TGA`` and ``.HDR`` readers and writers since these image file formats are commonly used for texture content processing pipelines, but are not currently supported by a built-in WIC codec.

This code is designed to build with Visual Studio 2017 ([15.9](https://walbourn.github.io/vs-2017-15-9-update/)), Visual Studio 2019, or clang for Windows v9 or later. It is recommended that you make use of the Windows 10 May 2020 Update SDK ([19041](https://walbourn.github.io/windows-10-may-2020-update-sdk/)) or later.
This code is designed to build with Visual Studio 2017 ([15.9](https://walbourn.github.io/vs-2017-15-9-update/)), Visual Studio 2019, Visual Studio 2022, or clang for Windows v11 or later. Use of the Windows 10 May 2020 Update SDK ([19041](https://walbourn.github.io/windows-10-may-2020-update-sdk/)) or later is required.

These components are designed to work without requiring any content from the legacy DirectX SDK. For details, see [Where is the DirectX SDK?](https://aka.ms/dxsdk).

Expand Down Expand Up @@ -87,10 +87,16 @@ For the latest version of DirectXTex, bug reports, etc. please visit the project

* Loading of 96bpp floating-point TIFF files results in a corrupted image prior to Windows 8. This fix is available on Windows 7 SP1 with KB 2670838 installed.

* The UWP projects and the VS 2019 Win10 classic desktop project include configurations for the ARM64 platform. These require VS 2017 (15.9 update) or VS 2019 to build, with the ARM64 toolset installed.
* The UWP projects and the Win10 classic desktop project include configurations for the ARM64 platform. These require VS 2017 (15.9 update) or later to build, with the ARM64 toolset installed.

* The ``CompileShaders.cmd`` script must have Windows-style (CRLF) line-endings. If it is changed to Linux-style (LF) line-endings, it can fail to build all the required shaders.

## Support

For questions, consider using [Stack Overflow](https://stackoverflow.com/questions/tagged/directxtk) with the *directxtk* tag, or the [DirectX Discord Server](https://discord.gg/directx) in the *dx12-developers* or *dx9-dx11-developers* channel.

For bug reports and feature requests, please use GitHub [issues](https://github.com/microsoft/DirectXTex/issues) for this project.

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
Expand All @@ -102,3 +108,9 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
## Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

## Credits

The DirectXTex library is the work of Chuck Walbourn, with contributions from Matt Lee, Xin Huang, Craig Peeper, and the numerous other Microsoft engineers who developed the D3DX utility library over the years.

Thanks to Paul Penson for his help with the implementation of ``MemoryStreamOnBlob``.
8 changes: 6 additions & 2 deletions Kits/DirectXTex/Shaders/CompileShaders.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ if exist %PCFXC% goto continue
set PCFXC=fxc.exe

:continue
@if not exist Compiled mkdir Compiled
if not defined CompileShadersOutput set CompileShadersOutput=Compiled
set StrTrim=%CompileShadersOutput%##
set StrTrim=%StrTrim: ##=%
set CompileShadersOutput=%StrTrim:##=%
@if not exist %CompileShadersOutput% mkdir %CompileShadersOutput%
call :CompileShader BC7Encode TryMode456CS
call :CompileShader BC7Encode TryMode137CS
call :CompileShader BC7Encode TryMode02CS
Expand All @@ -39,7 +43,7 @@ endlocal
exit /b

:CompileShader
set fxc=%PCFXC% %1.hlsl %FXCOPTS% /Tcs_4_0 /E%2 /FhCompiled\%1_%2.inc /FdCompiled\%1_%2.pdb /Vn%1_%2
set fxc=%PCFXC% %1.hlsl %FXCOPTS% /Tcs_4_0 /E%2 /Fh%CompileShadersOutput%\%1_%2.inc /Fd%CompileShadersOutput%\%1_%2.pdb /Vn%1_%2
echo.
echo %fxc%
%fxc% || set error=1
Expand Down
12 changes: 6 additions & 6 deletions Kits/DirectXTex/filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ inline void _CreateLinearFilter(_In_ size_t source, _In_ size_t dest, _In_ bool
ptrdiff_t isrcB = ptrdiff_t(srcB);
ptrdiff_t isrcA = isrcB - 1;

float weight = 1.0f + float(isrcB) - srcB;

if (isrcA < 0)
{
isrcA = (wrap) ? (ptrdiff_t(source) - 1) : 0;
Expand All @@ -86,8 +88,6 @@ inline void _CreateLinearFilter(_In_ size_t source, _In_ size_t dest, _In_ bool
isrcB = (wrap) ? 0 : (ptrdiff_t(source) - 1);
}

float weight = 1.0f + float(isrcB) - srcB;

auto& entry = lf[u];
entry.u0 = size_t(isrcA);
entry.weight0 = weight;
Expand Down Expand Up @@ -240,11 +240,11 @@ namespace TriangleFilter
TriangleRow() noexcept : remaining(0), next(nullptr) {}
};

static const size_t TF_FILTER_SIZE = sizeof(Filter) - sizeof(FilterFrom);
static const size_t TF_FROM_SIZE = sizeof(FilterFrom) - sizeof(FilterTo);
static const size_t TF_TO_SIZE = sizeof(FilterTo);
constexpr size_t TF_FILTER_SIZE = sizeof(Filter) - sizeof(FilterFrom);
constexpr size_t TF_FROM_SIZE = sizeof(FilterFrom) - sizeof(FilterTo);
constexpr size_t TF_TO_SIZE = sizeof(FilterTo);

static const float TF_EPSILON = 0.00001f;
constexpr float TF_EPSILON = 0.00001f;

inline HRESULT _Create(_In_ size_t source, _In_ size_t dest, _In_ bool wrap, _Inout_ std::unique_ptr<Filter>& tf) noexcept
{
Expand Down
3 changes: 2 additions & 1 deletion Kits/DirectXTex/scoped.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <cstddef>
#include <cstdint>
#include <memory>
#include <tuple>

#ifndef WIN32
#include <cstdlib>
Expand Down Expand Up @@ -98,7 +99,7 @@ class auto_delete_file
{
FILE_DISPOSITION_INFO info = {};
info.DeleteFile = TRUE;
(void)SetFileInformationByHandle(m_handle, FileDispositionInfo, &info, sizeof(info));
std::ignore = SetFileInformationByHandle(m_handle, FileDispositionInfo, &info, sizeof(info));
}
}

Expand Down
3 changes: 2 additions & 1 deletion XDKSamples/Tools/xtexconv/PortablePixMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <cstdint>
#include <memory>
#include <new>
#include <tuple>

#include "DirectXTex.h"

Expand Down Expand Up @@ -52,7 +53,7 @@ namespace
{
FILE_DISPOSITION_INFO info = {};
info.DeleteFile = TRUE;
(void)SetFileInformationByHandle(m_handle, FileDispositionInfo, &info, sizeof(info));
std::ignore = SetFileInformationByHandle(m_handle, FileDispositionInfo, &info, sizeof(info));
}
}

Expand Down
Loading

0 comments on commit 9654b6e

Please sign in to comment.