MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / CreateFrameBuffer

Method CreateFrameBuffer

samples/hellovr_vulkan/hellovr_vulkan_main.cpp:2584–2774  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: Creates a frame buffer. Returns true if the buffer was set up. Returns false if the setup failed. -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

2582// Returns false if the setup failed.
2583//-----------------------------------------------------------------------------
2584bool CMainApplication::CreateFrameBuffer( int nWidth, int nHeight, FramebufferDesc &framebufferDesc )
2585{
2586 //---------------------------//
2587 // Create color target //
2588 //---------------------------//
2589 VkImageCreateInfo imageCreateInfo = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };
2590 imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
2591 imageCreateInfo.extent.width = nWidth;
2592 imageCreateInfo.extent.height = nHeight;
2593 imageCreateInfo.extent.depth = 1;
2594 imageCreateInfo.mipLevels = 1;
2595 imageCreateInfo.arrayLayers = 1;
2596 imageCreateInfo.format = VK_FORMAT_R8G8B8A8_SRGB;
2597 imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
2598 imageCreateInfo.samples = ( VkSampleCountFlagBits ) m_nMSAASampleCount;
2599 imageCreateInfo.usage = ( VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT );
2600 imageCreateInfo.flags = 0;
2601
2602 VkResult nResult;
2603 nResult = vkCreateImage( m_pDevice, &imageCreateInfo, nullptr, &framebufferDesc.m_pImage );
2604 if ( nResult != VK_SUCCESS )
2605 {
2606 dprintf( "vkCreateImage failed for eye image with error %d\n", nResult );
2607 return false;
2608 }
2609 VkMemoryRequirements memoryRequirements = {};
2610 vkGetImageMemoryRequirements( m_pDevice, framebufferDesc.m_pImage, &memoryRequirements );
2611
2612 VkMemoryAllocateInfo memoryAllocateInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
2613 memoryAllocateInfo.allocationSize = memoryRequirements.size;
2614 if ( !MemoryTypeFromProperties( m_physicalDeviceMemoryProperties, memoryRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &memoryAllocateInfo.memoryTypeIndex ) )
2615 {
2616 dprintf( "Failed to find memory type matching requirements.\n" );
2617 return false;
2618 }
2619
2620 nResult = vkAllocateMemory( m_pDevice, &memoryAllocateInfo, nullptr, &framebufferDesc.m_pDeviceMemory );
2621 if ( nResult != VK_SUCCESS )
2622 {
2623 dprintf( "Failed to find memory for image.\n" );
2624 return false;
2625 }
2626
2627 nResult = vkBindImageMemory( m_pDevice, framebufferDesc.m_pImage, framebufferDesc.m_pDeviceMemory, 0 );
2628 if ( nResult != VK_SUCCESS )
2629 {
2630 dprintf( "Failed to bind memory for image.\n" );
2631 return false;
2632 }
2633
2634 VkImageViewCreateInfo imageViewCreateInfo = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO };
2635 imageViewCreateInfo.flags = 0;
2636 imageViewCreateInfo.image = framebufferDesc.m_pImage;
2637 imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
2638 imageViewCreateInfo.format = imageCreateInfo.format;
2639 imageViewCreateInfo.components = { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY };
2640 imageViewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2641 imageViewCreateInfo.subresourceRange.baseMipLevel = 0;

Callers

nothing calls this directly

Calls 2

MemoryTypeFromPropertiesFunction · 0.85
dprintfFunction · 0.70

Tested by

no test coverage detected