4

多くの記事では、固定バインディング ポイントを指定してアトミック カウンターを使用する方法について説明しています。

//Shader:
layout(binding = 0, offset = 0) uniform atomic_uint myAtomicCounter;

//App code
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, myBufferHandle);

ここでは、ハードコーディングされたバインディング ポイントbinding = 0がシェーダー コードとアプリケーション コードの両方で指定されています。これらの記事はこのようにしていると思います。

アトミック カウンターには場所が割り当てられていないため、Uniform*コマンドを使用して変更することはできません。プログラム オブジェクトのアトミック カウンターに属するバインディング、オフセット、およびストライドは無効になり、再リンクが成功するたびに新しいカウンターが割り当てられます。[shader_atomic_counters]

The above is fine until you want some more modular shader code. For example I have two shader include files, each needing an atomic counter that I've written as pluggable code that doesn't know about the other. Clearly I don't want to specify hard coded binding points and I'd like the application to handle it automatically. I don't really care which binding points they use, just that they aren't the same.

Vertex shader attributes appear similar. I can force a binding location at runtime (glBindAttribLocation) before shader linking or alternatively let OpenGL choose them for me and then query the result (glGetAttribLocation). I can also search through all attributes (glGetActiveAttrib).

How can I implement automatic unique binding points for atomic counters, so they're not hard coded and I can mix shader code?

リンク後に変更しないという制限がありますが、これが可能な方法がいくつかあります。

  1. シェーダーでバインディング ポイントを指定せず、リンク時に OpenGL に選択させます。OpenGLがこれを行うかどうかはわかりません。もしそうなら、どのように照会して、使用された結合点を見つけますか?
  2. リンクする前にシェーダー オブジェクトをクエリして、アトミック カウンターを見つけます。次に、属性の場合と同様に、一意のバインド場所を指定glBindAttribLocationします。結合点を割り当てるメカニズムはありますか?
  3. アトミック カウンターを探してすべてのシェーダー コードを解析し、バインド ポイントを、おそらく#defineマクロを使用して、シェーダー コード自体の一意のインデックスに置き換えます。最後の手段。私は本当にこれをする必要はありません。
4

2 に答える 2

1

ポイント 1:bindingアトミック カウンターのレイアウト パラメーターはオプションではありません

ポイント 2:bindingはオプションではないため、OpenGL コードから設定できても意味がありません。

したがって、あなたの唯一の頼りは#3です。

于 2015-12-14T05:50:21.150 に答える