Skip to content

Commit

Permalink
Merge #210
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bors[bot] and kvark authored Aug 5, 2020
2 parents 0a7426f + 0c7e6fa commit 3c9cb79
Show file tree
Hide file tree
Showing 8 changed files with 867 additions and 532 deletions.
505 changes: 209 additions & 296 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ FULL_LIBRARY_PATH=$(CURDIR)/target/debug
LIBRARY=target/debug/libportability.$(LIB_EXTENSION)
LIBRARY_FAST=target/release/libportability.$(LIB_EXTENSION)

.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
.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

all: $(NATIVE_TARGET)

dummy:

rebuild:
cargo build --manifest-path libportability/Cargo.toml --features $(BACKEND)

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

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

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

Expand Down
12 changes: 3 additions & 9 deletions libportability-gfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,10 @@ metal-capture = ["gfx-backend-metal/auto-capture"]

[dependencies]
copyless = "0.1.1"
env_logger = { version = "0.5", optional = true }
lazy_static = "1"
log = { version = "0.4", features = ["release_max_level_error"] }

[dependencies.env_logger]
version = "0.5"
optional = true

[dependencies.renderdoc]
version = "0.3"
optional = true
renderdoc = { version = "0.3", optional = true }

[dependencies.hal]
package = "gfx-hal"
Expand Down Expand Up @@ -68,5 +62,5 @@ optional = true

[dependencies.gfx-auxil]
git = "https://github.com/gfx-rs/gfx"
# path = "../../gfx/src/auxil/auxil"
#path = "../../gfx/src/auxil/auxil"
optional = true
105 changes: 84 additions & 21 deletions libportability-gfx/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,110 @@ pub fn limits_from_hal(limits: Limits) -> VkPhysicalDeviceLimits {
maxImageDimension2D: limits.max_image_2d_size,
maxImageDimension3D: limits.max_image_3d_size,
maxImageDimensionCube: limits.max_image_cube_size,
maxFramebufferWidth: limits.max_framebuffer_extent.width,
maxFramebufferHeight: limits.max_framebuffer_extent.height,
maxImageArrayLayers: limits.max_image_array_layers as _,
maxTexelBufferElements: limits.max_texel_elements as _,
maxTessellationPatchSize: limits.max_patch_size as _,
maxUniformBufferRange: limits.max_uniform_buffer_range as _,
maxStorageBufferRange: limits.max_storage_buffer_range as _,
maxPushConstantsSize: limits.max_push_constants_size as _,
maxViewports: limits.max_viewports as _,
maxViewportDimensions: limits.max_viewport_dimensions,
maxMemoryAllocationCount: limits.max_memory_allocation_count as _,
maxSamplerAllocationCount: limits.max_sampler_allocation_count as _,
bufferImageGranularity: limits.buffer_image_granularity,
sparseAddressSpaceSize: 0,
maxBoundDescriptorSets: limits.max_bound_descriptor_sets as _,
maxPerStageDescriptorSamplers: limits.max_per_stage_descriptor_samplers as _,
maxPerStageDescriptorUniformBuffers: limits.max_per_stage_descriptor_uniform_buffers as _,
maxPerStageDescriptorStorageBuffers: limits.max_per_stage_descriptor_storage_buffers as _,
maxPerStageDescriptorSampledImages: limits.max_per_stage_descriptor_sampled_images as _,
maxPerStageDescriptorStorageImages: limits.max_per_stage_descriptor_storage_images as _,
maxPerStageDescriptorInputAttachments: limits.max_per_stage_descriptor_input_attachments as _,
maxPerStageResources: limits.max_per_stage_resources as _,
maxDescriptorSetSamplers: limits.max_descriptor_set_samplers as _,
maxDescriptorSetUniformBuffers: limits.max_descriptor_set_uniform_buffers as _,
maxFragmentInputComponents: limits.max_fragment_input_components as _,
maxFramebufferLayers: limits.max_framebuffer_layers as _,
maxMemoryAllocationCount: limits.max_memory_allocation_count as _,
maxUniformBufferRange: limits.max_uniform_buffer_range as _,
// Warning: spec violation
// "The x/y rectangle of the viewport must lie entirely within the current attachment size."
viewportBoundsRange: [0.0, viewport_size as f32],
maxDescriptorSetUniformBuffersDynamic: limits.max_descriptor_set_uniform_buffers_dynamic.max(1) as _,
maxDescriptorSetStorageBuffers: limits.max_descriptor_set_storage_buffers as _,
maxDescriptorSetStorageBuffersDynamic: limits.max_descriptor_set_storage_buffers_dynamic.max(1) as _,
maxDescriptorSetSampledImages: limits.max_descriptor_set_sampled_images as _,
maxDescriptorSetStorageImages: limits.max_descriptor_set_storage_images as _,
maxDescriptorSetInputAttachments: limits.max_descriptor_set_input_attachments as _,
maxVertexInputAttributes: limits.max_vertex_input_attributes as _,
maxVertexInputBindings: limits.max_vertex_input_bindings as _,
maxVertexInputAttributeOffset: limits.max_vertex_input_attribute_offset as _,
maxVertexInputBindingStride: limits.max_vertex_input_binding_stride as _,
maxVertexOutputComponents: limits.max_vertex_output_components as _,
maxTessellationGenerationLevel: 0,
maxTessellationPatchSize: limits.max_patch_size as _,
maxTessellationControlPerVertexInputComponents: 0,
maxTessellationControlPerVertexOutputComponents: 0,
maxTessellationControlPerPatchOutputComponents: 0,
maxTessellationControlTotalOutputComponents: 0,
maxTessellationEvaluationInputComponents: 0,
maxTessellationEvaluationOutputComponents: 0,
maxGeometryShaderInvocations: limits.max_geometry_shader_invocations as _,
maxGeometryInputComponents: limits.max_geometry_input_components as _,
maxGeometryOutputComponents: limits.max_geometry_output_components as _,
maxGeometryOutputVertices: limits.max_geometry_output_vertices as _,
maxGeometryTotalOutputComponents: limits.max_geometry_total_output_components as _,
maxFragmentInputComponents: limits.max_fragment_input_components as _,
maxFragmentOutputAttachments: limits.max_fragment_output_attachments as _,
maxFragmentDualSrcAttachments: limits.max_fragment_dual_source_attachments as _,
maxFragmentCombinedOutputResources: limits.max_fragment_combined_output_resources as _,
maxComputeSharedMemorySize: limits.max_compute_shared_memory_size as _,
maxComputeWorkGroupCount: limits.max_compute_work_group_count,
maxComputeWorkGroupInvocations: limits.max_compute_work_group_invocations as _,
maxComputeWorkGroupSize: limits.max_compute_work_group_size,
bufferImageGranularity: limits.buffer_image_granularity,
subPixelPrecisionBits: 0,
subTexelPrecisionBits: 0,
mipmapPrecisionBits: 0,
maxDrawIndexedIndexValue: limits.max_draw_indexed_index_value,
maxDrawIndirectCount: limits.max_draw_indirect_count,
maxSamplerLodBias: limits.max_sampler_lod_bias,
maxSamplerAnisotropy: limits.max_sampler_anisotropy,
maxViewports: limits.max_viewports as _,
maxViewportDimensions: limits.max_viewport_dimensions,
// Warning: spec violation
// "The x/y rectangle of the viewport must lie entirely within the current attachment size."
viewportBoundsRange: [0.0, viewport_size as f32],
viewportSubPixelBits: 0,
minMemoryMapAlignment: limits.min_memory_map_alignment.max(1),
minTexelBufferOffsetAlignment: limits.min_texel_buffer_offset_alignment,
minUniformBufferOffsetAlignment: limits.min_uniform_buffer_offset_alignment,
minStorageBufferOffsetAlignment: limits.min_storage_buffer_offset_alignment,
minTexelOffset: 0,
maxTexelOffset: 0,
minTexelGatherOffset: 0,
maxTexelGatherOffset: 0,
minInterpolationOffset: 0.0,
maxInterpolationOffset: 0.0,
subPixelInterpolationOffsetBits: 0,
maxFramebufferWidth: limits.max_framebuffer_extent.width,
maxFramebufferHeight: limits.max_framebuffer_extent.height,
maxFramebufferLayers: limits.max_framebuffer_layers as _,
framebufferColorSampleCounts: limits.framebuffer_color_sample_counts as _,
framebufferDepthSampleCounts: limits.framebuffer_depth_sample_counts as _,
framebufferStencilSampleCounts: limits.framebuffer_stencil_sample_counts as _,
framebufferNoAttachmentsSampleCounts: 0, //TODO
maxColorAttachments: limits.max_color_attachments as _,
nonCoherentAtomSize: limits.non_coherent_atom_size as _,
maxSamplerAnisotropy: limits.max_sampler_anisotropy,
sampledImageColorSampleCounts: 0,
sampledImageIntegerSampleCounts: 0,
sampledImageDepthSampleCounts: 0,
sampledImageStencilSampleCounts: 0,
storageImageSampleCounts: 0,
maxSampleMaskWords: 0,
timestampComputeAndGraphics: 0,
timestampPeriod: 0.0,
maxClipDistances: 0,
maxCullDistances: 0,
maxCombinedClipAndCullDistances: 0,
discreteQueuePriorities: 0,
pointSizeRange: [0.0; 2],
lineWidthRange: [0.0; 2],
pointSizeGranularity: 0.0,
lineWidthGranularity: 0.0,
strictLines: 0,
standardSampleLocations: if limits.standard_sample_locations { VK_TRUE } else { VK_FALSE },
optimalBufferCopyOffsetAlignment: limits.optimal_buffer_copy_offset_alignment,
optimalBufferCopyRowPitchAlignment: limits.optimal_buffer_copy_pitch_alignment,
maxPerStageDescriptorSampledImages: limits.max_per_stage_descriptor_sampled_images as _,
maxPerStageDescriptorSamplers: limits.max_per_stage_descriptor_samplers as _,
maxDescriptorSetSampledImages: limits.max_descriptor_set_sampled_images as _,
maxDescriptorSetSamplers: limits.max_descriptor_set_samplers as _,
..unsafe { mem::zeroed() } //TODO
nonCoherentAtomSize: limits.non_coherent_atom_size as _,
}
}

Expand Down Expand Up @@ -355,7 +418,7 @@ pub fn map_image_usage(usage: VkImageUsageFlags) -> image::Usage {
image::Usage::from_bits_truncate(usage)
}

pub fn map_image_usage_from_hal(usage: image::Usage) -> VkImageUsageFlags {
pub fn _map_image_usage_from_hal(usage: image::Usage) -> VkImageUsageFlags {
usage.bits()
}

Expand Down
Loading

0 comments on commit 3c9cb79

Please sign in to comment.