Giter Club home page Giter Club logo

Comments (4)

wbrickner avatar wbrickner commented on May 26, 2024

Weird! I see that you are setting the copy destination flag correctly. Following the execution from .as_device_boxed_mut() above:

emu/emu_core/src/device.rs

Lines 260 to 302 in 9fe3db3

fn create_from_as<T, B: Borrow<T>>(
&mut self,
host_obj: B,
mutability: Mutability,
) -> DeviceBox<T>
where
T: AsBytes + ?Sized,
{
// serialize the data into bytes
// these bytes can later be deserialized back into T
let host_obj_bytes = host_obj.borrow().as_bytes();
// create a staging buffer with host_obj copied over
let staging_buffer = self.device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: host_obj_bytes.len() as u64,
usage: wgpu::BufferUsage::MAP_READ | wgpu::BufferUsage::COPY_DST,
mapped_at_creation: false,
});
// then create an initialized storage buffer of appropriate size
let storage_buffer = self
.device
.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: None,
usage: match mutability {
Mutability::Mut => wgpu::BufferUsage::STORAGE,
Mutability::Const => wgpu::BufferUsage::STORAGE,
} | wgpu::BufferUsage::COPY_SRC
| wgpu::BufferUsage::COPY_DST,
contents: host_obj_bytes,
});
// return the final DeviceBox
// note that we keep both the storage buffer and the staging buffer
// we will re-use the staging buffer for reads (but not for writes, for writes we just create a new staging buffer)
DeviceBox {
staging_buffer,
storage_buffer,
size: host_obj_bytes.len() as u64,
phantom: PhantomData,
mutability: Some(mutability),
}
}

Any idea what the issue is?

from emu.

wbrickner avatar wbrickner commented on May 26, 2024

Update: removing the

shapes.set(vec![
  Shape {
    x: 0,
    y: 0,
    w: 100,
    h: 100,
    r: [2, 9]
  };
  1024
])?;

eliminates the error, and things always complete successfully.
Alternatively, leaving the .set call and removing the final .get call also prevents the panic.

Are usage flags being corrupted by .set?

from emu.

wbrickner avatar wbrickner commented on May 26, 2024

Ok, here's the problem:

80a28e7#diff-c42b8503ace5f383ffbc7c9f91463d31dc54fc36b2d3974c49a3e2fc434024e9R331-R337

when setting, the existing staging buffer is discarded and replaced with a new staging buffer, which is created with the usage flag COPY_SRC.

Adding to the end of the function the construction of a new staging buffer with MAP_READ | COPY_DST (as it usually has, from the DeviceBox construction pathway) solves the issue, when it comes time to read the correct usage is there.

I would like to not do it this way, it seems quite wasteful to prepare a new allocation and immediately discard it etc. Mixing
COPY_SRC and COPY_DST and MAP_READ permissions is not allowed evidently. The usage flag paradigm is the problem here, unsure how fundamentally important it really is. Perhaps two staging buffers could be lazily prepared, one for copies to/from the GPU device.

from emu.

calebwin avatar calebwin commented on May 26, 2024

@wbrickner Thanks for doing this investigation in this issue. I see how the staging buffer creation is problematic...

If anyone has a PR that fixes this, I can review/edit/merge.

from emu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.