KhronosGroup / SPIRV-Guide

One stop shop for getting started with SPIR-V.
Creative Commons Attribution 4.0 International
171 stars 12 forks source link

Add Chapter - OpCopy* #27

Open spencer-lunarg opened 2 months ago

spencer-lunarg commented 2 months ago

OpCopyObject/OpCopyLogical/OpCopyMemory

How are they used, can they be used anywhere, etc

alan-baker commented 1 month ago

OpCopyObject is meant to be largely usable anywhere with any object. It is essentially a value copy. It does not allow other validation rules to be side-stepped (e.g. image and sampler in same block as the OpSampledImage instruction). As an example, the SPIRV-Tools optimizer uses it when performing some peep hole optimizations to avoid updating def/use information.

OpCopyLogical is a variant of OpCopyObject specifically specifically designed to handle similar, but not identical aggregates (array or structure). It is especially useful in Vulkan SPIR-V when changing between two versions of the same aggregate that differ only in layout decorations. For example, when DXC loads an aggregate from a resource it will have layout decorations. It then copies it to a version without layout decorations. OpCopyLogical reduces the number of instructions necessary to perform this transform.

OpCopyMemory is actually a variant of memcpy from C. Instead of specifying a size in bytes (as in OpCopyMemorySized) though, the whole object is copied (via the pointee type). This operation operates directly on memory. It could be lowered to a series of OpLoad and OpStore instructions. Vulkan traditionally uses OpCopyMemory because it uses logical pointers.