mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Introduce usage of [[nodiscard]] with C++17
This commit is contained in:
parent
43df4dd0f1
commit
4cdc51ba0f
@ -346,6 +346,10 @@ Finally, the last code example is using exceptions and return value transformati
|
||||
|
||||
Keep in mind that Vulkan-Hpp does not support RAII style handles and that you have to cleanup your resources in the error handler!
|
||||
|
||||
### C++17: [[nodiscard]]
|
||||
|
||||
With C++17 and above, some functions are attributed with [[nodiscard]], resulting in a warning if you don't use the return value in any way. You can switch those warnings off by defining VULKAN_HPP_NO_NODISCARD_WARNINGS.
|
||||
|
||||
### Enumerations
|
||||
|
||||
For the return value transformation, there's one special class of return values which require special handling: Enumerations. For enumerations you usually have to write code like this:
|
||||
|
@ -1983,7 +1983,21 @@ void VulkanHppGenerator::appendFunction( std::string & str,
|
||||
!definition,
|
||||
isStructureChain );
|
||||
|
||||
str += indentation + ( definition ? "VULKAN_HPP_INLINE " : "" );
|
||||
str += indentation;
|
||||
|
||||
if ( ( 1 < commandData.successCodes.size() ) || ( !enhanced && ( 1 < commandData.errorCodes.size() ) ) )
|
||||
{
|
||||
str += "VULKAN_HPP_NODISCARD ";
|
||||
}
|
||||
else if ( enhanced && ( 1 < commandData.errorCodes.size() ) )
|
||||
{
|
||||
str += "VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS ";
|
||||
}
|
||||
|
||||
if ( definition )
|
||||
{
|
||||
str += "VULKAN_HPP_INLINE ";
|
||||
}
|
||||
|
||||
appendFunctionHeaderReturnType( str,
|
||||
commandData,
|
||||
@ -8404,6 +8418,18 @@ int main( int argc, char ** argv )
|
||||
# define VULKAN_HPP_DEPRECATED( msg )
|
||||
#endif
|
||||
|
||||
#if ( 17 <= VULKAN_HPP_CPP_VERSION ) && !defined( VULKAN_HPP_NO_NODISCARD_WARNINGS )
|
||||
# define VULKAN_HPP_NODISCARD [[nodiscard]]
|
||||
# if defined(VULKAN_HPP_NO_EXCEPTIONS)
|
||||
# define VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS [[nodiscard]]
|
||||
# else
|
||||
# define VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS
|
||||
# endif
|
||||
#else
|
||||
# define VULKAN_HPP_NODISCARD
|
||||
# define VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS
|
||||
#endif
|
||||
|
||||
#if !defined(VULKAN_HPP_NAMESPACE)
|
||||
#define VULKAN_HPP_NAMESPACE vk
|
||||
#endif
|
||||
|
@ -166,7 +166,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -230,7 +230,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
;
|
||||
|
||||
/* Now present the image in the window */
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer, {} ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -173,7 +173,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -218,7 +218,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -184,7 +184,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
vk::su::submitAndWait( device, graphicsQueue, commandBuffer );
|
||||
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
device->waitIdle();
|
||||
|
@ -238,10 +238,10 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
|
||||
vk::ResultValue<uint32_t> result = device->acquireNextImage2KHR(
|
||||
vk::ResultValue<uint32_t> nexImage = device->acquireNextImage2KHR(
|
||||
vk::AcquireNextImageInfoKHR( swapChainData.swapChain.get(), UINT64_MAX, imageAcquiredSemaphore.get(), {}, 1 ) );
|
||||
assert( result.result == vk::Result::eSuccess );
|
||||
uint32_t currentBuffer = result.value;
|
||||
assert( nexImage.result == vk::Result::eSuccess );
|
||||
uint32_t currentBuffer = nexImage.value;
|
||||
|
||||
vk::ClearValue clearValue;
|
||||
clearValue.color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
|
||||
@ -271,7 +271,13 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
vk::su::submitAndWait( device, graphicsQueue, commandBuffer );
|
||||
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer ) );
|
||||
vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
}
|
||||
catch ( vk::SystemError & err )
|
||||
|
@ -252,7 +252,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
device->waitIdle();
|
||||
|
@ -203,12 +203,18 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
graphicsQueue.waitIdle();
|
||||
|
||||
uint64_t samplesPassed[2];
|
||||
device->getQueryPoolResults( queryPool.get(),
|
||||
vk::Result result = device->getQueryPoolResults( queryPool.get(),
|
||||
0,
|
||||
2,
|
||||
vk::ArrayProxy<uint64_t>( 4, samplesPassed ),
|
||||
sizeof( uint64_t ),
|
||||
vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eNotReady: std::cout << "vk::Device::getQueryPoolResults returned vk::Result::eNotReady !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
|
||||
std::cout << "vkGetQueryPoolResults data\n";
|
||||
std::cout << "samples_passed[0] = " << samplesPassed[0] << "\n";
|
||||
@ -227,7 +233,13 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -347,7 +347,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
// Store away the cache that we've populated. This could conceivably happen
|
||||
|
@ -286,7 +286,14 @@ void main()
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
}
|
||||
catch ( vk::SystemError & err )
|
||||
|
@ -231,7 +231,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
}
|
||||
catch ( vk::SystemError & err )
|
||||
|
@ -209,7 +209,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -135,7 +135,7 @@ AccelerationStructureData
|
||||
for ( size_t i = 0; i < instances.size(); i++ )
|
||||
{
|
||||
uint64_t accelerationStructureHandle = 0;
|
||||
device->getAccelerationStructureHandleNV( instances[i].first, sizeof( uint64_t ), &accelerationStructureHandle );
|
||||
device->getAccelerationStructureHandleNV<uint64_t>( instances[i].first, accelerationStructureHandle );
|
||||
|
||||
// For each instance we set its instance index to its index i in the instance vector, and set
|
||||
// its hit group index to 2*i. The hit group index defines which entry of the shader binding
|
||||
@ -1280,8 +1280,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
1,
|
||||
&( *perFrameData[frameIndex].renderCompleteSemaphore ) ),
|
||||
*perFrameData[frameIndex].fence );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR(
|
||||
vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR(
|
||||
*perFrameData[frameIndex].renderCompleteSemaphore, *swapChainData.swapChain, backBufferIndex ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
frameIndex = ( frameIndex + 1 ) % IMGUI_VK_QUEUED_FRAMES;
|
||||
|
||||
double endTime = glfwGetTime();
|
||||
|
@ -229,7 +229,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -252,7 +252,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
device->waitIdle();
|
||||
|
@ -170,7 +170,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
device->waitIdle();
|
||||
|
@ -203,7 +203,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
vk::Result result =
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
switch ( result )
|
||||
{
|
||||
case vk::Result::eSuccess: break;
|
||||
case vk::Result::eSuboptimalKHR: std::cout << "vk::Queue::presentKHR returned vk::Result::eSuboptimalKHR !\n";
|
||||
default: assert( false ); // an unexpected result is returned !
|
||||
}
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
2473
vulkan/vulkan.hpp
2473
vulkan/vulkan.hpp
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user