mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Introduce usage of clang-format to format vulkan.hpp and the other sources.
This commit is contained in:
parent
ce9fd81bd9
commit
f5e59484a6
89
.clang-format
Normal file
89
.clang-format
Normal file
@ -0,0 +1,89 @@
|
||||
---
|
||||
AccessModifierOffset : -2
|
||||
AlignAfterOpenBracket : Align
|
||||
AlignConsecutiveAssignments : true
|
||||
AlignConsecutiveDeclarations : true
|
||||
AlignConsecutiveMacros : true
|
||||
AlignEscapedNewlines : Left
|
||||
AlignOperands : true
|
||||
AlignTrailingComments : true
|
||||
AllowAllArgumentsOnNextLine : true
|
||||
AllowAllConstructorInitializersOnNextLine : true
|
||||
AllowAllParametersOfDeclarationOnNextLine : true
|
||||
AllowShortBlocksOnASingleLine : Empty
|
||||
AllowShortCaseLabelsOnASingleLine : true
|
||||
AllowShortFunctionsOnASingleLine : Empty
|
||||
AllowShortIfStatementsOnASingleLine : Never
|
||||
AllowShortLambdasOnASingleLine : Inline
|
||||
AllowShortLoopsOnASingleLine : false
|
||||
AlwaysBreakAfterReturnType : None
|
||||
AlwaysBreakBeforeMultilineStrings : true
|
||||
AlwaysBreakTemplateDeclarations : Yes
|
||||
BinPackArguments : false
|
||||
BinPackParameters : false
|
||||
BraceWrapping :
|
||||
AfterCaseLabel : true
|
||||
AfterClass : true
|
||||
AfterControlStatement : Always
|
||||
AfterEnum : true
|
||||
AfterFunction : true
|
||||
AfterNamespace : true
|
||||
AfterStruct : true
|
||||
AfterUnion : true
|
||||
AfterExternBlock : true
|
||||
BeforeCatch : true
|
||||
BeforeElse : true
|
||||
# BeforeLambdaBody : true
|
||||
IndentBraces : false
|
||||
SplitEmptyFunction : false
|
||||
SplitEmptyRecord : false
|
||||
SplitEmptyNamespace : false
|
||||
BreakBeforeBinaryOperators : None
|
||||
BreakBeforeBraces : Custom
|
||||
BreakBeforeTernaryOperators : true
|
||||
BreakConstructorInitializers : BeforeColon
|
||||
BreakInheritanceList : BeforeComma
|
||||
BreakStringLiterals : false
|
||||
ColumnLimit : 120
|
||||
CompactNamespaces : false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine : true
|
||||
ConstructorInitializerIndentWidth : 2
|
||||
ContinuationIndentWidth : 2
|
||||
Cpp11BracedListStyle : false
|
||||
FixNamespaceComments : true
|
||||
IncludeBlocks : Regroup
|
||||
# IndentCaseBlocks : true
|
||||
IndentCaseLabels : true
|
||||
IndentPPDirectives : AfterHash
|
||||
IndentWidth : 2
|
||||
IndentWrappedFunctionNames : true
|
||||
KeepEmptyLinesAtTheStartOfBlocks : false
|
||||
MaxEmptyLinesToKeep : 1
|
||||
NamespaceIndentation : All
|
||||
PointerAlignment : Middle
|
||||
ReflowComments : true
|
||||
SortIncludes : true
|
||||
SortUsingDeclarations : true
|
||||
SpaceAfterCStyleCast : false
|
||||
SpaceAfterLogicalNot : false
|
||||
SpaceAfterTemplateKeyword : true
|
||||
SpaceBeforeAssignmentOperators : true
|
||||
SpaceBeforeCpp11BracedList : false
|
||||
SpaceBeforeCtorInitializerColon : true
|
||||
SpaceBeforeInheritanceColon : true
|
||||
SpaceBeforeParens : ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon : true
|
||||
SpaceBeforeSquareBrackets : false
|
||||
SpaceInEmptyBlock : false
|
||||
SpaceInEmptyParentheses : false
|
||||
SpacesBeforeTrailingComments : 2
|
||||
SpacesInAngles : false
|
||||
SpacesInCStyleCastParentheses : false
|
||||
# SpacesInConditionalStatement : true
|
||||
SpacesInContainerLiterals : true
|
||||
SpacesInParentheses : true
|
||||
SpacesInSquareBrackets : false
|
||||
Standard : Latest
|
||||
UseCRLF : true
|
||||
UseTab : Never
|
||||
...
|
@ -30,6 +30,14 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
project(VulkanHppGenerator)
|
||||
|
||||
find_program(CLANG_FORMAT_EXECUTABLE NAMES clang-format)
|
||||
|
||||
if(CLANG_FORMAT_EXECUTABLE)
|
||||
add_definitions(-DCLANG_FORMAT_EXECUTABLE="${CLANG_FORMAT_EXECUTABLE}")
|
||||
else()
|
||||
message(WARNGING " Could not find clang-format. Generated vulkan.hpp will not be nicely formatted.")
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
add_compile_options(/W4)
|
||||
else(MSVC)
|
||||
|
@ -17,6 +17,12 @@ Vulkan-Hpp requires a C++11 capable compiler to compile. The following compilers
|
||||
* GCC >= 4.8.2 (earlier version might work, but are untested)
|
||||
* Clang >= 3.3
|
||||
|
||||
### Optional Features
|
||||
|
||||
#### Formatting
|
||||
|
||||
If the program clang-format is found by CMake, the define CLANG_FORMAT_EXECUTABLE is set accordingly. In that case, the generated vulkan.hpp is formatted using the .clang-format file located in the root directory of this project. Otherwise it's formatted as hard-coded in the generator.
|
||||
|
||||
## Usage
|
||||
|
||||
### namespace vk
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -14,11 +14,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <tinyxml2.h>
|
||||
#include <vector>
|
||||
|
||||
class VulkanHppGenerator
|
||||
{
|
||||
@ -29,7 +29,8 @@ class VulkanHppGenerator
|
||||
void appendBitmasks( std::string & str ) const;
|
||||
void appendDispatchLoaderDynamic( std::string & str ); // use vkGet*ProcAddress to get function pointers
|
||||
void appendDispatchLoaderStatic( std::string & str ); // use exported symbols from loader
|
||||
void appendDispatchLoaderDefault(std::string & str); // typedef to DispatchLoaderStatic or undefined type, based on VK_NO_PROTOTYPES
|
||||
void appendDispatchLoaderDefault(
|
||||
std::string & str ); // typedef to DispatchLoaderStatic or undefined type, based on VK_NO_PROTOTYPES
|
||||
void appendEnums( std::string & str ) const;
|
||||
void appendForwardDeclarations( std::string & str ) const;
|
||||
void appendHandles( std::string & str ) const;
|
||||
@ -46,10 +47,7 @@ class VulkanHppGenerator
|
||||
private:
|
||||
struct BaseTypeData
|
||||
{
|
||||
BaseTypeData(std::string const& type_, int line)
|
||||
: type(type_)
|
||||
, xmlLine(line)
|
||||
{}
|
||||
BaseTypeData( std::string const & type_, int line ) : type( type_ ), xmlLine( line ) {}
|
||||
|
||||
std::string type;
|
||||
int xmlLine;
|
||||
@ -58,9 +56,7 @@ class VulkanHppGenerator
|
||||
struct BitmaskData
|
||||
{
|
||||
BitmaskData( std::string const & r, std::string const & t, int line )
|
||||
: requirements(r)
|
||||
, type(t)
|
||||
, xmlLine(line)
|
||||
: requirements( r ), type( t ), xmlLine( line )
|
||||
{}
|
||||
|
||||
std::string requirements;
|
||||
@ -93,10 +89,7 @@ class VulkanHppGenerator
|
||||
|
||||
struct ParamData
|
||||
{
|
||||
ParamData(int line)
|
||||
: optional(false)
|
||||
, xmlLine(line)
|
||||
{}
|
||||
ParamData( int line ) : optional( false ), xmlLine( line ) {}
|
||||
|
||||
TypeData type;
|
||||
std::string name;
|
||||
@ -108,9 +101,7 @@ class VulkanHppGenerator
|
||||
|
||||
struct CommandData
|
||||
{
|
||||
CommandData(int line)
|
||||
: xmlLine(line)
|
||||
{}
|
||||
CommandData( int line ) : xmlLine( line ) {}
|
||||
|
||||
std::vector<ParamData> params;
|
||||
std::string platform;
|
||||
@ -124,9 +115,7 @@ class VulkanHppGenerator
|
||||
struct EnumValueData
|
||||
{
|
||||
EnumValueData( std::string const & vulkan, std::string const & vk, bool singleBit_ )
|
||||
: vulkanValue(vulkan)
|
||||
, vkValue(vk)
|
||||
, singleBit(singleBit_)
|
||||
: vulkanValue( vulkan ), vkValue( vk ), singleBit( singleBit_ )
|
||||
{}
|
||||
|
||||
std::string vulkanValue;
|
||||
@ -136,10 +125,17 @@ class VulkanHppGenerator
|
||||
|
||||
struct EnumData
|
||||
{
|
||||
void addEnumValue(int line, std::string const& valueName, bool bitmask, bool bitpos, std::string const& prefix, std::string const& postfix, std::string const& tag);
|
||||
void addEnumValue( int line,
|
||||
std::string const & valueName,
|
||||
bool bitmask,
|
||||
bool bitpos,
|
||||
std::string const & prefix,
|
||||
std::string const & postfix,
|
||||
std::string const & tag );
|
||||
|
||||
std::string alias; // alias for this enum
|
||||
std::vector<std::pair<std::string, std::string>> aliases; // pairs of vulkan enum value and corresponding vk::-namespace enum value
|
||||
std::vector<std::pair<std::string, std::string>>
|
||||
aliases; // pairs of vulkan enum value and corresponding vk::-namespace enum value
|
||||
bool isBitmask = false;
|
||||
std::string platform;
|
||||
std::vector<EnumValueData> values;
|
||||
@ -147,9 +143,7 @@ class VulkanHppGenerator
|
||||
|
||||
struct ExtensionData
|
||||
{
|
||||
ExtensionData(int line)
|
||||
: xmlLine(line)
|
||||
{}
|
||||
ExtensionData( int line ) : xmlLine( line ) {}
|
||||
|
||||
std::string deprecatedBy;
|
||||
std::string obsoletedBy;
|
||||
@ -160,10 +154,7 @@ class VulkanHppGenerator
|
||||
|
||||
struct FuncPointerData
|
||||
{
|
||||
FuncPointerData(std::string const& r, int line)
|
||||
: requirements(r)
|
||||
, xmlLine(line)
|
||||
{}
|
||||
FuncPointerData( std::string const & r, int line ) : requirements( r ), xmlLine( line ) {}
|
||||
|
||||
std::string requirements;
|
||||
int xmlLine;
|
||||
@ -171,10 +162,7 @@ class VulkanHppGenerator
|
||||
|
||||
struct HandleData
|
||||
{
|
||||
HandleData(std::vector<std::string> const& p, int line)
|
||||
: parents(p)
|
||||
, xmlLine(line)
|
||||
{}
|
||||
HandleData( std::vector<std::string> const & p, int line ) : parents( p ), xmlLine( line ) {}
|
||||
|
||||
std::string alias;
|
||||
std::set<std::string> childrenHandles;
|
||||
@ -188,9 +176,7 @@ class VulkanHppGenerator
|
||||
|
||||
struct MemberData
|
||||
{
|
||||
MemberData(int line)
|
||||
: xmlLine(line)
|
||||
{}
|
||||
MemberData( int line ) : xmlLine( line ) {}
|
||||
|
||||
TypeData type;
|
||||
std::string name;
|
||||
@ -204,10 +190,7 @@ class VulkanHppGenerator
|
||||
struct StructureData
|
||||
{
|
||||
StructureData( std::vector<std::string> const & extends, int line )
|
||||
: returnedOnly(false)
|
||||
, isUnion(false)
|
||||
, structExtends(extends)
|
||||
, xmlLine(line)
|
||||
: returnedOnly( false ), isUnion( false ), structExtends( extends ), xmlLine( line )
|
||||
{}
|
||||
|
||||
bool returnedOnly;
|
||||
@ -236,62 +219,278 @@ class VulkanHppGenerator
|
||||
|
||||
private:
|
||||
void appendArgumentPlainType( std::string & str, ParamData const & paramData ) const;
|
||||
void appendArguments(std::string & str, CommandData const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, bool firstCall, bool singular, size_t from, size_t to) const;
|
||||
void appendArgumentVector(std::string & str, size_t paramIndex, ParamData const& paramData, size_t returnParamIndex, size_t templateParamIndex, bool twoStep, bool firstCall, bool singular) const;
|
||||
void appendArguments( std::string & str,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
size_t templateParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool twoStep,
|
||||
bool firstCall,
|
||||
bool singular,
|
||||
size_t from,
|
||||
size_t to ) const;
|
||||
void appendArgumentVector( std::string & str,
|
||||
size_t paramIndex,
|
||||
ParamData const & paramData,
|
||||
size_t returnParamIndex,
|
||||
size_t templateParamIndex,
|
||||
bool twoStep,
|
||||
bool firstCall,
|
||||
bool singular ) const;
|
||||
void appendArgumentVulkanType( std::string & str, ParamData const & paramData ) const;
|
||||
void appendBitmask(std::string & os, std::string const& bitmaskName, std::string const& bitmaskType, std::string const& bitmaskAlias, std::string const& enumName, std::vector<EnumValueData> const& enumValues) const;
|
||||
void appendBitmaskToStringFunction(std::string & str, std::string const& flagsName, std::string const& enumName, std::vector<EnumValueData> const& enumValues) const;
|
||||
void appendCall(std::string &str, std::string const& name, CommandData const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, bool firstCall, bool singular) const;
|
||||
void appendCommand(std::string & str, std::string const& indentation, std::string const& name, CommandData const& commandData, bool definition) const;
|
||||
void appendBitmask( std::string & os,
|
||||
std::string const & bitmaskName,
|
||||
std::string const & bitmaskType,
|
||||
std::string const & bitmaskAlias,
|
||||
std::string const & enumName,
|
||||
std::vector<EnumValueData> const & enumValues ) const;
|
||||
void appendBitmaskToStringFunction( std::string & str,
|
||||
std::string const & flagsName,
|
||||
std::string const & enumName,
|
||||
std::vector<EnumValueData> const & enumValues ) const;
|
||||
void appendCall( std::string & str,
|
||||
std::string const & name,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
size_t templateParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool twoStep,
|
||||
bool firstCall,
|
||||
bool singular ) const;
|
||||
void appendCommand( std::string & str,
|
||||
std::string const & indentation,
|
||||
std::string const & name,
|
||||
CommandData const & commandData,
|
||||
bool definition ) const;
|
||||
void appendEnum( std::string & str, std::pair<std::string, EnumData> const & enumData ) const;
|
||||
void appendEnumInitializer(std::string& str, TypeData const& type, std::vector<std::string> const& arraySizes, std::vector<EnumValueData> const& values, bool argument) const;
|
||||
void appendEnumInitializer( std::string & str,
|
||||
TypeData const & type,
|
||||
std::vector<std::string> const & arraySizes,
|
||||
std::vector<EnumValueData> const & values,
|
||||
bool argument ) const;
|
||||
void appendEnumToString( std::string & str, std::pair<std::string, EnumData> const & enumData ) const;
|
||||
void appendFunction(std::string & str, std::string const& indentation, std::string const& name, CommandData const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, std::string const& enhancedReturnType, bool definition, bool enhanced, bool singular, bool unique, bool isStructureChain, bool withAllocator) const;
|
||||
void appendFunctionBodyEnhanced(std::string & str, std::string const& indentation, std::string const& name, CommandData const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, std::string const& enhancedReturnType, bool singular, bool unique, bool isStructureChain, bool withAllocator) const;
|
||||
std::string appendFunctionBodyEnhancedLocalReturnVariable(std::string & str, std::string const& indentation, CommandData const& commandData, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, std::string const& enhancedReturnType, bool singular, bool isStructureChain, bool withAllocator) const;
|
||||
void appendFunctionBodyEnhancedLocalReturnVariableVectorSize(std::string & str, std::vector<ParamData> const& params, std::pair<size_t, size_t> const& vectorParamIndex, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool withAllocator) const;
|
||||
void appendFunctionBodyEnhancedMultiVectorSizeCheck(std::string & str, std::string const& indentation, std::string const& name, CommandData const& commandData, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices) const;
|
||||
void appendFunctionBodyEnhancedReturnResultValue(std::string & str, std::string const& indentation, std::string const& returnName, std::string const& name, CommandData const& commandData, size_t returnParamIndex, bool twoStep, bool singular, bool unique) const;
|
||||
void appendFunctionBodyEnhancedSingleStep(std::string & str, std::string const& indentation, std::string const& name, CommandData const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool singular) const;
|
||||
void appendFunctionBodyEnhancedTwoStep(std::string & str, std::string const& indentation, std::string const& name, CommandData const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool singular, std::string const& returnName) const;
|
||||
void appendFunctionBodyEnhancedVectorOfStructureChain(std::string & str, std::string const& indentation, std::string const& name, CommandData const& commandData, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool withAllocator) const;
|
||||
void appendFunctionBodyEnhancedVectorOfUniqueHandles(std::string & str, std::string const& indentation, std::string const& name, CommandData const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, bool singular, bool withAllocator) const;
|
||||
void appendFunctionBodyStandard(std::string & str, std::string const& indentation, std::string const& commandName, CommandData const& commandData) const;
|
||||
void appendFunctionBodyStandardArgument(std::string & str, TypeData const& typeData, std::string const& name, std::vector<std::string> const& arraySizes) const;
|
||||
bool appendFunctionHeaderArgumentEnhanced(std::string & str, ParamData const& param, size_t paramIndex, std::map<size_t, size_t> const& vectorParamIndices, bool skip, bool argEncountered, bool isTemplateParam, bool isLastArgument, bool singular, bool withDefaults, bool withAllocator) const;
|
||||
void appendFunctionHeaderArgumentEnhancedPointer(std::string & str, ParamData const& param, std::string const& strippedParameterName, bool withDefaults, bool withAllocator) const;
|
||||
void appendFunctionHeaderArgumentEnhancedSimple(std::string & str, ParamData const& param, bool lastArgument, bool withDefaults, bool withAllocator) const;
|
||||
void appendFunctionHeaderArgumentEnhancedVector(std::string & str, ParamData const& param, std::string const& strippedParameterName, bool hasSizeParam, bool isTemplateParam, bool singular, bool withDefaults, bool withAllocator) const;
|
||||
void appendFunctionHeaderArguments(std::string & str, std::string const& name, CommandData const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool enhanced, bool singular, bool withDefaults, bool withAllocator) const;
|
||||
void appendFunctionHeaderArgumentsEnhanced(std::string & str, std::string const& name, CommandData const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool singular, bool withDefaults, bool withAllocator) const;
|
||||
void appendFunctionHeaderArgumentsStandard(std::string & str, std::string const& name, CommandData const& commandData, bool withDefaults) const;
|
||||
bool appendFunctionHeaderArgumentStandard(std::string & str, ParamData const& param, bool argEncountered, bool isLastArgument, bool withDefaults) const;
|
||||
void appendFunctionHeaderReturnType(std::string & str, CommandData const& commandData, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices, std::string const& enhancedReturnType, bool enhanced, bool twoStep, bool singular, bool unique, bool isStructureChain) const;
|
||||
void appendFunctionHeaderTemplate(std::string & str, std::string const& indentation, size_t returnParamIndex, size_t templateParamIndex, std::string const& enhancedReturnType, bool enhanced, bool singular, bool unique, bool withDefault, bool isStructureChain) const;
|
||||
void appendHandle(std::string & str, std::pair<std::string, HandleData> const& handle, std::set<std::string> & listedHandles) const;
|
||||
void appendFunction( std::string & str,
|
||||
std::string const & indentation,
|
||||
std::string const & name,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
size_t templateParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool twoStep,
|
||||
std::string const & enhancedReturnType,
|
||||
bool definition,
|
||||
bool enhanced,
|
||||
bool singular,
|
||||
bool unique,
|
||||
bool isStructureChain,
|
||||
bool withAllocator ) const;
|
||||
void appendFunctionBodyEnhanced( std::string & str,
|
||||
std::string const & indentation,
|
||||
std::string const & name,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
size_t templateParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool twoStep,
|
||||
std::string const & enhancedReturnType,
|
||||
bool singular,
|
||||
bool unique,
|
||||
bool isStructureChain,
|
||||
bool withAllocator ) const;
|
||||
std::string appendFunctionBodyEnhancedLocalReturnVariable( std::string & str,
|
||||
std::string const & indentation,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool twoStep,
|
||||
std::string const & enhancedReturnType,
|
||||
bool singular,
|
||||
bool isStructureChain,
|
||||
bool withAllocator ) const;
|
||||
void appendFunctionBodyEnhancedLocalReturnVariableVectorSize( std::string & str,
|
||||
std::vector<ParamData> const & params,
|
||||
std::pair<size_t, size_t> const & vectorParamIndex,
|
||||
size_t returnParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool withAllocator ) const;
|
||||
void appendFunctionBodyEnhancedMultiVectorSizeCheck( std::string & str,
|
||||
std::string const & indentation,
|
||||
std::string const & name,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices ) const;
|
||||
void appendFunctionBodyEnhancedReturnResultValue( std::string & str,
|
||||
std::string const & indentation,
|
||||
std::string const & returnName,
|
||||
std::string const & name,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
bool twoStep,
|
||||
bool singular,
|
||||
bool unique ) const;
|
||||
void appendFunctionBodyEnhancedSingleStep( std::string & str,
|
||||
std::string const & indentation,
|
||||
std::string const & name,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
size_t templateParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool singular ) const;
|
||||
void appendFunctionBodyEnhancedTwoStep( std::string & str,
|
||||
std::string const & indentation,
|
||||
std::string const & name,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
size_t templateParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool singular,
|
||||
std::string const & returnName ) const;
|
||||
void appendFunctionBodyEnhancedVectorOfStructureChain( std::string & str,
|
||||
std::string const & indentation,
|
||||
std::string const & name,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool withAllocator ) const;
|
||||
void appendFunctionBodyEnhancedVectorOfUniqueHandles( std::string & str,
|
||||
std::string const & indentation,
|
||||
std::string const & name,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
size_t templateParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool twoStep,
|
||||
bool singular,
|
||||
bool withAllocator ) const;
|
||||
void appendFunctionBodyStandard( std::string & str,
|
||||
std::string const & indentation,
|
||||
std::string const & commandName,
|
||||
CommandData const & commandData ) const;
|
||||
void appendFunctionBodyStandardArgument( std::string & str,
|
||||
TypeData const & typeData,
|
||||
std::string const & name,
|
||||
std::vector<std::string> const & arraySizes ) const;
|
||||
bool appendFunctionHeaderArgumentEnhanced( std::string & str,
|
||||
ParamData const & param,
|
||||
size_t paramIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool skip,
|
||||
bool argEncountered,
|
||||
bool isTemplateParam,
|
||||
bool isLastArgument,
|
||||
bool singular,
|
||||
bool withDefaults,
|
||||
bool withAllocator ) const;
|
||||
void appendFunctionHeaderArgumentEnhancedPointer( std::string & str,
|
||||
ParamData const & param,
|
||||
std::string const & strippedParameterName,
|
||||
bool withDefaults,
|
||||
bool withAllocator ) const;
|
||||
void appendFunctionHeaderArgumentEnhancedSimple(
|
||||
std::string & str, ParamData const & param, bool lastArgument, bool withDefaults, bool withAllocator ) const;
|
||||
void appendFunctionHeaderArgumentEnhancedVector( std::string & str,
|
||||
ParamData const & param,
|
||||
std::string const & strippedParameterName,
|
||||
bool hasSizeParam,
|
||||
bool isTemplateParam,
|
||||
bool singular,
|
||||
bool withDefaults,
|
||||
bool withAllocator ) const;
|
||||
void appendFunctionHeaderArguments( std::string & str,
|
||||
std::string const & name,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
size_t templateParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool enhanced,
|
||||
bool singular,
|
||||
bool withDefaults,
|
||||
bool withAllocator ) const;
|
||||
void appendFunctionHeaderArgumentsEnhanced( std::string & str,
|
||||
std::string const & name,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
size_t templateParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool singular,
|
||||
bool withDefaults,
|
||||
bool withAllocator ) const;
|
||||
void appendFunctionHeaderArgumentsStandard( std::string & str,
|
||||
std::string const & name,
|
||||
CommandData const & commandData,
|
||||
bool withDefaults ) const;
|
||||
bool appendFunctionHeaderArgumentStandard(
|
||||
std::string & str, ParamData const & param, bool argEncountered, bool isLastArgument, bool withDefaults ) const;
|
||||
void appendFunctionHeaderReturnType( std::string & str,
|
||||
CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
std::string const & enhancedReturnType,
|
||||
bool enhanced,
|
||||
bool twoStep,
|
||||
bool singular,
|
||||
bool unique,
|
||||
bool isStructureChain ) const;
|
||||
void appendFunctionHeaderTemplate( std::string & str,
|
||||
std::string const & indentation,
|
||||
size_t returnParamIndex,
|
||||
size_t templateParamIndex,
|
||||
std::string const & enhancedReturnType,
|
||||
bool enhanced,
|
||||
bool singular,
|
||||
bool unique,
|
||||
bool withDefault,
|
||||
bool isStructureChain ) const;
|
||||
void appendHandle( std::string & str,
|
||||
std::pair<std::string, HandleData> const & handle,
|
||||
std::set<std::string> & listedHandles ) const;
|
||||
void appendPlatformEnter( std::string & str, bool isAliased, std::string const & platform ) const;
|
||||
void appendPlatformLeave( std::string & str, bool isAliased, std::string const & platform ) const;
|
||||
void appendStruct(std::string & str, std::pair<std::string, StructureData> const& structure, std::set<std::string> & listedStructures) const;
|
||||
void appendStructAssignmentOperator(std::string &str, std::pair<std::string, StructureData> const& structure, std::string const& prefix) const;
|
||||
void appendStruct( std::string & str,
|
||||
std::pair<std::string, StructureData> const & structure,
|
||||
std::set<std::string> & listedStructures ) const;
|
||||
void appendStructAssignmentOperator( std::string & str,
|
||||
std::pair<std::string, StructureData> const & structure,
|
||||
std::string const & prefix ) const;
|
||||
void appendStructCompareOperators( std::string & str, std::pair<std::string, StructureData> const & structure ) const;
|
||||
void appendStructConstructor(std::string &str, std::pair<std::string, StructureData> const& structData, std::string const& prefix) const;
|
||||
bool appendStructConstructorArgument(std::string & str, bool listedArgument, std::string const& indentation, MemberData const& memberData) const;
|
||||
void appendStructConstructor( std::string & str,
|
||||
std::pair<std::string, StructureData> const & structData,
|
||||
std::string const & prefix ) const;
|
||||
bool appendStructConstructorArgument( std::string & str,
|
||||
bool listedArgument,
|
||||
std::string const & indentation,
|
||||
MemberData const & memberData ) const;
|
||||
void appendStructCopyConstructors( std::string & str, std::string const & vkName ) const;
|
||||
void appendStructMembers(std::string & str, std::pair<std::string,StructureData> const& structData, std::string const& prefix) const;
|
||||
void appendStructSetter(std::string & str, std::string const& structureName, bool isUnion, MemberData const& memberData) const;
|
||||
void appendStructSubConstructor(std::string &str, std::pair<std::string, StructureData> const& structData, std::string const& prefix) const;
|
||||
void appendStructMembers( std::string & str,
|
||||
std::pair<std::string, StructureData> const & structData,
|
||||
std::string const & prefix ) const;
|
||||
void appendStructSetter( std::string & str,
|
||||
std::string const & structureName,
|
||||
bool isUnion,
|
||||
MemberData const & memberData ) const;
|
||||
void appendStructSubConstructor( std::string & str,
|
||||
std::pair<std::string, StructureData> const & structData,
|
||||
std::string const & prefix ) const;
|
||||
void appendStructure( std::string & str, std::pair<std::string, StructureData> const & structure ) const;
|
||||
void appendUnion( std::string & str, std::pair<std::string, StructureData> const & structure ) const;
|
||||
void appendUniqueTypes(std::string &str, std::string const& parentType, std::set<std::string> const& childrenTypes) const;
|
||||
void appendUniqueTypes( std::string & str,
|
||||
std::string const & parentType,
|
||||
std::set<std::string> const & childrenTypes ) const;
|
||||
std::string constructConstexprString( std::pair<std::string, StructureData> const & structData ) const;
|
||||
void checkCorrectness();
|
||||
bool checkLenAttribute( std::string const & len, std::vector<ParamData> const & params );
|
||||
bool containsArray( std::string const & type ) const;
|
||||
bool containsUnion( std::string const & type ) const;
|
||||
std::string determineEnhancedReturnType(CommandData const& commandData, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool isStructureChain) const;
|
||||
size_t determineReturnParamIndex(CommandData const& commandData, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep) const;
|
||||
std::string determineEnhancedReturnType( CommandData const & commandData,
|
||||
size_t returnParamIndex,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool isStructureChain ) const;
|
||||
size_t determineReturnParamIndex( CommandData const & commandData,
|
||||
std::map<size_t, size_t> const & vectorParamIndices,
|
||||
bool twoStep ) const;
|
||||
std::string determineSubStruct( std::pair<std::string, StructureData> const & structure ) const;
|
||||
size_t determineTemplateParamIndex(std::vector<ParamData> const& params, std::map<size_t, size_t> const& vectorParamIndices) const;
|
||||
size_t determineTemplateParamIndex( std::vector<ParamData> const & params,
|
||||
std::map<size_t, size_t> const & vectorParamIndices ) const;
|
||||
std::map<size_t, size_t> determineVectorParamIndices( std::vector<ParamData> const & params ) const;
|
||||
bool holdsSType( std::string const & type ) const;
|
||||
bool isTwoStepAlgorithm( std::vector<ParamData> const & params ) const;
|
||||
@ -307,9 +506,23 @@ class VulkanHppGenerator
|
||||
void readCommands( tinyxml2::XMLElement const * element );
|
||||
std::string readComment( tinyxml2::XMLElement const * element );
|
||||
void readDefine( tinyxml2::XMLElement const * element, std::map<std::string, std::string> const & attributes );
|
||||
void readEnum(tinyxml2::XMLElement const* element, EnumData & enumData, bool bitmask, std::string const& prefix, std::string const& postfix);
|
||||
void readEnum(tinyxml2::XMLElement const* element, std::map<std::string, std::string> const& attributes, EnumData & enumData, bool bitmask, std::string const& prefix, std::string const& postfix);
|
||||
void readEnumAlias(tinyxml2::XMLElement const* element, std::map<std::string, std::string> const& attributes, EnumData & enumData, bool bitmask, std::string const& prefix, std::string const& postfix);
|
||||
void readEnum( tinyxml2::XMLElement const * element,
|
||||
EnumData & enumData,
|
||||
bool bitmask,
|
||||
std::string const & prefix,
|
||||
std::string const & postfix );
|
||||
void readEnum( tinyxml2::XMLElement const * element,
|
||||
std::map<std::string, std::string> const & attributes,
|
||||
EnumData & enumData,
|
||||
bool bitmask,
|
||||
std::string const & prefix,
|
||||
std::string const & postfix );
|
||||
void readEnumAlias( tinyxml2::XMLElement const * element,
|
||||
std::map<std::string, std::string> const & attributes,
|
||||
EnumData & enumData,
|
||||
bool bitmask,
|
||||
std::string const & prefix,
|
||||
std::string const & postfix );
|
||||
void readEnumConstant( tinyxml2::XMLElement const * element );
|
||||
void readEnums( tinyxml2::XMLElement const * element );
|
||||
void readExtension( tinyxml2::XMLElement const * element );
|
||||
@ -317,7 +530,10 @@ class VulkanHppGenerator
|
||||
void readExtensionDisabledEnum( std::string const & extensionName, tinyxml2::XMLElement const * element );
|
||||
void readExtensionDisabledRequire( std::string const & extensionName, tinyxml2::XMLElement const * element );
|
||||
void readExtensionDisabledType( tinyxml2::XMLElement const * element );
|
||||
void readExtensionRequire(tinyxml2::XMLElement const* element, std::string const& platform, std::string const& tag, std::map<std::string, int> & requirements);
|
||||
void readExtensionRequire( tinyxml2::XMLElement const * element,
|
||||
std::string const & platform,
|
||||
std::string const & tag,
|
||||
std::map<std::string, int> & requirements );
|
||||
void readExtensionRequireCommand( tinyxml2::XMLElement const * element, std::string const & platform );
|
||||
void readExtensionRequireType( tinyxml2::XMLElement const * element, std::string const & platform );
|
||||
void readExtensions( tinyxml2::XMLElement const * element );
|
||||
@ -331,15 +547,23 @@ class VulkanHppGenerator
|
||||
void readRegistry( tinyxml2::XMLElement const * element );
|
||||
void readRequireCommand( tinyxml2::XMLElement const * element );
|
||||
void readRequireEnum( tinyxml2::XMLElement const * element, std::string const & tag );
|
||||
void readRequireEnum(tinyxml2::XMLElement const* element, std::map<std::string, std::string> const& attributes, std::string const& tag);
|
||||
void readRequireEnumAlias(tinyxml2::XMLElement const* element, std::map<std::string, std::string> const& attributes, std::string const& tag);
|
||||
void readRequireEnum( tinyxml2::XMLElement const * element,
|
||||
std::map<std::string, std::string> const & attributes,
|
||||
std::string const & tag );
|
||||
void readRequireEnumAlias( tinyxml2::XMLElement const * element,
|
||||
std::map<std::string, std::string> const & attributes,
|
||||
std::string const & tag );
|
||||
void readRequires( tinyxml2::XMLElement const * element, std::map<std::string, std::string> const & attributes );
|
||||
void readRequireType( tinyxml2::XMLElement const * element );
|
||||
void readStruct(tinyxml2::XMLElement const* element, bool isUnion, std::map<std::string, std::string> const& attributes);
|
||||
void readStruct( tinyxml2::XMLElement const * element,
|
||||
bool isUnion,
|
||||
std::map<std::string, std::string> const & attributes );
|
||||
void readStructAlias( tinyxml2::XMLElement const * element, std::map<std::string, std::string> const & attributes );
|
||||
void readStructMember( tinyxml2::XMLElement const * element, std::vector<MemberData> & members );
|
||||
void readStructMemberEnum( tinyxml2::XMLElement const * element, MemberData & memberData );
|
||||
void readStructMemberName(tinyxml2::XMLElement const* element, MemberData & memberData, std::vector<MemberData> const& members);
|
||||
void readStructMemberName( tinyxml2::XMLElement const * element,
|
||||
MemberData & memberData,
|
||||
std::vector<MemberData> const & members );
|
||||
void readStructMemberType( tinyxml2::XMLElement const * element, MemberData & memberData );
|
||||
void readTag( tinyxml2::XMLElement const * element );
|
||||
void readTags( tinyxml2::XMLElement const * element );
|
||||
|
@ -16,6 +16,7 @@
|
||||
// Create and destroy a vk::UniqueInstance
|
||||
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "01_InitInstance";
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "02_EnumerateDevices";
|
||||
@ -36,8 +37,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
// enumerate the physicalDevices
|
||||
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
|
||||
|
||||
// Note: PhysicalDevices are not created, but just enumerated. Therefore, there is nothing like a UniquePhysicalDevice.
|
||||
// A PhysicalDevice is unique by definition, and there's no need to destroy it.
|
||||
// Note: PhysicalDevices are not created, but just enumerated. Therefore, there is nothing like a
|
||||
// UniquePhysicalDevice. A PhysicalDevice is unique by definition, and there's no need to destroy it.
|
||||
|
||||
/* VULKAN_HPP_KEY_END */
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "03_InitDevice";
|
||||
@ -39,16 +40,20 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
|
||||
|
||||
// get the first index into queueFamiliyProperties which supports graphics
|
||||
size_t graphicsQueueFamilyIndex = std::distance(queueFamilyProperties.begin(),
|
||||
std::find_if(queueFamilyProperties.begin(),
|
||||
queueFamilyProperties.end(),
|
||||
[](vk::QueueFamilyProperties const& qfp) { return qfp.queueFlags & vk::QueueFlagBits::eGraphics; }));
|
||||
size_t graphicsQueueFamilyIndex = std::distance(
|
||||
queueFamilyProperties.begin(),
|
||||
std::find_if(
|
||||
queueFamilyProperties.begin(), queueFamilyProperties.end(), []( vk::QueueFamilyProperties const & qfp ) {
|
||||
return qfp.queueFlags & vk::QueueFlagBits::eGraphics;
|
||||
} ) );
|
||||
assert( graphicsQueueFamilyIndex < queueFamilyProperties.size() );
|
||||
|
||||
// create a UniqueDevice
|
||||
float queuePriority = 0.0f;
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(vk::DeviceQueueCreateFlags(), static_cast<uint32_t>(graphicsQueueFamilyIndex), 1, &queuePriority);
|
||||
vk::UniqueDevice device = physicalDevice.createDeviceUnique(vk::DeviceCreateInfo(vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo));
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
|
||||
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
|
||||
vk::UniqueDevice device =
|
||||
physicalDevice.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo ) );
|
||||
|
||||
// Note: No need to explicitly destroy the device, as the corresponding destroy function is
|
||||
// called by the destructor of the UniqueDevice on leaving this scope.
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "04_InitCommandBuffer";
|
||||
@ -33,19 +34,25 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
|
||||
|
||||
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex(physicalDevice.getQueueFamilyProperties());
|
||||
uint32_t graphicsQueueFamilyIndex =
|
||||
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
|
||||
vk::UniqueDevice device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
|
||||
|
||||
/* VULKAN_HPP_KEY_START */
|
||||
|
||||
// create a UniqueCommandPool to allocate a CommandBuffer from
|
||||
vk::UniqueCommandPool commandPool = device->createCommandPoolUnique(vk::CommandPoolCreateInfo(vk::CommandPoolCreateFlags(), graphicsQueueFamilyIndex));
|
||||
vk::UniqueCommandPool commandPool = device->createCommandPoolUnique(
|
||||
vk::CommandPoolCreateInfo( vk::CommandPoolCreateFlags(), graphicsQueueFamilyIndex ) );
|
||||
|
||||
// allocate a CommandBuffer from the CommandPool
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
// Note: No need to explicitly free the CommandBuffer or destroy the CommandPool, as the corresponding free and destroy
|
||||
// functions are called by the destructor of the UniqueCommandBuffer and the UniqueCommandPool on leaving this scope.
|
||||
// Note: No need to explicitly free the CommandBuffer or destroy the CommandPool, as the corresponding free and
|
||||
// destroy functions are called by the destructor of the UniqueCommandBuffer and the UniqueCommandPool on leaving
|
||||
// this scope.
|
||||
|
||||
/* VULKAN_HPP_KEY_END */
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "05_InitSwapchain";
|
||||
@ -51,13 +52,18 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
// determine a queueFamilyIndex that suports present
|
||||
// first check if the graphicsQueueFamiliyIndex is good enough
|
||||
size_t presentQueueFamilyIndex = physicalDevice.getSurfaceSupportKHR(static_cast<uint32_t>(graphicsQueueFamilyIndex), surface.get()) ? graphicsQueueFamilyIndex : queueFamilyProperties.size();
|
||||
size_t presentQueueFamilyIndex =
|
||||
physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( graphicsQueueFamilyIndex ), surface.get() )
|
||||
? graphicsQueueFamilyIndex
|
||||
: queueFamilyProperties.size();
|
||||
if ( presentQueueFamilyIndex == queueFamilyProperties.size() )
|
||||
{
|
||||
// the graphicsQueueFamilyIndex doesn't support present -> look for an other family index that supports both graphics and present
|
||||
// the graphicsQueueFamilyIndex doesn't support present -> look for an other family index that supports both
|
||||
// graphics and present
|
||||
for ( size_t i = 0; i < queueFamilyProperties.size(); i++ )
|
||||
{
|
||||
if ((queueFamilyProperties[i].queueFlags & vk::QueueFlagBits::eGraphics) && physicalDevice.getSurfaceSupportKHR(static_cast<uint32_t>(i), surface.get()))
|
||||
if ( ( queueFamilyProperties[i].queueFlags & vk::QueueFlagBits::eGraphics ) &&
|
||||
physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( i ), surface.get() ) )
|
||||
{
|
||||
graphicsQueueFamilyIndex = vk::su::checked_cast<uint32_t>( i );
|
||||
presentQueueFamilyIndex = i;
|
||||
@ -66,7 +72,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
}
|
||||
if ( presentQueueFamilyIndex == queueFamilyProperties.size() )
|
||||
{
|
||||
// there's nothing like a single family index that supports both graphics and present -> look for an other family index that supports present
|
||||
// there's nothing like a single family index that supports both graphics and present -> look for an other
|
||||
// family index that supports present
|
||||
for ( size_t i = 0; i < queueFamilyProperties.size(); i++ )
|
||||
{
|
||||
if ( physicalDevice.getSurfaceSupportKHR( static_cast<uint32_t>( i ), surface.get() ) )
|
||||
@ -77,26 +84,31 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((graphicsQueueFamilyIndex == queueFamilyProperties.size()) || (presentQueueFamilyIndex == queueFamilyProperties.size()))
|
||||
if ( ( graphicsQueueFamilyIndex == queueFamilyProperties.size() ) ||
|
||||
( presentQueueFamilyIndex == queueFamilyProperties.size() ) )
|
||||
{
|
||||
throw std::runtime_error( "Could not find a queue for graphics or present -> terminating" );
|
||||
}
|
||||
|
||||
// create a device
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsQueueFamilyIndex, vk::su::getDeviceExtensions());
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex, vk::su::getDeviceExtensions() );
|
||||
|
||||
// get the supported VkFormats
|
||||
std::vector<vk::SurfaceFormatKHR> formats = physicalDevice.getSurfaceFormatsKHR( surface.get() );
|
||||
assert( !formats.empty() );
|
||||
vk::Format format = (formats[0].format == vk::Format::eUndefined) ? vk::Format::eB8G8R8A8Unorm : formats[0].format;
|
||||
vk::Format format =
|
||||
( formats[0].format == vk::Format::eUndefined ) ? vk::Format::eB8G8R8A8Unorm : formats[0].format;
|
||||
|
||||
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( surface.get() );
|
||||
VkExtent2D swapchainExtent;
|
||||
if ( surfaceCapabilities.currentExtent.width == std::numeric_limits<uint32_t>::max() )
|
||||
{
|
||||
// If the surface size is undefined, the size is set to the size of the images requested.
|
||||
swapchainExtent.width = vk::su::clamp(width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width);
|
||||
swapchainExtent.height = vk::su::clamp(height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height);
|
||||
swapchainExtent.width =
|
||||
vk::su::clamp( width, surfaceCapabilities.minImageExtent.width, surfaceCapabilities.maxImageExtent.width );
|
||||
swapchainExtent.height =
|
||||
vk::su::clamp( height, surfaceCapabilities.minImageExtent.height, surfaceCapabilities.maxImageExtent.height );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -107,21 +119,44 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
// The FIFO present mode is guaranteed by the spec to be supported
|
||||
vk::PresentModeKHR swapchainPresentMode = vk::PresentModeKHR::eFifo;
|
||||
|
||||
vk::SurfaceTransformFlagBitsKHR preTransform = (surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity) ? vk::SurfaceTransformFlagBitsKHR::eIdentity : surfaceCapabilities.currentTransform;
|
||||
vk::SurfaceTransformFlagBitsKHR preTransform =
|
||||
( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity )
|
||||
? vk::SurfaceTransformFlagBitsKHR::eIdentity
|
||||
: surfaceCapabilities.currentTransform;
|
||||
|
||||
vk::CompositeAlphaFlagBitsKHR compositeAlpha =
|
||||
(surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied) ? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied :
|
||||
(surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied) ? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied :
|
||||
(surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit) ? vk::CompositeAlphaFlagBitsKHR::eInherit : vk::CompositeAlphaFlagBitsKHR::eOpaque;
|
||||
( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied )
|
||||
? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied
|
||||
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied )
|
||||
? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied
|
||||
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::eInherit )
|
||||
? vk::CompositeAlphaFlagBitsKHR::eInherit
|
||||
: vk::CompositeAlphaFlagBitsKHR::eOpaque;
|
||||
|
||||
vk::SwapchainCreateInfoKHR swapChainCreateInfo(vk::SwapchainCreateFlagsKHR(), surface.get(), surfaceCapabilities.minImageCount, format, vk::ColorSpaceKHR::eSrgbNonlinear,
|
||||
swapchainExtent, 1, vk::ImageUsageFlagBits::eColorAttachment, vk::SharingMode::eExclusive, 0, nullptr, preTransform, compositeAlpha, swapchainPresentMode, true, nullptr);
|
||||
vk::SwapchainCreateInfoKHR swapChainCreateInfo( vk::SwapchainCreateFlagsKHR(),
|
||||
surface.get(),
|
||||
surfaceCapabilities.minImageCount,
|
||||
format,
|
||||
vk::ColorSpaceKHR::eSrgbNonlinear,
|
||||
swapchainExtent,
|
||||
1,
|
||||
vk::ImageUsageFlagBits::eColorAttachment,
|
||||
vk::SharingMode::eExclusive,
|
||||
0,
|
||||
nullptr,
|
||||
preTransform,
|
||||
compositeAlpha,
|
||||
swapchainPresentMode,
|
||||
true,
|
||||
nullptr );
|
||||
|
||||
uint32_t queueFamilyIndices[2] = { static_cast<uint32_t>(graphicsQueueFamilyIndex), static_cast<uint32_t>(presentQueueFamilyIndex) };
|
||||
uint32_t queueFamilyIndices[2] = { static_cast<uint32_t>( graphicsQueueFamilyIndex ),
|
||||
static_cast<uint32_t>( presentQueueFamilyIndex ) };
|
||||
if ( graphicsQueueFamilyIndex != presentQueueFamilyIndex )
|
||||
{
|
||||
// If the graphics and present queues are from different queue families, we either have to explicitly transfer ownership of images between
|
||||
// the queues, or we have to create the swapchain with imageSharingMode as VK_SHARING_MODE_CONCURRENT
|
||||
// If the graphics and present queues are from different queue families, we either have to explicitly transfer
|
||||
// ownership of images between the queues, or we have to create the swapchain with imageSharingMode as
|
||||
// VK_SHARING_MODE_CONCURRENT
|
||||
swapChainCreateInfo.imageSharingMode = vk::SharingMode::eConcurrent;
|
||||
swapChainCreateInfo.queueFamilyIndexCount = 2;
|
||||
swapChainCreateInfo.pQueueFamilyIndices = queueFamilyIndices;
|
||||
@ -133,11 +168,13 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
std::vector<vk::UniqueImageView> imageViews;
|
||||
imageViews.reserve( swapChainImages.size() );
|
||||
vk::ComponentMapping componentMapping(vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA);
|
||||
vk::ComponentMapping componentMapping(
|
||||
vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA );
|
||||
vk::ImageSubresourceRange subResourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 );
|
||||
for ( auto image : swapChainImages )
|
||||
{
|
||||
vk::ImageViewCreateInfo imageViewCreateInfo(vk::ImageViewCreateFlags(), image, vk::ImageViewType::e2D, format, componentMapping, subResourceRange);
|
||||
vk::ImageViewCreateInfo imageViewCreateInfo(
|
||||
vk::ImageViewCreateFlags(), image, vk::ImageViewType::e2D, format, componentMapping, subResourceRange );
|
||||
imageViews.push_back( device->createImageViewUnique( imageViewCreateInfo ) );
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "06_InitDepthBuffer";
|
||||
@ -35,8 +36,10 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
/* VULKAN_HPP_KEY_START */
|
||||
|
||||
@ -56,7 +59,15 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
{
|
||||
throw std::runtime_error( "DepthStencilAttachment is not supported for D16Unorm depth format." );
|
||||
}
|
||||
vk::ImageCreateInfo imageCreateInfo(vk::ImageCreateFlags(), vk::ImageType::e2D, depthFormat, vk::Extent3D(surfaceData.extent, 1), 1, 1, vk::SampleCountFlagBits::e1, tiling, vk::ImageUsageFlagBits::eDepthStencilAttachment);
|
||||
vk::ImageCreateInfo imageCreateInfo( vk::ImageCreateFlags(),
|
||||
vk::ImageType::e2D,
|
||||
depthFormat,
|
||||
vk::Extent3D( surfaceData.extent, 1 ),
|
||||
1,
|
||||
1,
|
||||
vk::SampleCountFlagBits::e1,
|
||||
tiling,
|
||||
vk::ImageUsageFlagBits::eDepthStencilAttachment );
|
||||
vk::UniqueImage depthImage = device->createImageUnique( imageCreateInfo );
|
||||
|
||||
vk::PhysicalDeviceMemoryProperties memoryProperties = physicalDevice.getMemoryProperties();
|
||||
@ -65,7 +76,9 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
uint32_t typeIndex = uint32_t( ~0 );
|
||||
for ( uint32_t i = 0; i < memoryProperties.memoryTypeCount; i++ )
|
||||
{
|
||||
if ((typeBits & 1) && ((memoryProperties.memoryTypes[i].propertyFlags & vk::MemoryPropertyFlagBits::eDeviceLocal) == vk::MemoryPropertyFlagBits::eDeviceLocal))
|
||||
if ( ( typeBits & 1 ) &&
|
||||
( ( memoryProperties.memoryTypes[i].propertyFlags & vk::MemoryPropertyFlagBits::eDeviceLocal ) ==
|
||||
vk::MemoryPropertyFlagBits::eDeviceLocal ) )
|
||||
{
|
||||
typeIndex = i;
|
||||
break;
|
||||
@ -73,13 +86,20 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
typeBits >>= 1;
|
||||
}
|
||||
assert( typeIndex != ~0 );
|
||||
vk::UniqueDeviceMemory depthMemory = device->allocateMemoryUnique(vk::MemoryAllocateInfo(memoryRequirements.size, typeIndex));
|
||||
vk::UniqueDeviceMemory depthMemory =
|
||||
device->allocateMemoryUnique( vk::MemoryAllocateInfo( memoryRequirements.size, typeIndex ) );
|
||||
|
||||
device->bindImageMemory( depthImage.get(), depthMemory.get(), 0 );
|
||||
|
||||
vk::ComponentMapping componentMapping(vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA);
|
||||
vk::ComponentMapping componentMapping(
|
||||
vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA );
|
||||
vk::ImageSubresourceRange subResourceRange( vk::ImageAspectFlagBits::eDepth, 0, 1, 0, 1 );
|
||||
vk::UniqueImageView depthView = device->createImageViewUnique(vk::ImageViewCreateInfo(vk::ImageViewCreateFlags(), depthImage.get(), vk::ImageViewType::e2D, depthFormat, componentMapping, subResourceRange));
|
||||
vk::UniqueImageView depthView = device->createImageViewUnique( vk::ImageViewCreateInfo( vk::ImageViewCreateFlags(),
|
||||
depthImage.get(),
|
||||
vk::ImageViewType::e2D,
|
||||
depthFormat,
|
||||
componentMapping,
|
||||
subResourceRange ) );
|
||||
|
||||
/* VULKAN_HPP_KEY_END */
|
||||
}
|
||||
|
@ -17,10 +17,12 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define GLM_FORCE_RADIANS
|
||||
#pragma warning(disable:4201) // disable warning C4201: nonstandard extension used: nameless struct/union; needed to get glm/detail/type_vec?.hpp without warnings
|
||||
#pragma warning( disable : 4201 ) // disable warning C4201: nonstandard extension used: nameless struct/union; needed
|
||||
// to get glm/detail/type_vec?.hpp without warnings
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
static char const * AppName = "07_InitUniformBuffer";
|
||||
@ -37,23 +39,46 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
|
||||
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, vk::su::findGraphicsQueueFamilyIndex(physicalDevice.getQueueFamilyProperties()));
|
||||
vk::UniqueDevice device = vk::su::createDevice(
|
||||
physicalDevice, vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ) );
|
||||
|
||||
/* VULKAN_HPP_KEY_START */
|
||||
|
||||
glm::mat4x4 model = glm::mat4x4( 1.0f );
|
||||
glm::mat4x4 view = glm::lookAt(glm::vec3(-5.0f, 3.0f, -10.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f));
|
||||
glm::mat4x4 view =
|
||||
glm::lookAt( glm::vec3( -5.0f, 3.0f, -10.0f ), glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, -1.0f, 0.0f ) );
|
||||
glm::mat4x4 projection = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 100.0f );
|
||||
glm::mat4x4 clip = glm::mat4x4(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 1.0f); // vulkan clip space has inverted y and half z !
|
||||
glm::mat4x4 clip = glm::mat4x4( 1.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
-1.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.5f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.5f,
|
||||
1.0f ); // vulkan clip space has inverted y and half z !
|
||||
glm::mat4x4 mvpc = clip * projection * view * model;
|
||||
|
||||
vk::UniqueBuffer uniformDataBuffer = device->createBufferUnique(vk::BufferCreateInfo(vk::BufferCreateFlags(), sizeof(mvpc), vk::BufferUsageFlagBits::eUniformBuffer));
|
||||
vk::UniqueBuffer uniformDataBuffer = device->createBufferUnique(
|
||||
vk::BufferCreateInfo( vk::BufferCreateFlags(), sizeof( mvpc ), vk::BufferUsageFlagBits::eUniformBuffer ) );
|
||||
|
||||
vk::MemoryRequirements memoryRequirements = device->getBufferMemoryRequirements( uniformDataBuffer.get() );
|
||||
uint32_t typeIndex = vk::su::findMemoryType(physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent);
|
||||
vk::UniqueDeviceMemory uniformDataMemory = device->allocateMemoryUnique(vk::MemoryAllocateInfo(memoryRequirements.size, typeIndex));
|
||||
uint32_t typeIndex =
|
||||
vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
|
||||
memoryRequirements.memoryTypeBits,
|
||||
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
|
||||
vk::UniqueDeviceMemory uniformDataMemory =
|
||||
device->allocateMemoryUnique( vk::MemoryAllocateInfo( memoryRequirements.size, typeIndex ) );
|
||||
|
||||
uint8_t* pData = static_cast<uint8_t*>(device->mapMemory(uniformDataMemory.get(), 0, memoryRequirements.size));
|
||||
uint8_t * pData =
|
||||
static_cast<uint8_t *>( device->mapMemory( uniformDataMemory.get(), 0, memoryRequirements.size ) );
|
||||
memcpy( pData, &mvpc, sizeof( mvpc ) );
|
||||
device->unmapMemory( uniformDataMemory.get() );
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "08_InitPipelineLayout";
|
||||
@ -33,19 +34,24 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
|
||||
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, vk::su::findGraphicsQueueFamilyIndex(physicalDevice.getQueueFamilyProperties()));
|
||||
vk::UniqueDevice device = vk::su::createDevice(
|
||||
physicalDevice, vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ) );
|
||||
|
||||
/* VULKAN_HPP_KEY_START */
|
||||
|
||||
// create a DescriptorSetLayout
|
||||
vk::DescriptorSetLayoutBinding descriptorSetLayoutBinding(0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex);
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), 1, &descriptorSetLayoutBinding));
|
||||
vk::DescriptorSetLayoutBinding descriptorSetLayoutBinding(
|
||||
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 1, &descriptorSetLayoutBinding ) );
|
||||
|
||||
// create a PipelineLayout using that DescriptorSetLayout
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
// Note: No need to explicitly destroy the layouts, as the corresponding destroy function is
|
||||
// called by the destructor of the UniqueDescriptorSetLayout or UniquePipelineLayout, respectively, on leaving this scope.
|
||||
// called by the destructor of the UniqueDescriptorSetLayout or UniquePipelineLayout, respectively, on leaving this
|
||||
// scope.
|
||||
|
||||
/* VULKAN_HPP_KEY_END */
|
||||
}
|
||||
|
@ -18,10 +18,12 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define GLM_FORCE_RADIANS
|
||||
#pragma warning(disable:4201) // disable warning C4201: nonstandard extension used: nameless struct/union; needed to get glm/detail/type_vec?.hpp without warnings
|
||||
#pragma warning( disable : 4201 ) // disable warning C4201: nonstandard extension used: nameless struct/union; needed
|
||||
// to get glm/detail/type_vec?.hpp without warnings
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
static char const * AppName = "09_InitDescriptorSet";
|
||||
@ -38,24 +40,34 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
|
||||
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, vk::su::findGraphicsQueueFamilyIndex(physicalDevice.getQueueFamilyProperties()));
|
||||
vk::UniqueDevice device = vk::su::createDevice(
|
||||
physicalDevice, vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ) );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(vk::Extent2D(0, 0)));
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice(
|
||||
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( vk::Extent2D( 0, 0 ) ) );
|
||||
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device, { {vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex} });
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
|
||||
|
||||
/* VULKAN_HPP_KEY_START */
|
||||
|
||||
// create a descriptor pool
|
||||
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eUniformBuffer, 1 );
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(vk::DescriptorPoolCreateInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 1, &poolSize));
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 1, &poolSize ) );
|
||||
|
||||
// allocate a descriptor set
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::DescriptorBufferInfo descriptorBufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
|
||||
device->updateDescriptorSets(vk::WriteDescriptorSet(descriptorSet.get(), 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &descriptorBufferInfo), {});
|
||||
device->updateDescriptorSets(
|
||||
vk::WriteDescriptorSet(
|
||||
descriptorSet.get(), 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &descriptorBufferInfo ),
|
||||
{} );
|
||||
|
||||
/* VULKAN_HPP_KEY_END */
|
||||
}
|
||||
|
@ -17,10 +17,12 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define GLM_FORCE_RADIANS
|
||||
#pragma warning(disable:4201) // disable warning C4201: nonstandard extension used: nameless struct/union; needed to get glm/detail/type_vec?.hpp without warnings
|
||||
#pragma warning( disable : 4201 ) // disable warning C4201: nonstandard extension used: nameless struct/union; needed
|
||||
// to get glm/detail/type_vec?.hpp without warnings
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
static char const * AppName = "10_InitRenderPass";
|
||||
@ -39,25 +41,50 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::Format colorFormat = vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format;
|
||||
vk::Format colorFormat =
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format;
|
||||
vk::Format depthFormat = vk::Format::eD16Unorm;
|
||||
|
||||
/* VULKAN_HPP_KEY_START */
|
||||
|
||||
vk::AttachmentDescription attachmentDescriptions[2];
|
||||
attachmentDescriptions[0] = vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), colorFormat, vk::SampleCountFlagBits::e1, vk::AttachmentLoadOp::eClear,
|
||||
vk::AttachmentStoreOp::eStore, vk::AttachmentLoadOp::eDontCare, vk::AttachmentStoreOp::eDontCare, vk::ImageLayout::eUndefined, vk::ImageLayout::ePresentSrcKHR);
|
||||
attachmentDescriptions[1] = vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), depthFormat, vk::SampleCountFlagBits::e1, vk::AttachmentLoadOp::eClear,
|
||||
vk::AttachmentStoreOp::eDontCare, vk::AttachmentLoadOp::eDontCare, vk::AttachmentStoreOp::eDontCare, vk::ImageLayout::eUndefined, vk::ImageLayout::eDepthStencilAttachmentOptimal);
|
||||
attachmentDescriptions[0] = vk::AttachmentDescription( vk::AttachmentDescriptionFlags(),
|
||||
colorFormat,
|
||||
vk::SampleCountFlagBits::e1,
|
||||
vk::AttachmentLoadOp::eClear,
|
||||
vk::AttachmentStoreOp::eStore,
|
||||
vk::AttachmentLoadOp::eDontCare,
|
||||
vk::AttachmentStoreOp::eDontCare,
|
||||
vk::ImageLayout::eUndefined,
|
||||
vk::ImageLayout::ePresentSrcKHR );
|
||||
attachmentDescriptions[1] = vk::AttachmentDescription( vk::AttachmentDescriptionFlags(),
|
||||
depthFormat,
|
||||
vk::SampleCountFlagBits::e1,
|
||||
vk::AttachmentLoadOp::eClear,
|
||||
vk::AttachmentStoreOp::eDontCare,
|
||||
vk::AttachmentLoadOp::eDontCare,
|
||||
vk::AttachmentStoreOp::eDontCare,
|
||||
vk::ImageLayout::eUndefined,
|
||||
vk::ImageLayout::eDepthStencilAttachmentOptimal );
|
||||
|
||||
vk::AttachmentReference colorReference( 0, vk::ImageLayout::eColorAttachmentOptimal );
|
||||
vk::AttachmentReference depthReference( 1, vk::ImageLayout::eDepthStencilAttachmentOptimal );
|
||||
vk::SubpassDescription subpass(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, 0, nullptr, 1, &colorReference, nullptr, &depthReference);
|
||||
vk::SubpassDescription subpass( vk::SubpassDescriptionFlags(),
|
||||
vk::PipelineBindPoint::eGraphics,
|
||||
0,
|
||||
nullptr,
|
||||
1,
|
||||
&colorReference,
|
||||
nullptr,
|
||||
&depthReference );
|
||||
|
||||
vk::UniqueRenderPass renderPass = device->createRenderPassUnique(vk::RenderPassCreateInfo(vk::RenderPassCreateFlags(), 2, attachmentDescriptions, 1, &subpass));
|
||||
vk::UniqueRenderPass renderPass = device->createRenderPassUnique(
|
||||
vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), 2, attachmentDescriptions, 1, &subpass ) );
|
||||
|
||||
// Note: No need to explicitly destroy the RenderPass or the Semaphore, as the corresponding destroy
|
||||
// functions are called by the destructor of the UniqueRenderPass and the UniqueSemaphore on leaving this scope.
|
||||
|
@ -17,8 +17,9 @@
|
||||
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "11_InitShaders";
|
||||
@ -35,7 +36,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
|
||||
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, vk::su::findGraphicsQueueFamilyIndex(physicalDevice.getQueueFamilyProperties()));
|
||||
vk::UniqueDevice device = vk::su::createDevice(
|
||||
physicalDevice, vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ) );
|
||||
|
||||
/* VULKAN_HPP_KEY_START */
|
||||
|
||||
@ -45,14 +47,16 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
bool ok = vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C, vertexShaderSPV );
|
||||
assert( ok );
|
||||
|
||||
vk::ShaderModuleCreateInfo vertexShaderModuleCreateInfo(vk::ShaderModuleCreateFlags(), vertexShaderSPV.size() * sizeof(unsigned int), vertexShaderSPV.data());
|
||||
vk::ShaderModuleCreateInfo vertexShaderModuleCreateInfo(
|
||||
vk::ShaderModuleCreateFlags(), vertexShaderSPV.size() * sizeof( unsigned int ), vertexShaderSPV.data() );
|
||||
vk::UniqueShaderModule vertexShaderModule = device->createShaderModuleUnique( vertexShaderModuleCreateInfo );
|
||||
|
||||
std::vector<unsigned int> fragmentShaderSPV;
|
||||
ok = vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C, fragmentShaderSPV );
|
||||
assert( ok );
|
||||
|
||||
vk::ShaderModuleCreateInfo fragmentShaderModuleCreateInfo(vk::ShaderModuleCreateFlags(), fragmentShaderSPV.size() * sizeof(unsigned int), fragmentShaderSPV.data());
|
||||
vk::ShaderModuleCreateInfo fragmentShaderModuleCreateInfo(
|
||||
vk::ShaderModuleCreateFlags(), fragmentShaderSPV.size() * sizeof( unsigned int ), fragmentShaderSPV.data() );
|
||||
vk::UniqueShaderModule fragmentShaderModule = device->createShaderModuleUnique( fragmentShaderModuleCreateInfo );
|
||||
|
||||
glslang::FinalizeProcess();
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "12_InitFrameBuffers";
|
||||
@ -35,15 +36,25 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, swapChainData.colorFormat, depthBufferData.format);
|
||||
vk::UniqueRenderPass renderPass =
|
||||
vk::su::createRenderPass( device, swapChainData.colorFormat, depthBufferData.format );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
@ -55,10 +66,17 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
for ( auto const & view : swapChainData.imageViews )
|
||||
{
|
||||
attachments[0] = view.get();
|
||||
framebuffers.push_back(device->createFramebufferUnique(vk::FramebufferCreateInfo(vk::FramebufferCreateFlags(), renderPass.get(), 2, attachments, surfaceData.extent.width, surfaceData.extent.height, 1)));
|
||||
framebuffers.push_back( device->createFramebufferUnique( vk::FramebufferCreateInfo( vk::FramebufferCreateFlags(),
|
||||
renderPass.get(),
|
||||
2,
|
||||
attachments,
|
||||
surfaceData.extent.width,
|
||||
surfaceData.extent.height,
|
||||
1 ) ) );
|
||||
}
|
||||
|
||||
// Note: No need to explicitly destroy the Framebuffers, as the destroy functions are called by the destructor of the UniqueFramebuffer on leaving this scope.
|
||||
// Note: No need to explicitly destroy the Framebuffers, as the destroy functions are called by the destructor of
|
||||
// the UniqueFramebuffer on leaving this scope.
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "../utils/geometries.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "13_InitVertexBuffer";
|
||||
@ -36,32 +37,51 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, swapChainData.colorFormat, depthBufferData.format);
|
||||
vk::UniqueRenderPass renderPass =
|
||||
vk::su::createRenderPass( device, swapChainData.colorFormat, depthBufferData.format );
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
// create a vertex buffer for some vertex and color data
|
||||
vk::UniqueBuffer vertexBuffer = device->createBufferUnique(vk::BufferCreateInfo(vk::BufferCreateFlags(), sizeof(coloredCubeData), vk::BufferUsageFlagBits::eVertexBuffer));
|
||||
vk::UniqueBuffer vertexBuffer = device->createBufferUnique( vk::BufferCreateInfo(
|
||||
vk::BufferCreateFlags(), sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer ) );
|
||||
|
||||
// allocate device memory for that buffer
|
||||
vk::MemoryRequirements memoryRequirements = device->getBufferMemoryRequirements( vertexBuffer.get() );
|
||||
uint32_t memoryTypeIndex = vk::su::findMemoryType(physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent);
|
||||
vk::UniqueDeviceMemory deviceMemory = device->allocateMemoryUnique(vk::MemoryAllocateInfo(memoryRequirements.size, memoryTypeIndex));
|
||||
uint32_t memoryTypeIndex =
|
||||
vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
|
||||
memoryRequirements.memoryTypeBits,
|
||||
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
|
||||
vk::UniqueDeviceMemory deviceMemory =
|
||||
device->allocateMemoryUnique( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
|
||||
|
||||
// copy the vertex and color data into that device memory
|
||||
uint8_t * pData = static_cast<uint8_t *>( device->mapMemory( deviceMemory.get(), 0, memoryRequirements.size ) );
|
||||
@ -71,8 +91,10 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
// and bind the device memory to the vertex buffer
|
||||
device->bindBufferMemory( vertexBuffer.get(), deviceMemory.get(), 0 );
|
||||
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique(vk::SemaphoreCreateInfo(vk::SemaphoreCreateFlags()));
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore =
|
||||
device->createSemaphoreUnique( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(
|
||||
swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
@ -82,7 +104,11 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) );
|
||||
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(0, 0), surfaceData.extent), 2, clearValues);
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
|
||||
commandBuffer->bindVertexBuffers( 0, *vertexBuffer, { 0 } );
|
||||
@ -91,8 +117,9 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
commandBuffer->end();
|
||||
vk::su::submitAndWait( device, graphicsQueue, commandBuffer );
|
||||
|
||||
// Note: No need to explicitly destroy the vertexBuffer, deviceMemory, or semaphore, as the destroy functions are called
|
||||
// by the destructor of the UniqueBuffer, UniqueDeviceMemory, and UniqueSemaphore, respectively, on leaving this scope.
|
||||
// Note: No need to explicitly destroy the vertexBuffer, deviceMemory, or semaphore, as the destroy functions are
|
||||
// called by the destructor of the UniqueBuffer, UniqueDeviceMemory, and UniqueSemaphore, respectively, on leaving
|
||||
// this scope.
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
}
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "14_InitPipeline";
|
||||
@ -39,35 +40,43 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, vk::Format::eD16Unorm);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
vk::Format::eD16Unorm );
|
||||
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device, { {vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex} });
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
vk::PipelineShaderStageCreateInfo pipelineShaderStageCreateInfos[2] =
|
||||
{
|
||||
vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule.get(), "main"),
|
||||
vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule.get(), "main")
|
||||
vk::PipelineShaderStageCreateInfo pipelineShaderStageCreateInfos[2] = {
|
||||
vk::PipelineShaderStageCreateInfo(
|
||||
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule.get(), "main" ),
|
||||
vk::PipelineShaderStageCreateInfo(
|
||||
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule.get(), "main" )
|
||||
};
|
||||
|
||||
vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( coloredCubeData[0] ) );
|
||||
vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
|
||||
{
|
||||
vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[2] = {
|
||||
vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ),
|
||||
vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 )
|
||||
};
|
||||
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo
|
||||
(
|
||||
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(
|
||||
vk::PipelineVertexInputStateCreateFlags(), // flags
|
||||
1, // vertexBindingDescriptionCount
|
||||
&vertexInputBindingDescription, // pVertexBindingDescription
|
||||
@ -75,12 +84,13 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
vertexInputAttributeDescriptions // pVertexAttributeDescriptions
|
||||
);
|
||||
|
||||
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleList);
|
||||
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(
|
||||
vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleList );
|
||||
|
||||
vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo(vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr);
|
||||
vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo(
|
||||
vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr );
|
||||
|
||||
vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo
|
||||
(
|
||||
vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo(
|
||||
vk::PipelineRasterizationStateCreateFlags(), // flags
|
||||
false, // depthClampEnable
|
||||
false, // rasterizerDiscardEnable
|
||||
@ -94,16 +104,15 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
1.0f // lineWidth
|
||||
);
|
||||
|
||||
vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo
|
||||
(
|
||||
vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo(
|
||||
vk::PipelineMultisampleStateCreateFlags(), // flags
|
||||
vk::SampleCountFlagBits::e1 // rasterizationSamples
|
||||
// other values can be default
|
||||
);
|
||||
|
||||
vk::StencilOpState stencilOpState(vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways);
|
||||
vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo
|
||||
(
|
||||
vk::StencilOpState stencilOpState(
|
||||
vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
|
||||
vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo(
|
||||
vk::PipelineDepthStencilStateCreateFlags(), // flags
|
||||
true, // depthTestEnable
|
||||
true, // depthWriteEnable
|
||||
@ -114,9 +123,9 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
stencilOpState // back
|
||||
);
|
||||
|
||||
vk::ColorComponentFlags colorComponentFlags(vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA);
|
||||
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState
|
||||
(
|
||||
vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG |
|
||||
vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA );
|
||||
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState(
|
||||
false, // blendEnable
|
||||
vk::BlendFactor::eZero, // srcColorBlendFactor
|
||||
vk::BlendFactor::eZero, // dstColorBlendFactor
|
||||
@ -126,8 +135,7 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
vk::BlendOp::eAdd, // alphaBlendOp
|
||||
colorComponentFlags // colorWriteMask
|
||||
);
|
||||
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo
|
||||
(
|
||||
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo(
|
||||
vk::PipelineColorBlendStateCreateFlags(), // flags
|
||||
false, // logicOpEnable
|
||||
vk::LogicOp::eNoOp, // logicOp
|
||||
@ -137,10 +145,10 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
);
|
||||
|
||||
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
|
||||
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates);
|
||||
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(
|
||||
vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates );
|
||||
|
||||
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
|
||||
(
|
||||
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo(
|
||||
vk::PipelineCreateFlags(), // flags
|
||||
2, // stageCount
|
||||
pipelineShaderStageCreateInfos, // pStages
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
@ -40,52 +41,94 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(surfaceData.extent));
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice(
|
||||
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( surfaceData.extent ) );
|
||||
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device, { {vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex} });
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, depthBufferData.format);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
depthBufferData.format );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, sizeof(coloredCubeData), vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
vk::su::copyToDevice(device, vertexBufferData.deviceMemory, coloredCubeData, sizeof(coloredCubeData) / sizeof(coloredCubeData[0]));
|
||||
vk::su::BufferData vertexBufferData(
|
||||
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
|
||||
vk::su::copyToDevice( device,
|
||||
vertexBufferData.deviceMemory,
|
||||
coloredCubeData,
|
||||
sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
|
||||
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(device, { {vk::DescriptorType::eUniformBuffer, 1} });
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::UniqueDescriptorPool descriptorPool =
|
||||
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::su::updateDescriptorSets(device, descriptorSet, {{vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView()}}, {});
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView() } },
|
||||
{} );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr),
|
||||
sizeof(coloredCubeData[0]), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise, true, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(
|
||||
device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
sizeof( coloredCubeData[0] ),
|
||||
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise,
|
||||
true,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
// Get the index of the next available swapchain image:
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(
|
||||
swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
@ -94,13 +137,24 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
vk::ClearValue clearValues[2];
|
||||
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(0, 0), surfaceData.extent), 2, clearValues);
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr);
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
commandBuffer->draw( 12 * 3, 1, 0, 0 );
|
||||
@ -116,7 +170,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -44,7 +44,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
|
||||
// initialize the DipatchLoaderDynamic to use
|
||||
static vk::DynamicLoader dl;
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
|
||||
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
|
||||
#endif
|
||||
|
||||
@ -54,14 +55,16 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
// Translate the version into major/minor for easier comparison
|
||||
uint32_t loader_major_version = VK_VERSION_MAJOR( apiVersion );
|
||||
uint32_t loader_minor_version = VK_VERSION_MINOR( apiVersion );
|
||||
std::cout << "Loader/Runtime support detected for Vulkan " << loader_major_version << "." << loader_minor_version << "\n";
|
||||
std::cout << "Loader/Runtime support detected for Vulkan " << loader_major_version << "." << loader_minor_version
|
||||
<< "\n";
|
||||
|
||||
// Check current version against what we want to run
|
||||
if ( loader_major_version > desiredMajorVersion ||
|
||||
( loader_major_version == desiredMajorVersion && loader_minor_version >= desiredMinorVersion ) )
|
||||
{
|
||||
// Create the instance
|
||||
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName, {}, vk::su::getInstanceExtensions(), desiredVersion);
|
||||
vk::UniqueInstance instance =
|
||||
vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions(), desiredVersion );
|
||||
#if !defined( NDEBUG )
|
||||
vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger( instance );
|
||||
#endif
|
||||
@ -69,9 +72,14 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
// Get the list of physical devices
|
||||
std::vector<vk::PhysicalDevice> physicalDevices = instance->enumeratePhysicalDevices();
|
||||
|
||||
// Go through the list of physical devices and select only those that are capable of running the API version we want.
|
||||
// Go through the list of physical devices and select only those that are capable of running the API version we
|
||||
// want.
|
||||
std::vector<vk::PhysicalDevice> desiredPhysicalDevices;
|
||||
std::copy_if(physicalDevices.begin(), physicalDevices.end(), std::back_inserter(desiredPhysicalDevices), [desiredVersion](vk::PhysicalDevice const& pd) { return pd.getProperties().apiVersion >= desiredVersion; });
|
||||
std::copy_if(
|
||||
physicalDevices.begin(),
|
||||
physicalDevices.end(),
|
||||
std::back_inserter( desiredPhysicalDevices ),
|
||||
[desiredVersion]( vk::PhysicalDevice const & pd ) { return pd.getProperties().apiVersion >= desiredVersion; } );
|
||||
|
||||
// If we have something in the desired version physical device list, we're good
|
||||
if ( desiredPhysicalDevices.size() > 0 )
|
||||
@ -87,11 +95,13 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
if ( usingMinorVersion < desiredMinorVersion )
|
||||
{
|
||||
std::cout << "Determined that this system can only use Vulkan API version " << usingVersionString << " instead of desired version " << desiredVersionString << std::endl;
|
||||
std::cout << "Determined that this system can only use Vulkan API version " << usingVersionString
|
||||
<< " instead of desired version " << desiredVersionString << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Determined that this system can run desired Vulkan API version " << desiredVersionString << std::endl;
|
||||
std::cout << "Determined that this system can run desired Vulkan API version " << desiredVersionString
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -36,66 +36,101 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 640, 640 ) );
|
||||
|
||||
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR(surfaceData.surface.get());
|
||||
vk::SurfaceCapabilitiesKHR surfaceCapabilities =
|
||||
physicalDevice.getSurfaceCapabilitiesKHR( surfaceData.surface.get() );
|
||||
if ( !( surfaceCapabilities.supportedUsageFlags & vk::ImageUsageFlagBits::eTransferDst ) )
|
||||
{
|
||||
std::cout << "Surface cannot be destination of blit - abort \n";
|
||||
exit( -1 );
|
||||
}
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferDst,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferDst,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( swapChainData.colorFormat );
|
||||
assert((formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eBlitSrc) && "Format cannot be used as transfer source");
|
||||
assert( ( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eBlitSrc ) &&
|
||||
"Format cannot be used as transfer source" );
|
||||
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
|
||||
// Get the index of the next available swapchain image:
|
||||
vk::ResultValue<uint32_t> nextImage = device->acquireNextImageKHR(swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> nextImage = device->acquireNextImageKHR(
|
||||
swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( nextImage.result == vk::Result::eSuccess );
|
||||
assert( nextImage.value < swapChainData.images.size() );
|
||||
uint32_t currentBuffer = nextImage.value;
|
||||
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
vk::su::setImageLayout(commandBuffer, swapChainData.images[currentBuffer], swapChainData.colorFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal);
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
swapChainData.images[currentBuffer],
|
||||
swapChainData.colorFormat,
|
||||
vk::ImageLayout::eUndefined,
|
||||
vk::ImageLayout::eTransferDstOptimal );
|
||||
|
||||
// Create an image, map it, and write some values to the image
|
||||
vk::ImageCreateInfo imageCreateInfo(vk::ImageCreateFlags(), vk::ImageType::e2D, swapChainData.colorFormat, vk::Extent3D(surfaceData.extent, 1), 1, 1, vk::SampleCountFlagBits::e1, vk::ImageTiling::eLinear, vk::ImageUsageFlagBits::eTransferSrc);
|
||||
vk::ImageCreateInfo imageCreateInfo( vk::ImageCreateFlags(),
|
||||
vk::ImageType::e2D,
|
||||
swapChainData.colorFormat,
|
||||
vk::Extent3D( surfaceData.extent, 1 ),
|
||||
1,
|
||||
1,
|
||||
vk::SampleCountFlagBits::e1,
|
||||
vk::ImageTiling::eLinear,
|
||||
vk::ImageUsageFlagBits::eTransferSrc );
|
||||
vk::UniqueImage blitSourceImage = device->createImageUnique( imageCreateInfo );
|
||||
|
||||
vk::PhysicalDeviceMemoryProperties memoryProperties = physicalDevice.getMemoryProperties();
|
||||
vk::MemoryRequirements memoryRequirements = device->getImageMemoryRequirements( blitSourceImage.get() );
|
||||
uint32_t memoryTypeIndex = vk::su::findMemoryType(memoryProperties, memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible);
|
||||
uint32_t memoryTypeIndex = vk::su::findMemoryType(
|
||||
memoryProperties, memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible );
|
||||
|
||||
vk::UniqueDeviceMemory deviceMemory = device->allocateMemoryUnique(vk::MemoryAllocateInfo(memoryRequirements.size, memoryTypeIndex));
|
||||
vk::UniqueDeviceMemory deviceMemory =
|
||||
device->allocateMemoryUnique( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
|
||||
device->bindImageMemory( blitSourceImage.get(), deviceMemory.get(), 0 );
|
||||
|
||||
vk::su::setImageLayout(commandBuffer, blitSourceImage.get(), swapChainData.colorFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eGeneral);
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
blitSourceImage.get(),
|
||||
swapChainData.colorFormat,
|
||||
vk::ImageLayout::eUndefined,
|
||||
vk::ImageLayout::eGeneral );
|
||||
|
||||
commandBuffer->end();
|
||||
|
||||
/* Queue the command buffer for execution */
|
||||
vk::UniqueFence commandFence = device->createFenceUnique( {} );
|
||||
vk::PipelineStageFlags pipeStageFlags( vk::PipelineStageFlagBits::eColorAttachmentOutput );
|
||||
graphicsQueue.submit(vk::SubmitInfo(1, &imageAcquiredSemaphore.get(), &pipeStageFlags, 1, &commandBuffer.get()), commandFence.get());
|
||||
graphicsQueue.submit( vk::SubmitInfo( 1, &imageAcquiredSemaphore.get(), &pipeStageFlags, 1, &commandBuffer.get() ),
|
||||
commandFence.get() );
|
||||
|
||||
/* Make sure command buffer is finished before mapping */
|
||||
while ( device->waitForFences( commandFence.get(), true, vk::su::FenceTimeout ) == vk::Result::eTimeout )
|
||||
;
|
||||
|
||||
unsigned char* pImageMemory = static_cast<unsigned char*>(device->mapMemory(deviceMemory.get(), 0, memoryRequirements.size));
|
||||
unsigned char * pImageMemory =
|
||||
static_cast<unsigned char *>( device->mapMemory( deviceMemory.get(), 0, memoryRequirements.size ) );
|
||||
|
||||
// Checkerboard of 8x8 pixel squares
|
||||
for ( uint32_t row = 0; row < surfaceData.extent.height; row++ )
|
||||
@ -119,27 +154,71 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
|
||||
// Intend to blit from this image, set the layout accordingly
|
||||
vk::su::setImageLayout(commandBuffer, blitSourceImage.get(), swapChainData.colorFormat, vk::ImageLayout::eGeneral, vk::ImageLayout::eTransferSrcOptimal);
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
blitSourceImage.get(),
|
||||
swapChainData.colorFormat,
|
||||
vk::ImageLayout::eGeneral,
|
||||
vk::ImageLayout::eTransferSrcOptimal );
|
||||
|
||||
vk::Image blitDestinationImage = swapChainData.images[currentBuffer];
|
||||
|
||||
// Do a 32x32 blit to all of the dst image - should get big squares
|
||||
vk::ImageSubresourceLayers imageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 );
|
||||
vk::ImageBlit imageBlit(imageSubresourceLayers, { { vk::Offset3D(0, 0, 0), vk::Offset3D(32, 32, 1) } }, imageSubresourceLayers, { { vk::Offset3D(0, 0, 0), vk::Offset3D(surfaceData.extent.width, surfaceData.extent.height, 1) } });
|
||||
commandBuffer->blitImage(blitSourceImage.get(), vk::ImageLayout::eTransferSrcOptimal, blitDestinationImage, vk::ImageLayout::eTransferDstOptimal, imageBlit, vk::Filter::eLinear);
|
||||
vk::ImageBlit imageBlit(
|
||||
imageSubresourceLayers,
|
||||
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( 32, 32, 1 ) } },
|
||||
imageSubresourceLayers,
|
||||
{ { vk::Offset3D( 0, 0, 0 ), vk::Offset3D( surfaceData.extent.width, surfaceData.extent.height, 1 ) } } );
|
||||
commandBuffer->blitImage( blitSourceImage.get(),
|
||||
vk::ImageLayout::eTransferSrcOptimal,
|
||||
blitDestinationImage,
|
||||
vk::ImageLayout::eTransferDstOptimal,
|
||||
imageBlit,
|
||||
vk::Filter::eLinear );
|
||||
|
||||
// Use a barrier to make sure the blit is finished before the copy starts
|
||||
vk::ImageMemoryBarrier memoryBarrier(vk::AccessFlagBits::eTransferWrite, vk::AccessFlagBits::eMemoryRead, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eTransferDstOptimal,
|
||||
VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED, blitDestinationImage, vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1));
|
||||
commandBuffer->pipelineBarrier(vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, vk::DependencyFlags(), nullptr, nullptr, memoryBarrier);
|
||||
vk::ImageMemoryBarrier memoryBarrier( vk::AccessFlagBits::eTransferWrite,
|
||||
vk::AccessFlagBits::eMemoryRead,
|
||||
vk::ImageLayout::eTransferDstOptimal,
|
||||
vk::ImageLayout::eTransferDstOptimal,
|
||||
VK_QUEUE_FAMILY_IGNORED,
|
||||
VK_QUEUE_FAMILY_IGNORED,
|
||||
blitDestinationImage,
|
||||
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
|
||||
commandBuffer->pipelineBarrier( vk::PipelineStageFlagBits::eTransfer,
|
||||
vk::PipelineStageFlagBits::eTransfer,
|
||||
vk::DependencyFlags(),
|
||||
nullptr,
|
||||
nullptr,
|
||||
memoryBarrier );
|
||||
|
||||
// Do a image copy to part of the dst image - checks should stay small
|
||||
vk::ImageCopy imageCopy(imageSubresourceLayers, vk::Offset3D(), imageSubresourceLayers, vk::Offset3D(256, 256, 0), vk::Extent3D(128, 128, 1));
|
||||
commandBuffer->copyImage(blitSourceImage.get(), vk::ImageLayout::eTransferSrcOptimal, blitDestinationImage, vk::ImageLayout::eTransferDstOptimal, imageCopy);
|
||||
vk::ImageCopy imageCopy( imageSubresourceLayers,
|
||||
vk::Offset3D(),
|
||||
imageSubresourceLayers,
|
||||
vk::Offset3D( 256, 256, 0 ),
|
||||
vk::Extent3D( 128, 128, 1 ) );
|
||||
commandBuffer->copyImage( blitSourceImage.get(),
|
||||
vk::ImageLayout::eTransferSrcOptimal,
|
||||
blitDestinationImage,
|
||||
vk::ImageLayout::eTransferDstOptimal,
|
||||
imageCopy );
|
||||
|
||||
vk::ImageMemoryBarrier prePresentBarrier(vk::AccessFlagBits::eTransferWrite, vk::AccessFlagBits::eMemoryRead, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::ePresentSrcKHR,
|
||||
VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED, swapChainData.images[currentBuffer], vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1));
|
||||
commandBuffer->pipelineBarrier(vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTopOfPipe, vk::DependencyFlags(), nullptr, nullptr, prePresentBarrier);
|
||||
vk::ImageMemoryBarrier prePresentBarrier(
|
||||
vk::AccessFlagBits::eTransferWrite,
|
||||
vk::AccessFlagBits::eMemoryRead,
|
||||
vk::ImageLayout::eTransferDstOptimal,
|
||||
vk::ImageLayout::ePresentSrcKHR,
|
||||
VK_QUEUE_FAMILY_IGNORED,
|
||||
VK_QUEUE_FAMILY_IGNORED,
|
||||
swapChainData.images[currentBuffer],
|
||||
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
|
||||
commandBuffer->pipelineBarrier( vk::PipelineStageFlagBits::eTransfer,
|
||||
vk::PipelineStageFlagBits::eTopOfPipe,
|
||||
vk::DependencyFlags(),
|
||||
nullptr,
|
||||
nullptr,
|
||||
prePresentBarrier );
|
||||
commandBuffer->end();
|
||||
|
||||
vk::UniqueFence drawFence = device->createFenceUnique( {} );
|
||||
@ -151,7 +230,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
;
|
||||
|
||||
/* Now present the image in the window */
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer, nullptr));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer, nullptr ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -16,6 +16,7 @@
|
||||
// Draw a cube
|
||||
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
@ -25,53 +26,73 @@ static char const* EngineName = "Vulkan.hpp";
|
||||
PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT;
|
||||
PFN_vkDestroyDebugUtilsMessengerEXT pfnVkDestroyDebugUtilsMessengerEXT;
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pMessenger)
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT( VkInstance instance,
|
||||
const VkDebugUtilsMessengerCreateInfoEXT * pCreateInfo,
|
||||
const VkAllocationCallbacks * pAllocator,
|
||||
VkDebugUtilsMessengerEXT * pMessenger )
|
||||
{
|
||||
return pfnVkCreateDebugUtilsMessengerEXT( instance, pCreateInfo, pAllocator, pMessenger );
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * pAllocator)
|
||||
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance,
|
||||
VkDebugUtilsMessengerEXT messenger,
|
||||
VkAllocationCallbacks const * pAllocator )
|
||||
{
|
||||
return pfnVkDestroyDebugUtilsMessengerEXT( instance, messenger, pAllocator );
|
||||
}
|
||||
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||
VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData, void * /*pUserData*/)
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||
VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData,
|
||||
void * /*pUserData*/ )
|
||||
{
|
||||
std::ostringstream message;
|
||||
|
||||
message << vk::to_string(static_cast<vk::DebugUtilsMessageSeverityFlagBitsEXT>(messageSeverity)) << ": " << vk::to_string(static_cast<vk::DebugUtilsMessageTypeFlagsEXT>(messageTypes)) << ":\n";
|
||||
message << "\t" << "messageIDName = <" << pCallbackData->pMessageIdName << ">\n";
|
||||
message << "\t" << "messageIdNumber = " << pCallbackData->messageIdNumber << "\n";
|
||||
message << "\t" << "message = <" << pCallbackData->pMessage << ">\n";
|
||||
message << vk::to_string( static_cast<vk::DebugUtilsMessageSeverityFlagBitsEXT>( messageSeverity ) ) << ": "
|
||||
<< vk::to_string( static_cast<vk::DebugUtilsMessageTypeFlagsEXT>( messageTypes ) ) << ":\n";
|
||||
message << "\t"
|
||||
<< "messageIDName = <" << pCallbackData->pMessageIdName << ">\n";
|
||||
message << "\t"
|
||||
<< "messageIdNumber = " << pCallbackData->messageIdNumber << "\n";
|
||||
message << "\t"
|
||||
<< "message = <" << pCallbackData->pMessage << ">\n";
|
||||
if ( 0 < pCallbackData->queueLabelCount )
|
||||
{
|
||||
message << "\t" << "Queue Labels:\n";
|
||||
message << "\t"
|
||||
<< "Queue Labels:\n";
|
||||
for ( uint8_t i = 0; i < pCallbackData->queueLabelCount; i++ )
|
||||
{
|
||||
message << "\t\t" << "labelName = <" << pCallbackData->pQueueLabels[i].pLabelName << ">\n";
|
||||
message << "\t\t"
|
||||
<< "labelName = <" << pCallbackData->pQueueLabels[i].pLabelName << ">\n";
|
||||
}
|
||||
}
|
||||
if ( 0 < pCallbackData->cmdBufLabelCount )
|
||||
{
|
||||
message << "\t" << "CommandBuffer Labels:\n";
|
||||
message << "\t"
|
||||
<< "CommandBuffer Labels:\n";
|
||||
for ( uint8_t i = 0; i < pCallbackData->cmdBufLabelCount; i++ )
|
||||
{
|
||||
message << "\t\t" << "labelName = <" << pCallbackData->pCmdBufLabels[i].pLabelName << ">\n";
|
||||
message << "\t\t"
|
||||
<< "labelName = <" << pCallbackData->pCmdBufLabels[i].pLabelName << ">\n";
|
||||
}
|
||||
}
|
||||
if ( 0 < pCallbackData->objectCount )
|
||||
{
|
||||
message << "\t" << "Objects:\n";
|
||||
message << "\t"
|
||||
<< "Objects:\n";
|
||||
for ( uint8_t i = 0; i < pCallbackData->objectCount; i++ )
|
||||
{
|
||||
message << "\t\t" << "Object " << i << "\n";
|
||||
message << "\t\t\t" << "objectType = " << vk::to_string(static_cast<vk::ObjectType>(pCallbackData->pObjects[i].objectType)) << "\n";
|
||||
message << "\t\t\t" << "objectHandle = " << pCallbackData->pObjects[i].objectHandle << "\n";
|
||||
message << "\t\t"
|
||||
<< "Object " << i << "\n";
|
||||
message << "\t\t\t"
|
||||
<< "objectType = "
|
||||
<< vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) << "\n";
|
||||
message << "\t\t\t"
|
||||
<< "objectHandle = " << pCallbackData->pObjects[i].objectHandle << "\n";
|
||||
if ( pCallbackData->pObjects[i].pObjectName )
|
||||
{
|
||||
message << "\t\t\t" << "objectName = <" << pCallbackData->pObjects[i].pObjectName << ">\n";
|
||||
message << "\t\t\t"
|
||||
<< "objectName = <" << pCallbackData->pObjects[i].pObjectName << ">\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -85,7 +106,6 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc(VkDebugUtilsMessageSeverityFlagB
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int main( int /*argc*/, char ** /*argv*/ )
|
||||
{
|
||||
try
|
||||
@ -94,34 +114,44 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
std::vector<vk::ExtensionProperties> props = vk::enumerateInstanceExtensionProperties();
|
||||
|
||||
auto propsIterator = std::find_if(props.begin(), props.end(), [](vk::ExtensionProperties const& ep) { return strcmp(ep.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0; });
|
||||
auto propsIterator = std::find_if( props.begin(), props.end(), []( vk::ExtensionProperties const & ep ) {
|
||||
return strcmp( ep.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME ) == 0;
|
||||
} );
|
||||
if ( propsIterator == props.end() )
|
||||
{
|
||||
std::cout << "Something went very wrong, cannot find " << VK_EXT_DEBUG_UTILS_EXTENSION_NAME << " extension" << std::endl;
|
||||
std::cout << "Something went very wrong, cannot find " << VK_EXT_DEBUG_UTILS_EXTENSION_NAME << " extension"
|
||||
<< std::endl;
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
|
||||
const char * extensionName = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
|
||||
vk::UniqueInstance instance = vk::createInstanceUnique(vk::InstanceCreateInfo(vk::InstanceCreateFlags(), &applicationInfo, 0, nullptr, 1, &extensionName));
|
||||
vk::UniqueInstance instance = vk::createInstanceUnique(
|
||||
vk::InstanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, 0, nullptr, 1, &extensionName ) );
|
||||
|
||||
pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(instance->getProcAddr("vkCreateDebugUtilsMessengerEXT"));
|
||||
pfnVkCreateDebugUtilsMessengerEXT =
|
||||
reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance->getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
|
||||
if ( !pfnVkCreateDebugUtilsMessengerEXT )
|
||||
{
|
||||
std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl;
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(instance->getProcAddr("vkDestroyDebugUtilsMessengerEXT"));
|
||||
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(
|
||||
instance->getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
|
||||
if ( !pfnVkDestroyDebugUtilsMessengerEXT )
|
||||
{
|
||||
std::cout << "GetInstanceProcAddr: Unable to find pfnVkDestroyDebugUtilsMessengerEXT function." << std::endl;
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags(vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning | vk::DebugUtilsMessageSeverityFlagBitsEXT::eError);
|
||||
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags(vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance | vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation);
|
||||
vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = instance->createDebugUtilsMessengerEXTUnique(vk::DebugUtilsMessengerCreateInfoEXT({}, severityFlags, messageTypeFlags, &debugMessageFunc));
|
||||
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning |
|
||||
vk::DebugUtilsMessageSeverityFlagBitsEXT::eError );
|
||||
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral |
|
||||
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
|
||||
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
|
||||
vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = instance->createDebugUtilsMessengerEXTUnique(
|
||||
vk::DebugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
}
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
@ -40,17 +41,29 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
@ -59,39 +72,70 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(surfaceData.extent));
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice(
|
||||
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( surfaceData.extent ) );
|
||||
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device,
|
||||
{ {vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex}, {vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment} });
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device,
|
||||
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
|
||||
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, depthBufferData.format);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
depthBufferData.format );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, sizeof(texturedCubeData), vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
vk::su::copyToDevice(device, vertexBufferData.deviceMemory, texturedCubeData, sizeof(texturedCubeData) / sizeof(texturedCubeData[0]));
|
||||
vk::su::BufferData vertexBufferData(
|
||||
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
|
||||
vk::su::copyToDevice( device,
|
||||
vertexBufferData.deviceMemory,
|
||||
texturedCubeData,
|
||||
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
|
||||
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(device, { {vk::DescriptorType::eUniformBuffer, 1}, {vk::DescriptorType::eCombinedImageSampler, 1} });
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::su::updateDescriptorSets(device, descriptorSet, {{vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView()}}, textureData);
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView() } },
|
||||
textureData );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr),
|
||||
sizeof(texturedCubeData[0]), {{ vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 }},
|
||||
vk::FrontFace::eClockwise, true, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline =
|
||||
vk::su::createGraphicsPipeline( device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
sizeof( texturedCubeData[0] ),
|
||||
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise,
|
||||
true,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
// Get the index of the next available swapchain image:
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(
|
||||
swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
@ -100,13 +144,24 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
vk::ClearValue clearValues[2];
|
||||
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(0, 0), surfaceData.extent), 2, clearValues);
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr);
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
commandBuffer->draw( 12 * 3, 1, 0, 0 );
|
||||
@ -122,7 +177,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
@ -40,31 +41,53 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, depthBufferData.format);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
depthBufferData.format );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, sizeof(coloredCubeData), vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
vk::su::copyToDevice(device, vertexBufferData.deviceMemory, coloredCubeData, sizeof(coloredCubeData) / sizeof(coloredCubeData[0]));
|
||||
vk::su::BufferData vertexBufferData(
|
||||
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
|
||||
vk::su::copyToDevice( device,
|
||||
vertexBufferData.deviceMemory,
|
||||
coloredCubeData,
|
||||
sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
@ -78,9 +101,25 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
/* Set up uniform buffer with 2 transform matrices in it */
|
||||
glm::mat4x4 mvpcs[2];
|
||||
glm::mat4x4 model = glm::mat4x4( 1.0f );
|
||||
glm::mat4x4 view = glm::lookAt(glm::vec3(0.0f, 3.0f, -10.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f));
|
||||
glm::mat4x4 view =
|
||||
glm::lookAt( glm::vec3( 0.0f, 3.0f, -10.0f ), glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, -1.0f, 0.0f ) );
|
||||
glm::mat4x4 projection = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 100.0f );
|
||||
glm::mat4x4 clip = glm::mat4x4(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 1.0f); // vulkan clip space has inverted y and half z !
|
||||
glm::mat4x4 clip = glm::mat4x4( 1.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
-1.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.5f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.5f,
|
||||
1.0f ); // vulkan clip space has inverted y and half z !
|
||||
mvpcs[0] = clip * projection * view * model;
|
||||
|
||||
model = glm::translate( model, glm::vec3( -1.5f, 1.5f, -1.5f ) );
|
||||
@ -89,29 +128,49 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
vk::DeviceSize bufferSize = sizeof( glm::mat4x4 );
|
||||
if ( limits.minUniformBufferOffsetAlignment )
|
||||
{
|
||||
bufferSize = (bufferSize + limits.minUniformBufferOffsetAlignment - 1) & ~(limits.minUniformBufferOffsetAlignment - 1);
|
||||
bufferSize =
|
||||
( bufferSize + limits.minUniformBufferOffsetAlignment - 1 ) & ~( limits.minUniformBufferOffsetAlignment - 1 );
|
||||
}
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, 2 * bufferSize, vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, 2 * bufferSize, vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice( device, uniformBufferData.deviceMemory, mvpcs, 2, bufferSize );
|
||||
|
||||
// create a DescriptorSetLayout with vk::DescriptorType::eUniformBufferDynamic
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device, { {vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex} });
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device, { { vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
// create a DescriptorPool with vk::DescriptorType::eUniformBufferDynamic
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } });
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::UniqueDescriptorPool descriptorPool =
|
||||
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::su::updateDescriptorSets(device, descriptorSet, {{vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, vk::UniqueBufferView()}}, {});
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, vk::UniqueBufferView() } },
|
||||
{} );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr),
|
||||
sizeof(coloredCubeData[0]), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise, true, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(
|
||||
device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
sizeof( coloredCubeData[0] ),
|
||||
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise,
|
||||
true,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
// Get the index of the next available swapchain image:
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(
|
||||
swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
@ -120,23 +179,35 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
vk::ClearValue clearValues[2];
|
||||
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(0, 0), surfaceData.extent), 2, clearValues);
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
/* The first draw should use the first matrix in the buffer */
|
||||
uint32_t dynamicOffset = 0;
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), dynamicOffset);
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), dynamicOffset );
|
||||
|
||||
commandBuffer->bindVertexBuffers( 0, *vertexBufferData.buffer, { 0 } );
|
||||
commandBuffer->draw( 12 * 3, 1, 0, 0 );
|
||||
|
||||
// the second draw should use the second matrix in the buffer;
|
||||
dynamicOffset = (uint32_t)bufferSize;
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), dynamicOffset);
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), dynamicOffset );
|
||||
commandBuffer->draw( 12 * 3, 1, 0, 0 );
|
||||
|
||||
commandBuffer->endRenderPass();
|
||||
@ -151,7 +222,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
@ -27,23 +28,30 @@ static char const* EngineName = "Vulkan.hpp";
|
||||
PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT;
|
||||
PFN_vkDestroyDebugUtilsMessengerEXT pfnVkDestroyDebugUtilsMessengerEXT;
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pMessenger)
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT( VkInstance instance,
|
||||
const VkDebugUtilsMessengerCreateInfoEXT * pCreateInfo,
|
||||
const VkAllocationCallbacks * pAllocator,
|
||||
VkDebugUtilsMessengerEXT * pMessenger )
|
||||
{
|
||||
return pfnVkCreateDebugUtilsMessengerEXT( instance, pCreateInfo, pAllocator, pMessenger );
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * pAllocator)
|
||||
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( VkInstance instance,
|
||||
VkDebugUtilsMessengerEXT messenger,
|
||||
VkAllocationCallbacks const * pAllocator )
|
||||
{
|
||||
return pfnVkDestroyDebugUtilsMessengerEXT( instance, messenger, pAllocator );
|
||||
}
|
||||
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||
VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData, void * /*pUserData*/)
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||
VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData,
|
||||
void * /*pUserData*/ )
|
||||
{
|
||||
std::string message;
|
||||
|
||||
message += vk::to_string(static_cast<vk::DebugUtilsMessageSeverityFlagBitsEXT>(messageSeverity)) + ": " + vk::to_string(static_cast<vk::DebugUtilsMessageTypeFlagsEXT>(messageTypes)) + ":\n";
|
||||
message += vk::to_string( static_cast<vk::DebugUtilsMessageSeverityFlagBitsEXT>( messageSeverity ) ) + ": " +
|
||||
vk::to_string( static_cast<vk::DebugUtilsMessageTypeFlagsEXT>( messageTypes ) ) + ":\n";
|
||||
message += std::string( "\t" ) + "messageIDName = <" + pCallbackData->pMessageIdName + ">\n";
|
||||
message += std::string( "\t" ) + "messageIdNumber = " + std::to_string( pCallbackData->messageIdNumber ) + "\n";
|
||||
message += std::string( "\t" ) + "message = <" + pCallbackData->pMessage + ">\n";
|
||||
@ -68,8 +76,10 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc(VkDebugUtilsMessageSeverityFlagB
|
||||
for ( uint8_t i = 0; i < pCallbackData->objectCount; i++ )
|
||||
{
|
||||
message += std::string( "\t" ) + "Object " + std::to_string( i ) + "\n";
|
||||
message += std::string("\t\t") + "objectType = " + vk::to_string(static_cast<vk::ObjectType>(pCallbackData->pObjects[i].objectType)) + "\n";
|
||||
message += std::string("\t\t") + "objectHandle = " + std::to_string(pCallbackData->pObjects[i].objectHandle) + "\n";
|
||||
message += std::string( "\t\t" ) + "objectType = " +
|
||||
vk::to_string( static_cast<vk::ObjectType>( pCallbackData->pObjects[i].objectType ) ) + "\n";
|
||||
message +=
|
||||
std::string( "\t\t" ) + "objectHandle = " + std::to_string( pCallbackData->pObjects[i].objectHandle ) + "\n";
|
||||
if ( pCallbackData->pObjects[i].pObjectName )
|
||||
{
|
||||
message += std::string( "\t\t" ) + "objectName = <" + pCallbackData->pObjects[i].pObjectName + ">\n";
|
||||
@ -89,9 +99,10 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugMessageFunc(VkDebugUtilsMessageSeverityFlagB
|
||||
bool checkLayers( std::vector<char const *> const & layers, std::vector<vk::LayerProperties> const & properties )
|
||||
{
|
||||
// return true if all layers are listed in the properties
|
||||
return std::all_of(layers.begin(), layers.end(), [&properties](char const* name)
|
||||
{
|
||||
return std::find_if(properties.begin(), properties.end(), [&name](vk::LayerProperties const& property) { return strcmp(property.layerName, name) == 0; }) != properties.end();
|
||||
return std::all_of( layers.begin(), layers.end(), [&properties]( char const * name ) {
|
||||
return std::find_if( properties.begin(), properties.end(), [&name]( vk::LayerProperties const & property ) {
|
||||
return strcmp( property.layerName, name ) == 0;
|
||||
} ) != properties.end();
|
||||
} );
|
||||
}
|
||||
|
||||
@ -102,7 +113,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
|
||||
// initialize the DipatchLoaderDynamic to use
|
||||
static vk::DynamicLoader dl;
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
|
||||
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
|
||||
#endif
|
||||
|
||||
@ -124,8 +136,12 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
instanceExtensionNames.push_back( VK_EXT_DEBUG_UTILS_EXTENSION_NAME );
|
||||
|
||||
vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
|
||||
vk::InstanceCreateInfo instanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, vk::su::checked_cast<uint32_t>(instanceLayerNames.size()), instanceLayerNames.data(),
|
||||
vk::su::checked_cast<uint32_t>(instanceExtensionNames.size()) , instanceExtensionNames.data() );
|
||||
vk::InstanceCreateInfo instanceCreateInfo( vk::InstanceCreateFlags(),
|
||||
&applicationInfo,
|
||||
vk::su::checked_cast<uint32_t>( instanceLayerNames.size() ),
|
||||
instanceLayerNames.data(),
|
||||
vk::su::checked_cast<uint32_t>( instanceExtensionNames.size() ),
|
||||
instanceExtensionNames.data() );
|
||||
vk::UniqueInstance instance = vk::createInstanceUnique( instanceCreateInfo );
|
||||
|
||||
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
|
||||
@ -133,39 +149,51 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init( *instance );
|
||||
#endif
|
||||
|
||||
pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(instance->getProcAddr("vkCreateDebugUtilsMessengerEXT"));
|
||||
pfnVkCreateDebugUtilsMessengerEXT =
|
||||
reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance->getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
|
||||
if ( !pfnVkCreateDebugUtilsMessengerEXT )
|
||||
{
|
||||
std::cout << "GetInstanceProcAddr: Unable to find pfnVkCreateDebugUtilsMessengerEXT function." << std::endl;
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(instance->getProcAddr("vkDestroyDebugUtilsMessengerEXT"));
|
||||
pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(
|
||||
instance->getProcAddr( "vkDestroyDebugUtilsMessengerEXT" ) );
|
||||
if ( !pfnVkDestroyDebugUtilsMessengerEXT )
|
||||
{
|
||||
std::cout << "GetInstanceProcAddr: Unable to find pfnVkDestroyDebugUtilsMessengerEXT function." << std::endl;
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags(vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning | vk::DebugUtilsMessageSeverityFlagBitsEXT::eError);
|
||||
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags(vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance | vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation);
|
||||
vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = instance->createDebugUtilsMessengerEXTUnique(vk::DebugUtilsMessengerCreateInfoEXT({}, severityFlags, messageTypeFlags, &debugMessageFunc));
|
||||
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning |
|
||||
vk::DebugUtilsMessageSeverityFlagBitsEXT::eError );
|
||||
vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags( vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral |
|
||||
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
|
||||
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
|
||||
vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = instance->createDebugUtilsMessengerEXTUnique(
|
||||
vk::DebugUtilsMessengerCreateInfoEXT( {}, severityFlags, messageTypeFlags, &debugMessageFunc ) );
|
||||
|
||||
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
|
||||
|
||||
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
|
||||
assert( !queueFamilyProperties.empty() );
|
||||
|
||||
auto qfpIt = std::find_if(queueFamilyProperties.begin(), queueFamilyProperties.end(), [](vk::QueueFamilyProperties const& qfp) { return !!(qfp.queueFlags & vk::QueueFlagBits::eGraphics); });
|
||||
auto qfpIt = std::find_if(
|
||||
queueFamilyProperties.begin(), queueFamilyProperties.end(), []( vk::QueueFamilyProperties const & qfp ) {
|
||||
return !!( qfp.queueFlags & vk::QueueFlagBits::eGraphics );
|
||||
} );
|
||||
assert( qfpIt != queueFamilyProperties.end() );
|
||||
uint32_t queueFamilyIndex = static_cast<uint32_t>( std::distance( queueFamilyProperties.begin(), qfpIt ) );
|
||||
|
||||
float queuePriority = 0.0f;
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority);
|
||||
vk::UniqueDevice device = physicalDevice.createDeviceUnique(vk::DeviceCreateInfo(vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo));
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
|
||||
vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority );
|
||||
vk::UniqueDevice device =
|
||||
physicalDevice.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo ) );
|
||||
|
||||
// Create a command pool (not a UniqueCommandPool, for testing purposes!
|
||||
vk::CommandPool commandPool = device->createCommandPool(vk::CommandPoolCreateInfo(vk::CommandPoolCreateFlags(), queueFamilyIndex));
|
||||
vk::CommandPool commandPool =
|
||||
device->createCommandPool( vk::CommandPoolCreateInfo( vk::CommandPoolCreateFlags(), queueFamilyIndex ) );
|
||||
|
||||
// The commandPool is not destroyed automatically (as it's not a UniqueCommandPool.
|
||||
// That is, the device is destroyed before the commmand pool and will trigger a validation error.
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "Events";
|
||||
@ -33,11 +34,15 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
|
||||
|
||||
uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex(physicalDevice.getQueueFamilyProperties());
|
||||
uint32_t graphicsQueueFamilyIndex =
|
||||
vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
|
||||
vk::UniqueDevice device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsQueueFamilyIndex );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsQueueFamilyIndex, 0 );
|
||||
|
||||
@ -74,7 +79,12 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
commandBuffer->reset( vk::CommandBufferResetFlags() );
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
commandBuffer->waitEvents(event.get(), vk::PipelineStageFlagBits::eHost, vk::PipelineStageFlagBits::eBottomOfPipe, nullptr, nullptr, nullptr);
|
||||
commandBuffer->waitEvents( event.get(),
|
||||
vk::PipelineStageFlagBits::eHost,
|
||||
vk::PipelineStageFlagBits::eBottomOfPipe,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr );
|
||||
commandBuffer->end();
|
||||
device->resetFences( fence.get() );
|
||||
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
@ -40,34 +41,58 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(surfaceData.extent));
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice(
|
||||
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( surfaceData.extent ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, depthBufferData.format);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
depthBufferData.format );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, sizeof(texturedCubeData), vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
vk::su::copyToDevice(device, vertexBufferData.deviceMemory, texturedCubeData, sizeof(texturedCubeData) / sizeof(texturedCubeData[0]));
|
||||
vk::su::BufferData vertexBufferData(
|
||||
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
|
||||
vk::su::copyToDevice( device,
|
||||
vertexBufferData.deviceMemory,
|
||||
texturedCubeData,
|
||||
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
@ -76,31 +101,37 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() );
|
||||
|
||||
vk::DescriptorSetLayoutBinding bindings[2] =
|
||||
{
|
||||
vk::DescriptorSetLayoutBinding bindings[2] = {
|
||||
vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ),
|
||||
vk::DescriptorSetLayoutBinding(1, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment, &textureData.textureSampler.get())
|
||||
vk::DescriptorSetLayoutBinding( 1,
|
||||
vk::DescriptorType::eCombinedImageSampler,
|
||||
1,
|
||||
vk::ShaderStageFlagBits::eFragment,
|
||||
&textureData.textureSampler.get() )
|
||||
};
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), 2, bindings));
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 2, bindings ) );
|
||||
|
||||
// Create pipeline layout
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
// Create a single pool to contain data for our descriptor set
|
||||
vk::DescriptorPoolSize poolSizes[2] =
|
||||
{
|
||||
vk::DescriptorPoolSize(vk::DescriptorType::eUniformBuffer, 1),
|
||||
vk::DescriptorPoolSize(vk::DescriptorType::eCombinedImageSampler, 1)
|
||||
};
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(vk::DescriptorPoolCreateInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 2, poolSizes));
|
||||
vk::DescriptorPoolSize poolSizes[2] = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
|
||||
vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 2, poolSizes ) );
|
||||
|
||||
// Populate descriptor sets
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
|
||||
vk::DescriptorImageInfo imageInfo(textureData.textureSampler.get(), textureData.imageData->imageView.get(), vk::ImageLayout::eShaderReadOnlyOptimal);
|
||||
vk::WriteDescriptorSet writeDescriptorSets[2] =
|
||||
{
|
||||
vk::DescriptorImageInfo imageInfo( textureData.textureSampler.get(),
|
||||
textureData.imageData->imageView.get(),
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
vk::WriteDescriptorSet writeDescriptorSets[2] = {
|
||||
vk::WriteDescriptorSet( descriptorSet.get(), 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfo ),
|
||||
vk::WriteDescriptorSet( descriptorSet.get(), 1, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo )
|
||||
};
|
||||
@ -109,25 +140,45 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
/* VULKAN_KEY_END */
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr),
|
||||
sizeof(texturedCubeData[0]), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise, true, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline =
|
||||
vk::su::createGraphicsPipeline( device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
sizeof( texturedCubeData[0] ),
|
||||
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise,
|
||||
true,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(
|
||||
swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
vk::ClearValue clearValues[2];
|
||||
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(0, 0), surfaceData.extent), 2, clearValues);
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr);
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
commandBuffer->draw( 12 * 3, 1, 0, 0 );
|
||||
@ -136,7 +187,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::submitAndWait( device, graphicsQueue, commandBuffer );
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
device->waitIdle();
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "InitTexture";
|
||||
@ -39,11 +40,16 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 50, 50 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
@ -56,17 +62,32 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
// See if we can use a linear tiled image for a texture, if not, we will need a staging buffer for the texture data
|
||||
bool needsStaging = !( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eSampledImage );
|
||||
|
||||
vk::UniqueImage image = device->createImageUnique(vk::ImageCreateInfo(vk::ImageCreateFlags(), vk::ImageType::e2D, format, vk::Extent3D(surfaceData.extent, 1), 1, 1,
|
||||
vk::SampleCountFlagBits::e1, needsStaging ? vk::ImageTiling::eOptimal : vk::ImageTiling::eLinear,
|
||||
vk::ImageUsageFlagBits::eSampled | (needsStaging ? vk::ImageUsageFlagBits::eTransferDst : vk::ImageUsageFlagBits()),
|
||||
vk::SharingMode::eExclusive, 0, nullptr, needsStaging ? vk::ImageLayout::eUndefined : vk::ImageLayout::ePreinitialized));
|
||||
vk::UniqueImage image = device->createImageUnique(
|
||||
vk::ImageCreateInfo( vk::ImageCreateFlags(),
|
||||
vk::ImageType::e2D,
|
||||
format,
|
||||
vk::Extent3D( surfaceData.extent, 1 ),
|
||||
1,
|
||||
1,
|
||||
vk::SampleCountFlagBits::e1,
|
||||
needsStaging ? vk::ImageTiling::eOptimal : vk::ImageTiling::eLinear,
|
||||
vk::ImageUsageFlagBits::eSampled |
|
||||
( needsStaging ? vk::ImageUsageFlagBits::eTransferDst : vk::ImageUsageFlagBits() ),
|
||||
vk::SharingMode::eExclusive,
|
||||
0,
|
||||
nullptr,
|
||||
needsStaging ? vk::ImageLayout::eUndefined : vk::ImageLayout::ePreinitialized ) );
|
||||
|
||||
vk::MemoryRequirements memoryRequirements = device->getImageMemoryRequirements( image.get() );
|
||||
uint32_t memoryTypeIndex = vk::su::findMemoryType(physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits,
|
||||
needsStaging ? vk::MemoryPropertyFlags() : (vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent));
|
||||
uint32_t memoryTypeIndex = vk::su::findMemoryType(
|
||||
physicalDevice.getMemoryProperties(),
|
||||
memoryRequirements.memoryTypeBits,
|
||||
needsStaging ? vk::MemoryPropertyFlags()
|
||||
: ( vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ) );
|
||||
|
||||
// allocate memory
|
||||
vk::UniqueDeviceMemory imageMemory = device->allocateMemoryUnique(vk::MemoryAllocateInfo(memoryRequirements.size, memoryTypeIndex));
|
||||
vk::UniqueDeviceMemory imageMemory =
|
||||
device->allocateMemoryUnique( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
|
||||
|
||||
// bind memory
|
||||
device->bindImageMemory( image.get(), imageMemory.get(), 0 );
|
||||
@ -76,23 +97,32 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
if ( needsStaging )
|
||||
{
|
||||
// Need a staging buffer to map and copy texture into
|
||||
textureBuffer = device->createBufferUnique(vk::BufferCreateInfo(vk::BufferCreateFlags(), surfaceData.extent.width * surfaceData.extent.height * 4, vk::BufferUsageFlagBits::eTransferSrc));
|
||||
textureBuffer =
|
||||
device->createBufferUnique( vk::BufferCreateInfo( vk::BufferCreateFlags(),
|
||||
surfaceData.extent.width * surfaceData.extent.height * 4,
|
||||
vk::BufferUsageFlagBits::eTransferSrc ) );
|
||||
|
||||
memoryRequirements = device->getBufferMemoryRequirements( textureBuffer.get() );
|
||||
memoryTypeIndex = vk::su::findMemoryType(physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent);
|
||||
memoryTypeIndex =
|
||||
vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
|
||||
memoryRequirements.memoryTypeBits,
|
||||
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
|
||||
|
||||
// allocate memory
|
||||
textureBufferMemory = device->allocateMemoryUnique(vk::MemoryAllocateInfo(memoryRequirements.size, memoryTypeIndex));
|
||||
textureBufferMemory =
|
||||
device->allocateMemoryUnique( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
|
||||
|
||||
// bind memory
|
||||
device->bindBufferMemory( textureBuffer.get(), textureBufferMemory.get(), 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
vk::SubresourceLayout subresourceLayout = device->getImageSubresourceLayout(image.get(), vk::ImageSubresource(vk::ImageAspectFlagBits::eColor));
|
||||
vk::SubresourceLayout subresourceLayout =
|
||||
device->getImageSubresourceLayout( image.get(), vk::ImageSubresource( vk::ImageAspectFlagBits::eColor ) );
|
||||
}
|
||||
|
||||
void* data = device->mapMemory(needsStaging ? textureBufferMemory.get() : imageMemory.get(), 0, memoryRequirements.size, vk::MemoryMapFlags());
|
||||
void * data = device->mapMemory(
|
||||
needsStaging ? textureBufferMemory.get() : imageMemory.get(), 0, memoryRequirements.size, vk::MemoryMapFlags() );
|
||||
|
||||
// Checkerboard of 16x16 pixel squares
|
||||
unsigned char * pImageMemory = static_cast<unsigned char *>( data );
|
||||
@ -115,27 +145,59 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
if ( needsStaging )
|
||||
{
|
||||
// Since we're going to blit to the texture image, set its layout to eTransferDstOptimal
|
||||
vk::su::setImageLayout(commandBuffer, image.get(), format, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal);
|
||||
vk::BufferImageCopy copyRegion(0, surfaceData.extent.width, surfaceData.extent.height, vk::ImageSubresourceLayers(vk::ImageAspectFlagBits::eColor, 0, 0, 1), vk::Offset3D(0, 0, 0), vk::Extent3D(surfaceData.extent, 1));
|
||||
commandBuffer->copyBufferToImage(textureBuffer.get(), image.get(), vk::ImageLayout::eTransferDstOptimal, copyRegion);
|
||||
vk::su::setImageLayout(
|
||||
commandBuffer, image.get(), format, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal );
|
||||
vk::BufferImageCopy copyRegion( 0,
|
||||
surfaceData.extent.width,
|
||||
surfaceData.extent.height,
|
||||
vk::ImageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 ),
|
||||
vk::Offset3D( 0, 0, 0 ),
|
||||
vk::Extent3D( surfaceData.extent, 1 ) );
|
||||
commandBuffer->copyBufferToImage(
|
||||
textureBuffer.get(), image.get(), vk::ImageLayout::eTransferDstOptimal, copyRegion );
|
||||
// Set the layout for the texture image from eTransferDstOptimal to SHADER_READ_ONLY
|
||||
vk::su::setImageLayout(commandBuffer, image.get(), format, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal);
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
image.get(),
|
||||
format,
|
||||
vk::ImageLayout::eTransferDstOptimal,
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we can use the linear tiled image as a texture, just do it
|
||||
vk::su::setImageLayout(commandBuffer, image.get(), format, vk::ImageLayout::ePreinitialized, vk::ImageLayout::eShaderReadOnlyOptimal);
|
||||
vk::su::setImageLayout(
|
||||
commandBuffer, image.get(), format, vk::ImageLayout::ePreinitialized, vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
}
|
||||
|
||||
commandBuffer->end();
|
||||
vk::su::submitAndWait( device, graphicsQueue, commandBuffer );
|
||||
|
||||
vk::UniqueSampler sampler = device->createSamplerUnique(vk::SamplerCreateInfo(vk::SamplerCreateFlags(), vk::Filter::eNearest, vk::Filter::eNearest, vk::SamplerMipmapMode::eNearest,
|
||||
vk::SamplerAddressMode::eClampToEdge, vk::SamplerAddressMode::eClampToEdge, vk::SamplerAddressMode::eClampToEdge, 0.0f, false, 1.0f, false, vk::CompareOp::eNever, 0.0f, 0.0f,
|
||||
vk::UniqueSampler sampler =
|
||||
device->createSamplerUnique( vk::SamplerCreateInfo( vk::SamplerCreateFlags(),
|
||||
vk::Filter::eNearest,
|
||||
vk::Filter::eNearest,
|
||||
vk::SamplerMipmapMode::eNearest,
|
||||
vk::SamplerAddressMode::eClampToEdge,
|
||||
vk::SamplerAddressMode::eClampToEdge,
|
||||
vk::SamplerAddressMode::eClampToEdge,
|
||||
0.0f,
|
||||
false,
|
||||
1.0f,
|
||||
false,
|
||||
vk::CompareOp::eNever,
|
||||
0.0f,
|
||||
0.0f,
|
||||
vk::BorderColor::eFloatOpaqueWhite ) );
|
||||
|
||||
vk::ComponentMapping componentMapping(vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA);
|
||||
vk::ImageViewCreateInfo imageViewCreateInfo(vk::ImageViewCreateFlags(), image.get(), vk::ImageViewType::e2D, format, componentMapping, vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1));
|
||||
vk::ComponentMapping componentMapping(
|
||||
vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA );
|
||||
vk::ImageViewCreateInfo imageViewCreateInfo(
|
||||
vk::ImageViewCreateFlags(),
|
||||
image.get(),
|
||||
vk::ImageViewType::e2D,
|
||||
format,
|
||||
componentMapping,
|
||||
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
|
||||
vk::UniqueImageView imageView = device->createImageViewUnique( imageViewCreateInfo );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
@ -75,100 +76,192 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
// Create a framebuffer with 2 attachments, one the color attachment the shaders render into, and the other an input attachment which
|
||||
// will be cleared to yellow, and then used by the shaders to color the drawn triangle. Final result should be a yellow triangle
|
||||
// Create a framebuffer with 2 attachments, one the color attachment the shaders render into, and the other an input
|
||||
// attachment which will be cleared to yellow, and then used by the shaders to color the drawn triangle. Final
|
||||
// result should be a yellow triangle
|
||||
|
||||
// Create the image that will be used as the input attachment
|
||||
// The image for the color attachment is the presentable image already created as part of the SwapChainData
|
||||
vk::UniqueImage inputImage = device->createImageUnique(vk::ImageCreateInfo(vk::ImageCreateFlags(), vk::ImageType::e2D, swapChainData.colorFormat, vk::Extent3D(surfaceData.extent, 1), 1, 1,
|
||||
vk::SampleCountFlagBits::e1, vk::ImageTiling::eOptimal, vk::ImageUsageFlagBits::eInputAttachment | vk::ImageUsageFlagBits::eTransferDst));
|
||||
vk::UniqueImage inputImage = device->createImageUnique(
|
||||
vk::ImageCreateInfo( vk::ImageCreateFlags(),
|
||||
vk::ImageType::e2D,
|
||||
swapChainData.colorFormat,
|
||||
vk::Extent3D( surfaceData.extent, 1 ),
|
||||
1,
|
||||
1,
|
||||
vk::SampleCountFlagBits::e1,
|
||||
vk::ImageTiling::eOptimal,
|
||||
vk::ImageUsageFlagBits::eInputAttachment | vk::ImageUsageFlagBits::eTransferDst ) );
|
||||
|
||||
vk::MemoryRequirements memoryRequirements = device->getImageMemoryRequirements( inputImage.get() );
|
||||
uint32_t memoryTypeIndex = vk::su::findMemoryType(physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlags());
|
||||
vk::UniqueDeviceMemory inputMemory = device->allocateMemoryUnique(vk::MemoryAllocateInfo(memoryRequirements.size, memoryTypeIndex));
|
||||
uint32_t memoryTypeIndex = vk::su::findMemoryType(
|
||||
physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlags() );
|
||||
vk::UniqueDeviceMemory inputMemory =
|
||||
device->allocateMemoryUnique( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
|
||||
device->bindImageMemory( inputImage.get(), inputMemory.get(), 0 );
|
||||
|
||||
// Set the image layout to TRANSFER_DST_OPTIMAL to be ready for clear
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
vk::su::setImageLayout(commandBuffer, inputImage.get(), swapChainData.colorFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal);
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
inputImage.get(),
|
||||
swapChainData.colorFormat,
|
||||
vk::ImageLayout::eUndefined,
|
||||
vk::ImageLayout::eTransferDstOptimal );
|
||||
|
||||
commandBuffer->clearColorImage(inputImage.get(), vk::ImageLayout::eTransferDstOptimal, vk::ClearColorValue(std::array<float, 4>({ {1.0f, 1.0f, 0.0f, 0.0f} })),
|
||||
vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS));
|
||||
commandBuffer->clearColorImage(
|
||||
inputImage.get(),
|
||||
vk::ImageLayout::eTransferDstOptimal,
|
||||
vk::ClearColorValue( std::array<float, 4>( { { 1.0f, 1.0f, 0.0f, 0.0f } } ) ),
|
||||
vk::ImageSubresourceRange(
|
||||
vk::ImageAspectFlagBits::eColor, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS ) );
|
||||
|
||||
// Set the image layout to SHADER_READONLY_OPTIMAL for use by the shaders
|
||||
vk::su::setImageLayout(commandBuffer, inputImage.get(), swapChainData.colorFormat, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal);
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
inputImage.get(),
|
||||
swapChainData.colorFormat,
|
||||
vk::ImageLayout::eTransferDstOptimal,
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
|
||||
vk::ComponentMapping componentMapping(vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA);
|
||||
vk::ImageViewCreateInfo imageViewCreateInfo(vk::ImageViewCreateFlags(), inputImage.get(), vk::ImageViewType::e2D, swapChainData.colorFormat, componentMapping, vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1));
|
||||
vk::ComponentMapping componentMapping(
|
||||
vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA );
|
||||
vk::ImageViewCreateInfo imageViewCreateInfo(
|
||||
vk::ImageViewCreateFlags(),
|
||||
inputImage.get(),
|
||||
vk::ImageViewType::e2D,
|
||||
swapChainData.colorFormat,
|
||||
componentMapping,
|
||||
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
|
||||
vk::UniqueImageView inputAttachmentView = device->createImageViewUnique( imageViewCreateInfo );
|
||||
|
||||
vk::DescriptorSetLayoutBinding layoutBinding(0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment);
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), 1, &layoutBinding));
|
||||
vk::DescriptorSetLayoutBinding layoutBinding(
|
||||
0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment );
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 1, &layoutBinding ) );
|
||||
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
vk::AttachmentDescription attachments[2] =
|
||||
{
|
||||
// First attachment is the color attachment - clear at the beginning of the renderpass and transition layout to PRESENT_SRC_KHR at the end of renderpass
|
||||
vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), swapChainData.colorFormat, vk::SampleCountFlagBits::e1, vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eStore,
|
||||
vk::AttachmentLoadOp::eDontCare, vk::AttachmentStoreOp::eDontCare, vk::ImageLayout::eUndefined, vk::ImageLayout::ePresentSrcKHR),
|
||||
vk::AttachmentDescription attachments[2] = {
|
||||
// First attachment is the color attachment - clear at the beginning of the renderpass and transition layout to
|
||||
// PRESENT_SRC_KHR at the end of renderpass
|
||||
vk::AttachmentDescription( vk::AttachmentDescriptionFlags(),
|
||||
swapChainData.colorFormat,
|
||||
vk::SampleCountFlagBits::e1,
|
||||
vk::AttachmentLoadOp::eClear,
|
||||
vk::AttachmentStoreOp::eStore,
|
||||
vk::AttachmentLoadOp::eDontCare,
|
||||
vk::AttachmentStoreOp::eDontCare,
|
||||
vk::ImageLayout::eUndefined,
|
||||
vk::ImageLayout::ePresentSrcKHR ),
|
||||
// Second attachment is input attachment. Once cleared it should have width*height yellow pixels.
|
||||
// Doing a subpassLoad in the fragment shader should give the shader the color at the fragments x,y location from the input attachment
|
||||
vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), swapChainData.colorFormat, vk::SampleCountFlagBits::e1, vk::AttachmentLoadOp::eLoad, vk::AttachmentStoreOp::eDontCare,
|
||||
vk::AttachmentLoadOp::eDontCare, vk::AttachmentStoreOp::eDontCare, vk::ImageLayout::eShaderReadOnlyOptimal, vk::ImageLayout::eShaderReadOnlyOptimal)
|
||||
// Doing a subpassLoad in the fragment shader should give the shader the color at the fragments x,y location from
|
||||
// the input attachment
|
||||
vk::AttachmentDescription( vk::AttachmentDescriptionFlags(),
|
||||
swapChainData.colorFormat,
|
||||
vk::SampleCountFlagBits::e1,
|
||||
vk::AttachmentLoadOp::eLoad,
|
||||
vk::AttachmentStoreOp::eDontCare,
|
||||
vk::AttachmentLoadOp::eDontCare,
|
||||
vk::AttachmentStoreOp::eDontCare,
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal )
|
||||
};
|
||||
vk::AttachmentReference colorReference( 0, vk::ImageLayout::eColorAttachmentOptimal );
|
||||
vk::AttachmentReference inputReference( 1, vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
vk::SubpassDescription subPass(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, 1, &inputReference, 1, &colorReference);
|
||||
vk::UniqueRenderPass renderPass = device->createRenderPassUnique(vk::RenderPassCreateInfo(vk::RenderPassCreateFlags(), 2, attachments, 1, &subPass));
|
||||
vk::SubpassDescription subPass(
|
||||
vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, 1, &inputReference, 1, &colorReference );
|
||||
vk::UniqueRenderPass renderPass = device->createRenderPassUnique(
|
||||
vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), 2, attachments, 1, &subPass ) );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, inputAttachmentView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, inputAttachmentView, surfaceData.extent );
|
||||
|
||||
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eInputAttachment, 1 );
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(vk::DescriptorPoolCreateInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 1, &poolSize));
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 1, &poolSize ) );
|
||||
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::DescriptorImageInfo inputImageInfo(nullptr, inputAttachmentView.get(), vk::ImageLayout::eShaderReadOnlyOptimal);
|
||||
vk::WriteDescriptorSet writeDescriptorSet(descriptorSet.get(), 0, 0, 1, vk::DescriptorType::eInputAttachment, &inputImageInfo);
|
||||
vk::DescriptorImageInfo inputImageInfo(
|
||||
nullptr, inputAttachmentView.get(), vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
vk::WriteDescriptorSet writeDescriptorSet(
|
||||
descriptorSet.get(), 0, 0, 1, vk::DescriptorType::eInputAttachment, &inputImageInfo );
|
||||
device->updateDescriptorSets( vk::ArrayProxy<const vk::WriteDescriptorSet>( 1, &writeDescriptorSet ), nullptr );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr), 0, {},
|
||||
vk::FrontFace::eClockwise, false, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline =
|
||||
vk::su::createGraphicsPipeline( device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
0,
|
||||
{},
|
||||
vk::FrontFace::eClockwise,
|
||||
false,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
|
||||
vk::ResultValue<uint32_t> result = device->acquireNextImage2KHR(vk::AcquireNextImageInfoKHR(swapChainData.swapChain.get(), UINT64_MAX, imageAcquiredSemaphore.get(), {}, 1));
|
||||
vk::ResultValue<uint32_t> result = device->acquireNextImage2KHR(
|
||||
vk::AcquireNextImageInfoKHR( swapChainData.swapChain.get(), UINT64_MAX, imageAcquiredSemaphore.get(), {}, 1 ) );
|
||||
assert( result.result == vk::Result::eSuccess );
|
||||
uint32_t currentBuffer = result.value;
|
||||
|
||||
vk::ClearValue clearValue;
|
||||
clearValue.color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
commandBuffer->beginRenderPass(vk::RenderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer].get(), vk::Rect2D(vk::Offset2D(0, 0), surfaceData.extent), 1, &clearValue), vk::SubpassContents::eInline);
|
||||
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
1,
|
||||
&clearValue ),
|
||||
vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr);
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
commandBuffer->draw( 3, 1, 0, 0 );
|
||||
|
@ -13,9 +13,11 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
// VulkanHpp Samples : InstanceExtensionProperties
|
||||
// Get global extension properties to know what extension are available to enable at CreateInstance time.
|
||||
// Get global extension properties to know what extension are available to enable at CreateInstance
|
||||
// time.
|
||||
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
@ -32,7 +34,11 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
// sort the extensions alphabetically
|
||||
|
||||
std::sort(extensionProperties.begin(), extensionProperties.end(), [](vk::ExtensionProperties const& a, vk::ExtensionProperties const& b) { return strcmp(a.extensionName, b.extensionName) < 0; });
|
||||
std::sort( extensionProperties.begin(),
|
||||
extensionProperties.end(),
|
||||
[]( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) {
|
||||
return strcmp( a.extensionName, b.extensionName ) < 0;
|
||||
} );
|
||||
|
||||
std::cout << "Instance Extensions:" << std::endl;
|
||||
for ( auto const & ep : extensionProperties )
|
||||
|
@ -16,6 +16,7 @@
|
||||
// Get list of global layers and their associated extensions, if any.
|
||||
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
@ -25,9 +26,9 @@ static char const* EngineName = "Vulkan.hpp";
|
||||
|
||||
struct PropertyData
|
||||
{
|
||||
PropertyData(vk::LayerProperties const& layerProperties_, std::vector<vk::ExtensionProperties> const& extensionProperties_)
|
||||
: layerProperties(layerProperties_)
|
||||
, extensionProperties(extensionProperties_)
|
||||
PropertyData( vk::LayerProperties const & layerProperties_,
|
||||
std::vector<vk::ExtensionProperties> const & extensionProperties_ )
|
||||
: layerProperties( layerProperties_ ), extensionProperties( extensionProperties_ )
|
||||
{}
|
||||
|
||||
vk::LayerProperties layerProperties;
|
||||
@ -47,7 +48,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
for ( auto const & layerProperty : layerProperties )
|
||||
{
|
||||
std::vector<vk::ExtensionProperties> extensionProperties = vk::enumerateInstanceExtensionProperties(std::string(layerProperty.layerName));
|
||||
std::vector<vk::ExtensionProperties> extensionProperties =
|
||||
vk::enumerateInstanceExtensionProperties( std::string( layerProperty.layerName ) );
|
||||
propertyData.push_back( PropertyData( layerProperty, extensionProperties ) );
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,8 @@
|
||||
// VulkanHpp Samples : InstanceLayerProperties
|
||||
// Get global layer properties to know what layers are available to enable at CreateInstance time.
|
||||
|
||||
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
@ -41,7 +41,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
{
|
||||
std::cout << lp.layerName << ":" << std::endl;
|
||||
std::cout << "\tVersion: " << lp.implementationVersion << std::endl;
|
||||
std::cout << "\tAPI Version: (" << (lp.specVersion >> 22) << "." << ((lp.specVersion >> 12) & 0x03FF) << "." << (lp.specVersion & 0xFFF) << ")" << std::endl;
|
||||
std::cout << "\tAPI Version: (" << ( lp.specVersion >> 22 ) << "." << ( ( lp.specVersion >> 12 ) & 0x03FF ) << "."
|
||||
<< ( lp.specVersion & 0xFFF ) << ")" << std::endl;
|
||||
std::cout << "\tDescription: " << lp.description << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
// Get the version of instance-level functionality supported by the implementation.
|
||||
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
@ -24,7 +25,8 @@ static char const* EngineName = "Vulkan.hpp";
|
||||
|
||||
std::string decodeAPIVersion( uint32_t apiVersion )
|
||||
{
|
||||
return std::to_string(VK_VERSION_MAJOR(apiVersion)) + "." + std::to_string(VK_VERSION_MINOR(apiVersion)) + "." + std::to_string(VK_VERSION_PATCH(apiVersion));
|
||||
return std::to_string( VK_VERSION_MAJOR( apiVersion ) ) + "." + std::to_string( VK_VERSION_MINOR( apiVersion ) ) +
|
||||
"." + std::to_string( VK_VERSION_PATCH( apiVersion ) );
|
||||
}
|
||||
|
||||
int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
@ -90,17 +91,29 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
@ -109,79 +122,121 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
textureData.setImage( device, commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(surfaceData.extent));
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice(
|
||||
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( surfaceData.extent ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, depthBufferData.format);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
depthBufferData.format );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, sizeof(texturedCubeData), vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
vk::su::copyToDevice(device, vertexBufferData.deviceMemory, texturedCubeData, sizeof(texturedCubeData) / sizeof(texturedCubeData[0]));
|
||||
vk::su::BufferData vertexBufferData(
|
||||
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
|
||||
vk::su::copyToDevice( device,
|
||||
vertexBufferData.deviceMemory,
|
||||
texturedCubeData,
|
||||
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
// Create first layout to contain uniform buffer data
|
||||
vk::DescriptorSetLayoutBinding uniformBinding(0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex);
|
||||
vk::UniqueDescriptorSetLayout uniformLayout = device->createDescriptorSetLayoutUnique(vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), 1, &uniformBinding));
|
||||
vk::DescriptorSetLayoutBinding uniformBinding(
|
||||
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
|
||||
vk::UniqueDescriptorSetLayout uniformLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 1, &uniformBinding ) );
|
||||
|
||||
// Create second layout containing combined sampler/image data
|
||||
vk::DescriptorSetLayoutBinding sampler2DBinding(0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eVertex);
|
||||
vk::UniqueDescriptorSetLayout samplerLayout = device->createDescriptorSetLayoutUnique(vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), 1, &sampler2DBinding));
|
||||
vk::DescriptorSetLayoutBinding sampler2DBinding(
|
||||
0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eVertex );
|
||||
vk::UniqueDescriptorSetLayout samplerLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 1, &sampler2DBinding ) );
|
||||
|
||||
// Create pipeline layout with multiple descriptor sets
|
||||
std::array<vk::DescriptorSetLayout, 2> descriptorSetLayouts = { uniformLayout.get(), samplerLayout.get() };
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 2, descriptorSetLayouts.data()));
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 2, descriptorSetLayouts.data() ) );
|
||||
|
||||
// Create a single pool to contain data for our two descriptor sets
|
||||
vk::DescriptorPoolSize poolSizes[2] =
|
||||
{
|
||||
vk::DescriptorPoolSize(vk::DescriptorType::eUniformBuffer, 1),
|
||||
vk::DescriptorPoolSize(vk::DescriptorType::eCombinedImageSampler, 1)
|
||||
};
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(vk::DescriptorPoolCreateInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 2, 2, poolSizes));
|
||||
vk::DescriptorPoolSize poolSizes[2] = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
|
||||
vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 2, 2, poolSizes ) );
|
||||
|
||||
// Populate descriptor sets
|
||||
std::vector<vk::UniqueDescriptorSet> descriptorSets = device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(descriptorPool.get(), 2, descriptorSetLayouts.data()));
|
||||
std::vector<vk::UniqueDescriptorSet> descriptorSets = device->allocateDescriptorSetsUnique(
|
||||
vk::DescriptorSetAllocateInfo( descriptorPool.get(), 2, descriptorSetLayouts.data() ) );
|
||||
|
||||
// Populate with info about our uniform buffer
|
||||
vk::DescriptorBufferInfo uniformBufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
|
||||
vk::DescriptorImageInfo textureImageInfo(textureData.textureSampler.get(), textureData.imageData->imageView.get(), vk::ImageLayout::eShaderReadOnlyOptimal);
|
||||
std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets =
|
||||
{
|
||||
vk::WriteDescriptorSet(descriptorSets[0].get(), 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &uniformBufferInfo),
|
||||
vk::WriteDescriptorSet(descriptorSets[1].get(), 0, 0, 1, vk::DescriptorType::eCombinedImageSampler, &textureImageInfo)
|
||||
vk::DescriptorImageInfo textureImageInfo( textureData.textureSampler.get(),
|
||||
textureData.imageData->imageView.get(),
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = {
|
||||
vk::WriteDescriptorSet(
|
||||
descriptorSets[0].get(), 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &uniformBufferInfo ),
|
||||
vk::WriteDescriptorSet(
|
||||
descriptorSets[1].get(), 0, 0, 1, vk::DescriptorType::eCombinedImageSampler, &textureImageInfo )
|
||||
};
|
||||
device->updateDescriptorSets( writeDescriptorSets, nullptr );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr),
|
||||
sizeof(texturedCubeData[0]), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise, true, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline =
|
||||
vk::su::createGraphicsPipeline( device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
sizeof( texturedCubeData[0] ),
|
||||
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise,
|
||||
true,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
|
||||
// Get the index of the next available swapchain image:
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(
|
||||
swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
vk::ClearValue clearValues[2];
|
||||
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(0, 0), surfaceData.extent), 2, clearValues);
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, { descriptorSets[0].get(), descriptorSets[1].get() }, nullptr);
|
||||
commandBuffer->bindDescriptorSets( vk::PipelineBindPoint::eGraphics,
|
||||
pipelineLayout.get(),
|
||||
0,
|
||||
{ descriptorSets[0].get(), descriptorSets[1].get() },
|
||||
nullptr );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
commandBuffer->draw( 12 * 3, 1, 0, 0 );
|
||||
@ -197,7 +252,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
device->waitIdle();
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
@ -40,67 +41,118 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(surfaceData.extent));
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice(
|
||||
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( surfaceData.extent ) );
|
||||
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device, { {vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex} });
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, depthBufferData.format);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
depthBufferData.format );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, sizeof(coloredCubeData), vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
vk::su::copyToDevice(device, vertexBufferData.deviceMemory, coloredCubeData, sizeof(coloredCubeData) / sizeof(coloredCubeData[0]));
|
||||
vk::su::BufferData vertexBufferData(
|
||||
physicalDevice, device, sizeof( coloredCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
|
||||
vk::su::copyToDevice( device,
|
||||
vertexBufferData.deviceMemory,
|
||||
coloredCubeData,
|
||||
sizeof( coloredCubeData ) / sizeof( coloredCubeData[0] ) );
|
||||
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(device, { {vk::DescriptorType::eUniformBuffer, 1} });
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::UniqueDescriptorPool descriptorPool =
|
||||
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::su::updateDescriptorSets(device, descriptorSet, {{vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView()}}, {});
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView() } },
|
||||
{} );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr),
|
||||
sizeof(coloredCubeData[0]), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise, true, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(
|
||||
device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
sizeof( coloredCubeData[0] ),
|
||||
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise,
|
||||
true,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique(vk::SemaphoreCreateInfo(vk::SemaphoreCreateFlags()));
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore =
|
||||
device->createSemaphoreUnique( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
|
||||
|
||||
// Get the index of the next available swapchain image:
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), UINT64_MAX, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer =
|
||||
device->acquireNextImageKHR( swapChainData.swapChain.get(), UINT64_MAX, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
/* Allocate a uniform buffer that will take query results. */
|
||||
vk::UniqueBuffer queryResultBuffer = device->createBufferUnique(vk::BufferCreateInfo(vk::BufferCreateFlags(), 4 * sizeof(uint64_t), vk::BufferUsageFlagBits::eUniformBuffer | vk::BufferUsageFlagBits::eTransferDst));
|
||||
vk::UniqueBuffer queryResultBuffer = device->createBufferUnique(
|
||||
vk::BufferCreateInfo( vk::BufferCreateFlags(),
|
||||
4 * sizeof( uint64_t ),
|
||||
vk::BufferUsageFlagBits::eUniformBuffer | vk::BufferUsageFlagBits::eTransferDst ) );
|
||||
|
||||
vk::MemoryRequirements memoryRequirements = device->getBufferMemoryRequirements( queryResultBuffer.get() );
|
||||
uint32_t memoryTypeIndex = vk::su::findMemoryType(physicalDevice.getMemoryProperties(), memoryRequirements.memoryTypeBits, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent);
|
||||
vk::UniqueDeviceMemory queryResultMemory = device->allocateMemoryUnique(vk::MemoryAllocateInfo(memoryRequirements.size, memoryTypeIndex));
|
||||
uint32_t memoryTypeIndex =
|
||||
vk::su::findMemoryType( physicalDevice.getMemoryProperties(),
|
||||
memoryRequirements.memoryTypeBits,
|
||||
vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent );
|
||||
vk::UniqueDeviceMemory queryResultMemory =
|
||||
device->allocateMemoryUnique( vk::MemoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ) );
|
||||
|
||||
device->bindBufferMemory( queryResultBuffer.get(), queryResultMemory.get(), 0 );
|
||||
|
||||
vk::UniqueQueryPool queryPool = device->createQueryPoolUnique(vk::QueryPoolCreateInfo(vk::QueryPoolCreateFlags(), vk::QueryType::eOcclusion, 2, vk::QueryPipelineStatisticFlags()));
|
||||
vk::UniqueQueryPool queryPool = device->createQueryPoolUnique( vk::QueryPoolCreateInfo(
|
||||
vk::QueryPoolCreateFlags(), vk::QueryType::eOcclusion, 2, vk::QueryPipelineStatisticFlags() ) );
|
||||
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) );
|
||||
commandBuffer->resetQueryPool( queryPool.get(), 0, 2 );
|
||||
@ -108,13 +160,25 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
vk::ClearValue clearValues[2];
|
||||
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
commandBuffer->beginRenderPass(vk::RenderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(), surfaceData.extent), 2, clearValues), vk::SubpassContents::eInline);
|
||||
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D(), surfaceData.extent ),
|
||||
2,
|
||||
clearValues ),
|
||||
vk::SubpassContents::eInline );
|
||||
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), {});
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), {} );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
commandBuffer->beginQuery( queryPool.get(), 0, vk::QueryControlFlags() );
|
||||
@ -125,7 +189,13 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
commandBuffer->endRenderPass();
|
||||
commandBuffer->endQuery( queryPool.get(), 1 );
|
||||
|
||||
commandBuffer->copyQueryPoolResults(queryPool.get(), 0, 2, queryResultBuffer.get(), 0, sizeof(uint64_t), vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait);
|
||||
commandBuffer->copyQueryPoolResults( queryPool.get(),
|
||||
0,
|
||||
2,
|
||||
queryResultBuffer.get(),
|
||||
0,
|
||||
sizeof( uint64_t ),
|
||||
vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
|
||||
commandBuffer->end();
|
||||
|
||||
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
|
||||
@ -137,14 +207,20 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
graphicsQueue.waitIdle();
|
||||
|
||||
uint64_t samplesPassed[2];
|
||||
device->getQueryPoolResults(queryPool.get(), 0, 2, vk::ArrayProxy<uint64_t>(4, samplesPassed), sizeof(uint64_t), vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait);
|
||||
device->getQueryPoolResults( queryPool.get(),
|
||||
0,
|
||||
2,
|
||||
vk::ArrayProxy<uint64_t>( 4, samplesPassed ),
|
||||
sizeof( uint64_t ),
|
||||
vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait );
|
||||
|
||||
std::cout << "vkGetQueryPoolResults data\n";
|
||||
std::cout << "samples_passed[0] = " << samplesPassed[0] << "\n";
|
||||
std::cout << "samples_passed[1] = " << samplesPassed[1] << "\n";
|
||||
|
||||
/* Read back query result from buffer */
|
||||
uint64_t *samplesPassedPtr = static_cast<uint64_t*>(device->mapMemory(queryResultMemory.get(), 0, memoryRequirements.size, vk::MemoryMapFlags()));
|
||||
uint64_t * samplesPassedPtr = static_cast<uint64_t *>(
|
||||
device->mapMemory( queryResultMemory.get(), 0, memoryRequirements.size, vk::MemoryMapFlags() ) );
|
||||
|
||||
std::cout << "vkCmdCopyQueryPoolResults data\n";
|
||||
std::cout << "samples_passed[0] = " << samplesPassedPtr[0] << "\n";
|
||||
@ -155,7 +231,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
static char const * AppName = "DeviceExtensionProperties";
|
||||
@ -39,10 +40,15 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
for ( size_t i = 0; i < physicalDevices.size(); i++ )
|
||||
{
|
||||
std::cout << "PhysicalDevice " << i << "\n";
|
||||
std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
|
||||
std::vector<vk::ExtensionProperties> extensionProperties =
|
||||
physicalDevices[i].enumerateDeviceExtensionProperties();
|
||||
|
||||
// sort the extensions alphabetically
|
||||
std::sort(extensionProperties.begin(), extensionProperties.end(), [](vk::ExtensionProperties const& a, vk::ExtensionProperties const& b) { return strcmp(a.extensionName, b.extensionName) < 0; });
|
||||
std::sort( extensionProperties.begin(),
|
||||
extensionProperties.end(),
|
||||
[]( vk::ExtensionProperties const & a, vk::ExtensionProperties const & b ) {
|
||||
return strcmp( a.extensionName, b.extensionName ) < 0;
|
||||
} );
|
||||
for ( auto const & ep : extensionProperties )
|
||||
{
|
||||
std::cout << "\t" << ep.extensionName << ":" << std::endl;
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
static char const * AppName = "PhysicalDeviceFeatures";
|
||||
@ -40,198 +41,314 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
for ( size_t i = 0; i < physicalDevices.size(); i++ )
|
||||
{
|
||||
// some features are only valid, if a corresponding extension is available!
|
||||
std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
|
||||
std::vector<vk::ExtensionProperties> extensionProperties =
|
||||
physicalDevices[i].enumerateDeviceExtensionProperties();
|
||||
|
||||
std::cout << "PhysicalDevice " << i << "\n";
|
||||
auto features2 = physicalDevices[i].getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDevice16BitStorageFeatures, vk::PhysicalDevice8BitStorageFeaturesKHR,
|
||||
vk::PhysicalDeviceASTCDecodeFeaturesEXT, vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT,
|
||||
vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT, vk::PhysicalDeviceCoherentMemoryFeaturesAMD,
|
||||
vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV, vk::PhysicalDeviceConditionalRenderingFeaturesEXT,
|
||||
vk::PhysicalDeviceCooperativeMatrixFeaturesNV, vk::PhysicalDeviceCornerSampledImageFeaturesNV,
|
||||
vk::PhysicalDeviceCoverageReductionModeFeaturesNV, vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV,
|
||||
vk::PhysicalDeviceDepthClipEnableFeaturesEXT, vk::PhysicalDeviceDescriptorIndexingFeaturesEXT, vk::PhysicalDeviceExclusiveScissorFeaturesNV,
|
||||
vk::PhysicalDeviceFragmentDensityMapFeaturesEXT, vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV,
|
||||
vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT, vk::PhysicalDeviceHostQueryResetFeaturesEXT,
|
||||
vk::PhysicalDeviceImagelessFramebufferFeaturesKHR, vk::PhysicalDeviceIndexTypeUint8FeaturesEXT,
|
||||
vk::PhysicalDeviceInlineUniformBlockFeaturesEXT, vk::PhysicalDeviceLineRasterizationFeaturesEXT,
|
||||
vk::PhysicalDeviceMemoryPriorityFeaturesEXT, vk::PhysicalDeviceMeshShaderFeaturesNV, vk::PhysicalDeviceMultiviewFeatures,
|
||||
vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR, vk::PhysicalDeviceProtectedMemoryFeatures,
|
||||
vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV, vk::PhysicalDeviceSamplerYcbcrConversionFeatures,
|
||||
vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT, vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR,
|
||||
vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT, vk::PhysicalDeviceShaderDrawParametersFeatures,
|
||||
vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR, vk::PhysicalDeviceShaderImageFootprintFeaturesNV,
|
||||
vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL, vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV,
|
||||
vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR, vk::PhysicalDeviceShadingRateImageFeaturesNV,
|
||||
vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT, vk::PhysicalDeviceTexelBufferAlignmentFeaturesEXT,
|
||||
vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT, vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR,
|
||||
vk::PhysicalDeviceTransformFeedbackFeaturesEXT, vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR,
|
||||
vk::PhysicalDeviceVariablePointersFeatures, vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT,
|
||||
vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR, vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT>();
|
||||
auto features2 = physicalDevices[i]
|
||||
.getFeatures2<vk::PhysicalDeviceFeatures2,
|
||||
vk::PhysicalDevice16BitStorageFeatures,
|
||||
vk::PhysicalDevice8BitStorageFeaturesKHR,
|
||||
vk::PhysicalDeviceASTCDecodeFeaturesEXT,
|
||||
vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT,
|
||||
vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT,
|
||||
vk::PhysicalDeviceCoherentMemoryFeaturesAMD,
|
||||
vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV,
|
||||
vk::PhysicalDeviceConditionalRenderingFeaturesEXT,
|
||||
vk::PhysicalDeviceCooperativeMatrixFeaturesNV,
|
||||
vk::PhysicalDeviceCornerSampledImageFeaturesNV,
|
||||
vk::PhysicalDeviceCoverageReductionModeFeaturesNV,
|
||||
vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV,
|
||||
vk::PhysicalDeviceDepthClipEnableFeaturesEXT,
|
||||
vk::PhysicalDeviceDescriptorIndexingFeaturesEXT,
|
||||
vk::PhysicalDeviceExclusiveScissorFeaturesNV,
|
||||
vk::PhysicalDeviceFragmentDensityMapFeaturesEXT,
|
||||
vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV,
|
||||
vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT,
|
||||
vk::PhysicalDeviceHostQueryResetFeaturesEXT,
|
||||
vk::PhysicalDeviceImagelessFramebufferFeaturesKHR,
|
||||
vk::PhysicalDeviceIndexTypeUint8FeaturesEXT,
|
||||
vk::PhysicalDeviceInlineUniformBlockFeaturesEXT,
|
||||
vk::PhysicalDeviceLineRasterizationFeaturesEXT,
|
||||
vk::PhysicalDeviceMemoryPriorityFeaturesEXT,
|
||||
vk::PhysicalDeviceMeshShaderFeaturesNV,
|
||||
vk::PhysicalDeviceMultiviewFeatures,
|
||||
vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR,
|
||||
vk::PhysicalDeviceProtectedMemoryFeatures,
|
||||
vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV,
|
||||
vk::PhysicalDeviceSamplerYcbcrConversionFeatures,
|
||||
vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT,
|
||||
vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR,
|
||||
vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT,
|
||||
vk::PhysicalDeviceShaderDrawParametersFeatures,
|
||||
vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR,
|
||||
vk::PhysicalDeviceShaderImageFootprintFeaturesNV,
|
||||
vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL,
|
||||
vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV,
|
||||
vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR,
|
||||
vk::PhysicalDeviceShadingRateImageFeaturesNV,
|
||||
vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT,
|
||||
vk::PhysicalDeviceTexelBufferAlignmentFeaturesEXT,
|
||||
vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT,
|
||||
vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR,
|
||||
vk::PhysicalDeviceTransformFeedbackFeaturesEXT,
|
||||
vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR,
|
||||
vk::PhysicalDeviceVariablePointersFeatures,
|
||||
vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT,
|
||||
vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR,
|
||||
vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT>();
|
||||
vk::PhysicalDeviceFeatures const & features = features2.get<vk::PhysicalDeviceFeatures2>().features;
|
||||
std::cout << "\tFeatures:\n";
|
||||
std::cout << "\t\talphaToOne : " << static_cast<bool>( features.alphaToOne ) << "\n";
|
||||
std::cout << "\t\tdepthBiasClamp : " << static_cast<bool>(features.depthBiasClamp) << "\n";
|
||||
std::cout << "\t\tdepthBounds : " << static_cast<bool>(features.depthBounds) << "\n";
|
||||
std::cout << "\t\tdepthBiasClamp : " << static_cast<bool>( features.depthBiasClamp )
|
||||
<< "\n";
|
||||
std::cout << "\t\tdepthBounds : " << static_cast<bool>( features.depthBounds )
|
||||
<< "\n";
|
||||
std::cout << "\t\tdepthClamp : " << static_cast<bool>( features.depthClamp ) << "\n";
|
||||
std::cout << "\t\tdrawIndirectFirstInstance : " << static_cast<bool>(features.drawIndirectFirstInstance) << "\n";
|
||||
std::cout << "\t\tdualSrcBlend : " << static_cast<bool>(features.dualSrcBlend) << "\n";
|
||||
std::cout << "\t\tfillModeNonSolid : " << static_cast<bool>(features.fillModeNonSolid) << "\n";
|
||||
std::cout << "\t\tfragmentStoresAndAtomics : " << static_cast<bool>(features.fragmentStoresAndAtomics) << "\n";
|
||||
std::cout << "\t\tfullDrawIndexUint32 : " << static_cast<bool>(features.fullDrawIndexUint32) << "\n";
|
||||
std::cout << "\t\tgeometryShader : " << static_cast<bool>(features.geometryShader) << "\n";
|
||||
std::cout << "\t\timageCubeArray : " << static_cast<bool>(features.imageCubeArray) << "\n";
|
||||
std::cout << "\t\tindependentBlend : " << static_cast<bool>(features.independentBlend) << "\n";
|
||||
std::cout << "\t\tinheritedQueries : " << static_cast<bool>(features.inheritedQueries) << "\n";
|
||||
std::cout << "\t\tlargePoints : " << static_cast<bool>(features.largePoints) << "\n";
|
||||
std::cout << "\t\tdrawIndirectFirstInstance : "
|
||||
<< static_cast<bool>( features.drawIndirectFirstInstance ) << "\n";
|
||||
std::cout << "\t\tdualSrcBlend : " << static_cast<bool>( features.dualSrcBlend )
|
||||
<< "\n";
|
||||
std::cout << "\t\tfillModeNonSolid : " << static_cast<bool>( features.fillModeNonSolid )
|
||||
<< "\n";
|
||||
std::cout << "\t\tfragmentStoresAndAtomics : "
|
||||
<< static_cast<bool>( features.fragmentStoresAndAtomics ) << "\n";
|
||||
std::cout << "\t\tfullDrawIndexUint32 : " << static_cast<bool>( features.fullDrawIndexUint32 )
|
||||
<< "\n";
|
||||
std::cout << "\t\tgeometryShader : " << static_cast<bool>( features.geometryShader )
|
||||
<< "\n";
|
||||
std::cout << "\t\timageCubeArray : " << static_cast<bool>( features.imageCubeArray )
|
||||
<< "\n";
|
||||
std::cout << "\t\tindependentBlend : " << static_cast<bool>( features.independentBlend )
|
||||
<< "\n";
|
||||
std::cout << "\t\tinheritedQueries : " << static_cast<bool>( features.inheritedQueries )
|
||||
<< "\n";
|
||||
std::cout << "\t\tlargePoints : " << static_cast<bool>( features.largePoints )
|
||||
<< "\n";
|
||||
std::cout << "\t\tlogicOp : " << static_cast<bool>( features.logicOp ) << "\n";
|
||||
std::cout << "\t\tmultiDrawIndirect : " << static_cast<bool>(features.multiDrawIndirect) << "\n";
|
||||
std::cout << "\t\tmultiViewport : " << static_cast<bool>(features.multiViewport) << "\n";
|
||||
std::cout << "\t\tocclusionQueryPrecise : " << static_cast<bool>(features.occlusionQueryPrecise) << "\n";
|
||||
std::cout << "\t\tpipelineStatisticsQuery : " << static_cast<bool>(features.pipelineStatisticsQuery) << "\n";
|
||||
std::cout << "\t\trobustBufferAccess : " << static_cast<bool>(features.robustBufferAccess) << "\n";
|
||||
std::cout << "\t\tsamplerAnisotropy : " << static_cast<bool>(features.samplerAnisotropy) << "\n";
|
||||
std::cout << "\t\tsampleRateShading : " << static_cast<bool>(features.sampleRateShading) << "\n";
|
||||
std::cout << "\t\tshaderClipDistance : " << static_cast<bool>(features.shaderClipDistance) << "\n";
|
||||
std::cout << "\t\tshaderCullDistance : " << static_cast<bool>(features.shaderCullDistance) << "\n";
|
||||
std::cout << "\t\tshaderFloat64 : " << static_cast<bool>(features.shaderFloat64) << "\n";
|
||||
std::cout << "\t\tshaderImageGatherExtended : " << static_cast<bool>(features.shaderImageGatherExtended) << "\n";
|
||||
std::cout << "\t\tshaderInt16 : " << static_cast<bool>(features.shaderInt16) << "\n";
|
||||
std::cout << "\t\tshaderInt64 : " << static_cast<bool>(features.shaderInt64) << "\n";
|
||||
std::cout << "\t\tshaderResourceMinLod : " << static_cast<bool>(features.shaderResourceMinLod) << "\n";
|
||||
std::cout << "\t\tshaderResourceResidency : " << static_cast<bool>(features.shaderResourceResidency) << "\n";
|
||||
std::cout << "\t\tshaderSampledImageArrayDynamicIndexing : " << static_cast<bool>(features.shaderSampledImageArrayDynamicIndexing) << "\n";
|
||||
std::cout << "\t\tshaderStorageBufferArrayDynamicIndexing : " << static_cast<bool>(features.shaderStorageBufferArrayDynamicIndexing) << "\n";
|
||||
std::cout << "\t\tshaderStorageImageArrayDynamicIndexing : " << static_cast<bool>(features.shaderStorageImageArrayDynamicIndexing) << "\n";
|
||||
std::cout << "\t\tshaderStorageImageExtendedFormats : " << static_cast<bool>(features.shaderStorageImageExtendedFormats) << "\n";
|
||||
std::cout << "\t\tshaderStorageImageMultisample : " << static_cast<bool>(features.shaderStorageImageMultisample) << "\n";
|
||||
std::cout << "\t\tshaderStorageImageReadWithoutFormat : " << static_cast<bool>(features.shaderStorageImageReadWithoutFormat) << "\n";
|
||||
std::cout << "\t\tshaderStorageImageWriteWithoutFormat : " << static_cast<bool>(features.shaderStorageImageWriteWithoutFormat) << "\n";
|
||||
std::cout << "\t\tshaderTessellationAndGeometryPointSize : " << static_cast<bool>(features.shaderTessellationAndGeometryPointSize) << "\n";
|
||||
std::cout << "\t\tshaderUniformBufferArrayDynamicIndexing : " << static_cast<bool>(features.shaderUniformBufferArrayDynamicIndexing) << "\n";
|
||||
std::cout << "\t\tsparseBinding : " << static_cast<bool>(features.sparseBinding) << "\n";
|
||||
std::cout << "\t\tsparseResidency16Samples : " << static_cast<bool>(features.sparseResidency16Samples) << "\n";
|
||||
std::cout << "\t\tsparseResidency2Samples : " << static_cast<bool>(features.sparseResidency2Samples) << "\n";
|
||||
std::cout << "\t\tsparseResidency4Samples : " << static_cast<bool>(features.sparseResidency4Samples) << "\n";
|
||||
std::cout << "\t\tsparseResidency8Samples : " << static_cast<bool>(features.sparseResidency8Samples) << "\n";
|
||||
std::cout << "\t\tsparseResidencyAliased : " << static_cast<bool>(features.sparseResidencyAliased) << "\n";
|
||||
std::cout << "\t\tsparseResidencyBuffer : " << static_cast<bool>(features.sparseResidencyBuffer) << "\n";
|
||||
std::cout << "\t\tsparseResidencyImage2D : " << static_cast<bool>(features.sparseResidencyImage2D) << "\n";
|
||||
std::cout << "\t\tsparseResidencyImage3D : " << static_cast<bool>(features.sparseResidencyImage3D) << "\n";
|
||||
std::cout << "\t\ttessellationShader : " << static_cast<bool>(features.tessellationShader) << "\n";
|
||||
std::cout << "\t\ttextureCompressionASTC_LDR : " << static_cast<bool>(features.textureCompressionASTC_LDR) << "\n";
|
||||
std::cout << "\t\ttextureCompressionBC : " << static_cast<bool>(features.textureCompressionBC) << "\n";
|
||||
std::cout << "\t\ttextureCompressionETC2 : " << static_cast<bool>(features.textureCompressionETC2) << "\n";
|
||||
std::cout << "\t\tvariableMultisampleRate : " << static_cast<bool>(features.variableMultisampleRate) << "\n";
|
||||
std::cout << "\t\tvertexPipelineStoresAndAtomics : " << static_cast<bool>(features.vertexPipelineStoresAndAtomics) << "\n";
|
||||
std::cout << "\t\tmultiDrawIndirect : " << static_cast<bool>( features.multiDrawIndirect )
|
||||
<< "\n";
|
||||
std::cout << "\t\tmultiViewport : " << static_cast<bool>( features.multiViewport )
|
||||
<< "\n";
|
||||
std::cout << "\t\tocclusionQueryPrecise : "
|
||||
<< static_cast<bool>( features.occlusionQueryPrecise ) << "\n";
|
||||
std::cout << "\t\tpipelineStatisticsQuery : "
|
||||
<< static_cast<bool>( features.pipelineStatisticsQuery ) << "\n";
|
||||
std::cout << "\t\trobustBufferAccess : " << static_cast<bool>( features.robustBufferAccess )
|
||||
<< "\n";
|
||||
std::cout << "\t\tsamplerAnisotropy : " << static_cast<bool>( features.samplerAnisotropy )
|
||||
<< "\n";
|
||||
std::cout << "\t\tsampleRateShading : " << static_cast<bool>( features.sampleRateShading )
|
||||
<< "\n";
|
||||
std::cout << "\t\tshaderClipDistance : " << static_cast<bool>( features.shaderClipDistance )
|
||||
<< "\n";
|
||||
std::cout << "\t\tshaderCullDistance : " << static_cast<bool>( features.shaderCullDistance )
|
||||
<< "\n";
|
||||
std::cout << "\t\tshaderFloat64 : " << static_cast<bool>( features.shaderFloat64 )
|
||||
<< "\n";
|
||||
std::cout << "\t\tshaderImageGatherExtended : "
|
||||
<< static_cast<bool>( features.shaderImageGatherExtended ) << "\n";
|
||||
std::cout << "\t\tshaderInt16 : " << static_cast<bool>( features.shaderInt16 )
|
||||
<< "\n";
|
||||
std::cout << "\t\tshaderInt64 : " << static_cast<bool>( features.shaderInt64 )
|
||||
<< "\n";
|
||||
std::cout << "\t\tshaderResourceMinLod : "
|
||||
<< static_cast<bool>( features.shaderResourceMinLod ) << "\n";
|
||||
std::cout << "\t\tshaderResourceResidency : "
|
||||
<< static_cast<bool>( features.shaderResourceResidency ) << "\n";
|
||||
std::cout << "\t\tshaderSampledImageArrayDynamicIndexing : "
|
||||
<< static_cast<bool>( features.shaderSampledImageArrayDynamicIndexing ) << "\n";
|
||||
std::cout << "\t\tshaderStorageBufferArrayDynamicIndexing : "
|
||||
<< static_cast<bool>( features.shaderStorageBufferArrayDynamicIndexing ) << "\n";
|
||||
std::cout << "\t\tshaderStorageImageArrayDynamicIndexing : "
|
||||
<< static_cast<bool>( features.shaderStorageImageArrayDynamicIndexing ) << "\n";
|
||||
std::cout << "\t\tshaderStorageImageExtendedFormats : "
|
||||
<< static_cast<bool>( features.shaderStorageImageExtendedFormats ) << "\n";
|
||||
std::cout << "\t\tshaderStorageImageMultisample : "
|
||||
<< static_cast<bool>( features.shaderStorageImageMultisample ) << "\n";
|
||||
std::cout << "\t\tshaderStorageImageReadWithoutFormat : "
|
||||
<< static_cast<bool>( features.shaderStorageImageReadWithoutFormat ) << "\n";
|
||||
std::cout << "\t\tshaderStorageImageWriteWithoutFormat : "
|
||||
<< static_cast<bool>( features.shaderStorageImageWriteWithoutFormat ) << "\n";
|
||||
std::cout << "\t\tshaderTessellationAndGeometryPointSize : "
|
||||
<< static_cast<bool>( features.shaderTessellationAndGeometryPointSize ) << "\n";
|
||||
std::cout << "\t\tshaderUniformBufferArrayDynamicIndexing : "
|
||||
<< static_cast<bool>( features.shaderUniformBufferArrayDynamicIndexing ) << "\n";
|
||||
std::cout << "\t\tsparseBinding : " << static_cast<bool>( features.sparseBinding )
|
||||
<< "\n";
|
||||
std::cout << "\t\tsparseResidency16Samples : "
|
||||
<< static_cast<bool>( features.sparseResidency16Samples ) << "\n";
|
||||
std::cout << "\t\tsparseResidency2Samples : "
|
||||
<< static_cast<bool>( features.sparseResidency2Samples ) << "\n";
|
||||
std::cout << "\t\tsparseResidency4Samples : "
|
||||
<< static_cast<bool>( features.sparseResidency4Samples ) << "\n";
|
||||
std::cout << "\t\tsparseResidency8Samples : "
|
||||
<< static_cast<bool>( features.sparseResidency8Samples ) << "\n";
|
||||
std::cout << "\t\tsparseResidencyAliased : "
|
||||
<< static_cast<bool>( features.sparseResidencyAliased ) << "\n";
|
||||
std::cout << "\t\tsparseResidencyBuffer : "
|
||||
<< static_cast<bool>( features.sparseResidencyBuffer ) << "\n";
|
||||
std::cout << "\t\tsparseResidencyImage2D : "
|
||||
<< static_cast<bool>( features.sparseResidencyImage2D ) << "\n";
|
||||
std::cout << "\t\tsparseResidencyImage3D : "
|
||||
<< static_cast<bool>( features.sparseResidencyImage3D ) << "\n";
|
||||
std::cout << "\t\ttessellationShader : " << static_cast<bool>( features.tessellationShader )
|
||||
<< "\n";
|
||||
std::cout << "\t\ttextureCompressionASTC_LDR : "
|
||||
<< static_cast<bool>( features.textureCompressionASTC_LDR ) << "\n";
|
||||
std::cout << "\t\ttextureCompressionBC : "
|
||||
<< static_cast<bool>( features.textureCompressionBC ) << "\n";
|
||||
std::cout << "\t\ttextureCompressionETC2 : "
|
||||
<< static_cast<bool>( features.textureCompressionETC2 ) << "\n";
|
||||
std::cout << "\t\tvariableMultisampleRate : "
|
||||
<< static_cast<bool>( features.variableMultisampleRate ) << "\n";
|
||||
std::cout << "\t\tvertexPipelineStoresAndAtomics : "
|
||||
<< static_cast<bool>( features.vertexPipelineStoresAndAtomics ) << "\n";
|
||||
std::cout << "\t\twideLines : " << static_cast<bool>( features.wideLines ) << "\n";
|
||||
std::cout << "\n";
|
||||
|
||||
vk::PhysicalDevice16BitStorageFeatures const& sixteenBitStorageFeatures = features2.get<vk::PhysicalDevice16BitStorageFeatures>();
|
||||
vk::PhysicalDevice16BitStorageFeatures const & sixteenBitStorageFeatures =
|
||||
features2.get<vk::PhysicalDevice16BitStorageFeatures>();
|
||||
std::cout << "\t16BitStorageFeatures:\n";
|
||||
std::cout << "\t\tstorageBuffer16BitAccess : " << static_cast<bool>(sixteenBitStorageFeatures.storageBuffer16BitAccess) << "\n";
|
||||
std::cout << "\t\tstorageInputOutput16 : " << static_cast<bool>(sixteenBitStorageFeatures.storageInputOutput16) << "\n";
|
||||
std::cout << "\t\tstoragePushConstant16 : " << static_cast<bool>(sixteenBitStorageFeatures.storagePushConstant16) << "\n";
|
||||
std::cout << "\t\tuniformAndStorageBuffer16BitAccess : " << static_cast<bool>(sixteenBitStorageFeatures.uniformAndStorageBuffer16BitAccess) << "\n";
|
||||
std::cout << "\t\tstorageBuffer16BitAccess : "
|
||||
<< static_cast<bool>( sixteenBitStorageFeatures.storageBuffer16BitAccess ) << "\n";
|
||||
std::cout << "\t\tstorageInputOutput16 : "
|
||||
<< static_cast<bool>( sixteenBitStorageFeatures.storageInputOutput16 ) << "\n";
|
||||
std::cout << "\t\tstoragePushConstant16 : "
|
||||
<< static_cast<bool>( sixteenBitStorageFeatures.storagePushConstant16 ) << "\n";
|
||||
std::cout << "\t\tuniformAndStorageBuffer16BitAccess : "
|
||||
<< static_cast<bool>( sixteenBitStorageFeatures.uniformAndStorageBuffer16BitAccess ) << "\n";
|
||||
std::cout << "\n";
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_KHR_8bit_storage" ) )
|
||||
{
|
||||
vk::PhysicalDevice8BitStorageFeaturesKHR const& eightBitStorageFeatures = features2.get<vk::PhysicalDevice8BitStorageFeaturesKHR>();
|
||||
vk::PhysicalDevice8BitStorageFeaturesKHR const & eightBitStorageFeatures =
|
||||
features2.get<vk::PhysicalDevice8BitStorageFeaturesKHR>();
|
||||
std::cout << "\t8BitStorageFeatures:\n";
|
||||
std::cout << "\t\tstorageBuffer8BitAccess : " << static_cast<bool>(eightBitStorageFeatures.storageBuffer8BitAccess) << "\n";
|
||||
std::cout << "\t\tstoragePushConstant8 : " << static_cast<bool>(eightBitStorageFeatures.storagePushConstant8) << "\n";
|
||||
std::cout << "\t\tuniformAndStorageBuffer8BitAccess : " << static_cast<bool>(eightBitStorageFeatures.uniformAndStorageBuffer8BitAccess) << "\n";
|
||||
std::cout << "\t\tstorageBuffer8BitAccess : "
|
||||
<< static_cast<bool>( eightBitStorageFeatures.storageBuffer8BitAccess ) << "\n";
|
||||
std::cout << "\t\tstoragePushConstant8 : "
|
||||
<< static_cast<bool>( eightBitStorageFeatures.storagePushConstant8 ) << "\n";
|
||||
std::cout << "\t\tuniformAndStorageBuffer8BitAccess : "
|
||||
<< static_cast<bool>( eightBitStorageFeatures.uniformAndStorageBuffer8BitAccess ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_astc_decode_mode" ) )
|
||||
{
|
||||
vk::PhysicalDeviceASTCDecodeFeaturesEXT const& astcDecodeFeatures = features2.get<vk::PhysicalDeviceASTCDecodeFeaturesEXT>();
|
||||
vk::PhysicalDeviceASTCDecodeFeaturesEXT const & astcDecodeFeatures =
|
||||
features2.get<vk::PhysicalDeviceASTCDecodeFeaturesEXT>();
|
||||
std::cout << "\tASTCDecodeFeature:\n";
|
||||
std::cout << "\t\tdecodeModeSharedExponent : " << static_cast<bool>(astcDecodeFeatures.decodeModeSharedExponent) << "\n";
|
||||
std::cout << "\t\tdecodeModeSharedExponent : "
|
||||
<< static_cast<bool>( astcDecodeFeatures.decodeModeSharedExponent ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_blend_operation_advanced" ) )
|
||||
{
|
||||
vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT const& blendOperationAdvancedFeatures = features2.get<vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT>();
|
||||
vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT const & blendOperationAdvancedFeatures =
|
||||
features2.get<vk::PhysicalDeviceBlendOperationAdvancedFeaturesEXT>();
|
||||
std::cout << "\tBlendOperationAdvancedFeatures:\n";
|
||||
std::cout << "\t\tadvancedBlendCoherentOperations : " << static_cast<bool>(blendOperationAdvancedFeatures.advancedBlendCoherentOperations) << "\n";
|
||||
std::cout << "\t\tadvancedBlendCoherentOperations : "
|
||||
<< static_cast<bool>( blendOperationAdvancedFeatures.advancedBlendCoherentOperations ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_buffer_device_address" ) )
|
||||
{
|
||||
vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT const& bufferDeviceAddressFeatures = features2.get<vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT>();
|
||||
vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT const & bufferDeviceAddressFeatures =
|
||||
features2.get<vk::PhysicalDeviceBufferDeviceAddressFeaturesEXT>();
|
||||
std::cout << "\tBufferDeviceAddressFeatures:\n";
|
||||
std::cout << "\t\tbufferDeviceAddress : " << static_cast<bool>(bufferDeviceAddressFeatures.bufferDeviceAddress) << "\n";
|
||||
std::cout << "\t\tbufferDeviceAddressCaptureReplay : " << static_cast<bool>(bufferDeviceAddressFeatures.bufferDeviceAddressCaptureReplay) << "\n";
|
||||
std::cout << "\t\tbufferDeviceAddressMultiDevice : " << static_cast<bool>(bufferDeviceAddressFeatures.bufferDeviceAddressMultiDevice) << "\n";
|
||||
std::cout << "\t\tbufferDeviceAddress : "
|
||||
<< static_cast<bool>( bufferDeviceAddressFeatures.bufferDeviceAddress ) << "\n";
|
||||
std::cout << "\t\tbufferDeviceAddressCaptureReplay : "
|
||||
<< static_cast<bool>( bufferDeviceAddressFeatures.bufferDeviceAddressCaptureReplay ) << "\n";
|
||||
std::cout << "\t\tbufferDeviceAddressMultiDevice : "
|
||||
<< static_cast<bool>( bufferDeviceAddressFeatures.bufferDeviceAddressMultiDevice ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_AMD_device_coherent_memory" ) )
|
||||
{
|
||||
vk::PhysicalDeviceCoherentMemoryFeaturesAMD const& coherentMemoryFeatures = features2.get<vk::PhysicalDeviceCoherentMemoryFeaturesAMD>();
|
||||
vk::PhysicalDeviceCoherentMemoryFeaturesAMD const & coherentMemoryFeatures =
|
||||
features2.get<vk::PhysicalDeviceCoherentMemoryFeaturesAMD>();
|
||||
std::cout << "\tCoherentMemoryFeatures:\n";
|
||||
std::cout << "\t\tdeviceCoherentMemory : " << static_cast<bool>(coherentMemoryFeatures.deviceCoherentMemory) << "\n";
|
||||
std::cout << "\t\tdeviceCoherentMemory : " << static_cast<bool>( coherentMemoryFeatures.deviceCoherentMemory )
|
||||
<< "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_NV_compute_shader_derivatives" ) )
|
||||
{
|
||||
vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV const& computeShaderDerivativesFeatures = features2.get<vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV>();
|
||||
vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV const & computeShaderDerivativesFeatures =
|
||||
features2.get<vk::PhysicalDeviceComputeShaderDerivativesFeaturesNV>();
|
||||
std::cout << "\tComputeShaderDerivativeFeatures:\n";
|
||||
std::cout << "\t\tcomputeDerivativeGroupLinear : " << static_cast<bool>(computeShaderDerivativesFeatures.computeDerivativeGroupLinear) << "\n";
|
||||
std::cout << "\t\tcomputeDerivativeGroupQuads : " << static_cast<bool>(computeShaderDerivativesFeatures.computeDerivativeGroupQuads) << "\n";
|
||||
std::cout << "\t\tcomputeDerivativeGroupLinear : "
|
||||
<< static_cast<bool>( computeShaderDerivativesFeatures.computeDerivativeGroupLinear ) << "\n";
|
||||
std::cout << "\t\tcomputeDerivativeGroupQuads : "
|
||||
<< static_cast<bool>( computeShaderDerivativesFeatures.computeDerivativeGroupQuads ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_conditional_rendering" ) )
|
||||
{
|
||||
vk::PhysicalDeviceConditionalRenderingFeaturesEXT const& conditionalRenderingFeatures = features2.get<vk::PhysicalDeviceConditionalRenderingFeaturesEXT>();
|
||||
vk::PhysicalDeviceConditionalRenderingFeaturesEXT const & conditionalRenderingFeatures =
|
||||
features2.get<vk::PhysicalDeviceConditionalRenderingFeaturesEXT>();
|
||||
std::cout << "\tConditionalRenderingFeatures:\n";
|
||||
std::cout << "\t\tconditionalRendering : " << static_cast<bool>(conditionalRenderingFeatures.conditionalRendering) << "\n";
|
||||
std::cout << "\t\tinheritedConditionalRendering : " << static_cast<bool>(conditionalRenderingFeatures.inheritedConditionalRendering) << "\n";
|
||||
std::cout << "\t\tconditionalRendering : "
|
||||
<< static_cast<bool>( conditionalRenderingFeatures.conditionalRendering ) << "\n";
|
||||
std::cout << "\t\tinheritedConditionalRendering : "
|
||||
<< static_cast<bool>( conditionalRenderingFeatures.inheritedConditionalRendering ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_NV_cooperative_matrix" ) )
|
||||
{
|
||||
vk::PhysicalDeviceCooperativeMatrixFeaturesNV const& cooperativeMatrixFeatures = features2.get<vk::PhysicalDeviceCooperativeMatrixFeaturesNV>();
|
||||
vk::PhysicalDeviceCooperativeMatrixFeaturesNV const & cooperativeMatrixFeatures =
|
||||
features2.get<vk::PhysicalDeviceCooperativeMatrixFeaturesNV>();
|
||||
std::cout << "\tCooperativeMatrixFeatures:\n";
|
||||
std::cout << "\t\tcooperativeMatrix : " << static_cast<bool>(cooperativeMatrixFeatures.cooperativeMatrix) << "\n";
|
||||
std::cout << "\t\tcooperativeMatrixRobustBufferAccess : " << static_cast<bool>(cooperativeMatrixFeatures.cooperativeMatrixRobustBufferAccess) << "\n";
|
||||
std::cout << "\t\tcooperativeMatrix : "
|
||||
<< static_cast<bool>( cooperativeMatrixFeatures.cooperativeMatrix ) << "\n";
|
||||
std::cout << "\t\tcooperativeMatrixRobustBufferAccess : "
|
||||
<< static_cast<bool>( cooperativeMatrixFeatures.cooperativeMatrixRobustBufferAccess ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_NV_corner_sampled_image" ) )
|
||||
{
|
||||
vk::PhysicalDeviceCornerSampledImageFeaturesNV const& cornerSampledImageFeatures = features2.get<vk::PhysicalDeviceCornerSampledImageFeaturesNV>();
|
||||
vk::PhysicalDeviceCornerSampledImageFeaturesNV const & cornerSampledImageFeatures =
|
||||
features2.get<vk::PhysicalDeviceCornerSampledImageFeaturesNV>();
|
||||
std::cout << "\tCornerSampledImageFeatures:\n";
|
||||
std::cout << "\t\tcornerSampledImage : " << static_cast<bool>(cornerSampledImageFeatures.cornerSampledImage) << "\n";
|
||||
std::cout << "\t\tcornerSampledImage : " << static_cast<bool>( cornerSampledImageFeatures.cornerSampledImage )
|
||||
<< "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_NV_coverage_reduction_mode" ) )
|
||||
{
|
||||
vk::PhysicalDeviceCoverageReductionModeFeaturesNV const& coverageReductionModeFeatures = features2.get<vk::PhysicalDeviceCoverageReductionModeFeaturesNV>();
|
||||
vk::PhysicalDeviceCoverageReductionModeFeaturesNV const & coverageReductionModeFeatures =
|
||||
features2.get<vk::PhysicalDeviceCoverageReductionModeFeaturesNV>();
|
||||
std::cout << "\tCoverageReductionModeFeatures:\n";
|
||||
std::cout << "\t\tcoverageReductionMode : " << static_cast<bool>(coverageReductionModeFeatures.coverageReductionMode) << "\n";
|
||||
std::cout << "\t\tcoverageReductionMode : "
|
||||
<< static_cast<bool>( coverageReductionModeFeatures.coverageReductionMode ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_NV_dedicated_allocation_image_aliasing" ) )
|
||||
{
|
||||
vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV const& dedicatedAllocationImageAliasingFeatures = features2.get<vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>();
|
||||
vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV const & dedicatedAllocationImageAliasingFeatures =
|
||||
features2.get<vk::PhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>();
|
||||
std::cout << "\tDedicatedAllocationAliasingFeatures:\n";
|
||||
std::cout << "\t\tdedicatedAllocationImageAliasing : " << static_cast<bool>(dedicatedAllocationImageAliasingFeatures.dedicatedAllocationImageAliasing) << "\n";
|
||||
std::cout << "\t\tdedicatedAllocationImageAliasing : "
|
||||
<< static_cast<bool>( dedicatedAllocationImageAliasingFeatures.dedicatedAllocationImageAliasing )
|
||||
<< "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_depth_clip_enable" ) )
|
||||
{
|
||||
vk::PhysicalDeviceDepthClipEnableFeaturesEXT const& depthClipEnabledFeatures = features2.get<vk::PhysicalDeviceDepthClipEnableFeaturesEXT>();
|
||||
vk::PhysicalDeviceDepthClipEnableFeaturesEXT const & depthClipEnabledFeatures =
|
||||
features2.get<vk::PhysicalDeviceDepthClipEnableFeaturesEXT>();
|
||||
std::cout << "\tDepthClipEnabledFeatures:\n";
|
||||
std::cout << "\t\tdepthClipEnable : " << static_cast<bool>( depthClipEnabledFeatures.depthClipEnable ) << "\n";
|
||||
std::cout << "\n";
|
||||
@ -239,70 +356,115 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_descriptor_indexing" ) )
|
||||
{
|
||||
vk::PhysicalDeviceDescriptorIndexingFeaturesEXT const& descriptorIndexingFeatures = features2.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
|
||||
vk::PhysicalDeviceDescriptorIndexingFeaturesEXT const & descriptorIndexingFeatures =
|
||||
features2.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
|
||||
std::cout << "\tDescriptorIndexingFeatures:\n";
|
||||
std::cout << "\t\tdescriptorBindingPartiallyBound : " << static_cast<bool>(descriptorIndexingFeatures.descriptorBindingPartiallyBound) << "\n";
|
||||
std::cout << "\t\tdescriptorBindingSampledImageUpdateAfterBind : " << static_cast<bool>(descriptorIndexingFeatures.descriptorBindingSampledImageUpdateAfterBind) << "\n";
|
||||
std::cout << "\t\tdescriptorBindingStorageBufferUpdateAfterBind : " << static_cast<bool>(descriptorIndexingFeatures.descriptorBindingStorageBufferUpdateAfterBind) << "\n";
|
||||
std::cout << "\t\tdescriptorBindingStorageImageUpdateAfterBind : " << static_cast<bool>(descriptorIndexingFeatures.descriptorBindingStorageImageUpdateAfterBind) << "\n";
|
||||
std::cout << "\t\tdescriptorBindingStorageTexelBufferUpdateAfterBind : " << static_cast<bool>(descriptorIndexingFeatures.descriptorBindingStorageTexelBufferUpdateAfterBind) << "\n";
|
||||
std::cout << "\t\tdescriptorBindingUniformBufferUpdateAfterBind : " << static_cast<bool>(descriptorIndexingFeatures.descriptorBindingUniformBufferUpdateAfterBind) << "\n";
|
||||
std::cout << "\t\tdescriptorBindingUniformTexelBufferUpdateAfterBind : " << static_cast<bool>(descriptorIndexingFeatures.descriptorBindingUniformTexelBufferUpdateAfterBind) << "\n";
|
||||
std::cout << "\t\tdescriptorBindingUpdateUnusedWhilePending : " << static_cast<bool>(descriptorIndexingFeatures.descriptorBindingUpdateUnusedWhilePending) << "\n";
|
||||
std::cout << "\t\tdescriptorBindingVariableDescriptorCount : " << static_cast<bool>(descriptorIndexingFeatures.descriptorBindingVariableDescriptorCount) << "\n";
|
||||
std::cout << "\t\truntimeDescriptorArray : " << static_cast<bool>(descriptorIndexingFeatures.runtimeDescriptorArray) << "\n";
|
||||
std::cout << "\t\tshaderInputAttachmentArrayDynamicIndexing : " << static_cast<bool>(descriptorIndexingFeatures.shaderInputAttachmentArrayDynamicIndexing) << "\n";
|
||||
std::cout << "\t\tshaderInputAttachmentArrayNonUniformIndexing : " << static_cast<bool>(descriptorIndexingFeatures.shaderInputAttachmentArrayNonUniformIndexing) << "\n";
|
||||
std::cout << "\t\tshaderSampledImageArrayNonUniformIndexing : " << static_cast<bool>(descriptorIndexingFeatures.shaderSampledImageArrayNonUniformIndexing) << "\n";
|
||||
std::cout << "\t\tshaderStorageBufferArrayNonUniformIndexing : " << static_cast<bool>(descriptorIndexingFeatures.shaderStorageBufferArrayNonUniformIndexing) << "\n";
|
||||
std::cout << "\t\tshaderStorageImageArrayNonUniformIndexing : " << static_cast<bool>(descriptorIndexingFeatures.shaderStorageImageArrayNonUniformIndexing) << "\n";
|
||||
std::cout << "\t\tshaderStorageTexelBufferArrayDynamicIndexing : " << static_cast<bool>(descriptorIndexingFeatures.shaderStorageTexelBufferArrayDynamicIndexing) << "\n";
|
||||
std::cout << "\t\tshaderStorageTexelBufferArrayNonUniformIndexing : " << static_cast<bool>(descriptorIndexingFeatures.shaderStorageTexelBufferArrayNonUniformIndexing) << "\n";
|
||||
std::cout << "\t\tshaderUniformBufferArrayNonUniformIndexing : " << static_cast<bool>(descriptorIndexingFeatures.shaderUniformBufferArrayNonUniformIndexing) << "\n";
|
||||
std::cout << "\t\tshaderUniformTexelBufferArrayDynamicIndexing : " << static_cast<bool>(descriptorIndexingFeatures.shaderUniformTexelBufferArrayDynamicIndexing) << "\n";
|
||||
std::cout << "\t\tshaderUniformTexelBufferArrayNonUniformIndexing : " << static_cast<bool>(descriptorIndexingFeatures.shaderUniformTexelBufferArrayNonUniformIndexing) << "\n";
|
||||
std::cout << "\t\tdescriptorBindingPartiallyBound : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.descriptorBindingPartiallyBound ) << "\n";
|
||||
std::cout << "\t\tdescriptorBindingSampledImageUpdateAfterBind : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.descriptorBindingSampledImageUpdateAfterBind )
|
||||
<< "\n";
|
||||
std::cout << "\t\tdescriptorBindingStorageBufferUpdateAfterBind : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.descriptorBindingStorageBufferUpdateAfterBind )
|
||||
<< "\n";
|
||||
std::cout << "\t\tdescriptorBindingStorageImageUpdateAfterBind : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.descriptorBindingStorageImageUpdateAfterBind )
|
||||
<< "\n";
|
||||
std::cout << "\t\tdescriptorBindingStorageTexelBufferUpdateAfterBind : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.descriptorBindingStorageTexelBufferUpdateAfterBind )
|
||||
<< "\n";
|
||||
std::cout << "\t\tdescriptorBindingUniformBufferUpdateAfterBind : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.descriptorBindingUniformBufferUpdateAfterBind )
|
||||
<< "\n";
|
||||
std::cout << "\t\tdescriptorBindingUniformTexelBufferUpdateAfterBind : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.descriptorBindingUniformTexelBufferUpdateAfterBind )
|
||||
<< "\n";
|
||||
std::cout << "\t\tdescriptorBindingUpdateUnusedWhilePending : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.descriptorBindingUpdateUnusedWhilePending ) << "\n";
|
||||
std::cout << "\t\tdescriptorBindingVariableDescriptorCount : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.descriptorBindingVariableDescriptorCount ) << "\n";
|
||||
std::cout << "\t\truntimeDescriptorArray : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.runtimeDescriptorArray ) << "\n";
|
||||
std::cout << "\t\tshaderInputAttachmentArrayDynamicIndexing : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.shaderInputAttachmentArrayDynamicIndexing ) << "\n";
|
||||
std::cout << "\t\tshaderInputAttachmentArrayNonUniformIndexing : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.shaderInputAttachmentArrayNonUniformIndexing )
|
||||
<< "\n";
|
||||
std::cout << "\t\tshaderSampledImageArrayNonUniformIndexing : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.shaderSampledImageArrayNonUniformIndexing ) << "\n";
|
||||
std::cout << "\t\tshaderStorageBufferArrayNonUniformIndexing : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.shaderStorageBufferArrayNonUniformIndexing ) << "\n";
|
||||
std::cout << "\t\tshaderStorageImageArrayNonUniformIndexing : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.shaderStorageImageArrayNonUniformIndexing ) << "\n";
|
||||
std::cout << "\t\tshaderStorageTexelBufferArrayDynamicIndexing : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.shaderStorageTexelBufferArrayDynamicIndexing )
|
||||
<< "\n";
|
||||
std::cout << "\t\tshaderStorageTexelBufferArrayNonUniformIndexing : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.shaderStorageTexelBufferArrayNonUniformIndexing )
|
||||
<< "\n";
|
||||
std::cout << "\t\tshaderUniformBufferArrayNonUniformIndexing : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.shaderUniformBufferArrayNonUniformIndexing ) << "\n";
|
||||
std::cout << "\t\tshaderUniformTexelBufferArrayDynamicIndexing : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.shaderUniformTexelBufferArrayDynamicIndexing )
|
||||
<< "\n";
|
||||
std::cout << "\t\tshaderUniformTexelBufferArrayNonUniformIndexing : "
|
||||
<< static_cast<bool>( descriptorIndexingFeatures.shaderUniformTexelBufferArrayNonUniformIndexing )
|
||||
<< "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_NV_scissor_exclusive" ) )
|
||||
{
|
||||
vk::PhysicalDeviceExclusiveScissorFeaturesNV const& exclusiveScissorFeatures = features2.get<vk::PhysicalDeviceExclusiveScissorFeaturesNV>();
|
||||
vk::PhysicalDeviceExclusiveScissorFeaturesNV const & exclusiveScissorFeatures =
|
||||
features2.get<vk::PhysicalDeviceExclusiveScissorFeaturesNV>();
|
||||
std::cout << "\tExclusiveScissorFeatures:\n";
|
||||
std::cout << "\t\texclusiveScissor : " << static_cast<bool>(exclusiveScissorFeatures.exclusiveScissor) << "\n";
|
||||
std::cout << "\t\texclusiveScissor : " << static_cast<bool>( exclusiveScissorFeatures.exclusiveScissor )
|
||||
<< "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_fragment_density_map" ) )
|
||||
{
|
||||
vk::PhysicalDeviceFragmentDensityMapFeaturesEXT const& fragmentDensityMapFeatures = features2.get<vk::PhysicalDeviceFragmentDensityMapFeaturesEXT>();
|
||||
vk::PhysicalDeviceFragmentDensityMapFeaturesEXT const & fragmentDensityMapFeatures =
|
||||
features2.get<vk::PhysicalDeviceFragmentDensityMapFeaturesEXT>();
|
||||
std::cout << "\tFragmentDensityMapFeatures:\n";
|
||||
std::cout << "\t\tfragmentDensityMap : " << static_cast<bool>(fragmentDensityMapFeatures.fragmentDensityMap) << "\n";
|
||||
std::cout << "\t\tfragmentDensityMapDynamic : " << static_cast<bool>(fragmentDensityMapFeatures.fragmentDensityMapDynamic) << "\n";
|
||||
std::cout << "\t\tfragmentDensityMapNonSubsampledImages : " << static_cast<bool>(fragmentDensityMapFeatures.fragmentDensityMapNonSubsampledImages) << "\n";
|
||||
std::cout << "\t\tfragmentDensityMap : "
|
||||
<< static_cast<bool>( fragmentDensityMapFeatures.fragmentDensityMap ) << "\n";
|
||||
std::cout << "\t\tfragmentDensityMapDynamic : "
|
||||
<< static_cast<bool>( fragmentDensityMapFeatures.fragmentDensityMapDynamic ) << "\n";
|
||||
std::cout << "\t\tfragmentDensityMapNonSubsampledImages : "
|
||||
<< static_cast<bool>( fragmentDensityMapFeatures.fragmentDensityMapNonSubsampledImages ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_NV_fragment_shader_barycentric" ) )
|
||||
{
|
||||
vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV const& fragmentShaderBarycentricFeatures = features2.get<vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV>();
|
||||
vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV const & fragmentShaderBarycentricFeatures =
|
||||
features2.get<vk::PhysicalDeviceFragmentShaderBarycentricFeaturesNV>();
|
||||
std::cout << "\tFragmentShaderBarycentricFeatures:\n";
|
||||
std::cout << "\t\tfragmentShaderBarycentric : " << static_cast<bool>(fragmentShaderBarycentricFeatures.fragmentShaderBarycentric) << "\n";
|
||||
std::cout << "\t\tfragmentShaderBarycentric : "
|
||||
<< static_cast<bool>( fragmentShaderBarycentricFeatures.fragmentShaderBarycentric ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_fragment_shader_interlock" ) )
|
||||
{
|
||||
vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT const& fragmentShaderInterlockFeatures = features2.get<vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT>();
|
||||
vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT const & fragmentShaderInterlockFeatures =
|
||||
features2.get<vk::PhysicalDeviceFragmentShaderInterlockFeaturesEXT>();
|
||||
std::cout << "\tFragmentShaderInterlockFeatures:\n";
|
||||
std::cout << "\t\tfragmentShaderPixelInterlock : " << static_cast<bool>(fragmentShaderInterlockFeatures.fragmentShaderPixelInterlock) << "\n";
|
||||
std::cout << "\t\tfragmentShaderSampleInterlock : " << static_cast<bool>(fragmentShaderInterlockFeatures.fragmentShaderSampleInterlock) << "\n";
|
||||
std::cout << "\t\tfragmentShaderShadingRateInterlock : " << static_cast<bool>(fragmentShaderInterlockFeatures.fragmentShaderShadingRateInterlock) << "\n";
|
||||
std::cout << "\t\tfragmentShaderPixelInterlock : "
|
||||
<< static_cast<bool>( fragmentShaderInterlockFeatures.fragmentShaderPixelInterlock ) << "\n";
|
||||
std::cout << "\t\tfragmentShaderSampleInterlock : "
|
||||
<< static_cast<bool>( fragmentShaderInterlockFeatures.fragmentShaderSampleInterlock ) << "\n";
|
||||
std::cout << "\t\tfragmentShaderShadingRateInterlock : "
|
||||
<< static_cast<bool>( fragmentShaderInterlockFeatures.fragmentShaderShadingRateInterlock ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_host_query_reset" ) )
|
||||
{
|
||||
vk::PhysicalDeviceHostQueryResetFeaturesEXT const& hostQueryResetFeatures = features2.get<vk::PhysicalDeviceHostQueryResetFeaturesEXT>();
|
||||
vk::PhysicalDeviceHostQueryResetFeaturesEXT const & hostQueryResetFeatures =
|
||||
features2.get<vk::PhysicalDeviceHostQueryResetFeaturesEXT>();
|
||||
std::cout << "\tHostQueryResetFeatures:\n";
|
||||
std::cout << "\t\thostQueryReset : " << static_cast<bool>( hostQueryResetFeatures.hostQueryReset ) << "\n";
|
||||
std::cout << "\n";
|
||||
@ -310,15 +472,18 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_KHR_imageless_framebuffer" ) )
|
||||
{
|
||||
vk::PhysicalDeviceImagelessFramebufferFeaturesKHR const& imagelessFramebufferFeatures = features2.get<vk::PhysicalDeviceImagelessFramebufferFeaturesKHR>();
|
||||
vk::PhysicalDeviceImagelessFramebufferFeaturesKHR const & imagelessFramebufferFeatures =
|
||||
features2.get<vk::PhysicalDeviceImagelessFramebufferFeaturesKHR>();
|
||||
std::cout << "\tImagelessFramebufferFeatures:\n";
|
||||
std::cout << "\t\timagelessFramebuffer : " << static_cast<bool>(imagelessFramebufferFeatures.imagelessFramebuffer) << "\n";
|
||||
std::cout << "\t\timagelessFramebuffer : "
|
||||
<< static_cast<bool>( imagelessFramebufferFeatures.imagelessFramebuffer ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_index_type_uint8" ) )
|
||||
{
|
||||
vk::PhysicalDeviceIndexTypeUint8FeaturesEXT const& indexTypeUint8Features = features2.get<vk::PhysicalDeviceIndexTypeUint8FeaturesEXT>();
|
||||
vk::PhysicalDeviceIndexTypeUint8FeaturesEXT const & indexTypeUint8Features =
|
||||
features2.get<vk::PhysicalDeviceIndexTypeUint8FeaturesEXT>();
|
||||
std::cout << "\tIndexTypeUint8Features:\n";
|
||||
std::cout << "\t\tindexTypeUint8 : " << static_cast<bool>( indexTypeUint8Features.indexTypeUint8 ) << "\n";
|
||||
std::cout << "\n";
|
||||
@ -326,29 +491,41 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_inline_uniform_block" ) )
|
||||
{
|
||||
vk::PhysicalDeviceInlineUniformBlockFeaturesEXT const& inlineUniformBlockFeatures = features2.get<vk::PhysicalDeviceInlineUniformBlockFeaturesEXT>();
|
||||
vk::PhysicalDeviceInlineUniformBlockFeaturesEXT const & inlineUniformBlockFeatures =
|
||||
features2.get<vk::PhysicalDeviceInlineUniformBlockFeaturesEXT>();
|
||||
std::cout << "\tInlineUniformBlockFeatures:\n";
|
||||
std::cout << "\t\tdescriptorBindingInlineUniformBlockUpdateAfterBind : " << static_cast<bool>(inlineUniformBlockFeatures.descriptorBindingInlineUniformBlockUpdateAfterBind) << "\n";
|
||||
std::cout << "\t\tinlineUniformBlock : " << static_cast<bool>(inlineUniformBlockFeatures.inlineUniformBlock) << "\n";
|
||||
std::cout << "\t\tdescriptorBindingInlineUniformBlockUpdateAfterBind : "
|
||||
<< static_cast<bool>( inlineUniformBlockFeatures.descriptorBindingInlineUniformBlockUpdateAfterBind )
|
||||
<< "\n";
|
||||
std::cout << "\t\tinlineUniformBlock : "
|
||||
<< static_cast<bool>( inlineUniformBlockFeatures.inlineUniformBlock ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_line_rasterization" ) )
|
||||
{
|
||||
vk::PhysicalDeviceLineRasterizationFeaturesEXT const& lineRasterizationFeatures = features2.get<vk::PhysicalDeviceLineRasterizationFeaturesEXT>();
|
||||
vk::PhysicalDeviceLineRasterizationFeaturesEXT const & lineRasterizationFeatures =
|
||||
features2.get<vk::PhysicalDeviceLineRasterizationFeaturesEXT>();
|
||||
std::cout << "\tLineRasterizationFeatures:\n";
|
||||
std::cout << "\t\tbresenhamLines : " << static_cast<bool>(lineRasterizationFeatures.bresenhamLines) << "\n";
|
||||
std::cout << "\t\trectangularLines : " << static_cast<bool>(lineRasterizationFeatures.rectangularLines) << "\n";
|
||||
std::cout << "\t\tsmoothLines : " << static_cast<bool>(lineRasterizationFeatures.smoothLines) << "\n";
|
||||
std::cout << "\t\tstippledBresenhamLines : " << static_cast<bool>(lineRasterizationFeatures.stippledBresenhamLines) << "\n";
|
||||
std::cout << "\t\tstippledRectangularLines : " << static_cast<bool>(lineRasterizationFeatures.stippledRectangularLines) << "\n";
|
||||
std::cout << "\t\tstippledSmoothLines : " << static_cast<bool>(lineRasterizationFeatures.stippledSmoothLines) << "\n";
|
||||
std::cout << "\t\tbresenhamLines : " << static_cast<bool>( lineRasterizationFeatures.bresenhamLines )
|
||||
<< "\n";
|
||||
std::cout << "\t\trectangularLines : "
|
||||
<< static_cast<bool>( lineRasterizationFeatures.rectangularLines ) << "\n";
|
||||
std::cout << "\t\tsmoothLines : " << static_cast<bool>( lineRasterizationFeatures.smoothLines )
|
||||
<< "\n";
|
||||
std::cout << "\t\tstippledBresenhamLines : "
|
||||
<< static_cast<bool>( lineRasterizationFeatures.stippledBresenhamLines ) << "\n";
|
||||
std::cout << "\t\tstippledRectangularLines : "
|
||||
<< static_cast<bool>( lineRasterizationFeatures.stippledRectangularLines ) << "\n";
|
||||
std::cout << "\t\tstippledSmoothLines : "
|
||||
<< static_cast<bool>( lineRasterizationFeatures.stippledSmoothLines ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_memory_priority" ) )
|
||||
{
|
||||
vk::PhysicalDeviceMemoryPriorityFeaturesEXT const& memoryPriorityFeatures = features2.get<vk::PhysicalDeviceMemoryPriorityFeaturesEXT>();
|
||||
vk::PhysicalDeviceMemoryPriorityFeaturesEXT const & memoryPriorityFeatures =
|
||||
features2.get<vk::PhysicalDeviceMemoryPriorityFeaturesEXT>();
|
||||
std::cout << "\tMemoryPriorityFeatures:\n";
|
||||
std::cout << "\t\tmemoryPriority : " << static_cast<bool>( memoryPriorityFeatures.memoryPriority ) << "\n";
|
||||
std::cout << "\n";
|
||||
@ -356,79 +533,100 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_NV_mesh_shader" ) )
|
||||
{
|
||||
vk::PhysicalDeviceMeshShaderFeaturesNV const& meshShaderFeatures = features2.get<vk::PhysicalDeviceMeshShaderFeaturesNV>();
|
||||
vk::PhysicalDeviceMeshShaderFeaturesNV const & meshShaderFeatures =
|
||||
features2.get<vk::PhysicalDeviceMeshShaderFeaturesNV>();
|
||||
std::cout << "\tMeshShaderFeatures:\n";
|
||||
std::cout << "\t\tmeshShader : " << static_cast<bool>( meshShaderFeatures.meshShader ) << "\n";
|
||||
std::cout << "\t\ttaskShader : " << static_cast<bool>( meshShaderFeatures.taskShader ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
vk::PhysicalDeviceMultiviewFeatures const& multiviewFeatures = features2.get<vk::PhysicalDeviceMultiviewFeatures>();
|
||||
vk::PhysicalDeviceMultiviewFeatures const & multiviewFeatures =
|
||||
features2.get<vk::PhysicalDeviceMultiviewFeatures>();
|
||||
std::cout << "\tMultiviewFeatures:\n";
|
||||
std::cout << "\t\tmultiview : " << static_cast<bool>( multiviewFeatures.multiview ) << "\n";
|
||||
std::cout << "\t\tmultiviewGeometryShader : " << static_cast<bool>(multiviewFeatures.multiviewGeometryShader) << "\n";
|
||||
std::cout << "\t\tmultiviewTessellationShader : " << static_cast<bool>(multiviewFeatures.multiviewTessellationShader) << "\n";
|
||||
std::cout << "\t\tmultiviewGeometryShader : "
|
||||
<< static_cast<bool>( multiviewFeatures.multiviewGeometryShader ) << "\n";
|
||||
std::cout << "\t\tmultiviewTessellationShader : "
|
||||
<< static_cast<bool>( multiviewFeatures.multiviewTessellationShader ) << "\n";
|
||||
std::cout << "\n";
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_KHR_pipeline_executable_properties" ) )
|
||||
{
|
||||
vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR const& pipelineExecutablePropertiesFeatures = features2.get<vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR>();
|
||||
vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR const & pipelineExecutablePropertiesFeatures =
|
||||
features2.get<vk::PhysicalDevicePipelineExecutablePropertiesFeaturesKHR>();
|
||||
std::cout << "\tPipelineExectuablePropertiesFeatures:\n";
|
||||
std::cout << "\t\tpipelineExecutableInfo : " << static_cast<bool>(pipelineExecutablePropertiesFeatures.pipelineExecutableInfo) << "\n";
|
||||
std::cout << "\t\tpipelineExecutableInfo : "
|
||||
<< static_cast<bool>( pipelineExecutablePropertiesFeatures.pipelineExecutableInfo ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
vk::PhysicalDeviceProtectedMemoryFeatures const& protectedMemoryFeatures = features2.get<vk::PhysicalDeviceProtectedMemoryFeatures>();
|
||||
vk::PhysicalDeviceProtectedMemoryFeatures const & protectedMemoryFeatures =
|
||||
features2.get<vk::PhysicalDeviceProtectedMemoryFeatures>();
|
||||
std::cout << "\tProtectedMemoryFeatures:\n";
|
||||
std::cout << "\t\tprotectedMemory : " << static_cast<bool>( protectedMemoryFeatures.protectedMemory ) << "\n";
|
||||
std::cout << "\n";
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_NV_representative_fragment_test" ) )
|
||||
{
|
||||
vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV const& representativeFragmentTestFeatures = features2.get<vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV>();
|
||||
vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV const & representativeFragmentTestFeatures =
|
||||
features2.get<vk::PhysicalDeviceRepresentativeFragmentTestFeaturesNV>();
|
||||
std::cout << "\tRepresentativeFragmentTestFeatures:\n";
|
||||
std::cout << "\t\trepresentativeFragmentTest : " << static_cast<bool>(representativeFragmentTestFeatures.representativeFragmentTest) << "\n";
|
||||
std::cout << "\t\trepresentativeFragmentTest : "
|
||||
<< static_cast<bool>( representativeFragmentTestFeatures.representativeFragmentTest ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
vk::PhysicalDeviceSamplerYcbcrConversionFeatures const& samplerYcbcrConversionFeatures = features2.get<vk::PhysicalDeviceSamplerYcbcrConversionFeatures>();
|
||||
vk::PhysicalDeviceSamplerYcbcrConversionFeatures const & samplerYcbcrConversionFeatures =
|
||||
features2.get<vk::PhysicalDeviceSamplerYcbcrConversionFeatures>();
|
||||
std::cout << "\tSamplerYcbcrConversionFeatures:\n";
|
||||
std::cout << "\t\tsamplerYcbcrConversion : " << static_cast<bool>(samplerYcbcrConversionFeatures.samplerYcbcrConversion) << "\n";
|
||||
std::cout << "\t\tsamplerYcbcrConversion : "
|
||||
<< static_cast<bool>( samplerYcbcrConversionFeatures.samplerYcbcrConversion ) << "\n";
|
||||
std::cout << "\n";
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_scalar_block_layout" ) )
|
||||
{
|
||||
vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT const& scalarBlockLayoutFeatures = features2.get<vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT>();
|
||||
vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT const & scalarBlockLayoutFeatures =
|
||||
features2.get<vk::PhysicalDeviceScalarBlockLayoutFeaturesEXT>();
|
||||
std::cout << "\tScalarBlockLayoutFeatures:\n";
|
||||
std::cout << "\t\tscalarBlockLayout : " << static_cast<bool>(scalarBlockLayoutFeatures.scalarBlockLayout) << "\n";
|
||||
std::cout << "\t\tscalarBlockLayout : " << static_cast<bool>( scalarBlockLayoutFeatures.scalarBlockLayout )
|
||||
<< "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_KHR_shader_atomic_int64" ) )
|
||||
{
|
||||
vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR const& shaderAtomicInt64Features = features2.get<vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR>();
|
||||
vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR const & shaderAtomicInt64Features =
|
||||
features2.get<vk::PhysicalDeviceShaderAtomicInt64FeaturesKHR>();
|
||||
std::cout << "\tShaderAtomicInt64Features:\n";
|
||||
std::cout << "\t\tshaderBufferInt64Atomics : " << static_cast<bool>(shaderAtomicInt64Features.shaderBufferInt64Atomics) << "\n";
|
||||
std::cout << "\t\tshaderSharedInt64Atomics : " << static_cast<bool>(shaderAtomicInt64Features.shaderSharedInt64Atomics) << "\n";
|
||||
std::cout << "\t\tshaderBufferInt64Atomics : "
|
||||
<< static_cast<bool>( shaderAtomicInt64Features.shaderBufferInt64Atomics ) << "\n";
|
||||
std::cout << "\t\tshaderSharedInt64Atomics : "
|
||||
<< static_cast<bool>( shaderAtomicInt64Features.shaderSharedInt64Atomics ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_shader_demote_to_helper_invocation" ) )
|
||||
{
|
||||
vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT const& shaderDemoteToHelperInvocationFeatures = features2.get<vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>();
|
||||
vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT const & shaderDemoteToHelperInvocationFeatures =
|
||||
features2.get<vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>();
|
||||
std::cout << "\tShaderDemoteToHelperInvocationFeatures:\n";
|
||||
std::cout << "\t\tshaderDemoteToHelperInvocation : " << static_cast<bool>(shaderDemoteToHelperInvocationFeatures.shaderDemoteToHelperInvocation) << "\n";
|
||||
std::cout << "\t\tshaderDemoteToHelperInvocation : "
|
||||
<< static_cast<bool>( shaderDemoteToHelperInvocationFeatures.shaderDemoteToHelperInvocation ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
vk::PhysicalDeviceShaderDrawParametersFeatures const& shaderDrawParametersFeature = features2.get<vk::PhysicalDeviceShaderDrawParametersFeatures>();
|
||||
vk::PhysicalDeviceShaderDrawParametersFeatures const & shaderDrawParametersFeature =
|
||||
features2.get<vk::PhysicalDeviceShaderDrawParametersFeatures>();
|
||||
std::cout << "\tShaderDrawParametersFeature:\n";
|
||||
std::cout << "\t\tshaderDrawParameters : " << static_cast<bool>(shaderDrawParametersFeature.shaderDrawParameters) << "\n";
|
||||
std::cout << "\t\tshaderDrawParameters : "
|
||||
<< static_cast<bool>( shaderDrawParametersFeature.shaderDrawParameters ) << "\n";
|
||||
std::cout << "\n";
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_KHR_shader_float16_int8" ) )
|
||||
{
|
||||
vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR const& shaderFloat16Int8Features = features2.get<vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR>();
|
||||
vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR const & shaderFloat16Int8Features =
|
||||
features2.get<vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR>();
|
||||
std::cout << "\tShaderFloat16Int8Features:\n";
|
||||
std::cout << "\t\tshaderFloat16 : " << static_cast<bool>( shaderFloat16Int8Features.shaderFloat16 ) << "\n";
|
||||
std::cout << "\t\tshaderInt8 : " << static_cast<bool>( shaderFloat16Int8Features.shaderInt8 ) << "\n";
|
||||
@ -437,128 +635,165 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_NV_shader_image_footprint" ) )
|
||||
{
|
||||
vk::PhysicalDeviceShaderImageFootprintFeaturesNV const& shaderImageFootprintFeatures = features2.get<vk::PhysicalDeviceShaderImageFootprintFeaturesNV>();
|
||||
vk::PhysicalDeviceShaderImageFootprintFeaturesNV const & shaderImageFootprintFeatures =
|
||||
features2.get<vk::PhysicalDeviceShaderImageFootprintFeaturesNV>();
|
||||
std::cout << "\tShaderImageFootprintFeatures:\n";
|
||||
std::cout << "\t\timageFootprint : " << static_cast<bool>(shaderImageFootprintFeatures.imageFootprint) << "\n";
|
||||
std::cout << "\t\timageFootprint : " << static_cast<bool>( shaderImageFootprintFeatures.imageFootprint )
|
||||
<< "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_INTEL_shader_integer_functions2" ) )
|
||||
{
|
||||
vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL const& shaderIntegerFunctions2Features = features2.get<vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>();
|
||||
vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL const & shaderIntegerFunctions2Features =
|
||||
features2.get<vk::PhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>();
|
||||
std::cout << "\tShaderIntegerFunctions2Features:\n";
|
||||
std::cout << "\t\tshaderIntegerFunctions2 : " << static_cast<bool>(shaderIntegerFunctions2Features.shaderIntegerFunctions2) << "\n";
|
||||
std::cout << "\t\tshaderIntegerFunctions2 : "
|
||||
<< static_cast<bool>( shaderIntegerFunctions2Features.shaderIntegerFunctions2 ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_NV_shader_sm_builtins" ) )
|
||||
{
|
||||
vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV const& shaderSMBuiltinsFeatures = features2.get<vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV>();
|
||||
vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV const & shaderSMBuiltinsFeatures =
|
||||
features2.get<vk::PhysicalDeviceShaderSMBuiltinsFeaturesNV>();
|
||||
std::cout << "\tShaderSMBuiltinsFeatures:\n";
|
||||
std::cout << "\t\tshaderSMBuiltins : " << static_cast<bool>(shaderSMBuiltinsFeatures.shaderSMBuiltins) << "\n";
|
||||
std::cout << "\t\tshaderSMBuiltins : " << static_cast<bool>( shaderSMBuiltinsFeatures.shaderSMBuiltins )
|
||||
<< "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_KHR_shader_subgroup_extended_types" ) )
|
||||
{
|
||||
vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR const& shaderSubgroupExtendedTypesFeatures = features2.get<vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR>();
|
||||
vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR const & shaderSubgroupExtendedTypesFeatures =
|
||||
features2.get<vk::PhysicalDeviceShaderSubgroupExtendedTypesFeaturesKHR>();
|
||||
std::cout << "\tShaderSubgroupExtendedTypeFeatures:\n";
|
||||
std::cout << "\t\tshaderSubgroupExtendedTypes : " << static_cast<bool>(shaderSubgroupExtendedTypesFeatures.shaderSubgroupExtendedTypes) << "\n";
|
||||
std::cout << "\t\tshaderSubgroupExtendedTypes : "
|
||||
<< static_cast<bool>( shaderSubgroupExtendedTypesFeatures.shaderSubgroupExtendedTypes ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_NV_shading_rate_image" ) )
|
||||
{
|
||||
vk::PhysicalDeviceShadingRateImageFeaturesNV const& shadingRateImageFeatures = features2.get<vk::PhysicalDeviceShadingRateImageFeaturesNV>();
|
||||
vk::PhysicalDeviceShadingRateImageFeaturesNV const & shadingRateImageFeatures =
|
||||
features2.get<vk::PhysicalDeviceShadingRateImageFeaturesNV>();
|
||||
std::cout << "\tShadingRateImageFeatures:\n";
|
||||
std::cout << "\t\tshadingRateCoarseSampleOrder : " << static_cast<bool>(shadingRateImageFeatures.shadingRateCoarseSampleOrder) << "\n";
|
||||
std::cout << "\t\tshadingRateImage : " << static_cast<bool>(shadingRateImageFeatures.shadingRateImage) << "\n";
|
||||
std::cout << "\t\tshadingRateCoarseSampleOrder : "
|
||||
<< static_cast<bool>( shadingRateImageFeatures.shadingRateCoarseSampleOrder ) << "\n";
|
||||
std::cout << "\t\tshadingRateImage : "
|
||||
<< static_cast<bool>( shadingRateImageFeatures.shadingRateImage ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_subgroup_size_control" ) )
|
||||
{
|
||||
vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT const& subgroupSizeControlFeatures = features2.get<vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT>();
|
||||
vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT const & subgroupSizeControlFeatures =
|
||||
features2.get<vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT>();
|
||||
std::cout << "\tSubgroupSizeControlFeatures:\n";
|
||||
std::cout << "\t\tcomputeFullSubgroups : " << static_cast<bool>(subgroupSizeControlFeatures.computeFullSubgroups) << "\n";
|
||||
std::cout << "\t\tsubgroupSizeControl : " << static_cast<bool>(subgroupSizeControlFeatures.subgroupSizeControl) << "\n";
|
||||
std::cout << "\t\tcomputeFullSubgroups : "
|
||||
<< static_cast<bool>( subgroupSizeControlFeatures.computeFullSubgroups ) << "\n";
|
||||
std::cout << "\t\tsubgroupSizeControl : "
|
||||
<< static_cast<bool>( subgroupSizeControlFeatures.subgroupSizeControl ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_texel_buffer_alignment" ) )
|
||||
{
|
||||
vk::PhysicalDeviceTexelBufferAlignmentFeaturesEXT const& texelBufferAlignmentFeatures = features2.get<vk::PhysicalDeviceTexelBufferAlignmentFeaturesEXT>();
|
||||
vk::PhysicalDeviceTexelBufferAlignmentFeaturesEXT const & texelBufferAlignmentFeatures =
|
||||
features2.get<vk::PhysicalDeviceTexelBufferAlignmentFeaturesEXT>();
|
||||
std::cout << "\tTexelBufferAlignmentFeatures:\n";
|
||||
std::cout << "\t\ttexelBufferAlignment : " << static_cast<bool>(texelBufferAlignmentFeatures.texelBufferAlignment) << "\n";
|
||||
std::cout << "\t\ttexelBufferAlignment : "
|
||||
<< static_cast<bool>( texelBufferAlignmentFeatures.texelBufferAlignment ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_texture_compression_astc_hdr" ) )
|
||||
{
|
||||
vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT const& textureCompressionASTCHDRFeatures = features2.get<vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT>();
|
||||
vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT const & textureCompressionASTCHDRFeatures =
|
||||
features2.get<vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT>();
|
||||
std::cout << "\tTextureCompressionASTCHHRFeatures:\n";
|
||||
std::cout << "\t\ttextureCompressionASTC_HDR : " << static_cast<bool>(textureCompressionASTCHDRFeatures.textureCompressionASTC_HDR) << "\n";
|
||||
std::cout << "\t\ttextureCompressionASTC_HDR : "
|
||||
<< static_cast<bool>( textureCompressionASTCHDRFeatures.textureCompressionASTC_HDR ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_KHR_timeline_semaphore" ) )
|
||||
{
|
||||
vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR const& timelineSemaphoreFeatures = features2.get<vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>();
|
||||
vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR const & timelineSemaphoreFeatures =
|
||||
features2.get<vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>();
|
||||
std::cout << "\tTimelineSemaphoreFeatures:\n";
|
||||
std::cout << "\t\ttimelineSemaphore :" << static_cast<bool>(timelineSemaphoreFeatures.timelineSemaphore) << "\n";
|
||||
std::cout << "\t\ttimelineSemaphore :" << static_cast<bool>( timelineSemaphoreFeatures.timelineSemaphore )
|
||||
<< "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_transform_feedback" ) )
|
||||
{
|
||||
vk::PhysicalDeviceTransformFeedbackFeaturesEXT const& transformFeedbackFeatures = features2.get<vk::PhysicalDeviceTransformFeedbackFeaturesEXT>();
|
||||
vk::PhysicalDeviceTransformFeedbackFeaturesEXT const & transformFeedbackFeatures =
|
||||
features2.get<vk::PhysicalDeviceTransformFeedbackFeaturesEXT>();
|
||||
std::cout << "\tTransformFeedbackFeatures:\n";
|
||||
std::cout << "\t\tgeometryStreams : " << static_cast<bool>( transformFeedbackFeatures.geometryStreams ) << "\n";
|
||||
std::cout << "\t\ttransformFeedback : " << static_cast<bool>(transformFeedbackFeatures.transformFeedback) << "\n";
|
||||
std::cout << "\t\ttransformFeedback : " << static_cast<bool>( transformFeedbackFeatures.transformFeedback )
|
||||
<< "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_KHR_uniform_buffer_standard_layout" ) )
|
||||
{
|
||||
vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR const& uniformBufferStandardLayoutFeatures = features2.get<vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR>();
|
||||
vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR const & uniformBufferStandardLayoutFeatures =
|
||||
features2.get<vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR>();
|
||||
std::cout << "\tUniformBufferStandardLayoutFeatures:\n";
|
||||
std::cout << "\t\tuniformBufferStandardLayout : " << static_cast<bool>(uniformBufferStandardLayoutFeatures.uniformBufferStandardLayout) << "\n";
|
||||
std::cout << "\t\tuniformBufferStandardLayout : "
|
||||
<< static_cast<bool>( uniformBufferStandardLayoutFeatures.uniformBufferStandardLayout ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_KHR_variable_pointers" ) )
|
||||
{
|
||||
vk::PhysicalDeviceVariablePointersFeatures const& variablePointersFeatures = features2.get<vk::PhysicalDeviceVariablePointersFeatures>();
|
||||
vk::PhysicalDeviceVariablePointersFeatures const & variablePointersFeatures =
|
||||
features2.get<vk::PhysicalDeviceVariablePointersFeatures>();
|
||||
std::cout << "\tVariablePointersFeatures:\n";
|
||||
std::cout << "\t\tvariablePointers : " << static_cast<bool>(variablePointersFeatures.variablePointers) << "\n";
|
||||
std::cout << "\t\tvariablePointersStorageBuffer : " << static_cast<bool>(variablePointersFeatures.variablePointersStorageBuffer) << "\n";
|
||||
std::cout << "\t\tvariablePointers : "
|
||||
<< static_cast<bool>( variablePointersFeatures.variablePointers ) << "\n";
|
||||
std::cout << "\t\tvariablePointersStorageBuffer : "
|
||||
<< static_cast<bool>( variablePointersFeatures.variablePointersStorageBuffer ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_vertex_attribute_divisor" ) )
|
||||
{
|
||||
vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT const& vertexAttributeDivisorFeatures = features2.get<vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT>();
|
||||
vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT const & vertexAttributeDivisorFeatures =
|
||||
features2.get<vk::PhysicalDeviceVertexAttributeDivisorFeaturesEXT>();
|
||||
std::cout << "\tVertexAttributeDivisorFeature:\n";
|
||||
std::cout << "\t\tvertexAttributeInstanceRateDivisor : " << static_cast<bool>(vertexAttributeDivisorFeatures.vertexAttributeInstanceRateDivisor) << "\n";
|
||||
std::cout << "\t\tvertexAttributeInstanceRateZeroDivisor : " << static_cast<bool>(vertexAttributeDivisorFeatures.vertexAttributeInstanceRateZeroDivisor) << "\n";
|
||||
std::cout << "\t\tvertexAttributeInstanceRateDivisor : "
|
||||
<< static_cast<bool>( vertexAttributeDivisorFeatures.vertexAttributeInstanceRateDivisor ) << "\n";
|
||||
std::cout << "\t\tvertexAttributeInstanceRateZeroDivisor : "
|
||||
<< static_cast<bool>( vertexAttributeDivisorFeatures.vertexAttributeInstanceRateZeroDivisor ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_KHR_vulkan_memory_model" ) )
|
||||
{
|
||||
vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR const& vulkanMemoryModelFeatures = features2.get<vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR>();
|
||||
vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR const & vulkanMemoryModelFeatures =
|
||||
features2.get<vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR>();
|
||||
std::cout << "\tVulkanMemoryModelFeatures:\n";
|
||||
std::cout << "\t\tvulkanMemoryModel : " << static_cast<bool>(vulkanMemoryModelFeatures.vulkanMemoryModel) << "\n";
|
||||
std::cout << "\t\tvulkanMemoryModelAvailabilityVisibilityChains : " << static_cast<bool>(vulkanMemoryModelFeatures.vulkanMemoryModelAvailabilityVisibilityChains) << "\n";
|
||||
std::cout << "\t\tvulkanMemoryModelDeviceScope : " << static_cast<bool>(vulkanMemoryModelFeatures.vulkanMemoryModelDeviceScope) << "\n";
|
||||
std::cout << "\t\tvulkanMemoryModel : "
|
||||
<< static_cast<bool>( vulkanMemoryModelFeatures.vulkanMemoryModel ) << "\n";
|
||||
std::cout << "\t\tvulkanMemoryModelAvailabilityVisibilityChains : "
|
||||
<< static_cast<bool>( vulkanMemoryModelFeatures.vulkanMemoryModelAvailabilityVisibilityChains )
|
||||
<< "\n";
|
||||
std::cout << "\t\tvulkanMemoryModelDeviceScope : "
|
||||
<< static_cast<bool>( vulkanMemoryModelFeatures.vulkanMemoryModelDeviceScope ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_KHR_sampler_ycbcr_conversion" ) )
|
||||
{
|
||||
vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT const& ycbcrImageArraysFeatures = features2.get<vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT>();
|
||||
vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT const & ycbcrImageArraysFeatures =
|
||||
features2.get<vk::PhysicalDeviceYcbcrImageArraysFeaturesEXT>();
|
||||
std::cout << "\tYcbcrImageArraysFeatures:\n";
|
||||
std::cout << "\t\tycbcrImageArrays : " << static_cast<bool>(ycbcrImageArraysFeatures.ycbcrImageArrays) << "\n";
|
||||
std::cout << "\t\tycbcrImageArrays : " << static_cast<bool>( ycbcrImageArraysFeatures.ycbcrImageArrays )
|
||||
<< "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
static char const * AppName = "PhysicalDeviceGroups";
|
||||
@ -39,13 +40,16 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
for ( size_t i = 0; i < groupProperties.size(); i++ )
|
||||
{
|
||||
std::cout << "Group Properties " << i << "\n";
|
||||
std::cout << "\t" << "physicalDeviceCount = " << groupProperties[i].physicalDeviceCount << "\n";
|
||||
std::cout << "\t" << "physicalDevices:\n";
|
||||
std::cout << "\t"
|
||||
<< "physicalDeviceCount = " << groupProperties[i].physicalDeviceCount << "\n";
|
||||
std::cout << "\t"
|
||||
<< "physicalDevices:\n";
|
||||
for ( size_t j = 0; j < groupProperties[i].physicalDeviceCount; j++ )
|
||||
{
|
||||
std::cout << "\t\t" << j << " : " << groupProperties[i].physicalDevices[j].getProperties().deviceName << "\n";
|
||||
}
|
||||
std::cout << "\t" << "subsetAllocation = " << static_cast<bool>(groupProperties[i].subsetAllocation) << "\n";
|
||||
std::cout << "\t"
|
||||
<< "subsetAllocation = " << static_cast<bool>( groupProperties[i].subsetAllocation ) << "\n";
|
||||
std::cout << "\n";
|
||||
|
||||
if ( 1 < groupProperties[i].physicalDeviceCount )
|
||||
@ -56,18 +60,22 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
|
||||
|
||||
// get the first index into queueFamiliyProperties which supports graphics
|
||||
size_t graphicsQueueFamilyIndex = std::distance(queueFamilyProperties.begin(),
|
||||
std::find_if(queueFamilyProperties.begin(),
|
||||
queueFamilyProperties.end(),
|
||||
[](vk::QueueFamilyProperties const& qfp) { return qfp.queueFlags & vk::QueueFlagBits::eGraphics; }));
|
||||
size_t graphicsQueueFamilyIndex = std::distance(
|
||||
queueFamilyProperties.begin(),
|
||||
std::find_if(
|
||||
queueFamilyProperties.begin(), queueFamilyProperties.end(), []( vk::QueueFamilyProperties const & qfp ) {
|
||||
return qfp.queueFlags & vk::QueueFlagBits::eGraphics;
|
||||
} ) );
|
||||
assert( graphicsQueueFamilyIndex < queueFamilyProperties.size() );
|
||||
|
||||
// create a UniqueDevice
|
||||
float queuePriority = 0.0f;
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(vk::DeviceQueueCreateFlags(), static_cast<uint32_t>(graphicsQueueFamilyIndex), 1, &queuePriority);
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
|
||||
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
|
||||
vk::DeviceCreateInfo deviceCreateInfo( vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo );
|
||||
|
||||
vk::DeviceGroupDeviceCreateInfo deviceGroupDeviceCreateInfo(groupProperties[i].physicalDeviceCount, groupProperties[i].physicalDevices);
|
||||
vk::DeviceGroupDeviceCreateInfo deviceGroupDeviceCreateInfo( groupProperties[i].physicalDeviceCount,
|
||||
groupProperties[i].physicalDevices );
|
||||
deviceCreateInfo.pNext = &deviceGroupDeviceCreateInfo;
|
||||
|
||||
vk::UniqueDevice device = physicalDevice.createDeviceUnique( deviceCreateInfo );
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
@ -62,26 +63,34 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
for ( size_t i = 0; i < physicalDevices.size(); i++ )
|
||||
{
|
||||
// some properties are only valid, if a corresponding extension is available!
|
||||
std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
|
||||
std::vector<vk::ExtensionProperties> extensionProperties =
|
||||
physicalDevices[i].enumerateDeviceExtensionProperties();
|
||||
bool containsMemoryBudget = vk::su::contains( extensionProperties, "VK_EXT_memory_budget" );
|
||||
|
||||
std::cout << "PhysicalDevice " << i << "\n";
|
||||
auto memoryProperties2 = physicalDevices[i].getMemoryProperties2<vk::PhysicalDeviceMemoryProperties2, vk::PhysicalDeviceMemoryBudgetPropertiesEXT>();
|
||||
vk::PhysicalDeviceMemoryProperties const& memoryProperties = memoryProperties2.get<vk::PhysicalDeviceMemoryProperties2>().memoryProperties;
|
||||
vk::PhysicalDeviceMemoryBudgetPropertiesEXT const& memoryBudgetProperties = memoryProperties2.get<vk::PhysicalDeviceMemoryBudgetPropertiesEXT>();
|
||||
auto memoryProperties2 =
|
||||
physicalDevices[i]
|
||||
.getMemoryProperties2<vk::PhysicalDeviceMemoryProperties2, vk::PhysicalDeviceMemoryBudgetPropertiesEXT>();
|
||||
vk::PhysicalDeviceMemoryProperties const & memoryProperties =
|
||||
memoryProperties2.get<vk::PhysicalDeviceMemoryProperties2>().memoryProperties;
|
||||
vk::PhysicalDeviceMemoryBudgetPropertiesEXT const & memoryBudgetProperties =
|
||||
memoryProperties2.get<vk::PhysicalDeviceMemoryBudgetPropertiesEXT>();
|
||||
std::cout << "memoryHeapCount: " << memoryProperties.memoryHeapCount << "\n";
|
||||
for ( uint32_t j = 0; j < memoryProperties.memoryHeapCount; j++ )
|
||||
{
|
||||
std::cout << " " << j << ": size = " << formatSize(memoryProperties.memoryHeaps[j].size) << ", flags = " << vk::to_string(memoryProperties.memoryHeaps[j].flags) << "\n";
|
||||
std::cout << " " << j << ": size = " << formatSize( memoryProperties.memoryHeaps[j].size )
|
||||
<< ", flags = " << vk::to_string( memoryProperties.memoryHeaps[j].flags ) << "\n";
|
||||
if ( containsMemoryBudget )
|
||||
{
|
||||
std::cout << " heapBudget = " << formatSize(memoryBudgetProperties.heapBudget[j]) << ", heapUsage = " << formatSize(memoryBudgetProperties.heapUsage[j]) << "\n";
|
||||
std::cout << " heapBudget = " << formatSize( memoryBudgetProperties.heapBudget[j] )
|
||||
<< ", heapUsage = " << formatSize( memoryBudgetProperties.heapUsage[j] ) << "\n";
|
||||
}
|
||||
}
|
||||
std::cout << "memoryTypeCount: " << memoryProperties.memoryTypeCount << "\n";
|
||||
for ( uint32_t j = 0; j < memoryProperties.memoryTypeCount; j++ )
|
||||
{
|
||||
std::cout << " " << j << ": heapIndex = " << memoryProperties.memoryTypes[j].heapIndex << ", flags = " << vk::to_string(memoryProperties.memoryTypes[j].propertyFlags) << "\n";
|
||||
std::cout << " " << j << ": heapIndex = " << memoryProperties.memoryTypes[j].heapIndex
|
||||
<< ", flags = " << vk::to_string( memoryProperties.memoryTypes[j].propertyFlags ) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
@ -42,29 +43,44 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
for ( size_t i = 0; i < physicalDevices.size(); i++ )
|
||||
{
|
||||
// some features are only valid, if a corresponding extension is available!
|
||||
std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
|
||||
std::vector<vk::ExtensionProperties> extensionProperties =
|
||||
physicalDevices[i].enumerateDeviceExtensionProperties();
|
||||
|
||||
std::cout << "PhysicalDevice " << i << "\n";
|
||||
|
||||
// need to explicitly specify all the template arguments for getQueueFamilyProperties2 to make the compiler happy
|
||||
using Chain = vk::StructureChain<vk::QueueFamilyProperties2, vk::QueueFamilyCheckpointPropertiesNV>;
|
||||
auto queueFamilyProperties2 = physicalDevices[i].getQueueFamilyProperties2<Chain, std::allocator<Chain>, vk::DispatchLoaderDynamic>();
|
||||
auto queueFamilyProperties2 =
|
||||
physicalDevices[i].getQueueFamilyProperties2<Chain, std::allocator<Chain>, vk::DispatchLoaderDynamic>();
|
||||
for ( size_t j = 0; j < queueFamilyProperties2.size(); j++ )
|
||||
{
|
||||
std::cout << "\t" << "QueueFamily " << j << "\n";
|
||||
vk::QueueFamilyProperties const& properties = queueFamilyProperties2[j].get<vk::QueueFamilyProperties2>().queueFamilyProperties;
|
||||
std::cout << "\t\t" << "QueueFamilyProperties:\n";
|
||||
std::cout << "\t\t\t" << "queueFlags = " << vk::to_string(properties.queueFlags) << "\n";
|
||||
std::cout << "\t\t\t" << "queueCount = " << properties.queueCount << "\n";
|
||||
std::cout << "\t\t\t" << "timestampValidBits = " << properties.timestampValidBits << "\n";
|
||||
std::cout << "\t\t\t" << "minImageTransferGranularity = " << properties.minImageTransferGranularity.width << " x " << properties.minImageTransferGranularity.height << " x " << properties.minImageTransferGranularity.depth << "\n";
|
||||
std::cout << "\t"
|
||||
<< "QueueFamily " << j << "\n";
|
||||
vk::QueueFamilyProperties const & properties =
|
||||
queueFamilyProperties2[j].get<vk::QueueFamilyProperties2>().queueFamilyProperties;
|
||||
std::cout << "\t\t"
|
||||
<< "QueueFamilyProperties:\n";
|
||||
std::cout << "\t\t\t"
|
||||
<< "queueFlags = " << vk::to_string( properties.queueFlags ) << "\n";
|
||||
std::cout << "\t\t\t"
|
||||
<< "queueCount = " << properties.queueCount << "\n";
|
||||
std::cout << "\t\t\t"
|
||||
<< "timestampValidBits = " << properties.timestampValidBits << "\n";
|
||||
std::cout << "\t\t\t"
|
||||
<< "minImageTransferGranularity = " << properties.minImageTransferGranularity.width << " x "
|
||||
<< properties.minImageTransferGranularity.height << " x "
|
||||
<< properties.minImageTransferGranularity.depth << "\n";
|
||||
std::cout << "\n";
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_NV_device_diagnostic_checkpoints" ) )
|
||||
{
|
||||
vk::QueueFamilyCheckpointPropertiesNV const& checkpointProperties = queueFamilyProperties2[j].get<vk::QueueFamilyCheckpointPropertiesNV>();
|
||||
std::cout << "\t\t" << "CheckPointPropertiesNV:\n";
|
||||
std::cout << "\t\t\t" << "checkpointExecutionStageMask = " << vk::to_string(checkpointProperties.checkpointExecutionStageMask) << "\n";
|
||||
vk::QueueFamilyCheckpointPropertiesNV const & checkpointProperties =
|
||||
queueFamilyProperties2[j].get<vk::QueueFamilyCheckpointPropertiesNV>();
|
||||
std::cout << "\t\t"
|
||||
<< "CheckPointPropertiesNV:\n";
|
||||
std::cout << "\t\t\t"
|
||||
<< "checkpointExecutionStageMask = "
|
||||
<< vk::to_string( checkpointProperties.checkpointExecutionStageMask ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <thread>
|
||||
@ -55,7 +56,6 @@ timestamp_t getMilliseconds()
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static char const * AppName = "PipelineCache";
|
||||
static char const * EngineName = "Vulkan.hpp";
|
||||
|
||||
@ -73,17 +73,29 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
@ -91,29 +103,51 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
textureData.setImage( device, commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(surfaceData.extent));
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice(
|
||||
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( surfaceData.extent ) );
|
||||
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device,
|
||||
{ {vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex}, {vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment} });
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device,
|
||||
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
|
||||
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, depthBufferData.format);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
depthBufferData.format );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, sizeof(texturedCubeData), vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
vk::su::copyToDevice(device, vertexBufferData.deviceMemory, texturedCubeData, sizeof(texturedCubeData) / sizeof(texturedCubeData[0]));
|
||||
vk::su::BufferData vertexBufferData(
|
||||
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
|
||||
vk::su::copyToDevice( device,
|
||||
vertexBufferData.deviceMemory,
|
||||
texturedCubeData,
|
||||
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
|
||||
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(device, { {vk::DescriptorType::eUniformBuffer, 1}, {vk::DescriptorType::eCombinedImageSampler, 1} });
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::su::updateDescriptorSets(device, descriptorSet, {{vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView()}}, textureData);
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView() } },
|
||||
textureData );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
@ -248,7 +282,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
}
|
||||
|
||||
// Feed the initial cache data into cache creation
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique(vk::PipelineCacheCreateInfo(vk::PipelineCacheCreateFlags(), startCacheSize, startCacheData));
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique(
|
||||
vk::PipelineCacheCreateInfo( vk::PipelineCacheCreateFlags(), startCacheSize, startCacheData ) );
|
||||
|
||||
// Free our initialData now that pipeline cache has been created
|
||||
free( startCacheData );
|
||||
@ -256,16 +291,26 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
// Time (roughly) taken to create the graphics pipeline
|
||||
timestamp_t start = getMilliseconds();
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr),
|
||||
sizeof(texturedCubeData[0]), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise, true, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline =
|
||||
vk::su::createGraphicsPipeline( device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
sizeof( texturedCubeData[0] ),
|
||||
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise,
|
||||
true,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
timestamp_t elapsed = getMilliseconds() - start;
|
||||
std::cout << " vkCreateGraphicsPipeline time: " << (double)elapsed << " ms\n";
|
||||
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique(vk::SemaphoreCreateInfo(vk::SemaphoreCreateFlags()));
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore =
|
||||
device->createSemaphoreUnique( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
|
||||
|
||||
// Get the index of the next available swapchain image:
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), UINT64_MAX, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer =
|
||||
device->acquireNextImageKHR( swapChainData.swapChain.get(), UINT64_MAX, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
@ -273,12 +318,24 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
|
||||
commandBuffer->beginRenderPass(vk::RenderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(), surfaceData.extent), 2, clearValues), vk::SubpassContents::eInline);
|
||||
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D(), surfaceData.extent ),
|
||||
2,
|
||||
clearValues ),
|
||||
vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), {});
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), {} );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
commandBuffer->draw( 12 * 3, 1, 0, 0 );
|
||||
@ -294,7 +351,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
// Store away the cache that we've populated. This could conceivably happen
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <thread>
|
||||
|
||||
static char const * AppName = "PipelineDerivative";
|
||||
@ -39,17 +40,29 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
@ -57,29 +70,51 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(surfaceData.extent));
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice(
|
||||
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( surfaceData.extent ) );
|
||||
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device,
|
||||
{ {vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex}, {vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment} });
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device,
|
||||
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
|
||||
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, depthBufferData.format);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
depthBufferData.format );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, sizeof(texturedCubeData), vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
vk::su::copyToDevice(device, vertexBufferData.deviceMemory, texturedCubeData, sizeof(texturedCubeData) / sizeof(texturedCubeData[0]));
|
||||
vk::su::BufferData vertexBufferData(
|
||||
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
|
||||
vk::su::copyToDevice( device,
|
||||
vertexBufferData.deviceMemory,
|
||||
texturedCubeData,
|
||||
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
|
||||
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(device, { {vk::DescriptorType::eUniformBuffer, 1}, {vk::DescriptorType::eCombinedImageSampler, 1} });
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::su::updateDescriptorSets(device, descriptorSet, {{vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView()}}, textureData);
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView() } },
|
||||
textureData );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
|
||||
@ -90,43 +125,96 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
// First pipeline has VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT set.
|
||||
// Second pipeline has a modified fragment shader and sets the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag.
|
||||
|
||||
vk::PipelineShaderStageCreateInfo pipelineShaderStageCreateInfos[2] =
|
||||
{
|
||||
vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule.get(), "main"),
|
||||
vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule.get(), "main")
|
||||
vk::PipelineShaderStageCreateInfo pipelineShaderStageCreateInfos[2] = {
|
||||
vk::PipelineShaderStageCreateInfo(
|
||||
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule.get(), "main" ),
|
||||
vk::PipelineShaderStageCreateInfo(
|
||||
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule.get(), "main" )
|
||||
};
|
||||
|
||||
vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( texturedCubeData[0] ) );
|
||||
vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
|
||||
{
|
||||
vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[2] = {
|
||||
vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ),
|
||||
vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 )
|
||||
};
|
||||
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(vk::PipelineVertexInputStateCreateFlags(), 1, &vertexInputBindingDescription, 2, vertexInputAttributeDescriptions);
|
||||
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(
|
||||
vk::PipelineVertexInputStateCreateFlags(),
|
||||
1,
|
||||
&vertexInputBindingDescription,
|
||||
2,
|
||||
vertexInputAttributeDescriptions );
|
||||
|
||||
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleList);
|
||||
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(
|
||||
vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleList );
|
||||
|
||||
vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo(vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr);
|
||||
vk::PipelineViewportStateCreateInfo pipelineViewportStateCreateInfo(
|
||||
vk::PipelineViewportStateCreateFlags(), 1, nullptr, 1, nullptr );
|
||||
|
||||
vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo(vk::PipelineRasterizationStateCreateFlags(), false, false, vk::PolygonMode::eFill, vk::CullModeFlagBits::eBack, vk::FrontFace::eClockwise, false, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
vk::PipelineRasterizationStateCreateInfo pipelineRasterizationStateCreateInfo(
|
||||
vk::PipelineRasterizationStateCreateFlags(),
|
||||
false,
|
||||
false,
|
||||
vk::PolygonMode::eFill,
|
||||
vk::CullModeFlagBits::eBack,
|
||||
vk::FrontFace::eClockwise,
|
||||
false,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
1.0f );
|
||||
|
||||
vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( {}, vk::SampleCountFlagBits::e1 );
|
||||
|
||||
vk::StencilOpState stencilOpState(vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways);
|
||||
vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo(vk::PipelineDepthStencilStateCreateFlags(), true, true, vk::CompareOp::eLessOrEqual, false, false, stencilOpState, stencilOpState);
|
||||
vk::StencilOpState stencilOpState(
|
||||
vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::StencilOp::eKeep, vk::CompareOp::eAlways );
|
||||
vk::PipelineDepthStencilStateCreateInfo pipelineDepthStencilStateCreateInfo(
|
||||
vk::PipelineDepthStencilStateCreateFlags(),
|
||||
true,
|
||||
true,
|
||||
vk::CompareOp::eLessOrEqual,
|
||||
false,
|
||||
false,
|
||||
stencilOpState,
|
||||
stencilOpState );
|
||||
|
||||
vk::ColorComponentFlags colorComponentFlags(vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA);
|
||||
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState(false, vk::BlendFactor::eZero, vk::BlendFactor::eZero, vk::BlendOp::eAdd, vk::BlendFactor::eZero, vk::BlendFactor::eZero, vk::BlendOp::eAdd, colorComponentFlags);
|
||||
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo(vk::PipelineColorBlendStateCreateFlags(), false, vk::LogicOp::eNoOp, 1, &pipelineColorBlendAttachmentState, { { 1.0f, 1.0f, 1.0f, 1.0f } });
|
||||
vk::ColorComponentFlags colorComponentFlags( vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG |
|
||||
vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA );
|
||||
vk::PipelineColorBlendAttachmentState pipelineColorBlendAttachmentState( false,
|
||||
vk::BlendFactor::eZero,
|
||||
vk::BlendFactor::eZero,
|
||||
vk::BlendOp::eAdd,
|
||||
vk::BlendFactor::eZero,
|
||||
vk::BlendFactor::eZero,
|
||||
vk::BlendOp::eAdd,
|
||||
colorComponentFlags );
|
||||
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateFlags(),
|
||||
false,
|
||||
vk::LogicOp::eNoOp,
|
||||
1,
|
||||
&pipelineColorBlendAttachmentState,
|
||||
{ { 1.0f, 1.0f, 1.0f, 1.0f } } );
|
||||
|
||||
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
|
||||
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates);
|
||||
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(
|
||||
vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates );
|
||||
|
||||
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo(vk::PipelineCreateFlagBits::eAllowDerivatives, 2, pipelineShaderStageCreateInfos, &pipelineVertexInputStateCreateInfo,
|
||||
&pipelineInputAssemblyStateCreateInfo, nullptr, &pipelineViewportStateCreateInfo, &pipelineRasterizationStateCreateInfo, &pipelineMultisampleStateCreateInfo,
|
||||
&pipelineDepthStencilStateCreateInfo, &pipelineColorBlendStateCreateInfo, &pipelineDynamicStateCreateInfo, pipelineLayout.get(), renderPass.get());
|
||||
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlagBits::eAllowDerivatives,
|
||||
2,
|
||||
pipelineShaderStageCreateInfos,
|
||||
&pipelineVertexInputStateCreateInfo,
|
||||
&pipelineInputAssemblyStateCreateInfo,
|
||||
nullptr,
|
||||
&pipelineViewportStateCreateInfo,
|
||||
&pipelineRasterizationStateCreateInfo,
|
||||
&pipelineMultisampleStateCreateInfo,
|
||||
&pipelineDepthStencilStateCreateInfo,
|
||||
&pipelineColorBlendStateCreateInfo,
|
||||
&pipelineDynamicStateCreateInfo,
|
||||
pipelineLayout.get(),
|
||||
renderPass.get() );
|
||||
|
||||
vk::UniquePipeline basePipeline = device->createGraphicsPipelineUnique(pipelineCache.get(), graphicsPipelineCreateInfo);
|
||||
vk::UniquePipeline basePipeline =
|
||||
device->createGraphicsPipelineUnique( pipelineCache.get(), graphicsPipelineCreateInfo );
|
||||
|
||||
// Now create the derivative pipeline, using a different fragment shader
|
||||
// This shader will shade the cube faces with interpolated colors
|
||||
@ -145,24 +233,29 @@ void main()
|
||||
|
||||
// Convert GLSL to SPIR-V
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule fragmentShaderModule2 = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C_2);
|
||||
vk::UniqueShaderModule fragmentShaderModule2 =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C_2 );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
// Modify pipeline info to reflect derivation
|
||||
pipelineShaderStageCreateInfos[1] = vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule2.get(), "main");
|
||||
pipelineShaderStageCreateInfos[1] = vk::PipelineShaderStageCreateInfo(
|
||||
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule2.get(), "main" );
|
||||
graphicsPipelineCreateInfo.flags = vk::PipelineCreateFlagBits::eDerivative;
|
||||
graphicsPipelineCreateInfo.basePipelineHandle = basePipeline.get();
|
||||
graphicsPipelineCreateInfo.basePipelineIndex = -1;
|
||||
|
||||
// And create the derived pipeline
|
||||
vk::UniquePipeline derivedPipeline = device->createGraphicsPipelineUnique(pipelineCache.get(), graphicsPipelineCreateInfo);
|
||||
vk::UniquePipeline derivedPipeline =
|
||||
device->createGraphicsPipelineUnique( pipelineCache.get(), graphicsPipelineCreateInfo );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique(vk::SemaphoreCreateInfo(vk::SemaphoreCreateFlags()));
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore =
|
||||
device->createSemaphoreUnique( vk::SemaphoreCreateInfo( vk::SemaphoreCreateFlags() ) );
|
||||
|
||||
// Get the index of the next available swapchain image
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), UINT64_MAX, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer =
|
||||
device->acquireNextImageKHR( swapChainData.swapChain.get(), UINT64_MAX, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
@ -170,12 +263,24 @@ void main()
|
||||
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
|
||||
commandBuffer->beginRenderPass(vk::RenderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(), surfaceData.extent), 2, clearValues), vk::SubpassContents::eInline);
|
||||
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D(), surfaceData.extent ),
|
||||
2,
|
||||
clearValues ),
|
||||
vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, derivedPipeline.get() );
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), {});
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), {} );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
commandBuffer->draw( 12 * 3, 1, 0, 0 );
|
||||
@ -191,7 +296,8 @@ void main()
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
}
|
||||
catch ( vk::SystemError & err )
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
@ -81,77 +82,115 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(surfaceData.extent));
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice(
|
||||
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( surfaceData.extent ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, depthBufferData.format);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
depthBufferData.format );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, sizeof(texturedCubeData), vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
vk::su::copyToDevice(device, vertexBufferData.deviceMemory, texturedCubeData, sizeof(texturedCubeData) / sizeof(texturedCubeData[0]));
|
||||
vk::su::BufferData vertexBufferData(
|
||||
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
|
||||
vk::su::copyToDevice( device,
|
||||
vertexBufferData.deviceMemory,
|
||||
texturedCubeData,
|
||||
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
|
||||
|
||||
// Create binding and layout for the following, matching contents of shader
|
||||
// binding 0 = uniform buffer (MVP)
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device, { {vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex} });
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
// Set up our push constant range, which mirrors the declaration of
|
||||
vk::PushConstantRange pushConstantRanges( vk::ShaderStageFlagBits::eFragment, 0, 8 );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get(), 1, &pushConstantRanges));
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::PipelineLayoutCreateInfo(
|
||||
vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get(), 1, &pushConstantRanges ) );
|
||||
|
||||
// Create a single pool to contain data for our descriptor set
|
||||
vk::DescriptorPoolSize poolSizes[2] =
|
||||
{
|
||||
vk::DescriptorPoolSize(vk::DescriptorType::eUniformBuffer, 1),
|
||||
vk::DescriptorPoolSize(vk::DescriptorType::eCombinedImageSampler, 1)
|
||||
};
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(vk::DescriptorPoolCreateInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 2, poolSizes));
|
||||
vk::DescriptorPoolSize poolSizes[2] = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
|
||||
vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 2, poolSizes ) );
|
||||
|
||||
// Populate descriptor sets
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
// Populate with info about our uniform buffer for MVP
|
||||
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
|
||||
device->updateDescriptorSets(vk::WriteDescriptorSet(*descriptorSet, 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfo), {});
|
||||
device->updateDescriptorSets(
|
||||
vk::WriteDescriptorSet( *descriptorSet, 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfo ), {} );
|
||||
|
||||
// Create our push constant data, which matches shader expectations
|
||||
std::array<unsigned, 2> pushConstants = { (unsigned)2, (unsigned)0x3F800000 };
|
||||
|
||||
// Ensure we have enough room for push constant data
|
||||
assert((sizeof(pushConstants) <= physicalDevice.getProperties().limits.maxPushConstantsSize) && "Too many push constants");
|
||||
assert( ( sizeof( pushConstants ) <= physicalDevice.getProperties().limits.maxPushConstantsSize ) &&
|
||||
"Too many push constants" );
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
commandBuffer->pushConstants<unsigned>(pipelineLayout.get(), vk::ShaderStageFlagBits::eFragment, 0, pushConstants);
|
||||
commandBuffer->pushConstants<unsigned>(
|
||||
pipelineLayout.get(), vk::ShaderStageFlagBits::eFragment, 0, pushConstants );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr),
|
||||
sizeof(texturedCubeData[0]), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise, true, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(
|
||||
device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
sizeof( texturedCubeData[0] ),
|
||||
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32B32A32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise,
|
||||
true,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(
|
||||
swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
@ -159,13 +198,24 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(0, 0), surfaceData.extent), 2, clearValues);
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr);
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
commandBuffer->draw( 12 * 3, 1, 0, 0 );
|
||||
@ -181,7 +231,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
}
|
||||
catch ( vk::SystemError & err )
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
@ -34,7 +35,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
|
||||
// initialize the DipatchLoaderDynamic to use
|
||||
static vk::DynamicLoader dl;
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
|
||||
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
|
||||
#endif
|
||||
|
||||
@ -42,7 +44,9 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
// To use PUSH_DESCRIPTOR, you must also specify GET_PHYSICAL_DEVICE_PROPERTIES_2
|
||||
std::vector<vk::ExtensionProperties> extensionProperties = vk::enumerateInstanceExtensionProperties();
|
||||
if (std::find_if(extensionProperties.begin(), extensionProperties.end(), [](vk::ExtensionProperties ep) { return (strcmp(ep.extensionName,VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME) == 0); }) == extensionProperties.end())
|
||||
if ( std::find_if( extensionProperties.begin(), extensionProperties.end(), []( vk::ExtensionProperties ep ) {
|
||||
return ( strcmp( ep.extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME ) == 0 );
|
||||
} ) == extensionProperties.end() )
|
||||
{
|
||||
std::cout << "No GET_PHYSICAL_DEVICE_PROPERTIES_2 extension" << std::endl;
|
||||
return 0;
|
||||
@ -60,7 +64,9 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
// Once instance is created, need to make sure the extension is available
|
||||
extensionProperties = physicalDevice.enumerateDeviceExtensionProperties();
|
||||
if (std::find_if(extensionProperties.begin(), extensionProperties.end(), [](vk::ExtensionProperties ep) { return (strcmp(ep.extensionName,VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME) == 0); }) == extensionProperties.end())
|
||||
if ( std::find_if( extensionProperties.begin(), extensionProperties.end(), []( vk::ExtensionProperties ep ) {
|
||||
return ( strcmp( ep.extensionName, VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME ) == 0 );
|
||||
} ) == extensionProperties.end() )
|
||||
{
|
||||
std::cout << "No extension for push descriptors" << std::endl;
|
||||
return 0;
|
||||
@ -71,17 +77,29 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, deviceExtensions);
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, deviceExtensions );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
@ -89,58 +107,94 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(surfaceData.extent));
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice(
|
||||
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( surfaceData.extent ) );
|
||||
|
||||
// Need to specify that descriptor set layout will be for push descriptors
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device,
|
||||
{ {vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex}, {vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment} },
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device,
|
||||
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
|
||||
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } },
|
||||
vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, depthBufferData.format);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
depthBufferData.format );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, sizeof(texturedCubeData), vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
vk::su::copyToDevice(device, vertexBufferData.deviceMemory, texturedCubeData, sizeof(texturedCubeData) / sizeof(texturedCubeData[0]));
|
||||
vk::su::BufferData vertexBufferData(
|
||||
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
|
||||
vk::su::copyToDevice( device,
|
||||
vertexBufferData.deviceMemory,
|
||||
texturedCubeData,
|
||||
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr),
|
||||
sizeof(texturedCubeData[0]), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise, true, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline =
|
||||
vk::su::createGraphicsPipeline( device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
sizeof( texturedCubeData[0] ),
|
||||
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise,
|
||||
true,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
|
||||
// Get the index of the next available swapchain image:
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(
|
||||
swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
vk::ClearValue clearValues[2];
|
||||
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(0, 0), surfaceData.extent), 2, clearValues);
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
|
||||
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
|
||||
vk::DescriptorImageInfo imageInfo(textureData.textureSampler.get(), textureData.imageData->imageView.get(), vk::ImageLayout::eShaderReadOnlyOptimal);
|
||||
vk::WriteDescriptorSet writeDescriptorSets[2] =
|
||||
{
|
||||
vk::DescriptorImageInfo imageInfo( textureData.textureSampler.get(),
|
||||
textureData.imageData->imageView.get(),
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
vk::WriteDescriptorSet writeDescriptorSets[2] = {
|
||||
vk::WriteDescriptorSet( {}, 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfo ),
|
||||
vk::WriteDescriptorSet( {}, 1, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo )
|
||||
};
|
||||
|
||||
// this call is from an extension and needs the dynamic dispatcher !!
|
||||
commandBuffer->pushDescriptorSetKHR(vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, {2, writeDescriptorSets});
|
||||
commandBuffer->pushDescriptorSetKHR(
|
||||
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, { 2, writeDescriptorSets } );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
commandBuffer->draw( 12 * 3, 1, 0, 0 );
|
||||
@ -156,7 +210,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -92,13 +92,15 @@ namespace vk
|
||||
return m_windowSize;
|
||||
}
|
||||
|
||||
CameraManipulator::Action CameraManipulator::mouseMove(glm::ivec2 const& position, MouseButton mouseButton, ModifierFlags & modifiers)
|
||||
CameraManipulator::Action
|
||||
CameraManipulator::mouseMove( glm::ivec2 const & position, MouseButton mouseButton, ModifierFlags & modifiers )
|
||||
{
|
||||
Action curAction = Action::None;
|
||||
switch ( mouseButton )
|
||||
{
|
||||
case MouseButton::Left:
|
||||
if (((modifiers & ModifierFlagBits::Ctrl) && (modifiers & ModifierFlagBits::Shift)) || (modifiers & ModifierFlagBits::Alt))
|
||||
if ( ( ( modifiers & ModifierFlagBits::Ctrl ) && ( modifiers & ModifierFlagBits::Shift ) ) ||
|
||||
( modifiers & ModifierFlagBits::Alt ) )
|
||||
{
|
||||
curAction = m_mode == Mode::Examine ? Action::LookAround : Action::Orbit;
|
||||
}
|
||||
@ -115,14 +117,9 @@ namespace vk
|
||||
curAction = m_mode == Mode::Examine ? Action::Orbit : Action::LookAround;
|
||||
}
|
||||
break;
|
||||
case MouseButton::Middle:
|
||||
curAction = Action::Pan;
|
||||
break;
|
||||
case MouseButton::Right:
|
||||
curAction = Action::Dolly;
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
case MouseButton::Middle: curAction = Action::Pan; break;
|
||||
case MouseButton::Right: curAction = Action::Dolly; break;
|
||||
default: assert( false );
|
||||
}
|
||||
assert( curAction != Action::None );
|
||||
motion( position, curAction );
|
||||
@ -130,7 +127,9 @@ namespace vk
|
||||
return curAction;
|
||||
}
|
||||
|
||||
void CameraManipulator::setLookat(const glm::vec3& cameraPosition, const glm::vec3& centerPosition, const glm::vec3& upVector)
|
||||
void CameraManipulator::setLookat( const glm::vec3 & cameraPosition,
|
||||
const glm::vec3 & centerPosition,
|
||||
const glm::vec3 & upVector )
|
||||
{
|
||||
m_cameraPosition = cameraPosition;
|
||||
m_centerPosition = centerPosition;
|
||||
@ -239,7 +238,8 @@ namespace vk
|
||||
|
||||
void CameraManipulator::motion( glm::ivec2 const & position, Action action )
|
||||
{
|
||||
glm::vec2 delta(float(position[0] - m_mousePosition[0]) / float(m_windowSize[0]), float(position[1] - m_mousePosition[1]) / float(m_windowSize[1]));
|
||||
glm::vec2 delta( float( position[0] - m_mousePosition[0] ) / float( m_windowSize[0] ),
|
||||
float( position[1] - m_mousePosition[1] ) / float( m_windowSize[1] ) );
|
||||
|
||||
switch ( action )
|
||||
{
|
||||
@ -253,12 +253,8 @@ namespace vk
|
||||
orbit( delta, false );
|
||||
}
|
||||
break;
|
||||
case Action::Dolly:
|
||||
dolly(delta);
|
||||
break;
|
||||
case Action::Pan:
|
||||
pan(delta);
|
||||
break;
|
||||
case Action::Dolly: dolly( delta ); break;
|
||||
case Action::Pan: pan( delta ); break;
|
||||
case Action::LookAround:
|
||||
if ( m_mode == Mode::Trackball )
|
||||
{
|
||||
@ -376,7 +372,8 @@ namespace vk
|
||||
{
|
||||
glm::vec2 p0( 2 * ( m_mousePosition[0] - m_windowSize[0] / 2 ) / double( m_windowSize[0] ),
|
||||
2 * ( m_windowSize[1] / 2 - m_mousePosition[1] ) / double( m_windowSize[1] ) );
|
||||
glm::vec2 p1(2 * (position[0] - m_windowSize[0] / 2) / double(m_windowSize[0]), 2 * (m_windowSize[1] / 2 - position[1]) / double(m_windowSize[1]));
|
||||
glm::vec2 p1( 2 * ( position[0] - m_windowSize[0] / 2 ) / double( m_windowSize[0] ),
|
||||
2 * ( m_windowSize[1] / 2 - position[1] ) / double( m_windowSize[1] ) );
|
||||
|
||||
// determine the z coordinate on the sphere
|
||||
glm::vec3 pTB0( p0[0], p0[1], projectOntoTBSphere( p0 ) );
|
||||
|
@ -15,37 +15,42 @@
|
||||
// VulkanHpp Samples : RayTracing
|
||||
// Simple sample how to ray trace using Vulkan
|
||||
|
||||
#include <vulkan/vulkan.hpp>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <numeric>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
|
||||
#include <vulkan/vulkan.hpp>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||
#define GLM_FORCE_RADIANS
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#pragma warning(disable:4201) // disable warning C4201: nonstandard extension used: nameless struct/union; needed to get glm/detail/type_vec?.hpp without warnings
|
||||
#pragma warning( disable : 4201 ) // disable warning C4201: nonstandard extension used: nameless struct/union; needed
|
||||
// to get glm/detail/type_vec?.hpp without warnings
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "CameraManipulator.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_inverse.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include "CameraManipulator.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
|
||||
static char const * AppName = "RayTracing";
|
||||
static char const * EngineName = "Vulkan.hpp";
|
||||
|
||||
struct GeometryInstanceData
|
||||
{
|
||||
GeometryInstanceData(glm::mat4x4 const& transform_, uint32_t instanceID_, uint8_t mask_, uint32_t instanceOffset_, uint8_t flags_, uint64_t accelerationStructureHandle_)
|
||||
: instanceId(instanceID_)
|
||||
, mask(mask_)
|
||||
, instanceOffset(instanceOffset_)
|
||||
, flags(flags_)
|
||||
, accelerationStructureHandle(accelerationStructureHandle_)
|
||||
GeometryInstanceData( glm::mat4x4 const & transform_,
|
||||
uint32_t instanceID_,
|
||||
uint8_t mask_,
|
||||
uint32_t instanceOffset_,
|
||||
uint8_t flags_,
|
||||
uint64_t accelerationStructureHandle_ )
|
||||
: instanceId( instanceID_ ),
|
||||
mask( mask_ ),
|
||||
instanceOffset( instanceOffset_ ),
|
||||
flags( flags_ ),
|
||||
accelerationStructureHandle( accelerationStructureHandle_ )
|
||||
{
|
||||
assert( !( instanceID_ & 0xFF000000 ) && !( instanceOffset_ & 0xFF000000 ) );
|
||||
memcpy( transform, &transform_, 12 * sizeof( float ) );
|
||||
@ -68,39 +73,62 @@ struct AccelerationStructureData
|
||||
std::unique_ptr<vk::su::BufferData> instanceBufferData;
|
||||
};
|
||||
|
||||
AccelerationStructureData createAccelerationStructureData(vk::PhysicalDevice const& physicalDevice, vk::UniqueDevice const& device, vk::UniqueCommandBuffer const& commandBuffer,
|
||||
std::vector<std::pair<vk::AccelerationStructureNV, glm::mat4x4>> const& instances, std::vector<vk::GeometryNV> const& geometries)
|
||||
AccelerationStructureData
|
||||
createAccelerationStructureData( vk::PhysicalDevice const & physicalDevice,
|
||||
vk::UniqueDevice const & device,
|
||||
vk::UniqueCommandBuffer const & commandBuffer,
|
||||
std::vector<std::pair<vk::AccelerationStructureNV, glm::mat4x4>> const & instances,
|
||||
std::vector<vk::GeometryNV> const & geometries )
|
||||
{
|
||||
assert( instances.empty() ^ geometries.empty() );
|
||||
|
||||
AccelerationStructureData accelerationStructureData;
|
||||
|
||||
vk::AccelerationStructureTypeNV accelerationStructureType = instances.empty() ? vk::AccelerationStructureTypeNV::eBottomLevel : vk::AccelerationStructureTypeNV::eTopLevel;
|
||||
vk::AccelerationStructureInfoNV accelerationStructureInfo(accelerationStructureType, {}, vk::su::checked_cast<uint32_t>(instances.size()),
|
||||
vk::su::checked_cast<uint32_t>(geometries.size()), geometries.data());
|
||||
accelerationStructureData.acclerationStructure = device->createAccelerationStructureNVUnique(vk::AccelerationStructureCreateInfoNV(0, accelerationStructureInfo));
|
||||
vk::AccelerationStructureTypeNV accelerationStructureType =
|
||||
instances.empty() ? vk::AccelerationStructureTypeNV::eBottomLevel : vk::AccelerationStructureTypeNV::eTopLevel;
|
||||
vk::AccelerationStructureInfoNV accelerationStructureInfo( accelerationStructureType,
|
||||
{},
|
||||
vk::su::checked_cast<uint32_t>( instances.size() ),
|
||||
vk::su::checked_cast<uint32_t>( geometries.size() ),
|
||||
geometries.data() );
|
||||
accelerationStructureData.acclerationStructure = device->createAccelerationStructureNVUnique(
|
||||
vk::AccelerationStructureCreateInfoNV( 0, accelerationStructureInfo ) );
|
||||
|
||||
vk::AccelerationStructureMemoryRequirementsInfoNV objectRequirements(vk::AccelerationStructureMemoryRequirementsTypeNV::eObject, *accelerationStructureData.acclerationStructure);
|
||||
vk::DeviceSize resultSizeInBytes = device->getAccelerationStructureMemoryRequirementsNV(objectRequirements).memoryRequirements.size;
|
||||
vk::AccelerationStructureMemoryRequirementsInfoNV objectRequirements(
|
||||
vk::AccelerationStructureMemoryRequirementsTypeNV::eObject, *accelerationStructureData.acclerationStructure );
|
||||
vk::DeviceSize resultSizeInBytes =
|
||||
device->getAccelerationStructureMemoryRequirementsNV( objectRequirements ).memoryRequirements.size;
|
||||
assert( 0 < resultSizeInBytes );
|
||||
accelerationStructureData.resultBufferData = std::unique_ptr<vk::su::BufferData>(new vk::su::BufferData(physicalDevice, device, resultSizeInBytes, vk::BufferUsageFlagBits::eRayTracingNV,
|
||||
accelerationStructureData.resultBufferData =
|
||||
std::unique_ptr<vk::su::BufferData>( new vk::su::BufferData( physicalDevice,
|
||||
device,
|
||||
resultSizeInBytes,
|
||||
vk::BufferUsageFlagBits::eRayTracingNV,
|
||||
vk::MemoryPropertyFlagBits::eDeviceLocal ) );
|
||||
|
||||
vk::AccelerationStructureMemoryRequirementsInfoNV buildScratchRequirements(vk::AccelerationStructureMemoryRequirementsTypeNV::eBuildScratch,
|
||||
vk::AccelerationStructureMemoryRequirementsInfoNV buildScratchRequirements(
|
||||
vk::AccelerationStructureMemoryRequirementsTypeNV::eBuildScratch, *accelerationStructureData.acclerationStructure );
|
||||
vk::AccelerationStructureMemoryRequirementsInfoNV updateScratchRequirements(
|
||||
vk::AccelerationStructureMemoryRequirementsTypeNV::eUpdateScratch,
|
||||
*accelerationStructureData.acclerationStructure );
|
||||
vk::AccelerationStructureMemoryRequirementsInfoNV updateScratchRequirements(vk::AccelerationStructureMemoryRequirementsTypeNV::eUpdateScratch,
|
||||
*accelerationStructureData.acclerationStructure);
|
||||
vk::DeviceSize scratchSizeInBytes =
|
||||
std::max(device->getAccelerationStructureMemoryRequirementsNV(buildScratchRequirements).memoryRequirements.size,
|
||||
vk::DeviceSize scratchSizeInBytes = std::max(
|
||||
device->getAccelerationStructureMemoryRequirementsNV( buildScratchRequirements ).memoryRequirements.size,
|
||||
device->getAccelerationStructureMemoryRequirementsNV( updateScratchRequirements ).memoryRequirements.size );
|
||||
assert( 0 < scratchSizeInBytes );
|
||||
|
||||
accelerationStructureData.scratchBufferData = std::unique_ptr<vk::su::BufferData>(new vk::su::BufferData(physicalDevice, device, scratchSizeInBytes, vk::BufferUsageFlagBits::eRayTracingNV,
|
||||
accelerationStructureData.scratchBufferData =
|
||||
std::unique_ptr<vk::su::BufferData>( new vk::su::BufferData( physicalDevice,
|
||||
device,
|
||||
scratchSizeInBytes,
|
||||
vk::BufferUsageFlagBits::eRayTracingNV,
|
||||
vk::MemoryPropertyFlagBits::eDeviceLocal ) );
|
||||
|
||||
if ( !instances.empty() )
|
||||
{
|
||||
accelerationStructureData.instanceBufferData = std::unique_ptr<vk::su::BufferData>(new vk::su::BufferData(physicalDevice, device, instances.size() * sizeof(GeometryInstanceData),
|
||||
accelerationStructureData.instanceBufferData =
|
||||
std::unique_ptr<vk::su::BufferData>( new vk::su::BufferData( physicalDevice,
|
||||
device,
|
||||
instances.size() * sizeof( GeometryInstanceData ),
|
||||
vk::BufferUsageFlagBits::eRayTracingNV ) );
|
||||
|
||||
std::vector<GeometryInstanceData> geometryInstanceData;
|
||||
@ -114,23 +142,43 @@ AccelerationStructureData createAccelerationStructureData(vk::PhysicalDevice con
|
||||
// table will contain the hit group to be executed when hitting this instance. We set this
|
||||
// index to 2*i due to the use of 2 types of rays in the scene: the camera rays and the shadow
|
||||
// rays. For each instance, the SBT will then have 2 hit groups
|
||||
geometryInstanceData.push_back(GeometryInstanceData(glm::transpose(instances[i].second), static_cast<uint32_t>(i), 0xFF, static_cast<uint32_t>(2 * i),
|
||||
static_cast<uint8_t>(vk::GeometryInstanceFlagBitsNV::eTriangleCullDisable), accelerationStructureHandle));
|
||||
geometryInstanceData.push_back(
|
||||
GeometryInstanceData( glm::transpose( instances[i].second ),
|
||||
static_cast<uint32_t>( i ),
|
||||
0xFF,
|
||||
static_cast<uint32_t>( 2 * i ),
|
||||
static_cast<uint8_t>( vk::GeometryInstanceFlagBitsNV::eTriangleCullDisable ),
|
||||
accelerationStructureHandle ) );
|
||||
}
|
||||
accelerationStructureData.instanceBufferData->upload( device, geometryInstanceData );
|
||||
}
|
||||
|
||||
device->bindAccelerationStructureMemoryNV(vk::BindAccelerationStructureMemoryInfoNV(*accelerationStructureData.acclerationStructure,
|
||||
*accelerationStructureData.resultBufferData->deviceMemory));
|
||||
device->bindAccelerationStructureMemoryNV( vk::BindAccelerationStructureMemoryInfoNV(
|
||||
*accelerationStructureData.acclerationStructure, *accelerationStructureData.resultBufferData->deviceMemory ) );
|
||||
|
||||
commandBuffer->buildAccelerationStructureNV(vk::AccelerationStructureInfoNV(accelerationStructureType, {}, vk::su::checked_cast<uint32_t>(instances.size()),
|
||||
vk::su::checked_cast<uint32_t>(geometries.size()), geometries.data()),
|
||||
accelerationStructureData.instanceBufferData ? *accelerationStructureData.instanceBufferData->buffer : nullptr, 0, false,
|
||||
*accelerationStructureData.acclerationStructure, nullptr, *accelerationStructureData.scratchBufferData->buffer, 0);
|
||||
commandBuffer->buildAccelerationStructureNV(
|
||||
vk::AccelerationStructureInfoNV( accelerationStructureType,
|
||||
{},
|
||||
vk::su::checked_cast<uint32_t>( instances.size() ),
|
||||
vk::su::checked_cast<uint32_t>( geometries.size() ),
|
||||
geometries.data() ),
|
||||
accelerationStructureData.instanceBufferData ? *accelerationStructureData.instanceBufferData->buffer : nullptr,
|
||||
0,
|
||||
false,
|
||||
*accelerationStructureData.acclerationStructure,
|
||||
nullptr,
|
||||
*accelerationStructureData.scratchBufferData->buffer,
|
||||
0 );
|
||||
|
||||
commandBuffer->pipelineBarrier(vk::PipelineStageFlagBits::eAccelerationStructureBuildNV, vk::PipelineStageFlagBits::eAccelerationStructureBuildNV, {},
|
||||
vk::MemoryBarrier(vk::AccessFlagBits::eAccelerationStructureWriteNV | vk::AccessFlagBits::eAccelerationStructureReadNV,
|
||||
vk::AccessFlagBits::eAccelerationStructureWriteNV | vk::AccessFlagBits::eAccelerationStructureReadNV), {}, {});
|
||||
commandBuffer->pipelineBarrier( vk::PipelineStageFlagBits::eAccelerationStructureBuildNV,
|
||||
vk::PipelineStageFlagBits::eAccelerationStructureBuildNV,
|
||||
{},
|
||||
vk::MemoryBarrier( vk::AccessFlagBits::eAccelerationStructureWriteNV |
|
||||
vk::AccessFlagBits::eAccelerationStructureReadNV,
|
||||
vk::AccessFlagBits::eAccelerationStructureWriteNV |
|
||||
vk::AccessFlagBits::eAccelerationStructureReadNV ),
|
||||
{},
|
||||
{} );
|
||||
|
||||
return accelerationStructureData;
|
||||
}
|
||||
@ -164,10 +212,7 @@ const size_t MaterialStride = ((sizeof(Material) + 15) / 16) * 16;
|
||||
struct Vertex
|
||||
{
|
||||
Vertex( glm::vec3 const & p, glm::vec3 const & n, glm::vec2 const & tc, int m = 0 )
|
||||
: pos(p)
|
||||
, nrm(n)
|
||||
, texCoord(tc)
|
||||
, matID(m)
|
||||
: pos( p ), nrm( n ), texCoord( tc ), matID( m )
|
||||
{}
|
||||
|
||||
glm::vec3 pos;
|
||||
@ -177,8 +222,7 @@ struct Vertex
|
||||
};
|
||||
const size_t VertexStride = ( ( sizeof( Vertex ) + 15 ) / 16 ) * 16;
|
||||
|
||||
static const std::vector<Vertex> cubeData =
|
||||
{
|
||||
static const std::vector<Vertex> cubeData = {
|
||||
// pos nrm texcoord matID
|
||||
// front face
|
||||
{ Vertex( glm::vec3( -1.0f, -1.0f, 1.0f ), glm::vec3( 0.0f, 0.0f, 1.0f ), glm::vec2( 0.0f, 0.0f ), 0 ) },
|
||||
@ -499,7 +543,8 @@ static void check_vk_result(VkResult err)
|
||||
|
||||
static void cursorPosCallback( GLFWwindow * window, double mouseX, double mouseY )
|
||||
{
|
||||
vk::su::CameraManipulator::MouseButton mouseButton = (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
|
||||
vk::su::CameraManipulator::MouseButton mouseButton =
|
||||
( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_LEFT ) == GLFW_PRESS )
|
||||
? vk::su::CameraManipulator::MouseButton::Left
|
||||
: ( glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_MIDDLE ) == GLFW_PRESS )
|
||||
? vk::su::CameraManipulator::MouseButton::Middle
|
||||
@ -522,8 +567,10 @@ static void cursorPosCallback(GLFWwindow* window, double mouseX, double mouseY)
|
||||
modifiers |= vk::su::CameraManipulator::ModifierFlagBits::Shift;
|
||||
}
|
||||
|
||||
vk::su::CameraManipulator & cameraManipulator = reinterpret_cast<AppInfo*>(glfwGetWindowUserPointer(window))->cameraManipulator;
|
||||
cameraManipulator.mouseMove(glm::ivec2(static_cast<int>(mouseX), static_cast<int>(mouseY)), mouseButton, modifiers);
|
||||
vk::su::CameraManipulator & cameraManipulator =
|
||||
reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
|
||||
cameraManipulator.mouseMove(
|
||||
glm::ivec2( static_cast<int>( mouseX ), static_cast<int>( mouseY ) ), mouseButton, modifiers );
|
||||
}
|
||||
}
|
||||
|
||||
@ -534,7 +581,8 @@ static void errorCallback(int error, const char* description)
|
||||
|
||||
static void framebufferSizeCallback( GLFWwindow * window, int w, int h )
|
||||
{
|
||||
vk::su::CameraManipulator & cameraManipulator = reinterpret_cast<AppInfo*>(glfwGetWindowUserPointer(window))->cameraManipulator;
|
||||
vk::su::CameraManipulator & cameraManipulator =
|
||||
reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
|
||||
cameraManipulator.setWindowSize( glm::ivec2( w, h ) );
|
||||
}
|
||||
|
||||
@ -545,9 +593,7 @@ static void keyCallback(GLFWwindow* window, int key, int /*scancode*/, int actio
|
||||
switch ( key )
|
||||
{
|
||||
case GLFW_KEY_ESCAPE:
|
||||
case 'Q':
|
||||
glfwSetWindowShouldClose(window, 1);
|
||||
break;
|
||||
case 'Q': glfwSetWindowShouldClose( window, 1 ); break;
|
||||
case 'R':
|
||||
{
|
||||
AppInfo * appInfo = reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) );
|
||||
@ -563,17 +609,18 @@ static void mouseButtonCallback(GLFWwindow* window, int /*button*/, int /*action
|
||||
double xpos, ypos;
|
||||
glfwGetCursorPos( window, &xpos, &ypos );
|
||||
|
||||
vk::su::CameraManipulator & cameraManipulator = reinterpret_cast<AppInfo*>(glfwGetWindowUserPointer(window))->cameraManipulator;
|
||||
vk::su::CameraManipulator & cameraManipulator =
|
||||
reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
|
||||
cameraManipulator.setMousePosition( glm::ivec2( static_cast<int>( xpos ), static_cast<int>( ypos ) ) );
|
||||
}
|
||||
|
||||
static void scrollCallback( GLFWwindow * window, double /*xoffset*/, double yoffset )
|
||||
{
|
||||
vk::su::CameraManipulator & cameraManipulator = reinterpret_cast<AppInfo*>(glfwGetWindowUserPointer(window))->cameraManipulator;
|
||||
vk::su::CameraManipulator & cameraManipulator =
|
||||
reinterpret_cast<AppInfo *>( glfwGetWindowUserPointer( window ) )->cameraManipulator;
|
||||
cameraManipulator.wheel( static_cast<int>( yoffset ) );
|
||||
}
|
||||
|
||||
|
||||
// random data and functions
|
||||
static std::random_device randomDevice;
|
||||
static std::mt19937 randomGenerator( randomDevice() );
|
||||
@ -591,7 +638,9 @@ glm::vec3 randomVec3(float minValue, float maxValue)
|
||||
{
|
||||
std::uniform_real_distribution<float> randomDistribution( minValue, maxValue );
|
||||
|
||||
return glm::vec3(randomDistribution(randomGenerator), randomDistribution(randomGenerator), randomDistribution(randomGenerator));
|
||||
return glm::vec3( randomDistribution( randomGenerator ),
|
||||
randomDistribution( randomGenerator ),
|
||||
randomDistribution( randomGenerator ) );
|
||||
}
|
||||
|
||||
int main( int /*argc*/, char ** /*argv*/ )
|
||||
@ -632,7 +681,8 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
|
||||
// Setup camera and make it available as the userPointer in the glfw window
|
||||
appInfo.cameraManipulator.setWindowSize( glm::u32vec2( windowExtent.width, windowExtent.height ) );
|
||||
glm::vec3 diagonal = 3.0f * glm::vec3(static_cast<float>(xMax), static_cast<float>(yMax), static_cast<float>(zMax));
|
||||
glm::vec3 diagonal =
|
||||
3.0f * glm::vec3( static_cast<float>( xMax ), static_cast<float>( yMax ), static_cast<float>( zMax ) );
|
||||
appInfo.cameraManipulator.setLookat( 1.5f * diagonal, 0.5f * diagonal, glm::vec3( 0, 1, 0 ) );
|
||||
glfwSetWindowUserPointer( window, &appInfo );
|
||||
|
||||
@ -656,23 +706,36 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
|
||||
// Create Window Surface (using glfw)
|
||||
vk::SurfaceKHR surface;
|
||||
VkResult err = glfwCreateWindowSurface(VkInstance(*instance), window, nullptr, reinterpret_cast<VkSurfaceKHR*>(&surface));
|
||||
VkResult err =
|
||||
glfwCreateWindowSurface( VkInstance( *instance ), window, nullptr, reinterpret_cast<VkSurfaceKHR *>( &surface ) );
|
||||
check_vk_result( err );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, surface);
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surface );
|
||||
|
||||
// Create a Device with ray tracing support (besides some other extensions needed) and needed features
|
||||
auto supportedFeatures = physicalDevice.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first,
|
||||
{VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_NV_RAY_TRACING_EXTENSION_NAME, VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME},
|
||||
&supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features, &supportedFeatures.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>());
|
||||
auto supportedFeatures =
|
||||
physicalDevice.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice,
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
{ VK_KHR_SWAPCHAIN_EXTENSION_NAME,
|
||||
VK_NV_RAY_TRACING_EXTENSION_NAME,
|
||||
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME },
|
||||
&supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features,
|
||||
&supportedFeatures.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>() );
|
||||
|
||||
// setup stuff per frame
|
||||
std::array<PerFrameData, IMGUI_VK_QUEUED_FRAMES> perFrameData;
|
||||
for ( int i = 0; i < IMGUI_VK_QUEUED_FRAMES; i++ )
|
||||
{
|
||||
perFrameData[i].commandPool = device->createCommandPoolUnique(vk::CommandPoolCreateInfo(vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first));
|
||||
perFrameData[i].commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(*perFrameData[i].commandPool, vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
perFrameData[i].commandPool = device->createCommandPoolUnique( vk::CommandPoolCreateInfo(
|
||||
vk::CommandPoolCreateFlagBits::eResetCommandBuffer, graphicsAndPresentQueueFamilyIndex.first ) );
|
||||
perFrameData[i].commandBuffer =
|
||||
std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
*perFrameData[i].commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
perFrameData[i].fence = device->createFenceUnique( vk::FenceCreateInfo( vk::FenceCreateFlagBits::eSignaled ) );
|
||||
perFrameData[i].presentCompleteSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
perFrameData[i].renderCompleteSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
@ -682,8 +745,7 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
// create a descriptor pool with a number of available descriptors
|
||||
std::vector<vk::DescriptorPoolSize> poolSizes =
|
||||
{
|
||||
std::vector<vk::DescriptorPoolSize> poolSizes = {
|
||||
{ vk::DescriptorType::eCombinedImageSampler, 1000 },
|
||||
{ vk::DescriptorType::eUniformBuffer, 1000 },
|
||||
{ vk::DescriptorType::eStorageBuffer, 1000 },
|
||||
@ -691,8 +753,14 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool( device, poolSizes );
|
||||
|
||||
// setup swap chain, render pass, depth buffer and the frame buffers
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, surface, windowExtent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eStorage, vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
surface,
|
||||
windowExtent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eStorage,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
vk::SurfaceFormatKHR surfaceFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surface ) );
|
||||
vk::Format depthFormat = vk::su::pickDepthFormat( physicalDevice );
|
||||
|
||||
@ -700,7 +768,8 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass( device, surfaceFormat.format, depthFormat );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, depthFormat, windowExtent );
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, windowExtent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, windowExtent );
|
||||
|
||||
bool samplerAnisotropy = supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features.samplerAnisotropy;
|
||||
|
||||
@ -710,15 +779,22 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
textures.reserve( textureCount );
|
||||
for ( size_t i = 0; i < textureCount; i++ )
|
||||
{
|
||||
textures.push_back(vk::su::TextureData(physicalDevice, device, {random<uint32_t>(2, 8) * 16, random<uint32_t>(2, 8) * 16},
|
||||
vk::ImageUsageFlagBits::eTransferDst | vk::ImageUsageFlagBits::eSampled, {}, samplerAnisotropy, true));
|
||||
textures.push_back( vk::su::TextureData( physicalDevice,
|
||||
device,
|
||||
{ random<uint32_t>( 2, 8 ) * 16, random<uint32_t>( 2, 8 ) * 16 },
|
||||
vk::ImageUsageFlagBits::eTransferDst | vk::ImageUsageFlagBits::eSampled,
|
||||
{},
|
||||
samplerAnisotropy,
|
||||
true ) );
|
||||
}
|
||||
vk::su::oneTimeSubmit(device, perFrameData[0].commandPool, graphicsQueue,
|
||||
[&](vk::UniqueCommandBuffer const& commandBuffer)
|
||||
{
|
||||
vk::su::oneTimeSubmit(
|
||||
device, perFrameData[0].commandPool, graphicsQueue, [&]( vk::UniqueCommandBuffer const & commandBuffer ) {
|
||||
for ( auto & t : textures )
|
||||
{
|
||||
t.setImage(device, commandBuffer, vk::su::CheckerboardImageGenerator({random<uint8_t>(), random<uint8_t>(), random<uint8_t>()},
|
||||
t.setImage(
|
||||
device,
|
||||
commandBuffer,
|
||||
vk::su::CheckerboardImageGenerator( { random<uint8_t>(), random<uint8_t>(), random<uint8_t>() },
|
||||
{ random<uint8_t>(), random<uint8_t>(), random<uint8_t>() } ) );
|
||||
}
|
||||
} );
|
||||
@ -732,7 +808,8 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
materials[i].diffuse = randomVec3( 0.0f, 1.0f );
|
||||
materials[i].textureID = vk::su::checked_cast<uint32_t>( i );
|
||||
}
|
||||
vk::su::BufferData materialBufferData(physicalDevice, device, materialCount * MaterialStride, vk::BufferUsageFlagBits::eStorageBuffer);
|
||||
vk::su::BufferData materialBufferData(
|
||||
physicalDevice, device, materialCount * MaterialStride, vk::BufferUsageFlagBits::eStorageBuffer );
|
||||
materialBufferData.upload( device, materials, MaterialStride );
|
||||
|
||||
// create a a 3D-array of cubes, randomly jittered, using a random material
|
||||
@ -749,7 +826,8 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
for ( auto const & v : cubeData )
|
||||
{
|
||||
vertices.push_back( v );
|
||||
vertices.back().pos += 3.0f * glm::vec3(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z)) + jitter;
|
||||
vertices.back().pos +=
|
||||
3.0f * glm::vec3( static_cast<float>( x ), static_cast<float>( y ), static_cast<float>( z ) ) + jitter;
|
||||
vertices.back().matID = static_cast<int>( m );
|
||||
}
|
||||
}
|
||||
@ -761,131 +839,215 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
std::iota( indices.begin(), indices.end(), 0 );
|
||||
|
||||
// there's just one vertex- and one index-buffer, but with more complex scene loaders there might be more!
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, vertices.size() * VertexStride,
|
||||
vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eStorageBuffer,
|
||||
vk::su::BufferData vertexBufferData( physicalDevice,
|
||||
device,
|
||||
vertices.size() * VertexStride,
|
||||
vk::BufferUsageFlagBits::eTransferDst |
|
||||
vk::BufferUsageFlagBits::eVertexBuffer |
|
||||
vk::BufferUsageFlagBits::eStorageBuffer,
|
||||
vk::MemoryPropertyFlagBits::eDeviceLocal );
|
||||
vertexBufferData.upload(physicalDevice, device, perFrameData[0].commandPool, graphicsQueue, vertices, VertexStride);
|
||||
vertexBufferData.upload(
|
||||
physicalDevice, device, perFrameData[0].commandPool, graphicsQueue, vertices, VertexStride );
|
||||
|
||||
vk::su::BufferData indexBufferData(physicalDevice, device, indices.size() * sizeof(uint32_t),
|
||||
vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eStorageBuffer,
|
||||
vk::su::BufferData indexBufferData( physicalDevice,
|
||||
device,
|
||||
indices.size() * sizeof( uint32_t ),
|
||||
vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eIndexBuffer |
|
||||
vk::BufferUsageFlagBits::eStorageBuffer,
|
||||
vk::MemoryPropertyFlagBits::eDeviceLocal );
|
||||
indexBufferData.upload(physicalDevice, device, perFrameData[0].commandPool, graphicsQueue, indices, sizeof(uint32_t));
|
||||
indexBufferData.upload(
|
||||
physicalDevice, device, perFrameData[0].commandPool, graphicsQueue, indices, sizeof( uint32_t ) );
|
||||
|
||||
glm::mat4x4 transform(glm::mat4x4(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f));
|
||||
glm::mat4x4 transform(
|
||||
glm::mat4x4( 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ) );
|
||||
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout =
|
||||
vk::su::createDescriptorSetLayout( device,
|
||||
{
|
||||
{ vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
|
||||
{ vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment },
|
||||
{ vk::DescriptorType::eCombinedImageSampler, static_cast<uint32_t>(textures.size()), vk::ShaderStageFlagBits::eFragment }
|
||||
});
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo({}, 1, &(*descriptorSetLayout)));
|
||||
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
|
||||
{ vk::DescriptorType::eStorageBuffer,
|
||||
1,
|
||||
vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment },
|
||||
{ vk::DescriptorType::eCombinedImageSampler,
|
||||
static_cast<uint32_t>( textures.size() ),
|
||||
vk::ShaderStageFlagBits::eFragment } } );
|
||||
vk::UniquePipelineLayout pipelineLayout =
|
||||
device->createPipelineLayoutUnique( vk::PipelineLayoutCreateInfo( {}, 1, &( *descriptorSetLayout ) ) );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, vk::UniquePipelineCache(), std::make_pair(*vertexShaderModule, nullptr),
|
||||
std::make_pair(*fragmentShaderModule, nullptr), VertexStride,
|
||||
{
|
||||
{ vk::Format::eR32G32B32Sfloat, vk::su::checked_cast<uint32_t>(offsetof(Vertex, pos)) },
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(
|
||||
device,
|
||||
vk::UniquePipelineCache(),
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
VertexStride,
|
||||
{ { vk::Format::eR32G32B32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, pos ) ) },
|
||||
{ vk::Format::eR32G32B32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, nrm ) ) },
|
||||
{ vk::Format::eR32G32Sfloat, vk::su::checked_cast<uint32_t>( offsetof( Vertex, texCoord ) ) },
|
||||
{ vk::Format::eR32Sint, vk::su::checked_cast<uint32_t>(offsetof(Vertex, matID)) }
|
||||
}, vk::FrontFace::eCounterClockwise, true, pipelineLayout, renderPass);
|
||||
{ vk::Format::eR32Sint, vk::su::checked_cast<uint32_t>( offsetof( Vertex, matID ) ) } },
|
||||
vk::FrontFace::eCounterClockwise,
|
||||
true,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(UniformBufferObject), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( UniformBufferObject ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::su::updateDescriptorSets(device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView() },
|
||||
{ vk::DescriptorType::eStorageBuffer, materialBufferData.buffer, vk::UniqueBufferView() } }, textures);
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView() },
|
||||
{ vk::DescriptorType::eStorageBuffer, materialBufferData.buffer, vk::UniqueBufferView() } },
|
||||
textures );
|
||||
|
||||
// RayTracing specific stuff
|
||||
|
||||
// create acceleration structures: one top-level, and just one bottom-level
|
||||
AccelerationStructureData topLevelAS, bottomLevelAS;
|
||||
vk::su::oneTimeSubmit(device, perFrameData[0].commandPool, graphicsQueue,
|
||||
[&](vk::UniqueCommandBuffer const& commandBuffer)
|
||||
{
|
||||
vk::GeometryDataNV geometryDataNV(vk::GeometryTrianglesNV(*vertexBufferData.buffer, 0, vk::su::checked_cast<uint32_t>(vertices.size()), VertexStride,
|
||||
vk::Format::eR32G32B32Sfloat, *indexBufferData.buffer, 0,
|
||||
vk::su::checked_cast<uint32_t>(indices.size()), vk::IndexType::eUint32), {});
|
||||
bottomLevelAS = createAccelerationStructureData(physicalDevice, device, commandBuffer, {}, {vk::GeometryNV(vk::GeometryTypeNV::eTriangles, geometryDataNV)});
|
||||
vk::su::oneTimeSubmit(
|
||||
device, perFrameData[0].commandPool, graphicsQueue, [&]( vk::UniqueCommandBuffer const & commandBuffer ) {
|
||||
vk::GeometryDataNV geometryDataNV( vk::GeometryTrianglesNV( *vertexBufferData.buffer,
|
||||
0,
|
||||
vk::su::checked_cast<uint32_t>( vertices.size() ),
|
||||
VertexStride,
|
||||
vk::Format::eR32G32B32Sfloat,
|
||||
*indexBufferData.buffer,
|
||||
0,
|
||||
vk::su::checked_cast<uint32_t>( indices.size() ),
|
||||
vk::IndexType::eUint32 ),
|
||||
{} );
|
||||
bottomLevelAS =
|
||||
createAccelerationStructureData( physicalDevice,
|
||||
device,
|
||||
commandBuffer,
|
||||
{},
|
||||
{ vk::GeometryNV( vk::GeometryTypeNV::eTriangles, geometryDataNV ) } );
|
||||
|
||||
topLevelAS = createAccelerationStructureData(physicalDevice, device, commandBuffer, {std::make_pair(*bottomLevelAS.acclerationStructure, transform)},
|
||||
topLevelAS =
|
||||
createAccelerationStructureData( physicalDevice,
|
||||
device,
|
||||
commandBuffer,
|
||||
{ std::make_pair( *bottomLevelAS.acclerationStructure, transform ) },
|
||||
std::vector<vk::GeometryNV>() );
|
||||
} );
|
||||
|
||||
// create raytracing descriptor set
|
||||
vk::su::oneTimeSubmit(device, perFrameData[0].commandPool, graphicsQueue,
|
||||
[&](vk::UniqueCommandBuffer const& commandBuffer)
|
||||
{
|
||||
vk::BufferMemoryBarrier bufferMemoryBarrier({}, vk::AccessFlagBits::eShaderRead, VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED, *vertexBufferData.buffer, 0,
|
||||
vk::su::oneTimeSubmit(
|
||||
device, perFrameData[0].commandPool, graphicsQueue, [&]( vk::UniqueCommandBuffer const & commandBuffer ) {
|
||||
vk::BufferMemoryBarrier bufferMemoryBarrier( {},
|
||||
vk::AccessFlagBits::eShaderRead,
|
||||
VK_QUEUE_FAMILY_IGNORED,
|
||||
VK_QUEUE_FAMILY_IGNORED,
|
||||
*vertexBufferData.buffer,
|
||||
0,
|
||||
VK_WHOLE_SIZE );
|
||||
commandBuffer->pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, nullptr, bufferMemoryBarrier, nullptr);
|
||||
commandBuffer->pipelineBarrier( vk::PipelineStageFlagBits::eAllCommands,
|
||||
vk::PipelineStageFlagBits::eAllCommands,
|
||||
{},
|
||||
nullptr,
|
||||
bufferMemoryBarrier,
|
||||
nullptr );
|
||||
|
||||
bufferMemoryBarrier.buffer = *indexBufferData.buffer;
|
||||
commandBuffer->pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, nullptr, bufferMemoryBarrier, nullptr);
|
||||
commandBuffer->pipelineBarrier( vk::PipelineStageFlagBits::eAllCommands,
|
||||
vk::PipelineStageFlagBits::eAllCommands,
|
||||
{},
|
||||
nullptr,
|
||||
bufferMemoryBarrier,
|
||||
nullptr );
|
||||
} );
|
||||
|
||||
std::vector<vk::DescriptorSetLayoutBinding> bindings;
|
||||
bindings.push_back(vk::DescriptorSetLayoutBinding(0, vk::DescriptorType::eAccelerationStructureNV, 1, vk::ShaderStageFlagBits::eRaygenNV | vk::ShaderStageFlagBits::eClosestHitNV));
|
||||
bindings.push_back(vk::DescriptorSetLayoutBinding(1, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eRaygenNV)); // raytracing output
|
||||
bindings.push_back(vk::DescriptorSetLayoutBinding(2, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eRaygenNV)); // camera information
|
||||
bindings.push_back(vk::DescriptorSetLayoutBinding(3, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV)); // vertex buffer
|
||||
bindings.push_back(vk::DescriptorSetLayoutBinding(4, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV)); // index buffer
|
||||
bindings.push_back(vk::DescriptorSetLayoutBinding(5, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV)); // material buffer
|
||||
bindings.push_back(vk::DescriptorSetLayoutBinding(6, vk::DescriptorType::eCombinedImageSampler, vk::su::checked_cast<uint32_t>(textures.size()), vk::ShaderStageFlagBits::eClosestHitNV)); // textures
|
||||
bindings.push_back(
|
||||
vk::DescriptorSetLayoutBinding( 0,
|
||||
vk::DescriptorType::eAccelerationStructureNV,
|
||||
1,
|
||||
vk::ShaderStageFlagBits::eRaygenNV | vk::ShaderStageFlagBits::eClosestHitNV ) );
|
||||
bindings.push_back( vk::DescriptorSetLayoutBinding(
|
||||
1, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eRaygenNV ) ); // raytracing output
|
||||
bindings.push_back( vk::DescriptorSetLayoutBinding(
|
||||
2, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eRaygenNV ) ); // camera information
|
||||
bindings.push_back( vk::DescriptorSetLayoutBinding(
|
||||
3, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ) ); // vertex buffer
|
||||
bindings.push_back( vk::DescriptorSetLayoutBinding(
|
||||
4, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ) ); // index buffer
|
||||
bindings.push_back( vk::DescriptorSetLayoutBinding(
|
||||
5, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eClosestHitNV ) ); // material buffer
|
||||
bindings.push_back( vk::DescriptorSetLayoutBinding( 6,
|
||||
vk::DescriptorType::eCombinedImageSampler,
|
||||
vk::su::checked_cast<uint32_t>( textures.size() ),
|
||||
vk::ShaderStageFlagBits::eClosestHitNV ) ); // textures
|
||||
|
||||
std::vector<vk::DescriptorPoolSize> descriptorPoolSizes;
|
||||
descriptorPoolSizes.reserve( bindings.size() );
|
||||
for ( const auto & b : bindings )
|
||||
{
|
||||
descriptorPoolSizes.push_back(vk::DescriptorPoolSize(b.descriptorType, vk::su::checked_cast<uint32_t>(swapChainData.images.size()) * b.descriptorCount));
|
||||
descriptorPoolSizes.push_back( vk::DescriptorPoolSize(
|
||||
b.descriptorType, vk::su::checked_cast<uint32_t>( swapChainData.images.size() ) * b.descriptorCount ) );
|
||||
}
|
||||
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, vk::su::checked_cast<uint32_t>(swapChainData.images.size()),
|
||||
vk::su::checked_cast<uint32_t>(descriptorPoolSizes.size()), descriptorPoolSizes.data());
|
||||
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
|
||||
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
|
||||
vk::su::checked_cast<uint32_t>( swapChainData.images.size() ),
|
||||
vk::su::checked_cast<uint32_t>( descriptorPoolSizes.size() ),
|
||||
descriptorPoolSizes.data() );
|
||||
vk::UniqueDescriptorPool rayTracingDescriptorPool = device->createDescriptorPoolUnique( descriptorPoolCreateInfo );
|
||||
vk::UniqueDescriptorSetLayout rayTracingDescriptorSetLayout = device->createDescriptorSetLayoutUnique(vk::DescriptorSetLayoutCreateInfo({}, static_cast<uint32_t>(bindings.size()),
|
||||
bindings.data()));
|
||||
vk::UniqueDescriptorSetLayout rayTracingDescriptorSetLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( {}, static_cast<uint32_t>( bindings.size() ), bindings.data() ) );
|
||||
std::vector<vk::DescriptorSetLayout> layouts;
|
||||
for ( size_t i = 0; i < swapChainData.images.size(); i++ )
|
||||
{
|
||||
layouts.push_back( *rayTracingDescriptorSetLayout );
|
||||
}
|
||||
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo(*rayTracingDescriptorPool, vk::su::checked_cast<uint32_t>(layouts.size()), layouts.data());
|
||||
std::vector<vk::UniqueDescriptorSet> rayTracingDescriptorSets = device->allocateDescriptorSetsUnique(descriptorSetAllocateInfo);
|
||||
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo(
|
||||
*rayTracingDescriptorPool, vk::su::checked_cast<uint32_t>( layouts.size() ), layouts.data() );
|
||||
std::vector<vk::UniqueDescriptorSet> rayTracingDescriptorSets =
|
||||
device->allocateDescriptorSetsUnique( descriptorSetAllocateInfo );
|
||||
|
||||
// Bind ray tracing specific descriptor sets into pNext of a vk::WriteDescriptorSet
|
||||
vk::WriteDescriptorSetAccelerationStructureNV writeDescriptorSetAcceleration(1, &*topLevelAS.acclerationStructure);
|
||||
vk::WriteDescriptorSetAccelerationStructureNV writeDescriptorSetAcceleration( 1,
|
||||
&*topLevelAS.acclerationStructure );
|
||||
std::vector<vk::WriteDescriptorSet> accelerationDescriptionSets;
|
||||
for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ )
|
||||
{
|
||||
accelerationDescriptionSets.push_back(vk::WriteDescriptorSet(*rayTracingDescriptorSets[i], 0, 0, 1, bindings[0].descriptorType));
|
||||
accelerationDescriptionSets.push_back(
|
||||
vk::WriteDescriptorSet( *rayTracingDescriptorSets[i], 0, 0, 1, bindings[0].descriptorType ) );
|
||||
accelerationDescriptionSets.back().pNext = &writeDescriptorSetAcceleration;
|
||||
}
|
||||
device->updateDescriptorSets( accelerationDescriptionSets, {} );
|
||||
|
||||
// Bind all the other buffers and images, starting with dstBinding == 2 (dstBinding == 1 is used by the backBuffer view)
|
||||
// Bind all the other buffers and images, starting with dstBinding == 2 (dstBinding == 1 is used by the backBuffer
|
||||
// view)
|
||||
for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ )
|
||||
{
|
||||
vk::su::updateDescriptorSets(device, rayTracingDescriptorSets[i],
|
||||
{
|
||||
{ bindings[2].descriptorType, uniformBufferData.buffer, vk::UniqueBufferView() },
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
rayTracingDescriptorSets[i],
|
||||
{ { bindings[2].descriptorType, uniformBufferData.buffer, vk::UniqueBufferView() },
|
||||
{ bindings[3].descriptorType, vertexBufferData.buffer, vk::UniqueBufferView() },
|
||||
{ bindings[4].descriptorType, indexBufferData.buffer, vk::UniqueBufferView() },
|
||||
{ bindings[5].descriptorType, materialBufferData.buffer, vk::UniqueBufferView() }
|
||||
}, textures, 2);
|
||||
{ bindings[5].descriptorType, materialBufferData.buffer, vk::UniqueBufferView() } },
|
||||
textures,
|
||||
2 );
|
||||
}
|
||||
|
||||
// create the ray-tracing shader modules
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule raygenShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eRaygenNV, raygenShaderText);
|
||||
vk::UniqueShaderModule missShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eMissNV, missShaderText);
|
||||
vk::UniqueShaderModule shadowMissShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eMissNV, shadowMissShaderText);
|
||||
vk::UniqueShaderModule closestHitShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eClosestHitNV, closestHitShaderText);
|
||||
vk::UniqueShaderModule raygenShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eRaygenNV, raygenShaderText );
|
||||
vk::UniqueShaderModule missShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eMissNV, missShaderText );
|
||||
vk::UniqueShaderModule shadowMissShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eMissNV, shadowMissShaderText );
|
||||
vk::UniqueShaderModule closestHitShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eClosestHitNV, closestHitShaderText );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
// create the ray tracing pipeline
|
||||
@ -893,28 +1055,46 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
std::vector<vk::RayTracingShaderGroupCreateInfoNV> shaderGroups;
|
||||
|
||||
// We use only one ray generation, that will implement the camera model
|
||||
shaderStages.push_back(vk::PipelineShaderStageCreateInfo({}, vk::ShaderStageFlagBits::eRaygenNV, *raygenShaderModule, "main"));
|
||||
shaderGroups.push_back(vk::RayTracingShaderGroupCreateInfoNV(vk::RayTracingShaderGroupTypeNV::eGeneral, 0, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV));
|
||||
shaderStages.push_back(
|
||||
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eRaygenNV, *raygenShaderModule, "main" ) );
|
||||
shaderGroups.push_back( vk::RayTracingShaderGroupCreateInfoNV(
|
||||
vk::RayTracingShaderGroupTypeNV::eGeneral, 0, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV ) );
|
||||
|
||||
// The first miss shader is used to look-up the environment in case the rays from the camera miss the geometry
|
||||
shaderStages.push_back(vk::PipelineShaderStageCreateInfo({}, vk::ShaderStageFlagBits::eMissNV, *missShaderModule, "main"));
|
||||
shaderGroups.push_back(vk::RayTracingShaderGroupCreateInfoNV(vk::RayTracingShaderGroupTypeNV::eGeneral, 1, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV));
|
||||
shaderStages.push_back(
|
||||
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eMissNV, *missShaderModule, "main" ) );
|
||||
shaderGroups.push_back( vk::RayTracingShaderGroupCreateInfoNV(
|
||||
vk::RayTracingShaderGroupTypeNV::eGeneral, 1, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV ) );
|
||||
|
||||
// The second miss shader is invoked when a shadow ray misses the geometry. It simply indicates that no occlusion has been found
|
||||
shaderStages.push_back(vk::PipelineShaderStageCreateInfo({}, vk::ShaderStageFlagBits::eMissNV, *shadowMissShaderModule, "main"));
|
||||
shaderGroups.push_back(vk::RayTracingShaderGroupCreateInfoNV(vk::RayTracingShaderGroupTypeNV::eGeneral, 2, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV));
|
||||
// The second miss shader is invoked when a shadow ray misses the geometry. It simply indicates that no occlusion
|
||||
// has been found
|
||||
shaderStages.push_back(
|
||||
vk::PipelineShaderStageCreateInfo( {}, vk::ShaderStageFlagBits::eMissNV, *shadowMissShaderModule, "main" ) );
|
||||
shaderGroups.push_back( vk::RayTracingShaderGroupCreateInfoNV(
|
||||
vk::RayTracingShaderGroupTypeNV::eGeneral, 2, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV ) );
|
||||
|
||||
// The first hit group defines the shaders invoked when a ray shot from the camera hit the geometry. In this case we only specify the closest hit
|
||||
// shader, and rely on the build-in triangle intersection and pass-through any-hit shader. However, explicit intersection and any hit shaders could be added as well.
|
||||
shaderStages.push_back(vk::PipelineShaderStageCreateInfo({}, vk::ShaderStageFlagBits::eClosestHitNV, *closestHitShaderModule, "main"));
|
||||
shaderGroups.push_back(vk::RayTracingShaderGroupCreateInfoNV(vk::RayTracingShaderGroupTypeNV::eTrianglesHitGroup, VK_SHADER_UNUSED_NV, 3, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV));
|
||||
// The first hit group defines the shaders invoked when a ray shot from the camera hit the geometry. In this case we
|
||||
// only specify the closest hit shader, and rely on the build-in triangle intersection and pass-through any-hit
|
||||
// shader. However, explicit intersection and any hit shaders could be added as well.
|
||||
shaderStages.push_back( vk::PipelineShaderStageCreateInfo(
|
||||
{}, vk::ShaderStageFlagBits::eClosestHitNV, *closestHitShaderModule, "main" ) );
|
||||
shaderGroups.push_back( vk::RayTracingShaderGroupCreateInfoNV( vk::RayTracingShaderGroupTypeNV::eTrianglesHitGroup,
|
||||
VK_SHADER_UNUSED_NV,
|
||||
3,
|
||||
VK_SHADER_UNUSED_NV,
|
||||
VK_SHADER_UNUSED_NV ) );
|
||||
|
||||
// The second hit group defines the shaders invoked when a shadow ray hits the geometry. For simple shadows we do not need any shader in that group: we will rely on
|
||||
// initializing the payload and update it only in the miss shader
|
||||
shaderGroups.push_back(vk::RayTracingShaderGroupCreateInfoNV(vk::RayTracingShaderGroupTypeNV::eTrianglesHitGroup, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV, VK_SHADER_UNUSED_NV));
|
||||
// The second hit group defines the shaders invoked when a shadow ray hits the geometry. For simple shadows we do
|
||||
// not need any shader in that group: we will rely on initializing the payload and update it only in the miss shader
|
||||
shaderGroups.push_back( vk::RayTracingShaderGroupCreateInfoNV( vk::RayTracingShaderGroupTypeNV::eTrianglesHitGroup,
|
||||
VK_SHADER_UNUSED_NV,
|
||||
VK_SHADER_UNUSED_NV,
|
||||
VK_SHADER_UNUSED_NV,
|
||||
VK_SHADER_UNUSED_NV ) );
|
||||
|
||||
// Create the layout of the pipeline following the provided descriptor set layout
|
||||
vk::UniquePipelineLayout rayTracingPipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo({}, 1, &*rayTracingDescriptorSetLayout));
|
||||
vk::UniquePipelineLayout rayTracingPipelineLayout =
|
||||
device->createPipelineLayoutUnique( vk::PipelineLayoutCreateInfo( {}, 1, &*rayTracingDescriptorSetLayout ) );
|
||||
|
||||
// Assemble the shader stages and recursion depth info into the raytracing pipeline
|
||||
// The ray tracing process can shoot rays from the camera, and a shadow ray can be shot from the
|
||||
@ -922,11 +1102,20 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
// as possible for performance reasons. Even recursive ray tracing should be flattened into a loop
|
||||
// in the ray generation to avoid deep recursion.
|
||||
uint32_t maxRecursionDepth = 2;
|
||||
vk::RayTracingPipelineCreateInfoNV rayTracingPipelineCreateInfo({}, static_cast<uint32_t>(shaderStages.size()), shaderStages.data(), static_cast<uint32_t>(shaderGroups.size()),
|
||||
shaderGroups.data(), maxRecursionDepth, *rayTracingPipelineLayout);
|
||||
vk::UniquePipeline rayTracingPipeline = device->createRayTracingPipelineNVUnique(nullptr, rayTracingPipelineCreateInfo);
|
||||
vk::RayTracingPipelineCreateInfoNV rayTracingPipelineCreateInfo( {},
|
||||
static_cast<uint32_t>( shaderStages.size() ),
|
||||
shaderStages.data(),
|
||||
static_cast<uint32_t>( shaderGroups.size() ),
|
||||
shaderGroups.data(),
|
||||
maxRecursionDepth,
|
||||
*rayTracingPipelineLayout );
|
||||
vk::UniquePipeline rayTracingPipeline =
|
||||
device->createRayTracingPipelineNVUnique( nullptr, rayTracingPipelineCreateInfo );
|
||||
|
||||
uint32_t shaderGroupHandleSize = physicalDevice.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV>().get<vk::PhysicalDeviceRayTracingPropertiesNV>().shaderGroupHandleSize;
|
||||
uint32_t shaderGroupHandleSize =
|
||||
physicalDevice.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV>()
|
||||
.get<vk::PhysicalDeviceRayTracingPropertiesNV>()
|
||||
.shaderGroupHandleSize;
|
||||
assert( !( shaderGroupHandleSize % 16 ) );
|
||||
uint32_t shaderBindingTableSize = 5 * shaderGroupHandleSize; // 1x raygen, 2x miss, 2x hitGroup
|
||||
|
||||
@ -934,7 +1123,11 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
std::vector<uint8_t> shaderHandleStorage( shaderBindingTableSize );
|
||||
device->getRayTracingShaderGroupHandlesNV<uint8_t>( *rayTracingPipeline, 0, 5, shaderHandleStorage );
|
||||
|
||||
vk::su::BufferData shaderBindingTableBufferData(physicalDevice, device, shaderBindingTableSize, vk::BufferUsageFlagBits::eTransferDst, vk::MemoryPropertyFlagBits::eHostVisible);
|
||||
vk::su::BufferData shaderBindingTableBufferData( physicalDevice,
|
||||
device,
|
||||
shaderBindingTableSize,
|
||||
vk::BufferUsageFlagBits::eTransferDst,
|
||||
vk::MemoryPropertyFlagBits::eHostVisible );
|
||||
shaderBindingTableBufferData.upload( device, shaderHandleStorage );
|
||||
|
||||
std::array<vk::ClearValue, 2> clearValues;
|
||||
@ -963,34 +1156,48 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
windowExtent.width = w;
|
||||
windowExtent.height = h;
|
||||
device->waitIdle();
|
||||
swapChainData = vk::su::SwapChainData(physicalDevice, device, surface, windowExtent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eStorage, swapChainData.swapChain,
|
||||
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
depthBufferData = vk::su::DepthBufferData(physicalDevice, device, vk::su::pickDepthFormat(physicalDevice), windowExtent);
|
||||
swapChainData =
|
||||
vk::su::SwapChainData( physicalDevice,
|
||||
device,
|
||||
surface,
|
||||
windowExtent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eStorage,
|
||||
swapChainData.swapChain,
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
depthBufferData =
|
||||
vk::su::DepthBufferData( physicalDevice, device, vk::su::pickDepthFormat( physicalDevice ), windowExtent );
|
||||
|
||||
vk::su::oneTimeSubmit(commandBuffer, graphicsQueue,
|
||||
[&](vk::UniqueCommandBuffer const& commandBuffer)
|
||||
{
|
||||
vk::su::setImageLayout(commandBuffer, *depthBufferData.image, depthFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eDepthStencilAttachmentOptimal);
|
||||
vk::su::oneTimeSubmit( commandBuffer, graphicsQueue, [&]( vk::UniqueCommandBuffer const & commandBuffer ) {
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
*depthBufferData.image,
|
||||
depthFormat,
|
||||
vk::ImageLayout::eUndefined,
|
||||
vk::ImageLayout::eDepthStencilAttachmentOptimal );
|
||||
} );
|
||||
|
||||
framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, windowExtent);
|
||||
framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, windowExtent );
|
||||
}
|
||||
|
||||
// update the uniformBufferObject
|
||||
assert( 0 < windowExtent.height );
|
||||
uniformBufferObject.view = appInfo.cameraManipulator.getMatrix();
|
||||
uniformBufferObject.proj = glm::perspective(glm::radians(65.0f), windowExtent.width / static_cast<float>(windowExtent.height), 0.1f, 1000.0f);
|
||||
uniformBufferObject.proj = glm::perspective(
|
||||
glm::radians( 65.0f ), windowExtent.width / static_cast<float>( windowExtent.height ), 0.1f, 1000.0f );
|
||||
uniformBufferObject.proj[1][1] *= -1; // Inverting Y for Vulkan
|
||||
uniformBufferObject.viewInverse = glm::inverse( uniformBufferObject.view );
|
||||
uniformBufferObject.projInverse = glm::inverse( uniformBufferObject.proj );
|
||||
uniformBufferData.upload( device, uniformBufferObject );
|
||||
|
||||
// frame begin
|
||||
vk::ResultValue<uint32_t> rv = device->acquireNextImageKHR(*swapChainData.swapChain, UINT64_MAX, *perFrameData[frameIndex].presentCompleteSemaphore, nullptr);
|
||||
vk::ResultValue<uint32_t> rv = device->acquireNextImageKHR(
|
||||
*swapChainData.swapChain, UINT64_MAX, *perFrameData[frameIndex].presentCompleteSemaphore, nullptr );
|
||||
assert( rv.result == vk::Result::eSuccess );
|
||||
uint32_t backBufferIndex = rv.value;
|
||||
|
||||
while (vk::Result::eTimeout == device->waitForFences(*perFrameData[frameIndex].fence, VK_TRUE, vk::su::FenceTimeout))
|
||||
while ( vk::Result::eTimeout ==
|
||||
device->waitForFences( *perFrameData[frameIndex].fence, VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
device->resetFences( *perFrameData[frameIndex].fence );
|
||||
|
||||
@ -998,13 +1205,24 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
|
||||
if ( appInfo.useRasterRender )
|
||||
{
|
||||
commandBuffer->beginRenderPass(vk::RenderPassBeginInfo(*renderPass, *framebuffers[backBufferIndex], vk::Rect2D(vk::Offset2D(0, 0), windowExtent),
|
||||
static_cast<uint32_t>(clearValues.size()), clearValues.data()), vk::SubpassContents::eInline);
|
||||
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( *renderPass,
|
||||
*framebuffers[backBufferIndex],
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ),
|
||||
static_cast<uint32_t>( clearValues.size() ),
|
||||
clearValues.data() ),
|
||||
vk::SubpassContents::eInline );
|
||||
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, *descriptorSet, nullptr);
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, *descriptorSet, nullptr );
|
||||
|
||||
commandBuffer->setViewport(0, vk::Viewport(0.0f, 0.0f, static_cast<float>(windowExtent.width), static_cast<float>(windowExtent.height), 0.0f, 1.0f));
|
||||
commandBuffer->setViewport( 0,
|
||||
vk::Viewport( 0.0f,
|
||||
0.0f,
|
||||
static_cast<float>( windowExtent.width ),
|
||||
static_cast<float>( windowExtent.height ),
|
||||
0.0f,
|
||||
1.0f ) );
|
||||
commandBuffer->setScissor( 0, vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ) );
|
||||
|
||||
commandBuffer->bindVertexBuffers( 0, *vertexBufferData.buffer, { 0 } );
|
||||
@ -1015,14 +1233,26 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
}
|
||||
else
|
||||
{
|
||||
vk::DescriptorImageInfo imageInfo(nullptr, *swapChainData.imageViews[backBufferIndex], vk::ImageLayout::eGeneral);
|
||||
device->updateDescriptorSets(vk::WriteDescriptorSet(*rayTracingDescriptorSets[backBufferIndex], 1, 0, 1, bindings[1].descriptorType, &imageInfo), {});
|
||||
vk::DescriptorImageInfo imageInfo(
|
||||
nullptr, *swapChainData.imageViews[backBufferIndex], vk::ImageLayout::eGeneral );
|
||||
device->updateDescriptorSets(
|
||||
vk::WriteDescriptorSet(
|
||||
*rayTracingDescriptorSets[backBufferIndex], 1, 0, 1, bindings[1].descriptorType, &imageInfo ),
|
||||
{} );
|
||||
|
||||
vk::su::setImageLayout(commandBuffer, swapChainData.images[backBufferIndex], surfaceFormat.format, vk::ImageLayout::eUndefined, vk::ImageLayout::eGeneral);
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
swapChainData.images[backBufferIndex],
|
||||
surfaceFormat.format,
|
||||
vk::ImageLayout::eUndefined,
|
||||
vk::ImageLayout::eGeneral );
|
||||
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eRayTracingNV, *rayTracingPipeline );
|
||||
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eRayTracingNV, *rayTracingPipelineLayout, 0, *rayTracingDescriptorSets[backBufferIndex], nullptr);
|
||||
commandBuffer->bindDescriptorSets( vk::PipelineBindPoint::eRayTracingNV,
|
||||
*rayTracingPipelineLayout,
|
||||
0,
|
||||
*rayTracingDescriptorSets[backBufferIndex],
|
||||
nullptr );
|
||||
|
||||
VkDeviceSize rayGenOffset = 0; // starting with raygen
|
||||
VkDeviceSize missOffset = shaderGroupHandleSize; // after raygen
|
||||
@ -1030,18 +1260,44 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
VkDeviceSize hitGroupOffset = shaderGroupHandleSize + 2 * shaderGroupHandleSize; // after 1x raygen and 2x miss
|
||||
VkDeviceSize hitGroupStride = shaderGroupHandleSize;
|
||||
|
||||
commandBuffer->traceRaysNV(*shaderBindingTableBufferData.buffer, rayGenOffset, *shaderBindingTableBufferData.buffer, missOffset, missStride, *shaderBindingTableBufferData.buffer,
|
||||
hitGroupOffset, hitGroupStride, nullptr, 0, 0, windowExtent.width, windowExtent.height, 1);
|
||||
commandBuffer->traceRaysNV( *shaderBindingTableBufferData.buffer,
|
||||
rayGenOffset,
|
||||
*shaderBindingTableBufferData.buffer,
|
||||
missOffset,
|
||||
missStride,
|
||||
*shaderBindingTableBufferData.buffer,
|
||||
hitGroupOffset,
|
||||
hitGroupStride,
|
||||
nullptr,
|
||||
0,
|
||||
0,
|
||||
windowExtent.width,
|
||||
windowExtent.height,
|
||||
1 );
|
||||
|
||||
vk::su::setImageLayout(commandBuffer, swapChainData.images[backBufferIndex], surfaceFormat.format, vk::ImageLayout::eGeneral, vk::ImageLayout::ePresentSrcKHR);
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
swapChainData.images[backBufferIndex],
|
||||
surfaceFormat.format,
|
||||
vk::ImageLayout::eGeneral,
|
||||
vk::ImageLayout::ePresentSrcKHR );
|
||||
}
|
||||
|
||||
// frame end
|
||||
commandBuffer->end();
|
||||
const vk::PipelineStageFlags waitDstStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput;
|
||||
graphicsQueue.submit(vk::SubmitInfo(1, &(*perFrameData[frameIndex].presentCompleteSemaphore), &waitDstStageMask, 1, &(*commandBuffer), 1,
|
||||
&(*perFrameData[frameIndex].renderCompleteSemaphore)), *perFrameData[frameIndex].fence);
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(1, &(*perFrameData[frameIndex].renderCompleteSemaphore), 1, &(*swapChainData.swapChain), &backBufferIndex));
|
||||
graphicsQueue.submit( vk::SubmitInfo( 1,
|
||||
&( *perFrameData[frameIndex].presentCompleteSemaphore ),
|
||||
&waitDstStageMask,
|
||||
1,
|
||||
&( *commandBuffer ),
|
||||
1,
|
||||
&( *perFrameData[frameIndex].renderCompleteSemaphore ) ),
|
||||
*perFrameData[frameIndex].fence );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( 1,
|
||||
&( *perFrameData[frameIndex].renderCompleteSemaphore ),
|
||||
1,
|
||||
&( *swapChainData.swapChain ),
|
||||
&backBufferIndex ) );
|
||||
frameIndex = ( frameIndex + 1 ) % IMGUI_VK_QUEUED_FRAMES;
|
||||
|
||||
double endTime = glfwGetTime();
|
||||
@ -1052,7 +1308,9 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
assert( 0 < frameCount );
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << AppName << ": " << vertices.size() << " Vertices " << (appInfo.useRasterRender ? "Rastering" : "RayTracing") << " ( " << frameCount / accumulatedTime << " fps)";
|
||||
oss << AppName << ": " << vertices.size() << " Vertices "
|
||||
<< ( appInfo.useRasterRender ? "Rastering" : "RayTracing" ) << " ( " << frameCount / accumulatedTime
|
||||
<< " fps)";
|
||||
glfwSetWindowTitle( window, oss.str().c_str() );
|
||||
|
||||
accumulatedTime = 0.0;
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
@ -40,45 +41,81 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(surfaceData.extent));
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice(
|
||||
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( surfaceData.extent ) );
|
||||
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device,
|
||||
{ {vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex}, {vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment} });
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device,
|
||||
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
|
||||
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, depthBufferData.format,
|
||||
vk::AttachmentLoadOp::eClear, vk::ImageLayout::eColorAttachmentOptimal);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
depthBufferData.format,
|
||||
vk::AttachmentLoadOp::eClear,
|
||||
vk::ImageLayout::eColorAttachmentOptimal );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, sizeof(texturedCubeData), vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
vk::su::copyToDevice(device, vertexBufferData.deviceMemory, texturedCubeData, sizeof(texturedCubeData) / sizeof(texturedCubeData[0]));
|
||||
vk::su::BufferData vertexBufferData(
|
||||
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
|
||||
vk::su::copyToDevice( device,
|
||||
vertexBufferData.deviceMemory,
|
||||
texturedCubeData,
|
||||
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr),
|
||||
sizeof(texturedCubeData[0]), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise, true, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline =
|
||||
vk::su::createGraphicsPipeline( device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
sizeof( texturedCubeData[0] ),
|
||||
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise,
|
||||
true,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
|
||||
@ -89,35 +126,54 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
checkeredTextureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() );
|
||||
|
||||
// create two identical descriptor sets, each with a different texture but identical UBOs
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(device, { {vk::DescriptorType::eUniformBuffer, 2}, {vk::DescriptorType::eCombinedImageSampler, 2} });
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 2 }, { vk::DescriptorType::eCombinedImageSampler, 2 } } );
|
||||
|
||||
vk::DescriptorSetLayout layouts[] = { descriptorSetLayout.get(), descriptorSetLayout.get() };
|
||||
std::vector<vk::UniqueDescriptorSet> descriptorSets = device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(descriptorPool.get(), 2, layouts));
|
||||
std::vector<vk::UniqueDescriptorSet> descriptorSets =
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( descriptorPool.get(), 2, layouts ) );
|
||||
assert( descriptorSets.size() == 2 );
|
||||
|
||||
vk::su::updateDescriptorSets(device, descriptorSets[0], {{vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView()}}, greenTextureData);
|
||||
vk::su::updateDescriptorSets(device, descriptorSets[1], {{vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView()}}, checkeredTextureData);
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSets[0],
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView() } },
|
||||
greenTextureData );
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSets[1],
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView() } },
|
||||
checkeredTextureData );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
// create four secondary command buffers, for each quadrant of the screen
|
||||
std::vector<vk::UniqueCommandBuffer> secondaryCommandBuffers = device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::eSecondary, 4));
|
||||
std::vector<vk::UniqueCommandBuffer> secondaryCommandBuffers = device->allocateCommandBuffersUnique(
|
||||
vk::CommandBufferAllocateInfo( commandPool.get(), vk::CommandBufferLevel::eSecondary, 4 ) );
|
||||
|
||||
// Get the index of the next available swapchain image:
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(
|
||||
swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
vk::su::setImageLayout(commandBuffer, swapChainData.images[currentBuffer.value], swapChainData.colorFormat, vk::ImageLayout::eUndefined, vk::ImageLayout::eColorAttachmentOptimal);
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
swapChainData.images[currentBuffer.value],
|
||||
swapChainData.colorFormat,
|
||||
vk::ImageLayout::eUndefined,
|
||||
vk::ImageLayout::eColorAttachmentOptimal );
|
||||
|
||||
const vk::DeviceSize offset = 0;
|
||||
vk::Viewport viewport( 0.0f, 0.0f, 200.0f, 200.0f, 0.0f, 1.0f );
|
||||
vk::Rect2D scissor( vk::Offset2D( 0, 0 ), vk::Extent2D( surfaceData.extent ) );
|
||||
|
||||
// now we record four separate command buffers, one for each quadrant of the screen
|
||||
vk::CommandBufferInheritanceInfo commandBufferInheritanceInfo(renderPass.get(), 0, framebuffers[currentBuffer.value].get());
|
||||
vk::CommandBufferBeginInfo secondaryBeginInfo(vk::CommandBufferUsageFlagBits::eOneTimeSubmit | vk::CommandBufferUsageFlagBits::eRenderPassContinue, &commandBufferInheritanceInfo);
|
||||
vk::CommandBufferInheritanceInfo commandBufferInheritanceInfo(
|
||||
renderPass.get(), 0, framebuffers[currentBuffer.value].get() );
|
||||
vk::CommandBufferBeginInfo secondaryBeginInfo( vk::CommandBufferUsageFlagBits::eOneTimeSubmit |
|
||||
vk::CommandBufferUsageFlagBits::eRenderPassContinue,
|
||||
&commandBufferInheritanceInfo );
|
||||
|
||||
for ( int i = 0; i < 4; i++ )
|
||||
{
|
||||
@ -126,7 +182,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
secondaryCommandBuffers[i]->begin( secondaryBeginInfo );
|
||||
secondaryCommandBuffers[i]->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
secondaryCommandBuffers[i]->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSets[i == 0 || i == 3].get(), nullptr);
|
||||
secondaryCommandBuffers[i]->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSets[i == 0 || i == 3].get(), nullptr );
|
||||
secondaryCommandBuffers[i]->bindVertexBuffers( 0, vertexBufferData.buffer.get(), offset );
|
||||
secondaryCommandBuffers[i]->setViewport( 0, viewport );
|
||||
secondaryCommandBuffers[i]->setScissor( 0, scissor );
|
||||
@ -134,20 +191,36 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
secondaryCommandBuffers[i]->end();
|
||||
}
|
||||
|
||||
|
||||
vk::ClearValue clearValues[2];
|
||||
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(0, 0), surfaceData.extent), 2, clearValues);
|
||||
// specifying VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS means this render pass may ONLY call vkCmdExecuteCommands
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
// specifying VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS means this render pass may ONLY call
|
||||
// vkCmdExecuteCommands
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eSecondaryCommandBuffers );
|
||||
commandBuffer->executeCommands( vk::uniqueToRaw( secondaryCommandBuffers ) );
|
||||
commandBuffer->endRenderPass();
|
||||
|
||||
vk::ImageMemoryBarrier prePresentBarrier(vk::AccessFlagBits::eColorAttachmentWrite, vk::AccessFlagBits::eMemoryRead, vk::ImageLayout::eColorAttachmentOptimal, vk::ImageLayout::ePresentSrcKHR,
|
||||
VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED, swapChainData.images[currentBuffer.value], vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1));
|
||||
commandBuffer->pipelineBarrier(vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::PipelineStageFlagBits::eBottomOfPipe, vk::DependencyFlags(), nullptr, nullptr, prePresentBarrier);
|
||||
vk::ImageMemoryBarrier prePresentBarrier(
|
||||
vk::AccessFlagBits::eColorAttachmentWrite,
|
||||
vk::AccessFlagBits::eMemoryRead,
|
||||
vk::ImageLayout::eColorAttachmentOptimal,
|
||||
vk::ImageLayout::ePresentSrcKHR,
|
||||
VK_QUEUE_FAMILY_IGNORED,
|
||||
VK_QUEUE_FAMILY_IGNORED,
|
||||
swapChainData.images[currentBuffer.value],
|
||||
vk::ImageSubresourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 ) );
|
||||
commandBuffer->pipelineBarrier( vk::PipelineStageFlagBits::eColorAttachmentOutput,
|
||||
vk::PipelineStageFlagBits::eBottomOfPipe,
|
||||
vk::DependencyFlags(),
|
||||
nullptr,
|
||||
nullptr,
|
||||
prePresentBarrier );
|
||||
commandBuffer->end();
|
||||
|
||||
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
|
||||
@ -159,7 +232,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
@ -56,7 +57,6 @@ void main()
|
||||
}
|
||||
)";
|
||||
|
||||
|
||||
int main( int /*argc*/, char ** /*argv*/ )
|
||||
{
|
||||
try
|
||||
@ -70,35 +70,59 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(surfaceData.extent));
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice(
|
||||
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( surfaceData.extent ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, depthBufferData.format,
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
depthBufferData.format,
|
||||
vk::AttachmentLoadOp::eClear );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderTextTS_T_C);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderTextTS_T_C );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, sizeof(texturedCubeData), vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
vk::su::copyToDevice(device, vertexBufferData.deviceMemory, texturedCubeData, sizeof(texturedCubeData) / sizeof(texturedCubeData[0]));
|
||||
vk::su::BufferData vertexBufferData(
|
||||
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
|
||||
vk::su::copyToDevice( device,
|
||||
vertexBufferData.deviceMemory,
|
||||
texturedCubeData,
|
||||
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
@ -109,45 +133,62 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
textureData.setImage( device, commandBuffer, vk::su::MonochromeImageGenerator( { 118, 185, 0 } ) );
|
||||
|
||||
// Create the separate sampler
|
||||
vk::UniqueSampler sampler = device->createSamplerUnique(vk::SamplerCreateInfo(vk::SamplerCreateFlags(), vk::Filter::eNearest, vk::Filter::eNearest, vk::SamplerMipmapMode::eNearest,
|
||||
vk::SamplerAddressMode::eClampToEdge, vk::SamplerAddressMode::eClampToEdge, vk::SamplerAddressMode::eClampToEdge,
|
||||
0.0f, false, 1.0f, false, vk::CompareOp::eNever, 0.0f, 0.0f, vk::BorderColor::eFloatOpaqueWhite));
|
||||
vk::UniqueSampler sampler =
|
||||
device->createSamplerUnique( vk::SamplerCreateInfo( vk::SamplerCreateFlags(),
|
||||
vk::Filter::eNearest,
|
||||
vk::Filter::eNearest,
|
||||
vk::SamplerMipmapMode::eNearest,
|
||||
vk::SamplerAddressMode::eClampToEdge,
|
||||
vk::SamplerAddressMode::eClampToEdge,
|
||||
vk::SamplerAddressMode::eClampToEdge,
|
||||
0.0f,
|
||||
false,
|
||||
1.0f,
|
||||
false,
|
||||
vk::CompareOp::eNever,
|
||||
0.0f,
|
||||
0.0f,
|
||||
vk::BorderColor::eFloatOpaqueWhite ) );
|
||||
|
||||
// Create binding and layout for the following, matching contents of shader
|
||||
// binding 0 = uniform buffer (MVP)
|
||||
// binding 1 = texture2D
|
||||
// binding 2 = sampler
|
||||
std::array<vk::DescriptorSetLayoutBinding, 3> resourceBindings =
|
||||
{
|
||||
std::array<vk::DescriptorSetLayoutBinding, 3> resourceBindings = {
|
||||
vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ),
|
||||
vk::DescriptorSetLayoutBinding( 1, vk::DescriptorType::eSampledImage, 1, vk::ShaderStageFlagBits::eFragment ),
|
||||
vk::DescriptorSetLayoutBinding( 2, vk::DescriptorType::eSampler, 1, vk::ShaderStageFlagBits::eFragment )
|
||||
};
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(),
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(),
|
||||
static_cast<uint32_t>( resourceBindings.size() ),
|
||||
resourceBindings.data() ) );
|
||||
|
||||
// Create pipeline layout
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &(*descriptorSetLayout)));
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &( *descriptorSetLayout ) ) );
|
||||
|
||||
// Create a single pool to contain data for the descriptor set
|
||||
std::array<vk::DescriptorPoolSize, 3> poolSizes =
|
||||
{
|
||||
vk::DescriptorPoolSize(vk::DescriptorType::eUniformBuffer, 1),
|
||||
std::array<vk::DescriptorPoolSize, 3> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
|
||||
vk::DescriptorPoolSize( vk::DescriptorType::eSampledImage, 1 ),
|
||||
vk::DescriptorPoolSize(vk::DescriptorType::eSampler, 1)
|
||||
};
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(vk::DescriptorPoolCreateInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1,
|
||||
static_cast<uint32_t>(poolSizes.size()), poolSizes.data()));
|
||||
vk::DescriptorPoolSize( vk::DescriptorType::eSampler, 1 ) };
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
|
||||
1,
|
||||
static_cast<uint32_t>( poolSizes.size() ),
|
||||
poolSizes.data() ) );
|
||||
|
||||
// Populate descriptor sets
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
|
||||
vk::DescriptorImageInfo imageInfo(textureData.textureSampler.get(), textureData.imageData->imageView.get(), vk::ImageLayout::eShaderReadOnlyOptimal);
|
||||
vk::DescriptorImageInfo imageInfo( textureData.textureSampler.get(),
|
||||
textureData.imageData->imageView.get(),
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
vk::DescriptorImageInfo samplerInfo( sampler.get(), {}, {} );
|
||||
std::array<vk::WriteDescriptorSet,3> descriptorWrites =
|
||||
{
|
||||
std::array<vk::WriteDescriptorSet, 3> descriptorWrites = {
|
||||
vk::WriteDescriptorSet( *descriptorSet, 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfo ),
|
||||
vk::WriteDescriptorSet( *descriptorSet, 1, 0, 1, vk::DescriptorType::eSampledImage, &imageInfo ),
|
||||
vk::WriteDescriptorSet( *descriptorSet, 2, 0, 1, vk::DescriptorType::eSampler, &samplerInfo )
|
||||
@ -158,13 +199,22 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr),
|
||||
sizeof(texturedCubeData[0]), { { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise, true, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline =
|
||||
vk::su::createGraphicsPipeline( device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
sizeof( texturedCubeData[0] ),
|
||||
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise,
|
||||
true,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
|
||||
// Get the index of the next available swapchain image:
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(
|
||||
swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
@ -172,14 +222,25 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(0, 0), surfaceData.extent), 2, clearValues);
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr);
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
commandBuffer->draw( 12 * 3, 1, 0, 0 );
|
||||
@ -195,7 +256,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
device->waitIdle();
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
@ -27,16 +28,29 @@ static char const* EngineName = "Vulkan.hpp";
|
||||
void cout( vk::SurfaceCapabilitiesKHR const & surfaceCapabilities )
|
||||
{
|
||||
std::cout << "\tCapabilities:\n";
|
||||
std::cout << "\t\t" << "currentExtent = " << surfaceCapabilities.currentExtent.width << " x " << surfaceCapabilities.currentExtent.height << "\n";
|
||||
std::cout << "\t\t" << "currentTransform = " << vk::to_string(surfaceCapabilities.currentTransform) << "\n";
|
||||
std::cout << "\t\t" << "maxImageArrayLayers = " << surfaceCapabilities.maxImageArrayLayers << "\n";
|
||||
std::cout << "\t\t" << "maxImageCount = " << surfaceCapabilities.maxImageCount << "\n";
|
||||
std::cout << "\t\t" << "maxImageExtent = " << surfaceCapabilities.maxImageExtent.width << " x " << surfaceCapabilities.maxImageExtent.height << "\n";
|
||||
std::cout << "\t\t" << "minImageCount = " << surfaceCapabilities.minImageCount << "\n";
|
||||
std::cout << "\t\t" << "minImageExtent = " << surfaceCapabilities.minImageExtent.width << " x " << surfaceCapabilities.minImageExtent.height << "\n";
|
||||
std::cout << "\t\t" << "supportedCompositeAlpha = " << vk::to_string(surfaceCapabilities.supportedCompositeAlpha) << "\n";
|
||||
std::cout << "\t\t" << "supportedTransforms = " << vk::to_string(surfaceCapabilities.supportedTransforms) << "\n";
|
||||
std::cout << "\t\t" << "supportedUsageFlags = " << vk::to_string(surfaceCapabilities.supportedUsageFlags) << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "currentExtent = " << surfaceCapabilities.currentExtent.width << " x "
|
||||
<< surfaceCapabilities.currentExtent.height << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "currentTransform = " << vk::to_string( surfaceCapabilities.currentTransform ) << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "maxImageArrayLayers = " << surfaceCapabilities.maxImageArrayLayers << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "maxImageCount = " << surfaceCapabilities.maxImageCount << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "maxImageExtent = " << surfaceCapabilities.maxImageExtent.width << " x "
|
||||
<< surfaceCapabilities.maxImageExtent.height << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "minImageCount = " << surfaceCapabilities.minImageCount << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "minImageExtent = " << surfaceCapabilities.minImageExtent.width << " x "
|
||||
<< surfaceCapabilities.minImageExtent.height << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "supportedCompositeAlpha = " << vk::to_string( surfaceCapabilities.supportedCompositeAlpha ) << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "supportedTransforms = " << vk::to_string( surfaceCapabilities.supportedTransforms ) << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "supportedUsageFlags = " << vk::to_string( surfaceCapabilities.supportedUsageFlags ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
@ -47,12 +61,18 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
// need to initialize the dynamic dispatcher before the very first vulkan call
|
||||
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
|
||||
static vk::DynamicLoader dl;
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
|
||||
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
|
||||
#endif
|
||||
|
||||
std::vector<vk::ExtensionProperties> instanceExtensionProperties = vk::enumerateInstanceExtensionProperties();
|
||||
bool supportsGetSurfaceCapabilities2 = (std::find_if(instanceExtensionProperties.begin(), instanceExtensionProperties.end(), [](vk::ExtensionProperties const& ep) { return strcmp(ep.extensionName, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME) == 0; }) != instanceExtensionProperties.end());
|
||||
bool supportsGetSurfaceCapabilities2 =
|
||||
( std::find_if( instanceExtensionProperties.begin(),
|
||||
instanceExtensionProperties.end(),
|
||||
[]( vk::ExtensionProperties const & ep ) {
|
||||
return strcmp( ep.extensionName, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME ) == 0;
|
||||
} ) != instanceExtensionProperties.end() );
|
||||
|
||||
std::vector<std::string> extensions = vk::su::getInstanceExtensions();
|
||||
if ( supportsGetSurfaceCapabilities2 )
|
||||
@ -76,53 +96,72 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
for ( size_t i = 0; i < physicalDevices.size(); i++ )
|
||||
{
|
||||
// some properties are only valid, if a corresponding extension is available!
|
||||
std::vector<vk::ExtensionProperties> extensionProperties = physicalDevices[i].enumerateDeviceExtensionProperties();
|
||||
std::vector<vk::ExtensionProperties> extensionProperties =
|
||||
physicalDevices[i].enumerateDeviceExtensionProperties();
|
||||
|
||||
std::cout << "PhysicalDevice " << i << "\n";
|
||||
if ( supportsGetSurfaceCapabilities2 )
|
||||
{
|
||||
auto surfaceCapabilities2 = physicalDevices[i].getSurfaceCapabilities2KHR<vk::SurfaceCapabilities2KHR, vk::DisplayNativeHdrSurfaceCapabilitiesAMD,
|
||||
vk::SharedPresentSurfaceCapabilitiesKHR, vk::SurfaceCapabilitiesFullScreenExclusiveEXT,
|
||||
auto surfaceCapabilities2 =
|
||||
physicalDevices[i]
|
||||
.getSurfaceCapabilities2KHR<vk::SurfaceCapabilities2KHR,
|
||||
vk::DisplayNativeHdrSurfaceCapabilitiesAMD,
|
||||
vk::SharedPresentSurfaceCapabilitiesKHR,
|
||||
vk::SurfaceCapabilitiesFullScreenExclusiveEXT,
|
||||
vk::SurfaceProtectedCapabilitiesKHR>( *surfaceData.surface );
|
||||
|
||||
vk::SurfaceCapabilitiesKHR const& surfaceCapabilities = surfaceCapabilities2.get<vk::SurfaceCapabilities2KHR>().surfaceCapabilities;
|
||||
vk::SurfaceCapabilitiesKHR const & surfaceCapabilities =
|
||||
surfaceCapabilities2.get<vk::SurfaceCapabilities2KHR>().surfaceCapabilities;
|
||||
cout( surfaceCapabilities );
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_AMD_display_native_hdr" ) )
|
||||
{
|
||||
vk::DisplayNativeHdrSurfaceCapabilitiesAMD displayNativeHdrSurfaceCapabilities = surfaceCapabilities2.get<vk::DisplayNativeHdrSurfaceCapabilitiesAMD>();
|
||||
vk::DisplayNativeHdrSurfaceCapabilitiesAMD displayNativeHdrSurfaceCapabilities =
|
||||
surfaceCapabilities2.get<vk::DisplayNativeHdrSurfaceCapabilitiesAMD>();
|
||||
std::cout << "\tDisplayNativeHdrSurfaceCapabilitiesAMD:\n";
|
||||
std::cout << "\t\t" << "localDimmingSupport = " << static_cast<bool>(displayNativeHdrSurfaceCapabilities.localDimmingSupport) << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "localDimmingSupport = "
|
||||
<< static_cast<bool>( displayNativeHdrSurfaceCapabilities.localDimmingSupport ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_KHR_shared_presentable_image" ) )
|
||||
{
|
||||
vk::SharedPresentSurfaceCapabilitiesKHR sharedPresentSurfaceCapabilities = surfaceCapabilities2.get<vk::SharedPresentSurfaceCapabilitiesKHR>();
|
||||
vk::SharedPresentSurfaceCapabilitiesKHR sharedPresentSurfaceCapabilities =
|
||||
surfaceCapabilities2.get<vk::SharedPresentSurfaceCapabilitiesKHR>();
|
||||
std::cout << "\tSharedPresentSurfaceCapabilitiesKHR:\n";
|
||||
std::cout << "\t\t" << "sharedPresentSupportedUsageFlags = " << vk::to_string(sharedPresentSurfaceCapabilities.sharedPresentSupportedUsageFlags) << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "sharedPresentSupportedUsageFlags = "
|
||||
<< vk::to_string( sharedPresentSurfaceCapabilities.sharedPresentSupportedUsageFlags ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_EXT_full_screen_exclusive" ) )
|
||||
{
|
||||
vk::SurfaceCapabilitiesFullScreenExclusiveEXT surfaceCapabilitiesFullScreenExclusive = surfaceCapabilities2.get<vk::SurfaceCapabilitiesFullScreenExclusiveEXT>();
|
||||
vk::SurfaceCapabilitiesFullScreenExclusiveEXT surfaceCapabilitiesFullScreenExclusive =
|
||||
surfaceCapabilities2.get<vk::SurfaceCapabilitiesFullScreenExclusiveEXT>();
|
||||
std::cout << "\tSurfaceCapabilitiesFullScreenExclusiveEXT:\n";
|
||||
std::cout << "\t\t" << "fullScreenExclusiveSupported = " << static_cast<bool>(surfaceCapabilitiesFullScreenExclusive.fullScreenExclusiveSupported) << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "fullScreenExclusiveSupported = "
|
||||
<< static_cast<bool>( surfaceCapabilitiesFullScreenExclusive.fullScreenExclusiveSupported ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
if ( vk::su::contains( extensionProperties, "VK_KHR_surface_protected_capabilities" ) )
|
||||
{
|
||||
vk::SurfaceProtectedCapabilitiesKHR surfaceProtectedCapabilities = surfaceCapabilities2.get<vk::SurfaceProtectedCapabilitiesKHR>();
|
||||
vk::SurfaceProtectedCapabilitiesKHR surfaceProtectedCapabilities =
|
||||
surfaceCapabilities2.get<vk::SurfaceProtectedCapabilitiesKHR>();
|
||||
std::cout << "\tSurfaceProtectedCapabilitiesKHR:\n";
|
||||
std::cout << "\t\t" << "supportsProtected = " << static_cast<bool>(surfaceProtectedCapabilities.supportsProtected) << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "supportsProtected = " << static_cast<bool>( surfaceProtectedCapabilities.supportsProtected )
|
||||
<< "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevices[i].getSurfaceCapabilitiesKHR(*surfaceData.surface);
|
||||
vk::SurfaceCapabilitiesKHR surfaceCapabilities =
|
||||
physicalDevices[i].getSurfaceCapabilitiesKHR( *surfaceData.surface );
|
||||
cout( surfaceCapabilities );
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
@ -44,12 +45,15 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
for ( size_t i = 0; i < physicalDevices.size(); i++ )
|
||||
{
|
||||
std::cout << "PhysicalDevice " << i << "\n";
|
||||
std::vector<vk::SurfaceFormatKHR> surfaceFormats = physicalDevices[i].getSurfaceFormatsKHR(*surfaceData.surface);
|
||||
std::vector<vk::SurfaceFormatKHR> surfaceFormats =
|
||||
physicalDevices[i].getSurfaceFormatsKHR( *surfaceData.surface );
|
||||
for ( size_t j = 0; j < surfaceFormats.size(); j++ )
|
||||
{
|
||||
std::cout << "\tFormat " << j << "\n";
|
||||
std::cout << "\t\t" << "colorSpace = " << vk::to_string(surfaceFormats[j].colorSpace) << "\n";
|
||||
std::cout << "\t\t" << "format = " << vk::to_string(surfaceFormats[j].format) << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "colorSpace = " << vk::to_string( surfaceFormats[j].colorSpace ) << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< "format = " << vk::to_string( surfaceFormats[j].format ) << "\n";
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
@ -40,17 +41,29 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::DepthBufferData depthBufferData( physicalDevice, device, vk::Format::eD16Unorm, surfaceData.extent );
|
||||
|
||||
@ -59,51 +72,93 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() );
|
||||
|
||||
vk::su::BufferData uniformBufferData(physicalDevice, device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
||||
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(surfaceData.extent));
|
||||
vk::su::BufferData uniformBufferData(
|
||||
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
vk::su::copyToDevice(
|
||||
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( surfaceData.extent ) );
|
||||
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device,
|
||||
{ {vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex}, {vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment} });
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device,
|
||||
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
|
||||
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, depthBufferData.format);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
depthBufferData.format );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText_PT_T );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_T_C );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, depthBufferData.imageView, surfaceData.extent );
|
||||
|
||||
vk::su::BufferData vertexBufferData(physicalDevice, device, sizeof(texturedCubeData), vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
vk::su::copyToDevice(device, vertexBufferData.deviceMemory, texturedCubeData, sizeof(texturedCubeData) / sizeof(texturedCubeData[0]));
|
||||
vk::su::BufferData vertexBufferData(
|
||||
physicalDevice, device, sizeof( texturedCubeData ), vk::BufferUsageFlagBits::eVertexBuffer );
|
||||
vk::su::copyToDevice( device,
|
||||
vertexBufferData.deviceMemory,
|
||||
texturedCubeData,
|
||||
sizeof( texturedCubeData ) / sizeof( texturedCubeData[0] ) );
|
||||
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(device, { {vk::DescriptorType::eUniformBuffer, 1}, {vk::DescriptorType::eCombinedImageSampler, 1} });
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::su::updateDescriptorSets(device, descriptorSet, {{vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView()}}, textureData);
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, vk::UniqueBufferView() } },
|
||||
textureData );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr),
|
||||
sizeof(texturedCubeData[0]), {{ vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 }},
|
||||
vk::FrontFace::eClockwise, true, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline =
|
||||
vk::su::createGraphicsPipeline( device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
sizeof( texturedCubeData[0] ),
|
||||
{ { vk::Format::eR32G32B32A32Sfloat, 0 }, { vk::Format::eR32G32Sfloat, 16 } },
|
||||
vk::FrontFace::eClockwise,
|
||||
true,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
|
||||
// Get the index of the next available swapchain image:
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(
|
||||
swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
vk::ClearValue clearValues[2];
|
||||
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(0, 0), surfaceData.extent), 2, clearValues);
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr);
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
commandBuffer->draw( 12 * 3, 1, 0, 0 );
|
||||
@ -119,7 +174,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
device->waitIdle();
|
||||
|
@ -19,8 +19,9 @@
|
||||
#include "../utils/math.hpp"
|
||||
#include "../utils/shaders.hpp"
|
||||
#include "../utils/utils.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
@ -82,48 +83,87 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
|
||||
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex(physicalDevice, *surfaceData.surface);
|
||||
vk::UniqueDevice device = vk::su::createDevice(physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions());
|
||||
std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex =
|
||||
vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, *surfaceData.surface );
|
||||
vk::UniqueDevice device =
|
||||
vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
|
||||
|
||||
vk::UniqueCommandPool commandPool = vk::su::createCommandPool( device, graphicsAndPresentQueueFamilyIndex.first );
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
|
||||
vk::Queue graphicsQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.first, 0 );
|
||||
vk::Queue presentQueue = device->getQueue( graphicsAndPresentQueueFamilyIndex.second, 0 );
|
||||
|
||||
vk::su::SwapChainData swapChainData(physicalDevice, device, *surfaceData.surface, surfaceData.extent, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(), graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.second);
|
||||
vk::su::SwapChainData swapChainData( physicalDevice,
|
||||
device,
|
||||
*surfaceData.surface,
|
||||
surfaceData.extent,
|
||||
vk::ImageUsageFlagBits::eColorAttachment |
|
||||
vk::ImageUsageFlagBits::eTransferSrc,
|
||||
vk::UniqueSwapchainKHR(),
|
||||
graphicsAndPresentQueueFamilyIndex.first,
|
||||
graphicsAndPresentQueueFamilyIndex.second );
|
||||
|
||||
vk::su::BufferData texelBufferData(physicalDevice, device, sizeof(texels), vk::BufferUsageFlagBits::eUniformTexelBuffer);
|
||||
vk::su::BufferData texelBufferData(
|
||||
physicalDevice, device, sizeof( texels ), vk::BufferUsageFlagBits::eUniformTexelBuffer );
|
||||
texelBufferData.upload( device, texels );
|
||||
|
||||
vk::UniqueBufferView texelBufferView = device->createBufferViewUnique(vk::BufferViewCreateInfo({}, *texelBufferData.buffer, texelFormat, 0, sizeof(texels)));
|
||||
vk::UniqueBufferView texelBufferView = device->createBufferViewUnique(
|
||||
vk::BufferViewCreateInfo( {}, *texelBufferData.buffer, texelFormat, 0, sizeof( texels ) ) );
|
||||
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device, { {vk::DescriptorType::eUniformTexelBuffer, 1, vk::ShaderStageFlagBits::eVertex} });
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get()));
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device, { { vk::DescriptorType::eUniformTexelBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(device, vk::su::pickSurfaceFormat(physicalDevice.getSurfaceFormatsKHR(surfaceData.surface.get())).format, vk::Format::eUndefined);
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface.get() ) ).format,
|
||||
vk::Format::eUndefined );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eVertex, vertexShaderText);
|
||||
vk::UniqueShaderModule fragmentShaderModule = vk::su::createShaderModule(device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C);
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eVertex, vertexShaderText );
|
||||
vk::UniqueShaderModule fragmentShaderModule =
|
||||
vk::su::createShaderModule( device, vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C );
|
||||
glslang::FinalizeProcess();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(device, renderPass, swapChainData.imageViews, vk::UniqueImageView(), surfaceData.extent);
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers = vk::su::createFramebuffers(
|
||||
device, renderPass, swapChainData.imageViews, vk::UniqueImageView(), surfaceData.extent );
|
||||
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(device, { {vk::DescriptorType::eUniformTexelBuffer, 1} });
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(*descriptorPool, 1, &*descriptorSetLayout)).front());
|
||||
vk::su::updateDescriptorSets(device, descriptorSet, {{vk::DescriptorType::eUniformTexelBuffer, texelBufferData.buffer, texelBufferView}}, {});
|
||||
vk::UniqueDescriptorPool descriptorPool =
|
||||
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformTexelBuffer, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
.front() );
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformTexelBuffer, texelBufferData.buffer, texelBufferView } },
|
||||
{} );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(device, pipelineCache, std::make_pair(*vertexShaderModule, nullptr), std::make_pair(*fragmentShaderModule, nullptr),
|
||||
0, {}, vk::FrontFace::eClockwise, false, pipelineLayout, renderPass);
|
||||
vk::UniquePipeline graphicsPipeline =
|
||||
vk::su::createGraphicsPipeline( device,
|
||||
pipelineCache,
|
||||
std::make_pair( *vertexShaderModule, nullptr ),
|
||||
std::make_pair( *fragmentShaderModule, nullptr ),
|
||||
0,
|
||||
{},
|
||||
vk::FrontFace::eClockwise,
|
||||
false,
|
||||
pipelineLayout,
|
||||
renderPass );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
// Get the index of the next available swapchain image:
|
||||
vk::UniqueSemaphore imageAcquiredSemaphore = device->createSemaphoreUnique( vk::SemaphoreCreateInfo() );
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr);
|
||||
vk::ResultValue<uint32_t> currentBuffer = device->acquireNextImageKHR(
|
||||
swapChainData.swapChain.get(), vk::su::FenceTimeout, imageAcquiredSemaphore.get(), nullptr );
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
assert( currentBuffer.value < framebuffers.size() );
|
||||
|
||||
@ -131,13 +171,24 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
|
||||
vk::ClearValue clearValue;
|
||||
clearValue.color = vk::ClearColorValue( std::array<float, 4>( { 0.2f, 0.2f, 0.2f, 0.2f } ) );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo(renderPass.get(), framebuffers[currentBuffer.value].get(), vk::Rect2D(vk::Offset2D(0, 0), surfaceData.extent), 1, &clearValue);
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
1,
|
||||
&clearValue );
|
||||
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
commandBuffer->bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr);
|
||||
commandBuffer->bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics, pipelineLayout.get(), 0, descriptorSet.get(), nullptr );
|
||||
|
||||
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->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 ) );
|
||||
|
||||
commandBuffer->draw( 3, 1, 0, 0 );
|
||||
@ -153,7 +204,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(vk::PresentInfoKHR(0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value));
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
|
@ -28,10 +28,26 @@ namespace vk
|
||||
}
|
||||
|
||||
glm::mat4x4 model = glm::mat4x4( 1.0f );
|
||||
glm::mat4x4 view = glm::lookAt(glm::vec3(-5.0f, 3.0f, -10.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f));
|
||||
glm::mat4x4 view =
|
||||
glm::lookAt( glm::vec3( -5.0f, 3.0f, -10.0f ), glm::vec3( 0.0f, 0.0f, 0.0f ), glm::vec3( 0.0f, -1.0f, 0.0f ) );
|
||||
glm::mat4x4 projection = glm::perspective( fov, 1.0f, 0.1f, 100.0f );
|
||||
glm::mat4x4 clip = glm::mat4x4(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 1.0f); // vulkan clip space has inverted y and half z !
|
||||
glm::mat4x4 clip = glm::mat4x4( 1.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
-1.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.5f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.5f,
|
||||
1.0f ); // vulkan clip space has inverted y and half z !
|
||||
return clip * projection * view * model;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace su
|
||||
} // namespace vk
|
||||
|
@ -15,7 +15,8 @@
|
||||
|
||||
#include <vulkan/vulkan.hpp>
|
||||
#define GLM_FORCE_RADIANS
|
||||
#pragma warning(disable:4201) // disable warning C4201: nonstandard extension used: nameless struct/union; needed to get glm/detail/type_vec?.hpp without warnings
|
||||
#pragma warning( disable : 4201 ) // disable warning C4201: nonstandard extension used: nameless struct/union; needed
|
||||
// to get glm/detail/type_vec?.hpp without warnings
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
namespace vk
|
||||
@ -24,4 +25,4 @@ namespace vk
|
||||
{
|
||||
glm::mat4x4 createModelViewProjectionClipMatrix( vk::Extent2D const & extent );
|
||||
}
|
||||
}
|
||||
} // namespace vk
|
||||
|
@ -14,15 +14,15 @@
|
||||
//
|
||||
|
||||
#include "shaders.hpp"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "StandAlone/ResourceLimits.h"
|
||||
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "StandAlone/ResourceLimits.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
namespace vk
|
||||
{
|
||||
namespace su
|
||||
{
|
||||
|
||||
EShLanguage translateShaderStage( vk::ShaderStageFlagBits stage )
|
||||
{
|
||||
switch ( stage )
|
||||
@ -41,13 +41,13 @@ namespace vk
|
||||
case vk::ShaderStageFlagBits::eCallableNV: return EShLangCallableNV;
|
||||
case vk::ShaderStageFlagBits::eTaskNV: return EShLangTaskNV;
|
||||
case vk::ShaderStageFlagBits::eMeshNV: return EShLangMeshNV;
|
||||
default:
|
||||
assert(false && "Unknown shader stage");
|
||||
return EShLangVertex;
|
||||
default: assert( false && "Unknown shader stage" ); return EShLangVertex;
|
||||
}
|
||||
}
|
||||
|
||||
bool GLSLtoSPV(const vk::ShaderStageFlagBits shaderType, std::string const& glslShader, std::vector<unsigned int> &spvShader)
|
||||
bool GLSLtoSPV( const vk::ShaderStageFlagBits shaderType,
|
||||
std::string const & glslShader,
|
||||
std::vector<unsigned int> & spvShader )
|
||||
{
|
||||
EShLanguage stage = translateShaderStage( shaderType );
|
||||
|
||||
@ -86,13 +86,16 @@ namespace vk
|
||||
return true;
|
||||
}
|
||||
|
||||
vk::UniqueShaderModule createShaderModule(vk::UniqueDevice &device, vk::ShaderStageFlagBits shaderStage, std::string const& shaderText)
|
||||
vk::UniqueShaderModule createShaderModule( vk::UniqueDevice & device,
|
||||
vk::ShaderStageFlagBits shaderStage,
|
||||
std::string const & shaderText )
|
||||
{
|
||||
std::vector<unsigned int> shaderSPV;
|
||||
bool ok = GLSLtoSPV( shaderStage, shaderText, shaderSPV );
|
||||
assert( ok );
|
||||
|
||||
return device->createShaderModuleUnique(vk::ShaderModuleCreateInfo(vk::ShaderModuleCreateFlags(), shaderSPV.size() * sizeof(unsigned int), shaderSPV.data()));
|
||||
}
|
||||
}
|
||||
return device->createShaderModuleUnique( vk::ShaderModuleCreateInfo(
|
||||
vk::ShaderModuleCreateFlags(), shaderSPV.size() * sizeof( unsigned int ), shaderSPV.data() ) );
|
||||
}
|
||||
} // namespace su
|
||||
} // namespace vk
|
||||
|
@ -14,6 +14,7 @@
|
||||
//
|
||||
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -21,12 +22,15 @@ namespace vk
|
||||
{
|
||||
namespace su
|
||||
{
|
||||
vk::UniqueShaderModule createShaderModule(vk::UniqueDevice &device, vk::ShaderStageFlagBits shaderStage, std::string const& shaderText);
|
||||
|
||||
bool GLSLtoSPV(const vk::ShaderStageFlagBits shaderType, std::string const& glslShader, std::vector<unsigned int> &spvShader);
|
||||
}
|
||||
}
|
||||
vk::UniqueShaderModule createShaderModule( vk::UniqueDevice & device,
|
||||
vk::ShaderStageFlagBits shaderStage,
|
||||
std::string const & shaderText );
|
||||
|
||||
bool GLSLtoSPV( const vk::ShaderStageFlagBits shaderType,
|
||||
std::string const & glslShader,
|
||||
std::vector<unsigned int> & spvShader );
|
||||
} // namespace su
|
||||
} // namespace vk
|
||||
|
||||
// vertex shader with (P)osition and (C)olor in and (C)olor out
|
||||
const std::string vertexShaderText_PC_C = R"(
|
||||
@ -76,7 +80,6 @@ void main()
|
||||
}
|
||||
)";
|
||||
|
||||
|
||||
// fragment shader with (C)olor in and (C)olor out
|
||||
const std::string fragmentShaderText_C_C = R"(
|
||||
#version 400
|
||||
@ -112,4 +115,3 @@ void main()
|
||||
outColor = texture(tex, inTexCoord);
|
||||
}
|
||||
)";
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,6 @@
|
||||
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
@ -40,14 +39,25 @@ namespace vk
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
void oneTimeSubmit(vk::UniqueDevice const& device, vk::UniqueCommandPool const& commandPool, vk::Queue const& queue, Func const& func)
|
||||
void oneTimeSubmit( vk::UniqueDevice const & device,
|
||||
vk::UniqueCommandPool const & commandPool,
|
||||
vk::Queue const & queue,
|
||||
Func const & func )
|
||||
{
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(*commandPool, vk::CommandBufferLevel::ePrimary, 1)).front());
|
||||
vk::UniqueCommandBuffer commandBuffer =
|
||||
std::move( device
|
||||
->allocateCommandBuffersUnique(
|
||||
vk::CommandBufferAllocateInfo( *commandPool, vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.front() );
|
||||
oneTimeSubmit( commandBuffer, queue, func );
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void copyToDevice(vk::UniqueDevice const& device, vk::UniqueDeviceMemory const& memory, T const* pData, size_t count, vk::DeviceSize stride = sizeof(T))
|
||||
void copyToDevice( vk::UniqueDevice const & device,
|
||||
vk::UniqueDeviceMemory const & memory,
|
||||
T const * pData,
|
||||
size_t count,
|
||||
vk::DeviceSize stride = sizeof( T ) )
|
||||
{
|
||||
assert( sizeof( T ) <= stride );
|
||||
uint8_t * deviceData = static_cast<uint8_t *>( device->mapMemory( memory.get(), 0, count * stride ) );
|
||||
@ -78,7 +88,11 @@ namespace vk
|
||||
return v < lo ? lo : hi < v ? hi : v;
|
||||
}
|
||||
|
||||
void setImageLayout(vk::UniqueCommandBuffer const &commandBuffer, vk::Image image, vk::Format format, vk::ImageLayout oldImageLayout, vk::ImageLayout newImageLayout);
|
||||
void setImageLayout( vk::UniqueCommandBuffer const & commandBuffer,
|
||||
vk::Image image,
|
||||
vk::Format format,
|
||||
vk::ImageLayout oldImageLayout,
|
||||
vk::ImageLayout newImageLayout );
|
||||
|
||||
struct WindowData
|
||||
{
|
||||
@ -96,13 +110,18 @@ namespace vk
|
||||
|
||||
struct BufferData
|
||||
{
|
||||
BufferData(vk::PhysicalDevice const& physicalDevice, vk::UniqueDevice const& device, vk::DeviceSize size, vk::BufferUsageFlags usage,
|
||||
vk::MemoryPropertyFlags propertyFlags = vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent);
|
||||
BufferData( vk::PhysicalDevice const & physicalDevice,
|
||||
vk::UniqueDevice const & device,
|
||||
vk::DeviceSize size,
|
||||
vk::BufferUsageFlags usage,
|
||||
vk::MemoryPropertyFlags propertyFlags = vk::MemoryPropertyFlagBits::eHostVisible |
|
||||
vk::MemoryPropertyFlagBits::eHostCoherent );
|
||||
|
||||
template <typename DataType>
|
||||
void upload( vk::UniqueDevice const & device, DataType const & data ) const
|
||||
{
|
||||
assert((m_propertyFlags & vk::MemoryPropertyFlagBits::eHostCoherent) && (m_propertyFlags & vk::MemoryPropertyFlagBits::eHostVisible));
|
||||
assert( ( m_propertyFlags & vk::MemoryPropertyFlagBits::eHostCoherent ) &&
|
||||
( m_propertyFlags & vk::MemoryPropertyFlagBits::eHostVisible ) );
|
||||
assert( sizeof( DataType ) <= m_size );
|
||||
|
||||
void * dataPtr = device->mapMemory( *this->deviceMemory, 0, sizeof( DataType ) );
|
||||
@ -122,7 +141,11 @@ namespace vk
|
||||
}
|
||||
|
||||
template <typename DataType>
|
||||
void upload(vk::PhysicalDevice const& physicalDevice, vk::UniqueDevice const& device, vk::UniqueCommandPool const& commandPool, vk::Queue queue, std::vector<DataType> const& data,
|
||||
void upload( vk::PhysicalDevice const & physicalDevice,
|
||||
vk::UniqueDevice const & device,
|
||||
vk::UniqueCommandPool const & commandPool,
|
||||
vk::Queue queue,
|
||||
std::vector<DataType> const & data,
|
||||
size_t stride ) const
|
||||
{
|
||||
assert( m_usage & vk::BufferUsageFlagBits::eTransferDst );
|
||||
@ -137,8 +160,9 @@ namespace vk
|
||||
vk::su::BufferData stagingBuffer( physicalDevice, device, dataSize, vk::BufferUsageFlagBits::eTransferSrc );
|
||||
copyToDevice( device, stagingBuffer.deviceMemory, data.data(), data.size(), elementSize );
|
||||
|
||||
vk::su::oneTimeSubmit(device, commandPool, queue,
|
||||
[&](vk::UniqueCommandBuffer const& commandBuffer) { commandBuffer->copyBuffer(*stagingBuffer.buffer, *this->buffer, vk::BufferCopy(0, 0, dataSize)); });
|
||||
vk::su::oneTimeSubmit( device, commandPool, queue, [&]( vk::UniqueCommandBuffer const & commandBuffer ) {
|
||||
commandBuffer->copyBuffer( *stagingBuffer.buffer, *this->buffer, vk::BufferCopy( 0, 0, dataSize ) );
|
||||
} );
|
||||
}
|
||||
|
||||
vk::UniqueBuffer buffer;
|
||||
@ -153,8 +177,15 @@ namespace vk
|
||||
|
||||
struct ImageData
|
||||
{
|
||||
ImageData(vk::PhysicalDevice const& physicalDevice, vk::UniqueDevice const& device, vk::Format format, vk::Extent2D const& extent, vk::ImageTiling tiling, vk::ImageUsageFlags usage
|
||||
, vk::ImageLayout initialLayout, vk::MemoryPropertyFlags memoryProperties, vk::ImageAspectFlags aspectMask);
|
||||
ImageData( vk::PhysicalDevice const & physicalDevice,
|
||||
vk::UniqueDevice const & device,
|
||||
vk::Format format,
|
||||
vk::Extent2D const & extent,
|
||||
vk::ImageTiling tiling,
|
||||
vk::ImageUsageFlags usage,
|
||||
vk::ImageLayout initialLayout,
|
||||
vk::MemoryPropertyFlags memoryProperties,
|
||||
vk::ImageAspectFlags aspectMask );
|
||||
|
||||
vk::Format format;
|
||||
vk::UniqueImage image;
|
||||
@ -164,7 +195,10 @@ namespace vk
|
||||
|
||||
struct DepthBufferData : public ImageData
|
||||
{
|
||||
DepthBufferData(vk::PhysicalDevice &physicalDevice, vk::UniqueDevice & device, vk::Format format, vk::Extent2D const& extent);
|
||||
DepthBufferData( vk::PhysicalDevice & physicalDevice,
|
||||
vk::UniqueDevice & device,
|
||||
vk::Format format,
|
||||
vk::Extent2D const & extent );
|
||||
};
|
||||
|
||||
struct SurfaceData
|
||||
@ -178,8 +212,14 @@ namespace vk
|
||||
|
||||
struct SwapChainData
|
||||
{
|
||||
SwapChainData(vk::PhysicalDevice const& physicalDevice, vk::UniqueDevice const& device, vk::SurfaceKHR const& surface, vk::Extent2D const& extent, vk::ImageUsageFlags usage,
|
||||
vk::UniqueSwapchainKHR const& oldSwapChain, uint32_t graphicsFamilyIndex, uint32_t presentFamilyIndex);
|
||||
SwapChainData( vk::PhysicalDevice const & physicalDevice,
|
||||
vk::UniqueDevice const & device,
|
||||
vk::SurfaceKHR const & surface,
|
||||
vk::Extent2D const & extent,
|
||||
vk::ImageUsageFlags usage,
|
||||
vk::UniqueSwapchainKHR const & oldSwapChain,
|
||||
uint32_t graphicsFamilyIndex,
|
||||
uint32_t presentFamilyIndex );
|
||||
|
||||
vk::Format colorFormat;
|
||||
vk::UniqueSwapchainKHR swapChain;
|
||||
@ -190,7 +230,8 @@ namespace vk
|
||||
class CheckerboardImageGenerator
|
||||
{
|
||||
public:
|
||||
CheckerboardImageGenerator(std::array<uint8_t, 3> const& rgb0 = {0, 0, 0}, std::array<uint8_t, 3> const& rgb1 = {255, 255, 255});
|
||||
CheckerboardImageGenerator( std::array<uint8_t, 3> const & rgb0 = { 0, 0, 0 },
|
||||
std::array<uint8_t, 3> const & rgb1 = { 255, 255, 255 } );
|
||||
|
||||
void operator()( void * data, vk::Extent2D & extent ) const;
|
||||
|
||||
@ -223,34 +264,62 @@ namespace vk
|
||||
unsigned char const * m_pixels;
|
||||
};
|
||||
|
||||
|
||||
struct TextureData
|
||||
{
|
||||
TextureData(vk::PhysicalDevice const& physicalDevice, vk::UniqueDevice const& device, vk::Extent2D const& extent_ = {256, 256}, vk::ImageUsageFlags usageFlags = {},
|
||||
vk::FormatFeatureFlags formatFeatureFlags = {}, bool anisotropyEnable = false, bool forceStaging = false);
|
||||
TextureData( vk::PhysicalDevice const & physicalDevice,
|
||||
vk::UniqueDevice const & device,
|
||||
vk::Extent2D const & extent_ = { 256, 256 },
|
||||
vk::ImageUsageFlags usageFlags = {},
|
||||
vk::FormatFeatureFlags formatFeatureFlags = {},
|
||||
bool anisotropyEnable = false,
|
||||
bool forceStaging = false );
|
||||
|
||||
template <typename ImageGenerator>
|
||||
void setImage(vk::UniqueDevice const& device, vk::UniqueCommandBuffer const& commandBuffer, ImageGenerator const& imageGenerator)
|
||||
void setImage( vk::UniqueDevice const & device,
|
||||
vk::UniqueCommandBuffer const & commandBuffer,
|
||||
ImageGenerator const & imageGenerator )
|
||||
{
|
||||
void* data = needsStaging
|
||||
? device->mapMemory(stagingBufferData->deviceMemory.get(), 0, device->getBufferMemoryRequirements(stagingBufferData->buffer.get()).size)
|
||||
: device->mapMemory(imageData->deviceMemory.get(), 0, device->getImageMemoryRequirements(imageData->image.get()).size);
|
||||
void * data =
|
||||
needsStaging
|
||||
? device->mapMemory( stagingBufferData->deviceMemory.get(),
|
||||
0,
|
||||
device->getBufferMemoryRequirements( stagingBufferData->buffer.get() ).size )
|
||||
: device->mapMemory(
|
||||
imageData->deviceMemory.get(), 0, device->getImageMemoryRequirements( imageData->image.get() ).size );
|
||||
imageGenerator( data, extent );
|
||||
device->unmapMemory( needsStaging ? stagingBufferData->deviceMemory.get() : imageData->deviceMemory.get() );
|
||||
|
||||
if ( needsStaging )
|
||||
{
|
||||
// Since we're going to blit to the texture image, set its layout to eTransferDstOptimal
|
||||
vk::su::setImageLayout(commandBuffer, imageData->image.get(), imageData->format, vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal);
|
||||
vk::BufferImageCopy copyRegion(0, extent.width, extent.height, vk::ImageSubresourceLayers(vk::ImageAspectFlagBits::eColor, 0, 0, 1), vk::Offset3D(0, 0, 0), vk::Extent3D(extent, 1));
|
||||
commandBuffer->copyBufferToImage(stagingBufferData->buffer.get(), imageData->image.get(), vk::ImageLayout::eTransferDstOptimal, copyRegion);
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
imageData->image.get(),
|
||||
imageData->format,
|
||||
vk::ImageLayout::eUndefined,
|
||||
vk::ImageLayout::eTransferDstOptimal );
|
||||
vk::BufferImageCopy copyRegion( 0,
|
||||
extent.width,
|
||||
extent.height,
|
||||
vk::ImageSubresourceLayers( vk::ImageAspectFlagBits::eColor, 0, 0, 1 ),
|
||||
vk::Offset3D( 0, 0, 0 ),
|
||||
vk::Extent3D( extent, 1 ) );
|
||||
commandBuffer->copyBufferToImage(
|
||||
stagingBufferData->buffer.get(), imageData->image.get(), vk::ImageLayout::eTransferDstOptimal, copyRegion );
|
||||
// Set the layout for the texture image from eTransferDstOptimal to SHADER_READ_ONLY
|
||||
vk::su::setImageLayout(commandBuffer, imageData->image.get(), imageData->format, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal);
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
imageData->image.get(),
|
||||
imageData->format,
|
||||
vk::ImageLayout::eTransferDstOptimal,
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we can use the linear tiled image as a texture, just do it
|
||||
vk::su::setImageLayout(commandBuffer, imageData->image.get(), imageData->format, vk::ImageLayout::ePreinitialized, vk::ImageLayout::eShaderReadOnlyOptimal);
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
imageData->image.get(),
|
||||
imageData->format,
|
||||
vk::ImageLayout::ePreinitialized,
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,7 +339,6 @@ namespace vk
|
||||
uint8_t m_data[VK_UUID_SIZE];
|
||||
};
|
||||
|
||||
|
||||
template <typename TargetType, typename SourceType>
|
||||
VULKAN_HPP_INLINE TargetType checked_cast( SourceType value )
|
||||
{
|
||||
@ -281,42 +349,84 @@ namespace vk
|
||||
return static_cast<TargetType>( value );
|
||||
}
|
||||
|
||||
vk::UniqueDeviceMemory allocateMemory(vk::UniqueDevice const& device, vk::PhysicalDeviceMemoryProperties const& memoryProperties, vk::MemoryRequirements const& memoryRequirements,
|
||||
vk::UniqueDeviceMemory allocateMemory( vk::UniqueDevice const & device,
|
||||
vk::PhysicalDeviceMemoryProperties const & memoryProperties,
|
||||
vk::MemoryRequirements const & memoryRequirements,
|
||||
vk::MemoryPropertyFlags memoryPropertyFlags );
|
||||
bool contains(std::vector<vk::ExtensionProperties> const& extensionProperties, std::string const& extensionName);
|
||||
bool contains( std::vector<vk::ExtensionProperties> const & extensionProperties,
|
||||
std::string const & extensionName );
|
||||
vk::UniqueCommandPool createCommandPool( vk::UniqueDevice & device, uint32_t queueFamilyIndex );
|
||||
vk::UniqueDebugUtilsMessengerEXT createDebugUtilsMessenger( vk::UniqueInstance & instance );
|
||||
vk::UniqueDescriptorPool createDescriptorPool(vk::UniqueDevice &device, std::vector<vk::DescriptorPoolSize> const& poolSizes);
|
||||
vk::UniqueDescriptorSetLayout createDescriptorSetLayout(vk::UniqueDevice const& device, std::vector<std::tuple<vk::DescriptorType, uint32_t, vk::ShaderStageFlags>> const& bindingData,
|
||||
vk::UniqueDescriptorPool createDescriptorPool( vk::UniqueDevice & device,
|
||||
std::vector<vk::DescriptorPoolSize> const & poolSizes );
|
||||
vk::UniqueDescriptorSetLayout createDescriptorSetLayout(
|
||||
vk::UniqueDevice const & device,
|
||||
std::vector<std::tuple<vk::DescriptorType, uint32_t, vk::ShaderStageFlags>> const & bindingData,
|
||||
vk::DescriptorSetLayoutCreateFlags flags = {} );
|
||||
vk::UniqueDevice createDevice(vk::PhysicalDevice physicalDevice, uint32_t queueFamilyIndex, std::vector<std::string> const& extensions = {}, vk::PhysicalDeviceFeatures const* physicalDeviceFeatures = nullptr, void const* pNext = nullptr);
|
||||
std::vector<vk::UniqueFramebuffer> createFramebuffers(vk::UniqueDevice &device, vk::UniqueRenderPass &renderPass, std::vector<vk::UniqueImageView> const& imageViews, vk::UniqueImageView const& depthImageView, vk::Extent2D const& extent);
|
||||
vk::UniquePipeline createGraphicsPipeline(vk::UniqueDevice const& device, vk::UniquePipelineCache const& pipelineCache,
|
||||
vk::UniqueDevice createDevice( vk::PhysicalDevice physicalDevice,
|
||||
uint32_t queueFamilyIndex,
|
||||
std::vector<std::string> const & extensions = {},
|
||||
vk::PhysicalDeviceFeatures const * physicalDeviceFeatures = nullptr,
|
||||
void const * pNext = nullptr );
|
||||
std::vector<vk::UniqueFramebuffer> createFramebuffers( vk::UniqueDevice & device,
|
||||
vk::UniqueRenderPass & renderPass,
|
||||
std::vector<vk::UniqueImageView> const & imageViews,
|
||||
vk::UniqueImageView const & depthImageView,
|
||||
vk::Extent2D const & extent );
|
||||
vk::UniquePipeline
|
||||
createGraphicsPipeline( vk::UniqueDevice const & device,
|
||||
vk::UniquePipelineCache const & pipelineCache,
|
||||
std::pair<vk::ShaderModule, vk::SpecializationInfo const *> const & vertexShaderData,
|
||||
std::pair<vk::ShaderModule, vk::SpecializationInfo const*> const& fragmentShaderData, uint32_t vertexStride,
|
||||
std::vector<std::pair<vk::Format, uint32_t>> const& vertexInputAttributeFormatOffset, vk::FrontFace frontFace, bool depthBuffered,
|
||||
vk::UniquePipelineLayout const& pipelineLayout, vk::UniqueRenderPass const& renderPass);
|
||||
vk::UniqueInstance createInstance(std::string const& appName, std::string const& engineName, std::vector<std::string> const& layers = {}, std::vector<std::string> const& extensions = {},
|
||||
std::pair<vk::ShaderModule, vk::SpecializationInfo const *> const & fragmentShaderData,
|
||||
uint32_t vertexStride,
|
||||
std::vector<std::pair<vk::Format, uint32_t>> const & vertexInputAttributeFormatOffset,
|
||||
vk::FrontFace frontFace,
|
||||
bool depthBuffered,
|
||||
vk::UniquePipelineLayout const & pipelineLayout,
|
||||
vk::UniqueRenderPass const & renderPass );
|
||||
vk::UniqueInstance createInstance( std::string const & appName,
|
||||
std::string const & engineName,
|
||||
std::vector<std::string> const & layers = {},
|
||||
std::vector<std::string> const & extensions = {},
|
||||
uint32_t apiVersion = VK_API_VERSION_1_0 );
|
||||
vk::UniqueRenderPass createRenderPass(vk::UniqueDevice &device, vk::Format colorFormat, vk::Format depthFormat, vk::AttachmentLoadOp loadOp = vk::AttachmentLoadOp::eClear, vk::ImageLayout colorFinalLayout = vk::ImageLayout::ePresentSrcKHR);
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessengerCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes, VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData, void * /*pUserData*/);
|
||||
vk::UniqueRenderPass createRenderPass( vk::UniqueDevice & device,
|
||||
vk::Format colorFormat,
|
||||
vk::Format depthFormat,
|
||||
vk::AttachmentLoadOp loadOp = vk::AttachmentLoadOp::eClear,
|
||||
vk::ImageLayout colorFinalLayout = vk::ImageLayout::ePresentSrcKHR );
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL
|
||||
debugUtilsMessengerCallback( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||
VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData,
|
||||
void * /*pUserData*/ );
|
||||
uint32_t findGraphicsQueueFamilyIndex( std::vector<vk::QueueFamilyProperties> const & queueFamilyProperties );
|
||||
std::pair<uint32_t, uint32_t> findGraphicsAndPresentQueueFamilyIndex(vk::PhysicalDevice physicalDevice, vk::SurfaceKHR const& surface);
|
||||
uint32_t findMemoryType(vk::PhysicalDeviceMemoryProperties const& memoryProperties, uint32_t typeBits, vk::MemoryPropertyFlags requirementsMask);
|
||||
std::pair<uint32_t, uint32_t> findGraphicsAndPresentQueueFamilyIndex( vk::PhysicalDevice physicalDevice,
|
||||
vk::SurfaceKHR const & surface );
|
||||
uint32_t findMemoryType( vk::PhysicalDeviceMemoryProperties const & memoryProperties,
|
||||
uint32_t typeBits,
|
||||
vk::MemoryPropertyFlags requirementsMask );
|
||||
std::vector<std::string> getDeviceExtensions();
|
||||
std::vector<std::string> getInstanceExtensions();
|
||||
vk::Format pickDepthFormat( vk::PhysicalDevice const & physicalDevice );
|
||||
vk::PresentModeKHR pickPresentMode( std::vector<vk::PresentModeKHR> const & presentModes );
|
||||
vk::SurfaceFormatKHR pickSurfaceFormat( std::vector<vk::SurfaceFormatKHR> const & formats );
|
||||
void submitAndWait( vk::UniqueDevice & device, vk::Queue queue, vk::UniqueCommandBuffer & commandBuffer );
|
||||
void updateDescriptorSets(vk::UniqueDevice const& device, vk::UniqueDescriptorSet const& descriptorSet,
|
||||
std::vector<std::tuple<vk::DescriptorType, vk::UniqueBuffer const&, vk::UniqueBufferView const&>> const& bufferData, vk::su::TextureData const& textureData,
|
||||
void updateDescriptorSets(
|
||||
vk::UniqueDevice const & device,
|
||||
vk::UniqueDescriptorSet const & descriptorSet,
|
||||
std::vector<std::tuple<vk::DescriptorType, vk::UniqueBuffer const &, vk::UniqueBufferView const &>> const &
|
||||
bufferData,
|
||||
vk::su::TextureData const & textureData,
|
||||
uint32_t bindingOffset = 0 );
|
||||
void updateDescriptorSets(
|
||||
vk::UniqueDevice const & device,
|
||||
vk::UniqueDescriptorSet const & descriptorSet,
|
||||
std::vector<std::tuple<vk::DescriptorType, vk::UniqueBuffer const &, vk::UniqueBufferView const &>> const &
|
||||
bufferData,
|
||||
std::vector<vk::su::TextureData> const & textureData,
|
||||
uint32_t bindingOffset = 0 );
|
||||
void updateDescriptorSets(vk::UniqueDevice const& device, vk::UniqueDescriptorSet const& descriptorSet,
|
||||
std::vector<std::tuple<vk::DescriptorType, vk::UniqueBuffer const&, vk::UniqueBufferView const&>> const& bufferData,
|
||||
std::vector<vk::su::TextureData> const& textureData, uint32_t bindingOffset = 0);
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace su
|
||||
} // namespace vk
|
||||
|
||||
std::ostream & operator<<( std::ostream & os, vk::su::UUID const & uuid );
|
@ -16,6 +16,7 @@
|
||||
// Compile test on device functions
|
||||
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "DeviceFunctions";
|
||||
@ -33,27 +34,33 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
|
||||
|
||||
// get the first index into queueFamiliyProperties which supports graphics
|
||||
size_t graphicsQueueFamilyIndex = std::distance(queueFamilyProperties.begin(),
|
||||
std::find_if(queueFamilyProperties.begin(),
|
||||
queueFamilyProperties.end(),
|
||||
[](vk::QueueFamilyProperties const& qfp) { return qfp.queueFlags & vk::QueueFlagBits::eGraphics; }));
|
||||
size_t graphicsQueueFamilyIndex = std::distance(
|
||||
queueFamilyProperties.begin(),
|
||||
std::find_if(
|
||||
queueFamilyProperties.begin(), queueFamilyProperties.end(), []( vk::QueueFamilyProperties const & qfp ) {
|
||||
return qfp.queueFlags & vk::QueueFlagBits::eGraphics;
|
||||
} ) );
|
||||
assert( graphicsQueueFamilyIndex < queueFamilyProperties.size() );
|
||||
|
||||
// create a UniqueDevice
|
||||
float queuePriority = 0.0f;
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(vk::DeviceQueueCreateFlags(), static_cast<uint32_t>(graphicsQueueFamilyIndex), 1, &queuePriority);
|
||||
vk::UniqueDevice device = physicalDevice.createDeviceUnique(vk::DeviceCreateInfo(vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo));
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
|
||||
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
|
||||
vk::UniqueDevice device =
|
||||
physicalDevice.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo ) );
|
||||
|
||||
std::vector<uint8_t> data;
|
||||
device->getAccelerationStructureHandleNV<uint8_t>( {}, data, vk::DispatchLoaderDynamic() );
|
||||
|
||||
std::vector<vk::UniqueCommandBuffer>::allocator_type vectorAllocator;
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique({}, vectorAllocator, vk::DispatchLoaderStatic()).front());
|
||||
vk::UniqueCommandBuffer commandBuffer =
|
||||
std::move( device->allocateCommandBuffersUnique( {}, vectorAllocator, vk::DispatchLoaderStatic() ).front() );
|
||||
|
||||
commandBuffer->begin( nullptr );
|
||||
|
||||
std::vector<vk::UniqueHandle<vk::CommandBuffer, vk::DispatchLoaderDynamic>>::allocator_type dynamicVectorAllocator;
|
||||
vk::UniqueHandle<vk::CommandBuffer, vk::DispatchLoaderDynamic> dynamicCommandBuffer = std::move(device->allocateCommandBuffersUnique({}, dynamicVectorAllocator, vk::DispatchLoaderDynamic()).front());
|
||||
vk::UniqueHandle<vk::CommandBuffer, vk::DispatchLoaderDynamic> dynamicCommandBuffer = std::move(
|
||||
device->allocateCommandBuffersUnique( {}, dynamicVectorAllocator, vk::DispatchLoaderDynamic() ).front() );
|
||||
}
|
||||
catch ( vk::SystemError const & err )
|
||||
{
|
||||
|
@ -17,11 +17,11 @@
|
||||
|
||||
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE
|
||||
|
||||
@ -30,7 +30,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
try
|
||||
{
|
||||
vk::DynamicLoader dl;
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
|
||||
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
|
||||
|
||||
vk::Instance instance = vk::createInstance( {}, nullptr );
|
||||
|
@ -16,6 +16,7 @@
|
||||
// Compile test on using std::hash on handles
|
||||
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
|
||||
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "NoExceptions";
|
||||
@ -30,7 +31,8 @@ VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE
|
||||
int main( int /*argc*/, char ** /*argv*/ )
|
||||
{
|
||||
vk::DynamicLoader dl;
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
|
||||
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
|
||||
|
||||
vk::ApplicationInfo appInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
|
||||
@ -47,20 +49,32 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
size_t graphicsQueueFamilyIndex = std::distance( queueFamilyProperties.begin(),
|
||||
std::find_if( queueFamilyProperties.begin(),
|
||||
queueFamilyProperties.end(),
|
||||
[](vk::QueueFamilyProperties const& qfp) { return qfp.queueFlags & vk::QueueFlagBits::eGraphics; }));
|
||||
[]( vk::QueueFamilyProperties const & qfp ) {
|
||||
return qfp.queueFlags & vk::QueueFlagBits::eGraphics;
|
||||
} ) );
|
||||
assert( graphicsQueueFamilyIndex < queueFamilyProperties.size() );
|
||||
|
||||
// create a UniqueDevice
|
||||
float queuePriority = 0.0f;
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(vk::DeviceQueueCreateFlags(), static_cast<uint32_t>(graphicsQueueFamilyIndex), 1, &queuePriority);
|
||||
vk::UniqueDevice device = physicalDevices[0].createDeviceUnique(vk::DeviceCreateInfo(vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo)).value;
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
|
||||
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
|
||||
vk::UniqueDevice device =
|
||||
physicalDevices[0]
|
||||
.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo ) )
|
||||
.value;
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init( *device );
|
||||
|
||||
// create a UniqueCommandPool to allocate a CommandBuffer from
|
||||
vk::UniqueCommandPool commandPool = device->createCommandPoolUnique(vk::CommandPoolCreateInfo(vk::CommandPoolCreateFlags(), deviceQueueCreateInfo.queueFamilyIndex)).value;
|
||||
vk::UniqueCommandPool commandPool = device
|
||||
->createCommandPoolUnique( vk::CommandPoolCreateInfo(
|
||||
vk::CommandPoolCreateFlags(), deviceQueueCreateInfo.queueFamilyIndex ) )
|
||||
.value;
|
||||
|
||||
// allocate a CommandBuffer from the CommandPool
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).value.front());
|
||||
vk::UniqueCommandBuffer commandBuffer = std::move( device
|
||||
->allocateCommandBuffersUnique( vk::CommandBufferAllocateInfo(
|
||||
commandPool.get(), vk::CommandBufferLevel::ePrimary, 1 ) )
|
||||
.value.front() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
|
||||
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static char const * AppName = "StructureChain";
|
||||
@ -42,7 +43,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
try
|
||||
{
|
||||
vk::DynamicLoader dl;
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
|
||||
dl.getProcAddress<PFN_vkGetInstanceProcAddr>( "vkGetInstanceProcAddr" );
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr );
|
||||
|
||||
vk::ApplicationInfo appInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
|
||||
@ -55,23 +57,34 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceIDProperties> sc1;
|
||||
vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceMaintenance3Properties> sc2;
|
||||
vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDevicePushDescriptorPropertiesKHR> sc3;
|
||||
vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceMaintenance3Properties> sc4;
|
||||
vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceIDProperties, vk::PhysicalDevicePushDescriptorPropertiesKHR> sc6;
|
||||
vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceMaintenance3Properties, vk::PhysicalDevicePushDescriptorPropertiesKHR> sc7;
|
||||
vk::StructureChain<vk::PhysicalDeviceProperties2,
|
||||
vk::PhysicalDeviceIDProperties,
|
||||
vk::PhysicalDeviceMaintenance3Properties>
|
||||
sc4;
|
||||
vk::StructureChain<vk::PhysicalDeviceProperties2,
|
||||
vk::PhysicalDeviceIDProperties,
|
||||
vk::PhysicalDevicePushDescriptorPropertiesKHR>
|
||||
sc6;
|
||||
vk::StructureChain<vk::PhysicalDeviceProperties2,
|
||||
vk::PhysicalDeviceIDProperties,
|
||||
vk::PhysicalDeviceMaintenance3Properties,
|
||||
vk::PhysicalDevicePushDescriptorPropertiesKHR>
|
||||
sc7;
|
||||
|
||||
// some invalid StructureChains
|
||||
// vk::StructureChain<vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceMaintenance3Properties> x;
|
||||
//vk::StructureChain<vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceMaintenance3Properties, vk::PhysicalDevicePushDescriptorPropertiesKHR> x;
|
||||
//vk::StructureChain<vk::PhysicalDeviceIDProperties, vk::PhysicalDevicePushDescriptorPropertiesKHR, vk::PhysicalDeviceMaintenance3Properties> x;
|
||||
//vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceIDProperties> x;
|
||||
//vk::StructureChain<vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceProperties2> x;
|
||||
// vk::StructureChain<vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceMaintenance3Properties,
|
||||
// vk::PhysicalDevicePushDescriptorPropertiesKHR> x; vk::StructureChain<vk::PhysicalDeviceIDProperties,
|
||||
// vk::PhysicalDevicePushDescriptorPropertiesKHR, vk::PhysicalDeviceMaintenance3Properties> x;
|
||||
// vk::StructureChain<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceIDProperties>
|
||||
// x; vk::StructureChain<vk::PhysicalDeviceIDProperties, vk::PhysicalDeviceProperties2> x;
|
||||
|
||||
// unlink a struct from a StructureChain
|
||||
sc7.unlink<vk::PhysicalDeviceMaintenance3Properties>();
|
||||
|
||||
// some invalid unlink calls
|
||||
//sc7.unlink<vk::PhysicalDeviceMaintenance3Properties>(); // assertion fires on trying to unlink some already unlinked structure
|
||||
//sc7.unlink<vk::PhysicalDeviceProperties2>();
|
||||
// sc7.unlink<vk::PhysicalDeviceMaintenance3Properties>(); // assertion fires on trying to unlink some already
|
||||
// unlinked structure sc7.unlink<vk::PhysicalDeviceProperties2>();
|
||||
// sc1.unlink<vk::PhysicalDeviceMaintenance3Properties>();
|
||||
|
||||
// re-link a struct
|
||||
@ -80,7 +93,8 @@ int main(int /*argc*/, char ** /*argv*/)
|
||||
// invalid re-linking
|
||||
// sc7.relink<vk::PhysicalDeviceProperties2>();
|
||||
// sc1.relink<vk::PhysicalDeviceMaintenance3Properties>();
|
||||
//sc1.relink<vk::PhysicalDeviceIDProperties>(); // assertion fires on trying to relink some structure that hasn't been unlinked
|
||||
// sc1.relink<vk::PhysicalDeviceIDProperties>(); // assertion fires on trying to relink some structure
|
||||
// that hasn't been unlinked
|
||||
|
||||
// simple call, passing structures in
|
||||
vk::PhysicalDeviceFeatures2 pdf;
|
||||
|
39808
vulkan/vulkan.hpp
39808
vulkan/vulkan.hpp
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user