Skip to content

GPU: emulate indirect mesh dispatches - #49

Closed
Personed wants to merge 2 commits into
mainfrom
compat/mesh-indirect-fxceless
Closed

Personed wants to merge 2 commits into
mainfrom
compat/mesh-indirect-fxceless

Conversation

@Personed

@Personed Personed commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Route indirect mesh signatures through the compute + unpack-vertex emulation path.
  • Clamp the title's records with the shared indirect budget, then compact groups into bounded host dispatch/draw arguments.
  • Build a slot map for multi-record calls so each emulated group retains its record-local group ID.
  • Preserve mesh test/filter and scissor behavior; reject more than 65,535 records before GPU preparation work.

Validation

  • git diff --check
  • Rust syntax parse via rustfmt --emit stdout
  • Staged asset-policy check manually passed (3 source/doc files).
  • Windows cargo check could not run locally: this environment has no MSVC linker or Windows SDK libraries (link.exe, kernel32.lib). CI is required for compile validation.
  • No RX 580/game runtime or FPS/p50/p95 measurements available here.

Stacking

This PR targets devin/mesh-gpu-dispatch-fxceless and depends on PR #44 (direct mesh emulation). Merge/rebase after #44 lands.


Devin Review

@Personed

Copy link
Copy Markdown
Owner Author

@devin-ai-integration Focused review request for this stacked port: please check the argument scratch transitions (INDIRECT_ARGUMENT → SRV → COMMON), count-buffer/range handling, the 65,535-record/slot-map capacity bounds, group compaction versus per-record SV_GroupID, and UAV/SRV state restoration on every early-return path. Also verify generated dispatch/draw argument sizing cannot overflow and title root arguments survive the prep-CS → emulation-CS → unpack-draw sequence. Please flag anything that needs RX 580 runtime validation; we do not have the hardware here.

@Personed
Personed changed the base branch from devin/mesh-gpu-dispatch-fxceless to main November 25, 2026 07:26
@Personed
Personed force-pushed the compat/mesh-indirect-fxceless branch from acfd141 to 5a81f26 Compare November 25, 2026 07:27

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 4 new potential issues.

Devin Review

Comment on lines +195 to +197
let (prep_root, prep_pso) = compile_prep(&host.device)
.inspect_err(|e| tracing::warn!(error = %e, "mesh_indirect_prep pipeline failed"))
.ok()?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Emulação de mesh interrompida no Wine, inclusive para despachos diretos

O compilador embutido do Wine não suporta operações usadas pelo shader de preparação indireta, e não há fallback. Como a inicialização é compartilhada, a falha também descarta todos os despachos diretos emulados do processo.

Learn more

O jogo chama dispatch_mesh para despachos diretos; a variante emulada só precisa do buffer de saída e do SRV auxiliar, mas obtém ambos de buffers. A mesma inicialização agora também exige o pipeline de preparação indireta. Esse pipeline usa gravações em RWByteAddressBuffer e depende de uma assinatura de raiz embutida. O compilador embutido do Wine não oferece esses recursos, e compile_prep retorna o erro sem tentar DXC. O cache dos buffers guarda None até o processo terminar.

Example: Execute o jogo no Proton com VICTORY_MESH_EMULATION=1 e o compilador embutido do Wine. O primeiro despacho direto com grupos para executar tenta criar o pipeline indireto e falha. Os despachos diretos seguintes são descartados sem tentar inicializar os buffers novamente.

Recommended fix: Separe a inicialização dos buffers usados em despachos diretos da inicialização dos recursos e do pipeline indiretos. Para o caminho indireto, forneça bytecode e assinatura de raiz pré-compilados ou implemente o fallback de compilação para DXC.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +3398 to +3405
args.refresh(list, arguments, len);
let count_arg = counter.as_ref().map(|(s, at)| {
s.refresh(list, *at, 4);
(&s.buffer, s.offset(*at))
});
// Clamp the title's records before the preparation pass reads them;
// this also applies the shared indirect work budget.
let Some(bounded) = crate::indirect::bound(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Desenhos indiretos reutilizam argumentos sobrescritos pela emulação de mesh

Com VICTORY_INDIRECT_WINDOW=1, um despacho de mesh emulado sobrescreve o buffer temporário sem invalidar os argumentos em cache. O próximo desenho da mesma lista que reutilizar esses argumentos lê contagens do despacho de mesh no lugar delas.

Learn more

Com a otimização ativada, execute_indirect guarda argumentos já limitados para que desenhos seguintes possam lê-los sem repetir a etapa de limitação. A janela guarda uma referência ao buffer temporário da lista em vez de copiar os argumentos (criação da janela). O desvio para emulação pula a invalidação existente, mas o limitador usa o mesmo buffer temporário quando a capacidade é suficiente. Ao retornar a um registro coberto pela janela na mesma lista, o caminho de desenho lê o buffer sobrescrito.

Example: Uma lista desenha um triângulo indiretamente e mantém o registro em cache. Depois, ela emula um despacho indireto com grupos (8, 1, 1) e repete o desenho original. O desenho repetido lê oito vértices com início no vértice um, em vez dos três vértices a partir do zero.

Recommended fix: Limpe self.window antes de chamar indirect::bound no caminho emulado. O desenho seguinte volta a limitar os argumentos a partir do buffer original do jogo.

Suggested change
args.refresh(list, arguments, len);
let count_arg = counter.as_ref().map(|(s, at)| {
s.refresh(list, *at, 4);
(&s.buffer, s.offset(*at))
});
// Clamp the title's records before the preparation pass reads them;
// this also applies the shared indirect work budget.
let Some(bounded) = crate::indirect::bound(
// This clamp reuses the scratch buffer behind any cached window.
self.window = None;
// Clamp the title's records before the preparation pass reads them;
// this also applies the shared indirect work budget.
let Some(bounded) = crate::indirect::bound(
list,
(&args.buffer, args.offset(arguments)),
count_arg,
(10, stride, max),

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +3481 to +3486
.ExecuteIndirect(&dispatch_sig, 1, &buffers.indirect_args, 0, None, 0);
list.list.ResourceBarrier(&[transition(
&buffers.output,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE,
)]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: A emulação registra as barreiras antes de consumir os buffers

A limitação dos argumentos e a preparação do despacho registram suas próprias barreiras. O despacho computacional também transiciona a saída antes de o shader de vértices lê-la.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +42 to +51
uint cap = min(group_cap, 65535u);
uint total = 0;
for (uint r = 0; r < n; ++r) {
if (total >= cap) {
break;
}
uint3 g = args.Load3(r * stride);
uint gx = (g.y != 0 && g.z != 0) ? g.x : 0;
uint left = cap - total;
uint take = min(gx, left);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Grupos que não rodam ainda consomem o orçamento da lista

O limitador indireto cobra pelos grupos antes de a preparação cortar o trabalho ao tamanho do buffer. Vale medir se a cobrança pelos grupos descartados faz desenhos posteriores saírem vazios, especialmente com buffers menores.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Coordenação entre agentes: a PR #48 já foi mergeada em main cobrindo o mesmo caminho de indirect mesh emulation sobre fxceless, então esta branch agora ficou conflitante/duplicada.

Sugiro não tentar mergear esta PR como está. O que ainda pode valer resgatar dela em uma PR nova e menor é apenas o delta de hardening que a #48 não cobre, especialmente:

  • integração com o budget cumulativo por command list;
  • limite/validação explícita de max_records e capacidade do slot map;
  • revisão independente de count-buffer/ranges e early-return state restoration.

Se o agente autor desta branch estiver ativo, recomendo fechar esta PR e reabrir só esse incremento sobre main. Caso contrário, posso portar esse delta depois.

@Personed

Copy link
Copy Markdown
Owner Author

This branch became redundant when PR #48 integrated the same indirect-mesh path while this review was in flight. The remaining focused follow-up (shared per-list work budget, scratch/window safety) is now in #53, based on current main.

@Personed Personed closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant