From 45f5d0d5bede2da089448761e7e5dfd87307f0ef Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 23 Sep 2021 15:19:09 +0800 Subject: [PATCH] fixed a bug that don't copy color_space data. --- inc/hgl/graph/VKDevice.h | 3 ++- inc/hgl/graph/VKDeviceAttribute.h | 4 ++-- src/SceneGraph/CMakeLists.txt | 2 +- src/SceneGraph/Vulkan/VKDeviceAttribute.cpp | 23 ++++++++++---------- src/SceneGraph/Vulkan/VKDeviceRenderPass.cpp | 2 +- src/SceneGraph/Vulkan/VKDeviceSwapchain.cpp | 6 ++--- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/inc/hgl/graph/VKDevice.h b/inc/hgl/graph/VKDevice.h index 3faa2452..1592a328 100644 --- a/inc/hgl/graph/VKDevice.h +++ b/inc/hgl/graph/VKDevice.h @@ -74,7 +74,8 @@ public: VkDescriptorPool GetDescriptorPool () {return attr->desc_pool;} VkPipelineCache GetPipelineCache () {return attr->pipeline_cache;} - const VkFormat GetSurfaceFormat ()const {return attr->format;} + const VkFormat GetSurfaceFormat ()const {return attr->surface_format.format;} + const VkColorSpaceKHR GetColorSpace ()const {return attr->surface_format.colorSpace;} VkQueue GetGraphicsQueue () {return attr->graphics_queue;} RenderPass * GetRenderPass () {return device_render_pass;} diff --git a/inc/hgl/graph/VKDeviceAttribute.h b/inc/hgl/graph/VKDeviceAttribute.h index 4f25fdaa..ddf13877 100644 --- a/inc/hgl/graph/VKDeviceAttribute.h +++ b/inc/hgl/graph/VKDeviceAttribute.h @@ -25,8 +25,8 @@ struct GPUDeviceAttribute List family_properties; List supports_present; - List surface_formts; - VkFormat format; + List surface_formats_list; + VkSurfaceFormatKHR surface_format; List present_modes; VkSurfaceTransformFlagBitsKHR preTransform; diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 3a72de92..fa2988a0 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -109,7 +109,7 @@ SET(VK_MEMORY_SOURCE ${SG_INCLUDE_PATH}/VKMemory.h Vulkan/VKMemoryAllocator.cpp Vulkan/VKBuffer.cpp ) - + SET(VK_DEVICE_SOURCE ${SG_INCLUDE_PATH}/VKDevice.h ${SG_INCLUDE_PATH}/VKDeviceAttribute.h Vulkan/VKDeviceAttribute.cpp diff --git a/src/SceneGraph/Vulkan/VKDeviceAttribute.cpp b/src/SceneGraph/Vulkan/VKDeviceAttribute.cpp index f8e1803c..20dfb22e 100644 --- a/src/SceneGraph/Vulkan/VKDeviceAttribute.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceAttribute.cpp @@ -71,29 +71,30 @@ void GPUDeviceAttribute::Refresh() { uint32_t format_count; + + surface_format.format = VK_FORMAT_B8G8R8A8_SRGB; + surface_format.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + if (vkGetPhysicalDeviceSurfaceFormatsKHR(pdevice, surface, &format_count, nullptr) == VK_SUCCESS) { - surface_formts.SetCount(format_count); + surface_formats_list.SetCount(format_count); - if (vkGetPhysicalDeviceSurfaceFormatsKHR(pdevice, surface, &format_count, surface_formts.GetData()) != VK_SUCCESS) + if (vkGetPhysicalDeviceSurfaceFormatsKHR(pdevice, surface, &format_count, surface_formats_list.GetData()) != VK_SUCCESS) { - surface_formts.Clear(); - format = VK_FORMAT_B8G8R8A8_UNORM; + surface_formats_list.Clear(); } else { - VkSurfaceFormatKHR *sf = surface_formts.GetData(); + VkSurfaceFormatKHR *sf = surface_formats_list.GetData(); - if (format_count == 1 && sf->format == VK_FORMAT_UNDEFINED) - format = VK_FORMAT_B8G8R8A8_UNORM; - else + if (format_count>1) { - format=VK_FORMAT_UNDEFINED; + surface_format.format=VK_FORMAT_UNDEFINED; for(uint32_t i=0;iformat>format) - format=sf->format; + if(sf->format>surface_format.format) + surface_format=*sf; ++sf; } diff --git a/src/SceneGraph/Vulkan/VKDeviceRenderPass.cpp b/src/SceneGraph/Vulkan/VKDeviceRenderPass.cpp index d8f1e50a..c79f746e 100644 --- a/src/SceneGraph/Vulkan/VKDeviceRenderPass.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceRenderPass.cpp @@ -8,7 +8,7 @@ void GPUDevice::InitRenderPassManage() { render_pass_manage=new DeviceRenderPassManage(attr->device,attr->pipeline_cache); - SwapchainRenderbufferInfo rbi(attr->format,attr->physical_device->GetDepthFormat()); + SwapchainRenderbufferInfo rbi(attr->surface_format.format,attr->physical_device->GetDepthFormat()); device_render_pass=render_pass_manage->AcquireRenderPass(&rbi); } diff --git a/src/SceneGraph/Vulkan/VKDeviceSwapchain.cpp b/src/SceneGraph/Vulkan/VKDeviceSwapchain.cpp index 9492ca05..e4d51270 100644 --- a/src/SceneGraph/Vulkan/VKDeviceSwapchain.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceSwapchain.cpp @@ -24,8 +24,8 @@ namespace swapchain_ci.flags =0; swapchain_ci.surface =dev_attr->surface; swapchain_ci.minImageCount =3;//rsa->surface_caps.minImageCount; - swapchain_ci.imageFormat =dev_attr->format; - swapchain_ci.imageColorSpace =VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + swapchain_ci.imageFormat =dev_attr->surface_format.format; + swapchain_ci.imageColorSpace =dev_attr->surface_format.colorSpace; swapchain_ci.imageExtent =extent; swapchain_ci.imageArrayLayers =1; swapchain_ci.imageUsage =VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; @@ -79,7 +79,7 @@ bool GPUDevice::CreateSwapchainColorTexture() return(false); for(VkImage ip:sc_images) - swapchain->sc_color.Add(CreateTexture2D(new SwapchainColorTextureCreateInfo(attr->format,swapchain->extent,ip))); + swapchain->sc_color.Add(CreateTexture2D(new SwapchainColorTextureCreateInfo(attr->surface_format.format,swapchain->extent,ip))); return(true); }