mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
* fix more compile errors * fix err * fix all compile errors * fix clippy errors * fix issues in ray-traced-triangle example * fix clippy warnings * fix wasm not compiling * fix test * fix clippy (again) * fix some rustfmt issues * fix more rustfmt issues * fix even more rustfmt issues * fix yet more rustfmt issues * add #[allow(dead_code)] to some structs to fix clippy on web assembly * more format fixes * even more format fixes * close to final format fixes * final format fixes (hopefully) * actual final format fixes (hopefully) * move ray_cube_cube example and fix bugs * move other examples * fix crash when dropping * fix test * apply clippy and rustfmt changes * fix some memory leaks * fix incompatibility with new wgpu trunk changes * fix clippy & fmt * fix clippy errors on github * update to trunk * remove a line that printed log "Created blas ..." in device create tlas * fix merge issues * fix merge * fix fmt * restored example ray scene functionality * WIP fix rebase * Fix compile issues * More fixes * Fix rebase * Add wgls backend write_value_type AccelerationStructure * Add back xtask Cargo.lock * Revert serde path * Doc typos * Add -diff * Revert more serde * Revert serde again? * Fix doc typo * add test * clippy & fmt * fix error "blas does not exist" * fix various things * fix unused acceleration structures causing invalid SPIR-V * fix merge * fix use after free in a different way (now moved tlas instances to wgpu_core) * refactor & fmt * remove accidentally created file * remove accidentally created file (actually) * merge & fix * Fix problems * fix validation error * fix validation * fix merge * fmt * fix merge * use staging buffer trackers in creating the ray-tracing staging buffers (not the tlas_s) * change one missed staging buffer's tracker * wip: example * finished shadow! * fix merge * clippy * remove some uses of blas ids * fmt * fix merge * deduplicate code shared between command_encoder_build_acceleration_structures and command_encoder_build_acceleration_structures_unsafe_tlas * clippy * fix merge * fix warnings * clippy & fmt * re-add matching to get_raw_tlas_instance_size and tlas_instance_into_bytes * fmt * fix command * wip: fix merge * fix merge * fmt & docs * fix wasm clippy * fix issues with tests * fix issues with tests * fmt & clippy (wasm) * wip ray-traced-triangle (non hal) * unify camera location in ray_shadows * fix tests * add readme to ray_traced_triangle * note that vertex format must be f32x3 (not yet validated) * changelog * require VertexFormat::Float32x3 * fix compile error * when creating and building acceleration structures require Features::RAY_TRACING_ACCELERATION_STRUCTURE is enabled * remove duplicate workaround * fix most feedback * remove all changes from .gitattributes * fix compile error in test * more changes along same lines * format * apply feedback to more places * fix `cargo clippy` not just `cargo clippy --all-features` * cache max instances from tlas creation * fix clippy * fix examples * fix tests * remove now useless docs * add more docs * yet more docs * still more docs * Documentation. * Running out of unique commit messages to say writing docs. * Add more references to docs. * Get BindGroup in scope * Remove unintentional changes * Remove #[allow(dead_code)] * Remove old comments * Add device.poll * make ray_scene start right way up * fmt * move scratch buffer to its own module * actually remove intentional changes (turns out wgt is inconsistent) * use better names in ray_scene/shader.wgsl * fmt * remove more unintentional changes. * work on ray_tracing use after free * spelling Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com> * grammar Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com> * move things into struct (should be all vectors with 3 item types or more) * remove long-standing locks. * fmt * move not using index buffer to test * impl index & index mut for tlas package * impl index & index mut for tlas package * fix errors * fix test errors * move everything out of ray_tracing.rs * more index_mut * fmt * fix docs links * move to separate impl block * fix older request review * fmt * remove missed deref * fix wasm clippy * change to suggestions * fmt * add a note as to why `command_encoder_build_acceleration_structures_unsafe_tlas` and `command_encoder_build_acceleration_structures` are currently separate * add a todo to reconsider soon `command_encoder_build_acceleration_structures_unsafe_tlas` * switch to mat4 in ray-tracing examples * Combine RT Tests Under Single Submodule * Add More Raytracing Tests and Re-Organize * Documentation and Formatting Fixes * Remove Forced Alignment in wgpu-hal * work on out_of_order_as_build and add out_of_order_as_build_use * fmt * update test label naming * fix one validation error * fix clippy & fmt * add acceleration structure creation tests * make mis-matched index test use the correct function * move validation into validate_command_buffer * fix tests * add blas and tlas to pending writes to remove (now unneeded) `device.poll()`s * remove commented out code from examples and properly use the constants in ray_shadow * add examples to examples\README.md * rename ray tracing to ray queries in readme * remove unneeded usage from scratch buffer creation * use snatchables for raw acceleration structures * format * add EXPERIMENTAL_ to features * fix missed comment --------- Co-authored-by: Daniel Keitel <daniel.mg.keitel@fau.de> Co-authored-by: JMS55 <47158642+JMS55@users.noreply.github.com> Co-authored-by: atlas dostal <rodol@rivalrebels.com> Co-authored-by: vero <email@atlasdostal.com> Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
251 lines
7.3 KiB
Rust
251 lines
7.3 KiB
Rust
use wgt::TextureFormatFeatures;
|
|
|
|
use crate::resource::{self, TextureDescriptor};
|
|
|
|
pub fn is_valid_copy_src_texture_format(
|
|
format: wgt::TextureFormat,
|
|
aspect: wgt::TextureAspect,
|
|
) -> bool {
|
|
use wgt::TextureAspect as Ta;
|
|
use wgt::TextureFormat as Tf;
|
|
match (format, aspect) {
|
|
(Tf::Depth24Plus, _) | (Tf::Depth24PlusStencil8, Ta::DepthOnly) => false,
|
|
_ => true,
|
|
}
|
|
}
|
|
|
|
pub fn is_valid_copy_dst_texture_format(
|
|
format: wgt::TextureFormat,
|
|
aspect: wgt::TextureAspect,
|
|
) -> bool {
|
|
use wgt::TextureAspect as Ta;
|
|
use wgt::TextureFormat as Tf;
|
|
match (format, aspect) {
|
|
(Tf::Depth24Plus | Tf::Depth32Float, _)
|
|
| (Tf::Depth24PlusStencil8 | Tf::Depth32FloatStencil8, Ta::DepthOnly) => false,
|
|
_ => true,
|
|
}
|
|
}
|
|
|
|
#[cfg_attr(
|
|
any(not(target_arch = "wasm32"), target_os = "emscripten"),
|
|
allow(unused)
|
|
)]
|
|
pub fn is_valid_external_image_copy_dst_texture_format(format: wgt::TextureFormat) -> bool {
|
|
use wgt::TextureFormat as Tf;
|
|
match format {
|
|
Tf::R8Unorm
|
|
| Tf::R16Float
|
|
| Tf::R32Float
|
|
| Tf::Rg8Unorm
|
|
| Tf::Rg16Float
|
|
| Tf::Rg32Float
|
|
| Tf::Rgba8Unorm
|
|
| Tf::Rgba8UnormSrgb
|
|
| Tf::Bgra8Unorm
|
|
| Tf::Bgra8UnormSrgb
|
|
| Tf::Rgb10a2Unorm
|
|
| Tf::Rgba16Float
|
|
| Tf::Rgba32Float => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
pub fn map_buffer_usage(usage: wgt::BufferUsages) -> hal::BufferUses {
|
|
let mut u = hal::BufferUses::empty();
|
|
u.set(
|
|
hal::BufferUses::MAP_READ,
|
|
usage.contains(wgt::BufferUsages::MAP_READ),
|
|
);
|
|
u.set(
|
|
hal::BufferUses::MAP_WRITE,
|
|
usage.contains(wgt::BufferUsages::MAP_WRITE),
|
|
);
|
|
u.set(
|
|
hal::BufferUses::COPY_SRC,
|
|
usage.contains(wgt::BufferUsages::COPY_SRC),
|
|
);
|
|
u.set(
|
|
hal::BufferUses::COPY_DST,
|
|
usage.contains(wgt::BufferUsages::COPY_DST),
|
|
);
|
|
u.set(
|
|
hal::BufferUses::INDEX,
|
|
usage.contains(wgt::BufferUsages::INDEX),
|
|
);
|
|
u.set(
|
|
hal::BufferUses::VERTEX,
|
|
usage.contains(wgt::BufferUsages::VERTEX),
|
|
);
|
|
u.set(
|
|
hal::BufferUses::UNIFORM,
|
|
usage.contains(wgt::BufferUsages::UNIFORM),
|
|
);
|
|
u.set(
|
|
hal::BufferUses::STORAGE_READ | hal::BufferUses::STORAGE_READ_WRITE,
|
|
usage.contains(wgt::BufferUsages::STORAGE),
|
|
);
|
|
u.set(
|
|
hal::BufferUses::INDIRECT,
|
|
usage.contains(wgt::BufferUsages::INDIRECT),
|
|
);
|
|
u.set(
|
|
hal::BufferUses::QUERY_RESOLVE,
|
|
usage.contains(wgt::BufferUsages::QUERY_RESOLVE),
|
|
);
|
|
u.set(
|
|
hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT,
|
|
usage.contains(wgt::BufferUsages::BLAS_INPUT),
|
|
);
|
|
u.set(
|
|
hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
|
|
usage.contains(wgt::BufferUsages::TLAS_INPUT),
|
|
);
|
|
u
|
|
}
|
|
|
|
pub fn map_texture_usage(
|
|
usage: wgt::TextureUsages,
|
|
aspect: hal::FormatAspects,
|
|
) -> hal::TextureUses {
|
|
let mut u = hal::TextureUses::empty();
|
|
u.set(
|
|
hal::TextureUses::COPY_SRC,
|
|
usage.contains(wgt::TextureUsages::COPY_SRC),
|
|
);
|
|
u.set(
|
|
hal::TextureUses::COPY_DST,
|
|
usage.contains(wgt::TextureUsages::COPY_DST),
|
|
);
|
|
u.set(
|
|
hal::TextureUses::RESOURCE,
|
|
usage.contains(wgt::TextureUsages::TEXTURE_BINDING),
|
|
);
|
|
u.set(
|
|
hal::TextureUses::STORAGE_READ | hal::TextureUses::STORAGE_READ_WRITE,
|
|
usage.contains(wgt::TextureUsages::STORAGE_BINDING),
|
|
);
|
|
let is_color = aspect.contains(hal::FormatAspects::COLOR);
|
|
u.set(
|
|
hal::TextureUses::COLOR_TARGET,
|
|
usage.contains(wgt::TextureUsages::RENDER_ATTACHMENT) && is_color,
|
|
);
|
|
u.set(
|
|
hal::TextureUses::DEPTH_STENCIL_READ | hal::TextureUses::DEPTH_STENCIL_WRITE,
|
|
usage.contains(wgt::TextureUsages::RENDER_ATTACHMENT) && !is_color,
|
|
);
|
|
u
|
|
}
|
|
|
|
pub fn map_texture_usage_for_texture(
|
|
desc: &TextureDescriptor,
|
|
format_features: &TextureFormatFeatures,
|
|
) -> hal::TextureUses {
|
|
// Enforce having COPY_DST/DEPTH_STENCIL_WRITE/COLOR_TARGET otherwise we
|
|
// wouldn't be able to initialize the texture.
|
|
map_texture_usage(desc.usage, desc.format.into())
|
|
| if desc.format.is_depth_stencil_format() {
|
|
hal::TextureUses::DEPTH_STENCIL_WRITE
|
|
} else if desc.usage.contains(wgt::TextureUsages::COPY_DST) {
|
|
hal::TextureUses::COPY_DST // (set already)
|
|
} else {
|
|
// Use COPY_DST only if we can't use COLOR_TARGET
|
|
if format_features
|
|
.allowed_usages
|
|
.contains(wgt::TextureUsages::RENDER_ATTACHMENT)
|
|
&& desc.dimension == wgt::TextureDimension::D2
|
|
// Render targets dimension must be 2d
|
|
{
|
|
hal::TextureUses::COLOR_TARGET
|
|
} else {
|
|
hal::TextureUses::COPY_DST
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn map_texture_usage_from_hal(uses: hal::TextureUses) -> wgt::TextureUsages {
|
|
let mut u = wgt::TextureUsages::empty();
|
|
u.set(
|
|
wgt::TextureUsages::COPY_SRC,
|
|
uses.contains(hal::TextureUses::COPY_SRC),
|
|
);
|
|
u.set(
|
|
wgt::TextureUsages::COPY_DST,
|
|
uses.contains(hal::TextureUses::COPY_DST),
|
|
);
|
|
u.set(
|
|
wgt::TextureUsages::TEXTURE_BINDING,
|
|
uses.contains(hal::TextureUses::RESOURCE),
|
|
);
|
|
u.set(
|
|
wgt::TextureUsages::STORAGE_BINDING,
|
|
uses.contains(hal::TextureUses::STORAGE_READ | hal::TextureUses::STORAGE_READ_WRITE),
|
|
);
|
|
u.set(
|
|
wgt::TextureUsages::RENDER_ATTACHMENT,
|
|
uses.contains(hal::TextureUses::COLOR_TARGET),
|
|
);
|
|
u
|
|
}
|
|
|
|
pub fn check_texture_dimension_size(
|
|
dimension: wgt::TextureDimension,
|
|
wgt::Extent3d {
|
|
width,
|
|
height,
|
|
depth_or_array_layers,
|
|
}: wgt::Extent3d,
|
|
sample_size: u32,
|
|
limits: &wgt::Limits,
|
|
) -> Result<(), resource::TextureDimensionError> {
|
|
use resource::{TextureDimensionError as Tde, TextureErrorDimension as Ted};
|
|
use wgt::TextureDimension::*;
|
|
|
|
let (extent_limits, sample_limit) = match dimension {
|
|
D1 => ([limits.max_texture_dimension_1d, 1, 1], 1),
|
|
D2 => (
|
|
[
|
|
limits.max_texture_dimension_2d,
|
|
limits.max_texture_dimension_2d,
|
|
limits.max_texture_array_layers,
|
|
],
|
|
32,
|
|
),
|
|
D3 => (
|
|
[
|
|
limits.max_texture_dimension_3d,
|
|
limits.max_texture_dimension_3d,
|
|
limits.max_texture_dimension_3d,
|
|
],
|
|
1,
|
|
),
|
|
};
|
|
|
|
for (&dim, (&given, &limit)) in [Ted::X, Ted::Y, Ted::Z].iter().zip(
|
|
[width, height, depth_or_array_layers]
|
|
.iter()
|
|
.zip(extent_limits.iter()),
|
|
) {
|
|
if given == 0 {
|
|
return Err(Tde::Zero(dim));
|
|
}
|
|
if given > limit {
|
|
return Err(Tde::LimitExceeded { dim, given, limit });
|
|
}
|
|
}
|
|
if sample_size == 0 || sample_size > sample_limit || !sample_size.is_power_of_two() {
|
|
return Err(Tde::InvalidSampleCount(sample_size));
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub fn bind_group_layout_flags(features: wgt::Features) -> hal::BindGroupLayoutFlags {
|
|
let mut flags = hal::BindGroupLayoutFlags::empty();
|
|
flags.set(
|
|
hal::BindGroupLayoutFlags::PARTIALLY_BOUND,
|
|
features.contains(wgt::Features::PARTIALLY_BOUND_BINDING_ARRAY),
|
|
);
|
|
flags
|
|
}
|