diff options
| author | mtamis <[email protected]> | 2017-02-28 18:24:59 +0100 |
|---|---|---|
| committer | mtamis <[email protected]> | 2017-02-28 18:24:59 +0100 |
| commit | 5581909a4d19db97304449f66404ff99a0429d3f (patch) | |
| tree | a90f7eb85c095a8aba45cf5e909c82c1cdbed77d /NvCloth/samples/external/DirectXTex/10.5.2016.2 | |
| parent | Fix cmake visual studio project generation (locate_gw_root.bat) (diff) | |
| download | nvcloth-5581909a4d19db97304449f66404ff99a0429d3f.tar.xz nvcloth-5581909a4d19db97304449f66404ff99a0429d3f.zip | |
Add visual samples.
Diffstat (limited to 'NvCloth/samples/external/DirectXTex/10.5.2016.2')
40 files changed, 2651 insertions, 0 deletions
diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/Win32/Debug/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/Win32/Debug/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..997aea2 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/Win32/Debug/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/Win32/Debug/directxtex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/Win32/Debug/directxtex.pdb Binary files differnew file mode 100644 index 0000000..17e59eb --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/Win32/Debug/directxtex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/Win32/Release/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/Win32/Release/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..de2d07a --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/Win32/Release/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/Win32/Release/directxtex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/Win32/Release/directxtex.pdb Binary files differnew file mode 100644 index 0000000..9f23b21 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/Win32/Release/directxtex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/x64/Debug/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/x64/Debug/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..a57b2d7 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/x64/Debug/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/x64/Debug/directxtex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/x64/Debug/directxtex.pdb Binary files differnew file mode 100644 index 0000000..ba864f3 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/x64/Debug/directxtex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/x64/Release/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/x64/Release/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..6dab420 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/x64/Release/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/x64/Release/directxtex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/x64/Release/directxtex.pdb Binary files differnew file mode 100644 index 0000000..588f72d --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2013/x64/Release/directxtex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/Win32/Debug/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/Win32/Debug/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..39a78a4 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/Win32/Debug/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/Win32/Debug/DirectXTex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/Win32/Debug/DirectXTex.pdb Binary files differnew file mode 100644 index 0000000..2307ceb --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/Win32/Debug/DirectXTex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/Win32/Release/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/Win32/Release/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..ea268bd --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/Win32/Release/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/Win32/Release/DirectXTex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/Win32/Release/DirectXTex.pdb Binary files differnew file mode 100644 index 0000000..8469ac4 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/Win32/Release/DirectXTex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/x64/Debug/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/x64/Debug/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..c7185e2 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/x64/Debug/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/x64/Debug/DirectXTex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/x64/Debug/DirectXTex.pdb Binary files differnew file mode 100644 index 0000000..f818d01 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/x64/Debug/DirectXTex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/x64/Release/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/x64/Release/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..62d7955 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/x64/Release/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/x64/Release/DirectXTex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/x64/Release/DirectXTex.pdb Binary files differnew file mode 100644 index 0000000..5dc8c6e --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/dynamiccrt/vs2015/x64/Release/DirectXTex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/Win32/Debug/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/Win32/Debug/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..fb12df6 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/Win32/Debug/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/Win32/Debug/directxtex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/Win32/Debug/directxtex.pdb Binary files differnew file mode 100644 index 0000000..dd97134 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/Win32/Debug/directxtex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/Win32/Release/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/Win32/Release/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..da06dda --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/Win32/Release/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/Win32/Release/directxtex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/Win32/Release/directxtex.pdb Binary files differnew file mode 100644 index 0000000..607d0a6 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/Win32/Release/directxtex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/x64/Debug/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/x64/Debug/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..4cb2733 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/x64/Debug/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/x64/Debug/directxtex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/x64/Debug/directxtex.pdb Binary files differnew file mode 100644 index 0000000..6d13872 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/x64/Debug/directxtex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/x64/Release/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/x64/Release/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..3e74fe6 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/x64/Release/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/x64/Release/directxtex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/x64/Release/directxtex.pdb Binary files differnew file mode 100644 index 0000000..ff21366 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2013/x64/Release/directxtex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/Win32/Debug/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/Win32/Debug/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..6252c58 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/Win32/Debug/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/Win32/Debug/DirectXTex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/Win32/Debug/DirectXTex.pdb Binary files differnew file mode 100644 index 0000000..9fb0d19 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/Win32/Debug/DirectXTex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/Win32/Release/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/Win32/Release/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..cee3cde --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/Win32/Release/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/Win32/Release/DirectXTex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/Win32/Release/DirectXTex.pdb Binary files differnew file mode 100644 index 0000000..dea5b06 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/Win32/Release/DirectXTex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/x64/Debug/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/x64/Debug/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..af61dde --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/x64/Debug/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/x64/Debug/DirectXTex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/x64/Debug/DirectXTex.pdb Binary files differnew file mode 100644 index 0000000..7241f67 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/x64/Debug/DirectXTex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/x64/Release/DirectXTex.lib b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/x64/Release/DirectXTex.lib Binary files differnew file mode 100644 index 0000000..70a0671 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/x64/Release/DirectXTex.lib diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/x64/Release/DirectXTex.pdb b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/x64/Release/DirectXTex.pdb Binary files differnew file mode 100644 index 0000000..4b244b7 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/bin/staticcrt/vs2015/x64/Release/DirectXTex.pdb diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/BC.h b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/BC.h new file mode 100644 index 0000000..8ddb366 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/BC.h @@ -0,0 +1,891 @@ +//------------------------------------------------------------------------------------- +// BC.h +// +// Block-compression (BC) functionality +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +// PARTICULAR PURPOSE. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// http://go.microsoft.com/fwlink/?LinkId=248926 +//------------------------------------------------------------------------------------- + +#pragma once + +#include <assert.h> +#include <directxmath.h> +#include <directxpackedvector.h> + +namespace DirectX +{ + +//------------------------------------------------------------------------------------- +// Constants +//------------------------------------------------------------------------------------- + +const uint16_t F16S_MASK = 0x8000; // f16 sign mask +const uint16_t F16EM_MASK = 0x7fff; // f16 exp & mantissa mask +const uint16_t F16MAX = 0x7bff; // MAXFLT bit pattern for XMHALF + +#define SIGN_EXTEND(x,nb) ((((x)&(1<<((nb)-1)))?((~0)<<(nb)):0)|(x)) + +// Because these are used in SAL annotations, they need to remain macros rather than const values +#define NUM_PIXELS_PER_BLOCK 16 +#define BC6H_MAX_REGIONS 2 +#define BC6H_MAX_INDICES 16 +#define BC7_MAX_REGIONS 3 +#define BC7_MAX_INDICES 16 + +const size_t BC6H_NUM_CHANNELS = 3; +const size_t BC6H_MAX_SHAPES = 32; + +const size_t BC7_NUM_CHANNELS = 4; +const size_t BC7_MAX_SHAPES = 64; + +const int32_t BC67_WEIGHT_MAX = 64; +const uint32_t BC67_WEIGHT_SHIFT = 6; +const int32_t BC67_WEIGHT_ROUND = 32; + +extern const int g_aWeights2[4]; +extern const int g_aWeights3[8]; +extern const int g_aWeights4[16]; + +enum BC_FLAGS +{ + BC_FLAGS_NONE = 0x0, + BC_FLAGS_DITHER_RGB = 0x10000, // Enables dithering for RGB colors for BC1-3 + BC_FLAGS_DITHER_A = 0x20000, // Enables dithering for Alpha channel for BC1-3 + BC_FLAGS_UNIFORM = 0x40000, // By default, uses perceptual weighting for BC1-3; this flag makes it a uniform weighting + BC_FLAGS_USE_3SUBSETS = 0x80000,// By default, BC7 skips mode 0 & 2; this flag adds those modes back +}; + +//------------------------------------------------------------------------------------- +// Structures +//------------------------------------------------------------------------------------- +class HDRColorA; + +class LDRColorA +{ +public: + uint8_t r, g, b, a; + + LDRColorA() = default; + LDRColorA(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a) : r(_r), g(_g), b(_b), a(_a) {} + + const uint8_t& operator [] (_In_range_(0,3) size_t uElement) const + { + switch(uElement) + { + case 0: return r; + case 1: return g; + case 2: return b; + case 3: return a; + default: assert(false); return r; + } + } + + uint8_t& operator [] (_In_range_(0,3) size_t uElement) + { + switch(uElement) + { + case 0: return r; + case 1: return g; + case 2: return b; + case 3: return a; + default: assert(false); return r; + } + } + + LDRColorA operator = (_In_ const HDRColorA& c); + + static void InterpolateRGB(_In_ const LDRColorA& c0, _In_ const LDRColorA& c1, _In_ size_t wc, _In_ _In_range_(2, 4) size_t wcprec, _Out_ LDRColorA& out) + { + const int* aWeights = nullptr; + switch(wcprec) + { + case 2: aWeights = g_aWeights2; assert( wc < 4 ); _Analysis_assume_( wc < 4 ); break; + case 3: aWeights = g_aWeights3; assert( wc < 8 ); _Analysis_assume_( wc < 8 ); break; + case 4: aWeights = g_aWeights4; assert( wc < 16 ); _Analysis_assume_( wc < 16 ); break; + default: assert(false); out.r = out.g = out.b = 0; return; + } + out.r = uint8_t((uint32_t(c0.r) * uint32_t(BC67_WEIGHT_MAX - aWeights[wc]) + uint32_t(c1.r) * uint32_t(aWeights[wc]) + BC67_WEIGHT_ROUND) >> BC67_WEIGHT_SHIFT); + out.g = uint8_t((uint32_t(c0.g) * uint32_t(BC67_WEIGHT_MAX - aWeights[wc]) + uint32_t(c1.g) * uint32_t(aWeights[wc]) + BC67_WEIGHT_ROUND) >> BC67_WEIGHT_SHIFT); + out.b = uint8_t((uint32_t(c0.b) * uint32_t(BC67_WEIGHT_MAX - aWeights[wc]) + uint32_t(c1.b) * uint32_t(aWeights[wc]) + BC67_WEIGHT_ROUND) >> BC67_WEIGHT_SHIFT); + } + + static void InterpolateA(_In_ const LDRColorA& c0, _In_ const LDRColorA& c1, _In_ size_t wa, _In_range_(2, 4) _In_ size_t waprec, _Out_ LDRColorA& out) + { + const int* aWeights = nullptr; + switch(waprec) + { + case 2: aWeights = g_aWeights2; assert( wa < 4 ); _Analysis_assume_( wa < 4 ); break; + case 3: aWeights = g_aWeights3; assert( wa < 8 ); _Analysis_assume_( wa < 8 ); break; + case 4: aWeights = g_aWeights4; assert( wa < 16 ); _Analysis_assume_( wa < 16 ); break; + default: assert(false); out.a = 0; return; + } + out.a = uint8_t((uint32_t(c0.a) * uint32_t(BC67_WEIGHT_MAX - aWeights[wa]) + uint32_t(c1.a) * uint32_t(aWeights[wa]) + BC67_WEIGHT_ROUND) >> BC67_WEIGHT_SHIFT); + } + + static void Interpolate(_In_ const LDRColorA& c0, _In_ const LDRColorA& c1, _In_ size_t wc, _In_ size_t wa, _In_ _In_range_(2, 4) size_t wcprec, _In_ _In_range_(2, 4) size_t waprec, _Out_ LDRColorA& out) + { + InterpolateRGB(c0, c1, wc, wcprec, out); + InterpolateA(c0, c1, wa, waprec, out); + } +}; + +static_assert( sizeof(LDRColorA) == 4, "Unexpected packing"); + +class HDRColorA +{ +public: + float r, g, b, a; + +public: + HDRColorA() = default; + HDRColorA(float _r, float _g, float _b, float _a) : r(_r), g(_g), b(_b), a(_a) {} + HDRColorA(const HDRColorA& c) : r(c.r), g(c.g), b(c.b), a(c.a) {} + HDRColorA(const LDRColorA& c) + { + r = float(c.r) * (1.0f/255.0f); + g = float(c.g) * (1.0f/255.0f); + b = float(c.b) * (1.0f/255.0f); + a = float(c.a) * (1.0f/255.0f); + } + + // binary operators + HDRColorA operator + ( _In_ const HDRColorA& c ) const + { + return HDRColorA(r + c.r, g + c.g, b + c.b, a + c.a); + } + + HDRColorA operator - ( _In_ const HDRColorA& c ) const + { + return HDRColorA(r - c.r, g - c.g, b - c.b, a - c.a); + } + + HDRColorA operator * ( _In_ float f ) const + { + return HDRColorA(r * f, g * f, b * f, a * f); + } + + HDRColorA operator / ( _In_ float f ) const + { + float fInv = 1.0f / f; + return HDRColorA(r * fInv, g * fInv, b * fInv, a * fInv); + } + + float operator * ( _In_ const HDRColorA& c ) const + { + return r * c.r + g * c.g + b * c.b + a * c.a; + } + + // assignment operators + HDRColorA& operator += ( _In_ const HDRColorA& c ) + { + r += c.r; + g += c.g; + b += c.b; + a += c.a; + return *this; + } + + HDRColorA& operator -= ( _In_ const HDRColorA& c ) + { + r -= c.r; + g -= c.g; + b -= c.b; + a -= c.a; + return *this; + } + + HDRColorA& operator *= ( _In_ float f ) + { + r *= f; + g *= f; + b *= f; + a *= f; + return *this; + } + + HDRColorA& operator /= ( _In_ float f ) + { + float fInv = 1.0f / f; + r *= fInv; + g *= fInv; + b *= fInv; + a *= fInv; + return *this; + } + + HDRColorA& operator = (_In_ const LDRColorA& c) + { + r = (float) c.r; + g = (float) c.g; + b = (float) c.b; + a = (float) c.a; + return *this; + } + + HDRColorA& Clamp(_In_ float fMin, _In_ float fMax) + { + r = std::min<float>(fMax, std::max<float>(fMin, r)); + g = std::min<float>(fMax, std::max<float>(fMin, g)); + b = std::min<float>(fMax, std::max<float>(fMin, b)); + a = std::min<float>(fMax, std::max<float>(fMin, a)); + return *this; + } + + LDRColorA ToLDRColorA() const + { + return LDRColorA((uint8_t) (r + 0.01f), (uint8_t) (g + 0.01f), (uint8_t) (b + 0.01f), (uint8_t) (a + 0.01f)); + } +}; + +inline LDRColorA LDRColorA::operator = (_In_ const HDRColorA& c) +{ + LDRColorA ret; + HDRColorA tmp(c); + tmp = tmp.Clamp(0.0f, 1.0f) * 255.0f; + ret.r = uint8_t(tmp.r + 0.001f); + ret.g = uint8_t(tmp.g + 0.001f); + ret.b = uint8_t(tmp.b + 0.001f); + ret.a = uint8_t(tmp.a + 0.001f); + return ret; +} + +struct LDREndPntPair +{ + LDRColorA A; + LDRColorA B; +}; + +struct HDREndPntPair +{ + HDRColorA A; + HDRColorA B; +}; + +inline HDRColorA* HDRColorALerp(_Out_ HDRColorA *pOut, _In_ const HDRColorA *pC1, _In_ const HDRColorA *pC2, _In_ float s) +{ + pOut->r = pC1->r + s * (pC2->r - pC1->r); + pOut->g = pC1->g + s * (pC2->g - pC1->g); + pOut->b = pC1->b + s * (pC2->b - pC1->b); + pOut->a = pC1->a + s * (pC2->a - pC1->a); + return pOut; +} + +#pragma pack(push,1) +// BC1/DXT1 compression (4 bits per texel) +struct D3DX_BC1 +{ + uint16_t rgb[2]; // 565 colors + uint32_t bitmap; // 2bpp rgb bitmap +}; + +// BC2/DXT2/3 compression (8 bits per texel) +struct D3DX_BC2 +{ + uint32_t bitmap[2]; // 4bpp alpha bitmap + D3DX_BC1 bc1; // BC1 rgb data +}; + +// BC3/DXT4/5 compression (8 bits per texel) +struct D3DX_BC3 +{ + uint8_t alpha[2]; // alpha values + uint8_t bitmap[6]; // 3bpp alpha bitmap + D3DX_BC1 bc1; // BC1 rgb data +}; +#pragma pack(pop) + +class INTColor +{ +public: + int r, g, b; + int pad; + +public: + INTColor() = default; + INTColor(int nr, int ng, int nb) {r = nr; g = ng; b = nb;} + INTColor(const INTColor& c) {r = c.r; g = c.g; b = c.b;} + + INTColor operator - ( _In_ const INTColor& c ) const + { + return INTColor(r - c.r, g - c.g, b - c.b); + } + + INTColor& operator += ( _In_ const INTColor& c ) + { + r += c.r; + g += c.g; + b += c.b; + return *this; + } + + INTColor& operator -= ( _In_ const INTColor& c ) + { + r -= c.r; + g -= c.g; + b -= c.b; + return *this; + } + + INTColor& operator &= ( _In_ const INTColor& c ) + { + r &= c.r; + g &= c.g; + b &= c.b; + return *this; + } + + int& operator [] ( _In_ uint8_t i ) + { + assert(i < sizeof(INTColor) / sizeof(int)); + _Analysis_assume_(i < sizeof(INTColor) / sizeof(int)); + return ((int*) this)[i]; + } + + void Set(_In_ const HDRColorA& c, _In_ bool bSigned) + { + PackedVector::XMHALF4 aF16; + + XMVECTOR v = XMLoadFloat4( (const XMFLOAT4*)& c ); + XMStoreHalf4( &aF16, v ); + + r = F16ToINT(aF16.x, bSigned); + g = F16ToINT(aF16.y, bSigned); + b = F16ToINT(aF16.z, bSigned); + } + + INTColor& Clamp(_In_ int iMin, _In_ int iMax) + { + r = std::min<int>(iMax, std::max<int>(iMin, r)); + g = std::min<int>(iMax, std::max<int>(iMin, g)); + b = std::min<int>(iMax, std::max<int>(iMin, b)); + return *this; + } + + INTColor& SignExtend(_In_ const LDRColorA& Prec) + { + r = SIGN_EXTEND(r, Prec.r); + g = SIGN_EXTEND(g, Prec.g); + b = SIGN_EXTEND(b, Prec.b); + return *this; + } + + void ToF16(_Out_writes_(3) PackedVector::HALF aF16[3], _In_ bool bSigned) const + { + aF16[0] = INT2F16(r, bSigned); + aF16[1] = INT2F16(g, bSigned); + aF16[2] = INT2F16(b, bSigned); + } + +private: + static int F16ToINT(_In_ const PackedVector::HALF& f, _In_ bool bSigned) + { + uint16_t input = *((const uint16_t*) &f); + int out, s; + if(bSigned) + { + s = input & F16S_MASK; + input &= F16EM_MASK; + if(input > F16MAX) out = F16MAX; + else out = input; + out = s ? -out : out; + } + else + { + if(input & F16S_MASK) out = 0; + else out = input; + } + return out; + } + + static PackedVector::HALF INT2F16(_In_ int input, _In_ bool bSigned) + { + PackedVector::HALF h; + uint16_t out; + if(bSigned) + { + int s = 0; + if(input < 0) + { + s = F16S_MASK; + input = -input; + } + out = uint16_t(s | input); + } + else + { + assert(input >= 0 && input <= F16MAX); + out = (uint16_t) input; + } + + *((uint16_t*) &h) = out; + return h; + } +}; + +static_assert( sizeof(INTColor) == 16, "Unexpected packing"); + +struct INTEndPntPair +{ + INTColor A; + INTColor B; +}; + +template< size_t SizeInBytes > +class CBits +{ +public: + uint8_t GetBit(_Inout_ size_t& uStartBit) const + { + assert(uStartBit < 128); + _Analysis_assume_(uStartBit < 128); + size_t uIndex = uStartBit >> 3; + uint8_t ret = (m_uBits[uIndex] >> (uStartBit - (uIndex << 3))) & 0x01; + uStartBit++; + return ret; + } + + uint8_t GetBits(_Inout_ size_t& uStartBit, _In_ size_t uNumBits) const + { + if(uNumBits == 0) return 0; + assert(uStartBit + uNumBits <= 128 && uNumBits <= 8); + _Analysis_assume_(uStartBit + uNumBits <= 128 && uNumBits <= 8); + uint8_t ret; + size_t uIndex = uStartBit >> 3; + size_t uBase = uStartBit - (uIndex << 3); + if(uBase + uNumBits > 8) + { + size_t uFirstIndexBits = 8 - uBase; + size_t uNextIndexBits = uNumBits - uFirstIndexBits; + ret = (m_uBits[uIndex] >> uBase) | ((m_uBits[uIndex+1] & ((1 << uNextIndexBits) - 1)) << uFirstIndexBits); + } + else + { + ret = (m_uBits[uIndex] >> uBase) & ((1 << uNumBits) - 1); + } + assert(ret < (1 << uNumBits)); + uStartBit += uNumBits; + return ret; + } + + void SetBit(_Inout_ size_t& uStartBit, _In_ uint8_t uValue) + { + assert(uStartBit < 128 && uValue < 2); + _Analysis_assume_(uStartBit < 128 && uValue < 2); + size_t uIndex = uStartBit >> 3; + size_t uBase = uStartBit - (uIndex << 3); + m_uBits[uIndex] &= ~(1 << uBase); + m_uBits[uIndex] |= uValue << uBase; + uStartBit++; + } + + void SetBits(_Inout_ size_t& uStartBit, _In_ size_t uNumBits, _In_ uint8_t uValue) + { + if(uNumBits == 0) + return; + assert(uStartBit + uNumBits <= 128 && uNumBits <= 8); + _Analysis_assume_(uStartBit + uNumBits <= 128 && uNumBits <= 8); + assert(uValue < (1 << uNumBits)); + size_t uIndex = uStartBit >> 3; + size_t uBase = uStartBit - (uIndex << 3); + if(uBase + uNumBits > 8) + { + size_t uFirstIndexBits = 8 - uBase; + size_t uNextIndexBits = uNumBits - uFirstIndexBits; + m_uBits[uIndex] &= ~(((1 << uFirstIndexBits) - 1) << uBase); + m_uBits[uIndex] |= uValue << uBase; + m_uBits[uIndex+1] &= ~((1 << uNextIndexBits) - 1); + m_uBits[uIndex+1] |= uValue >> uFirstIndexBits; + } + else + { + m_uBits[uIndex] &= ~(((1 << uNumBits) - 1) << uBase); + m_uBits[uIndex] |= uValue << uBase; + } + uStartBit += uNumBits; + } + +private: + uint8_t m_uBits[ SizeInBytes ]; +}; + +// BC6H compression (16 bits per texel) +class D3DX_BC6H : private CBits< 16 > +{ +public: + void Decode(_In_ bool bSigned, _Out_writes_(NUM_PIXELS_PER_BLOCK) HDRColorA* pOut) const; + void Encode(_In_ bool bSigned, _In_reads_(NUM_PIXELS_PER_BLOCK) const HDRColorA* const pIn); + +private: +#pragma warning(push) +#pragma warning(disable : 4480) + enum EField : uint8_t + { + NA, // N/A + M, // Mode + D, // Shape + RW, + RX, + RY, + RZ, + GW, + GX, + GY, + GZ, + BW, + BX, + BY, + BZ, + }; +#pragma warning(pop) + + struct ModeDescriptor + { + EField m_eField; + uint8_t m_uBit; + }; + + struct ModeInfo + { + uint8_t uMode; + uint8_t uPartitions; + bool bTransformed; + uint8_t uIndexPrec; + LDRColorA RGBAPrec[BC6H_MAX_REGIONS][2]; + }; + +#pragma warning(push) +#pragma warning(disable : 4512) + struct EncodeParams + { + float fBestErr; + const bool bSigned; + uint8_t uMode; + uint8_t uShape; + const HDRColorA* const aHDRPixels; + INTEndPntPair aUnqEndPts[BC6H_MAX_SHAPES][BC6H_MAX_REGIONS]; + INTColor aIPixels[NUM_PIXELS_PER_BLOCK]; + + EncodeParams(const HDRColorA* const aOriginal, bool bSignedFormat) : + aHDRPixels(aOriginal), fBestErr(FLT_MAX), bSigned(bSignedFormat) + { + for(size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i) + { + aIPixels[i].Set(aOriginal[i], bSigned); + } + } + }; +#pragma warning(pop) + + static int Quantize(_In_ int iValue, _In_ int prec, _In_ bool bSigned); + static int Unquantize(_In_ int comp, _In_ uint8_t uBitsPerComp, _In_ bool bSigned); + static int FinishUnquantize(_In_ int comp, _In_ bool bSigned); + + static bool EndPointsFit(_In_ const EncodeParams* pEP, _In_reads_(BC6H_MAX_REGIONS) const INTEndPntPair aEndPts[]); + + void GeneratePaletteQuantized(_In_ const EncodeParams* pEP, _In_ const INTEndPntPair& endPts, + _Out_writes_(BC6H_MAX_INDICES) INTColor aPalette[]) const; + float MapColorsQuantized(_In_ const EncodeParams* pEP, _In_reads_(np) const INTColor aColors[], _In_ size_t np, _In_ const INTEndPntPair &endPts) const; + float PerturbOne(_In_ const EncodeParams* pEP, _In_reads_(np) const INTColor aColors[], _In_ size_t np, _In_ uint8_t ch, + _In_ const INTEndPntPair& oldEndPts, _Out_ INTEndPntPair& newEndPts, _In_ float fOldErr, _In_ int do_b) const; + void OptimizeOne(_In_ const EncodeParams* pEP, _In_reads_(np) const INTColor aColors[], _In_ size_t np, _In_ float aOrgErr, + _In_ const INTEndPntPair &aOrgEndPts, _Out_ INTEndPntPair &aOptEndPts) const; + void OptimizeEndPoints(_In_ const EncodeParams* pEP, _In_reads_(BC6H_MAX_REGIONS) const float aOrgErr[], + _In_reads_(BC6H_MAX_REGIONS) const INTEndPntPair aOrgEndPts[], + _Out_writes_all_(BC6H_MAX_REGIONS) INTEndPntPair aOptEndPts[]) const; + static void SwapIndices(_In_ const EncodeParams* pEP, _Inout_updates_all_(BC6H_MAX_REGIONS) INTEndPntPair aEndPts[], + _In_reads_(NUM_PIXELS_PER_BLOCK) size_t aIndices[]); + void AssignIndices(_In_ const EncodeParams* pEP, _In_reads_(BC6H_MAX_REGIONS) const INTEndPntPair aEndPts[], + _Out_writes_(NUM_PIXELS_PER_BLOCK) size_t aIndices[], + _Out_writes_(BC6H_MAX_REGIONS) float aTotErr[]) const; + void QuantizeEndPts(_In_ const EncodeParams* pEP, _Out_writes_(BC6H_MAX_REGIONS) INTEndPntPair* qQntEndPts) const; + void EmitBlock(_In_ const EncodeParams* pEP, _In_reads_(BC6H_MAX_REGIONS) const INTEndPntPair aEndPts[], + _In_reads_(NUM_PIXELS_PER_BLOCK) const size_t aIndices[]); + void Refine(_Inout_ EncodeParams* pEP); + + static void GeneratePaletteUnquantized(_In_ const EncodeParams* pEP, _In_ size_t uRegion, _Out_writes_(BC6H_MAX_INDICES) INTColor aPalette[]); + float MapColors(_In_ const EncodeParams* pEP, _In_ size_t uRegion, _In_ size_t np, _In_reads_(np) const size_t* auIndex) const; + float RoughMSE(_Inout_ EncodeParams* pEP) const; + +private: + const static ModeDescriptor ms_aDesc[][82]; + const static ModeInfo ms_aInfo[]; + const static int ms_aModeToInfo[]; +}; + +// BC67 compression (16b bits per texel) +class D3DX_BC7 : private CBits< 16 > +{ +public: + void Decode(_Out_writes_(NUM_PIXELS_PER_BLOCK) HDRColorA* pOut) const; + void Encode(bool skip3subsets, _In_reads_(NUM_PIXELS_PER_BLOCK) const HDRColorA* const pIn); + +private: + struct ModeInfo + { + uint8_t uPartitions; + uint8_t uPartitionBits; + uint8_t uPBits; + uint8_t uRotationBits; + uint8_t uIndexModeBits; + uint8_t uIndexPrec; + uint8_t uIndexPrec2; + LDRColorA RGBAPrec; + LDRColorA RGBAPrecWithP; + }; + +#pragma warning(push) +#pragma warning(disable : 4512) + struct EncodeParams + { + uint8_t uMode; + LDREndPntPair aEndPts[BC7_MAX_SHAPES][BC7_MAX_REGIONS]; + LDRColorA aLDRPixels[NUM_PIXELS_PER_BLOCK]; + const HDRColorA* const aHDRPixels; + + EncodeParams(const HDRColorA* const aOriginal) : aHDRPixels(aOriginal) {} + }; +#pragma warning(pop) + + static uint8_t Quantize(_In_ uint8_t comp, _In_ uint8_t uPrec) + { + assert(0 < uPrec && uPrec <= 8); + uint8_t rnd = (uint8_t) std::min<uint16_t>(255, uint16_t(comp) + (1 << (7 - uPrec))); + return rnd >> (8 - uPrec); + } + + static LDRColorA Quantize(_In_ const LDRColorA& c, _In_ const LDRColorA& RGBAPrec) + { + LDRColorA q; + q.r = Quantize(c.r, RGBAPrec.r); + q.g = Quantize(c.g, RGBAPrec.g); + q.b = Quantize(c.b, RGBAPrec.b); + if(RGBAPrec.a) + q.a = Quantize(c.a, RGBAPrec.a); + else + q.a = 255; + return q; + } + + static uint8_t Unquantize(_In_ uint8_t comp, _In_ size_t uPrec) + { + assert(0 < uPrec && uPrec <= 8); + comp = comp << (8 - uPrec); + return comp | (comp >> uPrec); + } + + static LDRColorA Unquantize(_In_ const LDRColorA& c, _In_ const LDRColorA& RGBAPrec) + { + LDRColorA q; + q.r = Unquantize(c.r, RGBAPrec.r); + q.g = Unquantize(c.g, RGBAPrec.g); + q.b = Unquantize(c.b, RGBAPrec.b); + q.a = RGBAPrec.a > 0 ? Unquantize(c.a, RGBAPrec.a) : 255; + return q; + } + + void GeneratePaletteQuantized(_In_ const EncodeParams* pEP, _In_ size_t uIndexMode, _In_ const LDREndPntPair& endpts, + _Out_writes_(BC7_MAX_INDICES) LDRColorA aPalette[]) const; + float PerturbOne(_In_ const EncodeParams* pEP, _In_reads_(np) const LDRColorA colors[], _In_ size_t np, _In_ size_t uIndexMode, + _In_ size_t ch, _In_ const LDREndPntPair &old_endpts, + _Out_ LDREndPntPair &new_endpts, _In_ float old_err, _In_ uint8_t do_b) const; + void Exhaustive(_In_ const EncodeParams* pEP, _In_reads_(np) const LDRColorA aColors[], _In_ size_t np, _In_ size_t uIndexMode, + _In_ size_t ch, _Inout_ float& fOrgErr, _Inout_ LDREndPntPair& optEndPt) const; + void OptimizeOne(_In_ const EncodeParams* pEP, _In_reads_(np) const LDRColorA colors[], _In_ size_t np, _In_ size_t uIndexMode, + _In_ float orig_err, _In_ const LDREndPntPair &orig_endpts, _Out_ LDREndPntPair &opt_endpts) const; + void OptimizeEndPoints(_In_ const EncodeParams* pEP, _In_ size_t uShape, _In_ size_t uIndexMode, + _In_reads_(BC7_MAX_REGIONS) const float orig_err[], + _In_reads_(BC7_MAX_REGIONS) const LDREndPntPair orig_endpts[], + _Out_writes_(BC7_MAX_REGIONS) LDREndPntPair opt_endpts[]) const; + void AssignIndices(_In_ const EncodeParams* pEP, _In_ size_t uShape, _In_ size_t uIndexMode, + _In_reads_(BC7_MAX_REGIONS) LDREndPntPair endpts[], + _Out_writes_(NUM_PIXELS_PER_BLOCK) size_t aIndices[], _Out_writes_(NUM_PIXELS_PER_BLOCK) size_t aIndices2[], + _Out_writes_(BC7_MAX_REGIONS) float afTotErr[]) const; + void EmitBlock(_In_ const EncodeParams* pEP, _In_ size_t uShape, _In_ size_t uRotation, _In_ size_t uIndexMode, + _In_reads_(BC7_MAX_REGIONS) const LDREndPntPair aEndPts[], + _In_reads_(NUM_PIXELS_PER_BLOCK) const size_t aIndex[], + _In_reads_(NUM_PIXELS_PER_BLOCK) const size_t aIndex2[]); + float Refine(_In_ const EncodeParams* pEP, _In_ size_t uShape, _In_ size_t uRotation, _In_ size_t uIndexMode); + + float MapColors(_In_ const EncodeParams* pEP, _In_reads_(np) const LDRColorA aColors[], _In_ size_t np, _In_ size_t uIndexMode, + _In_ const LDREndPntPair& endPts, _In_ float fMinErr) const; + static float RoughMSE(_Inout_ EncodeParams* pEP, _In_ size_t uShape, _In_ size_t uIndexMode); + +private: + const static ModeInfo ms_aInfo[]; +}; + +//------------------------------------------------------------------------------------- +#pragma warning(push) +#pragma warning(disable : 4127) +template <bool bRange> void OptimizeAlpha(float *pX, float *pY, const float *pPoints, size_t cSteps) +{ + static const float pC6[] = { 5.0f/5.0f, 4.0f/5.0f, 3.0f/5.0f, 2.0f/5.0f, 1.0f/5.0f, 0.0f/5.0f }; + static const float pD6[] = { 0.0f/5.0f, 1.0f/5.0f, 2.0f/5.0f, 3.0f/5.0f, 4.0f/5.0f, 5.0f/5.0f }; + static const float pC8[] = { 7.0f/7.0f, 6.0f/7.0f, 5.0f/7.0f, 4.0f/7.0f, 3.0f/7.0f, 2.0f/7.0f, 1.0f/7.0f, 0.0f/7.0f }; + static const float pD8[] = { 0.0f/7.0f, 1.0f/7.0f, 2.0f/7.0f, 3.0f/7.0f, 4.0f/7.0f, 5.0f/7.0f, 6.0f/7.0f, 7.0f/7.0f }; + + const float *pC = (6 == cSteps) ? pC6 : pC8; + const float *pD = (6 == cSteps) ? pD6 : pD8; + + float MAX_VALUE = 1.0f; + float MIN_VALUE; + if (bRange) + { + MIN_VALUE = -1.0f; + } + else + { + MIN_VALUE = 0.0f; + } + + // Find Min and Max points, as starting point + float fX = MAX_VALUE; + float fY = MIN_VALUE; + + if(8 == cSteps) + { + for(size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++) + { + if(pPoints[iPoint] < fX) + fX = pPoints[iPoint]; + + if(pPoints[iPoint] > fY) + fY = pPoints[iPoint]; + } + } + else + { + for(size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++) + { + if(pPoints[iPoint] < fX && pPoints[iPoint] > MIN_VALUE) + fX = pPoints[iPoint]; + + if(pPoints[iPoint] > fY && pPoints[iPoint] < MAX_VALUE) + fY = pPoints[iPoint]; + } + + if (fX == fY) + { + fY = MAX_VALUE; + } + } + + // Use Newton's Method to find local minima of sum-of-squares error. + float fSteps = (float) (cSteps - 1); + + for(size_t iIteration = 0; iIteration < 8; iIteration++) + { + float fScale; + + if((fY - fX) < (1.0f / 256.0f)) + break; + + fScale = fSteps / (fY - fX); + + // Calculate new steps + float pSteps[8]; + + for(size_t iStep = 0; iStep < cSteps; iStep++) + pSteps[iStep] = pC[iStep] * fX + pD[iStep] * fY; + + if(6 == cSteps) + { + pSteps[6] = MIN_VALUE; + pSteps[7] = MAX_VALUE; + } + + // Evaluate function, and derivatives + float dX = 0.0f; + float dY = 0.0f; + float d2X = 0.0f; + float d2Y = 0.0f; + + for(size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++) + { + float fDot = (pPoints[iPoint] - fX) * fScale; + + size_t iStep; + + if(fDot <= 0.0f) + iStep = ((6 == cSteps) && (pPoints[iPoint] <= fX * 0.5f)) ? 6 : 0; + else if(fDot >= fSteps) + iStep = ((6 == cSteps) && (pPoints[iPoint] >= (fY + 1.0f) * 0.5f)) ? 7 : (cSteps - 1); + else + iStep = static_cast<int32_t>(fDot + 0.5f); + + + if(iStep < cSteps) + { + // D3DX had this computation backwards (pPoints[iPoint] - pSteps[iStep]) + // this fix improves RMS of the alpha component + float fDiff = pSteps[iStep] - pPoints[iPoint]; + + dX += pC[iStep] * fDiff; + d2X += pC[iStep] * pC[iStep]; + + dY += pD[iStep] * fDiff; + d2Y += pD[iStep] * pD[iStep]; + } + } + + // Move endpoints + if(d2X > 0.0f) + fX -= dX / d2X; + + if(d2Y > 0.0f) + fY -= dY / d2Y; + + if(fX > fY) + { + float f = fX; fX = fY; fY = f; + } + + if((dX * dX < (1.0f / 64.0f)) && (dY * dY < (1.0f / 64.0f))) + break; + } + + *pX = (fX < MIN_VALUE) ? MIN_VALUE : (fX > MAX_VALUE) ? MAX_VALUE : fX; + *pY = (fY < MIN_VALUE) ? MIN_VALUE : (fY > MAX_VALUE) ? MAX_VALUE : fY; +} +#pragma warning(pop) + + +//------------------------------------------------------------------------------------- +// Functions +//------------------------------------------------------------------------------------- + +typedef void (*BC_DECODE)(XMVECTOR *pColor, const uint8_t *pBC); +typedef void (*BC_ENCODE)(uint8_t *pDXT, const XMVECTOR *pColor, DWORD flags); + +void D3DXDecodeBC1(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(8) const uint8_t *pBC); +void D3DXDecodeBC2(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC); +void D3DXDecodeBC3(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC); +void D3DXDecodeBC4U(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(8) const uint8_t *pBC); +void D3DXDecodeBC4S(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(8) const uint8_t *pBC); +void D3DXDecodeBC5U(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC); +void D3DXDecodeBC5S(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC); +void D3DXDecodeBC6HU(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC); +void D3DXDecodeBC6HS(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC); +void D3DXDecodeBC7(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC); + +void D3DXEncodeBC1(_Out_writes_(8) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ float alphaRef, _In_ DWORD flags); + // BC1 requires one additional parameter, so it doesn't match signature of BC_ENCODE above + +void D3DXEncodeBC2(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags); +void D3DXEncodeBC3(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags); +void D3DXEncodeBC4U(_Out_writes_(8) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags); +void D3DXEncodeBC4S(_Out_writes_(8) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags); +void D3DXEncodeBC5U(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags); +void D3DXEncodeBC5S(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags); +void D3DXEncodeBC6HU(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags); +void D3DXEncodeBC6HS(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags); +void D3DXEncodeBC7(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ DWORD flags); + +}; // namespace diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/BCDirectCompute.h b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/BCDirectCompute.h new file mode 100644 index 0000000..8bbfa75 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/BCDirectCompute.h @@ -0,0 +1,67 @@ +//------------------------------------------------------------------------------------- +// BCDirectCompute.h +// +// Direct3D 11 Compute Shader BC Compressor +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +// PARTICULAR PURPOSE. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------------------------------- + +#pragma once + +namespace DirectX +{ + +class GPUCompressBC +{ +public: + GPUCompressBC(); + + HRESULT Initialize( _In_ ID3D11Device* pDevice ); + + HRESULT Prepare( _In_ size_t width, _In_ size_t height, _In_ DXGI_FORMAT format, _In_ float alphaWeight = 1.f, _In_ bool skip3subsets = true ); + + HRESULT Compress( _In_ const Image& srcImage, _In_ const Image& destImage ); + + DXGI_FORMAT GetSourceFormat() const { return m_srcformat; } + +private: + DXGI_FORMAT m_bcformat; + DXGI_FORMAT m_srcformat; + float m_alphaWeight; + bool m_skip3Subsets; + size_t m_width; + size_t m_height; + + Microsoft::WRL::ComPtr<ID3D11Device> m_device; + Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_context; + + Microsoft::WRL::ComPtr<ID3D11Buffer> m_err1; + Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> m_err1UAV; + Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_err1SRV; + + Microsoft::WRL::ComPtr<ID3D11Buffer> m_err2; + Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> m_err2UAV; + Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_err2SRV; + + Microsoft::WRL::ComPtr<ID3D11Buffer> m_output; + Microsoft::WRL::ComPtr<ID3D11Buffer> m_outputCPU; + Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> m_outputUAV; + Microsoft::WRL::ComPtr<ID3D11Buffer> m_constBuffer; + + // Compute shader library + Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC6H_tryModeG10CS; + Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC6H_tryModeLE10CS; + Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC6H_encodeBlockCS; + + Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode456CS; + Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode137CS; + Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode02CS; + Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_encodeBlockCS; +}; + +}; // namespace
\ No newline at end of file diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/DDS.h b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/DDS.h new file mode 100644 index 0000000..66bd734 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/DDS.h @@ -0,0 +1,243 @@ +//-------------------------------------------------------------------------------------- +// dds.h +// +// This header defines constants and structures that are useful when parsing +// DDS files. DDS files were originally designed to use several structures +// and constants that are native to DirectDraw and are defined in ddraw.h, +// such as DDSURFACEDESC2 and DDSCAPS2. This file defines similar +// (compatible) constants and structures so that one can use DDS files +// without needing to include ddraw.h. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +// PARTICULAR PURPOSE. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// http://go.microsoft.com/fwlink/?LinkId=248926 +//-------------------------------------------------------------------------------------- + +#pragma once + +#if defined(_XBOX_ONE) && defined(_TITLE) +#include <d3d11_x.h> +#else +#include <dxgiformat.h> +#endif + +#include <stdint.h> + +namespace DirectX +{ + +#pragma pack(push,1) + +const uint32_t DDS_MAGIC = 0x20534444; // "DDS " + +struct DDS_PIXELFORMAT +{ + uint32_t dwSize; + uint32_t dwFlags; + uint32_t dwFourCC; + uint32_t dwRGBBitCount; + uint32_t dwRBitMask; + uint32_t dwGBitMask; + uint32_t dwBBitMask; + uint32_t dwABitMask; +}; + +#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_ALPHA 0x00000002 // DDPF_ALPHA +#define DDS_PAL8 0x00000020 // DDPF_PALETTEINDEXED8 +#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV + +#ifndef MAKEFOURCC + #define MAKEFOURCC(ch0, ch1, ch2, ch3) \ + ((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \ + ((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 )) +#endif /* defined(MAKEFOURCC) */ + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT1 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT2 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT3 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT4 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT5 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_BC4_UNORM = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','4','U'), 0, 0, 0, 0, 0 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_BC4_SNORM = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','4','S'), 0, 0, 0, 0, 0 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_BC5_UNORM = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','5','U'), 0, 0, 0, 0, 0 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_BC5_SNORM = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','5','S'), 0, 0, 0, 0, 0 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_R8G8_B8G8 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_G8R8_G8B8 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_YUY2 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A8R8G8B8 = + { sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_X8R8G8B8 = + { sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A8B8G8R8 = + { sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_X8B8G8R8 = + { sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_G16R16 = + { sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_R5G6B5 = + { sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A1R5G5B5 = + { sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00007c00, 0x000003e0, 0x0000001f, 0x00008000 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A4R4G4B4 = + { sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00000f00, 0x000000f0, 0x0000000f, 0x0000f000 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_R8G8B8 = + { sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_L8 = + { sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 8, 0xff, 0x00, 0x00, 0x00 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_L16 = + { sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 16, 0xffff, 0x0000, 0x0000, 0x0000 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A8L8 = + { sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 16, 0x00ff, 0x0000, 0x0000, 0xff00 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A8 = + { sizeof(DDS_PIXELFORMAT), DDS_ALPHA, 0, 8, 0x00, 0x00, 0x00, 0xff }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_V8U8 = + { sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0x0000, 0x0000 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_Q8W8V8U8 = + { sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }; + +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_V16U16 = + { sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 }; + +// D3DFMT_A2R10G10B10/D3DFMT_A2B10G10R10 should be written using DX10 extension to avoid D3DX 10:10:10:2 reversal issue + +// This indicates the DDS_HEADER_DXT10 extension is present (the format is in dxgiFormat) +extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DX10 = + { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','1','0'), 0, 0, 0, 0, 0 }; + +#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT +#define DDS_HEADER_FLAGS_MIPMAP 0x00020000 // DDSD_MIPMAPCOUNT +#define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH +#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH +#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE + +#define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT +#define DDS_WIDTH 0x00000004 // DDSD_WIDTH + +#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE +#define DDS_SURFACE_FLAGS_MIPMAP 0x00400008 // DDSCAPS_COMPLEX | DDSCAPS_MIPMAP +#define DDS_SURFACE_FLAGS_CUBEMAP 0x00000008 // DDSCAPS_COMPLEX + +#define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX +#define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX +#define DDS_CUBEMAP_POSITIVEY 0x00001200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY +#define DDS_CUBEMAP_NEGATIVEY 0x00002200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY +#define DDS_CUBEMAP_POSITIVEZ 0x00004200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ +#define DDS_CUBEMAP_NEGATIVEZ 0x00008200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ + +#define DDS_CUBEMAP_ALLFACES ( DDS_CUBEMAP_POSITIVEX | DDS_CUBEMAP_NEGATIVEX |\ + DDS_CUBEMAP_POSITIVEY | DDS_CUBEMAP_NEGATIVEY |\ + DDS_CUBEMAP_POSITIVEZ | DDS_CUBEMAP_NEGATIVEZ ) + +#define DDS_CUBEMAP 0x00000200 // DDSCAPS2_CUBEMAP + +#define DDS_FLAGS_VOLUME 0x00200000 // DDSCAPS2_VOLUME + +// Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION +enum DDS_RESOURCE_DIMENSION +{ + DDS_DIMENSION_TEXTURE1D = 2, + DDS_DIMENSION_TEXTURE2D = 3, + DDS_DIMENSION_TEXTURE3D = 4, +}; + +// Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG +enum DDS_RESOURCE_MISC_FLAG +{ + DDS_RESOURCE_MISC_TEXTURECUBE = 0x4L, +}; + +enum DDS_MISC_FLAGS2 +{ + DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L, +}; + +enum DDS_ALPHA_MODE +{ + DDS_ALPHA_MODE_UNKNOWN = 0, + DDS_ALPHA_MODE_STRAIGHT = 1, + DDS_ALPHA_MODE_PREMULTIPLIED = 2, + DDS_ALPHA_MODE_OPAQUE = 3, + DDS_ALPHA_MODE_CUSTOM = 4, +}; + +struct DDS_HEADER +{ + uint32_t dwSize; + uint32_t dwFlags; + uint32_t dwHeight; + uint32_t dwWidth; + uint32_t dwPitchOrLinearSize; + uint32_t dwDepth; // only if DDS_HEADER_FLAGS_VOLUME is set in dwFlags + uint32_t dwMipMapCount; + uint32_t dwReserved1[11]; + DDS_PIXELFORMAT ddspf; + uint32_t dwCaps; + uint32_t dwCaps2; + uint32_t dwCaps3; + uint32_t dwCaps4; + uint32_t dwReserved2; +}; + +struct DDS_HEADER_DXT10 +{ + DXGI_FORMAT dxgiFormat; + uint32_t resourceDimension; + uint32_t miscFlag; // see DDS_RESOURCE_MISC_FLAG + uint32_t arraySize; + uint32_t miscFlags2; // see DDS_MISC_FLAGS2 +}; + +#pragma pack(pop) + +static_assert( sizeof(DDS_HEADER) == 124, "DDS Header size mismatch" ); +static_assert( sizeof(DDS_HEADER_DXT10) == 20, "DDS DX10 Extended Header size mismatch"); + +}; // namespace diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/DirectXTex.h b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/DirectXTex.h new file mode 100644 index 0000000..e2b848b --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/DirectXTex.h @@ -0,0 +1,636 @@ +//------------------------------------------------------------------------------------- +// DirectXTex.h +// +// DirectX Texture Library +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +// PARTICULAR PURPOSE. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// http://go.microsoft.com/fwlink/?LinkId=248926 +//------------------------------------------------------------------------------------- + +#pragma once + +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (_WIN32_WINNT <= _WIN32_WINNT_WIN8) +#error WIC is not supported on Windows Phone 8.0 +#endif + +#include <stdint.h> + +#include <algorithm> +#include <functional> + +#if defined(_XBOX_ONE) && defined(_TITLE) +#include <d3d11_x.h> +#define DCOMMON_H_INCLUDED +#else +#include <d3d11_1.h> +#endif + +#include <ocidl.h> + +#define DIRECTX_TEX_VERSION 134 + +struct IWICImagingFactory; +struct IWICMetadataQueryReader; + + +namespace DirectX +{ + + //--------------------------------------------------------------------------------- + // DXGI Format Utilities + bool __cdecl IsValid( _In_ DXGI_FORMAT fmt ); + bool __cdecl IsCompressed( _In_ DXGI_FORMAT fmt ); + bool __cdecl IsPacked( _In_ DXGI_FORMAT fmt ); + bool __cdecl IsVideo( _In_ DXGI_FORMAT fmt ); + bool __cdecl IsPlanar( _In_ DXGI_FORMAT fmt ); + bool __cdecl IsPalettized( _In_ DXGI_FORMAT fmt ); + bool __cdecl IsDepthStencil(_In_ DXGI_FORMAT fmt ); + bool __cdecl IsSRGB( _In_ DXGI_FORMAT fmt ); + bool __cdecl IsTypeless( _In_ DXGI_FORMAT fmt, _In_ bool partialTypeless = true ); + + bool __cdecl HasAlpha( _In_ DXGI_FORMAT fmt ); + + size_t __cdecl BitsPerPixel( _In_ DXGI_FORMAT fmt ); + + size_t __cdecl BitsPerColor( _In_ DXGI_FORMAT fmt ); + + enum CP_FLAGS + { + CP_FLAGS_NONE = 0x0, // Normal operation + CP_FLAGS_LEGACY_DWORD = 0x1, // Assume pitch is DWORD aligned instead of BYTE aligned + CP_FLAGS_PARAGRAPH = 0x2, // Assume pitch is 16-byte aligned instead of BYTE aligned + CP_FLAGS_YMM = 0x4, // Assume pitch is 32-byte aligned instead of BYTE aligned + CP_FLAGS_ZMM = 0x8, // Assume pitch is 64-byte aligned instead of BYTE aligned + CP_FLAGS_PAGE4K = 0x200, // Assume pitch is 4096-byte aligned instead of BYTE aligned + CP_FLAGS_24BPP = 0x10000, // Override with a legacy 24 bits-per-pixel format size + CP_FLAGS_16BPP = 0x20000, // Override with a legacy 16 bits-per-pixel format size + CP_FLAGS_8BPP = 0x40000, // Override with a legacy 8 bits-per-pixel format size + }; + + void __cdecl ComputePitch( _In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, + _Out_ size_t& rowPitch, _Out_ size_t& slicePitch, _In_ DWORD flags = CP_FLAGS_NONE ); + + size_t __cdecl ComputeScanlines( _In_ DXGI_FORMAT fmt, _In_ size_t height ); + + DXGI_FORMAT __cdecl MakeSRGB( _In_ DXGI_FORMAT fmt ); + DXGI_FORMAT __cdecl MakeTypeless( _In_ DXGI_FORMAT fmt ); + DXGI_FORMAT __cdecl MakeTypelessUNORM( _In_ DXGI_FORMAT fmt ); + DXGI_FORMAT __cdecl MakeTypelessFLOAT( _In_ DXGI_FORMAT fmt ); + + //--------------------------------------------------------------------------------- + // Texture metadata + enum TEX_DIMENSION + // Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION + { + TEX_DIMENSION_TEXTURE1D = 2, + TEX_DIMENSION_TEXTURE2D = 3, + TEX_DIMENSION_TEXTURE3D = 4, + }; + + enum TEX_MISC_FLAG + // Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG + { + TEX_MISC_TEXTURECUBE = 0x4L, + }; + + enum TEX_MISC_FLAG2 + { + TEX_MISC2_ALPHA_MODE_MASK = 0x7L, + }; + + enum TEX_ALPHA_MODE + // Matches DDS_ALPHA_MODE, encoded in MISC_FLAGS2 + { + TEX_ALPHA_MODE_UNKNOWN = 0, + TEX_ALPHA_MODE_STRAIGHT = 1, + TEX_ALPHA_MODE_PREMULTIPLIED = 2, + TEX_ALPHA_MODE_OPAQUE = 3, + TEX_ALPHA_MODE_CUSTOM = 4, + }; + + struct TexMetadata + { + size_t width; + size_t height; // Should be 1 for 1D textures + size_t depth; // Should be 1 for 1D or 2D textures + size_t arraySize; // For cubemap, this is a multiple of 6 + size_t mipLevels; + uint32_t miscFlags; + uint32_t miscFlags2; + DXGI_FORMAT format; + TEX_DIMENSION dimension; + + size_t __cdecl ComputeIndex( _In_ size_t mip, _In_ size_t item, _In_ size_t slice ) const; + // Returns size_t(-1) to indicate an out-of-range error + + bool __cdecl IsCubemap() const { return (miscFlags & TEX_MISC_TEXTURECUBE) != 0; } + // Helper for miscFlags + + bool __cdecl IsPMAlpha() const { return ((miscFlags2 & TEX_MISC2_ALPHA_MODE_MASK) == TEX_ALPHA_MODE_PREMULTIPLIED) != 0; } + void __cdecl SetAlphaMode( TEX_ALPHA_MODE mode ) { miscFlags2 = (miscFlags2 & ~TEX_MISC2_ALPHA_MODE_MASK) | static_cast<uint32_t>(mode); } + // Helpers for miscFlags2 + + bool __cdecl IsVolumemap() const { return (dimension == TEX_DIMENSION_TEXTURE3D); } + // Helper for dimension + }; + + enum DDS_FLAGS + { + DDS_FLAGS_NONE = 0x0, + + DDS_FLAGS_LEGACY_DWORD = 0x1, + // Assume pitch is DWORD aligned instead of BYTE aligned (used by some legacy DDS files) + + DDS_FLAGS_NO_LEGACY_EXPANSION = 0x2, + // Do not implicitly convert legacy formats that result in larger pixel sizes (24 bpp, 3:3:2, A8L8, A4L4, P8, A8P8) + + DDS_FLAGS_NO_R10B10G10A2_FIXUP = 0x4, + // Do not use work-around for long-standing D3DX DDS file format issue which reversed the 10:10:10:2 color order masks + + DDS_FLAGS_FORCE_RGB = 0x8, + // Convert DXGI 1.1 BGR formats to DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats + + DDS_FLAGS_NO_16BPP = 0x10, + // Conversions avoid use of 565, 5551, and 4444 formats and instead expand to 8888 to avoid use of optional WDDM 1.2 formats + + DDS_FLAGS_EXPAND_LUMINANCE = 0x20, + // When loading legacy luminance formats expand replicating the color channels rather than leaving them packed (L8, L16, A8L8) + + DDS_FLAGS_FORCE_DX10_EXT = 0x10000, + // Always use the 'DX10' header extension for DDS writer (i.e. don't try to write DX9 compatible DDS files) + + DDS_FLAGS_FORCE_DX10_EXT_MISC2 = 0x20000, + // DDS_FLAGS_FORCE_DX10_EXT including miscFlags2 information (result may not be compatible with D3DX10 or D3DX11) + }; + + enum WIC_FLAGS + { + WIC_FLAGS_NONE = 0x0, + + WIC_FLAGS_FORCE_RGB = 0x1, + // Loads DXGI 1.1 BGR formats as DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats + + WIC_FLAGS_NO_X2_BIAS = 0x2, + // Loads DXGI 1.1 X2 10:10:10:2 format as DXGI_FORMAT_R10G10B10A2_UNORM + + WIC_FLAGS_NO_16BPP = 0x4, + // Loads 565, 5551, and 4444 formats as 8888 to avoid use of optional WDDM 1.2 formats + + WIC_FLAGS_ALLOW_MONO = 0x8, + // Loads 1-bit monochrome (black & white) as R1_UNORM rather than 8-bit grayscale + + WIC_FLAGS_ALL_FRAMES = 0x10, + // Loads all images in a multi-frame file, converting/resizing to match the first frame as needed, defaults to 0th frame otherwise + + WIC_FLAGS_IGNORE_SRGB = 0x20, + // Ignores sRGB metadata if present in the file + + WIC_FLAGS_DITHER = 0x10000, + // Use ordered 4x4 dithering for any required conversions + + WIC_FLAGS_DITHER_DIFFUSION = 0x20000, + // Use error-diffusion dithering for any required conversions + + WIC_FLAGS_FILTER_POINT = 0x100000, + WIC_FLAGS_FILTER_LINEAR = 0x200000, + WIC_FLAGS_FILTER_CUBIC = 0x300000, + WIC_FLAGS_FILTER_FANT = 0x400000, // Combination of Linear and Box filter + // Filtering mode to use for any required image resizing (only needed when loading arrays of differently sized images; defaults to Fant) + }; + + HRESULT __cdecl GetMetadataFromDDSMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags, + _Out_ TexMetadata& metadata ); + HRESULT __cdecl GetMetadataFromDDSFile( _In_z_ LPCWSTR szFile, _In_ DWORD flags, + _Out_ TexMetadata& metadata ); + + HRESULT __cdecl GetMetadataFromTGAMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, + _Out_ TexMetadata& metadata ); + HRESULT __cdecl GetMetadataFromTGAFile( _In_z_ LPCWSTR szFile, + _Out_ TexMetadata& metadata ); + + HRESULT __cdecl GetMetadataFromWICMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags, + _Out_ TexMetadata& metadata, + _In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr); + + HRESULT __cdecl GetMetadataFromWICFile( _In_z_ LPCWSTR szFile, _In_ DWORD flags, + _Out_ TexMetadata& metadata, + _In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr); + + //--------------------------------------------------------------------------------- + // Bitmap image container + struct Image + { + size_t width; + size_t height; + DXGI_FORMAT format; + size_t rowPitch; + size_t slicePitch; + uint8_t* pixels; + }; + + class ScratchImage + { + public: + ScratchImage() + : _nimages(0), _size(0), _image(nullptr), _memory(nullptr) {} + ScratchImage(ScratchImage&& moveFrom) + : _nimages(0), _size(0), _image(nullptr), _memory(nullptr) { *this = std::move(moveFrom); } + ~ScratchImage() { Release(); } + + ScratchImage& __cdecl operator= (ScratchImage&& moveFrom); + + HRESULT __cdecl Initialize( _In_ const TexMetadata& mdata, _In_ DWORD flags = CP_FLAGS_NONE ); + + HRESULT __cdecl Initialize1D( _In_ DXGI_FORMAT fmt, _In_ size_t length, _In_ size_t arraySize, _In_ size_t mipLevels, _In_ DWORD flags = CP_FLAGS_NONE ); + HRESULT __cdecl Initialize2D( _In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, _In_ size_t arraySize, _In_ size_t mipLevels, _In_ DWORD flags = CP_FLAGS_NONE ); + HRESULT __cdecl Initialize3D( _In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, _In_ size_t depth, _In_ size_t mipLevels, _In_ DWORD flags = CP_FLAGS_NONE ); + HRESULT __cdecl InitializeCube( _In_ DXGI_FORMAT fmt, _In_ size_t width, _In_ size_t height, _In_ size_t nCubes, _In_ size_t mipLevels, _In_ DWORD flags = CP_FLAGS_NONE ); + + HRESULT __cdecl InitializeFromImage( _In_ const Image& srcImage, _In_ bool allow1D = false, _In_ DWORD flags = CP_FLAGS_NONE ); + HRESULT __cdecl InitializeArrayFromImages( _In_reads_(nImages) const Image* images, _In_ size_t nImages, _In_ bool allow1D = false, _In_ DWORD flags = CP_FLAGS_NONE ); + HRESULT __cdecl InitializeCubeFromImages( _In_reads_(nImages) const Image* images, _In_ size_t nImages, _In_ DWORD flags = CP_FLAGS_NONE ); + HRESULT __cdecl Initialize3DFromImages( _In_reads_(depth) const Image* images, _In_ size_t depth, _In_ DWORD flags = CP_FLAGS_NONE ); + + void __cdecl Release(); + + bool __cdecl OverrideFormat( _In_ DXGI_FORMAT f ); + + const TexMetadata& __cdecl GetMetadata() const { return _metadata; } + const Image* __cdecl GetImage(_In_ size_t mip, _In_ size_t item, _In_ size_t slice) const; + + const Image* __cdecl GetImages() const { return _image; } + size_t __cdecl GetImageCount() const { return _nimages; } + + uint8_t* __cdecl GetPixels() const { return _memory; } + size_t __cdecl GetPixelsSize() const { return _size; } + + bool __cdecl IsAlphaAllOpaque() const; + + private: + size_t _nimages; + size_t _size; + TexMetadata _metadata; + Image* _image; + uint8_t* _memory; + + // Hide copy constructor and assignment operator + ScratchImage( const ScratchImage& ); + ScratchImage& operator=( const ScratchImage& ); + }; + + //--------------------------------------------------------------------------------- + // Memory blob (allocated buffer pointer is always 16-byte aligned) + class Blob + { + public: + Blob() : _buffer(nullptr), _size(0) {} + Blob(Blob&& moveFrom) : _buffer(nullptr), _size(0) { *this = std::move(moveFrom); } + ~Blob() { Release(); } + + Blob& __cdecl operator= (Blob&& moveFrom); + + HRESULT __cdecl Initialize( _In_ size_t size ); + + void __cdecl Release(); + + void *__cdecl GetBufferPointer() const { return _buffer; } + size_t __cdecl GetBufferSize() const { return _size; } + + private: + void* _buffer; + size_t _size; + + // Hide copy constructor and assignment operator + Blob( const Blob& ); + Blob& operator=( const Blob& ); + }; + + //--------------------------------------------------------------------------------- + // Image I/O + + // DDS operations + HRESULT __cdecl LoadFromDDSMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags, + _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image ); + HRESULT __cdecl LoadFromDDSFile( _In_z_ LPCWSTR szFile, _In_ DWORD flags, + _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image ); + + HRESULT __cdecl SaveToDDSMemory( _In_ const Image& image, _In_ DWORD flags, + _Out_ Blob& blob ); + HRESULT __cdecl SaveToDDSMemory( _In_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags, + _Out_ Blob& blob ); + + HRESULT __cdecl SaveToDDSFile( _In_ const Image& image, _In_ DWORD flags, _In_z_ LPCWSTR szFile ); + HRESULT __cdecl SaveToDDSFile( _In_reads_(nimages) const Image* images, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags, _In_z_ LPCWSTR szFile ); + + // TGA operations + HRESULT __cdecl LoadFromTGAMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, + _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image ); + HRESULT __cdecl LoadFromTGAFile( _In_z_ LPCWSTR szFile, + _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image ); + + HRESULT __cdecl SaveToTGAMemory( _In_ const Image& image, _Out_ Blob& blob ); + HRESULT __cdecl SaveToTGAFile( _In_ const Image& image, _In_z_ LPCWSTR szFile ); + + // WIC operations + HRESULT __cdecl LoadFromWICMemory( _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DWORD flags, + _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image, + _In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr); + HRESULT __cdecl LoadFromWICFile( _In_z_ LPCWSTR szFile, _In_ DWORD flags, + _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image, + _In_opt_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr); + + HRESULT __cdecl SaveToWICMemory( _In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat, + _Out_ Blob& blob, _In_opt_ const GUID* targetFormat = nullptr, + _In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr ); + HRESULT __cdecl SaveToWICMemory( _In_count_(nimages) const Image* images, _In_ size_t nimages, _In_ DWORD flags, _In_ REFGUID guidContainerFormat, + _Out_ Blob& blob, _In_opt_ const GUID* targetFormat = nullptr, + _In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr ); + + HRESULT __cdecl SaveToWICFile( _In_ const Image& image, _In_ DWORD flags, _In_ REFGUID guidContainerFormat, + _In_z_ LPCWSTR szFile, _In_opt_ const GUID* targetFormat = nullptr, + _In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr ); + HRESULT __cdecl SaveToWICFile( _In_count_(nimages) const Image* images, _In_ size_t nimages, _In_ DWORD flags, _In_ REFGUID guidContainerFormat, + _In_z_ LPCWSTR szFile, _In_opt_ const GUID* targetFormat = nullptr, + _In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr ); + + //--------------------------------------------------------------------------------- + // Texture conversion, resizing, mipmap generation, and block compression + + enum TEX_FR_FLAGS + { + TEX_FR_ROTATE0 = 0x0, + TEX_FR_ROTATE90 = 0x1, + TEX_FR_ROTATE180 = 0x2, + TEX_FR_ROTATE270 = 0x3, + TEX_FR_FLIP_HORIZONTAL = 0x08, + TEX_FR_FLIP_VERTICAL = 0x10, + }; + + HRESULT __cdecl FlipRotate( _In_ const Image& srcImage, _In_ DWORD flags, _Out_ ScratchImage& image ); + HRESULT __cdecl FlipRotate( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ DWORD flags, _Out_ ScratchImage& result ); + // Flip and/or rotate image + + enum TEX_FILTER_FLAGS + { + TEX_FILTER_DEFAULT = 0, + + TEX_FILTER_WRAP_U = 0x1, + TEX_FILTER_WRAP_V = 0x2, + TEX_FILTER_WRAP_W = 0x4, + TEX_FILTER_WRAP = ( TEX_FILTER_WRAP_U | TEX_FILTER_WRAP_V | TEX_FILTER_WRAP_W ), + TEX_FILTER_MIRROR_U = 0x10, + TEX_FILTER_MIRROR_V = 0x20, + TEX_FILTER_MIRROR_W = 0x40, + TEX_FILTER_MIRROR = ( TEX_FILTER_MIRROR_U | TEX_FILTER_MIRROR_V | TEX_FILTER_MIRROR_W ), + // Wrap vs. Mirror vs. Clamp filtering options + + TEX_FILTER_SEPARATE_ALPHA = 0x100, + // Resize color and alpha channel independently + + TEX_FILTER_RGB_COPY_RED = 0x1000, + TEX_FILTER_RGB_COPY_GREEN = 0x2000, + TEX_FILTER_RGB_COPY_BLUE = 0x4000, + // When converting RGB to R, defaults to using grayscale. These flags indicate copying a specific channel instead + // When converting RGB to RG, defaults to copying RED | GREEN. These flags control which channels are selected instead. + + TEX_FILTER_DITHER = 0x10000, + // Use ordered 4x4 dithering for any required conversions + TEX_FILTER_DITHER_DIFFUSION = 0x20000, + // Use error-diffusion dithering for any required conversions + + TEX_FILTER_POINT = 0x100000, + TEX_FILTER_LINEAR = 0x200000, + TEX_FILTER_CUBIC = 0x300000, + TEX_FILTER_BOX = 0x400000, + TEX_FILTER_FANT = 0x400000, // Equiv to Box filtering for mipmap generation + TEX_FILTER_TRIANGLE = 0x500000, + // Filtering mode to use for any required image resizing + + TEX_FILTER_SRGB_IN = 0x1000000, + TEX_FILTER_SRGB_OUT = 0x2000000, + TEX_FILTER_SRGB = ( TEX_FILTER_SRGB_IN | TEX_FILTER_SRGB_OUT ), + // sRGB <-> RGB for use in conversion operations + // if the input format type is IsSRGB(), then SRGB_IN is on by default + // if the output format type is IsSRGB(), then SRGB_OUT is on by default + + TEX_FILTER_FORCE_NON_WIC = 0x10000000, + // Forces use of the non-WIC path when both are an option + + TEX_FILTER_FORCE_WIC = 0x20000000, + // Forces use of the WIC path even when logic would have picked a non-WIC path when both are an option + }; + + HRESULT __cdecl Resize( _In_ const Image& srcImage, _In_ size_t width, _In_ size_t height, _In_ DWORD filter, + _Out_ ScratchImage& image ); + HRESULT __cdecl Resize( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ size_t width, _In_ size_t height, _In_ DWORD filter, _Out_ ScratchImage& result ); + // Resize the image to width x height. Defaults to Fant filtering. + // Note for a complex resize, the result will always have mipLevels == 1 + + HRESULT __cdecl Convert( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold, + _Out_ ScratchImage& image ); + HRESULT __cdecl Convert( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold, _Out_ ScratchImage& result ); + // Convert the image to a new format + + HRESULT __cdecl ConvertToSinglePlane( _In_ const Image& srcImage, _Out_ ScratchImage& image ); + HRESULT __cdecl ConvertToSinglePlane( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _Out_ ScratchImage& image ); + // Converts the image from a planar format to an equivalent non-planar format + + HRESULT __cdecl GenerateMipMaps( _In_ const Image& baseImage, _In_ DWORD filter, _In_ size_t levels, + _Inout_ ScratchImage& mipChain, _In_ bool allow1D = false ); + HRESULT __cdecl GenerateMipMaps( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ DWORD filter, _In_ size_t levels, _Inout_ ScratchImage& mipChain ); + // levels of '0' indicates a full mipchain, otherwise is generates that number of total levels (including the source base image) + // Defaults to Fant filtering which is equivalent to a box filter + + HRESULT __cdecl GenerateMipMaps3D( _In_reads_(depth) const Image* baseImages, _In_ size_t depth, _In_ DWORD filter, _In_ size_t levels, + _Out_ ScratchImage& mipChain ); + HRESULT __cdecl GenerateMipMaps3D( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ DWORD filter, _In_ size_t levels, _Out_ ScratchImage& mipChain ); + // levels of '0' indicates a full mipchain, otherwise is generates that number of total levels (including the source base image) + // Defaults to Fant filtering which is equivalent to a box filter + + enum TEX_PMALPHA_FLAGS + { + TEX_PMALPHA_DEFAULT = 0, + + TEX_PMALPHA_IGNORE_SRGB = 0x1, + // ignores sRGB colorspace conversions + + TEX_PMALPHA_SRGB_IN = 0x1000000, + TEX_PMALPHA_SRGB_OUT = 0x2000000, + TEX_PMALPHA_SRGB = ( TEX_PMALPHA_SRGB_IN | TEX_PMALPHA_SRGB_OUT ), + // if the input format type is IsSRGB(), then SRGB_IN is on by default + // if the output format type is IsSRGB(), then SRGB_OUT is on by default + }; + + HRESULT __cdecl PremultiplyAlpha( _In_ const Image& srcImage, _In_ DWORD flags, _Out_ ScratchImage& image ); + HRESULT __cdecl PremultiplyAlpha( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags, _Out_ ScratchImage& result ); + // Converts to a premultiplied alpha version of the texture + + enum TEX_COMPRESS_FLAGS + { + TEX_COMPRESS_DEFAULT = 0, + + TEX_COMPRESS_RGB_DITHER = 0x10000, + // Enables dithering RGB colors for BC1-3 compression + + TEX_COMPRESS_A_DITHER = 0x20000, + // Enables dithering alpha for BC1-3 compression + + TEX_COMPRESS_DITHER = 0x30000, + // Enables both RGB and alpha dithering for BC1-3 compression + + TEX_COMPRESS_UNIFORM = 0x40000, + // Uniform color weighting for BC1-3 compression; by default uses perceptual weighting + + TEX_COMPRESS_BC7_USE_3SUBSETS = 0x80000, + // Enables exhaustive search for BC7 compress for mode 0 and 2; by default skips trying these modes + + TEX_COMPRESS_SRGB_IN = 0x1000000, + TEX_COMPRESS_SRGB_OUT = 0x2000000, + TEX_COMPRESS_SRGB = ( TEX_COMPRESS_SRGB_IN | TEX_COMPRESS_SRGB_OUT ), + // if the input format type is IsSRGB(), then SRGB_IN is on by default + // if the output format type is IsSRGB(), then SRGB_OUT is on by default + + TEX_COMPRESS_PARALLEL = 0x10000000, + // Compress is free to use multithreading to improve performance (by default it does not use multithreading) + }; + + HRESULT __cdecl Compress( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaRef, + _Out_ ScratchImage& cImage ); + HRESULT __cdecl Compress( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaRef, _Out_ ScratchImage& cImages ); + // Note that alphaRef is only used by BC1. 0.5f is a typical value to use + + HRESULT __cdecl Compress( _In_ ID3D11Device* pDevice, _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _In_ DWORD compress, + _In_ float alphaWeight, _Out_ ScratchImage& image ); + HRESULT __cdecl Compress( _In_ ID3D11Device* pDevice, _In_ const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaWeight, _Out_ ScratchImage& cImages ); + // DirectCompute-based compression (alphaWeight is only used by BC7. 1.0 is the typical value to use) + + HRESULT __cdecl Decompress( _In_ const Image& cImage, _In_ DXGI_FORMAT format, _Out_ ScratchImage& image ); + HRESULT __cdecl Decompress( _In_reads_(nimages) const Image* cImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ DXGI_FORMAT format, _Out_ ScratchImage& images ); + + //--------------------------------------------------------------------------------- + // Normal map operations + + enum CNMAP_FLAGS + { + CNMAP_DEFAULT = 0, + + CNMAP_CHANNEL_RED = 0x1, + CNMAP_CHANNEL_GREEN = 0x2, + CNMAP_CHANNEL_BLUE = 0x3, + CNMAP_CHANNEL_ALPHA = 0x4, + CNMAP_CHANNEL_LUMINANCE = 0x5, + // Channel selection when evaluting color value for height + // Luminance is a combination of red, green, and blue + + CNMAP_MIRROR_U = 0x1000, + CNMAP_MIRROR_V = 0x2000, + CNMAP_MIRROR = 0x3000, + // Use mirror semantics for scanline references (defaults to wrap) + + CNMAP_INVERT_SIGN = 0x4000, + // Inverts normal sign + + CNMAP_COMPUTE_OCCLUSION = 0x8000, + // Computes a crude occlusion term stored in the alpha channel + }; + + HRESULT __cdecl ComputeNormalMap( _In_ const Image& srcImage, _In_ DWORD flags, _In_ float amplitude, + _In_ DXGI_FORMAT format, _Out_ ScratchImage& normalMap ); + HRESULT __cdecl ComputeNormalMap( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ DWORD flags, _In_ float amplitude, _In_ DXGI_FORMAT format, _Out_ ScratchImage& normalMaps ); + + //--------------------------------------------------------------------------------- + // Misc image operations + + struct Rect + { + size_t x; + size_t y; + size_t w; + size_t h; + + Rect() = default; + Rect( size_t _x, size_t _y, size_t _w, size_t _h ) : x(_x), y(_y), w(_w), h(_h) {} + }; + + HRESULT __cdecl CopyRectangle( _In_ const Image& srcImage, _In_ const Rect& srcRect, _In_ const Image& dstImage, + _In_ DWORD filter, _In_ size_t xOffset, _In_ size_t yOffset ); + + enum CMSE_FLAGS + { + CMSE_DEFAULT = 0, + + CMSE_IMAGE1_SRGB = 0x1, + CMSE_IMAGE2_SRGB = 0x2, + // Indicates that image needs gamma correction before comparision + + CMSE_IGNORE_RED = 0x10, + CMSE_IGNORE_GREEN = 0x20, + CMSE_IGNORE_BLUE = 0x40, + CMSE_IGNORE_ALPHA = 0x80, + // Ignore the channel when computing MSE + + CMSE_IMAGE1_X2_BIAS = 0x100, + CMSE_IMAGE2_X2_BIAS = 0x200, + // Indicates that image should be scaled and biased before comparison (i.e. UNORM -> SNORM) + }; + + HRESULT __cdecl ComputeMSE( _In_ const Image& image1, _In_ const Image& image2, _Out_ float& mse, _Out_writes_opt_(4) float* mseV, _In_ DWORD flags = 0 ); + + //--------------------------------------------------------------------------------- + // WIC utility code + + enum WICCodecs + { + WIC_CODEC_BMP = 1, // Windows Bitmap (.bmp) + WIC_CODEC_JPEG, // Joint Photographic Experts Group (.jpg, .jpeg) + WIC_CODEC_PNG, // Portable Network Graphics (.png) + WIC_CODEC_TIFF, // Tagged Image File Format (.tif, .tiff) + WIC_CODEC_GIF, // Graphics Interchange Format (.gif) + WIC_CODEC_WMP, // Windows Media Photo / HD Photo / JPEG XR (.hdp, .jxr, .wdp) + WIC_CODEC_ICO, // Windows Icon (.ico) + }; + + REFGUID __cdecl GetWICCodec(_In_ WICCodecs codec); + + IWICImagingFactory* __cdecl GetWICFactory( bool& iswic2 ); + void __cdecl SetWICFactory( _In_opt_ IWICImagingFactory* pWIC); + + //--------------------------------------------------------------------------------- + // Direct3D 11 functions + bool __cdecl IsSupportedTexture( _In_ ID3D11Device* pDevice, _In_ const TexMetadata& metadata ); + + HRESULT __cdecl CreateTexture( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _Outptr_ ID3D11Resource** ppResource ); + + HRESULT __cdecl CreateShaderResourceView( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _Outptr_ ID3D11ShaderResourceView** ppSRV ); + + HRESULT __cdecl CreateTextureEx( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB, + _Outptr_ ID3D11Resource** ppResource ); + + HRESULT __cdecl CreateShaderResourceViewEx( _In_ ID3D11Device* pDevice, _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ bool forceSRGB, + _Outptr_ ID3D11ShaderResourceView** ppSRV ); + + HRESULT __cdecl CaptureTexture( _In_ ID3D11Device* pDevice, _In_ ID3D11DeviceContext* pContext, _In_ ID3D11Resource* pSource, _Out_ ScratchImage& result ); + +#include "DirectXTex.inl" + +}; // namespace diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/DirectXTex.inl b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/DirectXTex.inl new file mode 100644 index 0000000..605c2c8 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/DirectXTex.inl @@ -0,0 +1,130 @@ +//------------------------------------------------------------------------------------- +// DirectXTex.inl +// +// DirectX Texture Library +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +// PARTICULAR PURPOSE. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// http://go.microsoft.com/fwlink/?LinkId=248926 +//------------------------------------------------------------------------------------- + +#pragma once + +//===================================================================================== +// DXGI Format Utilities +//===================================================================================== + +_Use_decl_annotations_ +inline bool __cdecl IsValid( DXGI_FORMAT fmt ) +{ + return ( static_cast<size_t>(fmt) >= 1 && static_cast<size_t>(fmt) <= 190 ); +} + +_Use_decl_annotations_ +inline bool __cdecl IsCompressed(DXGI_FORMAT fmt) +{ + switch ( fmt ) + { + case DXGI_FORMAT_BC1_TYPELESS: + case DXGI_FORMAT_BC1_UNORM: + case DXGI_FORMAT_BC1_UNORM_SRGB: + case DXGI_FORMAT_BC2_TYPELESS: + case DXGI_FORMAT_BC2_UNORM: + case DXGI_FORMAT_BC2_UNORM_SRGB: + case DXGI_FORMAT_BC3_TYPELESS: + case DXGI_FORMAT_BC3_UNORM: + case DXGI_FORMAT_BC3_UNORM_SRGB: + case DXGI_FORMAT_BC4_TYPELESS: + case DXGI_FORMAT_BC4_UNORM: + case DXGI_FORMAT_BC4_SNORM: + case DXGI_FORMAT_BC5_TYPELESS: + case DXGI_FORMAT_BC5_UNORM: + case DXGI_FORMAT_BC5_SNORM: + case DXGI_FORMAT_BC6H_TYPELESS: + case DXGI_FORMAT_BC6H_UF16: + case DXGI_FORMAT_BC6H_SF16: + case DXGI_FORMAT_BC7_TYPELESS: + case DXGI_FORMAT_BC7_UNORM: + case DXGI_FORMAT_BC7_UNORM_SRGB: + return true; + + default: + return false; + } +} + +_Use_decl_annotations_ +inline bool __cdecl IsPalettized(DXGI_FORMAT fmt) +{ + switch( fmt ) + { + case DXGI_FORMAT_AI44: + case DXGI_FORMAT_IA44: + case DXGI_FORMAT_P8: + case DXGI_FORMAT_A8P8: + return true; + + default: + return false; + } +} + +_Use_decl_annotations_ +inline bool __cdecl IsSRGB(DXGI_FORMAT fmt) +{ + switch( fmt ) + { + case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: + case DXGI_FORMAT_BC1_UNORM_SRGB: + case DXGI_FORMAT_BC2_UNORM_SRGB: + case DXGI_FORMAT_BC3_UNORM_SRGB: + case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: + case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: + case DXGI_FORMAT_BC7_UNORM_SRGB: + return true; + + default: + return false; + } +} + + +//===================================================================================== +// Image I/O +//===================================================================================== +_Use_decl_annotations_ +inline HRESULT __cdecl SaveToDDSMemory(const Image& image, DWORD flags, Blob& blob) +{ + TexMetadata mdata; + memset( &mdata, 0, sizeof(mdata) ); + mdata.width = image.width; + mdata.height = image.height; + mdata.depth = 1; + mdata.arraySize = 1; + mdata.mipLevels = 1; + mdata.format = image.format; + mdata.dimension = TEX_DIMENSION_TEXTURE2D; + + return SaveToDDSMemory( &image, 1, mdata, flags, blob ); +} + +_Use_decl_annotations_ +inline HRESULT __cdecl SaveToDDSFile(const Image& image, DWORD flags, LPCWSTR szFile) +{ + TexMetadata mdata; + memset( &mdata, 0, sizeof(mdata) ); + mdata.width = image.width; + mdata.height = image.height; + mdata.depth = 1; + mdata.arraySize = 1; + mdata.mipLevels = 1; + mdata.format = image.format; + mdata.dimension = TEX_DIMENSION_TEXTURE2D; + + return SaveToDDSFile( &image, 1, mdata, flags, szFile ); +} diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/DirectXTexP.h b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/DirectXTexP.h new file mode 100644 index 0000000..269c11d --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/DirectXTexP.h @@ -0,0 +1,230 @@ +//------------------------------------------------------------------------------------- +// DirectXTexp.h +// +// DirectX Texture Library - Private header +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +// PARTICULAR PURPOSE. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// http://go.microsoft.com/fwlink/?LinkId=248926 +//------------------------------------------------------------------------------------- + +#pragma once + +#pragma warning(push) +#pragma warning(disable : 4005) +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#define NODRAWTEXT +#define NOGDI +#define NOBITMAP +#define NOMCX +#define NOSERVICE +#define NOHELP +#pragma warning(pop) + +#ifndef _WIN32_WINNT_WIN10 +#define _WIN32_WINNT_WIN10 0x0A00 +#endif + +#include <windows.h> +#include <directxmath.h> +#include <directxpackedvector.h> +#include <assert.h> + +#include <malloc.h> +#include <memory> + +#include <vector> + +#include <stdlib.h> +#include <search.h> + +#include <ole2.h> + +#include "directxtex.h" + +#include <wincodec.h> + +#include <wrl\client.h> + +#include "scoped.h" + +#define TEX_FILTER_MASK 0xF00000 + +#define XBOX_DXGI_FORMAT_R10G10B10_7E3_A2_FLOAT DXGI_FORMAT(116) +#define XBOX_DXGI_FORMAT_R10G10B10_6E4_A2_FLOAT DXGI_FORMAT(117) +#define XBOX_DXGI_FORMAT_D16_UNORM_S8_UINT DXGI_FORMAT(118) +#define XBOX_DXGI_FORMAT_R16_UNORM_X8_TYPELESS DXGI_FORMAT(119) +#define XBOX_DXGI_FORMAT_X16_TYPELESS_G8_UINT DXGI_FORMAT(120) + +#define WIN10_DXGI_FORMAT_P208 DXGI_FORMAT(130) +#define WIN10_DXGI_FORMAT_V208 DXGI_FORMAT(131) +#define WIN10_DXGI_FORMAT_V408 DXGI_FORMAT(132) + +#ifndef XBOX_DXGI_FORMAT_R10G10B10_SNORM_A2_UNORM +#define XBOX_DXGI_FORMAT_R10G10B10_SNORM_A2_UNORM DXGI_FORMAT(189) +#endif + +#define XBOX_DXGI_FORMAT_R4G4_UNORM DXGI_FORMAT(190) + + +namespace DirectX +{ + //--------------------------------------------------------------------------------- + // WIC helper functions + DXGI_FORMAT __cdecl _WICToDXGI( _In_ const GUID& guid ); + bool __cdecl _DXGIToWIC( _In_ DXGI_FORMAT format, _Out_ GUID& guid, _In_ bool ignoreRGBvsBGR = false ); + + DWORD __cdecl _CheckWICColorSpace( _In_ const GUID& sourceGUID, _In_ const GUID& targetGUID ); + + inline WICBitmapDitherType __cdecl _GetWICDither( _In_ DWORD flags ) + { + static_assert( TEX_FILTER_DITHER == 0x10000, "TEX_FILTER_DITHER* flag values don't match mask" ); + + static_assert( TEX_FILTER_DITHER == WIC_FLAGS_DITHER, "TEX_FILTER_DITHER* should match WIC_FLAGS_DITHER*" ); + static_assert( TEX_FILTER_DITHER_DIFFUSION == WIC_FLAGS_DITHER_DIFFUSION, "TEX_FILTER_DITHER* should match WIC_FLAGS_DITHER*" ); + + switch( flags & 0xF0000 ) + { + case TEX_FILTER_DITHER: + return WICBitmapDitherTypeOrdered4x4; + + case TEX_FILTER_DITHER_DIFFUSION: + return WICBitmapDitherTypeErrorDiffusion; + + default: + return WICBitmapDitherTypeNone; + } + } + + inline WICBitmapInterpolationMode __cdecl _GetWICInterp( _In_ DWORD flags ) + { + static_assert( TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MASK" ); + + static_assert( TEX_FILTER_POINT == WIC_FLAGS_FILTER_POINT, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" ); + static_assert( TEX_FILTER_LINEAR == WIC_FLAGS_FILTER_LINEAR, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" ); + static_assert( TEX_FILTER_CUBIC == WIC_FLAGS_FILTER_CUBIC, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" ); + static_assert( TEX_FILTER_FANT == WIC_FLAGS_FILTER_FANT, "TEX_FILTER_* flags should match WIC_FLAGS_FILTER_*" ); + + switch( flags & TEX_FILTER_MASK ) + { + case TEX_FILTER_POINT: + return WICBitmapInterpolationModeNearestNeighbor; + + case TEX_FILTER_LINEAR: + return WICBitmapInterpolationModeLinear; + + case TEX_FILTER_CUBIC: + return WICBitmapInterpolationModeCubic; + + case TEX_FILTER_FANT: + default: + return WICBitmapInterpolationModeFant; + } + } + + //--------------------------------------------------------------------------------- + // Image helper functions + void __cdecl _DetermineImageArray( _In_ const TexMetadata& metadata, _In_ DWORD cpFlags, + _Out_ size_t& nImages, _Out_ size_t& pixelSize ); + + _Success_(return != false) + bool __cdecl _SetupImageArray( _In_reads_bytes_(pixelSize) uint8_t *pMemory, _In_ size_t pixelSize, + _In_ const TexMetadata& metadata, _In_ DWORD cpFlags, + _Out_writes_(nImages) Image* images, _In_ size_t nImages ); + + //--------------------------------------------------------------------------------- + // Conversion helper functions + + enum TEXP_SCANLINE_FLAGS + { + TEXP_SCANLINE_NONE = 0, + TEXP_SCANLINE_SETALPHA = 0x1, // Set alpha channel to known opaque value + TEXP_SCANLINE_LEGACY = 0x2, // Enables specific legacy format conversion cases + }; + + enum CONVERT_FLAGS + { + CONVF_FLOAT = 0x1, + CONVF_UNORM = 0x2, + CONVF_UINT = 0x4, + CONVF_SNORM = 0x8, + CONVF_SINT = 0x10, + CONVF_DEPTH = 0x20, + CONVF_STENCIL = 0x40, + CONVF_SHAREDEXP = 0x80, + CONVF_BGR = 0x100, + CONVF_XR = 0x200, + CONVF_PACKED = 0x400, + CONVF_BC = 0x800, + CONVF_YUV = 0x1000, + CONVF_R = 0x10000, + CONVF_G = 0x20000, + CONVF_B = 0x40000, + CONVF_A = 0x80000, + CONVF_RGB_MASK = 0x70000, + CONVF_RGBA_MASK = 0xF0000, + }; + + DWORD __cdecl _GetConvertFlags( _In_ DXGI_FORMAT format ); + + void __cdecl _CopyScanline( _When_(pDestination == pSource, _Inout_updates_bytes_(outSize)) + _When_(pDestination != pSource, _Out_writes_bytes_(outSize)) + LPVOID pDestination, _In_ size_t outSize, + _In_reads_bytes_(inSize) LPCVOID pSource, _In_ size_t inSize, + _In_ DXGI_FORMAT format, _In_ DWORD flags ); + + void __cdecl _SwizzleScanline( _When_(pDestination == pSource, _In_) + _When_(pDestination != pSource, _Out_writes_bytes_(outSize)) + LPVOID pDestination, _In_ size_t outSize, + _In_reads_bytes_(inSize) LPCVOID pSource, _In_ size_t inSize, + _In_ DXGI_FORMAT format, _In_ DWORD flags ); + + _Success_(return != false) + bool __cdecl _ExpandScanline( _Out_writes_bytes_(outSize) LPVOID pDestination, _In_ size_t outSize, + _In_ DXGI_FORMAT outFormat, + _In_reads_bytes_(inSize) LPCVOID pSource, _In_ size_t inSize, + _In_ DXGI_FORMAT inFormat, _In_ DWORD flags ); + + _Success_(return != false) + bool __cdecl _LoadScanline( _Out_writes_(count) XMVECTOR* pDestination, _In_ size_t count, + _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DXGI_FORMAT format ); + + _Success_(return != false) + bool __cdecl _LoadScanlineLinear( _Out_writes_(count) XMVECTOR* pDestination, _In_ size_t count, + _In_reads_bytes_(size) LPCVOID pSource, _In_ size_t size, _In_ DXGI_FORMAT format, _In_ DWORD flags ); + + _Success_(return != false) + bool __cdecl _StoreScanline( LPVOID pDestination, _In_ size_t size, _In_ DXGI_FORMAT format, + _In_reads_(count) const XMVECTOR* pSource, _In_ size_t count, _In_ float threshold = 0 ); + + _Success_(return != false) + bool __cdecl _StoreScanlineLinear( LPVOID pDestination, _In_ size_t size, _In_ DXGI_FORMAT format, + _Inout_updates_all_(count) XMVECTOR* pSource, _In_ size_t count, _In_ DWORD flags, _In_ float threshold = 0 ); + + _Success_(return != false) + bool __cdecl _StoreScanlineDither( LPVOID pDestination, _In_ size_t size, _In_ DXGI_FORMAT format, + _Inout_updates_all_(count) XMVECTOR* pSource, _In_ size_t count, _In_ float threshold, size_t y, size_t z, + _Inout_updates_all_opt_(count+2) XMVECTOR* pDiffusionErrors ); + + HRESULT __cdecl _ConvertToR32G32B32A32( _In_ const Image& srcImage, _Inout_ ScratchImage& image ); + + HRESULT __cdecl _ConvertFromR32G32B32A32( _In_ const Image& srcImage, _In_ const Image& destImage ); + HRESULT __cdecl _ConvertFromR32G32B32A32( _In_ const Image& srcImage, _In_ DXGI_FORMAT format, _Inout_ ScratchImage& image ); + HRESULT __cdecl _ConvertFromR32G32B32A32( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ DXGI_FORMAT format, _Out_ ScratchImage& result ); + + void __cdecl _ConvertScanline( _Inout_updates_all_(count) XMVECTOR* pBuffer, _In_ size_t count, + _In_ DXGI_FORMAT outFormat, _In_ DXGI_FORMAT inFormat, _In_ DWORD flags ); + + //--------------------------------------------------------------------------------- + // DDS helper functions + HRESULT __cdecl _EncodeDDSHeader( _In_ const TexMetadata& metadata, DWORD flags, + _Out_writes_bytes_to_opt_(maxsize, required) LPVOID pDestination, _In_ size_t maxsize, _Out_ size_t& required ); + +}; // namespace diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/Filters.h b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/Filters.h new file mode 100644 index 0000000..c65eb77 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/Filters.h @@ -0,0 +1,422 @@ +//------------------------------------------------------------------------------------- +// filters.h +// +// Utility header with helpers for implementing image filters +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +// PARTICULAR PURPOSE. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------------------------------- + +#pragma once + +#include <directxmath.h> +#include <directxpackedvector.h> + +#include <memory> + +#include "scoped.h" + +namespace DirectX +{ + +//------------------------------------------------------------------------------------- +// Box filtering helpers +//------------------------------------------------------------------------------------- + +XMGLOBALCONST XMVECTORF32 g_boxScale = { 0.25f, 0.25f, 0.25f, 0.25f }; +XMGLOBALCONST XMVECTORF32 g_boxScale3D = { 0.125f, 0.125f, 0.125f, 0.125f }; + +#define AVERAGE4( res, p0, p1, p2, p3 ) \ +{ \ + XMVECTOR v = XMVectorAdd( (p0), (p1) ); \ + v = XMVectorAdd( v, (p2) ); \ + v = XMVectorAdd( v, (p3) ); \ + res = XMVectorMultiply( v, g_boxScale ); \ +} + +#define AVERAGE8( res, p0, p1, p2, p3, p4, p5, p6, p7) \ +{ \ + XMVECTOR v = XMVectorAdd( (p0), (p1) ); \ + v = XMVectorAdd( v, (p2) ); \ + v = XMVectorAdd( v, (p3) ); \ + v = XMVectorAdd( v, (p4) ); \ + v = XMVectorAdd( v, (p5) ); \ + v = XMVectorAdd( v, (p6) ); \ + v = XMVectorAdd( v, (p7) ); \ + res = XMVectorMultiply( v, g_boxScale3D ); \ +} + + +//------------------------------------------------------------------------------------- +// Linear filtering helpers +//------------------------------------------------------------------------------------- + +struct LinearFilter +{ + size_t u0; + float weight0; + size_t u1; + float weight1; +}; + +inline void _CreateLinearFilter( _In_ size_t source, _In_ size_t dest, _In_ bool wrap, _Out_writes_(dest) LinearFilter* lf ) +{ + assert( source > 0 ); + assert( dest > 0 ); + assert( lf != 0 ); + + float scale = float(source) / float(dest); + + // Mirror is the same case as clamp for linear + + for( size_t u = 0; u < dest; ++u ) + { + float srcB = ( float(u) + 0.5f ) * scale + 0.5f; + + ptrdiff_t isrcB = ptrdiff_t(srcB); + ptrdiff_t isrcA = isrcB - 1; + + if ( isrcA < 0 ) + { + isrcA = ( wrap ) ? ( source - 1) : 0; + } + + if ( size_t(isrcB) >= source ) + { + isrcB = ( wrap ) ? 0 : ( source - 1); + } + + float weight = 1.0f + float(isrcB) - srcB; + + auto& entry = lf[ u ]; + entry.u0 = size_t(isrcA); + entry.weight0 = weight; + + entry.u1 = size_t(isrcB); + entry.weight1 = 1.0f - weight; + } +} + +#define BILINEAR_INTERPOLATE( res, x, y, r0, r1 ) \ + res = ( y.weight0 * ( (r0)[ x.u0 ] * x.weight0 + (r0)[ x.u1 ] * x.weight1 ) ) \ + + ( y.weight1 * ( (r1)[ x.u0 ] * x.weight0 + (r1)[ x.u1 ] * x.weight1 ) ) + +#define TRILINEAR_INTERPOLATE( res, x, y, z, r0, r1, r2, r3 ) \ + res = ( z.weight0 * ( ( y.weight0 * ( (r0)[ x.u0 ] * x.weight0 + (r0)[ x.u1 ] * x.weight1 ) ) \ + + ( y.weight1 * ( (r1)[ x.u0 ] * x.weight0 + (r1)[ x.u1 ] * x.weight1 ) ) ) ) \ + + ( z.weight1 * ( ( y.weight0 * ( (r2)[ x.u0 ] * x.weight0 + (r2)[ x.u1 ] * x.weight1 ) ) \ + + ( y.weight1 * ( (r3)[ x.u0 ] * x.weight0 + (r3)[ x.u1 ] * x.weight1 ) ) ) ) + + +//------------------------------------------------------------------------------------- +// Cubic filtering helpers +//------------------------------------------------------------------------------------- + +XMGLOBALCONST XMVECTORF32 g_cubicThird = { 1.f/3.f, 1.f/3.f, 1.f/3.f, 1.f/3.f }; +XMGLOBALCONST XMVECTORF32 g_cubicSixth = { 1.f/6.f, 1.f/6.f, 1.f/6.f, 1.f/6.f }; +XMGLOBALCONST XMVECTORF32 g_cubicHalf = { 1.f/2.f, 1.f/2.f, 1.f/2.f, 1.f/2.f }; + +inline ptrdiff_t bounduvw( ptrdiff_t u, ptrdiff_t maxu, bool wrap, bool mirror ) +{ + if ( wrap ) + { + if ( u < 0 ) + { + u = maxu + u + 1; + } + else if ( u > maxu ) + { + u = u - maxu - 1; + } + } + else if ( mirror ) + { + if ( u < 0 ) + { + u = ( -u ) - 1; + } + else if ( u > maxu ) + { + u = maxu - (u - maxu - 1); + } + } + + // Handles clamp, but also a safety factor for degenerate images for wrap/mirror + u = std::min<ptrdiff_t>( u, maxu ); + u = std::max<ptrdiff_t>( u, 0 ); + + return u; +} + +struct CubicFilter +{ + size_t u0; + size_t u1; + size_t u2; + size_t u3; + float x; +}; + +inline void _CreateCubicFilter( _In_ size_t source, _In_ size_t dest, _In_ bool wrap, _In_ bool mirror, _Out_writes_(dest) CubicFilter* cf ) +{ + assert( source > 0 ); + assert( dest > 0 ); + assert( cf != 0 ); + + float scale = float(source) / float(dest); + + for( size_t u = 0; u < dest; ++u ) + { + float srcB = ( float(u) + 0.5f ) * scale - 0.5f; + + ptrdiff_t isrcB = bounduvw( ptrdiff_t(srcB), source - 1, wrap, mirror ); + ptrdiff_t isrcA = bounduvw( isrcB - 1, source - 1, wrap, mirror ); + ptrdiff_t isrcC = bounduvw( isrcB + 1, source - 1, wrap, mirror ); + ptrdiff_t isrcD = bounduvw( isrcB + 2, source - 1, wrap, mirror ); + + auto& entry = cf[ u ]; + entry.u0 = size_t(isrcA); + entry.u1 = size_t(isrcB); + entry.u2 = size_t(isrcC); + entry.u3 = size_t(isrcD); + + float x = srcB - float(isrcB); + entry.x = x; + } +} + +#define CUBIC_INTERPOLATE( res, dx, p0, p1, p2, p3 ) \ +{ \ + XMVECTOR a0 = (p1); \ + XMVECTOR d0 = (p0) - a0; \ + XMVECTOR d2 = (p2) - a0; \ + XMVECTOR d3 = (p3) - a0; \ + XMVECTOR a1 = d2 - g_cubicThird*d0 - g_cubicSixth*d3; \ + XMVECTOR a2 = g_cubicHalf*d0 + g_cubicHalf*d2; \ + XMVECTOR a3 = g_cubicSixth*d3 - g_cubicSixth*d0 - g_cubicHalf*d2; \ + XMVECTOR vdx = XMVectorReplicate( dx ); \ + XMVECTOR vdx2 = vdx * vdx; \ + XMVECTOR vdx3 = vdx2 * vdx; \ + res = a0 + a1*vdx + a2*vdx2 + a3*vdx3; \ +} + + +//------------------------------------------------------------------------------------- +// Triangle filtering helpers +//------------------------------------------------------------------------------------- + +namespace TriangleFilter +{ + struct FilterTo + { + size_t u; + float weight; + }; + + struct FilterFrom + { + size_t count; + size_t sizeInBytes; + FilterTo to[1]; // variable-sized array + }; + + struct Filter + { + size_t sizeInBytes; + size_t totalSize; + FilterFrom from[1]; // variable-sized array + }; + + struct TriangleRow + { + size_t remaining; + TriangleRow* next; + ScopedAlignedArrayXMVECTOR scanline; + + TriangleRow() : 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); + + static const 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 ) + { + assert( source > 0 ); + assert( dest > 0 ); + + float scale = float(dest) / float(source); + float scaleInv = 0.5f / scale; + + // Determine storage required for filter and allocate memory if needed + size_t totalSize = TF_FILTER_SIZE + TF_FROM_SIZE + TF_TO_SIZE; + float repeat = (wrap) ? 1.f : 0.f; + + for( size_t u = 0; u < source; ++u ) + { + float src = float(u) - 0.5f; + float destMin = src * scale; + float destMax = destMin + scale; + + totalSize += TF_FROM_SIZE + TF_TO_SIZE + size_t( destMax - destMin + repeat + 1.f ) * TF_TO_SIZE * 2; + } + + uint8_t* pFilter = nullptr; + + if ( tf ) + { + // See if existing filter memory block is large enough to reuse + if ( tf->totalSize >= totalSize ) + { + pFilter = reinterpret_cast<uint8_t*>( tf.get() ); + } + else + { + // Need to reallocate filter memory block + tf.reset( nullptr ); + } + } + + if ( !tf ) + { + // Allocate filter memory block + pFilter = new (std::nothrow) uint8_t[ totalSize ]; + if ( !pFilter ) + return E_OUTOFMEMORY; + + tf.reset( reinterpret_cast<Filter*>( pFilter ) ); + tf->totalSize = totalSize; + } + + assert( pFilter != 0 ); + + // Filter setup + size_t sizeInBytes = TF_FILTER_SIZE; + size_t accumU = 0; + float accumWeight = 0.f; + + for( size_t u = 0; u < source; ++u ) + { + // Setup from entry + size_t sizeFrom = sizeInBytes; + auto pFrom = reinterpret_cast<FilterFrom*>( pFilter + sizeInBytes ); + sizeInBytes += TF_FROM_SIZE; + + if ( sizeInBytes > totalSize ) + return E_FAIL; + + size_t toCount = 0; + + // Perform two passes to capture the influences from both sides + for( size_t j = 0; j < 2; ++j ) + { + float src = float( u + j ) - 0.5f; + + float destMin = src * scale; + float destMax = destMin + scale; + + if ( !wrap ) + { + // Clamp + if ( destMin < 0.f ) + destMin = 0.f; + if ( destMax > float(dest) ) + destMax = float(dest); + } + + for( auto k = static_cast<ptrdiff_t>( floorf( destMin ) ); float(k) < destMax; ++k ) + { + float d0 = float(k); + float d1 = d0 + 1.f; + + size_t u0; + if ( k < 0 ) + { + // Handle wrap + u0 = size_t( k + ptrdiff_t(dest) ); + } + else if ( k >= ptrdiff_t(dest) ) + { + // Handle wrap + u0 = size_t( k - ptrdiff_t(dest) ); + } + else + { + u0 = size_t( k ); + } + + // Save previous accumulated weight (if any) + if ( u0 != accumU ) + { + if ( accumWeight > TF_EPSILON ) + { + auto pTo = reinterpret_cast<FilterTo*>( pFilter + sizeInBytes ); + sizeInBytes += TF_TO_SIZE; + ++toCount; + + if ( sizeInBytes > totalSize ) + return E_FAIL; + + pTo->u = accumU; + pTo->weight = accumWeight; + } + + accumWeight = 0.f; + accumU = u0; + } + + // Clip destination + if ( d0 < destMin ) + d0 = destMin; + if ( d1 > destMax ) + d1 = destMax; + + // Calculate average weight over destination pixel + + float weight; + if ( !wrap && src < 0.f ) + weight = 1.f; + else if ( !wrap && ( ( src + 1.f ) >= float(source) ) ) + weight = 0.f; + else + weight = (d0 + d1) * scaleInv - src; + + accumWeight += (d1 - d0) * ( j ? (1.f - weight) : weight ); + } + } + + // Store accumulated weight + if ( accumWeight > TF_EPSILON ) + { + auto pTo = reinterpret_cast<FilterTo*>( pFilter + sizeInBytes ); + sizeInBytes += TF_TO_SIZE; + ++toCount; + + if ( sizeInBytes > totalSize ) + return E_FAIL; + + pTo->u = accumU; + pTo->weight = accumWeight; + } + + accumWeight = 0.f; + + // Finalize from entry + pFrom->count = toCount; + pFrom->sizeInBytes = sizeInBytes - sizeFrom; + } + + tf->sizeInBytes = sizeInBytes; + + return S_OK; + } + +}; // namespace + +}; // namespace
\ No newline at end of file diff --git a/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/scoped.h b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/scoped.h new file mode 100644 index 0000000..d6329b1 --- /dev/null +++ b/NvCloth/samples/external/DirectXTex/10.5.2016.2/include/scoped.h @@ -0,0 +1,32 @@ +//------------------------------------------------------------------------------------- +// scoped.h +// +// Utility header with helper classes for exception-safe handling of resources +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +// PARTICULAR PURPOSE. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------------------------------- + +#pragma once + +#include <assert.h> +#include <memory> +#include <malloc.h> + +//--------------------------------------------------------------------------------- +struct aligned_deleter { void operator()(void* p) { _aligned_free(p); } }; + +typedef std::unique_ptr<float[], aligned_deleter> ScopedAlignedArrayFloat; + +typedef std::unique_ptr<DirectX::XMVECTOR[], aligned_deleter> ScopedAlignedArrayXMVECTOR; + +//--------------------------------------------------------------------------------- +struct handle_closer { void operator()(HANDLE h) { assert(h != INVALID_HANDLE_VALUE); if (h) CloseHandle(h); } }; + +typedef public std::unique_ptr<void, handle_closer> ScopedHandle; + +inline HANDLE safe_handle( HANDLE h ) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; } |