240: Update to gfx-hal borrow refactor r=kvark a=kvark

Depends on https://github.com/gfx-rs/gfx/pull/3586
Also:
  - removes typed-arena dependency
  - removes soundness bug with semaphore fake state
  - use `make_slice` more

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
bors[bot] 2021-01-19 05:21:56 +00:00 committed by GitHub
commit 9737afa9be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 154 additions and 176 deletions

28
Cargo.lock generated
View file

@ -290,7 +290,7 @@ dependencies = [
[[package]] [[package]]
name = "gfx-auxil" name = "gfx-auxil"
version = "0.5.0" version = "0.5.0"
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad" source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
dependencies = [ dependencies = [
"fxhash", "fxhash",
"gfx-hal", "gfx-hal",
@ -300,7 +300,7 @@ dependencies = [
[[package]] [[package]]
name = "gfx-backend-dx11" name = "gfx-backend-dx11"
version = "0.6.0" version = "0.6.0"
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad" source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"bitflags", "bitflags",
@ -321,7 +321,7 @@ dependencies = [
[[package]] [[package]]
name = "gfx-backend-dx12" name = "gfx-backend-dx12"
version = "0.6.2" version = "0.6.2"
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad" source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"bit-set", "bit-set",
@ -341,7 +341,7 @@ dependencies = [
[[package]] [[package]]
name = "gfx-backend-empty" name = "gfx-backend-empty"
version = "0.6.0" version = "0.6.0"
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad" source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
dependencies = [ dependencies = [
"gfx-hal", "gfx-hal",
"log", "log",
@ -351,7 +351,7 @@ dependencies = [
[[package]] [[package]]
name = "gfx-backend-gl" name = "gfx-backend-gl"
version = "0.6.0" version = "0.6.0"
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad" source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"bitflags", "bitflags",
@ -364,7 +364,6 @@ dependencies = [
"log", "log",
"parking_lot", "parking_lot",
"raw-window-handle", "raw-window-handle",
"smallvec",
"spirv_cross", "spirv_cross",
"wasm-bindgen", "wasm-bindgen",
"web-sys", "web-sys",
@ -373,7 +372,7 @@ dependencies = [
[[package]] [[package]]
name = "gfx-backend-metal" name = "gfx-backend-metal"
version = "0.6.0" version = "0.6.0"
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad" source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"bitflags", "bitflags",
@ -396,7 +395,7 @@ dependencies = [
[[package]] [[package]]
name = "gfx-backend-vulkan" name = "gfx-backend-vulkan"
version = "0.6.5" version = "0.6.5"
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad" source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"ash", "ash",
@ -415,7 +414,7 @@ dependencies = [
[[package]] [[package]]
name = "gfx-hal" name = "gfx-hal"
version = "0.6.0" version = "0.6.0"
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad" source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"naga", "naga",
@ -540,7 +539,7 @@ dependencies = [
[[package]] [[package]]
name = "khronos-egl" name = "khronos-egl"
version = "3.0.0-beta" version = "3.0.0-beta"
source = "git+https://github.com/timothee-haudebourg/khronos-egl?rev=9568b2ee3b02f2c17cc9479f824db16daecf1664#9568b2ee3b02f2c17cc9479f824db16daecf1664" source = "git+https://github.com/timothee-haudebourg/khronos-egl?rev=4b769b8f2d068fa78db9285a8557cd11365fa314#4b769b8f2d068fa78db9285a8557cd11365fa314"
dependencies = [ dependencies = [
"libc", "libc",
"libloading", "libloading",
@ -760,7 +759,6 @@ dependencies = [
"log", "log",
"raw-window-handle", "raw-window-handle",
"renderdoc", "renderdoc",
"typed-arena",
] ]
[[package]] [[package]]
@ -838,7 +836,7 @@ dependencies = [
[[package]] [[package]]
name = "range-alloc" name = "range-alloc"
version = "0.1.1" version = "0.1.1"
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad" source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
[[package]] [[package]]
name = "raw-window-handle" name = "raw-window-handle"
@ -1019,12 +1017,6 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a686838375fc11103b9c1529c6508320b7bd5e2401cd62831ca51b3e82e61849" checksum = "a686838375fc11103b9c1529c6508320b7bd5e2401cd62831ca51b3e82e61849"
[[package]]
name = "typed-arena"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.1" version = "0.2.1"

View file

@ -8,3 +8,12 @@ members = [
[profile.release] [profile.release]
debug = true debug = true
panic = "abort" panic = "abort"
[patch."https://github.com/gfx-rs/gfx"]
#gfx-hal = { path = "../gfx/src/hal" }
#gfx-backend-empty = { path = "../gfx/src/backend/empty" }
#gfx-backend-vulkan = { path = "../gfx/src/backend/vulkan" }
#gfx-backend-gl = { path = "../gfx/src/backend/gl" }
#gfx-backend-dx12 = { path = "../gfx/src/backend/dx12" }
#gfx-backend-dx11 = { path = "../gfx/src/backend/dx11" }
#gfx-backend-metal = { path = "../gfx/src/backend/metal" }

View file

@ -23,44 +23,35 @@ copyless = "0.1.1"
env_logger = { version = "0.8", optional = true } env_logger = { version = "0.8", optional = true }
log = { version = "0.4", features = ["release_max_level_error"] } log = { version = "0.4", features = ["release_max_level_error"] }
renderdoc = { version = "0.3", optional = true } renderdoc = { version = "0.3", optional = true }
typed-arena = "2"
raw-window-handle = "0.3" raw-window-handle = "0.3"
[dependencies.hal] [dependencies.hal]
package = "gfx-hal" package = "gfx-hal"
git = "https://github.com/gfx-rs/gfx" git = "https://github.com/gfx-rs/gfx"
#path = "../../gfx/src/hal"
[dependencies.gfx-backend-empty] [dependencies.gfx-backend-empty]
git = "https://github.com/gfx-rs/gfx" git = "https://github.com/gfx-rs/gfx"
#path = "../../gfx/src/backend/empty"
[target.'cfg(not(any(target_os = "macos", target_os = "ios")))'.dependencies.gfx-backend-vulkan] [target.'cfg(not(any(target_os = "macos", target_os = "ios")))'.dependencies.gfx-backend-vulkan]
git = "https://github.com/gfx-rs/gfx" git = "https://github.com/gfx-rs/gfx"
#path = "../../gfx/src/backend/vulkan"
optional = true optional = true
[target.'cfg(windows)'.dependencies.gfx-backend-dx12] [target.'cfg(windows)'.dependencies.gfx-backend-dx12]
git = "https://github.com/gfx-rs/gfx" git = "https://github.com/gfx-rs/gfx"
#path = "../../gfx/src/backend/dx12"
optional = true optional = true
[target.'cfg(windows)'.dependencies.gfx-backend-dx11] [target.'cfg(windows)'.dependencies.gfx-backend-dx11]
git = "https://github.com/gfx-rs/gfx" git = "https://github.com/gfx-rs/gfx"
#path = "../../gfx/src/backend/dx11"
optional = true optional = true
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.gfx-backend-metal] [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.gfx-backend-metal]
git = "https://github.com/gfx-rs/gfx" git = "https://github.com/gfx-rs/gfx"
#path = "../../gfx/src/backend/metal"
optional = true optional = true
[target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "ios")))'.dependencies.gfx-backend-gl] [target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "ios")))'.dependencies.gfx-backend-gl]
git = "https://github.com/gfx-rs/gfx" git = "https://github.com/gfx-rs/gfx"
#path = "../../gfx/src/backend/gl"
optional = true optional = true
[dependencies.gfx-auxil] [dependencies.gfx-auxil]
git = "https://github.com/gfx-rs/gfx" git = "https://github.com/gfx-rs/gfx"
#path = "../../gfx/src/auxil/auxil"
optional = true optional = true

View file

@ -11,12 +11,11 @@ use hal::{
{command as com, memory, pass, pso, queue}, {Features, Instance}, {command as com, memory, pass, pso, queue}, {Features, Instance},
}; };
use typed_arena::Arena;
#[cfg(feature = "gfx-backend-metal")] #[cfg(feature = "gfx-backend-metal")]
use std::env; use std::env;
use std::{ use std::{
borrow::{Borrow, Cow}, borrow::{Borrow, Cow},
cell::Cell,
ffi::{CStr, CString}, ffi::{CStr, CString},
mem, mem,
os::raw::{c_int, c_void}, os::raw::{c_int, c_void},
@ -914,7 +913,12 @@ pub unsafe extern "C" fn gfxCreateDevice(
.map(|i| gpu.queue_groups.swap_remove(i).queues) .map(|i| gpu.queue_groups.swap_remove(i).queues)
.unwrap() .unwrap()
.into_iter() .into_iter()
.map(DispatchHandle::new) .map(|raw| {
DispatchHandle::new(Queue {
raw,
temp_semaphores: Vec::new(),
})
})
.collect(); .collect();
(info.queueFamilyIndex, queues) (info.queueFamilyIndex, queues)
@ -1146,12 +1150,12 @@ pub unsafe extern "C" fn gfxGetDeviceQueue(
{ {
if let Ok(value) = env::var("GFX_METAL_STITCHING") { if let Ok(value) = env::var("GFX_METAL_STITCHING") {
let mut q = queue; let mut q = queue;
q.stitch_deferred = match value.to_lowercase().as_str() { q.raw.stitch_deferred = match value.to_lowercase().as_str() {
"yes" => true, "yes" => true,
"no" => false, "no" => false,
other => panic!("unknown stitching option: {}", other), other => panic!("unknown stitching option: {}", other),
}; };
println!("GFX: stitching override {:?}", q.stitch_deferred); println!("GFX: stitching override {:?}", q.raw.stitch_deferred);
} }
} }
@ -1167,14 +1171,10 @@ pub unsafe extern "C" fn gfxQueueSubmit(
if submitCount == 0 { if submitCount == 0 {
use std::iter::empty; use std::iter::empty;
// sometimes, all you need is a fence... // sometimes, all you need is a fence...
let submission = hal::queue::Submission { queue.raw.submit(
command_buffers: empty(), empty(),
wait_semaphores: empty(), empty(),
signal_semaphores: empty(), empty(),
};
type RawSemaphore = <B as hal::Backend>::Semaphore;
queue.submit::<VkCommandBuffer, _, RawSemaphore, _, _>(
submission,
fence.as_mut().map(|f| &mut f.raw), fence.as_mut().map(|f| &mut f.raw),
); );
} else { } else {
@ -1184,7 +1184,7 @@ pub unsafe extern "C" fn gfxQueueSubmit(
submission.pCommandBuffers, submission.pCommandBuffers,
submission.commandBufferCount as usize, submission.commandBufferCount as usize,
); );
let wait_semaphores = { {
let semaphores = make_slice( let semaphores = make_slice(
submission.pWaitSemaphores, submission.pWaitSemaphores,
submission.waitSemaphoreCount as usize, submission.waitSemaphoreCount as usize,
@ -1194,13 +1194,11 @@ pub unsafe extern "C" fn gfxQueueSubmit(
submission.waitSemaphoreCount as usize, submission.waitSemaphoreCount as usize,
); );
stages queue.temp_semaphores.clear();
.into_iter() queue
.zip(semaphores) .temp_semaphores
.filter(|(_, semaphore)| !semaphore.is_fake) .extend(stages.iter().cloned().zip(semaphores.iter().cloned()));
.map(|(stage, semaphore)| { queue.temp_semaphores.retain(|&(_, sem)| !sem.is_fake.get());
(&semaphore.raw, conv::map_pipeline_stage_flags(*stage))
})
}; };
let signal_semaphores = make_slice( let signal_semaphores = make_slice(
submission.pSignalSemaphores, submission.pSignalSemaphores,
@ -1208,24 +1206,28 @@ pub unsafe extern "C" fn gfxQueueSubmit(
) )
.into_iter() .into_iter()
.map(|semaphore| { .map(|semaphore| {
semaphore.as_mut().unwrap().is_fake = false; semaphore.is_fake.set(false);
&semaphore.raw &semaphore.raw
}); });
let submission = hal::queue::Submission {
command_buffers: cmd_slice.iter(),
wait_semaphores,
signal_semaphores,
};
// only provide the fence for the last submission // only provide the fence for the last submission
//TODO: support multiple submissions at gfx-hal level
let fence = if i + 1 == submits.len() { let fence = if i + 1 == submits.len() {
fence.as_mut().map(|f| &mut f.raw) fence.as_mut().map(|f| &mut f.raw)
} else { } else {
None None
}; };
queue.submit(submission, fence); let Queue {
ref mut raw,
ref temp_semaphores,
} = *queue;
raw.submit(
cmd_slice.iter().map(|cmd_buf| &**cmd_buf),
temp_semaphores
.iter()
.map(|(stage, sem)| (&sem.raw, conv::map_pipeline_stage_flags(*stage))),
signal_semaphores,
fence,
);
} }
} }
@ -1233,7 +1235,7 @@ pub unsafe extern "C" fn gfxQueueSubmit(
} }
#[inline] #[inline]
pub unsafe extern "C" fn gfxQueueWaitIdle(mut queue: VkQueue) -> VkResult { pub unsafe extern "C" fn gfxQueueWaitIdle(mut queue: VkQueue) -> VkResult {
let _ = queue.wait_idle(); let _ = queue.raw.wait_idle();
VkResult::VK_SUCCESS VkResult::VK_SUCCESS
} }
#[inline] #[inline]
@ -1516,16 +1518,13 @@ pub unsafe extern "C" fn gfxResetFences(
fenceCount: u32, fenceCount: u32,
pFences: *const VkFence, pFences: *const VkFence,
) -> VkResult { ) -> VkResult {
let fence_slice = make_slice_mut(pFences as *mut VkFence, fenceCount as usize); for fence in make_slice_mut(pFences as *mut VkFence, fenceCount as usize) {
let fences = fence_slice.iter_mut().map(|fence| {
fence.as_mut().unwrap().is_fake = false; fence.as_mut().unwrap().is_fake = false;
&mut fence.raw if let Err(oom) = gpu.device.reset_fence(&mut fence.raw) {
}); return map_oom(oom);
match gpu.device.reset_fences(fences) {
Ok(()) => VkResult::VK_SUCCESS,
Err(oom) => map_oom(oom),
} }
}
VkResult::VK_SUCCESS
} }
#[inline] #[inline]
pub unsafe extern "C" fn gfxGetFenceStatus(gpu: VkDevice, fence: VkFence) -> VkResult { pub unsafe extern "C" fn gfxGetFenceStatus(gpu: VkDevice, fence: VkFence) -> VkResult {
@ -1587,7 +1586,7 @@ pub unsafe extern "C" fn gfxCreateSemaphore(
let semaphore = match gpu.device.create_semaphore() { let semaphore = match gpu.device.create_semaphore() {
Ok(raw) => Semaphore { Ok(raw) => Semaphore {
raw, raw,
is_fake: false, is_fake: Cell::new(false),
}, },
Err(oom) => return map_oom(oom), Err(oom) => return map_oom(oom),
}; };
@ -1982,14 +1981,14 @@ pub unsafe extern "C" fn gfxGetPipelineCacheData(
#[inline] #[inline]
pub unsafe extern "C" fn gfxMergePipelineCaches( pub unsafe extern "C" fn gfxMergePipelineCaches(
gpu: VkDevice, gpu: VkDevice,
dstCache: VkPipelineCache, mut dstCache: VkPipelineCache,
srcCacheCount: u32, srcCacheCount: u32,
pSrcCaches: *const VkPipelineCache, pSrcCaches: *const VkPipelineCache,
) -> VkResult { ) -> VkResult {
let caches = slice::from_raw_parts(pSrcCaches, srcCacheCount as usize); let caches = slice::from_raw_parts(pSrcCaches, srcCacheCount as usize);
match gpu match gpu
.device .device
.merge_pipeline_caches(&*dstCache, caches.iter().map(|h| &**h)) .merge_pipeline_caches(&mut *dstCache, caches.iter().map(|h| &**h))
{ {
Ok(()) => VkResult::VK_SUCCESS, Ok(()) => VkResult::VK_SUCCESS,
Err(oom) => map_oom(oom), Err(oom) => map_oom(oom),
@ -2005,7 +2004,7 @@ pub unsafe extern "C" fn gfxCreateGraphicsPipelines(
_pAllocator: *const VkAllocationCallbacks, _pAllocator: *const VkAllocationCallbacks,
pPipelines: *mut VkPipeline, pPipelines: *mut VkPipeline,
) -> VkResult { ) -> VkResult {
let infos = slice::from_raw_parts(pCreateInfos, createInfoCount as _); let infos = make_slice(pCreateInfos, createInfoCount as _);
let mut spec_constants = Vec::new(); let mut spec_constants = Vec::new();
let mut spec_data = Vec::new(); let mut spec_data = Vec::new();
@ -2033,10 +2032,12 @@ pub unsafe extern "C" fn gfxCreateGraphicsPipelines(
} }
} }
let out_pipelines = make_slice_mut(pPipelines, infos.len());
let mut cur_specialization = 0; let mut cur_specialization = 0;
let vertex_arena = Arena::with_capacity(createInfoCount as _); let mut vertex_buffers = Vec::new();
let mut vertex_attributes = Vec::new();
let descs = infos.into_iter().map(|info| { for (out_pipeline, info) in out_pipelines.iter_mut().zip(infos) {
let rasterizer_discard = (*info.pRasterizationState).rasterizerDiscardEnable == VK_TRUE; let rasterizer_discard = (*info.pRasterizationState).rasterizerDiscardEnable == VK_TRUE;
let empty_dyn_states = []; let empty_dyn_states = [];
@ -2047,26 +2048,21 @@ pub unsafe extern "C" fn gfxCreateGraphicsPipelines(
_ => &empty_dyn_states, _ => &empty_dyn_states,
}; };
let &mut (ref buffers, ref attributes) = {
let input_state = &*info.pVertexInputState; let input_state = &*info.pVertexInputState;
let bindings_slice = make_slice(
let bindings = slice::from_raw_parts(
input_state.pVertexBindingDescriptions, input_state.pVertexBindingDescriptions,
input_state.vertexBindingDescriptionCount as _, input_state.vertexBindingDescriptionCount as _,
); );
let attributes_slice = make_slice(
let attributes = slice::from_raw_parts(
input_state.pVertexAttributeDescriptions, input_state.pVertexAttributeDescriptions,
input_state.vertexAttributeDescriptionCount as _, input_state.vertexAttributeDescriptionCount as _,
); );
vertex_buffers.clear();
vertex_attributes.clear();
let bindings = bindings vertex_buffers.extend(bindings_slice.iter().map(|binding| {
.iter()
.map(|binding| {
let rate = match binding.inputRate { let rate = match binding.inputRate {
VkVertexInputRate::VK_VERTEX_INPUT_RATE_VERTEX => { VkVertexInputRate::VK_VERTEX_INPUT_RATE_VERTEX => pso::VertexInputRate::Vertex,
pso::VertexInputRate::Vertex
}
VkVertexInputRate::VK_VERTEX_INPUT_RATE_INSTANCE => { VkVertexInputRate::VK_VERTEX_INPUT_RATE_INSTANCE => {
pso::VertexInputRate::Instance(1) pso::VertexInputRate::Instance(1)
} }
@ -2078,12 +2074,8 @@ pub unsafe extern "C" fn gfxCreateGraphicsPipelines(
stride: binding.stride, stride: binding.stride,
rate, rate,
} }
}) }));
.collect::<Vec<_>>(); vertex_attributes.extend(attributes_slice.into_iter().map(|attrib| {
let attributes = attributes
.into_iter()
.map(|attrib| {
pso::AttributeDesc { pso::AttributeDesc {
location: attrib.location, location: attrib.location,
binding: attrib.binding, binding: attrib.binding,
@ -2092,11 +2084,7 @@ pub unsafe extern "C" fn gfxCreateGraphicsPipelines(
offset: attrib.offset, offset: attrib.offset,
}, },
} }
}) }));
.collect::<Vec<_>>();
vertex_arena.alloc((bindings, attributes))
};
let mut fragment = None; let mut fragment = None;
let primitive_assembler = { let primitive_assembler = {
@ -2180,8 +2168,8 @@ pub unsafe extern "C" fn gfxCreateGraphicsPipelines(
}; };
pso::PrimitiveAssemblerDesc::Vertex { pso::PrimitiveAssemblerDesc::Vertex {
buffers, buffers: &vertex_buffers,
attributes, attributes: &vertex_attributes,
input_assembler, input_assembler,
vertex: vertex.assume_init(), vertex: vertex.assume_init(),
tessellation: hull.and_then(|h| domain.map(|d| (h, d))), tessellation: hull.and_then(|h| domain.map(|d| (h, d))),
@ -2460,7 +2448,7 @@ pub unsafe extern "C" fn gfxCreateGraphicsPipelines(
} }
}; };
pso::GraphicsPipelineDesc { let desc = pso::GraphicsPipelineDesc {
label: None, label: None,
primitive_assembler, primitive_assembler,
rasterizer, rasterizer,
@ -2473,28 +2461,22 @@ pub unsafe extern "C" fn gfxCreateGraphicsPipelines(
subpass, subpass,
flags, flags,
parent, parent,
} };
}); *out_pipeline = match gpu
let pipelines = gpu
.device .device
.create_graphics_pipelines(descs, pipelineCache.as_ref()); .create_graphics_pipeline(&desc, pipelineCache.as_ref())
let out_pipelines = slice::from_raw_parts_mut(pPipelines, infos.len()); {
Ok(raw) => Handle::new(Pipeline::Graphics(raw)),
if pipelines.iter().any(|p| p.is_err()) { Err(e) => {
for pipeline in pipelines {
if let Err(e) = pipeline {
error!("{:?}", e); error!("{:?}", e);
Handle::null()
} }
} }
for op in out_pipelines {
*op = Handle::null();
} }
if out_pipelines.contains(&Handle::null()) {
VkResult::VK_ERROR_INCOMPATIBLE_DRIVER VkResult::VK_ERROR_INCOMPATIBLE_DRIVER
} else { } else {
for (op, raw) in out_pipelines.iter_mut().zip(pipelines) {
*op = Handle::new(Pipeline::Graphics(raw.unwrap()));
}
VkResult::VK_SUCCESS VkResult::VK_SUCCESS
} }
} }
@ -2534,8 +2516,10 @@ pub unsafe extern "C" fn gfxCreateComputePipelines(
} }
} }
let out_pipelines = make_slice_mut(pPipelines, infos.len());
let mut cur_specialization = 0; let mut cur_specialization = 0;
let descs = infos.iter().map(|info| {
for (out_pipeline, info) in out_pipelines.iter_mut().zip(infos) {
let name = CStr::from_ptr(info.stage.pName); let name = CStr::from_ptr(info.stage.pName);
let spec_count = info let spec_count = info
.stage .stage
@ -2594,34 +2578,29 @@ pub unsafe extern "C" fn gfxCreateComputePipelines(
} }
}; };
pso::ComputePipelineDesc { let desc = pso::ComputePipelineDesc {
label: None, label: None,
shader, shader,
layout, layout,
flags, flags,
parent, parent,
} };
});
let pipelines = gpu *out_pipeline = match gpu
.device .device
.create_compute_pipelines(descs, pipelineCache.as_ref()); .create_compute_pipeline(&desc, pipelineCache.as_ref())
let out_pipelines = slice::from_raw_parts_mut(pPipelines, infos.len()); {
Ok(raw) => Handle::new(Pipeline::Compute(raw)),
if pipelines.iter().any(|p| p.is_err()) { Err(e) => {
for pipeline in pipelines {
if let Err(e) = pipeline {
error!("{:?}", e); error!("{:?}", e);
Handle::null()
} }
} }
for op in out_pipelines {
*op = Handle::null();
} }
if out_pipelines.contains(&Handle::null()) {
VkResult::VK_ERROR_INCOMPATIBLE_DRIVER VkResult::VK_ERROR_INCOMPATIBLE_DRIVER
} else { } else {
for (op, raw) in out_pipelines.iter_mut().zip(pipelines) {
*op = Handle::new(Pipeline::Compute(raw.unwrap()));
}
VkResult::VK_SUCCESS VkResult::VK_SUCCESS
} }
} }
@ -2736,13 +2715,12 @@ pub unsafe extern "C" fn gfxCreateDescriptorSetLayout(
let sampler_iter = layout_bindings let sampler_iter = layout_bindings
.iter() .iter()
.flat_map(|binding| { .flat_map(|binding| {
if binding.pImmutableSamplers.is_null() { let slice = if binding.pImmutableSamplers.is_null() {
(&[]).into_iter().cloned() &[]
} else { } else {
let slice = slice::from_raw_parts(binding.pImmutableSamplers, binding.descriptorCount as _)
slice::from_raw_parts(binding.pImmutableSamplers, binding.descriptorCount as _); };
slice.iter().cloned() slice.iter().map(|handle| &**handle)
}
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -3504,7 +3482,9 @@ pub unsafe extern "C" fn gfxCmdBindDescriptorSets(
let descriptor_sets = slice::from_raw_parts(pDescriptorSets, descriptorSetCount as _) let descriptor_sets = slice::from_raw_parts(pDescriptorSets, descriptorSetCount as _)
.into_iter() .into_iter()
.map(|set| &**set); .map(|set| &**set);
let offsets = make_slice(pDynamicOffsets, dynamicOffsetCount as usize); let offsets = make_slice(pDynamicOffsets, dynamicOffsetCount as usize)
.iter()
.cloned();
match pipelineBindPoint { match pipelineBindPoint {
VkPipelineBindPoint::VK_PIPELINE_BIND_POINT_GRAPHICS => commandBuffer VkPipelineBindPoint::VK_PIPELINE_BIND_POINT_GRAPHICS => commandBuffer
@ -3542,7 +3522,7 @@ pub unsafe extern "C" fn gfxCmdBindVertexBuffers(
let views = buffers let views = buffers
.into_iter() .into_iter()
.zip(offsets) .zip(offsets)
.map(|(buffer, &offset)| (*buffer, hal::buffer::SubRange { offset, size: None })); .map(|(buffer, &offset)| (&**buffer, hal::buffer::SubRange { offset, size: None }));
commandBuffer.bind_vertex_buffers(firstBinding, views); commandBuffer.bind_vertex_buffers(firstBinding, views);
} }
@ -4215,10 +4195,11 @@ pub unsafe extern "C" fn gfxCmdExecuteCommands(
commandBufferCount: u32, commandBufferCount: u32,
pCommandBuffers: *const VkCommandBuffer, pCommandBuffers: *const VkCommandBuffer,
) { ) {
commandBuffer.execute_commands(slice::from_raw_parts( commandBuffer.execute_commands(
pCommandBuffers, make_slice(pCommandBuffers, commandBufferCount as _)
commandBufferCount as _, .iter()
)); .map(|handle| &**handle),
);
} }
#[inline] #[inline]
@ -4809,8 +4790,8 @@ pub unsafe extern "C" fn gfxAcquireNextImageKHR(
if let Some(fence) = fence.as_mut() { if let Some(fence) = fence.as_mut() {
fence.is_fake = true; fence.is_fake = true;
} }
if let Some(sem) = semaphore.as_mut() { if let Some(sem) = semaphore.as_ref() {
sem.is_fake = true; sem.is_fake.set(true);
} }
match swapchain.surface.raw.acquire_image(timeout) { match swapchain.surface.raw.acquire_image(timeout) {
@ -4858,7 +4839,7 @@ pub unsafe extern "C" fn gfxQueuePresentKHR(
.take() .take()
.expect("Frame was not acquired properly!"); .expect("Frame was not acquired properly!");
let sem = wait_semaphores.first_mut().map(|s| &mut s.raw); let sem = wait_semaphores.first_mut().map(|s| &mut s.raw);
if let Err(_) = queue.present(&mut sc.surface.raw, frame, sem) { if let Err(_) = queue.raw.present(&mut sc.surface.raw, frame, sem) {
return VkResult::VK_ERROR_SURFACE_LOST_KHR; return VkResult::VK_ERROR_SURFACE_LOST_KHR;
} }
} }

View file

@ -43,7 +43,7 @@ use crate::{
handle::{DispatchHandle, Handle}, handle::{DispatchHandle, Handle},
}; };
use std::{collections::HashMap, slice}; use std::{cell::Cell, collections::HashMap, slice};
pub use crate::impls::*; pub use crate::impls::*;
@ -51,7 +51,7 @@ pub use crate::impls::*;
pub type VkInstance = Handle<RawInstance>; pub type VkInstance = Handle<RawInstance>;
pub type VkPhysicalDevice = Handle<hal::adapter::Adapter<B>>; pub type VkPhysicalDevice = Handle<hal::adapter::Adapter<B>>;
pub type VkDevice = DispatchHandle<Gpu<B>>; pub type VkDevice = DispatchHandle<Gpu<B>>;
pub type VkQueue = DispatchHandle<<B as hal::Backend>::CommandQueue>; pub type VkQueue = DispatchHandle<Queue<B>>;
pub type VkCommandPool = Handle<CommandPool<B>>; pub type VkCommandPool = Handle<CommandPool<B>>;
pub type VkCommandBuffer = DispatchHandle<<B as hal::Backend>::CommandBuffer>; pub type VkCommandBuffer = DispatchHandle<<B as hal::Backend>::CommandBuffer>;
pub type VkDeviceMemory = Handle<<B as hal::Backend>::Memory>; pub type VkDeviceMemory = Handle<<B as hal::Backend>::Memory>;
@ -92,6 +92,11 @@ pub struct Gpu<B: hal::Backend> {
capturing: *mut (), capturing: *mut (),
} }
pub struct Queue<B: hal::Backend> {
raw: B::CommandQueue,
temp_semaphores: Vec<(VkPipelineStageFlags, VkSemaphore)>,
}
pub struct DescriptorPool<B: hal::Backend> { pub struct DescriptorPool<B: hal::Backend> {
raw: B::DescriptorPool, raw: B::DescriptorPool,
temp_sets: Vec<B::DescriptorSet>, temp_sets: Vec<B::DescriptorSet>,
@ -171,7 +176,7 @@ pub struct Framebuffer {
pub struct Semaphore<B: hal::Backend> { pub struct Semaphore<B: hal::Backend> {
raw: B::Semaphore, raw: B::Semaphore,
is_fake: bool, is_fake: Cell<bool>,
} }
pub struct Fence<B: hal::Backend> { pub struct Fence<B: hal::Backend> {