Move shaders back that were supposed to be defined in the middle of main() { } (#1097)

They were initially moved because rust currently doesnt support
function-like proc macros in a function, but now they are wrapped in a
mod anyway.
This commit is contained in:
Lucas Kent 2018-10-28 18:29:41 +11:00 committed by GitHub
parent 9d46e08cc7
commit 3fe7fc4495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 111 additions and 108 deletions

View File

@ -28,25 +28,6 @@ use vulkano::sync;
use std::sync::Arc;
mod cs {
vulkano_shaders::shader!{
ty: "compute",
src: "
#version 450
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
layout(set = 0, binding = 0) buffer Data {
uint data[];
} data;
void main() {
uint idx = gl_GlobalInvocationID.x;
data.data[idx] *= 12;
}"
}
}
fn main() {
// As with other examples, the first step is to create an instance.
let instance = Instance::new(None, &InstanceExtensions::none(), None).unwrap();
@ -90,6 +71,24 @@ fn main() {
// If you are familiar with graphics pipeline, the principle is the same except that compute
// pipelines are much simpler to create.
let pipeline = Arc::new({
mod cs {
vulkano_shaders::shader!{
ty: "compute",
src: "
#version 450
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
layout(set = 0, binding = 0) buffer Data {
uint data[];
} data;
void main() {
uint idx = gl_GlobalInvocationID.x;
data.data[idx] *= 12;
}"
}
}
let shader = cs::Shader::load(device.clone()).unwrap();
ComputePipeline::new(device.clone(), &shader.main_entry_point(), &()).unwrap()
});

View File

@ -84,34 +84,6 @@ use vulkano::pipeline::viewport::Viewport;
use vulkano::sync::GpuFuture;
use vulkano::format::ClearValue;
mod vs {
vulkano_shaders::shader!{
ty: "vertex",
src: "
#version 450
layout(location = 0) in vec2 position;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
}"
}
}
mod fs {
vulkano_shaders::shader!{
ty: "fragment",
src: "
#version 450
layout(location = 0) out vec4 f_color;
void main() {
f_color = vec4(1.0, 0.0, 0.0, 1.0);
}"
}
}
fn main() {
// The usual Vulkan initialization.
let instance = Instance::new(None, &InstanceExtensions::none(), None).unwrap();
@ -180,6 +152,34 @@ fn main() {
// At the end of the example, we copy the content of `image` (ie. the final image) to a buffer,
// then read the content of that buffer and save it to a PNG file.
mod vs {
vulkano_shaders::shader!{
ty: "vertex",
src: "
#version 450
layout(location = 0) in vec2 position;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
}"
}
}
mod fs {
vulkano_shaders::shader!{
ty: "fragment",
src: "
#version 450
layout(location = 0) out vec4 f_color;
void main() {
f_color = vec4(1.0, 0.0, 0.0, 1.0);
}"
}
}
let vs = vs::Shader::load(device.clone()).unwrap();
let fs = fs::Shader::load(device.clone()).unwrap();

View File

@ -22,6 +22,14 @@ use vulkano::sync;
use std::sync::Arc;
fn main() {
let instance = Instance::new(None, &InstanceExtensions::none(), None).unwrap();
let physical = PhysicalDevice::enumerate(&instance).next().unwrap();
let queue_family = physical.queue_families().find(|&q| q.supports_compute()).unwrap();
let (device, mut queues) = Device::new(physical, physical.supported_features(),
&DeviceExtensions::none(), [(queue_family, 0.5)].iter().cloned()).unwrap();
let queue = queues.next().unwrap();
mod cs {
vulkano_shaders::shader!{
ty: "compute",
@ -50,14 +58,8 @@ void main() {
}
}
fn main() {
let instance = Instance::new(None, &InstanceExtensions::none(), None).unwrap();
let physical = PhysicalDevice::enumerate(&instance).next().unwrap();
let queue_family = physical.queue_families().find(|&q| q.supports_compute()).unwrap();
let (device, mut queues) = Device::new(physical, physical.supported_features(),
&DeviceExtensions::none(), [(queue_family, 0.5)].iter().cloned()).unwrap();
let queue = queues.next().unwrap();
let shader = cs::Shader::load(device.clone()).unwrap();
let pipeline = Arc::new(ComputePipeline::new(device.clone(), &shader.main_entry_point(), &()).unwrap());
let data_buffer = {

View File

@ -22,6 +22,14 @@ use vulkano::sync;
use std::sync::Arc;
fn main() {
let instance = Instance::new(None, &InstanceExtensions::none(), None).unwrap();
let physical = PhysicalDevice::enumerate(&instance).next().unwrap();
let queue_family = physical.queue_families().find(|&q| q.supports_compute()).unwrap();
let (device, mut queues) = Device::new(physical, physical.supported_features(),
&DeviceExtensions::none(), [(queue_family, 0.5)].iter().cloned()).unwrap();
let queue = queues.next().unwrap();
mod cs {
vulkano_shaders::shader!{
ty: "compute",
@ -48,15 +56,8 @@ void main() {
}
}
fn main() {
let instance = Instance::new(None, &InstanceExtensions::none(), None).unwrap();
let physical = PhysicalDevice::enumerate(&instance).next().unwrap();
let queue_family = physical.queue_families().find(|&q| q.supports_compute()).unwrap();
let (device, mut queues) = Device::new(physical, physical.supported_features(),
&DeviceExtensions::none(), [(queue_family, 0.5)].iter().cloned()).unwrap();
let queue = queues.next().unwrap();
let shader = cs::Shader::load(device.clone()).unwrap();
let spec_consts = cs::SpecializationConstants {
enable: 1,
multiple: 1,

View File

@ -49,42 +49,6 @@ use winit::{EventsLoop, Window, WindowBuilder, Event, WindowEvent};
use std::sync::Arc;
// TODO: Move this back to the middle of the example, it makes for a more coherent sequential explanation (check git history)
// The raw shader creation API provided by the vulkano library is unsafe, for various reasons.
//
// An overview of what the `shader!` macro generates can be found in the
// `vulkano-shaders` crate docs. You can view them at https://docs.rs/vulkano-shaders/
//
// TODO: explain this in details
mod vs {
vulkano_shaders::shader!{
ty: "vertex",
src: "
#version 450
layout(location = 0) in vec2 position;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
}"
}
}
mod fs {
vulkano_shaders::shader!{
ty: "fragment",
src: "
#version 450
layout(location = 0) out vec4 f_color;
void main() {
f_color = vec4(1.0, 0.0, 0.0, 1.0);
}
"
}
}
fn main() {
// The first step of any Vulkan program is to create an instance.
let instance = {
@ -231,6 +195,43 @@ fn main() {
].iter().cloned()).unwrap()
};
// The next step is to create the shaders.
//
// The raw shader creation API provided by the vulkano library is unsafe, for various reasons.
//
// An overview of what the `vulkano_shaders::shader!` macro generates can be found in the
// `vulkano-shaders` crate docs. You can view them at https://docs.rs/vulkano-shaders/
//
// TODO: explain this in details
mod vs {
vulkano_shaders::shader!{
ty: "vertex",
src: "
#version 450
layout(location = 0) in vec2 position;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
}"
}
}
mod fs {
vulkano_shaders::shader!{
ty: "fragment",
src: "
#version 450
layout(location = 0) out vec4 f_color;
void main() {
f_color = vec4(1.0, 0.0, 0.0, 1.0);
}
"
}
}
let vs = vs::Shader::load(device.clone()).unwrap();
let fs = fs::Shader::load(device.clone()).unwrap();