diff options
| author | HampusM <hampus@hampusmat.com> | 2026-11-05 08:39:32 +0100 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-11-05 08:39:32 +0100 |
| commit | c45826d102dc4f47c16c65d9837cc03b59534f23 (patch) | |
| tree | 1a8d298523f473effbf30afd15d9f9a5b217c563 /engine/src/rendering | |
| parent | 6286df99584c2d2c674d27686aab124722a84c3e (diff) | |
refactor(engine): make compile again
Diffstat (limited to 'engine/src/rendering')
| -rw-r--r-- | engine/src/rendering/shader.rs | 23 | ||||
| -rw-r--r-- | engine/src/rendering/shader/cursor.rs | 4 | ||||
| -rw-r--r-- | engine/src/rendering/shader/reflection.rs | 98 |
3 files changed, 81 insertions, 44 deletions
diff --git a/engine/src/rendering/shader.rs b/engine/src/rendering/shader.rs index 3fdc2c1..2a2ac7a 100644 --- a/engine/src/rendering/shader.rs +++ b/engine/src/rendering/shader.rs @@ -13,6 +13,7 @@ use shader_slang::{ EntryPoint as SlangEntryPoint, GlobalSession as SlangGlobalSession, Module as SlangModule, + ObjectRc as SlangObjectRc, Session as SlangSession, }; @@ -73,7 +74,7 @@ bitflags! { #[derive(Clone)] pub struct Module { - inner: SlangModule, + inner: SlangObjectRc<SlangModule>, } impl Module @@ -95,7 +96,7 @@ impl Module } #[must_use] - pub fn file_path(&self) -> &str + pub fn file_path(&self) -> Option<&str> { self.inner.file_path() } @@ -103,7 +104,7 @@ impl Module pub struct EntryPoint { - inner: SlangEntryPoint, + inner: SlangObjectRc<SlangEntryPoint>, } impl EntryPoint @@ -120,7 +121,7 @@ impl EntryPoint #[derive(Clone)] pub struct Program { - inner: SlangComponentType, + inner: SlangObjectRc<SlangComponentType>, metadata: ProgramMetadata, } @@ -202,7 +203,7 @@ impl Debug for Program pub struct Blob { - inner: SlangBlob, + inner: SlangObjectRc<SlangBlob>, } impl Blob @@ -233,8 +234,8 @@ pub struct Settings #[derive(Sole)] pub struct Context { - global_session: SlangGlobalSession, - session: Option<SlangSession>, + global_session: SlangObjectRc<SlangGlobalSession>, + session: Option<SlangObjectRc<SlangSession>>, programs: hashbrown::HashMap<AssetId, Program>, } @@ -300,7 +301,7 @@ impl Context self.programs.get(asset_id) } - #[tracing::instrument(skip_all, fields(module_file = module.file_path()))] + #[tracing::instrument(skip_all)] pub fn compose_into_program( &self, module: Module, @@ -332,8 +333,10 @@ impl Context let components = entry_points .into_iter() - .map(|entry_point| SlangComponentType::from(entry_point.inner)) - .chain([SlangComponentType::from(module.inner)]) + .map(|entry_point| { + SlangObjectRc::<SlangComponentType>::from(entry_point.inner) + }) + .chain([SlangObjectRc::<SlangComponentType>::from(module.inner)]) .collect::<Vec<_>>(); let program = session diff --git a/engine/src/rendering/shader/cursor.rs b/engine/src/rendering/shader/cursor.rs index 7750623..a4a259a 100644 --- a/engine/src/rendering/shader/cursor.rs +++ b/engine/src/rendering/shader/cursor.rs @@ -268,14 +268,14 @@ impl BindingValue Self::Texture(_, BindingTextureKind::Texture2D) => { ty_kind == TypeKind::Resource && ty.resource_shape().is_some_and(|res_shape| { - (res_shape & ResourceShape::BASE) + (res_shape & ResourceShape::BASE_MASK) .contains(ResourceShape::TEXTURE_2D) }) } Self::Texture(_, BindingTextureKind::Cube) => { ty_kind == TypeKind::Resource && ty.resource_shape().is_some_and(|res_shape| { - (res_shape & ResourceShape::BASE) + (res_shape & ResourceShape::BASE_MASK) .contains(ResourceShape::TEXTURE_CUBE) }) } diff --git a/engine/src/rendering/shader/reflection.rs b/engine/src/rendering/shader/reflection.rs index c6d9248..10bff54 100644 --- a/engine/src/rendering/shader/reflection.rs +++ b/engine/src/rendering/shader/reflection.rs @@ -227,7 +227,7 @@ impl<'a> TypeLayout<'a> pub fn resource_shape(&self) -> Option<ResourceShape> { Some(ResourceShape::from_bits_retain( - self.inner.resource_shape()? as u32, + self.inner.resource_shape()?.bits(), )) } @@ -462,7 +462,6 @@ pub enum TypeKind Feedback, Pointer, DynamicResource, - Count, } impl TypeKind @@ -491,7 +490,7 @@ impl TypeKind shader_slang::TypeKind::Feedback => Self::Feedback, shader_slang::TypeKind::Pointer => Self::Pointer, shader_slang::TypeKind::DynamicResource => Self::DynamicResource, - shader_slang::TypeKind::Count => Self::Count, + _ => unimplemented!(), } } } @@ -551,33 +550,70 @@ impl ScalarType } } +// bitflags! { +// #[derive(Debug, Copy, Clone)] +// pub struct ResourceShape: u32 { +// const BASE = shader_slang::ResourceShape::SlangResourceBaseShapeMask as u32; +// const NONE = shader_slang::ResourceShape::SlangResourceNone as u32; +// const TEXTURE_1D = shader_slang::ResourceShape::SlangTexture1d as u32; +// const TEXTURE_2D = shader_slang::ResourceShape::SlangTexture2d as u32; +// const TEXTURE_3D = shader_slang::ResourceShape::SlangTexture3d as u32; +// const TEXTURE_CUBE = shader_slang::ResourceShape::SlangTextureCube as u32; +// const TEXTURE_BUFFER = shader_slang::ResourceShape::SlangTextureBuffer as u32; +// const STRUCTURED_BUFFER = shader_slang::ResourceShape::SlangStructuredBuffer as +// u32; const BYTE_ADDRESS_BUFFER = +// shader_slang::ResourceShape::SlangByteAddressBuffer as u32; const UNKNOWN = +// shader_slang::ResourceShape::SlangResourceUnknown as u32; +// const ACCELERATION_STRUCTURE = +// shader_slang::ResourceShape::SlangAccelerationStructure as u32; +// const TEXTURE_SUBPASS = shader_slang::ResourceShape::SlangTextureSubpass as u32; +// const EXT_SHAPE = shader_slang::ResourceShape::SlangResourceExtShapeMask as u32; +// const TEXTURE_FEEDBACK_FLAG = shader_slang::ResourceShape::SlangTextureFeedbackFlag +// as u32; const TEXTURE_SHADOW_FLAG = +// shader_slang::ResourceShape::SlangTextureShadowFlag as u32; +// const TEXTURE_ARRAY_FLAG = shader_slang::ResourceShape::SlangTextureArrayFlag as +// u32; const TEXTURE_MULTISAMPLE_FLAG = +// shader_slang::ResourceShape::SlangTextureMultisampleFlag as u32; +// const TEXTURE_COMBINED_FLAG = shader_slang::ResourceShape::SlangTextureCombinedFlag +// as u32; const TEXTURE_1D_ARRAY = shader_slang::ResourceShape::SlangTexture1dArray +// as u32; const TEXTURE_2D_ARRAY = shader_slang::ResourceShape::SlangTexture2dArray +// as u32; const TEXTURE_CUBE_ARRAY = +// shader_slang::ResourceShape::SlangTextureCubeArray as u32; +// const TEXTURE_2D_MULTISAMPLE = +// shader_slang::ResourceShape::SlangTexture2dMultisample as u32; +// const TEXTURE_2D_MULTISAMPLE_ARRAY = +// shader_slang::ResourceShape::SlangTexture2dMultisampleArray as u32; +// const TEXTURE_SUBPASS_MULTISAMPLE = +// shader_slang::ResourceShape::SlangTextureSubpassMultisample as u32; } +// } + bitflags! { -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct ResourceShape: u32 { - const BASE = shader_slang::ResourceShape::SlangResourceBaseShapeMask as u32; - const NONE = shader_slang::ResourceShape::SlangResourceNone as u32; - const TEXTURE_1D = shader_slang::ResourceShape::SlangTexture1d as u32; - const TEXTURE_2D = shader_slang::ResourceShape::SlangTexture2d as u32; - const TEXTURE_3D = shader_slang::ResourceShape::SlangTexture3d as u32; - const TEXTURE_CUBE = shader_slang::ResourceShape::SlangTextureCube as u32; - const TEXTURE_BUFFER = shader_slang::ResourceShape::SlangTextureBuffer as u32; - const STRUCTURED_BUFFER = shader_slang::ResourceShape::SlangStructuredBuffer as u32; - const BYTE_ADDRESS_BUFFER = shader_slang::ResourceShape::SlangByteAddressBuffer as u32; - const UNKNOWN = shader_slang::ResourceShape::SlangResourceUnknown as u32; - const ACCELERATION_STRUCTURE = shader_slang::ResourceShape::SlangAccelerationStructure as u32; - const TEXTURE_SUBPASS = shader_slang::ResourceShape::SlangTextureSubpass as u32; - const EXT_SHAPE = shader_slang::ResourceShape::SlangResourceExtShapeMask as u32; - const TEXTURE_FEEDBACK_FLAG = shader_slang::ResourceShape::SlangTextureFeedbackFlag as u32; - const TEXTURE_SHADOW_FLAG = shader_slang::ResourceShape::SlangTextureShadowFlag as u32; - const TEXTURE_ARRAY_FLAG = shader_slang::ResourceShape::SlangTextureArrayFlag as u32; - const TEXTURE_MULTISAMPLE_FLAG = shader_slang::ResourceShape::SlangTextureMultisampleFlag as u32; - const TEXTURE_COMBINED_FLAG = shader_slang::ResourceShape::SlangTextureCombinedFlag as u32; - const TEXTURE_1D_ARRAY = shader_slang::ResourceShape::SlangTexture1dArray as u32; - const TEXTURE_2D_ARRAY = shader_slang::ResourceShape::SlangTexture2dArray as u32; - const TEXTURE_CUBE_ARRAY = shader_slang::ResourceShape::SlangTextureCubeArray as u32; - const TEXTURE_2D_MULTISAMPLE = shader_slang::ResourceShape::SlangTexture2dMultisample as u32; - const TEXTURE_2D_MULTISAMPLE_ARRAY = shader_slang::ResourceShape::SlangTexture2dMultisampleArray as u32; - const TEXTURE_SUBPASS_MULTISAMPLE = shader_slang::ResourceShape::SlangTextureSubpassMultisample as u32; + const BASE_MASK = shader_slang::ResourceShape::BASE_MASK.bits(); + const NONE = shader_slang::ResourceShape::NONE.bits(); + const TEXTURE_1D = shader_slang::ResourceShape::TEXTURE1D.bits(); + const TEXTURE_2D = shader_slang::ResourceShape::TEXTURE2D.bits(); + const TEXTURE_3D = shader_slang::ResourceShape::TEXTURE3D.bits(); + const TEXTURE_CUBE = shader_slang::ResourceShape::TEXTURE_CUBE.bits(); + const TEXTURE_BUFFER = shader_slang::ResourceShape::TEXTURE_BUFFER.bits(); + const STRUCTURED_BUFFER = shader_slang::ResourceShape::STRUCTURED_BUFFER.bits(); + const BYTE_ADDRESS_BUFFER = shader_slang::ResourceShape::BYTE_ADDRESS_BUFFER.bits(); + const UNKNOWN = shader_slang::ResourceShape::UNKNOWN.bits(); + const ACCELERATION_STRUCTURE = shader_slang::ResourceShape::ACCELERATION_STRUCTURE.bits(); + const TEXTURE_SUBPASS = shader_slang::ResourceShape::TEXTURE_SUBPASS.bits(); + const EXT_MASK = shader_slang::ResourceShape::EXT_MASK.bits(); + const TEXTURE_FEEDBACK_FLAG = shader_slang::ResourceShape::TEXTURE_FEEDBACK_FLAG.bits(); + const TEXTURE_SHADOW_FLAG = shader_slang::ResourceShape::TEXTURE_SHADOW_FLAG.bits(); + const TEXTURE_ARRAY_FLAG = shader_slang::ResourceShape::TEXTURE_ARRAY_FLAG.bits(); + const TEXTURE_MULTISAMPLE_FLAG = shader_slang::ResourceShape::TEXTURE_MULTISAMPLE_FLAG.bits(); + const TEXTURE_COMBINED_FLAG = shader_slang::ResourceShape::TEXTURE_COMBINED_FLAG.bits(); + const TEXTURE_1D_ARRAY = shader_slang::ResourceShape::TEXTURE1D_ARRAY.bits(); + const TEXTURE_2D_ARRAY = shader_slang::ResourceShape::TEXTURE2D_ARRAY.bits(); + const TEXTURE_CUBE_ARRAY = shader_slang::ResourceShape::TEXTURE_CUBE_ARRAY.bits(); + const TEXTURE_2D_MULTISAMPLE = shader_slang::ResourceShape::TEXTURE2D_MULTISAMPLE.bits(); + const TEXTURE_2D_MULTISAMPLE_ARRAY = shader_slang::ResourceShape::TEXTURE2D_MULTISAMPLE_ARRAY.bits(); + const TEXTURE_SUBPASS_MULTISAMPLE = shader_slang::ResourceShape::TEXTURE_SUBPASS_MULTISAMPLE.bits(); } } @@ -609,7 +645,6 @@ pub enum ParameterCategory MetalArgumentBufferElement, MetalAttribute, MetalPayload, - Count, } impl ParameterCategory @@ -658,7 +693,7 @@ impl ParameterCategory } shader_slang::ParameterCategory::MetalAttribute => Self::MetalAttribute, shader_slang::ParameterCategory::MetalPayload => Self::MetalPayload, - shader_slang::ParameterCategory::Count => Self::Count, + _ => unimplemented!(), } } } @@ -683,7 +718,6 @@ pub enum Stage Mesh, Amplification, Dispatch, - Count, } impl Stage @@ -707,7 +741,7 @@ impl Stage shader_slang::Stage::Mesh => Self::Mesh, shader_slang::Stage::Amplification => Self::Amplification, shader_slang::Stage::Dispatch => Self::Dispatch, - shader_slang::Stage::Count => Self::Count, + _ => unimplemented!(), } } } |
