system still crashes

This commit is contained in:
Dynamitos
2025-02-02 09:39:01 +01:00
parent 3357af747a
commit 52cbdd8470
15 changed files with 69 additions and 59 deletions
+14 -5
View File
@@ -22,6 +22,11 @@ set(CMAKE_TOOLCHAIN_FILE ${EXTERNAL_ROOT}/vcpkg/scripts/buildsystems/vcpkg.cmake
set(CRCPP_ROOT ${EXTERNAL_ROOT}/CRCpp)
set(METAL_ROOT ${EXTERNAL_ROOT}/metal-cpp)
if(WIN32)
set(VCPKG_BASE_FOLDER ${VCPKG_INSTALLED_DIR}/x64-windows/)
elseif(APPLE)
set(VCPKG_BASE_FOLDER ${VCPKG_INSTALLED_DIR}/arm64-osx/)
endif()
set(Boost_NO_WARN_NEW_VERSIONS 1)
@@ -67,7 +72,7 @@ add_library(Engine SHARED "")
target_compile_definitions(Engine PRIVATE GLFW_WINDOWS)
target_include_directories(Engine PRIVATE src/Engine)
target_include_directories(Engine PRIVATE ${VCPKG_INSTALLED_DIR}/x64-windows/include/)
target_include_directories(Engine PRIVATE ${VCPKG_BASE_FOLDER}/include/)
target_link_libraries(Engine PUBLIC Vulkan::Vulkan)
target_link_libraries(Engine PUBLIC EnTT::EnTT)
target_link_libraries(Engine PUBLIC glfw)
@@ -82,11 +87,15 @@ target_link_libraries(Engine PUBLIC crcpp)
target_link_libraries(Engine PUBLIC fmt::fmt)
target_link_libraries(Engine PUBLIC unofficial::lunasvg::lunasvg)
target_link_libraries(Engine PUBLIC GPUOpen::VulkanMemoryAllocator)
target_link_libraries(Engine PUBLIC ${VCPKG_INSTALLED_DIR}/x64-windows/lib/slang.lib)
if(WIN32)
target_link_libraries(Engine PUBLIC ${VCPKG_BASE_FOLDER}/lib/slang.lib)
elseif(APPLE)
target_link_libraries(Engine PUBLIC ${VCPKG_BASE_FOLDER}/lib/libslang.dylib)
endif()
if(APPLE)
target_link_libraries(Engine PUBLIC metal)
SET(CMAKE_OSX_DEPLOYMENT_TARGET 14.3)
SET(CMAKE_OSX_DEPLOYMENT_TARGET 15.0)
endif()
if(UNIX)
target_link_libraries(Engine PUBLIC Threads::Threads)
@@ -136,8 +145,8 @@ add_subdirectory(src/)
if(WIN32)
add_custom_target(dll_copy ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Editor>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${VCPKG_INSTALLED_DIR}/x64-windows/bin/slang.dll $<TARGET_FILE_DIR:Editor>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${VCPKG_INSTALLED_DIR}/x64-windows/bin/slang-glslang.dll $<TARGET_FILE_DIR:Editor>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${VCPKG_BASE_FOLDER}/bin/slang.dll $<TARGET_FILE_DIR:Editor>
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${VCPKG_BASE_FOLDER}/bin/slang-glslang.dll $<TARGET_FILE_DIR:Editor>
COMMAND_EXPAND_LISTS
DEPENDS Editor)
elseif(APPLE)
+2 -1
View File
@@ -6,7 +6,6 @@ static const uint32_t MESH_GROUP_SIZE = 32;
struct ViewParameter
{
Frustum viewFrustum;
float4x4 viewMatrix;
float4x4 inverseViewMatrix;
float4x4 projectionMatrix;
@@ -19,6 +18,8 @@ struct ViewParameter
float2 invScreenDimensions;
uint frameIndex;
float time;
uint pad0;
uint pad1;
};
layout(set = 0)
ParameterBlock<ViewParameter> pViewParams;
-3
View File
@@ -89,9 +89,6 @@ int main() {
AssetImporter::importFont(FontImportArgs{
.filePath = "./fonts/arial.ttf",
});
AssetImporter::importFont(FontImportArgs{
.filePath = "C:\\Windows\\Fonts\\Calibri.ttf",
});
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/cube.fbx",
});
+1 -1
View File
@@ -18,7 +18,7 @@ void Actor::addChild(PActor child) {
child->setParent(this);
}
void Actor::removeChild(PActor child) {
children.remove(children.find(child), false);
children.remove(child, false);
child->setParent(nullptr);
}
+6 -7
View File
@@ -111,7 +111,6 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
}
}
}
template <typename = std::enable_if_t<std::is_copy_constructible_v<T>>>
constexpr Array(std::initializer_list<T> init, const allocator_type& alloc = allocator_type())
: arraySize(init.size()), allocated(init.size()), allocator(alloc) {
_data = allocateArray(init.size());
@@ -125,7 +124,7 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
arraySize = std::ranges::size(rg);
allocated = arraySize;
_data = allocateArray(allocated);
std::ranges::uninitialized_copy(rg.begin(), rg.end(), begin(), end());
std::uninitialized_copy(rg.begin(), rg.end(), begin());
} else {
for (auto it = std::ranges::begin(rg); it != std::ranges::end(rg); it++) {
add(*it);
@@ -296,10 +295,10 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
constexpr void remove_if(Pred pred, bool keepOrder = true) {
remove(find(pred), keepOrder);
}
constexpr void remove(const value_type& element, bool keepOrder = true) { remove(find(element), keepOrder); }
constexpr void remove(value_type&& element, bool keepOrder = true) { remove(find(element), keepOrder); }
constexpr void remove(iterator it, bool keepOrder = true) { removeAt(it - begin(), keepOrder); }
constexpr void remove(const_iterator it, bool keepOrder = true) { removeAt(it - cbegin(), keepOrder); }
constexpr void remove(const value_type& element, bool keepOrder = true) { erase(find(element), keepOrder); }
constexpr void remove(value_type&& element, bool keepOrder = true) { erase(find(element), keepOrder); }
constexpr void erase(iterator it, bool keepOrder = true) { removeAt(it - begin(), keepOrder); }
constexpr void erase(const_iterator it, bool keepOrder = true) { removeAt(it - cbegin(), keepOrder); }
constexpr void removeAt(size_type index, bool keepOrder = true) {
if (keepOrder) {
for (size_type i = index; i < arraySize - 1; ++i) {
@@ -558,4 +557,4 @@ template <typename T, size_t N> struct StaticArray {
iterator beginIt;
iterator endIt;
};
} // namespace Seele
} // namespace Seele
+1
View File
@@ -114,6 +114,7 @@ class CommandQueue {
MTL::CommandQueue* queue;
OCommand activeCommand;
Array<OCommand> pendingCommands;
Array<OCommand> readyCommands;
};
class IOCommandQueue {
public:
+24 -8
View File
@@ -40,7 +40,10 @@ void Command::present(MTL::Drawable* drawable) { cmdBuffer->presentDrawable(draw
void Command::end(PEvent signal) {
assert(!parallelEncoder);
blitEncoder->endEncoding();
if(blitEncoder)
{
blitEncoder->endEncoding();
}
if (signal != nullptr) {
cmdBuffer->encodeSignalEvent(signal->getHandle(), 1);
}
@@ -48,7 +51,9 @@ void Command::end(PEvent signal) {
cmdBuffer->commit();
}
void Command::waitDeviceIdle() { cmdBuffer->waitUntilCompleted(); }
void Command::waitDeviceIdle() {
cmdBuffer->waitUntilCompleted();
}
void Command::signalEvent(PEvent event) { cmdBuffer->encodeSignalEvent(event->getHandle(), 1); }
@@ -194,6 +199,7 @@ void ComputeCommand::dispatchIndirect(Gfx::PShaderBuffer buffer, uint32 offset){
CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) {
queue = graphics->getDevice()->newCommandQueue();
MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init();
descriptor->setErrorOptions(MTL::CommandBufferErrorOptionEncoderExecutionStatus);
activeCommand = new Command(graphics, queue->commandBuffer(descriptor));
descriptor->release();
}
@@ -214,7 +220,6 @@ void CommandQueue::executeCommands(Array<Gfx::ORenderCommand> commands) {
}
void CommandQueue::executeCommands(Array<Gfx::OComputeCommand> commands) {
submitCommands();
for (auto& command : commands) {
auto metalCmd = Gfx::PComputeCommand(command).cast<ComputeCommand>();
metalCmd->end();
@@ -225,7 +230,8 @@ void CommandQueue::submitCommands(PEvent signalSemaphore) {
activeCommand->getHandle()->addCompletedHandler(MTL::CommandBufferHandler([&](MTL::CommandBuffer* cmdBuffer) {
for (auto it = pendingCommands.begin(); it != pendingCommands.end(); it++) {
if ((*it)->getHandle() == cmdBuffer) {
pendingCommands.remove(it);
readyCommands.add(std::move(*it));
pendingCommands.erase(it);
return;
}
}
@@ -234,10 +240,20 @@ void CommandQueue::submitCommands(PEvent signalSemaphore) {
activeCommand->waitDeviceIdle();
PEvent prevCmdEvent = activeCommand->getCompletedEvent();
pendingCommands.add(std::move(activeCommand));
MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init();
descriptor->setErrorOptions(MTL::CommandBufferErrorOptionEncoderExecutionStatus);
activeCommand = new Command(graphics, queue->commandBuffer(descriptor));
activeCommand->waitForEvent(prevCmdEvent);
if(!readyCommands.empty())
{
activeCommand = std::move(readyCommands.front());
readyCommands.removeAt(0);
activeCommand->waitForEvent(prevCmdEvent);
}
else
{
MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init();
descriptor->setErrorOptions(MTL::CommandBufferErrorOptionEncoderExecutionStatus);
activeCommand = new Command(graphics, queue->commandBuffer(descriptor));
activeCommand->waitForEvent(prevCmdEvent);
descriptor->release();
}
}
IOCommandQueue::IOCommandQueue(PGraphics graphics) : graphics(graphics) {
+3 -1
View File
@@ -46,7 +46,9 @@ void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) { queue->getCommands
void Graphics::endRenderPass() { queue->getCommands()->endRenderPass(); }
void Graphics::waitDeviceIdle() { queue->getCommands()->waitDeviceIdle(); }
void Graphics::waitDeviceIdle() {
queue->submitCommands();
}
void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands) { queue->executeCommands(std::move(commands)); }
@@ -134,6 +134,7 @@ void CachedDepthPass::render() {
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
graphics->waitDeviceIdle();
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "CachedEnd");
query->endQuery();
}
@@ -270,7 +270,6 @@ void LightCullingPass::setupFrustums() {
frustumShader = graphics->createComputeShader({0});
// Have to compile shader before finalizing layout as parameters get mapped later
frustumLayout->create();
dispatchParamsLayout->create();
Gfx::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.computeShader = frustumShader;
@@ -301,6 +300,7 @@ void LightCullingPass::setupFrustums() {
frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
graphics->waitDeviceIdle();
Gfx::PDescriptorSet dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
dispatchParamsSet->updateBuffer(0, 0, frustumDispatchParamsBuffer);
dispatchParamsSet->updateBuffer(1, 0, frustumBuffer);
@@ -315,4 +315,7 @@ void LightCullingPass::setupFrustums() {
graphics->executeCommands(std::move(commands));
frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
graphics->waitDeviceIdle();
Frustum* frustums = (Frustum*)frustumBuffer->map();
std::cout << frustums << std::endl;
}
+2 -24
View File
@@ -7,7 +7,7 @@ RenderPass::RenderPass(Gfx::PGraphics graphics) : graphics(graphics) {
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = 576,//sizeof(ViewParameter),
.uniformLength = sizeof(ViewParameter),
});
UniformBufferCreateInfo uniformInitializer = {
.sourceData =
@@ -28,28 +28,6 @@ void RenderPass::beginFrame(const Component::Camera& cam) {
Matrix4 cameraMatrix = cam.getViewMatrix();
Matrix4 projectionMatrix = viewport->getProjectionMatrix();
viewParams = {
.viewFrustum =
{
.planes =
{
Plane{
.n = Vector(-0.62628, 0, 0.7796),
.d = 3.898,
},
Plane{
.n = Vector(0.62628, 0, 0.7796),
.d = 3.898,
},
Plane{
.n = Vector(0, 0.81915, 0.57358),
.d = 2.86788,
},
Plane{
.n = Vector(0, -0.81915, 0.57358),
.d = 2.86788,
},
},
},
.viewMatrix = cameraMatrix,
.inverseViewMatrix = glm::inverse(cameraMatrix),
.projectionMatrix = projectionMatrix,
@@ -82,7 +60,7 @@ void RenderPass::beginFrame(const Component::Camera& cam) {
corners[i] = world / world.w;
}
extract_planes_from_view_projection_matrix(viewParams.viewProjectionMatrix, viewParams.viewFrustum);
//extract_planes_from_view_projection_matrix(viewParams.viewProjectionMatrix, viewParams.viewFrustum);
viewParamsBuffer->rotateBuffer(sizeof(ViewParameter));
viewParamsBuffer->updateContents(0, sizeof(ViewParameter), &viewParams);
+2 -1
View File
@@ -50,7 +50,6 @@ class RenderPass {
void extract_planes_from_view_projection_matrix(const Matrix4 viewProj, Frustum& frustum);
struct ViewParameter {
Frustum viewFrustum;
Matrix4 viewMatrix;
Matrix4 inverseViewMatrix;
Matrix4 projectionMatrix;
@@ -63,6 +62,8 @@ class RenderPass {
Vector2 invScreenDimensions;
uint32 frameIndex;
float time;
uint32 pad0;
uint32 pad1;
} viewParams;
PRenderGraphResources resources;
Gfx::ODescriptorLayout viewParamsLayout;
+1
View File
@@ -125,6 +125,7 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
}
//createInfo.typeParameter.add({Pair<const char*, const char*>("IVertexData", permutation.vertexDataName)});
createInfo.modules.add(permutation.vertexDataName);
//createInfo.dumpIntermediate = true;
if (permutation.useMeshShading) {
if (permutation.hasTaskShader) {
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "Graphics/Descriptor.h"
#include "ShaderExpression.h"
#include <atomic>
namespace Seele {
+7 -7
View File
@@ -79,12 +79,12 @@ template <uint32 ml, uint32 mr, uint32 mt, uint32 mb> struct MarginClass {
};
#define DECLARE_MARGIN_CLASSES(x) \
using M_##x = MarginClass<x, x, x, x>; \
using M_X##x = MarginClass<x, x, -1, -1>; \
using M_Y##x = MarginClass<-1, -1, x, x>; \
using M_L##x = MarginClass<x, -1, -1, -1>; \
using M_R##x = MarginClass<-1, x, -1, -1>; \
using M_T##x = MarginClass<-1, -1, x, -1>; \
using M_B##x = MarginClass<-1, -1, -1, x>;
using M_X##x = MarginClass<x, x, -1u, -1u>; \
using M_Y##x = MarginClass<-1u, -1u, x, x>; \
using M_L##x = MarginClass<x, -1u, -1u, -1u>; \
using M_R##x = MarginClass<-1u, x, -1u, -1u>; \
using M_T##x = MarginClass<-1u, -1u, x, -1u>; \
using M_B##x = MarginClass<-1u, -1u, -1u, x>;
DECLARE_MARGIN_CLASSES(0)
DECLARE_MARGIN_CLASSES(1)
@@ -105,4 +105,4 @@ DECLARE_MARGIN_CLASSES(20)
DECLARE_MARGIN_CLASSES(24)
} // namespace Seele
} // namespace Seele