Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce implicit cast operators for vk::UniqueHandles, vk::SharedHandles and vk::raii::Handles #1771

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RAII_Samples/04_InitCommandBuffer/04_InitCommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::CommandPool commandPool( device, commandPoolCreateInfo );

// allocate a CommandBuffer from the CommandPool
vk::CommandBufferAllocateInfo commandBufferAllocateInfo( *commandPool, vk::CommandBufferLevel::ePrimary, 1 );
vk::CommandBufferAllocateInfo commandBufferAllocateInfo( commandPool, vk::CommandBufferLevel::ePrimary, 1 );
vk::raii::CommandBuffer commandBuffer = std::move( vk::raii::CommandBuffers( device, commandBufferAllocateInfo ).front() );

/* VULKAN_HPP_KEY_END */
Expand Down
12 changes: 6 additions & 6 deletions RAII_Samples/05_InitSwapchain/05_InitSwapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int main( int /*argc*/, char ** /*argv*/ )

// determine a queueFamilyIndex that suports present
// first check if the graphicsQueueFamiliyIndex is good enough
uint32_t presentQueueFamilyIndex = physicalDevice.getSurfaceSupportKHR( graphicsQueueFamilyIndex, *surface )
uint32_t presentQueueFamilyIndex = physicalDevice.getSurfaceSupportKHR( graphicsQueueFamilyIndex, surface )
? graphicsQueueFamilyIndex
: vk::su::checked_cast<uint32_t>( queueFamilyProperties.size() );
if ( presentQueueFamilyIndex == queueFamilyProperties.size() )
Expand All @@ -57,7 +57,7 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( size_t i = 0; i < queueFamilyProperties.size(); i++ )
{
if ( ( queueFamilyProperties[i].queueFlags & vk::QueueFlagBits::eGraphics ) &&
physicalDevice.getSurfaceSupportKHR( vk::su::checked_cast<uint32_t>( i ), *surface ) )
physicalDevice.getSurfaceSupportKHR( vk::su::checked_cast<uint32_t>( i ), surface ) )
{
graphicsQueueFamilyIndex = vk::su::checked_cast<uint32_t>( i );
presentQueueFamilyIndex = graphicsQueueFamilyIndex;
Expand All @@ -70,7 +70,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// family index that supports present
for ( size_t i = 0; i < queueFamilyProperties.size(); i++ )
{
if ( physicalDevice.getSurfaceSupportKHR( vk::su::checked_cast<uint32_t>( i ), *surface ) )
if ( physicalDevice.getSurfaceSupportKHR( vk::su::checked_cast<uint32_t>( i ), surface ) )
{
presentQueueFamilyIndex = vk::su::checked_cast<uint32_t>( i );
break;
Expand All @@ -87,11 +87,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsQueueFamilyIndex, vk::su::getDeviceExtensions() );

// get the supported VkFormats
std::vector<vk::SurfaceFormatKHR> formats = physicalDevice.getSurfaceFormatsKHR( *surface );
std::vector<vk::SurfaceFormatKHR> formats = physicalDevice.getSurfaceFormatsKHR( surface );
assert( !formats.empty() );
vk::Format format = ( formats[0].format == vk::Format::eUndefined ) ? vk::Format::eB8G8R8A8Unorm : formats[0].format;

vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( *surface );
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( surface );
vk::Extent2D swapchainExtent;
if ( surfaceCapabilities.currentExtent.width == std::numeric_limits<uint32_t>::max() )
{
Expand Down Expand Up @@ -119,7 +119,7 @@ int main( int /*argc*/, char ** /*argv*/ )
: vk::CompositeAlphaFlagBitsKHR::eOpaque;

vk::SwapchainCreateInfoKHR swapChainCreateInfo( vk::SwapchainCreateFlagsKHR(),
*surface,
surface,
vk::su::clamp( 3u, surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount ),
format,
vk::ColorSpaceKHR::eSrgbNonlinear,
Expand Down
4 changes: 2 additions & 2 deletions RAII_Samples/06_InitDepthBuffer/06_InitDepthBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ int main( int /*argc*/, char ** /*argv*/ )

vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, typeIndex );
vk::raii::DeviceMemory depthMemory( device, memoryAllocateInfo );
depthImage.bindMemory( *depthMemory, 0 );
depthImage.bindMemory( depthMemory, 0 );

vk::ImageViewCreateInfo imageViewCreateInfo( {}, *depthImage, vk::ImageViewType::e2D, depthFormat, {}, { vk::ImageAspectFlagBits::eDepth, 0, 1, 0, 1 } );
vk::ImageViewCreateInfo imageViewCreateInfo( {}, depthImage, vk::ImageViewType::e2D, depthFormat, {}, { vk::ImageAspectFlagBits::eDepth, 0, 1, 0, 1 } );
vk::raii::ImageView depthView( device, imageViewCreateInfo );

// while all vk::raii objects are automatically destroyed on scope leave, the Image should to be destroyed before the bound DeviceMemory
Expand Down
2 changes: 1 addition & 1 deletion RAII_Samples/07_InitUniformBuffer/07_InitUniformBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int main( int /*argc*/, char ** /*argv*/ )
memcpy( pData, &mvpc, sizeof( mvpc ) );
uniformDataMemory.unmapMemory();

uniformDataBuffer.bindMemory( *uniformDataMemory, 0 );
uniformDataBuffer.bindMemory( uniformDataMemory, 0 );

// while all vk::raii objects are automatically destroyed on scope leave, the Buffer should to be destroyed before the bound DeviceMemory
// but the standard destruction order would destroy the DeviceMemory before the Buffer, so destroy the Buffer here
Expand Down
6 changes: 3 additions & 3 deletions RAII_Samples/09_InitDescriptorSet/09_InitDescriptorSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::DescriptorPool descriptorPool( device, descriptorPoolCreateInfo );

// allocate a descriptor set
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout );
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( descriptorPool, *descriptorSetLayout );
vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, descriptorSetAllocateInfo ).front() );

vk::DescriptorBufferInfo descriptorBufferInfo( *uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::WriteDescriptorSet writeDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, descriptorBufferInfo );
vk::DescriptorBufferInfo descriptorBufferInfo( uniformBufferData.buffer, 0, sizeof( glm::mat4x4 ) );
vk::WriteDescriptorSet writeDescriptorSet( descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, descriptorBufferInfo );
device.updateDescriptorSets( writeDescriptorSet, nullptr );

/* VULKAN_HPP_KEY_END */
Expand Down
2 changes: 1 addition & 1 deletion RAII_Samples/10_InitRenderPass/10_InitRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );

vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format;
vk::Format depthFormat = vk::Format::eD16Unorm;

/* VULKAN_HPP_KEY_START */
Expand Down
6 changes: 3 additions & 3 deletions RAII_Samples/12_InitFrameBuffers/12_InitFrameBuffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_START */

std::array<vk::ImageView, 2> attachments;
attachments[1] = *depthBufferData.imageView;
attachments[1] = depthBufferData.imageView;

std::vector<vk::raii::Framebuffer> framebuffers;
framebuffers.reserve( swapChainData.imageViews.size() );
for ( auto const & view : swapChainData.imageViews )
{
attachments[0] = *view;
vk::FramebufferCreateInfo framebufferCreateInfo( {}, *renderPass, attachments, surfaceData.extent.width, surfaceData.extent.height, 1 );
attachments[0] = view;
vk::FramebufferCreateInfo framebufferCreateInfo( {}, renderPass, attachments, surfaceData.extent.width, surfaceData.extent.height, 1 );
framebuffers.push_back( vk::raii::Framebuffer( device, framebufferCreateInfo ) );
}

Expand Down
8 changes: 4 additions & 4 deletions RAII_Samples/13_InitVertexBuffer/13_InitVertexBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ int main( int /*argc*/, char ** /*argv*/ )
deviceMemory.unmapMemory();

// and bind the device memory to the vertex buffer
vertexBuffer.bindMemory( *deviceMemory, 0 );
vertexBuffer.bindMemory( deviceMemory, 0 );

vk::raii::Semaphore imageAcquiredSemaphore( device, vk::SemaphoreCreateInfo() );

vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );

Expand All @@ -110,10 +110,10 @@ int main( int /*argc*/, char ** /*argv*/ )

commandBuffer.begin( {} );

vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass, framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );

commandBuffer.bindVertexBuffers( 0, { *vertexBuffer }, { 0 } );
commandBuffer.bindVertexBuffers( 0, { vertexBuffer }, { 0 } );

commandBuffer.endRenderPass();
commandBuffer.end();
Expand Down
10 changes: 5 additions & 5 deletions RAII_Samples/14_InitPipeline/14_InitPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );

vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, vk::Format::eD16Unorm );

vk::raii::DescriptorSetLayout descriptorSetLayout =
Expand All @@ -68,8 +68,8 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_START */

std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = {
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eVertex, *vertexShaderModule, "main" ),
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eFragment, *fragmentShaderModule, "main" )
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eVertex, vertexShaderModule, "main" ),
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eFragment, fragmentShaderModule, "main" )
};

vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( coloredCubeData[0] ) );
Expand Down Expand Up @@ -147,8 +147,8 @@ int main( int /*argc*/, char ** /*argv*/ )
&pipelineDepthStencilStateCreateInfo, // pDepthStencilState
&pipelineColorBlendStateCreateInfo, // pColorBlendState
&pipelineDynamicStateCreateInfo, // pDynamicState
*pipelineLayout, // layout
*renderPass // renderPass
pipelineLayout, // layout
renderPass // renderPass
);

vk::raii::Pipeline pipeline( device, nullptr, graphicsPipelineCreateInfo );
Expand Down
16 changes: 8 additions & 8 deletions RAII_Samples/15_DrawCube/15_DrawCube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::makeDescriptorSetLayout( device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::raii::PipelineLayout pipelineLayout( device, { {}, *descriptorSetLayout } );

vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( *surfaceData.surface ) ).format;
vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format;
vk::raii::RenderPass renderPass = vk::raii::su::makeRenderPass( device, colorFormat, depthBufferData.format );

glslang::InitializeProcess();
Expand All @@ -94,7 +94,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::raii::su::copyToDevice( vertexBufferData.deviceMemory, coloredCubeData, sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );

vk::raii::DescriptorPool descriptorPool = vk::raii::su::makeDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, { *descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::DescriptorSet descriptorSet = std::move( vk::raii::DescriptorSets( device, { descriptorPool, *descriptorSetLayout } ).front() );
vk::raii::su::updateDescriptorSets(
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, VK_WHOLE_SIZE, nullptr } }, {} );

Expand All @@ -120,7 +120,7 @@ int main( int /*argc*/, char ** /*argv*/ )

vk::Result result;
uint32_t imageIndex;
std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, *imageAcquiredSemaphore );
std::tie( result, imageIndex ) = swapChainData.swapChain.acquireNextImage( vk::su::FenceTimeout, imageAcquiredSemaphore );
assert( result == vk::Result::eSuccess );
assert( imageIndex < swapChainData.images.size() );

Expand All @@ -129,12 +129,12 @@ int main( int /*argc*/, char ** /*argv*/ )
std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( 0.2f, 0.2f, 0.2f, 0.2f );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( *renderPass, *framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass, framebuffers[imageIndex], vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), clearValues );
commandBuffer.beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { *descriptorSet }, nullptr );
commandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline );
commandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, { descriptorSet }, nullptr );

commandBuffer.bindVertexBuffers( 0, { *vertexBufferData.buffer }, { 0 } );
commandBuffer.bindVertexBuffers( 0, { vertexBufferData.buffer }, { 0 } );
commandBuffer.setViewport(
0, vk::Viewport( 0.0f, 0.0f, static_cast<float>( surfaceData.extent.width ), static_cast<float>( surfaceData.extent.height ), 0.0f, 1.0f ) );
commandBuffer.setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ) );
Expand All @@ -149,7 +149,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, *drawFence );

while ( vk::Result::eTimeout == device.waitForFences( { *drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
while ( vk::Result::eTimeout == device.waitForFences( { drawFence }, VK_TRUE, vk::su::FenceTimeout ) )
;

vk::PresentInfoKHR presentInfoKHR( nullptr, *swapChainData.swapChain, imageIndex );
Expand Down
Loading
Loading