Put all inputs and outputs in entry point structs

This commit is contained in:
Pierre Krieger 2016-05-04 09:30:16 +02:00
parent e2fc113711
commit fe8706aae8
3 changed files with 108 additions and 58 deletions

View File

@ -31,47 +31,33 @@ pub fn write_entry_point(doc: &parse::Spirv, instruction: &parse::Instruction) -
let (ty, f_call) = match *execution { let (ty, f_call) = match *execution {
enums::ExecutionModel::ExecutionModelVertex => { enums::ExecutionModel::ExecutionModelVertex => {
let t = format!("::vulkano::pipeline::shader::VertexShaderEntryPoint<(), {}Input, Layout>", capitalized_ep_name); let t = format!("::vulkano::pipeline::shader::VertexShaderEntryPoint<(), {0}Input, {0}Output, Layout>", capitalized_ep_name);
let f = format!("vertex_shader_entry_point(::std::ffi::CStr::from_ptr(NAME.as_ptr() as *const _), Layout, {}Input)", capitalized_ep_name); let f = format!("vertex_shader_entry_point(::std::ffi::CStr::from_ptr(NAME.as_ptr() as *const _), {0}Input, {0}Output, Layout)", capitalized_ep_name);
(t, f) (t, f)
}, },
enums::ExecutionModel::ExecutionModelTessellationControl => { enums::ExecutionModel::ExecutionModelTessellationControl => {
(format!("::vulkano::pipeline::shader::TessControlShaderEntryPoint"), String::new()) let t = format!("::vulkano::pipeline::shader::TessControlShaderEntryPoint<(), {0}Input, {0}Output, Layout>", capitalized_ep_name);
let f = format!("tess_control_shader_entry_point(::std::ffi::CStr::from_ptr(NAME.as_ptr() as *const _), {0}Input, {0}Output, Layout)", capitalized_ep_name);
(t, f)
}, },
enums::ExecutionModel::ExecutionModelTessellationEvaluation => { enums::ExecutionModel::ExecutionModelTessellationEvaluation => {
(format!("::vulkano::pipeline::shader::TessEvaluationShaderEntryPoint"), String::new()) let t = format!("::vulkano::pipeline::shader::TessEvaluationShaderEntryPoint<(), {0}Input, {0}Output, Layout>", capitalized_ep_name);
let f = format!("tess_evaluation_shader_entry_point(::std::ffi::CStr::from_ptr(NAME.as_ptr() as *const _), {0}Input, {0}Output, Layout)", capitalized_ep_name);
(t, f)
}, },
enums::ExecutionModel::ExecutionModelGeometry => { enums::ExecutionModel::ExecutionModelGeometry => {
(format!("::vulkano::pipeline::shader::GeometryShaderEntryPoint"), String::new()) let t = format!("::vulkano::pipeline::shader::GeometryShaderEntryPoint<(), {0}Input, {0}Output, Layout>", capitalized_ep_name);
let f = format!("geometry_shader_entry_point(::std::ffi::CStr::from_ptr(NAME.as_ptr() as *const _), {0}Input, {0}Output, Layout)", capitalized_ep_name);
(t, f)
}, },
enums::ExecutionModel::ExecutionModelFragment => { enums::ExecutionModel::ExecutionModelFragment => {
let mut output_types = Vec::new(); let t = format!("::vulkano::pipeline::shader::FragmentShaderEntryPoint<(), {0}Input, {0}Output, Layout>", capitalized_ep_name);
let f = format!("fragment_shader_entry_point(::std::ffi::CStr::from_ptr(NAME.as_ptr() as *const _), {0}Input, {0}Output, Layout)", capitalized_ep_name);
for interface in interface.iter() { (t, f)
for i in doc.instructions.iter() {
match i {
&parse::Instruction::Variable { result_type_id, result_id, ref storage_class,
.. } if &result_id == interface =>
{
output_types.push(type_from_id(doc, result_type_id));
},
_ => ()
}
}
}
let output = {
let output = output_types.join(", ");
if output.is_empty() { output } else { output + "," }
};
let t = format!("::vulkano::pipeline::shader::FragmentShaderEntryPoint<(), ({output}), Layout>",
output = output);
(t, format!("fragment_shader_entry_point(::std::ffi::CStr::from_ptr(NAME.as_ptr() as *const _), Layout)"))
}, },
enums::ExecutionModel::ExecutionModelGLCompute => { enums::ExecutionModel::ExecutionModelGLCompute => {

View File

@ -47,15 +47,15 @@ use pipeline::vertex::Definition as VertexDefinition;
use pipeline::vertex::Vertex; use pipeline::vertex::Vertex;
use pipeline::viewport::ViewportsState; use pipeline::viewport::ViewportsState;
pub struct GraphicsPipelineParams<'a, Vdef, Vsp, Vi, Vl, Gs, Gi, Go, Gl, Fs, Fo, Fl, L, Rp> where L: 'a, Rp: 'a { pub struct GraphicsPipelineParams<'a, Vdef, Vsp, Vi, Vo, Vl, Gs, Gi, Go, Gl, Fs, Fi, Fo, Fl, L, Rp> where L: 'a, Rp: 'a {
pub vertex_input: Vdef, pub vertex_input: Vdef,
pub vertex_shader: VertexShaderEntryPoint<'a, Vsp, Vi, Vl>, pub vertex_shader: VertexShaderEntryPoint<'a, Vsp, Vi, Vo, Vl>,
pub input_assembly: InputAssembly, pub input_assembly: InputAssembly,
pub geometry_shader: Option<GeometryShaderEntryPoint<'a, Gs, Gi, Go, Gl>>, pub geometry_shader: Option<GeometryShaderEntryPoint<'a, Gs, Gi, Go, Gl>>,
pub viewport: ViewportsState, pub viewport: ViewportsState,
pub raster: Rasterization, pub raster: Rasterization,
pub multisample: Multisample, pub multisample: Multisample,
pub fragment_shader: FragmentShaderEntryPoint<'a, Fs, Fo, Fl>, pub fragment_shader: FragmentShaderEntryPoint<'a, Fs, Fi, Fo, Fl>,
pub depth_stencil: DepthStencil, pub depth_stencil: DepthStencil,
pub blend: Blend, pub blend: Blend,
pub layout: &'a Arc<L>, pub layout: &'a Arc<L>,
@ -94,23 +94,23 @@ impl<Vdef, L, Rp> GraphicsPipeline<Vdef, L, Rp>
{ {
/// Builds a new graphics pipeline object. /// Builds a new graphics pipeline object.
#[inline] #[inline]
pub fn new<'a, Vsp, Vi, Vl, Fs, Fo, Fl> pub fn new<'a, Vsp, Vi, Vo, Vl, Fs, Fi, Fo, Fl>
(device: &Arc<Device>, (device: &Arc<Device>,
params: GraphicsPipelineParams<'a, Vdef, Vsp, Vi, Vl, (), (), (), (), Fs, Fo, Fl, params: GraphicsPipelineParams<'a, Vdef, Vsp, Vi, Vo, Vl, (), (), (), (), Fs, Fi, Fo, Fl,
L, Rp>) L, Rp>)
-> Result<Arc<GraphicsPipeline<Vdef, L, Rp>>, GraphicsPipelineCreationError> -> Result<Arc<GraphicsPipeline<Vdef, L, Rp>>, GraphicsPipelineCreationError>
where Vdef: VertexDefinition<Vi>, where Vdef: VertexDefinition<Vi>,
L: PipelineLayout + PipelineLayoutSuperset<Vl> + PipelineLayoutSuperset<Fl>, L: PipelineLayout + PipelineLayoutSuperset<Vl> + PipelineLayoutSuperset<Fl>,
Vl: PipelineLayoutDesc, Fl: PipelineLayoutDesc Vl: PipelineLayoutDesc, Fl: PipelineLayoutDesc
{ {
GraphicsPipeline::new_inner::<_, _, _, (), (), (), (), _, _, _>(device, params) GraphicsPipeline::new_inner::<_, _, _, _, (), (), (), (), _, _, _, _>(device, params)
} }
/// Builds a new graphics pipeline object with a geometry shader. /// Builds a new graphics pipeline object with a geometry shader.
#[inline] #[inline]
pub fn with_geometry_shader<'a, Vsp, Vi, Vl, Gsp, Gi, Go, Gl, Fs, Fo, Fl> pub fn with_geometry_shader<'a, Vsp, Vi, Vo, Vl, Gsp, Gi, Go, Gl, Fs, Fi, Fo, Fl>
(device: &Arc<Device>, (device: &Arc<Device>,
params: GraphicsPipelineParams<'a, Vdef, Vsp, Vi, Vl, Gsp, Gi, Go, Gl, Fs, Fo, Fl, L, Rp>) params: GraphicsPipelineParams<'a, Vdef, Vsp, Vi, Vo, Vl, Gsp, Gi, Go, Gl, Fs, Fi, Fo, Fl, L, Rp>)
-> Result<Arc<GraphicsPipeline<Vdef, L, Rp>>, GraphicsPipelineCreationError> -> Result<Arc<GraphicsPipeline<Vdef, L, Rp>>, GraphicsPipelineCreationError>
where Vdef: VertexDefinition<Vi>, where Vdef: VertexDefinition<Vi>,
L: PipelineLayout + PipelineLayoutSuperset<Vl> + PipelineLayoutSuperset<Fl>, L: PipelineLayout + PipelineLayoutSuperset<Vl> + PipelineLayoutSuperset<Fl>,
@ -119,9 +119,9 @@ impl<Vdef, L, Rp> GraphicsPipeline<Vdef, L, Rp>
GraphicsPipeline::new_inner(device, params) GraphicsPipeline::new_inner(device, params)
} }
fn new_inner<'a, Vsp, Vi, Vl, Gsp, Gi, Go, Gl, Fs, Fo, Fl> fn new_inner<'a, Vsp, Vi, Vo, Vl, Gsp, Gi, Go, Gl, Fs, Fi, Fo, Fl>
(device: &Arc<Device>, (device: &Arc<Device>,
params: GraphicsPipelineParams<'a, Vdef, Vsp, Vi, Vl, Gsp, Gi, Go, Gl, Fs, Fo, Fl, L, Rp>) params: GraphicsPipelineParams<'a, Vdef, Vsp, Vi, Vo, Vl, Gsp, Gi, Go, Gl, Fs, Fi, Fo, Fl, L, Rp>)
-> Result<Arc<GraphicsPipeline<Vdef, L, Rp>>, GraphicsPipelineCreationError> -> Result<Arc<GraphicsPipeline<Vdef, L, Rp>>, GraphicsPipelineCreationError>
where Vdef: VertexDefinition<Vi>, where Vdef: VertexDefinition<Vi>,
L: PipelineLayout + PipelineLayoutSuperset<Vl> + PipelineLayoutSuperset<Fl>, L: PipelineLayout + PipelineLayoutSuperset<Vl> + PipelineLayoutSuperset<Fl>,

View File

@ -72,43 +72,48 @@ impl ShaderModule {
})) }))
} }
pub unsafe fn vertex_shader_entry_point<'a, S, V, L> pub unsafe fn vertex_shader_entry_point<'a, S, I, O, L>
(&'a self, name: &'a CStr, layout: L,vertex_input: V) (&'a self, name: &'a CStr, input: I, output: O, layout: L)
-> VertexShaderEntryPoint<'a, S, V, L> -> VertexShaderEntryPoint<'a, S, I, O, L>
{ {
VertexShaderEntryPoint { VertexShaderEntryPoint {
module: self, module: self,
name: name, name: name,
vertex_input: vertex_input, input: input,
output: output,
layout: layout, layout: layout,
marker: PhantomData, marker: PhantomData,
} }
} }
pub unsafe fn tess_control_shader_entry_point<'a, S, I, O, L> pub unsafe fn tess_control_shader_entry_point<'a, S, I, O, L>
(&'a self, name: &'a CStr, layout: L) -> TessControlShaderEntryPoint<'a, S, I, O, L> (&'a self, name: &'a CStr, input: I, output: O, layout: L) -> TessControlShaderEntryPoint<'a, S, I, O, L>
{ {
TessControlShaderEntryPoint { TessControlShaderEntryPoint {
module: self, module: self,
name: name, name: name,
layout: layout, layout: layout,
input: input,
output: output,
marker: PhantomData, marker: PhantomData,
} }
} }
pub unsafe fn tess_evaluation_shader_entry_point<'a, S, I, O, L> pub unsafe fn tess_evaluation_shader_entry_point<'a, S, I, O, L>
(&'a self, name: &'a CStr, layout: L) -> TessEvaluationShaderEntryPoint<'a, S, I, O, L> (&'a self, name: &'a CStr, input: I, output: O, layout: L) -> TessEvaluationShaderEntryPoint<'a, S, I, O, L>
{ {
TessEvaluationShaderEntryPoint { TessEvaluationShaderEntryPoint {
module: self, module: self,
name: name, name: name,
layout: layout, layout: layout,
input: input,
output: output,
marker: PhantomData, marker: PhantomData,
} }
} }
pub unsafe fn geometry_shader_entry_point<'a, S, I, O, L> pub unsafe fn geometry_shader_entry_point<'a, S, I, O, L>
(&'a self, name: &'a CStr, primitives: GeometryShaderExecutionMode, layout: L) (&'a self, name: &'a CStr, primitives: GeometryShaderExecutionMode, input: I, output: O, layout: L)
-> GeometryShaderEntryPoint<'a, S, I, O, L> -> GeometryShaderEntryPoint<'a, S, I, O, L>
{ {
GeometryShaderEntryPoint { GeometryShaderEntryPoint {
@ -116,6 +121,8 @@ impl ShaderModule {
name: name, name: name,
layout: layout, layout: layout,
primitives: primitives, primitives: primitives,
input: input,
output: output,
marker: PhantomData, marker: PhantomData,
} }
} }
@ -132,13 +139,15 @@ impl ShaderModule {
/// - Calling this function also determines the template parameters associated to the /// - Calling this function also determines the template parameters associated to the
/// `EntryPoint` struct. Therefore care must be taken that the values there are correct. /// `EntryPoint` struct. Therefore care must be taken that the values there are correct.
/// ///
pub unsafe fn fragment_shader_entry_point<'a, S, F, L>(&'a self, name: &'a CStr, layout: L) pub unsafe fn fragment_shader_entry_point<'a, S, I, O, L>(&'a self, name: &'a CStr, input: I, output: O, layout: L)
-> FragmentShaderEntryPoint<'a, S, F, L> -> FragmentShaderEntryPoint<'a, S, I, O, L>
{ {
FragmentShaderEntryPoint { FragmentShaderEntryPoint {
module: self, module: self,
name: name, name: name,
layout: layout, layout: layout,
input: input,
output: output,
marker: PhantomData, marker: PhantomData,
} }
} }
@ -175,15 +184,16 @@ impl Drop for ShaderModule {
} }
} }
pub struct VertexShaderEntryPoint<'a, S, V, L> { pub struct VertexShaderEntryPoint<'a, S, I, O, L> {
module: &'a ShaderModule, module: &'a ShaderModule,
name: &'a CStr, name: &'a CStr,
vertex_input: V, input: I,
layout: L, layout: L,
output: O,
marker: PhantomData<S>, marker: PhantomData<S>,
} }
impl<'a, S, V, L> VertexShaderEntryPoint<'a, S, V, L> { impl<'a, S, I, O, L> VertexShaderEntryPoint<'a, S, I, O, L> {
#[inline] #[inline]
pub fn module(&self) -> &'a ShaderModule { pub fn module(&self) -> &'a ShaderModule {
self.module self.module
@ -199,9 +209,15 @@ impl<'a, S, V, L> VertexShaderEntryPoint<'a, S, V, L> {
&self.layout &self.layout
} }
// TODO: rename "input" for consistency
#[inline] #[inline]
pub fn input_definition(&self) -> &V { pub fn input_definition(&self) -> &I {
&self.vertex_input &self.input
}
#[inline]
pub fn output(&self) -> &O {
&self.output
} }
} }
@ -209,7 +225,9 @@ pub struct TessControlShaderEntryPoint<'a, S, I, O, L> {
module: &'a ShaderModule, module: &'a ShaderModule,
name: &'a CStr, name: &'a CStr,
layout: L, layout: L,
marker: PhantomData<(S, I, O)>, input: I,
output: O,
marker: PhantomData<S>,
} }
impl<'a, S, I, O, L> TessControlShaderEntryPoint<'a, S, I, O, L> { impl<'a, S, I, O, L> TessControlShaderEntryPoint<'a, S, I, O, L> {
@ -227,13 +245,25 @@ impl<'a, S, I, O, L> TessControlShaderEntryPoint<'a, S, I, O, L> {
pub fn layout(&self) -> &L { pub fn layout(&self) -> &L {
&self.layout &self.layout
} }
#[inline]
pub fn input(&self) -> &I {
&self.input
}
#[inline]
pub fn output(&self) -> &O {
&self.output
}
} }
pub struct TessEvaluationShaderEntryPoint<'a, S, I, O, L> { pub struct TessEvaluationShaderEntryPoint<'a, S, I, O, L> {
module: &'a ShaderModule, module: &'a ShaderModule,
name: &'a CStr, name: &'a CStr,
layout: L, layout: L,
marker: PhantomData<(S, I, O)>, input: I,
output: O,
marker: PhantomData<S>,
} }
impl<'a, S, I, O, L> TessEvaluationShaderEntryPoint<'a, S, I, O, L> { impl<'a, S, I, O, L> TessEvaluationShaderEntryPoint<'a, S, I, O, L> {
@ -251,6 +281,16 @@ impl<'a, S, I, O, L> TessEvaluationShaderEntryPoint<'a, S, I, O, L> {
pub fn layout(&self) -> &L { pub fn layout(&self) -> &L {
&self.layout &self.layout
} }
#[inline]
pub fn input(&self) -> &I {
&self.input
}
#[inline]
pub fn output(&self) -> &O {
&self.output
}
} }
pub struct GeometryShaderEntryPoint<'a, S, I, O, L> { pub struct GeometryShaderEntryPoint<'a, S, I, O, L> {
@ -258,7 +298,9 @@ pub struct GeometryShaderEntryPoint<'a, S, I, O, L> {
name: &'a CStr, name: &'a CStr,
layout: L, layout: L,
primitives: GeometryShaderExecutionMode, primitives: GeometryShaderExecutionMode,
marker: PhantomData<(S, I, O)>, input: I,
output: O,
marker: PhantomData<S>,
} }
impl<'a, S, I, O, L> GeometryShaderEntryPoint<'a, S, I, O, L> { impl<'a, S, I, O, L> GeometryShaderEntryPoint<'a, S, I, O, L> {
@ -282,6 +324,16 @@ impl<'a, S, I, O, L> GeometryShaderEntryPoint<'a, S, I, O, L> {
pub fn layout(&self) -> &L { pub fn layout(&self) -> &L {
&self.layout &self.layout
} }
#[inline]
pub fn input(&self) -> &I {
&self.input
}
#[inline]
pub fn output(&self) -> &O {
&self.output
}
} }
/// Declares which type of primitives are expected by the geometry shader. /// Declares which type of primitives are expected by the geometry shader.
@ -318,14 +370,16 @@ impl GeometryShaderExecutionMode {
} }
} }
pub struct FragmentShaderEntryPoint<'a, S, F, L> { pub struct FragmentShaderEntryPoint<'a, S, I, O, L> {
module: &'a ShaderModule, module: &'a ShaderModule,
name: &'a CStr, name: &'a CStr,
layout: L, layout: L,
marker: PhantomData<(S, F)>, input: I,
output: O,
marker: PhantomData<S>,
} }
impl<'a, S, F, L> FragmentShaderEntryPoint<'a, S, F, L> { impl<'a, S, I, O, L> FragmentShaderEntryPoint<'a, S, I, O, L> {
#[inline] #[inline]
pub fn module(&self) -> &'a ShaderModule { pub fn module(&self) -> &'a ShaderModule {
self.module self.module
@ -340,6 +394,16 @@ impl<'a, S, F, L> FragmentShaderEntryPoint<'a, S, F, L> {
pub fn layout(&self) -> &L { pub fn layout(&self) -> &L {
&self.layout &self.layout
} }
#[inline]
pub fn input(&self) -> &I {
&self.input
}
#[inline]
pub fn output(&self) -> &O {
&self.output
}
} }
pub struct ComputeShaderEntryPoint<'a, S, L> { pub struct ComputeShaderEntryPoint<'a, S, L> {