Browse Source

More android fixes

Panagiotis Christopoulos Charitos 4 years ago
parent
commit
be796ff3bd

+ 2 - 3
AnKi/Gr/Vulkan/GrManagerImpl.cpp

@@ -153,7 +153,7 @@ Error GrManagerImpl::initInternal(const GrManagerInitInfo& init)
 	// Set m_r8g8b8ImagesSupported
 	// Set m_r8g8b8ImagesSupported
 	{
 	{
 		VkImageFormatProperties props = {};
 		VkImageFormatProperties props = {};
-		VkResult res = vkGetPhysicalDeviceImageFormatProperties(
+		const VkResult res = vkGetPhysicalDeviceImageFormatProperties(
 			m_physicalDevice, VK_FORMAT_R8G8B8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
 			m_physicalDevice, VK_FORMAT_R8G8B8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
 			VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &props);
 			VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &props);
 
 
@@ -173,7 +173,7 @@ Error GrManagerImpl::initInternal(const GrManagerInitInfo& init)
 	// Set m_s8ImagesSupported
 	// Set m_s8ImagesSupported
 	{
 	{
 		VkImageFormatProperties props = {};
 		VkImageFormatProperties props = {};
-		VkResult res = vkGetPhysicalDeviceImageFormatProperties(
+		const VkResult res = vkGetPhysicalDeviceImageFormatProperties(
 			m_physicalDevice, VK_FORMAT_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
 			m_physicalDevice, VK_FORMAT_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
 			VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &props);
 			VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &props);
 
 
@@ -1078,7 +1078,6 @@ TexturePtr GrManagerImpl::acquireNextPresentableTexture()
 		ANKI_VK_CHECKF(res);
 		ANKI_VK_CHECKF(res);
 	}
 	}
 
 
-	ANKI_ASSERT(imageIdx < MAX_FRAMES_IN_FLIGHT);
 	m_acquiredImageIdx = U8(imageIdx);
 	m_acquiredImageIdx = U8(imageIdx);
 	return m_crntSwapchain->m_textures[imageIdx];
 	return m_crntSwapchain->m_textures[imageIdx];
 }
 }

+ 9 - 11
AnKi/Gr/Vulkan/SwapchainFactory.cpp

@@ -24,10 +24,7 @@ MicroSwapchain::~MicroSwapchain()
 {
 {
 	const VkDevice dev = m_factory->m_gr->getDevice();
 	const VkDevice dev = m_factory->m_gr->getDevice();
 
 
-	for(TexturePtr& tex : m_textures)
-	{
-		tex.reset(nullptr);
-	}
+	m_textures.destroy(getAllocator());
 
 
 	if(m_swapchain)
 	if(m_swapchain)
 	{
 	{
@@ -161,26 +158,27 @@ Error MicroSwapchain::initInternal()
 
 
 	// Get images
 	// Get images
 	{
 	{
-		uint32_t count = 0;
+		U32 count = 0;
 		ANKI_VK_CHECK(vkGetSwapchainImagesKHR(dev, m_swapchain, &count, nullptr));
 		ANKI_VK_CHECK(vkGetSwapchainImagesKHR(dev, m_swapchain, &count, nullptr));
 		if(count != MAX_FRAMES_IN_FLIGHT)
 		if(count != MAX_FRAMES_IN_FLIGHT)
 		{
 		{
-			ANKI_VK_LOGE("Requested a swapchain with %u images but got one with %u", MAX_FRAMES_IN_FLIGHT, count);
-			return Error::FUNCTION_FAILED;
+			ANKI_VK_LOGI("Requested a swapchain with %u images but got one with %u", MAX_FRAMES_IN_FLIGHT, count);
 		}
 		}
 
 
+		m_textures.create(getAllocator(), count);
+
 		ANKI_VK_LOGI("Created a swapchain. Image count: %u, present mode: %u, size: %ux%u, vsync: %u", count,
 		ANKI_VK_LOGI("Created a swapchain. Image count: %u, present mode: %u, size: %ux%u, vsync: %u", count,
 					 presentMode, surfaceWidth, surfaceHeight, U32(m_factory->m_vsync));
 					 presentMode, surfaceWidth, surfaceHeight, U32(m_factory->m_vsync));
 
 
-		Array<VkImage, MAX_FRAMES_IN_FLIGHT> images;
+		Array<VkImage, 64> images;
+		ANKI_ASSERT(count <= 64);
 		ANKI_VK_CHECK(vkGetSwapchainImagesKHR(dev, m_swapchain, &count, &images[0]));
 		ANKI_VK_CHECK(vkGetSwapchainImagesKHR(dev, m_swapchain, &count, &images[0]));
-		for(U i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i)
+		for(U32 i = 0; i < count; ++i)
 		{
 		{
 			TextureInitInfo init("SwapchainImg");
 			TextureInitInfo init("SwapchainImg");
 			init.m_width = surfaceWidth;
 			init.m_width = surfaceWidth;
 			init.m_height = surfaceHeight;
 			init.m_height = surfaceHeight;
-			init.m_format = Format::B8G8R8A8_UNORM;
-			ANKI_ASSERT(surfaceFormat == VK_FORMAT_B8G8R8A8_UNORM);
+			init.m_format = Format(surfaceFormat); // anki::Format is compatible with VkFormat
 			init.m_usage = TextureUsageBit::IMAGE_COMPUTE_WRITE | TextureUsageBit::IMAGE_TRACE_RAYS_WRITE
 			init.m_usage = TextureUsageBit::IMAGE_COMPUTE_WRITE | TextureUsageBit::IMAGE_TRACE_RAYS_WRITE
 						   | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ
 						   | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ
 						   | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE | TextureUsageBit::PRESENT;
 						   | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE | TextureUsageBit::PRESENT;

+ 1 - 1
AnKi/Gr/Vulkan/SwapchainFactory.h

@@ -27,7 +27,7 @@ class MicroSwapchain
 public:
 public:
 	VkSwapchainKHR m_swapchain = {};
 	VkSwapchainKHR m_swapchain = {};
 
 
-	Array<TexturePtr, MAX_FRAMES_IN_FLIGHT> m_textures;
+	DynamicArray<TexturePtr> m_textures;
 
 
 	MicroSwapchain(SwapchainFactory* factory);
 	MicroSwapchain(SwapchainFactory* factory);
 
 

+ 41 - 40
AnKi/Resource/ResourceFilesystem.cpp

@@ -246,7 +246,7 @@ Error ResourceFilesystem::init(const ConfigSet& config, const CString& cacheDir)
 
 
 #if ANKI_OS_ANDROID
 #if ANKI_OS_ANDROID
 	// Add the files of the .apk
 	// Add the files of the .apk
-	ANKI_CHECK(addNewPath("*special*", excludedStrings));
+	ANKI_CHECK(addNewPath("", excludedStrings, true));
 #endif
 #endif
 
 
 	for(auto& path : paths)
 	for(auto& path : paths)
@@ -268,7 +268,7 @@ void ResourceFilesystem::addCachePath(const CString& path)
 	m_paths.emplaceBack(m_alloc, std::move(p));
 	m_paths.emplaceBack(m_alloc, std::move(p));
 }
 }
 
 
-Error ResourceFilesystem::addNewPath(const CString& path, const StringListAuto& excludedStrings)
+Error ResourceFilesystem::addNewPath(const CString& path, const StringListAuto& excludedStrings, Bool special)
 {
 {
 	U32 fileCount = 0;
 	U32 fileCount = 0;
 	static const CString extension(".ankizip");
 	static const CString extension(".ankizip");
@@ -285,8 +285,45 @@ Error ResourceFilesystem::addNewPath(const CString& path, const StringListAuto&
 		return false;
 		return false;
 	};
 	};
 
 
-	auto pos = path.find(extension);
-	if(pos != CString::NPOS && pos == path.getLength() - extension.getLength())
+	PtrSize pos;
+	if(special)
+	{
+		// Android apk, read the file that contains the directory structure
+
+		// Read the file
+		File dirStructure;
+		ANKI_CHECK(dirStructure.open("DirStructure.txt", FileOpenFlag::READ | FileOpenFlag::SPECIAL));
+		StringAuto txt(m_alloc);
+		ANKI_CHECK(dirStructure.readAllText(txt));
+
+		StringListAuto filenames(m_alloc);
+		filenames.splitString(txt, '\n');
+
+		if(filenames.isEmpty())
+		{
+			ANKI_RESOURCE_LOGE("DirStructure.txt is empty");
+			return Error::USER_DATA;
+		}
+
+		// Create the Path
+		m_paths.emplaceFront(m_alloc, Path());
+		Path& p = m_paths.getFront();
+		while(!filenames.isEmpty())
+		{
+			const String& filename = filenames.getFront();
+			if(!rejectPath(filename))
+			{
+				p.m_files.pushBack(m_alloc, filename);
+				++fileCount;
+			}
+			filenames.popFront();
+		}
+
+		p.m_path.sprintf(m_alloc, "%s", &path[0]);
+		p.m_isArchive = false;
+		p.m_isSpecial = true;
+	}
+	else if((pos = path.find(extension)) != CString::NPOS && pos == path.getLength() - extension.getLength())
 	{
 	{
 		// It's an archive
 		// It's an archive
 
 
@@ -333,42 +370,6 @@ Error ResourceFilesystem::addNewPath(const CString& path, const StringListAuto&
 		m_paths.emplaceFront(m_alloc, std::move(p));
 		m_paths.emplaceFront(m_alloc, std::move(p));
 		unzClose(zfile);
 		unzClose(zfile);
 	}
 	}
-	else if(path == "*special*")
-	{
-		// Android apk, read the file that contains the directory structure
-
-		// Read the file
-		File dirStructure;
-		ANKI_CHECK(dirStructure.open("DirStructure.txt", FileOpenFlag::READ | FileOpenFlag::SPECIAL));
-		StringAuto txt(m_alloc);
-		ANKI_CHECK(dirStructure.readAllText(txt));
-
-		StringListAuto filenames(m_alloc);
-		filenames.splitString(txt, '\n');
-
-		if(filenames.isEmpty())
-		{
-			ANKI_RESOURCE_LOGE("DirStructure.txt is empty");
-			return Error::USER_DATA;
-		}
-
-		// Create the Path
-		m_paths.emplaceFront(m_alloc, Path());
-		Path& p = m_paths.getFront();
-		while(!filenames.isEmpty())
-		{
-			const String& filename = filenames.getFront();
-			if(!rejectPath(filename))
-			{
-				p.m_files.pushBack(m_alloc, filename);
-				++fileCount;
-			}
-		}
-
-		p.m_path.sprintf(m_alloc, "%s", &path[0]);
-		p.m_isArchive = false;
-		p.m_isSpecial = true;
-	}
 	else
 	else
 	{
 	{
 		// It's simple directory
 		// It's simple directory

+ 1 - 1
AnKi/Resource/ResourceFilesystem.h

@@ -150,7 +150,7 @@ private:
 	String m_cacheDir;
 	String m_cacheDir;
 
 
 	/// Add a filesystem path or an archive. The path is read-only.
 	/// Add a filesystem path or an archive. The path is read-only.
-	ANKI_USE_RESULT Error addNewPath(const CString& path, const StringListAuto& excludedStrings);
+	ANKI_USE_RESULT Error addNewPath(const CString& path, const StringListAuto& excludedStrings, Bool special = false);
 
 
 	void addCachePath(const CString& path);
 	void addCachePath(const CString& path);
 };
 };