gfx-rs / naga

Universal shader translation in Rust

Home Page:https://github.com/gfx-rs/wgpu/tree/trunk/naga

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[spv-out] `ZeroValue` expressions produce too many `OpConstantNull` instructions

jimblandy opened this issue · comments

#2332 introduces Expression::ZeroValue, which the SPIR-V backend uses to produce OpConstantNull instructions. However, it doesn't check to see if it's already got an an appropriate null constant for the given type, resulting in code like this:

%274 = OpConstantNull %10
%275 = OpConstantNull %10
%276 = OpConstantNull %13
%277 = OpConstantNull %10
%278 = OpConstantNull %8
%279 = OpConstantNull %10
%280 = OpConstantNull %8
%281 = OpConstantNull %10
%282 = OpConstantNull %8
%283 = OpConstantNull %13
%284 = OpConstantNull %8

Only three of these are necessary.

This example appears is in the snapshot output tests/out/spv/bounds-check-image-rzsw.spvasm.

I think we cache all other constants besides the null variant. This shouldn't be too hard to do considering we have the system in place for it.

I think this is something I didn't catch while doing the composites. I can tackle this