[wgpu-core] validate that all resources passed to encoder commands belong to the same device as the encoder

This commit is contained in:
teoxoy 2024-04-16 12:37:50 +02:00 committed by Teodor Tanasoaia
parent a61c872269
commit 895879b8c6
3 changed files with 54 additions and 1 deletions

View File

@ -104,6 +104,11 @@ impl Global {
let dst_buffer = buffer_guard
.get(dst)
.map_err(|_| ClearError::InvalidBuffer(dst))?;
if dst_buffer.device.as_info().id() != cmd_buf.device.as_info().id() {
return Err(DeviceError::WrongDevice.into());
}
cmd_buf_data
.trackers
.buffers
@ -200,6 +205,10 @@ impl Global {
.get(dst)
.map_err(|_| ClearError::InvalidTexture(dst))?;
if dst_texture.device.as_info().id() != cmd_buf.device.as_info().id() {
return Err(DeviceError::WrongDevice.into());
}
// Check if subresource aspects are valid.
let clear_aspects =
hal::FormatAspects::new(dst_texture.desc.format, subresource_range.aspect);

View File

@ -9,7 +9,7 @@ use crate::{
hal_api::HalApi,
id::{self, Id},
init_tracker::MemoryInitKind,
resource::QuerySet,
resource::{QuerySet, Resource},
storage::Storage,
Epoch, FastHashMap, Index,
};
@ -429,11 +429,20 @@ impl Global {
.add_single(&*query_set_guard, query_set_id)
.ok_or(QueryError::InvalidQuerySet(query_set_id))?;
if query_set.device.as_info().id() != cmd_buf.device.as_info().id() {
return Err(DeviceError::WrongDevice.into());
}
let (dst_buffer, dst_pending) = {
let buffer_guard = hub.buffers.read();
let dst_buffer = buffer_guard
.get(destination)
.map_err(|_| QueryError::InvalidBuffer(destination))?;
if dst_buffer.device.as_info().id() != cmd_buf.device.as_info().id() {
return Err(DeviceError::WrongDevice.into());
}
tracker
.buffers
.set_single(dst_buffer, hal::BufferUses::COPY_DST)

View File

@ -607,6 +607,11 @@ impl Global {
let src_buffer = buffer_guard
.get(source)
.map_err(|_| TransferError::InvalidBuffer(source))?;
if src_buffer.device.as_info().id() != device.as_info().id() {
return Err(DeviceError::WrongDevice.into());
}
cmd_buf_data
.trackers
.buffers
@ -628,6 +633,11 @@ impl Global {
let dst_buffer = buffer_guard
.get(destination)
.map_err(|_| TransferError::InvalidBuffer(destination))?;
if dst_buffer.device.as_info().id() != device.as_info().id() {
return Err(DeviceError::WrongDevice.into());
}
cmd_buf_data
.trackers
.buffers
@ -777,6 +787,10 @@ impl Global {
.get(destination.texture)
.map_err(|_| TransferError::InvalidTexture(destination.texture))?;
if dst_texture.device.as_info().id() != device.as_info().id() {
return Err(DeviceError::WrongDevice.into());
}
let (hal_copy_size, array_layer_count) = validate_texture_copy_range(
destination,
&dst_texture.desc,
@ -807,6 +821,11 @@ impl Global {
let src_buffer = buffer_guard
.get(source.buffer)
.map_err(|_| TransferError::InvalidBuffer(source.buffer))?;
if src_buffer.device.as_info().id() != device.as_info().id() {
return Err(DeviceError::WrongDevice.into());
}
tracker
.buffers
.set_single(src_buffer, hal::BufferUses::COPY_SRC)
@ -938,6 +957,10 @@ impl Global {
.get(source.texture)
.map_err(|_| TransferError::InvalidTexture(source.texture))?;
if src_texture.device.as_info().id() != device.as_info().id() {
return Err(DeviceError::WrongDevice.into());
}
let (hal_copy_size, array_layer_count) =
validate_texture_copy_range(source, &src_texture.desc, CopySide::Source, copy_size)?;
@ -989,6 +1012,11 @@ impl Global {
let dst_buffer = buffer_guard
.get(destination.buffer)
.map_err(|_| TransferError::InvalidBuffer(destination.buffer))?;
if dst_buffer.device.as_info().id() != device.as_info().id() {
return Err(DeviceError::WrongDevice.into());
}
tracker
.buffers
.set_single(dst_buffer, hal::BufferUses::COPY_DST)
@ -1117,6 +1145,13 @@ impl Global {
.get(destination.texture)
.map_err(|_| TransferError::InvalidTexture(source.texture))?;
if src_texture.device.as_info().id() != device.as_info().id() {
return Err(DeviceError::WrongDevice.into());
}
if dst_texture.device.as_info().id() != device.as_info().id() {
return Err(DeviceError::WrongDevice.into());
}
// src and dst texture format must be copy-compatible
// https://gpuweb.github.io/gpuweb/#copy-compatible
if src_texture.desc.format.remove_srgb_suffix()