|
@@ -128,23 +128,22 @@ const SHADER_VISIBLE: u32 = 1;
|
|
|
#[cfg(windows)]
|
|
#[cfg(windows)]
|
|
|
static SHADER_HEAPS: std::sync::Mutex<Vec<(u64, u64, usize)>> = std::sync::Mutex::new(Vec::new());
|
|
static SHADER_HEAPS: std::sync::Mutex<Vec<(u64, u64, usize)>> = std::sync::Mutex::new(Vec::new());
|
|
|
|
|
|
|
|
-/// The shader-visible heap holding `handle`, and the descriptor's index.
|
|
|
|
|
|
|
+/// Makes the host descriptor for what the title wrote at `handle`, if it
|
|
|
|
|
+/// is in a shader-visible heap. Keeps `SHADER_HEAPS` locked for the duration
|
|
|
|
|
+/// so `Heap::drop` cannot free the heap concurrently.
|
|
|
#[cfg(windows)]
|
|
#[cfg(windows)]
|
|
|
-fn shader_slot<'a>(handle: u64) -> Option<(&'a Heap, u32)> {
|
|
|
|
|
|
|
+fn mirror(handle: u64) {
|
|
|
let heaps = SHADER_HEAPS.lock().unwrap_or_else(|e| e.into_inner());
|
|
let heaps = SHADER_HEAPS.lock().unwrap_or_else(|e| e.into_inner());
|
|
|
- let &(_, _, at) = heaps
|
|
|
|
|
|
|
+ let Some(&(_, _, at)) = heaps
|
|
|
.iter()
|
|
.iter()
|
|
|
- .find(|&&(start, end, _)| (start..end).contains(&handle))?;
|
|
|
|
|
- // SAFETY: registered heaps are live (removed when dropped).
|
|
|
|
|
|
|
+ .find(|&&(start, end, _)| (start..end).contains(&handle))
|
|
|
|
|
+ else {
|
|
|
|
|
+ return;
|
|
|
|
|
+ };
|
|
|
|
|
+ // SAFETY: registered heaps stay alive until `Heap::drop`, which takes
|
|
|
|
|
+ // the `SHADER_HEAPS` lock we hold here.
|
|
|
let heap = unsafe { &*(at as *const Heap) };
|
|
let heap = unsafe { &*(at as *const Heap) };
|
|
|
- Some((heap, heap.index(handle)?))
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/// Makes the host descriptor for what the title wrote at `handle`, if it
|
|
|
|
|
-/// is in a shader-visible heap.
|
|
|
|
|
-#[cfg(windows)]
|
|
|
|
|
-fn mirror(handle: u64) {
|
|
|
|
|
- let Some((heap, index)) = shader_slot(handle) else {
|
|
|
|
|
|
|
+ let Some(index) = heap.index(handle) else {
|
|
|
return;
|
|
return;
|
|
|
};
|
|
};
|
|
|
let mut pending = heap.pending.lock().unwrap_or_else(|e| e.into_inner());
|
|
let mut pending = heap.pending.lock().unwrap_or_else(|e| e.into_inner());
|
|
@@ -977,7 +976,9 @@ pub(crate) extern "system" fn create_sampler_x(_: This, desc: *const [u32; 27],
|
|
|
|
|
|
|
|
/// Device method: `count` descriptors of `kind` from `src` to `dst`.
|
|
/// Device method: `count` descriptors of `kind` from `src` to `dst`.
|
|
|
pub(crate) extern "system" fn copy_simple(_: This, count: u32, dst: u64, src: u64, kind: u32) {
|
|
pub(crate) extern "system" fn copy_simple(_: This, count: u32, dst: u64, src: u64, kind: u32) {
|
|
|
- let step = u64::from(increment(kind).unwrap_or(0));
|
|
|
|
|
|
|
+ let Some(step) = increment(kind).map(u64::from) else {
|
|
|
|
|
+ return;
|
|
|
|
|
+ };
|
|
|
let len = u64::from(count) * step;
|
|
let len = u64::from(count) * step;
|
|
|
if dst != 0 && src != 0 {
|
|
if dst != 0 && src != 0 {
|
|
|
// SAFETY: both ranges are descriptor slots the title owns.
|
|
// SAFETY: both ranges are descriptor slots the title owns.
|
|
@@ -1084,6 +1085,9 @@ pub(crate) extern "system" fn create_heap(
|
|
|
let placed = placement.address != 0 && placement.size == size;
|
|
let placed = placement.address != 0 && placement.size == size;
|
|
|
tracing::debug!(?desc, placed, "descriptor heap");
|
|
tracing::debug!(?desc, placed, "descriptor heap");
|
|
|
let (start, memory) = if placed {
|
|
let (start, memory) = if placed {
|
|
|
|
|
+ if placement.address.checked_add(size).is_none() {
|
|
|
|
|
+ return E_INVALIDARG;
|
|
|
|
|
+ }
|
|
|
(placement.address, None)
|
|
(placement.address, None)
|
|
|
} else {
|
|
} else {
|
|
|
match Memory::zeroed(size, 64) {
|
|
match Memory::zeroed(size, 64) {
|