Skip to content

Commit c86aa0c

Browse files
bors[bot]kvark
andauthored
Merge #210
210: Port to the new swapchain model r=kvark a=kvark Closes #208 Fixes #212 Also has general fixes to: - push constant offsets in `gfxCreatePipelineLayout` - destination subresources in `gfxCmdResolveImage` The PR is inviting for discussion: @grovesNL @msiglreith I'm not 100% sure what to do yet. The Good: 1. Being able to remove the old swapchain from gfx-rs COMPLETELY. It was hacky on all the backends other than Vulkan, quite complicated on Metal, and didn't work very in general. 2. Fullscreen support! It's not ideal yet (occasional hitches), but it was pretty much non-functional before. In general, stuff that runs is more robust this change. The Bad: 1. Portability implementation is a bit more complex now, but not extraordinary so. In general, I think it's a win if we move some complication out of gfx-rs into gfx-portability, since gfx-rs has more users, it's more important to keep clean. 2. We can't support recording a render pass that uses a swapchain image if either: - the image is not acquired at the moment of recording - the command buffer is re-usable. We expect the users to strictly acquire-record-submit-present. The Ugly: 1. Our KHR swapchain implementation is more limited: no support for any usage other than COLOR_ATTACHMENT. This is technically valid in Vulkan, but for some reason many apps expect to transfer to/from swapchain images. So this is fine for the matter of CTS and VkPI, but can introduce some friction in real world testing. 2. The new swapchain model itself needs to be evolved a bit more, according to gfx-rs/gfx#3184 . We don't know how exactly: there is both a risk (that we'll need to redo something here) and an opportunity (that we'll support other usages, for example). Co-authored-by: Dzmitry Malyshau <[email protected]>
2 parents 0a7426f + 0c7e6fa commit c86aa0c

File tree

8 files changed

+867
-532
lines changed

8 files changed

+867
-532
lines changed

Cargo.lock

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

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ 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 memcpy-report
63+
.PHONY: all dummy 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

67+
dummy:
68+
6769
rebuild:
6870
cargo build --manifest-path libportability/Cargo.toml --features $(BACKEND)
6971

@@ -117,12 +119,12 @@ binding: $(BINDING)
117119
$(BINDING): $(VULKAN_DIR)/vulkan/*.h
118120
bindgen --no-layout-tests --rustfmt-bindings $(VULKAN_DIR)/vulkan/vulkan.h -o $(BINDING)
119121

120-
$(LIBRARY): libportability*/src/*.rs libportability*/Cargo.toml Cargo.lock
122+
$(LIBRARY): dummy
121123
cargo build --manifest-path libportability/Cargo.toml --features $(BACKEND)
122-
cargo build --manifest-path libportability-icd/Cargo.toml --features $(BACKEND)
124+
cargo build --manifest-path libportability-icd/Cargo.toml --features $(BACKEND),portability-gfx/env_logger
123125
mkdir -p target/native
124126

125-
$(LIBRARY_FAST): libportability*/src/*.rs libportability*/Cargo.toml Cargo.lock
127+
$(LIBRARY_FAST): dummy
126128
cargo build --release --manifest-path libportability/Cargo.toml --features $(BACKEND)
127129
cargo build --release --manifest-path libportability-icd/Cargo.toml --features $(BACKEND)
128130

libportability-gfx/Cargo.toml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,10 @@ metal-capture = ["gfx-backend-metal/auto-capture"]
2020

2121
[dependencies]
2222
copyless = "0.1.1"
23+
env_logger = { version = "0.5", optional = true }
2324
lazy_static = "1"
2425
log = { version = "0.4", features = ["release_max_level_error"] }
25-
26-
[dependencies.env_logger]
27-
version = "0.5"
28-
optional = true
29-
30-
[dependencies.renderdoc]
31-
version = "0.3"
32-
optional = true
26+
renderdoc = { version = "0.3", optional = true }
3327

3428
[dependencies.hal]
3529
package = "gfx-hal"
@@ -68,5 +62,5 @@ optional = true
6862

6963
[dependencies.gfx-auxil]
7064
git = "https://github.com/gfx-rs/gfx"
71-
# path = "../../gfx/src/auxil/auxil"
65+
#path = "../../gfx/src/auxil/auxil"
7266
optional = true

libportability-gfx/src/conv.rs

Lines changed: 84 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,110 @@ pub fn limits_from_hal(limits: Limits) -> VkPhysicalDeviceLimits {
1414
maxImageDimension2D: limits.max_image_2d_size,
1515
maxImageDimension3D: limits.max_image_3d_size,
1616
maxImageDimensionCube: limits.max_image_cube_size,
17-
maxFramebufferWidth: limits.max_framebuffer_extent.width,
18-
maxFramebufferHeight: limits.max_framebuffer_extent.height,
17+
maxImageArrayLayers: limits.max_image_array_layers as _,
1918
maxTexelBufferElements: limits.max_texel_elements as _,
20-
maxTessellationPatchSize: limits.max_patch_size as _,
19+
maxUniformBufferRange: limits.max_uniform_buffer_range as _,
20+
maxStorageBufferRange: limits.max_storage_buffer_range as _,
2121
maxPushConstantsSize: limits.max_push_constants_size as _,
22-
maxViewports: limits.max_viewports as _,
23-
maxViewportDimensions: limits.max_viewport_dimensions,
22+
maxMemoryAllocationCount: limits.max_memory_allocation_count as _,
23+
maxSamplerAllocationCount: limits.max_sampler_allocation_count as _,
24+
bufferImageGranularity: limits.buffer_image_granularity,
25+
sparseAddressSpaceSize: 0,
2426
maxBoundDescriptorSets: limits.max_bound_descriptor_sets as _,
27+
maxPerStageDescriptorSamplers: limits.max_per_stage_descriptor_samplers as _,
2528
maxPerStageDescriptorUniformBuffers: limits.max_per_stage_descriptor_uniform_buffers as _,
29+
maxPerStageDescriptorStorageBuffers: limits.max_per_stage_descriptor_storage_buffers as _,
30+
maxPerStageDescriptorSampledImages: limits.max_per_stage_descriptor_sampled_images as _,
31+
maxPerStageDescriptorStorageImages: limits.max_per_stage_descriptor_storage_images as _,
32+
maxPerStageDescriptorInputAttachments: limits.max_per_stage_descriptor_input_attachments as _,
33+
maxPerStageResources: limits.max_per_stage_resources as _,
34+
maxDescriptorSetSamplers: limits.max_descriptor_set_samplers as _,
2635
maxDescriptorSetUniformBuffers: limits.max_descriptor_set_uniform_buffers as _,
27-
maxFragmentInputComponents: limits.max_fragment_input_components as _,
28-
maxFramebufferLayers: limits.max_framebuffer_layers as _,
29-
maxMemoryAllocationCount: limits.max_memory_allocation_count as _,
30-
maxUniformBufferRange: limits.max_uniform_buffer_range as _,
31-
// Warning: spec violation
32-
// "The x/y rectangle of the viewport must lie entirely within the current attachment size."
33-
viewportBoundsRange: [0.0, viewport_size as f32],
36+
maxDescriptorSetUniformBuffersDynamic: limits.max_descriptor_set_uniform_buffers_dynamic.max(1) as _,
37+
maxDescriptorSetStorageBuffers: limits.max_descriptor_set_storage_buffers as _,
38+
maxDescriptorSetStorageBuffersDynamic: limits.max_descriptor_set_storage_buffers_dynamic.max(1) as _,
39+
maxDescriptorSetSampledImages: limits.max_descriptor_set_sampled_images as _,
40+
maxDescriptorSetStorageImages: limits.max_descriptor_set_storage_images as _,
41+
maxDescriptorSetInputAttachments: limits.max_descriptor_set_input_attachments as _,
3442
maxVertexInputAttributes: limits.max_vertex_input_attributes as _,
3543
maxVertexInputBindings: limits.max_vertex_input_bindings as _,
3644
maxVertexInputAttributeOffset: limits.max_vertex_input_attribute_offset as _,
3745
maxVertexInputBindingStride: limits.max_vertex_input_binding_stride as _,
3846
maxVertexOutputComponents: limits.max_vertex_output_components as _,
47+
maxTessellationGenerationLevel: 0,
48+
maxTessellationPatchSize: limits.max_patch_size as _,
49+
maxTessellationControlPerVertexInputComponents: 0,
50+
maxTessellationControlPerVertexOutputComponents: 0,
51+
maxTessellationControlPerPatchOutputComponents: 0,
52+
maxTessellationControlTotalOutputComponents: 0,
53+
maxTessellationEvaluationInputComponents: 0,
54+
maxTessellationEvaluationOutputComponents: 0,
55+
maxGeometryShaderInvocations: limits.max_geometry_shader_invocations as _,
56+
maxGeometryInputComponents: limits.max_geometry_input_components as _,
57+
maxGeometryOutputComponents: limits.max_geometry_output_components as _,
58+
maxGeometryOutputVertices: limits.max_geometry_output_vertices as _,
59+
maxGeometryTotalOutputComponents: limits.max_geometry_total_output_components as _,
60+
maxFragmentInputComponents: limits.max_fragment_input_components as _,
61+
maxFragmentOutputAttachments: limits.max_fragment_output_attachments as _,
62+
maxFragmentDualSrcAttachments: limits.max_fragment_dual_source_attachments as _,
63+
maxFragmentCombinedOutputResources: limits.max_fragment_combined_output_resources as _,
64+
maxComputeSharedMemorySize: limits.max_compute_shared_memory_size as _,
3965
maxComputeWorkGroupCount: limits.max_compute_work_group_count,
66+
maxComputeWorkGroupInvocations: limits.max_compute_work_group_invocations as _,
4067
maxComputeWorkGroupSize: limits.max_compute_work_group_size,
41-
bufferImageGranularity: limits.buffer_image_granularity,
68+
subPixelPrecisionBits: 0,
69+
subTexelPrecisionBits: 0,
70+
mipmapPrecisionBits: 0,
71+
maxDrawIndexedIndexValue: limits.max_draw_indexed_index_value,
72+
maxDrawIndirectCount: limits.max_draw_indirect_count,
73+
maxSamplerLodBias: limits.max_sampler_lod_bias,
74+
maxSamplerAnisotropy: limits.max_sampler_anisotropy,
75+
maxViewports: limits.max_viewports as _,
76+
maxViewportDimensions: limits.max_viewport_dimensions,
77+
// Warning: spec violation
78+
// "The x/y rectangle of the viewport must lie entirely within the current attachment size."
79+
viewportBoundsRange: [0.0, viewport_size as f32],
80+
viewportSubPixelBits: 0,
81+
minMemoryMapAlignment: limits.min_memory_map_alignment.max(1),
4282
minTexelBufferOffsetAlignment: limits.min_texel_buffer_offset_alignment,
4383
minUniformBufferOffsetAlignment: limits.min_uniform_buffer_offset_alignment,
4484
minStorageBufferOffsetAlignment: limits.min_storage_buffer_offset_alignment,
85+
minTexelOffset: 0,
86+
maxTexelOffset: 0,
87+
minTexelGatherOffset: 0,
88+
maxTexelGatherOffset: 0,
89+
minInterpolationOffset: 0.0,
90+
maxInterpolationOffset: 0.0,
91+
subPixelInterpolationOffsetBits: 0,
92+
maxFramebufferWidth: limits.max_framebuffer_extent.width,
93+
maxFramebufferHeight: limits.max_framebuffer_extent.height,
94+
maxFramebufferLayers: limits.max_framebuffer_layers as _,
4595
framebufferColorSampleCounts: limits.framebuffer_color_sample_counts as _,
4696
framebufferDepthSampleCounts: limits.framebuffer_depth_sample_counts as _,
4797
framebufferStencilSampleCounts: limits.framebuffer_stencil_sample_counts as _,
98+
framebufferNoAttachmentsSampleCounts: 0, //TODO
4899
maxColorAttachments: limits.max_color_attachments as _,
49-
nonCoherentAtomSize: limits.non_coherent_atom_size as _,
50-
maxSamplerAnisotropy: limits.max_sampler_anisotropy,
100+
sampledImageColorSampleCounts: 0,
101+
sampledImageIntegerSampleCounts: 0,
102+
sampledImageDepthSampleCounts: 0,
103+
sampledImageStencilSampleCounts: 0,
104+
storageImageSampleCounts: 0,
105+
maxSampleMaskWords: 0,
106+
timestampComputeAndGraphics: 0,
107+
timestampPeriod: 0.0,
108+
maxClipDistances: 0,
109+
maxCullDistances: 0,
110+
maxCombinedClipAndCullDistances: 0,
111+
discreteQueuePriorities: 0,
112+
pointSizeRange: [0.0; 2],
113+
lineWidthRange: [0.0; 2],
114+
pointSizeGranularity: 0.0,
115+
lineWidthGranularity: 0.0,
116+
strictLines: 0,
117+
standardSampleLocations: if limits.standard_sample_locations { VK_TRUE } else { VK_FALSE },
51118
optimalBufferCopyOffsetAlignment: limits.optimal_buffer_copy_offset_alignment,
52119
optimalBufferCopyRowPitchAlignment: limits.optimal_buffer_copy_pitch_alignment,
53-
maxPerStageDescriptorSampledImages: limits.max_per_stage_descriptor_sampled_images as _,
54-
maxPerStageDescriptorSamplers: limits.max_per_stage_descriptor_samplers as _,
55-
maxDescriptorSetSampledImages: limits.max_descriptor_set_sampled_images as _,
56-
maxDescriptorSetSamplers: limits.max_descriptor_set_samplers as _,
57-
..unsafe { mem::zeroed() } //TODO
120+
nonCoherentAtomSize: limits.non_coherent_atom_size as _,
58121
}
59122
}
60123

@@ -355,7 +418,7 @@ pub fn map_image_usage(usage: VkImageUsageFlags) -> image::Usage {
355418
image::Usage::from_bits_truncate(usage)
356419
}
357420

358-
pub fn map_image_usage_from_hal(usage: image::Usage) -> VkImageUsageFlags {
421+
pub fn _map_image_usage_from_hal(usage: image::Usage) -> VkImageUsageFlags {
359422
usage.bits()
360423
}
361424

0 commit comments

Comments
 (0)