Fixing some descriptor binding stuff, made it work

This commit is contained in:
Dynamitos
2024-05-18 21:23:59 +02:00
parent 60d2164987
commit 838bd69fa7
18 changed files with 171 additions and 174 deletions
+4 -1
View File
@@ -3,4 +3,7 @@
url = https://github.com/d-bahr/CRCpp.git url = https://github.com/d-bahr/CRCpp.git
[submodule "external/vcpkg"] [submodule "external/vcpkg"]
path = external/vcpkg path = external/vcpkg
url = https://github.com/Microsoft/vcpkg.git url = https://github.com/Microsoft/vcpkg.git
[submodule "external/slang"]
path = external/slang
url = https://github.com/shader-slang/slang.git
+4 -8
View File
@@ -98,8 +98,8 @@ target_include_directories(AssetViewer PRIVATE src/AssetViewer)
if(MSVC) if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_WARNINGS)
target_compile_options(Engine PUBLIC /std:c++20 /Zi /MP14 /W4 /wd4505 /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 /fsanitize=address) target_compile_options(Editor PUBLIC /std:c++20 /Zi /MP14 /W4)
target_sources(Engine INTERFACE target_sources(Engine INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Seele.natvis> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Seele.natvis>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/Seele/Seele.natvis> $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/Seele/Seele.natvis>
@@ -107,13 +107,9 @@ if(MSVC)
install(FILES install(FILES
Seele.natvis Seele.natvis
DESTINATION Seele/) DESTINATION Seele/)
target_link_options(Engine PUBLIC /fsanitize=address /DEBUG)
target_link_options(Editor PUBLIC /fsanitize=address /DEBUG)
else() 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(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 -fsanitize=address) target_compile_options(Editor PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20)
target_link_options(Engine PUBLIC -fsanitize=address)
target_link_options(Editor PUBLIC -fsanitize=address)
endif() endif()
if(APPLE) if(APPLE)
#Metal lib throws that internally for some reason #Metal lib throws that internally for some reason
+5 -5
View File
@@ -9,14 +9,14 @@
"intelliSenseMode": "windows-msvc-x64", "intelliSenseMode": "windows-msvc-x64",
"inheritEnvironments": [ "msvc_x64" ], "inheritEnvironments": [ "msvc_x64" ],
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
"buildRoot": "C:/Users/Dynamitos/Seele/build", "buildRoot": "${workspaceRoot}/build",
"installRoot": "C:/Program Files/Seele" "installRoot": "C:/Program Files/Seele"
}, },
{ {
"name": "Release", "name": "Release",
"generator": "Visual Studio 17 2022 Win64", "generator": "Visual Studio 17 2022 Win64",
"configurationType": "Release", "configurationType": "Release",
"buildRoot": "C:/Users/Dynamitos/Seele/build/", "buildRoot": "${workspaceRoot}/build",
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
"buildCommandArgs": "", "buildCommandArgs": "",
"ctestCommandArgs": "", "ctestCommandArgs": "",
@@ -28,7 +28,7 @@
"name": "RelWithDebInfo", "name": "RelWithDebInfo",
"generator": "Visual Studio 17 2022 Win64", "generator": "Visual Studio 17 2022 Win64",
"configurationType": "RelWithDebInfo", "configurationType": "RelWithDebInfo",
"buildRoot": "C:/Users/Dynamitos/Seele/build/", "buildRoot": "${workspaceRoot}/build",
"installRoot": "C:/Program Files/Seele", "installRoot": "C:/Program Files/Seele",
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
"buildCommandArgs": "", "buildCommandArgs": "",
@@ -45,7 +45,7 @@
"intelliSenseMode": "windows-msvc-x64", "intelliSenseMode": "windows-msvc-x64",
"inheritEnvironments": [ "msvc_x64" ], "inheritEnvironments": [ "msvc_x64" ],
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
"buildRoot": "C:/Users/Dynamitos/Seele/build/", "buildRoot": "${workspaceRoot}/build",
"installRoot": "C:/Program Files/Seele", "installRoot": "C:/Program Files/Seele",
"addressSanitizerEnabled": true "addressSanitizerEnabled": true
}, },
@@ -53,7 +53,7 @@
"name": "MinSizeRel", "name": "MinSizeRel",
"generator": "Visual Studio 17 2022 Win64", "generator": "Visual Studio 17 2022 Win64",
"configurationType": "MinSizeRel", "configurationType": "MinSizeRel",
"buildRoot": "C:/Users/Dynamitos/Seele/build/", "buildRoot": "${workspaceRoot}/build",
"installRoot": "C:/Program Files/Seele", "installRoot": "C:/Program Files/Seele",
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
"buildCommandArgs": "", "buildCommandArgs": "",
Vendored Submodule
+1
Submodule external/slang added at 62b7219e71
+1 -1
+29 -60
View File
@@ -134,21 +134,21 @@ public:
using const_reverse_iterator = std::reverse_iterator<const_iterator>; using const_reverse_iterator = std::reverse_iterator<const_iterator>;
constexpr List() constexpr List()
: root(nullptr) : allocator(Allocator())
, tail(nullptr) , root(allocateNode())
, tail(root)
, beginIt(Iterator(root)) , beginIt(Iterator(root))
, endIt(Iterator(tail)) , endIt(Iterator(tail))
, _size(0) , _size(0)
, allocator(Allocator())
{ {
} }
constexpr explicit List(const Allocator& alloc) constexpr explicit List(const Allocator& alloc)
: root(nullptr) : allocator(alloc)
, tail(nullptr) , root(allocateNode())
, tail(root)
, beginIt(Iterator(root)) , beginIt(Iterator(root))
, endIt(Iterator(tail)) , endIt(Iterator(tail))
, _size(0) , _size(0)
, allocator(alloc)
{ {
} }
constexpr List(size_type count, const T& value = T(), const Allocator& alloc = Allocator()) constexpr List(size_type count, const T& value = T(), const Allocator& alloc = Allocator())
@@ -187,28 +187,33 @@ public:
} }
} }
constexpr List(List&& other) constexpr List(List&& other)
: root(std::move(other.root)) : allocator(std::move(other.allocator))
, root(std::move(other.root))
, tail(std::move(other.tail)) , tail(std::move(other.tail))
, beginIt(std::move(other.beginIt)) , beginIt(std::move(other.beginIt))
, endIt(std::move(other.endIt)) , endIt(std::move(other.endIt))
, _size(std::move(other._size)) , _size(std::move(other._size))
, allocator(std::move(other.allocator))
{ {
other.root = nullptr;
other.tail = nullptr;
other._size = 0; other._size = 0;
} }
constexpr List(List&& other, const Allocator& alloc) constexpr List(List&& other, const Allocator& alloc)
: root(std::move(other.root)) : allocator(alloc)
, root(std::move(other.root))
, tail(std::move(other.tail)) , tail(std::move(other.tail))
, beginIt(std::move(other.beginIt)) , beginIt(std::move(other.beginIt))
, endIt(std::move(other.endIt)) , endIt(std::move(other.endIt))
, _size(std::move(other._size)) , _size(std::move(other._size))
, allocator(alloc)
{ {
other.root = nullptr;
other.tail = nullptr;
other._size = 0; other._size = 0;
} }
constexpr ~List() constexpr ~List()
{ {
clear(); clear();
deallocateNode(tail);
} }
constexpr List& operator=(const List& other) constexpr List& operator=(const List& other)
{ {
@@ -246,6 +251,8 @@ public:
beginIt = other.beginIt; beginIt = other.beginIt;
endIt = other.endIt; endIt = other.endIt;
_size = other._size; _size = other._size;
other.root = nullptr;
other.tail = nullptr;
other._size = 0; other._size = 0;
markIteratorDirty(); markIteratorDirty();
} }
@@ -272,9 +279,7 @@ public:
destroyNode(tmp->prev); destroyNode(tmp->prev);
deallocateNode(tmp->prev); deallocateNode(tmp->prev);
} }
deallocateNode(tail); root = tail;
tail = nullptr;
root = nullptr;
markIteratorDirty(); markIteratorDirty();
_size = 0; _size = 0;
} }
@@ -287,29 +292,9 @@ public:
{ {
return addInternal(std::move(value)); 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<typename... args> template<typename... args>
constexpr reference emplace(args... arguments) constexpr reference emplace(args... arguments)
{ {
if (root == nullptr)
{
root = allocateNode();
tail = root;
}
std::allocator_traits<NodeAllocator>::construct(allocator, std::allocator_traits<NodeAllocator>::construct(allocator,
tail, tail,
tail->prev, tail->prev,
@@ -355,12 +340,6 @@ public:
} }
destroyNode(pos.node); destroyNode(pos.node);
deallocateNode(pos.node); deallocateNode(pos.node);
if (_size == 0)
{
deallocateNode(tail);
root = nullptr;
tail = nullptr;
}
markIteratorDirty(); markIteratorDirty();
return Iterator(next); return Iterator(next);
} }
@@ -387,25 +366,20 @@ public:
constexpr iterator insert(iterator pos, const T &value) constexpr iterator insert(iterator pos, const T &value)
{ {
_size++; _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(); Node *newNode = allocateNode();
initializeNode(newNode, value); initializeNode(newNode, value);
tmp->next = newNode;
newNode->prev = tmp;
newNode->next = pos.node; newNode->next = pos.node;
pos.node->prev = newNode; pos.node->prev = newNode;
Node *tmp = pos.node->prev;
if (tmp != nullptr)
{
tmp->next = newNode;
newNode->prev = tmp;
}
else
{
root = newNode;
}
markIteratorDirty(); markIteratorDirty();
return Iterator(newNode); return Iterator(newNode);
} }
@@ -474,11 +448,6 @@ private:
template<typename ValueType> template<typename ValueType>
constexpr iterator addInternal(ValueType&& value) constexpr iterator addInternal(ValueType&& value)
{ {
if (root == nullptr)
{
root = allocateNode();
tail = root;
}
initializeNode(tail, std::forward<ValueType>(value)); initializeNode(tail, std::forward<ValueType>(value));
Node* newTail = allocateNode(); Node* newTail = allocateNode();
newTail->prev = tail; newTail->prev = tail;
@@ -497,6 +466,7 @@ private:
cbeginIt = ConstIterator(root); cbeginIt = ConstIterator(root);
cendIt = ConstIterator(tail); cendIt = ConstIterator(tail);
} }
NodeAllocator allocator;
Node *root; Node *root;
Node *tail; Node *tail;
iterator beginIt; iterator beginIt;
@@ -504,6 +474,5 @@ private:
const_iterator cbeginIt; const_iterator cbeginIt;
const_iterator cendIt; const_iterator cendIt;
size_type _size; size_type _size;
NodeAllocator allocator;
}; };
} // namespace Seele } // namespace Seele
+5 -5
View File
@@ -70,7 +70,7 @@ void ShaderCompiler::compile()
{ {
for (const auto& [matName, mat] : materials) for (const auto& [matName, mat] : materials)
{ {
work.add([=]() { //work.add([=]() {
ShaderPermutation permutation; ShaderPermutation permutation;
if (pass.positionOnly) if (pass.positionOnly)
{ {
@@ -99,12 +99,12 @@ void ShaderCompiler::compile()
layout->addDescriptorLayout(mat->getDescriptorLayout()); layout->addDescriptorLayout(mat->getDescriptorLayout());
permutation.setMaterial(mat->getName()); permutation.setMaterial(mat->getName());
createShaders(permutation, std::move(layout)); createShaders(permutation, std::move(layout));
}); //});
} }
} }
else else
{ {
work.add([=]() { //work.add([=]() {
ShaderPermutation permutation; ShaderPermutation permutation;
if (pass.positionOnly) if (pass.positionOnly)
{ {
@@ -131,11 +131,11 @@ void ShaderCompiler::compile()
layout->addDescriptorLayout(vd->getVertexDataLayout()); layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout()); layout->addDescriptorLayout(vd->getInstanceDataLayout());
createShaders(permutation, std::move(layout)); createShaders(permutation, std::move(layout));
}); //});
} }
} }
} }
getThreadPool().runAndWait(std::move(work)); //getThreadPool().runAndWait(std::move(work));
} }
void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipelineLayout layout) void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipelineLayout layout)
+24 -15
View File
@@ -137,8 +137,7 @@ void VertexData::createDescriptors()
.size = cullingOffsets.size() * sizeof(uint32), .size = cullingOffsets.size() * sizeof(uint32),
.data = (uint8*)cullingOffsets.data(), .data = (uint8*)cullingOffsets.data(),
}, },
.numElements = cullingOffsets.size(), .numElements = cullingOffsets.size()
.name = "MeshletOffset"
}); });
cullingOffsetBuffer->pipelineBarrier( cullingOffsetBuffer->pipelineBarrier(
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
@@ -151,9 +150,8 @@ void VertexData::createDescriptors()
.sourceData = { .sourceData = {
.size = numMeshlets * sizeof(uint32), .size = numMeshlets * sizeof(uint32),
}, },
.numElements = numMeshlets, .numElements = numMeshlets
.name = "MeshletCulling" });
});
cullingBuffer->pipelineBarrier( cullingBuffer->pipelineBarrier(
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
@@ -166,8 +164,7 @@ void VertexData::createDescriptors()
.size = instanceData.size() * sizeof(InstanceData), .size = instanceData.size() * sizeof(InstanceData),
.data = (uint8*)instanceData.data(), .data = (uint8*)instanceData.data(),
}, },
.numElements = instanceData.size(), .numElements = instanceData.size()
.name = "InstanceBuffer"
}); });
instanceBuffer->pipelineBarrier( instanceBuffer->pipelineBarrier(
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
@@ -182,8 +179,7 @@ void VertexData::createDescriptors()
.size = sizeof(MeshData) * instanceMeshData.size(), .size = sizeof(MeshData) * instanceMeshData.size(),
.data = (uint8*)instanceMeshData.data(), .data = (uint8*)instanceMeshData.data(),
}, },
.numElements = instanceMeshData.size(), .numElements = instanceMeshData.size()
.name = "MeshDataBuffer"
}); });
instanceMeshDataBuffer->pipelineBarrier( instanceMeshDataBuffer->pipelineBarrier(
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
@@ -236,8 +232,8 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
.bounding = meshAABB,//.toSphere(), .bounding = meshAABB,//.toSphere(),
.numMeshlets = (uint32)loadedMeshlets.size(), .numMeshlets = (uint32)loadedMeshlets.size(),
.meshletOffset = meshletOffset, .meshletOffset = meshletOffset,
}; };
meshData[id].firstIndex = indices.size(); meshData[id].firstIndex = indices.size();
meshData[id].numIndices = loadedIndices.size(); meshData[id].numIndices = loadedIndices.size();
if (!graphics->supportMeshShading()) 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 }); instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 5, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER });
// cullingOffset // cullingOffset
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 6, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER }); 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 }); cullingOffsetBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .dynamic = true }); .dynamic = true,
instanceMeshDataBuffer = 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(); instanceDataLayout->create();
resizeBuffers(); resizeBuffers();
graphics->getShaderCompiler()->registerVertexData(this); graphics->getShaderCompiler()->registerVertexData(this);
+23 -11
View File
@@ -282,8 +282,11 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint
assert(descriptor->writeDescriptors.size() == 0); assert(descriptor->writeDescriptors.size() == 0);
descriptor->bind(); descriptor->bind();
boundResources.add(descriptor.getHandle()); boundResources.add(descriptor.getHandle());
boundResources.addAll(descriptor->boundResources); for (auto binding : descriptor->boundResources)
descriptor->boundResources.clear(); {
binding->bind();
boundResources.add(binding);
}
VkDescriptorSet setHandle = descriptor->getHandle(); VkDescriptorSet setHandle = descriptor->getHandle();
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle, dynamicOffsets.size(), dynamicOffsets.data()); 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<Gfx::PDescriptorSet>& descriptorS
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>(); auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
assert(descriptorSet->writeDescriptors.size() == 0); assert(descriptorSet->writeDescriptors.size() == 0);
descriptorSet->bind(); descriptorSet->bind();
boundResources.add(descriptorSet.getHandle()); 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(); 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()); 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<uin
auto descriptor = descriptorSet.cast<DescriptorSet>(); auto descriptor = descriptorSet.cast<DescriptorSet>();
assert(descriptor->writeDescriptors.size() == 0); assert(descriptor->writeDescriptors.size() == 0);
boundResources.add(descriptor.getHandle()); boundResources.add(descriptor.getHandle());
boundResources.addAll(descriptor->boundResources);
descriptor->boundResources.clear(); for (auto binding : descriptor->boundResources)
descriptor->bind(); {
binding->bind();
boundResources.add(binding);
}
VkDescriptorSet setHandle = descriptor->getHandle(); VkDescriptorSet setHandle = descriptor->getHandle();
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle, dynamicOffsets.size(), dynamicOffsets.data()); 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<Gfx::PDescriptorSet>& descriptor
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>(); auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
assert(descriptorSet->writeDescriptors.size() == 0); assert(descriptorSet->writeDescriptors.size() == 0);
descriptorSet->bind(); descriptorSet->bind();
boundResources.add(descriptorSet.getHandle());
//std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl; //std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl;
boundResources.add(descriptorSet.getHandle()); for (auto binding : descriptorSet->boundResources)
boundResources.addAll(descriptorSet->boundResources); {
descriptorSet->boundResources.clear(); binding->bind();
boundResources.add(binding);
}
sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle(); 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()); vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, dynamicOffsets.size(), dynamicOffsets.data());
+14 -42
View File
@@ -142,9 +142,6 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() {
cachedHandles[setIndex]->allocate(); cachedHandles[setIndex]->allocate();
PDescriptorSet vulkanSet = cachedHandles[setIndex]; 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 // Found set, stop searching
return vulkanSet; return vulkanSet;
@@ -177,7 +174,9 @@ DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
, owner(owner) , owner(owner)
, bindCount(0) , bindCount(0)
, currentlyInUse(false) , currentlyInUse(false)
{} {
boundResources.resize(owner->getLayout()->getBindings().size());
}
DescriptorSet::~DescriptorSet() DescriptorSet::~DescriptorSet()
{ {
@@ -186,11 +185,6 @@ DescriptorSet::~DescriptorSet()
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) { void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) {
PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>(); PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>();
UniformBuffer* cachedBuffer = reinterpret_cast<UniformBuffer*>(cachedData[binding]);
if (vulkanBuffer->isDataEquals(cachedBuffer)) {
// std::cout << "uniform data equal, skip" << std::endl;
return;
}
bufferInfos.add(VkDescriptorBufferInfo{ bufferInfos.add(VkDescriptorBufferInfo{
.buffer = vulkanBuffer->getHandle(), .buffer = vulkanBuffer->getHandle(),
.offset = 0, .offset = 0,
@@ -208,17 +202,11 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu
.pBufferInfo = &bufferInfos.back(), .pBufferInfo = &bufferInfos.back(),
}); });
cachedData[binding] = vulkanBuffer.getHandle(); boundResources[binding] = vulkanBuffer->getAlloc();
vulkanBuffer->getAlloc()->bind();
boundResources.add(vulkanBuffer->getAlloc());
} }
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuffer) { void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuffer) {
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>(); PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
ShaderBuffer* cachedBuffer = reinterpret_cast<ShaderBuffer*>(cachedData[binding]);
if (vulkanBuffer.getHandle() == cachedBuffer) {
return;
}
bufferInfos.add(VkDescriptorBufferInfo{ bufferInfos.add(VkDescriptorBufferInfo{
.buffer = vulkanBuffer->getHandle(), .buffer = vulkanBuffer->getHandle(),
@@ -236,18 +224,11 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuff
.pBufferInfo = &bufferInfos.back(), .pBufferInfo = &bufferInfos.back(),
}); });
cachedData[binding] = vulkanBuffer.getHandle(); boundResources[binding] = vulkanBuffer->getAlloc();
vulkanBuffer->getAlloc()->bind();
boundResources.add(vulkanBuffer->getAlloc());
} }
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) { void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) {
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>(); PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
ShaderBuffer* cachedBuffer = reinterpret_cast<ShaderBuffer*>(cachedData[binding]);
if (vulkanBuffer.getHandle() == cachedBuffer) {
return;
}
bufferInfos.add(VkDescriptorBufferInfo{ bufferInfos.add(VkDescriptorBufferInfo{
.buffer = vulkanBuffer->getHandle(), .buffer = vulkanBuffer->getHandle(),
.offset = 0, .offset = 0,
@@ -265,19 +246,14 @@ void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuf
.pBufferInfo = &bufferInfos.back(), .pBufferInfo = &bufferInfos.back(),
}); });
cachedData[binding] = vulkanBuffer.getHandle(); boundResources[binding] = vulkanBuffer->getAlloc();
vulkanBuffer->getAlloc()->bind();
boundResources.add(vulkanBuffer->getAlloc());
} }
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) { void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) {
PSampler vulkanSampler = samplerState.cast<Sampler>(); PSampler vulkanSampler = samplerState.cast<Sampler>();
Sampler* cachedSampler = reinterpret_cast<Sampler*>(cachedData[binding]);
if (vulkanSampler.getHandle() == cachedSampler) {
return;
}
imageInfos.add(VkDescriptorImageInfo{ imageInfos.add(VkDescriptorImageInfo{
.sampler = vulkanSampler->sampler, .sampler = vulkanSampler->getSampler(),
.imageView = VK_NULL_HANDLE, .imageView = VK_NULL_HANDLE,
.imageLayout = VK_IMAGE_LAYOUT_UNDEFINED, .imageLayout = VK_IMAGE_LAYOUT_UNDEFINED,
}); });
@@ -293,18 +269,15 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState)
.pImageInfo = &imageInfos.back(), .pImageInfo = &imageInfos.back(),
}); });
cachedData[binding] = vulkanSampler.getHandle(); boundResources[binding] = vulkanSampler->getHandle();
} }
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) { void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle(); TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
TextureBase* cachedTexture = reinterpret_cast<TextureBase*>(cachedData[binding]);
if (vulkanTexture == cachedTexture) {
return;
}
// It is assumed that the image is in the correct layout // It is assumed that the image is in the correct layout
imageInfos.add(VkDescriptorImageInfo{ imageInfos.add(VkDescriptorImageInfo{
.sampler = samplerState != nullptr ? samplerState.cast<Sampler>()->sampler : VK_NULL_HANDLE, .sampler = samplerState != nullptr ? samplerState.cast<Sampler>()->getSampler() : VK_NULL_HANDLE,
.imageView = vulkanTexture->getView(), .imageView = vulkanTexture->getView(),
.imageLayout = cast(vulkanTexture->getLayout()), .imageLayout = cast(vulkanTexture->getLayout()),
}); });
@@ -325,13 +298,12 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
.pImageInfo = &imageInfos.back(), .pImageInfo = &imageInfos.back(),
}); });
cachedData[binding] = vulkanTexture; boundResources[binding] = vulkanTexture->getHandle();
vulkanTexture->getHandle()->bind();
boundResources.add(vulkanTexture->getHandle());
} }
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> textures) { void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> textures) {
// maybe make this a parameter? // maybe make this a parameter?
uint32 arrayElement = 0; uint32 arrayElement = 0;
boundResources.resize(binding + textures.size());
for (auto& gfxTexture : textures) { for (auto& gfxTexture : textures) {
TextureBase* vulkanTexture = gfxTexture.cast<TextureBase>().getHandle(); TextureBase* vulkanTexture = gfxTexture.cast<TextureBase>().getHandle();
imageInfos.add(VkDescriptorImageInfo{ imageInfos.add(VkDescriptorImageInfo{
@@ -344,6 +316,7 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> te
if (vulkanTexture->getUsage() & VK_IMAGE_USAGE_STORAGE_BIT) { if (vulkanTexture->getUsage() & VK_IMAGE_USAGE_STORAGE_BIT) {
descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
} }
boundResources[binding + arrayElement] = vulkanTexture->getHandle();
writeDescriptors.add(VkWriteDescriptorSet{ writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr, .pNext = nullptr,
@@ -355,7 +328,6 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> te
.pImageInfo = &imageInfos.back(), .pImageInfo = &imageInfos.back(),
}); });
vulkanTexture->getHandle()->bind(); vulkanTexture->getHandle()->bind();
boundResources.add(vulkanTexture->getHandle());
} }
} }
+1 -1
View File
@@ -67,7 +67,7 @@ private:
// contains the previously bound resources at every binding // contains the previously bound resources at every binding
// since the layout is fixed, trying to bind a texture to a buffer // since the layout is fixed, trying to bind a texture to a buffer
// would not work anyways, so casts should be safe // would not work anyways, so casts should be safe
Array<void*> cachedData; //Array<void*> cachedData;
Array<PCommandBoundResource> boundResources; Array<PCommandBoundResource> boundResources;
VkDescriptorSet setHandle; VkDescriptorSet setHandle;
PGraphics graphics; PGraphics graphics;
+1 -3
View File
@@ -217,7 +217,6 @@ Gfx::PComputePipeline Graphics::createComputePipeline(Gfx::ComputePipelineCreate
Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo) Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo)
{ {
OSampler sampler = new Sampler();
VkSamplerCreateInfo vkInfo = { VkSamplerCreateInfo vkInfo = {
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
@@ -238,8 +237,7 @@ Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo)
.borderColor = cast(createInfo.borderColor), .borderColor = cast(createInfo.borderColor),
.unnormalizedCoordinates = createInfo.unnormalizedCoordinates, .unnormalizedCoordinates = createInfo.unnormalizedCoordinates,
}; };
VK_CHECK(vkCreateSampler(handle, &vkInfo, nullptr, &sampler->sampler)); return new Sampler(this, vkInfo);
return sampler;
} }
Gfx::ODescriptorLayout Graphics::createDescriptorLayout(const std::string& name) Gfx::ODescriptorLayout Graphics::createDescriptorLayout(const std::string& name)
+21
View File
@@ -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));
}
+16 -1
View File
@@ -85,10 +85,25 @@ protected:
}; };
DEFINE_REF(CommandBoundResource) 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 class Sampler : public Gfx::Sampler
{ {
public: 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) DEFINE_REF(Sampler)
+5 -4
View File
@@ -23,12 +23,13 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
option[1].name = slang::CompilerOptionName::EmitSpirvViaGLSL; option[1].name = slang::CompilerOptionName::EmitSpirvViaGLSL;
option[1].value.kind = slang::CompilerOptionValueKind::Int; option[1].value.kind = slang::CompilerOptionValueKind::Int;
option[1].value.intValue0 = 1; 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.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].name = slang::CompilerOptionName::DebugInformationFormat;
option[3].value.kind = slang::CompilerOptionValueKind::Int; 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.compilerOptionEntries = option.data();
sessionDesc.compilerOptionEntryCount = option.size(); sessionDesc.compilerOptionEntryCount = option.size();
sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR; sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR;
@@ -43,7 +44,7 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
sessionDesc.preprocessorMacroCount = macros.size(); sessionDesc.preprocessorMacroCount = macros.size();
sessionDesc.preprocessorMacros = macros.data(); sessionDesc.preprocessorMacros = macros.data();
slang::TargetDesc targetDesc; slang::TargetDesc targetDesc;
targetDesc.profile = globalSession->findProfile("sm_6_6"); targetDesc.profile = globalSession->findProfile("spirv_1_5");
targetDesc.format = target; targetDesc.format = target;
sessionDesc.targetCount = 1; sessionDesc.targetCount = 1;
sessionDesc.targets = &targetDesc; sessionDesc.targets = &targetDesc;
+4 -4
View File
@@ -26,14 +26,14 @@ public:
template<typename... Deps> template<typename... Deps>
void setupView(Dependencies<Deps...>) void setupView(Dependencies<Deps...>)
{ {
List<std::function<void()>> work; //List<std::function<void()>> work;
registry.view<Components..., Deps...>().each([&](Components&... comp, Deps&... deps){ registry.view<Components..., Deps...>().each([&](Components&... comp, Deps&... deps){
work.add([&]() { //work.add([&]() {
(accessComponent(deps), ...); (accessComponent(deps), ...);
update(comp...); update(comp...);
}); //});
}); });
getThreadPool().runAndWait(std::move(work)); //getThreadPool().runAndWait(std::move(work));
} }
virtual void run(double delta) override virtual void run(double delta) override
{ {
+12 -12
View File
@@ -23,18 +23,18 @@ ThreadPool::~ThreadPool()
} }
} }
void ThreadPool::runAndWait(List<std::function<void()>> functions) //void ThreadPool::runAndWait(List<std::function<void()>> functions)
{ //{
std::unique_lock l(taskLock); // std::unique_lock l(taskLock);
currentTask.numRemaining = functions.size(); // currentTask.numRemaining = functions.size();
currentTask.functions = std::move(functions); // currentTask.functions = std::move(functions);
taskCV.notify_all(); // taskCV.notify_all();
//
while (currentTask.numRemaining > 0) // while (currentTask.numRemaining > 0)
{ // {
completedCV.wait(l); // completedCV.wait(l);
} // }
} //}
void ThreadPool::work() void ThreadPool::work()
{ {
+1 -1
View File
@@ -11,7 +11,7 @@ class ThreadPool
public: public:
ThreadPool(uint32 numWorkers = std::thread::hardware_concurrency()); ThreadPool(uint32 numWorkers = std::thread::hardware_concurrency());
~ThreadPool(); ~ThreadPool();
void runAndWait(List<std::function<void()>> functions); //void runAndWait(List<std::function<void()>> functions);
private: private:
struct Task struct Task
{ {