mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-16 17:02:32 +00:00
Wholesome spec update.
Biggest change is that buffer binding is done one by one. There is a number of renamings of the fields, also the binding types are expanded.
This commit is contained in:
parent
a74de20ac6
commit
095f320470
@ -80,7 +80,7 @@ int main(
|
||||
WGPUBindGroupLayoutId bind_group_layout =
|
||||
wgpu_device_create_bind_group_layout(device,
|
||||
&(WGPUBindGroupLayoutDescriptor){
|
||||
.bindings = &(WGPUBindGroupLayoutBinding){
|
||||
.bindings = &(WGPUBindGroupLayoutEntry){
|
||||
.binding = 0,
|
||||
.visibility = WGPUShaderStage_COMPUTE,
|
||||
.ty = WGPUBindingType_StorageBuffer},
|
||||
@ -95,7 +95,7 @@ int main(
|
||||
|
||||
WGPUBindGroupId bind_group = wgpu_device_create_bind_group(device,
|
||||
&(WGPUBindGroupDescriptor){.layout = bind_group_layout,
|
||||
.bindings = &(WGPUBindGroupBinding){
|
||||
.bindings = &(WGPUBindGroupEntry){
|
||||
.binding = 0,
|
||||
.resource = resource},
|
||||
.bindings_length = BINDINGS_LENGTH});
|
||||
@ -135,7 +135,7 @@ int main(
|
||||
wgpu_compute_pass_dispatch(command_pass, numbers_length, 1, 1);
|
||||
wgpu_compute_pass_end_pass(command_pass);
|
||||
|
||||
WGPUQueueId queue = wgpu_device_get_queue(device);
|
||||
WGPUQueueId queue = wgpu_device_get_default_queue(device);
|
||||
|
||||
WGPUCommandBufferId command_buffer = wgpu_command_encoder_finish(encoder, NULL);
|
||||
|
||||
|
@ -260,7 +260,7 @@ int main() {
|
||||
wgpu_render_pass_set_pipeline(rpass, render_pipeline);
|
||||
wgpu_render_pass_set_bind_group(rpass, 0, bind_group, NULL, 0);
|
||||
wgpu_render_pass_draw(rpass, 3, 1, 0, 0);
|
||||
WGPUQueueId queue = wgpu_device_get_queue(device);
|
||||
WGPUQueueId queue = wgpu_device_get_default_queue(device);
|
||||
wgpu_render_pass_end_pass(rpass);
|
||||
WGPUCommandBufferId cmd_buf = wgpu_command_encoder_finish(cmd_encoder, NULL);
|
||||
wgpu_queue_submit(queue, &cmd_buf, 1);
|
||||
|
139
ffi/wgpu.h
139
ffi/wgpu.h
@ -42,8 +42,10 @@ typedef enum {
|
||||
WGPUBindingType_StorageBuffer = 1,
|
||||
WGPUBindingType_ReadonlyStorageBuffer = 2,
|
||||
WGPUBindingType_Sampler = 3,
|
||||
WGPUBindingType_SampledTexture = 4,
|
||||
WGPUBindingType_StorageTexture = 5,
|
||||
WGPUBindingType_ComparisonSampler = 4,
|
||||
WGPUBindingType_SampledTexture = 5,
|
||||
WGPUBindingType_ReadonlyStorageTexture = 6,
|
||||
WGPUBindingType_WriteonlyStorageTexture = 7,
|
||||
} WGPUBindingType;
|
||||
|
||||
typedef enum {
|
||||
@ -126,8 +128,25 @@ typedef enum {
|
||||
} WGPUPowerPreference;
|
||||
|
||||
typedef enum {
|
||||
/**
|
||||
* The presentation engine does **not** wait for a vertical blanking period and
|
||||
* the request is presented immediately. This is a low-latency presentation mode,
|
||||
* but visible tearing may be observed. Will fallback to `Fifo` if unavailable on the
|
||||
* selected platform and backend. Not optimal for mobile.
|
||||
*/
|
||||
WGPUPresentMode_Immediate = 0,
|
||||
/**
|
||||
* The presentation engine waits for the next vertical blanking period to update
|
||||
* the current image, but frames may be submitted without delay. This is a low-latency
|
||||
* presentation mode and visible tearing will **not** be observed. Will fallback to `Fifo`
|
||||
* if unavailable on the selected platform and backend. Not optimal for mobile.
|
||||
*/
|
||||
WGPUPresentMode_Mailbox = 1,
|
||||
/**
|
||||
* The presentation engine waits for the next vertical blanking period to update
|
||||
* the current image. The framerate will be capped at the display refresh rate,
|
||||
* corresponding to the `VSync`. Tearing cannot be observed. Optimal for mobile.
|
||||
*/
|
||||
WGPUPresentMode_Fifo = 2,
|
||||
} WGPUPresentMode;
|
||||
|
||||
@ -172,46 +191,40 @@ typedef enum {
|
||||
WGPUTextureFormat_R8Snorm = 1,
|
||||
WGPUTextureFormat_R8Uint = 2,
|
||||
WGPUTextureFormat_R8Sint = 3,
|
||||
WGPUTextureFormat_R16Unorm = 4,
|
||||
WGPUTextureFormat_R16Snorm = 5,
|
||||
WGPUTextureFormat_R16Uint = 6,
|
||||
WGPUTextureFormat_R16Sint = 7,
|
||||
WGPUTextureFormat_R16Float = 8,
|
||||
WGPUTextureFormat_Rg8Unorm = 9,
|
||||
WGPUTextureFormat_Rg8Snorm = 10,
|
||||
WGPUTextureFormat_Rg8Uint = 11,
|
||||
WGPUTextureFormat_Rg8Sint = 12,
|
||||
WGPUTextureFormat_R32Uint = 13,
|
||||
WGPUTextureFormat_R32Sint = 14,
|
||||
WGPUTextureFormat_R32Float = 15,
|
||||
WGPUTextureFormat_Rg16Unorm = 16,
|
||||
WGPUTextureFormat_Rg16Snorm = 17,
|
||||
WGPUTextureFormat_Rg16Uint = 18,
|
||||
WGPUTextureFormat_Rg16Sint = 19,
|
||||
WGPUTextureFormat_Rg16Float = 20,
|
||||
WGPUTextureFormat_Rgba8Unorm = 21,
|
||||
WGPUTextureFormat_Rgba8UnormSrgb = 22,
|
||||
WGPUTextureFormat_Rgba8Snorm = 23,
|
||||
WGPUTextureFormat_Rgba8Uint = 24,
|
||||
WGPUTextureFormat_Rgba8Sint = 25,
|
||||
WGPUTextureFormat_Bgra8Unorm = 26,
|
||||
WGPUTextureFormat_Bgra8UnormSrgb = 27,
|
||||
WGPUTextureFormat_Rgb10a2Unorm = 28,
|
||||
WGPUTextureFormat_Rg11b10Float = 29,
|
||||
WGPUTextureFormat_Rg32Uint = 30,
|
||||
WGPUTextureFormat_Rg32Sint = 31,
|
||||
WGPUTextureFormat_Rg32Float = 32,
|
||||
WGPUTextureFormat_Rgba16Unorm = 33,
|
||||
WGPUTextureFormat_Rgba16Snorm = 34,
|
||||
WGPUTextureFormat_Rgba16Uint = 35,
|
||||
WGPUTextureFormat_Rgba16Sint = 36,
|
||||
WGPUTextureFormat_Rgba16Float = 37,
|
||||
WGPUTextureFormat_Rgba32Uint = 38,
|
||||
WGPUTextureFormat_Rgba32Sint = 39,
|
||||
WGPUTextureFormat_Rgba32Float = 40,
|
||||
WGPUTextureFormat_Depth32Float = 41,
|
||||
WGPUTextureFormat_Depth24Plus = 42,
|
||||
WGPUTextureFormat_Depth24PlusStencil8 = 43,
|
||||
WGPUTextureFormat_R16Uint = 4,
|
||||
WGPUTextureFormat_R16Sint = 5,
|
||||
WGPUTextureFormat_R16Float = 6,
|
||||
WGPUTextureFormat_Rg8Unorm = 7,
|
||||
WGPUTextureFormat_Rg8Snorm = 8,
|
||||
WGPUTextureFormat_Rg8Uint = 9,
|
||||
WGPUTextureFormat_Rg8Sint = 10,
|
||||
WGPUTextureFormat_R32Uint = 11,
|
||||
WGPUTextureFormat_R32Sint = 12,
|
||||
WGPUTextureFormat_R32Float = 13,
|
||||
WGPUTextureFormat_Rg16Uint = 14,
|
||||
WGPUTextureFormat_Rg16Sint = 15,
|
||||
WGPUTextureFormat_Rg16Float = 16,
|
||||
WGPUTextureFormat_Rgba8Unorm = 17,
|
||||
WGPUTextureFormat_Rgba8UnormSrgb = 18,
|
||||
WGPUTextureFormat_Rgba8Snorm = 19,
|
||||
WGPUTextureFormat_Rgba8Uint = 20,
|
||||
WGPUTextureFormat_Rgba8Sint = 21,
|
||||
WGPUTextureFormat_Bgra8Unorm = 22,
|
||||
WGPUTextureFormat_Bgra8UnormSrgb = 23,
|
||||
WGPUTextureFormat_Rgb10a2Unorm = 24,
|
||||
WGPUTextureFormat_Rg11b10Float = 25,
|
||||
WGPUTextureFormat_Rg32Uint = 26,
|
||||
WGPUTextureFormat_Rg32Sint = 27,
|
||||
WGPUTextureFormat_Rg32Float = 28,
|
||||
WGPUTextureFormat_Rgba16Uint = 29,
|
||||
WGPUTextureFormat_Rgba16Sint = 30,
|
||||
WGPUTextureFormat_Rgba16Float = 31,
|
||||
WGPUTextureFormat_Rgba32Uint = 32,
|
||||
WGPUTextureFormat_Rgba32Sint = 33,
|
||||
WGPUTextureFormat_Rgba32Float = 34,
|
||||
WGPUTextureFormat_Depth32Float = 35,
|
||||
WGPUTextureFormat_Depth24Plus = 36,
|
||||
WGPUTextureFormat_Depth24PlusStencil8 = 37,
|
||||
} WGPUTextureFormat;
|
||||
|
||||
typedef enum {
|
||||
@ -358,8 +371,8 @@ typedef struct {
|
||||
typedef struct {
|
||||
WGPUBufferId buffer;
|
||||
WGPUBufferAddress offset;
|
||||
uint32_t row_pitch;
|
||||
uint32_t image_height;
|
||||
uint32_t bytes_per_row;
|
||||
uint32_t rows_per_image;
|
||||
} WGPUBufferCopyView;
|
||||
|
||||
typedef uint64_t WGPUId_Texture_Dummy;
|
||||
@ -448,11 +461,11 @@ typedef struct {
|
||||
typedef struct {
|
||||
uint32_t binding;
|
||||
WGPUBindingResource resource;
|
||||
} WGPUBindGroupBinding;
|
||||
} WGPUBindGroupEntry;
|
||||
|
||||
typedef struct {
|
||||
WGPUBindGroupLayoutId layout;
|
||||
const WGPUBindGroupBinding *bindings;
|
||||
const WGPUBindGroupEntry *bindings;
|
||||
uintptr_t bindings_length;
|
||||
} WGPUBindGroupDescriptor;
|
||||
|
||||
@ -466,13 +479,14 @@ typedef struct {
|
||||
uint32_t binding;
|
||||
WGPUShaderStage visibility;
|
||||
WGPUBindingType ty;
|
||||
WGPUTextureViewDimension texture_dimension;
|
||||
bool multisampled;
|
||||
bool dynamic;
|
||||
} WGPUBindGroupLayoutBinding;
|
||||
bool has_dynamic_offset;
|
||||
WGPUTextureViewDimension view_dimension;
|
||||
WGPUTextureFormat storage_texture_format;
|
||||
} WGPUBindGroupLayoutEntry;
|
||||
|
||||
typedef struct {
|
||||
const WGPUBindGroupLayoutBinding *bindings;
|
||||
const WGPUBindGroupLayoutEntry *bindings;
|
||||
uintptr_t bindings_length;
|
||||
} WGPUBindGroupLayoutDescriptor;
|
||||
|
||||
@ -616,7 +630,7 @@ typedef struct {
|
||||
WGPUFilterMode mipmap_filter;
|
||||
float lod_min_clamp;
|
||||
float lod_max_clamp;
|
||||
WGPUCompareFunction compare_function;
|
||||
const WGPUCompareFunction *compare;
|
||||
} WGPUSamplerDescriptor;
|
||||
|
||||
typedef struct {
|
||||
@ -847,9 +861,9 @@ WGPUTextureId wgpu_device_create_texture(WGPUDeviceId device_id, const WGPUTextu
|
||||
|
||||
void wgpu_device_destroy(WGPUDeviceId device_id);
|
||||
|
||||
void wgpu_device_get_limits(WGPUDeviceId _device_id, WGPULimits *limits);
|
||||
WGPUQueueId wgpu_device_get_default_queue(WGPUDeviceId device_id);
|
||||
|
||||
WGPUQueueId wgpu_device_get_queue(WGPUDeviceId device_id);
|
||||
void wgpu_device_get_limits(WGPUDeviceId _device_id, WGPULimits *limits);
|
||||
|
||||
void wgpu_device_poll(WGPUDeviceId device_id, bool force_wait);
|
||||
|
||||
@ -923,7 +937,8 @@ void wgpu_render_pass_set_blend_color(WGPURawPass *pass, const WGPUColor *color)
|
||||
|
||||
void wgpu_render_pass_set_index_buffer(WGPURawPass *pass,
|
||||
WGPUBufferId buffer_id,
|
||||
WGPUBufferAddress offset);
|
||||
WGPUBufferAddress offset,
|
||||
WGPUBufferAddress size);
|
||||
|
||||
void wgpu_render_pass_set_pipeline(WGPURawPass *pass, WGPURenderPipelineId pipeline_id);
|
||||
|
||||
@ -935,17 +950,11 @@ void wgpu_render_pass_set_scissor_rect(WGPURawPass *pass,
|
||||
|
||||
void wgpu_render_pass_set_stencil_reference(WGPURawPass *pass, uint32_t value);
|
||||
|
||||
/**
|
||||
* # Safety
|
||||
*
|
||||
* This function is unsafe as there is no guarantee that the given pointers
|
||||
* (`buffer_ids` and `offsets`) are valid for `length` elements.
|
||||
*/
|
||||
void wgpu_render_pass_set_vertex_buffers(WGPURawPass *pass,
|
||||
uint32_t start_slot,
|
||||
const WGPUBufferId *buffer_ids,
|
||||
const WGPUBufferAddress *offsets,
|
||||
uintptr_t length);
|
||||
void wgpu_render_pass_set_vertex_buffer(WGPURawPass *pass,
|
||||
uint32_t slot,
|
||||
WGPUBufferId buffer_id,
|
||||
WGPUBufferAddress offset,
|
||||
WGPUBufferAddress size);
|
||||
|
||||
void wgpu_render_pass_set_viewport(WGPURawPass *pass,
|
||||
float x,
|
||||
|
@ -27,33 +27,36 @@ pub enum BindingType {
|
||||
StorageBuffer = 1,
|
||||
ReadonlyStorageBuffer = 2,
|
||||
Sampler = 3,
|
||||
SampledTexture = 4,
|
||||
StorageTexture = 5,
|
||||
ComparisonSampler = 4,
|
||||
SampledTexture = 5,
|
||||
ReadonlyStorageTexture = 6,
|
||||
WriteonlyStorageTexture = 7,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
|
||||
pub struct BindGroupLayoutBinding {
|
||||
pub struct BindGroupLayoutEntry {
|
||||
pub binding: u32,
|
||||
pub visibility: wgt::ShaderStage,
|
||||
pub ty: BindingType,
|
||||
pub texture_dimension: wgt::TextureViewDimension,
|
||||
pub multisampled: bool,
|
||||
pub dynamic: bool,
|
||||
pub has_dynamic_offset: bool,
|
||||
pub view_dimension: wgt::TextureViewDimension,
|
||||
pub storage_texture_format: wgt::TextureFormat,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct BindGroupLayoutDescriptor {
|
||||
pub bindings: *const BindGroupLayoutBinding,
|
||||
pub bindings: *const BindGroupLayoutEntry,
|
||||
pub bindings_length: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BindGroupLayout<B: hal::Backend> {
|
||||
pub(crate) raw: B::DescriptorSetLayout,
|
||||
pub(crate) bindings: FastHashMap<u32, BindGroupLayoutBinding>,
|
||||
pub(crate) bindings: FastHashMap<u32, BindGroupLayoutEntry>,
|
||||
pub(crate) desc_ranges: DescriptorRanges,
|
||||
pub(crate) dynamic_count: usize,
|
||||
}
|
||||
@ -92,7 +95,7 @@ pub enum BindingResource {
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
|
||||
pub struct BindGroupBinding {
|
||||
pub struct BindGroupEntry {
|
||||
pub binding: u32,
|
||||
pub resource: BindingResource,
|
||||
}
|
||||
@ -101,7 +104,7 @@ pub struct BindGroupBinding {
|
||||
#[derive(Debug)]
|
||||
pub struct BindGroupDescriptor {
|
||||
pub layout: BindGroupLayoutId,
|
||||
pub bindings: *const BindGroupBinding,
|
||||
pub bindings: *const BindGroupEntry,
|
||||
pub bindings_length: usize,
|
||||
}
|
||||
|
||||
|
@ -116,12 +116,13 @@ enum RenderCommand {
|
||||
SetIndexBuffer {
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
size: BufferAddress,
|
||||
},
|
||||
SetVertexBuffers {
|
||||
start_index: u8,
|
||||
count: u8,
|
||||
phantom_buffer_ids: PhantomSlice<id::BufferId>,
|
||||
phantom_offsets: PhantomSlice<BufferAddress>,
|
||||
SetVertexBuffer {
|
||||
slot: u32,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
size: BufferAddress,
|
||||
},
|
||||
SetBlendColor(Color),
|
||||
SetStencilReference(u32),
|
||||
@ -971,15 +972,15 @@ impl<F> Global<F> {
|
||||
}
|
||||
state.vertex.update_limits();
|
||||
}
|
||||
RenderCommand::SetIndexBuffer { buffer_id, offset } => {
|
||||
RenderCommand::SetIndexBuffer { buffer_id, offset, size } => {
|
||||
let buffer = trackers
|
||||
.buffers
|
||||
.use_extend(&*buffer_guard, buffer_id, (), BufferUsage::INDEX)
|
||||
.unwrap();
|
||||
assert!(buffer.usage.contains(BufferUsage::INDEX));
|
||||
|
||||
let range = offset .. buffer.size;
|
||||
state.index.bound_buffer_view = Some((buffer_id, range));
|
||||
let end = if size != 0 { offset + size } else { buffer.size };
|
||||
state.index.bound_buffer_view = Some((buffer_id, offset .. end));
|
||||
state.index.update_limit();
|
||||
|
||||
let view = hal::buffer::IndexBufferView {
|
||||
@ -992,31 +993,20 @@ impl<F> Global<F> {
|
||||
raw.bind_index_buffer(view);
|
||||
}
|
||||
}
|
||||
RenderCommand::SetVertexBuffers { start_index, count, phantom_buffer_ids, phantom_offsets } => {
|
||||
let (new_peeker, buffer_ids) = unsafe {
|
||||
phantom_buffer_ids.decode_unaligned(peeker, count as usize, raw_data_end)
|
||||
RenderCommand::SetVertexBuffer { slot, buffer_id, offset, size } => {
|
||||
let buffer = trackers
|
||||
.buffers
|
||||
.use_extend(&*buffer_guard, buffer_id, (), BufferUsage::VERTEX)
|
||||
.unwrap();
|
||||
assert!(buffer.usage.contains(BufferUsage::VERTEX));
|
||||
state.vertex.inputs[slot as usize].total_size = if size != 0 {
|
||||
size
|
||||
} else {
|
||||
buffer.size - offset
|
||||
};
|
||||
let (new_peeker, offsets) = unsafe {
|
||||
phantom_offsets.decode_unaligned(new_peeker, count as usize, raw_data_end)
|
||||
};
|
||||
peeker = new_peeker;
|
||||
|
||||
let pairs = state.vertex.inputs[start_index as usize ..]
|
||||
.iter_mut()
|
||||
.zip(buffer_ids.iter().zip(offsets))
|
||||
.map(|(vbs, (&id, &offset))| {
|
||||
let buffer = trackers
|
||||
.buffers
|
||||
.use_extend(&*buffer_guard, id, (), BufferUsage::VERTEX)
|
||||
.unwrap();
|
||||
assert!(buffer.usage.contains(BufferUsage::VERTEX));
|
||||
|
||||
vbs.total_size = buffer.size - offset;
|
||||
(&buffer.raw, offset)
|
||||
});
|
||||
|
||||
unsafe {
|
||||
raw.bind_vertex_buffers(start_index as u32, pairs);
|
||||
raw.bind_vertex_buffers(slot, iter::once((&buffer.raw, offset)));
|
||||
}
|
||||
state.vertex.update_limits();
|
||||
}
|
||||
@ -1211,39 +1201,29 @@ pub mod render_ffi {
|
||||
pass: &mut RawPass,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
size: BufferAddress,
|
||||
) {
|
||||
pass.encode(&RenderCommand::SetIndexBuffer {
|
||||
buffer_id,
|
||||
offset,
|
||||
size,
|
||||
});
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// This function is unsafe as there is no guarantee that the given pointers
|
||||
/// (`buffer_ids` and `offsets`) are valid for `length` elements.
|
||||
// TODO: There might be other safety issues, such as using the unsafe
|
||||
// `RawPass::encode` and `RawPass::encode_slice`.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_render_pass_set_vertex_buffers(
|
||||
pub unsafe extern "C" fn wgpu_render_pass_set_vertex_buffer(
|
||||
pass: &mut RawPass,
|
||||
start_slot: u32,
|
||||
buffer_ids: *const id::BufferId,
|
||||
offsets: *const BufferAddress,
|
||||
length: usize,
|
||||
slot: u32,
|
||||
buffer_id: id::BufferId,
|
||||
offset: BufferAddress,
|
||||
size: BufferAddress,
|
||||
) {
|
||||
pass.encode(&RenderCommand::SetVertexBuffers {
|
||||
start_index: start_slot.try_into().unwrap(),
|
||||
count: length.try_into().unwrap(),
|
||||
phantom_buffer_ids: PhantomSlice::new(),
|
||||
phantom_offsets: PhantomSlice::new(),
|
||||
pass.encode(&RenderCommand::SetVertexBuffer {
|
||||
slot,
|
||||
buffer_id,
|
||||
offset,
|
||||
size,
|
||||
});
|
||||
pass.encode_slice(
|
||||
slice::from_raw_parts(buffer_ids, length),
|
||||
);
|
||||
pass.encode_slice(
|
||||
slice::from_raw_parts(offsets, length),
|
||||
);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -24,8 +24,8 @@ const BITS_PER_BYTE: u32 = 8;
|
||||
pub struct BufferCopyView {
|
||||
pub buffer: BufferId,
|
||||
pub offset: BufferAddress,
|
||||
pub row_pitch: u32,
|
||||
pub image_height: u32,
|
||||
pub bytes_per_row: u32,
|
||||
pub rows_per_image: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -161,12 +161,12 @@ impl<F> Global<F> {
|
||||
.surface_desc()
|
||||
.bits as u32
|
||||
/ BITS_PER_BYTE;
|
||||
let buffer_width = source.row_pitch / bytes_per_texel;
|
||||
assert_eq!(source.row_pitch % bytes_per_texel, 0);
|
||||
let buffer_width = source.bytes_per_row / bytes_per_texel;
|
||||
assert_eq!(source.bytes_per_row % bytes_per_texel, 0);
|
||||
let region = hal::command::BufferImageCopy {
|
||||
buffer_offset: source.offset,
|
||||
buffer_width,
|
||||
buffer_height: source.image_height,
|
||||
buffer_height: source.rows_per_image,
|
||||
image_layers: destination.to_sub_layers(aspects),
|
||||
image_offset: conv::map_origin(destination.origin),
|
||||
image_extent: conv::map_extent(copy_size),
|
||||
@ -225,12 +225,12 @@ impl<F> Global<F> {
|
||||
.surface_desc()
|
||||
.bits as u32
|
||||
/ BITS_PER_BYTE;
|
||||
let buffer_width = destination.row_pitch / bytes_per_texel;
|
||||
assert_eq!(destination.row_pitch % bytes_per_texel, 0);
|
||||
let buffer_width = destination.bytes_per_row / bytes_per_texel;
|
||||
assert_eq!(destination.bytes_per_row % bytes_per_texel, 0);
|
||||
let region = hal::command::BufferImageCopy {
|
||||
buffer_offset: destination.offset,
|
||||
buffer_width,
|
||||
buffer_height: destination.image_height,
|
||||
buffer_height: destination.rows_per_image,
|
||||
image_layers: source.to_sub_layers(aspects),
|
||||
image_offset: conv::map_origin(source.origin),
|
||||
image_extent: conv::map_extent(copy_size),
|
||||
|
@ -79,28 +79,31 @@ pub fn map_texture_usage(
|
||||
}
|
||||
|
||||
pub fn map_binding_type(
|
||||
binding: &binding_model::BindGroupLayoutBinding,
|
||||
binding: &binding_model::BindGroupLayoutEntry,
|
||||
) -> hal::pso::DescriptorType {
|
||||
use crate::binding_model::BindingType as Bt;
|
||||
use hal::pso::DescriptorType as H;
|
||||
match binding.ty {
|
||||
Bt::UniformBuffer => {
|
||||
if binding.dynamic {
|
||||
if binding.has_dynamic_offset {
|
||||
H::UniformBufferDynamic
|
||||
} else {
|
||||
H::UniformBuffer
|
||||
}
|
||||
}
|
||||
Bt::StorageBuffer | Bt::ReadonlyStorageBuffer => {
|
||||
if binding.dynamic {
|
||||
Bt::StorageBuffer |
|
||||
Bt::ReadonlyStorageBuffer => {
|
||||
if binding.has_dynamic_offset {
|
||||
H::StorageBufferDynamic
|
||||
} else {
|
||||
H::StorageBuffer
|
||||
}
|
||||
}
|
||||
Bt::Sampler => H::Sampler,
|
||||
Bt::Sampler |
|
||||
Bt::ComparisonSampler => H::Sampler,
|
||||
Bt::SampledTexture => H::SampledImage,
|
||||
Bt::StorageTexture => H::StorageImage,
|
||||
Bt::ReadonlyStorageTexture |
|
||||
Bt::WriteonlyStorageTexture => H::StorageImage,
|
||||
}
|
||||
}
|
||||
|
||||
@ -328,12 +331,9 @@ pub(crate) fn map_texture_format(
|
||||
Tf::R8Sint => H::R8Sint,
|
||||
|
||||
// Normal 16 bit formats
|
||||
Tf::R16Unorm => H::R16Unorm,
|
||||
Tf::R16Snorm => H::R16Snorm,
|
||||
Tf::R16Uint => H::R16Uint,
|
||||
Tf::R16Sint => H::R16Sint,
|
||||
Tf::R16Float => H::R16Sfloat,
|
||||
|
||||
Tf::Rg8Unorm => H::Rg8Unorm,
|
||||
Tf::Rg8Snorm => H::Rg8Snorm,
|
||||
Tf::Rg8Uint => H::Rg8Uint,
|
||||
@ -343,8 +343,6 @@ pub(crate) fn map_texture_format(
|
||||
Tf::R32Uint => H::R32Uint,
|
||||
Tf::R32Sint => H::R32Sint,
|
||||
Tf::R32Float => H::R32Sfloat,
|
||||
Tf::Rg16Unorm => H::Rg16Unorm,
|
||||
Tf::Rg16Snorm => H::Rg16Snorm,
|
||||
Tf::Rg16Uint => H::Rg16Uint,
|
||||
Tf::Rg16Sint => H::Rg16Sint,
|
||||
Tf::Rg16Float => H::Rg16Sfloat,
|
||||
@ -364,8 +362,6 @@ pub(crate) fn map_texture_format(
|
||||
Tf::Rg32Uint => H::Rg32Uint,
|
||||
Tf::Rg32Sint => H::Rg32Sint,
|
||||
Tf::Rg32Float => H::Rg32Sfloat,
|
||||
Tf::Rgba16Unorm => H::Rgba16Unorm,
|
||||
Tf::Rgba16Snorm => H::Rgba16Snorm,
|
||||
Tf::Rgba16Uint => H::Rgba16Uint,
|
||||
Tf::Rgba16Sint => H::Rgba16Sint,
|
||||
Tf::Rgba16Float => H::Rgba16Sfloat,
|
||||
|
@ -18,7 +18,7 @@ use crate::{
|
||||
Stored,
|
||||
};
|
||||
|
||||
use wgt::{BufferAddress, CompareFunction, InputStepMode, TextureFormat};
|
||||
use wgt::{BufferAddress, InputStepMode, TextureFormat};
|
||||
use arrayvec::ArrayVec;
|
||||
use copyless::VecHelper as _;
|
||||
use hal::{
|
||||
@ -825,11 +825,7 @@ impl<F: IdentityFilter<id::SamplerId>> Global<F> {
|
||||
),
|
||||
lod_bias: hal::image::Lod(0.0),
|
||||
lod_range: hal::image::Lod(desc.lod_min_clamp) .. hal::image::Lod(desc.lod_max_clamp),
|
||||
comparison: if desc.compare_function == CompareFunction::Always {
|
||||
None
|
||||
} else {
|
||||
Some(conv::map_compare_function(desc.compare_function))
|
||||
},
|
||||
comparison: desc.compare.cloned().map(conv::map_compare_function),
|
||||
border: hal::image::PackedColor(0),
|
||||
normalized: true,
|
||||
anisotropic: hal::image::Anisotropic::Off, //TODO
|
||||
@ -924,7 +920,7 @@ impl<F: IdentityFilter<id::BindGroupLayoutId>> Global<F> {
|
||||
raw,
|
||||
bindings: bindings_map,
|
||||
desc_ranges: DescriptorRanges::from_bindings(&raw_bindings),
|
||||
dynamic_count: bindings.iter().filter(|b| b.dynamic).count(),
|
||||
dynamic_count: bindings.iter().filter(|b| b.has_dynamic_offset).count(),
|
||||
};
|
||||
|
||||
hub.bind_group_layouts
|
||||
@ -1047,9 +1043,11 @@ impl<F: IdentityFilter<id::BindGroupId>> Global<F> {
|
||||
binding_model::BindingType::ReadonlyStorageBuffer => {
|
||||
(BIND_BUFFER_ALIGNMENT, wgt::BufferUsage::STORAGE_READ)
|
||||
}
|
||||
binding_model::BindingType::Sampler
|
||||
| binding_model::BindingType::SampledTexture
|
||||
| binding_model::BindingType::StorageTexture => {
|
||||
binding_model::BindingType::Sampler |
|
||||
binding_model::BindingType::ComparisonSampler |
|
||||
binding_model::BindingType::SampledTexture |
|
||||
binding_model::BindingType::ReadonlyStorageTexture |
|
||||
binding_model::BindingType::WriteonlyStorageTexture => {
|
||||
panic!("Mismatched buffer binding for {:?}", decl)
|
||||
}
|
||||
};
|
||||
@ -1086,7 +1084,11 @@ impl<F: IdentityFilter<id::BindGroupId>> Global<F> {
|
||||
hal::pso::Descriptor::Buffer(&buffer.raw, range)
|
||||
}
|
||||
binding_model::BindingResource::Sampler(id) => {
|
||||
assert_eq!(decl.ty, binding_model::BindingType::Sampler);
|
||||
match decl.ty {
|
||||
binding_model::BindingType::Sampler |
|
||||
binding_model::BindingType::ComparisonSampler => {}
|
||||
_ => panic!("Wrong binding type for a sampler: {:?}", decl.ty),
|
||||
}
|
||||
let sampler = used
|
||||
.samplers
|
||||
.use_extend(&*sampler_guard, id, (), ())
|
||||
@ -1099,7 +1101,8 @@ impl<F: IdentityFilter<id::BindGroupId>> Global<F> {
|
||||
resource::TextureUsage::SAMPLED,
|
||||
hal::image::Layout::ShaderReadOnlyOptimal,
|
||||
),
|
||||
binding_model::BindingType::StorageTexture => {
|
||||
binding_model::BindingType::ReadonlyStorageTexture |
|
||||
binding_model::BindingType::WriteonlyStorageTexture => {
|
||||
(resource::TextureUsage::STORAGE, hal::image::Layout::General)
|
||||
}
|
||||
_ => panic!("Mismatched texture binding for {:?}", decl),
|
||||
|
@ -14,8 +14,6 @@ use crate::{
|
||||
use wgt::{BufferAddress, BufferUsage, CompareFunction, TextureFormat};
|
||||
use hal;
|
||||
use rendy_memory::MemoryBlock;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde_crate::{Deserialize, Serialize};
|
||||
|
||||
use std::{borrow::Borrow, fmt};
|
||||
|
||||
@ -250,7 +248,7 @@ impl Default for FilterMode {
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct SamplerDescriptor {
|
||||
pub struct SamplerDescriptor<'a> {
|
||||
pub address_mode_u: AddressMode,
|
||||
pub address_mode_v: AddressMode,
|
||||
pub address_mode_w: AddressMode,
|
||||
@ -259,7 +257,7 @@ pub struct SamplerDescriptor {
|
||||
pub mipmap_filter: FilterMode,
|
||||
pub lod_min_clamp: f32,
|
||||
pub lod_max_clamp: f32,
|
||||
pub compare_function: CompareFunction,
|
||||
pub compare: Option<&'a CompareFunction>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -318,7 +318,7 @@ pub extern "C" fn wgpu_command_buffer_destroy(command_buffer_id: id::CommandBuff
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_device_get_queue(device_id: id::DeviceId) -> id::QueueId {
|
||||
pub extern "C" fn wgpu_device_get_default_queue(device_id: id::DeviceId) -> id::QueueId {
|
||||
device_id
|
||||
}
|
||||
|
||||
|
@ -290,6 +290,7 @@ pub struct RasterizationStateDescriptor {
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub enum TextureFormat {
|
||||
// Normal 8 bit formats
|
||||
R8Unorm = 0,
|
||||
@ -298,57 +299,50 @@ pub enum TextureFormat {
|
||||
R8Sint = 3,
|
||||
|
||||
// Normal 16 bit formats
|
||||
R16Unorm = 4,
|
||||
R16Snorm = 5,
|
||||
R16Uint = 6,
|
||||
R16Sint = 7,
|
||||
R16Float = 8,
|
||||
|
||||
Rg8Unorm = 9,
|
||||
Rg8Snorm = 10,
|
||||
Rg8Uint = 11,
|
||||
Rg8Sint = 12,
|
||||
R16Uint = 4,
|
||||
R16Sint = 5,
|
||||
R16Float = 6,
|
||||
Rg8Unorm = 7,
|
||||
Rg8Snorm = 8,
|
||||
Rg8Uint = 9,
|
||||
Rg8Sint = 10,
|
||||
|
||||
// Normal 32 bit formats
|
||||
R32Uint = 13,
|
||||
R32Sint = 14,
|
||||
R32Float = 15,
|
||||
Rg16Unorm = 16,
|
||||
Rg16Snorm = 17,
|
||||
Rg16Uint = 18,
|
||||
Rg16Sint = 19,
|
||||
Rg16Float = 20,
|
||||
Rgba8Unorm = 21,
|
||||
Rgba8UnormSrgb = 22,
|
||||
Rgba8Snorm = 23,
|
||||
Rgba8Uint = 24,
|
||||
Rgba8Sint = 25,
|
||||
Bgra8Unorm = 26,
|
||||
Bgra8UnormSrgb = 27,
|
||||
R32Uint = 11,
|
||||
R32Sint = 12,
|
||||
R32Float = 13,
|
||||
Rg16Uint = 14,
|
||||
Rg16Sint = 15,
|
||||
Rg16Float = 16,
|
||||
Rgba8Unorm = 17,
|
||||
Rgba8UnormSrgb = 18,
|
||||
Rgba8Snorm = 19,
|
||||
Rgba8Uint = 20,
|
||||
Rgba8Sint = 21,
|
||||
Bgra8Unorm = 22,
|
||||
Bgra8UnormSrgb = 23,
|
||||
|
||||
// Packed 32 bit formats
|
||||
Rgb10a2Unorm = 28,
|
||||
Rg11b10Float = 29,
|
||||
Rgb10a2Unorm = 24,
|
||||
Rg11b10Float = 25,
|
||||
|
||||
// Normal 64 bit formats
|
||||
Rg32Uint = 30,
|
||||
Rg32Sint = 31,
|
||||
Rg32Float = 32,
|
||||
Rgba16Unorm = 33,
|
||||
Rgba16Snorm = 34,
|
||||
Rgba16Uint = 35,
|
||||
Rgba16Sint = 36,
|
||||
Rgba16Float = 37,
|
||||
Rg32Uint = 26,
|
||||
Rg32Sint = 27,
|
||||
Rg32Float = 28,
|
||||
Rgba16Uint = 29,
|
||||
Rgba16Sint = 30,
|
||||
Rgba16Float = 31,
|
||||
|
||||
// Normal 128 bit formats
|
||||
Rgba32Uint = 38,
|
||||
Rgba32Sint = 39,
|
||||
Rgba32Float = 40,
|
||||
Rgba32Uint = 32,
|
||||
Rgba32Sint = 33,
|
||||
Rgba32Float = 34,
|
||||
|
||||
// Depth and stencil formats
|
||||
Depth32Float = 41,
|
||||
Depth24Plus = 42,
|
||||
Depth24PlusStencil8 = 43,
|
||||
Depth32Float = 35,
|
||||
Depth24Plus = 36,
|
||||
Depth24PlusStencil8 = 37,
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
|
Loading…
Reference in New Issue
Block a user