Fix slow compilation of large zero-initialized arrays; warn on large non-zero fills#586
Fix slow compilation of large zero-initialized arrays; warn on large non-zero fills#58639ali wants to merge 1 commit into
Conversation
…e with N operands
Firestar99
left a comment
There was a problem hiding this comment.
Fix slow compilation
First, could you explain what kind of slowdown you're seeing?
use OpConstantNull instead when fill_byte == 0
I like that idea, although I'm unsure if spirt supports that command @eddyb?
will create a huge list of repeated store instructions
Isn't the bug then that the emitted OpConstantComposite was broken up into a bunch of individual OpStore instructions / not being reassembled into an OpCompositeConstruct / OpConstantComposite? (Our destructure_composites post-link pass may be related to this?)
|
i needed to clarify that for First, could you explain what kind of slowdown you're seeing?compile time is slow, i believe its because of the long i'll attach the .spv file for this shader : |
| } | ||
| SpirvType::Array { element, count } => { | ||
| if fill_byte == 0 { | ||
| return self.constant_null(ty.def(self.span(), self)).def(self); |
There was a problem hiding this comment.
Context (SPIR-T)
(Future) SPIR-T supports OpConstantNull (e.g. in Rust-GPU/spirt#45) so this is definitely a good catch and won't cause any issues!
I haven't implemented SPV_EXT_replicated_composites (and VK_EXT_shader_replicated_composites has pretty bad adoption - according to https://vulkan.gpuinfo.org/listextensions.php - not to mention we'd need user opt-in anyway).
However, SPIR-T could take OpConstantCompositeReplicateEXT as input, and specifically Rust-GPU/spirt#45 would map it to either undoing the optimization, or optionally re-emitting OpConstantCompositeReplicateEXT on the output side if the extension is enabled etc. (and internally SPIR-T could optimize for this situation, but it doesn't really depend on how SPIR-V does any of this).
What else you should/could do here:
- because
OpConstantNullsupports all of these types, you can go as far as makingmemset_const_patternreturnOpConstantNullregardless of the type, and not keeping it specific to arrays (and it would also support e.g.structs) - (optional) for full
SpirvType::Adtsupport inmemset_const_patternyou just need to iterate over field types - (optional) I'd almost want to say that
constant_compositeitself should check for this situation
let arr = [0; 32 * 1024]compiled very slowly. The cause: Rvalue::Repeat with a zero element routes throughmemset, while will create a huge list of repeated store instructions, the fix: useOpConstantNullinstead whenfill_byte == 0, valid for any SPIR-V composite type, single instruction regardless of size.SPIR-V has no equivalent of
OpConstantNullfor non-zero values , so the best we can do is tell the user early by emitting a warning