Browse Source

Fix a vulkan bug

Panagiotis Christopoulos Charitos 7 years ago
parent
commit
630fa0a6cb

+ 2 - 1
src/anki/gr/vulkan/BufferImpl.cpp

@@ -138,7 +138,8 @@ Error BufferImpl::init(const BufferInitInfo& inf)
 	ANKI_TRACE_STOP_EVENT(VK_BIND_OBJECT);
 
 	m_access = access;
-	m_size = size;
+	m_size = inf.m_size;
+	m_actualSize = size;
 	m_usage = usage;
 	return Error::NONE;
 }

+ 6 - 5
src/anki/gr/vulkan/BufferImpl.h

@@ -47,15 +47,15 @@ public:
 		return m_handle;
 	}
 
-	PtrSize getSize() const
+	Bool usageValid(BufferUsageBit usage) const
 	{
-		ANKI_ASSERT(m_size);
-		return m_size;
+		return (m_usage & usage) == usage;
 	}
 
-	Bool usageValid(BufferUsageBit usage) const
+	PtrSize getActualSize() const
 	{
-		return (m_usage & usage) == usage;
+		ANKI_ASSERT(m_actualSize > 0);
+		return m_actualSize;
 	}
 
 	void computeBarrierInfo(BufferUsageBit before,
@@ -69,6 +69,7 @@ private:
 	VkBuffer m_handle = VK_NULL_HANDLE;
 	GpuMemoryHandle m_memHandle;
 	VkMemoryPropertyFlags m_memoryFlags = 0;
+	PtrSize m_actualSize = 0;
 
 #if ANKI_EXTRA_CHECKS
 	Bool8 m_mapped = false;

+ 3 - 2
src/anki/gr/vulkan/CommandBufferImpl.inl.h

@@ -620,8 +620,9 @@ inline void CommandBufferImpl::fillBuffer(BufferPtr buff, PtrSize offset, PtrSiz
 	ANKI_ASSERT(offset < impl.getSize());
 	ANKI_ASSERT((offset % 4) == 0 && "Should be multiple of 4");
 
-	size = (size == MAX_PTR_SIZE) ? (impl.getSize() - offset) : size;
-	ANKI_ASSERT(offset + size <= impl.getSize());
+	size = (size == MAX_PTR_SIZE) ? (impl.getActualSize() - offset) : size;
+	alignRoundUp(4, size); // Needs to be multiple of 4
+	ANKI_ASSERT(offset + size <= impl.getActualSize());
 	ANKI_ASSERT((size % 4) == 0 && "Should be multiple of 4");
 
 	ANKI_CMD(vkCmdFillBuffer(m_handle, impl.getHandle(), offset, size, value), ANY_OTHER_COMMAND);