From 2d83875f4b376f047c4541a6f6c13d36e5aa228b Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 18 Sep 2024 13:46:20 -0700 Subject: Add `IRWArray` interface, and make StructuredBuffer conform to them. (#5097) * Add `IRWArray` interface, and make StructuredBuffer conform to them. * Update user guide. * Fix. * Fixes. --- source/slang/core.meta.slang | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'source/slang/core.meta.slang') diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 03dda0fe5..afcff8e65 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -396,6 +396,15 @@ interface IArray } } +interface IRWArray : IArray +{ + __subscript(int index)->T + { + get; + set; + } +} + // The "comma operator" is effectively just a generic function that returns its second // argument. The left-to-right evaluation order guaranteed by Slang then ensures that // `left` is evaluated before `right`. @@ -1148,21 +1157,15 @@ extension int16_t : IRangedValue __generic __magic_type(ArrayExpressionType) -struct Array : IArray +struct Array : IRWArray { __intrinsic_op($(kIROp_GetArrayLength)) int getCount(); - - __subscript(int index) -> T - { - __intrinsic_op($(kIROp_GetElement)) - get; - } } /// An `N` component vector with elements of type `T`. __generic __magic_type(VectorExpressionType) -struct vector : IArray +struct vector : IRWArray { /// The element type of the vector typedef T Element; @@ -1182,8 +1185,6 @@ struct vector : IArray [ForceInline] int getCount() { return N; } - - __subscript(int index) -> T { __intrinsic_op($(kIROp_GetElement)) get; } } const int kRowMajorMatrixLayout = $(SLANG_MATRIX_LAYOUT_ROW_MAJOR); @@ -1192,7 +1193,7 @@ const int kColumnMajorMatrixLayout = $(SLANG_MATRIX_LAYOUT_COLUMN_MAJOR); /// A matrix with `R` rows and `C` columns, with elements of type `T`. __generic __magic_type(MatrixExpressionType) -struct matrix : IArray> +struct matrix : IRWArray> { __intrinsic_op($(kIROp_MakeMatrixFromScalar)) __implicit_conversion($(kConversionCost_ScalarToMatrix)) @@ -1207,8 +1208,6 @@ struct matrix : IArray> [ForceInline] int getCount() { return R; } - - __subscript(int index) -> vector { __intrinsic_op($(kIROp_GetElement)) get; } } __intrinsic_op($(kIROp_Eql)) -- cgit v1.2.3