[naga spv-in] OpImageWrite allows input other than Vector4. #6630
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Connections
None
Description
Please excuse the use of machine translation (Google Translate).
It seems that an error (The value [~] can not be stored) occurs if a vector smaller than Vector4 is entered as the value of OpImageWrite.
However, according to the SPIR-V specification: https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpImageWrite
I think that even if a value other than Vector4 is entered, there is no problem as long as it matches the format of the target texture.
Looking at the error, it seems that it must be Vector4 in naga-ir, so I think that
naga::front::spv
needs to absorb that difference!For now, I have created an implementation and made a PR.
The implementation is designed to insert an Expression that expands to Vector4 depending on the format of the texture to be written to.
However, this implementation has a flaw. It works fine for languages that write Vector sizes that correspond to the destination, such as hlsl, but an error occurs if it is not...
If it is implemented correctly, I thought that it should be corrected by looking at the value to be written, not the format of the texture to be written, but I did not know how to implement it. (That is why this pull request is not mergeable, but a draft.)
So I hope this PR will explain the problem.
Finally, I will also include the minimum sample code (HLSL, SPIR-V) that causes this problem.
Original japanese text
機械翻訳(google translate)を使用していることをご容赦ください。
OpImageWrite の値として Vector4 より小さいベクターが入っているとエラー (The value [~] can not be stored) になるようです。
ですが、SPIR-V の仕様書によると: https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpImageWrite
と書かれており、Vector4 以外が入っていても対象となるテクスチャのフォーマットと適合していれば問題がないと私は思えます。
エラーを見るに naga-ir では Vector4 でないといけないようなので、
naga::front::spv
がその差異を吸収する必要があると私は思います!ひとまず、実装を作っては見たので PR を作りました。
実装としては、書き込み先のテクスチャのフォーマットに応じて Vector4 に拡張する Expression を差し込むようになっています。
ですが、この実装には欠陥があり hlsl などの書き込み先に対応した Vector サイズを書き込む言語の場合は問題がないですが、そうではない場合にかえってエラーが発生します ...
正しく実装するならば、書き込み先のテクスチャのフォーマットではなく、書き込む値の方を見て補正すべきだと私は思いましたが、私にそれを実装する方法がわかりませんでした。(このプルリクエストがマージできるものではなく、ドラフトにしている理由です。)
なので、この PR はその問題の説明になれば幸いです。
最後に、この問題が発生する最小の サンプルコード (HLSL,SPIR-V)も載せておきます。
example shader code
example float2
example float
Testing
I've provided example shader code so you should be able to create your own tests based on that.
(Is this the right answer...? Sorry if I'm wrong.)
Checklist
cargo fmt
.taplo format
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.