Fix remaining bits to make teapot example compile

This commit is contained in:
Pierre Krieger 2016-03-23 11:15:43 +01:00
parent 8cc816e9f3
commit 6cf7b5ace4
8 changed files with 52 additions and 27 deletions

View File

@ -47,7 +47,7 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
&parse::Instruction::TypeStruct { result_id, .. } if result_id == pointed_ty => {
Some((
"::vulkano::descriptor_set::DescriptorType::UniformBuffer",
"::std::sync::Arc<::vulkano::buffer::AbstractBuffer>",
"::std::sync::Arc<::vulkano::buffer::Buffer>",
"::vulkano::descriptor_set::DescriptorBind::UniformBuffer { buffer: data, offset: 0, size: 128 /* FIXME */ }"
))
},

View File

@ -14,6 +14,7 @@ use std::ffi::OsStr;
use std::os::windows::ffi::OsStrExt;
use std::mem;
use std::ptr;
use std::sync::Arc;
mod vs { include!{concat!(env!("OUT_DIR"), "/shaders/examples/teapot_vs.glsl")} }
mod fs { include!{concat!(env!("OUT_DIR"), "/shaders/examples/teapot_fs.glsl")} }
@ -76,10 +77,9 @@ fn main() {
let depth_buffer = depth_buffer.transition(vulkano::image::Layout::DepthStencilAttachmentOptimal, &cb_pool, &queue).unwrap();
let depth_buffer = vulkano::image::ImageView::new(&depth_buffer).expect("failed to create image view");
let vertex_buffer = vulkano::buffer::Buffer
let vertex_buffer = vulkano::buffer::cpu_access::CpuAccessibleBuffer
::array(&device, teapot::VERTICES.len(),
&vulkano::buffer::Usage::all(),
vulkano::memory::HostVisible, &queue)
&vulkano::buffer::Usage::all(), Some(queue.family()))
.expect("failed to create buffer");
{
@ -89,10 +89,9 @@ fn main() {
}
}
let normals_buffer = vulkano::buffer::Buffer
let normals_buffer = vulkano::buffer::cpu_access::CpuAccessibleBuffer
::array(&device, teapot::NORMALS.len(),
&vulkano::buffer::Usage::all(),
vulkano::memory::HostVisible, &queue)
&vulkano::buffer::Usage::all(), Some(queue.family()))
.expect("failed to create buffer");
{
@ -102,10 +101,9 @@ fn main() {
}
}
let index_buffer = vulkano::buffer::Buffer
let index_buffer = vulkano::buffer::cpu_access::CpuAccessibleBuffer
::array(&device, teapot::INDICES.len(),
&vulkano::buffer::Usage::all(),
vulkano::memory::HostVisible, &queue)
&vulkano::buffer::Usage::all(), Some(queue.family()))
.expect("failed to create buffer");
{
@ -121,9 +119,8 @@ fn main() {
let view = cgmath::Matrix4::look_at(cgmath::Point3::new(0.3, 0.3, 1.0), cgmath::Point3::new(0.0, 0.0, 0.0), cgmath::Vector3::new(0.0, -1.0, 0.0));
let scale = cgmath::Matrix4::from_scale(0.01);
let uniform_buffer = vulkano::buffer::Buffer::<vs::ty::Data, _>
::new(&device, &vulkano::buffer::Usage::all(),
vulkano::memory::HostVisible, &queue)
let uniform_buffer = vulkano::buffer::cpu_access::CpuAccessibleBuffer::<vs::ty::Data>
::new(&device, &vulkano::buffer::Usage::all(), Some(queue.family()))
.expect("failed to create buffer");
{
let mut mapping = uniform_buffer.try_write().unwrap();
@ -217,7 +214,7 @@ fn main() {
.build().unwrap()
}).collect::<Vec<_>>();
let mut submissions: Vec<vulkano::command_buffer::Submission> = Vec::new();
let mut submissions: Vec<Arc<vulkano::command_buffer::Submission>> = Vec::new();
loop {
submissions.retain(|s| !s.destroying_would_block());

View File

@ -6,6 +6,7 @@ use std::sync::Mutex;
use smallvec::SmallVec;
use buffer::traits::Buffer;
use buffer::traits::TypedBuffer;
use buffer::unsafe_buffer::UnsafeBuffer;
use buffer::unsafe_buffer::Usage;
use command_buffer::Submission;
@ -48,7 +49,7 @@ impl<T> CpuAccessibleBuffer<T> {
impl<T> CpuAccessibleBuffer<[T]> {
#[inline]
pub fn array<'a, I>(device: &Arc<Device>, len: usize, usage: &Usage, queue_families: I)
-> Result<Arc<CpuAccessibleBuffer<T>>, OomError>
-> Result<Arc<CpuAccessibleBuffer<[T]>>, OomError>
where I: IntoIterator<Item = QueueFamily<'a>>
{
unsafe {
@ -98,22 +99,22 @@ impl<T: ?Sized> CpuAccessibleBuffer<T> {
}
impl<T: ?Sized> CpuAccessibleBuffer<T> where T: Content + 'static {
fn read(&self, timeout_ns: u64) -> CpuAccess<T> { // FIXME: error
pub fn read(&self, timeout_ns: u64) -> CpuAccess<T> { // FIXME: error
// FIXME: correct implementation
unsafe { self.memory.read() }
}
fn try_read(&self) -> Option<CpuAccess<T>> {
pub fn try_read(&self) -> Option<CpuAccess<T>> {
// FIXME: correct implementation
unsafe { Some(self.memory.read()) }
}
fn write(&self, timeout_ns: u64) -> CpuAccess<T> { // FIXME: error
pub fn write(&self, timeout_ns: u64) -> CpuAccess<T> { // FIXME: error
// FIXME: correct implementation
unsafe { self.memory.write() }
}
fn try_write(&self) -> Option<CpuAccess<T>> {
pub fn try_write(&self) -> Option<CpuAccess<T>> {
// FIXME: correct implementation
unsafe { Some(self.memory.write()) }
}
@ -149,3 +150,7 @@ unsafe impl<T: ?Sized> Buffer for CpuAccessibleBuffer<T> {
}
}
}
unsafe impl<T: ?Sized + 'static> TypedBuffer for CpuAccessibleBuffer<T> {
type Content = T;
}

View File

@ -8,6 +8,7 @@ use std::sync::atomic::Ordering;
use smallvec::SmallVec;
use buffer::traits::Buffer;
use buffer::traits::TypedBuffer;
use buffer::unsafe_buffer::UnsafeBuffer;
use buffer::unsafe_buffer::Usage;
use command_buffer::Submission;
@ -148,3 +149,7 @@ unsafe impl<T: ?Sized> Buffer for ImmutableBuffer<T> {
}
}
}
unsafe impl<T: ?Sized + 'static> TypedBuffer for ImmutableBuffer<T> {
type Content = T;
}

View File

@ -6,6 +6,7 @@ use std::sync::Arc;
use std::sync::Mutex;
use buffer::traits::Buffer;
use buffer::traits::TypedBuffer;
use buffer::unsafe_buffer::UnsafeBuffer;
use buffer::unsafe_buffer::Usage;
use command_buffer::Submission;
@ -100,3 +101,7 @@ unsafe impl<T: ?Sized> Buffer for StagingBuffer<T> {
}
}
}
unsafe impl<T: ?Sized + 'static> TypedBuffer for StagingBuffer<T> {
type Content = T;
}

View File

@ -1,9 +1,9 @@
use std::mem;
use std::ops::Range;
use std::sync::Arc;
use buffer::unsafe_buffer::UnsafeBuffer;
use command_buffer::Submission;
use memory::Content;
pub unsafe trait Buffer {
/// Returns the inner buffer.
@ -26,7 +26,7 @@ pub unsafe trait TypedBuffer: Buffer {
type Content: ?Sized + 'static;
#[inline]
fn len(&self) -> usize where Self::Content: Sized {
self.size() / mem::size_of::<Self::Content>()
fn len(&self) -> usize where Self::Content: Content {
self.size() / <Self::Content as Content>::indiv_size()
}
}

View File

@ -228,6 +228,9 @@ pub unsafe trait Content {
/// Returns true if the size is suitable to store a type like this.
fn is_size_suitable(usize) -> bool;
/// Returns the size of an individual element.
fn indiv_size() -> usize;
}
unsafe impl<T> Content for T {
@ -244,6 +247,11 @@ unsafe impl<T> Content for T {
fn is_size_suitable(size: usize) -> bool {
size == mem::size_of::<T>()
}
#[inline]
fn indiv_size() -> usize {
mem::size_of::<T>()
}
}
unsafe impl<T> Content for [T] {
@ -258,6 +266,11 @@ unsafe impl<T> Content for [T] {
fn is_size_suitable(size: usize) -> bool {
size % mem::size_of::<T>() == 0
}
#[inline]
fn indiv_size() -> usize {
mem::size_of::<T>()
}
}
/*

View File

@ -128,7 +128,7 @@ unsafe impl<T> Definition for SingleBufferDefinition<T> where T: Vertex {
}
unsafe impl<'a, B, V> Source<&'a Arc<B>> for SingleBufferDefinition<V>
where B: TypedBuffer<Content = V> + 'static, V: Vertex + 'static
where B: TypedBuffer<Content = [V]> + 'static, V: Vertex + 'static
{
type Iter = OptionIntoIter<Arc<Buffer>>;
@ -172,8 +172,8 @@ unsafe impl<T, U> Definition for TwoBuffersDefinition<T, U> where T: Vertex, U:
}
unsafe impl<'a, T, U, Bt, Bu> Source<(&'a Arc<Bt>, &'a Arc<Bu>)> for TwoBuffersDefinition<T, U>
where T: Vertex + 'static, Bt: TypedBuffer<Content = T> + 'static, T: 'static,
U: Vertex + 'static, Bu: TypedBuffer<Content = U> + 'static, T: 'static
where T: Vertex + 'static, Bt: TypedBuffer<Content = [T]> + 'static, T: 'static,
U: Vertex + 'static, Bu: TypedBuffer<Content = [U]> + 'static, T: 'static
{
type Iter = VecIntoIter<Arc<Buffer>>;
@ -219,8 +219,8 @@ unsafe impl<T, U> Definition for OneVertexOneInstanceDefinition<T, U> where T: V
}
unsafe impl<'a, T, U, Bt, Bu> Source<(&'a Arc<Bt>, &'a Arc<Bu>)> for OneVertexOneInstanceDefinition<T, U>
where T: Vertex + 'static, Bt: TypedBuffer<Content = T> + 'static, T: 'static,
U: Vertex + 'static, Bu: TypedBuffer<Content = U> + 'static, U: 'static
where T: Vertex + 'static, Bt: TypedBuffer<Content = [T]> + 'static, T: 'static,
U: Vertex + 'static, Bu: TypedBuffer<Content = [U]> + 'static, U: 'static
{
type Iter = VecIntoIter<Arc<Buffer>>;