Explorar el Código

Fix GCC 9.x warnings and workaround a GCC 9.x bug

Panagiotis Christopoulos Charitos hace 6 años
padre
commit
94c60480b2

+ 1 - 1
CMakeLists.txt

@@ -365,7 +365,7 @@ endif()
 if(NOT MSVC)
 	add_definitions("-pedantic -Wall -W -Wextra -Wstrict-aliasing -Wwrite-strings -Wunused -Wunused-variable "
 		"-Wno-unused-parameter -Wundef -Wno-ignored-attributes -Wno-implicit-fallthrough -Wunused-result"
-		"-Wconversion -Wno-sign-conversion -Wno-keyword-macro -Wno-string-conversion -std=c++14")
+		"-Wconversion -Wno-sign-conversion -Wno-keyword-macro -Wno-string-conversion -Wno-class-memaccess -std=c++14")
 else()
 	add_definitions("/wd4996 /wd4244 /wd4262 /wd4267")
 endif()

+ 1 - 0
src/anki/gr/RenderGraph.cpp

@@ -1289,6 +1289,7 @@ void RenderGraph::getStatistics(RenderGraphStatistics& statistics) const
 	{
 		Second start, end;
 		TimestampQueryResult res = m_statistics.m_timestamps[oldFrame * 2]->getResult(start);
+		(void)res;
 		ANKI_ASSERT(res == TimestampQueryResult::AVAILABLE);
 
 		res = m_statistics.m_timestamps[oldFrame * 2 + 1]->getResult(end);

+ 14 - 5
src/anki/gr/RenderGraph.h

@@ -15,6 +15,7 @@
 #include <anki/gr/CommandBuffer.h>
 #include <anki/util/HashMap.h>
 #include <anki/util/BitSet.h>
+#include <anki/util/WeakArray.h>
 
 namespace anki
 {
@@ -403,12 +404,20 @@ class GraphicsRenderPassDescription : public RenderPassDescriptionBase
 
 public:
 	void setFramebufferInfo(const FramebufferDescription& fbInfo,
-		const Array<RenderTargetHandle, MAX_COLOR_ATTACHMENTS>& colorRenderTargetHandles,
+		ConstWeakArray<RenderTargetHandle> colorRenderTargetHandles,
 		RenderTargetHandle depthStencilRenderTargetHandle,
-		U32 minx,
-		U32 miny,
-		U32 maxx,
-		U32 maxy);
+		U32 minx = 0,
+		U32 miny = 0,
+		U32 maxx = MAX_U32,
+		U32 maxy = MAX_U32);
+
+	void setFramebufferInfo(const FramebufferDescription& fbInfo,
+		std::initializer_list<RenderTargetHandle> colorRenderTargetHandles,
+		RenderTargetHandle depthStencilRenderTargetHandle,
+		U32 minx = 0,
+		U32 miny = 0,
+		U32 maxx = MAX_U32,
+		U32 maxy = MAX_U32);
 
 private:
 	Array<RenderTargetHandle, MAX_COLOR_ATTACHMENTS + 1> m_rtHandles;

+ 29 - 6
src/anki/gr/RenderGraph.inl.h

@@ -129,12 +129,35 @@ inline void RenderPassDescriptionBase::newDependency(const RenderPassDependency&
 }
 
 inline void GraphicsRenderPassDescription::setFramebufferInfo(const FramebufferDescription& fbInfo,
-	const Array<RenderTargetHandle, MAX_COLOR_ATTACHMENTS>& colorRenderTargetHandles,
+	std::initializer_list<RenderTargetHandle> colorRenderTargetHandles,
 	RenderTargetHandle depthStencilRenderTargetHandle,
-	U32 minx = 0,
-	U32 miny = 0,
-	U32 maxx = MAX_U32,
-	U32 maxy = MAX_U32)
+	U32 minx,
+	U32 miny,
+	U32 maxx,
+	U32 maxy)
+{
+	Array<RenderTargetHandle, MAX_COLOR_ATTACHMENTS> rts;
+	U32 count = 0;
+	for(const RenderTargetHandle& h : colorRenderTargetHandles)
+	{
+		rts[count++] = h;
+	}
+	setFramebufferInfo(fbInfo,
+		ConstWeakArray<RenderTargetHandle>(&rts[0], count),
+		depthStencilRenderTargetHandle,
+		minx,
+		miny,
+		maxx,
+		maxy);
+}
+
+inline void GraphicsRenderPassDescription::setFramebufferInfo(const FramebufferDescription& fbInfo,
+	ConstWeakArray<RenderTargetHandle> colorRenderTargetHandles,
+	RenderTargetHandle depthStencilRenderTargetHandle,
+	U32 minx,
+	U32 miny,
+	U32 maxx,
+	U32 maxy)
 {
 #if ANKI_ASSERTS_ENABLED
 	ANKI_ASSERT(fbInfo.isBacked() && "Forgot call GraphicsRenderPassFramebufferInfo::bake");
@@ -161,7 +184,7 @@ inline void GraphicsRenderPassDescription::setFramebufferInfo(const FramebufferD
 #endif
 
 	m_fbDescr = fbInfo;
-	memcpy(&m_rtHandles[0], &colorRenderTargetHandles[0], sizeof(colorRenderTargetHandles));
+	memcpy(m_rtHandles.getBegin(), colorRenderTargetHandles.getBegin(), colorRenderTargetHandles.getSizeInBytes());
 	m_rtHandles[MAX_COLOR_ATTACHMENTS] = depthStencilRenderTargetHandle;
 	m_fbRenderArea = {{minx, miny, maxx, maxy}};
 }

+ 2 - 2
src/anki/gr/Sampler.h

@@ -35,8 +35,8 @@ public:
 
 	U64 computeHash() const
 	{
-		const U8* const first = reinterpret_cast<const U8* const>(&m_minLod);
-		const U8* const last = reinterpret_cast<const U8* const>(&m_addressing) + sizeof(m_addressing);
+		const U8* first = reinterpret_cast<const U8*>(&m_minLod);
+		const U8* last = reinterpret_cast<const U8*>(&m_addressing) + sizeof(m_addressing);
 		const U32 size = U32(last - first);
 		ANKI_ASSERT(size
 					== sizeof(F32) * 2 + sizeof(SamplingFilter) * 2 + sizeof(CompareOperation) + sizeof(I8)

+ 2 - 2
src/anki/gr/Texture.h

@@ -43,8 +43,8 @@ public:
 
 	U64 computeHash() const
 	{
-		const U8* const first = reinterpret_cast<const U8* const>(&m_width);
-		const U8* const last = reinterpret_cast<const U8* const>(&m_samples) + sizeof(m_samples);
+		const U8* first = reinterpret_cast<const U8*>(&m_width);
+		const U8* last = reinterpret_cast<const U8*>(&m_samples) + sizeof(m_samples);
 		const U size = last - first;
 		ANKI_ASSERT(size
 					== sizeof(m_width) + sizeof(m_height) + sizeof(m_depth) + sizeof(m_layerCount) + sizeof(m_format)

+ 1 - 1
src/anki/math/Functions.cpp

@@ -36,7 +36,7 @@ static void sinCosInternal(const Scalar a_, Scalar& sina, Scalar& cosa)
 	const Scalar RATIONAL_HALF_PI = 201 / 128.0;
 	const Scalar REMAINDER_HALF_PI = Scalar(4.8382679e-4);
 
-	floatA = (a - RATIONAL_HALF_PI * intA) - REMAINDER_HALF_PI * intA;
+	floatA = (a - RATIONAL_HALF_PI * Scalar(intA)) - REMAINDER_HALF_PI * Scalar(intA);
 
 	Scalar floatAMinusHalfPi = (floatA - RATIONAL_HALF_PI) - REMAINDER_HALF_PI;
 

+ 12 - 0
src/anki/math/Quat.h

@@ -165,6 +165,18 @@ public:
 	}
 	/// @}
 
+	/// @name Operators with same type
+	/// @{
+	TQuat& operator=(const TQuat& b)
+	{
+		x() = b.x();
+		y() = b.y();
+		z() = b.z();
+		w() = b.w();
+		return *this;
+	}
+	/// @}
+
 	/// @name Other
 	/// @{
 

+ 1 - 0
src/anki/physics/Common.h

@@ -15,6 +15,7 @@
 #	pragma GCC diagnostic ignored "-Wall"
 #	pragma GCC diagnostic ignored "-Wconversion"
 #	pragma GCC diagnostic ignored "-Wfloat-conversion"
+#	pragma GCC diagnostic ignored "-Wdeprecated-copy"
 #endif
 #if ANKI_COMPILER_MSVC
 #	pragma warning(push)

+ 2 - 1
src/anki/renderer/Dbg.cpp

@@ -182,7 +182,8 @@ void Dbg::populateRenderGraph(RenderingContext& ctx)
 		},
 		this,
 		computeNumberOfSecondLevelCommandBuffers(U32(ctx.m_renderQueue->m_renderables.getSize())));
-	pass.setFramebufferInfo(m_fbDescr, {{m_runCtx.m_rt}}, m_r->getGBuffer().getDepthRt());
+
+	pass.setFramebufferInfo(m_fbDescr, {m_runCtx.m_rt}, m_r->getGBuffer().getDepthRt());
 
 	pass.newDependency({m_runCtx.m_rt, TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE});
 	pass.newDependency({m_r->getGBuffer().getDepthRt(),

+ 4 - 1
src/anki/renderer/DepthDownscale.cpp

@@ -65,7 +65,10 @@ Error DepthDownscale::initInternal(const ConfigSet&)
 		m_copyToBuff.m_buffAddr = m_copyToBuff.m_buff->map(0, buffInit.m_size, BufferMapAccessBit::READ);
 
 		// Fill the buffer with 1.0f
-		memorySet(static_cast<F32*>(m_copyToBuff.m_buffAddr), 1.0f, lastMipHeight * lastMipWidth);
+		for(U32 i = 0; i < lastMipHeight * lastMipWidth; ++i)
+		{
+			static_cast<F32*>(m_copyToBuff.m_buffAddr)[i] = 1.0f;
+		}
 	}
 
 	return Error::NONE;

+ 1 - 1
src/anki/renderer/DownscaleBlur.cpp

@@ -144,7 +144,7 @@ void DownscaleBlur::populateRenderGraph(RenderingContext& ctx)
 				},
 				this,
 				0);
-			pass.setFramebufferInfo(m_fbDescrs[i], {{m_runCtx.m_rt}}, {});
+			pass.setFramebufferInfo(m_fbDescrs[i], {m_runCtx.m_rt}, {});
 
 			if(i > 0)
 			{

+ 1 - 1
src/anki/renderer/FinalComposite.cpp

@@ -146,7 +146,7 @@ void FinalComposite::populateRenderGraph(RenderingContext& ctx)
 		},
 		this,
 		0);
-	pass.setFramebufferInfo(m_fbDescr, {{ctx.m_outRenderTarget}}, {});
+	pass.setFramebufferInfo(m_fbDescr, {ctx.m_outRenderTarget}, {});
 
 	pass.newDependency({ctx.m_outRenderTarget, TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE});
 

+ 2 - 1
src/anki/renderer/GBuffer.cpp

@@ -156,7 +156,8 @@ void GBuffer::populateRenderGraph(RenderingContext& ctx)
 	// Create pass
 	GraphicsRenderPassDescription& pass = rgraph.newGraphicsRenderPass("GBuffer");
 
-	pass.setFramebufferInfo(m_fbDescr, rts, m_depthRt);
+	pass.setFramebufferInfo(
+		m_fbDescr, ConstWeakArray<RenderTargetHandle>(&rts[0], GBUFFER_COLOR_ATTACHMENT_COUNT), m_depthRt);
 	pass.setWork(
 		[](RenderPassWorkContext& rgraphCtx) {
 			GBuffer* self = static_cast<GBuffer*>(rgraphCtx.m_userData);

+ 2 - 1
src/anki/renderer/GBufferPost.cpp

@@ -63,7 +63,8 @@ void GBufferPost::populateRenderGraph(RenderingContext& ctx)
 		[](RenderPassWorkContext& rgraphCtx) { static_cast<GBufferPost*>(rgraphCtx.m_userData)->run(rgraphCtx); },
 		this,
 		0);
-	rpass.setFramebufferInfo(m_fbDescr, {{m_r->getGBuffer().getColorRt(0), m_r->getGBuffer().getColorRt(1)}}, {});
+
+	rpass.setFramebufferInfo(m_fbDescr, {m_r->getGBuffer().getColorRt(0), m_r->getGBuffer().getColorRt(1)}, {});
 
 	rpass.newDependency({m_r->getGBuffer().getColorRt(0), TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ_WRITE});
 	rpass.newDependency({m_r->getGBuffer().getColorRt(1), TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ_WRITE});

+ 7 - 0
src/anki/renderer/ShadowMapping.cpp

@@ -292,7 +292,14 @@ void ShadowMapping::populateRenderGraph(RenderingContext& ctx)
 Mat4 ShadowMapping::createSpotLightTextureMatrix(const Viewport& viewport) const
 {
 	const F32 atlasSize = F32(m_atlas.m_tileResolution * m_atlas.m_tileCountBothAxis);
+#if ANKI_COMPILER_GCC_COMPATIBLE
+#	pragma GCC diagnostic push
+#	pragma GCC diagnostic ignored "-Wpedantic" // Because GCC and clang throw an incorrect warning
+#endif
 	const Vec2 uv(F32(viewport[0]) / atlasSize, F32(viewport[1]) / atlasSize);
+#if ANKI_COMPILER_GCC_COMPATIBLE
+#	pragma GCC diagnostic pop
+#endif
 	ANKI_ASSERT(uv >= Vec2(0.0f) && uv <= Vec2(1.0f));
 
 	ANKI_ASSERT(viewport[2] == viewport[3]);

+ 1 - 1
src/anki/resource/ParticleEmitterResource.cpp

@@ -27,7 +27,7 @@ ANKI_USE_RESULT Error getXmlVal(const XmlElement& el, const CString& tag, Vec3&
 
 ParticleEmitterProperties& ParticleEmitterProperties::operator=(const ParticleEmitterProperties& b)
 {
-	std::memcpy(this, &b, sizeof(ParticleEmitterProperties));
+	memcpy(this, &b, sizeof(ParticleEmitterProperties));
 	return *this;
 }
 

+ 6 - 0
src/anki/resource/RenderingKey.h

@@ -46,6 +46,12 @@ public:
 	{
 	}
 
+	RenderingKey& operator=(const RenderingKey& b)
+	{
+		memcpy(this, &b, sizeof(*this));
+		return *this;
+	}
+
 	Bool operator==(const RenderingKey& b) const
 	{
 		return m_pass == b.m_pass && m_lod == b.m_lod && m_instanceCount == b.m_instanceCount

+ 1 - 5
src/anki/resource/ShaderProgramResource.cpp

@@ -312,11 +312,7 @@ void ShaderProgramResource::initVariant(ConstWeakArray<ShaderProgramResourceMuta
 {
 	variant.m_activeInputVars.unsetAll();
 	variant.m_blockInfos.create(getAllocator(), m_inputVars.getSize());
-	variant.m_bindings.create(getAllocator(), m_inputVars.getSize());
-	if(m_inputVars.getSize() > 0)
-	{
-		memorySet<I16>(&variant.m_bindings[0], -1, variant.m_bindings.getSize());
-	}
+	variant.m_bindings.create(getAllocator(), m_inputVars.getSize(), -1);
 
 	// Get instance count, one mutation has it
 	U32 instanceCount = 1;

+ 1 - 1
src/anki/script/LuaBinder.cpp

@@ -94,7 +94,7 @@ void* LuaBinder::luaAllocCallback(void* userData, void* ptr, PtrSize osize, PtrS
 			// realloc
 
 			out = binder.m_alloc.getMemoryPool().allocate(nsize, 16);
-			std::memcpy(out, ptr, osize);
+			memcpy(out, ptr, osize);
 			binder.m_alloc.getMemoryPool().free(ptr);
 		}
 	}

+ 1 - 1
src/anki/util/File.cpp

@@ -348,7 +348,7 @@ Error File::readF32(F32& out)
 	Error err = readU32(integer);
 	if(!err)
 	{
-		std::memcpy(&out, &integer, sizeof(F32));
+		memcpy(&out, &integer, sizeof(F32));
 	}
 
 	return err;

+ 0 - 10
src/anki/util/Functions.h

@@ -269,16 +269,6 @@ struct RemovePointer<T*>
 	typedef T Type;
 };
 
-template<typename T>
-void memorySet(T* dest, T value, PtrSize count)
-{
-	ANKI_ASSERT(dest);
-	while(count--)
-	{
-		dest[count] = value;
-	}
-}
-
 /// Zero memory of an object
 template<typename T>
 void zeroMemory(T& x)

+ 7 - 0
src/anki/util/List.h

@@ -84,6 +84,13 @@ public:
 		ANKI_ASSERT(list);
 	}
 
+	ListIterator& operator=(const ListIterator& b)
+	{
+		m_node = b.m_node;
+		m_list = b.m_list;
+		return *this;
+	}
+
 	TValueReference operator*() const
 	{
 		ANKI_ASSERT(m_node);

+ 10 - 5
src/anki/util/SparseArray.h

@@ -75,6 +75,16 @@ public:
 		ANKI_ASSERT(arr);
 	}
 
+	SparseArrayIterator& operator=(const SparseArrayIterator& b)
+	{
+		m_array = b.m_array;
+		m_elementIdx = b.m_elementIdx;
+#if ANKI_EXTRA_CHECKS
+		m_iteratorVer = b.m_iteratorVer;
+#endif
+		return *this;
+	}
+
 	TValueReference operator*() const
 	{
 		check();
@@ -360,11 +370,6 @@ protected:
 	public:
 		Index m_idx;
 		Bool m_alive;
-
-		Metadata() = delete;
-		Metadata(const Metadata&) = delete;
-		Metadata(Metadata&&) = delete;
-		~Metadata() = delete;
 	};
 
 	Value* m_elements = nullptr;

+ 4 - 4
src/anki/util/String.cpp

@@ -154,7 +154,7 @@ void String::create(Allocator alloc, const CStringType& cstr)
 	auto len = cstr.getLength();
 	auto size = len + 1;
 	m_data.create(alloc, size);
-	std::memcpy(&m_data[0], &cstr[0], sizeof(Char) * size);
+	memcpy(&m_data[0], &cstr[0], sizeof(Char) * size);
 }
 
 void String::create(Allocator alloc, ConstIterator first, ConstIterator last)
@@ -163,7 +163,7 @@ void String::create(Allocator alloc, ConstIterator first, ConstIterator last)
 	auto length = last - first;
 	m_data.create(alloc, length + 1);
 
-	std::memcpy(&m_data[0], first, length);
+	memcpy(&m_data[0], first, length);
 	m_data[length] = '\0';
 }
 
@@ -194,10 +194,10 @@ void String::appendInternal(Allocator& alloc, const Char* str, PtrSize strLen)
 
 	if(!m_data.isEmpty())
 	{
-		std::memcpy(&newData[0], &m_data[0], sizeof(Char) * size);
+		memcpy(&newData[0], &m_data[0], sizeof(Char) * size);
 	}
 
-	std::memcpy(&newData[size - 1], str, sizeof(Char) * strLen);
+	memcpy(&newData[size - 1], str, sizeof(Char) * strLen);
 
 	newData[newData.getSize() - 1] = '\0';
 

+ 2 - 2
src/anki/util/StringList.cpp

@@ -54,12 +54,12 @@ void StringList::join(const CString& separator, StringAuto& out) const
 	for(; it != Base::getEnd(); it++)
 	{
 		const String& from = *it;
-		std::memcpy(to, &from[0], from.getLength() * sizeof(Char));
+		memcpy(to, &from[0], from.getLength() * sizeof(Char));
 		to += from.getLength();
 
 		if(it != Base::end() - 1)
 		{
-			std::memcpy(to, &separator[0], sepLen * sizeof(Char));
+			memcpy(to, &separator[0], sepLen * sizeof(Char));
 			to += sepLen;
 		}
 	}

+ 1 - 1
src/anki/util/ThreadPosix.cpp

@@ -48,7 +48,7 @@ Thread::Thread(const char* name)
 	{
 		U len = std::strlen(name);
 		len = std::min<U>(len, sizeof(m_name) - 1);
-		std::memcpy(&m_name[0], &name[0], len);
+		memcpy(&m_name[0], &name[0], len);
 		m_name[len] = '\0';
 	}
 	else

+ 1 - 1
src/anki/util/ThreadWindows.cpp

@@ -44,7 +44,7 @@ Thread::Thread(const char* name)
 	{
 		U len = std::strlen(name);
 		len = min<U>(len, sizeof(m_name) - 1);
-		std::memcpy(&m_name[0], &name[0], len);
+		memcpy(&m_name[0], &name[0], len);
 		m_name[len] = '\0';
 	}
 	else