Skip to content

Instantly share code, notes, and snippets.

@smkplus
Forked from aras-p/texarray.md
Created February 10, 2020 19:18
Show Gist options
  • Save smkplus/1a3ab826f4d6f2f349fa5cc931f0e26d to your computer and use it in GitHub Desktop.
Save smkplus/1a3ab826f4d6f2f349fa5cc931f0e26d to your computer and use it in GitHub Desktop.
Possible texture array syntax

Unity shader side:

UNITY_DECLARE_TEX2DARRAY(name)
UNITY_SAMPLE_TEX2DARRAY(name,coord) // coord is float3

On DX11-like systems (DX11, and I'd assume XB1/PS4) the macros expand to:

#define UNITY_DECLARE_TEX2DARRAY(name) Texture2DArray(name); SamplerState sampler##name
#define UNITY_SAMPLE_TEX2DARRAY(name,coord) name.Sample(coord)

On hlsl2glsl-like systems (GL+EXT_texture_array, GLES3, Metal) the macros expand to:

#define UNITY_DECLARE_TEX2DARRAY(name) sampler2DArray name
#define UNITY_SAMPLE_TEX2DARRAY(name,coord) tex2DArray(name,coord)

and hlsl2glslfork has to learn how to parse that & emit proper GLSL. glsl-optimizer might also need minor updates, but concept of "texture arrays" should already be there

Unity code side:

I'd assume that GfxDeviceTypes.h TextureDimension needs to get a new entry for kTexDim2DArray. Review all places that have any tables sized kTexDimCount.

Shader lexer/parser probably needs a keyword for 2D arrays, i.e. shader_lex.lpp.

Shader compiler side needs to emit reflection info for 2D arrays, CompilerHLSL11.cpp etc.

GraphicsCaps needs to get a bool for whether 2D arrays are supported.

Otherwise, probably basing implementation on Texture3D.cpp/h would be good - just like texture arrays, it needs to check for hardware support, has no asset pipeline just yet (only create/fill from code), etc. Expose it to scripts in TextureBindings.txt, similar to 3D textures.

Array uploading/update code added to GfxDevice.h interface, possibly with an empty base implementation (for platforms that can't have them), again probably similar to 3D textures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment