Updated samples for 2410 release (#46)

* 2410 release update

* Pull Request 3948: Updating PlayFabStore sample to use new property name for 2410 GDK
This commit is contained in:
jonmartinms 2024-11-12 10:03:14 -08:00 коммит произвёл GitHub
Родитель 3e11735ae0
Коммит 3acf5ffbe5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
872 изменённых файлов: 82100 добавлений и 19729 удалений

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

@ -85,7 +85,7 @@ namespace DX
// Handle text encoding
if (encoding == Encoding::UTF16)
{
m_data.reset(reinterpret_cast<wchar_t*>(data.release()));
m_data.reset(reinterpret_cast<wchar_t*>(data.release())); // [CodeQL.SM02986]: The cast here is intentional to handle UTF16 vs. UTF8 encoding.
m_end = reinterpret_cast<wchar_t*>(&data[out]);
}
else

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

@ -7,7 +7,7 @@
#pragma once
#pragma warning(push)
#pragma warning(disable : 4062 4316 4324) // We don't care that ShaderRecord (or derived types) are potentially unaligned or padded. They won't be in the Upload Heap
#pragma warning(disable : 4061 4062 4316 4324) // We don't care that ShaderRecord (or derived types) are potentially unaligned or padded. They won't be in the Upload Heap
#include <iomanip>
#include <sstream>
@ -256,9 +256,8 @@ inline void PrintStateObjectDesc(const D3D12_STATE_OBJECT_DESC* pDesc)
wstr << L"| [2]: Intersection Import: " << (hitGroup->IntersectionShaderImport ? hitGroup->IntersectionShaderImport : L"[none]") << L"\n";
break;
}
case D3D12_STATE_SUBOBJECT_TYPE_STATE_OBJECT_CONFIG:
case D3D12_STATE_SUBOBJECT_TYPE_RAYTRACING_PIPELINE_CONFIG1:
case D3D12_STATE_SUBOBJECT_TYPE_MAX_VALID:
default:
break;
}
wstr << L"|--------------------------------------------------------------------\n";

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

@ -104,6 +104,7 @@ void MSAAHelper::SetDevice(_In_ ID3D12Device* device)
}
}
if (m_depthBufferFormat != DXGI_FORMAT_UNKNOWN)
{
D3D12_FEATURE_DATA_FORMAT_SUPPORT formatSupport = { m_depthBufferFormat, D3D12_FORMAT_SUPPORT1_NONE, D3D12_FORMAT_SUPPORT2_NONE };
if (FAILED(device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &formatSupport, sizeof(formatSupport))))
@ -346,6 +347,7 @@ void MSAAHelper::Resolve(_In_ ID3D12GraphicsCommandList* commandList,
}
}
void MSAAHelper::ResolveDepth(_In_ ID3D12GraphicsCommandList* commandList,
_In_ ID3D12Resource* depthBuffer,
D3D12_RESOURCE_STATES beforeState,
@ -375,6 +377,32 @@ void MSAAHelper::ResolveDepth(_In_ ID3D12GraphicsCommandList* commandList,
}
void MSAAHelper::Transition(_In_ ID3D12GraphicsCommandList* commandList, D3D12_RESOURCE_STATES beforeState, D3D12_RESOURCE_STATES afterState)
{
if (beforeState != afterState)
{
const D3D12_RESOURCE_BARRIER barrier = CD3DX12_RESOURCE_BARRIER::Transition(
m_msaaRenderTarget.Get(),
beforeState,
afterState);
commandList->ResourceBarrier(1, &barrier);
}
}
void MSAAHelper::TransitionDepth(_In_ ID3D12GraphicsCommandList* commandList, D3D12_RESOURCE_STATES beforeState, D3D12_RESOURCE_STATES afterState)
{
if (beforeState != afterState)
{
const D3D12_RESOURCE_BARRIER barrier = CD3DX12_RESOURCE_BARRIER::Transition(
m_msaaDepthStencil.Get(),
beforeState,
afterState);
commandList->ResourceBarrier(1, &barrier);
}
}
#else
//======================================================================================
// Direct3D 11
@ -431,6 +459,7 @@ void MSAAHelper::SetDevice(_In_ ID3D11Device* device)
}
}
if (m_depthBufferFormat != DXGI_FORMAT_UNKNOWN)
{
UINT formatSupport = 0;
if (FAILED(device->CheckFormatSupport(m_depthBufferFormat, &formatSupport)))

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

@ -47,6 +47,10 @@ namespace DX
D3D12_RESOURCE_STATES beforeState = D3D12_RESOURCE_STATE_DEPTH_WRITE,
D3D12_RESOURCE_STATES afterState = D3D12_RESOURCE_STATE_DEPTH_WRITE);
void Transition(_In_ ID3D12GraphicsCommandList* commandList, D3D12_RESOURCE_STATES beforeState, D3D12_RESOURCE_STATES afterState);
void TransitionDepth(_In_ ID3D12GraphicsCommandList* commandList, D3D12_RESOURCE_STATES beforeState, D3D12_RESOURCE_STATES afterState);
ID3D12Resource* GetMSAARenderTarget() const noexcept { return m_msaaRenderTarget.Get(); }
ID3D12Resource* GetMSAADepthStencil() const noexcept { return m_msaaDepthStencil.Get(); }

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

@ -55,7 +55,14 @@ namespace DX
#endif
if (!inFile)
{
#ifdef _DEBUG
wchar_t errorMessage[MAX_PATH] = {};
swprintf_s(errorMessage, MAX_PATH, L"ReadData: file not open %ls\n", name);
OutputDebugStringW(errorMessage);
#endif
throw std::runtime_error("ReadData");
}
const std::streampos len = inFile.tellg();
if (!inFile)

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

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2013-2019 Niels Lohmann
Copyright (c) 2013-2022 Niels Lohmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.

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

@ -1 +1 @@
e6e6805c6c80d6ec82ba719afd435fd2280535da
9cca280a4d0ccf0c08f47a99aa71d1b0e52f8d03

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -869,6 +869,33 @@ namespace
return true;
}
inline bool IsValid(const X3DAUDIO_DISTANCE_CURVE& curve) noexcept
{
// These match the validation ranges in X3DAudio.
if (!curve.pPoints)
return false;
if (curve.PointCount < 2)
return false;
if (curve.pPoints[0].Distance != 0.f)
return false;
if (curve.pPoints[curve.PointCount - 1].Distance != 1.f)
return false;
for (uint32_t j = 0; j < curve.PointCount; ++j)
{
if (curve.pPoints[j].Distance < 0.f || curve.pPoints[j].Distance > 1.f)
return false;
if (!std::isfinite(curve.pPoints[j].DSPSetting))
return false;
}
return true;
}
}
void AudioListener::SetCone(const X3DAUDIO_CONE& listenerCone)
@ -880,6 +907,44 @@ void AudioListener::SetCone(const X3DAUDIO_CONE& listenerCone)
pCone = &ListenerCone;
}
bool AudioListener::IsValid() const
{
if (!std::isfinite(OrientFront.x))
return false;
if (!std::isfinite(OrientFront.y))
return false;
if (!std::isfinite(OrientFront.z))
return false;
if (!std::isfinite(OrientTop.x))
return false;
if (!std::isfinite(OrientTop.y))
return false;
if (!std::isfinite(OrientTop.z))
return false;
if (!std::isfinite(Position.x))
return false;
if (!std::isfinite(Position.y))
return false;
if (!std::isfinite(Position.z))
if (!std::isfinite(Velocity.x))
return false;
if (!std::isfinite(Velocity.y))
return false;
if (!std::isfinite(Velocity.z))
return false;
if (pCone)
{
if (!::IsValid(*pCone))
return false;
}
return true;
}
void AudioEmitter::SetCone(const X3DAUDIO_CONE& emitterCone)
{
if (!::IsValid(emitterCone))
@ -889,6 +954,101 @@ void AudioEmitter::SetCone(const X3DAUDIO_CONE& emitterCone)
pCone = &EmitterCone;
}
bool AudioEmitter::IsValid() const
{
if (!std::isfinite(OrientFront.x))
return false;
if (!std::isfinite(OrientFront.y))
return false;
if (!std::isfinite(OrientFront.z))
return false;
if (!std::isfinite(OrientTop.x))
return false;
if (!std::isfinite(OrientTop.y))
return false;
if (!std::isfinite(OrientTop.z))
return false;
if (!std::isfinite(Position.x))
return false;
if (!std::isfinite(Position.y))
return false;
if (!std::isfinite(Position.z))
if (!std::isfinite(Velocity.x))
return false;
if (!std::isfinite(Velocity.y))
return false;
if (!std::isfinite(Velocity.z))
return false;
if (pCone)
{
if (!::IsValid(*pCone))
return false;
}
if (!std::isfinite(InnerRadius))
return false;
if (!std::isfinite(InnerRadiusAngle))
return false;
if (ChannelCount == 0 || ChannelCount > XAUDIO2_MAX_AUDIO_CHANNELS)
return false;
if (ChannelCount > 1)
{
if (!pChannelAzimuths)
return false;
for (uint32_t j = 0; j < ChannelCount; ++j)
{
if (pChannelAzimuths[j] < 0.f || pChannelAzimuths[j] > X3DAUDIO_2PI)
return false;
}
}
if (!std::isfinite(ChannelRadius))
return false;
if (!std::isfinite(CurveDistanceScaler))
return false;
if (!std::isfinite(DopplerScaler))
return false;
if (pVolumeCurve)
{
if (!::IsValid(*pVolumeCurve))
return false;
}
if (pLFECurve)
{
if (!::IsValid(*pLFECurve))
return false;
}
if (pLPFDirectCurve)
{
if (!::IsValid(*pLPFDirectCurve))
return false;
}
if (pLPFReverbCurve)
{
if (!::IsValid(*pLPFReverbCurve))
return false;
}
if (pReverbCurve)
{
if (!::IsValid(*pReverbCurve))
return false;
}
return true;
}
namespace
{
// **Note these constants came from xact3d3.h in the legacy DirectX SDK**

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

@ -537,6 +537,7 @@
<ClInclude Include="Src\AlignedNew.h" />
<ClInclude Include="Src\Bezier.h" />
<ClInclude Include="Src\BinaryReader.h" />
<ClInclude Include="Src\CMO.h" />
<ClInclude Include="Src\d3dx12.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Gaming.Xbox.XboxOne.x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Gaming.Xbox.Scarlett.x64'">true</ExcludedFromBuild>
@ -691,10 +692,13 @@
<_ATGFXCPath>$(WindowsSDK_ExecutablePath_x64.Split(';')[0])</_ATGFXCPath>
<_ATGFXCPath>$(_ATGFXCPath.Replace("x64",""))</_ATGFXCPath>
<_ATGFXCPath Condition="'$(_ATGFXCPath)' != '' and !HasTrailingSlash('$(_ATGFXCPath)')">$(_ATGFXCPath)\</_ATGFXCPath>
<_ATGFXCVer>$([System.Text.RegularExpressions.Regex]::Match($(_ATGFXCPath), `10\.0\.\d+\.0`))</_ATGFXCVer>
<_ATGFXCVer Condition="'$(_ATGFXCVer)' != '' and !HasTrailingSlash('$(_ATGFXCVer)')">$(_ATGFXCVer)\</_ATGFXCVer>
</PropertyGroup>
<Exec Condition="!Exists('Src/Shaders/Compiled/SpriteEffect_SpriteVertexShader.inc')" WorkingDirectory="$(ProjectDir)Src/Shaders" Command="CompileShaders dxil" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath);CompileShadersOutput=$(ProjectDir)Src/Shaders/Compiled" LogStandardErrorAsError="true" />
<Exec Condition="!Exists('Src/Shaders/Compiled/SpriteEffect_SpriteVertexShader.inc')" WorkingDirectory="$(ProjectDir)Src/Shaders" Command="CompileShaders dxil" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath);WindowsSDKVersion=$(_ATGFXCVer);CompileShadersOutput=$(ProjectDir)Src/Shaders/Compiled" LogStandardErrorAsError="true" />
<PropertyGroup>
<_ATGFXCPath />
<_ATGFXCVer />
</PropertyGroup>
</Target>
<Target Name="ATGDeleteShaders" AfterTargets="Clean" Condition="'$(Platform)'=='Gaming.Desktop.x64'">

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

@ -153,6 +153,9 @@
<ClInclude Include="Inc\BufferHelpers.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="Src\CMO.h">
<Filter>Src\Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Audio\AudioEngine.cpp">

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

@ -355,6 +355,7 @@
<ClInclude Include="Src\AlignedNew.h" />
<ClInclude Include="Src\Bezier.h" />
<ClInclude Include="Src\BinaryReader.h" />
<ClInclude Include="Src\CMO.h" />
<ClInclude Include="Src\DDS.h" />
<ClInclude Include="Src\DemandCreate.h" />
<ClInclude Include="Src\EffectCommon.h" />

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

@ -150,6 +150,9 @@
<ClInclude Include="Inc\BufferHelpers.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="Src\CMO.h">
<Filter>Src\Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Audio\AudioEngine.cpp">

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

@ -42,6 +42,7 @@
<ClInclude Include="Src\AlignedNew.h" />
<ClInclude Include="Src\Bezier.h" />
<ClInclude Include="Src\BinaryReader.h" />
<ClInclude Include="Src\CMO.h" />
<ClInclude Include="Src\d3dx12.h" />
<ClInclude Include="Src\DemandCreate.h" />
<ClInclude Include="Src\EffectCommon.h" />
@ -277,10 +278,13 @@
<_ATGFXCPath>$(WindowsSDK_ExecutablePath_x64.Split(';')[0])</_ATGFXCPath>
<_ATGFXCPath>$(_ATGFXCPath.Replace("x64",""))</_ATGFXCPath>
<_ATGFXCPath Condition="'$(_ATGFXCPath)' != '' and !HasTrailingSlash('$(_ATGFXCPath)')">$(_ATGFXCPath)\</_ATGFXCPath>
<_ATGFXCVer>$([System.Text.RegularExpressions.Regex]::Match($(_ATGFXCPath), `10\.0\.\d+\.0`))</_ATGFXCVer>
<_ATGFXCVer Condition="'$(_ATGFXCVer)' != '' and !HasTrailingSlash('$(_ATGFXCVer)')">$(_ATGFXCVer)\</_ATGFXCVer>
</PropertyGroup>
<Exec Condition="!Exists('Src/Shaders/Compiled/SpriteEffect_SpriteVertexShader.inc')" WorkingDirectory="$(ProjectDir)Src/Shaders" Command="CompileShaders dxil" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath);CompileShadersOutput=$(ProjectDir)Src/Shaders/Compiled" LogStandardErrorAsError="true" />
<Exec Condition="!Exists('Src/Shaders/Compiled/SpriteEffect_SpriteVertexShader.inc')" WorkingDirectory="$(ProjectDir)Src/Shaders" Command="CompileShaders dxil" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath);WindowsSDKVersion=$(_ATGFXCVer);CompileShadersOutput=$(ProjectDir)Src\Shaders\Compiled" LogStandardErrorAsError="true" />
<PropertyGroup>
<_ATGFXCPath />
<_ATGFXCVer />
</PropertyGroup>
</Target>
<Target Name="ATGDeleteShaders" AfterTargets="Clean">

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

@ -153,6 +153,9 @@
<ClInclude Include="Inc\BufferHelpers.h">
<Filter>Inc</Filter>
</ClInclude>
<ClInclude Include="Src\CMO.h">
<Filter>Src\Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\CommonStates.cpp">

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

@ -159,7 +159,7 @@ namespace DirectX
SoundEffectInstance_UseRedirectLFE = 0x10000,
};
enum AUDIO_ENGINE_REVERB : unsigned int
enum AUDIO_ENGINE_REVERB : uint32_t
{
Reverb_Off,
Reverb_Default,
@ -195,7 +195,7 @@ namespace DirectX
Reverb_MAX
};
enum SoundState
enum SoundState : uint32_t
{
STOPPED = 0,
PLAYING,
@ -547,6 +547,8 @@ namespace DirectX
}
void __cdecl SetCone(const X3DAUDIO_CONE& listenerCone);
bool __cdecl IsValid() const;
};
@ -666,6 +668,8 @@ namespace DirectX
pLPFReverbCurve = nullptr;
pReverbCurve = nullptr;
}
bool __cdecl IsValid() const;
};
@ -819,8 +823,8 @@ namespace DirectX
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
#endif
DEFINE_ENUM_FLAG_OPERATORS(AUDIO_ENGINE_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(SOUND_EFFECT_INSTANCE_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(AUDIO_ENGINE_FLAGS)
DEFINE_ENUM_FLAG_OPERATORS(SOUND_EFFECT_INSTANCE_FLAGS)
#ifdef __clang__
#pragma clang diagnostic pop

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

@ -20,6 +20,7 @@
#include <d3d12.h>
#endif
#include <cstdint>
#include <memory>
@ -76,7 +77,7 @@ namespace DirectX
D3D12_GPU_DESCRIPTOR_HANDLE AnisotropicClamp() const;
// These index into the heap returned by SamplerDescriptorHeap
enum class SamplerIndex
enum class SamplerIndex : uint32_t
{
PointWrap,
PointClamp,

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

@ -57,6 +57,7 @@ namespace DirectX
DDS_LOADER_IGNORE_SRGB = 0x2,
DDS_LOADER_MIP_AUTOGEN = 0x8,
DDS_LOADER_MIP_RESERVE = 0x10,
DDS_LOADER_IGNORE_MIPS = 0x20,
};
}
@ -159,7 +160,7 @@ namespace DirectX
inline namespace DX12
{
DEFINE_ENUM_FLAG_OPERATORS(DDS_LOADER_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(DDS_LOADER_FLAGS)
}
#ifdef __clang__

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

@ -338,7 +338,7 @@ namespace DirectX
class EnvironmentMapEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog
{
public:
enum Mapping
enum Mapping : uint32_t
{
Mapping_Cube = 0, // Cubic environment map
Mapping_Sphere, // Spherical environment map
@ -664,7 +664,7 @@ namespace DirectX
class DebugEffect : public IEffect, public IEffectMatrices
{
public:
enum Mode
enum Mode : uint32_t
{
Mode_Default = 0, // Hemispherical ambient lighting
Mode_Normals, // RGB normals

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

@ -87,7 +87,7 @@ namespace DirectX
static constexpr int c_MergedInput = -2;
#endif
enum DeadZone
enum DeadZone : uint32_t
{
DEAD_ZONE_INDEPENDENT_AXES = 0,
DEAD_ZONE_CIRCULAR,
@ -187,7 +187,7 @@ namespace DirectX
struct Capabilities
{
enum Type
enum Type : uint32_t
{
UNKNOWN = 0,
GAMEPAD,
@ -222,7 +222,7 @@ namespace DirectX
class ButtonStateTracker
{
public:
enum ButtonState
enum ButtonState : uint32_t
{
UP = 0, // Button is up
HELD = 1, // Button is held down

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

@ -21,6 +21,7 @@
#endif
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <memory>
@ -137,7 +138,7 @@ namespace DirectX
class GraphicsMemory
{
public:
enum Tag
enum Tag : uint32_t
{
TAG_GENERIC = 0,
TAG_CONSTANT,

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

@ -709,7 +709,7 @@ namespace DirectX
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
#endif
DEFINE_ENUM_FLAG_OPERATORS(ModelLoaderFlags);
DEFINE_ENUM_FLAG_OPERATORS(ModelLoaderFlags)
#ifdef __clang__
#pragma clang diagnostic pop

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

@ -28,6 +28,7 @@
#pragma comment(lib,"gameinput.lib")
#endif
#include <cstdint>
#include <memory>
#ifdef USING_COREWINDOW
@ -55,7 +56,7 @@ namespace DirectX
virtual ~Mouse();
enum Mode
enum Mode : uint32_t
{
MODE_ABSOLUTE = 0,
MODE_RELATIVE,
@ -77,7 +78,7 @@ namespace DirectX
class ButtonStateTracker
{
public:
enum ButtonState
enum ButtonState : uint32_t
{
UP = 0, // Button is up
HELD = 1, // Button is held down

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

@ -20,6 +20,7 @@
#include <d3d12.h>
#endif
#include <cstdint>
#include <memory>
#include <DirectXMath.h>
@ -55,7 +56,7 @@ namespace DirectX
class BasicPostProcess : public IPostProcess
{
public:
enum Effect : unsigned int
enum Effect : uint32_t
{
Copy,
Monochrome,
@ -106,7 +107,7 @@ namespace DirectX
class DualPostProcess : public IPostProcess
{
public:
enum Effect : unsigned int
enum Effect : uint32_t
{
Merge,
BloomCombine,
@ -150,7 +151,7 @@ namespace DirectX
{
public:
// Tone-mapping operator
enum Operator : unsigned int
enum Operator : uint32_t
{
None, // Pass-through
Saturate, // Clamp [0,1]
@ -160,7 +161,7 @@ namespace DirectX
};
// Electro-Optical Transfer Function (EOTF)
enum TransferFunction : unsigned int
enum TransferFunction : uint32_t
{
Linear, // Pass-through
SRGB, // sRGB (Rec.709 and approximate sRGB display curve)
@ -169,7 +170,7 @@ namespace DirectX
};
// Color Rotation Transform for HDR10
enum ColorPrimaryRotation : unsigned int
enum ColorPrimaryRotation : uint32_t
{
HDTV_to_UHDTV, // Rec.709 to Rec.2020
DCI_P3_D65_to_UHDTV, // DCI-P3-D65 (a.k.a Display P3 or P3D65) to Rec.2020

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

@ -63,6 +63,22 @@ namespace DirectX
rtvFormats[0] = rtFormat;
}
// MSAA single render target convenience constructor
RenderTargetState(
_In_ DXGI_FORMAT rtFormat,
_In_ DXGI_FORMAT dsFormat,
_In_ uint32_t sampleCount,
_In_ uint32_t quality = 0) noexcept
: sampleMask(UINT_MAX)
, numRenderTargets(1)
, rtvFormats{}
, dsvFormat(dsFormat)
, sampleDesc{ sampleCount, quality }
, nodeMask(0)
{
rtvFormats[0] = rtFormat;
}
// Convenience constructors converting from DXGI_SWAPCHAIN_DESC
#if defined(__dxgi_h__) || defined(__d3d11_x_h__) || defined(__d3d12_x_h__) || defined(__XBOX_D3D12_X__)
RenderTargetState(

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

@ -39,7 +39,7 @@ namespace DirectX
inline namespace DX12
{
enum SpriteSortMode
enum SpriteSortMode : uint32_t
{
SpriteSortMode_Deferred,
SpriteSortMode_Immediate,

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

@ -144,7 +144,7 @@ namespace DirectX
inline namespace DX12
{
DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS)
}
#ifdef __clang__

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

@ -6,7 +6,7 @@ http://go.microsoft.com/fwlink/?LinkID=615561
Copyright (c) Microsoft Corporation.
**June 4, 2024**
**October 28, 2024**
This package contains the "DirectX Tool Kit", a collection of helper classes for writing Direct3D 12 C++ code for Universal Windows Platform (UWP) apps for Windows 11 and Windows 10, game titles for Xbox Series X\|S and Xbox One, and Win32 desktop applications for Windows 11 and Windows 10.
@ -104,7 +104,9 @@ For a full change history, see [CHANGELOG.md](https://github.com/microsoft/Direc
* The UWP projects and the Win10 classic desktop project include configurations for the ARM64 platform. Building these requires installing the ARM64 toolset.
* When using clang/LLVM for the ARM64 platform, the Windows 11 SDK ([22000](https://walbourn.github.io/windows-sdk-for-windows-11/)) or later is required.
* For ARM64/AArch64 development, the VS 2022 compiler is strongly recommended over the VS 2019 toolset. The Windows SDK (26100 or later) is not compatible with VS 2019 for Win32 on ARM64 development. *Note that the ARM32/AArch32 platform is [deprecated](https://learn.microsoft.com/windows/arm/arm32-to-arm64)*.
* When using clang/LLVM for the ARM64/AArch64 platform, the Windows 11 SDK ([22000](https://walbourn.github.io/windows-sdk-for-windows-11/)) or later is required.
* The ``CompileShaders.cmd`` script must have Windows-style (CRLF) line-endings. If it is changed to Linux-style (LF) line-endings, it can fail to build all the required shaders.

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

@ -46,6 +46,12 @@ public:
Impl(_In_ ID3D12Device* device, uint32_t effectFlags, const EffectPipelineStateDescription& pipelineDescription,
D3D12_COMPARISON_FUNC alphaFunction);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
enum RootParameterIndex
{
ConstantBuffer,

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

@ -56,6 +56,12 @@ class BasicEffect::Impl : public EffectBase<BasicEffectTraits>
public:
Impl(_In_ ID3D12Device* device, uint32_t effectFlags, const EffectPipelineStateDescription& pipelineDescription);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
enum RootParameterIndex
{
ConstantBuffer,

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

@ -135,6 +135,12 @@ namespace
mMutex{}
{ }
DeviceResources(const DeviceResources&) = delete;
DeviceResources& operator=(const DeviceResources&) = delete;
DeviceResources(DeviceResources&&) = delete;
DeviceResources& operator=(DeviceResources&&) = delete;
ID3D12RootSignature* GetRootSignature(int slot, const D3D12_ROOT_SIGNATURE_DESC& desc)
{
assert(slot >= 0 && slot < RootSignatureCount);
@ -166,6 +172,12 @@ class BasicPostProcess::Impl : public AlignedNew<PostProcessConstants>
public:
Impl(_In_ ID3D12Device* device, const RenderTargetState& rtState, Effect ifx);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
void Process(_In_ ID3D12GraphicsCommandList* commandList);
void SetDirtyFlag() noexcept { mDirtyFlags = INT_MAX; }

181
Kits/DirectXTK12/Src/CMO.h Normal file
Просмотреть файл

@ -0,0 +1,181 @@
//--------------------------------------------------------------------------------------
// File: CMO.h
//
// .CMO files are built by Visual Studio's MeshContentTask and an example renderer was
// provided in the VS Direct3D Starter Kit
// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-1-of-3/
// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-2-of-3/
// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-3-of-3/
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
// http://go.microsoft.com/fwlink/?LinkID=615561
//--------------------------------------------------------------------------------------
#pragma once
#include <DirectXMath.h>
#include <cstdint>
namespace VSD3DStarter
{
// .CMO files
// UINT - Mesh count
// { [Mesh count]
// UINT - Length of name
// wchar_t[] - Name of mesh (if length > 0)
// UINT - Material count
// { [Material count]
// UINT - Length of material name
// wchar_t[] - Name of material (if length > 0)
// Material structure
// UINT - Length of pixel shader name
// wchar_t[] - Name of pixel shader (if length > 0)
// { [8]
// UINT - Length of texture name
// wchar_t[] - Name of texture (if length > 0)
// }
// }
// BYTE - 1 if there is skeletal animation data present
// UINT - SubMesh count
// { [SubMesh count]
// SubMesh structure
// }
// UINT - IB Count
// { [IB Count]
// UINT - Number of USHORTs in IB
// USHORT[] - Array of indices
// }
// UINT - VB Count
// { [VB Count]
// UINT - Number of verts in VB
// Vertex[] - Array of vertices
// }
// UINT - Skinning VB Count
// { [Skinning VB Count]
// UINT - Number of verts in Skinning VB
// SkinningVertex[] - Array of skinning verts
// }
// MeshExtents structure
// [If skeleton animation data is not present, file ends here]
// UINT - Bone count
// { [Bone count]
// UINT - Length of bone name
// wchar_t[] - Bone name (if length > 0)
// Bone structure
// }
// UINT - Animation clip count
// { [Animation clip count]
// UINT - Length of clip name
// wchar_t[] - Clip name (if length > 0)
// float - Start time
// float - End time
// UINT - Keyframe count
// { [Keyframe count]
// Keyframe structure
// }
// }
// }
#pragma pack(push,1)
struct Material
{
DirectX::XMFLOAT4 Ambient;
DirectX::XMFLOAT4 Diffuse;
DirectX::XMFLOAT4 Specular;
float SpecularPower;
DirectX::XMFLOAT4 Emissive;
DirectX::XMFLOAT4X4 UVTransform;
};
constexpr uint32_t MAX_TEXTURE = 8;
struct SubMesh
{
uint32_t MaterialIndex;
uint32_t IndexBufferIndex;
uint32_t VertexBufferIndex;
uint32_t StartIndex;
uint32_t PrimCount;
};
constexpr uint32_t NUM_BONE_INFLUENCES = 4;
// Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal,
// tangent, color (RGBA), and texture mapping information
struct VertexPositionNormalTangentColorTexture
{
DirectX::XMFLOAT3 position;
DirectX::XMFLOAT3 normal;
DirectX::XMFLOAT4 tangent;
uint32_t color;
DirectX::XMFLOAT2 textureCoordinate;
};
struct SkinningVertex
{
uint32_t boneIndex[NUM_BONE_INFLUENCES];
float boneWeight[NUM_BONE_INFLUENCES];
};
struct MeshExtents
{
float CenterX, CenterY, CenterZ;
float Radius;
float MinX, MinY, MinZ;
float MaxX, MaxY, MaxZ;
};
struct Bone
{
int32_t ParentIndex;
DirectX::XMFLOAT4X4 InvBindPos;
DirectX::XMFLOAT4X4 BindPos;
DirectX::XMFLOAT4X4 LocalTransform;
};
struct Clip
{
float StartTime;
float EndTime;
uint32_t keys;
};
struct Keyframe
{
uint32_t BoneIndex;
float Time;
DirectX::XMFLOAT4X4 Transform;
};
#pragma pack(pop)
const Material s_defMaterial =
{
{ 0.2f, 0.2f, 0.2f, 1.f },
{ 0.8f, 0.8f, 0.8f, 1.f },
{ 0.0f, 0.0f, 0.0f, 1.f },
1.f,
{ 0.0f, 0.0f, 0.0f, 1.0f },
{ 1.f, 0.f, 0.f, 0.f,
0.f, 1.f, 0.f, 0.f,
0.f, 0.f, 1.f, 0.f,
0.f, 0.f, 0.f, 1.f },
};
} // namespace
static_assert(sizeof(VSD3DStarter::Material) == 132, "CMO Mesh structure size incorrect");
static_assert(sizeof(VSD3DStarter::SubMesh) == 20, "CMO Mesh structure size incorrect");
static_assert(sizeof(VSD3DStarter::VertexPositionNormalTangentColorTexture) == 52, "CMO Mesh structure size incorrect");
static_assert(sizeof(VSD3DStarter::SkinningVertex) == 32, "CMO Mesh structure size incorrect");
static_assert(sizeof(VSD3DStarter::MeshExtents) == 40, "CMO Mesh structure size incorrect");
static_assert(sizeof(VSD3DStarter::Bone) == 196, "CMO Mesh structure size incorrect");
static_assert(sizeof(VSD3DStarter::Clip) == 12, "CMO Mesh structure size incorrect");
static_assert(sizeof(VSD3DStarter::Keyframe) == 72, "CMO Mesh structure size incorrect");

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

@ -464,6 +464,12 @@ public:
}
}
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
D3D12_GPU_DESCRIPTOR_HANDLE Get(SamplerIndex i) const
{
return mDescriptors.GetGpuHandle(static_cast<size_t>(i));

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

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

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

@ -299,7 +299,7 @@ namespace
bool isCubeMap = false;
size_t mipCount = header->mipMapCount;
if (0 == mipCount)
if ((0 == mipCount) || (loadFlags & DDS_LOADER_IGNORE_MIPS))
{
mipCount = 1;
}

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

@ -47,6 +47,12 @@ public:
Impl(_In_ ID3D12Device* device, uint32_t effectFlags, const EffectPipelineStateDescription& pipelineDescription,
DebugEffect::Mode debugMode);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
enum RootParameterIndex
{
ConstantBuffer,

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

@ -89,6 +89,12 @@ namespace
{
}
DeviceResources(const DeviceResources&) = delete;
DeviceResources& operator=(const DeviceResources&) = delete;
DeviceResources(DeviceResources&&) = delete;
DeviceResources& operator=(DeviceResources&&) = delete;
ID3D12RootSignature* GetRootSignature(const D3D12_ROOT_SIGNATURE_DESC& desc)
{
return DemandCreate(mRootSignature, mMutex, [&](ID3D12RootSignature** pResult) noexcept -> HRESULT
@ -117,6 +123,12 @@ class DualPostProcess::Impl : public AlignedNew<PostProcessConstants>
public:
Impl(_In_ ID3D12Device* device, const RenderTargetState& rtState, Effect ifx);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
void Process(_In_ ID3D12GraphicsCommandList* commandList);
void SetDirtyFlag() noexcept { mDirtyFlags = INT_MAX; }

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

@ -45,6 +45,12 @@ class DualTextureEffect::Impl : public EffectBase<DualTextureEffectTraits>
public:
Impl(_In_ ID3D12Device* device, uint32_t effectFlags, const EffectPipelineStateDescription& pipelineDescription);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
enum RootParameterIndex
{
Texture1SRV,

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

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

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

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

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

@ -63,6 +63,12 @@ public:
const EffectPipelineStateDescription& pipelineDescription,
EnvironmentMapEffect::Mapping mapping);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
enum RootParameterIndex
{
TextureSRV,

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

@ -27,6 +27,12 @@ class GeometricPrimitive::Impl
public:
Impl() noexcept : mIndexCount(0), mVertexBufferView{}, mIndexBufferView{} {}
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
void Initialize(const VertexCollection& vertices, const IndexCollection& indices, _In_opt_ ID3D12Device* device);
void LoadStaticBuffers(

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

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

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

@ -17,161 +17,8 @@
using namespace DirectX;
using Microsoft::WRL::ComPtr;
#include "CMO.h"
//--------------------------------------------------------------------------------------
// .CMO files are built by Visual Studio's MeshContentTask and an example renderer was
// provided in the VS Direct3D Starter Kit
// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-1-of-3/
// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-2-of-3/
// https://devblogs.microsoft.com/cppblog/developing-an-app-with-the-visual-studio-3d-starter-kit-part-3-of-3/
//--------------------------------------------------------------------------------------
namespace VSD3DStarter
{
// .CMO files
// UINT - Mesh count
// { [Mesh count]
// UINT - Length of name
// wchar_t[] - Name of mesh (if length > 0)
// UINT - Material count
// { [Material count]
// UINT - Length of material name
// wchar_t[] - Name of material (if length > 0)
// Material structure
// UINT - Length of pixel shader name
// wchar_t[] - Name of pixel shader (if length > 0)
// { [8]
// UINT - Length of texture name
// wchar_t[] - Name of texture (if length > 0)
// }
// }
// BYTE - 1 if there is skeletal animation data present
// UINT - SubMesh count
// { [SubMesh count]
// SubMesh structure
// }
// UINT - IB Count
// { [IB Count]
// UINT - Number of USHORTs in IB
// USHORT[] - Array of indices
// }
// UINT - VB Count
// { [VB Count]
// UINT - Number of verts in VB
// Vertex[] - Array of vertices
// }
// UINT - Skinning VB Count
// { [Skinning VB Count]
// UINT - Number of verts in Skinning VB
// SkinningVertex[] - Array of skinning verts
// }
// MeshExtents structure
// [If skeleton animation data is not present, file ends here]
// UINT - Bone count
// { [Bone count]
// UINT - Length of bone name
// wchar_t[] - Bone name (if length > 0)
// Bone structure
// }
// UINT - Animation clip count
// { [Animation clip count]
// UINT - Length of clip name
// wchar_t[] - Clip name (if length > 0)
// float - Start time
// float - End time
// UINT - Keyframe count
// { [Keyframe count]
// Keyframe structure
// }
// }
// }
#pragma pack(push,1)
struct Material
{
DirectX::XMFLOAT4 Ambient;
DirectX::XMFLOAT4 Diffuse;
DirectX::XMFLOAT4 Specular;
float SpecularPower;
DirectX::XMFLOAT4 Emissive;
DirectX::XMFLOAT4X4 UVTransform;
};
constexpr uint32_t MAX_TEXTURE = 8;
struct SubMesh
{
uint32_t MaterialIndex;
uint32_t IndexBufferIndex;
uint32_t VertexBufferIndex;
uint32_t StartIndex;
uint32_t PrimCount;
};
constexpr uint32_t NUM_BONE_INFLUENCES = 4;
struct SkinningVertex
{
uint32_t boneIndex[NUM_BONE_INFLUENCES];
float boneWeight[NUM_BONE_INFLUENCES];
};
struct MeshExtents
{
float CenterX, CenterY, CenterZ;
float Radius;
float MinX, MinY, MinZ;
float MaxX, MaxY, MaxZ;
};
struct Bone
{
int32_t ParentIndex;
DirectX::XMFLOAT4X4 InvBindPos;
DirectX::XMFLOAT4X4 BindPos;
DirectX::XMFLOAT4X4 LocalTransform;
};
struct Clip
{
float StartTime;
float EndTime;
uint32_t keys;
};
struct Keyframe
{
uint32_t BoneIndex;
float Time;
DirectX::XMFLOAT4X4 Transform;
};
#pragma pack(pop)
const Material s_defMaterial =
{
{ 0.2f, 0.2f, 0.2f, 1.f },
{ 0.8f, 0.8f, 0.8f, 1.f },
{ 0.0f, 0.0f, 0.0f, 1.f },
1.f,
{ 0.0f, 0.0f, 0.0f, 1.0f },
{ 1.f, 0.f, 0.f, 0.f,
0.f, 1.f, 0.f, 0.f,
0.f, 0.f, 1.f, 0.f,
0.f, 0.f, 0.f, 1.f },
};
} // namespace
static_assert(sizeof(VSD3DStarter::Material) == 132, "CMO Mesh structure size incorrect");
static_assert(sizeof(VSD3DStarter::SubMesh) == 20, "CMO Mesh structure size incorrect");
static_assert(sizeof(VSD3DStarter::SkinningVertex) == 32, "CMO Mesh structure size incorrect");
static_assert(sizeof(VSD3DStarter::MeshExtents) == 40, "CMO Mesh structure size incorrect");
static_assert(sizeof(VSD3DStarter::Bone) == 196, "CMO Mesh structure size incorrect");
static_assert(sizeof(VSD3DStarter::Clip) == 12, "CMO Mesh structure size incorrect");
static_assert(sizeof(VSD3DStarter::Keyframe) == 72, "CMO Mesh structure size incorrect");
namespace
{
@ -208,6 +55,8 @@ namespace
static const D3D12_INPUT_ELEMENT_DESC InputElements[InputElementCount];
};
static_assert(sizeof(VertexPositionNormalTangentColorTexture) == sizeof(VSD3DStarter::VertexPositionNormalTangentColorTexture), "mismatch with CMO vertex type");
const D3D12_INPUT_ELEMENT_DESC VertexPositionNormalTangentColorTexture::InputElements[] =
{
{ "SV_Position", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
@ -375,7 +224,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
if (dataSize < usedSize)
throw std::runtime_error("End of file");
auto meshName = reinterpret_cast<const wchar_t*>(static_cast<const void*>(meshData + usedSize));
auto meshName = reinterpret_cast<const wchar_t*>(static_cast<const void*>(meshData + usedSize)); // [CodeQL.SM02986]: The cast here is intentional.
usedSize += sizeof(wchar_t)*(*nName);
if (dataSize < usedSize)
@ -404,7 +253,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
if (dataSize < usedSize)
throw std::runtime_error("End of file");
auto matName = reinterpret_cast<const wchar_t*>(static_cast<const void*>(meshData + usedSize));
auto matName = reinterpret_cast<const wchar_t*>(static_cast<const void*>(meshData + usedSize)); // [CodeQL.SM02986]: The cast here is intentional.
usedSize += sizeof(wchar_t)*(*nName);
if (dataSize < usedSize)
@ -426,7 +275,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
if (dataSize < usedSize)
throw std::runtime_error("End of file");
auto psName = reinterpret_cast<const wchar_t*>(static_cast<const void*>(meshData + usedSize));
auto psName = reinterpret_cast<const wchar_t*>(static_cast<const void*>(meshData + usedSize)); // [CodeQL.SM02986]: The cast here is intentional.
usedSize += sizeof(wchar_t)*(*nName);
if (dataSize < usedSize)
@ -441,7 +290,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
if (dataSize < usedSize)
throw std::runtime_error("End of file");
auto txtName = reinterpret_cast<const wchar_t*>(static_cast<const void*>(meshData + usedSize));
auto txtName = reinterpret_cast<const wchar_t*>(static_cast<const void*>(meshData + usedSize)); // [CodeQL.SM02986]: The cast here is intentional.
usedSize += sizeof(wchar_t)*(*nName);
if (dataSize < usedSize)
@ -665,7 +514,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
if (dataSize < usedSize)
throw std::runtime_error("End of file");
auto boneName = reinterpret_cast<const wchar_t*>(static_cast<const void*>(meshData + usedSize));
auto boneName = reinterpret_cast<const wchar_t*>(static_cast<const void*>(meshData + usedSize)); // [CodeQL.SM02986]: The cast here is intentional.
usedSize += sizeof(wchar_t) * (*nName);
if (dataSize < usedSize)

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

@ -71,6 +71,12 @@ class NormalMapEffect::Impl : public EffectBase<NormalMapEffectTraits>
public:
explicit Impl(_In_ ID3D12Device* device);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
void Initialize(
_In_ ID3D12Device* device,
uint32_t effectFlags,

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

@ -73,6 +73,12 @@ class PBREffect::Impl : public EffectBase<PBREffectTraits>
public:
explicit Impl(_In_ ID3D12Device* device);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
void Initialize(
_In_ ID3D12Device* device,
uint32_t effectFlags,

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

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

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

@ -24,6 +24,12 @@ class PrimitiveBatchBase::Impl
public:
Impl(_In_ ID3D12Device* device, size_t maxIndices, size_t maxVertices, size_t vertexSize);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
void Begin(_In_ ID3D12GraphicsCommandList* cmdList);
void End();

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

@ -230,6 +230,12 @@ namespace
generateMipsPSO = CreateGenMipsPipelineState(device, rootSignature.Get(), GenerateMips_main, sizeof(GenerateMips_main));
}
GenerateMipsResources(const GenerateMipsResources&) = delete;
GenerateMipsResources& operator=(const GenerateMipsResources&) = delete;
GenerateMipsResources(GenerateMipsResources&&) = default;
GenerateMipsResources& operator=(GenerateMipsResources&&) = default;
private:
static ComPtr<ID3D12RootSignature> CreateGenMipsRootSignature(
_In_ ID3D12Device* device)
@ -315,6 +321,12 @@ public:
}
}
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
// Call this before your multiple calls to Upload.
void Begin(D3D12_COMMAND_LIST_TYPE commandType)
{

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

@ -123,8 +123,11 @@ namespace
bufferDesc.SampleDesc.Count = 1;
ComPtr<ID3D12Resource> copySource(pSource);
D3D12_RESOURCE_STATES beforeStateSource = beforeState;
if (desc.SampleDesc.Count > 1)
{
TransitionResource(commandList.Get(), pSource, beforeState, D3D12_RESOURCE_STATE_RESOLVE_SOURCE);
// MSAA content must be resolved before being copied to a staging texture
auto descCopy = desc;
descCopy.SampleDesc.Count = 1;
@ -136,7 +139,7 @@ namespace
&defaultHeapProperties,
D3D12_HEAP_FLAG_NONE,
&descCopy,
D3D12_RESOURCE_STATE_COPY_DEST,
D3D12_RESOURCE_STATE_RESOLVE_DEST,
nullptr,
IID_GRAPHICS_PPV_ARGS(pTemp.GetAddressOf()));
if (FAILED(hr))
@ -166,6 +169,11 @@ namespace
}
copySource = pTemp;
beforeState = D3D12_RESOURCE_STATE_RESOLVE_DEST;
}
else
{
beforeStateSource = D3D12_RESOURCE_STATE_COPY_SOURCE;
}
// Create a staging texture
@ -177,14 +185,21 @@ namespace
nullptr,
IID_GRAPHICS_PPV_ARGS(pStaging));
if (FAILED(hr))
{
if (*pStaging)
{
(*pStaging)->Release();
*pStaging = nullptr;
}
return hr;
}
SetDebugObjectName(*pStaging, L"ScreenGrab staging");
assert(*pStaging);
// Transition the resource if necessary
TransitionResource(commandList.Get(), pSource, beforeState, D3D12_RESOURCE_STATE_COPY_SOURCE);
TransitionResource(commandList.Get(), copySource.Get(), beforeState, D3D12_RESOURCE_STATE_COPY_SOURCE);
// Get the copy target location
D3D12_PLACED_SUBRESOURCE_FOOTPRINT bufferFootprint = {};
@ -200,12 +215,16 @@ namespace
// Copy the texture
commandList->CopyTextureRegion(&copyDest, 0, 0, 0, &copySrc, nullptr);
// Transition the resource to the next state
TransitionResource(commandList.Get(), pSource, D3D12_RESOURCE_STATE_COPY_SOURCE, afterState);
// Transition the source resource to the next state
TransitionResource(commandList.Get(), pSource, beforeStateSource, afterState);
hr = commandList->Close();
if (FAILED(hr))
{
(*pStaging)->Release();
*pStaging = nullptr;
return hr;
}
// Execute the command list
pCommandQ->ExecuteCommandLists(1, CommandListCast(commandList.GetAddressOf()));
@ -213,7 +232,11 @@ namespace
// Signal the fence
hr = pCommandQ->Signal(fence.Get(), 1);
if (FAILED(hr))
{
(*pStaging)->Release();
*pStaging = nullptr;
return hr;
}
// Block until the copy is complete
while (fence->GetCompletedValue() < 1)
@ -291,13 +314,12 @@ HRESULT DirectX::SaveDDSTextureToFile(
auto_delete_file delonfail(hFile.get());
// Setup header
constexpr size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10);
uint8_t fileHeader[MAX_HEADER_SIZE] = {};
uint8_t fileHeader[DDS_DX10_HEADER_SIZE] = {};
*reinterpret_cast<uint32_t*>(&fileHeader[0]) = DDS_MAGIC;
auto header = reinterpret_cast<DDS_HEADER*>(&fileHeader[0] + sizeof(uint32_t));
size_t headerSize = sizeof(uint32_t) + sizeof(DDS_HEADER);
size_t headerSize = DDS_MIN_HEADER_SIZE;
header->size = sizeof(DDS_HEADER);
header->flags = DDS_HEADER_FLAGS_TEXTURE | DDS_HEADER_FLAGS_MIPMAP;
header->height = desc.Height;
@ -355,7 +377,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
memcpy(&header->ddspf, &DDSPF_DX10, sizeof(DDS_PIXELFORMAT));
headerSize += sizeof(DDS_HEADER_DXT10);
extHeader = reinterpret_cast<DDS_HEADER_DXT10*>(fileHeader + sizeof(uint32_t) + sizeof(DDS_HEADER));
extHeader = reinterpret_cast<DDS_HEADER_DXT10*>(fileHeader + DDS_MIN_HEADER_SIZE);
extHeader->dxgiFormat = desc.Format;
extHeader->resourceDimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
extHeader->arraySize = 1;
@ -795,7 +817,9 @@ HRESULT DirectX::SaveWICTextureToFile(
else
{
// No conversion required
hr = frame->WritePixels(desc.Height, static_cast<UINT>(dstRowPitch), static_cast<UINT>(imageSize), static_cast<BYTE*>(pMappedMemory));
hr = frame->WritePixels(desc.Height,
static_cast<UINT>(dstRowPitch), static_cast<UINT>(imageSize),
static_cast<BYTE*>(pMappedMemory));
}
pStaging->Unmap(0, &writeRange);

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

@ -34,7 +34,7 @@ if not exist %XBOXFXC% goto needxdk
goto continue
:continuegxdk
set XBOXOPTS=/D__XBOX_PER_THREAD_SCRATCH_SIZE_LIMIT_IN_BYTES=0
set XBOXOPTS=-HV 2021 /D__XBOX_PER_THREAD_SCRATCH_SIZE_LIMIT_IN_BYTES=0
if %2.==scarlett. (
set XBOXPREFIX=XboxGamingScarlett
set XBOXDXC="%GameDKLatest%\GXDK\bin\Scarlett\DXC.exe"
@ -49,23 +49,36 @@ if not exist %XBOXDXC% goto needgxdk
goto continue
:continuedxil
set DXILOPTS=-HV 2021
if defined DirectXShaderCompiler goto dxcviaenv
set PCDXC="%WindowsSdkVerBinPath%%FXCARCH%\dxc.exe"
if exist %PCDXC% goto continue
if exist %PCDXC% goto dxilver
set PCDXC="%WindowsSdkBinPath%%WindowsSDKVersion%\%FXCARCH%\dxc.exe"
if exist %PCDXC% goto continue
if exist %PCDXC% goto dxilver
set PCDXC=dxc.exe
goto continue
:dxilver
if not defined WindowsSDKVersion goto continue
REM known DXC.EXE versions that don't support -HV 2021
if not "x%WindowsSDKVersion:10.0.19041.0=%"=="x%WindowsSDKVersion%" set DXILOPTS=%DXILOPTS:-HV 2021=%
if not "x%WindowsSDKVersion:10.0.20348.0=%"=="x%WindowsSDKVersion%" set DXILOPTS=%DXILOPTS:-HV 2021=%
if not "x%WindowsSDKVersion:10.0.22000.0=%"=="x%WindowsSDKVersion%" set DXILOPTS=%DXILOPTS:-HV 2021=%
goto continue
:dxcviaenv
set PCDXC="%DirectXShaderCompiler%"
if exist %PCDXC% goto continue
goto needdxil
if not exist %PCDXC% goto needdxil
if not "x%DirectXShaderCompiler:10.0.19041.0=%"=="x%DirectXShaderCompiler%" set DXILOPTS=%DXILOPTS:-HV 2021=%
if not "x%DirectXShaderCompiler:10.0.20348.0=%"=="x%DirectXShaderCompiler%" set DXILOPTS=%DXILOPTS:-HV 2021=%
if not "x%DirectXShaderCompiler:10.0.22000.0=%"=="x%DirectXShaderCompiler%" set DXILOPTS=%DXILOPTS:-HV 2021=%
goto continue
:continuepc
set PCOPTS=
if defined LegacyShaderCompiler goto fxcviaenv
set PCFXC="%WindowsSdkVerBinPath%%FXCARCH%\fxc.exe"
if exist %PCFXC% goto continue
set PCFXC="%WindowsSdkBinPath%%WindowsSDKVersion%\%FXCARCH%\fxc.exe"
@ -74,6 +87,12 @@ set PCFXC="%WindowsSdkDir%bin\%WindowsSDKVersion%\%FXCARCH%\fxc.exe"
if exist %PCFXC% goto continue
set PCFXC=fxc.exe
goto continue
:fxcviaenv
set PCFXC="%LegacyShaderCompiler%"
if not exist %PCFXC% goto needfxc
goto continue
:continue
if not defined CompileShadersOutput set CompileShadersOutput=Compiled
@ -293,28 +312,28 @@ endlocal
exit /b 0
:CompileShader
set fxc=%PCFXC% "%1.fx" %FXCOPTS% /T%2_5_1 %PCOPTS% /E%3 "/Fh%CompileShadersOutput%\%1_%3.inc" "/Fd%CompileShadersOutput%\%1_%3.pdb" /Vn%1_%3
set fxc=%PCFXC% "%1.fx" %FXCOPTS% /T%2_5_1 /E%3 "/Fh%CompileShadersOutput%\%1_%3.inc" "/Fd%CompileShadersOutput%\%1_%3.pdb" /Vn%1_%3
echo.
echo %fxc%
%fxc% || set error=1
exit /b
:CompileComputeShader
set fxc=%PCFXC% "%1.hlsl" %FXCOPTS% /Tcs_5_1 %PCOPTS% /E%2 "/Fh%CompileShadersOutput%\%1_%2.inc" "/Fd%CompileShadersOutput%\%1_%2.pdb" /Vn%1_%2
set fxc=%PCFXC% "%1.hlsl" %FXCOPTS% /Tcs_5_1 /E%2 "/Fh%CompileShadersOutput%\%1_%2.inc" "/Fd%CompileShadersOutput%\%1_%2.pdb" /Vn%1_%2
echo.
echo %fxc%
%fxc% || set error=1
exit /b
:CompileShaderdxil
set dxc=%PCDXC% "%1.fx" %FXCOPTS% /T%2_6_0 /E%3 "/Fh%CompileShadersOutput%\%1_%3.inc" "/Fd%CompileShadersOutput%\%1_%3.pdb" /Vn%1_%3
set dxc=%PCDXC% "%1.fx" %FXCOPTS% /T%2_6_0 %DXILOPTS% /E%3 "/Fh%CompileShadersOutput%\%1_%3.inc" "/Fd%CompileShadersOutput%\%1_%3.pdb" /Vn%1_%3
echo.
echo %dxc%
%dxc% || set error=1
exit /b
:CompileComputeShaderdxil
set dxc=%PCDXC% "%1.hlsl" %FXCOPTS% /Tcs_6_0 /E%2 "/Fh%CompileShadersOutput%\%1_%2.inc" "/Fd%CompileShadersOutput%\%1_%2.pdb" /Vn%1_%2
set dxc=%PCDXC% "%1.hlsl" %FXCOPTS% /Tcs_6_0 %DXILOPTS% /E%2 "/Fh%CompileShadersOutput%\%1_%2.inc" "/Fd%CompileShadersOutput%\%1_%2.pdb" /Vn%1_%2
echo.
echo %dxc%
%dxc% || set error=1
@ -335,14 +354,14 @@ echo %fxc%
exit /b
:CompileShadergxdk
set dxc=%XBOXDXC% "%1.fx" %FXCOPTS% -HV 2021 /T%2_6_0 %XBOXOPTS% /E%3 "/Fh%CompileShadersOutput%\%XBOXPREFIX%%1_%3.inc" "/Fd%CompileShadersOutput%\%XBOXPREFIX%%1_%3.pdb" /Vn%1_%3
set dxc=%XBOXDXC% "%1.fx" %FXCOPTS% /T%2_6_0 %XBOXOPTS% /E%3 "/Fh%CompileShadersOutput%\%XBOXPREFIX%%1_%3.inc" "/Fd%CompileShadersOutput%\%XBOXPREFIX%%1_%3.pdb" /Vn%1_%3
echo.
echo %dxc%
%dxc% || set error=1
exit /b
:CompileComputeShadergxdk
set dxc=%XBOXDXC% "%1.hlsl" %FXCOPTS% -HV 2021 /Tcs_6_0 %XBOXOPTS% /E%2 "/Fh%CompileShadersOutput%\%XBOXPREFIX%%1_%2.inc" "/Fd%CompileShadersOutput%\%XBOXPREFIX%%1_%2.pdb" /Vn%1_%2
set dxc=%XBOXDXC% "%1.hlsl" %FXCOPTS% /Tcs_6_0 %XBOXOPTS% /E%2 "/Fh%CompileShadersOutput%\%XBOXPREFIX%%1_%2.inc" "/Fd%CompileShadersOutput%\%XBOXPREFIX%%1_%2.pdb" /Vn%1_%2
echo.
echo %dxc%
%dxc% || set error=1
@ -358,6 +377,10 @@ echo ERROR: CompileShaders gxdk requires the Microsoft Gaming SDK
echo (try re-running from the Microsoft GDKX Gaming Command Prompt)
exit /b 1
:needfxc
echo ERROR: CompileShaders requires FXC.EXE
exit /b 1
:needdxil
echo ERROR: CompileShaders dxil requires DXC.EXE
exit /b 1

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

@ -58,6 +58,12 @@ class SkinnedEffect::Impl : public EffectBase<SkinnedEffectTraits>
public:
Impl(_In_ ID3D12Device* device, uint32_t effectFlags, const EffectPipelineStateDescription& pipelineDescription);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
enum RootParameterIndex
{
ConstantBuffer,

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

@ -79,6 +79,12 @@ public:
const SpriteBatchPipelineStateDescription& psoDesc,
const D3D12_VIEWPORT* viewport);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
void XM_CALLCONV Begin(
_In_ ID3D12GraphicsCommandList* commandList,
SpriteSortMode sortMode = SpriteSortMode_Deferred,

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

@ -39,6 +39,12 @@ public:
size_t glyphCount,
float lineSpacing) noexcept(false);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
Glyph const* FindGlyph(wchar_t character) const;
void SetDefaultCharacter(wchar_t character);

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

@ -227,6 +227,12 @@ namespace
{
}
DeviceResources(const DeviceResources&) = delete;
DeviceResources& operator=(const DeviceResources&) = delete;
DeviceResources(DeviceResources&&) = delete;
DeviceResources& operator=(DeviceResources&&) = delete;
ID3D12RootSignature* GetRootSignature(const D3D12_ROOT_SIGNATURE_DESC& desc)
{
return DemandCreate(mRootSignature, mMutex, [&](ID3D12RootSignature** pResult) noexcept -> HRESULT
@ -255,6 +261,12 @@ class ToneMapPostProcess::Impl : public AlignedNew<ToneMapConstants>
public:
Impl(_In_ ID3D12Device* device, const RenderTargetState& rtState, Operator op, TransferFunction func, bool mrt = false);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
Impl(Impl&&) = default;
Impl& operator=(Impl&&) = default;
void Process(_In_ ID3D12GraphicsCommandList* commandList);
void SetDirtyFlag() noexcept { mDirtyFlags = INT_MAX; }

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

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

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

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

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

@ -47,7 +47,7 @@ struct IWICImagingFactory;
struct IWICMetadataQueryReader;
#endif
#define DIRECTX_TEX_VERSION 204
#define DIRECTX_TEX_VERSION 206
namespace DirectX
@ -72,7 +72,9 @@ namespace DirectX
size_t __cdecl BitsPerColor(_In_ DXGI_FORMAT fmt) noexcept;
enum FORMAT_TYPE
size_t __cdecl BytesPerBlock(_In_ DXGI_FORMAT fmt) noexcept;
enum FORMAT_TYPE : uint32_t
{
FORMAT_TYPE_TYPELESS,
FORMAT_TYPE_FLOAT,
@ -84,7 +86,7 @@ namespace DirectX
FORMAT_TYPE __cdecl FormatDataType(_In_ DXGI_FORMAT fmt) noexcept;
enum CP_FLAGS : unsigned long
enum CP_FLAGS : uint32_t
{
CP_FLAGS_NONE = 0x0,
// Normal operation
@ -134,7 +136,7 @@ namespace DirectX
//---------------------------------------------------------------------------------
// Texture metadata
enum TEX_DIMENSION
enum TEX_DIMENSION : uint32_t
// Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION
{
TEX_DIMENSION_TEXTURE1D = 2,
@ -142,18 +144,18 @@ namespace DirectX
TEX_DIMENSION_TEXTURE3D = 4,
};
enum TEX_MISC_FLAG : unsigned long
enum TEX_MISC_FLAG : uint32_t
// Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG
{
TEX_MISC_TEXTURECUBE = 0x4L,
};
enum TEX_MISC_FLAG2 : unsigned long
enum TEX_MISC_FLAG2 : uint32_t
{
TEX_MISC2_ALPHA_MODE_MASK = 0x7L,
};
enum TEX_ALPHA_MODE
enum TEX_ALPHA_MODE : uint32_t
// Matches DDS_ALPHA_MODE, encoded in MISC_FLAGS2
{
TEX_ALPHA_MODE_UNKNOWN = 0,
@ -208,7 +210,7 @@ namespace DirectX
bool __cdecl IsDX10() const noexcept { return (fourCC == 0x30315844); }
};
enum DDS_FLAGS : unsigned long
enum DDS_FLAGS : uint32_t
{
DDS_FLAGS_NONE = 0x0,
@ -236,6 +238,9 @@ namespace DirectX
DDS_FLAGS_PERMISSIVE = 0x80,
// Allow some file variants due to common bugs in the header written by various leagcy DDS writers
DDS_FLAGS_IGNORE_MIPS = 0x100,
// Allow some files to be read that have incorrect mipcount values in the header by only reading the top-level mip
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)
@ -252,7 +257,7 @@ namespace DirectX
// Enables the loader to read large dimension .dds files (i.e. greater than known hardware requirements)
};
enum TGA_FLAGS : unsigned long
enum TGA_FLAGS : uint32_t
{
TGA_FLAGS_NONE = 0x0,
@ -275,7 +280,7 @@ namespace DirectX
// If no colorspace is specified in TGA 2.0 metadata, assume sRGB
};
enum WIC_FLAGS : unsigned long
enum WIC_FLAGS : uint32_t
{
WIC_FLAGS_NONE = 0x0,
@ -320,7 +325,7 @@ namespace DirectX
};
HRESULT __cdecl GetMetadataFromDDSMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_In_ DDS_FLAGS flags,
_Out_ TexMetadata& metadata) noexcept;
HRESULT __cdecl GetMetadataFromDDSFile(
@ -329,7 +334,7 @@ namespace DirectX
_Out_ TexMetadata& metadata) noexcept;
HRESULT __cdecl GetMetadataFromDDSMemoryEx(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_In_ DDS_FLAGS flags,
_Out_ TexMetadata& metadata,
_Out_opt_ DDSMetaData* ddPixelFormat) noexcept;
@ -340,14 +345,14 @@ namespace DirectX
_Out_opt_ DDSMetaData* ddPixelFormat) noexcept;
HRESULT __cdecl GetMetadataFromHDRMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_Out_ TexMetadata& metadata) noexcept;
HRESULT __cdecl GetMetadataFromHDRFile(
_In_z_ const wchar_t* szFile,
_Out_ TexMetadata& metadata) noexcept;
HRESULT __cdecl GetMetadataFromTGAMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_In_ TGA_FLAGS flags,
_Out_ TexMetadata& metadata) noexcept;
HRESULT __cdecl GetMetadataFromTGAFile(
@ -357,7 +362,7 @@ namespace DirectX
#ifdef _WIN32
HRESULT __cdecl GetMetadataFromWICMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_In_ WIC_FLAGS flags,
_Out_ TexMetadata& metadata,
_In_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
@ -371,7 +376,7 @@ namespace DirectX
// Compatability helpers
HRESULT __cdecl GetMetadataFromTGAMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_Out_ TexMetadata& metadata) noexcept;
HRESULT __cdecl GetMetadataFromTGAFile(
_In_z_ const wchar_t* szFile,
@ -456,7 +461,10 @@ namespace DirectX
void __cdecl Release() noexcept;
void *__cdecl GetBufferPointer() const noexcept { return m_buffer; }
uint8_t* __cdecl GetBufferPointer() const noexcept { return m_buffer; }
const uint8_t* __cdecl GetConstBufferPointer() const noexcept { return m_buffer; }
size_t __cdecl GetBufferSize() const noexcept { return m_size; }
HRESULT __cdecl Resize(size_t size) noexcept;
@ -466,8 +474,8 @@ namespace DirectX
// Shorten size without reallocation
private:
void* m_buffer;
size_t m_size;
uint8_t* m_buffer;
size_t m_size;
};
//---------------------------------------------------------------------------------
@ -475,7 +483,7 @@ namespace DirectX
// DDS operations
HRESULT __cdecl LoadFromDDSMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_In_ DDS_FLAGS flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image) noexcept;
HRESULT __cdecl LoadFromDDSFile(
@ -484,7 +492,7 @@ namespace DirectX
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image) noexcept;
HRESULT __cdecl LoadFromDDSMemoryEx(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_In_ DDS_FLAGS flags,
_Out_opt_ TexMetadata* metadata,
_Out_opt_ DDSMetaData* ddPixelFormat,
@ -512,7 +520,7 @@ namespace DirectX
// HDR operations
HRESULT __cdecl LoadFromHDRMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image) noexcept;
HRESULT __cdecl LoadFromHDRFile(
_In_z_ const wchar_t* szFile,
@ -523,7 +531,7 @@ namespace DirectX
// TGA operations
HRESULT __cdecl LoadFromTGAMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_In_ TGA_FLAGS flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image) noexcept;
HRESULT __cdecl LoadFromTGAFile(
@ -541,7 +549,7 @@ namespace DirectX
// WIC operations
#ifdef _WIN32
HRESULT __cdecl LoadFromWICMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_In_ WIC_FLAGS flags,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image,
_In_ std::function<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
@ -573,7 +581,7 @@ namespace DirectX
// Compatability helpers
HRESULT __cdecl LoadFromTGAMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image) noexcept;
HRESULT __cdecl LoadFromTGAFile(
_In_z_ const wchar_t* szFile,
@ -585,7 +593,7 @@ namespace DirectX
//---------------------------------------------------------------------------------
// Texture conversion, resizing, mipmap generation, and block compression
enum TEX_FR_FLAGS : unsigned long
enum TEX_FR_FLAGS : uint32_t
{
TEX_FR_ROTATE0 = 0x0,
TEX_FR_ROTATE90 = 0x1,
@ -603,7 +611,7 @@ namespace DirectX
// Flip and/or rotate image
#endif
enum TEX_FILTER_FLAGS : unsigned long
enum TEX_FILTER_FLAGS : uint32_t
{
TEX_FILTER_DEFAULT = 0,
@ -657,9 +665,9 @@ namespace DirectX
// Forces use of the WIC path even when logic would have picked a non-WIC path when both are an option
};
constexpr unsigned long TEX_FILTER_DITHER_MASK = 0xF0000;
constexpr unsigned long TEX_FILTER_MODE_MASK = 0xF00000;
constexpr unsigned long TEX_FILTER_SRGB_MASK = 0xF000000;
constexpr uint32_t TEX_FILTER_DITHER_MASK = 0xF0000;
constexpr uint32_t TEX_FILTER_MODE_MASK = 0xF00000;
constexpr uint32_t TEX_FILTER_SRGB_MASK = 0xF000000;
HRESULT __cdecl Resize(
_In_ const Image& srcImage, _In_ size_t width, _In_ size_t height,
@ -726,7 +734,7 @@ namespace DirectX
_In_ float alphaReference, _Inout_ ScratchImage& mipChain) noexcept;
enum TEX_PMALPHA_FLAGS : unsigned long
enum TEX_PMALPHA_FLAGS : uint32_t
{
TEX_PMALPHA_DEFAULT = 0,
@ -749,7 +757,7 @@ namespace DirectX
_In_ TEX_PMALPHA_FLAGS flags, _Out_ ScratchImage& result) noexcept;
// Converts to/from a premultiplied alpha version of the texture
enum TEX_COMPRESS_FLAGS : unsigned long
enum TEX_COMPRESS_FLAGS : uint32_t
{
TEX_COMPRESS_DEFAULT = 0,
@ -835,7 +843,7 @@ namespace DirectX
//---------------------------------------------------------------------------------
// Normal map operations
enum CNMAP_FLAGS : unsigned long
enum CNMAP_FLAGS : uint32_t
{
CNMAP_DEFAULT = 0,
@ -884,7 +892,7 @@ namespace DirectX
_In_ const Image& srcImage, _In_ const Rect& srcRect, _In_ const Image& dstImage,
_In_ TEX_FILTER_FLAGS filter, _In_ size_t xOffset, _In_ size_t yOffset) noexcept;
enum CMSE_FLAGS : unsigned long
enum CMSE_FLAGS : uint32_t
{
CMSE_DEFAULT = 0,
@ -926,7 +934,7 @@ namespace DirectX
//---------------------------------------------------------------------------------
// WIC utility code
#ifdef _WIN32
enum WICCodecs
enum WICCodecs : uint32_t
{
WIC_CODEC_BMP = 1, // Windows Bitmap (.bmp)
WIC_CODEC_JPEG, // Joint Photographic Experts Group (.jpg, .jpeg)
@ -948,7 +956,7 @@ namespace DirectX
// DDS helper functions
HRESULT __cdecl EncodeDDSHeader(
_In_ const TexMetadata& metadata, DDS_FLAGS flags,
_Out_writes_bytes_to_opt_(maxsize, required) void* pDestination, _In_ size_t maxsize,
_Out_writes_bytes_to_opt_(maxsize, required) uint8_t* pDestination, _In_ size_t maxsize,
_Out_ size_t& required) noexcept;
//---------------------------------------------------------------------------------

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

@ -14,29 +14,29 @@
//=====================================================================================
// Bitmask flags enumerator operators
//=====================================================================================
DEFINE_ENUM_FLAG_OPERATORS(CP_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(DDS_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(TGA_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(WIC_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(TEX_FR_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(TEX_FILTER_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(TEX_PMALPHA_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(TEX_COMPRESS_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(CNMAP_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(CMSE_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(CREATETEX_FLAGS);
DEFINE_ENUM_FLAG_OPERATORS(CP_FLAGS)
DEFINE_ENUM_FLAG_OPERATORS(DDS_FLAGS)
DEFINE_ENUM_FLAG_OPERATORS(TGA_FLAGS)
DEFINE_ENUM_FLAG_OPERATORS(WIC_FLAGS)
DEFINE_ENUM_FLAG_OPERATORS(TEX_FR_FLAGS)
DEFINE_ENUM_FLAG_OPERATORS(TEX_FILTER_FLAGS)
DEFINE_ENUM_FLAG_OPERATORS(TEX_PMALPHA_FLAGS)
DEFINE_ENUM_FLAG_OPERATORS(TEX_COMPRESS_FLAGS)
DEFINE_ENUM_FLAG_OPERATORS(CNMAP_FLAGS)
DEFINE_ENUM_FLAG_OPERATORS(CMSE_FLAGS)
DEFINE_ENUM_FLAG_OPERATORS(CREATETEX_FLAGS)
// WIC_FILTER modes match TEX_FILTER modes
constexpr WIC_FLAGS operator|(WIC_FLAGS a, TEX_FILTER_FLAGS b) { return static_cast<WIC_FLAGS>(static_cast<unsigned long>(a) | static_cast<unsigned long>(b & TEX_FILTER_MODE_MASK)); }
constexpr WIC_FLAGS operator|(TEX_FILTER_FLAGS a, WIC_FLAGS b) { return static_cast<WIC_FLAGS>(static_cast<unsigned long>(a & TEX_FILTER_MODE_MASK) | static_cast<unsigned long>(b)); }
constexpr WIC_FLAGS operator|(WIC_FLAGS a, TEX_FILTER_FLAGS b) { return static_cast<WIC_FLAGS>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b & TEX_FILTER_MODE_MASK)); }
constexpr WIC_FLAGS operator|(TEX_FILTER_FLAGS a, WIC_FLAGS b) { return static_cast<WIC_FLAGS>(static_cast<uint32_t>(a & TEX_FILTER_MODE_MASK) | static_cast<uint32_t>(b)); }
// TEX_PMALPHA_SRGB match TEX_FILTER_SRGB
constexpr TEX_PMALPHA_FLAGS operator|(TEX_PMALPHA_FLAGS a, TEX_FILTER_FLAGS b) { return static_cast<TEX_PMALPHA_FLAGS>(static_cast<unsigned long>(a) | static_cast<unsigned long>(b & TEX_FILTER_SRGB_MASK)); }
constexpr TEX_PMALPHA_FLAGS operator|(TEX_FILTER_FLAGS a, TEX_PMALPHA_FLAGS b) { return static_cast<TEX_PMALPHA_FLAGS>(static_cast<unsigned long>(a & TEX_FILTER_SRGB_MASK) | static_cast<unsigned long>(b)); }
constexpr TEX_PMALPHA_FLAGS operator|(TEX_PMALPHA_FLAGS a, TEX_FILTER_FLAGS b) { return static_cast<TEX_PMALPHA_FLAGS>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b & TEX_FILTER_SRGB_MASK)); }
constexpr TEX_PMALPHA_FLAGS operator|(TEX_FILTER_FLAGS a, TEX_PMALPHA_FLAGS b) { return static_cast<TEX_PMALPHA_FLAGS>(static_cast<uint32_t>(a & TEX_FILTER_SRGB_MASK) | static_cast<uint32_t>(b)); }
// TEX_COMPRESS_SRGB match TEX_FILTER_SRGB
constexpr TEX_COMPRESS_FLAGS operator|(TEX_COMPRESS_FLAGS a, TEX_FILTER_FLAGS b) { return static_cast<TEX_COMPRESS_FLAGS>(static_cast<unsigned long>(a) | static_cast<unsigned long>(b & TEX_FILTER_SRGB_MASK)); }
constexpr TEX_COMPRESS_FLAGS operator|(TEX_FILTER_FLAGS a, TEX_COMPRESS_FLAGS b) { return static_cast<TEX_COMPRESS_FLAGS>(static_cast<unsigned long>(a & TEX_FILTER_SRGB_MASK) | static_cast<unsigned long>(b)); }
constexpr TEX_COMPRESS_FLAGS operator|(TEX_COMPRESS_FLAGS a, TEX_FILTER_FLAGS b) { return static_cast<TEX_COMPRESS_FLAGS>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b & TEX_FILTER_SRGB_MASK)); }
constexpr TEX_COMPRESS_FLAGS operator|(TEX_FILTER_FLAGS a, TEX_COMPRESS_FLAGS b) { return static_cast<TEX_COMPRESS_FLAGS>(static_cast<uint32_t>(a & TEX_FILTER_SRGB_MASK) | static_cast<uint32_t>(b)); }
//=====================================================================================
@ -156,7 +156,7 @@ inline HRESULT __cdecl SaveToDDSFile(const Image& image, DDS_FLAGS flags, const
// Compatability helpers
//=====================================================================================
_Use_decl_annotations_
inline HRESULT __cdecl GetMetadataFromTGAMemory(const void* pSource, size_t size, TexMetadata& metadata) noexcept
inline HRESULT __cdecl GetMetadataFromTGAMemory(const uint8_t* pSource, size_t size, TexMetadata& metadata) noexcept
{
return GetMetadataFromTGAMemory(pSource, size, TGA_FLAGS_NONE, metadata);
}
@ -168,7 +168,7 @@ inline HRESULT __cdecl GetMetadataFromTGAFile(const wchar_t* szFile, TexMetadata
}
_Use_decl_annotations_
inline HRESULT __cdecl LoadFromTGAMemory(const void* pSource, size_t size, TexMetadata* metadata, ScratchImage& image) noexcept
inline HRESULT __cdecl LoadFromTGAMemory(const uint8_t* pSource, size_t size, TexMetadata* metadata, ScratchImage& image) noexcept
{
return LoadFromTGAMemory(pSource, size, TGA_FLAGS_NONE, metadata, image);
}

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

@ -22,8 +22,6 @@ static_assert(static_cast<int>(TEX_DIMENSION_TEXTURE3D) == static_cast<int>(DDS_
namespace
{
constexpr size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10);
//-------------------------------------------------------------------------------------
// Legacy format mapping table (used for DDS files without 'DX10' extended header)
//-------------------------------------------------------------------------------------
@ -48,6 +46,9 @@ namespace
CONV_FLAGS_L8 = 0x40000, // Source is a 8 luminance format
CONV_FLAGS_L16 = 0x80000, // Source is a 16 luminance format
CONV_FLAGS_A8L8 = 0x100000, // Source is a 8:8 luminance format
CONV_FLAGS_L6V5U5 = 0x200000, // Source is a 6:5:5 bumpluminance format
CONV_FLAGS_L8U8V8 = 0x400000, // Source is a X:8:8:8 bumpluminance format
CONV_FLAGS_WUV10 = 0x800000, // Source is a 2:10:10:10 bump format
};
struct LegacyDDS
@ -143,7 +144,7 @@ namespace
{ DXGI_FORMAT_R8G8B8A8_UNORM, CONV_FLAGS_EXPAND
| CONV_FLAGS_PAL8
| CONV_FLAGS_A8P8, { sizeof(DDS_PIXELFORMAT), DDS_PAL8A, 0, 16, 0, 0, 0, 0 } }, // D3DFMT_A8P8
| CONV_FLAGS_A8P8, { sizeof(DDS_PIXELFORMAT), DDS_PAL8A, 0, 16, 0, 0, 0, 0xff00 } }, // D3DFMT_A8P8
{ DXGI_FORMAT_R8G8B8A8_UNORM, CONV_FLAGS_EXPAND
| CONV_FLAGS_PAL8, { sizeof(DDS_PIXELFORMAT), DDS_PAL8, 0, 8, 0, 0, 0, 0 } }, // D3DFMT_P8
@ -159,6 +160,11 @@ namespace
{ DXGI_FORMAT_R8G8_SNORM, CONV_FLAGS_NONE, DDSPF_V8U8 }, // D3DFMT_V8U8
{ DXGI_FORMAT_R8G8B8A8_SNORM, CONV_FLAGS_NONE, DDSPF_Q8W8V8U8 }, // D3DFMT_Q8W8V8U8
{ DXGI_FORMAT_R16G16_SNORM, CONV_FLAGS_NONE, DDSPF_V16U16 }, // D3DFMT_V16U16
{ DXGI_FORMAT_R8G8B8A8_UNORM, CONV_FLAGS_L6V5U5
| CONV_FLAGS_EXPAND, DDSPF_L6V5U5 }, // D3DFMT_L6V5U5
{ DXGI_FORMAT_R8G8B8A8_UNORM, CONV_FLAGS_L8U8V8, DDSPF_X8L8V8U8 }, // D3DFMT_X8L8V8U8
{ DXGI_FORMAT_R10G10B10A2_UNORM, CONV_FLAGS_WUV10, DDSPF_A2W10V10U10 }, // D3DFMT_A2W10V10U10
};
// Note that many common DDS reader/writers (including D3DX) swap the
@ -168,15 +174,14 @@ namespace
// header extension and specify the DXGI_FORMAT_R10G10B10A2_UNORM format directly
// We do not support the following legacy Direct3D 9 formats:
// BumpDuDv D3DFMT_A2W10V10U10
// BumpLuminance D3DFMT_L6V5U5, D3DFMT_X8L8V8U8
// FourCC 117 D3DFMT_CxV8U8
// ZBuffer D3DFMT_D16_LOCKABLE
// D3DFMT_D16_LOCKABLE (DDPF_ZBUFFER: 0x00000400)
// FourCC 82 D3DFMT_D32F_LOCKABLE
// FourCC 117 D3DFMT_CxV8U8
// We do not support the following known FourCC codes:
// FourCC CTX1 (Xbox 360 only)
// FourCC EAR, EARG, ET2, ET2A (Ericsson Texture Compression)
// FourCC MET1 (a.k.a. D3DFMT_MULTI2_ARGB8; rarely supported by any hardware)
DXGI_FORMAT GetDXGIFormat(const DDS_HEADER& hdr, const DDS_PIXELFORMAT& ddpf,
DDS_FLAGS flags,
@ -217,17 +222,16 @@ namespace
if (ddpf.fourCC == entry->ddpf.fourCC)
break;
}
else if (ddpfFlags == entry->ddpf.flags)
else if ((ddpfFlags == entry->ddpf.flags) && (ddpf.RGBBitCount == entry->ddpf.RGBBitCount))
{
if (entry->ddpf.flags & DDS_PAL8)
{
if (ddpf.RGBBitCount == entry->ddpf.RGBBitCount)
break;
// PAL8 / PAL8A
break;
}
else if (entry->ddpf.flags & DDS_ALPHA)
{
if (ddpf.RGBBitCount == entry->ddpf.RGBBitCount
&& ddpf.ABitMask == entry->ddpf.ABitMask)
if (ddpf.ABitMask == entry->ddpf.ABitMask)
break;
}
else if (entry->ddpf.flags & DDS_LUMINANCE)
@ -235,47 +239,52 @@ namespace
if (entry->ddpf.flags & DDS_ALPHAPIXELS)
{
// LUMINANCEA
if (ddpf.RGBBitCount == entry->ddpf.RGBBitCount
&& ddpf.RBitMask == entry->ddpf.RBitMask
if (ddpf.RBitMask == entry->ddpf.RBitMask
&& ddpf.ABitMask == entry->ddpf.ABitMask)
break;
}
else
{
// LUMINANCE
if (ddpf.RGBBitCount == entry->ddpf.RGBBitCount
&& ddpf.RBitMask == entry->ddpf.RBitMask)
if (ddpf.RBitMask == entry->ddpf.RBitMask)
break;
}
}
else if (entry->ddpf.flags & DDS_BUMPDUDV)
{
if (ddpf.RGBBitCount == entry->ddpf.RGBBitCount
&& ddpf.RBitMask == entry->ddpf.RBitMask
if (entry->ddpf.flags & DDS_ALPHAPIXELS)
{
// BUMPDUDVA
if (ddpf.RBitMask == entry->ddpf.RBitMask
&& ddpf.ABitMask == entry->ddpf.ABitMask)
{
flags &= ~DDS_FLAGS_NO_R10B10G10A2_FIXUP;
break;
}
}
else
{
// BUMPDUDV
if (ddpf.RBitMask == entry->ddpf.RBitMask)
break;
}
}
else if (entry->ddpf.flags & DDS_ALPHAPIXELS)
{
// RGBA
if (ddpf.RBitMask == entry->ddpf.RBitMask
&& ddpf.GBitMask == entry->ddpf.GBitMask
&& ddpf.BBitMask == entry->ddpf.BBitMask
&& ddpf.ABitMask == entry->ddpf.ABitMask)
break;
}
else if (ddpf.RGBBitCount == entry->ddpf.RGBBitCount)
else
{
if (entry->ddpf.flags & DDS_ALPHAPIXELS)
{
// RGBA
if (ddpf.RBitMask == entry->ddpf.RBitMask
&& ddpf.GBitMask == entry->ddpf.GBitMask
&& ddpf.BBitMask == entry->ddpf.BBitMask
&& ddpf.ABitMask == entry->ddpf.ABitMask)
break;
}
else
{
// RGB
if (ddpf.RBitMask == entry->ddpf.RBitMask
&& ddpf.GBitMask == entry->ddpf.GBitMask
&& ddpf.BBitMask == entry->ddpf.BBitMask)
break;
}
// RGB
if (ddpf.RBitMask == entry->ddpf.RBitMask
&& ddpf.GBitMask == entry->ddpf.GBitMask
&& ddpf.BBitMask == entry->ddpf.BBitMask)
break;
}
}
}
@ -326,7 +335,7 @@ namespace
*ddPixelFormat = {};
}
if (size < (sizeof(DDS_HEADER) + sizeof(uint32_t)))
if (size < DDS_MIN_HEADER_SIZE)
{
return HRESULT_E_INVALID_DATA;
}
@ -369,8 +378,10 @@ namespace
}
metadata.mipLevels = pHeader->mipMapCount;
if (metadata.mipLevels == 0)
if ((metadata.mipLevels == 0) || (flags & DDS_FLAGS_IGNORE_MIPS))
{
metadata.mipLevels = 1;
}
// Check for DX10 extension
if ((pHeader->ddspf.flags & DDS_FOURCC)
@ -384,18 +395,18 @@ namespace
}
// Buffer must be big enough for both headers and magic value
if (size < (sizeof(DDS_HEADER) + sizeof(uint32_t) + sizeof(DDS_HEADER_DXT10)))
if (size < DDS_DX10_HEADER_SIZE)
{
return E_FAIL;
}
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>(static_cast<const uint8_t*>(pSource) + sizeof(uint32_t) + sizeof(DDS_HEADER));
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>(static_cast<const uint8_t*>(pSource) + DDS_MIN_HEADER_SIZE);
convFlags |= CONV_FLAGS_DX10;
metadata.arraySize = d3d10ext->arraySize;
if (metadata.arraySize == 0)
{
return HRESULT_E_INVALID_DATA;
metadata.arraySize = 1;
}
metadata.format = d3d10ext->dxgiFormat;
@ -664,7 +675,7 @@ _Use_decl_annotations_
HRESULT DirectX::EncodeDDSHeader(
const TexMetadata& metadata,
DDS_FLAGS flags,
void* pDestination,
uint8_t* pDestination,
size_t maxsize,
size_t& required) noexcept
{
@ -824,7 +835,7 @@ HRESULT DirectX::EncodeDDSHeader(
}
}
required = sizeof(uint32_t) + sizeof(DDS_HEADER);
required = DDS_MIN_HEADER_SIZE;
if (ddpf.size == 0)
{
@ -840,7 +851,7 @@ HRESULT DirectX::EncodeDDSHeader(
if (maxsize < required)
return E_NOT_SUFFICIENT_BUFFER;
*static_cast<uint32_t*>(pDestination) = DDS_MAGIC;
*reinterpret_cast<uint32_t*>(pDestination) = DDS_MAGIC;
auto header = reinterpret_cast<DDS_HEADER*>(static_cast<uint8_t*>(pDestination) + sizeof(uint32_t));
assert(header);
@ -996,7 +1007,10 @@ namespace
TEXP_LEGACY_B4G4R4A4,
TEXP_LEGACY_L8,
TEXP_LEGACY_L16,
TEXP_LEGACY_A8L8
TEXP_LEGACY_A8L8,
TEXP_LEGACY_L6V5U5,
TEXP_LEGACY_X8L8V8U8,
TEXP_LEGACY_A2W10V10U10
};
constexpr TEXP_LEGACY_FORMAT FindLegacyFormat(uint32_t flags) noexcept
@ -1023,6 +1037,12 @@ namespace
lformat = TEXP_LEGACY_L16;
else if (flags & CONV_FLAGS_A8L8)
lformat = TEXP_LEGACY_A8L8;
else if (flags & CONV_FLAGS_L6V5U5)
lformat = TEXP_LEGACY_L6V5U5;
else if (flags & CONV_FLAGS_L8U8V8)
lformat = TEXP_LEGACY_X8L8V8U8;
else if (flags & CONV_FLAGS_WUV10)
lformat = TEXP_LEGACY_A2W10V10U10;
return lformat;
}
@ -1328,11 +1348,120 @@ namespace
}
return false;
case TEXP_LEGACY_L6V5U5:
if (outFormat != DXGI_FORMAT_R8G8B8A8_UNORM)
return false;
// D3DFMT_L6V5U5 -> DXGI_FORMAT_R8G8B8A8_UNORM (LUVA)
if (inSize >= 2 && outSize >= 4)
{
const uint16_t* __restrict sPtr = static_cast<const uint16_t*>(pSource);
uint32_t * __restrict dPtr = static_cast<uint32_t*>(pDestination);
for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 3))); icount += 2, ocount += 4)
{
const uint16_t t = *(sPtr++);
// Converts unsigned 6-bit/signed 5-bit/signed 5-bit bump luminance to 8:8:8:8 unsigned
uint32_t t1 = ((t & 0xFC00) >> 8) | ((t & 0xC000) >> 14);
constexpr int m = 1U << 4;
int8_t v = ((((t >> 5) & 0x1f) ^ m) - m) + 16;
int8_t u = (((t & 0x1f) ^ m) - m) + 16;
auto t2 = static_cast<uint32_t>(u << 3 | u >> 2);
auto t3 = static_cast<uint32_t>(v << 3 | v >> 2);
*(dPtr++) = t1 | (t2 << 8) | (t3 << 16) | 0xff000000;
}
return true;
}
return false;
default:
return false;
}
}
_Success_(return)
bool LegacyConvertScanline(
_Out_writes_bytes_(outSize) void* pDestination,
size_t outSize,
_In_ DXGI_FORMAT outFormat,
_In_reads_bytes_(inSize) const void* pSource,
size_t inSize,
_In_ TEXP_LEGACY_FORMAT inFormat,
uint32_t tflags) noexcept
{
assert(pDestination && outSize > 0);
assert(pSource && inSize > 0);
switch (inFormat)
{
case TEXP_LEGACY_X8L8V8U8:
if (outFormat != DXGI_FORMAT_R8G8B8A8_UNORM)
return false;
// D3DFMT_X8L8V8U8 -> DXGI_FORMAT_R8G8B8A8_UNORM (LUVA)
if (inSize >= 4 && outSize >= 4)
{
auto sPtr = static_cast<const uint32_t*>(pSource);
auto dPtr = static_cast<uint32_t*>(pDestination);
for (size_t ocount = 0, icount = 0; ((icount < (inSize - 3)) && (ocount < (outSize - 3))); icount += 4, ocount += 4)
{
const uint32_t t = *(sPtr++);
// Converts 8-bit unsigned / 8-bit signed / 8-bit signed to 8:8:8:8 unsigned
uint32_t t1 = (t >> 16) & 0xff;
constexpr int m = 1U << 7;
uint32_t v = ((((t >> 8) & 0xff) ^ m) - m) + 128;
uint32_t u = (((t & 0xff) ^ m) - m) + 128;
uint32_t t2 = u << 8;
uint32_t t3 = v << 16;
*(dPtr++) = t1 | t2 | t3 | 0xff000000;
}
return true;
}
return false;
case TEXP_LEGACY_A2W10V10U10:
if (outFormat != DXGI_FORMAT_R10G10B10A2_UNORM)
return false;
// D3DFMT_A2W10V10U10 -> DXGI_FORMAT_R10G10B10A2_UNORM (UVWA)
if (inSize >= 4 && outSize >= 4)
{
auto sPtr = static_cast<const uint32_t*>(pSource);
auto dPtr = static_cast<uint32_t*>(pDestination);
for (size_t ocount = 0, icount = 0; ((icount < (inSize - 3)) && (ocount < (outSize - 3))); icount += 4, ocount += 4)
{
const uint32_t t = *(sPtr++);
// Converts 2-bit unsigned / 10-bit signed / 10-bit signed / 10-bit signed to 2:10:10:10 unsigned
constexpr int m = 1U << 9;
uint32_t w = ((((t >> 20) & 0x3ff) ^ m) - m) + 512;
uint32_t v = ((((t >> 10) & 0x3ff) ^ m) - m) + 512;
uint32_t u = (((t & 0x3ff) ^ m) - m) + 512;
uint32_t t1 = u;
uint32_t t2 = v << 10;
uint32_t t3 = w << 20;
uint32_t ta = (tflags & TEXP_SCANLINE_SETALPHA) ? 0xC0000000 : (t & 0xC0000000);
*(dPtr++) = t1 | t2 | t3 | ta;
}
return true;
}
return false;
default:
return false;
}
}
//-------------------------------------------------------------------------------------
// Converts or copies image data from pPixels into scratch image data
@ -1356,7 +1485,7 @@ namespace
{
if (convFlags & CONV_FLAGS_888)
cpFlags |= CP_FLAGS_24BPP;
else if (convFlags & (CONV_FLAGS_565 | CONV_FLAGS_5551 | CONV_FLAGS_4444 | CONV_FLAGS_8332 | CONV_FLAGS_A8P8 | CONV_FLAGS_L16 | CONV_FLAGS_A8L8))
else if (convFlags & (CONV_FLAGS_565 | CONV_FLAGS_5551 | CONV_FLAGS_4444 | CONV_FLAGS_8332 | CONV_FLAGS_A8P8 | CONV_FLAGS_L16 | CONV_FLAGS_A8L8 | CONV_FLAGS_L6V5U5))
cpFlags |= CP_FLAGS_16BPP;
else if (convFlags & (CONV_FLAGS_44 | CONV_FLAGS_332 | CONV_FLAGS_PAL8 | CONV_FLAGS_L8))
cpFlags |= CP_FLAGS_8BPP;
@ -1502,13 +1631,18 @@ namespace
}
else if (convFlags & CONV_FLAGS_SWIZZLE)
{
SwizzleScanline(pDest, dpitch, pSrc, spitch,
metadata.format, tflags);
SwizzleScanline(pDest, dpitch, pSrc, spitch, metadata.format, tflags);
}
else if (convFlags & (CONV_FLAGS_L8U8V8 | CONV_FLAGS_WUV10))
{
const TEXP_LEGACY_FORMAT lformat = FindLegacyFormat(convFlags);
if (!LegacyConvertScanline(pDest, dpitch, metadata.format,
pSrc, spitch, lformat, tflags))
return E_FAIL;
}
else
{
CopyScanline(pDest, dpitch, pSrc, spitch,
metadata.format, tflags);
CopyScanline(pDest, dpitch, pSrc, spitch, metadata.format, tflags);
}
pSrc += spitch;
@ -1605,6 +1739,13 @@ namespace
{
SwizzleScanline(pDest, dpitch, pSrc, spitch, metadata.format, tflags);
}
else if (convFlags & (CONV_FLAGS_L8U8V8 | CONV_FLAGS_WUV10))
{
const TEXP_LEGACY_FORMAT lformat = FindLegacyFormat(convFlags);
if (!LegacyConvertScanline(pDest, dpitch, metadata.format,
pSrc, spitch, lformat, tflags))
return E_FAIL;
}
else
{
CopyScanline(pDest, dpitch, pSrc, spitch, metadata.format, tflags);
@ -1662,6 +1803,14 @@ namespace
{
SwizzleScanline(pPixels, rowPitch, pPixels, rowPitch, metadata.format, tflags);
}
else if (convFlags & (CONV_FLAGS_L8U8V8 | CONV_FLAGS_WUV10))
{
const TEXP_LEGACY_FORMAT lformat = FindLegacyFormat(convFlags);
if (!LegacyConvertScanline(pPixels, rowPitch, metadata.format, pPixels, rowPitch, lformat, tflags))
{
return E_UNEXPECTED;
}
}
else
{
CopyScanline(pPixels, rowPitch, pPixels, rowPitch, metadata.format, tflags);
@ -1686,7 +1835,7 @@ namespace
_Use_decl_annotations_
HRESULT DirectX::GetMetadataFromDDSMemory(
const void* pSource,
const uint8_t* pSource,
size_t size,
DDS_FLAGS flags,
TexMetadata& metadata) noexcept
@ -1696,7 +1845,7 @@ HRESULT DirectX::GetMetadataFromDDSMemory(
_Use_decl_annotations_
HRESULT DirectX::GetMetadataFromDDSMemoryEx(
const void* pSource,
const uint8_t* pSource,
size_t size,
DDS_FLAGS flags,
TexMetadata& metadata,
@ -1774,24 +1923,24 @@ HRESULT DirectX::GetMetadataFromDDSFileEx(
#endif
// Need at least enough data to fill the standard header and magic number to be a valid DDS
if (len < (sizeof(DDS_HEADER) + sizeof(uint32_t)))
if (len < DDS_MIN_HEADER_SIZE)
{
return E_FAIL;
}
// Read the header in (including extended header if present)
uint8_t header[MAX_HEADER_SIZE] = {};
uint8_t header[DDS_DX10_HEADER_SIZE] = {};
#ifdef _WIN32
DWORD bytesRead = 0;
if (!ReadFile(hFile.get(), header, MAX_HEADER_SIZE, &bytesRead, nullptr))
if (!ReadFile(hFile.get(), header, DDS_DX10_HEADER_SIZE, &bytesRead, nullptr))
{
return HRESULT_FROM_WIN32(GetLastError());
}
auto const headerLen = static_cast<size_t>(bytesRead);
#else
auto const headerLen = std::min<size_t>(len, MAX_HEADER_SIZE);
auto const headerLen = std::min<size_t>(len, DDS_DX10_HEADER_SIZE);
inFile.read(reinterpret_cast<char*>(header), headerLen);
if (!inFile)
@ -1808,7 +1957,7 @@ HRESULT DirectX::GetMetadataFromDDSFileEx(
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT DirectX::LoadFromDDSMemory(
const void* pSource,
const uint8_t* pSource,
size_t size,
DDS_FLAGS flags,
TexMetadata* metadata,
@ -1819,7 +1968,7 @@ HRESULT DirectX::LoadFromDDSMemory(
_Use_decl_annotations_
HRESULT DirectX::LoadFromDDSMemoryEx(
const void* pSource,
const uint8_t* pSource,
size_t size,
DDS_FLAGS flags,
TexMetadata* metadata,
@ -1837,7 +1986,7 @@ HRESULT DirectX::LoadFromDDSMemoryEx(
if (FAILED(hr))
return hr;
size_t offset = sizeof(uint32_t) + sizeof(DDS_HEADER);
size_t offset = DDS_MIN_HEADER_SIZE;
if (convFlags & CONV_FLAGS_DX10)
offset += sizeof(DDS_HEADER_DXT10);
@ -1958,24 +2107,24 @@ HRESULT DirectX::LoadFromDDSFileEx(
#endif
// Need at least enough data to fill the standard header and magic number to be a valid DDS
if (len < (sizeof(DDS_HEADER) + sizeof(uint32_t)))
if (len < DDS_MIN_HEADER_SIZE)
{
return E_FAIL;
}
// Read the header in (including extended header if present)
uint8_t header[MAX_HEADER_SIZE] = {};
uint8_t header[DDS_DX10_HEADER_SIZE] = {};
#ifdef _WIN32
DWORD bytesRead = 0;
if (!ReadFile(hFile.get(), header, MAX_HEADER_SIZE, &bytesRead, nullptr))
if (!ReadFile(hFile.get(), header, DDS_DX10_HEADER_SIZE, &bytesRead, nullptr))
{
return HRESULT_FROM_WIN32(GetLastError());
}
auto const headerLen = static_cast<size_t>(bytesRead);
#else
auto const headerLen = std::min<size_t>(len, MAX_HEADER_SIZE);
auto const headerLen = std::min<size_t>(len, DDS_DX10_HEADER_SIZE);
inFile.read(reinterpret_cast<char*>(header), headerLen);
if (!inFile)
@ -1988,24 +2137,24 @@ HRESULT DirectX::LoadFromDDSFileEx(
if (FAILED(hr))
return hr;
size_t offset = MAX_HEADER_SIZE;
size_t offset = DDS_DX10_HEADER_SIZE;
if (!(convFlags & CONV_FLAGS_DX10))
{
#ifdef _WIN32
// Must reset file position since we read more than the standard header above
const LARGE_INTEGER filePos = { { sizeof(uint32_t) + sizeof(DDS_HEADER), 0 } };
const LARGE_INTEGER filePos = { { DDS_MIN_HEADER_SIZE, 0 } };
if (!SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN))
{
return HRESULT_FROM_WIN32(GetLastError());
}
#else
inFile.seekg(sizeof(uint32_t) + sizeof(DDS_HEADER), std::ios::beg);
inFile.seekg(DDS_MIN_HEADER_SIZE, std::ios::beg);
if (!inFile)
return E_FAIL;
#endif
offset = sizeof(uint32_t) + sizeof(DDS_HEADER);
offset = DDS_MIN_HEADER_SIZE;
}
std::unique_ptr<uint32_t[]> pal8;
@ -2133,7 +2282,7 @@ HRESULT DirectX::LoadFromDDSFileEx(
}
#endif
if (convFlags & (CONV_FLAGS_SWIZZLE | CONV_FLAGS_NOALPHA))
if (convFlags & (CONV_FLAGS_SWIZZLE | CONV_FLAGS_NOALPHA | CONV_FLAGS_L8U8V8 | CONV_FLAGS_WUV10))
{
// Swizzle/copy image in place
hr = CopyImageInPlace(convFlags, image);
@ -2206,7 +2355,7 @@ HRESULT DirectX::SaveToDDSMemory(
if (FAILED(hr))
return hr;
auto pDestination = static_cast<uint8_t*>(blob.GetBufferPointer());
auto pDestination = blob.GetBufferPointer();
assert(pDestination);
hr = EncodeDDSHeader(metadata, flags, pDestination, blob.GetBufferSize(), required);
@ -2391,9 +2540,9 @@ HRESULT DirectX::SaveToDDSFile(
return E_INVALIDARG;
// Create DDS Header
uint8_t header[MAX_HEADER_SIZE];
uint8_t header[DDS_DX10_HEADER_SIZE];
size_t required;
HRESULT hr = EncodeDDSHeader(metadata, flags, header, MAX_HEADER_SIZE, required);
HRESULT hr = EncodeDDSHeader(metadata, flags, header, DDS_DX10_HEADER_SIZE, required);
if (FAILED(hr))
return hr;

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

@ -94,7 +94,7 @@ namespace
// Decodes HDR header
//-------------------------------------------------------------------------------------
HRESULT DecodeHDRHeader(
_In_reads_bytes_(size) const void* pSource,
_In_reads_bytes_(size) const uint8_t* pSource,
size_t size,
_Out_ TexMetadata& metadata,
size_t& offset,
@ -121,7 +121,7 @@ namespace
// Process first part of header
bool formatFound = false;
auto info = static_cast<const char*>(pSource);
auto info = reinterpret_cast<const char*>(pSource);
while (size > 0)
{
if (*info == '\n')
@ -310,7 +310,7 @@ namespace
return E_FAIL;
}
offset = size_t(info - static_cast<const char*>(pSource));
offset = size_t(info - reinterpret_cast<const char*>(pSource));
metadata.width = width;
metadata.height = height;
@ -600,7 +600,7 @@ namespace
// Obtain metadata from HDR file in memory/on disk
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT DirectX::GetMetadataFromHDRMemory(const void* pSource, size_t size, TexMetadata& metadata) noexcept
HRESULT DirectX::GetMetadataFromHDRMemory(const uint8_t* pSource, size_t size, TexMetadata& metadata) noexcept
{
if (!pSource || size == 0)
return E_INVALIDARG;
@ -696,7 +696,7 @@ HRESULT DirectX::GetMetadataFromHDRFile(const wchar_t* szFile, TexMetadata& meta
// Load a HDR file in memory
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata* metadata, ScratchImage& image) noexcept
HRESULT DirectX::LoadFromHDRMemory(const uint8_t* pSource, size_t size, TexMetadata* metadata, ScratchImage& image) noexcept
{
if (!pSource || size == 0)
return E_INVALIDARG;
@ -1045,7 +1045,7 @@ HRESULT DirectX::SaveToHDRMemory(const Image& image, Blob& blob) noexcept
return hr;
// Copy header
auto dPtr = static_cast<uint8_t*>(blob.GetBufferPointer());
auto dPtr = blob.GetBufferPointer();
assert(dPtr != nullptr);
memcpy(dPtr, header, headerLen);
dPtr += headerLen;
@ -1097,7 +1097,7 @@ HRESULT DirectX::SaveToHDRMemory(const Image& image, Blob& blob) noexcept
}
#endif
hr = blob.Trim(size_t(dPtr - static_cast<uint8_t*>(blob.GetBufferPointer())));
hr = blob.Trim(size_t(dPtr - blob.GetConstBufferPointer()));
if (FAILED(hr))
{
blob.Release();
@ -1184,7 +1184,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce
#ifdef _WIN32
auto const bytesToWrite = static_cast<const DWORD>(blob.GetBufferSize());
DWORD bytesWritten;
if (!WriteFile(hFile.get(), blob.GetBufferPointer(), bytesToWrite, &bytesWritten, nullptr))
if (!WriteFile(hFile.get(), blob.GetConstBufferPointer(), bytesToWrite, &bytesWritten, nullptr))
{
return HRESULT_FROM_WIN32(GetLastError());
}
@ -1194,7 +1194,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce
return E_FAIL;
}
#else
outFile.write(reinterpret_cast<char*>(blob.GetBufferPointer()),
outFile.write(reinterpret_cast<const char*>(blob.GetConstBufferPointer()),
static_cast<std::streamsize>(blob.GetBufferSize()));
if (!outFile)

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

@ -2955,7 +2955,7 @@ HRESULT DirectX::GenerateMipMaps(
mdata.mipLevels = levels;
mdata.format = baseImage.format;
unsigned long filter_select = (filter & TEX_FILTER_MODE_MASK);
uint32_t filter_select = (filter & TEX_FILTER_MODE_MASK);
if (!filter_select)
{
// Default filter choice
@ -3170,7 +3170,7 @@ HRESULT DirectX::GenerateMipMaps(
TexMetadata mdata2 = metadata;
mdata2.mipLevels = levels;
unsigned long filter_select = (filter & TEX_FILTER_MODE_MASK);
uint32_t filter_select = (filter & TEX_FILTER_MODE_MASK);
if (!filter_select)
{
// Default filter choice
@ -3300,7 +3300,7 @@ HRESULT DirectX::GenerateMipMaps3D(
HRESULT hr = E_UNEXPECTED;
unsigned long filter_select = (filter & TEX_FILTER_MODE_MASK);
uint32_t filter_select = (filter & TEX_FILTER_MODE_MASK);
if (!filter_select)
{
// Default filter choice
@ -3419,7 +3419,7 @@ HRESULT DirectX::GenerateMipMaps3D(
static_assert(TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MODE_MASK");
unsigned long filter_select = (filter & TEX_FILTER_MODE_MASK);
uint32_t filter_select = (filter & TEX_FILTER_MODE_MASK);
if (!filter_select)
{
// Default filter choice

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

@ -811,7 +811,7 @@ namespace
static_assert(TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MASK");
unsigned long filter_select = filter & TEX_FILTER_MODE_MASK;
uint32_t filter_select = filter & TEX_FILTER_MODE_MASK;
if (!filter_select)
{
// Default filter choice

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

@ -139,7 +139,7 @@ namespace
// Decodes TGA header
//-------------------------------------------------------------------------------------
HRESULT DecodeTGAHeader(
_In_reads_bytes_(size) const void* pSource,
_In_reads_bytes_(size) const uint8_t* pSource,
size_t size,
TGA_FLAGS flags,
_Out_ TexMetadata& metadata,
@ -156,7 +156,7 @@ namespace
return HRESULT_E_INVALID_DATA;
}
auto pHeader = static_cast<const TGA_HEADER*>(pSource);
auto pHeader = reinterpret_cast<const TGA_HEADER*>(pSource);
if (pHeader->bDescriptor & (TGA_FLAGS_INTERLEAVED_2WAY | TGA_FLAGS_INTERLEAVED_4WAY))
{
@ -1447,7 +1447,7 @@ namespace
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT DirectX::GetMetadataFromTGAMemory(
const void* pSource,
const uint8_t* pSource,
size_t size,
TGA_FLAGS flags,
TexMetadata& metadata) noexcept
@ -1641,7 +1641,7 @@ HRESULT DirectX::GetMetadataFromTGAFile(const wchar_t* szFile, TGA_FLAGS flags,
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT DirectX::LoadFromTGAMemory(
const void* pSource,
const uint8_t* pSource,
size_t size,
TGA_FLAGS flags,
TexMetadata* metadata,
@ -2279,7 +2279,7 @@ HRESULT DirectX::SaveToTGAMemory(
return hr;
// Copy header
auto destPtr = static_cast<uint8_t*>(blob.GetBufferPointer());
auto destPtr = blob.GetBufferPointer();
assert(destPtr != nullptr);
uint8_t* dPtr = destPtr;
@ -2396,7 +2396,7 @@ HRESULT DirectX::SaveToTGAFile(
#ifdef _WIN32
const DWORD bytesToWrite = static_cast<DWORD>(blob.GetBufferSize());
DWORD bytesWritten;
if (!WriteFile(hFile.get(), blob.GetBufferPointer(), bytesToWrite, &bytesWritten, nullptr))
if (!WriteFile(hFile.get(), blob.GetConstBufferPointer(), bytesToWrite, &bytesWritten, nullptr))
{
return HRESULT_FROM_WIN32(GetLastError());
}
@ -2406,7 +2406,7 @@ HRESULT DirectX::SaveToTGAFile(
return E_FAIL;
}
#else
outFile.write(reinterpret_cast<char*>(blob.GetBufferPointer()),
outFile.write(reinterpret_cast<const char*>(blob.GetConstBufferPointer()),
static_cast<std::streamsize>(blob.GetBufferSize()));
if (!outFile)

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

@ -920,6 +920,45 @@ size_t DirectX::BitsPerColor(DXGI_FORMAT fmt) noexcept
}
//-------------------------------------------------------------------------------------
// Returns bytes per block for a given DXGI BC format, or 0 on failure
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
size_t DirectX::BytesPerBlock(DXGI_FORMAT fmt) noexcept
{
switch (fmt)
{
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC1_UNORM:
case DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT_BC4_TYPELESS:
case DXGI_FORMAT_BC4_UNORM:
case DXGI_FORMAT_BC4_SNORM:
return 8;
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_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 16;
default:
return 0;
}
}
//-------------------------------------------------------------------------------------
// Computes the image row pitch in bytes, and the slice ptich (size in bytes of the image)
// based on DXGI format, width, and height
@ -1649,7 +1688,7 @@ HRESULT Blob::Initialize(size_t size) noexcept
Release();
m_buffer = _aligned_malloc(size, 16);
m_buffer = reinterpret_cast<uint8_t*>(_aligned_malloc(size, 16));
if (!m_buffer)
{
Release();
@ -1685,7 +1724,7 @@ HRESULT Blob::Resize(size_t size) noexcept
if (!m_buffer || !m_size)
return E_UNEXPECTED;
void *tbuffer = _aligned_malloc(size, 16);
auto tbuffer = reinterpret_cast<uint8_t*>(_aligned_malloc(size, 16));
if (!tbuffer)
return E_OUTOFMEMORY;

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

@ -208,7 +208,7 @@ namespace
m_streamEOF(0),
mRefCount(1)
{
assert(mBlob.GetBufferPointer() && mBlob.GetBufferSize() > 0);
assert(mBlob.GetConstBufferPointer() && mBlob.GetBufferSize() > 0);
}
public:
@ -254,7 +254,7 @@ namespace
HRESULT STDMETHODCALLTYPE Read(void* pv, ULONG cb, ULONG* pcbRead) override
{
size_t maxRead = m_streamEOF - m_streamPosition;
auto ptr = static_cast<const uint8_t*>(mBlob.GetBufferPointer());
auto ptr = mBlob.GetBufferPointer();
if (cb > maxRead)
{
const uint64_t pos = uint64_t(m_streamPosition) + uint64_t(maxRead);
@ -324,7 +324,7 @@ namespace
if (pos > UINT32_MAX)
return HRESULT_E_ARITHMETIC_OVERFLOW;
auto ptr = static_cast<uint8_t*>(mBlob.GetBufferPointer());
auto ptr = mBlob.GetBufferPointer();
memcpy(&ptr[m_streamPosition], pv, cb);
m_streamPosition = static_cast<size_t>(pos);
@ -347,7 +347,7 @@ namespace
if (blobSize >= size.LowPart)
{
auto ptr = static_cast<uint8_t*>(mBlob.GetBufferPointer());
auto ptr = mBlob.GetBufferPointer();
if (m_streamEOF < size.LowPart)
{
memset(&ptr[m_streamEOF], 0, size.LowPart - m_streamEOF);
@ -367,7 +367,7 @@ namespace
if (FAILED(hr))
return hr;
auto ptr = static_cast<uint8_t*>(mBlob.GetBufferPointer());
auto ptr = mBlob.GetBufferPointer();
if (m_streamEOF < size.LowPart)
{
memset(&ptr[m_streamEOF], 0, size.LowPart - m_streamEOF);
@ -1221,7 +1221,7 @@ namespace
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT DirectX::GetMetadataFromWICMemory(
const void* pSource,
const uint8_t* pSource,
size_t size,
WIC_FLAGS flags,
TexMetadata& metadata,
@ -1244,7 +1244,7 @@ HRESULT DirectX::GetMetadataFromWICMemory(
if (FAILED(hr))
return hr;
hr = stream->InitializeFromMemory(static_cast<BYTE*>(const_cast<void*>(pSource)),
hr = stream->InitializeFromMemory(static_cast<BYTE*>(const_cast<uint8_t*>(pSource)),
static_cast<UINT>(size));
if (FAILED(hr))
return hr;
@ -1312,7 +1312,7 @@ HRESULT DirectX::GetMetadataFromWICFile(
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT DirectX::LoadFromWICMemory(
const void* pSource,
const uint8_t* pSource,
size_t size,
WIC_FLAGS flags,
TexMetadata* metadata,
@ -1338,7 +1338,7 @@ HRESULT DirectX::LoadFromWICMemory(
if (FAILED(hr))
return hr;
hr = stream->InitializeFromMemory(static_cast<uint8_t*>(const_cast<void*>(pSource)), static_cast<DWORD>(size));
hr = stream->InitializeFromMemory(static_cast<uint8_t*>(const_cast<uint8_t*>(pSource)), static_cast<DWORD>(size));
if (FAILED(hr))
return hr;

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

@ -41,6 +41,9 @@
#include <d3d11_1.h>
#endif
#include <cstdint>
#include <utility>
#define DIRECTX_TEX_XBOX_VERSION 150
namespace Xbox
@ -69,12 +72,12 @@ namespace Xbox
XboxImage(const XboxImage&) = delete;
XboxImage& operator=(const XboxImage&) = delete;
HRESULT Initialize(_In_ const XG_TEXTURE1D_DESC& desc, _In_ const XG_RESOURCE_LAYOUT& layout, _In_ uint32_t miscFlags2 = 0);
HRESULT Initialize(_In_ const XG_TEXTURE2D_DESC& desc, _In_ const XG_RESOURCE_LAYOUT& layout, _In_ uint32_t miscFlags2 = 0);
HRESULT Initialize(_In_ const XG_TEXTURE3D_DESC& desc, _In_ const XG_RESOURCE_LAYOUT& layout, _In_ uint32_t miscFlags2 = 0);
HRESULT Initialize(_In_ const DirectX::TexMetadata& mdata, _In_ XboxTileMode tm, _In_ uint32_t size, _In_ uint32_t alignment);
HRESULT __cdecl Initialize(_In_ const XG_TEXTURE1D_DESC& desc, _In_ const XG_RESOURCE_LAYOUT& layout, _In_ uint32_t miscFlags2 = 0);
HRESULT __cdecl Initialize(_In_ const XG_TEXTURE2D_DESC& desc, _In_ const XG_RESOURCE_LAYOUT& layout, _In_ uint32_t miscFlags2 = 0);
HRESULT __cdecl Initialize(_In_ const XG_TEXTURE3D_DESC& desc, _In_ const XG_RESOURCE_LAYOUT& layout, _In_ uint32_t miscFlags2 = 0);
HRESULT __cdecl Initialize(_In_ const DirectX::TexMetadata& mdata, _In_ XboxTileMode tm, _In_ uint32_t size, _In_ uint32_t alignment);
void Release();
void __cdecl Release();
const DirectX::TexMetadata& GetMetadata() const { return metadata; }
XboxTileMode GetTileMode() const { return tilemode; }
@ -94,65 +97,65 @@ namespace Xbox
//---------------------------------------------------------------------------------
// Image I/O
HRESULT GetMetadataFromDDSMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
HRESULT __cdecl GetMetadataFromDDSMemory(
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_Out_ DirectX::TexMetadata& metadata, _Out_ bool& isXbox);
HRESULT GetMetadataFromDDSFile(
HRESULT __cdecl GetMetadataFromDDSFile(
_In_z_ const wchar_t* szFile, _Out_ DirectX::TexMetadata& metadata, _Out_ bool& isXbox);
HRESULT GetMetadataFromDDSMemoryEx(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
HRESULT __cdecl GetMetadataFromDDSMemoryEx(
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_Out_ DirectX::TexMetadata& metadata, _Out_ bool& isXbox,
_Out_opt_ DirectX::DDSMetaData* ddPixelFormat);
HRESULT GetMetadataFromDDSFileEx(
HRESULT __cdecl GetMetadataFromDDSFileEx(
_In_z_ const wchar_t* szFile, _Out_ DirectX::TexMetadata& metadata, _Out_ bool& isXbox,
_Out_opt_ DirectX::DDSMetaData* ddPixelFormat);
HRESULT LoadFromDDSMemory(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
HRESULT __cdecl LoadFromDDSMemory(
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_Out_opt_ DirectX::TexMetadata* metadata, _Out_ XboxImage& image);
HRESULT LoadFromDDSFile(
HRESULT __cdecl LoadFromDDSFile(
_In_z_ const wchar_t* szFile,
_Out_opt_ DirectX::TexMetadata* metadata, _Out_ XboxImage& image);
HRESULT LoadFromDDSMemoryEx(
_In_reads_bytes_(size) const void* pSource, _In_ size_t size,
HRESULT __cdecl LoadFromDDSMemoryEx(
_In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size,
_Out_opt_ DirectX::TexMetadata* metadata,
_Out_opt_ DirectX::DDSMetaData* ddPixelFormat,
_Out_ XboxImage& image);
HRESULT LoadFromDDSFileEx(
HRESULT __cdecl LoadFromDDSFileEx(
_In_z_ const wchar_t* szFile,
_Out_opt_ DirectX::TexMetadata* metadata,
_Out_opt_ DirectX::DDSMetaData* ddPixelFormat,
_Out_ XboxImage& image);
HRESULT SaveToDDSMemory(_In_ const XboxImage& xbox, _Out_ DirectX::Blob& blob);
HRESULT SaveToDDSFile(_In_ const XboxImage& xbox, _In_z_ const wchar_t* szFile);
HRESULT __cdecl SaveToDDSMemory(_In_ const XboxImage& xbox, _Out_ DirectX::Blob& blob);
HRESULT __cdecl SaveToDDSFile(_In_ const XboxImage& xbox, _In_z_ const wchar_t* szFile);
//---------------------------------------------------------------------------------
// Xbox Texture Tiling / Detiling (requires XG DLL to be present at runtime)
HRESULT Tile(_In_ const DirectX::Image& srcImage, _Out_ XboxImage& xbox, _In_ XboxTileMode mode = c_XboxTileModeInvalid);
HRESULT Tile(
HRESULT __cdecl Tile(_In_ const DirectX::Image& srcImage, _Out_ XboxImage& xbox, _In_ XboxTileMode mode = c_XboxTileModeInvalid);
HRESULT __cdecl Tile(
_In_ const DirectX::Image* srcImages, _In_ size_t nimages, _In_ const DirectX::TexMetadata& metadata,
_Out_ XboxImage& xbox, _In_ XboxTileMode mode = c_XboxTileModeInvalid);
HRESULT Detile(_In_ const XboxImage& xbox, _Out_ DirectX::ScratchImage& image);
HRESULT __cdecl Detile(_In_ const XboxImage& xbox, _Out_ DirectX::ScratchImage& image);
//---------------------------------------------------------------------------------
// Direct3D 11.X functions
#if defined(_XBOX_ONE) && defined(_TITLE) && defined(__d3d11_x_h__)
HRESULT CreateTexture(
HRESULT __cdecl CreateTexture(
_In_ ID3D11DeviceX* d3dDevice,
_In_ const XboxImage& xbox, _Outptr_opt_ ID3D11Resource** ppResource, _Outptr_ void** grfxMemory);
HRESULT CreateShaderResourceView(
HRESULT __cdecl CreateShaderResourceView(
_In_ ID3D11DeviceX* d3dDevice,
_In_ const XboxImage& xbox, _Outptr_opt_ ID3D11ShaderResourceView** ppSRV, _Outptr_ void** grfxMemory);
void FreeTextureMemory(_In_ ID3D11DeviceX* d3dDevice, _In_opt_ void* grfxMemory);
void __cdecl FreeTextureMemory(_In_ ID3D11DeviceX* d3dDevice, _In_opt_ void* grfxMemory);
#endif
@ -161,12 +164,18 @@ namespace Xbox
#if ((defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)) && (defined(__d3d12_x_h__) || defined(__XBOX_D3D12_X__))
HRESULT CreateTexture(
HRESULT __cdecl CreateTexture(
_In_ ID3D12Device* d3dDevice,
_In_ const XboxImage& xbox, _Outptr_opt_ ID3D12Resource** ppResource, _Outptr_ void** grfxMemory);
void FreeTextureMemory(_In_ ID3D12Device* d3dDevice, _In_opt_ void* grfxMemory);
void __cdecl FreeTextureMemory(_In_ ID3D12Device* d3dDevice, _In_opt_ void* grfxMemory);
#endif
//---------------------------------------------------------------------------------
// DDS helper functions
HRESULT __cdecl EncodeDDSHeader(
const XboxImage& xbox,
_Out_writes_bytes_(maxsize) uint8_t* pDestination, _In_ size_t maxsize) noexcept;
} // namespace

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

@ -23,39 +23,11 @@ using namespace Xbox;
namespace
{
const DDS_PIXELFORMAT DDSPF_XBOX =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('X','B','O','X'), 0, 0, 0, 0, 0 };
#pragma pack(push,1)
struct DDS_HEADER_XBOX
// Must match structure in XboxDDSTextureLoader module
{
DXGI_FORMAT dxgiFormat;
uint32_t resourceDimension;
uint32_t miscFlag; // see DDS_RESOURCE_MISC_FLAG
uint32_t arraySize;
uint32_t miscFlags2; // see DDS_MISC_FLAGS2
uint32_t tileMode; // see XG_TILE_MODE / XG_SWIZZLE_MODE
uint32_t baseAlignment;
uint32_t dataSize;
uint32_t xdkVer; // matching _XDK_VER / _GXDK_VER
};
#pragma pack(pop)
constexpr uint32_t XBOX_TILEMODE_SCARLETT = 0x1000000;
static_assert(sizeof(DDS_HEADER_XBOX) == 36, "DDS XBOX Header size mismatch");
static_assert(sizeof(DDS_HEADER_XBOX) >= sizeof(DDS_HEADER_DXT10), "DDS XBOX Header should be larger than DX10 header");
constexpr size_t XBOX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_XBOX);
//-------------------------------------------------------------------------------------
// Decodes DDS header using XBOX extended header (variant of DX10 header)
//-------------------------------------------------------------------------------------
HRESULT DecodeDDSHeader(
_In_reads_bytes_(size) const void* pSource,
_In_reads_bytes_(size) const uint8_t* pSource,
size_t size,
DirectX::TexMetadata& metadata,
_Out_opt_ DDSMetaData* ddPixelFormat,
@ -86,7 +58,7 @@ namespace
*ddPixelFormat = {};
}
if (size < (sizeof(DDS_HEADER) + sizeof(uint32_t)))
if (size < DDS_MIN_HEADER_SIZE)
{
return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
}
@ -120,13 +92,13 @@ namespace
}
// Buffer must be big enough for both headers and magic value
if (size < XBOX_HEADER_SIZE)
if (size < DDS_XBOX_HEADER_SIZE)
{
return E_FAIL;
}
auto xboxext = reinterpret_cast<const DDS_HEADER_XBOX*>(
reinterpret_cast<const uint8_t*>(pSource) + sizeof(uint32_t) + sizeof(DDS_HEADER));
reinterpret_cast<const uint8_t*>(pSource) + DDS_MIN_HEADER_SIZE);
metadata.arraySize = xboxext->arraySize;
if (metadata.arraySize == 0)
@ -244,159 +216,6 @@ namespace
return S_OK;
}
//-------------------------------------------------------------------------------------
// Encodes DDS file header (magic value, header, XBOX extended header)
//-------------------------------------------------------------------------------------
HRESULT EncodeDDSHeader(
const XboxImage& xbox,
_Out_writes_(maxsize) void* pDestination,
size_t maxsize)
{
if (!pDestination)
return E_POINTER;
if (maxsize < XBOX_HEADER_SIZE)
return E_NOT_SUFFICIENT_BUFFER;
*reinterpret_cast<uint32_t*>(pDestination) = DDS_MAGIC;
auto header = reinterpret_cast<DDS_HEADER*>(reinterpret_cast<uint8_t*>(pDestination) + sizeof(uint32_t));
memset(header, 0, sizeof(DDS_HEADER));
header->size = sizeof(DDS_HEADER);
header->flags = DDS_HEADER_FLAGS_TEXTURE;
header->caps = DDS_SURFACE_FLAGS_TEXTURE;
auto& metadata = xbox.GetMetadata();
if (metadata.mipLevels > 0)
{
header->flags |= DDS_HEADER_FLAGS_MIPMAP;
if (metadata.mipLevels > UINT32_MAX)
return E_INVALIDARG;
header->mipMapCount = static_cast<uint32_t>(metadata.mipLevels);
if (header->mipMapCount > 1)
header->caps |= DDS_SURFACE_FLAGS_MIPMAP;
}
switch (metadata.dimension)
{
case TEX_DIMENSION_TEXTURE1D:
if (metadata.width > UINT32_MAX)
return E_INVALIDARG;
header->width = static_cast<uint32_t>(metadata.width);
header->height = header->depth = 1;
break;
case TEX_DIMENSION_TEXTURE2D:
if (metadata.height > UINT32_MAX
|| metadata.width > UINT32_MAX)
return E_INVALIDARG;
header->height = static_cast<uint32_t>(metadata.height);
header->width = static_cast<uint32_t>(metadata.width);
header->depth = 1;
if (metadata.IsCubemap())
{
header->caps |= DDS_SURFACE_FLAGS_CUBEMAP;
header->caps2 |= DDS_CUBEMAP_ALLFACES;
}
break;
case TEX_DIMENSION_TEXTURE3D:
if (metadata.height > UINT32_MAX
|| metadata.width > UINT32_MAX
|| metadata.depth > UINT32_MAX)
return E_INVALIDARG;
header->flags |= DDS_HEADER_FLAGS_VOLUME;
header->caps2 |= DDS_FLAGS_VOLUME;
header->height = static_cast<uint32_t>(metadata.height);
header->width = static_cast<uint32_t>(metadata.width);
header->depth = static_cast<uint32_t>(metadata.depth);
break;
default:
return E_FAIL;
}
size_t rowPitch, slicePitch;
ComputePitch(metadata.format, metadata.width, metadata.height, rowPitch, slicePitch, CP_FLAGS_NONE);
if (slicePitch > UINT32_MAX
|| rowPitch > UINT32_MAX)
return E_FAIL;
if (IsCompressed(metadata.format))
{
header->flags |= DDS_HEADER_FLAGS_LINEARSIZE;
header->pitchOrLinearSize = static_cast<uint32_t>(slicePitch);
}
else
{
header->flags |= DDS_HEADER_FLAGS_PITCH;
header->pitchOrLinearSize = static_cast<uint32_t>(rowPitch);
}
memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_XBOX, sizeof(DDS_PIXELFORMAT));
// Setup XBOX extended header
auto xboxext = reinterpret_cast<DDS_HEADER_XBOX*>(reinterpret_cast<uint8_t*>(header) + sizeof(DDS_HEADER));
memset(xboxext, 0, sizeof(DDS_HEADER_XBOX));
xboxext->dxgiFormat = metadata.format;
xboxext->resourceDimension = metadata.dimension;
if (metadata.arraySize > UINT32_MAX)
return E_INVALIDARG;
static_assert(static_cast<int>(TEX_MISC_TEXTURECUBE) == static_cast<int>(DDS_RESOURCE_MISC_TEXTURECUBE), "DDS header mismatch");
xboxext->miscFlag = metadata.miscFlags & ~static_cast<uint32_t>(TEX_MISC_TEXTURECUBE);
if (metadata.miscFlags & TEX_MISC_TEXTURECUBE)
{
xboxext->miscFlag |= TEX_MISC_TEXTURECUBE;
assert((metadata.arraySize % 6) == 0);
xboxext->arraySize = static_cast<UINT>(metadata.arraySize / 6);
}
else
{
xboxext->arraySize = static_cast<UINT>(metadata.arraySize);
}
static_assert(static_cast<int>(TEX_MISC2_ALPHA_MODE_MASK) == static_cast<int>(DDS_MISC_FLAGS2_ALPHA_MODE_MASK), "DDS header mismatch");
static_assert(static_cast<int>(TEX_ALPHA_MODE_UNKNOWN) == static_cast<int>(DDS_ALPHA_MODE_UNKNOWN), "DDS header mismatch");
static_assert(static_cast<int>(TEX_ALPHA_MODE_STRAIGHT) == static_cast<int>(DDS_ALPHA_MODE_STRAIGHT), "DDS header mismatch");
static_assert(static_cast<int>(TEX_ALPHA_MODE_PREMULTIPLIED) == static_cast<int>(DDS_ALPHA_MODE_PREMULTIPLIED), "DDS header mismatch");
static_assert(static_cast<int>(TEX_ALPHA_MODE_OPAQUE) == static_cast<int>(DDS_ALPHA_MODE_OPAQUE), "DDS header mismatch");
static_assert(static_cast<int>(TEX_ALPHA_MODE_CUSTOM) == static_cast<int>(DDS_ALPHA_MODE_CUSTOM), "DDS header mismatch");
xboxext->miscFlags2 = metadata.miscFlags2;
#if defined(_GAMING_XBOX_SCARLETT) || defined(_USE_SCARLETT)
xboxext->tileMode = static_cast<uint32_t>(xbox.GetTileMode()) | XBOX_TILEMODE_SCARLETT;
#else
xboxext->tileMode = static_cast<uint32_t>(xbox.GetTileMode());
#endif
xboxext->baseAlignment = xbox.GetAlignment();
xboxext->dataSize = xbox.GetSize();
#ifdef _GXDK_VER
xboxext->xdkVer = _GXDK_VER;
#elif defined(_XDK_VER)
xboxext->xdkVer = _XDK_VER;
#endif
return S_OK;
}
}
@ -404,13 +223,167 @@ namespace
// Entry-points
//=====================================================================================
//-------------------------------------------------------------------------------------
// Encodes DDS file header (magic value, header, XBOX extended header)
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT Xbox::EncodeDDSHeader(
const XboxImage& xbox,
uint8_t* pDestination,
size_t maxsize) noexcept
{
if (!pDestination)
return E_INVALIDARG;
if (maxsize < DDS_XBOX_HEADER_SIZE)
return E_NOT_SUFFICIENT_BUFFER;
*reinterpret_cast<uint32_t*>(pDestination) = DDS_MAGIC;
auto header = reinterpret_cast<DDS_HEADER*>(reinterpret_cast<uint8_t*>(pDestination) + sizeof(uint32_t));
memset(header, 0, sizeof(DDS_HEADER));
header->size = sizeof(DDS_HEADER);
header->flags = DDS_HEADER_FLAGS_TEXTURE;
header->caps = DDS_SURFACE_FLAGS_TEXTURE;
auto& metadata = xbox.GetMetadata();
if (metadata.mipLevels > 0)
{
header->flags |= DDS_HEADER_FLAGS_MIPMAP;
if (metadata.mipLevels > UINT32_MAX)
return E_INVALIDARG;
header->mipMapCount = static_cast<uint32_t>(metadata.mipLevels);
if (header->mipMapCount > 1)
header->caps |= DDS_SURFACE_FLAGS_MIPMAP;
}
switch (metadata.dimension)
{
case TEX_DIMENSION_TEXTURE1D:
if (metadata.width > UINT32_MAX)
return E_INVALIDARG;
header->width = static_cast<uint32_t>(metadata.width);
header->height = header->depth = 1;
break;
case TEX_DIMENSION_TEXTURE2D:
if (metadata.height > UINT32_MAX
|| metadata.width > UINT32_MAX)
return E_INVALIDARG;
header->height = static_cast<uint32_t>(metadata.height);
header->width = static_cast<uint32_t>(metadata.width);
header->depth = 1;
if (metadata.IsCubemap())
{
header->caps |= DDS_SURFACE_FLAGS_CUBEMAP;
header->caps2 |= DDS_CUBEMAP_ALLFACES;
}
break;
case TEX_DIMENSION_TEXTURE3D:
if (metadata.height > UINT32_MAX
|| metadata.width > UINT32_MAX
|| metadata.depth > UINT32_MAX)
return E_INVALIDARG;
header->flags |= DDS_HEADER_FLAGS_VOLUME;
header->caps2 |= DDS_FLAGS_VOLUME;
header->height = static_cast<uint32_t>(metadata.height);
header->width = static_cast<uint32_t>(metadata.width);
header->depth = static_cast<uint32_t>(metadata.depth);
break;
default:
return E_FAIL;
}
size_t rowPitch, slicePitch;
ComputePitch(metadata.format, metadata.width, metadata.height, rowPitch, slicePitch, CP_FLAGS_NONE);
if (slicePitch > UINT32_MAX
|| rowPitch > UINT32_MAX)
return E_FAIL;
if (IsCompressed(metadata.format))
{
header->flags |= DDS_HEADER_FLAGS_LINEARSIZE;
header->pitchOrLinearSize = static_cast<uint32_t>(slicePitch);
}
else
{
header->flags |= DDS_HEADER_FLAGS_PITCH;
header->pitchOrLinearSize = static_cast<uint32_t>(rowPitch);
}
memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_XBOX, sizeof(DDS_PIXELFORMAT));
// Setup XBOX extended header
auto xboxext = reinterpret_cast<DDS_HEADER_XBOX*>(reinterpret_cast<uint8_t*>(header) + sizeof(DDS_HEADER));
memset(xboxext, 0, sizeof(DDS_HEADER_XBOX));
xboxext->dxgiFormat = metadata.format;
xboxext->resourceDimension = metadata.dimension;
if (metadata.arraySize > UINT32_MAX)
return E_INVALIDARG;
static_assert(static_cast<int>(TEX_MISC_TEXTURECUBE) == static_cast<int>(DDS_RESOURCE_MISC_TEXTURECUBE), "DDS header mismatch");
xboxext->miscFlag = metadata.miscFlags & ~static_cast<uint32_t>(TEX_MISC_TEXTURECUBE);
if (metadata.miscFlags & TEX_MISC_TEXTURECUBE)
{
xboxext->miscFlag |= TEX_MISC_TEXTURECUBE;
assert((metadata.arraySize % 6) == 0);
xboxext->arraySize = static_cast<UINT>(metadata.arraySize / 6);
}
else
{
xboxext->arraySize = static_cast<UINT>(metadata.arraySize);
}
static_assert(static_cast<int>(TEX_MISC2_ALPHA_MODE_MASK) == static_cast<int>(DDS_MISC_FLAGS2_ALPHA_MODE_MASK), "DDS header mismatch");
static_assert(static_cast<int>(TEX_ALPHA_MODE_UNKNOWN) == static_cast<int>(DDS_ALPHA_MODE_UNKNOWN), "DDS header mismatch");
static_assert(static_cast<int>(TEX_ALPHA_MODE_STRAIGHT) == static_cast<int>(DDS_ALPHA_MODE_STRAIGHT), "DDS header mismatch");
static_assert(static_cast<int>(TEX_ALPHA_MODE_PREMULTIPLIED) == static_cast<int>(DDS_ALPHA_MODE_PREMULTIPLIED), "DDS header mismatch");
static_assert(static_cast<int>(TEX_ALPHA_MODE_OPAQUE) == static_cast<int>(DDS_ALPHA_MODE_OPAQUE), "DDS header mismatch");
static_assert(static_cast<int>(TEX_ALPHA_MODE_CUSTOM) == static_cast<int>(DDS_ALPHA_MODE_CUSTOM), "DDS header mismatch");
xboxext->miscFlags2 = metadata.miscFlags2;
#if defined(_GAMING_XBOX_SCARLETT) || defined(_USE_SCARLETT)
xboxext->tileMode = static_cast<uint32_t>(xbox.GetTileMode()) | XBOX_TILEMODE_SCARLETT;
#else
xboxext->tileMode = static_cast<uint32_t>(xbox.GetTileMode());
#endif
xboxext->baseAlignment = xbox.GetAlignment();
xboxext->dataSize = xbox.GetSize();
#ifdef _GXDK_VER
xboxext->xdkVer = _GXDK_VER;
#elif defined(_XDK_VER)
xboxext->xdkVer = _XDK_VER;
#endif
return S_OK;
}
//-------------------------------------------------------------------------------------
// Obtain metadata from DDS file in memory/on disk
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT Xbox::GetMetadataFromDDSMemory(
const void* pSource,
const uint8_t* pSource,
size_t size,
TexMetadata& metadata,
bool& isXbox)
@ -420,7 +393,7 @@ HRESULT Xbox::GetMetadataFromDDSMemory(
_Use_decl_annotations_
HRESULT Xbox::GetMetadataFromDDSMemoryEx(
const void* pSource,
const uint8_t* pSource,
size_t size,
TexMetadata& metadata,
bool& isXbox,
@ -491,16 +464,16 @@ HRESULT Xbox::GetMetadataFromDDSFileEx(
}
// Need at least enough data to fill the standard header and magic number to be a valid DDS
if (fileInfo.EndOfFile.LowPart < (sizeof(DDS_HEADER) + sizeof(uint32_t)))
if (fileInfo.EndOfFile.LowPart < DDS_MIN_HEADER_SIZE)
{
return E_FAIL;
}
// Read the header in (including extended header if present)
uint8_t header[XBOX_HEADER_SIZE] = {};
uint8_t header[DDS_XBOX_HEADER_SIZE] = {};
DWORD bytesRead = 0;
if (!ReadFile(hFile.get(), header, XBOX_HEADER_SIZE, &bytesRead, nullptr))
if (!ReadFile(hFile.get(), header, DDS_XBOX_HEADER_SIZE, &bytesRead, nullptr))
{
return HRESULT_FROM_WIN32(GetLastError());
}
@ -525,7 +498,7 @@ HRESULT Xbox::GetMetadataFromDDSFileEx(
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT Xbox::LoadFromDDSMemory(
const void* pSource,
const uint8_t* pSource,
size_t size,
TexMetadata* metadata,
XboxImage& xbox)
@ -535,7 +508,7 @@ HRESULT Xbox::LoadFromDDSMemory(
_Use_decl_annotations_
HRESULT Xbox::LoadFromDDSMemoryEx(
const void* pSource,
const uint8_t* pSource,
size_t size,
TexMetadata* metadata,
DDSMetaData* ddPixelFormat,
@ -566,13 +539,13 @@ HRESULT Xbox::LoadFromDDSMemoryEx(
return E_FAIL;
}
if (size <= XBOX_HEADER_SIZE)
if (size <= DDS_XBOX_HEADER_SIZE)
{
return E_FAIL;
}
// Copy tiled data
const size_t remaining = size - XBOX_HEADER_SIZE;
const size_t remaining = size - DDS_XBOX_HEADER_SIZE;
if (remaining < dataSize)
{
@ -585,7 +558,7 @@ HRESULT Xbox::LoadFromDDSMemoryEx(
assert(xbox.GetPointer() != nullptr);
memcpy(xbox.GetPointer(), reinterpret_cast<const uint8_t*>(pSource) + XBOX_HEADER_SIZE, dataSize);
memcpy(xbox.GetPointer(), reinterpret_cast<const uint8_t*>(pSource) + DDS_XBOX_HEADER_SIZE, dataSize);
if (metadata)
memcpy(metadata, &mdata, sizeof(TexMetadata));
@ -644,16 +617,16 @@ HRESULT Xbox::LoadFromDDSFileEx(
}
// Need at least enough data to fill the standard header and magic number to be a valid DDS
if (fileInfo.EndOfFile.LowPart < (sizeof(DDS_HEADER) + sizeof(uint32_t)))
if (fileInfo.EndOfFile.LowPart < DDS_MIN_HEADER_SIZE)
{
return E_FAIL;
}
// Read the header in (including extended header if present)
uint8_t header[XBOX_HEADER_SIZE] = {};
uint8_t header[DDS_XBOX_HEADER_SIZE] = {};
DWORD bytesRead = 0;
if (!ReadFile(hFile.get(), header, XBOX_HEADER_SIZE, &bytesRead, nullptr))
if (!ReadFile(hFile.get(), header, DDS_XBOX_HEADER_SIZE, &bytesRead, nullptr))
{
return HRESULT_FROM_WIN32(GetLastError());
}
@ -677,7 +650,7 @@ HRESULT Xbox::LoadFromDDSFileEx(
}
// Read tiled data
const DWORD remaining = fileInfo.EndOfFile.LowPart - XBOX_HEADER_SIZE;
const DWORD remaining = fileInfo.EndOfFile.LowPart - DDS_XBOX_HEADER_SIZE;
if (remaining == 0)
return E_FAIL;
@ -716,15 +689,15 @@ HRESULT Xbox::SaveToDDSMemory(const XboxImage& xbox, Blob& blob)
blob.Release();
HRESULT hr = blob.Initialize(XBOX_HEADER_SIZE + xbox.GetSize());
HRESULT hr = blob.Initialize(DDS_XBOX_HEADER_SIZE + xbox.GetSize());
if (FAILED(hr))
return hr;
// Copy header
auto pDestination = reinterpret_cast<uint8_t*>(blob.GetBufferPointer());
auto pDestination = blob.GetBufferPointer();
assert(pDestination);
hr = EncodeDDSHeader(xbox, pDestination, XBOX_HEADER_SIZE);
hr = EncodeDDSHeader(xbox, pDestination, DDS_XBOX_HEADER_SIZE);
if (FAILED(hr))
{
blob.Release();
@ -732,8 +705,8 @@ HRESULT Xbox::SaveToDDSMemory(const XboxImage& xbox, Blob& blob)
}
// Copy tiled data
const size_t remaining = blob.GetBufferSize() - XBOX_HEADER_SIZE;
pDestination += XBOX_HEADER_SIZE;
const size_t remaining = blob.GetBufferSize() - DDS_XBOX_HEADER_SIZE;
pDestination += DDS_XBOX_HEADER_SIZE;
if (!remaining)
{
@ -763,8 +736,8 @@ HRESULT Xbox::SaveToDDSFile(const XboxImage& xbox, const wchar_t* szFile)
return E_INVALIDARG;
// Create DDS Header
uint8_t header[XBOX_HEADER_SIZE] = {};
HRESULT hr = EncodeDDSHeader(xbox, header, XBOX_HEADER_SIZE);
uint8_t header[DDS_XBOX_HEADER_SIZE] = {};
HRESULT hr = EncodeDDSHeader(xbox, header, DDS_XBOX_HEADER_SIZE);
if (FAILED(hr))
return hr;
@ -782,12 +755,12 @@ HRESULT Xbox::SaveToDDSFile(const XboxImage& xbox, const wchar_t* szFile)
}
DWORD bytesWritten;
if (!WriteFile(hFile.get(), header, static_cast<DWORD>(XBOX_HEADER_SIZE), &bytesWritten, nullptr))
if (!WriteFile(hFile.get(), header, static_cast<DWORD>(DDS_XBOX_HEADER_SIZE), &bytesWritten, nullptr))
{
return HRESULT_FROM_WIN32(GetLastError());
}
if (bytesWritten != XBOX_HEADER_SIZE)
if (bytesWritten != DDS_XBOX_HEADER_SIZE)
{
return E_FAIL;
}

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

@ -268,10 +268,13 @@
<_ATGFXCPath>$(WindowsSDK_ExecutablePath_x64.Split(';')[0])</_ATGFXCPath>
<_ATGFXCPath>$(_ATGFXCPath.Replace("x64",""))</_ATGFXCPath>
<_ATGFXCPath Condition="'$(_ATGFXCPath)' != '' and !HasTrailingSlash('$(_ATGFXCPath)')">$(_ATGFXCPath)\</_ATGFXCPath>
<_ATGFXCVer>$([System.Text.RegularExpressions.Regex]::Match($(_ATGFXCPath), `10\.0\.\d+\.0`))</_ATGFXCVer>
<_ATGFXCVer Condition="'$(_ATGFXCVer)' != '' and !HasTrailingSlash('$(_ATGFXCVer)')">$(_ATGFXCVer)\</_ATGFXCVer>
</PropertyGroup>
<Exec Condition="!Exists('Shaders/Compiled/BC6HEncode_EncodeBlockCS.inc')" WorkingDirectory="$(ProjectDir)Shaders" Command="CompileShaders" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath)" LogStandardErrorAsError="true" />
<Exec Condition="!Exists('Shaders/Compiled/BC6HEncode_EncodeBlockCS.inc')" WorkingDirectory="$(ProjectDir)Shaders" Command="CompileShaders" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath);WindowsSDKVersion=$(_ATGFXCVer);CompileShadersOutput=$(ProjectDir)Shaders/Compiled" LogStandardErrorAsError="true" />
<PropertyGroup>
<_ATGFXCPath />
<_ATGFXCVer />
</PropertyGroup>
</Target>
<Target Name="ATGDeleteShaders" AfterTargets="Clean">

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

@ -6,7 +6,7 @@ http://go.microsoft.com/fwlink/?LinkId=248926
Copyright (c) Microsoft Corporation.
**June 4, 2024**
**October 28, 2024**
This package contains DirectXTex, a shared source library for reading and writing ``.DDS`` files, and performing various texture content processing operations including resizing, format conversion, mip-map generation, block compression for Direct3D runtime texture resources, and height-map to normal-map conversion. This library makes use of the Windows Image Component (WIC) APIs. It also includes ``.TGA`` and ``.HDR`` readers and writers since these image file formats are commonly used for texture content processing pipelines, but are not currently supported by a built-in WIC codec.
@ -26,6 +26,10 @@ These components are designed to work without requiring any content from the leg
+ Contains optional source files for the DirectXTex library, such as adapter loading functions using the OpenEXR library, Xbox texture tiling extensions, etc.
* ``Common\``
+ Contains shared source headers used by the DirectXTex library and tools.
* ``Texconv\``
+ This DirectXTex sample is an implementation of the [texconv](https://github.com/Microsoft/DirectXTex/wiki/Texconv) command-line texture utility from the DirectX SDK utilizing DirectXTex rather than D3DX.
@ -94,10 +98,33 @@ For a full change history, see [CHANGELOG.md](https://github.com/microsoft/Direc
* The UWP projects and the Win10 classic desktop project include configurations for the ARM64 platform. Building these requires installing the ARM64 toolset.
* When using clang/LLVM for the ARM64 platform, the Windows 11 SDK ([22000](https://walbourn.github.io/windows-sdk-for-windows-11/)) or later is required.
* For ARM64/AArch64 development, the VS 2022 compiler is strongly recommended over the VS 2019 toolset. The Windows SDK (26100 or later) is not compatible with VS 2019 for Win32 on ARM64 development. *Note that the ARM32/AArch32 platform is [deprecated](https://learn.microsoft.com/windows/arm/arm32-to-arm64)*.
* When using clang/LLVM for the ARM64/AArch64 platform, the Windows 11 SDK ([22000](https://walbourn.github.io/windows-sdk-for-windows-11/)) or later is required.
* The ``CompileShaders.cmd`` script must have Windows-style (CRLF) line-endings. If it is changed to Linux-style (LF) line-endings, it can fail to build all the required shaders.
* As of the October 2024 release, the command-line tools also support GNU-style long options using ``--``. All existing switches continue to function, but some of the `-` options are now deprecated per this table:
|texassemble||texconv||texdiag||
|---|---|---|---|---|---|
|-tonemap|--tonemap|-badtails|--bad-tails|-badtails|--bad-tails|
|-bgcolor|--gif-bg-color|-fixbc4x4|--fix-bc-4x4|-ignoremips|--ignore-mips|
|-swizzle|--swizzle|-ignoremips|--ignore-mips|-permissive|--permissive|
|-stripmips|--strip-mips|-inverty|--invert-y|-targetx|--target-x||-targety|--target-y|
|||-keepcoverage|--keep-coverage|||
|||-permissive|--permissive|||
|||-reconstructz|--reconstruct-z|||
|||-rotatecolor|--rotate-color|||
|||-singleproc|--single-proc|||
|||-swizzle|--swizzle|||
|||-tgazeroalpha|--tga-zero-alpha|||
|||-timing|--timing|||
|||-tonemap|--tonemap|||
|||-wiclossless|--wic-lossless|||
|||-wicmulti|--wic-multiframe|||
|||-x2bias|--x2-bias|||
## Support
For questions, consider using [Stack Overflow](https://stackoverflow.com/questions/tagged/directxtk) with the *directxtk* tag, or the [DirectX Discord Server](https://discord.gg/directx) in the *dx12-developers* or *dx9-dx11-developers* channel.

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

@ -9,6 +9,7 @@ if %PROCESSOR_ARCHITECTURE%.==ARM64. (set FXCARCH=arm64) else (if %PROCESSOR_ARC
set FXCOPTS=/nologo /WX /Ges /Zi /Zpc /Qstrip_reflect /Qstrip_debug
if defined LegacyShaderCompiler goto fxcviaenv
set PCFXC="%WindowsSdkVerBinPath%%FXCARCH%\fxc.exe"
if exist %PCFXC% goto continue
set PCFXC="%WindowsSdkBinPath%%WindowsSDKVersion%\%FXCARCH%\fxc.exe"
@ -17,6 +18,12 @@ set PCFXC="%WindowsSdkDir%bin\%WindowsSDKVersion%\%FXCARCH%\fxc.exe"
if exist %PCFXC% goto continue
set PCFXC=fxc.exe
goto continue
:fxcviaenv
set PCFXC="%LegacyShaderCompiler%"
if not exist %PCFXC% goto needfxc
goto continue
:continue
if not defined CompileShadersOutput set CompileShadersOutput=Compiled
@ -54,3 +61,7 @@ echo %fxc%
echo %fxc4%
%fxc4% || set error=1
exit /b
:needfxc
echo ERROR: CompileShaders requires FXC.EXE
exit /b 1

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

@ -113,8 +113,10 @@ LiveResources::~LiveResources()
XUserUnregisterForChangeEvent(m_userChangedEventToken, false);
XNetworkingUnregisterConnectivityHintChanged(m_networkConnectivityChangedToken, false);
auto async = new XAsyncBlock{};
XblCleanupAsync(async);
XAsyncBlock async = {};
XblCleanupAsync(&async);
XAsyncGetStatus(&async, true); // this is a blocking call so we can use a stack variable
XTaskQueueCloseHandle(m_asyncQueue);
}

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

@ -917,7 +917,7 @@ bool Sample::LoadPointFile(LPCWSTR inFile, PointSound* outChannel)
outChannel->curBufferLoc = 0;
outChannel->volume = 1.f;
if (DirectX::LoadWAVAudioFromFileEx(inFile, m_waveFile, WavData))
if (FAILED(DirectX::LoadWAVAudioFromFileEx(inFile, m_waveFile, WavData)))
{
return false;
}

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 73 KiB

После

Ширина:  |  Высота:  |  Размер: 108 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 50 KiB

После

Ширина:  |  Высота:  |  Размер: 12 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 28 KiB

После

Ширина:  |  Высота:  |  Размер: 1.9 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 1.3 MiB

После

Ширина:  |  Высота:  |  Размер: 764 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 19 KiB

После

Ширина:  |  Высота:  |  Размер: 5.2 KiB

Двоичные данные
Samples/Audio/InGameChat/Assets/LargeLogo.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 73 KiB

После

Ширина:  |  Высота:  |  Размер: 108 KiB

Двоичные данные
Samples/Audio/InGameChat/Assets/Logo.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 49 KiB

После

Ширина:  |  Высота:  |  Размер: 12 KiB

Двоичные данные
Samples/Audio/InGameChat/Assets/SmallLogo.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 24 KiB

После

Ширина:  |  Высота:  |  Размер: 1.9 KiB

Двоичные данные
Samples/Audio/InGameChat/Assets/SplashScreen.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 1.2 MiB

После

Ширина:  |  Высота:  |  Размер: 764 KiB

Двоичные данные
Samples/Audio/InGameChat/Assets/StoreLogo.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 19 KiB

После

Ширина:  |  Высота:  |  Размер: 5.2 KiB

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

@ -732,9 +732,6 @@ void Sample::CreateDeviceDependentResources()
if (FAILED(device->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &shaderModel, sizeof(shaderModel)))
|| (shaderModel.HighestShaderModel < D3D_SHADER_MODEL_6_0))
{
#ifdef _DEBUG
OutputDebugStringA("ERROR: Shader Model 6.0 is not supported!\n");
#endif
throw std::runtime_error("Shader Model 6.0 is not supported!");
}
#endif

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 73 KiB

После

Ширина:  |  Высота:  |  Размер: 108 KiB

Двоичные данные
Samples/Audio/SimpleCustomAPO/Assets/Logo.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 50 KiB

После

Ширина:  |  Высота:  |  Размер: 12 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 28 KiB

После

Ширина:  |  Высота:  |  Размер: 1.9 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 1.3 MiB

После

Ширина:  |  Высота:  |  Размер: 764 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 19 KiB

После

Ширина:  |  Высота:  |  Размер: 5.2 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 73 KiB

После

Ширина:  |  Высота:  |  Размер: 108 KiB

Двоичные данные
Samples/Audio/SimplePlay3DSound/Assets/Logo.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 50 KiB

После

Ширина:  |  Высота:  |  Размер: 12 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 28 KiB

После

Ширина:  |  Высота:  |  Размер: 1.9 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 1.3 MiB

После

Ширина:  |  Высота:  |  Размер: 764 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 19 KiB

После

Ширина:  |  Высота:  |  Размер: 5.2 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 73 KiB

После

Ширина:  |  Высота:  |  Размер: 108 KiB

Двоичные данные
Samples/Audio/SimplePlaySound/Assets/Logo.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 50 KiB

После

Ширина:  |  Высота:  |  Размер: 12 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 28 KiB

После

Ширина:  |  Высота:  |  Размер: 1.9 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 1.3 MiB

После

Ширина:  |  Высота:  |  Размер: 764 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 19 KiB

После

Ширина:  |  Высота:  |  Размер: 5.2 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 73 KiB

После

Ширина:  |  Высота:  |  Размер: 108 KiB

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше