Skip to content

Suggestion: allow casting to texture/buffer resource types #1067

@TheRealMJP

Description

@TheRealMJP

Hey guys! I hope that this is okay to post here, but I wanted to suggest a new HLSL language feature just in case someone else hasn't already brought it up. In both my home and work codebases we make heavy use of "bindless" descriptors, where we use integer handles to index into unbounded texture/buffer arrays in order to access these resources in our shader code. This is very flexible since it essentially gives you global access to all of your SRV descriptors, but it's currently a bit awkward to express in HLSL since your texture/buffer arrays are strongly-typed. So you end up having to declare something like this in your shader code:

// Some common file shared among all shader code
Texture2D Tex2DTable[] : register(t0, space0);
Texture2DArray Tex2DArrayTable[] : register(t0, space1);
TextureCube TexCubeTable[] : register(t0, space2);
Texture3D Tex3DTable[] : register(t0, space3);
Texture2DMS<float4> Tex2DMSTable[] : register(t0, space4);
ByteAddressBuffer RawBufferTable[] : register(t0, space5);
Buffer<uint> BufferUintTable[] : register(t0, space6);

// When you want to access a resource
Texture2D myTexture = Tex2DTable[descriptorHandle];

You then you have to overlap these arrays onto the same global descriptor table by creating separate descriptor ranges in the root signature. This list obviously isn't exhaustive...there are many more possible combinations of texture or buffer types (we have many more in our version of this file in our codebase). And there's really infinite possibilities for StructuredBuffer types, so for those we end up having to reserve additional descriptor ranges and declare the arrays locally on a per-shader basis.

It would be great if a future version of HLSL allowed us to do something like this instead:

SRVDescriptor GlobalSRVTable[] : register(t0, space0);

Texture2D<float2> myTexture = Texture2D<float2>(GlobalSRVTable[descriptorHandle]);

That way we would only need one unbounded array in our shader code, and one unbounded descriptor range in the root signature.

Either way it's not super-critical since the current situation is workable, but I thought I would suggest this so that future code can be cleaner.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions