Permalink
Browse files

Vulkan: Use VK_KHR_DEDICATED_ALLOCATION for frame buffers for minor s…

…peedup on some GPUs. Check for the debug report extension before enabling it.
  • Loading branch information...
hrydgard committed Dec 30, 2017
1 parent 25a9573 commit b9726245acf5a151a437d6fa89b574aba3b63011
Showing with 28 additions and 6 deletions.
  1. +11 −4 Common/Vulkan/VulkanContext.cpp
  2. +8 −0 Common/Vulkan/VulkanContext.h
  3. +9 −2 ext/native/thin3d/VulkanRenderManager.cpp
@@ -125,11 +125,16 @@ VkResult VulkanContext::CreateInstance(const CreateInfo &info) {
#endif
if (flags_ & VULKAN_FLAG_VALIDATE) {
for (size_t i = 0; i < ARRAY_SIZE(validationLayers); i++) {
instance_layer_names_.push_back(validationLayers[i]);
device_layer_names_.push_back(validationLayers[i]);
if (IsInstanceExtensionAvailable(VK_EXT_DEBUG_REPORT_EXTENSION_NAME)) {
for (size_t i = 0; i < ARRAY_SIZE(validationLayers); i++) {
instance_layer_names_.push_back(validationLayers[i]);
device_layer_names_.push_back(validationLayers[i]);
}
instance_extensions_enabled_.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
} else {
ELOG("Validation layer extension not available - not enabling Vulkan validation.");
flags_ &= ~VULKAN_FLAG_VALIDATE;
}
instance_extensions_enabled_.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
}
// Validate that all the instance extensions we ask for are actually available.
@@ -550,6 +555,8 @@ VkResult VulkanContext::CreateDevice() {
}
assert(found);
deviceExtensionsLookup_.DEDICATED_ALLOCATION = EnableDeviceExtension(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME);
VkDeviceCreateInfo device_info { VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO };
device_info.queueCreateInfoCount = 1;
device_info.pQueueCreateInfos = &queue_info;
@@ -104,6 +104,11 @@ class VulkanDeleteList {
std::vector<Callback> callbacks_;
};
// For fast extension-enabled checks.
struct VulkanDeviceExtensions {
bool DEDICATED_ALLOCATION;
};
// VulkanContext manages the device and swapchain, and deferred deletion of objects.
class VulkanContext {
public:
@@ -233,6 +238,8 @@ class VulkanContext {
MAX_INFLIGHT_FRAMES = 3,
};
const VulkanDeviceExtensions &DeviceExtensions() { return deviceExtensionsLookup_; }
private:
// A layer can expose extensions, keep track of those extensions here.
struct LayerProperties {
@@ -265,6 +272,7 @@ class VulkanContext {
std::vector<const char *> device_extensions_enabled_;
std::vector<VkExtensionProperties> device_extension_properties_;
VulkanDeviceExtensions deviceExtensionsLookup_{};
std::vector<VkPhysicalDevice> physical_devices_;
@@ -38,13 +38,20 @@ void CreateImage(VulkanContext *vulkan, VkCommandBuffer cmd, VKRImage &img, int
vkCreateImage(vulkan->GetDevice(), &ici, nullptr, &img.image);
// TODO: If available, use nVidia's VK_NV_dedicated_allocation for framebuffers
VkMemoryRequirements memreq;
vkGetImageMemoryRequirements(vulkan->GetDevice(), img.image, &memreq);
VkMemoryAllocateInfo alloc{ VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
alloc.allocationSize = memreq.size;
// Hint to the driver that this allocation is image-specific. Some drivers benefit.
// We only bother supporting the KHR extension, not the old NV one.
VkMemoryDedicatedAllocateInfoKHR dedicated{ VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR };
if (vulkan->DeviceExtensions().DEDICATED_ALLOCATION) {
alloc.pNext = &dedicated;
dedicated.image = img.image;

This comment has been minimized.

Show comment
Hide comment
@unknownbrackets

unknownbrackets Dec 30, 2017

Collaborator

I wonder if it's desirable to see if the driver supports or requires dedicated allocations for the buffers?

http://asawicki.info/articles/VK_KHR_dedicated_allocation.php5

-[Unknown]

@unknownbrackets

unknownbrackets Dec 30, 2017

Collaborator

I wonder if it's desirable to see if the driver supports or requires dedicated allocations for the buffers?

http://asawicki.info/articles/VK_KHR_dedicated_allocation.php5

-[Unknown]

This comment has been minimized.

Show comment
Hide comment
@hrydgard

hrydgard Dec 30, 2017

Owner

Oh, I had missed the require thing, ugh. Thought drivers could only prefer, in which case this would never cause any trouble since we always have done separate allocations for render target. Think I'll need to turn this off to be safe, I wonder why a driver would want to require dedicated allocations, when if you leave the extension non-enabled, they anyway have to support non-dedicated ones.. bleh.

@hrydgard

hrydgard Dec 30, 2017

Owner

Oh, I had missed the require thing, ugh. Thought drivers could only prefer, in which case this would never cause any trouble since we always have done separate allocations for render target. Think I'll need to turn this off to be safe, I wonder why a driver would want to require dedicated allocations, when if you leave the extension non-enabled, they anyway have to support non-dedicated ones.. bleh.

}
vulkan->MemoryTypeFromProperties(memreq.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &alloc.memoryTypeIndex);
VkResult res = vkAllocateMemory(vulkan->GetDevice(), &alloc, nullptr, &img.memory);
assert(res == VK_SUCCESS);

0 comments on commit b972624

Please sign in to comment.