mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[rs] Get cube working
This commit is contained in:
committed by
Josh Groves
parent
9aedbed2eb
commit
49ef627bb0
@@ -88,6 +88,7 @@ web-sys = { version = "0.3.36", features = [
|
||||
"NodeList",
|
||||
"Gpu",
|
||||
"GpuAdapter",
|
||||
"GpuAddressMode",
|
||||
"GpuBindGroup",
|
||||
"GpuBindGroupBinding",
|
||||
"GpuBindGroupDescriptor",
|
||||
@@ -100,6 +101,7 @@ web-sys = { version = "0.3.36", features = [
|
||||
"GpuBindingType",
|
||||
"GpuBuffer",
|
||||
"GpuBufferBinding",
|
||||
"GpuBufferCopyView",
|
||||
"GpuBufferDescriptor",
|
||||
"GpuCanvasContext",
|
||||
"GpuColorDict",
|
||||
@@ -118,11 +120,13 @@ web-sys = { version = "0.3.36", features = [
|
||||
"GpuDevice",
|
||||
"GpuDeviceDescriptor",
|
||||
"GpuExtent3dDict",
|
||||
"GpuFilterMode",
|
||||
"GpuFrontFace",
|
||||
"GpuIndexFormat",
|
||||
"GpuInputStepMode",
|
||||
"GpuLimits",
|
||||
"GpuLoadOp",
|
||||
"GpuOrigin3dDict",
|
||||
"GpuPipelineLayout",
|
||||
"GpuPipelineLayoutDescriptor",
|
||||
"GpuPowerPreference",
|
||||
@@ -138,6 +142,7 @@ web-sys = { version = "0.3.36", features = [
|
||||
"GpuRenderPipelineDescriptor",
|
||||
"GpuRequestAdapterOptions",
|
||||
"GpuSampler",
|
||||
"GpuSamplerDescriptor",
|
||||
"GpuShaderModule",
|
||||
"GpuShaderModuleDescriptor",
|
||||
"GpuStencilOperation",
|
||||
@@ -146,6 +151,7 @@ web-sys = { version = "0.3.36", features = [
|
||||
"GpuSwapChain",
|
||||
"GpuSwapChainDescriptor",
|
||||
"GpuTexture",
|
||||
"GpuTextureCopyView",
|
||||
"GpuTextureDescriptor",
|
||||
"GpuTextureDimension",
|
||||
"GpuTextureFormat",
|
||||
|
||||
@@ -206,7 +206,7 @@ impl framework::Example for Example {
|
||||
mag_filter: wgpu::FilterMode::Nearest,
|
||||
min_filter: wgpu::FilterMode::Linear,
|
||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
lod_min_clamp: -100.0,
|
||||
lod_min_clamp: 0.0,
|
||||
lod_max_clamp: 100.0,
|
||||
compare: wgpu::CompareFunction::Undefined,
|
||||
});
|
||||
@@ -241,14 +241,12 @@ impl framework::Example for Example {
|
||||
});
|
||||
|
||||
// Create the render pipeline
|
||||
let vs_bytes =
|
||||
framework::load_glsl(include_str!("shader.vert"), framework::ShaderStage::Vertex);
|
||||
let fs_bytes = framework::load_glsl(
|
||||
include_str!("shader.frag"),
|
||||
framework::ShaderStage::Fragment,
|
||||
);
|
||||
let vs_module = device.create_shader_module(&vs_bytes);
|
||||
let fs_module = device.create_shader_module(&fs_bytes);
|
||||
let vs_bytes = include_bytes!("shader.vert.spv");
|
||||
let fs_bytes = include_bytes!("shader.frag.spv");
|
||||
let vs_module = device
|
||||
.create_shader_module(&wgpu::read_spirv(std::io::Cursor::new(&vs_bytes[..])).unwrap());
|
||||
let fs_module = device
|
||||
.create_shader_module(&wgpu::read_spirv(std::io::Cursor::new(&fs_bytes[..])).unwrap());
|
||||
|
||||
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
layout: &pipeline_layout,
|
||||
|
||||
@@ -8,5 +8,5 @@ layout(set = 0, binding = 2) uniform sampler s_Color;
|
||||
void main() {
|
||||
vec4 tex = texture(sampler2D(t_Color, s_Color), v_TexCoord);
|
||||
float mag = length(v_TexCoord-vec2(0.5));
|
||||
o_Target = mix(tex, vec4(0.0), mag*mag);
|
||||
o_Target = vec4(mix(tex.xyz, vec3(0.0), mag*mag), 1.0);
|
||||
}
|
||||
|
||||
BIN
wgpu/examples/cube/shader.frag.spv
Normal file
BIN
wgpu/examples/cube/shader.frag.spv
Normal file
Binary file not shown.
BIN
wgpu/examples/cube/shader.vert.spv
Normal file
BIN
wgpu/examples/cube/shader.vert.spv
Normal file
Binary file not shown.
@@ -3,7 +3,8 @@ use wgn;
|
||||
use crate::{
|
||||
backend::native_gpu_future, BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource,
|
||||
BindingType, BufferDescriptor, CommandEncoderDescriptor, ComputePipelineDescriptor,
|
||||
PipelineLayoutDescriptor, RenderPipelineDescriptor, TextureDescriptor, TextureViewDimension,
|
||||
PipelineLayoutDescriptor, RenderPipelineDescriptor, SamplerDescriptor, TextureDescriptor,
|
||||
TextureViewDimension,
|
||||
};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
@@ -30,6 +31,24 @@ pub type SurfaceId = wgc::id::SurfaceId;
|
||||
pub type SwapChainId = wgc::id::SwapChainId;
|
||||
pub type RenderPassEncoderId = wgc::id::RenderPassId;
|
||||
|
||||
fn map_buffer_copy_view(view: crate::BufferCopyView<'_>) -> wgc::command::BufferCopyView {
|
||||
wgc::command::BufferCopyView {
|
||||
buffer: view.buffer.id,
|
||||
offset: view.offset,
|
||||
bytes_per_row: view.bytes_per_row,
|
||||
rows_per_image: view.rows_per_image,
|
||||
}
|
||||
}
|
||||
|
||||
fn map_texture_copy_view<'a>(view: crate::TextureCopyView<'a>) -> wgc::command::TextureCopyView {
|
||||
wgc::command::TextureCopyView {
|
||||
texture: view.texture.id,
|
||||
mip_level: view.mip_level,
|
||||
array_layer: view.array_layer,
|
||||
origin: view.origin,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn request_adapter(
|
||||
options: &crate::RequestAdapterOptions<'_>,
|
||||
backends: wgt::BackendBit,
|
||||
@@ -284,7 +303,7 @@ pub(crate) fn create_compute_pipeline(
|
||||
|
||||
pub(crate) type CreateBufferMappedDetail = BufferDetail;
|
||||
|
||||
pub(crate) fn create_buffer_mapped<'a>(
|
||||
pub(crate) fn device_create_buffer_mapped<'a>(
|
||||
device: &DeviceId,
|
||||
desc: &BufferDescriptor,
|
||||
) -> crate::CreateBufferMapped<'a> {
|
||||
@@ -316,7 +335,7 @@ pub(crate) struct BufferDetail {
|
||||
device_id: DeviceId,
|
||||
}
|
||||
|
||||
pub(crate) fn create_buffer_mapped_finish(
|
||||
pub(crate) fn device_create_buffer_mapped_finish(
|
||||
create_buffer_mapped: crate::CreateBufferMapped<'_>,
|
||||
) -> crate::Buffer {
|
||||
buffer_unmap(&create_buffer_mapped.id);
|
||||
@@ -332,7 +351,7 @@ pub(crate) fn buffer_unmap(buffer: &BufferId) {
|
||||
wgn::wgpu_buffer_unmap(*buffer);
|
||||
}
|
||||
|
||||
pub(crate) fn create_buffer(device: &DeviceId, desc: &BufferDescriptor) -> crate::Buffer {
|
||||
pub(crate) fn device_create_buffer(device: &DeviceId, desc: &BufferDescriptor) -> crate::Buffer {
|
||||
let owned_label = OwnedLabel::new(desc.label.as_deref());
|
||||
crate::Buffer {
|
||||
id: wgn::wgpu_device_create_buffer(
|
||||
@@ -347,7 +366,7 @@ pub(crate) fn create_buffer(device: &DeviceId, desc: &BufferDescriptor) -> crate
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn create_texture(device: &DeviceId, desc: &TextureDescriptor) -> TextureId {
|
||||
pub(crate) fn device_create_texture(device: &DeviceId, desc: &TextureDescriptor) -> TextureId {
|
||||
let owned_label = OwnedLabel::new(desc.label.as_deref());
|
||||
wgn::wgpu_device_create_texture(
|
||||
*device,
|
||||
@@ -363,6 +382,10 @@ pub(crate) fn create_texture(device: &DeviceId, desc: &TextureDescriptor) -> Tex
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn device_create_sampler(device: &DeviceId, desc: &SamplerDescriptor) -> SamplerId {
|
||||
wgn::wgpu_device_create_sampler(*device, desc)
|
||||
}
|
||||
|
||||
pub(crate) fn create_command_encoder(
|
||||
device: &DeviceId,
|
||||
desc: &CommandEncoderDescriptor,
|
||||
@@ -376,7 +399,7 @@ pub(crate) fn create_command_encoder(
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn copy_buffer_to_buffer(
|
||||
pub(crate) fn command_encoder_copy_buffer_to_buffer(
|
||||
command_encoder: &CommandEncoderId,
|
||||
source: &crate::Buffer,
|
||||
source_offset: wgt::BufferAddress,
|
||||
@@ -394,6 +417,20 @@ pub(crate) fn copy_buffer_to_buffer(
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn command_encoder_copy_buffer_to_texture(
|
||||
command_encoder: &CommandEncoderId,
|
||||
source: crate::BufferCopyView,
|
||||
destination: crate::TextureCopyView,
|
||||
copy_size: wgt::Extent3d,
|
||||
) {
|
||||
wgn::wgpu_command_encoder_copy_buffer_to_texture(
|
||||
*command_encoder,
|
||||
&map_buffer_copy_view(source),
|
||||
&map_texture_copy_view(destination),
|
||||
copy_size,
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn begin_compute_pass(command_encoder: &CommandEncoderId) -> ComputePassId {
|
||||
unsafe { wgn::wgpu_command_encoder_begin_compute_pass(*command_encoder, None) }
|
||||
}
|
||||
@@ -515,7 +552,9 @@ impl BufferReadMappingDetail {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn create_surface<W: raw_window_handle::HasRawWindowHandle>(window: &W) -> SurfaceId {
|
||||
pub(crate) fn device_create_surface<W: raw_window_handle::HasRawWindowHandle>(
|
||||
window: &W,
|
||||
) -> SurfaceId {
|
||||
wgn::wgpu_create_surface(window.raw_window_handle())
|
||||
}
|
||||
|
||||
@@ -597,6 +636,22 @@ pub(crate) fn render_pass_set_bind_group(
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn render_pass_set_index_buffer<'a>(
|
||||
render_pass: &RenderPassEncoderId,
|
||||
buffer: &'a crate::Buffer,
|
||||
offset: wgt::BufferAddress,
|
||||
size: wgt::BufferAddress,
|
||||
) {
|
||||
unsafe {
|
||||
wgn::wgpu_render_pass_set_index_buffer(
|
||||
render_pass.as_mut().unwrap(),
|
||||
buffer.id,
|
||||
offset,
|
||||
size,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn render_pass_set_vertex_buffer<'a>(
|
||||
render_pass: &RenderPassEncoderId,
|
||||
slot: u32,
|
||||
@@ -631,6 +686,24 @@ pub(crate) fn render_pass_draw(
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn render_pass_draw_indexed(
|
||||
render_pass: &RenderPassEncoderId,
|
||||
indices: Range<u32>,
|
||||
base_vertex: i32,
|
||||
instances: Range<u32>,
|
||||
) {
|
||||
unsafe {
|
||||
wgn::wgpu_render_pass_draw_indexed(
|
||||
render_pass.as_mut().unwrap(),
|
||||
indices.end - indices.start,
|
||||
instances.end - instances.start,
|
||||
indices.start,
|
||||
base_vertex,
|
||||
instances.start,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn render_pass_end_pass(render_pass: &RenderPassEncoderId) {
|
||||
unsafe {
|
||||
wgn::wgpu_render_pass_end_pass(*render_pass);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::{
|
||||
BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource, BindingType, BufferDescriptor,
|
||||
CommandEncoderDescriptor, ComputePipelineDescriptor, PipelineLayoutDescriptor,
|
||||
ProgrammableStageDescriptor, RenderPipelineDescriptor, TextureDescriptor, TextureViewDimension,
|
||||
ProgrammableStageDescriptor, RenderPipelineDescriptor, SamplerDescriptor, TextureDescriptor,
|
||||
TextureViewDimension,
|
||||
};
|
||||
|
||||
use std::ops::Range;
|
||||
@@ -474,6 +475,14 @@ fn map_extent_3d(extent: wgt::Extent3d) -> web_sys::GpuExtent3dDict {
|
||||
web_sys::GpuExtent3dDict::new(extent.depth, extent.height, extent.width)
|
||||
}
|
||||
|
||||
fn map_origin_3d(origin: wgt::Origin3d) -> web_sys::GpuOrigin3dDict {
|
||||
let mut mapped = web_sys::GpuOrigin3dDict::new();
|
||||
mapped.x(origin.x);
|
||||
mapped.y(origin.y);
|
||||
mapped.z(origin.z);
|
||||
mapped
|
||||
}
|
||||
|
||||
fn map_texture_dimension(texture_dimension: wgt::TextureDimension) -> web_sys::GpuTextureDimension {
|
||||
match texture_dimension {
|
||||
wgt::TextureDimension::D1 => web_sys::GpuTextureDimension::N1d,
|
||||
@@ -482,6 +491,36 @@ fn map_texture_dimension(texture_dimension: wgt::TextureDimension) -> web_sys::G
|
||||
}
|
||||
}
|
||||
|
||||
fn map_buffer_copy_view(view: crate::BufferCopyView<'_>) -> web_sys::GpuBufferCopyView {
|
||||
let mut mapped =
|
||||
web_sys::GpuBufferCopyView::new(&view.buffer.id, view.rows_per_image, view.bytes_per_row);
|
||||
mapped.offset(view.offset as f64);
|
||||
mapped
|
||||
}
|
||||
|
||||
fn map_texture_copy_view<'a>(view: crate::TextureCopyView<'a>) -> web_sys::GpuTextureCopyView {
|
||||
let mut mapped = web_sys::GpuTextureCopyView::new(&view.texture.id);
|
||||
mapped.array_layer(view.array_layer);
|
||||
mapped.mip_level(view.mip_level);
|
||||
mapped.origin(&map_origin_3d(view.origin));
|
||||
mapped
|
||||
}
|
||||
|
||||
fn map_filter_mode(mode: wgt::FilterMode) -> web_sys::GpuFilterMode {
|
||||
match mode {
|
||||
wgt::FilterMode::Nearest => web_sys::GpuFilterMode::Nearest,
|
||||
wgt::FilterMode::Linear => web_sys::GpuFilterMode::Linear,
|
||||
}
|
||||
}
|
||||
|
||||
fn map_address_mode(mode: wgt::AddressMode) -> web_sys::GpuAddressMode {
|
||||
match mode {
|
||||
wgt::AddressMode::ClampToEdge => web_sys::GpuAddressMode::ClampToEdge,
|
||||
wgt::AddressMode::Repeat => web_sys::GpuAddressMode::Repeat,
|
||||
wgt::AddressMode::MirrorRepeat => web_sys::GpuAddressMode::MirrorRepeat,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn create_render_pipeline(
|
||||
device: &DeviceId,
|
||||
desc: &RenderPipelineDescriptor,
|
||||
@@ -558,7 +597,7 @@ pub(crate) struct CreateBufferMappedDetail {
|
||||
array_buffer: js_sys::ArrayBuffer,
|
||||
}
|
||||
|
||||
pub(crate) fn create_buffer_mapped<'a>(
|
||||
pub(crate) fn device_create_buffer_mapped<'a>(
|
||||
device: &DeviceId,
|
||||
desc: &BufferDescriptor,
|
||||
) -> crate::CreateBufferMapped<'a> {
|
||||
@@ -581,7 +620,7 @@ pub(crate) fn create_buffer_mapped<'a>(
|
||||
|
||||
pub type BufferDetail = ();
|
||||
|
||||
pub(crate) fn create_buffer_mapped_finish(
|
||||
pub(crate) fn device_create_buffer_mapped_finish(
|
||||
create_buffer_mapped: crate::CreateBufferMapped<'_>,
|
||||
) -> crate::Buffer {
|
||||
unsafe {
|
||||
@@ -614,7 +653,7 @@ pub(crate) fn buffer_unmap(buffer: &BufferId) {
|
||||
buffer.unmap();
|
||||
}
|
||||
|
||||
pub(crate) fn create_buffer(device: &DeviceId, desc: &BufferDescriptor) -> crate::Buffer {
|
||||
pub(crate) fn device_create_buffer(device: &DeviceId, desc: &BufferDescriptor) -> crate::Buffer {
|
||||
let mapped_desc = web_sys::GpuBufferDescriptor::new(desc.size as f64, desc.usage.bits());
|
||||
crate::Buffer {
|
||||
id: device.create_buffer(&mapped_desc),
|
||||
@@ -622,7 +661,7 @@ pub(crate) fn create_buffer(device: &DeviceId, desc: &BufferDescriptor) -> crate
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn create_texture(device: &DeviceId, desc: &TextureDescriptor) -> TextureId {
|
||||
pub(crate) fn device_create_texture(device: &DeviceId, desc: &TextureDescriptor) -> TextureId {
|
||||
let extent = map_extent_3d(desc.size);
|
||||
let mut mapped_desc = web_sys::GpuTextureDescriptor::new(
|
||||
map_texture_format(desc.format),
|
||||
@@ -637,6 +676,22 @@ pub(crate) fn create_texture(device: &DeviceId, desc: &TextureDescriptor) -> Tex
|
||||
device.create_texture(&mapped_desc)
|
||||
}
|
||||
|
||||
pub(crate) fn device_create_sampler(device: &DeviceId, desc: &SamplerDescriptor) -> SamplerId {
|
||||
let mut mapped_desc = web_sys::GpuSamplerDescriptor::new();
|
||||
mapped_desc.address_mode_u(map_address_mode(desc.address_mode_u));
|
||||
mapped_desc.address_mode_v(map_address_mode(desc.address_mode_v));
|
||||
mapped_desc.address_mode_w(map_address_mode(desc.address_mode_w));
|
||||
if let Some(compare) = map_compare_function(desc.compare) {
|
||||
mapped_desc.compare(compare);
|
||||
}
|
||||
mapped_desc.lod_max_clamp(desc.lod_max_clamp);
|
||||
mapped_desc.lod_min_clamp(desc.lod_min_clamp);
|
||||
mapped_desc.mag_filter(map_filter_mode(desc.mag_filter));
|
||||
mapped_desc.min_filter(map_filter_mode(desc.min_filter));
|
||||
mapped_desc.mipmap_filter(map_filter_mode(desc.mipmap_filter));
|
||||
device.create_sampler_with_descriptor(&mapped_desc)
|
||||
}
|
||||
|
||||
pub(crate) fn create_command_encoder(
|
||||
device: &DeviceId,
|
||||
_desc: &CommandEncoderDescriptor,
|
||||
@@ -645,7 +700,7 @@ pub(crate) fn create_command_encoder(
|
||||
device.create_command_encoder_with_descriptor(&mapped_desc)
|
||||
}
|
||||
|
||||
pub(crate) fn copy_buffer_to_buffer(
|
||||
pub(crate) fn command_encoder_copy_buffer_to_buffer(
|
||||
command_encoder: &CommandEncoderId,
|
||||
source: &crate::Buffer,
|
||||
source_offset: wgt::BufferAddress,
|
||||
@@ -662,6 +717,19 @@ pub(crate) fn copy_buffer_to_buffer(
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn command_encoder_copy_buffer_to_texture(
|
||||
command_encoder: &CommandEncoderId,
|
||||
source: crate::BufferCopyView,
|
||||
destination: crate::TextureCopyView,
|
||||
copy_size: wgt::Extent3d,
|
||||
) {
|
||||
command_encoder.copy_buffer_to_texture_with_gpu_extent_3d_dict(
|
||||
&map_buffer_copy_view(source),
|
||||
&map_texture_copy_view(destination),
|
||||
&map_extent_3d(copy_size),
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn begin_compute_pass(command_encoder: &CommandEncoderId) -> ComputePassId {
|
||||
let mapped_desc = web_sys::GpuComputePassDescriptor::new();
|
||||
command_encoder.begin_compute_pass_with_descriptor(&mapped_desc)
|
||||
@@ -752,7 +820,9 @@ impl BufferReadMappingDetail {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn create_surface<W: raw_window_handle::HasRawWindowHandle>(window: &W) -> SurfaceId {
|
||||
pub(crate) fn device_create_surface<W: raw_window_handle::HasRawWindowHandle>(
|
||||
window: &W,
|
||||
) -> SurfaceId {
|
||||
let handle = window.raw_window_handle();
|
||||
let canvas_attribute = match handle {
|
||||
raw_window_handle::RawWindowHandle::Web(web_handle) => web_handle.id,
|
||||
@@ -877,6 +947,19 @@ pub(crate) fn render_pass_set_bind_group(
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn render_pass_set_index_buffer<'a>(
|
||||
render_pass: &RenderPassEncoderId,
|
||||
buffer: &'a crate::Buffer,
|
||||
offset: wgt::BufferAddress,
|
||||
_size: wgt::BufferAddress,
|
||||
) {
|
||||
render_pass.set_index_buffer_with_f64(
|
||||
&buffer.id,
|
||||
offset as f64,
|
||||
// TODO: size,
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn render_pass_set_vertex_buffer<'a>(
|
||||
render_pass: &RenderPassEncoderId,
|
||||
slot: u32,
|
||||
@@ -905,6 +988,21 @@ pub(crate) fn render_pass_draw(
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn render_pass_draw_indexed(
|
||||
render_pass: &RenderPassEncoderId,
|
||||
indices: Range<u32>,
|
||||
base_vertex: i32,
|
||||
instances: Range<u32>,
|
||||
) {
|
||||
render_pass.draw_indexed(
|
||||
indices.end - indices.start,
|
||||
instances.end - instances.start,
|
||||
indices.start,
|
||||
base_vertex,
|
||||
instances.start,
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn render_pass_end_pass(render_pass: &RenderPassEncoderId) {
|
||||
render_pass.end_pass();
|
||||
}
|
||||
|
||||
162
wgpu/src/lib.rs
162
wgpu/src/lib.rs
@@ -468,7 +468,6 @@ pub struct SwapChainOutput {
|
||||
swap_chain_id: backend::SwapChainId,
|
||||
}
|
||||
|
||||
/*
|
||||
/// A view of a buffer which can be used to copy to or from a texture.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BufferCopyView<'a> {
|
||||
@@ -488,17 +487,6 @@ pub struct BufferCopyView<'a> {
|
||||
pub rows_per_image: u32,
|
||||
}
|
||||
|
||||
impl BufferCopyView<'_> {
|
||||
fn into_native(self) -> wgc::command::BufferCopyView {
|
||||
wgc::command::BufferCopyView {
|
||||
buffer: self.buffer.id,
|
||||
offset: self.offset,
|
||||
bytes_per_row: self.bytes_per_row,
|
||||
rows_per_image: self.rows_per_image,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A view of a texture which can be used to copy to or from a buffer or another texture.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TextureCopyView<'a> {
|
||||
@@ -515,18 +503,6 @@ pub struct TextureCopyView<'a> {
|
||||
pub origin: Origin3d,
|
||||
}
|
||||
|
||||
impl<'a> TextureCopyView<'a> {
|
||||
fn into_native(self) -> wgc::command::TextureCopyView {
|
||||
wgc::command::TextureCopyView {
|
||||
texture: self.texture.id,
|
||||
mip_level: self.mip_level,
|
||||
array_layer: self.array_layer,
|
||||
origin: self.origin,
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/// A buffer being created, mapped in host memory.
|
||||
pub struct CreateBufferMapped<'a> {
|
||||
id: backend::BufferId,
|
||||
@@ -545,7 +521,7 @@ impl CreateBufferMapped<'_> {
|
||||
|
||||
/// Unmaps the buffer from host memory and returns a [`Buffer`].
|
||||
pub fn finish(self) -> Buffer {
|
||||
backend::create_buffer_mapped_finish(self)
|
||||
backend::device_create_buffer_mapped_finish(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -553,7 +529,7 @@ impl Surface {
|
||||
/// Creates a surface from a raw window handle.
|
||||
pub fn create<W: raw_window_handle::HasRawWindowHandle>(window: &W) -> Self {
|
||||
Surface {
|
||||
id: backend::create_surface(window),
|
||||
id: backend::device_create_surface(window),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -668,7 +644,7 @@ impl Device {
|
||||
|
||||
/// Creates a new buffer.
|
||||
pub fn create_buffer(&self, desc: &BufferDescriptor) -> Buffer {
|
||||
backend::create_buffer(&self.id, desc)
|
||||
backend::device_create_buffer(&self.id, desc)
|
||||
}
|
||||
|
||||
/// Creates a new buffer and maps it into host-visible memory.
|
||||
@@ -677,7 +653,7 @@ impl Device {
|
||||
/// will not be created until calling [`CreateBufferMapped::finish`].
|
||||
pub fn create_buffer_mapped(&self, desc: &BufferDescriptor) -> CreateBufferMapped<'_> {
|
||||
assert_ne!(desc.size, 0);
|
||||
backend::create_buffer_mapped(&self.id, desc)
|
||||
backend::device_create_buffer_mapped(&self.id, desc)
|
||||
}
|
||||
|
||||
/// Creates a new buffer, maps it into host-visible memory, copies data from the given slice,
|
||||
@@ -697,21 +673,19 @@ impl Device {
|
||||
/// `desc` specifies the general format of the texture.
|
||||
pub fn create_texture(&self, desc: &TextureDescriptor) -> Texture {
|
||||
Texture {
|
||||
id: backend::create_texture(&self.id, desc),
|
||||
id: backend::device_create_texture(&self.id, desc),
|
||||
owned: true,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/// Creates a new [`Sampler`].
|
||||
///
|
||||
/// `desc` specifies the behavior of the sampler.
|
||||
pub fn create_sampler(&self, desc: &SamplerDescriptor) -> Sampler {
|
||||
Sampler {
|
||||
id: wgn::wgpu_device_create_sampler(self.id, desc),
|
||||
}
|
||||
/// Creates a new [`Sampler`].
|
||||
///
|
||||
/// `desc` specifies the behavior of the sampler.
|
||||
pub fn create_sampler(&self, desc: &SamplerDescriptor) -> Sampler {
|
||||
Sampler {
|
||||
id: backend::device_create_sampler(&self.id, desc),
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/// Create a new [`SwapChain`] which targets `surface`.
|
||||
pub fn create_swap_chain(&self, surface: &Surface, desc: &SwapChainDescriptor) -> SwapChain {
|
||||
@@ -931,7 +905,7 @@ impl CommandEncoder {
|
||||
destination_offset: BufferAddress,
|
||||
copy_size: BufferAddress,
|
||||
) {
|
||||
backend::copy_buffer_to_buffer(
|
||||
backend::command_encoder_copy_buffer_to_buffer(
|
||||
&self.id,
|
||||
source,
|
||||
source_offset,
|
||||
@@ -941,36 +915,31 @@ impl CommandEncoder {
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
/// Copy data from a buffer to a texture.
|
||||
pub fn copy_buffer_to_texture(
|
||||
&mut self,
|
||||
source: BufferCopyView,
|
||||
destination: TextureCopyView,
|
||||
copy_size: Extent3d,
|
||||
) {
|
||||
wgn::wgpu_command_encoder_copy_buffer_to_texture(
|
||||
self.id,
|
||||
&source.into_native(),
|
||||
&destination.into_native(),
|
||||
copy_size,
|
||||
);
|
||||
}
|
||||
/// Copy data from a buffer to a texture.
|
||||
pub fn copy_buffer_to_texture(
|
||||
&mut self,
|
||||
source: BufferCopyView,
|
||||
destination: TextureCopyView,
|
||||
copy_size: Extent3d,
|
||||
) {
|
||||
backend::command_encoder_copy_buffer_to_texture(&self.id, source, destination, copy_size);
|
||||
}
|
||||
|
||||
/// Copy data from a texture to a buffer.
|
||||
pub fn copy_texture_to_buffer(
|
||||
&mut self,
|
||||
source: TextureCopyView,
|
||||
destination: BufferCopyView,
|
||||
copy_size: Extent3d,
|
||||
) {
|
||||
wgn::wgpu_command_encoder_copy_texture_to_buffer(
|
||||
self.id,
|
||||
&source.into_native(),
|
||||
&destination.into_native(),
|
||||
copy_size,
|
||||
);
|
||||
}
|
||||
/*
|
||||
/// Copy data from a texture to a buffer.
|
||||
pub fn copy_texture_to_buffer(
|
||||
&mut self,
|
||||
source: TextureCopyView,
|
||||
destination: BufferCopyView,
|
||||
copy_size: Extent3d,
|
||||
) {
|
||||
wgn::wgpu_command_encoder_copy_texture_to_buffer(
|
||||
self.id,
|
||||
&source.into_native(),
|
||||
&destination.into_native(),
|
||||
copy_size,
|
||||
);
|
||||
}
|
||||
|
||||
/// Copy data from one texture to another.
|
||||
pub fn copy_texture_to_texture(
|
||||
@@ -1008,35 +977,29 @@ impl<'a> RenderPass<'a> {
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn set_blend_color(&mut self, color: Color) {
|
||||
unsafe {
|
||||
wgn::wgpu_render_pass_set_blend_color(self.id.as_mut().unwrap(), &color);
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the active index buffer.
|
||||
///
|
||||
/// Subsequent calls to [`draw_indexed`](RenderPass::draw_indexed) on this [`RenderPass`] will
|
||||
/// use `buffer` as the source index buffer.
|
||||
///
|
||||
/// If `size == 0`, the remaining part of the buffer is considered.
|
||||
pub fn set_index_buffer(
|
||||
&mut self,
|
||||
buffer: &'a Buffer,
|
||||
offset: BufferAddress,
|
||||
size: BufferAddress,
|
||||
) {
|
||||
unsafe {
|
||||
wgn::wgpu_render_pass_set_index_buffer(
|
||||
self.id.as_mut().unwrap(),
|
||||
buffer.id,
|
||||
offset,
|
||||
size,
|
||||
);
|
||||
pub fn set_blend_color(&mut self, color: Color) {
|
||||
unsafe {
|
||||
wgn::wgpu_render_pass_set_blend_color(self.id.as_mut().unwrap(), &color);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/// Sets the active index buffer.
|
||||
///
|
||||
/// Subsequent calls to [`draw_indexed`](RenderPass::draw_indexed) on this [`RenderPass`] will
|
||||
/// use `buffer` as the source index buffer.
|
||||
///
|
||||
/// If `size == 0`, the remaining part of the buffer is considered.
|
||||
pub fn set_index_buffer(
|
||||
&mut self,
|
||||
buffer: &'a Buffer,
|
||||
offset: BufferAddress,
|
||||
size: BufferAddress,
|
||||
) {
|
||||
backend::render_pass_set_index_buffer(&self.id, buffer, offset, size)
|
||||
}
|
||||
|
||||
/// Assign a vertex buffer to a slot.
|
||||
///
|
||||
/// Subsequent calls to [`draw`] and [`draw_indexed`] on this
|
||||
@@ -1105,24 +1068,15 @@ impl<'a> RenderPass<'a> {
|
||||
backend::render_pass_draw(&self.id, vertices, instances)
|
||||
}
|
||||
|
||||
/*
|
||||
/// Draws indexed primitives using the active index buffer and the active vertex buffers.
|
||||
///
|
||||
/// The active index buffer can be set with [`RenderPass::set_index_buffer`], while the active
|
||||
/// vertex buffers can be set with [`RenderPass::set_vertex_buffer`].
|
||||
pub fn draw_indexed(&mut self, indices: Range<u32>, base_vertex: i32, instances: Range<u32>) {
|
||||
unsafe {
|
||||
wgn::wgpu_render_pass_draw_indexed(
|
||||
self.id.as_mut().unwrap(),
|
||||
indices.end - indices.start,
|
||||
instances.end - instances.start,
|
||||
indices.start,
|
||||
base_vertex,
|
||||
instances.start,
|
||||
);
|
||||
}
|
||||
backend::render_pass_draw_indexed(&self.id, indices, base_vertex, instances);
|
||||
}
|
||||
|
||||
/*
|
||||
/// Draws primitives from the active vertex buffer(s) based on the contents of the `indirect_buffer`.
|
||||
///
|
||||
/// The active vertex buffers can be set with [`RenderPass::set_vertex_buffer`].
|
||||
|
||||
Reference in New Issue
Block a user