External Texture Size Uniform

The Slang README seems to imply that external texture sizes are available to shaders:

Builtin texture size uniform variables

If a member of a UBO or a push constant block is called ???Size# where ???# is the name of a texture variable, that member must be a vec4, which will receive these values:

  • X: Horizontal size of texture
  • Y: Vertical size of texture
  • Z: 1.0 / (Horizontal size of texture)
  • W: 1.0 / (Vertical size of texture)

It is valid to use a size variable without declaring the texture itself. This is useful for vertex shading. It is valid (although probably not useful) for a variable to be present in both a push constant block and a UBO block at the same time.

However, when I tried this it didn’t work. It seems like this section only applies to the pre-defined textures and things like feedback. Is that correct?

1 Like

It is correct.

At least, it didn’t worled an all of the drivers last time I tried. Can’t remember exactly which worked, but yeah, in the end a call to textureSize() in the fragment shader is needed.

2 Likes

Thanks. I was using Vulkan FYI.

2 Likes

I was looking at this the other day after I fixed the d3d mipmap thing, and it works on at least some of the d3d drivers but not glcore or vulkan. I’m hoping to get some time to work on it soon™

2 Likes