OpenGLレッドブックバージョン8(GL 4.3)の例11.19 whileループにimageLoad()
を配置し、前のプリミティブの少なくとも1つのフラグメントがこの値を更新するまでポーリングを維持します。この本はGLSL memoryBarrier()
と言っています。例11.19は、メモリバリアの非常に単純な使用例を示しています。それは、フラグメント間のある程度の順序付けが保証されることを可能にする。
functionUsingBarriers()
の上部では、単純なループを使用して、メモリロケーションの内容 が現在のプリミティブIDに達するまで待機します。 同じプリミティブの2つのフラグメントが同じ ピクセルに存在しないことがわかっているので、 関数の本体でコードを実行するとき、前のプリミティブの少なくとも1つのフラグメントは 処理された。次に非整数演算を使用して、 フラグメントの位置でメモリの内容を変更します。我々は、他のシェーダ の呼び出しに、もともとは関数の先頭でポーリングされた共有メモリ位置 に書き込むことによって行われます。当社修正された画像の内容が他のシェーダの呼び出し前にメモリ に書き戻されることを保証するためには、関数の本体の中に開始、我々は カラー画像の更新と順序を強制する プリミティブカウンターの間にメモリバリアへの呼び出しを使用します。
しかし、GL仕様4.3は、別の呼び出しによって書かれた1回の呼び出しのポール・メモリは、どのようにすることができ、他の呼び出しが開始されていることを前提とし、その書き込み
を完了することができた
を語ります以前のプリミティブのフラグメント呼び出しが開始され、その書き込みが完了したことを確認しますか?
郵便SRCコード
#version 420 core layout (rgba32f} uniform coherent image2D my_image; // Declaration of function void functionUsingBarriers(coherent uimageBuffer i) { uint val; // This loop essentially waits until at least one fragment from // an earlier primitive (that is, one with gl_PrimitiveID - 1) // has reached the end of this function point. Note that this is // not a robust loop as not every primitive will generate // fragments. do { val = imageLoad(i, 0).x; } while (val != gl_PrimitiveID); // At this point, we can load data from another global image vec4 frag = imageLoad(my_image, gl_FragCoord.xy); // Operate on it... frag *= 0.1234; frag = pow(frag, 2.2); // Write it back to memory imageStore(my_image, gl_FragCoord.xy, frag); // Now, we’re about to signal that we’re done with processing // the pixel. We need to ensure that all stores thus far have // been posted to memory. So, we insert a memory barrier. memoryBarrier(); // Now we write back into the original "primitive count" memory // to signal that we have reached this point. The stores // resulting from processing "my_image" will have reached memory // before this store is committed due to the barrier. imageStore(i, 0, gl_PrimitiveID + 1); // Now issue another barrier to ensure that the results of the // image store are committed to memory before this shader // invocation ends. memoryBarrier(); }
私たちは皆この本を持っていません。この例で何が起こっているのか具体的な詳細を実際に教えてもらえますか?特に、「以前のプリミティブ」は何を意味していますか? –
こんにちはNicol、私は質問を更新しました。それを再度読んでください。 –