From c9c9e1e7b83eefe41579fcc0ca7ab228a8d1cab1 Mon Sep 17 00:00:00 2001 From: Kolja Lubitz Date: Thu, 6 Jan 2022 22:47:36 +0100 Subject: [PATCH 1/4] Fix MacOS Build --- src/plugins/metal/src/metal_material_constant_buffer.h | 2 +- src/plugins/metal/src/metal_material_constant_buffer.mm | 3 +-- src/plugins/metal/src/metal_painter.mm | 8 ++++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/plugins/metal/src/metal_material_constant_buffer.h b/src/plugins/metal/src/metal_material_constant_buffer.h index 715b5dfb11..55948348c9 100644 --- a/src/plugins/metal/src/metal_material_constant_buffer.h +++ b/src/plugins/metal/src/metal_material_constant_buffer.h @@ -9,7 +9,7 @@ namespace Halley public: explicit MetalMaterialConstantBuffer(MetalVideo& video); ~MetalMaterialConstantBuffer(); - void update(const MaterialDataBlock& dataBlock) override; + void update(gsl::span data) override; void bindVertex(id encoder, int bindPoint); void bindFragment(id encoder, int bindPoint); private: diff --git a/src/plugins/metal/src/metal_material_constant_buffer.mm b/src/plugins/metal/src/metal_material_constant_buffer.mm index 806f20a1f8..434c507729 100644 --- a/src/plugins/metal/src/metal_material_constant_buffer.mm +++ b/src/plugins/metal/src/metal_material_constant_buffer.mm @@ -11,10 +11,9 @@ MetalMaterialConstantBuffer::~MetalMaterialConstantBuffer() {} -void MetalMaterialConstantBuffer::update(const MaterialDataBlock& dataBlock) { +void MetalMaterialConstantBuffer::update(gsl::span data) { // We must pad up to a multiple of 16 (float4) // TODO we ought to move this somewhere it won't be called so often. - auto data = dataBlock.getData(); const size_t padding = alignUp(data.size_bytes(), 16); auto padded = malloc(data.size_bytes() + padding); diff --git a/src/plugins/metal/src/metal_painter.mm b/src/plugins/metal/src/metal_painter.mm index 922c908e6f..18117031f6 100644 --- a/src/plugins/metal/src/metal_painter.mm +++ b/src/plugins/metal/src/metal_painter.mm @@ -8,7 +8,7 @@ using namespace Halley; MetalPainter::MetalPainter(MetalVideo& video, Resources& resources) - : Painter(resources) + : Painter(video, resources) , video(video) , indexBuffer(nil) {} @@ -43,7 +43,8 @@ [encoder setRenderPipelineState:pipelineState]; // Metal requires the global material to be bound for each material pass, as it has no 'global' state. - static_cast(halleyGlobalMaterial->getDataBlocks().front().getConstantBuffer()).bindVertex(encoder, 0); + // static_cast(halleyGlobalMaterial->getDataBlocks().front().getConstantBuffer()).bindVertex(encoder, 0); + static_cast(getConstantBuffer(halleyGlobalMaterial->getDataBlocks().front())).bindVertex(encoder, 0); // Bind textures int texIndex = 0; @@ -127,13 +128,12 @@ void MetalPainter::setMaterialData(const Material& material) { for (auto& dataBlock : material.getDataBlocks()) { if (dataBlock.getType() != MaterialDataBlockType::SharedExternal) { - static_cast(dataBlock.getConstantBuffer()).bindFragment(encoder, 0); + static_cast(getConstantBuffer(dataBlock)).bindFragment(encoder, 0); } } } void MetalPainter::onUpdateProjection(Material& material) { - material.uploadData(*this); setMaterialData(material); } From f1b0704020f27356c61c286636a80d99ec0fd2b9 Mon Sep 17 00:00:00 2001 From: Kolja Lubitz Date: Tue, 11 Jan 2022 22:24:24 +0100 Subject: [PATCH 2/4] CMake fix for USE_METAL 0 --- src/tools/editor/CMakeLists.txt | 10 ++++++---- src/tools/editor/src/halley_editor.cpp | 8 ++++---- src/tools/launcher/CMakeLists.txt | 8 +++++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/tools/editor/CMakeLists.txt b/src/tools/editor/CMakeLists.txt index e9cc2e8054..ff0137207f 100644 --- a/src/tools/editor/CMakeLists.txt +++ b/src/tools/editor/CMakeLists.txt @@ -28,7 +28,7 @@ set (editor_sources "src/assets/graph/graph_editor.cpp" "src/assets/graph/render_graph_editor.cpp" "src/assets/graph/ui_graph_node.cpp" - + "src/project/core_api_wrapper.cpp" "src/scene/choose_window.cpp" @@ -115,7 +115,7 @@ set (editor_headers "src/scene/gizmos/scripting/scripting_gizmo_toolbar.h" "src/scene/gizmos/scripting/scripting_gizmo.h" "src/scene/gizmos/scripting/scripting_node_editor.h" - + "src/ui/console_window.h" "src/ui/ecs_window.h" "src/ui/editor_settings_window.h" @@ -143,8 +143,10 @@ set (editor_gen_definitions ) -if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND USE_METAL EQUAL 1) set(EXTRA_LIBS bz2 z halley-metal) +elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(EXTRA_LIBS bz2 z) elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(EXTRA_LIBS pthread) endif() @@ -153,7 +155,7 @@ include_directories(${FREETYPE_INCLUDE_DIR} "../tools/include") halleyProjectCodegen(halley-editor "${editor_sources}" "${editor_headers}" "${editor_resources}" "${editor_gen_definitions}" ${CMAKE_CURRENT_SOURCE_DIR}/../../../bin) add_dependencies(halley-editor halley-cmd halley-core halley-net halley-sdl halley-opengl) -if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND USE_METAL EQUAL 1) add_dependencies(halley-editor halley-metal) endif() diff --git a/src/tools/editor/src/halley_editor.cpp b/src/tools/editor/src/halley_editor.cpp index ec7927c4b4..d354cea9f8 100644 --- a/src/tools/editor/src/halley_editor.cpp +++ b/src/tools/editor/src/halley_editor.cpp @@ -33,12 +33,12 @@ int HalleyEditor::initPlugins(IPluginRegistry ®istry) #ifdef _WIN32 initDX11Plugin(registry); -#elif __APPLE__ +#elif defined(__APPLE__) && defined(USE_METAL) initMetalPlugin(registry); #else initOpenGLPlugin(registry); #endif - + return HalleyAPIFlags::Video | HalleyAPIFlags::Audio | HalleyAPIFlags::Input | HalleyAPIFlags::Network; } @@ -138,7 +138,7 @@ std::unique_ptr HalleyEditor::loadProject(Path path) project->loadGameResources(getAPI()); preferences->addRecent(path.string()); - + return project; } @@ -153,7 +153,7 @@ std::unique_ptr HalleyEditor::createProject(Path path) } preferences->addRecent(path.string()); - + return project; } diff --git a/src/tools/launcher/CMakeLists.txt b/src/tools/launcher/CMakeLists.txt index 52469d8c79..0a1b35a657 100644 --- a/src/tools/launcher/CMakeLists.txt +++ b/src/tools/launcher/CMakeLists.txt @@ -35,8 +35,10 @@ set (launcher_gen_definitions ) -if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND USE_METAL EQUAL 1) set(EXTRA_LIBS bz2 z halley-metal) +elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(EXTRA_LIBS bz2 z) elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(EXTRA_LIBS pthread) endif() @@ -45,8 +47,8 @@ include_directories(${FREETYPE_INCLUDE_DIR} "../tools/include") halleyProjectCodegen(halley-launcher "${launcher_sources}" "${launcher_headers}" "" "${launcher_gen_definitions}" ${CMAKE_CURRENT_SOURCE_DIR}/bin) add_dependencies(halley-launcher halley-cmd halley-core halley-net halley-sdl halley-opengl) -if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - add_dependencies(halley-launcher halley-metal) +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND USE_METAL EQUAL 1) + add_dependencies(halley-editor halley-metal) endif() get_property(deps GLOBAL PROPERTY halley_external_plugin_dependencies) From 64f6e61190b78d5fa9e08667fe0a1feed5e9544c Mon Sep 17 00:00:00 2001 From: Kolja Lubitz Date: Tue, 11 Jan 2022 22:26:44 +0100 Subject: [PATCH 3/4] Fix Copy and Paste Error --- src/tools/launcher/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/launcher/CMakeLists.txt b/src/tools/launcher/CMakeLists.txt index 0a1b35a657..780930187e 100644 --- a/src/tools/launcher/CMakeLists.txt +++ b/src/tools/launcher/CMakeLists.txt @@ -48,7 +48,7 @@ include_directories(${FREETYPE_INCLUDE_DIR} "../tools/include") halleyProjectCodegen(halley-launcher "${launcher_sources}" "${launcher_headers}" "" "${launcher_gen_definitions}" ${CMAKE_CURRENT_SOURCE_DIR}/bin) add_dependencies(halley-launcher halley-cmd halley-core halley-net halley-sdl halley-opengl) if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND USE_METAL EQUAL 1) - add_dependencies(halley-editor halley-metal) + add_dependencies(halley-launcher halley-metal) endif() get_property(deps GLOBAL PROPERTY halley_external_plugin_dependencies) From 895e5ae482787eb09185928625e1ee9be3845fbc Mon Sep 17 00:00:00 2001 From: Kolja Lubitz Date: Thu, 13 Jan 2022 22:15:29 +0100 Subject: [PATCH 4/4] Fix include --- .../net/include/halley/net/session/network_session.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/engine/net/include/halley/net/session/network_session.h b/src/engine/net/include/halley/net/session/network_session.h index 03da7b35f2..b7dadbe6ce 100644 --- a/src/engine/net/include/halley/net/session/network_session.h +++ b/src/engine/net/include/halley/net/session/network_session.h @@ -6,7 +6,7 @@ #include "network_session_messages.h" #include "shared_data.h" #include "network_session_control_messages.h" -#include "connection/network_service.h" +#include "../connection/network_service.h" namespace Halley { class NetworkService; @@ -50,7 +50,7 @@ namespace Halley { virtual void onHosting(); virtual void onConnected(int peerId); virtual void onDisconnected(int peerId); - + private: NetworkService& service; NetworkSessionType type = NetworkSessionType::Undefined; @@ -79,7 +79,7 @@ namespace Halley { void checkForOutboundStateChanges(int ownerId); OutboundNetworkPacket makeUpdateSharedDataPacket(int ownerId); - + OutboundNetworkPacket doMakeControlPacket(NetworkSessionControlMessageType msgType, OutboundNetworkPacket packet); void onConnection(NetworkService::Acceptor& acceptor); @@ -95,7 +95,7 @@ namespace Halley { { return static_cast(doGetMutableSessionSharedData()); } - + const SessionSharedDataType& getSessionSharedData() const { return static_cast(doGetSessionSharedData()); @@ -121,7 +121,7 @@ namespace Halley { { return std::make_unique(); } - + std::unique_ptr makePeerSharedData() override final { return std::make_unique();