summaryrefslogtreecommitdiff
path: root/engine/src/rendering
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/rendering')
-rw-r--r--engine/src/rendering/backend.rs1
-rw-r--r--engine/src/rendering/backend/opengl.rs108
-rw-r--r--engine/src/rendering/backend/opengl/glutin_compat.rs52
-rw-r--r--engine/src/rendering/backend/opengl/graphics_mesh.rs9
-rw-r--r--engine/src/rendering/main_render_pass.rs67
-rw-r--r--engine/src/rendering/object.rs7
-rw-r--r--engine/src/rendering/shader.rs78
-rw-r--r--engine/src/rendering/shader/cursor.rs26
8 files changed, 186 insertions, 162 deletions
diff --git a/engine/src/rendering/backend.rs b/engine/src/rendering/backend.rs
index d69b338..495f223 100644
--- a/engine/src/rendering/backend.rs
+++ b/engine/src/rendering/backend.rs
@@ -3,6 +3,7 @@ use ecs::extension::Extension;
pub mod opengl;
/// Returns the default rendering backend.
+#[must_use]
pub fn get_default() -> impl Extension
{
self::opengl::Extension::default()
diff --git a/engine/src/rendering/backend/opengl.rs b/engine/src/rendering/backend/opengl.rs
index 8b887b3..0a04d6e 100644
--- a/engine/src/rendering/backend/opengl.rs
+++ b/engine/src/rendering/backend/opengl.rs
@@ -419,7 +419,7 @@ impl BackendShaderBinding
);
}
BackendShaderBinding::Texture(texture) => {
- texture.bind_to_texture_unit(gl_context, binding_index.0)
+ texture.bind_to_texture_unit(gl_context, binding_index.0);
}
}
}
@@ -542,10 +542,9 @@ fn prepare_windows(
let window_handle = match window
.as_ref()
- .map(|window| unsafe {
+ .and_then(|window| unsafe {
windowing_context.get_window_as_handle(&window.wid())
})
- .flatten()
.transpose()
{
Ok(window_handle) => window_handle,
@@ -555,7 +554,7 @@ fn prepare_windows(
}
};
- let (new_window_creation_attrs, gl_config) = match DisplayBuilder::new()
+ let (new_window_creation_attrs, gl_config) = match DisplayBuilder::default()
.with_window_attributes(window_creation_attrs.clone())
.build(
window_handle,
@@ -638,7 +637,7 @@ fn init_window_graphics(
};
let Ok(window_inner_size) =
- PhysicalSize::<NonZero<u32>>::try_convert_from(window.inner_size.clone())
+ PhysicalSize::<NonZero<u32>>::try_convert_from(window.inner_size)
else {
tracing::error!(
"Cannot create a surface for a window with a width/height of 0",
@@ -669,7 +668,7 @@ fn init_window_graphics(
let gl_context = match graphics_ctx.gl_context.get_or_try_insert_with_fn(|| {
create_gl_context(
&window_gl_config.gl_config,
- &graphics_props,
+ graphics_props,
window_handle,
&window_surface,
)
@@ -684,10 +683,10 @@ fn init_window_graphics(
if let Err(err) = gl_context.make_current(&window_surface) {
tracing::error!("Failed to make GL context current: {err}");
continue;
- };
+ }
if let Err(err) = gl_set_viewport(
- &gl_context,
+ gl_context,
&Vec2 { x: 0, y: 0 }.into(),
&opengl_bindings::data_types::Dimens {
width: window.inner_size.width,
@@ -697,26 +696,22 @@ fn init_window_graphics(
tracing::error!("Failed to set viewport: {err}");
}
- set_enabled(
- &gl_context,
- Capability::DepthTest,
- graphics_props.depth_test,
- );
+ set_enabled(gl_context, Capability::DepthTest, graphics_props.depth_test);
set_enabled(
- &gl_context,
+ gl_context,
Capability::MultiSample,
graphics_props.multisampling_sample_cnt.is_some(),
);
if graphics_props.debug {
- enable(&gl_context, Capability::DebugOutput);
- enable(&gl_context, Capability::DebugOutputSynchronous);
+ enable(gl_context, Capability::DebugOutput);
+ enable(gl_context, Capability::DebugOutputSynchronous);
- set_debug_message_callback(&gl_context, opengl_debug_message_cb);
+ set_debug_message_callback(gl_context, opengl_debug_message_cb);
match set_debug_message_control(
- &gl_context,
+ gl_context,
None,
None,
None,
@@ -739,7 +734,7 @@ fn init_window_graphics(
window_ent_id,
(Surface {
id: surface_id,
- size: window.inner_size.clone(),
+ size: window.inner_size,
},),
);
@@ -747,7 +742,7 @@ fn init_window_graphics(
surface_id,
GraphicsContextSurface {
window_surface,
- size: window.inner_size.clone(),
+ size: window.inner_size,
},
);
}
@@ -927,7 +922,7 @@ fn handle_commands(
program.activate(gl_context);
- for (binding_index, binding) in bindings.iter() {
+ for (binding_index, binding) in bindings {
binding.bind(gl_context, binding_index);
}
@@ -945,7 +940,7 @@ fn handle_commands(
backend_resources,
object_store,
gl_context,
- shader_object_id.clone(),
+ shader_object_id,
&binding_location,
binding_value,
);
@@ -1097,7 +1092,7 @@ fn handle_commands(
Command::CreateMesh { obj_id, mesh, usage: mesh_usage } => {
let mesh = match &mesh {
AssetOrValue::Asset(mesh_asset) => {
- let Some(mesh) = assets.get(&mesh_asset) else {
+ let Some(mesh) = assets.get(mesh_asset) else {
tracing::error!(
asset_id=?mesh_asset.id(),
"Mesh asset does not exist"
@@ -1116,7 +1111,7 @@ fn handle_commands(
obj_id,
|| {
Ok(BackendResource::Mesh {
- mesh: GraphicsMesh::new(gl_context, &mesh, mesh_usage)?,
+ mesh: GraphicsMesh::new(gl_context, mesh, mesh_usage)?,
vertex_attrs_updated_for_shader: None,
})
},
@@ -1201,7 +1196,7 @@ fn handle_commands(
if let Err(err) = draw_mesh(gl_context, graphics_mesh, &draw_mesh_opts) {
tracing::error!("Failed to draw mesh: {err}");
- };
+ }
}
Command::UpdateDrawProperties(properties, update_flags) => {
update_draw_properties(
@@ -1237,7 +1232,7 @@ fn create_gl_context(
}
.map_err(CreateGlContextError::CreateGlutinContext)?;
- MaybeCurrentContextWithFns::new(glutin_context, &surface)
+ MaybeCurrentContextWithFns::new(glutin_context, surface)
.map_err(CreateGlContextError::MakeContextCurrent)
}
@@ -1519,8 +1514,8 @@ fn update_framebuffer_properties(
}
}
-fn set_shader_binding<'backend_resources>(
- backend_resources: &'backend_resources mut BackendResourceStore,
+fn set_shader_binding(
+ backend_resources: &mut BackendResourceStore,
object_store: &ObjectStore,
gl_context: &MaybeCurrentContextWithFns,
shader_object_id: ObjectId,
@@ -1549,14 +1544,11 @@ fn set_shader_binding<'backend_resources>(
None => return None,
};
- if let Some(prev_binding) =
+ // TODO: Textures should probably also be handled somehow here
+ if let Some(BackendShaderBinding::Uniform(prev_binding_uniform_buf)) =
shader_bindings.remove(ShaderBindingIndex(binding_location.binding_index))
{
- // TODO: Textures should probably also be handled somehow here
- if let BackendShaderBinding::Uniform(prev_binding_uniform_buf) = prev_binding
- {
- prev_binding_uniform_buf.delete(gl_context);
- }
+ prev_binding_uniform_buf.delete(gl_context);
}
return Some(
@@ -1588,27 +1580,27 @@ fn set_shader_binding<'backend_resources>(
None => return None,
};
- let binding = match shader_bindings
- .get(ShaderBindingIndex(binding_location.binding_index))
- .cloned()
+ let binding = if let Some(binding @ BackendShaderBinding::Uniform(_)) =
+ shader_bindings
+ .get(ShaderBindingIndex(binding_location.binding_index))
+ .cloned()
{
- Some(binding @ BackendShaderBinding::Uniform(_)) => binding,
- Some(_) | None => {
- let uniform_buf = GlBuffer::<u8>::new(gl_context);
+ binding
+ } else {
+ let uniform_buf = GlBuffer::<u8>::new(gl_context);
- uniform_buf
- .init(
- gl_context,
- binding_location.binding_size,
- opengl_bindings::buffer::Usage::Dynamic,
- )
- .unwrap();
+ uniform_buf
+ .init(
+ gl_context,
+ binding_location.binding_size,
+ opengl_bindings::buffer::Usage::Dynamic,
+ )
+ .unwrap();
- shader_bindings
- .entry(ShaderBindingIndex(binding_location.binding_index))
- .set_or_insert_with(|| BackendShaderBinding::Uniform(uniform_buf))
- .clone()
- }
+ shader_bindings
+ .entry(ShaderBindingIndex(binding_location.binding_index))
+ .set_or_insert_with(|| BackendShaderBinding::Uniform(uniform_buf))
+ .clone()
};
let BackendShaderBinding::Uniform(binding_uniform_buf) = &binding else {
@@ -1828,8 +1820,7 @@ fn create_shader_program(
stage: ShaderStage::Vertex,
entrypoint: vs_entry_point_reflection
.name()
- .map(|name| name.to_string().into())
- .unwrap_or("(none)".into()),
+ .map_or("(none)".into(), |name| name.to_string().into()),
})?;
let (fs_entry_point_index, fs_entry_point_reflection) = shader_program_reflection
@@ -1849,15 +1840,14 @@ fn create_shader_program(
stage: ShaderStage::Fragment,
entrypoint: fs_entry_point_reflection
.name()
- .map(|name| name.to_string().into())
- .unwrap_or("(none)".into()),
+ .map_or("(none)".into(), |name| name.to_string().into()),
})?;
let vertex_shader = GlShader::new(current_context, ShaderKind::Vertex);
vertex_shader.set_source(
current_context,
- &vertex_shader_entry_point_code.as_str().unwrap(),
+ vertex_shader_entry_point_code.as_str().unwrap(),
)?;
vertex_shader.compile(current_context)?;
@@ -1866,7 +1856,7 @@ fn create_shader_program(
fragment_shader.set_source(
current_context,
- &fragment_shader_entry_point_code.as_str().unwrap(),
+ fragment_shader_entry_point_code.as_str().unwrap(),
)?;
fragment_shader.compile(current_context)?;
@@ -1938,7 +1928,7 @@ fn opengl_debug_message_cb(
_ => {
emit_log_with_message!(tracing::Level::WARN);
}
- };
+ }
}
#[inline]
diff --git a/engine/src/rendering/backend/opengl/glutin_compat.rs b/engine/src/rendering/backend/opengl/glutin_compat.rs
index 27f82ad..0bdfcd2 100644
--- a/engine/src/rendering/backend/opengl/glutin_compat.rs
+++ b/engine/src/rendering/backend/opengl/glutin_compat.rs
@@ -66,12 +66,6 @@ pub struct DisplayBuilder
impl DisplayBuilder
{
- /// Create new display builder.
- pub fn new() -> Self
- {
- Default::default()
- }
-
/// The preference in picking the configuration.
#[allow(dead_code)]
pub fn with_preference(mut self, preference: ApiPreference) -> Self
@@ -153,7 +147,7 @@ impl DisplayBuilder
config_picker_fn(gl_configs).ok_or(Error::NoConfigPicked)?;
let window_attrs = cfg_select! {
- windows => { self.window_attributes }
+ windows => self.window_attributes,
_ => {
finalize_window_creation_attrs(self.window_attributes, &picked_gl_config)
}
@@ -179,39 +173,36 @@ pub enum Error
WindowRequired,
}
+#[allow(unused_variables)]
fn create_display(
display_handle: &DisplayHandle<'_>,
- _api_preference: ApiPreference,
- _raw_window_handle: Option<RawWindowHandle>,
+ api_preference: ApiPreference,
+ raw_window_handle: Option<RawWindowHandle>,
) -> Result<Display, GlutinError>
{
let preference = cfg_select! {
- windows => {
- match _api_preference {
- ApiPreference::PreferEgl => {
- DisplayApiPreference::EglThenWgl(_raw_window_handle)
- }
- ApiPreference::FallbackEgl => {
- DisplayApiPreference::WglThenEgl(_raw_window_handle)
- }
+ windows => match _api_preference {
+ ApiPreference::PreferEgl => {
+ DisplayApiPreference::EglThenWgl(_raw_window_handle)
}
- }
- target_os = "linux" => {
- match _api_preference {
- ApiPreference::PreferEgl => DisplayApiPreference::EglThenGlx(Box::new(
- crate::windowing::window::platform::x11::register_xlib_error_hook,
- )),
- ApiPreference::FallbackEgl => DisplayApiPreference::GlxThenEgl(Box::new(
- crate::windowing::window::platform::x11::register_xlib_error_hook,
- )),
+ ApiPreference::FallbackEgl => {
+ DisplayApiPreference::WglThenEgl(_raw_window_handle)
}
- }
- target_os = "macos" => { DisplayApiPreference::Cgl }
+ },
+ target_os = "linux" => match api_preference {
+ ApiPreference::PreferEgl => DisplayApiPreference::EglThenGlx(Box::new(
+ crate::windowing::window::platform::x11::register_xlib_error_hook,
+ )),
+ ApiPreference::FallbackEgl => DisplayApiPreference::GlxThenEgl(Box::new(
+ crate::windowing::window::platform::x11::register_xlib_error_hook,
+ )),
+ },
+ target_os = "macos" => DisplayApiPreference::Cgl,
};
let handle = display_handle.as_raw();
- unsafe { Ok(Display::new(handle, preference)?) }
+ unsafe { Display::new(handle, preference) }
}
/// Finalize [`Window`] creation by applying the options from the [`Config`], be
@@ -235,7 +226,8 @@ fn finalize_window_creation_attrs(
if let Some(x11_visual) = glutin::platform::x11::X11GlConfigExt::x11_visual(gl_config)
{
return attributes.with_x_visual_id(Some(
- x11_visual.visual_id() as crate::windowing::window::XVisualID
+ crate::windowing::window::XVisualID::try_from(x11_visual.visual_id())
+ .expect("X visual ID is too large"),
));
}
diff --git a/engine/src/rendering/backend/opengl/graphics_mesh.rs b/engine/src/rendering/backend/opengl/graphics_mesh.rs
index 43cd254..899f50f 100644
--- a/engine/src/rendering/backend/opengl/graphics_mesh.rs
+++ b/engine/src/rendering/backend/opengl/graphics_mesh.rs
@@ -69,8 +69,7 @@ impl GraphicsMesh
max_value,
} => {
panic!(
- "Size of vertex ({}) is too large. Must be less than {max_value}",
- value
+ "Size of vertex ({value}) is too large. Must be less than {max_value}"
);
}
}
@@ -86,7 +85,7 @@ impl GraphicsMesh
vertex_arr.bind_element_buffer(current_context, &index_buffer);
return Ok(Self {
- vertex_buffer: vertex_buffer,
+ vertex_buffer,
vertex_attr_props: mesh.vertex_buf().vertex_attr_props().to_vec(),
last_max_vertex_attr_index: 0,
index_buffer: Some(index_buffer),
@@ -99,7 +98,7 @@ impl GraphicsMesh
}
Ok(Self {
- vertex_buffer: vertex_buffer,
+ vertex_buffer,
vertex_attr_props: mesh.vertex_buf().vertex_attr_props().to_vec(),
last_max_vertex_attr_index: 0,
index_buffer: None,
@@ -135,7 +134,7 @@ impl GraphicsMesh
.map_err(Error::StoreIndicesFailed)?;
self.vertex_arr
- .bind_element_buffer(current_context, &index_buffer);
+ .bind_element_buffer(current_context, index_buffer);
self.element_cnt = indices
.len()
diff --git a/engine/src/rendering/main_render_pass.rs b/engine/src/rendering/main_render_pass.rs
index c762231..cb38071 100644
--- a/engine/src/rendering/main_render_pass.rs
+++ b/engine/src/rendering/main_render_pass.rs
@@ -237,9 +237,9 @@ pub fn add_main_render_pass(
continue;
}
- let model_material = match model_spec.find_first_material(&assets) {
+ let model_material = match model_spec.find_first_material(assets) {
MaterialSearchResult::Found(model_material_asset)
- if let Some(model_material) = assets.get(&model_material_asset) =>
+ if let Some(model_material) = assets.get(model_material_asset) =>
{
model_material
}
@@ -251,7 +251,7 @@ pub fn add_main_render_pass(
if model_material
.textures()
- .any(|texture_asset| !assets.is_loaded_and_has_type(&texture_asset))
+ .any(|texture_asset| !assets.is_loaded_and_has_type(texture_asset))
{
continue;
}
@@ -273,13 +273,7 @@ pub fn add_main_render_pass(
.commands
.push(Command::ActivateShader(shaders.main_3d_shader_obj_id));
- if let Some(draw_flags) = draw_flags.as_deref().and_then(|draw_flags| {
- if draw_flags.polygon_mode_config != PolygonModeConfig::default() {
- Some(draw_flags)
- } else {
- None
- }
- }) {
+ if let Some(draw_flags) = draw_flags.as_deref().filter(|&draw_flags| draw_flags.polygon_mode_config != PolygonModeConfig::default()) {
render_pass.commands.push(Command::UpdateDrawProperties(
DrawProperties {
polygon_mode_config: draw_flags.polygon_mode_config.clone(),
@@ -310,7 +304,7 @@ pub fn add_main_render_pass(
if let Some(scene_skybox) = &scene_skybox {
let Some(sky_box_ids) = load_sky_box(
scene_ent_id,
- &scene_skybox,
+ scene_skybox,
scene_skybox_state.as_deref(),
assets,
object_store,
@@ -489,9 +483,9 @@ fn add_renderable_creation_commands(
debug_assert!(model_spec.materials.len() <= 1);
- let model_material = match model_spec.find_first_material(&assets) {
+ let model_material = match model_spec.find_first_material(assets) {
MaterialSearchResult::Found(model_material_asset) => {
- let Some(model_material) = assets.get(&model_material_asset) else {
+ let Some(model_material) = assets.get(model_material_asset) else {
return;
};
@@ -726,7 +720,7 @@ fn add_set_3d_shader_renderable_bindings(
{
let (material, material_flags, transform) = renderable;
- let transform = match transform.as_deref() {
+ let transform = match transform {
Some(transform) => transform,
None => &Transform::default(),
};
@@ -735,11 +729,10 @@ fn add_set_3d_shader_renderable_bindings(
let inverted_model_matrix = model_matrix.inverse();
let material_flags = material_flags
- .as_deref()
.unwrap_or(&const { MaterialFlags::builder().build() });
let env_lighting = match &scene_env_lighting {
- Some(env_lighting) => &env_lighting,
+ Some(env_lighting) => env_lighting,
None => &EnvironmentalLighting::default(),
};
@@ -754,8 +747,7 @@ fn add_set_3d_shader_renderable_bindings(
let diffuse_map_obj_id = material
.diffuse_map
.as_ref()
- .map(|diffuse_map| ObjectId::Asset(diffuse_map.id()))
- .unwrap_or(white_1x1_tex_obj_id);
+ .map_or(white_1x1_tex_obj_id, |diffuse_map| ObjectId::Asset(diffuse_map.id()));
render_pass.commands.extend(
[
@@ -766,10 +758,8 @@ fn add_set_3d_shader_renderable_bindings(
.field("model_inverted")
.binding(inverted_model_matrix.into())?,
material_shader_cursor.field("ambient").binding(
- material_flags
- .use_ambient_color
- .then_some(&material.ambient)
- .unwrap_or(&env_lighting.ambient_color)
+ if material_flags
+ .use_ambient_color { &material.ambient } else { &env_lighting.ambient_color }
.to_rgb_lossy()
.into(),
)?,
@@ -784,8 +774,7 @@ fn add_set_3d_shader_renderable_bindings(
material
.ambient_map
.as_ref()
- .map(|ambient_map| ObjectId::Asset(ambient_map.id()))
- .unwrap_or(diffuse_map_obj_id),
+ .map_or(diffuse_map_obj_id, |ambient_map| ObjectId::Asset(ambient_map.id())),
ShaderBindingTextureKind::Texture2D,
),
)?,
@@ -800,8 +789,7 @@ fn add_set_3d_shader_renderable_bindings(
material
.specular_map
.as_ref()
- .map(|specular_map| ObjectId::Asset(specular_map.id()))
- .unwrap_or(white_1x1_tex_obj_id),
+ .map_or(white_1x1_tex_obj_id, |specular_map| ObjectId::Asset(specular_map.id())),
ShaderBindingTextureKind::Texture2D,
),
)?,
@@ -907,24 +895,21 @@ fn load_sky_box(
actions: &mut Actions,
) -> Result<Option<SkyBoxIds>, crate::Error>
{
- let mesh_object_id = match &sky_box_state {
- Some(sky_box_state) => sky_box_state.mesh_object_id,
- None => {
- let sky_box_mesh =
- Mesh::cube(Dimens3 { width: 1.0, height: 1.0, depth: 1.0 });
+ let mesh_object_id = if let Some(sky_box_state) = &sky_box_state { sky_box_state.mesh_object_id } else {
+ let sky_box_mesh =
+ Mesh::cube(Dimens3 { width: 1.0, height: 1.0, depth: 1.0 });
- let mesh_object_id = ObjectId::new_sequential();
+ let mesh_object_id = ObjectId::new_sequential();
- object_store.insert_pending(mesh_object_id);
+ object_store.insert_pending(mesh_object_id);
- render_pass.commands.push(Command::CreateMesh {
- obj_id: mesh_object_id,
- mesh: AssetOrValue::Value(sky_box_mesh),
- usage: MeshUsage::Static,
- });
+ render_pass.commands.push(Command::CreateMesh {
+ obj_id: mesh_object_id,
+ mesh: AssetOrValue::Value(sky_box_mesh),
+ usage: MeshUsage::Static,
+ });
- mesh_object_id
- }
+ mesh_object_id
};
let texture_object_id = match &sky_box {
@@ -952,7 +937,7 @@ fn load_sky_box(
})
.collect::<Vec<_>>()
.as_array::<6>()
- .cloned()
+ .copied()
else {
return Ok(None);
};
diff --git a/engine/src/rendering/object.rs b/engine/src/rendering/object.rs
index 61e7ed5..d496eda 100644
--- a/engine/src/rendering/object.rs
+++ b/engine/src/rendering/object.rs
@@ -26,6 +26,7 @@ impl Id
))
}
+ #[must_use]
pub fn into_asset_id(self) -> Option<AssetId>
{
match self {
@@ -55,16 +56,19 @@ pub struct Store
impl Store
{
+ #[must_use]
pub fn get_obj(&self, id: &Id) -> Option<&Object>
{
self.objects.get(id).and_then(|obj| obj.as_ref())
}
+ #[must_use]
pub fn contains_maybe_pending_with_id(&self, id: &Id) -> bool
{
self.objects.contains_key(id)
}
+ #[must_use]
pub fn contains_non_pending_with_id(&self, id: &Id) -> bool
{
self.objects.get(id).and_then(|obj| obj.as_ref()).is_some()
@@ -96,16 +100,19 @@ pub struct Object
impl Object
{
+ #[must_use]
pub fn from_raw(raw: RawValue, kind: Kind) -> Self
{
Self { raw, kind }
}
+ #[must_use]
pub fn as_raw(&self) -> RawValue
{
self.raw
}
+ #[must_use]
pub fn kind(&self) -> Kind
{
self.kind
diff --git a/engine/src/rendering/shader.rs b/engine/src/rendering/shader.rs
index 3f07381..085773b 100644
--- a/engine/src/rendering/shader.rs
+++ b/engine/src/rendering/shader.rs
@@ -70,6 +70,7 @@ pub struct Module
impl Module
{
+ #[must_use]
pub fn entry_points(&self) -> impl ExactSizeIterator<Item = EntryPoint> + use<'_>
{
self.inner
@@ -77,6 +78,7 @@ impl Module
.map(|entry_point| EntryPoint { inner: entry_point })
}
+ #[must_use]
pub fn get_entry_point(&self, entry_point: &str) -> Option<EntryPoint>
{
let entry_point = self.inner.find_entry_point_by_name(entry_point)?;
@@ -84,6 +86,7 @@ impl Module
Some(EntryPoint { inner: entry_point })
}
+ #[must_use]
pub fn file_path(&self) -> &str
{
self.inner.file_path()
@@ -97,6 +100,7 @@ pub struct EntryPoint
impl EntryPoint
{
+ #[must_use]
pub fn function(&self) -> FunctionReflection<'_>
{
FunctionReflection {
@@ -110,8 +114,9 @@ pub struct FunctionReflection<'a>
inner: &'a shader_slang::reflection::Function,
}
-impl<'a> FunctionReflection<'a>
+impl FunctionReflection<'_>
{
+ #[must_use]
pub fn name(&self) -> Option<&str>
{
self.inner.name()
@@ -125,21 +130,25 @@ pub struct EntryPointReflection<'a>
impl<'a> EntryPointReflection<'a>
{
+ #[must_use]
pub fn name(&self) -> Option<&str>
{
self.inner.name()
}
+ #[must_use]
pub fn name_override(&self) -> Option<&str>
{
self.inner.name_override()
}
+ #[must_use]
pub fn stage(&self) -> Stage
{
Stage::from_slang_stage(self.inner.stage())
}
+ #[must_use]
pub fn parameters(&self) -> impl ExactSizeIterator<Item = VariableLayout<'a>>
{
self.inner
@@ -147,6 +156,7 @@ impl<'a> EntryPointReflection<'a>
.map(|param| VariableLayout { inner: param })
}
+ #[must_use]
pub fn var_layout(&self) -> Option<VariableLayout<'a>>
{
Some(VariableLayout { inner: self.inner.var_layout()? })
@@ -172,6 +182,7 @@ impl Program
})
}
+ #[must_use]
pub fn metadata(&self) -> &ProgramMetadata
{
&self.metadata
@@ -186,7 +197,7 @@ impl Program
pub fn reflection(&self, target: u32) -> Result<ProgramReflection<'_>, Error>
{
- let reflection = self.inner.layout(target as i64)?;
+ let reflection = self.inner.layout(i64::from(target))?;
Ok(ProgramReflection { inner: reflection })
}
@@ -209,6 +220,7 @@ pub struct ProgramReflection<'a>
impl<'a> ProgramReflection<'a>
{
+ #[must_use]
pub fn get_entry_point_by_index(&self, index: u32)
-> Option<EntryPointReflection<'a>>
{
@@ -217,6 +229,7 @@ impl<'a> ProgramReflection<'a>
})
}
+ #[must_use]
pub fn get_entry_point_by_name(&self, name: &str)
-> Option<EntryPointReflection<'a>>
{
@@ -225,6 +238,7 @@ impl<'a> ProgramReflection<'a>
})
}
+ #[must_use]
pub fn entry_points(
&self,
) -> impl ExactSizeIterator<Item = EntryPointReflection<'a>> + use<'a>
@@ -234,6 +248,7 @@ impl<'a> ProgramReflection<'a>
.map(|entry_point| EntryPointReflection { inner: entry_point })
}
+ #[must_use]
pub fn global_params_type_layout(&self) -> Option<TypeLayout<'a>>
{
Some(TypeLayout {
@@ -241,6 +256,7 @@ impl<'a> ProgramReflection<'a>
})
}
+ #[must_use]
pub fn global_params_var_layout(&self) -> Option<VariableLayout<'a>>
{
Some(VariableLayout {
@@ -248,6 +264,7 @@ impl<'a> ProgramReflection<'a>
})
}
+ #[must_use]
pub fn get_type(&self, name: &str) -> Option<TypeReflection<'a>>
{
Some(TypeReflection {
@@ -255,12 +272,13 @@ impl<'a> ProgramReflection<'a>
})
}
+ #[must_use]
pub fn get_type_layout(&self, ty: &TypeReflection<'a>) -> Option<TypeLayout<'a>>
{
Some(TypeLayout {
inner: self
.inner
- .type_layout(&ty.inner, shader_slang::LayoutRules::Default)?,
+ .type_layout(ty.inner, shader_slang::LayoutRules::Default)?,
})
}
}
@@ -273,16 +291,19 @@ pub struct VariableLayout<'a>
impl<'a> VariableLayout<'a>
{
+ #[must_use]
pub fn name(&self) -> Option<&'a str>
{
self.inner.name()
}
+ #[must_use]
pub fn semantic_name(&self) -> Option<&str>
{
self.inner.semantic_name()
}
+ #[must_use]
pub fn binding_index(&self) -> u32
{
self.inner
@@ -291,6 +312,7 @@ impl<'a> VariableLayout<'a>
// self.inner.binding_index()
}
+ #[must_use]
pub fn varying_input_offset(&self) -> Option<usize>
{
if !self
@@ -304,26 +326,31 @@ impl<'a> VariableLayout<'a>
Some(self.inner.offset(SlangParameterCategory::VaryingInput))
}
+ #[must_use]
pub fn binding_space(&self) -> u32
{
self.inner.binding_space()
}
+ #[must_use]
pub fn semantic_index(&self) -> usize
{
self.inner.semantic_index()
}
+ #[must_use]
pub fn offset(&self) -> usize
{
self.inner.offset(shader_slang::ParameterCategory::Uniform)
}
+ #[must_use]
pub fn ty(&self) -> Option<TypeReflection<'a>>
{
self.inner.ty().map(|ty| TypeReflection { inner: ty })
}
+ #[must_use]
pub fn type_layout(&self) -> Option<TypeLayout<'a>>
{
Some(TypeLayout { inner: self.inner.type_layout()? })
@@ -338,11 +365,13 @@ pub struct TypeLayout<'a>
impl<'a> TypeLayout<'a>
{
+ #[must_use]
pub fn kind(&self) -> TypeKind
{
TypeKind::from_slang_type_kind(self.inner.kind())
}
+ #[must_use]
pub fn scalar_type(&self) -> Option<ScalarType>
{
Some(ScalarType::from_slang_scalar_type(
@@ -350,6 +379,7 @@ impl<'a> TypeLayout<'a>
))
}
+ #[must_use]
pub fn resource_shape(&self) -> Option<ResourceShape>
{
Some(ResourceShape::from_bits_retain(
@@ -357,6 +387,7 @@ impl<'a> TypeLayout<'a>
))
}
+ #[must_use]
pub fn get_field_by_name(&self, name: &str) -> Option<VariableLayout<'a>>
{
let index = self.inner.find_field_index_by_name(name);
@@ -372,16 +403,19 @@ impl<'a> TypeLayout<'a>
Some(VariableLayout { inner: field })
}
+ #[must_use]
pub fn parameter_category(&self) -> ParameterCategory
{
ParameterCategory::from_slang_parameter_category(self.inner.parameter_category())
}
+ #[must_use]
pub fn binding_range_descriptor_set_index(&self, index: i64) -> i64
{
self.inner.binding_range_descriptor_set_index(index)
}
+ #[must_use]
pub fn get_field_binding_range_offset_by_name(&self, name: &str) -> Option<u64>
{
let field_index = self.inner.find_field_index_by_name(name);
@@ -400,40 +434,47 @@ impl<'a> TypeLayout<'a>
Some(field_binding_range_offset.cast_unsigned())
}
+ #[must_use]
pub fn ty(&self) -> Option<TypeReflection<'a>>
{
self.inner.ty().map(|ty| TypeReflection { inner: ty })
}
+ #[must_use]
pub fn fields(&self) -> FieldIter<'a>
{
FieldIter {
- type_layout: self.clone(),
+ type_layout: *self,
cnt: self.field_cnt(),
index: 0,
}
}
+ #[must_use]
pub fn field_cnt(&self) -> u32
{
self.inner.field_count()
}
+ #[must_use]
pub fn element_cnt(&self) -> Option<usize>
{
self.inner.element_count()
}
+ #[must_use]
pub fn row_cnt(&self) -> Option<u32>
{
self.inner.row_count()
}
+ #[must_use]
pub fn column_cnt(&self) -> Option<u32>
{
self.inner.column_count()
}
+ #[must_use]
pub fn element_type_layout(&self) -> Option<TypeLayout<'a>>
{
self.inner
@@ -441,6 +482,7 @@ impl<'a> TypeLayout<'a>
.map(|type_layout| TypeLayout { inner: type_layout })
}
+ #[must_use]
pub fn element_var_layout(&self) -> Option<VariableLayout<'a>>
{
self.inner
@@ -448,6 +490,7 @@ impl<'a> TypeLayout<'a>
.map(|var_layout| VariableLayout { inner: var_layout })
}
+ #[must_use]
pub fn container_var_layout(&self) -> Option<VariableLayout<'a>>
{
self.inner
@@ -455,6 +498,7 @@ impl<'a> TypeLayout<'a>
.map(|var_layout| VariableLayout { inner: var_layout })
}
+ #[must_use]
pub fn uniform_size(&self) -> Option<usize>
{
// tracing::debug!(
@@ -483,6 +527,7 @@ impl<'a> TypeLayout<'a>
Some(self.inner.size(SlangParameterCategory::Uniform))
}
+ #[must_use]
pub fn stride(&self) -> usize
{
self.inner.stride(self.inner.categories().next().unwrap())
@@ -556,6 +601,7 @@ pub struct TypeReflection<'a>
impl TypeReflection<'_>
{
+ #[must_use]
pub fn kind(&self) -> TypeKind
{
TypeKind::from_slang_type_kind(self.inner.kind())
@@ -787,6 +833,7 @@ pub struct Blob
impl Blob
{
+ #[must_use]
pub fn as_bytes(&self) -> &[u8]
{
self.inner.as_slice()
@@ -868,11 +915,13 @@ pub struct Context
impl Context
{
+ #[must_use]
pub fn get_module(&self, asset_id: &AssetId) -> Option<&Module>
{
self.modules.get(asset_id)
}
+ #[must_use]
pub fn get_program(&self, asset_id: &AssetId) -> Option<&Program>
{
self.programs.get(asset_id)
@@ -1008,19 +1057,13 @@ impl VertexDescription
);
}
- let scalar_type = match (
+ let (TypeKind::Scalar | TypeKind::Vector, Some(scalar_type)) = (
var_input.type_layout.kind(),
var_input.type_layout.scalar_type(),
- ) {
- (TypeKind::Scalar, Some(scalar_type)) => scalar_type,
- (TypeKind::Vector, Some(scalar_type)) => scalar_type,
- _ => {
- return Err(
- VertexDescriptionError::UnsupportedVertexInputType {
- name: name.to_owned(),
- },
- );
- }
+ ) else {
+ return Err(VertexDescriptionError::UnsupportedVertexInputType {
+ name: name.to_owned(),
+ });
};
seen_inputs.insert(semantic_name.clone());
@@ -1072,6 +1115,7 @@ impl VertexInputSemName
}
}
+ #[must_use]
pub fn matches_vertex_label(&self, vertex_label: &VertexLabel) -> bool
{
match (self, vertex_label) {
@@ -1291,7 +1335,7 @@ pub(super) fn prepare(collector: &mut crate::ecs::extension::Collector<'_>)
let session_desc = shader_slang::SessionDesc::default()
.targets(&targets)
- .search_paths(&[""])
+ .search_paths([""])
.options(&session_options);
let Some(session) = global_session.create_session(&session_desc) else {
@@ -1359,7 +1403,7 @@ fn load_modules(
context.modules.insert(*asset_id, module.clone());
if !module_source.link_entrypoints.is_empty() {
- assert!(context.programs.get(asset_id).is_none());
+ assert!(!context.programs.contains_key(asset_id));
let shader_program = match context
.compose_into_program(module, module_source.link_entrypoints)
diff --git a/engine/src/rendering/shader/cursor.rs b/engine/src/rendering/shader/cursor.rs
index 49f6b47..551830d 100644
--- a/engine/src/rendering/shader/cursor.rs
+++ b/engine/src/rendering/shader/cursor.rs
@@ -2,7 +2,7 @@ use std::borrow::Cow;
use std::fmt::Display;
use std::hint::cold_path;
-use circular_buffer::FixedCircularBuffer;
+use circular_buffer::HeapCircularBuffer;
use crate::color::{Color, Rgb, Rgba};
use crate::data_types::matrix::Matrix;
@@ -27,6 +27,7 @@ pub struct Cursor<'a>
impl<'a> Cursor<'a>
{
+ #[must_use]
pub fn new(var_layout: VariableLayout<'a>) -> Self
{
let binding_location = BindingLocation {
@@ -38,10 +39,11 @@ impl<'a> Cursor<'a>
Self {
type_layout: var_layout.type_layout().unwrap(),
binding_location,
- location_path: LocationPath::default(),
+ location_path: LocationPath::new(),
}
}
+ #[must_use]
pub fn field(&self, name: impl Into<Cow<'static, str>>) -> Self
{
let name = name.into();
@@ -100,6 +102,7 @@ impl<'a> Cursor<'a>
}
}
+ #[must_use]
pub fn element(mut self, index: usize) -> Self
{
let element_type_layout = self.type_layout.element_type_layout().unwrap();
@@ -125,15 +128,23 @@ impl<'a> Cursor<'a>
}
/// Shader cursor location.
-#[derive(Debug, Clone, Default)]
+#[derive(Debug, Clone)]
pub struct LocationPath
{
- locations: FixedCircularBuffer<Location, 16>,
+ locations: HeapCircularBuffer<Location>,
is_truncated: bool,
}
impl LocationPath
{
+ fn new() -> Self
+ {
+ Self {
+ locations: HeapCircularBuffer::with_capacity(16),
+ is_truncated: false,
+ }
+ }
+
fn push(&mut self, location: Location)
{
if self.locations.push_back(location).is_some() {
@@ -231,12 +242,7 @@ impl BindingValue
Self::Float(_) => {
ty_kind == TypeKind::Scalar && scalar_ty == Some(ScalarType::Float32)
}
- Self::FVec3(_) => {
- ty_kind == TypeKind::Vector
- && element_scalar_ty == Some(ScalarType::Float32)
- && element_cnt == Some(3)
- }
- Self::Color(Color::Rgb(_)) => {
+ Self::FVec3(_) | Self::Color(Color::Rgb(_)) => {
ty_kind == TypeKind::Vector
&& element_scalar_ty == Some(ScalarType::Float32)
&& element_cnt == Some(3)