1
0
mirror of https://github.com/microsoft/DirectXTex synced 2024-11-22 04:20:07 +00:00

Replaced _countof / ARRAYSIZE with std::size

This commit is contained in:
Chuck Walbourn 2021-01-02 12:44:35 -08:00
parent 2f8e8120ae
commit f764da5176
15 changed files with 38 additions and 37 deletions

View File

@ -347,7 +347,7 @@ HRESULT InitDevice( const TexMetadata& mdata )
D3D_DRIVER_TYPE_WARP, D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE, D3D_DRIVER_TYPE_REFERENCE,
}; };
UINT numDriverTypes = ARRAYSIZE( driverTypes ); constexpr UINT numDriverTypes = static_cast<UINT>(std::size(driverTypes));
D3D_FEATURE_LEVEL featureLevels[] = D3D_FEATURE_LEVEL featureLevels[] =
{ {
@ -355,7 +355,7 @@ HRESULT InitDevice( const TexMetadata& mdata )
D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_10_0,
}; };
UINT numFeatureLevels = ARRAYSIZE( featureLevels ); constexpr UINT numFeatureLevels = static_cast<UINT>(std::size(featureLevels));
DXGI_SWAP_CHAIN_DESC sd = {}; DXGI_SWAP_CHAIN_DESC sd = {};
sd.BufferCount = 1; sd.BufferCount = 1;
@ -444,7 +444,7 @@ HRESULT InitDevice( const TexMetadata& mdata )
{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, sizeof(XMFLOAT4), D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, sizeof(XMFLOAT4), D3D11_INPUT_PER_VERTEX_DATA, 0 },
}; };
UINT numElements = ARRAYSIZE( layout ); constexpr UINT numElements = static_cast<UINT>(std::size(layout));
// Create the input layout // Create the input layout
hr = g_pd3dDevice->CreateInputLayout( layout, numElements, g_VS, sizeof(g_VS), &g_pVertexLayout ); hr = g_pd3dDevice->CreateInputLayout( layout, numElements, g_VS, sizeof(g_VS), &g_pVertexLayout );
@ -574,17 +574,17 @@ HRESULT InitDevice( const TexMetadata& mdata )
if ( isCubeMap ) if ( isCubeMap )
{ {
nverts = _countof(verticesCube); nverts = static_cast<UINT>(std::size(verticesCube));
InitData.pSysMem = verticesCube; InitData.pSysMem = verticesCube;
} }
else if ( is1D ) else if ( is1D )
{ {
nverts = _countof(vertices1D); nverts = static_cast<UINT>(std::size(vertices1D));
InitData.pSysMem = vertices1D; InitData.pSysMem = vertices1D;
} }
else else
{ {
nverts = _countof(vertices); nverts = static_cast<UINT>(std::size(vertices));
InitData.pSysMem = vertices; InitData.pSysMem = vertices;
} }
@ -627,12 +627,12 @@ HRESULT InitDevice( const TexMetadata& mdata )
if ( isCubeMap ) if ( isCubeMap )
{ {
g_iIndices = _countof(indicesCube); g_iIndices = static_cast<UINT>(std::size(indicesCube));
InitData.pSysMem = indicesCube; InitData.pSysMem = indicesCube;
} }
else else
{ {
g_iIndices = _countof(indices); g_iIndices = static_cast<UINT>(std::size(indices));
InitData.pSysMem = indices; InitData.pSysMem = indices;
} }

View File

@ -11,7 +11,6 @@
#pragma once #pragma once
#include <assert.h>
#include <DirectXMath.h> #include <DirectXMath.h>
#include <DirectXPackedVector.h> #include <DirectXPackedVector.h>

View File

@ -1660,12 +1660,12 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const noexcept
if (ms_aModeToInfo[uMode] >= 0) if (ms_aModeToInfo[uMode] >= 0)
{ {
assert(static_cast<unsigned int>(ms_aModeToInfo[uMode]) < _countof(ms_aInfo)); assert(static_cast<unsigned int>(ms_aModeToInfo[uMode]) < std::size(ms_aInfo));
_Analysis_assume_(ms_aModeToInfo[uMode] < _countof(ms_aInfo)); _Analysis_assume_(ms_aModeToInfo[uMode] < std::size(ms_aInfo));
const ModeDescriptor* desc = ms_aDesc[ms_aModeToInfo[uMode]]; const ModeDescriptor* desc = ms_aDesc[ms_aModeToInfo[uMode]];
assert(static_cast<unsigned int>(ms_aModeToInfo[uMode]) < _countof(ms_aDesc)); assert(static_cast<unsigned int>(ms_aModeToInfo[uMode]) < std::size(ms_aDesc));
_Analysis_assume_(ms_aModeToInfo[uMode] < _countof(ms_aDesc)); _Analysis_assume_(ms_aModeToInfo[uMode] < std::size(ms_aDesc));
const ModeInfo& info = ms_aInfo[ms_aModeToInfo[uMode]]; const ModeInfo& info = ms_aInfo[ms_aModeToInfo[uMode]];
INTEndPntPair aEndPts[BC6H_MAX_REGIONS] = {}; INTEndPntPair aEndPts[BC6H_MAX_REGIONS] = {};
@ -1811,7 +1811,7 @@ void D3DX_BC6H::Encode(bool bSigned, const HDRColorA* const pIn) noexcept
EncodeParams EP(pIn, bSigned); EncodeParams EP(pIn, bSigned);
for (EP.uMode = 0; EP.uMode < ARRAYSIZE(ms_aInfo) && EP.fBestErr > 0; ++EP.uMode) for (EP.uMode = 0; EP.uMode < std::size(ms_aInfo) && EP.fBestErr > 0; ++EP.uMode)
{ {
const uint8_t uShapes = ms_aInfo[EP.uMode].uPartitions ? 32u : 1u; const uint8_t uShapes = ms_aInfo[EP.uMode].uPartitions ? 32u : 1u;
// Number of rough cases to look at. reasonable values of this are 1, uShapes/4, and uShapes // Number of rough cases to look at. reasonable values of this are 1, uShapes/4, and uShapes

View File

@ -2988,9 +2988,9 @@ uint32_t DirectX::_GetConvertFlags(DXGI_FORMAT format) noexcept
{ {
#ifdef _DEBUG #ifdef _DEBUG
// Ensure conversion table is in ascending order // Ensure conversion table is in ascending order
assert(_countof(g_ConvertTable) > 0); assert(std::size(g_ConvertTable) > 0);
DXGI_FORMAT lastvalue = g_ConvertTable[0].format; DXGI_FORMAT lastvalue = g_ConvertTable[0].format;
for (size_t index = 1; index < _countof(g_ConvertTable); ++index) for (size_t index = 1; index < std::size(g_ConvertTable); ++index)
{ {
assert(g_ConvertTable[index].format > lastvalue); assert(g_ConvertTable[index].format > lastvalue);
lastvalue = g_ConvertTable[index].format; lastvalue = g_ConvertTable[index].format;
@ -2998,7 +2998,7 @@ uint32_t DirectX::_GetConvertFlags(DXGI_FORMAT format) noexcept
#endif #endif
ConvertData key = { format, 0, 0 }; ConvertData key = { format, 0, 0 };
auto in = reinterpret_cast<const ConvertData*>(bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), auto in = reinterpret_cast<const ConvertData*>(bsearch_s(&key, g_ConvertTable, std::size(g_ConvertTable), sizeof(ConvertData),
ConvertCompare, nullptr)); ConvertCompare, nullptr));
return (in) ? in->flags : 0; return (in) ? in->flags : 0;
} }
@ -3020,9 +3020,9 @@ void DirectX::_ConvertScanline(
#ifdef _DEBUG #ifdef _DEBUG
// Ensure conversion table is in ascending order // Ensure conversion table is in ascending order
assert(_countof(g_ConvertTable) > 0); assert(std::size(g_ConvertTable) > 0);
DXGI_FORMAT lastvalue = g_ConvertTable[0].format; DXGI_FORMAT lastvalue = g_ConvertTable[0].format;
for (size_t index = 1; index < _countof(g_ConvertTable); ++index) for (size_t index = 1; index < std::size(g_ConvertTable); ++index)
{ {
assert(g_ConvertTable[index].format > lastvalue); assert(g_ConvertTable[index].format > lastvalue);
lastvalue = g_ConvertTable[index].format; lastvalue = g_ConvertTable[index].format;
@ -3032,10 +3032,10 @@ void DirectX::_ConvertScanline(
// Determine conversion details about source and dest formats // Determine conversion details about source and dest formats
ConvertData key = { inFormat, 0, 0 }; ConvertData key = { inFormat, 0, 0 };
auto in = reinterpret_cast<const ConvertData*>( auto in = reinterpret_cast<const ConvertData*>(
bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), ConvertCompare, nullptr)); bsearch_s(&key, g_ConvertTable, std::size(g_ConvertTable), sizeof(ConvertData), ConvertCompare, nullptr));
key.format = outFormat; key.format = outFormat;
auto out = reinterpret_cast<const ConvertData*>( auto out = reinterpret_cast<const ConvertData*>(
bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), ConvertCompare, nullptr)); bsearch_s(&key, g_ConvertTable, std::size(g_ConvertTable), sizeof(ConvertData), ConvertCompare, nullptr));
if (!in || !out) if (!in || !out)
{ {
assert(false); assert(false);

View File

@ -114,6 +114,7 @@
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
#include <cstring> #include <cstring>
#include <iterator>
#include <memory> #include <memory>
#include <DirectXPackedVector.h> #include <DirectXPackedVector.h>

View File

@ -123,7 +123,7 @@ namespace
_Use_decl_annotations_ _Use_decl_annotations_
DXGI_FORMAT DirectX::_WICToDXGI(const GUID& guid) noexcept DXGI_FORMAT DirectX::_WICToDXGI(const GUID& guid) noexcept
{ {
for (size_t i = 0; i < _countof(g_WICFormats); ++i) for (size_t i = 0; i < std::size(g_WICFormats); ++i)
{ {
if (memcmp(&g_WICFormats[i].wic, &guid, sizeof(GUID)) == 0) if (memcmp(&g_WICFormats[i].wic, &guid, sizeof(GUID)) == 0)
return g_WICFormats[i].format; return g_WICFormats[i].format;
@ -186,7 +186,7 @@ bool DirectX::_DXGIToWIC(DXGI_FORMAT format, GUID& guid, bool ignoreRGBvsBGR) no
#endif #endif
default: default:
for (size_t i = 0; i < _countof(g_WICFormats); ++i) for (size_t i = 0; i < std::size(g_WICFormats); ++i)
{ {
if (g_WICFormats[i].format == format) if (g_WICFormats[i].format == format)
{ {
@ -205,7 +205,7 @@ TEX_FILTER_FLAGS DirectX::_CheckWICColorSpace(_In_ const GUID& sourceGUID, _In_
{ {
TEX_FILTER_FLAGS srgb = TEX_FILTER_DEFAULT; TEX_FILTER_FLAGS srgb = TEX_FILTER_DEFAULT;
for (size_t i = 0; i < _countof(g_WICFormats); ++i) for (size_t i = 0; i < std::size(g_WICFormats); ++i)
{ {
if (memcmp(&g_WICFormats[i].wic, &sourceGUID, sizeof(GUID)) == 0) if (memcmp(&g_WICFormats[i].wic, &sourceGUID, sizeof(GUID)) == 0)
{ {

View File

@ -200,7 +200,7 @@ namespace
} }
else else
{ {
for (size_t i = 0; i < _countof(g_WICConvert); ++i) for (size_t i = 0; i < std::size(g_WICConvert); ++i)
{ {
if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0) if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0)
{ {

View File

@ -9,8 +9,9 @@
#pragma once #pragma once
#include <assert.h> #include <cassert>
#include <memory> #include <memory>
#include <malloc.h> #include <malloc.h>
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------

View File

@ -156,7 +156,7 @@ HRESULT LoadAnimatedGif(const wchar_t* szFile, std::vector<std::unique_ptr<Scrat
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
hr = palette->GetColors(_countof(rgbColors), rgbColors, &actualColors); hr = palette->GetColors(static_cast<UINT>(std::size(rgbColors)), rgbColors, &actualColors);
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
} }

View File

@ -564,7 +564,7 @@ namespace
wchar_t version[32] = {}; wchar_t version[32] = {};
wchar_t appName[_MAX_PATH] = {}; wchar_t appName[_MAX_PATH] = {};
if (GetModuleFileNameW(nullptr, appName, _countof(appName))) if (GetModuleFileNameW(nullptr, appName, static_cast<DWORD>(std::size(appName))))
{ {
DWORD size = GetFileVersionInfoSizeW(appName, nullptr); DWORD size = GetFileVersionInfoSizeW(appName, nullptr);
if (size > 0) if (size > 0)

View File

@ -701,7 +701,7 @@ namespace
wchar_t version[32] = {}; wchar_t version[32] = {};
wchar_t appName[_MAX_PATH] = {}; wchar_t appName[_MAX_PATH] = {};
if (GetModuleFileNameW(nullptr, appName, _countof(appName))) if (GetModuleFileNameW(nullptr, appName, static_cast<UINT>(std::size(appName))))
{ {
DWORD size = GetFileVersionInfoSizeW(appName, nullptr); DWORD size = GetFileVersionInfoSizeW(appName, nullptr);
if (size > 0) if (size > 0)
@ -919,7 +919,7 @@ namespace
D3D_FEATURE_LEVEL fl; D3D_FEATURE_LEVEL fl;
HRESULT hr = s_DynamicD3D11CreateDevice(pAdapter.Get(), HRESULT hr = s_DynamicD3D11CreateDevice(pAdapter.Get(),
(pAdapter) ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE, (pAdapter) ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE,
nullptr, createDeviceFlags, featureLevels, _countof(featureLevels), nullptr, createDeviceFlags, featureLevels, static_cast<UINT>(std::size(featureLevels)),
D3D11_SDK_VERSION, pDevice, &fl, nullptr); D3D11_SDK_VERSION, pDevice, &fl, nullptr);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {

View File

@ -525,7 +525,7 @@ namespace
wchar_t version[32] = {}; wchar_t version[32] = {};
wchar_t appName[_MAX_PATH] = {}; wchar_t appName[_MAX_PATH] = {};
if (GetModuleFileNameW(nullptr, appName, _countof(appName))) if (GetModuleFileNameW(nullptr, appName, static_cast<DWORD>(std::size(appName))))
{ {
DWORD size = GetFileVersionInfoSizeW(appName, nullptr); DWORD size = GetFileVersionInfoSizeW(appName, nullptr);
if (size > 0) if (size > 0)

View File

@ -230,7 +230,7 @@ namespace
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
DXGI_FORMAT _WICToDXGI(const GUID& guid) noexcept DXGI_FORMAT _WICToDXGI(const GUID& guid) noexcept
{ {
for (size_t i = 0; i < _countof(g_WICFormats); ++i) for (size_t i = 0; i < std::size(g_WICFormats); ++i)
{ {
if (memcmp(&g_WICFormats[i].wic, &guid, sizeof(GUID)) == 0) if (memcmp(&g_WICFormats[i].wic, &guid, sizeof(GUID)) == 0)
return g_WICFormats[i].format; return g_WICFormats[i].format;
@ -465,7 +465,7 @@ namespace
} }
else else
{ {
for (size_t i = 0; i < _countof(g_WICConvert); ++i) for (size_t i = 0; i < std::size(g_WICConvert); ++i)
{ {
if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0) if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0)
{ {

View File

@ -247,7 +247,7 @@ namespace
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
DXGI_FORMAT _WICToDXGI(const GUID& guid) noexcept DXGI_FORMAT _WICToDXGI(const GUID& guid) noexcept
{ {
for (size_t i = 0; i < _countof(g_WICFormats); ++i) for (size_t i = 0; i < std::size(g_WICFormats); ++i)
{ {
if (memcmp(&g_WICFormats[i].wic, &guid, sizeof(GUID)) == 0) if (memcmp(&g_WICFormats[i].wic, &guid, sizeof(GUID)) == 0)
return g_WICFormats[i].format; return g_WICFormats[i].format;
@ -393,7 +393,7 @@ namespace
DXGI_FORMAT format = _WICToDXGI(pixelFormat); DXGI_FORMAT format = _WICToDXGI(pixelFormat);
if (format == DXGI_FORMAT_UNKNOWN) if (format == DXGI_FORMAT_UNKNOWN)
{ {
for (size_t i = 0; i < _countof(g_WICConvert); ++i) for (size_t i = 0; i < std::size(g_WICConvert); ++i)
{ {
if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0) if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0)
{ {

View File

@ -214,7 +214,7 @@ namespace
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
D3DFORMAT _WICToD3D9(const GUID& guid) noexcept D3DFORMAT _WICToD3D9(const GUID& guid) noexcept
{ {
for (size_t i = 0; i < _countof(g_WICFormats); ++i) for (size_t i = 0; i < std::size(g_WICFormats); ++i)
{ {
if (memcmp(&g_WICFormats[i].wic, &guid, sizeof(GUID)) == 0) if (memcmp(&g_WICFormats[i].wic, &guid, sizeof(GUID)) == 0)
return g_WICFormats[i].format; return g_WICFormats[i].format;
@ -331,7 +331,7 @@ namespace
D3DFORMAT format = _WICToD3D9(pixelFormat); D3DFORMAT format = _WICToD3D9(pixelFormat);
if (format == D3DFMT_UNKNOWN) if (format == D3DFMT_UNKNOWN)
{ {
for (size_t i = 0; i < _countof(g_WICConvert); ++i) for (size_t i = 0; i < std::size(g_WICConvert); ++i)
{ {
if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0) if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0)
{ {