From 89571e5298ade42724cfce097833064e5ef28841 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Tue, 23 Apr 2024 08:11:44 +0200 Subject: [PATCH] Fixing vulkan --- .clang-format | 244 ---------------- .clangd | 0 .gitignore | 1 + .vscode/c_cpp_properties.json | 36 --- .vscode/launch.json | 12 +- .vscode/settings.json | 142 +-------- CMakeLists.txt | 24 +- cmake/SuperBuild.cmake | 57 ++-- compile_commands.json | 1 - external/vcpkg | 2 +- src/Editor/main.cpp | 188 +----------- src/Engine/Asset/AssetRegistry.cpp | 10 +- src/Engine/Graphics/Descriptor.h | 3 +- src/Engine/Graphics/Initializer.h | 2 +- src/Engine/Graphics/RenderPass/DebugPass.cpp | 2 +- .../Graphics/RenderPass/LightCullingPass.cpp | 4 +- .../Graphics/RenderPass/SkyboxRenderPass.cpp | 2 +- src/Engine/Graphics/RenderPass/UIPass.cpp | 4 +- src/Engine/Graphics/Vulkan/Buffer.cpp | 273 +++++++----------- src/Engine/Graphics/Vulkan/Buffer.h | 4 + src/Engine/Graphics/Vulkan/Command.cpp | 20 +- src/Engine/Graphics/Vulkan/Command.h | 31 +- src/Engine/Graphics/Vulkan/Descriptor.cpp | 16 +- src/Engine/Graphics/Vulkan/Descriptor.h | 2 +- src/Engine/Graphics/Vulkan/Enums.cpp | 36 --- src/Engine/Graphics/Vulkan/Graphics.cpp | 4 +- src/Engine/Graphics/Vulkan/Pipeline.cpp | 4 +- src/Engine/Graphics/Vulkan/Pipeline.h | 4 +- src/Engine/Graphics/Vulkan/PipelineCache.cpp | 6 +- src/Engine/Graphics/Vulkan/Shader.cpp | 4 +- src/Engine/Graphics/Vulkan/Window.cpp | 1 + src/Engine/Graphics/slang-compile.cpp | 1 - vcpkg.json | 3 +- 33 files changed, 217 insertions(+), 926 deletions(-) delete mode 100644 .clang-format delete mode 100644 .clangd delete mode 100644 .vscode/c_cpp_properties.json delete mode 120000 compile_commands.json diff --git a/.clang-format b/.clang-format deleted file mode 100644 index dcf16f8..0000000 --- a/.clang-format +++ /dev/null @@ -1,244 +0,0 @@ -# BasedOnStyle: LLVM -AccessModifierOffset: -2 -AlignAfterOpenBracket: Align -AlignArrayOfStructures: None -AlignConsecutiveAssignments: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: true -AlignConsecutiveBitFields: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveDeclarations: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveMacros: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveShortCaseStatements: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCaseColons: false -AlignEscapedNewlines: Right -AlignOperands: Align -AlignTrailingComments: - Kind: Always - OverEmptyLines: 0 -AllowAllArgumentsOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowBreakBeforeNoexceptSpecifier: Never -AllowShortBlocksOnASingleLine: Never -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: true -AllowShortEnumsOnASingleLine: true -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: Never -AllowShortLambdasOnASingleLine: All -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: MultiLine -AttributeMacros: - - __capability -BinPackArguments: true -BinPackParameters: true -BitFieldColonSpacing: Both -BraceWrapping: - AfterCaseLabel: false - AfterClass: false - AfterControlStatement: Never - AfterEnum: false - AfterExternBlock: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakAdjacentStringLiterals: true -BreakAfterAttributes: Leave -BreakAfterJavaFieldAnnotations: false -BreakArrays: true -BreakBeforeBinaryOperators: None -BreakBeforeConceptDeclarations: Always -BreakBeforeBraces: Attach -BreakBeforeInlineASMColon: OnlyMultiline -BreakBeforeTernaryOperators: true -BreakConstructorInitializers: BeforeColon -BreakInheritanceList: BeforeColon -BreakStringLiterals: true -ColumnLimit: 120 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DerivePointerAlignment: false -DisableFormat: false -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: LogicalBlock -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IfMacros: - - KJ_IF_MAYBE -IncludeBlocks: Preserve -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - SortPriority: 0 - CaseSensitive: false - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - SortPriority: 0 - CaseSensitive: false - - Regex: '.*' - Priority: 1 - SortPriority: 0 - CaseSensitive: false -IncludeIsMainRegex: '(Test)?$' -IncludeIsMainSourceRegex: '' -IndentAccessModifiers: false -IndentCaseBlocks: false -IndentCaseLabels: false -IndentExternBlock: AfterExternBlock -IndentGotoLabels: true -IndentPPDirectives: None -IndentRequiresClause: true -IndentWidth: 2 -IndentWrappedFunctionNames: false -InsertBraces: false -InsertNewlineAtEOF: false -InsertTrailingCommas: None -IntegerLiteralSeparator: - Binary: 0 - BinaryMinDigits: 0 - Decimal: 0 - DecimalMinDigits: 0 - Hex: 0 - HexMinDigits: 0 -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: true -KeepEmptyLinesAtEOF: false -LambdaBodyIndentation: Signature -LineEnding: DeriveLF -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 2 -ObjCBreakBeforeNestedBlockParam: true -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PackConstructorInitializers: BinPack -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakOpenParenthesis: 0 -PenaltyBreakScopeResolution: 500 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 -PenaltyIndentedWhitespace: 0 -PenaltyReturnTypeOnItsOwnLine: 60 -PointerAlignment: Left -PPIndentWidth: -1 -QualifierAlignment: Leave -ReferenceAlignment: Pointer -ReflowComments: true -RemoveBracesLLVM: false -RemoveParentheses: Leave -RemoveSemicolon: false -RequiresClausePosition: OwnLine -RequiresExpressionIndentation: OuterScope -SeparateDefinitionBlocks: Leave -ShortNamespaceLines: 1 -SkipMacroDefinitionBody: false -SortIncludes: CaseSensitive -SortJavaStaticImport: Before -SortUsingDeclarations: LexicographicNumeric -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: true -SpaceAroundPointerQualifiers: Default -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeJsonColon: false -SpaceBeforeParens: ControlStatements -SpaceBeforeParensOptions: - AfterControlStatements: true - AfterForeachMacros: true - AfterFunctionDefinitionName: false - AfterFunctionDeclarationName: false - AfterIfMacros: true - AfterOverloadedOperator: false - AfterPlacementOperator: true - AfterRequiresInClause: false - AfterRequiresInExpression: false - BeforeNonEmptyParentheses: false -SpaceBeforeRangeBasedForLoopColon: true -SpaceBeforeSquareBrackets: false -SpaceInEmptyBlock: false -SpacesBeforeTrailingComments: 1 -SpacesInAngles: Never -SpacesInContainerLiterals: true -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParens: Never -SpacesInParensOptions: - InCStyleCasts: false - InConditionalStatements: false - InEmptyParentheses: false - Other: false -SpacesInSquareBrackets: false -Standard: Latest -StatementAttributeLikeMacros: - - Q_EMIT -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION -TabWidth: 8 -UseTab: Never -VerilogBreakBetweenInstancePorts: true -WhitespaceSensitiveMacros: - - BOOST_PP_STRINGIZE - - CF_SWIFT_NAME - - NS_SWIFT_NAME - - PP_STRINGIZE - - STRINGIZE -... - diff --git a/.clangd b/.clangd deleted file mode 100644 index e69de29..0000000 diff --git a/.gitignore b/.gitignore index d638f85..51c5133 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ bld/ [Oo]bj/ [Ll]og/ vcpkg_installed/ +build/ # Visual Studio 2015/2017 cache/options directory .vs/ diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index 1eeb684..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "configurations": [ - { - "name": "Win32", - "includePath": [ - "${workspaceFolder}/src/**" - ], - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE" - ], - "windowsSdkVersion": "10.0.20348.0", - "compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe", - "cppStandard": "c++20", - "intelliSenseMode": "windows-msvc-x64", - "configurationProvider": "ms-vscode.cmake-tools" - }, - { - "name": "Mac", - "includePath": [ - "${workspaceFolder}/src/**" - ], - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE" - ], - "compilerPath": "/usr/bin/clang", - "cppStandard": "c++20", - "intelliSenseMode": "macos-clang-arm64", - "configurationProvider": "ms-vscode.cmake-tools" - } - ], - "version": 4 -} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 614bf8d..9f61d57 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,10 +8,10 @@ "name": "Editor", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceRoot}/bin/Editor.exe", + "program": "${workspaceRoot}/build/Editor.exe", "args": [], "stopAtEntry": false, - "cwd": "${workspaceRoot}/bin", + "cwd": "${workspaceRoot}/build", "console": "internalConsole", "environment": [], "symbolSearchPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.25.28610\\lib\\x64", @@ -28,10 +28,10 @@ "name": "Editor (Mac)", "type": "lldb", "request": "launch", - "program": "${workspaceRoot}/bin/Editor", + "program": "${workspaceRoot}/build/Editor", "args": [], "stopAtEntry": false, - "cwd": "${workspaceRoot}/bin", + "cwd": "${workspaceRoot}/build", "environment": [ { "name": "VK_LAYER_PATH", @@ -49,10 +49,10 @@ "name": "Editor (Linux)", "type": "cppdbg", "request": "launch", - "program": "${workspaceRoot}/bin/Editor", + "program": "${workspaceRoot}/build/Editor", "args": [], "stopAtEntry": false, - "cwd": "${workspaceRoot}/bin", + "cwd": "${workspaceRoot}/build", "environment": [], "externalConsole": false, "MIMode": "gdb", diff --git a/.vscode/settings.json b/.vscode/settings.json index 6b827b4..fdd9d93 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,144 +1,5 @@ { - "telemetry.enableTelemetry": false, "cmake.cmakePath": "cmake", - "cmake.buildDirectory": "${workspaceFolder}/bin", - "files.associations": { - "*.h": "cpp", - "*.ush": "hlsl", - "*.slang": "hlsl", - "*.pl": "prolog", - "xstring": "cpp", - "list": "cpp", - "xhash": "cpp", - "xiosbase": "cpp", - "xmemory": "cpp", - "xtree": "cpp", - "type_traits": "cpp", - "vector": "cpp", - "*.rh": "cpp", - "memory": "cpp", - "*.ipp": "cpp", - "iostream": "cpp", - "initializer_list": "cpp", - "algorithm": "cpp", - "array": "cpp", - "atomic": "cpp", - "cctype": "cpp", - "chrono": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "concepts": "cpp", - "condition_variable": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "exception": "cpp", - "forward_list": "cpp", - "fstream": "cpp", - "functional": "cpp", - "iomanip": "cpp", - "ios": "cpp", - "iosfwd": "cpp", - "istream": "cpp", - "iterator": "cpp", - "limits": "cpp", - "map": "cpp", - "mutex": "cpp", - "new": "cpp", - "numeric": "cpp", - "ostream": "cpp", - "ratio": "cpp", - "set": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "string": "cpp", - "system_error": "cpp", - "thread": "cpp", - "tuple": "cpp", - "typeinfo": "cpp", - "unordered_map": "cpp", - "utility": "cpp", - "valarray": "cpp", - "xfacet": "cpp", - "xlocale": "cpp", - "xlocinfo": "cpp", - "xlocmon": "cpp", - "xlocnum": "cpp", - "xloctime": "cpp", - "xstddef": "cpp", - "xtr1common": "cpp", - "xutility": "cpp", - "filesystem": "cpp", - "bitset": "cpp", - "complex": "cpp", - "csignal": "cpp", - "deque": "cpp", - "locale": "cpp", - "optional": "cpp", - "typeindex": "cpp", - "variant": "cpp", - "xlocbuf": "cpp", - "xlocmes": "cpp", - "codecvt": "cpp", - "regex": "cpp", - "strstream": "cpp", - "resumable": "cpp", - "future": "cpp", - "cstdarg": "cpp", - "cwctype": "cpp", - "queue": "cpp", - "random": "cpp", - "shared_mutex": "cpp", - "unordered_set": "cpp", - "csetjmp": "cpp", - "memory_resource": "cpp", - "*.inc": "cpp", - "any": "cpp", - "bit": "cpp", - "cfenv": "cpp", - "cinttypes": "cpp", - "compare": "cpp", - "execution": "cpp", - "hash_map": "cpp", - "hash_set": "cpp", - "scoped_allocator": "cpp", - "stack": "cpp", - "coroutine": "cpp", - "*.tcc": "cpp", - "stop_token": "cpp", - "span": "cpp", - "charconv": "cpp", - "format": "cpp", - "semaphore": "cpp", - "netfwd": "cpp", - "string_view": "cpp", - "rope": "cpp", - "slist": "cpp", - "numbers": "cpp", - "barrier": "cpp", - "latch": "cpp", - "ranges": "cpp", - "source_location": "cpp", - "syncstream": "cpp", - "stdfloat": "cpp", - "__bit_reference": "cpp", - "__config": "cpp", - "__debug": "cpp", - "__errc": "cpp", - "__hash_table": "cpp", - "__locale": "cpp", - "__mutex_base": "cpp", - "__node_handle": "cpp", - "__split_buffer": "cpp", - "__threading_support": "cpp", - "__tree": "cpp", - "__verbose_abort": "cpp" - }, "cmake.skipConfigureIfCachePresent": false, "cmake.configureArgs": [ "-Wno-dev" @@ -163,6 +24,5 @@ "lldb.displayFormat": "auto", "lldb.showDisassembly": "auto", "lldb.dereferencePointers": true, - "lldb.consoleMode": "commands", - "cmake.generator": "Xcode", + "lldb.consoleMode": "commands" } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index fac3163..01e1cde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,15 +28,16 @@ project (Seele) include(cmake/SuperBuild.cmake) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build) #Workaround for vs, because it places artifacts into an additional subfolder -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/bin) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/bin) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_CURRENT_SOURCE_DIR}/bin) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/bin) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/bin) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_CURRENT_SOURCE_DIR}/bin) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/build) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/build) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_CURRENT_SOURCE_DIR}/build) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_CURRENT_SOURCE_DIR}/build) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/build) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/build) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_CURRENT_SOURCE_DIR}/build) find_package(Vulkan REQUIRED) find_package(assimp CONFIG REQUIRED) @@ -49,7 +50,6 @@ find_package(Ktx CONFIG REQUIRED) find_package(nlohmann_json CONFIG REQUIRED) find_package(fmt CONFIG REQUIRED) find_package(VulkanMemoryAllocator CONFIG REQUIRED) -find_package(glslang CONFIG REQUIRED) if(UNIX) find_package(Threads REQUIRED) @@ -75,11 +75,7 @@ target_link_libraries(Engine PUBLIC crcpp) target_link_libraries(Engine PUBLIC fmt::fmt) target_link_libraries(Engine PUBLIC GPUOpen::VulkanMemoryAllocator) target_link_libraries(Engine PUBLIC slang) -target_link_libraries(Engine PUBLIC glslang::glslang) if(APPLE) - target_include_directories(Engine PUBLIC /usr/local/include) - target_link_directories(Engine PUBLIC /usr/local/lib) - target_link_libraries(Engine PUBLIC metalirconverter) target_link_libraries(Engine PUBLIC metal) SET(CMAKE_OSX_DEPLOYMENT_TARGET 14.3) endif() @@ -152,8 +148,6 @@ install( Editor Engine crcpp - metal - slang EXPORT EngineTargets FILE_SET HEADERS diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index 37966c7..5870d6f 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -2,37 +2,34 @@ include (ExternalProject) #--------------SLang------------------------------ -set(SLANG_ROOT ${EXTERNAL_ROOT}/slang) -#add_library(shader-slang SHARED IMPORTED) -#if(WIN32) -# add_library(shader-slang-glslang SHARED IMPORTED) -# set(SLANG_ROOT ${EXTERNAL_ROOT}/slang/bin/windows-x64/release/) -# set_target_properties(shader-slang-glslang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/bin/slang-glslang.dll) -# set_target_properties(shader-slang-glslang PROPERTIES IMPORTED_IMPLIB ${SLANG_ROOT}/lib/slang.lib) -# set_target_properties(shader-slang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}/bin/slang.dll) -# set_target_properties(shader-slang PROPERTIES IMPORTED_IMPLIB ${SLANG_ROOT}/lib/slang.lib) -# target_link_libraries(shader-slang INTERFACE shader-slang-glslang) -# install(FILES -# ${SLANG_ROOT}/bin/slang-glslang.dll -# ${SLANG_ROOT}/bin/slang.dll -# DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) -# install(FILES -# ${SLANG_ROOT}/lib/slang.lib -# DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) -#elseif(APPLE) -# set(BINARY_ROOT ${SLANG_ROOT}/bin/macosx-aarch64/release/) -# set_target_properties(shader-slang PROPERTIES IMPORTED_LOCATION ${BINARY_ROOT}/libslang.dylib) -# install(FILES -# ${BINARY_ROOT}/libslang.dylib -# DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) -#endif() -#target_include_directories(shader-slang INTERFACE -# $ -# $ -#) +add_library(slang SHARED IMPORTED) +if(WIN32) + add_library(slang-glslang SHARED IMPORTED) + set(SLANG_ROOT ${EXTERNAL_ROOT}/slang/bin/windows-x64/release/) + set_target_properties(slang-glslang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}slang-glslang.dll) + set_target_properties(slang-glslang PROPERTIES IMPORTED_IMPLIB ${SLANG_ROOT}slang.lib) + set_target_properties(slang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}slang.dll) + set_target_properties(slang PROPERTIES IMPORTED_IMPLIB ${SLANG_ROOT}slang.lib) + target_link_libraries(slang INTERFACE slang-glslang) + install(FILES + ${SLANG_ROOT}slang-glslang.dll + ${SLANG_ROOT}slang.dll + DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) + install(FILES + ${SLANG_ROOT}slang.lib + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) +elseif(APPLE) + set(BINARY_ROOT ${SLANG_ROOT}/bin/macosx-aarch64/release/) + set_target_properties(slang PROPERTIES IMPORTED_LOCATION ${BINARY_ROOT}/libslang.dylib) + install(FILES + ${BINARY_ROOT}/libslang.dylib + DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) +endif() +target_include_directories(slang INTERFACE + $ + $ +) -add_subdirectory(${SLANG_ROOT}) -target_compile_definitions(compiler-core PUBLIC SLANG_ENABLE_DXIL_SUPPORT=1) #--------------CRC++------------------------------ add_library(crcpp INTERFACE) diff --git a/compile_commands.json b/compile_commands.json deleted file mode 120000 index b8bca52..0000000 --- a/compile_commands.json +++ /dev/null @@ -1 +0,0 @@ -bin/compile_commands.json \ No newline at end of file diff --git a/external/vcpkg b/external/vcpkg index c442507..042c31e 160000 --- a/external/vcpkg +++ b/external/vcpkg @@ -1 +1 @@ -Subproject commit c44250706fb0e336618e1a9bcb3a2783f2f18073 +Subproject commit 042c31edc695ab91f6cf43f58f964baf33d53137 diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index 6509399..c91079a 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -5,12 +5,14 @@ #include "Asset/MeshLoader.h" #include "Asset/TextureLoader.h" #include "Graphics/Initializer.h" +#ifdef __APPLE__ #include "Graphics/Metal/Graphics.h" +#else +#include "Graphics/Vulkan/Graphics.h" +#endif #include "Graphics/StaticMeshVertexData.h" #include "Graphics/Vulkan/Graphics.h" -#include "Window/InspectorView.h" #include "Window/PlayView.h" -#include "Window/SceneView.h" #include "Window/WindowManager.h" #include @@ -21,6 +23,7 @@ using namespace Seele::Editor; static Gfx::OGraphics graphics; int main() { + std::string gameName = "MeshShadingDemo"; #ifdef WIN32 std::filesystem::path outputPath = "C:/Users/Dynamitos/MeshShadingDemoGame"; std::filesystem::path sourcePath = "C:/Users/Dynamitos/MeshShadingDemo"; @@ -34,7 +37,6 @@ int main() { std::filesystem::path sourcePath = "/home/dynamitos/MeshShadingDemo"; std::filesystem::path binaryPath = sourcePath / "cmake" / "libMeshShadingDemo.so"; #endif - std::string gameName = "MeshShadingDemo"; std::filesystem::path cmakePath = outputPath / "cmake"; #ifdef __APPLE__ @@ -52,178 +54,12 @@ int main() { AssetImporter::importFont(FontImportArgs{ .filePath = "./fonts/Calibri.ttf", }); - // AssetImporter::importMesh(MeshImportArgs{ - // .filePath = sourcePath / "old_resources/models/arena.fbx", - // }); - // AssetImporter::importMesh(MeshImportArgs{ - // .filePath = sourcePath / "old_resources/models/frog.fbx", - // }); - // AssetImporter::importMesh(MeshImportArgs{ - // .filePath = sourcePath / "old_resources/models/train.fbx", - // }); - // AssetImporter::importMesh(MeshImportArgs{ - // .filePath= sourcePath / "old_resources/models/bird.fbx", - // }); AssetImporter::importMesh(MeshImportArgs{ .filePath = sourcePath / "import/models/cube.fbx", }); - // AssetImporter::importMesh(MeshImportArgs{ - // .filePath= sourcePath / "old_resources/models/flameThrower.fbx", - // }); - // AssetImporter::importMesh(MeshImportArgs{ - // .filePath= sourcePath / "old_resources/models/player.fbx", - // }); - // AssetImporter::importMesh(MeshImportArgs{ - // .filePath= sourcePath / "old_resources/models/shotgun.fbx", - // }); - // AssetImporter::importMesh(MeshImportArgs{ - // .filePath= sourcePath / "old_resources/models/track.fbx", - // }); - // AssetImporter::importMesh(MeshImportArgs{ - // .filePath= sourcePath / "old_resources/models/zombie.fbx", - // }); - - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/Dirt.png", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/DirtGrass.png", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/Grass.png", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/Ice.png", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/Lava.png", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/Obsidian.png", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/Rocks.png", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/Sand.png", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/Water.png", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/Wood.png", - // }); - // - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level0/blendMap.png", - // .importPath = "level0", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level0/heightMap.png", - // .importPath = "level0", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level0/trackMap.png", - // .importPath = "level0", - // }); - // AssetImporter::importMaterial(MaterialImportArgs{ - // .filePath= sourcePath / "old_resources/shaders/TerrainMaterial.json", - // .importPath = "level0", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level1/blendMap.png", - // .importPath = "level1", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level1/heightMap.png", - // .importPath = "level1", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level1/trackMap.png", - // .importPath = "level1", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level2/blendMap.png", - // .importPath = "level2", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level2/heightMap.png", - // .importPath = "level2", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level2/trackMap.png", - // .importPath = "level2", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level3/blendMap.png", - // .importPath = "level3", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level3/heightMap.png", - // .importPath = "level3", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level3/trackMap.png", - // .importPath = "level3", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level4/blendMap.png", - // .importPath = "level4", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level4/heightMap.png", - // .importPath = "level4", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level4/trackMap.png", - // .importPath = "level4", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level5/blendMap.png", - // .importPath = "level5", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level5/heightMap.png", - // .importPath = "level5", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level5/trackMap.png", - // .importPath = "level5", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level6/blendMap.png", - // .importPath = "level6", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level6/heightMap.png", - // .importPath = "level6", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level6/trackMap.png", - // .importPath = "level6", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level7/blendMap.png", - // .importPath = "level7", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level7/heightMap.png", - // .importPath = "level7", - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/textures/level7/trackMap.png", - // .importPath = "level7", - // }); - // - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/skyboxes/FS000_Day_01.png", - // .type = TextureImportType::TEXTURE_CUBEMAP, - // }); - // AssetImporter::importTexture(TextureImportArgs{ - // .filePath= sourcePath / "old_resources/skyboxes/FS000_Night_01.png", - // .type = TextureImportType::TEXTURE_CUBEMAP, - // }); - + AssetImporter::importMesh(MeshImportArgs{ + .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.blend" + }); WindowCreateInfo mainWindowInfo; mainWindowInfo.title = "SeeleEngine"; mainWindowInfo.width = 1920; @@ -237,14 +73,6 @@ int main() { sceneViewInfo.dimensions.offset.y = 0; sceneViewInfo.numSamples = Gfx::SE_SAMPLE_COUNT_1_BIT; OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string()); - - // ViewportCreateInfo inspectorViewInfo; - // inspectorViewInfo.dimensions.size.x = 640; - // inspectorViewInfo.dimensions.size.y = 720; - // inspectorViewInfo.dimensions.offset.x = 640; - // inspectorViewInfo.dimensions.offset.y = 0; - // PInspectorView inspectorView = new InspectorView(graphics, window, inspectorViewInfo); - // window->addView(inspectorView); sceneView->setFocused(); while (windowManager->isActive()) { diff --git a/src/Engine/Asset/AssetRegistry.cpp b/src/Engine/Asset/AssetRegistry.cpp index ff9c906..5910283 100644 --- a/src/Engine/Asset/AssetRegistry.cpp +++ b/src/Engine/Asset/AssetRegistry.cpp @@ -323,15 +323,15 @@ void AssetRegistry::saveAsset(PAsset asset, uint64 identifier, const std::filesy std::string path = (folderPath / name).replace_extension("asset").string(); auto assetStream = createWriteStream(std::move(path), std::ios::binary); - ArchiveBuffer assetBuffer(graphics); + ArchiveBuffer buffer(graphics); // write identifier - Serialization::save(assetBuffer, identifier); + Serialization::save(buffer, identifier); // write name - Serialization::save(assetBuffer, name); + Serialization::save(buffer, name); // write folder - Serialization::save(assetBuffer, folderPath.string()); + Serialization::save(buffer, folderPath.string()); // write asset data - asset->save(assetBuffer); + asset->save(buffer); assetBuffer.writeToStream(assetStream); } diff --git a/src/Engine/Graphics/Descriptor.h b/src/Engine/Graphics/Descriptor.h index 61a356c..2ac0772 100644 --- a/src/Engine/Graphics/Descriptor.h +++ b/src/Engine/Graphics/Descriptor.h @@ -67,6 +67,7 @@ public: bool operator<(PDescriptorSet other); constexpr PDescriptorLayout getLayout() const { return layout; } + constexpr const std::string& getName() const { return layout->getName(); } protected: PDescriptorLayout layout; @@ -83,7 +84,7 @@ public: void addPushConstants(const SePushConstantRange& pushConstants); constexpr uint32 getHash() const { return layoutHash; } constexpr const Map& getLayouts() const { return descriptorSetLayouts; } - constexpr uint32 findParameter(const std::string& name) const { return parameterMapping[name]; } + constexpr uint32 findParameter(const std::string& param) const { return parameterMapping[param]; } void addMapping(Map mapping); constexpr std::string getName() const {return name;}; diff --git a/src/Engine/Graphics/Initializer.h b/src/Engine/Graphics/Initializer.h index fbf8601..5be5bef 100644 --- a/src/Engine/Graphics/Initializer.h +++ b/src/Engine/Graphics/Initializer.h @@ -118,9 +118,9 @@ struct ShaderBufferCreateInfo DECLARE_NAME_REF(Gfx, PipelineLayout) struct ShaderCreateInfo { + std::string name; // Debug info std::string mainModule; Array additionalModules; - std::string name; // Debug info std::string entryPoint; Array> typeParameter; Map defines; diff --git a/src/Engine/Graphics/RenderPass/DebugPass.cpp b/src/Engine/Graphics/RenderPass/DebugPass.cpp index 83d7ad2..f57f647 100644 --- a/src/Engine/Graphics/RenderPass/DebugPass.cpp +++ b/src/Engine/Graphics/RenderPass/DebugPass.cpp @@ -124,9 +124,9 @@ void DebugPass::createRenderPass() pipelineLayout->create(); ShaderCreateInfo createInfo = { + .name = "DebugVertex", .mainModule = "Debug", .additionalModules = { "Debug" }, - .name = "DebugVertex", .entryPoint = "vertexMain", }; vertexShader = graphics->createVertexShader(createInfo); diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index f264efc..2e7aea1 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -133,8 +133,8 @@ void LightCullingPass::publishOutputs() ShaderCreateInfo createInfo = { .name = "Culling", - .additionalModules = {"LightCulling"}, .mainModule = "LightCulling", + .additionalModules = {"LightCulling"}, .entryPoint = "cullLights", .rootSignature = cullingLayout, }; @@ -226,8 +226,8 @@ void LightCullingPass::setupFrustums() frustumLayout->create(); ShaderCreateInfo createInfo = { .name = "Frustum", - .additionalModules = {"ComputeFrustums"}, .mainModule = "ComputeFrustums", + .additionalModules = {"ComputeFrustums"}, .entryPoint = "computeFrustums", .rootSignature = frustumLayout, }; diff --git a/src/Engine/Graphics/RenderPass/SkyboxRenderPass.cpp b/src/Engine/Graphics/RenderPass/SkyboxRenderPass.cpp index b32a49b..61fe90b 100644 --- a/src/Engine/Graphics/RenderPass/SkyboxRenderPass.cpp +++ b/src/Engine/Graphics/RenderPass/SkyboxRenderPass.cpp @@ -111,9 +111,9 @@ void SkyboxRenderPass::createRenderPass() }); ShaderCreateInfo createInfo = { + .name = "SkyboxVertex", .mainModule = "Skybox", .additionalModules = {"Skybox"}, - .name = "SkyboxVertex", .entryPoint = "vertexMain", }; vertexShader = graphics->createVertexShader(createInfo); diff --git a/src/Engine/Graphics/RenderPass/UIPass.cpp b/src/Engine/Graphics/RenderPass/UIPass.cpp index ef69205..5e67ee9 100644 --- a/src/Engine/Graphics/RenderPass/UIPass.cpp +++ b/src/Engine/Graphics/RenderPass/UIPass.cpp @@ -139,7 +139,7 @@ void UIPass::createRenderPass() descriptorSet->updateSampler(1, backgroundSampler); descriptorSet->writeChanges(); - Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout(); + pipelineLayout = graphics->createPipelineLayout(); pipelineLayout->addDescriptorLayout(descriptorLayout); pipelineLayout->create(); @@ -153,7 +153,7 @@ void UIPass::createRenderPass() pipelineInfo.vertexShader = vertexShader; pipelineInfo.fragmentShader = fragmentShader; pipelineInfo.renderPass = renderPass; - pipelineInfo.pipelineLayout = std::move(pipelineLayout); + pipelineInfo.pipelineLayout = pipelineLayout; pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE; pipelineInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; diff --git a/src/Engine/Graphics/Vulkan/Buffer.cpp b/src/Engine/Graphics/Vulkan/Buffer.cpp index 343c30b..f94abb7 100644 --- a/src/Engine/Graphics/Vulkan/Buffer.cpp +++ b/src/Engine/Graphics/Vulkan/Buffer.cpp @@ -13,57 +13,23 @@ struct PendingBuffer { bool writeOnly; }; -static Map pendingBuffers; +static Map pendingBuffers; -Buffer::Buffer(PGraphics graphics, uint64 size, VkBufferUsageFlags usage, - Gfx::QueueType &queueType, bool dynamic, std::string name) - : graphics(graphics), currentBuffer(0), size(size), owner(queueType), - name(name) { +Buffer::Buffer(PGraphics graphics, uint64 size, VkBufferUsageFlags usage, Gfx::QueueType& queueType, bool dynamic, + std::string name) + : graphics(graphics), currentBuffer(0), size(size), owner(queueType), usage(usage), name(name) { if (dynamic) { numBuffers = Gfx::numFramesBuffered; } else { numBuffers = 1; } - VkBufferCreateInfo info = { - .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, - .pNext = nullptr, - .size = size, - .usage = usage, - .sharingMode = VK_SHARING_MODE_EXCLUSIVE, - }; - VmaAllocationCreateInfo allocInfo = { - .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT | - VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT, - .usage = VMA_MEMORY_USAGE_AUTO, - }; - for (uint32 i = 0; i < numBuffers; ++i) { - vmaCreateBuffer(graphics->getAllocator(), &info, &allocInfo, - &buffers[i].buffer, &buffers[i].allocation, - &buffers[i].info); - vmaGetAllocationMemoryProperties(graphics->getAllocator(), - buffers[i].allocation, - &buffers[i].properties); - // std::cout << "Create buffer " << std::hex << (uint64)buffers[i].buffer << - // std::dec; - if (!name.empty()) { - VkDebugUtilsObjectNameInfoEXT nameInfo = { - .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, - .pNext = nullptr, - .objectType = VK_OBJECT_TYPE_BUFFER, - .objectHandle = (uint64)buffers[i].buffer, - .pObjectName = this->name.c_str()}; - graphics->vkSetDebugUtilsObjectNameEXT(&nameInfo); - // std::cout << ": " << name; - } - // std::cout << std::endl; - } + createBuffer(); } Buffer::~Buffer() { for (uint32 i = 0; i < numBuffers; ++i) { - graphics->getDestructionManager()->queueBuffer( - graphics->getQueueCommands(owner)->getCommands(), buffers[i].buffer, - buffers[i].allocation); + graphics->getDestructionManager()->queueBuffer(graphics->getQueueCommands(owner)->getCommands(), buffers[i].buffer, + buffers[i].allocation); } } @@ -112,16 +78,12 @@ void Buffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { dynamicBarriers[i] = barrier; dynamicBarriers[i].buffer = buffers[i].buffer; } - vkCmdPipelineBarrier(srcCommand, srcStage, srcStage, 0, 0, nullptr, - numBuffers, dynamicBarriers, 0, nullptr); - vkCmdPipelineBarrier(dstCommand, dstStage, dstStage, 0, 0, nullptr, - numBuffers, dynamicBarriers, 0, nullptr); + vkCmdPipelineBarrier(srcCommand, srcStage, srcStage, 0, 0, nullptr, numBuffers, dynamicBarriers, 0, nullptr); + vkCmdPipelineBarrier(dstCommand, dstStage, dstStage, 0, 0, nullptr, numBuffers, dynamicBarriers, 0, nullptr); sourcePool->submitCommands(); } -void Buffer::executePipelineBarrier(VkAccessFlags srcAccess, - VkPipelineStageFlags srcStage, - VkAccessFlags dstAccess, +void Buffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) { PCommand commandBuffer = graphics->getQueueCommands(owner)->getCommands(); VkBufferMemoryBarrier barrier = { @@ -139,15 +101,15 @@ void Buffer::executePipelineBarrier(VkAccessFlags srcAccess, dynamicBarriers[i] = barrier; dynamicBarriers[i].buffer = buffers[i].buffer; } - vkCmdPipelineBarrier(commandBuffer->getHandle(), srcStage, dstStage, 0, 0, - nullptr, numBuffers, dynamicBarriers, 0, nullptr); + vkCmdPipelineBarrier(commandBuffer->getHandle(), srcStage, dstStage, 0, 0, nullptr, numBuffers, dynamicBarriers, 0, + nullptr); } -void *Buffer::map(bool writeOnly) { return mapRegion(0, size, writeOnly); } -void *Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, - bool writeOnly) { - void *data = nullptr; +void* Buffer::map(bool writeOnly) { return mapRegion(0, size, writeOnly); } + +void* Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly) { + void* data = nullptr; PendingBuffer pending; pending.writeOnly = writeOnly; @@ -155,10 +117,8 @@ void *Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, pending.offset = regionOffset; pending.size = regionSize; if (writeOnly) { - if (buffers[currentBuffer].properties & - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) { - VK_CHECK(vmaMapMemory(graphics->getAllocator(), - buffers[currentBuffer].allocation, &data)); + if (buffers[currentBuffer].properties & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) { + VK_CHECK(vmaMapMemory(graphics->getAllocator(), buffers[currentBuffer].allocation, &data)); } else { VkBufferCreateInfo stagingInfo = { .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, @@ -172,8 +132,7 @@ void *Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, .usage = VMA_MEMORY_USAGE_AUTO, .requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, }; - VK_CHECK(vmaCreateBuffer(graphics->getAllocator(), &stagingInfo, - &allocInfo, &pending.stagingBuffer, + VK_CHECK(vmaCreateBuffer(graphics->getAllocator(), &stagingInfo, &allocInfo, &pending.stagingBuffer, &pending.allocation, nullptr)); vmaMapMemory(graphics->getAllocator(), pending.allocation, &data); } @@ -189,15 +148,12 @@ void *Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, void Buffer::unmap() { auto found = pendingBuffers.find(this); if (found != pendingBuffers.end()) { - PendingBuffer &pending = found->value; + PendingBuffer& pending = found->value; if (pending.writeOnly) { - if (buffers[currentBuffer].properties & - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) { - vmaUnmapMemory(graphics->getAllocator(), - buffers[currentBuffer].allocation); + if (buffers[currentBuffer].properties & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) { + vmaUnmapMemory(graphics->getAllocator(), buffers[currentBuffer].allocation); } else { - vmaFlushAllocation(graphics->getAllocator(), pending.allocation, 0, - VK_WHOLE_SIZE); + vmaFlushAllocation(graphics->getAllocator(), pending.allocation, 0, VK_WHOLE_SIZE); vmaUnmapMemory(graphics->getAllocator(), pending.allocation); PCommand command = graphics->getQueueCommands(owner)->getCommands(); VkCommandBuffer cmdHandle = command->getHandle(); @@ -218,11 +174,9 @@ void Buffer::unmap() { .offset = 0, .size = size, }; - vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 1, - &barrier, 0, nullptr); - vkCmdCopyBuffer(cmdHandle, pending.stagingBuffer, - buffers[currentBuffer].buffer, 1, ®ion); + vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, + nullptr, 1, &barrier, 0, nullptr); + vkCmdCopyBuffer(cmdHandle, pending.stagingBuffer, buffers[currentBuffer].buffer, 1, ®ion); barrier = { .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, .pNext = nullptr, @@ -234,27 +188,49 @@ void Buffer::unmap() { .offset = 0, .size = size, }; - vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, - 1, &barrier, 0, nullptr); - graphics->getDestructionManager()->queueBuffer( - command, pending.stagingBuffer, pending.allocation); + vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, + nullptr, 1, &barrier, 0, nullptr); + graphics->getDestructionManager()->queueBuffer(command, pending.stagingBuffer, pending.allocation); } } - // requestOwnershipTransfer(pending.prevQueue); - pendingBuffers.erase(this); } } -UniformBuffer::UniformBuffer(PGraphics graphics, - const UniformBufferCreateInfo &createInfo) +void Buffer::createBuffer() +{ + VkBufferCreateInfo info = { + .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, + .pNext = nullptr, + .size = size, + .usage = usage, + .sharingMode = VK_SHARING_MODE_EXCLUSIVE, + }; + VmaAllocationCreateInfo allocInfo = { + .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT | + VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT, + .usage = VMA_MEMORY_USAGE_AUTO, + }; + buffers.add(); + vmaCreateBuffer(graphics->getAllocator(), &info, &allocInfo, &buffers.back().buffer, &buffers.back().allocation, + &buffers.back().info); + vmaGetAllocationMemoryProperties(graphics->getAllocator(), buffers.back().allocation, &buffers.back().properties); + if (!name.empty()) { + VkDebugUtilsObjectNameInfoEXT nameInfo = { .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, + .pNext = nullptr, + .objectType = VK_OBJECT_TYPE_BUFFER, + .objectHandle = (uint64)buffers.back().buffer, + .pObjectName = this->name.c_str() }; + graphics->vkSetDebugUtilsObjectNameEXT(&nameInfo); + } +} + +UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo) : Gfx::UniformBuffer(graphics->getFamilyMapping(), createInfo.sourceData), - Vulkan::Buffer(graphics, createInfo.sourceData.size, - VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, currentOwner, + Vulkan::Buffer(graphics, createInfo.sourceData.size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, currentOwner, createInfo.dynamic, createInfo.name) { if (createInfo.sourceData.data != nullptr) { - void *data = map(); + void* data = map(); std::memcpy(data, createInfo.sourceData.data, createInfo.sourceData.size); unmap(); } @@ -262,19 +238,17 @@ UniformBuffer::UniformBuffer(PGraphics graphics, UniformBuffer::~UniformBuffer() {} -bool UniformBuffer::updateContents(const DataSource &sourceData) { +bool UniformBuffer::updateContents(const DataSource& sourceData) { if (!Gfx::UniformBuffer::updateContents(sourceData)) { // no update was performed, skip return false; } - void *data = map(); + void* data = map(); std::memcpy(data, sourceData.data, sourceData.size); unmap(); return true; } -void UniformBuffer::beginFrame() { Vulkan::Buffer::advanceBuffer(); } - void UniformBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner) { Gfx::QueueOwnedResource::transferOwnership(newOwner); } @@ -283,31 +257,21 @@ void UniformBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Vulkan::Buffer::executeOwnershipBarrier(newOwner); } -void UniformBuffer::executePipelineBarrier(VkAccessFlags srcAccess, - VkPipelineStageFlags srcStage, - VkAccessFlags dstAccess, - VkPipelineStageFlags dstStage) { - Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, - dstStage); +void UniformBuffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, + VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) { + Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); } -VkAccessFlags UniformBuffer::getSourceAccessMask() { - return VK_ACCESS_MEMORY_WRITE_BIT; -} +VkAccessFlags UniformBuffer::getSourceAccessMask() { return VK_ACCESS_MEMORY_WRITE_BIT; } -VkAccessFlags UniformBuffer::getDestAccessMask() { - return VK_ACCESS_UNIFORM_READ_BIT; -} +VkAccessFlags UniformBuffer::getDestAccessMask() { return VK_ACCESS_UNIFORM_READ_BIT; } -ShaderBuffer::ShaderBuffer(PGraphics graphics, - const ShaderBufferCreateInfo &sourceData) - : Gfx::ShaderBuffer(graphics->getFamilyMapping(), sourceData.numElements, - sourceData.sourceData), - Vulkan::Buffer(graphics, sourceData.sourceData.size, - VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, currentOwner, +ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& sourceData) + : Gfx::ShaderBuffer(graphics->getFamilyMapping(), sourceData.numElements, sourceData.sourceData), + Vulkan::Buffer(graphics, sourceData.sourceData.size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, currentOwner, sourceData.dynamic, sourceData.name) { if (sourceData.sourceData.data != nullptr) { - void *data = map(); + void* data = map(); std::memcpy(data, sourceData.sourceData.data, sourceData.sourceData.size); unmap(); } @@ -315,18 +279,16 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, ShaderBuffer::~ShaderBuffer() {} -bool ShaderBuffer::updateContents(const DataSource &sourceData) { +bool ShaderBuffer::updateContents(const DataSource& sourceData) { assert(sourceData.size <= getSize()); Gfx::ShaderBuffer::updateContents(sourceData); // We always want to update, as the contents could be different on the GPU - void *data = map(); + void* data = map(); std::memcpy(data, sourceData.data, sourceData.size); unmap(); return true; } -void ShaderBuffer::beginFrame() { Vulkan::Buffer::advanceBuffer(); } - void ShaderBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner) { Gfx::QueueOwnedResource::transferOwnership(newOwner); } @@ -335,31 +297,22 @@ void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Vulkan::Buffer::executeOwnershipBarrier(newOwner); } -void ShaderBuffer::executePipelineBarrier(VkAccessFlags srcAccess, - VkPipelineStageFlags srcStage, - VkAccessFlags dstAccess, - VkPipelineStageFlags dstStage) { - Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, - dstStage); +void ShaderBuffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, + VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) { + Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); } -VkAccessFlags ShaderBuffer::getSourceAccessMask() { - return VK_ACCESS_MEMORY_WRITE_BIT; -} +VkAccessFlags ShaderBuffer::getSourceAccessMask() { return VK_ACCESS_MEMORY_WRITE_BIT; } -VkAccessFlags ShaderBuffer::getDestAccessMask() { - return VK_ACCESS_MEMORY_READ_BIT; -} +VkAccessFlags ShaderBuffer::getDestAccessMask() { return VK_ACCESS_MEMORY_READ_BIT; } -VertexBuffer::VertexBuffer(PGraphics graphics, - const VertexBufferCreateInfo &sourceData) - : Gfx::VertexBuffer(graphics->getFamilyMapping(), sourceData.numVertices, - sourceData.vertexSize, sourceData.sourceData.owner), - Vulkan::Buffer(graphics, sourceData.sourceData.size, - VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, currentOwner, false, +VertexBuffer::VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& sourceData) + : Gfx::VertexBuffer(graphics->getFamilyMapping(), sourceData.numVertices, sourceData.vertexSize, + sourceData.sourceData.owner), + Vulkan::Buffer(graphics, sourceData.sourceData.size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, currentOwner, false, sourceData.name) { if (sourceData.sourceData.data != nullptr) { - void *data = map(); + void* data = map(); std::memcpy(data, sourceData.sourceData.data, sourceData.sourceData.size); unmap(); } @@ -368,20 +321,18 @@ VertexBuffer::VertexBuffer(PGraphics graphics, VertexBuffer::~VertexBuffer() {} void VertexBuffer::updateRegion(DataSource update) { - void *data = mapRegion(update.offset, update.size); + void* data = mapRegion(update.offset, update.size); std::memcpy(data, update.data, update.size); unmap(); } -void VertexBuffer::download(Array &buffer) { - void *data = map(false); +void VertexBuffer::download(Array& buffer) { + void* data = map(false); buffer.resize(size); std::memcpy(buffer.data(), data, size); unmap(); } -void VertexBuffer::beginFrame() { Vulkan::Buffer::advanceBuffer(); } - void VertexBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner) { Gfx::QueueOwnedResource::transferOwnership(newOwner); } @@ -390,31 +341,22 @@ void VertexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Vulkan::Buffer::executeOwnershipBarrier(newOwner); } -void VertexBuffer::executePipelineBarrier(VkAccessFlags srcAccess, - VkPipelineStageFlags srcStage, - VkAccessFlags dstAccess, - VkPipelineStageFlags dstStage) { - Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, - dstStage); +void VertexBuffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, + VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) { + Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); } -VkAccessFlags VertexBuffer::getSourceAccessMask() { - return VK_ACCESS_MEMORY_WRITE_BIT; -} +VkAccessFlags VertexBuffer::getSourceAccessMask() { return VK_ACCESS_MEMORY_WRITE_BIT; } -VkAccessFlags VertexBuffer::getDestAccessMask() { - return VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT; -} +VkAccessFlags VertexBuffer::getDestAccessMask() { return VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT; } -IndexBuffer::IndexBuffer(PGraphics graphics, - const IndexBufferCreateInfo &sourceData) - : Gfx::IndexBuffer(graphics->getFamilyMapping(), sourceData.sourceData.size, - sourceData.indexType, sourceData.sourceData.owner), - Vulkan::Buffer(graphics, sourceData.sourceData.size, - VK_BUFFER_USAGE_INDEX_BUFFER_BIT, currentOwner, false, +IndexBuffer::IndexBuffer(PGraphics graphics, const IndexBufferCreateInfo& sourceData) + : Gfx::IndexBuffer(graphics->getFamilyMapping(), sourceData.sourceData.size, sourceData.indexType, + sourceData.sourceData.owner), + Vulkan::Buffer(graphics, sourceData.sourceData.size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, currentOwner, false, sourceData.name) { if (sourceData.sourceData.data != nullptr) { - void *data = map(); + void* data = map(); std::memcpy(data, sourceData.sourceData.data, sourceData.sourceData.size); unmap(); } @@ -422,15 +364,13 @@ IndexBuffer::IndexBuffer(PGraphics graphics, IndexBuffer::~IndexBuffer() {} -void IndexBuffer::download(Array &buffer) { - void *data = map(false); +void IndexBuffer::download(Array& buffer) { + void* data = map(false); buffer.resize(size); std::memcpy(buffer.data(), data, size); unmap(); } -void IndexBuffer::beginFrame() { Vulkan::Buffer::advanceBuffer(); } - void IndexBuffer::requestOwnershipTransfer(Gfx::QueueType newOwner) { Gfx::QueueOwnedResource::transferOwnership(newOwner); } @@ -439,18 +379,11 @@ void IndexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Vulkan::Buffer::executeOwnershipBarrier(newOwner); } -void IndexBuffer::executePipelineBarrier(VkAccessFlags srcAccess, - VkPipelineStageFlags srcStage, - VkAccessFlags dstAccess, - VkPipelineStageFlags dstStage) { - Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, - dstStage); +void IndexBuffer::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage, + VkAccessFlags dstAccess, VkPipelineStageFlags dstStage) { + Vulkan::Buffer::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage); } -VkAccessFlags IndexBuffer::getSourceAccessMask() { - return VK_ACCESS_MEMORY_WRITE_BIT; -} +VkAccessFlags IndexBuffer::getSourceAccessMask() { return VK_ACCESS_MEMORY_WRITE_BIT; } -VkAccessFlags IndexBuffer::getDestAccessMask() { - return VK_ACCESS_INDEX_READ_BIT; -} \ No newline at end of file +VkAccessFlags IndexBuffer::getDestAccessMask() { return VK_ACCESS_INDEX_READ_BIT; } \ No newline at end of file diff --git a/src/Engine/Graphics/Vulkan/Buffer.h b/src/Engine/Graphics/Vulkan/Buffer.h index bede959..eb202aa 100644 --- a/src/Engine/Graphics/Vulkan/Buffer.h +++ b/src/Engine/Graphics/Vulkan/Buffer.h @@ -4,6 +4,8 @@ namespace Seele { namespace Vulkan { +DECLARE_REF(Command) +DECLARE_REF(Fence) class Buffer { public: Buffer(PGraphics graphics, uint64 size, VkBufferUsageFlags usage, @@ -28,8 +30,10 @@ protected: uint64 size; Gfx::QueueType &owner; Array buffers; + VkBufferUsageFlags usage; uint32 numBuffers; std::string name; + void createBuffer(); void executeOwnershipBarrier(Gfx::QueueType newOwner); void executePipelineBarrier(VkAccessFlags srcAccess, diff --git a/src/Engine/Graphics/Vulkan/Command.cpp b/src/Engine/Graphics/Vulkan/Command.cpp index 0eea9d9..50f921d 100644 --- a/src/Engine/Graphics/Vulkan/Command.cpp +++ b/src/Engine/Graphics/Vulkan/Command.cpp @@ -279,7 +279,7 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) descriptor->bind(); VkDescriptorSet setHandle = descriptor->getHandle(); - vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr); + vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle, 0, nullptr); } void RenderCommand::bindDescriptor(const Array& descriptorSets) { @@ -292,7 +292,7 @@ void RenderCommand::bindDescriptor(const Array& descriptorS descriptorSet->bind(); boundDescriptors.add(descriptorSet.getHandle()); - sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle(); + sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle(); } vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, 0, nullptr); delete[] sets; @@ -416,7 +416,7 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) descriptor->bind(); VkDescriptorSet setHandle = descriptor->getHandle(); - vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr); + vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle, 0, nullptr); } void ComputeCommand::bindDescriptor(const Array& descriptorSets) @@ -431,7 +431,7 @@ void ComputeCommand::bindDescriptor(const Array& descriptor //std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl; boundDescriptors.add(descriptorSet.getHandle()); - sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle(); + sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle(); } vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, 0, nullptr); delete[] sets; @@ -469,9 +469,9 @@ CommandPool::CommandPool(PGraphics graphics, PQueue queue) CommandPool::~CommandPool() { vkDeviceWaitIdle(graphics->getDevice()); - for (auto& command : allocatedBuffers) + for (auto& cmd : allocatedBuffers) { - command->checkFence(); + cmd->checkFence(); } allocatedRenderCommands.clear(); allocatedComputeCommands.clear(); @@ -487,17 +487,17 @@ PCommand CommandPool::getCommands() } void CommandPool::cacheCommands(Array commands) { - for(auto&& command : commands) + for(auto&& cmd : commands) { - allocatedRenderCommands.add(std::move(command)); + allocatedRenderCommands.add(std::move(cmd)); } } void CommandPool::cacheCommands(Array commands) { - for(auto&& command : commands) + for(auto&& cmd : commands) { - allocatedComputeCommands.add(std::move(command)); + allocatedComputeCommands.add(std::move(cmd)); } } diff --git a/src/Engine/Graphics/Vulkan/Command.h b/src/Engine/Graphics/Vulkan/Command.h index 32c51fd..3c9637d 100644 --- a/src/Engine/Graphics/Vulkan/Command.h +++ b/src/Engine/Graphics/Vulkan/Command.h @@ -73,18 +73,13 @@ public: virtual void setViewport(Gfx::PViewport viewport) override; virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override; virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override; - virtual void - bindDescriptor(const Array &descriptorSets) override; - virtual void - bindVertexBuffer(const Array &buffers) override; + virtual void bindDescriptor(const Array& descriptorSets) override; + virtual void bindVertexBuffer(const Array& buffers) override; virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override; - virtual void pushConstants(Gfx::PPipelineLayout layout, - Gfx::SeShaderStageFlags stage, uint32 offset, - uint32 size, const void *data) override; - virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, - uint32 firstInstance) override; - virtual void drawIndexed(uint32 indexCount, uint32 instanceCount, - int32 firstIndex, uint32 vertexOffset, + virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, + const void* data) override; + virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override; + virtual void drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset, uint32 firstInstance) override; virtual void drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) override; @@ -113,12 +108,10 @@ public: bool isReady(); virtual void bindPipeline(Gfx::PComputePipeline pipeline) override; virtual void bindDescriptor(Gfx::PDescriptorSet set) override; - virtual void bindDescriptor(const Array &sets) override; - virtual void pushConstants(Gfx::PPipelineLayout layout, - Gfx::SeShaderStageFlags stage, uint32 offset, - uint32 size, const void *data) override; - virtual void dispatch(uint32 threadX, uint32 threadY, - uint32 threadZ) override; + virtual void bindDescriptor(const Array& sets) override; + virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, + const void* data) override; + virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override; private: PComputePipeline pipeline; @@ -141,8 +134,8 @@ public: PCommand getCommands(); void cacheCommands(Array commands); void cacheCommands(Array commands); - ORenderCommand createRenderCommand(const std::string &name); - OComputeCommand createComputeCommand(const std::string &name); + ORenderCommand createRenderCommand(const std::string& name); + OComputeCommand createComputeCommand(const std::string& name); constexpr VkCommandPool getHandle() const { return commandPool; } void submitCommands(PSemaphore signalSemaphore = nullptr); diff --git a/src/Engine/Graphics/Vulkan/Descriptor.cpp b/src/Engine/Graphics/Vulkan/Descriptor.cpp index 9d07f85..abd97a9 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.cpp +++ b/src/Engine/Graphics/Vulkan/Descriptor.cpp @@ -161,6 +161,7 @@ void DescriptorPool::reset() { DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) : Gfx::DescriptorSet(owner->getLayout()), setHandle(VK_NULL_HANDLE), graphics(graphics), owner(owner), bindCount(0), currentlyInUse(false) {} + DescriptorSet::~DescriptorSet() {} void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) { @@ -315,8 +316,8 @@ void DescriptorSet::writeChanges() { } } -PipelineLayout::PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout) - : Gfx::PipelineLayout(baseLayout), graphics(graphics), layoutHandle(VK_NULL_HANDLE) {} +PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout) + : Gfx::PipelineLayout(name, baseLayout), graphics(graphics), layoutHandle(VK_NULL_HANDLE) {} PipelineLayout::~PipelineLayout() {} @@ -324,15 +325,10 @@ Map cachedLayouts; void PipelineLayout::create() { vulkanDescriptorLayouts.resize(descriptorSetLayouts.size()); - for (size_t i = 0; i < descriptorSetLayouts.size(); ++i) { - // There could be unused descriptor set indices - if (descriptorSetLayouts[i] == nullptr) { - vulkanDescriptorLayouts[i] = VK_NULL_HANDLE; - continue; - } - PDescriptorLayout layout = descriptorSetLayouts[i].cast(); + for (auto [name, desc] : descriptorSetLayouts) { + PDescriptorLayout layout = desc.cast(); layout->create(); - vulkanDescriptorLayouts[i] = layout->getHandle(); + vulkanDescriptorLayouts[parameterMapping[layout->getName()]] = layout->getHandle(); } Array vkPushConstants(pushConstants.size()); diff --git a/src/Engine/Graphics/Vulkan/Descriptor.h b/src/Engine/Graphics/Vulkan/Descriptor.h index cdad028..8835709 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.h +++ b/src/Engine/Graphics/Vulkan/Descriptor.h @@ -84,7 +84,7 @@ DEFINE_REF(DescriptorSet) class PipelineLayout : public Gfx::PipelineLayout { public: - PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout); + PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout); virtual ~PipelineLayout(); virtual void create(); constexpr VkPipelineLayout getHandle() const { return layoutHandle; } diff --git a/src/Engine/Graphics/Vulkan/Enums.cpp b/src/Engine/Graphics/Vulkan/Enums.cpp index 40d9a6a..383a058 100644 --- a/src/Engine/Graphics/Vulkan/Enums.cpp +++ b/src/Engine/Graphics/Vulkan/Enums.cpp @@ -102,24 +102,6 @@ VkShaderStageFlagBits Seele::Vulkan::cast(const Seele::Gfx::SeShaderStageFlagBit return VK_SHADER_STAGE_ALL_GRAPHICS; case SE_SHADER_STAGE_ALL: return VK_SHADER_STAGE_ALL; -#ifdef USE_EXTENSIONS - case SE_SHADER_STAGE_RAYGEN_BIT_NV: - return VK_SHADER_STAGE_RAYGEN_BIT_NV; - case SE_SHADER_STAGE_ANY_HIT_BIT_NV: - return VK_SHADER_STAGE_ANY_HIT_BIT_NV; - case SE_SHADER_STAGE_CLOSEST_HIT_BIT_NV: - return VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV; - case SE_SHADER_STAGE_MISS_BIT_NV: - return VK_SHADER_STAGE_MISS_BIT_NV; - case SE_SHADER_STAGE_INTERSECTION_BIT_NV: - return VK_SHADER_STAGE_INTERSECTION_BIT_NV; - case SE_SHADER_STAGE_CALLABLE_BIT_NV: - return VK_SHADER_STAGE_CALLABLE_BIT_NV; - case SE_SHADER_STAGE_TASK_BIT_NV: - return VK_SHADER_STAGE_TASK_BIT_NV; - case SE_SHADER_STAGE_MESH_BIT_NV: - return VK_SHADER_STAGE_MESH_BIT_NV; -#endif default: throw std::logic_error("Not implemented"); } @@ -145,24 +127,6 @@ Seele::Gfx::SeShaderStageFlagBits Seele::Vulkan::cast(const VkShaderStageFlagBit return SE_SHADER_STAGE_ALL_GRAPHICS; case VK_SHADER_STAGE_ALL: return SE_SHADER_STAGE_ALL; -#ifdef USE_EXTENSIONS - case VK_SHADER_STAGE_RAYGEN_BIT_NV: - return SE_SHADER_STAGE_RAYGEN_BIT_NV; - case VK_SHADER_STAGE_ANY_HIT_BIT_NV: - return SE_SHADER_STAGE_ANY_HIT_BIT_NV; - case VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV: - return SE_SHADER_STAGE_CLOSEST_HIT_BIT_NV; - case VK_SHADER_STAGE_MISS_BIT_NV: - return SE_SHADER_STAGE_MISS_BIT_NV; - case VK_SHADER_STAGE_INTERSECTION_BIT_NV: - return SE_SHADER_STAGE_INTERSECTION_BIT_NV; - case VK_SHADER_STAGE_CALLABLE_BIT_NV: - return SE_SHADER_STAGE_CALLABLE_BIT_NV; - case VK_SHADER_STAGE_TASK_BIT_NV: - return SE_SHADER_STAGE_TASK_BIT_NV; - case VK_SHADER_STAGE_MESH_BIT_NV: - return SE_SHADER_STAGE_MESH_BIT_NV; -#endif default: throw std::logic_error("Not implemented"); } diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index 3997d9b..41f2830 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -247,9 +247,9 @@ Gfx::ODescriptorLayout Graphics::createDescriptorLayout(const std::string& name) return new DescriptorLayout(this, name); } -Gfx::OPipelineLayout Graphics::createPipelineLayout(Gfx::PPipelineLayout baseLayout) +Gfx::OPipelineLayout Graphics::createPipelineLayout(const std::string& name, Gfx::PPipelineLayout baseLayout) { - return new PipelineLayout(this, baseLayout); + return new PipelineLayout(this, name, baseLayout); } Gfx::OVertexInput Graphics::createVertexInput(VertexInputStateCreateInfo createInfo) diff --git a/src/Engine/Graphics/Vulkan/Pipeline.cpp b/src/Engine/Graphics/Vulkan/Pipeline.cpp index 59404d8..1c079a7 100644 --- a/src/Engine/Graphics/Vulkan/Pipeline.cpp +++ b/src/Engine/Graphics/Vulkan/Pipeline.cpp @@ -14,7 +14,7 @@ VertexInput::~VertexInput() { } -GraphicsPipeline::GraphicsPipeline(PGraphics graphics, VkPipeline handle, Gfx::OPipelineLayout pipelineLayout) +GraphicsPipeline::GraphicsPipeline(PGraphics graphics, VkPipeline handle, Gfx::PPipelineLayout pipelineLayout) : Gfx::GraphicsPipeline(std::move(pipelineLayout)) , graphics(graphics) , pipeline(handle) @@ -35,7 +35,7 @@ VkPipelineLayout GraphicsPipeline::getLayout() const return Gfx::PPipelineLayout(layout).cast()->getHandle(); } -ComputePipeline::ComputePipeline(PGraphics graphics, VkPipeline handle, Gfx::OPipelineLayout pipelineLayout) +ComputePipeline::ComputePipeline(PGraphics graphics, VkPipeline handle, Gfx::PPipelineLayout pipelineLayout) : Gfx::ComputePipeline(std::move(pipelineLayout)) , graphics(graphics) , pipeline(handle) diff --git a/src/Engine/Graphics/Vulkan/Pipeline.h b/src/Engine/Graphics/Vulkan/Pipeline.h index d459ad7..8cc07f7 100644 --- a/src/Engine/Graphics/Vulkan/Pipeline.h +++ b/src/Engine/Graphics/Vulkan/Pipeline.h @@ -18,7 +18,7 @@ DECLARE_REF(Graphics) class GraphicsPipeline : public Gfx::GraphicsPipeline { public: - GraphicsPipeline(PGraphics graphics, VkPipeline handle, Gfx::OPipelineLayout pipelineLayout); + GraphicsPipeline(PGraphics graphics, VkPipeline handle, Gfx::PPipelineLayout pipelineLayout); virtual ~GraphicsPipeline(); void bind(VkCommandBuffer handle); VkPipelineLayout getLayout() const; @@ -30,7 +30,7 @@ DEFINE_REF(GraphicsPipeline) class ComputePipeline : public Gfx::ComputePipeline { public: - ComputePipeline(PGraphics graphics, VkPipeline handle, Gfx::OPipelineLayout pipelineLayout); + ComputePipeline(PGraphics graphics, VkPipeline handle, Gfx::PPipelineLayout pipelineLayout); virtual ~ComputePipeline(); void bind(VkCommandBuffer handle); VkPipelineLayout getLayout() const; diff --git a/src/Engine/Graphics/Vulkan/PipelineCache.cpp b/src/Engine/Graphics/Vulkan/PipelineCache.cpp index 96dc90d..9915f1b 100644 --- a/src/Engine/Graphics/Vulkan/PipelineCache.cpp +++ b/src/Engine/Graphics/Vulkan/PipelineCache.cpp @@ -252,7 +252,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf int64 delta = std::chrono::duration_cast(endTime - beginTime).count(); std::cout << "Gfx creation time: " << delta << std::endl; - OGraphicsPipeline pipeline = new GraphicsPipeline(graphics, pipelineHandle, std::move(gfxInfo.pipelineLayout)); + OGraphicsPipeline pipeline = new GraphicsPipeline(graphics, pipelineHandle, gfxInfo.pipelineLayout); PGraphicsPipeline result = pipeline; graphicsPipelines[hash] = std::move(pipeline); return result; @@ -423,7 +423,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI int64 delta = std::chrono::duration_cast(endTime - beginTime).count(); std::cout << "Gfx creation time: " << delta << std::endl; - OGraphicsPipeline pipeline = new GraphicsPipeline(graphics, pipelineHandle, std::move(gfxInfo.pipelineLayout)); + OGraphicsPipeline pipeline = new GraphicsPipeline(graphics, pipelineHandle, gfxInfo.pipelineLayout); PGraphicsPipeline result = pipeline; graphicsPipelines[hash] = std::move(pipeline); return result; @@ -462,7 +462,7 @@ PComputePipeline PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo co int64 delta = std::chrono::duration_cast(endTime - beginTime).count(); std::cout << "Compute creation time: " << delta << std::endl; - OComputePipeline pipeline = new ComputePipeline(graphics, pipelineHandle, std::move(computeInfo.pipelineLayout)); + OComputePipeline pipeline = new ComputePipeline(graphics, pipelineHandle, computeInfo.pipelineLayout); PComputePipeline result = pipeline; graphicsPipelines[hash] = std::move(pipeline); return result; diff --git a/src/Engine/Graphics/Vulkan/Shader.cpp b/src/Engine/Graphics/Vulkan/Shader.cpp index 8123e69..031f763 100644 --- a/src/Engine/Graphics/Vulkan/Shader.cpp +++ b/src/Engine/Graphics/Vulkan/Shader.cpp @@ -30,7 +30,9 @@ uint32 Seele::Vulkan::Shader::getShaderHash() const void Shader::create(const ShaderCreateInfo& createInfo) { - Slang::ComPtr kernelBlob = generateShader(createInfo, SLANG_SPIRV); + Map paramMapping; + Slang::ComPtr kernelBlob = generateShader(createInfo, SLANG_SPIRV, paramMapping); + const_cast(createInfo.rootSignature.getHandle())->addMapping(paramMapping); VkShaderModuleCreateInfo moduleInfo = { .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, diff --git a/src/Engine/Graphics/Vulkan/Window.cpp b/src/Engine/Graphics/Vulkan/Window.cpp index 0cf001e..a8b7550 100644 --- a/src/Engine/Graphics/Vulkan/Window.cpp +++ b/src/Engine/Graphics/Vulkan/Window.cpp @@ -143,6 +143,7 @@ void Window::endFrame() VK_CHECK(r); } currentSemaphoreIndex = (currentSemaphoreIndex + 1) % Gfx::numFramesBuffered; + graphics->waitDeviceIdle(); } void Window::onWindowCloseEvent() diff --git a/src/Engine/Graphics/slang-compile.cpp b/src/Engine/Graphics/slang-compile.cpp index 726724e..8fadd44 100644 --- a/src/Engine/Graphics/slang-compile.cpp +++ b/src/Engine/Graphics/slang-compile.cpp @@ -1,5 +1,4 @@ #include "slang-compile.h" -#include #include #include "Containers/Array.h" #include diff --git a/vcpkg.json b/vcpkg.json index a84c309..d023adf 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -12,7 +12,6 @@ "fmt", "gtest", "vulkan-memory-allocator", - "shader-slang", - "glslang" + "shader-slang" ] } \ No newline at end of file