mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
native: Texture view creation
This commit is contained in:
parent
ef4ee9c29d
commit
1137ad2f70
@ -113,7 +113,7 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
|||||||
} else {
|
} else {
|
||||||
extent = Some(view.extent);
|
extent = Some(view.extent);
|
||||||
}
|
}
|
||||||
let query = tracker.query(view.source_id.0);
|
let query = tracker.query(view.texture_id.0);
|
||||||
let (_, layout) = conv::map_texture_state(
|
let (_, layout) = conv::map_texture_state(
|
||||||
query.usage,
|
query.usage,
|
||||||
hal::format::Aspects::DEPTH | hal::format::Aspects::STENCIL,
|
hal::format::Aspects::DEPTH | hal::format::Aspects::STENCIL,
|
||||||
@ -137,7 +137,7 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
|||||||
} else {
|
} else {
|
||||||
extent = Some(view.extent);
|
extent = Some(view.extent);
|
||||||
}
|
}
|
||||||
let query = tracker.query(view.source_id.0);
|
let query = tracker.query(view.texture_id.0);
|
||||||
let (_, layout) = conv::map_texture_state(query.usage, hal::format::Aspects::COLOR);
|
let (_, layout) = conv::map_texture_state(query.usage, hal::format::Aspects::COLOR);
|
||||||
hal::pass::Attachment {
|
hal::pass::Attachment {
|
||||||
format: Some(conv::map_texture_format(view.format)),
|
format: Some(conv::map_texture_format(view.format)),
|
||||||
|
|||||||
@ -59,15 +59,12 @@ pub extern "C" fn wgpu_render_pass_end_pass(
|
|||||||
.consume(pass.texture_tracker)
|
.consume(pass.texture_tracker)
|
||||||
.map(|(id, transit)| {
|
.map(|(id, transit)| {
|
||||||
let t = texture_guard.get(id);
|
let t = texture_guard.get(id);
|
||||||
|
let aspects = t.full_range.aspects;
|
||||||
hal::memory::Barrier::Image {
|
hal::memory::Barrier::Image {
|
||||||
states: conv::map_texture_state(transit.start, t.aspects) ..
|
states: conv::map_texture_state(transit.start, aspects) ..
|
||||||
conv::map_texture_state(transit.end, t.aspects),
|
conv::map_texture_state(transit.end, aspects),
|
||||||
target: &t.raw,
|
target: &t.raw,
|
||||||
range: hal::image::SubresourceRange { //TODO!
|
range: t.full_range.clone(), //TODO?
|
||||||
aspects: t.aspects,
|
|
||||||
levels: 0 .. 1,
|
|
||||||
layers: 0 .. 1,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -277,11 +277,11 @@ fn checked_u32_as_u16(value: u32) -> u16 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_texture_dimension_size(
|
pub fn map_texture_dimension_size(
|
||||||
dimension: resource::TextureDimension, size: Extent3d
|
dimension: resource::TextureDimension,
|
||||||
|
Extent3d { width, height, depth }: Extent3d,
|
||||||
) -> hal::image::Kind {
|
) -> hal::image::Kind {
|
||||||
use hal::image::Kind as H;
|
use hal::image::Kind as H;
|
||||||
use resource::TextureDimension::*;
|
use resource::TextureDimension::*;
|
||||||
let Extent3d { width, height, depth } = size;
|
|
||||||
match dimension {
|
match dimension {
|
||||||
D1 => {
|
D1 => {
|
||||||
assert_eq!(height, 1);
|
assert_eq!(height, 1);
|
||||||
@ -292,6 +292,40 @@ pub fn map_texture_dimension_size(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn map_texture_view_dimension(
|
||||||
|
dimension: resource::TextureViewDimension,
|
||||||
|
) -> hal::image::ViewKind {
|
||||||
|
use hal::image::ViewKind as H;
|
||||||
|
use resource::TextureViewDimension::*;
|
||||||
|
match dimension {
|
||||||
|
D1 => H::D1,
|
||||||
|
D2 => H::D2,
|
||||||
|
D2Array => H::D2Array,
|
||||||
|
Cube => H::Cube,
|
||||||
|
CubeArray => H::CubeArray,
|
||||||
|
D3 => H::D3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn map_texture_aspect_flags(
|
||||||
|
aspect: resource::TextureAspectFlags
|
||||||
|
) -> hal::format::Aspects {
|
||||||
|
use resource::TextureAspectFlags as Taf;
|
||||||
|
use hal::format::Aspects;
|
||||||
|
|
||||||
|
let mut flags = Aspects::empty();
|
||||||
|
if aspect.contains(Taf::COLOR) {
|
||||||
|
flags |= Aspects::COLOR;
|
||||||
|
}
|
||||||
|
if aspect.contains(Taf::DEPTH) {
|
||||||
|
flags |= Aspects::DEPTH;
|
||||||
|
}
|
||||||
|
if aspect.contains(Taf::STENCIL) {
|
||||||
|
flags |= Aspects::STENCIL;
|
||||||
|
}
|
||||||
|
flags
|
||||||
|
}
|
||||||
|
|
||||||
pub fn map_buffer_state(
|
pub fn map_buffer_state(
|
||||||
usage: resource::BufferUsageFlags,
|
usage: resource::BufferUsageFlags,
|
||||||
) -> hal::buffer::State {
|
) -> hal::buffer::State {
|
||||||
|
|||||||
@ -2,8 +2,10 @@ use {back, binding_model, command, conv, pipeline, resource};
|
|||||||
use registry::{HUB, Items, Registry};
|
use registry::{HUB, Items, Registry};
|
||||||
use track::{BufferTracker, TextureTracker};
|
use track::{BufferTracker, TextureTracker};
|
||||||
use {
|
use {
|
||||||
|
Stored,
|
||||||
AttachmentStateId, BindGroupLayoutId, BlendStateId, CommandBufferId, DepthStencilStateId,
|
AttachmentStateId, BindGroupLayoutId, BlendStateId, CommandBufferId, DepthStencilStateId,
|
||||||
DeviceId, PipelineLayoutId, QueueId, RenderPipelineId, ShaderModuleId, TextureId,
|
DeviceId, PipelineLayoutId, QueueId, RenderPipelineId, ShaderModuleId,
|
||||||
|
TextureId, TextureViewId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use hal::command::RawCommandBuffer;
|
use hal::command::RawCommandBuffer;
|
||||||
@ -68,6 +70,7 @@ pub(crate) struct ShaderModule<B: hal::Backend> {
|
|||||||
pub raw: B::ShaderModule,
|
pub raw: B::ShaderModule,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_device_create_texture(
|
pub extern "C" fn wgpu_device_create_texture(
|
||||||
device_id: DeviceId,
|
device_id: DeviceId,
|
||||||
@ -109,11 +112,20 @@ pub extern "C" fn wgpu_device_create_texture(
|
|||||||
.bind_image_memory(&image_memory, 0, image_unbound)
|
.bind_image_memory(&image_memory, 0, image_unbound)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let full_range = hal::image::SubresourceRange {
|
||||||
|
aspects,
|
||||||
|
levels: 0 .. 1, //TODO: mips
|
||||||
|
layers: 0 .. 1, //TODO
|
||||||
|
};
|
||||||
|
|
||||||
let id = HUB.textures
|
let id = HUB.textures
|
||||||
.lock()
|
.lock()
|
||||||
.register(resource::Texture {
|
.register(resource::Texture {
|
||||||
raw: bound_image,
|
raw: bound_image,
|
||||||
aspects,
|
device_id: Stored(device_id),
|
||||||
|
kind,
|
||||||
|
format: desc.format,
|
||||||
|
full_range,
|
||||||
});
|
});
|
||||||
let query = device.texture_tracker
|
let query = device.texture_tracker
|
||||||
.lock()
|
.lock()
|
||||||
@ -124,6 +136,80 @@ pub extern "C" fn wgpu_device_create_texture(
|
|||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn wgpu_texture_create_texture_view(
|
||||||
|
texture_id: TextureId,
|
||||||
|
desc: &resource::TextureViewDescriptor,
|
||||||
|
) -> TextureViewId {
|
||||||
|
let texture_guard = HUB.textures.lock();
|
||||||
|
let texture = texture_guard.get(texture_id);
|
||||||
|
|
||||||
|
let raw = HUB.devices
|
||||||
|
.lock()
|
||||||
|
.get(texture.device_id.0)
|
||||||
|
.raw
|
||||||
|
.create_image_view(
|
||||||
|
&texture.raw,
|
||||||
|
conv::map_texture_view_dimension(desc.dimension),
|
||||||
|
conv::map_texture_format(desc.format),
|
||||||
|
hal::format::Swizzle::NO,
|
||||||
|
hal::image::SubresourceRange {
|
||||||
|
aspects: conv::map_texture_aspect_flags(desc.aspect),
|
||||||
|
levels: desc.base_mip_level as u8 .. (desc.base_mip_level + desc.level_count) as u8,
|
||||||
|
layers: desc.base_array_layer as u16 .. (desc.base_array_layer + desc.array_count) as u16,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
HUB.texture_views
|
||||||
|
.lock()
|
||||||
|
.register(resource::TextureView {
|
||||||
|
raw,
|
||||||
|
texture_id: Stored(texture_id),
|
||||||
|
format: texture.format,
|
||||||
|
extent: texture.kind.extent(),
|
||||||
|
samples: texture.kind.num_samples(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn wgpu_texture_create_default_texture_view(
|
||||||
|
texture_id: TextureId,
|
||||||
|
) -> TextureViewId {
|
||||||
|
let texture_guard = HUB.textures.lock();
|
||||||
|
let texture = texture_guard.get(texture_id);
|
||||||
|
|
||||||
|
let view_kind = match texture.kind {
|
||||||
|
hal::image::Kind::D1(..) => hal::image::ViewKind::D1,
|
||||||
|
hal::image::Kind::D2(..) => hal::image::ViewKind::D2, //TODO: array
|
||||||
|
hal::image::Kind::D3(..) => hal::image::ViewKind::D3,
|
||||||
|
};
|
||||||
|
|
||||||
|
let raw = HUB.devices
|
||||||
|
.lock()
|
||||||
|
.get(texture.device_id.0)
|
||||||
|
.raw
|
||||||
|
.create_image_view(
|
||||||
|
&texture.raw,
|
||||||
|
view_kind,
|
||||||
|
conv::map_texture_format(texture.format),
|
||||||
|
hal::format::Swizzle::NO,
|
||||||
|
texture.full_range.clone(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
HUB.texture_views
|
||||||
|
.lock()
|
||||||
|
.register(resource::TextureView {
|
||||||
|
raw,
|
||||||
|
texture_id: Stored(texture_id),
|
||||||
|
format: texture.format,
|
||||||
|
extent: texture.kind.extent(),
|
||||||
|
samples: texture.kind.num_samples(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_device_create_bind_group_layout(
|
pub extern "C" fn wgpu_device_create_bind_group_layout(
|
||||||
device_id: DeviceId,
|
device_id: DeviceId,
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
use {Extent3d, Stored, TextureId};
|
use {
|
||||||
|
Extent3d, Stored,
|
||||||
|
DeviceId, TextureId,
|
||||||
|
};
|
||||||
|
|
||||||
use hal;
|
use hal;
|
||||||
|
|
||||||
@ -75,17 +78,53 @@ pub struct TextureDescriptor {
|
|||||||
|
|
||||||
pub(crate) struct Texture<B: hal::Backend> {
|
pub(crate) struct Texture<B: hal::Backend> {
|
||||||
pub raw: B::Image,
|
pub raw: B::Image,
|
||||||
pub aspects: hal::format::Aspects,
|
pub device_id: Stored<DeviceId>,
|
||||||
|
pub kind: hal::image::Kind,
|
||||||
|
pub format: TextureFormat,
|
||||||
|
pub full_range: hal::image::SubresourceRange,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct TextureAspectFlags: u32 {
|
||||||
|
const COLOR = 1;
|
||||||
|
const DEPTH = 2;
|
||||||
|
const STENCIL = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
pub enum TextureViewDimension {
|
||||||
|
D1,
|
||||||
|
D2,
|
||||||
|
D2Array,
|
||||||
|
Cube,
|
||||||
|
CubeArray,
|
||||||
|
D3,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct TextureViewDescriptor {
|
||||||
|
pub format: TextureFormat,
|
||||||
|
pub dimension: TextureViewDimension,
|
||||||
|
pub aspect: TextureAspectFlags,
|
||||||
|
pub base_mip_level: u32,
|
||||||
|
pub level_count: u32,
|
||||||
|
pub base_array_layer: u32,
|
||||||
|
pub array_count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct TextureView<B: hal::Backend> {
|
pub(crate) struct TextureView<B: hal::Backend> {
|
||||||
pub raw: B::ImageView,
|
pub raw: B::ImageView,
|
||||||
pub source_id: Stored<TextureId>,
|
pub texture_id: Stored<TextureId>,
|
||||||
pub format: TextureFormat,
|
pub format: TextureFormat,
|
||||||
pub extent: hal::image::Extent,
|
pub extent: hal::image::Extent,
|
||||||
pub samples: hal::image::NumSamples,
|
pub samples: hal::image::NumSamples,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
pub enum AddressMode {
|
pub enum AddressMode {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user