@@ -746,3 +746,92 @@ Examples:
746746 @llvm.dx.resource.load.cbufferrow.8(
747747 target("dx.CBuffer", target("dx.Layout", {i16}, 2, 0)) %buffer,
748748 i32 %index)
749+
750+ Resource dimensions
751+ -------------------
752+
753+ *relevant types: Textures and Buffer *
754+
755+ The `getDimensions `_ DXIL operation returns the dimensions of a texture or
756+ buffer resource. It returns a `Dimensions `_ type, which is a struct
757+ containing four ``i32 `` values. The values in the struct represent the size
758+ of each dimension of the resource, and when aplicable the number of array
759+ elements or number of samples. The mapping is defined in the
760+ `getDimensions `_ documentation.
761+
762+ The LLVM IR representation of this operation has several forms
763+ depending on the resource type and the specific ``getDimensions `` query.
764+ The intrinsics return a scalar or anonymous struct with up to 4 `i32 `
765+ elements. The intrinsic names include suffixes to indicate the number of
766+ elements in the return value. The suffix `.x ` indicates a single `i32 `
767+ return value, `.xy ` indicates a struct with two `i32 ` values, and `.xyz `
768+ indicates a struct with three `i32 ` values.
769+
770+ Intrinsics representing queries on multisampled texture resources include
771+ `.ms. ` in their name and their return value includes an additional `i32 ` for
772+ the number of samples.
773+
774+ Intrinsics with `mip_level ` argument and `.levels. ` in their name are used
775+ for texture resources with multiple MIP levels. Their return
776+ struct includes an additional `i32 ` for the number of levels the resource has.
777+
778+ .. code-block :: llvm
779+
780+ i32 @llvm.dx.resource.getdimensions.x( target("dx.*") handle )
781+ {i32, i32} @llvm.dx.resource.getdimensions.xy( target("dx.*") handle )
782+ {i32, i32, i32} @llvm.dx.resource.getdimensions.xyz( target("dx.*") handle )
783+ {i32, i32} @llvm.dx.resource.getdimensions.levels.x( target("dx.*") handle, i32 mip_level )
784+ {i32, i32, i32} @llvm.dx.resource.getdimensions.levels.xy( target("dx.*") handle, i32 mip_level )
785+ {i32, i32, i32, i32} @llvm.dx.resource.getdimensions.levels.xyz( target("dx.*") handle, i32 mip_level )
786+ {i32, i32, i32} @llvm.dx.resource.getdimensions.ms.xy( target("dx.*") handle )
787+ {i32, i32, i32, i32} @llvm.dx.resource.getdimensions.ms.xyz( target("dx.*") handle )
788+
789+ .. list-table :: ``@llvm.dx.resource.getdimensions.*``
790+ :header-rows: 1
791+
792+ * - Argument
793+ -
794+ - Type
795+ - Description
796+ * - Return value
797+ -
798+ - `i32 `, `{i32, i32} `, `{i32, i32, i32} `, or `{i32, i32, i32, i32} `
799+ - Width, height, and depth of the resource (based on the specific suffix), and a number of levels or samples where aplicable.
800+ * - ``%handle ``
801+ - 0
802+ - ``target(dx.*) ``
803+ - Resource handle
804+ * - ``%mip_level ``
805+ - 1
806+ - ``i32 ``
807+ - MIP level for the requested dimensions.
808+
809+ Examples:
810+
811+ .. code-block :: llvm
812+
813+ ; RWBuffer<float4>
814+ %dim = call i32 @llvm.dx.resource.getdimensions.x(target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %handle)
815+
816+ ; Texture2D
817+ %0 = call {i32, i32} @llvm.dx.resource.getdimensions.xy(target("dx.Texture", ...) %tex2d)
818+ %tex2d_width = extractvalue {i32, i32} %0, 0
819+ %tex2d_height = extractvalue {i32, i32} %0, 1
820+
821+ ; Texture2DArray with levels
822+ %1 = call {i32, i32, i32, i32} @llvm.dx.resource.getdimensions.levels.xyz(
823+ target("dx.Texture", ...) %tex2darray, i32 1)
824+ %tex2darray_width = extractvalue {i32, i32, i32, i32} %1, 0
825+ %tex2darray_height = extractvalue {i32, i32, i32, i32} %1, 1
826+ %tex2darray_elem_count = extractvalue {i32, i32, i32, i32} %1, 2
827+ %tex2darray_levels_count = extractvalue {i32, i32, i32, i32} %1, 3
828+
829+ ; Texture2DMS
830+ %2 = call {i32, i32, i32} @llvm.dx.resource.getdimensions.ms.xy(
831+ target("dx.Texture", ...) %tex2dms)
832+ %tex2dms_width = extractvalue {i32, i32, i32} %2, 0
833+ %tex2dms_height = extractvalue {i32, i32, i32} %2, 1
834+ %tex2dms_samples_count = extractvalue {i32, i32, i32} %2, 2
835+
836+ .. _Dimensions : https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#resource-operation-return-types
837+ .. _getDimensions : https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#getdimensions
0 commit comments