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

Cleaned up clang warnings in DDSTextureLoader, ScreenGrab, WICTextureLoader

This commit is contained in:
Chuck Walbourn 2019-07-31 17:05:23 -07:00
parent 5dcfb90b9e
commit bc0325b806
11 changed files with 204 additions and 158 deletions

View File

@ -20,8 +20,9 @@
#include <algorithm>
#include <memory>
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
#pragma comment(lib,"dxguid.lib")
#ifdef __clang__
#pragma clang diagnostic ignored "-Wcovered-switch-default"
#pragma clang diagnostic ignored "-Wswitch-enum"
#endif
using namespace DirectX;
@ -65,7 +66,6 @@ struct DDS_PIXELFORMAT
#define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH
#define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT
#define DDS_WIDTH 0x00000004 // DDSD_WIDTH
#define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX
#define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX
@ -189,7 +189,7 @@ namespace
// setup the pointers in the process request
*header = hdr;
ptrdiff_t offset = sizeof(uint32_t)
auto offset = sizeof(uint32_t)
+ sizeof(DDS_HEADER)
+ (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0);
*bitData = ddsData + offset;
@ -309,7 +309,7 @@ namespace
// setup the pointers in the process request
*header = hdr;
ptrdiff_t offset = sizeof(uint32_t) + sizeof(DDS_HEADER)
auto offset = sizeof(uint32_t) + sizeof(DDS_HEADER)
+ (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0);
*bitData = ddsData.get() + offset;
*bitSize = fileInfo.EndOfFile.LowPart - offset;
@ -950,7 +950,7 @@ namespace
assert(index < mipCount * arraySize);
_Analysis_assume_(index < mipCount * arraySize);
initData[index].pSysMem = (const void*)pSrcBits;
initData[index].pSysMem = pSrcBits;
initData[index].SysMemPitch = static_cast<UINT>(RowBytes);
initData[index].SysMemSlicePitch = static_cast<UINT>(NumBytes);
++index;
@ -1032,7 +1032,7 @@ namespace
desc.Usage = usage;
desc.BindFlags = bindFlags;
desc.CPUAccessFlags = cpuAccessFlags;
desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE;
desc.MiscFlags = miscFlags & ~static_cast<unsigned int>(D3D11_RESOURCE_MISC_TEXTURECUBE);
ID3D11Texture1D* tex = nullptr;
hr = d3dDevice->CreateTexture1D(&desc,
@ -1049,13 +1049,13 @@ namespace
if (arraySize > 1)
{
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
SRVDesc.Texture1DArray.MipLevels = (!mipCount) ? -1 : desc.MipLevels;
SRVDesc.Texture1DArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
SRVDesc.Texture1DArray.ArraySize = static_cast<UINT>(arraySize);
}
else
{
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
SRVDesc.Texture1D.MipLevels = (!mipCount) ? -1 : desc.MipLevels;
SRVDesc.Texture1D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
}
hr = d3dDevice->CreateShaderResourceView(tex,
@ -1101,7 +1101,7 @@ namespace
}
else
{
desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE;
desc.MiscFlags = miscFlags & ~static_cast<unsigned int>(D3D11_RESOURCE_MISC_TEXTURECUBE);
}
ID3D11Texture2D* tex = nullptr;
@ -1121,7 +1121,7 @@ namespace
if (arraySize > 6)
{
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY;
SRVDesc.TextureCubeArray.MipLevels = (!mipCount) ? -1 : desc.MipLevels;
SRVDesc.TextureCubeArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
// Earlier we set arraySize to (NumCubes * 6)
SRVDesc.TextureCubeArray.NumCubes = static_cast<UINT>(arraySize / 6);
@ -1129,19 +1129,19 @@ namespace
else
{
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
SRVDesc.TextureCube.MipLevels = (!mipCount) ? -1 : desc.MipLevels;
SRVDesc.TextureCube.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
}
}
else if (arraySize > 1)
{
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
SRVDesc.Texture2DArray.MipLevels = (!mipCount) ? -1 : desc.MipLevels;
SRVDesc.Texture2DArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
SRVDesc.Texture2DArray.ArraySize = static_cast<UINT>(arraySize);
}
else
{
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
SRVDesc.Texture2D.MipLevels = (!mipCount) ? -1 : desc.MipLevels;
SRVDesc.Texture2D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
}
hr = d3dDevice->CreateShaderResourceView(tex,
@ -1179,7 +1179,7 @@ namespace
desc.Usage = usage;
desc.BindFlags = bindFlags;
desc.CPUAccessFlags = cpuAccessFlags;
desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE;
desc.MiscFlags = miscFlags & ~static_cast<unsigned int>(D3D11_RESOURCE_MISC_TEXTURECUBE);
ID3D11Texture3D* tex = nullptr;
hr = d3dDevice->CreateTexture3D(&desc,
@ -1194,7 +1194,7 @@ namespace
SRVDesc.Format = format;
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
SRVDesc.Texture3D.MipLevels = (!mipCount) ? -1 : desc.MipLevels;
SRVDesc.Texture3D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
hr = d3dDevice->CreateShaderResourceView(tex,
&SRVDesc,
@ -1260,7 +1260,7 @@ namespace
if ((header->ddspf.flags & DDS_FOURCC) &&
(MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC))
{
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>((const char*)header + sizeof(DDS_HEADER));
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>(reinterpret_cast<const uint8_t*>(header) + sizeof(DDS_HEADER));
arraySize = d3d10ext->arraySize;
if (arraySize == 0)
@ -1604,7 +1604,7 @@ namespace
{
if (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC)
{
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>((const char*)header + sizeof(DDS_HEADER));
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>(reinterpret_cast<const uint8_t*>(header) + sizeof(DDS_HEADER));
auto mode = static_cast<DDS_ALPHA_MODE>(d3d10ext->miscFlags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK);
switch (mode)
{
@ -1613,6 +1613,10 @@ namespace
case DDS_ALPHA_MODE_OPAQUE:
case DDS_ALPHA_MODE_CUSTOM:
return mode;
case DDS_ALPHA_MODE_UNKNOWN:
default:
break;
}
}
else if ((MAKEFOURCC('D', 'X', 'T', '2') == header->ddspf.fourCC)

View File

@ -126,4 +126,4 @@ namespace DirectX
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
}
}

View File

@ -20,6 +20,14 @@
#include <algorithm>
#include <memory>
#ifdef __clang__
#pragma clang diagnostic ignored "-Wtautological-type-limit-compare"
#pragma clang diagnostic ignored "-Wcovered-switch-default"
#pragma clang diagnostic ignored "-Wswitch"
#pragma clang diagnostic ignored "-Wswitch-enum"
#endif
#define D3DX12_NO_STATE_OBJECT_HELPERS
#include "d3dx12.h"
using namespace DirectX;
@ -63,7 +71,6 @@ struct DDS_PIXELFORMAT
#define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH
#define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT
#define DDS_WIDTH 0x00000004 // DDSD_WIDTH
#define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX
#define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX
@ -203,7 +210,7 @@ namespace
// setup the pointers in the process request
*header = hdr;
ptrdiff_t offset = sizeof(uint32_t)
auto offset = sizeof(uint32_t)
+ sizeof(DDS_HEADER)
+ (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0);
*bitData = ddsData + offset;
@ -313,7 +320,7 @@ namespace
// setup the pointers in the process request
*header = hdr;
ptrdiff_t offset = sizeof(uint32_t) + sizeof(DDS_HEADER)
auto offset = sizeof(uint32_t) + sizeof(DDS_HEADER)
+ (bDXT10Header ? sizeof(DDS_HEADER_DXT10) : 0);
*bitData = ddsData.get() + offset;
*bitSize = fileInfo.EndOfFile.LowPart - offset;
@ -938,13 +945,13 @@ namespace
if (!slicePlane)
{
// Plane 0
res.SlicePitch = res.RowPitch * height;
res.SlicePitch = res.RowPitch * static_cast<LONG>(height);
}
else
{
// Plane 1
res.pData = reinterpret_cast<const uint8_t*>(res.pData) + res.RowPitch * height;
res.SlicePitch = res.RowPitch * ((height + 1) >> 1);
res.pData = reinterpret_cast<const uint8_t*>(res.pData) + uintptr_t(res.RowPitch) * height;
res.SlicePitch = res.RowPitch * ((static_cast<LONG>(height) + 1) >> 1);
}
break;
@ -952,14 +959,14 @@ namespace
if (!slicePlane)
{
// Plane 0
res.SlicePitch = res.RowPitch * height;
res.SlicePitch = res.RowPitch * static_cast<LONG>(height);
}
else
{
// Plane 1
res.pData = reinterpret_cast<const uint8_t*>(res.pData) + res.RowPitch * height;
res.pData = reinterpret_cast<const uint8_t*>(res.pData) + uintptr_t(res.RowPitch) * height;
res.RowPitch = (res.RowPitch >> 1);
res.SlicePitch = res.RowPitch * height;
res.SlicePitch = res.RowPitch * static_cast<LONG>(height);
}
break;
}
@ -1116,7 +1123,7 @@ namespace
&desc,
D3D12_RESOURCE_STATE_COPY_DEST,
nullptr,
IID_PPV_ARGS(texture));
IID_ID3D12Resource, reinterpret_cast<void**>(texture));
if (SUCCEEDED(hr))
{
_Analysis_assume_(*texture != nullptr);
@ -1159,7 +1166,7 @@ namespace
if ((header->ddspf.flags & DDS_FOURCC) &&
(MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC))
{
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>((const char*)header + sizeof(DDS_HEADER));
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>(reinterpret_cast<const uint8_t*>(header) + sizeof(DDS_HEADER));
arraySize = d3d10ext->arraySize;
if (arraySize == 0)
@ -1388,7 +1395,7 @@ namespace
{
if ( MAKEFOURCC( 'D', 'X', '1', '0' ) == header->ddspf.fourCC )
{
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>( (const char*)header + sizeof(DDS_HEADER) );
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>(reinterpret_cast<const uint8_t*>(header) + sizeof(DDS_HEADER));
auto mode = static_cast<DDS_ALPHA_MODE>( d3d10ext->miscFlags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK );
switch( mode )
{
@ -1397,6 +1404,10 @@ namespace
case DDS_ALPHA_MODE_OPAQUE:
case DDS_ALPHA_MODE_CUSTOM:
return mode;
case DDS_ALPHA_MODE_UNKNOWN:
default:
break;
}
}
else if ( ( MAKEFOURCC( 'D', 'X', 'T', '2' ) == header->ddspf.fourCC )

View File

@ -80,9 +80,6 @@ namespace
#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH
#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE
#define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT
#define DDS_WIDTH 0x00000004 // DDSD_WIDTH
#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE
typedef struct
@ -213,7 +210,7 @@ namespace
}
}
void clear() { m_handle = 0; }
void clear() { m_handle = nullptr; }
private:
HANDLE m_handle;
@ -225,7 +222,7 @@ namespace
class auto_delete_file_wic
{
public:
auto_delete_file_wic(ComPtr<IWICStream>& hFile, const wchar_t* szFile) : m_handle(hFile), m_filename(szFile) {}
auto_delete_file_wic(ComPtr<IWICStream>& hFile, const wchar_t* szFile) : m_filename(szFile), m_handle(hFile) {}
~auto_delete_file_wic()
{
if (m_filename)
@ -235,7 +232,7 @@ namespace
}
}
void clear() { m_filename = 0; }
void clear() { m_filename = nullptr; }
private:
const wchar_t* m_filename;
@ -627,7 +624,7 @@ namespace
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
ComPtr<ID3D11Texture2D> pTexture;
HRESULT hr = pSource->QueryInterface(IID_PPV_ARGS(pTexture.GetAddressOf()));
HRESULT hr = pSource->QueryInterface(IID_ID3D11Texture2D, reinterpret_cast<void**>(pTexture.GetAddressOf()));
if ( FAILED(hr) )
return hr;
@ -711,49 +708,53 @@ namespace
//--------------------------------------------------------------------------------------
bool g_WIC2 = false;
BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept
{
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
ifactory
);
if (SUCCEEDED(hr))
{
// WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true;
return TRUE;
}
else
{
hr = CoCreateInstance(
CLSID_WICImagingFactory1,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
ifactory
);
return SUCCEEDED(hr) ? TRUE : FALSE;
}
#else
return SUCCEEDED(CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
ifactory)) ? TRUE : FALSE;
#endif
}
IWICImagingFactory* _GetWIC()
{
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
IWICImagingFactory* factory = nullptr;
InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, LPVOID *ifactory) -> BOOL
{
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
ifactory
);
if ( SUCCEEDED(hr) )
{
// WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true;
return TRUE;
}
else
{
hr = CoCreateInstance(
CLSID_WICImagingFactory1,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
ifactory
);
return SUCCEEDED(hr) ? TRUE : FALSE;
}
#else
return SUCCEEDED( CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
ifactory) ) ? TRUE : FALSE;
#endif
}, nullptr, reinterpret_cast<LPVOID*>(&factory));
InitializeWICFactory,
nullptr,
reinterpret_cast<LPVOID*>(&factory));
return factory;
}

View File

@ -19,7 +19,7 @@
#include <d3d11_1.h>
#include <ocidl.h>
#include <OCIdl.h>
#include <stdint.h>
#include <functional>
@ -36,4 +36,4 @@ namespace DirectX
_In_z_ const wchar_t* fileName,
_In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void(IPropertyBag2*)> setCustomProps = nullptr );
}
}

View File

@ -31,6 +31,14 @@
#include <wrl\client.h>
#ifdef __clang__
#pragma clang diagnostic ignored "-Wtautological-type-limit-compare"
#pragma clang diagnostic ignored "-Wcovered-switch-default"
#pragma clang diagnostic ignored "-Wswitch"
#pragma clang diagnostic ignored "-Wswitch-enum"
#endif
#define D3DX12_NO_STATE_OBJECT_HELPERS
#include "d3dx12.h"
using Microsoft::WRL::ComPtr;
@ -80,9 +88,6 @@ namespace
#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH
#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE
#define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT
#define DDS_WIDTH 0x00000004 // DDSD_WIDTH
#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE
typedef struct
@ -213,7 +218,7 @@ namespace
}
}
void clear() { m_handle = 0; }
void clear() { m_handle = nullptr; }
private:
HANDLE m_handle;
@ -225,7 +230,7 @@ namespace
class auto_delete_file_wic
{
public:
auto_delete_file_wic(ComPtr<IWICStream>& hFile, LPCWSTR szFile) : m_handle(hFile), m_filename(szFile) {}
auto_delete_file_wic(ComPtr<IWICStream>& hFile, LPCWSTR szFile) : m_filename(szFile), m_handle(hFile) {}
~auto_delete_file_wic()
{
if (m_filename)
@ -235,7 +240,7 @@ namespace
}
}
void clear() { m_filename = 0; }
void clear() { m_filename = nullptr; }
private:
LPCWSTR m_filename;
@ -676,19 +681,19 @@ namespace
// Create a command allocator
ComPtr<ID3D12CommandAllocator> commandAlloc;
hr = device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(commandAlloc.GetAddressOf()));
hr = device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_ID3D12CommandAllocator, reinterpret_cast<void**>(commandAlloc.GetAddressOf()));
if (FAILED(hr))
return hr;
// Spin up a new command list
ComPtr<ID3D12GraphicsCommandList> commandList;
hr = device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, commandAlloc.Get(), nullptr, IID_PPV_ARGS(commandList.GetAddressOf()));
hr = device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, commandAlloc.Get(), nullptr, IID_ID3D12GraphicsCommandList, reinterpret_cast<void**>(commandList.GetAddressOf()));
if (FAILED(hr))
return hr;
// Create a fence
ComPtr<ID3D12Fence> fence;
hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(fence.GetAddressOf()));
hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_ID3D12Fence, reinterpret_cast<void**>(fence.GetAddressOf()));
if (FAILED(hr))
return hr;
@ -726,7 +731,8 @@ namespace
&descCopy,
D3D12_RESOURCE_STATE_COPY_DEST,
nullptr,
IID_PPV_ARGS(pTemp.GetAddressOf()));
IID_ID3D12Resource,
reinterpret_cast<void**>(pTemp.GetAddressOf()));
if (FAILED(hr))
return hr;
@ -761,7 +767,8 @@ namespace
&bufferDesc,
D3D12_RESOURCE_STATE_COPY_DEST,
nullptr,
IID_PPV_ARGS(pStaging.ReleaseAndGetAddressOf()));
IID_ID3D12Resource,
reinterpret_cast<void**>(pStaging.ReleaseAndGetAddressOf()));
if (FAILED(hr))
return hr;
@ -806,21 +813,25 @@ namespace
return S_OK;
}
BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept
{
return SUCCEEDED(CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
ifactory)) ? TRUE : FALSE;
}
IWICImagingFactory2* _GetWIC()
{
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
IWICImagingFactory2* factory = nullptr;
(void)InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, PVOID *ifactory) -> BOOL
{
return SUCCEEDED( CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
ifactory) ) ? TRUE : FALSE;
}, nullptr, reinterpret_cast<LPVOID*>(&factory));
InitializeWICFactory,
nullptr,
reinterpret_cast<LPVOID*>(&factory));
return factory;
}
@ -840,7 +851,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
return E_INVALIDARG;
ComPtr<ID3D12Device> device;
pCommandQ->GetDevice(IID_PPV_ARGS(device.GetAddressOf()));
pCommandQ->GetDevice(IID_ID3D12Device, reinterpret_cast<void**>(device.GetAddressOf()));
// Get the size of the image
const auto desc = pSource->GetDesc();
@ -863,7 +874,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
&totalResourceSize);
// Round up the srcPitch to multiples of 256
UINT64 dstRowPitch = (fpRowPitch + 255) & ~0xFF;
UINT64 dstRowPitch = (fpRowPitch + 255) & ~0xFFu;
if (dstRowPitch > UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
@ -1045,7 +1056,7 @@ HRESULT DirectX::SaveWICTextureToFile(
return E_INVALIDARG;
ComPtr<ID3D12Device> device;
pCommandQ->GetDevice(IID_PPV_ARGS(device.GetAddressOf()));
pCommandQ->GetDevice(IID_ID3D12Device, reinterpret_cast<void**>(device.GetAddressOf()));
// Get the size of the image
const auto desc = pSource->GetDesc();
@ -1068,7 +1079,7 @@ HRESULT DirectX::SaveWICTextureToFile(
&totalResourceSize);
// Round up the srcPitch to multiples of 256
UINT64 dstRowPitch = (fpRowPitch + 255) & ~0xFF;
UINT64 dstRowPitch = (fpRowPitch + 255) & ~0xFFu;
if (dstRowPitch > UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);

View File

@ -19,7 +19,7 @@
#include <d3d12.h>
#include <ocidl.h>
#include <OCIdl.h>
#include <stdint.h>
#include <functional>
@ -42,4 +42,4 @@ namespace DirectX
D3D12_RESOURCE_STATES afterState = D3D12_RESOURCE_STATE_RENDER_TARGET,
_In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr);
}
}

View File

@ -36,8 +36,9 @@
#include <algorithm>
#include <memory>
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
#pragma comment(lib,"dxguid.lib")
#ifdef __clang__
#pragma clang diagnostic ignored "-Wcovered-switch-default"
#pragma clang diagnostic ignored "-Wswitch-enum"
#endif
using namespace DirectX;
@ -164,49 +165,53 @@ namespace
bool g_WIC2 = false;
//--------------------------------------------------------------------------------------
BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept
{
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
ifactory
);
if (SUCCEEDED(hr))
{
// WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true;
return TRUE;
}
else
{
hr = CoCreateInstance(
CLSID_WICImagingFactory1,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
ifactory
);
return SUCCEEDED(hr) ? TRUE : FALSE;
}
#else
return SUCCEEDED(CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
ifactory)) ? TRUE : FALSE;
#endif
}
IWICImagingFactory* _GetWIC()
{
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
IWICImagingFactory* factory = nullptr;
InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, PVOID *ifactory) -> BOOL
{
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
ifactory
);
if (SUCCEEDED(hr))
{
// WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true;
return TRUE;
}
else
{
hr = CoCreateInstance(
CLSID_WICImagingFactory1,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
ifactory
);
return SUCCEEDED(hr) ? TRUE : FALSE;
}
#else
return SUCCEEDED(CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
ifactory)) ? TRUE : FALSE;
#endif
}, nullptr, reinterpret_cast<LPVOID*>(&factory));
(void)InitOnceExecuteOnce(&s_initOnce,
InitializeWICFactory,
nullptr,
reinterpret_cast<LPVOID*>(&factory));
return factory;
}
@ -647,7 +652,7 @@ namespace
SRVDesc.Format = desc.Format;
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
SRVDesc.Texture2D.MipLevels = (autogen) ? -1 : 1;
SRVDesc.Texture2D.MipLevels = (autogen) ? UINT(-1) : 1;
hr = d3dDevice->CreateShaderResourceView(tex, &SRVDesc, textureView);
if (FAILED(hr))

View File

@ -123,4 +123,5 @@ namespace DirectX
_In_ unsigned int loadFlags,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView);
}
}

View File

@ -30,6 +30,14 @@
#include <wrl\client.h>
#ifdef __clang__
#pragma clang diagnostic ignored "-Wtautological-type-limit-compare"
#pragma clang diagnostic ignored "-Wcovered-switch-default"
#pragma clang diagnostic ignored "-Wswitch"
#pragma clang diagnostic ignored "-Wswitch-enum"
#endif
#define D3DX12_NO_STATE_OBJECT_HELPERS
#include "d3dx12.h"
using namespace DirectX;
@ -143,21 +151,25 @@ namespace
// We don't support n-channel formats
};
BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept
{
return SUCCEEDED(CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
ifactory)) ? TRUE : FALSE;
}
IWICImagingFactory2* _GetWIC()
{
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
IWICImagingFactory2* factory = nullptr;
(void)InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, PVOID *ifactory) -> BOOL
{
return SUCCEEDED( CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
ifactory) ) ? TRUE : FALSE;
}, nullptr, reinterpret_cast<LPVOID*>(&factory));
InitializeWICFactory,
nullptr,
reinterpret_cast<LPVOID*>(&factory));
return factory;
}
@ -513,7 +525,8 @@ namespace
&desc,
D3D12_RESOURCE_STATE_COPY_DEST,
nullptr,
IID_PPV_ARGS(&tex));
IID_ID3D12Resource,
reinterpret_cast<void**>(&tex));
if (FAILED(hr))
{
@ -523,8 +536,8 @@ namespace
_Analysis_assume_(tex != nullptr);
subresource.pData = decodedData.get();
subresource.RowPitch = rowPitch;
subresource.SlicePitch = imageSize;
subresource.RowPitch = static_cast<LONG>(rowPitch);
subresource.SlicePitch = static_cast<LONG>(imageSize);
*texture = tex;
return hr;

View File

@ -75,4 +75,4 @@ namespace DirectX
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource);
}
}