KhronosGroup / KhronosGroup/GLSL

Want pass-by-reference function-call syntax to avoid implication of doing large copies.

Open
#84 20 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
458
Forks
114
Avg merge
4m
Merged PRs (30d)
1

Description

Here's my minimal test code:

#version 450
#extension GL_ARB_separate_shader_objects : enable

layout(location = 0) in vec2 fragScreenCoord;
layout(location = 0) out vec4 resColor;

#define MaxObjectsCount 20
struct Object
{
  uint bla1;
  uint bla2;
};

struct Objects
{
  Object data[MaxObjectsCount];
};

Objects objects;

void CompareExchange(/*inout Objects objects, */uint i, uint j)
{
  if(objects.data[i].bla1 > objects.data[j].bla1)
  {
    Object tmp = objects.data[i];
    objects.data[i] = objects.data[j];
    objects.data[j] = tmp;
  }
}
void main()
{
  resColor = vec4(1.0f, 0.5f, 0.0f, 1.0f);
  for(int i = 0; i < MaxObjectsCount; i++)
  {
    objects.data[i].bla1 = uint(gl_FragCoord.x) - i;
    objects.data[i].bla2 = uint(gl_FragCoord.y) + i;
  }
  for(int i = 0; i < MaxObjectsCount; i++)
  {
    for(int j = 0; j < MaxObjectsCount - i - 1; j++)
    {
      CompareExchange(/*objects, */j, j + 1);
    }
  }
  resColor.r += objects.data[0].bla1 * 1e-3f;
}


This code runs in fragment shader and takes approximately 30ms on my GTX1050. Uncommenting the function argument makes this code run approximately 20(!) times slower to about 650ms. The results are the same both in OpenGL application that uses glCompileShader() and in Vulkan that uses glslang to compile this glsl into spirv.

So my questions are: why is there no syntax for proper function inlining to make sure that this does not happen? Why is there no syntax for proper pass-by-reference instead of pass-by-copy-in/copy-out semantic "inout"?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the minimal GLSL shader as the reproduction case and compare compilation through glCompileShader() and glslang to SPIR-V. Review the existing inout parameter semantics and determine what specification change would define reference passing or inlining; done means the syntax and semantics are specified and the benchmark no longer incurs the reported slowdown.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.