mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Texture view creation in Rust and the example
This commit is contained in:
parent
1137ad2f70
commit
879cd64b30
@ -10,6 +10,19 @@ fn main() {
|
||||
},
|
||||
});
|
||||
|
||||
let texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
size: wgpu::Extent3d {
|
||||
width: 256,
|
||||
height: 256,
|
||||
depth: 1,
|
||||
},
|
||||
array_size: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::R8g8b8a8Unorm,
|
||||
usage: wgpu::TextureUsageFlags::OUTPUT_ATTACHMENT,
|
||||
});
|
||||
let color_view = texture.create_default_texture_view();
|
||||
|
||||
let vs_bytes = include_bytes!("./../data/hello_triangle.vert.spv");
|
||||
let vs_module = device.create_shader_module(vs_bytes);
|
||||
let fs_bytes = include_bytes!("./../data/hello_triangle.frag.spv");
|
||||
@ -53,7 +66,6 @@ fn main() {
|
||||
let mut cmd_buf = device.create_command_buffer(&wgpu::CommandBufferDescriptor {});
|
||||
|
||||
{
|
||||
let color_view = unimplemented!(); //TODO!
|
||||
let rpass = cmd_buf.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: &[
|
||||
wgpu::RenderPassColorAttachmentDescriptor {
|
||||
|
||||
19
examples/vk_layer_settings.txt
Normal file
19
examples/vk_layer_settings.txt
Normal file
@ -0,0 +1,19 @@
|
||||
lunarg_core_validation.debug_action = VK_DBG_LAYER_ACTION_LOG_MSG
|
||||
lunarg_core_validation.report_flags = error,warn,perf
|
||||
lunarg_core_validation.log_filename = stdout
|
||||
|
||||
lunarg_object_tracker.debug_action = VK_DBG_LAYER_ACTION_LOG_MSG
|
||||
lunarg_object_tracker.report_flags = error,warn,perf
|
||||
lunarg_object_tracker.log_filename = stdout
|
||||
|
||||
lunarg_parameter_validation.debug_action = VK_DBG_LAYER_ACTION_LOG_MSG
|
||||
lunarg_parameter_validation.report_flags = error,warn,perf
|
||||
lunarg_parameter_validation.log_filename = stdout
|
||||
|
||||
google_threading.debug_action = VK_DBG_LAYER_ACTION_LOG_MSG
|
||||
google_threading.report_flags = error,warn,perf
|
||||
google_threading.log_filename = stdout
|
||||
|
||||
google_unique_objects.debug_action = VK_DBG_LAYER_ACTION_LOG_MSG
|
||||
google_unique_objects.report_flags = error,warn,perf
|
||||
google_unique_objects.log_filename = stdout
|
||||
@ -100,6 +100,10 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
||||
let view_guard = HUB.texture_views.lock();
|
||||
|
||||
let mut current_comb = device.com_allocator.extend(cmb);
|
||||
current_comb.begin(
|
||||
hal::command::CommandBufferFlags::ONE_TIME_SUBMIT,
|
||||
hal::command::CommandBufferInheritanceInfo::default(),
|
||||
);
|
||||
let mut extent = None;
|
||||
|
||||
let render_pass = {
|
||||
|
||||
@ -40,39 +40,43 @@ pub extern "C" fn wgpu_render_pass_end_pass(
|
||||
.take(pass_id);
|
||||
pass.raw.end_render_pass();
|
||||
|
||||
let buffer_guard = HUB.buffers.lock();
|
||||
let texture_guard = HUB.textures.lock();
|
||||
let mut cmb_guard = HUB.command_buffers.lock();
|
||||
let cmb = cmb_guard.get_mut(pass.cmb_id.0);
|
||||
|
||||
let buffer_barriers = cmb.buffer_tracker
|
||||
.consume(pass.buffer_tracker)
|
||||
.map(|(id, transit)| {
|
||||
let b = buffer_guard.get(id);
|
||||
hal::memory::Barrier::Buffer {
|
||||
states: conv::map_buffer_state(transit.start) ..
|
||||
conv::map_buffer_state(transit.end),
|
||||
target: &b.raw,
|
||||
}
|
||||
});
|
||||
let texture_barriers = cmb.texture_tracker
|
||||
.consume(pass.texture_tracker)
|
||||
.map(|(id, transit)| {
|
||||
let t = texture_guard.get(id);
|
||||
let aspects = t.full_range.aspects;
|
||||
hal::memory::Barrier::Image {
|
||||
states: conv::map_texture_state(transit.start, aspects) ..
|
||||
conv::map_texture_state(transit.end, aspects),
|
||||
target: &t.raw,
|
||||
range: t.full_range.clone(), //TODO?
|
||||
}
|
||||
});
|
||||
if let Some(ref mut last) = cmb.raw.last_mut() {
|
||||
let buffer_guard = HUB.buffers.lock();
|
||||
let texture_guard = HUB.textures.lock();
|
||||
|
||||
pass.raw.pipeline_barrier(
|
||||
hal::pso::PipelineStage::TOP_OF_PIPE .. hal::pso::PipelineStage::BOTTOM_OF_PIPE,
|
||||
hal::memory::Dependencies::empty(),
|
||||
buffer_barriers.chain(texture_barriers),
|
||||
);
|
||||
let buffer_barriers = cmb.buffer_tracker
|
||||
.consume(pass.buffer_tracker)
|
||||
.map(|(id, transit)| {
|
||||
let b = buffer_guard.get(id);
|
||||
hal::memory::Barrier::Buffer {
|
||||
states: conv::map_buffer_state(transit.start) ..
|
||||
conv::map_buffer_state(transit.end),
|
||||
target: &b.raw,
|
||||
}
|
||||
});
|
||||
let texture_barriers = cmb.texture_tracker
|
||||
.consume(pass.texture_tracker)
|
||||
.map(|(id, transit)| {
|
||||
let t = texture_guard.get(id);
|
||||
let aspects = t.full_range.aspects;
|
||||
hal::memory::Barrier::Image {
|
||||
states: conv::map_texture_state(transit.start, aspects) ..
|
||||
conv::map_texture_state(transit.end, aspects),
|
||||
target: &t.raw,
|
||||
range: t.full_range.clone(), //TODO?
|
||||
}
|
||||
});
|
||||
|
||||
last.pipeline_barrier(
|
||||
hal::pso::PipelineStage::TOP_OF_PIPE .. hal::pso::PipelineStage::BOTTOM_OF_PIPE,
|
||||
hal::memory::Dependencies::empty(),
|
||||
buffer_barriers.chain(texture_barriers),
|
||||
);
|
||||
last.finish();
|
||||
}
|
||||
|
||||
cmb.raw.push(pass.raw);
|
||||
pass.cmb_id.0
|
||||
|
||||
@ -8,7 +8,8 @@ use std::ffi::CString;
|
||||
pub use wgn::{
|
||||
AdapterDescriptor, Color, CommandBufferDescriptor, DeviceDescriptor, Extensions, Extent3d,
|
||||
Origin3d, PowerPreference, ShaderModuleDescriptor, ShaderStage,
|
||||
BindGroupLayoutBinding, BindingType, TextureDimension, TextureDescriptor, TextureFormat, TextureUsageFlags,
|
||||
BindGroupLayoutBinding, BindingType, TextureDimension, TextureDescriptor, TextureFormat,
|
||||
TextureUsageFlags, TextureViewDescriptor,
|
||||
PrimitiveTopology, BlendStateDescriptor, ColorWriteFlags, DepthStencilStateDescriptor,
|
||||
RenderPassDescriptor, RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
|
||||
LoadOp, StoreOp,
|
||||
@ -243,13 +244,27 @@ impl Device {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_texture(&self, desc: TextureDescriptor) -> Texture {
|
||||
pub fn create_texture(&self, desc: &TextureDescriptor) -> Texture {
|
||||
Texture {
|
||||
id: wgn::wgpu_device_create_texture(self.id, &desc),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Texture {
|
||||
pub fn create_texture_view(&self, desc: &TextureViewDescriptor) -> TextureView {
|
||||
TextureView {
|
||||
id: wgn::wgpu_texture_create_texture_view(self.id, &desc),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_default_texture_view(&self) -> TextureView {
|
||||
TextureView {
|
||||
id: wgn::wgpu_texture_create_default_texture_view(self.id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CommandBuffer {
|
||||
pub fn begin_render_pass(&mut self, desc: &RenderPassDescriptor<&TextureView>) -> RenderPass {
|
||||
let colors = desc.color_attachments
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user