0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Unity : Compute Shaderで Failed to present D3D11 swapchain due to device reset/removed の解決法

Last updated at Posted at 2021-07-16

UnityのCompute Shaderを使っていると,なぞに落ちたりすることが多々あります.

Compute Shader (DirectCompute)では現在(2021年)Runtime Error的なものを吐き出してくれず,構文エラー以外の実行時エラーは,コメントアウトをするなどして,たどる必要があります.今回は以下のようなエラーに遭遇し,Unity Editorが落ちてしまいました.

 エラー: Failed to present D3D11 swapchain

image.png

Failed to present D3D11 swapchain due to device reset/removed. This error can happen if you draw or dispatch very expensive workloads the GPU, which can cause Windows to detect a GPU Timeout and reset the device.  If you believe this error is due to built in Unity functionality, please submit a bug This is an unrecoverable error and the editor will shut down.

解決法

CPU側でp2gMassBuffer, sortedP2gMassBufferを生成していたのですが,P2GMassという構造体で作成したCompute Bufferだったが↓,

GridSortCS.SetBuffer(this.rearrangeParticlesKernel.Index, "_P2GMassBuffer", p2gMassBuffer);
GridSortCS.SetBuffer(this.rearrangeParticlesKernel.Index, "_SortedP2GMassBuffer", sortedP2gMassBuffer);

GPU側では,MpmParticleという別の構造体でのCompute Bufferにいれてしまっていました↓.

StructuredBuffer<MpmParticle>	_P2GMassBuffer;
RWStructuredBuffer<MpmParticle>	_SortedP2GMassBuffer;

そこで以下のように,MpmParticleからP2GMassに変更したところ,エラーが起こらなくなりました.

StructuredBuffer<P2GMass>	_P2GMassBuffer;
RWStructuredBuffer<P2GMass>	_SortedP2GMassBuffer;

最後に

Compute Shaderは配列からindexがはみ出ていたり,今回のような別の構造体のCompute Bufferを使っていてもエラーを教えてくれないので,コメントアウトでどこがエラーの元かを2分探索方式で探していき,最後に絞りこめた行を見て目視であっているかチェックしたり,Compute BufferをC#側にもちかえって,デバッグするしかないので,時間をかけてじっくりデバッグしましょう!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?