Git Product home page Git Product logo

spirv-reflect-rs's Introduction

spirv-reflect

spirv-reflect on travis-ci.com Latest version Documentation MIT APACHE2

Reflection API in rust for SPIR-V shader byte code, intended for Vulkan applications.

This crate provides an FFI layer and idiomatic rust wrappers for the excellent SPIRV-Reflect C/C++ library.

Features

  • Extract descriptor bindings from SPIR-V bytecode, to assist in the generation of Vulkan descriptor set and pipeline layouts.
  • Extract push constant block size from SPIR-V bytecode to assist in the generation of pipeline layouts.
  • Extract full layout data for uniform buffer and push constant blocks from SPIR-V bytecode, to assist in application updates of these structures.
  • Extract input/output variables from SPIR-V bytecode (including semantic decorations for HLSL shaders), to assist in validation of pipeline input/output settings.
  • Easily map Vulkan types to DirectX 12 resource types
  • Remap descriptor bindings, and update the source SPIR-V bytecode accordingly.
  • Log all reflection data as human-readable text.

Planned Features

  • Extensive unit tests and examples.
  • Pure rust version.
  • Command line tool for reflection and manipulation.

Usage

Add this to your Cargo.toml:

[dependencies]
spirv-reflect = "0.2.3"

and add this to your crate root:

extern crate spirv_reflect;

Example

Currently there is only a single monolithic demo example, which shows some usage. A CLI tool is planned that will be useful on its own, and as a clean example of usage patterns.

cargo run --release --example demo

License

Licensed under either of

at your option.

Credits and Special Thanks

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Contributions are always welcome; please look at the issue tracker to see what known improvements are documented.

Code of Conduct

Contribution to the spirv-reflect crate is organized under the terms of the Contributor Covenant, the maintainer of spirv-reflect, @gwihlidal, promises to intervene to uphold that code of conduct.

spirv-reflect-rs's People

Contributors

alexene avatar arthurkvalladares avatar frizi avatar georgeouzou avatar gwihlidal avatar jasper-bekkers avatar jaynus avatar jefffrey avatar lcnr avatar marijns95 avatar ralith avatar thehamsta avatar tomsmalley avatar veykril avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spirv-reflect-rs's Issues

Remove "parallel" feature from `cc` dependency

Since you're only compiling one c file we don't need the parallel feature and thus it can be turned off for cc, this makes the list of dependencies quite a bit smaller since it doesn't need to drag in rayon speeding up (clean) build times.

Why does ShaderModule::get_code returned a Vec instead of a slice?

It looks like the native function returns a const pointer. I think this could be safely changed to:

    pub fn get_code(&self) -> &[u32] {
        static EMPTY: &[u32] = &[];
        match self.module {
            Some(ref module) => {
                let code_size = unsafe { ffi::spvReflectGetCodeSize(module) as usize };
                let code_slice = unsafe {
                    std::slice::from_raw_parts(ffi::spvReflectGetCode(module), code_size / 4)
                };
                code_slice
            }
            None => EMPTY,
        }
    }

For reference:

https://github.com/jaynus/SPIRV-Reflect/blob/300aeab3d4bd7c36968e5ef10fe30b2a8c5d45bc/spirv_reflect.h#L456-L460

/*! @fn spvReflectGetCode
 @param  p_module  Pointer to an instance of SpvReflectShaderModule.
 @return           Returns a const pointer to the compiled SPIR-V bytecode.
*/
const uint32_t* spvReflectGetCode(const SpvReflectShaderModule* p_module);

Null pointer causing crash in debug builds.

I suspect there is a bug in the library. In particular at line:

let ffi_members =

It seems like it is possible for ffi_type.members to be null if ffi_type.member_count is 0. However, rust considers this unsafe and will return the error:

unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`

Thus no application using this crate can run correctly in debug mode.

OS: ubuntu 22.04
crate version: 0.2.3
rustc version: rustc 1.78.0-nightly (ef324565d 2024-02-27)

0.2.3 does not build with sccache on macOS

Trying to compile the examples for bevy on macOS I get spirv-reflect failing:
os: macOS 10.15.6
compiler: Apple clang 11.0.3

warning: error: invalid argument '-std=c++11' not allowed with 'C'

error: failed to run custom build command for `spirv-reflect v0.2.3`

Caused by:
  process didn't exit successfully: `/Users/moritz/code/crates/bevy/target/debug/build/spirv-reflect-e0c20f0369bf5f90/build-script-build` (exit code: 1)
  --- stdout
  TARGET = Some("x86_64-apple-darwin")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-apple-darwin")
  CXX_x86_64-apple-darwin = None
  CXX_x86_64_apple_darwin = None
  HOST_CXX = None
  CXX = None
  CXXFLAGS_x86_64-apple-darwin = None
  CXXFLAGS_x86_64_apple_darwin = None
  HOST_CXXFLAGS = None
  CXXFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("cmpxchg16b,fxsr,mmx,sse,sse2,sse3,ssse3")
  running: "sccache" "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-arch" "x86_64" "-stdlib=libc++" "-I" "src" "-Wall" "-Wextra" "-std=c++11" "-Wno-missing-field-initializers" "-Wno-sign-compare" "-Wno-deprecated" "-o" "/Users/moritz/code/crates/bevy/target/debug/build/spirv-reflect-c4be2b0e2b8154af/out/vendor/spirv_reflect.o" "-c" "vendor/spirv_reflect.c"
  cargo:warning=error: invalid argument '-std=c++11' not allowed with 'C'
  exit code: 1

  --- stderr


  error occurred: Command "sccache" "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-arch" "x86_64" "-stdlib=libc++" "-I" "src" "-Wall" "-Wextra" "-std=c++11" "-Wno-missing-field-initializers" "-Wno-sign-compare" "-Wno-deprecated" "-o" "/Users/moritz/code/crates/bevy/target/debug/build/spirv-reflect-c4be2b0e2b8154af/out/vendor/spirv_reflect.o" "-c" "vendor/spirv_reflect.c" with args "c++" did not execute successfully (status code exit code: 1).

I guess this is LLVM/clang asking to be concise. If vendor/spirv_reflect.c is C, omit C++ flags. If it is C++, rename it to vendor/spirv_reflect.cpp. But that's just a guess.

Update spirv_headers to 1.4.1

Please consider using version 1.4.1 of spirv_headers.
They removed num_derive which depends on syn (slow build).
This would optimize your build time and help other crates depending on this (see amethyst/rendy#203).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.