Skip to content

Commit

Permalink
Merge #197
Browse files Browse the repository at this point in the history
197: Fixes #58 + minor fixes r=Frizi a=malobre

Fixes #58 + minor changes:
* The `source_shaders` example had incorrect logging filter
* The `quads` example used `println!` instead of logging-macros


Co-authored-by: Maël Obréjan <malobre@armanix.net>
  • Loading branch information
bors[bot] and Maël Obréjan committed Sep 23, 2019
2 parents 9e7cb21 + 1a23b74 commit b48f5d1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
39 changes: 27 additions & 12 deletions factory/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,24 @@ where
&self,
buffer: &mut Buffer<B>,
offset: u64,
content: &[T],
) -> Result<(), MapError> {
content: &T,
) -> Result<(), MapError>
where
T: ?Sized + 'static,
{
let content_size = std::mem::size_of_val(content);

let content = std::slice::from_raw_parts(
content.as_ptr() as *const u8,
content.len() * std::mem::size_of::<T>(),
{
let content_ptr: *const T = content;
content_ptr as *const u8
},
content_size,
);

let mut mapped = buffer.map(&self.device, offset..offset + content.len() as u64)?;
let mut mapped = buffer.map(&self.device, offset..offset + content_size as u64)?;
mapped
.write(&self.device, 0..content.len() as u64)?
.write(&self.device, 0..content_size as u64)?
.write(content);
Ok(())
}
Expand Down Expand Up @@ -437,13 +445,17 @@ where
&self,
buffer: &Buffer<B>,
offset: u64,
content: &[T],
content: &T,
last: Option<BufferState>,
next: BufferState,
) -> Result<(), UploadError> {
) -> Result<(), UploadError>
where
T: ?Sized + 'static,
{
assert!(buffer.info().usage.contains(buffer::Usage::TRANSFER_DST));

let content_size = content.len() as u64 * std::mem::size_of::<T>() as u64;
let content_size = std::mem::size_of_val(content) as u64;

let mut staging = self
.create_buffer(
BufferInfo {
Expand Down Expand Up @@ -544,17 +556,20 @@ where
image_layers: SubresourceLayers,
image_offset: image::Offset,
image_extent: Extent,
content: &[T],
content: &T,
last: impl Into<ImageStateOrLayout>,
next: ImageState,
) -> Result<(), UploadError> {
) -> Result<(), UploadError>
where
T: ?Sized + 'static,
{
assert!(image.info().usage.contains(image::Usage::TRANSFER_DST));
assert_eq!(image.format().surface_desc().aspects, image_layers.aspects);
assert!(image_layers.layers.start <= image_layers.layers.end);
assert!(image_layers.layers.end <= image.kind().num_layers());
assert!(image_layers.level <= image.info().levels);

let content_size = content.len() as u64 * std::mem::size_of::<T>() as u64;
let content_size = std::mem::size_of_val(content) as u64;
let format_desc = image.format().surface_desc();
let texels_count = (image_extent.width / format_desc.dim.0 as u32) as u64
* (image_extent.height / format_desc.dim.1 as u32) as u64
Expand Down
2 changes: 1 addition & 1 deletion mesh/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl<'a> MeshBuilder<'a> {
factory.upload_buffer(
&mut buffer,
0,
&indices,
&**indices,
None,
BufferState::new(queue)
.with_access(gfx_hal::buffer::Access::INDEX_BUFFER_READ)
Expand Down
6 changes: 3 additions & 3 deletions rendy/examples/quads/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ where
.upload_buffer(
posvelbuff,
0,
&POSVEL_DATA,
&POSVEL_DATA[..],
None,
BufferState {
queue: QueueId {
Expand Down Expand Up @@ -582,7 +582,7 @@ fn run(
WindowEvent::Resized(_dims) => {
let started = std::time::Instant::now();
graph.take().unwrap().dispose(&mut factory, &());
println!("Graph disposed in: {:?}", started.elapsed());
log::trace!("Graph disposed in: {:?}", started.elapsed());
graph = Some(build_graph(&mut factory, &mut families, &window));
}
_ => {}
Expand Down Expand Up @@ -691,7 +691,7 @@ fn build_graph(

let started = std::time::Instant::now();
let graph = graph_builder.build(factory, families, &()).unwrap();
println!("Graph built in: {:?}", started.elapsed());
log::trace!("Graph built in: {:?}", started.elapsed());
graph
}

Expand Down
2 changes: 1 addition & 1 deletion rendy/examples/source_shaders/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ fn run(
#[cfg(any(feature = "dx12", feature = "metal", feature = "vulkan"))]
fn main() {
env_logger::Builder::from_default_env()
.filter_module("triangle", log::LevelFilter::Trace)
.filter_module("source_shaders", log::LevelFilter::Trace)
.init();

let config: Config = Default::default();
Expand Down

0 comments on commit b48f5d1

Please sign in to comment.