Skip to content

Commit

Permalink
Updated func signatures
Browse files Browse the repository at this point in the history
Signed-off-by: Hal Gentz <[email protected]>
  • Loading branch information
goddessfreya committed May 27, 2018
1 parent 460e45a commit 45a9dde
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 22 deletions.
17 changes: 12 additions & 5 deletions src/backend/dx12/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,14 +1262,16 @@ impl d::Device<B> for Device {
rp
}

fn create_pipeline_layout<IS, IR>(
fn create_pipeline_layout<IS, IR, IB>(
&self,
sets: IS,
push_constant_ranges: IR,
) -> n::PipelineLayout
where
IS: IntoIterator,
IS::Item: Borrow<n::DescriptorSetLayout>,
IS::Item: Borrow<(n::DescriptorSetLayout, IB)>,
IB: IntoIterator,
IB::Item: Borrow<u32>,
IR: IntoIterator,
IR::Item: Borrow<(pso::ShaderStageFlags, Range<u32>)>,
{
Expand Down Expand Up @@ -1331,6 +1333,7 @@ impl d::Device<B> for Device {
let mut sum = 0;
let bindings = &desc_set
.borrow()
.0
.bindings;

for binding in bindings {
Expand All @@ -1348,7 +1351,7 @@ impl d::Device<B> for Device {
let mut set_tables = Vec::with_capacity(sets.len());

for (i, set) in sets.iter().enumerate() {
let set = set.borrow();
let set = set.borrow().0;
let mut table_type = n::SetTableTypes::empty();

let mut param = d3d12::D3D12_ROOT_PARAMETER {
Expand Down Expand Up @@ -1728,7 +1731,11 @@ impl d::Device<B> for Device {
})
}

fn create_shader_module(&self, raw_data: &[u8]) -> Result<n::ShaderModule, d::ShaderError> {
fn create_shader_module(
&self,
raw_data: &[u8],
_pipeline_layout: &n::PipelineLayout,
) -> Result<n::ShaderModule, d::ShaderError> {
Ok(n::ShaderModule::Spirv(raw_data.into()))
}

Expand Down Expand Up @@ -2925,7 +2932,7 @@ impl d::Device<B> for Device {
unsafe {
self.raw.clone().CreateRenderTargetView(resource, &rtv_desc, rtv_handle);
}

resources.push(resource);

let surface_type = config
Expand Down
12 changes: 9 additions & 3 deletions src/backend/empty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ impl hal::Device<Backend> for Device {
unimplemented!()
}

fn create_pipeline_layout<IS, IR>(&self, _: IS, _: IR) -> ()
fn create_pipeline_layout<IS, IR, IB>(&self, _: IS, _: IR) -> ()
where
IS: IntoIterator,
IS::Item: Borrow<()>,
IS::Item: Borrow<((), IB)>,
IB: IntoIterator,
IB::Item: Borrow<u32>,
IR: IntoIterator,
IR::Item: Borrow<(pso::ShaderStageFlags, Range<u32>)>,
{
Expand All @@ -159,7 +161,11 @@ impl hal::Device<Backend> for Device {
unimplemented!()
}

fn create_shader_module(&self, _: &[u8]) -> Result<(), device::ShaderError> {
fn create_shader_module(
&self,
_: &[u8],
_: &(),
) -> Result<(), device::ShaderError> {
unimplemented!()
}

Expand Down
7 changes: 5 additions & 2 deletions src/backend/gl/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,12 @@ impl d::Device<B> for Device {
}
}

fn create_pipeline_layout<IS, IR>(&self, _: IS, _: IR) -> n::PipelineLayout
fn create_pipeline_layout<IS, IR, IB>(&self, _: IS, _: IR) -> n::PipelineLayout
where
IS: IntoIterator,
IS::Item: Borrow<n::DescriptorSetLayout>,
IS::Item: Borrow<(n::DescriptorSetLayout, IB)>,
IB: IntoIterator,
IB::Item: Borrow<u32>,
IR: IntoIterator,
IR::Item: Borrow<(pso::ShaderStageFlags, Range<u32>)>,
{
Expand Down Expand Up @@ -603,6 +605,7 @@ impl d::Device<B> for Device {
fn create_shader_module(
&self,
raw_data: &[u8],
_pipeline_layout: &n::PipelineLayout,
) -> Result<n::ShaderModule, d::ShaderError> {
Ok(n::ShaderModule::Spirv(raw_data.into()))
}
Expand Down
14 changes: 10 additions & 4 deletions src/backend/metal/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,16 @@ impl hal::Device<Backend> for Device {
}
}

fn create_pipeline_layout<IS, IR>(
fn create_pipeline_layout<IS, IR, IB>(
&self,
set_layouts: IS,
_push_constant_ranges: IR,
) -> n::PipelineLayout
where
IS: IntoIterator,
IS::Item: Borrow<n::DescriptorSetLayout>,
IS::Item: Borrow<(n::DescriptorSetLayout, IB)>,
IB: IntoIterator,
IB::Item: Borrow<u32>,
IR: IntoIterator,
IR::Item: Borrow<(pso::ShaderStageFlags, Range<u32>)>
{
Expand All @@ -595,7 +597,7 @@ impl hal::Device<Backend> for Device {
let mut res_overrides = HashMap::new();

for (set_index, set_layout) in set_layouts.into_iter().enumerate() {
match set_layout.borrow() {
match set_layout.borrow().0 {
&n::DescriptorSetLayout::Emulated(ref set_bindings) => {
for set_binding in set_bindings {
for &mut(stage_bit, stage, ref mut counters) in stage_infos.iter_mut() {
Expand Down Expand Up @@ -920,7 +922,11 @@ impl hal::Device<Backend> for Device {
Ok(n::FrameBuffer(descriptor))
}

fn create_shader_module(&self, raw_data: &[u8]) -> Result<n::ShaderModule, ShaderError> {
fn create_shader_module(
&self,
raw_data: &[u8],
_pipeline_layout: &n::PipelineLayout,
) -> Result<n::ShaderModule, ShaderError> {
//TODO: we can probably at least parse here and save the `Ast`
let depends_on_pipeline_layout = true; //TODO: !self.private_caps.argument_buffers
Ok(if depends_on_pipeline_layout {
Expand Down
14 changes: 10 additions & 4 deletions src/backend/vulkan/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,19 @@ impl d::Device<B> for Device {
n::RenderPass { raw: renderpass }
}

fn create_pipeline_layout<IS, IR>(&self, sets: IS, push_constant_ranges: IR) -> n::PipelineLayout
fn create_pipeline_layout<IS, IR, IB>(&self, sets: IS, push_constant_ranges: IR) -> n::PipelineLayout
where
IS: IntoIterator,
IS::Item: Borrow<n::DescriptorSetLayout>,
IS::Item: Borrow<(n::DescriptorSetLayout, IB)>,
IB: IntoIterator,
IB::Item: Borrow<u32>,
IR: IntoIterator,
IR::Item: Borrow<(pso::ShaderStageFlags, Range<u32>)>,
{
let set_layouts = sets
.into_iter()
.map(|set| {
set.borrow().raw
set.borrow().0.raw
}).collect::<Vec<_>>();

debug!("create_pipeline_layout {:?}", set_layouts);
Expand Down Expand Up @@ -811,7 +813,11 @@ impl d::Device<B> for Device {
Ok(n::Framebuffer { raw: framebuffer })
}

fn create_shader_module(&self, spirv_data: &[u8]) -> Result<n::ShaderModule, d::ShaderError> {
fn create_shader_module(
&self,
spirv_data: &[u8],
_pipeline_layout: &n::PipelineLayout,
) -> Result<n::ShaderModule, d::ShaderError> {
// spec requires "codeSize must be a multiple of 4"
assert_eq!(spirv_data.len() & 3, 0);

Expand Down
18 changes: 14 additions & 4 deletions src/hal/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,20 @@ pub trait Device<B: Backend>: Any + Send + Sync {
///
/// # Arguments
///
/// * `set_layouts` - Descriptor set layouts
/// * `set_layouts` - The descriptor layouts and the sets which will use that layout.
/// * `push_constants` - Ranges of push constants. A shader stage may only contain one push
/// constant block. The length of the range indicates the number of u32 constants occupied
/// by the push constant block.
fn create_pipeline_layout<IS, IR>(
fn create_pipeline_layout<IS, IR, IB>(
&self,
set_layouts: IS,
push_constant: IR,
) -> B::PipelineLayout
where
IS: IntoIterator,
IS::Item: Borrow<B::DescriptorSetLayout>,
IS::Item: Borrow<(B::DescriptorSetLayout, IB)>,
IB: IntoIterator,
IB::Item: Borrow<u32>,
IR: IntoIterator,
IR::Item: Borrow<(pso::ShaderStageFlags, Range<u32>)>;

Expand Down Expand Up @@ -270,9 +272,17 @@ pub trait Device<B: Backend>: Any + Send + Sync {
/// which references the framebuffer, has finished execution.
fn destroy_framebuffer(&self, buf: B::Framebuffer);

/// Creates a shader module
///
/// Creating a shader module requires passing in both the spirv for the
/// shader and the pipeline layout that will be used with this shader.
///
/// Shader modules should not be passed to pipelines who's pipeline layout
/// was diffrent then the one the shader module was created with.
fn create_shader_module(
&self, spirv_data: &[u8]
&self,
spirv_data: &[u8],
pipeline_layout: &B::PipelineLayout,
) -> Result<B::ShaderModule, ShaderError>;

///
Expand Down

0 comments on commit 45a9dde

Please sign in to comment.