使用重复映射的磁贴访问限制Tile access limitations with duplicate mappings

使用重复映射的磁贴访问存在一些限制,例如在复制具有重叠的源和目标的流式资源时,或在呈现给在呈现区域中共享的磁贴时。There are limitations on tile access with duplicate mappings, such as when copying streaming resources with overlapping source and destination, or when rendering to tiles shared within the render area.

复制具有重叠的源和目标的流式处理资源Copying streaming resources with overlapping source and destination

如果副本的源和目标区域中的磁贴*操作具有重复的中将具有重叠,即使这两个资源已不流式处理资源并将复制的复制区域映射*操作支持重叠将复制,复制*(就像在源复制到临时位置中,转到的目标之前) 的操作将正常行为。If tiles in the source and destination area of a Copy* operation have duplicated mappings in the copy area that would have overlapped even if both resources were not streaming resources and the Copy* operation supports overlapping copies, the Copy* operation will behave fine (as if the source is copied to a temporary location before going to the destination). 但是,如果重叠不明显(例如,源区域和目标区域虽不同,但共享映射,或者映射复制在特定表面),那么共享磁贴上的复制操作的结果则不明确。But if the overlap is not obvious (like the source and destination resources are different but share mappings or mappings are duplicated over a given surface), results of the copy operation on the tiles that are shared are undefined.

将复制到目标区域中的重复磁贴的流式处理资源Copying to streaming resource with duplicated tiles in destination area

复制到目标区域中使用重复磁贴的流式资源会在这些磁贴中产生不明确的结果,除非数据本身完全相同;不同磁贴可能会以不同的顺序写入磁贴。Copying to a streaming resource with duplicated tiles in the destination area produces undefined results in these tiles unless the data itself is identical; different tiles might write the tiles in different orders.

映射到重复的磁贴访问 UAVUAV accesses to duplicate tiles mappings

假设流式资源上的无序访问视图 (UAV) 在区域内有重复磁贴映射,或者有其他资源绑定至管道。Suppose an unordered access view (UAV) on a streaming resource has duplicate tile mappings in its area or with other resources bound to the pipeline. 如果由不同线程执行,那么这些重复磁贴的访问排序则不明确,正如内存访问 UAV 的任何排序通常都是无序。Ordering of accesses to these duplicated tiles is undefined if performed by different threads, just as any ordering of memory access to UAVs in general is unordered.

在磁贴映射更改或无法从外部映射的内容更新后的呈现Rendering after tile mapping changes or content updates from outside mappings

如果流式处理资源的磁贴映射已更改或映射的平铺的池磁贴中的内容已更改通过另一个流式处理资源的映射和流式处理资源将要通过呈现呈现目标视图或者深度模具视图,该应用程序必须清除 (使用 fixed 的函数清除 Api) 或通过使用复制完全复制*/更新*Api 呈现在区域内已更改的磁贴 (映射或未映射)。If a streaming resource's tile mappings have changed or content in mapped tiled pool tiles have changed via another streaming resource's mappings, and the streaming resource is going to be rendered via render target view or depth stencil view, the application must Clear (using the fixed function Clear APIs) or fully copy over using Copy*/Update* APIs the tiles that have changed within the area being rendered (mapped or not).

在这些情况下,如果应用程序未清除或复制,则会导致特定渲染目标视图或深度模具视图的硬件优化结构失效,并将导致某些硬件上出现糟糕的渲染结果以及不同硬件之间的不一致。Failure of an application to clear or copy in these cases results in hardware optimization structures for the given render target view or depth stencil view being stale, and will result in garbage rendering results on some hardware and inconsistency across different hardware. 硬件使用的这些隐藏优化数据结构可能存在于各个映射的本地,并且对相同内存的其他映射不可见。These hidden optimization data structures used by hardware might be local to individual mappings and not visible to other mappings to the same memory.

在清除资源视图(将资源中的所有元素设为一个值)时,你可清除含有矩形的渲染目标视图。When you clear a resource view (setting all the elements in a resource view to one value), you can clear render target views with rectangles. 对于支持流式资源的硬件,清除资源视图必须还支持在仅深度表面(无模具)上清除含有矩形的深度模具视图。For hardware that supports streaming resources, clearing a resource view must also support clearing of depth stencil views with rectangles, for depth only surfaces (without stencil). 这项操作可让应用程序仅清除表面的必要区域。This operation allows applications to clear only the necessary area of a surface.

如果应用程序需要保留映射变更的流式资源中区域的内存内容,则必须绕过清除要求。If an application needs to preserve existing memory contents of areas in a streaming resource where mappings have changed, that application must work around the clear requirement. 应用程序可首先保存磁贴映射变更的区域的内容(将其复制到临时表面),发布必要的清除命令,然后将内容复制回来,即可绕过清除要求。The application can accomplish this work-around by first saving the contents where tile mappings have changed (by copying them to a temporary surface), issuing the required clear command, and then copying the contents back. 尽管这能够完成保留表面内容的任务,进而实现增量渲染,但缺点是表面上后续的渲染性能会受到影响,因为渲染优化可能会丢失。While this would accomplish the task of preserving surface contents for incremental rendering, the downside is that subsequent rendering performance on the surface might suffer because rendering optimizations might be lost.

如果磁贴同时映射至多个流式资源,且通过其中一个流式资源以任何方式(渲染、复制等)操作磁贴内容,那么若要通过任何其他流式资源渲染相同磁贴,则首先必须按照上述步骤清除磁贴。If a tile is mapped into multiple streaming resources at the same time and tile contents are manipulated by any means (render, copy, and so on) via one of the streaming resources, if the same tile is to be rendered via any other streaming resource, the tile must be cleared first as previously described.

呈现到外部共享磁贴呈现区域Rendering to tiles shared outside render area

假设流式资源中的某个区域正在从渲染区向外部渲染,并且该渲染区引用的磁贴池磁贴也从渲染区向外部映射(包括同时或非同时通过其他流式资源)。Suppose an area in a streaming resource is being rendered to and the tile pool tiles referenced by the render area are also mapped to from outside the render area (including via other streaming resources, at the same time or not). 即使底层内存布局兼容,在通过其他映射查看时,渲染至这些磁贴的数据也不一定会正确呈现。Data rendered to these tiles isn't guaranteed to appear correctly when viewed through the other mappings, even though the underlying memory layout is compatible. 这种现象是因为某些硬件所使用的优化数据结构存在于可渲染表面的各个映射的本地,对相同内存位置的其他映射不可见。This fact is due to optimization data structures some hardware use that can be local to individual mappings for renderable surfaces and not visible to other mappings to the same memory location.

你可从渲染映射复制到可访问的相同内存的所有其他映射(如果不再需要旧内容,则可以清理该内存或将其他数据复制到其中),进而绕开这种限制。You can work around this restriction by copying from the rendered mapping to all the other mappings to the same memory that might be accessed (or clearing that memory or copying other data to it if the old contents are no longer needed). 尽管看似多余,但是这种绕开限制的方法可让相同内存的所有其他映射正确了解如何访问其内容,至少保证只需一个物理内存备份所节约的内存的完整性。While this work-around seems redundant, it makes all other mappings to the same memory correctly understand how to access its contents, and at least the memory savings of having only a single physical memory backing remains intact.

此外,当你在使用共享映射(除非仅读取)的不同流式资源之间切换时,你必须在切换之间指定多个平铺资源之间的数据访问排序限制(障碍)。Also, when you switch between using different streaming resources that share mappings (unless only reading), you must specify a data access ordering constraint (a barrier) between multiple tiled resources, in between the switches.

呈现区域中共享磁贴的呈现Rendering to tiles shared within render area

如果流式资源中的某个区域的渲染位置与渲染区内多个磁贴的映射位置是同一个磁贴池位置,那么这些磁贴上的渲染结果则不明确。If an area in a streaming resource is being rendered to and within the render area multiple tiles are mapped to the same tile pool location, rendering results are undefined on those tiles.

在流式处理共享磁贴的资源之间的数据兼容性Data compatibility across streaming resources sharing tiles

假设多个流式资源映射至相同的磁贴池位置,并且每个资源均用于访问相同的数据。Suppose multiple streaming resources have mappings to the same tile pool locations and each resource is used to access the same data. 如果关于避免硬件优化结构问题的其他规定得以避免、相应障碍得以确定(指定多个平铺资源之间的数据访问排序限制)并且流式资源互相兼容,这种情况才会发生。This scenario is only valid if the other rules about avoiding problems with hardware optimization structures are avoided, appropriate barriers are specified (specifying a data access ordering constraint between multiple tiled resources), and the streaming resources are compatible with each other.

对于后者,我们会在本文中讨论流式资源共享磁贴不兼容的影响。The latter is described here in terms of what it means for streaming resources sharing tiles to be incompatible. 访问重复磁贴映射上相同数据的不兼容条件是使用不同的表面尺寸或格式,或者资源上渲染目标或深度模具绑定标记的差异。The incompatibility conditions of accessing the same data across duplicate tile mappings are the use of different surface dimensions or format, or differences in the presence of render target or depth stencil bind flags on the resources. 如果你之后通过来自不兼容资源的映射进行读取或渲染,那么以一种映射写入内存会产生不明确的结果。Writing to the memory with one type of mapping produces undefined results if you subsequently read or render via a mapping from an incompatible resource.

如果其他资源共享映射首先使用新数据进行初始化(循环内存用于不同目的),那么由于数据并未在不兼容的解释中流出,因此后续的读取或渲染操作不受影响。If the other resource sharing mappings are first initialized with new data (recycling the memory for a different purpose), the subsequent read or render operation is fine since data isn't bleeding across incompatible interpretations. 但是,当你在访问此类不兼容映射之间切换时,你必须指定障碍(指定多个平铺资源之间的数据访问排序限制)。But, when you switch between accessing incompatible mappings like this, you must specify barriers (specifying a data access ordering constraint between multiple tiled resources).

如果渲染目标或深度模具绑定标记在任何相互的资源共享映射上不固定,则限制会少得多。If the render target or depth stencil bind flag isn't set on any of the resources sharing mappings with each other, there are far fewer restrictions. 只要格式和表面类型(例如 Texture2D)相同,就可以共享磁贴。As long as the format and surface types (for example, Texture2D) are the same, tiles can be shared. 兼容的不同格式是如 BC 的情况下*未压缩的 32 位或 16 位每个组件的格式,如 BC6H 和 R32G32B32A32 调整图面和等效项。Different formats being compatible are cases such as BC* surfaces and the equivalent sized uncompressed 32 bit or 16 bit per component format, like BC6H and R32G32B32A32. 每个元素的许多 32 位格式可以是作为别名 R32_ *也 (R10G10B10A2_*,R8G8B8A8_*,B8G8R8A8_*,B8G8R8X8_ *,R16G16_*); 始终为非流式处理资源允许此操作。Many 32 bit per element formats can be aliased with R32_* as well (R10G10B10A2_*, R8G8B8A8_*, B8G8R8A8_*,B8G8R8X8_*,R16G16_*); this operation has always been allowed for non-streaming resources.

如果格式相兼容,并且磁贴填充纯色,则不影响填充和非填充磁贴之间的共享。Sharing between packed and non-packed tiles is fine if the formats are compatible and the tiles are filled with solid color.

最后,如果共享磁贴映射的资源之间没有什么共同点(任何资源都没有渲染目标或深度模具绑定标记的情况除外),那么只能安全共享填充为 0 的内存;对于指定资源格式的定义(通常为 0),映射将呈现为 0 所解码的任何内容。Finally, if nothing is common about the resources sharing tile mappings except that none have render target or depth stencil bind flags, only memory filled with 0 can be shared safely; the mapping will appear as whatever 0 decodes to for the definition of the given resource format (typically just 0).

相关主题Related topics

管道到流式处理资源的访问权限Pipeline access to streaming resources