mirror of
https://github.com/microsoft/DirectXTex
synced 2024-12-25 19:01:05 +00:00
Added make_AlignedArray helpers to scoped.h
This commit is contained in:
parent
fd13c32036
commit
95c4991486
@ -28,7 +28,7 @@ option(ENABLE_CODE_ANALYSIS "Use Static Code Analysis on build" OFF)
|
||||
# NOTE requires adding DirectXTexEXR.h/.cpp source files (vcpkg does this automatically)
|
||||
option(ENABLE_OPENEXR_SUPPORT "Build with OpenEXR support" OFF)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
@ -74,8 +74,7 @@ if(BUILD_DX11)
|
||||
DirectXTex/BCDirectCompute.h
|
||||
DirectXTex/BCDirectCompute.cpp
|
||||
DirectXTex/DirectXTexCompressGPU.cpp
|
||||
DirectXTex/DirectXTexD3D11.cpp
|
||||
DirectXTex/Shaders/Compiled/BC6HEncode_EncodeBlockCS.inc)
|
||||
DirectXTex/DirectXTexD3D11.cpp)
|
||||
endif()
|
||||
if(BUILD_DX12)
|
||||
set(LIBRARY_SOURCES ${LIBRARY_SOURCES}
|
||||
@ -92,9 +91,10 @@ if(ENABLE_OPENEXR_SUPPORT)
|
||||
DirectXTex/DirectXTexEXR.cpp)
|
||||
endif()
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
|
||||
|
||||
if(BUILD_DX11)
|
||||
set(LIBRARY_SOURCES ${LIBRARY_SOURCES}
|
||||
DirectXTex/Shaders/Compiled/BC6HEncode_EncodeBlockCS.inc)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${PROJECT_SOURCE_DIR}/DirectXTex/Shaders/Compiled/BC6HEncode_EncodeBlockCS.inc"
|
||||
MAIN_DEPENDENCY "${PROJECT_SOURCE_DIR}/DirectXTex/Shaders/CompileShaders.cmd"
|
||||
@ -105,6 +105,8 @@ if(BUILD_DX11)
|
||||
USES_TERMINAL)
|
||||
endif()
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
|
||||
|
||||
source_group(${PROJECT_NAME} REGULAR_EXPRESSION DirectXTex/*.*)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
@ -160,8 +162,7 @@ install(EXPORT ${PROJECT_NAME}-targets
|
||||
install(FILES ${LIBRARY_HEADERS}
|
||||
DESTINATION include)
|
||||
|
||||
install(
|
||||
FILES
|
||||
install(FILES
|
||||
${PROJECT_BINARY_DIR}/cmake/${PACKAGE_NAME}-config.cmake
|
||||
${PROJECT_BINARY_DIR}/cmake/${PACKAGE_NAME}-config-version.cmake
|
||||
DESTINATION cmake/)
|
||||
|
@ -59,7 +59,7 @@ namespace
|
||||
return E_POINTER;
|
||||
}
|
||||
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR) * srcImage.width), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(srcImage.width);
|
||||
if (!scanline)
|
||||
{
|
||||
image.Release();
|
||||
|
@ -2640,7 +2640,7 @@ HRESULT DirectX::_ConvertToR16G16B16A16(const Image& srcImage, ScratchImage& ima
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR) * srcImage.width), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(srcImage.width);
|
||||
if (!scanline)
|
||||
{
|
||||
image.Release();
|
||||
@ -2693,7 +2693,7 @@ HRESULT DirectX::_ConvertFromR16G16B16A16(const Image& srcImage, const Image& de
|
||||
if (srcImage.width != destImage.width || srcImage.height != destImage.height)
|
||||
return E_FAIL;
|
||||
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR) * srcImage.width), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(srcImage.width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -4597,7 +4597,7 @@ namespace
|
||||
if (filter & TEX_FILTER_DITHER_DIFFUSION)
|
||||
{
|
||||
// Error diffusion dithering (aka Floyd-Steinberg dithering)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*(width * 2 + 2)), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(width) * 2 + 2);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -4620,7 +4620,7 @@ namespace
|
||||
}
|
||||
else
|
||||
{
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*width), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
|
@ -786,7 +786,7 @@ bool ScratchImage::IsAlphaAllOpaque() const noexcept
|
||||
}
|
||||
else
|
||||
{
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*m_metadata.width), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(m_metadata.width);
|
||||
if (!scanline)
|
||||
return false;
|
||||
|
||||
|
@ -142,7 +142,7 @@ namespace
|
||||
assert(srcImage.width == destImage.width);
|
||||
assert(srcImage.height == destImage.height);
|
||||
|
||||
ScopedAlignedArrayXMVECTOR scanline(reinterpret_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*srcImage.width), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(srcImage.width);
|
||||
if (!scanline)
|
||||
{
|
||||
return E_OUTOFMEMORY;
|
||||
@ -214,13 +214,13 @@ namespace
|
||||
{
|
||||
coverage = 0.0f;
|
||||
|
||||
ScopedAlignedArrayXMVECTOR row0(reinterpret_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*srcImage.width), 16)));
|
||||
auto row0 = make_AlignedArrayXMVECTOR(srcImage.width);
|
||||
if (!row0)
|
||||
{
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
ScopedAlignedArrayXMVECTOR row1(reinterpret_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*srcImage.width), 16)));
|
||||
auto row1 = make_AlignedArrayXMVECTOR(srcImage.width);
|
||||
if (!row1)
|
||||
{
|
||||
return E_OUTOFMEMORY;
|
||||
@ -896,7 +896,7 @@ namespace
|
||||
size_t height = mipChain.GetMetadata().height;
|
||||
|
||||
// Allocate temporary space (2 scanlines)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*width * 2), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(width) * 2);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -983,7 +983,7 @@ namespace
|
||||
return E_FAIL;
|
||||
|
||||
// Allocate temporary space (3 scanlines)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*width * 3), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(width) * 3);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -1074,7 +1074,7 @@ namespace
|
||||
size_t height = mipChain.GetMetadata().height;
|
||||
|
||||
// Allocate temporary space (3 scanlines, plus X and Y filters)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*width * 3), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(width) * 3);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -1185,7 +1185,7 @@ namespace
|
||||
size_t height = mipChain.GetMetadata().height;
|
||||
|
||||
// Allocate temporary space (5 scanlines, plus X and Y filters)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*width * 5), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(width) * 5);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -1373,7 +1373,7 @@ namespace
|
||||
size_t height = mipChain.GetMetadata().height;
|
||||
|
||||
// Allocate initial temporary space (1 scanline, accumulation rows, plus X and Y filters)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc(sizeof(XMVECTOR) * width, 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -1462,9 +1462,10 @@ namespace
|
||||
}
|
||||
else
|
||||
{
|
||||
rowAcc->scanline.reset(static_cast<XMVECTOR*>(_aligned_malloc(sizeof(XMVECTOR) * nwidth, 16)));
|
||||
if (!rowAcc->scanline)
|
||||
auto nscanline = make_AlignedArrayXMVECTOR(nwidth);
|
||||
if (!nscanline)
|
||||
return E_OUTOFMEMORY;
|
||||
rowAcc->scanline.swap(nscanline);
|
||||
}
|
||||
|
||||
memset(rowAcc->scanline.get(), 0, sizeof(XMVECTOR) * nwidth);
|
||||
@ -1641,7 +1642,7 @@ namespace
|
||||
size_t height = mipChain.GetMetadata().height;
|
||||
|
||||
// Allocate temporary space (2 scanlines)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*width * 2), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(width) * 2);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -1790,7 +1791,7 @@ namespace
|
||||
return E_FAIL;
|
||||
|
||||
// Allocate temporary space (5 scanlines)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*width * 5), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(width) * 5);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -1959,7 +1960,7 @@ namespace
|
||||
size_t height = mipChain.GetMetadata().height;
|
||||
|
||||
// Allocate temporary space (5 scanlines, plus X/Y/Z filters)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*width * 5), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(width) * 5);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -2152,7 +2153,7 @@ namespace
|
||||
size_t height = mipChain.GetMetadata().height;
|
||||
|
||||
// Allocate temporary space (17 scanlines, plus X/Y/Z filters)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*width * 17), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(width) * 17);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -2533,7 +2534,7 @@ namespace
|
||||
size_t height = mipChain.GetMetadata().height;
|
||||
|
||||
// Allocate initial temporary space (1 scanline, accumulation rows, plus X/Y/Z filters)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc(sizeof(XMVECTOR) * width, 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -2616,10 +2617,10 @@ namespace
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t bytes = sizeof(XMVECTOR) * nwidth * nheight;
|
||||
sliceAcc->scanline.reset(static_cast<XMVECTOR*>(_aligned_malloc(bytes, 16)));
|
||||
if (!sliceAcc->scanline)
|
||||
auto nscanline = make_AlignedArrayXMVECTOR(uint64_t(nwidth) * uint64_t(nheight));
|
||||
if (!nscanline)
|
||||
return E_OUTOFMEMORY;
|
||||
sliceAcc->scanline.swap(nscanline);
|
||||
}
|
||||
|
||||
memset(sliceAcc->scanline.get(), 0, sizeof(XMVECTOR) * nwidth * nheight);
|
||||
|
@ -33,7 +33,7 @@ namespace
|
||||
|
||||
const size_t width = image1.width;
|
||||
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*width) * 2, 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(width) * 2);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -184,7 +184,7 @@ namespace
|
||||
|
||||
const size_t width = image.width;
|
||||
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*width), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -222,7 +222,7 @@ namespace
|
||||
|
||||
const size_t width = srcImage.width;
|
||||
|
||||
ScopedAlignedArrayXMVECTOR scanlines(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*width*2), 16)));
|
||||
auto scanlines = make_AlignedArrayXMVECTOR(uint64_t(width) * 2);
|
||||
if (!scanlines)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -347,7 +347,7 @@ HRESULT DirectX::CopyRectangle(
|
||||
|
||||
uint8_t* pDest = dstImage.pixels + (yOffset * dstImage.rowPitch) + (xOffset * dbpp);
|
||||
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*srcRect.w), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(srcRect.w);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
|
@ -92,11 +92,11 @@ namespace
|
||||
return E_FAIL;
|
||||
|
||||
// Allocate temporary space (4 scanlines and 3 evaluated rows)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*width * 4), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(width) * 4);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
ScopedAlignedArrayFloat buffer(static_cast<float*>(_aligned_malloc(((sizeof(float) * (width + 2)) * 3), 16)));
|
||||
auto buffer = make_AlignedArrayFloat((uint64_t(width) + 2) * 3);
|
||||
if (!buffer)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
|
@ -31,7 +31,7 @@ namespace
|
||||
assert(srcImage.width == destImage.width);
|
||||
assert(srcImage.height == destImage.height);
|
||||
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*srcImage.width), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(srcImage.width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -74,7 +74,7 @@ namespace
|
||||
static_assert(static_cast<int>(TEX_PMALPHA_SRGB) == static_cast<int>(TEX_FILTER_SRGB), "TEX_PMALHPA_SRGB* should match TEX_FILTER_SRGB*");
|
||||
flags &= TEX_PMALPHA_SRGB;
|
||||
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*srcImage.width), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(srcImage.width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -116,7 +116,7 @@ namespace
|
||||
assert(srcImage.width == destImage.width);
|
||||
assert(srcImage.height == destImage.height);
|
||||
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*srcImage.width), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(srcImage.width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -162,7 +162,7 @@ namespace
|
||||
static_assert(static_cast<int>(TEX_PMALPHA_SRGB) == static_cast<int>(TEX_FILTER_SRGB), "TEX_PMALPHA_SRGB* should match TEX_FILTER_SRGB*");
|
||||
flags &= TEX_PMALPHA_SRGB;
|
||||
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc((sizeof(XMVECTOR)*srcImage.width), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(srcImage.width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
|
@ -251,8 +251,7 @@ namespace
|
||||
assert(srcImage.format == destImage.format);
|
||||
|
||||
// Allocate temporary space (2 scanlines)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc(
|
||||
(sizeof(XMVECTOR) * (srcImage.width + destImage.width)), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(srcImage.width + destImage.width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -312,8 +311,7 @@ namespace
|
||||
return E_FAIL;
|
||||
|
||||
// Allocate temporary space (3 scanlines)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc(
|
||||
(sizeof(XMVECTOR) * (srcImage.width * 2 + destImage.width)), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(srcImage.width) * 2 + destImage.width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -371,8 +369,7 @@ namespace
|
||||
assert(srcImage.format == destImage.format);
|
||||
|
||||
// Allocate temporary space (3 scanlines, plus X and Y filters)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc(
|
||||
(sizeof(XMVECTOR) * (srcImage.width * 2 + destImage.width)), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(srcImage.width) * 2 + destImage.width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -457,8 +454,7 @@ namespace
|
||||
assert(srcImage.format == destImage.format);
|
||||
|
||||
// Allocate temporary space (5 scanlines, plus X and Y filters)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc(
|
||||
(sizeof(XMVECTOR) * (srcImage.width * 4 + destImage.width)), 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(uint64_t(srcImage.width) * 4 + destImage.width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -619,7 +615,7 @@ namespace
|
||||
using namespace TriangleFilter;
|
||||
|
||||
// Allocate initial temporary space (1 scanline, accumulation rows, plus X and Y filters)
|
||||
ScopedAlignedArrayXMVECTOR scanline(static_cast<XMVECTOR*>(_aligned_malloc(sizeof(XMVECTOR) * srcImage.width, 16)));
|
||||
auto scanline = make_AlignedArrayXMVECTOR(srcImage.width);
|
||||
if (!scanline)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
@ -688,9 +684,10 @@ namespace
|
||||
}
|
||||
else
|
||||
{
|
||||
rowAcc->scanline.reset(static_cast<XMVECTOR*>(_aligned_malloc(sizeof(XMVECTOR) * destImage.width, 16)));
|
||||
if (!rowAcc->scanline)
|
||||
auto nscanline = make_AlignedArrayXMVECTOR(destImage.width);
|
||||
if (!nscanline)
|
||||
return E_OUTOFMEMORY;
|
||||
rowAcc->scanline.swap(nscanline);
|
||||
}
|
||||
|
||||
memset(rowAcc->scanline.get(), 0, sizeof(XMVECTOR) * destImage.width);
|
||||
|
@ -10,6 +10,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include <malloc.h>
|
||||
@ -19,8 +21,26 @@ struct aligned_deleter { void operator()(void* p) noexcept { _aligned_free(p); }
|
||||
|
||||
using ScopedAlignedArrayFloat = std::unique_ptr<float[], aligned_deleter>;
|
||||
|
||||
inline ScopedAlignedArrayFloat make_AlignedArrayFloat(uint64_t count)
|
||||
{
|
||||
uint64_t size = sizeof(float) * count;
|
||||
if (size > static_cast<uint64_t>(UINT32_MAX))
|
||||
return nullptr;
|
||||
auto ptr = _aligned_malloc(static_cast<size_t>(size), 16);
|
||||
return ScopedAlignedArrayFloat(static_cast<float*>(ptr));
|
||||
}
|
||||
|
||||
using ScopedAlignedArrayXMVECTOR = std::unique_ptr<DirectX::XMVECTOR[], aligned_deleter>;
|
||||
|
||||
inline ScopedAlignedArrayXMVECTOR make_AlignedArrayXMVECTOR(uint64_t count)
|
||||
{
|
||||
uint64_t size = sizeof(DirectX::XMVECTOR) * count;
|
||||
if (size > static_cast<uint64_t>(UINT32_MAX))
|
||||
return nullptr;
|
||||
auto ptr = _aligned_malloc(static_cast<size_t>(size), 16);
|
||||
return ScopedAlignedArrayXMVECTOR(static_cast<DirectX::XMVECTOR*>(ptr));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
struct handle_closer { void operator()(HANDLE h) noexcept { assert(h != INVALID_HANDLE_VALUE); if (h) CloseHandle(h); } };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user