2

そのシーンのレンダリングターゲットでもあるテクスチャを渡すシェーダーを使用してシーンをレンダリングすると、望ましくない動作が発生するのではないかと思いました。

だから基本的に:

texture t;

shader->SetTexture("texture",t);

device->SetRenderTarget( 0, t->surface );

shader->Begin("effect")
// do some more shader stuff

device->EndScene();

これは正確に何を引き起こしますか?

レンダリングする前にレンダリングターゲットをクリアしなくても、テクスチャはすべて同じように機能しますか?device-> Endが呼び出されるまで、最終的な変更はテクスチャに書き込まれないと思いますか?

4

3 に答える 3

3

I assume you're talking about DirectX9. The documentation does not say anything about this specific case, but I can tell you the following:

I just assume the final changes don't get written into the texture until device->End is called

This is a wrong assumption. Think about it, you're assuming all the pixels of all the triangles you draw will be stored 'somewhere' and all your texture fetches executed without any pixels being written back to the render target. This requires an arbitrary amount of memory and is therefore not possible.

In practice:

  • the hardware usually processes triangles as they come, many at once
  • it updates the frame buffer (which in your case is the texture memory backing) when it wants, assuming there can't be race conditions

So, assuming DX9 does not complain (try it if you really want to know, I don't do DX9 anymore), it will be undefined.

That said, DirectX10 is being more explicit about it (source):

If any subresources are also currently bound for reading or writing (perhaps in a different part of the pipeline), those bind points will be NULL'ed out to prevent the same subresource from being read and written simultaneously in a single rendering operation.

So, in DirectX10, your texture setting will be removed by the API.

于 2009-10-25T18:08:09.840 に答える
3

詳細を指摘することはできませんが、未定義の動作であると確信しています。グラフィックカードがフラグメントのシェーディングに使用する方法はさまざまです(一度に異なる量を実行するなど)が、実際には、一度に複数のフラグメントを実行します。これは、同じ場所への読み取りと書き込みの両方が行われ、競合状態が発生することを意味します。お勧めではないと思います。

于 2009-10-25T05:41:06.563 に答える
2

デバッグランタイムはこれを行うことを防ぎ、警告を提供します。リリースランタイムは「機能する可能性があります」(ただし、おそらく機能しません)。

問題は、テクスチャからピクセルをロードしてから使用されるまでにかなりの遅延があるという事実から生じます。これは、テクセルのブロックをキャッシュにロードすることで修正されます。書き込みはバッファリングされ、メモリに直接書き込まれます。したがって、すでに更新されている可能性があるテクセルを読み取っている可能性があるが、キャッシュが古くなっているという問題が発生する可能性があります。書き込まれているテクセルのみを読んでいる場合は「機能する可能性があります」が、現実的にはそのような実装の詳細はIHVに任されています。彼らはこれが機能することを許可する義務を負いません。

他の人が言ったように...それは非常に未定義の振る舞いです。

于 2009-10-26T12:07:43.843 に答える