[Vulkan] A texture left in Common or UnorderedAccess by an earlier command list is sampled with the wrong descriptor layout

Abierto
#4,103 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
18/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
csharp

Línea de trabajo

Start from the review on PR #4094 and the sampled-image descriptor path; the named pieces are GetCbLayoutTracker, SubmittedLayoutReplay.RecordAssumed, CorrectAssumedLayouts, SubresourceLayoutTracker, TransitionTexture and RestoreAfterTransfer. Reproduce with the Vulkan validation layer: move a texture to Common, submit, then sample it in a later command list with no transition. Done means an agreed thread-safe tracker design, correction barriers for the sampled layout, and the new single- and multi-threaded tests passing.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

area-Graphics bug
Stride version

master, with #4094

Platforms

Windows

Graphics API

Vulkan

What happens

#4094 makes a sampled-image descriptor declare GENERAL when the command list that samples the texture has it in Common or UnorderedAccess. As the review of #4094 points out, this only covers a texture that this command list moved itself: currentCbLayouts is cleared on Reset. A texture moved to Common once, for example in an earlier frame, then sampled in later command lists with no transition of their own, still gets SHADER_READ_ONLY_OPTIMAL while the image is in GENERAL. "Move once, sample later" is a natural pattern for Common, which means any use.

Expected: the descriptor declares the layout the image is in when the command list runs.

Steps to reproduce
  1. Move a texture to BarrierLayout.Common, and submit that command list.
  2. In a later command list, sample the texture with no transition (for example with DrawTexture).
  3. Run with the Vulkan validation layer.
Log and callstack
Cannot use VkImage ... with specific layout SHADER_READ_ONLY_OPTIMAL that doesn't match the previous known layout GENERAL
Screenshots and other details

The fix touches the barrier design, so I'd like to agree on the approach before the PR.

What exists. When a command list first touches a texture through a transition, GetCbLayoutTracker clones the texture's shared tracker and records that layout as assumed (SubmittedLayoutReplay.RecordAssumed). At submission, CorrectAssumedLayouts replays the list's transitions on the layouts the earlier submissions really left, and records correction barriers before the list. The sampled descriptor never joins this: it only looks in currentCbLayouts, deliberately not in the shared tracker, "which can be mutated by other CBs recording concurrently".

Why the obvious change is not enough.

  • SubresourceLayoutTracker is a mutable struct with several fields, held in a field of the texture with no synchronization. TransitionTexture and RestoreAfterTransfer already clone it and write it back from the recording thread, which is rare on worker lists today because RenderSystem.Draw transitions the stage's targets on the main list first. If the sampled path read it too, every texture a worker list samples would be exposed, and a torn copy can give a stale layout or a NullReferenceException in Get.
  • Recording every sampled texture as assumed adds a dictionary entry and recorded transitions per texture per command list, and can add correction barriers where none were recorded before.
  • The bound read-only depth case only applies today when the list has no layout for the texture, so it would have to win over the tracked layout.

Proposal.

  1. Make the shared tracker safe to clone and update from several recording threads, for example by swapping an immutable snapshot, or with a lock around the clone and the write-back.
  2. Have the sampled descriptor take the tracker as a transition does (GetCbLayoutTracker), so its layout is assumed at record time and corrected at submission, whatever the submission order.
  3. Keep the bound read-only depth rule first.

Tests: a texture moved to Common in one command list and sampled in a later one, with no transition, checked on Vulkan with sync validation; the multi-threaded draw path through the engine tests.

Does this approach look right, or would you prefer another one, for example documenting that a texture in Common or UnorderedAccess must be transitioned in the command list that samples it?

Lenguaje dominante
C#
Estrellas
8k
Forks
1.2k
Merge medio
1 d 1 h
PR fusionados (30 d)
321

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de stride3d/stride

Todos los issues de stride3d/stride

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.