# Copyright 2018 Jacob Lifshay
[workspace]
members = [
+ "shader-compiler",
+ "shader-compiler-llvm-7",
"vulkan-driver",
]
apt-get install -y \
clang-7 \
libclang-7-dev \
+ llvm-7-dev \
cmake \
ninja-build \
libgl1-mesa-dev \
COPY external/ external/
COPY Cargo.toml Cargo.toml
COPY vulkan-driver/Cargo.toml vulkan-driver/build.rs vulkan-driver/vulkan-wrapper.h vulkan-driver/
+COPY shader-compiler/Cargo.toml shader-compiler/
+COPY shader-compiler-llvm-7/Cargo.toml shader-compiler-llvm-7/
RUN set -e; \
mkdir -p vulkan-driver/src; \
+ mkdir -p shader-compiler/src; \
+ mkdir -p shader-compiler-llvm-7/src; \
echo "// empty" > vulkan-driver/src/lib.rs; \
+ echo "// empty" > shader-compiler/src/lib.rs; \
+ echo "// empty" > shader-compiler-llvm-7/src/lib.rs; \
cargo build; \
- rm vulkan-driver/src/lib.rs
+ rm */src/lib.rs
COPY . .
-RUN touch -c vulkan-driver/src/lib.rs && cargo build
+RUN touch -c */src/lib.rs && cargo build
CMD ["./run-cts.sh", "--no-update"]
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# Copyright 2018 Jacob Lifshay
+[package]
+name = "shader-compiler-llvm-7"
+version = "0.1.0"
+authors = ["Jacob Lifshay <programmerjake@gmail.com>"]
+license = "LGPL-2.1-or-later"
+
+[lib]
+crate-type = ["rlib"]
+
+[dependencies]
+shader-compiler = {path = "../shader-compiler"}
+llvm-sys = "70"
--- /dev/null
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright 2018 Jacob Lifshay
+use llvm_sys;
+use shader_compiler::backend::*;
+use std::ffi::CString;
+use std::os::raw::c_char;
+
+#[repr(transparent)]
+pub struct LLVM7Context(llvm_sys::prelude::LLVMContextRef);
+
+impl Drop for LLVM7Context {
+ fn drop(&mut self) {
+ unsafe {
+ llvm_sys::core::LLVMContextDispose(self.0);
+ }
+ }
+}
+
+unsafe impl Send for LLVM7Context {}
+
+impl<'a> Context<'a> for LLVM7Context {
+ type Module = LLVM7Module;
+ fn create_module(&self, name: &str) -> LLVM7Module {
+ let name = CString::new(name).unwrap();
+ unsafe {
+ LLVM7Module(llvm_sys::core::LLVMModuleCreateWithNameInContext(
+ name.as_ptr(),
+ self.0,
+ ))
+ }
+ }
+}
+
+#[repr(transparent)]
+pub struct LLVM7Module(llvm_sys::prelude::LLVMModuleRef);
+
+impl Drop for LLVM7Module {
+ fn drop(&mut self) {
+ unsafe {
+ llvm_sys::core::LLVMDisposeModule(self.0);
+ }
+ }
+}
+
+impl<'a> Module<'a> for LLVM7Module {
+ fn set_source_file_name(&mut self, source_file_name: &str) {
+ unsafe {
+ llvm_sys::core::LLVMSetSourceFileName(
+ self.0,
+ source_file_name.as_ptr() as *const c_char,
+ source_file_name.len(),
+ )
+ }
+ }
+}
+
+pub struct LLVM7ShaderCompiler;
+
+impl ShaderCompiler for LLVM7ShaderCompiler {
+ fn name() -> &'static str {
+ "LLVM 7"
+ }
+ fn run_with_user<SCU: ShaderCompilerUser>(shader_compiler_user: SCU) -> SCU::ReturnType {
+ let context = unsafe { LLVM7Context(llvm_sys::core::LLVMContextCreate()) };
+ shader_compiler_user.run_with_context(&context)
+ }
+}
--- /dev/null
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright 2018 Jacob Lifshay
+extern crate llvm_sys;
+extern crate shader_compiler;
+
+mod backend;
+
+pub fn create_shader_compiler() -> backend::LLVM7ShaderCompiler {
+ backend::LLVM7ShaderCompiler
+}
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# Copyright 2018 Jacob Lifshay
+[package]
+name = "shader-compiler"
+version = "0.1.0"
+authors = ["Jacob Lifshay <programmerjake@gmail.com>"]
+license = "LGPL-2.1-or-later"
+
+[lib]
+crate-type = ["rlib"]
+
+[dependencies]
--- /dev/null
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright 2018 Jacob Lifshay
+#![deny(missing_docs)]
+
+//! Shader Compiler for Kazan
+
+/// Shader Compiler Backend traits
+pub mod backend {
+ /// equivalent to LLVM's 'Module'
+ pub trait Module<'a> {
+ /// set's the source file name for this module
+ fn set_source_file_name(&mut self, source_file_name: &str);
+ }
+
+ /// instance of a compiler backend; equivalent to LLVM's `LLVMContext`
+ pub trait Context<'a> {
+ /// the `Module` type
+ type Module: Module<'a>;
+ /// create a new `Module`
+ fn create_module(&self, name: &str) -> Self::Module;
+ }
+
+ /// trait that the user of `ShaderCompiler` implements
+ pub trait ShaderCompilerUser {
+ /// the return type of `run_with_context`
+ type ReturnType;
+ /// the function that the user of `ShaderCompiler` implements
+ fn run_with_context<'a, C: Context<'a>>(self, context: &'a C) -> Self::ReturnType;
+ }
+
+ /// main shader compiler backend trait
+ pub trait ShaderCompiler: Send + Sync + 'static {
+ /// get shader compiler's name
+ fn name() -> &'static str;
+ /// run a passed-in function with a new compiler context.
+ /// this round-about method is used because generic associated types are not in stable Rust yet
+ fn run_with_user<SCU: ShaderCompilerUser>(shader_compiler_user: SCU) -> SCU::ReturnType;
+ }
+}
enum-map = "0.4"
uuid = {version = "0.7", features = ["v5"]}
sys-info = "0.5"
+shader-compiler = {path = "../shader-compiler"}
+shader-compiler-llvm-7 = {path = "../shader-compiler-llvm-7"}
[target.'cfg(unix)'.dependencies]
xcb = {version = "0.8", features = ["shm"]}
extern crate errno;
#[cfg(unix)]
extern crate libc;
+extern crate shader_compiler;
extern crate sys_info;
extern crate uuid;
#[cfg(unix)]