From 541b12aa5d13425a45c907a8ea9f30e6445df88f Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Wed, 24 Apr 2024 23:25:34 +0200 Subject: [PATCH] Fixing some import problems --- CMakeLists.txt | 1 + CMakeSettings.json | 2 +- external/vcpkg | 2 +- res/shaders/BasePass.slang | 2 +- res/shaders/MeshletBasePass.slang | 2 +- res/shaders/lib/Common.slang | 1 + res/shaders/lib/LightEnv.slang | 1 + res/shaders/lib/Material.slang | 2 +- res/shaders/lib/Scene.slang | 6 +-- res/shaders/lib/VertexData.slang | 2 +- src/Editor/Asset/MeshLoader.cpp | 56 ++++++++++++----------- src/Editor/Asset/MeshLoader.h | 1 - src/Editor/main.cpp | 2 +- src/Engine/Graphics/Enums.h | 4 +- src/Engine/Graphics/Meshlet.cpp | 15 +++--- src/Engine/Graphics/VertexData.cpp | 14 ++---- src/Engine/Graphics/VertexData.h | 2 +- src/Engine/Graphics/Vulkan/Descriptor.cpp | 2 +- src/Engine/Graphics/Vulkan/Graphics.cpp | 2 +- src/Engine/Graphics/slang-compile.cpp | 25 +++++----- 20 files changed, 75 insertions(+), 69 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 679b47f..b259f1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_CURRENT_SOURCE_DIR}/bu 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_RELWITHDEBINFO ${CMAKE_CURRENT_SOURCE_DIR}/build) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_CURRENT_SOURCE_DIR}/build) find_package(Vulkan REQUIRED) diff --git a/CMakeSettings.json b/CMakeSettings.json index 61aeeec..a3c993f 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -28,7 +28,7 @@ "name": "RelWithDebInfo", "generator": "Visual Studio 17 2022 Win64", "configurationType": "RelWithDebInfo", - "buildRoot": "C:/Users/Dynamitos/Seele/build/", + "buildRoot": "${CMAKE_CURRENT_SOURCE_DIR}/cmake", "installRoot": "C:/Program Files/Seele", "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", "buildCommandArgs": "", diff --git a/external/vcpkg b/external/vcpkg index 042c31e..4002e5f 160000 --- a/external/vcpkg +++ b/external/vcpkg @@ -1 +1 @@ -Subproject commit 042c31edc695ab91f6cf43f58f964baf33d53137 +Subproject commit 4002e5f3598cc0d216c395bc0db3de44a2d2ec9b diff --git a/res/shaders/BasePass.slang b/res/shaders/BasePass.slang index 2c73c22..53e6b65 100644 --- a/res/shaders/BasePass.slang +++ b/res/shaders/BasePass.slang @@ -31,5 +31,5 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target //uint lightIndex = pLightCullingData.lightIndexList[startOffset + i]; result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf); } - return float4(1.0f, 0.1f, 0.5f, 1.0f); + return float4(result, 1.0f); } diff --git a/res/shaders/MeshletBasePass.slang b/res/shaders/MeshletBasePass.slang index d709e3a..87bfe89 100644 --- a/res/shaders/MeshletBasePass.slang +++ b/res/shaders/MeshletBasePass.slang @@ -47,7 +47,7 @@ void taskMain( { uint m = mesh.meshletOffset + i; MeshletDescription meshlet = pScene.meshletInfos[m]; - if(meshlet.bounding.insideFrustum(localToView, viewFrustum)) + //if(meshlet.bounding.insideFrustum(localToView, viewFrustum)) { uint index; InterlockedAdd(head, 1, index); diff --git a/res/shaders/lib/Common.slang b/res/shaders/lib/Common.slang index 4ff4d90..82c26c9 100644 --- a/res/shaders/lib/Common.slang +++ b/res/shaders/lib/Common.slang @@ -10,6 +10,7 @@ struct ViewParameter float4 cameraPos_WS; float2 screenDimensions; } +layout(set=0) ParameterBlock pViewParams; float4 clipToView(float4 clip) diff --git a/res/shaders/lib/LightEnv.slang b/res/shaders/lib/LightEnv.slang index 23509fb..608ef05 100644 --- a/res/shaders/lib/LightEnv.slang +++ b/res/shaders/lib/LightEnv.slang @@ -63,4 +63,5 @@ struct LightEnv StructuredBuffer pointLights; uint numPointLights; }; +layout(set=3) ParameterBlock pLightEnv; diff --git a/res/shaders/lib/Material.slang b/res/shaders/lib/Material.slang index da0c53c..1946341 100644 --- a/res/shaders/lib/Material.slang +++ b/res/shaders/lib/Material.slang @@ -7,5 +7,5 @@ interface IMaterial associatedtype BRDF : IBRDF; BRDF prepare(MaterialParameter input); }; - +layout(set=4) ParameterBlock pMaterial; diff --git a/res/shaders/lib/Scene.slang b/res/shaders/lib/Scene.slang index ee09564..e0718cf 100644 --- a/res/shaders/lib/Scene.slang +++ b/res/shaders/lib/Scene.slang @@ -22,8 +22,8 @@ struct MeshData uint32_t pad0[3]; }; -static const uint MAX_VERTICES = 64; -static const uint MAX_PRIMITIVES = 126; +static const uint MAX_VERTICES = 256; +static const uint MAX_PRIMITIVES = 256; static const uint TASK_GROUP_SIZE = 128; static const uint MESH_GROUP_SIZE = 32; static const uint MAX_MESHLETS_PER_MESH = 512; @@ -41,6 +41,6 @@ struct Scene StructuredBuffer primitiveIndices; StructuredBuffer vertexIndices; }; -layout(set=1) +layout(set=2) ParameterBlock pScene; diff --git a/res/shaders/lib/VertexData.slang b/res/shaders/lib/VertexData.slang index 5592b8b..0d41e67 100644 --- a/res/shaders/lib/VertexData.slang +++ b/res/shaders/lib/VertexData.slang @@ -11,5 +11,5 @@ interface IVertexData VertexAttributes getAttributes(uint index); }; -layout(set=2) +layout(set=1) ParameterBlock pVertexData; \ No newline at end of file diff --git a/src/Editor/Asset/MeshLoader.cpp b/src/Editor/Asset/MeshLoader.cpp index f27a082..7d76325 100644 --- a/src/Editor/Asset/MeshLoader.cpp +++ b/src/Editor/Asset/MeshLoader.cpp @@ -78,7 +78,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName matCode["params"]["diffuseTexture"] = { {"type", "Texture2D"}, - {"default", texFilename.string()} + {"default", fmt::format("{0}/{1}", importPath, texFilename.string())} }; matCode["params"]["diffuseSampler"] = { @@ -123,7 +123,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName matCode["params"]["normalTexture"] = { {"type", "Texture2D"}, - {"default", texFilename.string()} + {"default", fmt::format("{0}/{1}", importPath, texFilename.string())} }; matCode["params"]["normalSampler"] = { @@ -326,25 +326,28 @@ void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path& aiTexture* tex = scene->mTextures[i]; auto texPath = std::filesystem::path(tex->mFilename.C_Str()); auto texPngPath = meshDirectory; - texPngPath.append(texPath.filename().string()); - if(tex->mHeight == 0) + texPngPath.append(fmt::format("{0}.{1}", texPath.filename().string(), tex->achFormatHint)); + if (!std::filesystem::exists(texPngPath)) { - // already compressed, just dump it to the disk - std::ofstream file(texPngPath, std::ios::binary); - file.write((const char*)tex->pcData, tex->mWidth); - file.flush(); - } - else - { - // recompress data so that the TextureLoader can read it - unsigned char* texData = new unsigned char[tex->mWidth * tex->mHeight * 4]; - convertAssimpARGB(texData, tex->pcData, tex->mWidth * tex->mHeight); - stbi_write_png(texPngPath.string().c_str(), tex->mWidth, tex->mHeight, 4, tex->pcData, tex->mWidth * 32); - delete[] texData; + if (tex->mHeight == 0) + { + // already compressed, just dump it to the disk + std::ofstream file(texPngPath, std::ios::binary); + file.write((const char*)tex->pcData, tex->mWidth); + file.flush(); + } + else + { + // recompress data so that the TextureLoader can read it + unsigned char* texData = new unsigned char[tex->mWidth * tex->mHeight * 4]; + convertAssimpARGB(texData, tex->pcData, tex->mWidth * tex->mHeight); + stbi_write_png(texPngPath.string().c_str(), tex->mWidth, tex->mHeight, 4, tex->pcData, tex->mWidth * 32); + delete[] texData; + } } std::cout << "Loading model texture " << texPngPath.string() << std::endl; AssetImporter::importTexture(TextureImportArgs { - .filePath = texPath, + .filePath = texPngPath, .importPath = importPath, }); } @@ -353,21 +356,21 @@ void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path& Matrix4 convertMatrix(aiMatrix4x4 matrix) { return Matrix4( - matrix.a1, matrix.a2, matrix.a3, matrix.a4, - matrix.b1, matrix.b2, matrix.b3, matrix.b4, - matrix.c1, matrix.c2, matrix.c3, matrix.c4, - matrix.d1, matrix.d2, matrix.d3, matrix.d4 + matrix.a1, matrix.b1, matrix.c1, matrix.d1, + matrix.a2, matrix.b2, matrix.c2, matrix.d2, + matrix.a3, matrix.b3, matrix.c3, matrix.d3, + matrix.a4, matrix.b4, matrix.c4, matrix.d4 ); } -Matrix4 MeshLoader::loadNodeTransform(aiNode* node) +aiMatrix4x4 loadNodeTransform(aiNode* node) { - Matrix4 parent = Matrix4(1); + aiMatrix4x4 parent = aiMatrix4x4(); if (node->mParent != nullptr) { parent = loadNodeTransform(node->mParent); } - return parent * convertMatrix(node->mTransformation); + return node->mTransformation * parent; } void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset) @@ -382,10 +385,11 @@ void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset) aiProcess_SortByPType | aiProcess_GenBoundingBoxes | aiProcess_GenSmoothNormals | + aiProcess_ImproveCacheLocality | aiProcess_GenUVCoords | - aiProcess_SortByPType | aiProcess_FindDegenerates)); const aiScene *scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace); + std::cout << importer.GetErrorString() << std::endl; Array globalMaterials(scene->mNumMaterials); loadTextures(scene, args.filePath.parent_path(), args.importPath); @@ -408,7 +412,7 @@ void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset) continue; } meshes.add(std::move(globalMeshes[meshNode->mMeshes[i]])); - meshes.back()->transform = loadNodeTransform(meshNode); + meshes.back()->transform = convertMatrix(loadNodeTransform(meshNode)); } } meshAsset->meshes = std::move(meshes); diff --git a/src/Editor/Asset/MeshLoader.h b/src/Editor/Asset/MeshLoader.h index 11a24a1..efbfaa0 100644 --- a/src/Editor/Asset/MeshLoader.h +++ b/src/Editor/Asset/MeshLoader.h @@ -30,7 +30,6 @@ private: void loadGlobalMeshes(const aiScene* scene, const Array& materials, Array& globalMeshes, Component::Collider& collider); void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels); - Matrix4 loadNodeTransform(aiNode* node); void import(MeshImportArgs args, PMeshAsset meshAsset); Gfx::PGraphics graphics; }; diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index b0db6e2..c3d7407 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -58,7 +58,7 @@ int main() { .filePath = sourcePath / "import/models/cube.fbx", }); AssetImporter::importMesh(MeshImportArgs{ - .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.blend", + .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.obj", .importPath = "Whitechapel" }); WindowCreateInfo mainWindowInfo; diff --git a/src/Engine/Graphics/Enums.h b/src/Engine/Graphics/Enums.h index 8309979..afa5bde 100644 --- a/src/Engine/Graphics/Enums.h +++ b/src/Engine/Graphics/Enums.h @@ -169,8 +169,8 @@ static constexpr bool useMeshShading = true; static constexpr uint32 numFramesBuffered = 3; // meshlet dimensions curated by NVIDIA -static constexpr uint32 numVerticesPerMeshlet = 64; -static constexpr uint32 numPrimitivesPerMeshlet = 126; +static constexpr uint32 numVerticesPerMeshlet = 256; +static constexpr uint32 numPrimitivesPerMeshlet = 256; double getCurrentFrameDelta(); uint32 getCurrentFrameIndex(); diff --git a/src/Engine/Graphics/Meshlet.cpp b/src/Engine/Graphics/Meshlet.cpp index 2edaf90..7b7bf6a 100644 --- a/src/Engine/Graphics/Meshlet.cpp +++ b/src/Engine/Graphics/Meshlet.cpp @@ -2,6 +2,7 @@ #include "Containers/Map.h" #include "Containers/List.h" #include "Containers/Set.h" +#include using namespace Seele; @@ -194,7 +195,7 @@ bool addTriangle(const Array& positions, Meshlet ¤t, Triangle& tri int f2 = findIndex(current, tri.indices[1]); int f3 = findIndex(current, tri.indices[2]); - if (f1 == -1 || f2 == -1 || f3 == -1) + if (f1 == -1 || f2 == -1 || f3 == -1 || current.numPrimitives == Gfx::numPrimitivesPerMeshlet) { return false; } @@ -214,16 +215,16 @@ void Meshlet::build(const Array &positions, const Array &indices .numVertices = 0, .numPrimitives = 0, }; - Array optimizedIndices; - tipsifyIndexBuffer(indices, positions.size(), 25, optimizedIndices); - Array triangles(optimizedIndices.size() / 3); + //Array optimizedIndices = indices; + //tipsifyIndexBuffer(indices, positions.size(), 25, optimizedIndices); + Array triangles(indices.size() / 3); for (size_t i = 0; i < triangles.size(); ++i) { triangles[i] = Triangle{ .indices = { - optimizedIndices[i * 3 + 0], - optimizedIndices[i * 3 + 1], - optimizedIndices[i * 3 + 2], + indices[i * 3 + 0], + indices[i * 3 + 1], + indices[i * 3 + 2], }, }; } diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index 829a504..4bf276a 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -164,11 +164,7 @@ void VertexData::loadMesh(MeshId id, Array loadedIndices, Array std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices, m.numVertices * sizeof(uint32)); uint32 primitiveOffset = primitiveIndices.size(); primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3)); - for(size_t x = 0; x < m.numPrimitives*3; ++x) - { - primitiveIndices[primitiveOffset + x] = m.primitiveLayout[x]; - } - //std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8)); + std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8)); meshlets.add(MeshletDescription{ .bounding = m.boundingBox.toSphere(), .vertexCount = m.numVertices, @@ -218,7 +214,7 @@ void VertexData::loadMesh(MeshId id, Array loadedIndices, Array }); primitiveIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .sourceData = { - .size = sizeof(uint32) * primitiveIndices.size(), + .size = sizeof(uint8) * primitiveIndices.size(), .data = (uint8*)primitiveIndices.data(), }, .numElements = primitiveIndices.size(), @@ -280,11 +276,11 @@ void Seele::VertexData::init(Gfx::PGraphics _graphics) // meshData instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,}); // meshletData - instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding =2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); + instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); // primitiveIndices - instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding =3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); + instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); // vetexIndices - instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding =4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); + instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); instanceDataLayout->create(); resizeBuffers(); diff --git a/src/Engine/Graphics/VertexData.h b/src/Engine/Graphics/VertexData.h index 3046749..28898a2 100644 --- a/src/Engine/Graphics/VertexData.h +++ b/src/Engine/Graphics/VertexData.h @@ -99,7 +99,7 @@ protected: Map meshOffsets; Map meshVertexCounts; Array meshlets; - Array primitiveIndices; + Array primitiveIndices; Array vertexIndices; Array indices; Gfx::PGraphics graphics; diff --git a/src/Engine/Graphics/Vulkan/Descriptor.cpp b/src/Engine/Graphics/Vulkan/Descriptor.cpp index 8789cf4..5467e3f 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.cpp +++ b/src/Engine/Graphics/Vulkan/Descriptor.cpp @@ -328,7 +328,7 @@ void PipelineLayout::create() { PDescriptorLayout layout = desc.cast(); layout->create(); uint32 parameterIndex = parameterMapping[layout->getName()]; - if (parameterIndex > vulkanDescriptorLayouts.size()) + if (parameterIndex >= vulkanDescriptorLayouts.size()) { vulkanDescriptorLayouts.resize(parameterIndex + 1); } diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index 41f2830..b9a0809 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -489,7 +489,7 @@ void Graphics::pickPhysicalDevice() { if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0) { - meshShadingEnabled = true; + //meshShadingEnabled = true; break; } } diff --git a/src/Engine/Graphics/slang-compile.cpp b/src/Engine/Graphics/slang-compile.cpp index a41231c..8f200e0 100644 --- a/src/Engine/Graphics/slang-compile.cpp +++ b/src/Engine/Graphics/slang-compile.cpp @@ -16,7 +16,7 @@ Slang::ComPtr Seele::generateShader(const ShaderCreateInfo& create } slang::SessionDesc sessionDesc; sessionDesc.flags = 0; - StaticArray option; + StaticArray option; option[0].name = slang::CompilerOptionName::DumpIntermediates; option[0].value = slang::CompilerOptionValue(); option[0].value.kind = slang::CompilerOptionValueKind::Int; @@ -25,14 +25,6 @@ Slang::ComPtr Seele::generateShader(const ShaderCreateInfo& create option[1].value = slang::CompilerOptionValue(); option[1].value.kind = slang::CompilerOptionValueKind::Int; option[1].value.intValue0 = 1; - option[2].name = slang::CompilerOptionName::DebugInformation; - option[2].value = slang::CompilerOptionValue(); - option[2].value.kind = slang::CompilerOptionValueKind::Int; - option[2].value.intValue0 = 3; - option[3].name = slang::CompilerOptionName::DebugInformationFormat; - option[3].value = slang::CompilerOptionValue(); - option[3].value.kind = slang::CompilerOptionValueKind::Int; - option[3].value.stringValue0 = "c7"; sessionDesc.compilerOptionEntries = option.data(); sessionDesc.compilerOptionEntryCount = option.size(); sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR; @@ -112,8 +104,19 @@ Slang::ComPtr Seele::generateShader(const ShaderCreateInfo& create for(size_t i = 0; i < signature->getParameterCount(); ++i) { auto param = signature->getParameterByIndex(i); - paramMapping[param->getName()] = param->getBindingIndex(); - std::cout << "Parameter " << param->getName() << " index " << param->getBindingIndex() << std::endl; + // workaround + if (std::strcmp(param->getName(), "pVertexData") == 0) + { + paramMapping[param->getName()] = 1; + } + else if (std::strcmp(param->getName(), "pMaterial") == 0) + { + paramMapping[param->getName()] = 4; + } + else + { + paramMapping[param->getName()] = param->getBindingIndex(); + } } return kernelBlob; }