Jump to content
  • Advertisement
Sign in to follow this  
khawk

NVIDIA Releases GLSL Generator for DescriptorSet Indexed Types

Recommended Posts

NVIDIA recently released an open source sample of a GLSL header generator for DescriptorSet-indexed types in Vulkan. The project demonstrates how to simplify usage of VK_EXT_descriptor_indexing and GL_EXT_nonuniform_qualifier within GLSL. A script generates structure and function overloads to hide the code for indexing descriptor sets of samplers and textures.

For example, the tool turns:

// BEFORE

// we use a big resource table for descriptorset indexing
layout(set = 0, binding=0) uniform sampler2D  res_tex2Ds[];

// let's make use of GL_EXT_buffer_reference2
layout(buffer_reference, scalar) buffer Material {
  // we want to be cache efficient 
  uint16_t albedoTex;
  uint16_t normalTex;
  ...
};

layout(push_constant, scalar) uniform inputData {
  Material materials;
};

  // example usage
  Material  mat = materials[idx];
  
  // if idx varies non-uniformly (e.g. raytracing)
  // our texture fetches can start to look pretty ugly
  
  vec4 albedo = texture(res_tex2Ds[nonuniformEXT(uint(mat.albedoTex))], uv);

into:

// AFTER

// where descriptorsets start that are used for indexing
#define DIT_DSET_IDX 0

// this file is generated by the lua script
#include "sampler_indexed_types.glsl"

layout(buffer_reference, scalar) buffer Material {
  // new types are available
  // for example: struct sampler2D_u16 { uint16_t idx; }
  
  sampler2D_u16 albedoTex;
  sampler2D_u16 normalTex;
  ...
};

layout(push_constant, scalar) uniform inputData {
  Material materials;
};

  // example usage
  Material  mat = materials[idx];
  
  // much nicer looking access
  vec4 albedo = texture(mat.albedoTex, uv);

Check out the blog post for more information and the Github project here.


View full story

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!