Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables of opaque types should be allowed #235

Open
JuanDiegoMontoya opened this issue Mar 15, 2024 · 0 comments
Open

Variables of opaque types should be allowed #235

JuanDiegoMontoya opened this issue Mar 15, 2024 · 0 comments

Comments

@JuanDiegoMontoya
Copy link

It's currently illegal to have a variable (local or global) with an opaque type, e.g., sampler2D or image2D. Being able to do so would have a number of advantages, particularly for bindless renderers where all resources may reside in array descriptors. The main one would be the ability to make type-safe aliases of resources.

One way to deal with this issue is to use macros that refer to specific indices of a descriptor array:

#define SAMPLER_NEAREST       s_bigSamplerArray[0]
#define SAMPLER_LINEAR_MIP    s_bigSamplerArray[1]
#define SAMPLER_LINEAR_SHADOW s_bigSamplerArray[2]
...
color = texture(sampler2D(fooTexture, SAMPLER_LINEAR_MIP), uv);

But macros have several issues:

  • Inability to assign to them at runtime
  • Infinite scope (unless explicitly #undef'd at some point)
  • Can cause confusing error messages or surprising bugs due to being simple text replacement

Being able to make a variable that refers to an object of an opaque type would generally make it easier to do logic on resources without having to add a layer of "indirection" (e.g., an if-else chain or switch statement in a bindful renderer).

While it's mostly a quality-of-life feature, it seems odd for it to be missing in the first place.

P.S. HLSL allows declaring locals and return values of opaque types, but they must be guaranteed to map to one unique resource (so no conditionally assigning them).

Related issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant