mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
[vk] use destructuring for cache keys
If fields are unused, they shouldn't be part of the cache key.
This commit is contained in:
parent
d14849df48
commit
cc406f919e
@ -59,12 +59,18 @@ impl super::CommandEncoder {
|
||||
Ok(match self.framebuffers.entry(key) {
|
||||
Entry::Occupied(e) => *e.get(),
|
||||
Entry::Vacant(e) => {
|
||||
let super::FramebufferKey {
|
||||
raw_pass,
|
||||
ref attachments,
|
||||
extent,
|
||||
} = *e.key();
|
||||
|
||||
let vk_info = vk::FramebufferCreateInfo::default()
|
||||
.render_pass(e.key().raw_pass)
|
||||
.width(e.key().extent.width)
|
||||
.height(e.key().extent.height)
|
||||
.layers(e.key().extent.depth_or_array_layers)
|
||||
.attachments(&e.key().attachments);
|
||||
.render_pass(raw_pass)
|
||||
.width(extent.width)
|
||||
.height(extent.height)
|
||||
.layers(extent.depth_or_array_layers)
|
||||
.attachments(attachments);
|
||||
|
||||
let raw = unsafe { self.device.raw.create_framebuffer(&vk_info, None).unwrap() };
|
||||
*e.insert(raw)
|
||||
@ -79,15 +85,22 @@ impl super::CommandEncoder {
|
||||
Ok(match self.temp_texture_views.entry(key) {
|
||||
Entry::Occupied(e) => *e.get(),
|
||||
Entry::Vacant(e) => {
|
||||
let super::TempTextureViewKey {
|
||||
texture,
|
||||
format,
|
||||
mip_level,
|
||||
depth_slice,
|
||||
} = *e.key();
|
||||
|
||||
let vk_info = vk::ImageViewCreateInfo::default()
|
||||
.image(e.key().texture)
|
||||
.image(texture)
|
||||
.view_type(vk::ImageViewType::TYPE_2D)
|
||||
.format(e.key().format)
|
||||
.format(format)
|
||||
.subresource_range(vk::ImageSubresourceRange {
|
||||
aspect_mask: vk::ImageAspectFlags::COLOR,
|
||||
base_mip_level: e.key().mip_level,
|
||||
base_mip_level: mip_level,
|
||||
level_count: 1,
|
||||
base_array_layer: e.key().depth_slice,
|
||||
base_array_layer: depth_slice,
|
||||
layer_count: 1,
|
||||
});
|
||||
let raw = unsafe { self.device.raw.create_image_view(&vk_info, None) }
|
||||
|
||||
@ -75,45 +75,65 @@ impl super::DeviceShared {
|
||||
Ok(match self.render_passes.lock().entry(key) {
|
||||
Entry::Occupied(e) => *e.get(),
|
||||
Entry::Vacant(e) => {
|
||||
let super::RenderPassKey {
|
||||
ref colors,
|
||||
ref depth_stencil,
|
||||
sample_count,
|
||||
multiview,
|
||||
} = *e.key();
|
||||
|
||||
let mut vk_attachments = Vec::new();
|
||||
let mut color_refs = Vec::with_capacity(e.key().colors.len());
|
||||
let mut color_refs = Vec::with_capacity(colors.len());
|
||||
let mut resolve_refs = Vec::with_capacity(color_refs.capacity());
|
||||
let mut ds_ref = None;
|
||||
let samples = vk::SampleCountFlags::from_raw(e.key().sample_count);
|
||||
let samples = vk::SampleCountFlags::from_raw(sample_count);
|
||||
let unused = vk::AttachmentReference {
|
||||
attachment: vk::ATTACHMENT_UNUSED,
|
||||
layout: vk::ImageLayout::UNDEFINED,
|
||||
};
|
||||
for cat in e.key().colors.iter() {
|
||||
let (color_ref, resolve_ref) = if let Some(cat) = cat.as_ref() {
|
||||
for cat in colors.iter() {
|
||||
let (color_ref, resolve_ref) =
|
||||
if let Some(super::ColorAttachmentKey { base, resolve }) = cat {
|
||||
let super::AttachmentKey {
|
||||
format,
|
||||
layout,
|
||||
ops,
|
||||
} = *base;
|
||||
|
||||
let color_ref = vk::AttachmentReference {
|
||||
attachment: vk_attachments.len() as u32,
|
||||
layout: cat.base.layout,
|
||||
layout,
|
||||
};
|
||||
vk_attachments.push({
|
||||
let (load_op, store_op) = conv::map_attachment_ops(cat.base.ops);
|
||||
let (load_op, store_op) = conv::map_attachment_ops(ops);
|
||||
vk::AttachmentDescription::default()
|
||||
.format(cat.base.format)
|
||||
.format(format)
|
||||
.samples(samples)
|
||||
.load_op(load_op)
|
||||
.store_op(store_op)
|
||||
.initial_layout(cat.base.layout)
|
||||
.final_layout(cat.base.layout)
|
||||
.initial_layout(layout)
|
||||
.final_layout(layout)
|
||||
});
|
||||
let resolve_ref = if let Some(ref rat) = cat.resolve {
|
||||
let (load_op, store_op) = conv::map_attachment_ops(rat.ops);
|
||||
let resolve_ref = if let Some(rat) = resolve {
|
||||
let super::AttachmentKey {
|
||||
format,
|
||||
layout,
|
||||
ops,
|
||||
} = *rat;
|
||||
|
||||
let (load_op, store_op) = conv::map_attachment_ops(ops);
|
||||
let vk_attachment = vk::AttachmentDescription::default()
|
||||
.format(rat.format)
|
||||
.format(format)
|
||||
.samples(vk::SampleCountFlags::TYPE_1)
|
||||
.load_op(load_op)
|
||||
.store_op(store_op)
|
||||
.initial_layout(rat.layout)
|
||||
.final_layout(rat.layout);
|
||||
.initial_layout(layout)
|
||||
.final_layout(layout);
|
||||
vk_attachments.push(vk_attachment);
|
||||
|
||||
vk::AttachmentReference {
|
||||
attachment: vk_attachments.len() as u32 - 1,
|
||||
layout: rat.layout,
|
||||
layout,
|
||||
}
|
||||
} else {
|
||||
unused
|
||||
@ -128,23 +148,33 @@ impl super::DeviceShared {
|
||||
resolve_refs.push(resolve_ref);
|
||||
}
|
||||
|
||||
if let Some(ref ds) = e.key().depth_stencil {
|
||||
if let Some(ds) = depth_stencil {
|
||||
let super::DepthStencilAttachmentKey {
|
||||
ref base,
|
||||
stencil_ops,
|
||||
} = *ds;
|
||||
|
||||
let super::AttachmentKey {
|
||||
format,
|
||||
layout,
|
||||
ops,
|
||||
} = *base;
|
||||
|
||||
ds_ref = Some(vk::AttachmentReference {
|
||||
attachment: vk_attachments.len() as u32,
|
||||
layout: ds.base.layout,
|
||||
layout,
|
||||
});
|
||||
let (load_op, store_op) = conv::map_attachment_ops(ds.base.ops);
|
||||
let (stencil_load_op, stencil_store_op) =
|
||||
conv::map_attachment_ops(ds.stencil_ops);
|
||||
let (load_op, store_op) = conv::map_attachment_ops(ops);
|
||||
let (stencil_load_op, stencil_store_op) = conv::map_attachment_ops(stencil_ops);
|
||||
let vk_attachment = vk::AttachmentDescription::default()
|
||||
.format(ds.base.format)
|
||||
.format(format)
|
||||
.samples(samples)
|
||||
.load_op(load_op)
|
||||
.store_op(store_op)
|
||||
.stencil_load_op(stencil_load_op)
|
||||
.stencil_store_op(stencil_store_op)
|
||||
.initial_layout(ds.base.layout)
|
||||
.final_layout(ds.base.layout);
|
||||
.initial_layout(layout)
|
||||
.final_layout(layout);
|
||||
vk_attachments.push(vk_attachment);
|
||||
}
|
||||
|
||||
@ -174,7 +204,7 @@ impl super::DeviceShared {
|
||||
|
||||
let mut multiview_info;
|
||||
let mask;
|
||||
if let Some(multiview) = e.key().multiview {
|
||||
if let Some(multiview) = multiview {
|
||||
// Sanity checks, better to panic here than cause a driver crash
|
||||
assert!(multiview.get() <= 8);
|
||||
assert!(multiview.get() > 1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user