Triangle example, minor corrections

This commit is contained in:
Dzmitry Malyshau 2019-01-21 16:16:13 -05:00
parent 32f7ae4f28
commit 2ec9d05074
4 changed files with 30 additions and 29 deletions

View File

@ -27,7 +27,7 @@ fn main() {
let depth_stencil_state =
device.create_depth_stencil_state(&wgpu::DepthStencilStateDescriptor::IGNORE);
let _render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
layout: &pipeline_layout,
stages: &[
wgpu::PipelineStageDescriptor {
@ -44,7 +44,7 @@ fn main() {
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
attachments_state: wgpu::AttachmentsState {
color_attachments: &[wgpu::Attachment {
format: wgpu::TextureFormat::R8g8b8a8Unorm,
format: wgpu::TextureFormat::B8g8r8a8Unorm,
samples: 1,
}],
depth_stencil_attachment: None,
@ -95,7 +95,7 @@ fn main() {
let (_, view) = swap_chain.get_next_texture();
let mut cmd_buf = device.create_command_buffer(&wgpu::CommandBufferDescriptor {});
{
let rpass = cmd_buf.begin_render_pass(&wgpu::RenderPassDescriptor {
let mut rpass = cmd_buf.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &view,
load_op: wgpu::LoadOp::Clear,
@ -104,6 +104,8 @@ fn main() {
}],
depth_stencil_attachment: None,
});
rpass.set_pipeline(&render_pipeline);
rpass.draw(0..3, 0..1);
rpass.end_pass();
}
@ -118,6 +120,7 @@ fn main() {
#[cfg(not(feature = "winit"))]
{
let _ = render_pipeline;
let texture = device.create_texture(&wgpu::TextureDescriptor {
size: wgpu::Extent3d {
width: 256,

View File

@ -26,7 +26,7 @@ use log::trace;
use std::collections::hash_map::Entry;
use std::ops::Range;
use std::slice;
use std::{iter, slice};
use std::thread::ThreadId;
@ -336,6 +336,11 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
clear_values,
hal::command::SubpassContents::Inline,
);
current_comb.set_scissors(0, iter::once(&rect));
current_comb.set_viewports(0, iter::once(hal::pso::Viewport {
rect,
depth: 0.0 .. 1.0,
}));
}
HUB.render_passes.write().register(RenderPass::new(

View File

@ -303,6 +303,18 @@ pub extern "C" fn wgpu_device_create_buffer(
id
}
#[no_mangle]
pub extern "C" fn wgpu_buffer_destroy(buffer_id: BufferId) {
let buffer_guard = HUB.buffers.read();
let buffer = buffer_guard.get(buffer_id);
HUB.devices
.read()
.get(buffer.device_id.value)
.destroyed
.lock()
.add(ResourceId::Buffer(buffer_id), &buffer.life_guard);
}
#[no_mangle]
pub extern "C" fn wgpu_device_create_texture(
device_id: DeviceId,
@ -477,8 +489,8 @@ pub extern "C" fn wgpu_texture_create_default_texture_view(texture_id: TextureId
pub extern "C" fn wgpu_texture_destroy(texture_id: TextureId) {
let texture_guard = HUB.textures.read();
let texture = texture_guard.get(texture_id);
let device_guard = HUB.devices.write();
device_guard
HUB.devices
.read()
.get(texture.device_id.value)
.destroyed
.lock()
@ -844,12 +856,6 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
device_id: DeviceId,
desc: &pipeline::RenderPipelineDescriptor,
) -> RenderPipelineId {
// TODO
let extent = hal::window::Extent2D {
width: 100,
height: 100,
};
let device_guard = HUB.devices.read();
let device = device_guard.get(device_id);
let pipeline_layout_guard = HUB.pipeline_layouts.read();
@ -1003,21 +1009,8 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
// TODO
let baked_states = hal::pso::BakedStates {
viewport: Some(hal::pso::Viewport {
rect: hal::pso::Rect {
x: 0,
y: 0,
w: extent.width as i16,
h: extent.height as i16,
},
depth: (0.0..1.0),
}),
scissor: Some(hal::pso::Rect {
x: 0,
y: 0,
w: extent.width as i16,
h: extent.height as i16,
}),
viewport: None,
scissor: None,
blend_color: None,
depth_bounds: None,
};

View File

@ -374,7 +374,7 @@ impl<'a> RenderPass<'a> {
}
pub fn draw(
&self, vertices: Range<u32>, instances: Range<u32>
&mut self, vertices: Range<u32>, instances: Range<u32>
) {
wgn::wgpu_render_pass_draw(
self.id,
@ -386,7 +386,7 @@ impl<'a> RenderPass<'a> {
}
pub fn draw_indexed(
&self, indices: Range<u32>, base_vertex: i32, instances: Range<u32>
&mut self, indices: Range<u32>, base_vertex: i32, instances: Range<u32>
) {
wgn::wgpu_render_pass_draw_indexed(
self.id,