Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3a4c5cd
fix(d3d12): populate `dsv_readonly_flags` for render encoder
9Shain Nov 9, 2026
da316cf
chore(d3d12): make `{Begin|End}Event` no-op
9Shain Nov 9, 2026
e035dec
feat(d3d12): introduce render encoder prepass
9Shain Nov 9, 2026
e7be8ec
refactor(d3d12): populate render icb in render prepass
9Shain Nov 9, 2026
6913d64
refactor(d3d12): populate one indirect command per thread
9Shain Nov 9, 2026
a76bec7
feat(d3d12): implement `ExecuteIndirect()` for geometry & tessellatio…
9Shain Nov 10, 2026
25b8f19
fix(dxmt): use 3d thread coordinate for kernel `cs_clear_texture3d_*`
9Shain Nov 16, 2026
4f9ecbe
fix(d3d12): bail out of invalid draw command early
9Shain Nov 16, 2026
5fb1b21
feat(d3d12): implement indirect mesh draw fallback of `ExecuteIndirec…
9Shain Nov 16, 2026
569f44a
refactor(d3d12): explicitly intialize `*EncoderData` data members
9Shain Nov 19, 2026
c064ab1
refactor(d3d12): track pass boundary in command list
9Shain Nov 19, 2026
44ae9a6
feat(d3d12, dxmt): introduce occlusion query resolve encoder
9Shain Nov 23, 2026
4920880
feat(d3d12): allocate buffer for d3d12 query heap
9Shain Nov 23, 2026
2227256
feat(d3d12): implement occlusion query
9Shain Nov 23, 2026
2198ae4
feat(d3d12): add `ID3D12Device5` stubs
9Shain Nov 24, 2026
8377538
fix(airconv): set tessellation payload struct type packed
9Shain Nov 25, 2026
583210c
fix(airconv): multiply max tessellation mesh workgroup count by `patc…
9Shain Nov 25, 2026
b57b5fd
fix(airconv): guard dxil hull control point phase execution by output…
9Shain Nov 25, 2026
5be53a7
fix(airconv): correct the workload count estimation of quad domain
9Shain Nov 25, 2026
fb988d0
fix(d3d12): add object & mesh stages to render encoder waiting fence
9Shain Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/airconv/airconv_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef __AIRCONV_H
#define __AIRCONV_H

#define AIRCONV_VERSION 26
#define AIRCONV_VERSION 30

#ifdef __cplusplus
#include <string>
Expand Down
9 changes: 4 additions & 5 deletions src/airconv/dxbc_converter_ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ get_max_potential_workload_count(uint32_t max_tess_factor, SM50ShaderInternal *p
case microsoft::D3D11_SB_TESSELLATOR_DOMAIN_TRI:
return std::ceil((max_tess_factor - 1) / 4.0) * 3 + (max_tess_factor & 1);
case microsoft::D3D11_SB_TESSELLATOR_DOMAIN_QUAD:
return std::ceil((max_tess_factor - 1) / 4.0) * 4 + (max_tess_factor & 1);
;
return max_tess_factor + ((max_tess_factor & 1) == 0);
}
}

Expand Down Expand Up @@ -275,15 +274,15 @@ convert_dxbc_vertex_hull_shader(

uint32_t max_workload_count = get_max_potential_workload_count(factor_int, pHullStage);

func_signature.UseMaxMeshWorkgroupSize(max_workload_count);
func_signature.UseMaxMeshWorkgroupSize(max_workload_count * patch_per_group);

constexpr uint32_t size_workload_info = sizeof(TessMeshWorkload);

auto payload_struct_type = llvm::StructType::create(
context,
{hs_output_per_group_type, hs_pcout_per_group_scaler_type, types._int,
llvm::ArrayType::get(types._int, max_workload_count * patch_per_group * size_workload_info / 4)},
"payload"
"payload", true
);
uint32_t payload_struct_size = module.getDataLayout().getTypeAllocSize(payload_struct_type);

Expand Down Expand Up @@ -910,7 +909,7 @@ convert_dxbc_tesselator_domain_shader(
context,
{hs_output_per_group_type, hs_pcout_per_group_scaler_type, types._int,
llvm::ArrayType::get(types._int, max_workload_count * patch_per_group * size_workload_info / 4)},
"payload"
"payload", true
);
uint32_t payload_struct_size = module.getDataLayout().getTypeAllocSize(payload_struct_type);

Expand Down
18 changes: 17 additions & 1 deletion src/airconv/nt/dxil_converter_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ Converter::Converter(EntryPoint const &entry, dxmt::dxbc::context &ctx) :
air(ctx.air),
entry(entry) {
for (const auto &property : entry.properties) {
if (property.tag == EntryPropertyTag::HSState)
if (property.tag == EntryPropertyTag::HSState) {
pcf_ = property.hs_state.patch_constant_function;
output_control_point_count_ = property.hs_state.output_control_point_count;
}
}
}

Expand Down Expand Up @@ -135,6 +137,20 @@ Converter::Run(llvm::BasicBlock *ReturnBB) {
return PCFStart;
}

if (output_control_point_count_) {
auto cp_active = llvm::BasicBlock::Create(air.getContext(), "cp_active", ctx.function);
auto cp_end = llvm::BasicBlock::Create(air.getContext(), "cp_end", ctx.function);
ir.SetInsertPoint(cp_active);
auto is_active_control_point_thread = ctx.builder.CreateICmp(
llvm::CmpInst::ICMP_ULT, ctx.resource.thread_id_in_patch, ctx.builder.getInt32(output_control_point_count_)
);
ir.CreateCondBr(is_active_control_point_thread, block_map_[&entry.function->getEntryBlock()], cp_end);
ir.SetInsertPoint(cp_end);
air.CreateBarrier(llvm::air::MemFlags::Threadgroup);
ir.CreateBr(pcf_ ? PCFStart : ReturnBB);
return cp_active;
}

return block_map_[&entry.function->getEntryBlock()];
}

Expand Down
1 change: 1 addition & 0 deletions src/airconv/nt/dxil_converter_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Converter {
const EntryPoint &entry;

const llvm::Function *pcf_ = nullptr;
uint32_t output_control_point_count_ = 0;
llvm::DenseMap<const llvm::Value *, llvm::Value *> value_map_;
llvm::DenseMap<const llvm::BasicBlock *, llvm::BasicBlock *> block_map_;
llvm::DenseMap<llvm::Type *, llvm::Type *> type_map_;
Expand Down
181 changes: 84 additions & 97 deletions src/d3d12/d3d12_command_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ MTLD3D12CommandAllocatorImpl::Reset() {
case EncoderType::Resolve:
reinterpret_cast<ResolveEncoderData *>(next)->~ResolveEncoderData();
break;
case EncoderType::OcclusionQueryResolve:
reinterpret_cast<OcclusionQueryResolveEncoderData *>(next)->~OcclusionQueryResolveEncoderData();
break;
}
next = next->next;
}
Expand Down Expand Up @@ -204,7 +207,7 @@ MTLD3D12CommandAllocatorImpl::EncodeIndirectComputeCommand(MTLD3D12CommandSignat

auto &cmd_setpso_res = EncodeComputeCommand<wmtcmd_compute_setpso>();
cmd_setpso_res.type = WMTComputeCommandSetPSO;
cmd_setpso_res.pso = pCmdSig->compute_resolver;
cmd_setpso_res.pso = pCmdSig->resolver;
cmd_setpso_res.threadgroup_size = {1, 1, 1};

auto &cmd_argbuf_res = EncodeComputeCommand<wmtcmd_compute_setbuffer>();
Expand All @@ -214,8 +217,8 @@ MTLD3D12CommandAllocatorImpl::EncodeIndirectComputeCommand(MTLD3D12CommandSignat
cmd_argbuf_res.index = 30;

auto &cmd_dispatch_res = EncodeComputeCommand<wmtcmd_compute_dispatch>();
cmd_dispatch_res.type = WMTComputeCommandDispatch;
cmd_dispatch_res.size = {1, 1, 1};
cmd_dispatch_res.type = WMTComputeCommandDispatchThreads;
cmd_dispatch_res.size = {MaxCount, 1, 1};

auto &cmd_setpso = EncodeComputeCommand<wmtcmd_compute_setpso>();
cmd_setpso.type = WMTComputeCommandSetPSO;
Expand All @@ -236,95 +239,96 @@ MTLD3D12CommandAllocatorImpl::EncodeIndirectComputeCommand(MTLD3D12CommandSignat

IndirectRenderCommandData *
MTLD3D12CommandAllocatorImpl::EncodeIndirectRenderCommand(
MTLD3D12CommandSignature *pCmdSig, MTLD3D12GraphicsPipelineState *pPSO, size_t MaxCount
MTLD3D12CommandSignature *pCmdSig, MTLD3D12GraphicsPipelineState *pPSO, size_t MaxCount,
D3D12_PRIMITIVE_TOPOLOGY Topology
) {
WMTIndirectCommandBufferInfo info;
info.inherit_buffers = !(pCmdSig->UpdateVertexBuffers || pCmdSig->UpdateIndexBuffer || pCmdSig->UpdateRootArguments);
info.inherit_pso = 1;
info.inherit_cull_mode = 1;
info.inherit_fill_mode = 1;
info.inherit_front_facing = 1;
info.inherit_depth_bias = 1;
info.inherit_depth_clip_mode = 1;
info.inherit_depth_stencil_state = 1;
info.support_color_attachment_mapping = 0;
info.support_dynamic_attribute_stride = 0;
info.support_ray_tracing = 0;
info.type = pCmdSig->CommandType == D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED ? WMTIndirectCommandTypeDrawIndexed
: WMTIndirectCommandTypeDraw;
info.max_vertex_buffer_binding = 31;
info.max_fragment_buffer_binding = 31;
info.max_object_buffer_binding = 0;
info.max_mesh_buffer_binding = 0;
info.max_kernel_buffer_binding = 0;
info.max_kernel_threadgroup_memory_binding = 0;
info.max_object_threadgroup_memory_binding = 0;
info.gpu_resource_id = 0;

auto icb = device_->GetMTLDevice().newIndirectCommandBuffer(info, MaxCount, WMTResourceStorageModePrivate);
bool use_emulated_mesh = pPSO->is_geometry || pPSO->is_tess;
bool encode_binding =
use_emulated_mesh || pCmdSig->UpdateVertexBuffers || pCmdSig->UpdateIndexBuffer || pCmdSig->UpdateRootArguments;

auto [Ptr, Offset] = AllocateGPUHeap(sizeof(IndirectRenderCommandData), 16);

auto data = reinterpret_cast<IndirectRenderCommandData *>(Ptr);

data->cmd_buf = info.gpu_resource_id;
data->max_count = MaxCount;
uint32_t cmd_flags = 0;
if (pPSO->is_geometry)
cmd_flags |= kIndirectRenderCommandFlagIsGeometry;
if (pPSO->is_tess)
cmd_flags |= kIndirectRenderCommandFlagIsTessellation;

{
// populated outside
data->max_count_buffer = 0;
data->argument_buffer = 0;
data->rootsig_qwords = 0;
data->rootsig_qwords_stride = 0;
data->static_samplers = 0;
data->vertex_buffer = 0;
data->vertex_argbuf_stride = 0;
data->primitive_type = 0;
data->index_buffer = 0;
data->index_buffer_format = {};
}

{
/**
* TODO: move these out?
*/

auto &cmd_use_icb = EncodeRenderCommand<wmtcmd_render_useresource>();
cmd_use_icb.type = WMTRenderCommandUseResource;
cmd_use_icb.stages = WMTRenderStageVertex;
data->cmd_buf = 0;
data->max_count = MaxCount;
data->max_count_buffer = 0;
data->argument_buffer = 0;
data->rootsig_qwords = 0;
data->rootsig_qwords_stride = 0;
data->static_samplers = 0;
data->vertex_buffer = 0;
data->vertex_argbuf_stride = 0;
data->primitive_type = 0;
data->index_buffer = 0;
data->index_buffer_format = {};
data->dyn_ib_args = 0;
data->flags = cmd_flags;
data->vertex_increment_per_warp = 0;
data->vertex_per_warp = 0;

if (!use_emulated_mesh || device_->mesh_icb_supported) {
WMTIndirectCommandBufferInfo info;
info.inherit_buffers = !encode_binding;
info.inherit_pso = 1;
info.inherit_cull_mode = 1;
info.inherit_fill_mode = 1;
info.inherit_front_facing = 1;
info.inherit_depth_bias = 1;
info.inherit_depth_clip_mode = 1;
info.inherit_depth_stencil_state = 1;
info.support_color_attachment_mapping = 0;
info.support_dynamic_attribute_stride = 0;
info.support_ray_tracing = 0;
info.type = use_emulated_mesh ? WMTIndirectCommandTypeDrawMeshThreadgroups
: pCmdSig->CommandType == D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED ? WMTIndirectCommandTypeDrawIndexed
: WMTIndirectCommandTypeDraw;
info.max_vertex_buffer_binding = 31;
info.max_fragment_buffer_binding = 31;
info.max_object_buffer_binding = 31;
info.max_mesh_buffer_binding = 31;
info.max_kernel_buffer_binding = 0;
info.max_kernel_threadgroup_memory_binding = 0;
info.max_object_threadgroup_memory_binding = 0;
info.gpu_resource_id = 0;
auto icb = device_->GetMTLDevice().newIndirectCommandBuffer(info, MaxCount, WMTResourceStorageModePrivate | WMTResourceHazardTrackingModeUntracked);

data->cmd_buf = info.gpu_resource_id;

auto &cmd_use_icb = EncodeRenderPrepassCommand<wmtcmd_compute_useresource>();
cmd_use_icb.type = WMTComputeCommandUseResource;
cmd_use_icb.usage = WMTResourceUsageRead | WMTResourceUsageWrite;
cmd_use_icb.resource = icb;

auto &cmd_setpso_res = EncodeRenderCommand<wmtcmd_render_setpso>();
cmd_setpso_res.type = WMTRenderCommandSetPSO;
cmd_setpso_res.pso = pCmdSig->render_resolver;

auto &cmd_argbuf_res = EncodeRenderCommand<wmtcmd_render_setbuffer>();
cmd_argbuf_res.type = WMTRenderCommandSetVertexBuffer;
cmd_argbuf_res.buffer = gpu_heap_buffer_;
cmd_argbuf_res.offset = Offset;
cmd_argbuf_res.index = 30;
auto &cmd = EncodeRenderCommand<wmtcmd_render_executecommands>();
cmd.type = WMTRenderCommandExecuteCommandsInBuffer;
cmd.indirect_command_buffer = icb;
cmd.location = 0;
cmd.length = MaxCount;

auto &cmd_draw_res = EncodeRenderCommand<wmtcmd_render_draw>();
cmd_draw_res.type = WMTRenderCommandDraw;
cmd_draw_res.primitive_type = WMTPrimitiveTypePoint;
cmd_draw_res.vertex_start = 0;
cmd_draw_res.vertex_count = 1;
cmd_draw_res.base_instance = 0;
cmd_draw_res.instance_count = 1;

auto &cmd_setpso = EncodeRenderCommand<wmtcmd_render_setpso>();
cmd_setpso.type = WMTRenderCommandSetPSO;
cmd_setpso.pso = pPSO->GetRenderPipelineVariant({} /* FIXME: value should not matter here until gs/ts */);
icb_.push_back(std::move(icb));
}

auto &cmd = EncodeRenderCommand<wmtcmd_render_executecommands>();
cmd.type = WMTRenderCommandExecuteCommandsInBuffer;
cmd.indirect_command_buffer = icb;
cmd.location = 0;
cmd.length = MaxCount;
auto &cmd_setpso_res = EncodeRenderPrepassCommand<wmtcmd_compute_setpso>();
cmd_setpso_res.type = WMTComputeCommandSetPSO;
cmd_setpso_res.pso = pCmdSig->resolver;
cmd_setpso_res.threadgroup_size = {32, 1, 1};

icb_.push_back(std::move(icb));
auto &cmd_argbuf_res = EncodeRenderPrepassCommand<wmtcmd_compute_setbuffer>();
cmd_argbuf_res.type = WMTComputeCommandSetBuffer;
cmd_argbuf_res.buffer = gpu_heap_buffer_;
cmd_argbuf_res.offset = Offset;
cmd_argbuf_res.index = 30;

auto &cmd_draw_res = EncodeRenderPrepassCommand<wmtcmd_compute_dispatch>();
cmd_draw_res.type = WMTComputeCommandDispatchThreads;
cmd_draw_res.size = {MaxCount, 1, 1};

return data;
}
Expand All @@ -347,12 +351,7 @@ SimpleCommandContext<MTLD3D12CommandAllocatorImpl>::getComputePipeline(std::stri
template <>
void
SimpleCommandContext<MTLD3D12CommandAllocatorImpl>::startComputePass() {
ctx.InvalidateCurrentPass();
auto compute = ctx.AllocatePass<ComputeEncoderData>();
compute->type = EncoderType::Compute;
compute->cmd_head.type = WMTComputeCommandNop;
compute->cmd_head.next.set(0);
compute->cmd_tail = (wmtcmd_base *)&compute->cmd_head;
ctx.AllocatePass<ComputeEncoderData>();
}

template <>
Expand Down Expand Up @@ -437,19 +436,7 @@ SimpleCommandContext<MTLD3D12CommandAllocatorImpl>::getDefaultLibrary() {
template <>
void
SimpleCommandContext<MTLD3D12CommandAllocatorImpl>::startRenderPass() {
ctx.InvalidateCurrentPass();
auto render = ctx.AllocatePass<RenderEncoderData>();
render->type = EncoderType::Render;
render->cmd_head.type = WMTRenderCommandNop;
render->cmd_head.next.set(0);
render->cmd_tail = (wmtcmd_base *)&render->cmd_head;
render->dsv_planar_flags = 0;
render->dsv_readonly_flags = 0;
render->render_target_count = 0;
render->render_target_width = 16384;
render->render_target_height = 16384;
render->render_target_array_length = 0;
render->default_raster_sample_count = 1;
ctx.AllocatePass<RenderEncoderData>();
}

template <>
Expand Down
Loading
Loading