Skip to content

Guus/param var conv #1146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
869c2bb
Rewrite core join shards
guusw May 26, 2025
12b6ad1
Rewrite core sort/remove
guusw May 26, 2025
e53d301
Move ReferencedVar to utility.hpp as TVarOrReference
guusw May 26, 2025
15d5488
Rewrite core Slice shard
guusw May 27, 2025
d9f2867
Upgrade spdlog
guusw May 27, 2025
7e0b421
Remove unused variable
guusw May 27, 2025
620fc42
Fix entt warning on string literal operator
guusw May 27, 2025
e22cbc9
Update paramVarToShaderParameter paramvar usage
guusw May 27, 2025
705602a
Move temp allocator log and fix
guusw May 28, 2025
6c4be6f
Move coro annotations
guusw May 28, 2025
8ac60b9
Fix slice default variables
guusw May 28, 2025
3e94de7
Fix implicit conversion of Var to TableVar in formatting
guusw May 30, 2025
6db4b9e
Shards anim remove gfx dependency
guusw May 30, 2025
4ce8162
Allow each union to specify it's own registry/inline header by duplic…
guusw Jun 2, 2025
995fe98
Missing inline on coro functions
guusw Jun 2, 2025
06ba491
Fix
guusw Jun 2, 2025
f2033ca
Fix headers
guusw Jun 2, 2025
404247b
Fix gfx header dependencies
guusw Jun 3, 2025
581d1dc
Fix header path
guusw Jun 3, 2025
fa6bdac
Fix all references to gfx headers with <shards/gfx
guusw Jun 3, 2025
c7b8970
Add wgpu-headers dependency for bindings.hpp
guusw Jun 3, 2025
b16cfc5
Fix duplicated target type
Jun 3, 2025
6d9435f
Fix CMAKE_PROPERTIES_TO_DUPLICATE scan
guusw Jun 3, 2025
fee6518
Fix coverage paths
guusw Jun 4, 2025
794fe5e
Missing stdarg
guusw Jun 4, 2025
8839e81
Cleanup TReferencedVar
guusw Jun 4, 2025
f897257
Add FS.ReplaceExtension
guusw Jun 5, 2025
b96ea21
std if extensions
guusw Jun 5, 2025
a2c7de1
Add @cond-eval to speed up large if blocks
guusw Jun 5, 2025
6559608
Use cond-eval for hot reload
guusw Jun 5, 2025
3a70d7b
Rename cond-eval to if
guusw Jun 5, 2025
4687a0f
wgpu-headers target detection
guusw Jun 6, 2025
659d85f
Fix shard inside @if
guusw Jun 9, 2025
929ecde
Expose sleep call that support chrono::nanoseconds. Fix channel outpu…
guusw Jun 9, 2025
f874dc8
Fix tracy enable on union & add GFX.DisplayRefreshRate shard
guusw Jun 10, 2025
5f40042
Fix BufferedConsumer temporary return value
guusw Jun 10, 2025
768a313
Fix tracy-client not being added to root cargo
guusw Jun 10, 2025
7dd64e2
Missing stdarg
guusw Jun 3, 2025
779da01
Fix wgpu-headers usage for wasm
guusw Jun 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ jobs:
lcov \
--capture \
--directory build/src \
--directory build/modules \
--output-file coverage/coverage.info
# remove external dependencies
lcov \
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test-macos-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ jobs:
lcov \
--capture \
--directory build/src \
--directory build/modules \
--output-file coverage/coverage.info \
--ignore-errors inconsistent,gcov,range,format
# remove external dependencies
Expand Down
39 changes: 25 additions & 14 deletions cmake/Modules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@ option(SHARDS_WITH_DEFAULT "Default SHARDS_WITH_<name> state of modules" OFF)
# The same happens for the rust modules
#
# If you have any dependencies between the two, you should link both targets against each other in a ciruclar fashion
# on the final executable target, e.g.:
# target_link_libraries(shards-rust_union shards-cpp-union)
# target_link_libraries(shards-cpp-union shards-rust-union)
# on the final executable target, e.g.:
# target_link_libraries(shards-rust_union shards-cpp-union)
# target_link_libraries(shards-cpp-union shards-rust-union)
#
# If any of the cpp modules for example has a dependency that needs any rust code (for example, gfx, gfx-core)
# you need to link in that dependency as an OBJECT library as well, so it will be in the same static union lib
#
# Since you can not chain OBJECT libraries in cmake (it will miss the lowest level objects)
# you can set up an intermediate interface target like this:
# add_library(gfx-texture-file-obj OBJECT texture_file/texture_file.cpp)
# add_library(gfx-texture-file-obj OBJECT texture_file/texture_file.cpp)
#
# add_library(gfx-texture-file INTERFACE)
# target_sources(gfx-texture-file PUBLIC $<TARGET_OBJECTS:gfx-texture-file-obj>)
# target_link_libraries(gfx-texture-file INTERFACE gfx-texture-file-obj)
# add_library(gfx-texture-file INTERFACE)
# target_sources(gfx-texture-file PUBLIC $<TARGET_OBJECTS:gfx-texture-file-obj>)
# target_link_libraries(gfx-texture-file INTERFACE gfx-texture-file-obj)
#
# gfx-texture-file can then be linked into a module as usual, e.g.:
# target_link_libraries(shards-module-gfx gfx-texture-file)

# target_link_libraries(shards-module-gfx gfx-texture-file)
function(is_module_enabled OUTPUT_VARIABLE MODULE_ID)
if(${SHARDS_WITH_EVERYTHING})
set(${OUTPUT_VARIABLE} TRUE PARENT_SCOPE)
Expand Down Expand Up @@ -207,6 +206,7 @@ function(shards_generate_rust_union TARGET_NAME)
get_property(RUST_FEATURES TARGET ${RUST_TARGET} PROPERTY RUST_FEATURES)
unset(RUST_FEATURES_STRING)
unset(RUST_FEATURES_STRING1)

if(RUST_FEATURES)
unset(RUST_FEATURES_QUOTED)

Expand Down Expand Up @@ -257,6 +257,9 @@ function(shards_generate_rust_union TARGET_NAME)
file(COPY_FILE ${CARGO_TOML}.tmp ${CARGO_TOML} ONLY_IF_DIFFERENT)

unset(ENABLED_FEATURES)
if(TRACY_ENABLE)
list(APPEND ENABLED_FEATURES tracy)
endif()

# Add the rust library
add_rust_library(NAME ${TARGET_NAME}
Expand Down Expand Up @@ -311,8 +314,8 @@ function(shards_generate_union UNION_TARGET_NAME)
)
endif()

target_compile_definitions(${UNION_TARGET_NAME} PRIVATE
SHARDS_CORE_DLL=1
target_compile_definitions(${UNION_TARGET_NAME} PRIVATE
SHARDS_CORE_DLL=1
shards_core_EXPORTS=1)

foreach(TARGET_NAME ${SHARDS_MODULE_TARGETS})
Expand All @@ -321,6 +324,7 @@ function(shards_generate_union UNION_TARGET_NAME)
if(UNION_EXTRA_ENABLED_MODULES)
if(NOT "${MODULE_ID}" IN_LIST UNION_EXTRA_ENABLED_MODULES)
message(DEBUG "Skipping module ${MODULE_ID}")
message(VERBOSE "Not enabled in set: ${UNION_EXTRA_ENABLED_MODULES}")
continue()
else()
message(DEBUG "Including module ${MODULE_ID}")
Expand All @@ -333,10 +337,16 @@ function(shards_generate_union UNION_TARGET_NAME)
endif()
endif()

message(DEBUG "${UNION_TARGET_NAME}: Adding module ${TARGET_NAME} (id: ${MODULE_ID})")
target_link_libraries(${UNION_TARGET_NAME} ${TARGET_NAME})
list(APPEND ENABLED_MODULE_IDS ${MODULE_ID})
list(APPEND ENABLED_MODULE_TARGETS ${TARGET_NAME})

set(DUP_TARGET_NAME "${UNION_TARGET_NAME}_${TARGET_NAME}")
duplicate_library_target(${TARGET_NAME} OBJECT ${DUP_TARGET_NAME})
message(DEBUG "${UNION_TARGET_NAME}: Adding module ${TARGET_NAME} (as: ${DUP_TARGET_NAME}, id: ${MODULE_ID})")
target_link_libraries(${UNION_TARGET_NAME} ${DUP_TARGET_NAME})

# Add the generated include path to the module duplicate
target_include_directories(${DUP_TARGET_NAME} PUBLIC ${GENERATED_ROOT_DIR})
endforeach()

# message(STATUS "ENABLED_MODULE_IDS ${ENABLED_MODULE_IDS}")
Expand All @@ -349,7 +359,8 @@ function(shards_generate_union UNION_TARGET_NAME)
set(GENERATED_TEMP "${CMAKE_CURRENT_BINARY_DIR}/temp.cpp")

# Add include path to shards core so it can inline the code that is generated here
target_include_directories(shards-core PUBLIC ${GENERATED_ROOT_DIR})
# target_include_directories(shards-core PUBLIC ${GENERATED_ROOT_DIR})
target_include_directories(${UNION_TARGET_NAME} PUBLIC ${GENERATED_ROOT_DIR})

file(WRITE ${GENERATED_TEMP}
"// This file is generated by CMake\n"
Expand Down
7 changes: 6 additions & 1 deletion cmake/Utils.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Get all propreties that cmake supports
if(NOT CMAKE_PROPERTIES_TO_DUPLICATE)
execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTIES_TO_DUPLICATE)
execute_process(COMMAND ${CMAKE_COMMAND} --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTIES_TO_DUPLICATE)

# Convert command output into a CMake list
string(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTIES_TO_DUPLICATE "${CMAKE_PROPERTIES_TO_DUPLICATE}")
Expand All @@ -12,17 +12,21 @@ if(NOT CMAKE_PROPERTIES_TO_DUPLICATE)
"INTERFACE_CXX_MODULE_HEADER_UNIT_SETS" "CXX_MODULE_HEADER_UNIT_SETS"
"INTERFACE_CXX_MODULE_SETS" "CXX_MODULE_SETS"
"BINARY_DIR" "IMPORTED" "SOURCE_DIR"
"MANUALLY_ADDED_DEPENDENCIES"
)

foreach(IGNORED_PROPERTY ${IGNORED_PROPERTIES})
list(REMOVE_ITEM CMAKE_PROPERTIES_TO_DUPLICATE ${IGNORED_PROPERTY})
endforeach()

message(VERBOSE "CMAKE_PROPERTIES_TO_DUPLICATE: ${CMAKE_PROPERTIES_TO_DUPLICATE}")
endif()

# Helper function that duplicates a library target into a new type
# This allows defining a static library and duplicating it into a shared library target (with different defines, etc.)
function(duplicate_library_target TARGET TYPE NEW_TARGET)
add_library(${NEW_TARGET} ${TYPE})
message(VERBOSE "Duplicating library target ${TARGET} into ${NEW_TARGET} of type ${TYPE}")

foreach(PROPERTY ${CMAKE_PROPERTIES_TO_DUPLICATE})
string(REPLACE "<CONFIG>" "${CMAKE_BUILD_TYPE}" PROPERTY ${PROPERTY})
Expand All @@ -37,6 +41,7 @@ function(duplicate_library_target TARGET TYPE NEW_TARGET)
if(IS_PROPERTY_SET)
get_target_property(VALUE ${TARGET} ${PROPERTY})
set_target_properties(${NEW_TARGET} PROPERTIES ${PROPERTY} "${VALUE}")
# message(VERBOSE "Setting ${PROPERTY} to ${VALUE}")
endif()
endforeach()

Expand Down
5 changes: 4 additions & 1 deletion cmake/rust/union_Cargo.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ version = "${CARGO_CRATE_VERSION}"
edition = "2021"

[features]
tracy = []
tracy = ["tracy-client"]

[dependencies]
${CARGO_CRATE_DEPS}
tracy-client = { version = "0.17.4", optional = true }

[patch.crates-io]
chrono = { git = "https://github.com/shards-lang/chrono", rev = "5aaf74235778120b5984b46ced47478c1431d9a0" }
Expand All @@ -27,6 +28,8 @@ onig_sys = { git = "https://github.com/shards-lang/rust-onig.git", version = "=6
objc = { git = "https://github.com/shards-lang/rust-objc.git", version = "=0.2.7", branch = "shards-0.2.7" }
metal = { git = "https://github.com/shards-lang/metal-rs.git", version = "=0.29.0", branch = "shards-0.29.0" }

tracy-client = { git = "https://github.com/nagisa/rust_tracy_client", tag = "tracy-client-v0.15.0" }

[profile.dev.package]
tiny-skia = { opt-level = 3 }
resvg = { opt-level = 3 }
Expand Down
2 changes: 1 addition & 1 deletion deps/entt
2 changes: 1 addition & 1 deletion deps/spdlog
Submodule spdlog updated 175 files
4 changes: 4 additions & 0 deletions include/shards/dllshard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class Core {
return sCore._core->referenceVariable(context, name);
}

static SHVar *findVariable(SHContext *context, struct SHStringWithLen name) {
return sCore._core->findVariable(context, name);
}

static void releaseVariable(SHVar *variable) { return sCore._core->releaseVariable(variable); }

static SHWireState suspend(SHContext *context, double seconds) { return sCore._core->suspend(context, seconds); }
Expand Down
3 changes: 3 additions & 0 deletions include/shards/shards.h
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ typedef void(__cdecl *SHUnregisterRunLoopCallback)(SHString eventName);
typedef void(__cdecl *SHUnregisterExitCallback)(SHString eventName);

typedef struct SHVar *(__cdecl *SHReferenceVariable)(struct SHContext *context, struct SHStringWithLen name);
typedef struct SHVar *(__cdecl *SHFindVariable)(struct SHContext *context, struct SHStringWithLen name);
typedef struct SHVar *(__cdecl *SHReferenceWireVariable)(SHWireRef wire, struct SHStringWithLen name);

typedef struct SHExternalVariable {
Expand Down Expand Up @@ -1292,6 +1293,8 @@ typedef struct _SHCore {
// We never needed it before but actually useful to expose for rust and swift shards
SHReferenceVariable referenceGlobalVariable;

SHFindVariable findVariable;

//! ADD NEW FUNCTIONS AT BOTTOM OF THIS STRUCT
} SHCore;

Expand Down
51 changes: 48 additions & 3 deletions include/shards/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,12 @@ template <class SH_CORE> struct TTableVar : public SHVar {

TTableVar(const TTableVar &other) : SHVar() { SH_CORE::cloneVar(*this, other); }

TTableVar(const SHVar &other) : SHVar() {
explicit TTableVar(const SHVar &other) : SHVar() {
assert(other.valueType == SHType::Table);
SH_CORE::cloneVar(*this, other);
}

TTableVar(SHVar &&other) : SHVar() {
explicit TTableVar(SHVar &&other) : SHVar() {
assert(other.valueType == SHType::Table);
std::swap<SHVar>(*this, *reinterpret_cast<TTableVar *>(&other));
}
Expand Down Expand Up @@ -710,7 +710,7 @@ template <class SH_CORE> struct TSeqVar : public SHVar {

TSeqVar(TSeqVar &&other) : SHVar() { std::swap<SHVar>(*this, other); }

TSeqVar(SHVar &&other) : SHVar() {
explicit TSeqVar(SHVar &&other) : SHVar() {
assert(other.valueType == SHType::Seq);
std::swap<SHVar>(*this, other);
}
Expand Down Expand Up @@ -842,6 +842,49 @@ ALWAYS_INLINE inline void assignVariableValue(SHVar &v, const SHVar &other) {
v.version = other.version;
}

template <class SH_CORE> struct TVarOrReference {
const SHVar *ptr;
SHVar *owned = nullptr;

TVarOrReference(SHContext *context, const SHVar &v) : ptr(&v) {
if (v.valueType == SHType::ContextVar) {
if (auto var = SH_CORE::findVariable(context, toSWL(SHSTRVIEW(v)))) {
ptr = var;
owned = var;
} else {
throw std::runtime_error(fmt::format("Variable {} not found", SHSTRVIEW(v)));
}
}
}

TVarOrReference(SHContext *context, const char *varName) : ptr(nullptr) {
if (auto var = SH_CORE::findVariable(context, toSWL(varName))) {
ptr = var;
owned = var;
} else {
throw std::runtime_error(fmt::format("Variable {} not found", varName));
}
}

~TVarOrReference() {
if (owned) {
SH_CORE::releaseVariable(const_cast<SHVar *>(owned));
}
}

TVarOrReference(const TVarOrReference &) = delete;
TVarOrReference &operator=(const TVarOrReference &) = delete;
TVarOrReference(TVarOrReference &&) = delete;
TVarOrReference &operator=(TVarOrReference &&) = delete;

bool isVariable() const { return owned != nullptr; }

const SHVar &get() const { return *ptr; }
operator const SHVar &() const { return *ptr; }
SHVar &get() { return const_cast<SHVar &>(*ptr); }
operator SHVar &() { return const_cast<SHVar &>(*ptr); }
};

}; // namespace shards

// specialize hash for TOwnedVar
Expand All @@ -851,4 +894,6 @@ template <typename T> struct hash<shards::TOwnedVar<T>> {
};
} // namespace std

template <typename SH_CORE> auto format_as(const shards::TOwnedVar<SH_CORE> &ov) { return (SHVar &)ov; }

#endif
4 changes: 1 addition & 3 deletions lib/hot-reload.shs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@include("std/if.shs" Once: true)
@define(script-hot-reload false IgnoreRedefined: true)

; Builds wrapper wires around imported hot-reloadable wires
Expand Down Expand Up @@ -148,8 +147,7 @@
})

@inline-template(maybe-hot-reload [script-path wires] {
@if-root(@script-hot-reload {
; #(Log("Running hot reload macro"))
@if(@script-hot-reload {
@hot-reload(@script-dir @include-dirs @namespace script-path wires)
} {
@include(script-path)
Expand Down
42 changes: 29 additions & 13 deletions lib/std/if.shs
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
@template(if-filter-ast [] {
If({ExpectTable | Take("shs") | IsSeq} {
ExpectTable | Take("shs")
} {
= in
[in]
}
)
})
@macro(if-root [cond yes no] {
@template(filter-ast [] {
If({ExpectTable | Take("shs") | IsSeq} {
ExpectTable | Take("shs")
} {
= in
[in]
}
)
})

Sequence(pipelines)
cond | If(IsAny([true "true" 1]) {
@ast(yes) | FromJson | @filter-ast()
@ast(yes) | FromJson | @if-filter-ast()
} {
@ast(no) | FromJson | @if-filter-ast()
}
) | ToJson
})

@macro(when [cond yes] {
cond | If(IsAny([true "true" 1]) {
@ast(yes) | FromJson | @if-filter-ast()
} {
[[]]
}
) | ToJson
})

@macro(when-not [cond no] {
cond | If(IsAny([true "true" 1]) {
[[]]
} {
@ast(no) | FromJson | @filter-ast()
@ast(no) | FromJson | @if-filter-ast()
}
) | ToJson
})
25 changes: 25 additions & 0 deletions shards/core/check_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef C25C0EEE_CC07_432E_9764_0EC84FA97064
#define C25C0EEE_CC07_432E_9764_0EC84FA97064

#include <shards/shards.hpp>
#include "exception.hpp"

namespace shards {
inline void checkType(const SHType &type, SHType expectedType, const char *name) {
if (type != expectedType)
throw formatException("{} type should be {}, was {}", name, magic_enum::enum_name(expectedType), magic_enum::enum_name(type));
}

inline void checkEnumType(const SHVar &var, const shards::Type &expectedType, const char *name) {
checkType(var.valueType, SHType::Enum, name);
shards::Type actualType = shards::Type::Enum(var.payload.enumVendorId, var.payload.enumTypeId);
if (expectedType != actualType) {
SHTypeInfo typeInfoA = expectedType;
SHTypeInfo typeInfoB = actualType;
throw formatException("{} enum type should be {}/{}, was {}/{}", name, typeInfoA.enumeration.vendorId,
typeInfoA.enumeration.typeId, typeInfoB.enumeration.vendorId, typeInfoB.enumeration.typeId);
}
}
} // namespace shards

#endif /* C25C0EEE_CC07_432E_9764_0EC84FA97064 */
Loading
Loading