Skip to content
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

egui gfx backend #295

Merged
merged 48 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3c14a85
Change using crate::* crate::shardsc::* where applicable
guusw Jun 23, 2022
9c50d72
Remove unused
guusw Jun 29, 2022
bc505cc
Disable vsync
guusw Jun 27, 2022
be3baa3
Add shader Compound append. Viewport shader global. Disable debug by …
guusw Jun 9, 2022
2c63b95
Fix GeneratorContext::getTexture generating an error on non-existing …
guusw Jun 25, 2022
969ef1d
Override backend from GFX_BACKEND env. Use vulkan backend on windows.
guusw Jun 28, 2022
468b6f5
Return correct OS scaling factor from Window::getDrawScale
guusw Jun 28, 2022
57c82d1
Add resizable_item_pool from DynamicWGPUBufferPool
guusw Jun 30, 2022
fa36483
Add custom init for resizable_item_pool
guusw Jun 24, 2022
0a49154
Add getters for Texture. Add TextureFormatFlags::None
guusw Jun 30, 2022
0dfa810
Add egui gfx integration & standalone test
guusw Jun 22, 2022
1c8d340
Show FPS in test & small cleanup
guusw Jun 30, 2022
6639202
Apply screen rect & draw scale
guusw Jun 30, 2022
b54802d
Add rust EXCLUDE_DEPENDS
guusw Jun 29, 2022
d3e86d4
Add rust_interop header for bindgen
guusw Jun 29, 2022
7e780bc
Integrate egui rendering into UI shard
guusw Jun 30, 2022
9948080
Fix missing header
guusw Jun 29, 2022
f166b09
Point shardsc.rs to generated bindings
guusw Jun 29, 2022
0261636
Fix generated binding allowlists
guusw Jun 29, 2022
869d4fe
Reorder functions. Add Window::getVirtualDrawableSize
guusw Jun 29, 2022
b8363ed
Use automatic c++ gfx bindings where posible. Bundle rust build scrip…
guusw Jun 30, 2022
5b47d35
Fixes for gcc bindings
guusw Jun 30, 2022
57cb6c4
Add missing build script crate
guusw Jun 30, 2022
47a7ad6
Remove empty header
guusw Jun 30, 2022
1100018
Remove unused
guusw Jun 30, 2022
8d79464
Fix egui shader flags default value
guusw Jun 30, 2022
020c418
Fix BUILD_STANDALONE_EGUI_TEST flag usage
guusw Jun 30, 2022
8dd7241
Remove direct usage of webgpu headers
guusw Jun 30, 2022
65baa45
Fixes for emscripten bindgen
guusw Jun 30, 2022
282378a
Use --sysroot=
guusw Jun 30, 2022
f7284bc
Fix missing header
guusw Jun 30, 2022
297fb96
Allow unstable thiscall on x86 windows
guusw Jul 1, 2022
df28f7e
Force windows CI to run D3D12. Fix ios bindgen sysroot
guusw Jul 1, 2022
4f57a25
Force test_gfx to run under D3D12 on CI
guusw Jul 1, 2022
c0aa23f
Also enable feature(abi_thiscall) on the shards rust project
guusw Jul 1, 2022
dbff1f5
Pass correct sysroot to bindgen but keep host SDKROOT
guusw Jul 1, 2022
af45dd0
Minor fixes & formatting
guusw Jul 1, 2022
6a05c14
Explicitly add bindgen system c++ include path
guusw Jul 1, 2022
7895a21
Force GFX_BACKEND=D3D12 when running samples
guusw Jul 1, 2022
1dce379
Only set BINDGEN_EXTRA_CLANG_ARGS if required
guusw Jul 1, 2022
a56c5dd
Assert on renderer createBindGroup
guusw Jul 2, 2022
2cd3652
Fix texture sub-region updates
guusw Jul 2, 2022
d16349f
Add line info to context.cpp logs
guusw Jul 3, 2022
75cf827
Don't create texture layout based on material
guusw Jul 3, 2022
604f5fe
Detect recreation of swapchain
guusw Jul 3, 2022
612ac4c
Give bind groups a label
guusw Jul 3, 2022
53d7b04
Add some comments about the workings of osx_rust_build.sh
guusw Jul 4, 2022
a63213e
Run rustfmt
guusw Jul 1, 2022
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
3 changes: 2 additions & 1 deletion .github/workflows/build-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
- name: Run samples
shell: msys2 {0}
run: |
export GFX_BACKEND=D3D12
cd docs/samples
for i in $(find shards -name '*.edn');
do
Expand Down Expand Up @@ -135,7 +136,7 @@ jobs:
git config --global user.name "Fragcolor bot"
git config --global user.email "[email protected]"
mkdocs gh-deploy --force --message "Publish documentation from {sha}

Using MkDocs {version}."
- name: Upload artifact
uses: actions/upload-artifact@v2
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ jobs:
run: |
cd build
ninja test_gfx
GFX_TEST_PLATFORM_ID="github-windows" ./test_gfx
GFX_BACKEND=D3D12 GFX_TEST_PLATFORM_ID="github-windows" ./test_gfx
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
Expand Down Expand Up @@ -303,6 +303,7 @@ jobs:
RUST_BACKTRACE: 1
shell: msys2 {0}
run: |
export GFX_BACKEND=D3D12
cd build
echo "Running test: gfx_window"
./shards ../src/tests/gfx_window.edn
Expand Down
72 changes: 46 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 28 additions & 3 deletions cmake/Rust.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ endmacro()

# Need this custom build script to inherit the correct SDK variables from XCode
if(IOS)
set(RUST_BUILD_SCRIPT "${CMAKE_SOURCE_DIR}/cmake/osx_rust_build.sh")
set(RUST_BUILD_SCRIPT "${CMAKE_SOURCE_DIR}/cmake/osx_rust_build.sh" ${XCODE_SDK})
endif()

# Defines a rust target
Expand All @@ -108,6 +108,7 @@ function(add_rust_library)
FEATURES # (Optional) List of features to pass to rust build
ENVIRONMENT # (Optional) Environment variables
DEPENDS # (Optional) Extra file-level dependencies
EXCLUDE_DEPENDS # (Optional) Extra file-level dependencies to ignore
)
cmake_parse_arguments(RUST "${OPTS}" "${ARGS}" "${MULTI_ARGS}" ${ARGN})

Expand All @@ -128,6 +129,9 @@ function(add_rust_library)
if(RUST_TEMP_SOURCES)
list(REMOVE_ITEM RUST_SOURCES ${RUST_TEMP_SOURCES})
endif()
if(RUST_EXCLUDE_DEPENDS)
list(REMOVE_ITEM RUST_SOURCES ${RUST_EXCLUDE_DEPENDS})
endif()
message(VERBOSE " RUST_SOURCES: ${RUST_SOURCES}")

if(RUST_CARGO_TARGET)
Expand Down Expand Up @@ -156,9 +160,30 @@ function(add_rust_library)

set(RUST_CRATE_TYPE_ARG --crate-type staticlib)

# When the compiler can't automatically provide include paths (emscripten):
# pass the sysroot to the bindgen clang arguments
if(EMSCRIPTEN_SYSROOT)
file(TO_CMAKE_PATH "${EMSCRIPTEN_SYSROOT}" TMP_SYSROOT)
list(APPEND EXTRA_CLANG_ARGS "--sysroot=${TMP_SYSROOT}")
endif()

if(EMSCRIPTEN)
# Required to have some symbols be exported
# https://github.com/rust-lang/rust-bindgen/issues/751
list(APPEND EXTRA_CLANG_ARGS "-fvisibility=default")
endif()

if(EXTRA_CLANG_ARGS)
set(BINDGEN_EXTRA_CLANG_ARGS BINDGEN_EXTRA_CLANG_ARGS="${EXTRA_CLANG_ARGS}")
endif()

if(RUST_TARGET_PATH)
list(APPEND RUST_ENVIRONMENT "CARGO_TARGET_DIR=${RUST_TARGET_PATH}")
endif()

add_custom_command(
OUTPUT ${GENERATED_LIB_PATH}
COMMAND ${CMAKE_COMMAND} -E env RUSTFLAGS="${RUST_FLAGS}" ${RUST_ENVIRONMENT} ${RUST_BUILD_SCRIPT} ${CARGO_EXE} ${RUST_CARGO_TOOLCHAIN} rustc ${RUST_CARGO_UNSTABLE_FLAGS} ${RUST_FEATURES_ARG} ${RUST_CRATE_TYPE_ARG} ${RUST_TARGET_ARG} ${RUST_CARGO_FLAGS}
COMMAND ${CMAKE_COMMAND} -E env RUSTFLAGS="${RUST_FLAGS}" ${BINDGEN_EXTRA_CLANG_ARGS} ${RUST_ENVIRONMENT} ${RUST_BUILD_SCRIPT} ${CARGO_EXE} ${RUST_CARGO_TOOLCHAIN} rustc ${RUST_CARGO_UNSTABLE_FLAGS} ${RUST_FEATURES_ARG} ${RUST_CRATE_TYPE_ARG} ${RUST_TARGET_ARG} ${RUST_CARGO_FLAGS}
WORKING_DIRECTORY ${RUST_PROJECT_PATH}
DEPENDS ${RUST_SOURCES} ${RUST_DEPENDS}
USES_TERMINAL
Expand All @@ -176,4 +201,4 @@ function(add_rust_library)
set_target_properties(${RUST_TARGET_NAME} PROPERTIES
IMPORTED_LOCATION ${GENERATED_LIB_PATH}
)
endfunction()
endfunction()
13 changes: 12 additions & 1 deletion cmake/osx_rust_build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#!/bin/bash
# Script to work around some issues when calling `cargo build`/`cargo rustc` from Xcode for iOS
#
# The SDKROOT needs to be set to the HOST SDKROOT so that build scripts are able to build
# if not, it results in linker errors similar to this issue https://github.com/TimNN/cargo-lipo/issues/41
#
# Additionally, bindgen needs to be passed the sysroot for the target platform to be able to find the system headers

set -ex
SDKROOT=`xcrun --sdk macosx --show-sdk-path` $@
TARGET_SDKROOT=`xcrun --sdk $1 --show-sdk-path`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this script? I need to run this all the time on Mac? If so annoying.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it's only for iOS.

There's some issues because the build process runs through Xcode and sets the SDKROOT environment variables.
It was similar to this issue TimNN/cargo-lipo#41 (unrelated repo)

Additionally bindgen needs some additional clang parameters to find the correct include files for iOS (similar to https://github.com/gfx-rs/wgpu-native/blob/91e14b8ffda0a5ec1d87fd27b7b9e8e62495720d/build.rs#L99)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document it? We need some iOS instructions at least.

shift
export SDKROOT=`xcrun --sdk macosx --show-sdk-path`
export BINDGEN_EXTRA_CLANG_ARGS="-isysroot $TARGET_SDKROOT -isystem $TARGET_SDKROOT/usr/include/c++/v1 $BINDGEN_EXTRA_CLANG_ARGS"
$@
7 changes: 5 additions & 2 deletions rust/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
set(FEATURES shards run_bindgen)
set(FEATURES shards)

if(RUST_SHLISP)
list(APPEND FEATURES scripting)
endif()

# Bindgen dependency
list(APPEND EXTRA_SOURCES ${SHARDS_DIR}/include/shards.h)
list(APPEND EXTRA_SOURCES ${SHARDS_DIR}/src/extra/rust_interop.hpp ${SHARDS_DIR}/include/shards.h)

# egui integration sources
file(GLOB_RECURSE EXTRA_SOURCES "${SHARDS_DIR}/src/gfx/egui/src/*.rs")

if(ANDROID OR LINUX)
set(NEED_OPENSSL_SYS ON)
Expand Down
7 changes: 4 additions & 3 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ parity-scale-codec = { version = "2.3.1", default-features = false, optional = t
chacha20poly1305 = { version = "0.9.0", optional = true }
egui = { version = "0.18.1", optional = true }
half = { version = "1.8.2" }
egui-gfx = { path = "../src/gfx/egui"}

[target.'cfg(not(target_arch="wasm32"))'.dependencies]
dlopen = { version = "0.1.8", optional = true }
Expand All @@ -48,7 +49,8 @@ webbrowser = { version = "0.5.5", optional = true }
ctor = "0.1.16"

[build-dependencies]
bindgen = { version = "0.59.1", optional = true }
bindgen = { version = "0.60.1" }
gfx-build = { path = "../src/gfx/rust/build" }

[features]
default = []
Expand All @@ -75,8 +77,7 @@ shards = ["reqwest",
"chacha20poly1305",
"egui"]
dllshard = ["dlopen"]
run_bindgen = ["bindgen"]
scripting = []

[profile.release]
panic = "abort"
panic = "abort"
38 changes: 23 additions & 15 deletions rust/build.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/* Copyright © 2020 Fragcolor Pte. Ltd. */

#[cfg(feature = "run_bindgen")]
extern crate bindgen;
extern crate gfx_build;
use std::env;
use std::path::PathBuf;

#[cfg(feature = "run_bindgen")]
fn bindgen_it() {
fn generate_shardsc() {
use std::env::var;

let shards_dir = var("SHARDS_DIR").unwrap_or("../".to_string());
let shards_dir = var("SHARDS_DIR").unwrap_or("..".to_string());
let shards_include_dir = format!("{}/include", shards_dir);
let src_extra_dir = format!("{}/src/extra", shards_dir);
let gfx_path = format!("{}/src/gfx", shards_dir);

println!("cargo:rustc-link-search={}/build", shards_dir);
// Tell cargo to invalidate the built crate whenever the wrapper changes
println!("cargo:rerun-if-changed={}/include/shards.h", shards_dir);
let main_header_path = format!("{}/rust_interop.hpp", src_extra_dir);

let header_path = shards_dir + "/include/shards.h";
// Tell cargo to regenerate the bindings whenever the headers change
println!("cargo:rerun-if-changed={}/shards.h", shards_include_dir);
println!("cargo:rerun-if-changed={}", main_header_path);

let bindings = bindgen::Builder::default()
.header(header_path)
let builder = gfx_build::setup_bindgen_for_gfx(gfx_path.as_str(), bindgen::Builder::default());
let bindings = builder
.header(main_header_path)
.clang_arg("-DSH_NO_ANON")
.clang_arg("-DSH_USE_ENUMS")
.allowlist_type("SH.*")
.allowlist_var("SH.*")
.allowlist_function("SH.*")
.clang_arg(format!("-I{}", shards_include_dir))
.clang_arg(format!("-I{}/src", shards_dir))
.derive_default(true)
.use_core()
.generate()
.expect("Unable to generate bindings");

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file("src/shardsc.rs")
.write_to_file(out_path.join("shardsc.rs"))
.expect("Couldn't write bindings!");

println!("Done processing shards.h");
}

#[cfg(not(feature = "run_bindgen"))]
fn bindgen_it() {}

fn main() {
bindgen_it();
generate_shardsc();
}
1 change: 1 addition & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/* Copyright © 2020 Fragcolor Pte. Ltd. */

#![cfg_attr(all(target_os = "windows", target_arch = "x86"), feature(abi_thiscall))]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
Expand Down
Loading