Open hekota opened 1 month ago
@hekota - can you compare this to #101579 please and figure out which one we should go forward with?
clang/include/clang/Basic/Builtins.td
Add
def HLSLBufferGetDimensions : LangBuiltin<"HLSL_LANG"> {
let Spellings = ["__builtin_hlsl_buffer_get_dimensions"];
let Attributes = [NoThrow, CustomTypeChecking];
let Prototype = "void(...)";
}
CustomTypeChecking
struct Astruct {float a;};
RWStructuredBuffer<Astruct > Buf : register(u0);
uint count, stride;
Buf.GetDimensions(count, stride);
It should generate DXIL that looks like so.
%8 = call %dx.types.Dimensions @dx.op.getDimensions(i32 72, %dx.types.Handle %7, i32 undef)
%9 = extractvalue %dx.types.Dimensions %8
HLSLExternalSemaSource.cpp
create a addGetDimensionsMethods
function that defines a GetDimensions
TokenKind::identifier.HLSLExternalSemaSource.cpp
call addGetDimensionsMethods
for 23 types:
llvm/include/llvm/IR/IntrinsicsDirectX.td
and llvm/include/llvm/IR/IntrinsicsSPIRV.td
define an intrinsic whose first parameter is the buffer handle and whose return type is an anonymous struct. The struct return type is used to represent out parameters for the above count and stride. An Example of this was done in the splitDouble pr.clang/lib/CodeGen/CGHLSLRuntime.h
.clang/lib/CodeGen/CGBuiltin.cpp
. should be a standard Builder.CreateIntrinsic
calling
CGM.getHLSLRuntime().getBufferGetDimensionsIntrinsic(),
where the first argument is the buffer handle Value *ResHandle = EmitScalarExpr(E->getArg(0));
DXIL.td
add a def DimensionsTy : : DXILOpParamType;
to map out params.DXILOpBuilder.h
define a getter for %dx.types.Dimensions
.DXILOpBuilder.cpp
implemented the getter getDimensionsType
which returns a StructType.There are 54 cases of GetDimensions we need to support. Below is how they are used per Handle type.
Texture1D
Texture1DArray
Texture2D
Texture2DMS
Texture2DArray
Texture2DArrayMS
Texture3D
TextureCUBE
TextureCUBEArray
Buffer
RWTexture1D
RWTexture1DArray
RWTexture2D
RWTexture2DArray
RWTexture2DMS
RWTexture3D
RWBuffer
ByteAddressBuffer
RWByteAddressBuffer
StructuredBuffer
RWStructuredBuffer
AppendStructuredBuffer
ConsumeStructuredBuffer
We need LLVM intrinsic for bufferGetDimensions which will be lowered to the op.dx.getDimensions dxil operations. These will be used on structured buffers.
https://godbolt.org/z/bz7zxsf5n