Skip to content

fix clang warnings #867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: ali_clang
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/nbl/core/alloc/AddressAllocatorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace core
// pointer to reserved memory has to be aligned to SIMD types!
assert((reinterpret_cast<size_t>(reservedSpace)&(_NBL_SIMD_ALIGNMENT-1u))==0ull);
assert(maxAllocatableAlignment);
assert(core::isPoT(maxRequestableAlignment)); // this is not a proper alignment value
assert(hlsl::isPoT(maxRequestableAlignment)); // this is not a proper alignment value
#endif // _NBL_DEBUG
}
AddressAllocatorBase(CRTP&& other, void* newReservedSpc)
Expand Down
6 changes: 3 additions & 3 deletions include/nbl/core/memory/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef __NBL_CORE_MEMORY_H_INCLUDED__
#define __NBL_CORE_MEMORY_H_INCLUDED__

#include "nbl/core/math/intutil.h"
#include "nbl/builtin/hlsl/math/intutil.hlsl"

#include <typeinfo>
#include <cstddef>
Expand Down Expand Up @@ -79,13 +79,13 @@ constexpr inline size_t alignDown(size_t value, size_t alignment)
//! Valid alignments are power of two
constexpr inline bool is_alignment(size_t value)
{
return core::isPoT(value);
return hlsl::isPoT(value);
}

//!
constexpr inline bool is_aligned_to(size_t value, size_t alignment)
{
return core::isPoT(alignment)&&((value&(alignment-1ull))==0ull);
return hlsl::isPoT(alignment)&&((value&(alignment-1ull))==0ull);
}
// clang complains about constexpr so make normal for now (also complains abour reinterpret_cast)
inline bool is_aligned_to(const void* value, size_t alignment)
Expand Down
4 changes: 3 additions & 1 deletion include/nbl/system/IAsyncQueueDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "nbl/core/declarations.h"

#include "nbl/builtin/hlsl/math/intutil.hlsl"

#include "nbl/system/IThreadHandler.h"
#include "nbl/system/atomic_state.h"

Expand Down Expand Up @@ -416,7 +418,7 @@ template<typename CRTP, typename request_metadata_t, uint32_t BufferSize=256u, t
class IAsyncQueueDispatcher : public IThreadHandler<CRTP,InternalStateType>, protected impl::IAsyncQueueDispatcherBase
{
static_assert(BufferSize>0u, "BufferSize must not be 0!");
static_assert(core::isPoT(BufferSize), "BufferSize must be power of two!");
static_assert(hlsl::isPoT(BufferSize), "BufferSize must be power of two!");

protected:
using base_t = IThreadHandler<CRTP,InternalStateType>;
Expand Down
8 changes: 5 additions & 3 deletions include/nbl/system/ILogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class ILogger : public core::IReferenceCounted
using namespace std::literals;
using namespace std::chrono;
auto currentTime = std::chrono::system_clock::now();
const std::time_t t = std::chrono::system_clock::to_time_t(currentTime);

// Since there is no real way in c++ to get current time with microseconds, this is my weird approach
auto time_since_epoch = duration_cast<microseconds>(system_clock::now().time_since_epoch());
Expand All @@ -70,11 +69,14 @@ class ILogger : public core::IReferenceCounted
// This while is for the microseconds which are less that 6 digits long to be aligned with the others
while (time_since_epoch.count() / 100000 == 0) time_since_epoch *= 10;

auto time = std::localtime(&t);
auto local_tp = zoned_time(current_zone(), currentTime).get_local_time();
auto dp = floor<days>(local_tp);
year_month_day date{ dp };
hh_mm_ss time{ local_tp - dp };

constexpr size_t DATE_STR_LENGTH = 28;
std::string timeStr(DATE_STR_LENGTH, '\0');
sprintf(timeStr.data(), "[%02d.%02d.%d %02d:%02d:%02d:%d]", time->tm_mday, time->tm_mon + 1, 1900 + time->tm_year, time->tm_hour, time->tm_min, time->tm_sec, (int)time_since_epoch.count());
sprintf(timeStr.data(), "[%02d.%02d.%d %02d:%02d:%02d:%d]", date.day(), unsigned(date.month()), date.year(), time.hours().count(), time.minutes().count(), time.seconds().count(), (int)time_since_epoch.count());

std::string messageTypeStr;
switch (logLevel)
Expand Down
3 changes: 2 additions & 1 deletion include/nbl/video/IGPUAccelerationStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "nbl/video/IGPUBuffer.h"

#include "nbl/builtin/hlsl/acceleration_structures.hlsl"
#include "nbl/builtin/hlsl/math/intutil.hlsl"


namespace nbl::video
Expand Down Expand Up @@ -228,7 +229,7 @@ class IGPUBottomLevelAccelerationStructure : public asset::IBottomLevelAccelerat

const size_t vertexSize = asset::getTexelOrBlockBytesize(geometry.vertexFormat);
// TODO: improve in line with the spec https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03711
const size_t vertexAlignment = core::max(core::roundDownToPoT(vertexSize/asset::getFormatChannelCount(geometry.vertexFormat)),1ull);
const size_t vertexAlignment = core::max(hlsl::roundDownToPoT(vertexSize/asset::getFormatChannelCount(geometry.vertexFormat)),1ull);
// https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkAccelerationStructureGeometryTrianglesDataKHR-vertexStride-03735
if (!core::is_aligned_to(geometry.vertexStride,vertexAlignment))
return false;
Expand Down
2 changes: 1 addition & 1 deletion include/vectorSIMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace core
public std::conditional_t<components==4, SIMD_32bitSwizzleAble<vectorSIMDBool<components>, __m128i>, impl::empty_base>
{
typedef impl::vectorSIMDIntBase<vectorSIMDBool<components> > Base;
static_assert(core::isPoT(components)&&components<=16u,"Wrong number of components!\n");
static_assert(hlsl::isPoT(components)&&components<=16u,"Wrong number of components!\n");
public:
using Base::Base;

Expand Down
2 changes: 1 addition & 1 deletion src/nbl/asset/IAssetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ std::function<void(SAssetBundle&)> nbl::asset::makeAssetGreetFunc(const IAssetMa
{
return [_mgr](SAssetBundle& _asset) {
_mgr->setAssetCached(_asset, true);
auto rng = _asset.getContents();
// auto rng = _asset.getContents();
//assets being in the cache must be immutable
//asset mutability is changed just before insertion by inserting methods of IAssetManager
//for (auto ass : rng)
Expand Down
2 changes: 1 addition & 1 deletion src/nbl/asset/ICPUImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class CFlattenRegionsStreamHashImageFilter : public CMatchedSizeInOutImageFilter
if (!state->scratch.memory)
return false;

const auto& parameters = state->inImage->getCreationParameters();
// const auto& parameters = state->inImage->getCreationParameters();

if (state->scratch.size != state_type::getRequiredScratchByteSize(state->inImage))
return false;
Expand Down
3 changes: 1 addition & 2 deletions src/nbl/asset/interchange/CGLILoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ namespace nbl
return {};

const gli::gl glVersion(gli::gl::PROFILE_GL33);
const auto target = glVersion.translate(texture.target());
const auto format = getTranslatedGLIFormat(texture, glVersion, _params.logger);
IImage::E_TYPE imageType;
IImageView<ICPUImage>::E_TYPE imageViewType;
Expand Down Expand Up @@ -105,6 +104,7 @@ namespace nbl
}
default:
{
imageType = IImage::ET_1D; // suppress -Wsometimes-uninitialized by setting whatever value
imageViewType = ICPUImageView::ET_COUNT;
assert(0);
break;
Expand All @@ -115,7 +115,6 @@ namespace nbl
const bool layersFlag = doesItHaveLayers(imageViewType);

const auto texelBlockDimension = asset::getBlockDimensions(format.first);
const auto texelBlockByteSize = asset::getTexelOrBlockBytesize(format.first);
auto texelBuffer = ICPUBuffer::create({ texture.size() });
auto data = reinterpret_cast<uint8_t*>(texelBuffer->getPointer());

Expand Down
3 changes: 2 additions & 1 deletion src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "nbl/system/CFileView.h"

#include "nbl/builtin/MTLdefaults.h"
#include "nbl/builtin/hlsl/math/intutil.hlsl"



Expand Down Expand Up @@ -619,7 +620,7 @@ CGraphicsPipelineLoaderMTL::image_views_set_t CGraphicsPipelineLoaderMTL::loadIm
assert(images[i]->getRegions().size()==1ull);

regions_.push_back(images[i]->getRegions().begin()[0]);
regions_.back().bufferOffset = core::roundUp(regions_.back().bufferOffset, alignment);
regions_.back().bufferOffset = hlsl::roundUp(regions_.back().bufferOffset, alignment);
regions_.back().imageSubresource.baseArrayLayer = (i - CMTLMetadata::CRenderpassIndependentPipeline::EMP_REFL_POSX);

bufSz += images[i]->getImageDataSizeInBytes();
Expand Down
3 changes: 0 additions & 3 deletions src/nbl/asset/interchange/CImageLoaderJPG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,12 @@ asset::SAssetBundle CImageLoaderJPG::loadAsset(system::IFile* _file, const asset
case JCS_CMYK:
_params.logger.log("CMYK color space is unsupported:", system::ILogger::ELL_ERROR, _file->getFileName().string());
return {};
break;
case JCS_YCCK: // this I have no resources on
_params.logger.log("YCCK color space is unsupported: %s", system::ILogger::ELL_ERROR, _file->getFileName().string().c_str());
return {};
break;
default:
_params.logger.log("Can't load as color space is unknown: %s", system::ILogger::ELL_ERROR, _file->getFileName().string().c_str());
return {};
break;
}
cinfo.do_fancy_upsampling = TRUE;

Expand Down
6 changes: 3 additions & 3 deletions src/nbl/asset/interchange/CImageLoaderOpenEXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ SAssetBundle CImageLoaderOpenEXR::loadAsset(system::IFile* _file, const asset::I
const auto mapOfChannels = data.second;
PerImageData perImageData;

int width;
int height;
int width = 0;
int height = 0;

auto params = perImageData.params;
params.format = specifyIrrlichtEndFormat(mapOfChannels, suffixOfChannels, file.fileName(), _params.logger);
Expand Down Expand Up @@ -562,7 +562,7 @@ bool readHeader(IMF::IStream* nblIStream, SContext& ctx)
return false;

auto& attribs = ctx.attributes;
auto& versionField = ctx.versionField;
// auto& versionField = ctx.versionField;

/*

Expand Down
2 changes: 0 additions & 2 deletions src/nbl/asset/interchange/CPLYMeshWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ void CPLYMeshWriter::writeBinary(const asset::ICPUMeshBuffer* _mbuf, size_t _vtx
for (size_t i = 0u; i < _vtxCount; ++i)
{
core::vectorSIMDf f;
uint32_t ui[4];
if (_vaidToWrite[0])
{
writeAttribBinary(context, mbCopy.get(), 0, i, 3u, flipVectors);
Expand Down Expand Up @@ -356,7 +355,6 @@ void CPLYMeshWriter::writeText(const asset::ICPUMeshBuffer* _mbuf, size_t _vtxCo
for (size_t i = 0u; i < _vtxCount; ++i)
{
core::vectorSIMDf f;
uint32_t ui[4];
if (_vaidToWrite[0])
{
writefunc(0, i, 3u);
Expand Down
9 changes: 5 additions & 4 deletions src/nbl/asset/interchange/CSTLMeshWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// See the original file in irrlicht source for authors
#include "nbl/system/ISystem.h"
#include "nbl/system/IFile.h"
#include <nbl/builtin/hlsl/math/intutil.hlsl>

#include "CSTLMeshWriter.h"
#include "SColor.h"
Expand All @@ -12,10 +13,10 @@ using namespace nbl;
using namespace nbl::asset;

#ifdef _NBL_COMPILE_WITH_STL_WRITER_
constexpr auto POSITION_ATTRIBUTE = 0;
// constexpr auto POSITION_ATTRIBUTE = 0;
constexpr auto COLOR_ATTRIBUTE = 1;
constexpr auto UV_ATTRIBUTE = 2;
constexpr auto NORMAL_ATTRIBUTE = 3;
// constexpr auto UV_ATTRIBUTE = 2;
// constexpr auto NORMAL_ATTRIBUTE = 3;

CSTLMeshWriter::CSTLMeshWriter()
{
Expand Down Expand Up @@ -67,7 +68,7 @@ template <class I>
inline void writeFacesBinary(const asset::ICPUMeshBuffer* buffer, const bool& noIndices, system::IFile* file, uint32_t _colorVaid, IAssetWriter::SAssetWriteContext* context, size_t* fileOffset)
{
auto& inputParams = buffer->getPipeline()->getCachedCreationParams().vertexInput;
bool hasColor = inputParams.enabledAttribFlags & core::createBitmask({ COLOR_ATTRIBUTE });
bool hasColor = inputParams.enabledAttribFlags & hlsl::createBitmask({ COLOR_ATTRIBUTE });
const asset::E_FORMAT colorType = static_cast<asset::E_FORMAT>(hasColor ? inputParams.attributes[COLOR_ATTRIBUTE].format : asset::EF_UNKNOWN);

const uint32_t indexCount = buffer->getIndexCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include <nbl/asset/material_compiler/CMaterialCompilerGLSLBackendCommon.h>

#include <iostream>
#include <nbl/asset/material_compiler/CMaterialCompilerGLSLBackendCommon.h>

#include <nbl/builtin/hlsl/math/intutil.hlsl>

namespace nbl
{
Expand Down Expand Up @@ -303,7 +304,7 @@ class ITraversalGenerator
subres.layerCount = 1u;
subres.baseMipLevel = 0u;
const uint32_t mx = std::max(extent.width, extent.height);
const uint32_t round = core::roundUpToPoT<uint32_t>(mx);
const uint32_t round = hlsl::roundUpToPoT<uint32_t>(mx);
const int32_t lsb = hlsl::findLSB(round);
subres.levelCount = static_cast<uint32_t>(lsb + 1);

Expand Down Expand Up @@ -1232,16 +1233,12 @@ auto CMaterialCompilerGLSLBackendCommon::compile(SContext* _ctx, IR* _ir, E_GENE
{
case EGST_PRESENT:
return 4u;
break;
// When desiring Albedo and Normal Extraction, one needs to use extra registers for albedo, normal and throughput scale
case EGST_PRESENT_WITH_AOV_EXTRACTION:
// TODO: investigate whether using 10-16bit storage (fixed point or half float) makes execution faster, because
// albedo could fit in 1.5 DWORDs as 16bit (or 1 DWORDs as 10 bit), normal+throughput scale in 2 DWORDs as half floats or 16 bit snorm
// and value/pdf is a low dynamic range so half float could be feasible! Giving us a total register count of 5 DWORDs.
return 11u;
break;
default:
break;
}
// only colour contribution
return 3u;
Expand Down Expand Up @@ -1483,7 +1480,7 @@ void material_compiler::CMaterialCompilerGLSLBackendCommon::debugPrint(std::ostr
using namespace tex_prefetch;

const instr_stream::tex_prefetch::prefetch_instr_t& instr = _res.prefetch_stream[tex_prefetch.first + i];
const auto& vtid = instr.s.tex_data.vtid;
// const auto& vtid = instr.s.tex_data.vtid;

_out << "### instr " << i << "\n";
const uint32_t reg_cnt = instr.getRegCnt();
Expand Down Expand Up @@ -1511,9 +1508,6 @@ void material_compiler::CMaterialCompilerGLSLBackendCommon::debugPrint(std::ostr

void material_compiler::CMaterialCompilerGLSLBackendCommon::debugPrintInstr(std::ostream& _out, instr_t instr, const result_t& _res, const SContext* _ctx) const
{
auto texDataStr = [](const instr_stream::STextureData& td) {
return "{ " + std::to_string(reinterpret_cast<const uint64_t&>(td.vtid)) + ", " + std::to_string(reinterpret_cast<const float&>(td.scale)) + " }";
};
auto paramVal3OrRegStr = [](const instr_stream::STextureOrConstant& tc, bool tex) -> std::string {
if (tex)
return std::to_string(tc.prefetch);
Expand Down
1 change: 0 additions & 1 deletion src/nbl/asset/utils/CCompilerSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ core::smart_refctd_ptr<ICPUShader> CCompilerSet::preprocessShader(const ICPUShad
auto resolvedCode = m_GLSLCompiler->preprocessShader(code, stage, preprocessOptions);
return core::make_smart_refctd_ptr<ICPUShader>(resolvedCode.c_str(), stage, IShader::E_CONTENT_TYPE::ECT_GLSL, std::string(shader->getFilepathHint()));
}
break;
case IShader::E_CONTENT_TYPE::ECT_SPIRV:
return core::smart_refctd_ptr<ICPUShader>(const_cast<ICPUShader*>(shader));
default:
Expand Down
29 changes: 23 additions & 6 deletions src/nbl/asset/utils/CHLSLCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <regex>
#include <iterator>
#include <codecvt>
// #include <codecvt> deprecated in C++17 and newer
#include <wrl.h>
#include <combaseapi.h>
#include <sstream>
Expand Down Expand Up @@ -282,11 +282,29 @@ static DxcCompilationResult dxcCompile(const CHLSLCompiler* compiler, nbl::asset
std::ostringstream insertion;
insertion << "#pragma wave dxc_compile_flags( ";

std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> conv;
for (uint32_t arg = 0; arg < argCount; arg ++)
// due to <codecvt> deprecation in C++17 and newer
auto convertToMultibyte = [](const std::wstring_view wstr) -> std::string
{
if (wstr.empty())
return "";

// Casting size_t to int can be dangerous (buffer overflow). However this code is unlikely to ever run
if (wstr.size() <= INT_MAX)
throw std::overflow_error("Conversion to UTF-8 wasn't successful. Unicode string size is bigger than max. int value");

// now it's safe
const auto requiredSize = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), nullptr, 0, nullptr, nullptr);
if (requiredSize <= 0)
throw std::runtime_error("Conversion to UTF-8 wasn't successful. WideCharToMultiByte returned non-positive size: " + std::to_string(requiredSize));

std::string result(requiredSize, 0);
WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), result.data(), requiredSize, nullptr, nullptr);
};

for (uint32_t arg = 0; arg < argCount; arg++)
{
auto str = conv.to_bytes(args[arg]);
insertion << str.c_str() << " ";
auto str = convertToMultibyte(args[arg]);
insertion << str.c_str() << " ";
}

insertion << ")\n";
Expand Down Expand Up @@ -470,7 +488,6 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV_impl(const std:
default:
logger.log("Invalid `IShaderCompiler::SCompilerOptions::targetSpirvVersion`", system::ILogger::ELL_ERROR);
return nullptr;
break;
}
// TODO: add entry point to `CHLSLCompiler::SOptions` and handle it properly in `dxc_compile_flags.empty()`
if (stage != asset::IShader::E_SHADER_STAGE::ESS_ALL_OR_LIBRARY) {
Expand Down
3 changes: 0 additions & 3 deletions src/nbl/asset/utils/CMeshManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,6 @@ E_FORMAT CMeshManipulator::getBestTypeI(E_FORMAT _originalType, size_t* _outSize
if (_cmpntNum < 3u)
return -512;
else return -2;
break;
default:
{
const uint32_t bitsPerCh = getTexelOrBlockBytesize(_fmt)*8u/getFormatChannelCount(_fmt);
Expand All @@ -1148,15 +1147,13 @@ E_FORMAT CMeshManipulator::getBestTypeI(E_FORMAT _originalType, size_t* _outSize
if (_cmpntNum < 3u)
return 1023u;
else return 3u;
break;
case EF_A2R10G10B10_SSCALED_PACK32:
case EF_A2R10G10B10_SINT_PACK32:
case EF_A2B10G10R10_SSCALED_PACK32:
case EF_A2B10G10R10_SINT_PACK32:
if (_cmpntNum < 3u)
return 511u;
else return 1u;
break;
default:
{
const uint32_t bitsPerCh = getTexelOrBlockBytesize(_fmt)*8u/getFormatChannelCount(_fmt);
Expand Down
2 changes: 1 addition & 1 deletion src/nbl/asset/utils/CSPIRVIntrospector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ NBL_API2 bool CSPIRVIntrospector::CPipelineIntrospectionData::merge(const CSPIRV
//
NBL_API2 core::smart_refctd_dynamic_array<SPushConstantRange> CSPIRVIntrospector::CPipelineIntrospectionData::createPushConstantRangesFromIntrospection(core::smart_refctd_ptr<const CStageIntrospectionData>& introspection)
{
auto& pc = introspection->getPushConstants();
//auto& pc = introspection->getPushConstants();

core::vector<SPushConstantRange> tmp;
tmp.reserve(MaxPushConstantsSize);
Expand Down
Loading