From b74d9b203ce8528e8ae292327f07b39672228300 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sun, 20 Sep 2020 17:19:12 +0100 Subject: [PATCH] Added full module example --- examples/godot_examples/.gitignore | 1 + .../godot_examples/custom_module/.gitignore | 1 + .../godot_examples/custom_module/README.md | 20 +++++++++++++ .../KomputeSummatorNode.cpp} | 26 ++++++++--------- .../KomputeSummatorNode.h} | 8 +++--- .../{ => kompute_summator}/SCsub | 3 +- .../{src => kompute_summator}/config.py | 0 .../include/kompute/Kompute.hpp | 0 .../include/vulkan/vk_icd.h | 0 .../include/vulkan/vk_layer.h | 0 .../include/vulkan/vk_platform.h | 0 .../include/vulkan/vk_sdk_platform.h | 0 .../include/vulkan/vulkan.h | 0 .../include/vulkan/vulkan.hpp | 0 .../include/vulkan/vulkan_android.h | 0 .../include/vulkan/vulkan_beta.h | 0 .../include/vulkan/vulkan_core.h | 0 .../include/vulkan/vulkan_fuchsia.h | 0 .../include/vulkan/vulkan_ggp.h | 0 .../include/vulkan/vulkan_ios.h | 0 .../include/vulkan/vulkan_macos.h | 0 .../include/vulkan/vulkan_metal.h | 0 .../include/vulkan/vulkan_vi.h | 0 .../include/vulkan/vulkan_wayland.h | 0 .../include/vulkan/vulkan_win32.h | 0 .../include/vulkan/vulkan_xcb.h | 0 .../include/vulkan/vulkan_xlib.h | 0 .../include/vulkan/vulkan_xlib_xrandr.h | 0 .../kompute_summator/register_types.cpp | 14 ++++++++++ .../register_types.h | 4 +-- .../custom_module/src/register_types.cpp | 14 ---------- .../gdnative_shared/src/config.py | 5 ---- .../godot_examples/godot_engine/.gdignore | 0 .../assets/CustomModuleExampleScene.tscn | 8 ++++++ .../scripts/CustomModuleExampleScene.gd | 28 +++++++++++++++++++ 35 files changed, 92 insertions(+), 40 deletions(-) rename examples/godot_examples/custom_module/{src/KomputeSummator.cpp => kompute_summator/KomputeSummatorNode.cpp} (79%) rename examples/godot_examples/custom_module/{src/KomputeSummator.hpp => kompute_summator/KomputeSummatorNode.h} (75%) rename examples/godot_examples/custom_module/{ => kompute_summator}/SCsub (75%) rename examples/godot_examples/custom_module/{src => kompute_summator}/config.py (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/kompute/Kompute.hpp (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vk_icd.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vk_layer.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vk_platform.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vk_sdk_platform.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan.hpp (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_android.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_beta.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_core.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_fuchsia.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_ggp.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_ios.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_macos.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_metal.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_vi.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_wayland.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_win32.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_xcb.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_xlib.h (100%) rename examples/godot_examples/custom_module/{ => kompute_summator}/include/vulkan/vulkan_xlib_xrandr.h (100%) create mode 100644 examples/godot_examples/custom_module/kompute_summator/register_types.cpp rename examples/godot_examples/custom_module/{src => kompute_summator}/register_types.h (58%) delete mode 100644 examples/godot_examples/custom_module/src/register_types.cpp delete mode 100644 examples/godot_examples/gdnative_shared/src/config.py create mode 100644 examples/godot_examples/godot_engine/.gdignore create mode 100755 examples/godot_examples/godot_resources/assets/CustomModuleExampleScene.tscn create mode 100755 examples/godot_examples/godot_resources/scripts/CustomModuleExampleScene.gd diff --git a/examples/godot_examples/.gitignore b/examples/godot_examples/.gitignore index 37f05f2b7..ee3ffe884 100644 --- a/examples/godot_examples/.gitignore +++ b/examples/godot_examples/.gitignore @@ -1 +1,2 @@ .import +godot_engine/godot diff --git a/examples/godot_examples/custom_module/.gitignore b/examples/godot_examples/custom_module/.gitignore index 95f76b1ec..1e6a0400e 100644 --- a/examples/godot_examples/custom_module/.gitignore +++ b/examples/godot_examples/custom_module/.gitignore @@ -1,2 +1,3 @@ vulkan-kompute lib +godot diff --git a/examples/godot_examples/custom_module/README.md b/examples/godot_examples/custom_module/README.md index d8e88ee00..f0f077fec 100644 --- a/examples/godot_examples/custom_module/README.md +++ b/examples/godot_examples/custom_module/README.md @@ -42,4 +42,24 @@ Now to build godot you will need to set up a couple of things for the Scons file * Copy the `kompute.lib` library from the Kompute build to `lib/kompute.lib` * Make sure the versions above match as we provide the headers in the `include` folder - if you used different versions make sure these match as well +### Clone godot repository + +Now we can clone the godot repository - it must be on a separate repository, so you can use the parent directory if you are on the Kompute repo. + +``` +cd ../../godot_engine + +git clone --branch 3.2.3-stable https://github.com/godotengine/godot + +cd godot/ +``` + +And now we can build against our module + +``` +wscons -j16 custom_modules=../../custom_module/ platform=windows target=release_debug +``` + + + diff --git a/examples/godot_examples/custom_module/src/KomputeSummator.cpp b/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.cpp similarity index 79% rename from examples/godot_examples/custom_module/src/KomputeSummator.cpp rename to examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.cpp index a206f275f..3f17f0888 100644 --- a/examples/godot_examples/custom_module/src/KomputeSummator.cpp +++ b/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.cpp @@ -2,13 +2,13 @@ #include -#include "KomputeSummator.hpp" +#include "KomputeSummatorNode.h" -KomputeSummator::KomputeSummator() { +KomputeSummatorNode::KomputeSummatorNode() { this->_init(); } -void KomputeSummator::add(float value) { +void KomputeSummatorNode::add(float value) { // Set the new data in the local device this->mSecondaryTensor->setData({value}); // Execute recorded sequence @@ -20,14 +20,14 @@ void KomputeSummator::add(float value) { } } -void KomputeSummator::reset() { +void KomputeSummatorNode::reset() { } -float KomputeSummator::get_total() const { +float KomputeSummatorNode::get_total() const { return this->mPrimaryTensor->data()[0]; } -void KomputeSummator::_init() { +void KomputeSummatorNode::_init() { std::cout << "CALLING INIT" << std::endl; this->mPrimaryTensor = this->mManager.buildTensor({ 0.0 }); this->mSecondaryTensor = this->mManager.buildTensor({ 0.0 }); @@ -74,16 +74,16 @@ void KomputeSummator::_init() { } } -void KomputeSummator::_process(float delta) { +void KomputeSummatorNode::_process(float delta) { } -void KomputeSummator::_bind_methods() { - ClassDB::bind_method(D_METHOD("_process", "delta"), &KomputeSummator::_process); - ClassDB::bind_method(D_METHOD("_init"), &KomputeSummator::_init); +void KomputeSummatorNode::_bind_methods() { + ClassDB::bind_method(D_METHOD("_process", "delta"), &KomputeSummatorNode::_process); + ClassDB::bind_method(D_METHOD("_init"), &KomputeSummatorNode::_init); - ClassDB::bind_method(D_METHOD("add", "value"), &KomputeSummator::add); - ClassDB::bind_method(D_METHOD("reset"), &KomputeSummator::reset); - ClassDB::bind_method(D_METHOD("get_total"), &KomputeSummator::get_total); + ClassDB::bind_method(D_METHOD("add", "value"), &KomputeSummatorNode::add); + ClassDB::bind_method(D_METHOD("reset"), &KomputeSummatorNode::reset); + ClassDB::bind_method(D_METHOD("get_total"), &KomputeSummatorNode::get_total); } diff --git a/examples/godot_examples/custom_module/src/KomputeSummator.hpp b/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.h similarity index 75% rename from examples/godot_examples/custom_module/src/KomputeSummator.hpp rename to examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.h index cfa1c9cc9..5bc201a90 100644 --- a/examples/godot_examples/custom_module/src/KomputeSummator.hpp +++ b/examples/godot_examples/custom_module/kompute_summator/KomputeSummatorNode.h @@ -4,13 +4,13 @@ #include "kompute/Kompute.hpp" -#include "scene/main/node_2d.h" +#include "scene/main/node.h" -class KomputeSummator : public Node2D { - GDCLASS(KomputeSummator, Node2D); +class KomputeSummatorNode : public Node { + GDCLASS(KomputeSummatorNode, Node); public: - KomputeSummator(); + KomputeSummatorNode(); void add(float value); void reset(); diff --git a/examples/godot_examples/custom_module/SCsub b/examples/godot_examples/custom_module/kompute_summator/SCsub similarity index 75% rename from examples/godot_examples/custom_module/SCsub rename to examples/godot_examples/custom_module/kompute_summator/SCsub index fc91c680e..6ce3176f4 100644 --- a/examples/godot_examples/custom_module/SCsub +++ b/examples/godot_examples/custom_module/kompute_summator/SCsub @@ -6,9 +6,8 @@ dir_path = os.getcwd() # Kompute & Vulkan header files env.Append(CPPPATH = ['include/']) -env.Append(CPPPATH = ['src/']) -env.add_source_files(env.modules_sources, "src/*.cpp") +env.add_source_files(env.modules_sources, "*.cpp") # Kompute & Vulkan libraries env.Append(LIBS=[ diff --git a/examples/godot_examples/custom_module/src/config.py b/examples/godot_examples/custom_module/kompute_summator/config.py similarity index 100% rename from examples/godot_examples/custom_module/src/config.py rename to examples/godot_examples/custom_module/kompute_summator/config.py diff --git a/examples/godot_examples/custom_module/include/kompute/Kompute.hpp b/examples/godot_examples/custom_module/kompute_summator/include/kompute/Kompute.hpp similarity index 100% rename from examples/godot_examples/custom_module/include/kompute/Kompute.hpp rename to examples/godot_examples/custom_module/kompute_summator/include/kompute/Kompute.hpp diff --git a/examples/godot_examples/custom_module/include/vulkan/vk_icd.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vk_icd.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vk_icd.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vk_icd.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vk_layer.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vk_layer.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vk_layer.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vk_layer.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vk_platform.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vk_platform.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vk_platform.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vk_platform.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vk_sdk_platform.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vk_sdk_platform.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vk_sdk_platform.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vk_sdk_platform.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan.hpp b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan.hpp similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan.hpp rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan.hpp diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_android.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_android.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_android.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_android.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_beta.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_beta.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_beta.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_beta.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_core.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_core.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_core.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_core.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_fuchsia.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_fuchsia.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_fuchsia.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_fuchsia.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_ggp.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_ggp.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_ggp.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_ggp.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_ios.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_ios.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_ios.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_ios.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_macos.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_macos.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_macos.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_macos.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_metal.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_metal.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_metal.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_metal.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_vi.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_vi.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_vi.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_vi.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_wayland.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_wayland.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_wayland.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_wayland.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_win32.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_win32.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_win32.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_win32.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_xcb.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_xcb.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_xcb.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_xcb.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_xlib.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_xlib.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_xlib.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_xlib.h diff --git a/examples/godot_examples/custom_module/include/vulkan/vulkan_xlib_xrandr.h b/examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_xlib_xrandr.h similarity index 100% rename from examples/godot_examples/custom_module/include/vulkan/vulkan_xlib_xrandr.h rename to examples/godot_examples/custom_module/kompute_summator/include/vulkan/vulkan_xlib_xrandr.h diff --git a/examples/godot_examples/custom_module/kompute_summator/register_types.cpp b/examples/godot_examples/custom_module/kompute_summator/register_types.cpp new file mode 100644 index 000000000..c04b3ecc9 --- /dev/null +++ b/examples/godot_examples/custom_module/kompute_summator/register_types.cpp @@ -0,0 +1,14 @@ +/* register_types.cpp */ + +#include "register_types.h" + +#include "core/class_db.h" +#include "KomputeSummatorNode.h" + +void register_kompute_summator_types() { + ClassDB::register_class(); +} + +void unregister_kompute_summator_types() { + // Nothing to do here in this example. +} diff --git a/examples/godot_examples/custom_module/src/register_types.h b/examples/godot_examples/custom_module/kompute_summator/register_types.h similarity index 58% rename from examples/godot_examples/custom_module/src/register_types.h rename to examples/godot_examples/custom_module/kompute_summator/register_types.h index fa64f1c7b..eeef27432 100644 --- a/examples/godot_examples/custom_module/src/register_types.h +++ b/examples/godot_examples/custom_module/kompute_summator/register_types.h @@ -1,6 +1,6 @@ /* register_types.h */ #pragma once -void register_summator_types(); -void unregister_summator_types(); +void register_kompute_summator_types(); +void unregister_kompute_summator_types(); /* yes, the word in the middle must be the same as the module folder name */ diff --git a/examples/godot_examples/custom_module/src/register_types.cpp b/examples/godot_examples/custom_module/src/register_types.cpp deleted file mode 100644 index 76dfc95d5..000000000 --- a/examples/godot_examples/custom_module/src/register_types.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/* register_types.cpp */ - -#include "register_types.h" - -#include "core/class_db.h" -#include "KomputeSummator.hpp" - -void register_summator_types() { - ClassDB::register_class(); -} - -void unregister_summator_types() { - // Nothing to do here in this example. -} diff --git a/examples/godot_examples/gdnative_shared/src/config.py b/examples/godot_examples/gdnative_shared/src/config.py deleted file mode 100644 index 1c8cd12a2..000000000 --- a/examples/godot_examples/gdnative_shared/src/config.py +++ /dev/null @@ -1,5 +0,0 @@ -def can_build(env, platform): - return True - -def configure(env): - pass diff --git a/examples/godot_examples/godot_engine/.gdignore b/examples/godot_examples/godot_engine/.gdignore new file mode 100644 index 000000000..e69de29bb diff --git a/examples/godot_examples/godot_resources/assets/CustomModuleExampleScene.tscn b/examples/godot_examples/godot_resources/assets/CustomModuleExampleScene.tscn new file mode 100755 index 000000000..a98375112 --- /dev/null +++ b/examples/godot_examples/godot_resources/assets/CustomModuleExampleScene.tscn @@ -0,0 +1,8 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://godot_resources/scripts/CustomModuleExampleScene.gd" type="Script" id=1] + +[node name="Parent" type="Node2D"] +script = ExtResource( 1 ) + +[node name="CustomKomputeNode" type="KomputeSummatorNode" parent="."] diff --git a/examples/godot_examples/godot_resources/scripts/CustomModuleExampleScene.gd b/examples/godot_examples/godot_resources/scripts/CustomModuleExampleScene.gd new file mode 100755 index 000000000..45f68783e --- /dev/null +++ b/examples/godot_examples/godot_resources/scripts/CustomModuleExampleScene.gd @@ -0,0 +1,28 @@ +extends Node2D + +# Called when the node enters the scene tree for the first time. +func _ready(): + print("hello") + + # Use existing node + print($CustomKomputeNode.get_total()) + + $CustomKomputeNode.add(10) + print($CustomKomputeNode.get_total()) + + $CustomKomputeNode.add(10) + print($CustomKomputeNode.get_total()) + + # Create new instance + var s = KomputeSummatorNode.new() + + # This will print 0 as it's a new instance + print(s.get_total()) + + # Now we can again send further commands + s.add(10) + print(s.get_total()) + + s.add(10) + print(s.get_total()) +