Browse Source

Vulkan renderer validation fixes (#1424)

* Skip Instanced Draw Call if no instances

* Fix sampler min/max LOD clamp

These values defaulted to `0.0f`, causing mip-sampling to be completely disabled.

* `fillModeNonSolid` support error handling

Actually test and fail if the device supports `fillModeNonSolid`.

* Acquire the actual Swapchain image count

The create-info struct for creating a swapchain object only actually requests a minimum. After the swapchain is created you must actually get the actual swapchain image-count from the object just in case the driver decides to provide more images than requested.

* Use `VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT` for main command-buffer
Wunk 7 months ago
parent
commit
0da5b5fe3d

+ 3 - 0
TestFramework/Renderer/VK/RenderInstancesVK.cpp

@@ -34,6 +34,9 @@ void RenderInstancesVK::Unlock()
 
 
 void RenderInstancesVK::Draw(RenderPrimitive *inPrimitive, int inStartInstance, int inNumInstances) const
 void RenderInstancesVK::Draw(RenderPrimitive *inPrimitive, int inStartInstance, int inNumInstances) const
 {
 {
+	if (inNumInstances <= 0)
+		return;
+
 	VkCommandBuffer command_buffer = mRenderer->GetCommandBuffer();
 	VkCommandBuffer command_buffer = mRenderer->GetCommandBuffer();
 	RenderPrimitiveVK *primitive = static_cast<RenderPrimitiveVK *>(inPrimitive);
 	RenderPrimitiveVK *primitive = static_cast<RenderPrimitiveVK *>(inPrimitive);
 
 

+ 19 - 3
TestFramework/Renderer/VK/RendererVK.cpp

@@ -291,6 +291,10 @@ void RendererVK::Initialize()
 	// Get memory properties
 	// Get memory properties
 	vkGetPhysicalDeviceMemoryProperties(mPhysicalDevice, &mMemoryProperties);
 	vkGetPhysicalDeviceMemoryProperties(mPhysicalDevice, &mMemoryProperties);
 
 
+	// Get features
+	VkPhysicalDeviceFeatures physical_device_features = {};
+	vkGetPhysicalDeviceFeatures(mPhysicalDevice, &physical_device_features);
+
 	// Create device
 	// Create device
 	float queue_priority = 1.0f;
 	float queue_priority = 1.0f;
 	VkDeviceQueueCreateInfo queue_create_info[2] = {};
 	VkDeviceQueueCreateInfo queue_create_info[2] = {};
@@ -302,8 +306,13 @@ void RendererVK::Initialize()
 	}
 	}
 	queue_create_info[0].queueFamilyIndex = selected_device.mGraphicsQueueIndex;
 	queue_create_info[0].queueFamilyIndex = selected_device.mGraphicsQueueIndex;
 	queue_create_info[1].queueFamilyIndex = selected_device.mPresentQueueIndex;
 	queue_create_info[1].queueFamilyIndex = selected_device.mPresentQueueIndex;
+
 	VkPhysicalDeviceFeatures device_features = {};
 	VkPhysicalDeviceFeatures device_features = {};
+
+	if (!physical_device_features.fillModeNonSolid)
+		FatalError("fillModeNonSolid not supported!");
 	device_features.fillModeNonSolid = VK_TRUE;
 	device_features.fillModeNonSolid = VK_TRUE;
+
 	VkDeviceCreateInfo device_create_info = {};
 	VkDeviceCreateInfo device_create_info = {};
 	device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
 	device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
 	device_create_info.queueCreateInfoCount = selected_device.mGraphicsQueueIndex != selected_device.mPresentQueueIndex? 2 : 1;
 	device_create_info.queueCreateInfoCount = selected_device.mGraphicsQueueIndex != selected_device.mPresentQueueIndex? 2 : 1;
@@ -469,6 +478,8 @@ void RendererVK::Initialize()
 	sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
 	sampler_info.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
 	sampler_info.unnormalizedCoordinates = VK_FALSE;
 	sampler_info.unnormalizedCoordinates = VK_FALSE;
 	sampler_info.compareEnable = VK_FALSE;
 	sampler_info.compareEnable = VK_FALSE;
+	sampler_info.minLod = 0.0f;
+	sampler_info.maxLod = VK_LOD_CLAMP_NONE;
 	sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
 	sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
 	FatalErrorIfFailed(vkCreateSampler(mDevice, &sampler_info, nullptr, &mTextureSamplerRepeat));
 	FatalErrorIfFailed(vkCreateSampler(mDevice, &sampler_info, nullptr, &mTextureSamplerRepeat));
 
 
@@ -636,11 +647,11 @@ void RendererVK::CreateSwapChain(VkPhysicalDevice inDevice)
 		return;
 		return;
 
 
 	// Create the swap chain
 	// Create the swap chain
-	uint32 image_count = max(min(capabilities.minImageCount + 1, capabilities.maxImageCount), capabilities.minImageCount);
+	uint32 desired_image_count = max(min(capabilities.minImageCount + 1, capabilities.maxImageCount), capabilities.minImageCount);
 	VkSwapchainCreateInfoKHR swapchain_create_info = {};
 	VkSwapchainCreateInfoKHR swapchain_create_info = {};
 	swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
 	swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
 	swapchain_create_info.surface = mSurface;
 	swapchain_create_info.surface = mSurface;
-	swapchain_create_info.minImageCount = image_count;
+	swapchain_create_info.minImageCount = desired_image_count;
 	swapchain_create_info.imageFormat = format.format;
 	swapchain_create_info.imageFormat = format.format;
 	swapchain_create_info.imageColorSpace = format.colorSpace;
 	swapchain_create_info.imageColorSpace = format.colorSpace;
 	swapchain_create_info.imageExtent = mSwapChainExtent;
 	swapchain_create_info.imageExtent = mSwapChainExtent;
@@ -664,9 +675,13 @@ void RendererVK::CreateSwapChain(VkPhysicalDevice inDevice)
 	swapchain_create_info.clipped = VK_TRUE;
 	swapchain_create_info.clipped = VK_TRUE;
 	FatalErrorIfFailed(vkCreateSwapchainKHR(mDevice, &swapchain_create_info, nullptr, &mSwapChain));
 	FatalErrorIfFailed(vkCreateSwapchainKHR(mDevice, &swapchain_create_info, nullptr, &mSwapChain));
 
 
+	// Get the actual swap chain image count
+	uint32 image_count;
+	FatalErrorIfFailed(vkGetSwapchainImagesKHR(mDevice, mSwapChain, &image_count, nullptr));
+
 	// Get the swap chain images
 	// Get the swap chain images
 	mSwapChainImages.resize(image_count);
 	mSwapChainImages.resize(image_count);
-	vkGetSwapchainImagesKHR(mDevice, mSwapChain, &image_count, mSwapChainImages.data());
+	FatalErrorIfFailed(vkGetSwapchainImagesKHR(mDevice, mSwapChain, &image_count, mSwapChainImages.data()));
 
 
 	// Create image views
 	// Create image views
 	mSwapChainImageViews.resize(image_count);
 	mSwapChainImageViews.resize(image_count);
@@ -773,6 +788,7 @@ void RendererVK::BeginFrame(const CameraState &inCamera, float inWorldScale)
 
 
 	VkCommandBufferBeginInfo command_buffer_begin_info = {};
 	VkCommandBufferBeginInfo command_buffer_begin_info = {};
 	command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
 	command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
+	command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
 	FatalErrorIfFailed(vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info));
 	FatalErrorIfFailed(vkBeginCommandBuffer(command_buffer, &command_buffer_begin_info));
 
 
 	// Begin the shadow pass
 	// Begin the shadow pass