Skip to content

Commit

Permalink
misc: Move glslang Rust bindings to separate crate
Browse files Browse the repository at this point in the history
  • Loading branch information
caseif committed Aug 13, 2024
1 parent f800a60 commit de1f5fa
Show file tree
Hide file tree
Showing 14 changed files with 1,171 additions and 831 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ use crate::argus::render_opengl_rust::state::RendererState;
use crate::argus::render_opengl_rust::util::gl_util::*;
use render_rustabi::argus::render::*;
use resman_rustabi::argus::resman::{Resource, ResourceManager};
use shadertools::glslang::bindings::{Client, Stage, TargetClientVersion, TargetLanguageVersion};
use shadertools::shadertools::compile_glsl_to_spirv;
use spirv_cross_sys::*;
use spirv_cross_sys::bindings::*;
use std::collections::HashMap;
use std::ffi::CString;
use std::{ffi, mem, ptr};
use lowlevel_rustabi::util::cstr_to_str;
use shadertools::glslang::{Client, Stage, TargetClientVersion, TargetLanguageVersion};

#[derive(Default)]
pub(crate) struct ShaderReflectionInfo {
Expand Down Expand Up @@ -73,8 +73,8 @@ fn compile_shaders(shaders: &Vec<Resource>) -> (Vec<GlShaderHandle>, ShaderRefle
(to_shadertools_stage(shader.get_stage()), shader.get_uid())
})
.collect(),
Client::Opengl,
TargetClientVersion::Opengl450,
Client::OpenGL,
TargetClientVersion::OpenGL450,
TargetLanguageVersion::Spv1_0,
) {
Ok(res) => res,
Expand Down
1 change: 1 addition & 0 deletions engine/libs/shadertools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ crate-type = ["rlib", "staticlib"]
[dependencies]
bitmask = "0.5"
glsl = "6.0"
glslang = { path = "../../../external-bindings/glslang" }
libc = "0.2"

[features]
Expand Down
8 changes: 2 additions & 6 deletions engine/libs/shadertools/src/c_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#[path = "./glslang/mod.rs"]
mod glslang;

use core::ptr;
use libc::c_char;
use std::alloc::{alloc, dealloc, Layout};
Expand All @@ -27,8 +24,7 @@ use std::convert::TryInto;
use std::ffi::CStr;
use std::mem::{size_of, size_of_val};
use std::ptr::null;

use glslang::bindings::*;
use glslang::{Client, Stage, TargetClientVersion, TargetLanguageVersion};

#[repr(C)]
struct SizedByteArray {
Expand Down Expand Up @@ -149,7 +145,7 @@ pub unsafe extern "C" fn transpile_glsl(
) -> *mut InteropShaderCompilationResult {
let mut sources_map = HashMap::<Stage, String>::with_capacity(count.into());
for i in 0..count {
let stage = *stages.offset(i as isize);
let stage: Stage = *stages.add(i);
match CStr::from_ptr(*(glsl_sources.offset(i as isize) as *const *const c_char)).to_str() {
Ok(src_str) => {
sources_map.insert(stage, src_str.to_owned());
Expand Down
Loading

0 comments on commit de1f5fa

Please sign in to comment.