Skip to content

Commit

Permalink
Fix wrong usage of 'structureChains' in generating functions returnin…
Browse files Browse the repository at this point in the history
…g a StructureChain and a vector of data. (#1594)
  • Loading branch information
asuessenbach authored Jun 19, 2023
1 parent babfbdd commit c55cf16
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 37 deletions.
41 changes: 20 additions & 21 deletions VulkanHppGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2234,22 +2234,7 @@ std::string VulkanHppGenerator::generateArgumentListEnhanced( std::vector<ParamD
}
if ( withAllocators )
{
bool useStructureChainAllocator = false;
if ( flavourFlags & CommandFlavourFlagBits::chained )
{
// use StructureChainAllocator only, if a vector param is a chained return param
auto it = std::find_if(
chainedReturnParams.begin(), chainedReturnParams.end(), [&vectorParams]( size_t crp ) { return vectorParams.find( crp ) != vectorParams.end(); } );
if ( it != chainedReturnParams.end() )
{
// assert that there's no other chained vector param !
assert( std::find_if( std::next( it ),
chainedReturnParams.end(),
[&vectorParams]( size_t crp ) { return vectorParams.find( crp ) != vectorParams.end(); } ) == chainedReturnParams.end() );
useStructureChainAllocator = true;
}
}
if ( useStructureChainAllocator )
if ( ( flavourFlags & CommandFlavourFlagBits::chained ) && needsStructureChainResize( vectorParams, chainedReturnParams ) )
{
if ( encounteredArgument )
{
Expand Down Expand Up @@ -2928,6 +2913,7 @@ std::string VulkanHppGenerator::generateCallSequence( std::string const &
size_t initialSkipCount,
std::set<size_t> const & singularParams,
std::set<size_t> const & templatedParams,
std::vector<size_t> const & chainedReturnParams,
CommandFlavourFlags flavourFlags,
bool raii ) const
{
Expand All @@ -2951,7 +2937,7 @@ std::string VulkanHppGenerator::generateCallSequence( std::string const &
std::string vectorName = startLowerCase( stripPrefix( commandData.params[vectorParamIt->first].name, "p" ) );
std::string vectorSize = startLowerCase( stripPrefix( commandData.params[vectorParamIt->second.lenParam].name, "p" ) );

if ( flavourFlags & CommandFlavourFlagBits::chained )
if ( ( flavourFlags & CommandFlavourFlagBits::chained ) && needsStructureChainResize( vectorParams, chainedReturnParams ) )
{
assert( vectorParams.size() == 1 );
// chained data needs some more handling!!
Expand Down Expand Up @@ -3282,8 +3268,8 @@ std::string VulkanHppGenerator::generateCommandEnhanced( std::string const &
std::string dataPreparation =
generateDataPreparation( commandData, initialSkipCount, returnParams, vectorParams, templatedParams, flavourFlags, enumerating );
std::string dataSizeChecks = generateDataSizeChecks( commandData, returnParams, dataTypes, vectorParams, templatedParams, singular );
std::string callSequence =
generateCallSequence( name, commandData, returnParams, vectorParams, initialSkipCount, singularParams, templatedParams, flavourFlags, false );
std::string callSequence = generateCallSequence(
name, commandData, returnParams, vectorParams, initialSkipCount, singularParams, templatedParams, chainedReturnParams, flavourFlags, false );
std::string resultCheck = generateResultCheck( commandData, className, classSeparator, commandName, enumerating );
std::string returnStatement = generateReturnStatement( name,
commandData,
Expand Down Expand Up @@ -7391,8 +7377,8 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandEnhanced( std::string c
}
)";

std::string callSequence =
generateCallSequence( name, commandData, returnParams, vectorParams, initialSkipCount, singularParams, templatedParams, flavourFlags, true );
std::string callSequence = generateCallSequence(
name, commandData, returnParams, vectorParams, initialSkipCount, singularParams, templatedParams, chainedReturnParams, flavourFlags, true );
std::string className = initialSkipCount ? stripPrefix( commandData.params[initialSkipCount - 1].type.type, "Vk" ) : "Context";
std::string returnVariable = generateReturnVariable( commandData, returnParams, vectorParams, flavourFlags );
std::string dataDeclarations =
Expand Down Expand Up @@ -11445,6 +11431,19 @@ bool VulkanHppGenerator::isTypeUsed( std::string const & type ) const
return false;
}

bool VulkanHppGenerator::needsStructureChainResize( std::map<size_t, VectorParamData> const & vectorParams,
std::vector<size_t> const & chainedReturnParams ) const
{
auto it = std::find_if(
chainedReturnParams.begin(), chainedReturnParams.end(), [&vectorParams]( size_t crp ) { return vectorParams.find( crp ) != vectorParams.end(); } );
// assert that there's no other chained vector param !
assert(
( it == chainedReturnParams.end() ) ||
( std::find_if( std::next( it ), chainedReturnParams.end(), [&vectorParams]( size_t crp ) { return vectorParams.find( crp ) != vectorParams.end(); } ) ==
chainedReturnParams.end() ) );
return ( it != chainedReturnParams.end() );
}

std::pair<bool, std::map<size_t, std::vector<size_t>>> VulkanHppGenerator::needsVectorSizeCheck( std::vector<ParamData> const & params,
std::map<size_t, VectorParamData> const & vectorParams,
std::vector<size_t> const & returnParams,
Expand Down
2 changes: 2 additions & 0 deletions VulkanHppGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ class VulkanHppGenerator
size_t initialSkipCount,
std::set<size_t> const & singularParams,
std::set<size_t> const & templatedParams,
std::vector<size_t> const & chainedReturnParams,
CommandFlavourFlags flavourFlags,
bool raii ) const;
std::string generateChainTemplates( std::vector<size_t> const & returnParams, bool chained ) const;
Expand Down Expand Up @@ -936,6 +937,7 @@ class VulkanHppGenerator
bool isSupportedFeature( std::string const & name ) const;
bool isTypeRequired( std::string const & type ) const;
bool isTypeUsed( std::string const & type ) const;
bool needsStructureChainResize( std::map<size_t, VectorParamData> const & vectorParams, std::vector<size_t> const & chainedReturnParams ) const;
std::pair<bool, std::map<size_t, std::vector<size_t>>> needsVectorSizeCheck( std::vector<ParamData> const & params,
std::map<size_t, VectorParamData> const & vectorParams,
std::vector<size_t> const & returnParams,
Expand Down
8 changes: 7 additions & 1 deletion tests/EnableBetaExtensions/EnableBetaExtensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
#define VK_ENABLE_BETA_EXTENSIONS
#include <vulkan/vulkan.hpp>

int main(int /*argc*/, char** /*argv*/)
int main( int /*argc*/, char ** /*argv*/ )
{
vk::Device device;

vk::VideoEncodeSessionParametersGetInfoKHR videoSessionParametersInfo;
auto stuff = device.getEncodedVideoSessionParametersKHR<vk::VideoEncodeSessionParametersFeedbackInfoKHR,
vk::VideoEncodeH264SessionParametersFeedbackInfoEXT,
vk::VideoEncodeH265SessionParametersFeedbackInfoEXT>( videoSessionParametersInfo );
return 0;
}
10 changes: 0 additions & 10 deletions vulkan/vulkan_funcs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18660,12 +18660,7 @@ namespace VULKAN_HPP_NAMESPACE
nullptr );
if ( ( result == VK_SUCCESS ) && dataSize )
{
structureChains.resize( dataSize );
data.resize( dataSize );
for ( size_t i = 0; i < dataSize; i++ )
{
data[i].pNext = structureChains[i].template get<void>().pNext;
}
result = d.vkGetEncodedVideoSessionParametersKHR( m_device,
reinterpret_cast<const VkVideoEncodeSessionParametersGetInfoKHR *>( &videoSessionParametersInfo ),
reinterpret_cast<VkVideoEncodeSessionParametersFeedbackInfoKHR *>( &feedbackInfo ),
Expand Down Expand Up @@ -18709,12 +18704,7 @@ namespace VULKAN_HPP_NAMESPACE
nullptr );
if ( ( result == VK_SUCCESS ) && dataSize )
{
structureChains.resize( dataSize );
data.resize( dataSize );
for ( size_t i = 0; i < dataSize; i++ )
{
data[i].pNext = structureChains[i].template get<void>().pNext;
}
result = d.vkGetEncodedVideoSessionParametersKHR( m_device,
reinterpret_cast<const VkVideoEncodeSessionParametersGetInfoKHR *>( &videoSessionParametersInfo ),
reinterpret_cast<VkVideoEncodeSessionParametersFeedbackInfoKHR *>( &feedbackInfo ),
Expand Down
5 changes: 0 additions & 5 deletions vulkan/vulkan_raii.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18567,12 +18567,7 @@ namespace VULKAN_HPP_NAMESPACE
nullptr );
if ( ( result == VK_SUCCESS ) && dataSize )
{
structureChains.resize( dataSize );
data.resize( dataSize );
for ( size_t i = 0; i < dataSize; i++ )
{
data[i].pNext = structureChains[i].template get<void>().pNext;
}
result = getDispatcher()->vkGetEncodedVideoSessionParametersKHR(
static_cast<VkDevice>( m_device ),
reinterpret_cast<const VkVideoEncodeSessionParametersGetInfoKHR *>( &videoSessionParametersInfo ),
Expand Down

0 comments on commit c55cf16

Please sign in to comment.