mirror of
https://github.com/italicsjenga/portability.git
synced 2024-11-25 16:31:32 +11:00
Merge #240
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:
commit
9737afa9be
28
Cargo.lock
generated
28
Cargo.lock
generated
|
@ -290,7 +290,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gfx-auxil"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad"
|
||||
source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
|
||||
dependencies = [
|
||||
"fxhash",
|
||||
"gfx-hal",
|
||||
|
@ -300,7 +300,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gfx-backend-dx11"
|
||||
version = "0.6.0"
|
||||
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad"
|
||||
source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bitflags",
|
||||
|
@ -321,7 +321,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gfx-backend-dx12"
|
||||
version = "0.6.2"
|
||||
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad"
|
||||
source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bit-set",
|
||||
|
@ -341,7 +341,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gfx-backend-empty"
|
||||
version = "0.6.0"
|
||||
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad"
|
||||
source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
|
||||
dependencies = [
|
||||
"gfx-hal",
|
||||
"log",
|
||||
|
@ -351,7 +351,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gfx-backend-gl"
|
||||
version = "0.6.0"
|
||||
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad"
|
||||
source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bitflags",
|
||||
|
@ -364,7 +364,6 @@ dependencies = [
|
|||
"log",
|
||||
"parking_lot",
|
||||
"raw-window-handle",
|
||||
"smallvec",
|
||||
"spirv_cross",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
|
@ -373,7 +372,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gfx-backend-metal"
|
||||
version = "0.6.0"
|
||||
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad"
|
||||
source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bitflags",
|
||||
|
@ -396,7 +395,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gfx-backend-vulkan"
|
||||
version = "0.6.5"
|
||||
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad"
|
||||
source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"ash",
|
||||
|
@ -415,7 +414,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gfx-hal"
|
||||
version = "0.6.0"
|
||||
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad"
|
||||
source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"naga",
|
||||
|
@ -540,7 +539,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "khronos-egl"
|
||||
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 = [
|
||||
"libc",
|
||||
"libloading",
|
||||
|
@ -760,7 +759,6 @@ dependencies = [
|
|||
"log",
|
||||
"raw-window-handle",
|
||||
"renderdoc",
|
||||
"typed-arena",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -838,7 +836,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "range-alloc"
|
||||
version = "0.1.1"
|
||||
source = "git+https://github.com/gfx-rs/gfx#cda1b3dce32b872a33755510ded93bf36965a6ad"
|
||||
source = "git+https://github.com/gfx-rs/gfx#477f17957a54d024f0077584b68e308376cb05c6"
|
||||
|
||||
[[package]]
|
||||
name = "raw-window-handle"
|
||||
|
@ -1019,12 +1017,6 @@ version = "0.1.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a686838375fc11103b9c1529c6508320b7bd5e2401cd62831ca51b3e82e61849"
|
||||
|
||||
[[package]]
|
||||
name = "typed-arena"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
|
|
|
@ -8,3 +8,12 @@ members = [
|
|||
[profile.release]
|
||||
debug = true
|
||||
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" }
|
||||
|
|
|
@ -23,44 +23,35 @@ copyless = "0.1.1"
|
|||
env_logger = { version = "0.8", optional = true }
|
||||
log = { version = "0.4", features = ["release_max_level_error"] }
|
||||
renderdoc = { version = "0.3", optional = true }
|
||||
typed-arena = "2"
|
||||
raw-window-handle = "0.3"
|
||||
|
||||
[dependencies.hal]
|
||||
package = "gfx-hal"
|
||||
git = "https://github.com/gfx-rs/gfx"
|
||||
#path = "../../gfx/src/hal"
|
||||
|
||||
[dependencies.gfx-backend-empty]
|
||||
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]
|
||||
git = "https://github.com/gfx-rs/gfx"
|
||||
#path = "../../gfx/src/backend/vulkan"
|
||||
optional = true
|
||||
|
||||
[target.'cfg(windows)'.dependencies.gfx-backend-dx12]
|
||||
git = "https://github.com/gfx-rs/gfx"
|
||||
#path = "../../gfx/src/backend/dx12"
|
||||
optional = true
|
||||
|
||||
[target.'cfg(windows)'.dependencies.gfx-backend-dx11]
|
||||
git = "https://github.com/gfx-rs/gfx"
|
||||
#path = "../../gfx/src/backend/dx11"
|
||||
optional = true
|
||||
|
||||
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.gfx-backend-metal]
|
||||
git = "https://github.com/gfx-rs/gfx"
|
||||
#path = "../../gfx/src/backend/metal"
|
||||
optional = true
|
||||
|
||||
[target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "ios")))'.dependencies.gfx-backend-gl]
|
||||
git = "https://github.com/gfx-rs/gfx"
|
||||
#path = "../../gfx/src/backend/gl"
|
||||
optional = true
|
||||
|
||||
[dependencies.gfx-auxil]
|
||||
git = "https://github.com/gfx-rs/gfx"
|
||||
#path = "../../gfx/src/auxil/auxil"
|
||||
optional = true
|
||||
|
|
|
@ -11,12 +11,11 @@ use hal::{
|
|||
{command as com, memory, pass, pso, queue}, {Features, Instance},
|
||||
};
|
||||
|
||||
use typed_arena::Arena;
|
||||
|
||||
#[cfg(feature = "gfx-backend-metal")]
|
||||
use std::env;
|
||||
use std::{
|
||||
borrow::{Borrow, Cow},
|
||||
cell::Cell,
|
||||
ffi::{CStr, CString},
|
||||
mem,
|
||||
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)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(DispatchHandle::new)
|
||||
.map(|raw| {
|
||||
DispatchHandle::new(Queue {
|
||||
raw,
|
||||
temp_semaphores: Vec::new(),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
(info.queueFamilyIndex, queues)
|
||||
|
@ -1146,12 +1150,12 @@ pub unsafe extern "C" fn gfxGetDeviceQueue(
|
|||
{
|
||||
if let Ok(value) = env::var("GFX_METAL_STITCHING") {
|
||||
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,
|
||||
"no" => false,
|
||||
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 {
|
||||
use std::iter::empty;
|
||||
// sometimes, all you need is a fence...
|
||||
let submission = hal::queue::Submission {
|
||||
command_buffers: empty(),
|
||||
wait_semaphores: empty(),
|
||||
signal_semaphores: empty(),
|
||||
};
|
||||
type RawSemaphore = <B as hal::Backend>::Semaphore;
|
||||
queue.submit::<VkCommandBuffer, _, RawSemaphore, _, _>(
|
||||
submission,
|
||||
queue.raw.submit(
|
||||
empty(),
|
||||
empty(),
|
||||
empty(),
|
||||
fence.as_mut().map(|f| &mut f.raw),
|
||||
);
|
||||
} else {
|
||||
|
@ -1184,7 +1184,7 @@ pub unsafe extern "C" fn gfxQueueSubmit(
|
|||
submission.pCommandBuffers,
|
||||
submission.commandBufferCount as usize,
|
||||
);
|
||||
let wait_semaphores = {
|
||||
{
|
||||
let semaphores = make_slice(
|
||||
submission.pWaitSemaphores,
|
||||
submission.waitSemaphoreCount as usize,
|
||||
|
@ -1194,13 +1194,11 @@ pub unsafe extern "C" fn gfxQueueSubmit(
|
|||
submission.waitSemaphoreCount as usize,
|
||||
);
|
||||
|
||||
stages
|
||||
.into_iter()
|
||||
.zip(semaphores)
|
||||
.filter(|(_, semaphore)| !semaphore.is_fake)
|
||||
.map(|(stage, semaphore)| {
|
||||
(&semaphore.raw, conv::map_pipeline_stage_flags(*stage))
|
||||
})
|
||||
queue.temp_semaphores.clear();
|
||||
queue
|
||||
.temp_semaphores
|
||||
.extend(stages.iter().cloned().zip(semaphores.iter().cloned()));
|
||||
queue.temp_semaphores.retain(|&(_, sem)| !sem.is_fake.get());
|
||||
};
|
||||
let signal_semaphores = make_slice(
|
||||
submission.pSignalSemaphores,
|
||||
|
@ -1208,24 +1206,28 @@ pub unsafe extern "C" fn gfxQueueSubmit(
|
|||
)
|
||||
.into_iter()
|
||||
.map(|semaphore| {
|
||||
semaphore.as_mut().unwrap().is_fake = false;
|
||||
semaphore.is_fake.set(false);
|
||||
&semaphore.raw
|
||||
});
|
||||
|
||||
let submission = hal::queue::Submission {
|
||||
command_buffers: cmd_slice.iter(),
|
||||
wait_semaphores,
|
||||
signal_semaphores,
|
||||
};
|
||||
|
||||
// only provide the fence for the last submission
|
||||
//TODO: support multiple submissions at gfx-hal level
|
||||
let fence = if i + 1 == submits.len() {
|
||||
fence.as_mut().map(|f| &mut f.raw)
|
||||
} else {
|
||||
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]
|
||||
pub unsafe extern "C" fn gfxQueueWaitIdle(mut queue: VkQueue) -> VkResult {
|
||||
let _ = queue.wait_idle();
|
||||
let _ = queue.raw.wait_idle();
|
||||
VkResult::VK_SUCCESS
|
||||
}
|
||||
#[inline]
|
||||
|
@ -1516,16 +1518,13 @@ pub unsafe extern "C" fn gfxResetFences(
|
|||
fenceCount: u32,
|
||||
pFences: *const VkFence,
|
||||
) -> VkResult {
|
||||
let fence_slice = make_slice_mut(pFences as *mut VkFence, fenceCount as usize);
|
||||
let fences = fence_slice.iter_mut().map(|fence| {
|
||||
for fence in make_slice_mut(pFences as *mut VkFence, fenceCount as usize) {
|
||||
fence.as_mut().unwrap().is_fake = false;
|
||||
&mut fence.raw
|
||||
});
|
||||
|
||||
match gpu.device.reset_fences(fences) {
|
||||
Ok(()) => VkResult::VK_SUCCESS,
|
||||
Err(oom) => map_oom(oom),
|
||||
if let Err(oom) = gpu.device.reset_fence(&mut fence.raw) {
|
||||
return map_oom(oom);
|
||||
}
|
||||
}
|
||||
VkResult::VK_SUCCESS
|
||||
}
|
||||
#[inline]
|
||||
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() {
|
||||
Ok(raw) => Semaphore {
|
||||
raw,
|
||||
is_fake: false,
|
||||
is_fake: Cell::new(false),
|
||||
},
|
||||
Err(oom) => return map_oom(oom),
|
||||
};
|
||||
|
@ -1982,14 +1981,14 @@ pub unsafe extern "C" fn gfxGetPipelineCacheData(
|
|||
#[inline]
|
||||
pub unsafe extern "C" fn gfxMergePipelineCaches(
|
||||
gpu: VkDevice,
|
||||
dstCache: VkPipelineCache,
|
||||
mut dstCache: VkPipelineCache,
|
||||
srcCacheCount: u32,
|
||||
pSrcCaches: *const VkPipelineCache,
|
||||
) -> VkResult {
|
||||
let caches = slice::from_raw_parts(pSrcCaches, srcCacheCount as usize);
|
||||
match gpu
|
||||
.device
|
||||
.merge_pipeline_caches(&*dstCache, caches.iter().map(|h| &**h))
|
||||
.merge_pipeline_caches(&mut *dstCache, caches.iter().map(|h| &**h))
|
||||
{
|
||||
Ok(()) => VkResult::VK_SUCCESS,
|
||||
Err(oom) => map_oom(oom),
|
||||
|
@ -2005,7 +2004,7 @@ pub unsafe extern "C" fn gfxCreateGraphicsPipelines(
|
|||
_pAllocator: *const VkAllocationCallbacks,
|
||||
pPipelines: *mut VkPipeline,
|
||||
) -> 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_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 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 empty_dyn_states = [];
|
||||
|
@ -2047,56 +2048,43 @@ pub unsafe extern "C" fn gfxCreateGraphicsPipelines(
|
|||
_ => &empty_dyn_states,
|
||||
};
|
||||
|
||||
let &mut (ref buffers, ref attributes) = {
|
||||
let input_state = &*info.pVertexInputState;
|
||||
let input_state = &*info.pVertexInputState;
|
||||
let bindings_slice = make_slice(
|
||||
input_state.pVertexBindingDescriptions,
|
||||
input_state.vertexBindingDescriptionCount as _,
|
||||
);
|
||||
let attributes_slice = make_slice(
|
||||
input_state.pVertexAttributeDescriptions,
|
||||
input_state.vertexAttributeDescriptionCount as _,
|
||||
);
|
||||
vertex_buffers.clear();
|
||||
vertex_attributes.clear();
|
||||
|
||||
let bindings = slice::from_raw_parts(
|
||||
input_state.pVertexBindingDescriptions,
|
||||
input_state.vertexBindingDescriptionCount as _,
|
||||
);
|
||||
vertex_buffers.extend(bindings_slice.iter().map(|binding| {
|
||||
let rate = match binding.inputRate {
|
||||
VkVertexInputRate::VK_VERTEX_INPUT_RATE_VERTEX => pso::VertexInputRate::Vertex,
|
||||
VkVertexInputRate::VK_VERTEX_INPUT_RATE_INSTANCE => {
|
||||
pso::VertexInputRate::Instance(1)
|
||||
}
|
||||
rate => panic!("Unexpected input rate: {:?}", rate),
|
||||
};
|
||||
|
||||
let attributes = slice::from_raw_parts(
|
||||
input_state.pVertexAttributeDescriptions,
|
||||
input_state.vertexAttributeDescriptionCount as _,
|
||||
);
|
||||
|
||||
let bindings = bindings
|
||||
.iter()
|
||||
.map(|binding| {
|
||||
let rate = match binding.inputRate {
|
||||
VkVertexInputRate::VK_VERTEX_INPUT_RATE_VERTEX => {
|
||||
pso::VertexInputRate::Vertex
|
||||
}
|
||||
VkVertexInputRate::VK_VERTEX_INPUT_RATE_INSTANCE => {
|
||||
pso::VertexInputRate::Instance(1)
|
||||
}
|
||||
rate => panic!("Unexpected input rate: {:?}", rate),
|
||||
};
|
||||
|
||||
pso::VertexBufferDesc {
|
||||
binding: binding.binding,
|
||||
stride: binding.stride,
|
||||
rate,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let attributes = attributes
|
||||
.into_iter()
|
||||
.map(|attrib| {
|
||||
pso::AttributeDesc {
|
||||
location: attrib.location,
|
||||
binding: attrib.binding,
|
||||
element: pso::Element {
|
||||
format: conv::map_format(attrib.format).unwrap(), // TODO: undefined allowed?
|
||||
offset: attrib.offset,
|
||||
},
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
vertex_arena.alloc((bindings, attributes))
|
||||
};
|
||||
pso::VertexBufferDesc {
|
||||
binding: binding.binding,
|
||||
stride: binding.stride,
|
||||
rate,
|
||||
}
|
||||
}));
|
||||
vertex_attributes.extend(attributes_slice.into_iter().map(|attrib| {
|
||||
pso::AttributeDesc {
|
||||
location: attrib.location,
|
||||
binding: attrib.binding,
|
||||
element: pso::Element {
|
||||
format: conv::map_format(attrib.format).unwrap(), // TODO: undefined allowed?
|
||||
offset: attrib.offset,
|
||||
},
|
||||
}
|
||||
}));
|
||||
|
||||
let mut fragment = None;
|
||||
let primitive_assembler = {
|
||||
|
@ -2180,8 +2168,8 @@ pub unsafe extern "C" fn gfxCreateGraphicsPipelines(
|
|||
};
|
||||
|
||||
pso::PrimitiveAssemblerDesc::Vertex {
|
||||
buffers,
|
||||
attributes,
|
||||
buffers: &vertex_buffers,
|
||||
attributes: &vertex_attributes,
|
||||
input_assembler,
|
||||
vertex: vertex.assume_init(),
|
||||
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,
|
||||
primitive_assembler,
|
||||
rasterizer,
|
||||
|
@ -2473,28 +2461,22 @@ pub unsafe extern "C" fn gfxCreateGraphicsPipelines(
|
|||
subpass,
|
||||
flags,
|
||||
parent,
|
||||
}
|
||||
});
|
||||
|
||||
let pipelines = gpu
|
||||
.device
|
||||
.create_graphics_pipelines(descs, pipelineCache.as_ref());
|
||||
let out_pipelines = slice::from_raw_parts_mut(pPipelines, infos.len());
|
||||
|
||||
if pipelines.iter().any(|p| p.is_err()) {
|
||||
for pipeline in pipelines {
|
||||
if let Err(e) = pipeline {
|
||||
};
|
||||
*out_pipeline = match gpu
|
||||
.device
|
||||
.create_graphics_pipeline(&desc, pipelineCache.as_ref())
|
||||
{
|
||||
Ok(raw) => Handle::new(Pipeline::Graphics(raw)),
|
||||
Err(e) => {
|
||||
error!("{:?}", e);
|
||||
Handle::null()
|
||||
}
|
||||
}
|
||||
for op in out_pipelines {
|
||||
*op = Handle::null();
|
||||
}
|
||||
}
|
||||
|
||||
if out_pipelines.contains(&Handle::null()) {
|
||||
VkResult::VK_ERROR_INCOMPATIBLE_DRIVER
|
||||
} else {
|
||||
for (op, raw) in out_pipelines.iter_mut().zip(pipelines) {
|
||||
*op = Handle::new(Pipeline::Graphics(raw.unwrap()));
|
||||
}
|
||||
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 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 spec_count = info
|
||||
.stage
|
||||
|
@ -2594,34 +2578,29 @@ pub unsafe extern "C" fn gfxCreateComputePipelines(
|
|||
}
|
||||
};
|
||||
|
||||
pso::ComputePipelineDesc {
|
||||
let desc = pso::ComputePipelineDesc {
|
||||
label: None,
|
||||
shader,
|
||||
layout,
|
||||
flags,
|
||||
parent,
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let pipelines = gpu
|
||||
.device
|
||||
.create_compute_pipelines(descs, pipelineCache.as_ref());
|
||||
let out_pipelines = slice::from_raw_parts_mut(pPipelines, infos.len());
|
||||
|
||||
if pipelines.iter().any(|p| p.is_err()) {
|
||||
for pipeline in pipelines {
|
||||
if let Err(e) = pipeline {
|
||||
*out_pipeline = match gpu
|
||||
.device
|
||||
.create_compute_pipeline(&desc, pipelineCache.as_ref())
|
||||
{
|
||||
Ok(raw) => Handle::new(Pipeline::Compute(raw)),
|
||||
Err(e) => {
|
||||
error!("{:?}", e);
|
||||
Handle::null()
|
||||
}
|
||||
}
|
||||
for op in out_pipelines {
|
||||
*op = Handle::null();
|
||||
}
|
||||
}
|
||||
|
||||
if out_pipelines.contains(&Handle::null()) {
|
||||
VkResult::VK_ERROR_INCOMPATIBLE_DRIVER
|
||||
} else {
|
||||
for (op, raw) in out_pipelines.iter_mut().zip(pipelines) {
|
||||
*op = Handle::new(Pipeline::Compute(raw.unwrap()));
|
||||
}
|
||||
VkResult::VK_SUCCESS
|
||||
}
|
||||
}
|
||||
|
@ -2736,13 +2715,12 @@ pub unsafe extern "C" fn gfxCreateDescriptorSetLayout(
|
|||
let sampler_iter = layout_bindings
|
||||
.iter()
|
||||
.flat_map(|binding| {
|
||||
if binding.pImmutableSamplers.is_null() {
|
||||
(&[]).into_iter().cloned()
|
||||
let slice = if binding.pImmutableSamplers.is_null() {
|
||||
&[]
|
||||
} else {
|
||||
let slice =
|
||||
slice::from_raw_parts(binding.pImmutableSamplers, binding.descriptorCount as _);
|
||||
slice.iter().cloned()
|
||||
}
|
||||
slice::from_raw_parts(binding.pImmutableSamplers, binding.descriptorCount as _)
|
||||
};
|
||||
slice.iter().map(|handle| &**handle)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -3504,7 +3482,9 @@ pub unsafe extern "C" fn gfxCmdBindDescriptorSets(
|
|||
let descriptor_sets = slice::from_raw_parts(pDescriptorSets, descriptorSetCount as _)
|
||||
.into_iter()
|
||||
.map(|set| &**set);
|
||||
let offsets = make_slice(pDynamicOffsets, dynamicOffsetCount as usize);
|
||||
let offsets = make_slice(pDynamicOffsets, dynamicOffsetCount as usize)
|
||||
.iter()
|
||||
.cloned();
|
||||
|
||||
match pipelineBindPoint {
|
||||
VkPipelineBindPoint::VK_PIPELINE_BIND_POINT_GRAPHICS => commandBuffer
|
||||
|
@ -3542,7 +3522,7 @@ pub unsafe extern "C" fn gfxCmdBindVertexBuffers(
|
|||
let views = buffers
|
||||
.into_iter()
|
||||
.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);
|
||||
}
|
||||
|
@ -4215,10 +4195,11 @@ pub unsafe extern "C" fn gfxCmdExecuteCommands(
|
|||
commandBufferCount: u32,
|
||||
pCommandBuffers: *const VkCommandBuffer,
|
||||
) {
|
||||
commandBuffer.execute_commands(slice::from_raw_parts(
|
||||
pCommandBuffers,
|
||||
commandBufferCount as _,
|
||||
));
|
||||
commandBuffer.execute_commands(
|
||||
make_slice(pCommandBuffers, commandBufferCount as _)
|
||||
.iter()
|
||||
.map(|handle| &**handle),
|
||||
);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -4809,8 +4790,8 @@ pub unsafe extern "C" fn gfxAcquireNextImageKHR(
|
|||
if let Some(fence) = fence.as_mut() {
|
||||
fence.is_fake = true;
|
||||
}
|
||||
if let Some(sem) = semaphore.as_mut() {
|
||||
sem.is_fake = true;
|
||||
if let Some(sem) = semaphore.as_ref() {
|
||||
sem.is_fake.set(true);
|
||||
}
|
||||
|
||||
match swapchain.surface.raw.acquire_image(timeout) {
|
||||
|
@ -4858,7 +4839,7 @@ pub unsafe extern "C" fn gfxQueuePresentKHR(
|
|||
.take()
|
||||
.expect("Frame was not acquired properly!");
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ use crate::{
|
|||
handle::{DispatchHandle, Handle},
|
||||
};
|
||||
|
||||
use std::{collections::HashMap, slice};
|
||||
use std::{cell::Cell, collections::HashMap, slice};
|
||||
|
||||
pub use crate::impls::*;
|
||||
|
||||
|
@ -51,7 +51,7 @@ pub use crate::impls::*;
|
|||
pub type VkInstance = Handle<RawInstance>;
|
||||
pub type VkPhysicalDevice = Handle<hal::adapter::Adapter<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 VkCommandBuffer = DispatchHandle<<B as hal::Backend>::CommandBuffer>;
|
||||
pub type VkDeviceMemory = Handle<<B as hal::Backend>::Memory>;
|
||||
|
@ -92,6 +92,11 @@ pub struct Gpu<B: hal::Backend> {
|
|||
capturing: *mut (),
|
||||
}
|
||||
|
||||
pub struct Queue<B: hal::Backend> {
|
||||
raw: B::CommandQueue,
|
||||
temp_semaphores: Vec<(VkPipelineStageFlags, VkSemaphore)>,
|
||||
}
|
||||
|
||||
pub struct DescriptorPool<B: hal::Backend> {
|
||||
raw: B::DescriptorPool,
|
||||
temp_sets: Vec<B::DescriptorSet>,
|
||||
|
@ -171,7 +176,7 @@ pub struct Framebuffer {
|
|||
|
||||
pub struct Semaphore<B: hal::Backend> {
|
||||
raw: B::Semaphore,
|
||||
is_fake: bool,
|
||||
is_fake: Cell<bool>,
|
||||
}
|
||||
|
||||
pub struct Fence<B: hal::Backend> {
|
||||
|
|
Loading…
Reference in a new issue