diff --git a/.gitmodules b/.gitmodules index 91ee4d1..b598ae1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,4 +3,7 @@ url = https://github.com/d-bahr/CRCpp.git [submodule "external/vcpkg"] path = external/vcpkg - url = https://github.com/Microsoft/vcpkg.git \ No newline at end of file + url = https://github.com/Microsoft/vcpkg.git +[submodule "external/slang"] + path = external/slang + url = https://github.com/shader-slang/slang.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 85aee38..01e8e39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,8 +98,8 @@ target_include_directories(AssetViewer PRIVATE src/AssetViewer) if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) - target_compile_options(Engine PUBLIC /std:c++20 /Zi /MP14 /W4 /wd4505 /fsanitize=address) - target_compile_options(Editor PUBLIC /std:c++20 /Zi /MP14 /W4 /fsanitize=address) + target_compile_options(Engine PUBLIC /std:c++20 /Zi /MP14 /W4 /wd4505) + target_compile_options(Editor PUBLIC /std:c++20 /Zi /MP14 /W4) target_sources(Engine INTERFACE $ $ @@ -107,13 +107,9 @@ if(MSVC) install(FILES Seele.natvis DESTINATION Seele/) - target_link_options(Engine PUBLIC /fsanitize=address /DEBUG) - target_link_options(Editor PUBLIC /fsanitize=address /DEBUG) else() - target_compile_options(Engine PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20 -Wno-missing-field-initializers -Wno-unused-function -fsanitize=address) - target_compile_options(Editor PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20 -fsanitize=address) - target_link_options(Engine PUBLIC -fsanitize=address) - target_link_options(Editor PUBLIC -fsanitize=address) + target_compile_options(Engine PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20 -Wno-missing-field-initializers -Wno-unused-function) + target_compile_options(Editor PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20) endif() if(APPLE) #Metal lib throws that internally for some reason diff --git a/CMakeSettings.json b/CMakeSettings.json index 194561b..3e76710 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -9,14 +9,14 @@ "intelliSenseMode": "windows-msvc-x64", "inheritEnvironments": [ "msvc_x64" ], "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", - "buildRoot": "C:/Users/Dynamitos/Seele/build", + "buildRoot": "${workspaceRoot}/build", "installRoot": "C:/Program Files/Seele" }, { "name": "Release", "generator": "Visual Studio 17 2022 Win64", "configurationType": "Release", - "buildRoot": "C:/Users/Dynamitos/Seele/build/", + "buildRoot": "${workspaceRoot}/build", "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", "buildCommandArgs": "", "ctestCommandArgs": "", @@ -28,7 +28,7 @@ "name": "RelWithDebInfo", "generator": "Visual Studio 17 2022 Win64", "configurationType": "RelWithDebInfo", - "buildRoot": "C:/Users/Dynamitos/Seele/build/", + "buildRoot": "${workspaceRoot}/build", "installRoot": "C:/Program Files/Seele", "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", "buildCommandArgs": "", @@ -45,7 +45,7 @@ "intelliSenseMode": "windows-msvc-x64", "inheritEnvironments": [ "msvc_x64" ], "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", - "buildRoot": "C:/Users/Dynamitos/Seele/build/", + "buildRoot": "${workspaceRoot}/build", "installRoot": "C:/Program Files/Seele", "addressSanitizerEnabled": true }, @@ -53,7 +53,7 @@ "name": "MinSizeRel", "generator": "Visual Studio 17 2022 Win64", "configurationType": "MinSizeRel", - "buildRoot": "C:/Users/Dynamitos/Seele/build/", + "buildRoot": "${workspaceRoot}/build", "installRoot": "C:/Program Files/Seele", "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", "buildCommandArgs": "", diff --git a/external/slang b/external/slang new file mode 160000 index 0000000..62b7219 --- /dev/null +++ b/external/slang @@ -0,0 +1 @@ +Subproject commit 62b7219e715bd4c0f984bcd98c9767fb6422c78f diff --git a/external/vcpkg b/external/vcpkg index 943c5ef..4002e5f 160000 --- a/external/vcpkg +++ b/external/vcpkg @@ -1 +1 @@ -Subproject commit 943c5ef1c8f6b5e6ced092b242c8299caae2ff01 +Subproject commit 4002e5f3598cc0d216c395bc0db3de44a2d2ec9b diff --git a/src/Engine/Containers/List.h b/src/Engine/Containers/List.h index 79d2cf3..d2c7cd8 100644 --- a/src/Engine/Containers/List.h +++ b/src/Engine/Containers/List.h @@ -134,21 +134,21 @@ public: using const_reverse_iterator = std::reverse_iterator; constexpr List() - : root(nullptr) - , tail(nullptr) + : allocator(Allocator()) + , root(allocateNode()) + , tail(root) , beginIt(Iterator(root)) , endIt(Iterator(tail)) , _size(0) - , allocator(Allocator()) { } constexpr explicit List(const Allocator& alloc) - : root(nullptr) - , tail(nullptr) + : allocator(alloc) + , root(allocateNode()) + , tail(root) , beginIt(Iterator(root)) , endIt(Iterator(tail)) , _size(0) - , allocator(alloc) { } constexpr List(size_type count, const T& value = T(), const Allocator& alloc = Allocator()) @@ -187,28 +187,33 @@ public: } } constexpr List(List&& other) - : root(std::move(other.root)) + : allocator(std::move(other.allocator)) + , root(std::move(other.root)) , tail(std::move(other.tail)) , beginIt(std::move(other.beginIt)) , endIt(std::move(other.endIt)) , _size(std::move(other._size)) - , allocator(std::move(other.allocator)) { + other.root = nullptr; + other.tail = nullptr; other._size = 0; } constexpr List(List&& other, const Allocator& alloc) - : root(std::move(other.root)) + : allocator(alloc) + , root(std::move(other.root)) , tail(std::move(other.tail)) , beginIt(std::move(other.beginIt)) , endIt(std::move(other.endIt)) , _size(std::move(other._size)) - , allocator(alloc) { + other.root = nullptr; + other.tail = nullptr; other._size = 0; } constexpr ~List() { clear(); + deallocateNode(tail); } constexpr List& operator=(const List& other) { @@ -246,6 +251,8 @@ public: beginIt = other.beginIt; endIt = other.endIt; _size = other._size; + other.root = nullptr; + other.tail = nullptr; other._size = 0; markIteratorDirty(); } @@ -272,9 +279,7 @@ public: destroyNode(tmp->prev); deallocateNode(tmp->prev); } - deallocateNode(tail); - tail = nullptr; - root = nullptr; + root = tail; markIteratorDirty(); _size = 0; } @@ -287,29 +292,9 @@ public: { return addInternal(std::move(value)); } - // takes all elements from other and move-inserts them into - // this, clearing other in the process - constexpr void moveElements(List&& other) - { - tail->prev->next = other.root; - other.root->prev = tail->prev; - _size += other._size; - deallocateNode(tail); - tail = other.tail; - other._size = 0; - other.root = nullptr; - other.tail = nullptr; - markIteratorDirty(); - other.markIteratorDirty(); - } template constexpr reference emplace(args... arguments) { - if (root == nullptr) - { - root = allocateNode(); - tail = root; - } std::allocator_traits::construct(allocator, tail, tail->prev, @@ -355,12 +340,6 @@ public: } destroyNode(pos.node); deallocateNode(pos.node); - if (_size == 0) - { - deallocateNode(tail); - root = nullptr; - tail = nullptr; - } markIteratorDirty(); return Iterator(next); } @@ -387,25 +366,20 @@ public: constexpr iterator insert(iterator pos, const T &value) { _size++; - if (root == nullptr) - { - root = allocateNode(); - root->data = value; - tail = allocateNode(); - root->next = tail; - root->prev = nullptr; - tail->prev = root; - tail->next = nullptr; - markIteratorDirty(); - return beginIt; - } - Node *tmp = pos.node->prev; Node *newNode = allocateNode(); initializeNode(newNode, value); - tmp->next = newNode; - newNode->prev = tmp; newNode->next = pos.node; pos.node->prev = newNode; + Node *tmp = pos.node->prev; + if (tmp != nullptr) + { + tmp->next = newNode; + newNode->prev = tmp; + } + else + { + root = newNode; + } markIteratorDirty(); return Iterator(newNode); } @@ -474,11 +448,6 @@ private: template constexpr iterator addInternal(ValueType&& value) { - if (root == nullptr) - { - root = allocateNode(); - tail = root; - } initializeNode(tail, std::forward(value)); Node* newTail = allocateNode(); newTail->prev = tail; @@ -497,6 +466,7 @@ private: cbeginIt = ConstIterator(root); cendIt = ConstIterator(tail); } + NodeAllocator allocator; Node *root; Node *tail; iterator beginIt; @@ -504,6 +474,5 @@ private: const_iterator cbeginIt; const_iterator cendIt; size_type _size; - NodeAllocator allocator; }; } // namespace Seele \ No newline at end of file diff --git a/src/Engine/Graphics/Shader.cpp b/src/Engine/Graphics/Shader.cpp index 1db9eda..e9b59b3 100644 --- a/src/Engine/Graphics/Shader.cpp +++ b/src/Engine/Graphics/Shader.cpp @@ -70,7 +70,7 @@ void ShaderCompiler::compile() { for (const auto& [matName, mat] : materials) { - work.add([=]() { + //work.add([=]() { ShaderPermutation permutation; if (pass.positionOnly) { @@ -99,12 +99,12 @@ void ShaderCompiler::compile() layout->addDescriptorLayout(mat->getDescriptorLayout()); permutation.setMaterial(mat->getName()); createShaders(permutation, std::move(layout)); - }); + //}); } } else { - work.add([=]() { + //work.add([=]() { ShaderPermutation permutation; if (pass.positionOnly) { @@ -131,11 +131,11 @@ void ShaderCompiler::compile() layout->addDescriptorLayout(vd->getVertexDataLayout()); layout->addDescriptorLayout(vd->getInstanceDataLayout()); createShaders(permutation, std::move(layout)); - }); + //}); } } } - getThreadPool().runAndWait(std::move(work)); + //getThreadPool().runAndWait(std::move(work)); } void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipelineLayout layout) diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index 939a0a0..a7b4d9c 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -137,8 +137,7 @@ void VertexData::createDescriptors() .size = cullingOffsets.size() * sizeof(uint32), .data = (uint8*)cullingOffsets.data(), }, - .numElements = cullingOffsets.size(), - .name = "MeshletOffset" + .numElements = cullingOffsets.size() }); cullingOffsetBuffer->pipelineBarrier( Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, @@ -151,9 +150,8 @@ void VertexData::createDescriptors() .sourceData = { .size = numMeshlets * sizeof(uint32), }, - .numElements = numMeshlets, - .name = "MeshletCulling" - }); + .numElements = numMeshlets + }); cullingBuffer->pipelineBarrier( Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, @@ -166,8 +164,7 @@ void VertexData::createDescriptors() .size = instanceData.size() * sizeof(InstanceData), .data = (uint8*)instanceData.data(), }, - .numElements = instanceData.size(), - .name = "InstanceBuffer" + .numElements = instanceData.size() }); instanceBuffer->pipelineBarrier( Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, @@ -182,8 +179,7 @@ void VertexData::createDescriptors() .size = sizeof(MeshData) * instanceMeshData.size(), .data = (uint8*)instanceMeshData.data(), }, - .numElements = instanceMeshData.size(), - .name = "MeshDataBuffer" + .numElements = instanceMeshData.size() }); instanceMeshDataBuffer->pipelineBarrier( Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, @@ -236,8 +232,8 @@ void VertexData::loadMesh(MeshId id, Array loadedIndices, Array .bounding = meshAABB,//.toSphere(), .numMeshlets = (uint32)loadedMeshlets.size(), .meshletOffset = meshletOffset, - }; - + }; + meshData[id].firstIndex = indices.size(); meshData[id].numIndices = loadedIndices.size(); if (!graphics->supportMeshShading()) @@ -347,10 +343,23 @@ void VertexData::init(Gfx::PGraphics _graphics) instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 5, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER }); // cullingOffset instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 6, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER }); - cullingOffsetBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .dynamic = true }); - cullingBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .dynamic = true }); - instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .dynamic = true }); - instanceMeshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .dynamic = true }); + + cullingOffsetBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ + .dynamic = true, + .name = "MeshletOffset", + }); + cullingBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ + .dynamic = true, + .name = "MeshletCulling", + }); + instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ + .dynamic = true, + .name = "InstanceBuffer", + }); + instanceMeshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ + .dynamic = true, + .name = "MeshDataBuffer", + }); instanceDataLayout->create(); resizeBuffers(); graphics->getShaderCompiler()->registerVertexData(this); diff --git a/src/Engine/Graphics/Vulkan/Command.cpp b/src/Engine/Graphics/Vulkan/Command.cpp index 31dd51a..f9884a5 100644 --- a/src/Engine/Graphics/Vulkan/Command.cpp +++ b/src/Engine/Graphics/Vulkan/Command.cpp @@ -282,8 +282,11 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, ArraywriteDescriptors.size() == 0); descriptor->bind(); boundResources.add(descriptor.getHandle()); - boundResources.addAll(descriptor->boundResources); - descriptor->boundResources.clear(); + for (auto binding : descriptor->boundResources) + { + binding->bind(); + boundResources.add(binding); + } VkDescriptorSet setHandle = descriptor->getHandle(); vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle, dynamicOffsets.size(), dynamicOffsets.data()); @@ -298,10 +301,13 @@ void RenderCommand::bindDescriptor(const Array& descriptorS auto descriptorSet = descriptorSets[i].cast(); assert(descriptorSet->writeDescriptors.size() == 0); descriptorSet->bind(); - boundResources.add(descriptorSet.getHandle()); - boundResources.addAll(descriptorSet->boundResources); - descriptorSet->boundResources.clear(); + + for (auto binding : descriptorSet->boundResources) + { + binding->bind(); + boundResources.add(binding); + } sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle(); } vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, dynamicOffsets.size(), dynamicOffsets.data()); @@ -434,9 +440,12 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array(); assert(descriptor->writeDescriptors.size() == 0); boundResources.add(descriptor.getHandle()); - boundResources.addAll(descriptor->boundResources); - descriptor->boundResources.clear(); - descriptor->bind(); + + for (auto binding : descriptor->boundResources) + { + binding->bind(); + boundResources.add(binding); + } VkDescriptorSet setHandle = descriptor->getHandle(); vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle, dynamicOffsets.size(), dynamicOffsets.data()); @@ -451,11 +460,14 @@ void ComputeCommand::bindDescriptor(const Array& descriptor auto descriptorSet = descriptorSets[i].cast(); assert(descriptorSet->writeDescriptors.size() == 0); descriptorSet->bind(); + boundResources.add(descriptorSet.getHandle()); //std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl; - boundResources.add(descriptorSet.getHandle()); - boundResources.addAll(descriptorSet->boundResources); - descriptorSet->boundResources.clear(); + for (auto binding : descriptorSet->boundResources) + { + binding->bind(); + boundResources.add(binding); + } sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle(); } vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, dynamicOffsets.size(), dynamicOffsets.data()); diff --git a/src/Engine/Graphics/Vulkan/Descriptor.cpp b/src/Engine/Graphics/Vulkan/Descriptor.cpp index 8f3b06b..246ca9f 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.cpp +++ b/src/Engine/Graphics/Vulkan/Descriptor.cpp @@ -142,9 +142,6 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() { cachedHandles[setIndex]->allocate(); PDescriptorSet vulkanSet = cachedHandles[setIndex]; - vulkanSet->cachedData.resize(layout->bindings.size()); - // Not really pretty, but this way the set knows which ones are valid - std::memset(vulkanSet->cachedData.data(), 0, sizeof(void*) * vulkanSet->cachedData.size()); // Found set, stop searching return vulkanSet; @@ -177,7 +174,9 @@ DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner) , owner(owner) , bindCount(0) , currentlyInUse(false) -{} +{ + boundResources.resize(owner->getLayout()->getBindings().size()); +} DescriptorSet::~DescriptorSet() { @@ -186,11 +185,6 @@ DescriptorSet::~DescriptorSet() void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) { PUniformBuffer vulkanBuffer = uniformBuffer.cast(); - UniformBuffer* cachedBuffer = reinterpret_cast(cachedData[binding]); - if (vulkanBuffer->isDataEquals(cachedBuffer)) { - // std::cout << "uniform data equal, skip" << std::endl; - return; - } bufferInfos.add(VkDescriptorBufferInfo{ .buffer = vulkanBuffer->getHandle(), .offset = 0, @@ -208,17 +202,11 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu .pBufferInfo = &bufferInfos.back(), }); - cachedData[binding] = vulkanBuffer.getHandle(); - vulkanBuffer->getAlloc()->bind(); - boundResources.add(vulkanBuffer->getAlloc()); + boundResources[binding] = vulkanBuffer->getAlloc(); } void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuffer) { PShaderBuffer vulkanBuffer = shaderBuffer.cast(); - ShaderBuffer* cachedBuffer = reinterpret_cast(cachedData[binding]); - if (vulkanBuffer.getHandle() == cachedBuffer) { - return; - } bufferInfos.add(VkDescriptorBufferInfo{ .buffer = vulkanBuffer->getHandle(), @@ -236,18 +224,11 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuff .pBufferInfo = &bufferInfos.back(), }); - cachedData[binding] = vulkanBuffer.getHandle(); - vulkanBuffer->getAlloc()->bind(); - boundResources.add(vulkanBuffer->getAlloc()); + boundResources[binding] = vulkanBuffer->getAlloc(); } void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) { PShaderBuffer vulkanBuffer = shaderBuffer.cast(); - ShaderBuffer* cachedBuffer = reinterpret_cast(cachedData[binding]); - if (vulkanBuffer.getHandle() == cachedBuffer) { - return; - } - bufferInfos.add(VkDescriptorBufferInfo{ .buffer = vulkanBuffer->getHandle(), .offset = 0, @@ -265,19 +246,14 @@ void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuf .pBufferInfo = &bufferInfos.back(), }); - cachedData[binding] = vulkanBuffer.getHandle(); - vulkanBuffer->getAlloc()->bind(); - boundResources.add(vulkanBuffer->getAlloc()); + boundResources[binding] = vulkanBuffer->getAlloc(); } void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) { PSampler vulkanSampler = samplerState.cast(); - Sampler* cachedSampler = reinterpret_cast(cachedData[binding]); - if (vulkanSampler.getHandle() == cachedSampler) { - return; - } + imageInfos.add(VkDescriptorImageInfo{ - .sampler = vulkanSampler->sampler, + .sampler = vulkanSampler->getSampler(), .imageView = VK_NULL_HANDLE, .imageLayout = VK_IMAGE_LAYOUT_UNDEFINED, }); @@ -293,18 +269,15 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) .pImageInfo = &imageInfos.back(), }); - cachedData[binding] = vulkanSampler.getHandle(); + boundResources[binding] = vulkanSampler->getHandle(); } void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) { TextureBase* vulkanTexture = texture.cast().getHandle(); - TextureBase* cachedTexture = reinterpret_cast(cachedData[binding]); - if (vulkanTexture == cachedTexture) { - return; - } + // It is assumed that the image is in the correct layout imageInfos.add(VkDescriptorImageInfo{ - .sampler = samplerState != nullptr ? samplerState.cast()->sampler : VK_NULL_HANDLE, + .sampler = samplerState != nullptr ? samplerState.cast()->getSampler() : VK_NULL_HANDLE, .imageView = vulkanTexture->getView(), .imageLayout = cast(vulkanTexture->getLayout()), }); @@ -325,13 +298,12 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx:: .pImageInfo = &imageInfos.back(), }); - cachedData[binding] = vulkanTexture; - vulkanTexture->getHandle()->bind(); - boundResources.add(vulkanTexture->getHandle()); + boundResources[binding] = vulkanTexture->getHandle(); } void DescriptorSet::updateTextureArray(uint32_t binding, Array textures) { // maybe make this a parameter? uint32 arrayElement = 0; + boundResources.resize(binding + textures.size()); for (auto& gfxTexture : textures) { TextureBase* vulkanTexture = gfxTexture.cast().getHandle(); imageInfos.add(VkDescriptorImageInfo{ @@ -344,6 +316,7 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array te if (vulkanTexture->getUsage() & VK_IMAGE_USAGE_STORAGE_BIT) { descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; } + boundResources[binding + arrayElement] = vulkanTexture->getHandle(); writeDescriptors.add(VkWriteDescriptorSet{ .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .pNext = nullptr, @@ -355,7 +328,6 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array te .pImageInfo = &imageInfos.back(), }); vulkanTexture->getHandle()->bind(); - boundResources.add(vulkanTexture->getHandle()); } } diff --git a/src/Engine/Graphics/Vulkan/Descriptor.h b/src/Engine/Graphics/Vulkan/Descriptor.h index 3265f51..e50b5fe 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.h +++ b/src/Engine/Graphics/Vulkan/Descriptor.h @@ -67,7 +67,7 @@ private: // contains the previously bound resources at every binding // since the layout is fixed, trying to bind a texture to a buffer // would not work anyways, so casts should be safe - Array cachedData; + //Array cachedData; Array boundResources; VkDescriptorSet setHandle; PGraphics graphics; diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index 1844508..aa052eb 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -217,7 +217,6 @@ Gfx::PComputePipeline Graphics::createComputePipeline(Gfx::ComputePipelineCreate Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo) { - OSampler sampler = new Sampler(); VkSamplerCreateInfo vkInfo = { .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .pNext = nullptr, @@ -238,8 +237,7 @@ Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo) .borderColor = cast(createInfo.borderColor), .unnormalizedCoordinates = createInfo.unnormalizedCoordinates, }; - VK_CHECK(vkCreateSampler(handle, &vkInfo, nullptr, &sampler->sampler)); - return sampler; + return new Sampler(this, vkInfo); } Gfx::ODescriptorLayout Graphics::createDescriptorLayout(const std::string& name) diff --git a/src/Engine/Graphics/Vulkan/Resources.cpp b/src/Engine/Graphics/Vulkan/Resources.cpp index 872f8cf..3fbd0bd 100644 --- a/src/Engine/Graphics/Vulkan/Resources.cpp +++ b/src/Engine/Graphics/Vulkan/Resources.cpp @@ -117,3 +117,24 @@ void DestructionManager::notifyCommandComplete() } } } + +SamplerHandle::SamplerHandle(PGraphics graphics, VkSamplerCreateInfo createInfo) + : CommandBoundResource(graphics) +{ + vkCreateSampler(graphics->getDevice(), &createInfo, nullptr, &sampler); +} + +SamplerHandle::~SamplerHandle() +{ + vkDestroySampler(graphics->getDevice(), sampler, nullptr); +} + +Sampler::Sampler(PGraphics graphics, VkSamplerCreateInfo createInfo) + : graphics(graphics) + , handle(new SamplerHandle(graphics, createInfo)) +{} + +Sampler::~Sampler() +{ + graphics->getDestructionManager()->queueResourceForDestruction(std::move(handle)); +} diff --git a/src/Engine/Graphics/Vulkan/Resources.h b/src/Engine/Graphics/Vulkan/Resources.h index fd222d7..a1958d2 100644 --- a/src/Engine/Graphics/Vulkan/Resources.h +++ b/src/Engine/Graphics/Vulkan/Resources.h @@ -85,10 +85,25 @@ protected: }; DEFINE_REF(CommandBoundResource) +class SamplerHandle : public CommandBoundResource +{ +public: + SamplerHandle(PGraphics graphics, VkSamplerCreateInfo createInfo); + virtual ~SamplerHandle(); + VkSampler sampler; +}; +DEFINE_REF(SamplerHandle) + class Sampler : public Gfx::Sampler { public: - VkSampler sampler; + Sampler(PGraphics graphics, VkSamplerCreateInfo createInfo); + virtual ~Sampler(); + PSamplerHandle getHandle() const { return handle; } + VkSampler getSampler() const { return handle->sampler; } +private: + PGraphics graphics; + OSamplerHandle handle; }; DEFINE_REF(Sampler) diff --git a/src/Engine/Graphics/slang-compile.cpp b/src/Engine/Graphics/slang-compile.cpp index f886a94..0501fbd 100644 --- a/src/Engine/Graphics/slang-compile.cpp +++ b/src/Engine/Graphics/slang-compile.cpp @@ -23,12 +23,13 @@ Slang::ComPtr Seele::generateShader(const ShaderCreateInfo& create option[1].name = slang::CompilerOptionName::EmitSpirvViaGLSL; option[1].value.kind = slang::CompilerOptionValueKind::Int; option[1].value.intValue0 = 1; - option[2].name = slang::CompilerOptionName::EmitIr; + option[2].name = slang::CompilerOptionName::DebugInformation; option[2].value.kind = slang::CompilerOptionValueKind::Int; - option[2].value.intValue0 = 1; + option[2].value.intValue0 = SLANG_DEBUG_INFO_LEVEL_NONE; option[3].name = slang::CompilerOptionName::DebugInformationFormat; option[3].value.kind = slang::CompilerOptionValueKind::Int; - option[3].value.intValue0 = SLANG_DEBUG_INFO_FORMAT_C7; + option[3].value.intValue0 = SLANG_DEBUG_INFO_FORMAT_PDB; + sessionDesc.compilerOptionEntries = option.data(); sessionDesc.compilerOptionEntryCount = option.size(); sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR; @@ -43,7 +44,7 @@ Slang::ComPtr Seele::generateShader(const ShaderCreateInfo& create sessionDesc.preprocessorMacroCount = macros.size(); sessionDesc.preprocessorMacros = macros.data(); slang::TargetDesc targetDesc; - targetDesc.profile = globalSession->findProfile("sm_6_6"); + targetDesc.profile = globalSession->findProfile("spirv_1_5"); targetDesc.format = target; sessionDesc.targetCount = 1; sessionDesc.targets = &targetDesc; diff --git a/src/Engine/System/ComponentSystem.h b/src/Engine/System/ComponentSystem.h index 71def7c..7703f1a 100644 --- a/src/Engine/System/ComponentSystem.h +++ b/src/Engine/System/ComponentSystem.h @@ -26,14 +26,14 @@ public: template void setupView(Dependencies) { - List> work; + //List> work; registry.view().each([&](Components&... comp, Deps&... deps){ - work.add([&]() { + //work.add([&]() { (accessComponent(deps), ...); update(comp...); - }); + //}); }); - getThreadPool().runAndWait(std::move(work)); + //getThreadPool().runAndWait(std::move(work)); } virtual void run(double delta) override { diff --git a/src/Engine/ThreadPool.cpp b/src/Engine/ThreadPool.cpp index 52cd6ab..c442eb2 100644 --- a/src/Engine/ThreadPool.cpp +++ b/src/Engine/ThreadPool.cpp @@ -23,18 +23,18 @@ ThreadPool::~ThreadPool() } } -void ThreadPool::runAndWait(List> functions) -{ - std::unique_lock l(taskLock); - currentTask.numRemaining = functions.size(); - currentTask.functions = std::move(functions); - taskCV.notify_all(); - - while (currentTask.numRemaining > 0) - { - completedCV.wait(l); - } -} +//void ThreadPool::runAndWait(List> functions) +//{ +// std::unique_lock l(taskLock); +// currentTask.numRemaining = functions.size(); +// currentTask.functions = std::move(functions); +// taskCV.notify_all(); +// +// while (currentTask.numRemaining > 0) +// { +// completedCV.wait(l); +// } +//} void ThreadPool::work() { diff --git a/src/Engine/ThreadPool.h b/src/Engine/ThreadPool.h index 5ff7f3c..861e2ea 100644 --- a/src/Engine/ThreadPool.h +++ b/src/Engine/ThreadPool.h @@ -11,7 +11,7 @@ class ThreadPool public: ThreadPool(uint32 numWorkers = std::thread::hardware_concurrency()); ~ThreadPool(); - void runAndWait(List> functions); + //void runAndWait(List> functions); private: struct Task {