Skip to content

Commit 33d5089

Browse files
committed
Unify the texture view creation
1 parent 49d2c33 commit 33d5089

File tree

1 file changed

+34
-54
lines changed

1 file changed

+34
-54
lines changed

src/device.rs

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,9 @@ pub extern "C" fn wgpu_device_create_texture(
550550

551551
pub fn texture_create_view(
552552
texture_id: TextureId,
553-
desc: &resource::TextureViewDescriptor,
553+
format: resource::TextureFormat,
554+
view_kind: hal::image::ViewKind,
555+
range: hal::image::SubresourceRange,
554556
) -> resource::TextureView<back::Backend> {
555557
let texture_guard = HUB.textures.read();
556558
let texture = &texture_guard[texture_id];
@@ -561,14 +563,10 @@ pub fn texture_create_view(
561563
[texture.device_id.value].raw
562564
.create_image_view(
563565
&texture.raw,
564-
conv::map_texture_view_dimension(desc.dimension),
565-
conv::map_texture_format(desc.format),
566+
view_kind,
567+
conv::map_texture_format(format),
566568
hal::format::Swizzle::NO,
567-
hal::image::SubresourceRange {
568-
aspects: conv::map_texture_aspect_flags(desc.aspect),
569-
levels: desc.base_mip_level as u8 .. (desc.base_mip_level + desc.level_count) as u8,
570-
layers: desc.base_array_layer as u16 .. (desc.base_array_layer + desc.array_count) as u16,
571-
},
569+
range,
572570
)
573571
.unwrap()
574572
};
@@ -610,61 +608,43 @@ pub extern "C" fn wgpu_texture_create_view(
610608
texture_id: TextureId,
611609
desc: &resource::TextureViewDescriptor,
612610
) -> TextureViewId {
613-
let view = texture_create_view(texture_id, desc);
614-
let texture_id = view.texture_id.value;
611+
let view = texture_create_view(
612+
texture_id,
613+
desc.format,
614+
conv::map_texture_view_dimension(desc.dimension),
615+
hal::image::SubresourceRange {
616+
aspects: conv::map_texture_aspect_flags(desc.aspect),
617+
levels: desc.base_mip_level as u8 .. (desc.base_mip_level + desc.level_count) as u8,
618+
layers: desc.base_array_layer as u16 .. (desc.base_array_layer + desc.array_count) as u16,
619+
},
620+
);
615621
let ref_count = view.life_guard.ref_count.clone();
616622
let id = HUB.texture_views.register_local(view);
617623
device_track_view(texture_id, id, ref_count);
618624
id
619625
}
620626

621-
pub fn texture_create_default_view(
622-
texture_id: TextureId
623-
) -> resource::TextureView<back::Backend> {
624-
let texture_guard = HUB.textures.read();
625-
let texture = &texture_guard[texture_id];
626-
627-
let view_kind = match texture.kind {
628-
hal::image::Kind::D1(_, 1) => hal::image::ViewKind::D1,
629-
hal::image::Kind::D1(..) => hal::image::ViewKind::D1Array,
630-
hal::image::Kind::D2(_, _, 1, _) => hal::image::ViewKind::D2,
631-
hal::image::Kind::D2(..) => hal::image::ViewKind::D2Array,
632-
hal::image::Kind::D3(..) => hal::image::ViewKind::D3,
633-
};
634-
635-
let raw = unsafe{
636-
HUB.devices
637-
.read()
638-
[texture.device_id.value].raw
639-
.create_image_view(
640-
&texture.raw,
641-
view_kind,
642-
conv::map_texture_format(texture.format),
643-
hal::format::Swizzle::NO,
644-
texture.full_range.clone(),
645-
)
646-
.unwrap()
647-
};
648-
649-
resource::TextureView {
650-
raw,
651-
texture_id: Stored {
652-
value: texture_id,
653-
ref_count: texture.life_guard.ref_count.clone(),
654-
},
655-
format: texture.format,
656-
extent: texture.kind.extent(),
657-
samples: texture.kind.num_samples(),
658-
is_owned_by_swap_chain: false,
659-
life_guard: LifeGuard::new(),
660-
}
661-
}
662-
663627
#[cfg(feature = "local")]
664628
#[no_mangle]
665629
pub extern "C" fn wgpu_texture_create_default_view(texture_id: TextureId) -> TextureViewId {
666-
let view = texture_create_default_view(texture_id);
667-
let texture_id = view.texture_id.value;
630+
let (format, view_kind, range) = {
631+
let texture_guard = HUB.textures.read();
632+
let texture = &texture_guard[texture_id];
633+
let view_kind = match texture.kind {
634+
hal::image::Kind::D1(_, 1) => hal::image::ViewKind::D1,
635+
hal::image::Kind::D1(..) => hal::image::ViewKind::D1Array,
636+
hal::image::Kind::D2(_, _, 1, _) => hal::image::ViewKind::D2,
637+
hal::image::Kind::D2(..) => hal::image::ViewKind::D2Array,
638+
hal::image::Kind::D3(..) => hal::image::ViewKind::D3,
639+
};
640+
(texture.format, view_kind, texture.full_range.clone())
641+
};
642+
let view = texture_create_view(
643+
texture_id,
644+
format,
645+
view_kind,
646+
range,
647+
);
668648
let ref_count = view.life_guard.ref_count.clone();
669649
let id = HUB.texture_views.register_local(view);
670650
device_track_view(texture_id, id, ref_count);

0 commit comments

Comments
 (0)