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

Vulkan backend (first steps) #983

Merged
merged 69 commits into from
Aug 12, 2016
Merged
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
9daffe1
Dummy vulkan backend/window projects
sectopod Apr 29, 2016
812fd87
[vk] basic application info
sectopod Apr 30, 2016
280126c
[vk] successful instance creation
sectopod May 1, 2016
8a9129b
[vk] basic device queries
sectopod May 1, 2016
2e262a8
[vk] Removed ApplicationInfo
sectopod May 2, 2016
d620460
[vk] basic device creation
sectopod May 2, 2016
dbcc311
[vk] basic swapchain creation
sectopod May 3, 2016
37b26e1
[vk] - graphics queue selection
sectopod May 11, 2016
617c2e7
[vk] dummy command buffer and graphics queue
sectopod May 11, 2016
9e11262
Removed clone_empty() and implemented gfx_app::Factory for simpler cb…
sectopod May 11, 2016
4f4b3c0
[vk] implemented submit()
sectopod May 12, 2016
8eb42e3
[vk] factory mock
sectopod May 12, 2016
188ab22
[vk] moved the backend into the Arc-shared struct
sectopod May 12, 2016
9262429
[vk] command buffer creation, refactored all error checks
sectopod May 12, 2016
78b0e2f
[vk] added missing BeginCommandInfo calls
sectopod May 13, 2016
987fbb7
[vk] added Shader struct
sectopod May 13, 2016
c24159e
[vk] Shader creation and deletion
sectopod May 13, 2016
ebfc11d
[vk] Texture creation
sectopod May 14, 2016
e0102c5
[vk] added data module for enum translation
sectopod May 14, 2016
f067cd7
[vk] format translation
sectopod May 14, 2016
5e974a4
[vk] image layout and flags
sectopod May 14, 2016
375dc5c
[vk] sampler creation
sectopod May 14, 2016
ac751c1
[vk] xcb surface hookup for the window
sectopod May 15, 2016
2d005e5
[vk] updated to vk-sys change, it's no longer a generator
sectopod May 16, 2016
958c6cc
[vk] image views
sectopod May 17, 2016
ed2ff5d
[vk] RTV and SRV creation/deletion
sectopod May 17, 2016
0a24537
[vk] creating swapchain target views
sectopod May 17, 2016
ea25e88
[vk] frame and swapchain mechanics
sectopod May 18, 2016
ce254eb
[vk] image barriers for the presentable layouts
sectopod May 18, 2016
67529f4
[vk] extended RTV/SRV to also carry the layout and sub range
sectopod May 19, 2016
c06425c
[vk] color clear command
sectopod May 19, 2016
a4686b7
[vk] validation layers support
sectopod May 19, 2016
a9c47e0
[vk] querying proper memory types
sectopod May 20, 2016
fb706e7
[vk] buffer creation and deletion
sectopod May 20, 2016
28d1cf9
[vk] refined buffer memory allocation
sectopod May 20, 2016
8f82b55
[vk] first bits of pipelines
sectopod May 20, 2016
4379b5f
[vk] minor refactor of the unsafe vulkan calls
sectopod May 20, 2016
7f95281
[vk] dummy pipeline layout and descriptor pool creation for PSO
sectopod May 20, 2016
2082434
[vk] PSO deletion
sectopod May 20, 2016
2b3d2c2
[vk] dummy program creation
sectopod May 22, 2016
d77b456
[vk] pipeline shader stages
sectopod May 22, 2016
fd58a15
[vk] added render pass to the pipeline
sectopod May 22, 2016
c32e7fe
[vk] implemented rough create_buffer_const_raw()
sectopod May 22, 2016
87eebc4
[vk] render pass attachments
sectopod May 23, 2016
924637a
[vk] render sub pass
sectopod May 23, 2016
f5de795
[pso] Moved the buffer descriptor out of the AttributeDesc
sectopod May 23, 2016
ab7ab55
[vk] pipeline vertex attributes
sectopod May 23, 2016
b309095
[vk] pipeline input assembly
sectopod May 24, 2016
e5c16ba
[vk] pipeline viewport, scissor, and dynamic state
sectopod May 24, 2016
f3d4c9f
[vk] pipeline rasterization state
sectopod May 24, 2016
cdb5ac9
[vk] pipeline multisample state (dummy)
sectopod May 24, 2016
f44eaa2
Improved LayerError
sectopod May 25, 2016
c4b5739
Updated the tests
sectopod May 25, 2016
c47fd22
[vk] pipeline depth/stencil state
sectopod May 25, 2016
148a651
[vk] pipeline blending
sectopod May 26, 2016
a92099b
[vk] application launcher support
sectopod May 26, 2016
1a9c64a
[vk] depth-stencil view creation
sectopod May 26, 2016
3290f26
[vk] depth-stencil clears and view destruction
sectopod May 26, 2016
713c197
[vk] terrain example shaders
sectopod May 28, 2016
85ecf75
[vk] cube spv shaders
sectopod May 29, 2016
b4784c6
Added CB, SRV, UAV, and samplers to PSO descriptor
sectopod May 30, 2016
c3e438e
[vk] descriptor layout init
sectopod May 30, 2016
d6e01b4
[vk] FBO creation and hashing. CommandBuffer destruction and reset.
sectopod Jun 4, 2016
9e21c41
Merge fixes
sectopod Aug 10, 2016
feb5354
All around version bumps
sectopod Aug 10, 2016
f0f7faa
[GL] Fixed the deferred example u_CamPosAndRadius
sectopod Aug 10, 2016
e58f21e
[VK] Fixed vk-sys dependency to point to owned git path
sectopod Aug 10, 2016
5291dcf
[VK] Enabled the feature for Travis CI
sectopod Aug 11, 2016
7e0767b
[DX11] Ported to the new Core API
sectopod Aug 12, 2016
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
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -32,13 +32,15 @@ addons:
- libxcursor1
- libsdl2-dev
script:
- travis-cargo build
- travis-cargo build -- --features vulkan
- travis-cargo test -- -p gfx_core
- travis-cargo test -- -p gfx
- travis-cargo test -- -p gfx_device_gl
- travis-cargo test -- -p gfx_window_glutin
- travis-cargo test -- -p gfx_window_glfw
- travis-cargo test -- -p gfx_window_sdl
# - travis-cargo test -- -p gfx_device_vulkan
# - travis-cargo test -- -p gfx_window_vulkan
- travis-cargo test
after_success:
- travis-cargo doc -- -j 1
30 changes: 22 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -8,27 +8,40 @@ license = "Apache-2.0"
authors = ["The Gfx-rs Developers"]

[features]
default = []
vulkan = ["gfx_device_vulkan", "gfx_window_vulkan"]
unstable = []


[lib]
name = "gfx_app"

[dependencies]
env_logger = "0.3"
glutin = "0.6"
winit = "0.5.1"
gfx_core = { path = "src/core", version = "0.4" }
gfx_device_gl = { path = "src/backend/gl", version = "0.11" }
gfx_window_glutin = { path = "src/window/glutin", version = "0.12" }
gfx = { path = "src/render", version = "0.12" }
gfx_core = { path = "src/core", version = "0.5" }
gfx = { path = "src/render", version = "0.13" }
gfx_device_gl = { path = "src/backend/gl", version = "0.12" }
gfx_window_glutin = { path = "src/window/glutin", version = "0.13" }

[dependencies.gfx_device_vulkan]
path = "src/backend/vulkan"
version = "0.1"
optional = true

[dependencies.gfx_window_vulkan]
path = "src/window/vulkan"
version = "0.1"
optional = true

[target.'cfg(unix)'.dependencies]
gfx_window_glfw = { path = "src/window/glfw", version = "0.11" }
gfx_window_sdl = { path = "src/window/sdl", version = "0.3" }
gfx_window_glfw = { path = "src/window/glfw", version = "0.12" }
gfx_window_sdl = { path = "src/window/sdl", version = "0.4" }

[target.'cfg(windows)'.dependencies]
gfx_device_dx11 = { path = "src/backend/dx11", version = "0.3" }
gfx_window_dxgi = { path = "src/window/dxgi", version = "0.3" }
gfx_device_dx11 = { path = "src/backend/dx11", version = "0.4" }
gfx_window_dxgi = { path = "src/window/dxgi", version = "0.4" }

[target.x86_64-apple-darwin.dependencies]
gfx_device_metal = { path = "src/backend/metal", version = "0.1" }
@@ -90,6 +103,7 @@ rand = "0.3"
genmesh = "0.4"
noise = "0.1"
image = "0.6"
winit = "0.5"

[target.x86_64-unknown-linux-gnu.dev_dependencies]
glfw = "0.5"
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ environment:
- TARGET: nightly-x86_64-pc-windows
COMPILER: msvc
install:
- if %COMPILER%==gnu choco install mingw
- if %COMPILER%==gnu choco install -y mingw
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-${env:TARGET}-${env:COMPILER}.exe" -FileName "rust-install.exe"
- ps: .\rust-install.exe /VERYSILENT /NORESTART /DIR="C:\rust" | Out-Null
- ps: $env:PATH="$env:PATH;C:\rust\bin;C:\tools\mingw64\bin"
Binary file added examples/cube/data/frag.spv
Binary file not shown.
Binary file added examples/cube/data/vert.spv
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/cube/main.rs
Original file line number Diff line number Diff line change
@@ -72,6 +72,7 @@ impl<R: gfx::Resources> gfx_app::Application<R> for App<R> {
glsl_es_100: include_bytes!("shader/cube_100_es.glslv"),
hlsl_40: include_bytes!("data/vertex.fx"),
msl_11: include_bytes!("shader/cube_vertex.metal"),
vulkan: include_bytes!("data/vert.spv"),
.. gfx_app::shade::Source::empty()
};
let ps = gfx_app::shade::Source {
@@ -80,6 +81,7 @@ impl<R: gfx::Resources> gfx_app::Application<R> for App<R> {
glsl_es_100: include_bytes!("shader/cube_100_es.glslf"),
hlsl_40: include_bytes!("data/pixel.fx"),
msl_11: include_bytes!("shader/cube_frag.metal"),
vulkan: include_bytes!("data/frag.spv"),
.. gfx_app::shade::Source::empty()
};

5 changes: 4 additions & 1 deletion examples/cube/shader/cube_150.glslv
Original file line number Diff line number Diff line change
@@ -4,9 +4,12 @@ in vec4 a_Pos;
in vec2 a_TexCoord;
out vec2 v_TexCoord;

uniform mat4 u_Transform;
uniform Locals {
mat4 u_Transform;
};

void main() {
v_TexCoord = a_TexCoord;
gl_Position = u_Transform * a_Pos;
gl_ClipDistance[0] = 1.0;
}
11 changes: 11 additions & 0 deletions examples/cube/shader/make_vulkan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

echo Compiling...
ln -s cube_150.glslv out.vert
ln -s cube_150.glslf out.frag
glslangValidator -V -o ../data/vert.spv out.vert
glslangValidator -V -o ../data/frag.spv out.frag
rm out.vert out.frag
echo Validating...
spirv-val ../data/vert.spv
spirv-val ../data/frag.spv
6 changes: 3 additions & 3 deletions examples/deferred/shader/light.glslf
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

layout(std140)
uniform LightLocals {
vec4 u_CameraPosAndRadius;
vec4 u_CamPosAndRadius;
};
uniform sampler2D t_Position;
uniform sampler2D t_Normal;
@@ -18,14 +18,14 @@ void main() {

vec3 light = v_LightPos;
vec3 to_light = normalize(light - pos);
vec3 to_cam = normalize(u_CameraPosAndRadius.xyz - pos);
vec3 to_cam = normalize(u_CamPosAndRadius.xyz - pos);

vec3 n = normalize(normal);
float s = pow(max(0.0, dot(to_cam, reflect(-to_light, n))), 20.0);
float d = max(0.0, dot(n, to_light));

float dist_sq = dot(light - pos, light - pos);
float scale = max(0.0, 1.0 - dist_sq * u_CameraPosAndRadius.w);
float scale = max(0.0, 1.0 - dist_sq * u_CamPosAndRadius.w);

vec3 res_color = d * diffuse + vec3(s);

4 changes: 0 additions & 4 deletions examples/performance/main.rs
Original file line number Diff line number Diff line change
@@ -150,10 +150,6 @@ impl GFX {
}
}

fn duration_to_f64(dur: Duration) -> f64 {
dur.as_secs() as f64 + dur.subsec_nanos() as f64 / 1000_000_000.0
}

impl Renderer for GFX {
fn render(&mut self, proj_view: &Matrix4<f32>) {
let start = Instant::now();
17 changes: 8 additions & 9 deletions examples/shadow/main.rs
Original file line number Diff line number Diff line change
@@ -194,14 +194,13 @@ struct Scene<R: gfx::Resources, C: gfx::CommandBuffer<R>> {
// Section-4: scene construction routines

/// Create a full scene
fn create_scene<R, F, C>(factory: &mut F, encoder: &gfx::Encoder<R, C>,
fn create_scene<R, F>(factory: &mut F,
out_color: gfx::handle::RenderTargetView<R, ColorFormat>,
out_depth: gfx::handle::DepthStencilView<R, DepthFormat>,
shadow_pso: gfx::PipelineState<R, shadow::Meta>)
-> Scene<R, C> where
-> Scene<R, F::CommandBuffer> where
R: gfx::Resources,
F: gfx::Factory<R>,
C: gfx::CommandBuffer<R>,
F: gfx_app::Factory<R>,
{
use cgmath::{SquareMatrix, Matrix4, deg};
use gfx::traits::FactoryExt;
@@ -264,7 +263,7 @@ fn create_scene<R, F, C>(factory: &mut F, encoder: &gfx::Encoder<R, C>,
shadow: factory.view_texture_as_depth_stencil(
&shadow_tex, 0, Some(i as gfx::Layer), gfx::tex::DepthStencilFlags::empty(),
).unwrap(),
encoder: encoder.clone_empty(),
encoder: factory.create_encoder(),
}).collect();
let light_buf = factory.create_constant_buffer(MAX_LIGHTS);

@@ -424,8 +423,8 @@ impl<R, C> gfx_app::ApplicationBase<R, C> for App<R, C> where
R: gfx::Resources + 'static,
C: gfx::CommandBuffer<R> + Send + 'static,
{
fn new<F>(mut factory: F, encoder: gfx::Encoder<R, C>, init: gfx_app::Init<R>) -> Self where
F: gfx::Factory<R>
fn new<F>(mut factory: F, init: gfx_app::Init<R>) -> Self where
F: gfx_app::Factory<R, CommandBuffer=C>,
{
use std::env;
use gfx::traits::FactoryExt;
@@ -487,15 +486,15 @@ impl<R, C> gfx_app::ApplicationBase<R, C> for App<R, C> where
).unwrap()
};

let scene = create_scene(&mut factory, &encoder,
let scene = create_scene(&mut factory,
init.color.clone(), init.depth.clone(),
shadow_pso);

App {
init: init,
is_parallel: is_parallel,
forward_pso: forward_pso,
encoder: encoder,
encoder: factory.create_encoder(),
scene: scene,
}
}
Binary file added examples/terrain/data/frag.spv
Binary file not shown.
Binary file added examples/terrain/data/vert.spv
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/terrain/main.rs
Original file line number Diff line number Diff line change
@@ -82,13 +82,15 @@ impl<R: gfx::Resources> gfx_app::Application<R> for App<R> {
glsl_150: include_bytes!("shader/terrain_150.glslv"),
hlsl_40: include_bytes!("data/vertex.fx"),
msl_11: include_bytes!("shader/terrain_vertex.metal"),
vulkan: include_bytes!("data/vert.spv"),
.. gfx_app::shade::Source::empty()
};
let ps = gfx_app::shade::Source {
glsl_120: include_bytes!("shader/terrain_120.glslf"),
glsl_150: include_bytes!("shader/terrain_150.glslf"),
hlsl_40: include_bytes!("data/pixel.fx"),
msl_11: include_bytes!("shader/terrain_frag.metal"),
vulkan: include_bytes!("data/frag.spv"),
.. gfx_app::shade::Source::empty()
};

11 changes: 11 additions & 0 deletions examples/terrain/shader/make_vulkan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

echo Compiling...
ln -s terrain_150.glslv out.vert
ln -s terrain_150.glslf out.frag
glslangValidator -V -o ../data/vert.spv out.vert
glslangValidator -V -o ../data/frag.spv out.frag
rm out.vert out.frag
echo Validating...
spirv-val ../data/vert.spv
spirv-val ../data/frag.spv
1 change: 1 addition & 0 deletions examples/terrain/shader/terrain_150.glslv
Original file line number Diff line number Diff line change
@@ -13,4 +13,5 @@ uniform Locals {
void main() {
v_Color = a_Color;
gl_Position = u_Proj * u_View * u_Model * vec4(a_Pos, 1.0);
gl_ClipDistance[0] = 1.0;
}
1 change: 0 additions & 1 deletion examples/triangle/main.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
#[macro_use]
extern crate gfx;
extern crate gfx_window_glutin;
extern crate gfx_device_gl;
extern crate glutin;

use gfx::traits::FactoryExt;
4 changes: 2 additions & 2 deletions src/backend/dx11/Cargo.toml
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@

[package]
name = "gfx_device_dx11"
version = "0.3.0"
version = "0.4.0"
description = "DirectX-11 backend for gfx-rs"
homepage = "https://github.com/gfx-rs/gfx"
repository = "https://github.com/gfx-rs/gfx"
@@ -27,7 +27,7 @@ name = "gfx_device_dx11"

[dependencies]
log = "0.3"
gfx_core = { path = "../../core", version = "0.4" }
gfx_core = { path = "../../core", version = "0.5" }
d3d11-sys = "0.2"
d3dcompiler-sys = "0.2"
dxguid-sys = "0.2"
30 changes: 17 additions & 13 deletions src/backend/dx11/src/command.rs
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ pub enum Command {
unsafe impl Send for Command {}

struct Cache {
attributes: [Option<pso::AttributeDesc>; MAX_VERTEX_ATTRIBUTES],
attrib_strides: [Option<pso::ElemStride>; MAX_VERTEX_ATTRIBUTES],
rasterizer: *const ID3D11RasterizerState,
depth_stencil: *const ID3D11DepthStencilState,
stencil_ref: UINT,
@@ -103,7 +103,7 @@ unsafe impl Send for Cache {}
impl Cache {
fn new() -> Cache {
Cache {
attributes: [None; MAX_VERTEX_ATTRIBUTES],
attrib_strides: [None; MAX_VERTEX_ATTRIBUTES],
rasterizer: ptr::null(),
depth_stencil: ptr::null(),
stencil_ref: 0,
@@ -119,7 +119,6 @@ pub struct CommandBuffer<P> {
}

pub trait Parser: Sized {
fn clone_empty(&self) -> Self;
fn reset(&mut self);
fn parse(&mut self, Command);
fn update_buffer(&mut self, Buffer, &[u8], usize);
@@ -144,18 +143,22 @@ impl<P: Parser> CommandBuffer<P> {
}

impl<P: Parser> draw::CommandBuffer<Resources> for CommandBuffer<P> {
fn clone_empty(&self) -> CommandBuffer<P> {
self.parser.clone_empty().into()
}

fn reset(&mut self) {
self.parser.reset();
self.cache = Cache::new();
}

fn bind_pipeline_state(&mut self, pso: Pipeline) {
self.parser.parse(Command::SetPrimitive(pso.topology));
self.cache.attributes = pso.attributes;
for (stride, ad_option) in self.cache.attrib_strides.iter_mut().zip(pso.attributes.iter()) {
*stride = ad_option.map(|(buf_id, _)| match pso.vertex_buffers[buf_id as usize] {
Some(ref bdesc) => bdesc.stride,
None => {
error!("Unexpected use of buffer id {}", buf_id);
0
},
});
}
if self.cache.rasterizer != pso.rasterizer {
self.cache.rasterizer = pso.rasterizer;
self.parser.parse(Command::SetRasterizer(pso.rasterizer));
@@ -167,17 +170,18 @@ impl<P: Parser> draw::CommandBuffer<Resources> for CommandBuffer<P> {
}

fn bind_vertex_buffers(&mut self, vbs: pso::VertexBufferSet<Resources>) {
//Note: assumes `bind_pipeline_state` is called prior
let mut buffers = [native::Buffer(ptr::null_mut()); MAX_VERTEX_ATTRIBUTES];
let mut strides = [0; MAX_VERTEX_ATTRIBUTES];
let mut offsets = [0; MAX_VERTEX_ATTRIBUTES];
for i in 0 .. MAX_VERTEX_ATTRIBUTES {
match (vbs.0[i], self.cache.attributes[i]) {
(None, Some(fm)) => {
error!("No vertex input provided for slot {} of format {:?}", i, fm)
match (vbs.0[i], self.cache.attrib_strides[i]) {
(None, Some(stride)) => {
error!("No vertex input provided for slot {} with stride {}", i, stride)
},
(Some((buffer, offset)), Some(ref format)) => {
(Some((buffer, offset)), Some(stride)) => {
buffers[i] = buffer.0;
strides[i] = format.0.stride as UINT;
strides[i] = stride as UINT;
offsets[i] = offset as UINT;
},
(_, None) => (),
Loading