From 354b37be560560dbd7e58f04dc15d9113c3af28c Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 5 Feb 2019 15:15:39 +0000 Subject: [PATCH] Add support for VK_EXT_sample_locations --- qrenderdoc/Code/pyrenderdoc/renderdoc.i | 1 + .../VulkanPipelineStateViewer.cpp | 28 +- .../PipelineState/VulkanPipelineStateViewer.h | 3 +- renderdoc/api/replay/data_types.h | 17 + renderdoc/api/replay/vk_pipestate.h | 22 ++ renderdoc/driver/vulkan/vk_common.h | 16 + renderdoc/driver/vulkan/vk_core.cpp | 5 + renderdoc/driver/vulkan/vk_core.h | 8 + renderdoc/driver/vulkan/vk_dispatchtables.cpp | 13 +- renderdoc/driver/vulkan/vk_dispatchtables.h | 15 +- renderdoc/driver/vulkan/vk_hookset_defs.h | 77 ++++- renderdoc/driver/vulkan/vk_info.cpp | 98 +++++- renderdoc/driver/vulkan/vk_info.h | 34 +- renderdoc/driver/vulkan/vk_layer.cpp | 13 +- renderdoc/driver/vulkan/vk_next_chains.cpp | 13 +- renderdoc/driver/vulkan/vk_replay.cpp | 16 + renderdoc/driver/vulkan/vk_serialise.cpp | 152 ++++++++- renderdoc/driver/vulkan/vk_shader_cache.cpp | 6 +- renderdoc/driver/vulkan/vk_state.cpp | 30 +- renderdoc/driver/vulkan/vk_state.h | 7 + renderdoc/driver/vulkan/vk_stringise.cpp | 3 +- .../driver/vulkan/wrappers/vk_cmd_funcs.cpp | 36 ++- .../vulkan/wrappers/vk_device_funcs.cpp | 50 ++- .../vulkan/wrappers/vk_dynamic_funcs.cpp | 69 ++++ .../driver/vulkan/wrappers/vk_get_funcs.cpp | 8 + renderdoc/replay/renderdoc_serialise.inl | 15 +- util/test/demos/demos.vcxproj | 1 + util/test/demos/demos.vcxproj.filters | 3 + util/test/demos/vk/vk_helpers.h | 23 ++ util/test/demos/vk/vk_sample_locations.cpp | 301 ++++++++++++++++++ util/test/tests/Vulkan/VK_Indirect.py | 5 +- util/test/tests/Vulkan/VK_Sample_Locations.py | 137 ++++++++ 32 files changed, 1145 insertions(+), 80 deletions(-) create mode 100644 util/test/demos/vk/vk_sample_locations.cpp create mode 100644 util/test/tests/Vulkan/VK_Sample_Locations.py diff --git a/qrenderdoc/Code/pyrenderdoc/renderdoc.i b/qrenderdoc/Code/pyrenderdoc/renderdoc.i index cf05a0006..594a7f763 100644 --- a/qrenderdoc/Code/pyrenderdoc/renderdoc.i +++ b/qrenderdoc/Code/pyrenderdoc/renderdoc.i @@ -284,6 +284,7 @@ TEMPLATE_ARRAY_INSTANTIATE(rdcarray, BoundVBuffer) TEMPLATE_ARRAY_INSTANTIATE(rdcarray, VertexInputAttribute) TEMPLATE_ARRAY_INSTANTIATE(rdcarray, BoundResource) TEMPLATE_ARRAY_INSTANTIATE(rdcarray, BoundResourceArray) +TEMPLATE_ARRAY_INSTANTIATE(rdcarray, FloatVector) TEMPLATE_NAMESPACE_ARRAY_INSTANTIATE(rdcarray, VKPipe, Attachment) TEMPLATE_NAMESPACE_ARRAY_INSTANTIATE(rdcarray, VKPipe, BindingElement) TEMPLATE_NAMESPACE_ARRAY_INSTANTIATE(rdcarray, VKPipe, DescriptorBinding) diff --git a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp index 8bbc0bdbd..e2ca8da1d 100644 --- a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp @@ -428,7 +428,7 @@ void VulkanPipelineStateViewer::setEmptyRow(RDTreeWidgetItem *node) template void VulkanPipelineStateViewer::setViewDetails(RDTreeWidgetItem *node, const bindType &view, - TextureDescription *tex) + TextureDescription *tex, bool includeSampleLocations) { if(tex == NULL) return; @@ -437,8 +437,10 @@ void VulkanPipelineStateViewer::setViewDetails(RDTreeWidgetItem *node, const bin bool viewdetails = false; + const VKPipe::State &state = *m_Ctx.CurVulkanPipelineState(); + { - for(const VKPipe::ImageData &im : m_Ctx.CurVulkanPipelineState()->images) + for(const VKPipe::ImageData &im : state.images) { if(im.resourceId == tex->resourceId) { @@ -486,6 +488,26 @@ void VulkanPipelineStateViewer::setViewDetails(RDTreeWidgetItem *node, const bin } } + if(includeSampleLocations && state.multisample.rasterSamples > 1 && + !state.multisample.sampleLocations.customLocations.isEmpty()) + { + text += tr("Rendering with custom sample locations over %1x%2 grid:\n") + .arg(state.multisample.sampleLocations.gridWidth) + .arg(state.multisample.sampleLocations.gridHeight); + + const rdcarray &locations = state.multisample.sampleLocations.customLocations; + + for(int i = 0; i < locations.count(); i++) + { + text += QFormatStr(" [%1]: %2, %3\n") + .arg(i) + .arg(Formatter::Format(locations[i].x)) + .arg(Formatter::Format(locations[i].y)); + } + + viewdetails = true; + } + text = text.trimmed(); node->setToolTip(text); @@ -2186,7 +2208,7 @@ void VulkanPipelineStateViewer::setState() targets[i] = true; } - setViewDetails(node, p, tex); + setViewDetails(node, p, tex, resIdx < 0); ui->fbAttach->addTopLevelItem(node); } diff --git a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.h b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.h index 2af070f05..6ac7f6b4d 100644 --- a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.h +++ b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.h @@ -108,7 +108,8 @@ private: const VKPipe::Shader *stageForSender(QWidget *widget); template - void setViewDetails(RDTreeWidgetItem *node, const viewType &view, TextureDescription *tex); + void setViewDetails(RDTreeWidgetItem *node, const viewType &view, TextureDescription *tex, + bool includeSampleLocations = false); template void setViewDetails(RDTreeWidgetItem *node, const viewType &view, BufferDescription *buf); diff --git a/renderdoc/api/replay/data_types.h b/renderdoc/api/replay/data_types.h index 3749d57f9..32924e81e 100644 --- a/renderdoc/api/replay/data_types.h +++ b/renderdoc/api/replay/data_types.h @@ -30,6 +30,7 @@ DOCUMENT("A floating point four-component vector"); struct FloatVector { + DOCUMENT(""); FloatVector() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {} FloatVector(const FloatVector &) = default; FloatVector(float X, float Y, float Z, float W) : x(X), y(Y), z(Z), w(W) {} @@ -38,6 +39,22 @@ struct FloatVector { } #endif + bool operator==(const FloatVector &o) const + { + return x == o.x && y == o.y && z == o.z && w == o.w; + } + bool operator<(const FloatVector &o) const + { + if(!(x == o.x)) + return x < o.x; + if(!(y == o.y)) + return y < o.y; + if(!(z == o.z)) + return z < o.z; + if(!(w == o.w)) + return w < o.w; + return false; + } DOCUMENT("The x component."); float x; DOCUMENT("The y component."); diff --git a/renderdoc/api/replay/vk_pipestate.h b/renderdoc/api/replay/vk_pipestate.h index 3fce78331..d36d73dbe 100644 --- a/renderdoc/api/replay/vk_pipestate.h +++ b/renderdoc/api/replay/vk_pipestate.h @@ -636,6 +636,25 @@ See :data:`conservativeRasterizationMode` float lineWidth = 0.0f; }; +DOCUMENT("Describes state of custom sample locations in the pipeline."); +struct SampleLocations +{ + DOCUMENT(""); + SampleLocations() = default; + SampleLocations(const SampleLocations &) = default; + + DOCUMENT("The width in pixels of the region configured."); + uint32_t gridWidth = 1; + DOCUMENT("The height in pixels of the region configured."); + uint32_t gridHeight = 1; + DOCUMENT(R"(A list of :class:`FloatVector` giving the custom sample locations. Only x and y are +valid, z and w are set to 0.0. + +If the list is empty then the standard sample pattern is in use. +)"); + rdcarray customLocations; +}; + DOCUMENT("Describes the multisampling state in the pipeline."); struct MultiSample { @@ -651,6 +670,8 @@ struct MultiSample float minSampleShading = 0.0f; DOCUMENT("A mask that generated samples should be masked with using bitwise ``AND``."); uint32_t sampleMask = 0; + DOCUMENT("The :class:`VKSampleLocations` with any custom sample locations that are configured."); + SampleLocations sampleLocations; }; DOCUMENT("Describes the pipeline blending state."); @@ -1013,6 +1034,7 @@ DECLARE_REFLECTION_STRUCT(VKPipe::TransformFeedback); DECLARE_REFLECTION_STRUCT(VKPipe::ViewportScissor); DECLARE_REFLECTION_STRUCT(VKPipe::ViewState); DECLARE_REFLECTION_STRUCT(VKPipe::Rasterizer); +DECLARE_REFLECTION_STRUCT(VKPipe::SampleLocations); DECLARE_REFLECTION_STRUCT(VKPipe::MultiSample); DECLARE_REFLECTION_STRUCT(VKPipe::ColorBlendState); DECLARE_REFLECTION_STRUCT(VKPipe::DepthStencil); diff --git a/renderdoc/driver/vulkan/vk_common.h b/renderdoc/driver/vulkan/vk_common.h index 2d7ae7366..c283478fc 100644 --- a/renderdoc/driver/vulkan/vk_common.h +++ b/renderdoc/driver/vulkan/vk_common.h @@ -519,6 +519,7 @@ enum class VulkanChunk : uint32_t vkCmdDrawIndirectByteCountEXT, vkCmdBeginConditionalRenderingEXT, vkCmdEndConditionalRenderingEXT, + vkCmdSetSampleLocationsEXT, Max, }; @@ -570,6 +571,7 @@ DECLARE_REFLECTION_STRUCT(VkAcquireNextImageInfoKHR); DECLARE_REFLECTION_STRUCT(VkApplicationInfo); DECLARE_REFLECTION_STRUCT(VkAttachmentDescription2KHR); DECLARE_REFLECTION_STRUCT(VkAttachmentReference2KHR); +DECLARE_REFLECTION_STRUCT(VkAttachmentSampleLocationsEXT); DECLARE_REFLECTION_STRUCT(VkBindBufferMemoryDeviceGroupInfo); DECLARE_REFLECTION_STRUCT(VkBindBufferMemoryInfo); DECLARE_REFLECTION_STRUCT(VkBindImageMemoryDeviceGroupInfo); @@ -671,6 +673,7 @@ DECLARE_REFLECTION_STRUCT(VkMemoryFdPropertiesKHR); DECLARE_REFLECTION_STRUCT(VkMemoryGetFdInfoKHR); DECLARE_REFLECTION_STRUCT(VkMemoryPriorityAllocateInfoEXT); DECLARE_REFLECTION_STRUCT(VkMemoryRequirements2); +DECLARE_REFLECTION_STRUCT(VkMultisamplePropertiesEXT); DECLARE_REFLECTION_STRUCT(VkPhysicalDevice16BitStorageFeatures); DECLARE_REFLECTION_STRUCT(VkPhysicalDevice8BitStorageFeaturesKHR); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceASTCDecodeFeaturesEXT); @@ -706,6 +709,7 @@ DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceShaderDrawParameterFeatures); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceShaderImageFootprintFeaturesNV); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceFloat16Int8FeaturesKHR); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceFloatControlsPropertiesKHR); +DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceSampleLocationsPropertiesEXT); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceSparseImageFormatInfo2); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceSubgroupProperties); DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceSurfaceInfo2KHR); @@ -725,6 +729,7 @@ DECLARE_REFLECTION_STRUCT(VkPipelineMultisampleStateCreateInfo); DECLARE_REFLECTION_STRUCT(VkPipelineRasterizationConservativeStateCreateInfoEXT); DECLARE_REFLECTION_STRUCT(VkPipelineRasterizationStateCreateInfo); DECLARE_REFLECTION_STRUCT(VkPipelineRasterizationStateStreamCreateInfoEXT); +DECLARE_REFLECTION_STRUCT(VkPipelineSampleLocationsStateCreateInfoEXT); DECLARE_REFLECTION_STRUCT(VkPipelineShaderStageCreateInfo); DECLARE_REFLECTION_STRUCT(VkPipelineTessellationDomainOriginStateCreateInfo); DECLARE_REFLECTION_STRUCT(VkPipelineTessellationStateCreateInfo); @@ -741,6 +746,8 @@ DECLARE_REFLECTION_STRUCT(VkRenderPassCreateInfo); DECLARE_REFLECTION_STRUCT(VkRenderPassCreateInfo2KHR); DECLARE_REFLECTION_STRUCT(VkRenderPassInputAttachmentAspectCreateInfo); DECLARE_REFLECTION_STRUCT(VkRenderPassMultiviewCreateInfo); +DECLARE_REFLECTION_STRUCT(VkRenderPassSampleLocationsBeginInfoEXT); +DECLARE_REFLECTION_STRUCT(VkSampleLocationsInfoEXT); DECLARE_REFLECTION_STRUCT(VkSamplerCreateInfo); DECLARE_REFLECTION_STRUCT(VkSamplerReductionModeCreateInfoEXT); DECLARE_REFLECTION_STRUCT(VkSamplerYcbcrConversionCreateInfo); @@ -759,6 +766,7 @@ DECLARE_REFLECTION_STRUCT(VkSubpassDependency2KHR); DECLARE_REFLECTION_STRUCT(VkSubpassDescription2KHR); DECLARE_REFLECTION_STRUCT(VkSubpassDescriptionDepthStencilResolveKHR); DECLARE_REFLECTION_STRUCT(VkSubpassEndInfoKHR); +DECLARE_REFLECTION_STRUCT(VkSubpassSampleLocationsEXT); DECLARE_REFLECTION_STRUCT(VkSurfaceCapabilities2EXT); DECLARE_REFLECTION_STRUCT(VkSurfaceCapabilities2KHR); DECLARE_REFLECTION_STRUCT(VkSurfaceFormat2KHR); @@ -773,6 +781,7 @@ DECLARE_DESERIALISE_TYPE(VkAcquireNextImageInfoKHR); DECLARE_DESERIALISE_TYPE(VkApplicationInfo); DECLARE_DESERIALISE_TYPE(VkAttachmentDescription2KHR); DECLARE_DESERIALISE_TYPE(VkAttachmentReference2KHR); +DECLARE_DESERIALISE_TYPE(VkAttachmentSampleLocationsEXT); DECLARE_DESERIALISE_TYPE(VkBindBufferMemoryDeviceGroupInfo); DECLARE_DESERIALISE_TYPE(VkBindBufferMemoryInfo); DECLARE_DESERIALISE_TYPE(VkBindImageMemoryDeviceGroupInfo); @@ -874,6 +883,7 @@ DECLARE_DESERIALISE_TYPE(VkMemoryFdPropertiesKHR); DECLARE_DESERIALISE_TYPE(VkMemoryGetFdInfoKHR); DECLARE_DESERIALISE_TYPE(VkMemoryPriorityAllocateInfoEXT); DECLARE_DESERIALISE_TYPE(VkMemoryRequirements2); +DECLARE_DESERIALISE_TYPE(VkMultisamplePropertiesEXT); DECLARE_DESERIALISE_TYPE(VkPhysicalDevice16BitStorageFeatures); DECLARE_DESERIALISE_TYPE(VkPhysicalDevice8BitStorageFeaturesKHR); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceASTCDecodeFeaturesEXT); @@ -909,6 +919,7 @@ DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceShaderDrawParameterFeatures); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceShaderImageFootprintFeaturesNV); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceFloat16Int8FeaturesKHR); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceFloatControlsPropertiesKHR); +DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceSampleLocationsPropertiesEXT); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceSparseImageFormatInfo2); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceSubgroupProperties); DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceSurfaceInfo2KHR); @@ -928,6 +939,7 @@ DECLARE_DESERIALISE_TYPE(VkPipelineMultisampleStateCreateInfo); DECLARE_DESERIALISE_TYPE(VkPipelineRasterizationConservativeStateCreateInfoEXT); DECLARE_DESERIALISE_TYPE(VkPipelineRasterizationStateCreateInfo); DECLARE_DESERIALISE_TYPE(VkPipelineRasterizationStateStreamCreateInfoEXT); +DECLARE_DESERIALISE_TYPE(VkPipelineSampleLocationsStateCreateInfoEXT); DECLARE_DESERIALISE_TYPE(VkPipelineShaderStageCreateInfo); DECLARE_DESERIALISE_TYPE(VkPipelineTessellationDomainOriginStateCreateInfo); DECLARE_DESERIALISE_TYPE(VkPipelineTessellationStateCreateInfo); @@ -944,6 +956,8 @@ DECLARE_DESERIALISE_TYPE(VkRenderPassCreateInfo); DECLARE_DESERIALISE_TYPE(VkRenderPassCreateInfo2KHR); DECLARE_DESERIALISE_TYPE(VkRenderPassInputAttachmentAspectCreateInfo); DECLARE_DESERIALISE_TYPE(VkRenderPassMultiviewCreateInfo); +DECLARE_DESERIALISE_TYPE(VkRenderPassSampleLocationsBeginInfoEXT); +DECLARE_DESERIALISE_TYPE(VkSampleLocationsInfoEXT); DECLARE_DESERIALISE_TYPE(VkSamplerCreateInfo); DECLARE_DESERIALISE_TYPE(VkSamplerReductionModeCreateInfoEXT); DECLARE_DESERIALISE_TYPE(VkSamplerYcbcrConversionCreateInfo); @@ -962,6 +976,7 @@ DECLARE_DESERIALISE_TYPE(VkSubpassDependency2KHR); DECLARE_DESERIALISE_TYPE(VkSubpassDescription2KHR); DECLARE_DESERIALISE_TYPE(VkSubpassDescriptionDepthStencilResolveKHR); DECLARE_DESERIALISE_TYPE(VkSubpassEndInfoKHR); +DECLARE_DESERIALISE_TYPE(VkSubpassSampleLocationsEXT); DECLARE_DESERIALISE_TYPE(VkSurfaceCapabilities2EXT); DECLARE_DESERIALISE_TYPE(VkSurfaceCapabilities2KHR); DECLARE_DESERIALISE_TYPE(VkSurfaceFormat2KHR); @@ -1026,6 +1041,7 @@ DECLARE_REFLECTION_STRUCT(VkPushConstantRange); DECLARE_REFLECTION_STRUCT(VkQueueFamilyProperties); DECLARE_REFLECTION_STRUCT(VkRect2D); DECLARE_REFLECTION_STRUCT(VkRectLayerKHR); +DECLARE_REFLECTION_STRUCT(VkSampleLocationEXT); DECLARE_REFLECTION_STRUCT(VkSparseBufferMemoryBindInfo); DECLARE_REFLECTION_STRUCT(VkSparseImageFormatProperties); DECLARE_REFLECTION_STRUCT(VkSparseImageMemoryBind); diff --git a/renderdoc/driver/vulkan/vk_core.cpp b/renderdoc/driver/vulkan/vk_core.cpp index d3e3aa621..28e2faccf 100644 --- a/renderdoc/driver/vulkan/vk_core.cpp +++ b/renderdoc/driver/vulkan/vk_core.cpp @@ -687,6 +687,9 @@ static const VkExtensionProperties supportedExtensions[] = { { VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME, VK_EXT_QUEUE_FAMILY_FOREIGN_SPEC_VERSION, }, + { + VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME, VK_EXT_SAMPLE_LOCATIONS_SPEC_VERSION, + }, { VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME, VK_EXT_SAMPLER_FILTER_MINMAX_SPEC_VERSION, }, @@ -2767,6 +2770,8 @@ bool WrappedVulkan::ProcessChunk(ReadSerialiser &ser, VulkanChunk chunk) return Serialise_vkCmdBeginConditionalRenderingEXT(ser, VK_NULL_HANDLE, NULL); case VulkanChunk::vkCmdEndConditionalRenderingEXT: return Serialise_vkCmdEndConditionalRenderingEXT(ser, VK_NULL_HANDLE); + case VulkanChunk::vkCmdSetSampleLocationsEXT: + return Serialise_vkCmdSetSampleLocationsEXT(ser, VK_NULL_HANDLE, NULL); default: { SystemChunk system = (SystemChunk)chunk; diff --git a/renderdoc/driver/vulkan/vk_core.h b/renderdoc/driver/vulkan/vk_core.h index d077d0713..84a1a8a46 100644 --- a/renderdoc/driver/vulkan/vk_core.h +++ b/renderdoc/driver/vulkan/vk_core.h @@ -1999,4 +1999,12 @@ public: VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin); IMPLEMENT_FUNCTION_SERIALISED(void, vkCmdEndConditionalRenderingEXT, VkCommandBuffer commandBuffer); + + // VK_EXT_sample_locations + + IMPLEMENT_FUNCTION_SERIALISED(void, vkCmdSetSampleLocationsEXT, VkCommandBuffer commandBuffer, + const VkSampleLocationsInfoEXT *pSampleLocationsInfo); + void vkGetPhysicalDeviceMultisamplePropertiesEXT(VkPhysicalDevice physicalDevice, + VkSampleCountFlagBits samples, + VkMultisamplePropertiesEXT *pMultisampleProperties); }; diff --git a/renderdoc/driver/vulkan/vk_dispatchtables.cpp b/renderdoc/driver/vulkan/vk_dispatchtables.cpp index 15e92e59a..dda4f82aa 100644 --- a/renderdoc/driver/vulkan/vk_dispatchtables.cpp +++ b/renderdoc/driver/vulkan/vk_dispatchtables.cpp @@ -74,11 +74,14 @@ void InitInstanceExtensionTables(VkInstance instance, InstanceDeviceInfo *info) instance = Unwrap(instance); -#undef CheckExt -#define CheckExt(name, ver) \ - bool name = info->ext_##name; \ +#undef DeclExt +#define DeclExt(name) \ + bool name = false; \ (void)name; +#undef CheckExt +#define CheckExt(name, ver) name = info->ext_##name; + #undef HookInitExtension #define HookInitExtension(cond, func) \ if(cond) \ @@ -98,6 +101,8 @@ void InitInstanceExtensionTables(VkInstance instance, InstanceDeviceInfo *info) table->CONCAT(func, suffix) = table->func; \ } + DeclExts(); + CheckInstanceExts(); InstanceGPA(EnumerateDeviceExtensionProperties); @@ -137,6 +142,8 @@ void InitDeviceExtensionTables(VkDevice device, InstanceDeviceInfo *info) table->CONCAT(func, suffix) = table->func; \ } + DeclExts(); + CheckInstanceExts(); CheckDeviceExts(); diff --git a/renderdoc/driver/vulkan/vk_dispatchtables.h b/renderdoc/driver/vulkan/vk_dispatchtables.h index 5eb60e6cc..9a844b30d 100644 --- a/renderdoc/driver/vulkan/vk_dispatchtables.h +++ b/renderdoc/driver/vulkan/vk_dispatchtables.h @@ -38,23 +38,14 @@ void InitReplayTables(void *vulkanModule); struct InstanceDeviceInfo { -#undef CheckExt -#define CheckExt(name, ver) ext_##name = false; - InstanceDeviceInfo() - { - CheckDeviceExts(); - CheckInstanceExts(); - } - -#undef CheckExt -#define CheckExt(name, ver) bool ext_##name; +#undef DeclExt +#define DeclExt(name) bool ext_##name = false; bool brokenGetDeviceProcAddr = false; int vulkanVersion = VK_API_VERSION_1_0; - CheckDeviceExts(); - CheckInstanceExts(); + DeclExts(); }; void InitInstanceExtensionTables(VkInstance instance, InstanceDeviceInfo *info); diff --git a/renderdoc/driver/vulkan/vk_hookset_defs.h b/renderdoc/driver/vulkan/vk_hookset_defs.h index 66178dfd4..2714c01cd 100644 --- a/renderdoc/driver/vulkan/vk_hookset_defs.h +++ b/renderdoc/driver/vulkan/vk_hookset_defs.h @@ -291,6 +291,71 @@ // They're not really used or relevant on win32/android but for platform simplicity // we just include it always, it does no harm to include. +// this is the union of the lists below - necessary because some extensions are in both lists +// (device extensions with physical device functions) +#define DeclExts() \ + DeclExt(KHR_xlib_surface); \ + DeclExt(KHR_xcb_surface); \ + DeclExt(KHR_win32_surface); \ + DeclExt(KHR_android_surface); \ + DeclExt(MVK_macos_surface); \ + DeclExt(KHR_surface); \ + DeclExt(EXT_debug_report); \ + DeclExt(KHR_display); \ + DeclExt(NV_external_memory_capabilities); \ + DeclExt(KHR_get_physical_device_properties2); \ + DeclExt(EXT_display_surface_counter); \ + DeclExt(EXT_direct_mode_display); \ + DeclExt(EXT_acquire_xlib_display); \ + DeclExt(KHR_external_memory_capabilities); \ + DeclExt(KHR_external_semaphore_capabilities); \ + DeclExt(KHR_external_fence_capabilities); \ + DeclExt(EXT_debug_utils); \ + DeclExt(KHR_device_group_creation); \ + DeclExt(protected_memory); \ + DeclExt(KHR_get_surface_capabilities2); \ + DeclExt(KHR_get_display_properties2); \ + /* device extensions */ \ + DeclExt(EXT_debug_marker); \ + DeclExt(KHR_swapchain); \ + DeclExt(KHR_display_swapchain); \ + DeclExt(NV_external_memory); \ + DeclExt(NV_external_memory_win32); \ + DeclExt(NV_win32_keyed_mutex); \ + DeclExt(KHR_maintenance1); \ + DeclExt(KHR_maintenance2); \ + DeclExt(KHR_maintenance3); \ + DeclExt(EXT_display_control); \ + DeclExt(KHR_external_memory); \ + DeclExt(KHR_external_memory_win32); \ + DeclExt(KHR_external_memory_fd); \ + DeclExt(KHR_external_semaphore); \ + DeclExt(KHR_external_semaphore_win32); \ + DeclExt(KHR_external_semaphore_fd); \ + DeclExt(KHR_external_fence); \ + DeclExt(KHR_external_fence_win32); \ + DeclExt(KHR_external_fence_fd); \ + DeclExt(KHR_get_memory_requirements2); \ + DeclExt(AMD_shader_info); \ + DeclExt(KHR_push_descriptor); \ + DeclExt(KHR_descriptor_update_template); \ + DeclExt(KHR_bind_memory2); \ + DeclExt(EXT_conservative_rasterization); \ + DeclExt(EXT_global_priority); \ + DeclExt(AMD_buffer_marker); \ + DeclExt(EXT_vertex_attribute_divisor); \ + DeclExt(EXT_sampler_filter_minmax); \ + DeclExt(KHR_sampler_ycbcr_conversion); \ + DeclExt(KHR_device_group); \ + DeclExt(MVK_moltenvk); \ + DeclExt(KHR_draw_indirect_count); \ + DeclExt(EXT_validation_cache); \ + DeclExt(KHR_shared_presentable_image); \ + DeclExt(KHR_create_renderpass2); \ + DeclExt(EXT_transform_feedback); \ + DeclExt(EXT_conditional_rendering); \ + DeclExt(EXT_sample_locations); + // for simplicity and since the check itself is platform agnostic, // these aren't protected in platform defines #define CheckInstanceExts() \ @@ -314,7 +379,8 @@ CheckExt(KHR_device_group_creation, VK11); \ CheckExt(protected_memory, VK11); \ CheckExt(KHR_get_surface_capabilities2, VKXX); \ - CheckExt(KHR_get_display_properties2, VKXX); + CheckExt(KHR_get_display_properties2, VKXX); \ + CheckExt(EXT_sample_locations, VKXX); #define CheckDeviceExts() \ CheckExt(EXT_debug_marker, VKXX); \ @@ -354,7 +420,8 @@ CheckExt(KHR_shared_presentable_image, VKXX); \ CheckExt(KHR_create_renderpass2, VKXX); \ CheckExt(EXT_transform_feedback, VKXX); \ - CheckExt(EXT_conditional_rendering, VKXX); + CheckExt(EXT_conditional_rendering, VKXX); \ + CheckExt(EXT_sample_locations, VKXX); #define HookInitVulkanInstanceExts() \ HookInitExtension(KHR_surface, DestroySurfaceKHR); \ @@ -408,6 +475,7 @@ HookInitExtension(KHR_get_display_properties2, GetPhysicalDeviceDisplayPlaneProperties2KHR); \ HookInitExtension(KHR_get_display_properties2, GetDisplayModeProperties2KHR); \ HookInitExtension(KHR_get_display_properties2, GetDisplayPlaneCapabilities2KHR); \ + HookInitExtension(EXT_sample_locations, GetPhysicalDeviceMultisamplePropertiesEXT); \ HookInitInstance_PlatformSpecific() #define HookInitVulkanDeviceExts() \ @@ -483,6 +551,7 @@ HookInitExtension(EXT_transform_feedback, CmdDrawIndirectByteCountEXT); \ HookInitExtension(EXT_conditional_rendering, CmdBeginConditionalRenderingEXT); \ HookInitExtension(EXT_conditional_rendering, CmdEndConditionalRenderingEXT); \ + HookInitExtension(EXT_sample_locations, CmdSetSampleLocationsEXT); \ HookInitDevice_PlatformSpecific() #define DefineHooks() \ @@ -1039,6 +1108,10 @@ HookDefine2(void, vkCmdBeginConditionalRenderingEXT, VkCommandBuffer, commandBuffer, \ const VkConditionalRenderingBeginInfoEXT *, pConditionalRenderingBegin); \ HookDefine1(void, vkCmdEndConditionalRenderingEXT, VkCommandBuffer, commandBuffer); \ + HookDefine2(void, vkCmdSetSampleLocationsEXT, VkCommandBuffer, commandBuffer, \ + const VkSampleLocationsInfoEXT *, pSampleLocationsInfo); \ + HookDefine3(void, vkGetPhysicalDeviceMultisamplePropertiesEXT, VkPhysicalDevice, physicalDevice, \ + VkSampleCountFlagBits, samples, VkMultisamplePropertiesEXT *, pMultisampleProperties); \ HookDefine_PlatformSpecific() struct VkLayerInstanceDispatchTableExtended : VkLayerInstanceDispatchTable diff --git a/renderdoc/driver/vulkan/vk_info.cpp b/renderdoc/driver/vulkan/vk_info.cpp index 8b5cda30a..1794d0b52 100644 --- a/renderdoc/driver/vulkan/vk_info.cpp +++ b/renderdoc/driver/vulkan/vk_info.cpp @@ -25,6 +25,65 @@ #include "vk_info.h" #include "3rdparty/glslang/SPIRV/spirv.hpp" +VkDynamicState ConvertDynamicState(VulkanDynamicStateIndex idx) +{ + switch(idx) + { + case VkDynamicViewport: return VK_DYNAMIC_STATE_VIEWPORT; + case VkDynamicScissor: return VK_DYNAMIC_STATE_SCISSOR; + case VkDynamicLineWidth: return VK_DYNAMIC_STATE_LINE_WIDTH; + case VkDynamicDepthBias: return VK_DYNAMIC_STATE_DEPTH_BIAS; + case VkDynamicBlendConstants: return VK_DYNAMIC_STATE_BLEND_CONSTANTS; + case VkDynamicDepthBounds: return VK_DYNAMIC_STATE_DEPTH_BOUNDS; + case VkDynamicStencilCompareMask: return VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK; + case VkDynamicStencilWriteMask: return VK_DYNAMIC_STATE_STENCIL_WRITE_MASK; + case VkDynamicStencilReference: return VK_DYNAMIC_STATE_STENCIL_REFERENCE; + case VkDynamicViewportWScalingNV: return VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV; + case VkDynamicDiscardRectangleEXT: return VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT; + case VkDynamicSampleLocationsEXT: return VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT; + case VkDynamicViewportShadingRatePaletteNV: + return VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV; + case VkDynamicViewportCoarseSampleOrderNV: + return VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV; + case VkDynamicExclusiveScissorNV: return VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV; + case VkDynamicCount: break; + } + + RDCERR("Unexpected vulkan dynamic state index %u", idx); + + return VK_DYNAMIC_STATE_MAX_ENUM; +} + +VulkanDynamicStateIndex ConvertDynamicState(VkDynamicState state) +{ + switch(state) + { + case VK_DYNAMIC_STATE_VIEWPORT: return VkDynamicViewport; + case VK_DYNAMIC_STATE_SCISSOR: return VkDynamicScissor; + case VK_DYNAMIC_STATE_LINE_WIDTH: return VkDynamicLineWidth; + case VK_DYNAMIC_STATE_DEPTH_BIAS: return VkDynamicDepthBias; + case VK_DYNAMIC_STATE_BLEND_CONSTANTS: return VkDynamicBlendConstants; + case VK_DYNAMIC_STATE_DEPTH_BOUNDS: return VkDynamicDepthBounds; + case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK: return VkDynamicStencilCompareMask; + case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK: return VkDynamicStencilWriteMask; + case VK_DYNAMIC_STATE_STENCIL_REFERENCE: return VkDynamicStencilReference; + case VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV: return VkDynamicViewportWScalingNV; + case VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT: return VkDynamicDiscardRectangleEXT; + case VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT: return VkDynamicSampleLocationsEXT; + case VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV: + return VkDynamicViewportShadingRatePaletteNV; + case VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV: + return VkDynamicViewportCoarseSampleOrderNV; + case VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV: return VkDynamicExclusiveScissorNV; + case VK_DYNAMIC_STATE_RANGE_SIZE: + case VK_DYNAMIC_STATE_MAX_ENUM: break; + } + + RDCERR("Unexpected vulkan state %u", state); + + return VkDynamicCount; +} + void DescSetLayout::Init(VulkanResourceManager *resourceMan, VulkanCreationInfo &info, const VkDescriptorSetLayoutCreateInfo *pCreateInfo) { @@ -152,7 +211,12 @@ void VulkanCreationInfo::Pipeline::Init(VulkanResourceManager *resourceMan, Vulk renderpass = GetResID(pCreateInfo->renderPass); subpass = pCreateInfo->subpass; - // need to figure out which states are valid to be NULL + RDCEraseEl(dynamicStates); + if(pCreateInfo->pDynamicState) + { + for(uint32_t i = 0; i < pCreateInfo->pDynamicState->dynamicStateCount; i++) + dynamicStates[ConvertDynamicState(pCreateInfo->pDynamicState->pDynamicStates[i])] = true; + } // VkPipelineShaderStageCreateInfo for(uint32_t i = 0; i < pCreateInfo->stageCount; i++) @@ -317,6 +381,31 @@ void VulkanCreationInfo::Pipeline::Init(VulkanResourceManager *resourceMan, Vulk : ~0U; alphaToCoverageEnable = pCreateInfo->pMultisampleState->alphaToCoverageEnable ? true : false; alphaToOneEnable = pCreateInfo->pMultisampleState->alphaToOneEnable ? true : false; + + // VkPipelineSampleLocationsStateCreateInfoEXT + sampleLocations.enabled = false; + sampleLocations.gridSize.width = 1; + sampleLocations.gridSize.height = 1; + + const VkPipelineSampleLocationsStateCreateInfoEXT *sampleLoc = + (const VkPipelineSampleLocationsStateCreateInfoEXT *)FindNextStruct( + pCreateInfo->pMultisampleState, + VK_STRUCTURE_TYPE_PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT); + if(sampleLoc) + { + sampleLocations.enabled = sampleLoc->sampleLocationsEnable ? true : false; + + if(!dynamicStates[VkDynamicSampleLocationsEXT]) + { + sampleLocations.gridSize = sampleLoc->sampleLocationsInfo.sampleLocationGridSize; + sampleLocations.locations.insert(sampleLocations.locations.begin(), + sampleLoc->sampleLocationsInfo.pSampleLocations, + sampleLoc->sampleLocationsInfo.pSampleLocations + + sampleLoc->sampleLocationsInfo.sampleLocationsCount); + + RDCASSERTEQUAL(sampleLoc->sampleLocationsInfo.sampleLocationsPerPixel, rasterizationSamples); + } + } } else { @@ -399,13 +488,6 @@ void VulkanCreationInfo::Pipeline::Init(VulkanResourceManager *resourceMan, Vulk attachments.clear(); } - - RDCEraseEl(dynamicStates); - if(pCreateInfo->pDynamicState) - { - for(uint32_t i = 0; i < pCreateInfo->pDynamicState->dynamicStateCount; i++) - dynamicStates[pCreateInfo->pDynamicState->pDynamicStates[i]] = true; - } } void VulkanCreationInfo::Pipeline::Init(VulkanResourceManager *resourceMan, VulkanCreationInfo &info, diff --git a/renderdoc/driver/vulkan/vk_info.h b/renderdoc/driver/vulkan/vk_info.h index 48fb4b46b..40b2e6891 100644 --- a/renderdoc/driver/vulkan/vk_info.h +++ b/renderdoc/driver/vulkan/vk_info.h @@ -30,6 +30,30 @@ struct VulkanCreationInfo; +// linearised version of VkDynamicState +enum VulkanDynamicStateIndex +{ + VkDynamicViewport, + VkDynamicScissor, + VkDynamicLineWidth, + VkDynamicDepthBias, + VkDynamicBlendConstants, + VkDynamicDepthBounds, + VkDynamicStencilCompareMask, + VkDynamicStencilWriteMask, + VkDynamicStencilReference, + VkDynamicViewportWScalingNV, + VkDynamicDiscardRectangleEXT, + VkDynamicSampleLocationsEXT, + VkDynamicViewportShadingRatePaletteNV, + VkDynamicViewportCoarseSampleOrderNV, + VkDynamicExclusiveScissorNV, + VkDynamicCount, +}; + +VkDynamicState ConvertDynamicState(VulkanDynamicStateIndex idx); +VulkanDynamicStateIndex ConvertDynamicState(VkDynamicState state); + struct DescSetLayout { void Init(VulkanResourceManager *resourceMan, VulkanCreationInfo &info, @@ -205,6 +229,14 @@ struct VulkanCreationInfo bool alphaToCoverageEnable; bool alphaToOneEnable; + // VkPipelineSampleLocationsStateCreateInfoEXT + struct + { + bool enabled; + VkExtent2D gridSize; + std::vector locations; + } sampleLocations; + // VkPipelineDepthStencilStateCreateInfo bool depthTestEnable; bool depthWriteEnable; @@ -237,7 +269,7 @@ struct VulkanCreationInfo vector attachments; // VkPipelineDynamicStateCreateInfo - bool dynamicStates[VK_DYNAMIC_STATE_RANGE_SIZE]; + bool dynamicStates[VkDynamicCount]; }; map m_Pipeline; diff --git a/renderdoc/driver/vulkan/vk_layer.cpp b/renderdoc/driver/vulkan/vk_layer.cpp index d00241d4c..b1a017194 100644 --- a/renderdoc/driver/vulkan/vk_layer.cpp +++ b/renderdoc/driver/vulkan/vk_layer.cpp @@ -257,11 +257,14 @@ VK_LAYER_RENDERDOC_CaptureEnumerateInstanceExtensionProperties( pProperties); } -#undef CheckExt -#define CheckExt(name, ver) \ - bool name = instDevInfo == NULL || instDevInfo->ext_##name; \ +#undef DeclExt +#define DeclExt(name) \ + bool name = false; \ (void)name; +#undef CheckExt +#define CheckExt(name, ver) name = instDevInfo == NULL || instDevInfo->ext_##name; + #undef HookInit #define HookInit(function) \ if(!strcmp(pName, STRINGIZE(CONCAT(vk, function)))) \ @@ -304,6 +307,8 @@ VK_LAYER_RENDERDOC_CaptureGetDeviceProcAddr(VkDevice device, const char *pName) InstanceDeviceInfo *instDevInfo = GetRecord(device)->instDevInfo; + DeclExts(); + CheckInstanceExts(); CheckDeviceExts(); @@ -373,6 +378,8 @@ VK_LAYER_RENDERDOC_CaptureGetInstanceProcAddr(VkInstance instance, const char *p "Working around by assuming all extensions are enabled - WILL CAUSE SPEC-BROKEN BEHAVIOUR", pName); + DeclExts(); + CheckInstanceExts(); CheckDeviceExts(); diff --git a/renderdoc/driver/vulkan/vk_next_chains.cpp b/renderdoc/driver/vulkan/vk_next_chains.cpp index 89bee56ac..e3bb3e83b 100644 --- a/renderdoc/driver/vulkan/vk_next_chains.cpp +++ b/renderdoc/driver/vulkan/vk_next_chains.cpp @@ -142,6 +142,7 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, COPY_STRUCT(VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS, VkMemoryDedicatedRequirements); \ COPY_STRUCT(VK_STRUCTURE_TYPE_MEMORY_PRIORITY_ALLOCATE_INFO_EXT, VkMemoryPriorityAllocateInfoEXT); \ COPY_STRUCT(VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, VkMemoryRequirements2); \ + COPY_STRUCT(VK_STRUCTURE_TYPE_MULTISAMPLE_PROPERTIES_EXT, VkMultisamplePropertiesEXT); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES, \ VkPhysicalDevice16BitStorageFeatures); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR, \ @@ -201,6 +202,8 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, VkPhysicalDeviceProtectedMemoryProperties); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR, \ VkPhysicalDevicePushDescriptorPropertiesKHR); \ + COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT, \ + VkPhysicalDeviceSampleLocationsPropertiesEXT); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT, \ VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES, \ @@ -248,6 +251,8 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, VkPipelineRasterizationStateCreateInfo); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_STREAM_CREATE_INFO_EXT, \ VkPipelineRasterizationStateStreamCreateInfoEXT); \ + COPY_STRUCT(VK_STRUCTURE_TYPE_PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT, \ + VkPipelineSampleLocationsStateCreateInfoEXT); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, VkPipelineShaderStageCreateInfo); \ COPY_STRUCT(VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO, \ VkPipelineTessellationDomainOriginStateCreateInfo); \ @@ -269,6 +274,9 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, COPY_STRUCT(VK_STRUCTURE_TYPE_RENDER_PASS_INPUT_ATTACHMENT_ASPECT_CREATE_INFO, \ VkRenderPassInputAttachmentAspectCreateInfo); \ COPY_STRUCT(VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO, VkRenderPassMultiviewCreateInfo); \ + COPY_STRUCT(VK_STRUCTURE_TYPE_RENDER_PASS_SAMPLE_LOCATIONS_BEGIN_INFO_EXT, \ + VkRenderPassSampleLocationsBeginInfoEXT); \ + COPY_STRUCT(VK_STRUCTURE_TYPE_SAMPLE_LOCATIONS_INFO_EXT, VkSampleLocationsInfoEXT); \ COPY_STRUCT(VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, VkSamplerCreateInfo); \ COPY_STRUCT(VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT, \ VkSamplerReductionModeCreateInfoEXT); \ @@ -444,7 +452,6 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, case VK_STRUCTURE_TYPE_INDIRECT_COMMANDS_LAYOUT_CREATE_INFO_NVX: \ case VK_STRUCTURE_TYPE_MEMORY_GET_ANDROID_HARDWARE_BUFFER_INFO_ANDROID: \ case VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT: \ - case VK_STRUCTURE_TYPE_MULTISAMPLE_PROPERTIES_EXT: \ case VK_STRUCTURE_TYPE_OBJECT_TABLE_CREATE_INFO_NVX: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT: \ @@ -465,7 +472,6 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PER_VIEW_ATTRIBUTES_PROPERTIES_NVX: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PROPERTIES_NV: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_REPRESENTATIVE_FRAGMENT_TEST_FEATURES_NV: \ - case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADING_RATE_IMAGE_FEATURES_NV: \ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADING_RATE_IMAGE_PROPERTIES_NV: \ @@ -475,7 +481,6 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, case VK_STRUCTURE_TYPE_PIPELINE_DISCARD_RECTANGLE_STATE_CREATE_INFO_EXT: \ case VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_RASTERIZATION_ORDER_AMD: \ case VK_STRUCTURE_TYPE_PIPELINE_REPRESENTATIVE_FRAGMENT_TEST_STATE_CREATE_INFO_NV: \ - case VK_STRUCTURE_TYPE_PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT: \ case VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_COARSE_SAMPLE_ORDER_STATE_CREATE_INFO_NV: \ case VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_EXCLUSIVE_SCISSOR_STATE_CREATE_INFO_NV: \ case VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SHADING_RATE_IMAGE_STATE_CREATE_INFO_NV: \ @@ -485,8 +490,6 @@ static void AppendModifiedChainedStruct(byte *&tempMem, VkStruct *outputStruct, case VK_STRUCTURE_TYPE_QUEUE_FAMILY_CHECKPOINT_PROPERTIES_NV: \ case VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_NV: \ case VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV: \ - case VK_STRUCTURE_TYPE_RENDER_PASS_SAMPLE_LOCATIONS_BEGIN_INFO_EXT: \ - case VK_STRUCTURE_TYPE_SAMPLE_LOCATIONS_INFO_EXT: \ case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_NV: \ case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK_EXT: diff --git a/renderdoc/driver/vulkan/vk_replay.cpp b/renderdoc/driver/vulkan/vk_replay.cpp index 553b51908..ef5c2b830 100644 --- a/renderdoc/driver/vulkan/vk_replay.cpp +++ b/renderdoc/driver/vulkan/vk_replay.cpp @@ -1112,6 +1112,22 @@ void VulkanReplay::SavePipelineState() m_VulkanPipelineState.multisample.minSampleShading = p.minSampleShading; m_VulkanPipelineState.multisample.sampleMask = p.sampleMask; + m_VulkanPipelineState.multisample.sampleLocations.customLocations.clear(); + if(p.sampleLocations.enabled) + { + m_VulkanPipelineState.multisample.sampleLocations.gridWidth = + state.sampleLocations.gridSize.width; + m_VulkanPipelineState.multisample.sampleLocations.gridHeight = + state.sampleLocations.gridSize.height; + m_VulkanPipelineState.multisample.sampleLocations.customLocations.reserve( + state.sampleLocations.locations.size()); + for(const VkSampleLocationEXT &loc : state.sampleLocations.locations) + { + m_VulkanPipelineState.multisample.sampleLocations.customLocations.push_back( + {loc.x, loc.y, 0.0f, 0.0f}); + } + } + // Color Blend m_VulkanPipelineState.colorBlend.alphaToCoverageEnable = p.alphaToCoverageEnable; m_VulkanPipelineState.colorBlend.alphaToOneEnable = p.alphaToOneEnable; diff --git a/renderdoc/driver/vulkan/vk_serialise.cpp b/renderdoc/driver/vulkan/vk_serialise.cpp index 82cd9eb07..04c1cbf6e 100644 --- a/renderdoc/driver/vulkan/vk_serialise.cpp +++ b/renderdoc/driver/vulkan/vk_serialise.cpp @@ -477,6 +477,16 @@ SERIALISE_VK_HANDLES(); PNEXT_STRUCT(VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT, \ VkSamplerReductionModeCreateInfoEXT) \ \ + /* VK_EXT_sample_locations */ \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_SAMPLE_LOCATIONS_INFO_EXT, VkSampleLocationsInfoEXT) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_RENDER_PASS_SAMPLE_LOCATIONS_BEGIN_INFO_EXT, \ + VkRenderPassSampleLocationsBeginInfoEXT) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT, \ + VkPipelineSampleLocationsStateCreateInfoEXT) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT, \ + VkPhysicalDeviceSampleLocationsPropertiesEXT) \ + PNEXT_STRUCT(VK_STRUCTURE_TYPE_MULTISAMPLE_PROPERTIES_EXT, VkMultisamplePropertiesEXT) \ + \ /* VK_EXT_transform_feedback */ \ PNEXT_STRUCT(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT, \ VkPhysicalDeviceTransformFeedbackFeaturesEXT) \ @@ -813,13 +823,6 @@ SERIALISE_VK_HANDLES(); PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_VIEW_IMAGE_FORMAT_INFO_EXT) \ PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_FILTER_CUBIC_IMAGE_VIEW_IMAGE_FORMAT_PROPERTIES_EXT) \ \ - /* VK_EXT_sample_locations */ \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_SAMPLE_LOCATIONS_INFO_EXT) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_RENDER_PASS_SAMPLE_LOCATIONS_BEGIN_INFO_EXT) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT) \ - PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_MULTISAMPLE_PROPERTIES_EXT) \ - \ /* VK_EXT_scalar_block_layout */ \ PNEXT_UNSUPPORTED(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT) \ \ @@ -3749,6 +3752,84 @@ void Deserialise(const VkRenderPassMultiviewCreateInfo &el) delete[] el.pCorrelationMasks; } +template +void DoSerialise(SerialiserType &ser, VkSampleLocationEXT &el) +{ + SERIALISE_MEMBER(x); + SERIALISE_MEMBER(y); +} + +template +void DoSerialise(SerialiserType &ser, VkSampleLocationsInfoEXT &el) +{ + RDCASSERT(ser.IsReading() || el.sType == VK_STRUCTURE_TYPE_SAMPLE_LOCATIONS_INFO_EXT); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(sampleLocationsPerPixel); + SERIALISE_MEMBER(sampleLocationGridSize); + SERIALISE_MEMBER(sampleLocationsCount); + SERIALISE_MEMBER_ARRAY(pSampleLocations, sampleLocationsCount); +} + +template <> +void Deserialise(const VkSampleLocationsInfoEXT &el) +{ + DeserialiseNext(el.pNext); + delete[] el.pSampleLocations; +} + +template +void DoSerialise(SerialiserType &ser, VkSubpassSampleLocationsEXT &el) +{ + SERIALISE_MEMBER(subpassIndex); + SERIALISE_MEMBER(sampleLocationsInfo); +} + +template <> +void Deserialise(const VkSubpassSampleLocationsEXT &el) +{ + Deserialise(el.sampleLocationsInfo); +} + +template +void DoSerialise(SerialiserType &ser, VkAttachmentSampleLocationsEXT &el) +{ + SERIALISE_MEMBER(attachmentIndex); + SERIALISE_MEMBER(sampleLocationsInfo); +} + +template <> +void Deserialise(const VkAttachmentSampleLocationsEXT &el) +{ + Deserialise(el.sampleLocationsInfo); +} + +template +void DoSerialise(SerialiserType &ser, VkRenderPassSampleLocationsBeginInfoEXT &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_RENDER_PASS_SAMPLE_LOCATIONS_BEGIN_INFO_EXT); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(attachmentInitialSampleLocationsCount); + SERIALISE_MEMBER_ARRAY(pAttachmentInitialSampleLocations, attachmentInitialSampleLocationsCount); + SERIALISE_MEMBER(postSubpassSampleLocationsCount); + SERIALISE_MEMBER_ARRAY(pPostSubpassSampleLocations, postSubpassSampleLocationsCount); +} + +template <> +void Deserialise(const VkRenderPassSampleLocationsBeginInfoEXT &el) +{ + DeserialiseNext(el.pNext); + for(uint32_t j = 0; + el.pAttachmentInitialSampleLocations && j < el.attachmentInitialSampleLocationsCount; j++) + Deserialise(el.pAttachmentInitialSampleLocations[j]); + delete[] el.pAttachmentInitialSampleLocations; + for(uint32_t j = 0; el.pPostSubpassSampleLocations && j < el.postSubpassSampleLocationsCount; j++) + Deserialise(el.pPostSubpassSampleLocations[j]); + delete[] el.pPostSubpassSampleLocations; +} + template void DoSerialise(SerialiserType &ser, VkPhysicalDeviceMultiviewFeatures &el) { @@ -4059,6 +4140,41 @@ void Deserialise(const VkValidationFlagsEXT &el) delete[] el.pDisabledValidationChecks; } +template +void DoSerialise(SerialiserType &ser, VkPhysicalDeviceSampleLocationsPropertiesEXT &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(sampleLocationSampleCounts); + SERIALISE_MEMBER(maxSampleLocationGridSize); + SERIALISE_MEMBER(sampleLocationCoordinateRange); + SERIALISE_MEMBER(sampleLocationSubPixelBits); + SERIALISE_MEMBER(variableSampleLocations); +} + +template <> +void Deserialise(const VkPhysicalDeviceSampleLocationsPropertiesEXT &el) +{ + DeserialiseNext(el.pNext); +} + +template +void DoSerialise(SerialiserType &ser, VkMultisamplePropertiesEXT &el) +{ + RDCASSERT(ser.IsReading() || el.sType == VK_STRUCTURE_TYPE_MULTISAMPLE_PROPERTIES_EXT); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(maxSampleLocationGridSize); +} + +template <> +void Deserialise(const VkMultisamplePropertiesEXT &el) +{ + DeserialiseNext(el.pNext); +} + template void DoSerialise(SerialiserType &ser, VkPhysicalDeviceTransformFeedbackFeaturesEXT &el) { @@ -4101,6 +4217,23 @@ void Deserialise(const VkPhysicalDeviceTransformFeedbackPropertiesEXT &el) DeserialiseNext(el.pNext); } +template +void DoSerialise(SerialiserType &ser, VkPipelineSampleLocationsStateCreateInfoEXT &el) +{ + RDCASSERT(ser.IsReading() || + el.sType == VK_STRUCTURE_TYPE_PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT); + SerialiseNext(ser, el.sType, el.pNext); + + SERIALISE_MEMBER(sampleLocationsEnable); + SERIALISE_MEMBER(sampleLocationsInfo); +} + +template <> +void Deserialise(const VkPipelineSampleLocationsStateCreateInfoEXT &el) +{ + DeserialiseNext(el.pNext); +} + template void DoSerialise(SerialiserType &ser, VkPipelineRasterizationStateStreamCreateInfoEXT &el) { @@ -6034,6 +6167,7 @@ INSTANTIATE_SERIALISE_TYPE(VkMemoryFdPropertiesKHR); INSTANTIATE_SERIALISE_TYPE(VkMemoryGetFdInfoKHR); INSTANTIATE_SERIALISE_TYPE(VkMemoryPriorityAllocateInfoEXT); INSTANTIATE_SERIALISE_TYPE(VkMemoryRequirements2); +INSTANTIATE_SERIALISE_TYPE(VkMultisamplePropertiesEXT); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDevice16BitStorageFeatures); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDevice8BitStorageFeaturesKHR); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceASTCDecodeFeaturesEXT); @@ -6065,6 +6199,7 @@ INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceSamplerYcbcrConversionFeatures); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceShaderAtomicInt64FeaturesKHR); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceShaderCorePropertiesAMD); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceShaderDrawParameterFeatures); +INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceSampleLocationsPropertiesEXT); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceSparseImageFormatInfo2); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceSubgroupProperties); INSTANTIATE_SERIALISE_TYPE(VkPhysicalDeviceSurfaceInfo2KHR); @@ -6085,6 +6220,7 @@ INSTANTIATE_SERIALISE_TYPE(VkPipelineMultisampleStateCreateInfo); INSTANTIATE_SERIALISE_TYPE(VkPipelineRasterizationConservativeStateCreateInfoEXT); INSTANTIATE_SERIALISE_TYPE(VkPipelineRasterizationStateCreateInfo); INSTANTIATE_SERIALISE_TYPE(VkPipelineRasterizationStateStreamCreateInfoEXT); +INSTANTIATE_SERIALISE_TYPE(VkPipelineSampleLocationsStateCreateInfoEXT); INSTANTIATE_SERIALISE_TYPE(VkPipelineShaderStageCreateInfo); INSTANTIATE_SERIALISE_TYPE(VkPipelineTessellationDomainOriginStateCreateInfo); INSTANTIATE_SERIALISE_TYPE(VkPipelineTessellationStateCreateInfo); @@ -6101,6 +6237,8 @@ INSTANTIATE_SERIALISE_TYPE(VkRenderPassCreateInfo); INSTANTIATE_SERIALISE_TYPE(VkRenderPassCreateInfo2KHR); INSTANTIATE_SERIALISE_TYPE(VkRenderPassInputAttachmentAspectCreateInfo); INSTANTIATE_SERIALISE_TYPE(VkRenderPassMultiviewCreateInfo); +INSTANTIATE_SERIALISE_TYPE(VkRenderPassSampleLocationsBeginInfoEXT); +INSTANTIATE_SERIALISE_TYPE(VkSampleLocationsInfoEXT); INSTANTIATE_SERIALISE_TYPE(VkSamplerCreateInfo); INSTANTIATE_SERIALISE_TYPE(VkSamplerReductionModeCreateInfoEXT); INSTANTIATE_SERIALISE_TYPE(VkSamplerYcbcrConversionCreateInfo); diff --git a/renderdoc/driver/vulkan/vk_shader_cache.cpp b/renderdoc/driver/vulkan/vk_shader_cache.cpp index c5444290a..657ea64ae 100644 --- a/renderdoc/driver/vulkan/vk_shader_cache.cpp +++ b/renderdoc/driver/vulkan/vk_shader_cache.cpp @@ -498,16 +498,16 @@ void VulkanShaderCache::MakeGraphicsPipelineInfo(VkGraphicsPipelineCreateInfo &p RDCASSERT(ARRAY_COUNT(atts) >= pipeInfo.attachments.size()); - static VkDynamicState dynSt[VK_DYNAMIC_STATE_RANGE_SIZE]; + static VkDynamicState dynSt[VkDynamicCount]; static VkPipelineDynamicStateCreateInfo dyn = {VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO}; dyn.dynamicStateCount = 0; dyn.pDynamicStates = dynSt; - for(uint32_t i = 0; i < VK_DYNAMIC_STATE_RANGE_SIZE; i++) + for(uint32_t i = 0; i < VkDynamicCount; i++) if(pipeInfo.dynamicStates[i]) - dynSt[dyn.dynamicStateCount++] = (VkDynamicState)i; + dynSt[dyn.dynamicStateCount++] = ConvertDynamicState((VulkanDynamicStateIndex)i); // since we don't have to worry about threading, we point everything at the above static structs diff --git a/renderdoc/driver/vulkan/vk_state.cpp b/renderdoc/driver/vulkan/vk_state.cpp index 413b7527b..54449caf5 100644 --- a/renderdoc/driver/vulkan/vk_state.cpp +++ b/renderdoc/driver/vulkan/vk_state.cpp @@ -222,7 +222,7 @@ void VulkanRenderState::BindPipeline(VkCommandBuffer cmd, PipelineBinding bindin const vector &pushRanges = m_CreationInfo->m_PipelineLayout[pipeLayoutId].pushRanges; - bool dynamicStates[VK_DYNAMIC_STATE_RANGE_SIZE] = {0}; + bool dynamicStates[VkDynamicCount] = {0}; memcpy(dynamicStates, m_CreationInfo->m_Pipeline[graphics.pipeline].dynamicStates, sizeof(dynamicStates)); @@ -230,41 +230,51 @@ void VulkanRenderState::BindPipeline(VkCommandBuffer cmd, PipelineBinding bindin sizeof(m_CreationInfo->m_Pipeline[graphics.pipeline].dynamicStates), "Dynamic states array size is out of sync"); - if(!views.empty() && dynamicStates[VK_DYNAMIC_STATE_VIEWPORT]) + if(!views.empty() && dynamicStates[VkDynamicViewport]) ObjDisp(cmd)->CmdSetViewport(Unwrap(cmd), 0, (uint32_t)views.size(), &views[0]); - if(!scissors.empty() && dynamicStates[VK_DYNAMIC_STATE_SCISSOR]) + if(!scissors.empty() && dynamicStates[VkDynamicScissor]) ObjDisp(cmd)->CmdSetScissor(Unwrap(cmd), 0, (uint32_t)scissors.size(), &scissors[0]); - if(dynamicStates[VK_DYNAMIC_STATE_LINE_WIDTH]) + if(dynamicStates[VkDynamicLineWidth]) ObjDisp(cmd)->CmdSetLineWidth(Unwrap(cmd), lineWidth); - if(dynamicStates[VK_DYNAMIC_STATE_DEPTH_BIAS]) + if(dynamicStates[VkDynamicDepthBias]) ObjDisp(cmd)->CmdSetDepthBias(Unwrap(cmd), bias.depth, bias.biasclamp, bias.slope); - if(dynamicStates[VK_DYNAMIC_STATE_BLEND_CONSTANTS]) + if(dynamicStates[VkDynamicBlendConstants]) ObjDisp(cmd)->CmdSetBlendConstants(Unwrap(cmd), blendConst); - if(dynamicStates[VK_DYNAMIC_STATE_DEPTH_BOUNDS]) + if(dynamicStates[VkDynamicDepthBounds]) ObjDisp(cmd)->CmdSetDepthBounds(Unwrap(cmd), mindepth, maxdepth); - if(dynamicStates[VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK]) + if(dynamicStates[VkDynamicStencilCompareMask]) { ObjDisp(cmd)->CmdSetStencilCompareMask(Unwrap(cmd), VK_STENCIL_FACE_BACK_BIT, back.compare); ObjDisp(cmd)->CmdSetStencilCompareMask(Unwrap(cmd), VK_STENCIL_FACE_FRONT_BIT, front.compare); } - if(dynamicStates[VK_DYNAMIC_STATE_STENCIL_WRITE_MASK]) + if(dynamicStates[VkDynamicStencilWriteMask]) { ObjDisp(cmd)->CmdSetStencilWriteMask(Unwrap(cmd), VK_STENCIL_FACE_BACK_BIT, back.write); ObjDisp(cmd)->CmdSetStencilWriteMask(Unwrap(cmd), VK_STENCIL_FACE_FRONT_BIT, front.write); } - if(dynamicStates[VK_DYNAMIC_STATE_STENCIL_REFERENCE]) + if(dynamicStates[VkDynamicStencilReference]) { ObjDisp(cmd)->CmdSetStencilReference(Unwrap(cmd), VK_STENCIL_FACE_BACK_BIT, back.ref); ObjDisp(cmd)->CmdSetStencilReference(Unwrap(cmd), VK_STENCIL_FACE_FRONT_BIT, front.ref); } + if(dynamicStates[VkDynamicSampleLocationsEXT]) + { + VkSampleLocationsInfoEXT info = {VK_STRUCTURE_TYPE_SAMPLE_LOCATIONS_INFO_EXT}; + info.pSampleLocations = sampleLocations.locations.data(); + info.sampleLocationsCount = (uint32_t)sampleLocations.locations.size(); + info.sampleLocationsPerPixel = sampleLocations.sampleCount; + info.sampleLocationGridSize = sampleLocations.gridSize; + ObjDisp(cmd)->CmdSetSampleLocationsEXT(Unwrap(cmd), &info); + } + // only set push constant ranges that the layout uses for(size_t i = 0; i < pushRanges.size(); i++) ObjDisp(cmd)->CmdPushConstants(Unwrap(cmd), Unwrap(layout), pushRanges[i].stageFlags, diff --git a/renderdoc/driver/vulkan/vk_state.h b/renderdoc/driver/vulkan/vk_state.h index c4b227e5b..bd6d01355 100644 --- a/renderdoc/driver/vulkan/vk_state.h +++ b/renderdoc/driver/vulkan/vk_state.h @@ -75,6 +75,13 @@ struct VulkanRenderState uint32_t compare, write, ref; } front, back; + struct + { + VkSampleCountFlagBits sampleCount; + VkExtent2D gridSize; + std::vector locations; + } sampleLocations; + // this should be big enough for any implementation byte pushconsts[1024]; // the actual number of bytes that have been uploaded diff --git a/renderdoc/driver/vulkan/vk_stringise.cpp b/renderdoc/driver/vulkan/vk_stringise.cpp index 7d4bacb86..7345a2e56 100644 --- a/renderdoc/driver/vulkan/vk_stringise.cpp +++ b/renderdoc/driver/vulkan/vk_stringise.cpp @@ -28,7 +28,7 @@ template <> std::string DoStringise(const VulkanChunk &el) { - RDCCOMPILE_ASSERT((uint32_t)VulkanChunk::Max == 1130, "Chunks changed without updating names"); + RDCCOMPILE_ASSERT((uint32_t)VulkanChunk::Max == 1131, "Chunks changed without updating names"); BEGIN_ENUM_STRINGISE(VulkanChunk) { @@ -162,6 +162,7 @@ std::string DoStringise(const VulkanChunk &el) STRINGISE_ENUM_CLASS(vkCmdDrawIndirectByteCountEXT) STRINGISE_ENUM_CLASS(vkCmdBeginConditionalRenderingEXT) STRINGISE_ENUM_CLASS(vkCmdEndConditionalRenderingEXT) + STRINGISE_ENUM_CLASS(vkCmdSetSampleLocationsEXT) STRINGISE_ENUM_CLASS_NAMED(Max, "Max Chunk"); } END_ENUM_STRINGISE() diff --git a/renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp index 0125f36e0..9c7a4b867 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp @@ -1827,49 +1827,58 @@ bool WrappedVulkan::Serialise_vkCmdBindPipeline(SerialiserType &ser, VkCommandBu { m_RenderState.graphics.pipeline = liveid; - if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VK_DYNAMIC_STATE_VIEWPORT]) + if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VkDynamicViewport]) { m_RenderState.views = m_CreationInfo.m_Pipeline[liveid].viewports; } - if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VK_DYNAMIC_STATE_SCISSOR]) + if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VkDynamicScissor]) { m_RenderState.scissors = m_CreationInfo.m_Pipeline[liveid].scissors; } - if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VK_DYNAMIC_STATE_LINE_WIDTH]) + if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VkDynamicLineWidth]) { m_RenderState.lineWidth = m_CreationInfo.m_Pipeline[liveid].lineWidth; } - if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VK_DYNAMIC_STATE_DEPTH_BIAS]) + if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VkDynamicDepthBias]) { m_RenderState.bias.depth = m_CreationInfo.m_Pipeline[liveid].depthBiasConstantFactor; m_RenderState.bias.biasclamp = m_CreationInfo.m_Pipeline[liveid].depthBiasClamp; m_RenderState.bias.slope = m_CreationInfo.m_Pipeline[liveid].depthBiasSlopeFactor; } - if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VK_DYNAMIC_STATE_BLEND_CONSTANTS]) + if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VkDynamicBlendConstants]) { memcpy(m_RenderState.blendConst, m_CreationInfo.m_Pipeline[liveid].blendConst, sizeof(float) * 4); } - if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VK_DYNAMIC_STATE_DEPTH_BOUNDS]) + if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VkDynamicDepthBounds]) { m_RenderState.mindepth = m_CreationInfo.m_Pipeline[liveid].minDepthBounds; m_RenderState.maxdepth = m_CreationInfo.m_Pipeline[liveid].maxDepthBounds; } - if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK]) + if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VkDynamicStencilCompareMask]) { m_RenderState.front.compare = m_CreationInfo.m_Pipeline[liveid].front.compareMask; m_RenderState.back.compare = m_CreationInfo.m_Pipeline[liveid].back.compareMask; } - if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VK_DYNAMIC_STATE_STENCIL_WRITE_MASK]) + if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VkDynamicStencilWriteMask]) { m_RenderState.front.write = m_CreationInfo.m_Pipeline[liveid].front.writeMask; m_RenderState.back.write = m_CreationInfo.m_Pipeline[liveid].back.writeMask; } - if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VK_DYNAMIC_STATE_STENCIL_REFERENCE]) + if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VkDynamicStencilReference]) { m_RenderState.front.ref = m_CreationInfo.m_Pipeline[liveid].front.reference; m_RenderState.back.ref = m_CreationInfo.m_Pipeline[liveid].back.reference; } + if(!m_CreationInfo.m_Pipeline[liveid].dynamicStates[VkDynamicSampleLocationsEXT]) + { + m_RenderState.sampleLocations.locations = + m_CreationInfo.m_Pipeline[liveid].sampleLocations.locations; + m_RenderState.sampleLocations.gridSize = + m_CreationInfo.m_Pipeline[liveid].sampleLocations.gridSize; + m_RenderState.sampleLocations.sampleCount = + m_CreationInfo.m_Pipeline[liveid].rasterizationSamples; + } } } } @@ -3256,7 +3265,7 @@ bool WrappedVulkan::Serialise_vkCmdDebugMarkerBeginEXT(SerialiserType &ser, const VkDebugMarkerMarkerInfoEXT *pMarker) { SERIALISE_ELEMENT(commandBuffer); - SERIALISE_ELEMENT_LOCAL(Marker, *pMarker); + SERIALISE_ELEMENT_LOCAL(Marker, *pMarker).Named("pMarker"); SERIALISE_CHECK_READ_ERRORS(); @@ -3408,7 +3417,7 @@ bool WrappedVulkan::Serialise_vkCmdDebugMarkerInsertEXT(SerialiserType &ser, const VkDebugMarkerMarkerInfoEXT *pMarker) { SERIALISE_ELEMENT(commandBuffer); - SERIALISE_ELEMENT_LOCAL(Marker, *pMarker); + SERIALISE_ELEMENT_LOCAL(Marker, *pMarker).Named("pMarker"); SERIALISE_CHECK_READ_ERRORS(); @@ -4791,7 +4800,8 @@ bool WrappedVulkan::Serialise_vkCmdBeginConditionalRenderingEXT( const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) { SERIALISE_ELEMENT(commandBuffer); - SERIALISE_ELEMENT_LOCAL(BeginInfo, *pConditionalRenderingBegin); + SERIALISE_ELEMENT_LOCAL(BeginInfo, *pConditionalRenderingBegin) + .Named("pConditionalRenderingBegin"); Serialise_DebugMessages(ser); @@ -5068,4 +5078,4 @@ INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdEndQueryIndexedEXT, VkCommandBuffer c INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdBeginConditionalRenderingEXT, VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin); -INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdEndConditionalRenderingEXT, VkCommandBuffer commandBuffer); \ No newline at end of file +INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdEndConditionalRenderingEXT, VkCommandBuffer commandBuffer); diff --git a/renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp index 08ded5e94..b14ba4c0c 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp @@ -539,12 +539,42 @@ VkResult WrappedVulkan::vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo if(renderdocAppInfo.apiVersion > VK_API_VERSION_1_0) record->instDevInfo->vulkanVersion = renderdocAppInfo.apiVersion; + std::set availablePhysDeviceFunctions; + + { + uint32_t count = 0; + ObjDisp(m_Instance)->EnumeratePhysicalDevices(Unwrap(m_Instance), &count, NULL); + + std::vector physDevs(count); + ObjDisp(m_Instance)->EnumeratePhysicalDevices(Unwrap(m_Instance), &count, physDevs.data()); + + std::vector exts; + for(VkPhysicalDevice p : physDevs) + { + ObjDisp(m_Instance)->EnumerateDeviceExtensionProperties(p, NULL, &count, NULL); + + exts.resize(count); + ObjDisp(m_Instance)->EnumerateDeviceExtensionProperties(p, NULL, &count, exts.data()); + + for(const VkExtensionProperties &e : exts) + { + availablePhysDeviceFunctions.insert(e.extensionName); + } + } + // we don't bother wrapping these, they're temporary handles + } + +// an extension is available if: +// * it's enabled in the instance creation +// * it's promoted in the selected vulkan version +// * it's a device extension and available on at least one physical device #undef CheckExt -#define CheckExt(name, ver) \ - if(!strcmp(modifiedCreateInfo.ppEnabledExtensionNames[i], "VK_" #name) || \ - record->instDevInfo->vulkanVersion >= ver) \ - { \ - record->instDevInfo->ext_##name = true; \ +#define CheckExt(name, ver) \ + if(!strcmp(modifiedCreateInfo.ppEnabledExtensionNames[i], "VK_" #name) || \ + record->instDevInfo->vulkanVersion >= ver || \ + availablePhysDeviceFunctions.find("VK_" #name) != availablePhysDeviceFunctions.end()) \ + { \ + record->instDevInfo->ext_##name = true; \ } for(uint32_t i = 0; i < modifiedCreateInfo.enabledExtensionCount; i++) @@ -2196,6 +2226,16 @@ VkResult WrappedVulkan::vkCreateDevice(VkPhysicalDevice physicalDevice, // for enabled extensions for instance functions CheckInstanceExts(); +// we unset the extension because it may be a 'shared' extension that's available at both instance +// and device. Only set it to enabled if it's really enabled for this device. This can happen with a +// device extension that is reported by another physical device than the one selected - it becomes +// available at instance level (e.g. for physical device queries) but is not available at *this* +// device level. +#undef CheckExt +#define CheckExt(name, ver) record->instDevInfo->ext_##name = false; + + CheckDeviceExts(); + #undef CheckExt #define CheckExt(name, ver) \ if(!strcmp(createInfo.ppEnabledExtensionNames[i], "VK_" #name) || \ diff --git a/renderdoc/driver/vulkan/wrappers/vk_dynamic_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_dynamic_funcs.cpp index 5a96789de..2471b736e 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_dynamic_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_dynamic_funcs.cpp @@ -601,6 +601,72 @@ void WrappedVulkan::vkCmdSetStencilReference(VkCommandBuffer commandBuffer, } } +template +bool WrappedVulkan::Serialise_vkCmdSetSampleLocationsEXT( + SerialiserType &ser, VkCommandBuffer commandBuffer, + const VkSampleLocationsInfoEXT *pSampleLocationsInfo) +{ + SERIALISE_ELEMENT(commandBuffer); + SERIALISE_ELEMENT_LOCAL(sampleInfo, *pSampleLocationsInfo).Named("pSampleLocationsInfo"); + + Serialise_DebugMessages(ser); + + SERIALISE_CHECK_READ_ERRORS(); + + if(IsReplayingAndReading()) + { + m_LastCmdBufferID = GetResourceManager()->GetOriginalID(GetResID(commandBuffer)); + + if(IsActiveReplaying(m_State)) + { + if(InRerecordRange(m_LastCmdBufferID)) + { + commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); + + if(ShouldUpdateRenderState(m_LastCmdBufferID)) + { + m_RenderState.sampleLocations.locations.clear(); + m_RenderState.sampleLocations.locations.insert( + m_RenderState.sampleLocations.locations.begin(), sampleInfo.pSampleLocations, + sampleInfo.pSampleLocations + sampleInfo.sampleLocationsCount); + m_RenderState.sampleLocations.gridSize = sampleInfo.sampleLocationGridSize; + m_RenderState.sampleLocations.sampleCount = sampleInfo.sampleLocationsPerPixel; + } + } + else + { + commandBuffer = VK_NULL_HANDLE; + } + } + + if(commandBuffer != VK_NULL_HANDLE) + ObjDisp(commandBuffer)->CmdSetSampleLocationsEXT(Unwrap(commandBuffer), &sampleInfo); + } + + return true; +} + +void WrappedVulkan::vkCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer, + const VkSampleLocationsInfoEXT *pSampleLocationsInfo) +{ + SCOPED_DBG_SINK(); + + SERIALISE_TIME_CALL( + ObjDisp(commandBuffer)->CmdSetSampleLocationsEXT(Unwrap(commandBuffer), pSampleLocationsInfo)); + + if(IsCaptureMode(m_State)) + { + VkResourceRecord *record = GetRecord(commandBuffer); + + CACHE_THREAD_SERIALISER(); + + SCOPED_SERIALISE_CHUNK(VulkanChunk::vkCmdSetSampleLocationsEXT); + Serialise_vkCmdSetSampleLocationsEXT(ser, commandBuffer, pSampleLocationsInfo); + + record->AddChunk(scope.Get()); + } +} + INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdSetViewport, VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewport *pViewports); @@ -630,3 +696,6 @@ INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdSetStencilWriteMask, VkCommandBuffer INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdSetStencilReference, VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t reference); + +INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdSetSampleLocationsEXT, VkCommandBuffer commandBuffer, + const VkSampleLocationsInfoEXT *pSampleLocationsInfo); \ No newline at end of file diff --git a/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp index 81998f247..98e2f454f 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp @@ -696,4 +696,12 @@ VkResult WrappedVulkan::vkGetValidationCacheDataEXT(VkDevice device, { return ObjDisp(device)->GetValidationCacheDataEXT(Unwrap(device), validationCache, pDataSize, pData); +} +void WrappedVulkan::vkGetPhysicalDeviceMultisamplePropertiesEXT( + VkPhysicalDevice physicalDevice, VkSampleCountFlagBits samples, + VkMultisamplePropertiesEXT *pMultisampleProperties) +{ + return ObjDisp(physicalDevice) + ->GetPhysicalDeviceMultisamplePropertiesEXT(Unwrap(physicalDevice), samples, + pMultisampleProperties); } \ No newline at end of file diff --git a/renderdoc/replay/renderdoc_serialise.inl b/renderdoc/replay/renderdoc_serialise.inl index 8add939bd..40a908164 100644 --- a/renderdoc/replay/renderdoc_serialise.inl +++ b/renderdoc/replay/renderdoc_serialise.inl @@ -2000,6 +2000,16 @@ void DoSerialise(SerialiserType &ser, VKPipe::Rasterizer &el) SIZE_CHECK(36); } +template +void DoSerialise(SerialiserType &ser, VKPipe::SampleLocations &el) +{ + SERIALISE_MEMBER(gridWidth); + SERIALISE_MEMBER(gridHeight); + SERIALISE_MEMBER(customLocations); + + SIZE_CHECK(24); +} + template void DoSerialise(SerialiserType &ser, VKPipe::MultiSample &el) { @@ -2007,8 +2017,9 @@ void DoSerialise(SerialiserType &ser, VKPipe::MultiSample &el) SERIALISE_MEMBER(sampleShadingEnable); SERIALISE_MEMBER(minSampleShading); SERIALISE_MEMBER(sampleMask); + SERIALISE_MEMBER(sampleLocations); - SIZE_CHECK(16); + SIZE_CHECK(40); } template @@ -2170,7 +2181,7 @@ void DoSerialise(SerialiserType &ser, VKPipe::State &el) SERIALISE_MEMBER(conditionalRendering); - SIZE_CHECK(1384); + SIZE_CHECK(1408); } #pragma endregion Vulkan pipeline state diff --git a/util/test/demos/demos.vcxproj b/util/test/demos/demos.vcxproj index 8a677dc45..4add3184f 100644 --- a/util/test/demos/demos.vcxproj +++ b/util/test/demos/demos.vcxproj @@ -196,6 +196,7 @@ + diff --git a/util/test/demos/demos.vcxproj.filters b/util/test/demos/demos.vcxproj.filters index 3a59635a1..84cfcd6c6 100644 --- a/util/test/demos/demos.vcxproj.filters +++ b/util/test/demos/demos.vcxproj.filters @@ -246,6 +246,9 @@ OpenGL\demos + + Vulkan\demos + diff --git a/util/test/demos/vk/vk_helpers.h b/util/test/demos/vk/vk_helpers.h index 400b6cf46..2617f78c3 100644 --- a/util/test/demos/vk/vk_helpers.h +++ b/util/test/demos/vk/vk_helpers.h @@ -266,6 +266,23 @@ struct DeviceCreateInfo : public VkDeviceCreateInfo operator const VkDeviceCreateInfo *() const { return this; } }; +struct PhysicalDeviceProperties2KHR : public VkPhysicalDeviceProperties2KHR +{ + PhysicalDeviceProperties2KHR() + { + sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR; + pNext = NULL; + } + + PhysicalDeviceProperties2KHR &next(void *next) + { + this->pNext = next; + return *this; + } + + operator VkPhysicalDeviceProperties2KHR *() { return this; } +}; + struct SemaphoreCreateInfo : public VkSemaphoreCreateInfo { SemaphoreCreateInfo() : VkSemaphoreCreateInfo() @@ -810,6 +827,12 @@ struct RenderPassBeginInfo : public VkRenderPassBeginInfo this->pClearValues = clearVals.data(); } + RenderPassBeginInfo &next(const void *next) + { + this->pNext = next; + return *this; + } + operator const VkRenderPassBeginInfo *() const { return this; } }; diff --git a/util/test/demos/vk/vk_sample_locations.cpp b/util/test/demos/vk/vk_sample_locations.cpp new file mode 100644 index 000000000..5bc00877b --- /dev/null +++ b/util/test/demos/vk/vk_sample_locations.cpp @@ -0,0 +1,301 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2018-2019 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "vk_test.h" + +struct VK_Sample_Locations : VulkanGraphicsTest +{ + static constexpr const char *Description = + "Draws two triangles with different sample locations using VK_EXT_sample_locations"; + + std::string common = R"EOSHADER( + +#version 420 core + +struct v2f +{ + vec4 pos; + vec4 col; + vec4 uv; +}; + +)EOSHADER"; + + const std::string vertex = R"EOSHADER( + +layout(location = 0) in vec3 Position; +layout(location = 1) in vec4 Color; +layout(location = 2) in vec2 UV; + +layout(location = 0) out v2f vertOut; + +void main() +{ + vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); + gl_Position = vertOut.pos; + vertOut.col = Color; + vertOut.uv = vec4(UV.xy, 0, 1); +} + +)EOSHADER"; + + const std::string pixel = R"EOSHADER( + +layout(location = 0) in v2f vertIn; + +layout(location = 0, index = 0) out vec4 Color; + +void main() +{ + Color = vertIn.col; +} + +)EOSHADER"; + + int main(int argc, char **argv) + { + instExts.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); + devExts.push_back(VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME); + + // initialise, create window, create context, etc + if(!Init(argc, argv)) + return 3; + + VkPhysicalDeviceSampleLocationsPropertiesEXT sampleProps = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT}; + + vkGetPhysicalDeviceProperties2KHR(phys, vkh::PhysicalDeviceProperties2KHR().next(&sampleProps)); + + TEST_ASSERT(sampleProps.sampleLocationSampleCounts & VK_SAMPLE_COUNT_4_BIT, + "Sample locations for MSAA 4x not supported"); + + VkPipelineLayout layout = createPipelineLayout(vkh::PipelineLayoutCreateInfo()); + + // create multi-sampled image + AllocatedImage msaaimg( + allocator, + vkh::ImageCreateInfo(scissor.extent.width, scissor.extent.height, 0, swapFormat, + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | + VK_IMAGE_USAGE_SAMPLED_BIT, + 1, 1, VK_SAMPLE_COUNT_4_BIT), + VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_GPU_ONLY})); + + VkImageView msview = + createImageView(vkh::ImageViewCreateInfo(msaaimg.image, VK_IMAGE_VIEW_TYPE_2D, swapFormat)); + + // create renderpass using the DS image + vkh::RenderPassCreator renderPassCreateInfo; + + renderPassCreateInfo.attachments.push_back(vkh::AttachmentDescription( + swapFormat, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE, VK_SAMPLE_COUNT_4_BIT)); + renderPassCreateInfo.attachments.push_back( + vkh::AttachmentDescription(swapFormat, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL)); + + renderPassCreateInfo.addSubpass( + {VkAttachmentReference({0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL})}, VK_ATTACHMENT_UNUSED, + VK_IMAGE_LAYOUT_UNDEFINED, {VkAttachmentReference({1, VK_IMAGE_LAYOUT_GENERAL})}); + + VkRenderPass renderPass = createRenderPass(renderPassCreateInfo); + + // create framebuffers using swapchain images and DS image + std::vector fbs; + fbs.resize(swapImageViews.size()); + + for(size_t i = 0; i < swapImageViews.size(); i++) + fbs[i] = createFramebuffer( + vkh::FramebufferCreateInfo(renderPass, {msview, swapImageViews[i]}, scissor.extent)); + + vkh::GraphicsPipelineCreateInfo pipeCreateInfo; + + pipeCreateInfo.layout = layout; + pipeCreateInfo.renderPass = renderPass; + + pipeCreateInfo.vertexInputState.vertexBindingDescriptions = {vkh::vertexBind(0, DefaultA2V)}; + pipeCreateInfo.vertexInputState.vertexAttributeDescriptions = { + vkh::vertexAttr(0, 0, DefaultA2V, pos), vkh::vertexAttr(1, 0, DefaultA2V, col), + vkh::vertexAttr(2, 0, DefaultA2V, uv), + }; + + pipeCreateInfo.stages = { + CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + }; + + pipeCreateInfo.dynamicState.dynamicStates.push_back(VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT); + + VkPipelineSampleLocationsStateCreateInfoEXT samplePipe = { + VK_STRUCTURE_TYPE_PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT, + }; + + samplePipe.sampleLocationsEnable = VK_TRUE; + samplePipe.sampleLocationsInfo.sType = VK_STRUCTURE_TYPE_SAMPLE_LOCATIONS_INFO_EXT; + + pipeCreateInfo.multisampleState.pNext = &samplePipe; + pipeCreateInfo.multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; + + VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); + + AllocatedBuffer vb( + allocator, vkh::BufferCreateInfo(sizeof(DefaultTri), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | + VK_BUFFER_USAGE_TRANSFER_DST_BIT), + VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_CPU_TO_GPU})); + + vb.upload(DefaultTri); + + while(Running()) + { + VkCommandBuffer cmd = GetCommandBuffer(); + + vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo()); + + VkImage swapimg = + StartUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); + + vkCmdClearColorImage(cmd, swapimg, VK_IMAGE_LAYOUT_GENERAL, + vkh::ClearColorValue(0.4f, 0.5f, 0.6f, 1.0f), 1, + vkh::ImageSubresourceRange()); + + vkh::cmdPipelineBarrier( + cmd, { + vkh::ImageMemoryBarrier(0, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, msaaimg.image), + }); + + vkCmdClearColorImage(cmd, msaaimg.image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + vkh::ClearColorValue(0.6f, 0.5f, 0.4f, 1.0f), 1, + vkh::ImageSubresourceRange()); + + vkh::cmdPipelineBarrier( + cmd, { + vkh::ImageMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, msaaimg.image), + }); + + VkRect2D region = scissor; + region.extent.width /= 2; + + VkViewport view = viewport; + view.width /= 2.0f; + + VkRenderPassSampleLocationsBeginInfoEXT sampleBegin = { + VK_STRUCTURE_TYPE_RENDER_PASS_SAMPLE_LOCATIONS_BEGIN_INFO_EXT, + }; + + float gridBase = sampleProps.sampleLocationCoordinateRange[0]; + float gridDim = sampleProps.sampleLocationCoordinateRange[1]; + +// rescales from [-8, 8] to [maxGrid[0], maxGrid[1]] in both dimension +#define SAMPLE_POS(x, y) \ + { \ + (((x) + 8.0f) / 16.0f) * gridDim + gridBase, (((y) + 8.0f) / 16.0f) * gridDim + gridBase \ + } + + // vertical grid and degenerate + VkSampleLocationEXT locations1[4] = { + // TL + SAMPLE_POS(0.0f, -8.0f), + // TR + SAMPLE_POS(0.0f, -8.0f), + // BL + SAMPLE_POS(0.0f, 8.0f), + // BR + SAMPLE_POS(0.0f, 8.0f), + }; + + // rotated grid + VkSampleLocationEXT locations2[4] = { + // TL + SAMPLE_POS(-2.0f, -6.0f), + // TR + SAMPLE_POS(6.0f, -2.0f), + // BL + SAMPLE_POS(-6.0f, 2.0f), + // BR + SAMPLE_POS(2.0f, 6.0f), + }; + + VkSubpassSampleLocationsEXT subpassSamples = {}; + subpassSamples.subpassIndex = 0; + subpassSamples.sampleLocationsInfo.sType = VK_STRUCTURE_TYPE_SAMPLE_LOCATIONS_INFO_EXT; + subpassSamples.sampleLocationsInfo.sampleLocationGridSize.width = 1; + subpassSamples.sampleLocationsInfo.sampleLocationGridSize.height = 1; + subpassSamples.sampleLocationsInfo.sampleLocationsCount = 4; + subpassSamples.sampleLocationsInfo.sampleLocationsPerPixel = VK_SAMPLE_COUNT_4_BIT; + subpassSamples.sampleLocationsInfo.pSampleLocations = locations1; + + sampleBegin.postSubpassSampleLocationsCount = 1; + sampleBegin.pPostSubpassSampleLocations = &subpassSamples; + + vkCmdBeginRenderPass(cmd, vkh::RenderPassBeginInfo(renderPass, fbs[swapIndex], region, + {vkh::ClearValue(0.0f, 0.0f, 0.0f, 1.0f)}) + .next(&sampleBegin), + VK_SUBPASS_CONTENTS_INLINE); + + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); + vkCmdSetSampleLocationsEXT(cmd, &subpassSamples.sampleLocationsInfo); + vkCmdSetViewport(cmd, 0, 1, &view); + vkCmdSetScissor(cmd, 0, 1, ®ion); + vkh::cmdBindVertexBuffers(cmd, 0, {vb.buffer}, {0}); + setMarker(cmd, "Degenerate Sample Locations"); + vkCmdDraw(cmd, 3, 1, 0, 0); + + vkCmdEndRenderPass(cmd); + + region.offset.x += region.extent.width; + view.x += view.width; + + subpassSamples.sampleLocationsInfo.pSampleLocations = locations2; + + vkCmdBeginRenderPass(cmd, vkh::RenderPassBeginInfo(renderPass, fbs[swapIndex], region, + {vkh::ClearValue(0.0f, 0.0f, 0.0f, 1.0f)}) + .next(&sampleBegin), + VK_SUBPASS_CONTENTS_INLINE); + + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); + vkCmdSetSampleLocationsEXT(cmd, &subpassSamples.sampleLocationsInfo); + vkCmdSetViewport(cmd, 0, 1, &view); + vkCmdSetScissor(cmd, 0, 1, ®ion); + vkh::cmdBindVertexBuffers(cmd, 0, {vb.buffer}, {0}); + setMarker(cmd, "Rotated Grid Sample Locations"); + vkCmdDraw(cmd, 3, 1, 0, 0); + + vkCmdEndRenderPass(cmd); + + FinishUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); + + vkEndCommandBuffer(cmd); + + Submit(0, 1, {cmd}); + + Present(); + } + + return 0; + } +}; + +REGISTER_TEST(VK_Sample_Locations); \ No newline at end of file diff --git a/util/test/tests/Vulkan/VK_Indirect.py b/util/test/tests/Vulkan/VK_Indirect.py index 58edbb8ac..26584778d 100644 --- a/util/test/tests/Vulkan/VK_Indirect.py +++ b/util/test/tests/Vulkan/VK_Indirect.py @@ -83,7 +83,10 @@ class VK_Indirect(rdtest.TestCase): for y in range(0, 8): # 3 groups of 2 threads each for z in range(0, 5): # 5 groups of 1 thread each idx = 100 + z*8*6 + y*6 + x - rdtest.value_compare(uints[idx], [x, y, z, 12345]) + if not rdtest.value_compare(uints[idx], [x, y, z, 12345]): + raise rdtest.TestFailureException( + 'expected thread index data @ {},{},{}: {} is not as expected: {}' + .format(x, y, z, uints[idx], [x, y, z, 12345])) rdtest.log.success("Dispatched buffer contents are as expected for {}".format(level)) diff --git a/util/test/tests/Vulkan/VK_Sample_Locations.py b/util/test/tests/Vulkan/VK_Sample_Locations.py new file mode 100644 index 000000000..3b9743677 --- /dev/null +++ b/util/test/tests/Vulkan/VK_Sample_Locations.py @@ -0,0 +1,137 @@ +import renderdoc as rd +import rdtest +from PIL import Image + + +class VK_Sample_Locations(rdtest.TestCase): + def get_capture(self): + return rdtest.run_and_capture("demos_x64", "VK_Sample_Locations", 5) + + def check_capture(self): + draw: rd.DrawcallDescription = self.find_draw("Degenerate") + self.controller.SetFrameEvent(draw.next.eventId, True) + pipe: rd.VKState = self.controller.GetVulkanPipelineState() + + if pipe.multisample.rasterSamples != 4: + raise rdtest.TestFailureException("MSAA sample count is {}, not 1".format(pipe.multisample.rasterSamples)) + + sampleLoc: rd.VKSampleLocations = pipe.multisample.sampleLocations + + if sampleLoc.gridWidth != 1: + raise rdtest.TestFailureException("Sample locations grid width is {}, not 1".format(sampleLoc.gridWidth)) + if sampleLoc.gridHeight != 1: + raise rdtest.TestFailureException("Sample locations grid height is {}, not 1".format(sampleLoc.gridHeight)) + + # [0] and [1] should be identical, as should [2] and [3], but they should be different from each other + if not sampleLoc.customLocations[0] == sampleLoc.customLocations[1]: + raise rdtest.TestFailureException("In degenerate case, sample locations [0] and [1] don't match: {} vs {}" + .format(sampleLoc.customLocations[0], sampleLoc.customLocations[1])) + + if not sampleLoc.customLocations[2] == sampleLoc.customLocations[3]: + raise rdtest.TestFailureException("In degenerate case, sample locations [2] and [3] don't match: {} vs {}" + .format(sampleLoc.customLocations[2], sampleLoc.customLocations[3])) + + if sampleLoc.customLocations[1] == sampleLoc.customLocations[2]: + raise rdtest.TestFailureException("In degenerate case, sample locations [1] and [2] DO match: {} vs {}" + .format(sampleLoc.customLocations[1], sampleLoc.customLocations[2])) + + draw: rd.DrawcallDescription = self.find_draw("Rotated") + self.controller.SetFrameEvent(draw.next.eventId, True) + pipe: rd.VKState = self.controller.GetVulkanPipelineState() + + if pipe.multisample.rasterSamples != 4: + raise rdtest.TestFailureException("MSAA sample count is {}, not 1".format(pipe.multisample.rasterSamples)) + + sampleLoc: rd.VKSampleLocations = pipe.multisample.sampleLocations + + if sampleLoc.gridWidth != 1: + raise rdtest.TestFailureException("Sample locations grid width is {}, not 1".format(sampleLoc.gridWidth)) + if sampleLoc.gridHeight != 1: + raise rdtest.TestFailureException("Sample locations grid height is {}, not 1".format(sampleLoc.gridHeight)) + + # All sample locations should be unique + if sampleLoc.customLocations[0] == sampleLoc.customLocations[1]: + raise rdtest.TestFailureException("In rotated case, sample locations [0] and [1] DO match: {} vs {}" + .format(sampleLoc.customLocations[0], sampleLoc.customLocations[1])) + + if sampleLoc.customLocations[1] == sampleLoc.customLocations[2]: + raise rdtest.TestFailureException("In rotated case, sample locations [1] and [2] DO match: {} vs {}" + .format(sampleLoc.customLocations[1], sampleLoc.customLocations[2])) + + if sampleLoc.customLocations[2] == sampleLoc.customLocations[3]: + raise rdtest.TestFailureException("In rotated case, sample locations [2] and [3] DO match: {} vs {}" + .format(sampleLoc.customLocations[2], sampleLoc.customLocations[3])) + + rdtest.log.success("Pipeline state is correct") + + # Grab the multisampled image's ID here + save_data = rd.TextureSave() + curpass: rd.VKCurrentPass = pipe.currentPass + save_data.resourceId = curpass.framebuffer.attachments[curpass.renderpass.colorAttachments[0]].imageResourceId + save_data.destType = rd.FileType.PNG + save_data.sample.mapToArray = False + + dim = (0, 0) + texs = self.controller.GetTextures() + for tex in texs: + if tex.resourceId == save_data.resourceId: + dim = (tex.width, tex.height) + + if dim == (0,0): + raise rdtest.TestFailureException("Couldn't get dimensions of texture") + + last_draw: rd.DrawcallDescription = self.get_last_draw() + + self.controller.SetFrameEvent(last_draw.eventId, True) + + # Due to the variability of rasterization between implementations or even drivers, + # we don't want to check against a 'known good'. + # So instead we verify that at the first degenerate draw each pair of two sample's images are identical and that + # in the rotated grid case each sample's image is distinct. + # In future we could also check that the degenerate case 'stretches' the triangle up, as with the way the + # geometry is defined the second sample image should be a superset (i.e. strictly more samples covered). + rotated_paths = [] + degenerate_paths = [] + + for sample in range(0, 4): + tmp_path = rdtest.get_tmp_path('sample{}.png'.format(sample)) + degenerate_path = rdtest.get_tmp_path('degenerate{}.png'.format(sample)) + rotated_path = rdtest.get_tmp_path('rotated{}.png'.format(sample)) + + rotated_paths.append(rotated_path) + degenerate_paths.append(degenerate_path) + + save_data.sample.sampleIndex = sample + self.controller.SaveTexture(save_data, tmp_path) + + try: + img = Image.open(tmp_path) + except Exception as ex: + raise FileNotFoundError("Can't open {}".format(rdtest.sanitise_filename(tmp_path))) + + img.crop((0, 0, dim[0]/2, dim[1])).save(degenerate_path) + img.crop((dim[0]/2, 0, dim[0], dim[1])).save(rotated_path) + + # first two degenerate images should be identical, as should the last two, and they should be different. + if not rdtest.image_compare(degenerate_paths[0], degenerate_paths[1], 0): + raise rdtest.TestFailureException("Degenerate grid sample 0 and 1 are different", + degenerate_paths[0], degenerate_paths[1]) + + if not rdtest.image_compare(degenerate_paths[2], degenerate_paths[3], 0): + raise rdtest.TestFailureException("Degenerate grid sample 2 and 3 are different", + degenerate_paths[2], degenerate_paths[3]) + + if rdtest.image_compare(degenerate_paths[1], degenerate_paths[2], 0): + raise rdtest.TestFailureException("Degenerate grid sample 1 and 2 are identical", + degenerate_paths[1], degenerate_paths[2]) + + rdtest.log.success("Degenerate grid sample images are as expected") + + # all rotated images should be different + for A in range(0, 4): + for B in range(A+1, 4): + if rdtest.image_compare(rotated_paths[A], rotated_paths[B], 0): + raise rdtest.TestFailureException("Rotated grid sample {} and {} are identical".format(A, B), + rotated_paths[A], rotated_paths[B]) + + rdtest.log.success("Rotated grid sample images are as expected")