Add CmdBindIndexBuffer

This commit is contained in:
Pierre Krieger 2016-11-10 09:52:39 +01:00
parent f4814bcc6e
commit 77aedd71d9
4 changed files with 97 additions and 0 deletions

View File

@ -192,6 +192,7 @@ impl<L, P> UnsyncedCommandBuffer<L, P> where L: CommandsList, P: CommandPool {
current_state: DynamicState::none(),
bound_graphics_pipeline: 0,
bound_compute_pipeline: 0,
bound_index_buffer: (0, 0, 0),
resources_states: StatesManager::new(),
marker: PhantomData,
};

View File

@ -0,0 +1,93 @@
// Copyright (c) 2016 The vulkano developers
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
// at your option. All files in the project carrying such
// notice may not be copied, modified, or distributed except
// according to those terms.
use std::sync::Arc;
use buffer::TrackedBuffer;
use buffer::TypedBuffer;
use command_buffer::RawCommandBufferPrototype;
use command_buffer::CommandsList;
use command_buffer::CommandsListSink;
use device::Device;
use pipeline::input_assembly::Index;
use VulkanObject;
use VulkanPointers;
use vk;
/// Wraps around a commands list and adds a command that binds an index buffer at the end of it.
pub struct CmdBindIndexBuffer<L, B> where L: CommandsList {
// Parent commands list.
previous: L,
// Raw handle of the buffer to bind.
raw_buffer: vk::Buffer,
// Raw offset of the buffer to bind.
offset: vk::DeviceSize,
// Type of index.
index_type: vk::IndexType,
// The device of the buffer, so that we can compare it with the command buffer's device.
device: Arc<Device>,
// The buffer to bind. Unused, but we need to keep it alive.
buffer: B,
}
impl<L, B, I> CmdBindIndexBuffer<L, B>
where L: CommandsList,
B: TrackedBuffer + TypedBuffer<Content = [I]>,
I: Index + 'static
{
/// Builds the command.
#[inline]
pub fn new(previous: L, buffer: B) -> CmdBindIndexBuffer<L, B> {
let device;
let raw_buffer;
let offset;
{
let inner = buffer.inner();
device = inner.buffer.device().clone();
raw_buffer = inner.buffer.internal_object();
offset = inner.offset as vk::DeviceSize;
}
CmdBindIndexBuffer {
previous: previous,
raw_buffer: raw_buffer,
offset: offset,
index_type: I::ty() as vk::IndexType,
device: device,
buffer: buffer,
}
}
}
impl<L, B> CmdBindIndexBuffer<L, B> where L: CommandsList, B: TrackedBuffer {
#[inline]
fn append<'a>(&'a self, builder: &mut CommandsListSink<'a>) {
self.previous.append(builder);
assert_eq!(self.device.internal_object(), builder.device().internal_object());
builder.add_buffer_transition(&self.buffer, 0, self.buffer.size(), false);
builder.add_command(Box::new(move |raw: &mut RawCommandBufferPrototype| {
let params = (self.raw_buffer, self.offset, self.index_type);
if raw.bound_index_buffer == params {
return;
}
raw.bound_index_buffer = params;
unsafe {
let vk = raw.device.pointers();
let cmd = raw.command_buffer.clone().take().unwrap();
vk.CmdBindIndexBuffer(cmd, self.raw_buffer, self.offset, self.index_type);
}
}));
}
}

View File

@ -37,6 +37,7 @@ use pipeline::vertex::Source;
use sync::Fence;
use vk;
pub use self::bind_index_buffer::CmdBindIndexBuffer;
pub use self::bind_descriptor_sets::{CmdBindDescriptorSets, CmdBindDescriptorSetsError};
pub use self::bind_pipeline::CmdBindPipeline;
pub use self::blit_image_unsynced::{BlitRegion, BlitRegionAspect};
@ -48,6 +49,7 @@ pub use self::set_state::{CmdSetState};
pub use self::update_buffer::{CmdUpdateBuffer, CmdUpdateBufferError};
mod bind_descriptor_sets;
mod bind_index_buffer;
mod bind_pipeline;
mod blit_image_unsynced;
mod copy_buffer;

View File

@ -125,6 +125,7 @@ pub struct RawCommandBufferPrototype<'a> {
current_state: DynamicState,
bound_graphics_pipeline: vk::Pipeline,
bound_compute_pipeline: vk::Pipeline,
bound_index_buffer: (vk::Buffer, vk::DeviceSize, vk::IndexType),
resources_states: StatesManager,
marker: PhantomData<&'a ()>,
}