1
0
mirror of https://github.com/microsoft/DirectXTex synced 2024-11-25 05:40:06 +00:00

Code review for OpenMP code path

This commit is contained in:
Chuck Walbourn 2019-12-13 22:26:18 -08:00
parent 3bf3c288f3
commit 5d5ebd7b7c
2 changed files with 17 additions and 7 deletions

View File

@ -15,6 +15,9 @@ option(BUILD_DX11 "Build with DirectX11 Runtime support" ON)
# Includes the functions for creating Direct3D 12 resources at runtime # Includes the functions for creating Direct3D 12 resources at runtime
option(BUILD_DX12 "Build with DirectX12 Runtime support" ON) option(BUILD_DX12 "Build with DirectX12 Runtime support" ON)
# Enable the use of OpenMP for software BC6H/BC7 compression
option(BC_USE_OPENMP "Build with OpenMP support" ON)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
@ -107,6 +110,8 @@ if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
set(WarningsLib "-Wpedantic" "-Wextra") set(WarningsLib "-Wpedantic" "-Wextra")
target_compile_options(${PROJECT_NAME} PRIVATE ${WarningsLib}) target_compile_options(${PROJECT_NAME} PRIVATE ${WarningsLib})
# OpenMP is not supported for clang for Windows by default
set(WarningsEXE ${WarningsLib} "-Wno-c++98-compat" "-Wno-c++98-compat-pedantic" "-Wno-switch" "-Wno-switch-enum" "-Wno-language-extension-token" "-Wno-missing-prototypes") set(WarningsEXE ${WarningsLib} "-Wno-c++98-compat" "-Wno-c++98-compat-pedantic" "-Wno-switch" "-Wno-switch-enum" "-Wno-language-extension-token" "-Wno-missing-prototypes")
target_compile_options(texassemble PRIVATE ${WarningsEXE}) target_compile_options(texassemble PRIVATE ${WarningsEXE})
target_compile_options(texconv PRIVATE ${WarningsEXE}) target_compile_options(texconv PRIVATE ${WarningsEXE})
@ -118,6 +123,11 @@ if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
target_compile_options(texconv PRIVATE /permissive- /Zc:__cplusplus) target_compile_options(texconv PRIVATE /permissive- /Zc:__cplusplus)
target_compile_options(texdiag PRIVATE /permissive- /Zc:__cplusplus) target_compile_options(texdiag PRIVATE /permissive- /Zc:__cplusplus)
if(BC_USE_OPENMP MATCHES ON)
target_compile_options(${PROJECT_NAME} PRIVATE /openmp /Zc:twoPhase-)
target_compile_options(texconv PRIVATE /openmp /Zc:twoPhase-)
endif()
set(WarningsEXE "/wd4061" "/wd4062" "/wd4365" "/wd4668" "/wd4710" "/wd4820" "/wd5039" "/wd5045") set(WarningsEXE "/wd4061" "/wd4062" "/wd4365" "/wd4668" "/wd4710" "/wd4820" "/wd5039" "/wd5045")
target_compile_options(texassemble PRIVATE ${WarningsEXE}) target_compile_options(texassemble PRIVATE ${WarningsEXE})
target_compile_options(texconv PRIVATE ${WarningsEXE}) target_compile_options(texconv PRIVATE ${WarningsEXE})

View File

@ -250,12 +250,12 @@ namespace
assert((y >= 0) && (y < int(image.height))); assert((y >= 0) && (y < int(image.height)));
size_t rowPitch = image.rowPitch; size_t rowPitch = image.rowPitch;
const uint8_t *pSrc = image.pixels + (y*rowPitch) + (x*sbpp); const uint8_t *pSrc = image.pixels + (size_t(y)*rowPitch) + (size_t(x)*sbpp);
uint8_t *pDest = result.pixels + (nb*blocksize); uint8_t *pDest = result.pixels + (size_t(nb)*blocksize);
size_t ph = std::min<size_t>(4, image.height - y); size_t ph = std::min<size_t>(4, image.height - size_t(y));
size_t pw = std::min<size_t>(4, image.width - x); size_t pw = std::min<size_t>(4, image.width - size_t(x));
assert(pw > 0 && ph > 0); assert(pw > 0 && ph > 0);
ptrdiff_t bytesLeft = pEnd - pSrc; ptrdiff_t bytesLeft = pEnd - pSrc;
@ -268,19 +268,19 @@ namespace
if (ph > 1) if (ph > 1)
{ {
bytesToRead = std::min<size_t>(rowPitch, size_t(bytesLeft - rowPitch)); bytesToRead = std::min<size_t>(rowPitch, size_t(bytesLeft) - rowPitch);
if (!_LoadScanline(&temp[4], pw, pSrc + rowPitch, bytesToRead, format)) if (!_LoadScanline(&temp[4], pw, pSrc + rowPitch, bytesToRead, format))
fail = true; fail = true;
if (ph > 2) if (ph > 2)
{ {
bytesToRead = std::min<size_t>(rowPitch, size_t(bytesLeft - rowPitch * 2)); bytesToRead = std::min<size_t>(rowPitch, size_t(bytesLeft) - rowPitch * 2);
if (!_LoadScanline(&temp[8], pw, pSrc + rowPitch * 2, bytesToRead, format)) if (!_LoadScanline(&temp[8], pw, pSrc + rowPitch * 2, bytesToRead, format))
fail = true; fail = true;
if (ph > 3) if (ph > 3)
{ {
bytesToRead = std::min<size_t>(rowPitch, size_t(bytesLeft - rowPitch * 3)); bytesToRead = std::min<size_t>(rowPitch, size_t(bytesLeft) - rowPitch * 3);
if (!_LoadScanline(&temp[12], pw, pSrc + rowPitch * 3, bytesToRead, format)) if (!_LoadScanline(&temp[12], pw, pSrc + rowPitch * 3, bytesToRead, format))
fail = true; fail = true;
} }