1
0
mirror of https://github.com/microsoft/DirectXTex synced 2024-11-21 12:00:06 +00:00

Fix DX12 Capture transition state handling for MSAA (#532)

This commit is contained in:
Chuck Walbourn 2024-10-14 15:49:44 -07:00 committed by GitHub
parent 1262c4b293
commit 09affb78aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 356 additions and 298 deletions

View File

@ -18,6 +18,7 @@
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <memory>
#include <new>
@ -53,6 +54,8 @@ using namespace DirectX;
//
// See DDS.h in the 'Texconv' sample and the 'DirectXTex' library
//--------------------------------------------------------------------------------------
namespace
{
#pragma pack(push,1)
constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS "
@ -126,9 +129,15 @@ struct DDS_HEADER_DXT10
#pragma pack(pop)
static_assert(sizeof(DDS_PIXELFORMAT) == 32, "DDS pixel format size mismatch");
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
{
struct handle_closer { void operator()(HANDLE h) noexcept { if (h) CloseHandle(h); } };
using ScopedHandle = std::unique_ptr<void, handle_closer>;
@ -168,7 +177,7 @@ namespace
return E_FAIL;
}
if (ddsDataSize < (sizeof(uint32_t) + sizeof(DDS_HEADER)))
if (ddsDataSize < DDS_MIN_HEADER_SIZE)
{
return E_FAIL;
}
@ -195,7 +204,7 @@ namespace
(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;
}
@ -205,8 +214,7 @@ namespace
// 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;
@ -264,7 +272,7 @@ namespace
}
// 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;
}
@ -319,7 +327,7 @@ namespace
(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;
@ -330,7 +338,7 @@ namespace
// 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;

View File

@ -18,6 +18,7 @@
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <memory>
#include <new>
@ -81,6 +82,8 @@ using namespace DirectX;
//
// See DDS.h in the 'Texconv' sample and the 'DirectXTex' library
//--------------------------------------------------------------------------------------
namespace
{
#pragma pack(push,1)
constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS "
@ -154,9 +157,15 @@ struct DDS_HEADER_DXT10
#pragma pack(pop)
static_assert(sizeof(DDS_PIXELFORMAT) == 32, "DDS pixel format size mismatch");
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
{
#ifdef _WIN32
struct handle_closer { void operator()(HANDLE h) noexcept { if (h) CloseHandle(h); } };
@ -214,7 +223,7 @@ namespace
return E_FAIL;
}
if (ddsDataSize < (sizeof(uint32_t) + sizeof(DDS_HEADER)))
if (ddsDataSize < DDS_MIN_HEADER_SIZE)
{
return E_FAIL;
}
@ -241,7 +250,7 @@ namespace
(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;
}
@ -251,8 +260,7 @@ namespace
// 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;
@ -302,7 +310,7 @@ namespace
}
// 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;
}
@ -345,7 +353,7 @@ namespace
return E_FAIL;
// Need at least enough data to fill the header and magic number to be a valid DDS
if (fileLen < (sizeof(uint32_t) + sizeof(DDS_HEADER)))
if (fileLen < DDS_MIN_HEADER_SIZE)
return E_FAIL;
ddsData.reset(new (std::nothrow) uint8_t[size_t(fileLen)]);
@ -395,7 +403,7 @@ namespace
(MAKEFOURCC('D', 'X', '1', '0') == hdr->ddspf.fourCC))
{
// Must be long enough for both headers and magic value
if (len < (sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10)))
if (len < DDS_DX10_HEADER_SIZE)
{
ddsData.reset();
return E_FAIL;
@ -406,7 +414,7 @@ namespace
// 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 = len - offset;

View File

@ -20,6 +20,7 @@
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <memory>
#include <new>
@ -57,6 +58,8 @@ using Microsoft::WRL::ComPtr;
//
// See DDS.h in the 'Texconv' sample and the 'DirectXTex' library
//--------------------------------------------------------------------------------------
namespace
{
#pragma pack(push,1)
constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS "
@ -115,9 +118,12 @@ struct DDS_HEADER
#pragma pack(pop)
static_assert(sizeof(DDS_PIXELFORMAT) == 32, "DDS pixel format size mismatch");
static_assert(sizeof(DDS_HEADER) == 124, "DDS Header size mismatch");
constexpr size_t DDS_DX9_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER);
//--------------------------------------------------------------------------------------
namespace
{
struct handle_closer { void operator()(HANDLE h) noexcept { if (h) CloseHandle(h); } };
using ScopedHandle = std::unique_ptr<void, handle_closer>;
@ -144,7 +150,7 @@ namespace
return E_FAIL;
}
if (ddsDataSize < (sizeof(uint32_t) + sizeof(DDS_HEADER)))
if (ddsDataSize < DDS_DX9_HEADER_SIZE)
{
return E_FAIL;
}
@ -175,9 +181,8 @@ namespace
// setup the pointers in the process request
*header = hdr;
auto offset = sizeof(uint32_t) + sizeof(DDS_HEADER);
*bitData = ddsData + offset;
*bitSize = ddsDataSize - offset;
*bitData = ddsData + DDS_DX9_HEADER_SIZE;
*bitSize = ddsDataSize - DDS_DX9_HEADER_SIZE;
return S_OK;
}
@ -234,7 +239,7 @@ namespace
}
// 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_DX9_HEADER_SIZE)
{
return E_FAIL;
}
@ -294,9 +299,8 @@ namespace
// setup the pointers in the process request
*header = hdr;
auto offset = sizeof(uint32_t) + sizeof(DDS_HEADER);
*bitData = ddsData.get() + offset;
*bitSize = fileInfo.EndOfFile.LowPart - offset;
*bitData = ddsData.get() + DDS_DX9_HEADER_SIZE;
*bitSize = fileInfo.EndOfFile.LowPart - DDS_DX9_HEADER_SIZE;
return S_OK;
}

View File

@ -217,8 +217,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;
@ -230,7 +233,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))
@ -267,6 +270,11 @@ namespace
}
copySource = pTemp;
beforeState = D3D12_RESOURCE_STATE_RESOLVE_DEST;
}
else
{
beforeStateSource = D3D12_RESOURCE_STATE_COPY_SOURCE;
}
// Create a staging texture
@ -283,7 +291,7 @@ namespace
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
for (UINT j = 0; j < numberOfResources; ++j)
@ -293,8 +301,8 @@ namespace
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))

View File

@ -26,6 +26,7 @@
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <memory>
#include <new>
@ -71,7 +72,7 @@ namespace
{
#pragma pack(push,1)
#define DDS_MAGIC 0x20534444 // "DDS "
constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS "
struct DDS_PIXELFORMAT
{
@ -129,6 +130,14 @@ namespace
#pragma pack(pop)
static_assert(sizeof(DDS_PIXELFORMAT) == 32, "DDS pixel format size mismatch");
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");
const DDS_PIXELFORMAT DDSPF_DXT1 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 };
@ -816,13 +825,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;
@ -879,7 +887,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
memcpy_s(&header->ddspf, sizeof(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 = D3D11_RESOURCE_DIMENSION_TEXTURE2D;
extHeader->arraySize = 1;

View File

@ -26,6 +26,7 @@
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <memory>
#include <new>
@ -93,7 +94,7 @@ namespace
{
#pragma pack(push,1)
#define DDS_MAGIC 0x20534444 // "DDS "
constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS "
struct DDS_PIXELFORMAT
{
@ -149,8 +150,16 @@ namespace
uint32_t reserved;
};
static_assert(sizeof(DDS_PIXELFORMAT) == 32, "DDS pixel format size mismatch");
static_assert(sizeof(DDS_HEADER) == 124, "DDS Header size mismatch");
static_assert(sizeof(DDS_HEADER_DXT10) == 20, "DDS DX10 Extended Header size mismatch");
#pragma pack(pop)
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");
const DDS_PIXELFORMAT DDSPF_DXT1 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 };
@ -755,8 +764,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;
@ -768,7 +780,7 @@ namespace
&defaultHeapProperties,
D3D12_HEAP_FLAG_NONE,
&descCopy,
D3D12_RESOURCE_STATE_COPY_DEST,
D3D12_RESOURCE_STATE_RESOLVE_DEST,
nullptr,
IID_ID3D12Resource,
reinterpret_cast<void**>(pTemp.GetAddressOf()));
@ -797,6 +809,11 @@ namespace
}
copySource = pTemp;
beforeState = D3D12_RESOURCE_STATE_RESOLVE_DEST;
}
else
{
beforeStateSource = D3D12_RESOURCE_STATE_COPY_SOURCE;
}
// Create a staging texture
@ -815,7 +832,7 @@ namespace
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 = {};
@ -831,8 +848,8 @@ 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))
@ -954,13 +971,12 @@ HRESULT DirectX::SaveDDSTextureToFile(
#endif
// 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;
@ -1017,7 +1033,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;
@ -1422,7 +1438,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);

View File

@ -20,6 +20,7 @@
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <memory>
#include <new>
@ -65,7 +66,7 @@ namespace
{
#pragma pack(push,1)
#define DDS_MAGIC 0x20534444 // "DDS "
constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS "
struct DDS_PIXELFORMAT
{
@ -116,6 +117,11 @@ namespace
#pragma pack(pop)
static_assert(sizeof(DDS_PIXELFORMAT) == 32, "DDS pixel format size mismatch");
static_assert(sizeof(DDS_HEADER) == 124, "DDS Header size mismatch");
constexpr size_t DDS_DX9_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER);
const DDS_PIXELFORMAT DDSPF_DXT1 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 };
@ -606,13 +612,11 @@ HRESULT DirectX::SaveDDSTextureToFile(
auto_delete_file delonfail(hFile.get());
// Setup header
constexpr size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER);
uint8_t fileHeader[MAX_HEADER_SIZE] = {};
uint8_t fileHeader[DDS_DX9_HEADER_SIZE] = {};
*reinterpret_cast<uint32_t*>(&fileHeader[0]) = DDS_MAGIC;
auto header = reinterpret_cast<DDS_HEADER*>(&fileHeader[0] + sizeof(uint32_t));
constexpr size_t headerSize = sizeof(uint32_t) + sizeof(DDS_HEADER);
header->size = sizeof(DDS_HEADER);
header->flags = DDS_HEADER_FLAGS_TEXTURE | DDS_HEADER_FLAGS_MIPMAP;
header->height = desc.Height;
@ -726,10 +730,10 @@ HRESULT DirectX::SaveDDSTextureToFile(
// Write header & pixels
DWORD bytesWritten;
if (!WriteFile(hFile.get(), fileHeader, static_cast<DWORD>(headerSize), &bytesWritten, nullptr))
if (!WriteFile(hFile.get(), fileHeader, static_cast<DWORD>(DDS_DX9_HEADER_SIZE), &bytesWritten, nullptr))
return HRESULT_FROM_WIN32(GetLastError());
if (bytesWritten != headerSize)
if (bytesWritten != DDS_DX9_HEADER_SIZE)
return E_FAIL;
if (!WriteFile(hFile.get(), pixels.get(), static_cast<DWORD>(slicePitch), &bytesWritten, nullptr))