Skip to content

Commit 5779641

Browse files
bors[bot]kvark
andcommitted
Merge #178
178: gfx update, copyless handles, signposts r=msiglreith a=kvark Co-authored-by: Dzmitry Malyshau <[email protected]>
2 parents c5125e1 + 5d8488b commit 5779641

File tree

7 files changed

+181
-115
lines changed

7 files changed

+181
-115
lines changed

Cargo.lock

Lines changed: 106 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ FULL_LIBRARY_PATH=$(CURDIR)/target/debug
6060
LIBRARY=target/debug/libportability.$(LIB_EXTENSION)
6161
LIBRARY_FAST=target/release/libportability.$(LIB_EXTENSION)
6262

63-
.PHONY: all rebuild debug release version-debug version-release binding run-native cts clean cherry dota-debug dota-release dota-orig dota-bench-gfx dota-bench-orig dota-bench-gl package
63+
.PHONY: all rebuild debug release version-debug version-release binding run-native cts clean cherry dota-debug dota-release dota-orig dota-bench-gfx dota-bench-orig dota-bench-gl package memcpy-report
6464

6565
all: $(NATIVE_TARGET)
6666

@@ -172,3 +172,7 @@ target/debug/libvulkan.$(LIB_EXTENSION):
172172

173173
cherry: $(LIBRARY) target/debug/libvulkan.$(LIB_EXTENSION)
174174
cd $(CHERRY_DIR) && rm -f Cherry.db && RUST_LOG=warn LD_LIBRARY_PATH=$(FULL_LIBRARY_PATH) go run server.go
175+
176+
memcpy-report:
177+
RUSTFLAGS='-g --emit=llvm-ir' cd libportability && cargo build --release --features $(BACKEND)
178+
../memcpy-find/memcpy-find target/release/deps/portability.ll | rustfilt >etc/portability-memcpy.txt

libportability-gfx/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ nightly = []
1818
metal-capture = ["gfx-backend-metal/auto-capture"]
1919

2020
[dependencies]
21+
copyless = "0.1.1"
2122
lazy_static = "1.0"
2223
log = { version = "0.4", features = ["release_max_level_error"] }
2324

libportability-gfx/src/conv.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,25 @@ use super::*;
88

99
pub fn limits_from_hal(limits: Limits) -> VkPhysicalDeviceLimits {
1010
VkPhysicalDeviceLimits {
11-
maxImageDimension1D: limits.max_texture_size as _,
12-
maxImageDimension2D: limits.max_texture_size as _,
13-
maxImageDimension3D: limits.max_texture_size as _,
14-
maxImageDimensionCube: limits.max_texture_size as _,
15-
maxFramebufferWidth: limits.max_texture_size as _, //TODO
16-
maxFramebufferHeight: limits.max_texture_size as _, //TODO
11+
maxImageDimension1D: limits.max_image_1d_size,
12+
maxImageDimension2D: limits.max_image_2d_size,
13+
maxImageDimension3D: limits.max_image_3d_size,
14+
maxImageDimensionCube: limits.max_image_cube_size,
15+
maxFramebufferWidth: limits.max_framebuffer_extent.width,
16+
maxFramebufferHeight: limits.max_framebuffer_extent.height,
1717
maxTexelBufferElements: limits.max_texel_elements as _,
1818
maxTessellationPatchSize: limits.max_patch_size as _,
19-
maxPushConstantsSize: 0x80, //TODO
19+
maxPushConstantsSize: limits.max_push_constants_size as _,
2020
maxViewports: limits.max_viewports as _,
21-
maxViewportDimensions: [limits.max_texture_size as u32; 2],
21+
maxViewportDimensions: limits.max_viewport_dimensions,
2222
maxVertexInputAttributes: limits.max_vertex_input_attributes as _,
2323
maxVertexInputBindings: limits.max_vertex_input_bindings as _,
2424
maxVertexInputAttributeOffset: limits.max_vertex_input_attribute_offset as _,
2525
maxVertexInputBindingStride: limits.max_vertex_input_binding_stride as _,
2626
maxVertexOutputComponents: limits.max_vertex_output_components as _,
27-
maxComputeWorkGroupCount: limits.max_compute_group_count,
28-
maxComputeWorkGroupSize: limits.max_compute_group_size,
29-
bufferImageGranularity: 1, //TODO
30-
optimalBufferCopyOffsetAlignment: limits.min_buffer_copy_offset_alignment,
31-
optimalBufferCopyRowPitchAlignment: limits.min_buffer_copy_pitch_alignment,
27+
maxComputeWorkGroupCount: limits.max_compute_work_group_count,
28+
maxComputeWorkGroupSize: limits.max_compute_work_group_size,
29+
bufferImageGranularity: limits.buffer_image_granularity,
3230
minTexelBufferOffsetAlignment: limits.min_texel_buffer_offset_alignment,
3331
minUniformBufferOffsetAlignment: limits.min_uniform_buffer_offset_alignment,
3432
minStorageBufferOffsetAlignment: limits.min_storage_buffer_offset_alignment,
@@ -38,6 +36,8 @@ pub fn limits_from_hal(limits: Limits) -> VkPhysicalDeviceLimits {
3836
maxColorAttachments: limits.max_color_attachments as _,
3937
nonCoherentAtomSize: limits.non_coherent_atom_size as _,
4038
maxSamplerAnisotropy: limits.max_sampler_anisotropy,
39+
optimalBufferCopyOffsetAlignment: limits.optimal_buffer_copy_offset_alignment,
40+
optimalBufferCopyRowPitchAlignment: limits.optimal_buffer_copy_pitch_alignment,
4141
.. unsafe { mem::zeroed() } //TODO
4242
}
4343
}

libportability-gfx/src/handle.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use std::sync::{Arc, Mutex};
66
#[cfg(feature = "nightly")]
77
use hal::backend::FastHashMap;
88

9+
use copyless::{BoxAllocation, BoxHelper};
10+
11+
912
#[cfg(feature = "nightly")]
1013
lazy_static! {
1114
static ref REGISTRY: Arc<Mutex<FastHashMap<usize, &'static str>>> = Arc::new(Mutex::new(FastHashMap::default()));
@@ -25,9 +28,12 @@ impl Handle<()> {
2528
}
2629
}
2730

28-
impl<T: 'static> Handle<T> {
29-
pub fn new(value: T) -> Self {
30-
let ptr = Box::into_raw(Box::new(value));
31+
pub struct HandleAllocation<T>(BoxAllocation<T>);
32+
33+
impl<T> HandleAllocation<T> {
34+
#[inline(always)]
35+
pub fn init(self, value: T) -> Handle<T> {
36+
let ptr = Box::into_raw(self.0.init(value));
3137
#[cfg(feature = "nightly")]
3238
{
3339
use std::intrinsics::type_name;
@@ -36,6 +42,17 @@ impl<T: 'static> Handle<T> {
3642
}
3743
Handle(ptr)
3844
}
45+
}
46+
47+
impl<T: 'static> Handle<T> {
48+
pub fn alloc() -> HandleAllocation<T> {
49+
HandleAllocation(Box::alloc())
50+
}
51+
52+
// Note: ideally this constructor isn't used
53+
pub fn new(value: T) -> Self {
54+
Self::alloc().init(value)
55+
}
3956

4057
pub fn null() -> Self {
4158
Handle(VK_NULL_HANDLE as *mut _)
@@ -125,17 +142,31 @@ pub type DispatchHandle<T> = Handle<T>;
125142
#[cfg(feature = "dispatch")]
126143
mod dispatch {
127144
use VK_NULL_HANDLE;
145+
use copyless::{BoxAllocation, BoxHelper};
128146
use std::{borrow, cmp, fmt, ops};
129147

130148
const ICD_LOADER_MAGIC: u64 = 0x01CDC0DE;
131149

132150
#[repr(C)]
133151
pub struct DispatchHandle<T>(*mut (u64, T));
134152

153+
pub struct DisplatchHandleAllocation<T>(BoxAllocation<(u64, T)>);
154+
155+
impl<T> DisplatchHandleAllocation<T> {
156+
#[inline(always)]
157+
pub fn init(self, value: T) -> DispatchHandle<T> {
158+
let ptr = Box::into_raw(self.0.init((ICD_LOADER_MAGIC, value)));
159+
DispatchHandle(ptr)
160+
}
161+
}
162+
135163
impl<T> DispatchHandle<T> {
164+
pub fn alloc() -> DisplatchHandleAllocation<T> {
165+
DisplatchHandleAllocation(Box::alloc())
166+
}
167+
136168
pub fn new(value: T) -> Self {
137-
let ptr = Box::into_raw(Box::new((ICD_LOADER_MAGIC, value)));
138-
DispatchHandle(ptr)
169+
Self::alloc().init(value)
139170
}
140171

141172
pub fn null() -> Self {

libportability-gfx/src/impls.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use hal::device::WaitFor;
99
use hal::pool::RawCommandPool;
1010
use hal::queue::RawCommandQueue;
1111

12+
#[cfg(feature = "gfx-backend-metal")]
13+
use std::env;
1214
use std::ffi::{CStr, CString};
1315
use std::os::raw::c_int;
1416
#[cfg(feature = "renderdoc")]
@@ -759,7 +761,6 @@ pub extern "C" fn gfxCreateDevice(
759761
#[cfg(feature = "gfx-backend-metal")]
760762
{
761763
use back::OnlineRecording;
762-
use std::env;
763764

764765
if let Ok(value) = env::var("GFX_METAL_RECORDING") {
765766
gpu.device.online_recording = match value.to_lowercase().as_str() {
@@ -1033,8 +1034,6 @@ pub extern "C" fn gfxGetDeviceQueue(
10331034

10341035
#[cfg(feature = "gfx-backend-metal")]
10351036
{
1036-
use std::env;
1037-
10381037
if let Ok(value) = env::var("GFX_METAL_STITCHING") {
10391038
let mut q = queue;
10401039
q.stitch_deferred = match value.to_lowercase().as_str() {
@@ -3166,11 +3165,11 @@ pub extern "C" fn gfxAllocateCommandBuffers(
31663165
level => panic!("Unexpected command buffer lvel: {:?}", level),
31673166
};
31683167

3169-
let count = info.commandBufferCount as usize;
3170-
let cmd_bufs = info.commandPool.pool.allocate_vec(count, level);
3171-
3172-
let output = unsafe { slice::from_raw_parts_mut(pCommandBuffers, count) };
3173-
for (out, cmd_buf) in output.iter_mut().zip(cmd_bufs) {
3168+
let output = unsafe {
3169+
slice::from_raw_parts_mut(pCommandBuffers, info.commandBufferCount as usize)
3170+
};
3171+
for out in output.iter_mut() {
3172+
let cmd_buf = info.commandPool.pool.allocate_one(level);
31743173
*out = DispatchHandle::new(cmd_buf);
31753174
}
31763175
info.commandPool.buffers.extend_from_slice(output);
@@ -4283,7 +4282,6 @@ pub extern "C" fn gfxCreateSwapchainKHR(
42834282
#[cfg(feature = "gfx-backend-metal")]
42844283
{
42854284
use back::AcquireMode;
4286-
use std::env;
42874285

42884286
if let Ok(value) = env::var("GFX_METAL_ACQUIRING") {
42894287
swapchain.acquire_mode = match value.to_lowercase().as_str() {
@@ -4644,9 +4642,13 @@ pub extern "C" fn gfxCreateMetalSurfaceEXT(
46444642
let info = unsafe { &*pCreateInfo };
46454643
#[cfg(feature = "gfx-backend-metal")]
46464644
unsafe {
4645+
let enable_signposts = env::var("GFX_METAL_SIGNPOSTS").is_ok();
4646+
if enable_signposts {
4647+
println!("GFX: enabled signposts");
4648+
}
46474649
assert_eq!(info.flags, 0);
46484650
*pSurface = Handle::new(
4649-
instance.backend.create_surface_from_layer(info.pLayer as *mut _),
4651+
instance.backend.create_surface_from_layer(info.pLayer as *mut _, enable_signposts),
46504652
);
46514653
VkResult::VK_SUCCESS
46524654
}
@@ -4668,9 +4670,15 @@ pub extern "C" fn gfxCreateMacOSSurfaceMVK(
46684670
let info = unsafe { &*pCreateInfo };
46694671
#[cfg(target_os="macos")]
46704672
unsafe {
4673+
use std::env;
4674+
4675+
let enable_signposts = env::var("GFX_METAL_SIGNPOSTS").is_ok();
4676+
if enable_signposts {
4677+
println!("GFX: enabled signposts");
4678+
}
46714679
assert_eq!(info.flags, 0);
46724680
*pSurface = Handle::new(
4673-
instance.backend.create_surface_from_nsview(info.pView),
4681+
instance.backend.create_surface_from_nsview(info.pView, enable_signposts),
46744682
);
46754683
VkResult::VK_SUCCESS
46764684
}

libportability-gfx/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern crate gfx_backend_metal as back;
1414
#[cfg(feature = "gfx-backend-vulkan")]
1515
extern crate gfx_backend_vulkan as back;
1616

17+
extern crate copyless;
1718
#[macro_use]
1819
extern crate lazy_static;
1920
#[macro_use]

0 commit comments

Comments
 (0)