Added multisampling example (work-in-progress)
This commit is contained in:
parent
ac4ac3ad4d
commit
a4aa8c632a
1 changed files with 3 additions and 10 deletions
|
|
@ -123,32 +123,25 @@ public:
|
||||||
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||||
info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||||
info.samples = SAMPLE_COUNT;
|
info.samples = SAMPLE_COUNT;
|
||||||
|
// Image will only be used as a transient target
|
||||||
// This image will only be used as a transient render target.
|
|
||||||
// Its purpose is only to hold the multisampled data before resolving the render pass.
|
|
||||||
info.usage = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
info.usage = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||||
info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
|
||||||
// Create texture
|
|
||||||
vkTools::checkResult(vkCreateImage(device, &info, nullptr, &multisampleTarget.image));
|
vkTools::checkResult(vkCreateImage(device, &info, nullptr, &multisampleTarget.image));
|
||||||
|
|
||||||
// Allocate memory for the texture.
|
|
||||||
VkMemoryRequirements memReqs;
|
VkMemoryRequirements memReqs;
|
||||||
vkGetImageMemoryRequirements(device, multisampleTarget.image, &memReqs);
|
vkGetImageMemoryRequirements(device, multisampleTarget.image, &memReqs);
|
||||||
|
|
||||||
VkMemoryAllocateInfo alloc = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
|
VkMemoryAllocateInfo alloc = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
|
||||||
alloc.allocationSize = memReqs.size;
|
alloc.allocationSize = memReqs.size;
|
||||||
// For multisampled attachments, we will want to use LAZILY allocated if such a type is available.
|
|
||||||
// Lazily allocated memory is not actually allocated until the memory is actually used.
|
|
||||||
// This texture will only live on the tile buffer, so it never needs to be backed by actual memory.
|
|
||||||
VkMemoryAllocateInfo memAlloc = vkTools::initializers::memoryAllocateInfo();
|
VkMemoryAllocateInfo memAlloc = vkTools::initializers::memoryAllocateInfo();
|
||||||
// Try to get a lazily allocated memory type
|
// Try to get a lazily allocated memory type
|
||||||
|
// todo : Fallback to other memory formats?
|
||||||
getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, &memAlloc.memoryTypeIndex);
|
getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, &memAlloc.memoryTypeIndex);
|
||||||
vkTools::checkResult(vkAllocateMemory(device, &alloc, nullptr, &multisampleTarget.memory));
|
vkTools::checkResult(vkAllocateMemory(device, &alloc, nullptr, &multisampleTarget.memory));
|
||||||
vkBindImageMemory(device, multisampleTarget.image, multisampleTarget.memory, 0);
|
vkBindImageMemory(device, multisampleTarget.image, multisampleTarget.memory, 0);
|
||||||
|
|
||||||
// Create an image view for the new texture.
|
// Create image view for the MSAA target
|
||||||
// Note that CreateImageView must happen after BindImageMemory.
|
|
||||||
VkImageViewCreateInfo viewInfo = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO };
|
VkImageViewCreateInfo viewInfo = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO };
|
||||||
viewInfo.image = multisampleTarget.image;
|
viewInfo.image = multisampleTarget.image;
|
||||||
viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue