A Direct3D 12 to Render Metadata Mapping Method Based on Kernel-Level Nested Parsing

By establishing a D3D metadata structure and global index format in VKD3D, the rendering errors caused by GPU's lack of support for ShaderDrawParameters feature were resolved, achieving stable and compatible operation of D3D12 applications and multi-view synchronization.

CN121708191BActive Publication Date: 2026-05-15北京麟卓信息科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-02-12
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

When the GPU does not support the ShaderDrawParameters feature, VKD3D cannot accurately map the rendering metadata of D3D12 applications, leading to problems such as rendering errors, instantiation failures, multi-view synchronization anomalies, performance drops, and even crashes.

Method used

By establishing the structure and global index format of D3D metadata, creating D3D metadata UBO, initializing a four-level storage structure, intercepting resource binding, dynamic state configuration and drawing call operations, capturing relevant parameters, parsing view index and drawing call information, generating D3D metadata, establishing a mapping dictionary, grouping and binding UBOs according to priority, recording drawing commands and inserting resource barriers, parsing indirect commands, and completing rendering.

Benefits of technology

It enables D3D12 applications to run normally on GPUs that do not support the ShaderDrawParameters feature, avoiding rendering errors and performance degradation, and ensuring multi-view synchronization and stable rendering effects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121708191B_ABST
    Figure CN121708191B_ABST
Patent Text Reader

Abstract

The application discloses a Direct3D 12 to rendering metadata mapping method based on kernel level nested analysis, establishes a structure body and a global index of D3D metadata in a VKD3D compilation stage, creates D3D metadata UBO when starting, intercepts resource binding, dynamic state configuration, multi-view setting and drawing calling and the like operations of VKD3D when executing, captures related parameters and generates complete D3D metadata in combination with kernel analysis, groups metadata according to a mapping dictionary between system values dependent on D3D12 colorizers and metadata demand types, writes the grouped metadata into the UBO of the corresponding metadata group according to a single view or multi-view scene, combines the metadata into a drawing group, submits the command buffer to the GPU to complete rendering after batch recording of the drawing command, and realizes compatible running of the D3D12 application in the case that the GPU does not support the ShaderDrawParameters feature.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer software development technology, specifically relating to a method for mapping Direct3D 12 to rendering metadata based on kernel-level nested parsing. Background Technology

[0002] VKD3D is an open-source project that simulates Direct3D 12 (hereinafter referred to as D3D12) based on the Vulkan 1.3 standard. Its core workflow is to translate the D3D12 API calls on the Windows platform into Vulkan API calls on the Linux platform, and to compile the D3D12 HLSL shaders into Vulkan-compatible SPIR-V shaders. Its key lies in accurately replicating the rendering semantics, resource binding rules, and pipeline synchronization behavior of D3D12. ShaderDrawParameters is a core device feature defined in Vulkan 1.0 and above. Its core function is to allow the shader stage to directly access the metadata related to the drawing call, including the index of the current drawing call in the command buffer gl_DrawID, the current instance index gl_InstanceIndex, the current vertex index gl_VertexIndex, and the indirect drawing command parameter gl_DrawIndirectCommand, etc.

[0003] However, D3D12's HLSL shaders natively support accessing the aforementioned metadata via system value semantics. This feature is widely used in core application rendering scenarios such as instantiation drawing, batch rendering, multi-view rendering, and dynamic resource indexing. In existing technologies, VKD3D relies on the ShaderDrawParameters feature to directly map D3D12 system values ​​to corresponding Vulkan metadata variables. However, when the GPU does not support this feature, the SPIR-V shader will be unable to access variables such as gl_DrawID, leading to problems such as rendering errors, instantiation failures, multi-view synchronization anomalies, performance drops, and even crashes in D3D12 applications. Summary of the Invention

[0004] In view of this, the present invention provides a Direct3D 12 to rendering metadata mapping method based on kernel-level nested parsing, which enables the compatible operation of D3D12 applications even when the GPU does not support the ShaderDrawParameters feature.

[0005] This invention provides a method for mapping Direct3D 12 to rendering metadata based on kernel-level nested parsing, which specifically includes the following steps:

[0006] During the VKD3D compilation phase, the structure of D3D metadata, the global index format of single view and multi-view are established. At startup, D3D metadata UBOs and metadata groups storing D3D metadata UBOs are created, and the metadata groups, view metadata sub-tables and metadata items are initialized.

[0007] When creating a root signature in a D3D application, VKD3D reserves a setting slot in the root signature; when setting the viewport, it captures viewport parameters; when setting the clipping rectangle, it captures the clipping rectangle; when setting the view instance mask, it parses the view index parameter to extract the view index and extracts the number of views from the multi-view interface parameters; when executing a direct drawing scene, it extracts the vertex index, vertex start position, instance start position, number of vertices, and number of instances, and generates a DrawID from a global atomic counter; when executing an indirect drawing scene, it extracts the offset of the indirect command in the buffer, parses the indirect command buffer to generate a Vulkan indirect command structure; when executing a nested indirect drawing scene, it extracts the offset of the indirect command count buffer, recursively parses the nested parameters to generate a Vulkan indirect count command structure, adds a nesting marker, parses the count buffer to obtain the number of nested drawings, and constructs D3D metadata;

[0008] A mapping dictionary is established between system values ​​dependent on D3D12 shaders and metadata requirement types. When continuously drawing and generating D3D metadata, the grouping conditions of D3D metadata are determined according to the mapping dictionary, and the metadata group corresponding to the D3D metadata is determined accordingly. D3D metadata is added to the metadata group, and metadata items in the same metadata group are merged into the same drawing group. The D3D metadata UBO corresponding to the drawing group is bound to the set slot. Drawing commands are recorded in batches according to the metadata items in the drawing group. The metadata group index and view index of the drawing group are added to the command buffer. The command buffer is submitted to the GPU, and the GPU executes the drawing commands in the command buffer to complete the rendering.

[0009] Furthermore, the method of adding D3D metadata to the metadata group is as follows: if there are idle metadata items in the metadata group, the metadata is added to the idle metadata item, and when its view count is greater than 1, the offset of the metadata item is recorded in the view metadata sub-table of the current metadata group, written to the D3D metadata UBO, the count of used metadata items is incremented by 1, and a global index is allocated to it; when its view count is 1, it is written to the D3D metadata UBO, the count of used metadata items is incremented by 1, and a global index is allocated to it.

[0010] If a metadata group has no free metadata items, a new metadata group is created, its index is set to the previous group's index incremented by 1, the metadata group is initialized, and then the metadata items are written to the corresponding UBO of the new metadata group according to the value of its view count, and a global index is allocated.

[0011] Furthermore, the global index includes a globally unique identifier for the metadata group, a view index, and an intra-group index. If the number of views for the D3D metadata is greater than 1, the intra-group index is not empty; otherwise, the intra-group index is not set.

[0012] Furthermore, the method of writing it into the D3D metadata UBO is as follows: the writing address is pMappedMemory + usedCount * sizeof(D3D12DrawMetadata), where pMappedMemory is the virtual address of the UBO mapped to the CPU, usedCount is the number of used metadata items, and sizeof(D3D12DrawMetadata) is the size of the metadata.

[0013] Furthermore, the method of batch recording drawing commands based on metadata items within the drawing group is as follows:

[0014] If the dynamic states of all metadata items within a drawing group are the same, the dynamic state setting command is recorded only once; otherwise, the dynamic state setting commands are recorded sequentially according to the drawing call order. For direct drawing scenarios, non-indexed direct drawing commands or indexed direct drawing commands are recorded in batches based on the metadata items, and the continuous drawing calls of the current drawing group are merged into batch commands. For indirect drawing scenarios, non-indexed indirect drawing commands or indexed indirect drawing commands are recorded, and the associated information of the indirect command buffer is also recorded.

[0015] Furthermore, after the D3D metadata UBO update is completed, a resource barrier is inserted, and the resource barrier entry mark is added to the command buffer.

[0016] Furthermore, when the kernel receives a command buffer containing non-indexed indirect drawing commands or indexed indirect drawing commands, it extracts the indirect command buffer handle, offset, number of drawing calls, and command step size from the command parameters; maps the memory of the indirect command buffer to the kernel address space, obtains the kernel virtual address, and sets the mapping permission to read-only; it traverses each command in the indirect command buffer according to the command step size, extracts the total number of vertices, total number of instances, starting vertex, and starting instance required for the current indirect drawing; and supplements the obtained data into the original Vulkan indirect command structure fields of the D3D metadata. When the kernel receives a command buffer containing non-indexed nested indirect drawing commands or indexed nested indirect drawing commands, it extracts the indirect command buffer handle, offset, number of drawing calls, command step size, count buffer handle, count offset, and count type from the command parameters, maps the count buffer to read the actual number of drawing calls, recursively parses the nested indirect command buffers, and marks in the D3D metadata whether the current drawing call is a nested indirect scene and the parsing status of the count buffer and the indirect command buffer.

[0017] Furthermore, for the vertex shader, metadata reading instructions and vertex data reading instructions are executed in parallel. In multi-view scenarios, an extended output structure is added with a view identifier field, and a default view is used when the view identifier goes out of bounds. For the geometry shader, the nested drawing number of metadata is read, and the input or output topology type and maximum number of vertices are dynamically adjusted according to the primitive topology type of the metadata. For the tessellation surface shader, the view identifier is added as control point data in the TCS stage, so that each control point carries view information independently. In the TES stage, the view identifier is read and combined with the tessellation factor in the metadata to adjust the vertex position.

[0018] Furthermore, the mapping dictionary is established as follows:

[0019] Traverse the abstract syntax tree of the HLSL shader, identify the system values ​​that the D3D12 shader depends on, and map them to class A of metadata requirements when only SV_VertexID is depended on, class B of metadata requirements when SV_VertexID and SV_InstanceID are depended on, class C of metadata requirements when SV_VertexID and SV_DrawID are depended on, and class D of metadata requirements when SV_VertexID, SV_InstanceID, SV_DrawID and SV_ViewID are depended on.

[0020] Furthermore, the method for determining the grouping conditions of D3D metadata based on the mapping dictionary, and thereby determining the metadata group corresponding to the D3D metadata, is as follows:

[0021] When the higher priority grouping conditions are the same, and the lower priority grouping conditions are different and there is no conflict, the D3D metadata is grouped according to the highest priority grouping condition, and the metadata group to which the D3D metadata belongs is determined. The grouped D3D metadata needs to be supplemented with the difference information related to the lower priority grouping conditions in its D3D metadata UBO.

[0022] When the newly generated D3D metadata does not meet the currently selected grouping conditions or cannot supplement the difference information related to lower priority grouping conditions, or when the number of used metadata items in the metadata group reaches the maximum value, or when the newly generated D3D metadata is nested indirect drawing while the current metadata group is indirect or direct drawing, the current grouping process is terminated and a new metadata group is created.

[0023] The grouping conditions, in descending order of priority, include metadata requirement type, pipeline status hash, resource binding topology, and drawing parameter feature code.

[0024] Beneficial effects:

[0025] This invention establishes the structure and global index format of D3D metadata during the VKD3D compilation phase, creates D3D metadata UBOs at startup, and initializes a four-level storage structure. When the D3D application executes, VKD3D intercepts operations such as resource binding, dynamic state configuration, multi-view settings, and drawing calls, captures relevant parameters, and combines them with kernel parsing to generate complete D3D metadata. Simultaneously, it traverses the HLSL shader abstract syntax tree to identify system value dependencies and map them to metadata requirement types. The metadata is grouped according to the priority of metadata requirement type, pipeline state hash, resource binding topology, and drawing parameter feature code. The grouped metadata is written into the corresponding metadata group's UBO according to single-view or multi-view scenes and a global index is allocated. The metadata groups are merged into drawing groups, the UBOs are bound, dynamic states and batch drawing commands are recorded and resource barriers are inserted, and relevant markers are added to the command buffer. After receiving the command buffer, the kernel parses ordinary indirect commands and nested indirect commands and supplements the metadata. Finally, the command buffer is submitted to the GPU, and the GPU executes the drawing commands to complete the rendering. Attached Figure Description

[0026] Figure 1 This is a flowchart illustrating a Direct3D 12 to rendering metadata mapping method based on kernel-level nested parsing provided by the present invention. Detailed Implementation

[0027] The present invention will be described in detail below with reference to the accompanying drawings and embodiments.

[0028] This invention provides a Direct3D12 to rendering metadata mapping method based on kernel-level nested parsing. The core idea is as follows: During the VKD3D compilation phase, a structure and global index format for D3D metadata are established. At startup, D3D metadata UBOs are created, and a four-level storage structure is initialized. When the D3D application executes, VKD3D intercepts operations such as resource binding, dynamic state configuration, multi-view settings, and drawing calls, captures relevant parameters, and combines them with kernel parsing to generate complete D3D metadata. Simultaneously, it traverses the HLSL shader abstract syntax tree to identify system value dependencies and map them to metadata requirement types. Metadata is grouped according to the priority of metadata requirement type, pipeline state hash, resource binding topology, and drawing parameter feature codes. The grouped metadata is written to the corresponding metadata group's UBO according to single-view or multi-view scenes and a global index is allocated. The metadata groups are merged into drawing groups, UBOs are bound, dynamic states and batch drawing commands are recorded, and resource barriers are inserted. Relevant markers are added to the command buffer. After receiving the command buffer, the kernel parses ordinary indirect commands and nested indirect commands and supplements the metadata. Finally, the command buffer is submitted to the GPU, and the GPU executes the drawing commands to complete rendering.

[0029] This invention provides a method for mapping Direct3D12 to rendering metadata based on kernel-level nested parsing, the processing flow of which is as follows: Figure 1 As shown, the specific steps include:

[0030] Step 1: During the VKD3D compilation phase, a structure called D3D12DrawMetadata is established, which contains fields containing semantics of input parameters or system values ​​extracted from the D3D12 drawing interface and related interfaces, as well as fields supplemented, calculated, or parsed by VKD3D; and a global index format for single-view and multi-view applications is established.

[0031] Specifically, the structure of D3D12DrawMetadata in D3D metadata is as follows:

[0032] typedefstruct_D3D12DrawMetadata{

[0033] uint32_tDrawID; / / Corresponds to SV_DrawID, a globally unique drawing call ID.

[0034] uint32_tInstanceID; / / Corresponds to SV_InstanceID, instance index (for instantiating and drawing the scene).

[0035] uint32_tVertexID; / / Corresponds to SV_VertexID, vertex index

[0036] uint32_tViewID; / / Corresponds to SV_ViewID, view index (for multi-view scenarios, such as VR)

[0037] uint32_tBaseVertexLocation; / / Starting vertex position (DrawIndexed series interface)

[0038] uint32_tBaseInstanceLocation; / / Instance starting position (for instantiating the drawing interface)

[0039] uint32_tNumVertices; / / Number of vertices

[0040] uint32_tNumInstances; / / Number of instances

[0041] uint32_tNumViews; / / Number of views (for multi-view scenarios)

[0042] uint32_tIndirectCommandOffset; / / Offset of the indirect command in the buffer (for indirect scene drawing)

[0043] uint32_tIndirectCountOffset; / / Offset of the indirect command count buffer (DrawIndirectCount scenario)

[0044] VkRect2DScissorRect; / / Clipping rectangle (dynamic state parameter, used for grouping)

[0045] VkViewportViewport; / / Viewport parameter (dynamic state parameter, used for grouping)

[0046] VkDrawIndirectCommandRawIndirectCmd; / / Raw Vulkan indirect command structure (used for kernel pre-parsing supplementation)

[0047] VkDrawIndirectCountCommandRawIndirectCountCmd; / / Raw Vulkan indirect count command structure

[0048] }D3D12DrawMetadata;

[0049] Among them, the vertex index VertexID, view index ViewID, vertex start position BaseVertexLocation, instance start position BaseInstanceLocation, number of vertices NumVertices, number of instances NumInstances, number of views NumViews, indirect command buffer offset IndirectCommandOffset, indirect command count buffer offset IndirectCountOffset, clipping rectangle ScissorRect, and viewport parameter Viewport are all directly extracted from D3D12 interface parameters, system value semantics, or dynamic states; DrawID is supplemented by VKD3D calculation and generated by a global atomic counter maintained by VKD3D, with an initial value of 0, incrementing by 1 for each captured drawing call to ensure uniqueness across command buffers and threads; the initial value of InstanceID is taken from the BaseInst of the D3D12 drawing interface. The `BaseInstanceLocation` parameter is dynamically adjusted by VKD3D based on the instantiated drawing group. `VkDrawIndirectCommandRawIndirectCmd` is generated by parsing the ordinary indirect command buffer using the Linux kernel's `VKD3D_indirect_cmd_parse` function, corresponding to the `VkDrawIndirectCommand` structure. `VkDrawIndirectCountCommandRawIndirectCountCmd` is generated by parsing the nested indirect command buffer using the Linux kernel's `VKD3D_nested_indirect_cmd_parse` function, corresponding to the `VkDrawIndirectCountCommand` structure. `IsNestedIndirect` is a nesting flag, a boolean field added by the kernel after parsing nested indirect commands, used to mark whether the current drawing call is a nested indirect scenario.

[0050] Specifically, the global index format for a single view is 20 bits, including a 10-bit group index and a 10-bit intra-group index, while the global index format for multiple views is 20 bits, including a 10-bit group index, a 3-bit view index, and a 7-bit intra-group index.

[0051] In addition, a shared memory structure MetaSyncInfo can be established, with a fixed layout of atomic markers such as metadata validity and indirect command parsing status. The extended shared memory synchronization structure MetaSyncInfo contains fields such as metadata validity markers, indirect command parsing markers, nested indirect command ready markers, and group indexes, providing a foundation for user-mode and kernel-mode synchronization.

[0052] Step 2: When VKD3D starts, it creates a D3D metadata UBO to store D3D metadata. The D3D metadata UBO is CPU writable and GPU accessible. It creates and initializes a metadata group to store the D3D metadata UBO, and initializes a four-level storage structure including a global index pool, metadata group, view metadata sub-table, and metadata items. The global index pool is used to store the allocated metadata group, the metadata group is used to store the D3D metadata UBO, the view metadata sub-table is used to store the metadata offset of all drawing calls under the view, and the metadata items are used to store D3D metadata.

[0053] The method for creating a storage container metadata group for D3D metadata UBOs that is writable by the CPU and accessible by the GPU is as follows: Create a UBO buffer to store D3D metadata as the storage carrier of D3D metadata on the GPU side, set its unified buffer and transmission target, set it to exclusive mode, and set its size to the product of the size of the metadata group and the size of a single metadata structure; allocate physical memory for the UBO buffer, and ensure that the memory attributes simultaneously satisfy CPU writability and GPU accessibility; bind the UBO buffer to the physical memory, and then map the physical memory on the GPU side to the CPU's virtual address space; initialize the number of used metadata items in the metadata group and the globally unique identifier of the metadata group to 0, and initialize the metadata group to adapt to a single-view scene.

[0054] Specifically, in the four-level storage structure, the GlobalMetaPool is used to store all allocated metadata groups, implemented using a dynamic array where each element is a MetaGroup pointer, with an initial capacity of 128; each MetaGroup corresponds to a VulkanUBO, used to store a fixed number of D3D metadata instances, with a newly added viewMetaSubtable field for storing sub-metadata in multi-view scenarios; each ViewMetaSubtable corresponds to a ViewID, storing the metadata offsets of all drawing calls under that view, supporting independent synchronization of multi-view metadata; and each D3D12DrawMetadata item corresponds to the complete metadata of a D3D12 drawing call.

[0055] Step 3: The D3D application starts and executes. When the application performs resource binding operations, VKD3D reserves a D3D metadata UBO descriptor slot in the root signature when creating the root signature, and binds the slot to the D3D metadata UBO when setting the root signature. When the application performs dynamic state configuration operations, VKD3D captures the viewport parameter when setting the viewport and captures the clipping rectangle parameter ScissorRect when setting the clipping rectangle.

[0056] When the application executes multi-view configuration to set the view instance mask, VKD3D parses the view index parameter, extracts the ViewID from the ViewInstanceMask parameter, and extracts the corresponding total number of views NumViews from the multi-view related interface parameters.

[0057] When an application executes a draw call operation, VKD3D captures input parameters to extract the vertex index (VertexID), vertex start position (BaseVertexLocation), instance start position (BaseInstanceLocation), number of vertices (NumVertices), and number of instances (NumInstances) when performing direct drawing of a scene, and generates a DrawID using a global atomic counter. When performing indirect drawing of a scene, it captures basic parameters to extract the offset of the indirect command in the buffer (IndirectCommandOffset), and the Linux kernel's VKD3D_indirect_cmd_parse function parses the indirect command buffer to generate an indirect command structure (Vk). When executing nested indirect drawing, `DrawIndirectCommandRawIndirectCmd` captures nested parameters, extracts the indirect command count buffer offset `IndirectCountOffset`, and recursively parses the nested parameters by the kernel function `VKD3D_nested_indirect_cmd_parse` to generate a Vulkan indirect count command structure `VkDrawIndirectCountCommandRawIndirectCountCmd`. A nesting flag `IsNestedIndirect` is added, and the count buffer is parsed to obtain the nested drawing count `nestedDrawCount`, thus completing the construction of D3D metadata.

[0058] Furthermore, multi-dimensional validation is performed on the constructed D3D metadata, including basic validation, indirect command validation, multi-view validation, and dynamic state validation. If the validation fails, DXGI_ERROR_INVALID_CALL is returned and an error log is recorded, including error fields and call stack.

[0059] Step 4: Traverse the abstract syntax tree of the HLSL shader, identify the system values ​​that the D3D12 shader depends on, and map them to class A of metadata requirements when only SV_VertexID is depended on, class B of metadata requirements when SV_VertexID and SV_InstanceID are depended on, class C of metadata requirements when SV_VertexID and SV_DrawID are depended on, and class D of metadata requirements when SV_VertexID, SV_InstanceID, SV_DrawID and SV_ViewID are depended on. Establish a system value mapping dictionary.

[0060] Step 5: When continuously drawing and generating D3D metadata, determine the grouping conditions that the D3D metadata must meet based on the system value mapping dictionary; when the higher priority grouping conditions are the same, and the lower priority grouping conditions are different and there is no conflict, group the D3D metadata according to the highest priority grouping condition, determine the metadata group to which the D3D metadata belongs, and supplement the grouped D3D metadata with the difference information related to the lower priority grouping conditions in its D3D metadata UBO.

[0061] When the newly generated D3D metadata does not meet the currently selected grouping conditions or cannot supplement the difference information related to lower priority grouping conditions, or when the number of used metadata items in the metadata group reaches the maximum value, or when the newly generated D3D metadata is a nested indirect drawing while the current metadata group is an indirect or direct drawing, the current grouping process is terminated and a new metadata group is created.

[0062] The grouping conditions, in descending order of priority, include metadata requirement type, pipeline status hash, resource binding topology, and drawing parameter feature code.

[0063] Specifically, the method of grouping by pipeline status hash is as follows: calculate the 32-bit hash value of dynamic status parameters and multi-view parameters, and group consecutive draw calls with the same hash value into one draw group.

[0064] The grouping method based on the drawing parameter feature code is as follows: the feature code is generated based on the fixed parameters of the D3D12 drawing call. The constituent fields include: number of vertices, number of instances, primitive topology type, indirect command type and number of views. Each constituent field is converted into an 8-bit or 16-bit integer and concatenated into a 64-bit feature code. Drawing calls with the same and consecutive feature codes are grouped together.

[0065] The resource binding topology grouping method is as follows: describe the distribution of slots corresponding to the types of non-metadata resources bound to the drawing call, generate an code for each resource binding slot by slot number and resource type, and concatenate all slot codes in sequence to form a topology identifier. Drawing calls with the same and consecutive topology identifiers are grouped together.

[0066] The grouping method based on metadata requirement type is as follows: based on the identified system value dependencies of the shader, each draw call is labeled with a requirement type, and draw calls with the same and consecutive requirement types are grouped together.

[0067] Step 6: Add the determined grouped D3D metadata to the corresponding metadata group. If the number of used metadata items in the metadata group is less than the size of the metadata group, it means that there is still free space in the current metadata group, so the free space is reused. When the number of views of the D3D metadata is greater than 1, it means that it is a multi-view scenario. In this case, the offset of the metadata item is recorded in the view metadata sub-table of the current metadata group, the D3D metadata is written to the D3D metadata UBO, the number of used metadata items is incremented by 1, a global index is allocated for the D3D metadata including the global unique identifier of the metadata group, the view index, and the group index, and the global index is written to the global index pool. When the number of views of the D3D metadata is 1, it means that it is a single-view scenario. In this case, the D3D metadata is written to the D3D metadata UBO, the number of used metadata items is incremented by 1, and a global index is allocated for the D3D metadata including the metadata group identifier and the group index.

[0068] If the number of used metadata items in a metadata group is not less than the size of the metadata group, it means that the current metadata group is full. In this case, a new metadata group is created, its index is set to the previous group's index incremented by 1, the metadata group is initialized, and then, depending on whether it is a single-view or multi-view scenario, the metadata items are written to the UBO of the new metadata group and a global index of the corresponding format is allocated.

[0069] When writing D3D metadata to D3D metadata UBO, the write address is pMappedMemory + usedCount * sizeof(D3D12DrawMetadata), where pMappedMemory is the virtual address of UBO mapped to the CPU, and usedCount is the number of used metadata items.

[0070] Step 7: Merge metadata items within the metadata group into the same drawing group, and bind the D3D metadata UBO corresponding to the current drawing group to the D3D metadata UBO descriptor slot reserved by Vulkan; if the dynamic state of all metadata items in the current drawing group is the same, record the dynamic state setting command only once; otherwise, record the dynamic state setting commands sequentially according to the drawing call order; for direct drawing scenarios, record non-indexed direct drawing commands or indexed direct drawing commands in batches according to the metadata items, and merge the continuous drawing calls of the current drawing group into batch commands; for indirect drawing scenarios, record non-indexed indirect drawing commands or indexed indirect drawing commands, and record the association information of the indirect command buffer at the same time, thereby completing the serialization and writing of various drawing-related instructions into the Vulkan command buffer.

[0071] Furthermore, after the D3D metadata UBO is updated, a resource barrier is inserted to ensure that the UBO has been updated before the GPU reads the metadata; in the VKD3D command buffer, the index of the metadata group corresponding to all its drawing groups, the view index in the multi-view scene, and the resource barrier entry mark are added.

[0072] Step 8: Submit the command buffer to the GPU. The GPU executes the drawing commands in the command buffer to complete the rendering.

[0073] Furthermore, in this invention, when the kernel receives a command buffer containing non-indexed indirect drawing commands or indexed indirect drawing commands, it extracts the indirect command buffer handle, offset, number of drawing calls, and command step size from the command parameters; maps the memory of the indirect command buffer to the kernel address space, obtains the kernel virtual address, and sets the mapping permission to read-only; it traverses each command in the indirect command buffer according to the command step size, extracts the total number of vertices, total number of instances, starting vertex, and starting instance required for the current indirect drawing; and supplements the obtained data into the VkDrawIndirectCommandRawIndirectCmd field of the original Vulkan indirect command structure in the D3D metadata. When the kernel receives a command buffer containing non-indexed nested indirect drawing commands or indexed nested indirect drawing commands, it extracts the indirect command buffer handle, offset, number of drawing calls, command step size, count buffer handle, count offset, and count type from the command parameters, maps the count buffer to read the actual number of drawing calls, recursively parses the nested indirect command buffer, and marks in the D3D metadata whether the current drawing call is a nested indirect scene and the parsing status of the count buffer and the indirect command buffer.

[0074] Furthermore, this invention optimizes the vertex shader, geometry shader, and subdivision surface shader respectively, specifically as follows:

[0075] For the vertex shader VS, metadata read instructions and vertex data read instructions are executed in parallel. In multi-view scenarios, the extended output structure adds a view identifier field, and a default view is used when the view identifier goes out of bounds. For the geometry shader GS, nestedDrawCount from the metadata is read, and the number of EmitVertex calls is controlled by instructions to avoid model duplication or missing data. The input or output topology type and maximum number of vertices are dynamically adjusted based on the PrimitiveTopology field in the metadata. For the subdivision surface shader TCS or TES, the view identifier is added as control point data in the TCS stage to ensure that each control point independently carries view information. In the TES stage, the view identifier is read and combined with the subdivision factor in the metadata to adjust the vertex position and ensure the synchronization of multi-view subdivision results.

[0076] Example:

[0077] This embodiment employs a kernel-level nested parsing-based Direct3D 12 to rendering metadata mapping method provided by this invention. It enables the normal operation of D3D 12 applications in a GPU hardware environment that does not support the Vulkan device feature of shaderDrawParameters. The specific process includes:

[0078] Full interception of S1, D3D12 drawing interfaces and related interfaces.

[0079] S1.1 Core Drawing Interface Interception: Modify the implementation of D3D12 drawing-related interfaces in the VKD3D source code involving device management and command list processing, including the core functions of ID3D12GraphicsCommandList such as DrawInstanced, DrawIndexedInstanced, DrawIndirect, DrawIndexedIndirect, DrawIndirectCount, and DrawIndexedIndirectCount. Add interception logic at the function entry point to capture all input parameters of D3D12 drawing calls (such as the number of vertices, the number of instances, and the indirect command buffer handle).

[0080] S1.2, Related Interface Interception: Added interception of interfaces related to D3D12 resource binding, dynamic status, and command list management to ensure the integrity of metadata transmission.

[0081] The root signature interface intercepts the ID3D12Device method CreateRootSignature and the ID3D12GraphicsCommandList method SetGraphicsRootSignature to reserve descriptor slots for metadata UBO.

[0082] The dynamic state interface intercepts the RSSetViewports and RSSetScissorRects methods of ID3D12GraphicsCommandList to capture dynamic viewport or clipping rectangle parameters for grouping rule determination.

[0083] The command list reuse interface intercepts the Reset method of ID3D12CommandAllocator and the Reset method of ID3D12GraphicsCommandList for associated recycling of the metadata index table;

[0084] The multi-view interface intercepts the SetViewInstanceMask method of ID3D12GraphicsCommandList to capture the view index (ViewID) parameter for multi-view metadata synchronization.

[0085] S1.3 Metadata Field Extraction and Expansion: For different drawing interfaces and associated interfaces, extract the core metadata fields corresponding to D3D12 system values, expand the D3D12DrawMetadata structure (sorted according to memory alignment requirements, using 4-byte alignment), and add fields related to multiple views and dynamic states:

[0086] typedef struct _D3D12DrawMetadata {

[0087] uint32_t DrawID; / / Corresponds to SV_DrawID, a globally unique drawing call ID.

[0088] uint32_t InstanceID; / / Corresponds to SV_InstanceID, instance index (for instantiating and drawing the scene).

[0089] uint32_t VertexID; / / Corresponds to SV_VertexID, vertex index

[0090] uint32_t ViewID; / / Corresponds to SV_ViewID, view index (for multi-view scenarios, such as VR)

[0091] uint32_t BaseVertexLocation; / / Starting vertex position (DrawIndexed series interface)

[0092] uint32_t BaseInstanceLocation; / / Instance starting position (for instantiating the drawing interface)

[0093] uint32_t NumVertices; / / Number of vertices

[0094] uint32_t NumInstances; / / Number of instances

[0095] uint32_t NumViews; / / Number of views (for multi-view scenarios)

[0096] uint32_t IndirectCommandOffset; / / Offset of the indirect command in the buffer (for indirect scene drawing)

[0097] uint32_t IndirectCountOffset; / / Offset of the indirect command count buffer (DrawIndirectCount scenario)

[0098] VkRect2D ScissorRect; / / Clipping rectangle (dynamic state parameter, used for grouping)

[0099] VkViewport Viewport; / / Viewport parameters (dynamic state parameters, used for grouping)

[0100] VkDrawIndirectCommand RawIndirectCmd; / / Raw Vulkan indirect command structure (used for kernel pre-parsing supplementation)

[0101] VkDrawIndirectCountCommand RawIndirectCountCmd; / / Raw Vulkan indirect count command structure

[0102] } D3D12DrawMetadata;

[0103] Among them, DrawID is generated using a global atomic counter (with an initial value of 0, incrementing by 1 for each captured draw call), ensuring uniqueness across command buffers and threads; the initial value of InstanceID is BaseInstanceLocation, and it is dynamically adjusted subsequently according to the grouping of instance draws; ViewID is parsed from the ViewInstanceMask parameter of the SetViewInstanceMask interface (e.g., ViewID = ViewInstanceMask & 0xFF); ScissorRect and Viewport are captured from the dynamic state interface and used for grouping rule judgment; other fields are directly extracted from the input parameters of the D3D12 draw interface.

[0104] S1.4. Enhanced metadata validity verification: After extracting the metadata, add multi-dimensional verification logic.

[0105] Basic verification: Check whether NumVertices and NumInstances are non-zero values to avoid invalid draw calls;

[0106] Indirect command verification: In the case of indirect drawing scenarios, verify the address validity of the indirect command buffer and the count buffer. Confirm through the resource tracking module of VKD3D that the buffer is bound, accessible, and the memory state is D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT;

[0107] Multi-view verification: In multi-view scenarios, check whether NumViews matches the ViewID range (ViewID < NumViews) to avoid view index out-of-bounds;

[0108] Dynamic state verification: Check whether the width and height of the Viewport are positive numbers and whether the coordinates of the ScissorRect are within the viewport range to avoid illegal rendering parameters;

[0109] When the verification fails, return DXGI_ERROR_INVALID_CALL according to the D3D12 specification and record detailed logs, including error fields and call stack information.

[0110] S2. Structured construction and dynamic management of the metadata index table.

[0111] S2.1. Optimization of the core structure of the index table. Add a MetaIndexTableManager module in VKD3D to be responsible for the storage, index management, and dynamic resource regulation of metadata. Define a four-level structure (add a view metadata sub-table to adapt to multi-view scenarios):

[0112] The GlobalMetaPool stores all allocated metadata groups. It is implemented using a dynamic array, with each element being a MetaGroup pointer. The initial capacity is 128. The expansion strategy doubles the capacity when the utilization rate is ≥80%, and the shrinkage strategy halves the capacity when the utilization rate is ≤20% and the capacity is ≥256, thus avoiding memory redundancy.

[0113] MetaGroups, each corresponding to a Vulkan UBO, store a fixed number of D3D12DrawMetadata instances. The group size GROUP_SIZE is calculated using the following formula: GROUP_SIZE = floor(MAX_UBO_SIZE / sizeof(D3D12DrawMetadata)). MAX_UBO_SIZE is obtained by querying the Vulkan physical device's VkPhysicalDeviceLimits method maxUniformBufferRange (normally 64KB) using vkGetPhysicalDeviceProperties2. After calculation, GROUP_SIZE is fixed at 1024. When sizeof(D3D12DrawMetadata) is 48 bytes, 64KB / 48B ≈ 1365, rounded to 1024 for redundancy. Each MetaGroup also includes a viewMetaSubtable field (a dynamic array) to store sub-metadata in multi-view scenarios.

[0114] The ViewMetaSubtable is a subtable that corresponds to a view (ViewID) and stores the metadata offsets of all drawing calls under that view. It supports independent synchronization of metadata for multiple views.

[0115] Metadata items (D3D12DrawMetadata) each correspond to the complete metadata of a D3D12 drawing call.

[0116] S2.2 Enhanced creation and initialization of metadata groups: When MetaIndexTableManager is initialized, the first MetaGroup is created, and the following operations are performed:

[0117] Call vkCreateBuffer to create a UBO buffer with the following parameters: usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT (adds the purpose of transmission target, supports batch updates), sharingMode = VK_SHARING_MODE_EXCLUSIVE, size = GROUP_SIZE * sizeof(D3D12DrawMetadata);

[0118] The system calls `vkGetMemoryRequirements` to obtain the buffer memory requirements, and then uses `vkGetPhysicalDeviceMemoryProperties` to select the memory attributes as `VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT` (prioritizing device local memory to reduce GPU access latency). Finally, it calls `vkCreateDeviceMemory` to allocate the memory.

[0119] Call vkBindBufferMemory to bind the buffer to memory;

[0120] Map memory to user-space address space: Obtain the CPU virtual address of UBO through vkMapMemory, set flags = VK_MEMORY_MAP_RANGE_WRITE_BIT | VK_MEMORY_MAP_RANGE_INVALIDATE_RANGE_BIT (to optimize write performance), and store it as the MetaGroup method pMappedMemory. Subsequent metadata writes will directly operate on this address.

[0121] The MetaGroup's usedCount (number of used metadata items) is initialized to 0, the MetaGroup's groupIndex (globally unique group index) is initialized to 0, and the MetaGroup's viewMetaSubtable capacity is NumViews (initially 1, dynamically expanded in multi-view scenarios).

[0122] S2.3, Detailed Metadata Index Allocation Process: When MetaIndexTableManager receives the D3D12DrawMetadata extracted in step 1, it performs index allocation.

[0123] Check if the usedCount of the current last MetaGroup is less than GROUP_SIZE:

[0124] If so, determine if it is a multi-view scenario (NumViews > 1):

[0125] In a multi-view scenario: Record the metadata offset (usedCount) in viewMetaSubtable[ViewID]. Write the metadata to the address of pMappedMemory + usedCount * sizeof(D3D12DrawMetadata) for this group, update usedCount by incrementing it by 1, and assign a global index of (groupIndex << 10) | (ViewID << 7) | (usedCount - 1) (10-bit group index, 3-bit view index, 7-bit intra-group index, totaling 20 bits, supporting 1024 groups, 8 views, and 128 intra-group items).

[0126] In a single-view scenario: metadata is written directly, and the allocated global index is (groupIndex << 10) | (usedCount - 1) (10 bits for the group index, 10 bits for the intra-group index, for a total of 20 bits).

[0127] If not, create a new MetaGroup, increment the groupIndex of the previous group index by 1, write metadata according to single-view or multi-view scenarios, set usedCount to 1, and allocate the corresponding global index.

[0128] S2.4, Extension of metadata recycling and reuse mechanism.

[0129] Regular recycling: When the VKD3D command buffer is reset (ID3D12CommandAllocator's Reset method) or a draw call is canceled, MetaIndexTableManager receives the recycling notification, traverses all metadata items associated with the command buffer, marks them as free through the freeSlots bitmap in MetaGroup (each bit corresponds to an index within the group, 1 indicates free), and reuses them in the future.

[0130] Command list reuse and recycling: When the ID3D12GraphicsCommandList method Reset (command list reset and reuse) is called, MetaIndexTableManager uses the command list's metaIndexCache field (used to store the metadata index of the last recorded data) to recycle the associated metadata items in batches, while retaining the MetaGroup and viewMetaSubtable structures (to avoid duplicate creation), and only clearing the metadata content and freeSlots bitmap;

[0131] Resource release: When all metadata items in MetaGroup are idle and the GlobalMetaPool usage is ≤20%, call vkUnmapMemory, vkDestroyBuffer, and vkFreeMemory to release the resources of the group and remove the group pointer from GlobalMetaPool; in multi-view scenarios, release the dynamic array memory of viewMetaSubtable first.

[0132] S2.5, multi-threading and multi-view metadata synchronization.

[0133] Multi-threaded synchronization: The MetaIndexTableManager maintains a global atomic counter g_GlobalDrawID (std method atomic).<uint32_t> Each thread obtains a unique DrawID by using g_GlobalDrawID.fetch_add(1, std's method memory_order_relaxed) when recording a drawing call; each thread maintains a ThreadLocalMetaCache (thread-local cache) to cache metadata items to be submitted, and writes them to the MetaGroup in batches when submitting to reduce lock contention;

[0134] Multi-view synchronization: In a multi-view scenario, each ViewMetaSubtable maintains an independent atomic marker viewMetaValid(std method atomic) <bool>GPU access to metadata UBO is only allowed when all views have viewMetaValid set to true. VKD3D inserts a memory barrier (srcStageMask = VK_PIPELINE_STAGE_HOST_BIT, dstStageMask = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT) via vkCmdPipelineBarrier to ensure that metadata from multiple views is synchronously visible.

[0135] S3. Aggregation of drawing calls based on multi-dimensional deterministic grouping.

[0136] S3.1 Grouping Pre-processing: Root Signature Metadata Slot Reservation: When the CreateRootSignature method of ID3D12Device is intercepted, VKD3D automatically reserves a metadata UBO descriptor slot in the D3D12 root signature (fixed as root parameter index VKD3D_META_ROOT_PARAM_INDEX = 1, descriptor type D3D12_DESCRIPTOR_RANGE_TYPE_CBV), and maps this slot to a fixed binding slot of Vulkan (VKD3D_META_UBO_BINDING_SLOT = 1) when converting to Vulkan descriptor set layout; when the application sets the root signature (SetGraphicsRootSignature), VKD3D automatically binds the metadata UBO to the reserved slot to avoid resource conflicts.

[0137] S3.2, Grouping method implementation.

[0138] Pipeline status hash grouping:

[0139] The hash input extension adds dynamic state parameters (viewport width and height, ScissorRect bottom right corner coordinates) and multiple view parameters (NumViews) to the original input, ensuring that drawing calls with the same dynamic state and view configuration are grouped together.

[0140] Hash calculation uses the MurmurHash3 algorithm to calculate a 32-bit hash value and quantifies dynamic state parameters (such as retaining integer bits for the width and height of the viewport to avoid different hash values ​​due to differences in floating-point precision).

[0141] Grouping rules: consecutive draw calls with the same hash value are grouped into one draw group (DrawGroup), and each DrawGroup corresponds to one MetaGroup.

[0142] Plotting parameter feature code grouping:

[0143] The feature code is generated based on fixed parameters of the D3D12 drawing call. The constituent fields include: NumVertices (number of vertices), NumInstances (number of instances), PrimitiveTopology (primitive topology type, such as triangle list or strip), IndirectType (indirect command type, such as normal indirect or counted indirect), and ViewCount (number of views).

[0144] The feature code calculation converts each constituent field into an 8-bit or 16-bit integer (e.g., NumVertices takes the lower 16 bits, PrimitiveTopology takes the lower 8 bits), and concatenates them into a 64-bit feature code (uint64_t). No hash calculation is required; the group is determined directly by numerical comparison.

[0145] Grouping rules group consecutive draw calls with the same signature into one group. This is suitable for scenarios where draw parameters are fixed but pipeline states are slightly different (e.g., different textures but the same number of vertices / topology), reducing the need for group splitting.

[0146] Resource binding topology grouping:

[0147] Resource binding topology definition describes the type and slot distribution of non-metadata resources (textures, samplers, other UBOs) bound to the drawing call, such as slot 2 for texture 2D, slot 3 for sampler, and slot 4 for UBO;

[0148] Topology identifier generation: For each resource, bind a slot and generate an 8-bit code according to the slot number (4 bits) and resource type (4 bits, such as texture 2D=01, sampler=02, UBO=03). Concatenate all the slot codes in order to form a topology identifier (e.g., the codes for slots 2, 3, and 4 are 2-01-3-02-4-03).

[0149] Grouping rules group consecutive draw calls with the same topology identifier into one group to ensure that the layout of non-metadata resources accessed by draw calls within the group is consistent, avoiding UBO access conflicts caused by differences in resource binding. This is suitable for scenarios where pipeline states are different but resource binding layouts are the same (such as different shaders but consistent texture slots).

[0150] Metadata requirement type grouping:

[0151] Based on the system values ​​that the D3D12 shader depends on, draw calls are classified into four types: Type A: SV_VertexID only, Type B: SV_VertexID and SV_InstanceID required, Type C: SV_VertexID and SV_DrawID required, and Type D: SV_VertexID, SV_InstanceID, SV_DrawID, and SV_ViewID required (for multi-view scenarios).

[0152] Type determination is performed by using the D3D12SystemValueDetector module to identify the system value dependencies of the shader and to mark the requirement type for each drawing call.

[0153] The grouping rule groups consecutive drawing calls of the same type together to avoid mixing drawing calls of different types (e.g., mixing Type A and Type D would lead to redundant metadata UBO storage). This is suitable for scenarios with significant differences in metadata dependencies.

[0154] S3.3 Grouping Priority and Merging Logic.

[0155] Grouping priority is determined according to the order from metadata requirement type, pipeline status hash, resource binding topology to drawing parameter feature code, to ensure that core metadata dependencies are satisfied first, and then other features are aggregated.

[0156] Merging is triggered when consecutive draw calls meet the same high-priority grouping conditions and different low-priority grouping conditions, and can be merged into a DrawGroup (e.g., the same requirement type and pipeline hash, but different resource topologies but no conflict). However, the resource topology difference field needs to be added to the metadata UBO.

[0157] Group termination conditions: The current DrawGroup is terminated and a new group is created when the following conditions are met: the metadata requirement type of the new draw call is different from that of the current group; the pipeline state hash or resource binding topology of the new draw call is different from that of the current group and cannot be made compatible by supplementing metadata; the usedCount of the current MetaGroup reaches GROUP_SIZE; the new draw call is a nested indirect draw, while the current group is a normal indirect or direct draw.

[0158] S3.4, Command buffer recording and resource barrier synchronization.

[0159] Within a DrawGroup, VKD3D performs the following operations when recording Vulkan commands for each DrawGroup:

[0160] Bind the metadata UBO by calling vkCmdBindDescriptorSets to bind the current MetaGroup's UBO to VKD3D_META_UBO_BINDING_SLOT;

[0161] For dynamic state settings, if the dynamic states (viewport or clipping rectangle) called during drawing within the group are the same, vkCmdSetViewport and vkCmdSetScissor will only be recorded once; if they are different, they will be recorded in the order of drawing calls, but it will be ensured that dynamic state switching does not affect metadata access.

[0162] Batch drawing commands: Directly draw scenes and record in batches using vkCmdDraw or vkCmdDrawIndexed; Indirectly draw scenes and record in batches using vkCmdDrawIndirect or vkCmdDrawIndexedIndirect, and record the indirect command buffer association information.

[0163] After resource barrier insertion and metadata UBO update (after user-space writing or kernel pre-parsing), record the vkCmdPipelineBarrier command and set the following:

[0164] srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;

[0165] dstAccessMask = VK_ACCESS_UNIFORM_READ_BIT;

[0166] srcStageMask = VK_PIPELINE_STAGE_HOST_BIT;

[0167] dstStageMask = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_GEOMETRY_BIT;

[0168] Ensure that UBO has been updated before the GPU reads the metadata.

[0169] S3.5 Enhanced association between command buffer and metadata group: The following fields have been added to the VKD3DCommandBuffer structure of VKD3D:

[0170] metaGroupIndices: A dynamic array that stores the groupIndex of the MetaGroup corresponding to all DrawGroups in this command buffer;

[0171] viewMetaIndices: A dynamic array that stores the ViewMetaSubtable indices in multi-view scenarios;

[0172] metaBarrierRecorded: Boolean value, indicating whether a resource barrier for recording metadata (UBO) has been established;

[0173] When the command buffer is committed (the `ExecuteCommandLists` method of `ID3D12CommandQueue`), `MetaIndexTableManager` quickly locates the metadata groups and sub-tables that need to be synchronized through `metaGroupIndices` and `viewMetaIndices`, and checks `metaBarrierRecorded` to ensure that the barrier has been recorded, thus preventing the GPU from accessing invalid data.

[0174] S4, Linux kernel-level nested indirect command pre-parsing.

[0175] S4.1 Kernel Module Extension Enhancement: Modify the Linux kernel's Vulkan command processing subsystem, adding two new functions: VKD3D_indirect_cmd_parse (normal indirect command parsing) and VKD3D_nested_indirect_cmd_parse (nested indirect command parsing). These functions are registered in the Vulkan command buffer submission path and executed before being submitted to the GPU. A new function, VKD3D_indirect_cmd_cache (indirect command cache), is added to store parsed indirect commands and avoid duplicate parsing.

[0176] S4.2, Normal Indirect Command Parsing Process: When the kernel receives a command buffer containing vkCmdDrawIndirect / vkCmdDrawIndexedIndirect, VKD3D_indirect_cmd_parse performs the following operations:

[0177] Extract command parameters: Extract the indirect command buffer handle (VkBuffer), offset, draw count, and stride (command step size) from the command parameters;

[0178] Buffer mapping: Call drm_vma_node_map to map the memory of the indirect command buffer to the kernel address space, obtain the kernel virtual address pKernelBuffer, and set the mapping permission to read-only to avoid accidental writing to kernel mode;

[0179] Command parsing: Iterate through each command in the indirect command buffer by stride (a total of drawCount commands). For each VkDrawIndirectCommand, extract:

[0180] vertexCount, a method of D3D12DrawMetadata called NumVertices;

[0181] instanceCount, a method of D3D12DrawMetadata called NumInstances;

[0182] The method BaseVertexLocation in D3D12DrawMetadata is used for firstVertex;

[0183] firstInstance, D3D12DrawMetadata method BaseInstanceLocation;

[0184] Metadata supplementation: Locate the corresponding metadata item through metaGroupIndices and viewMetaIndices in the command buffer, write the parsed fields into D3D12DrawMetadata, and update the RawIndirectCmd field;

[0185] The process involves caching and releasing the cache, storing the parsed results in VKD3D_indirect_cmd_cache (the cache key is the buffer handle and offset), and then calling drm_vma_node_unmap to unmap the buffer.

[0186] S4.3 Nested Indirect Command Parsing Process: When the kernel receives a nested indirect command containing vkCmdDrawIndirectCount and vkCmdDrawIndexedIndirectCount (i.e., the drawCount of the indirect command is specified by another count buffer), VKD3D_nested_indirect_cmd_parse performs the following operations:

[0187] Extract nested parameters, including not only ordinary indirect command parameters, but also the count buffer handle (countBuffer), count offset (countOffset), and count type (countType, such as VK_INDIRECT_COUNT_TYPE_UINT32).

[0188] The count buffer is parsed by calling drm_vma_node_map to map the count buffer and reading the count value (nestedDrawCount) at countOffset, which is the actual number of drawing calls.

[0189] Recursively parse, using nestedDrawCount as the new drawCount, and call VKD3D_indirect_cmd_parse to parse the nested indirect command buffer;

[0190] Nested marker: Set the IsNestedIndirect marker (a new boolean field) in the corresponding D3D12DrawMetadata and record the count buffer information for VKD3D user mode to determine whether it is a nested scene;

[0191] Multi-buffer synchronization uses the MetaSyncInfo feature in shared memory to mark the parsing status of the counting buffer and the indirect command buffer, ensuring that metadata is updated only after both have been parsed.

[0192] S4.4, Optimized shared memory synchronization mechanism.

[0193] The shared memory structure has been expanded by modifying the MetaSyncInfo structure and adding fields related to nested indirect commands.

[0194] typedef struct _MetaSyncInfo {

[0195] atomic_t metaValid; / / Metadata validity flag: 0 = not ready, 1 = ready

[0196] atomic_t indirectParsed; / / Indirect command parsing flag: 0 = unparsed, 1 = parsed

[0197] atomic_t nestedIndirectValid; / / Nested indirect command validity flag: 0 = not ready, 1 = ready

[0198] uint32_t groupIndex; / / Corresponding metadata group index

[0199] uint32_t viewIndex; / / The index of the corresponding view (in multi-view scenarios)

[0200] uint32_t usedCount; / / The number of metadata items used within the group

[0201] uint32_t nestedDrawCount; / / Number of draws from nested indirect commands

[0202] MetaSyncInfo;

[0203] Synchronization process:

[0204] After writing metadata to the VKD3D user space, call atomic_set(&pSyncInfo->metaValid, 1);

[0205] After parsing a regular indirect command, the kernel calls atomic_set(&pSyncInfo->indirectParsed, 1); after parsing a nested indirect command, it calls atomic_set(&pSyncInfo->nestedIndirectValid, 1) and writes nestedDrawCount.

[0206] Before the GPU executes, VKD3D confirms that all states are ready by atomic_read(&pSyncInfo->metaValid) && atomic_read(&pSyncInfo->indirectParsed).

[0207] S4.5, Extension of exception handling mechanism.

[0208] The added exception types include: Nesting depth exceeding the limit, when the depth of nested indirect commands is greater than 3 (configurable), -E2BIG is returned to avoid recursive parsing stack overflow; Illegal count buffer data, when nestedDrawCount is greater than MAX_DRAW_COUNT (e.g., 1048576), -EINVAL is returned; Cache conflict, when the same key already exists in VKD3D_indirect_cmd_cache but the data is inconsistent, -EEXIST is returned and parsing is re-executed; Exception notification, the kernel sends an exception signal to VKD3D user space via drm_signal_user_fence, VKD3D receives it and returns an error code according to the D3D12 specification, and records it in the kernel log, including the exception type, buffer address, and nesting depth.

[0209] Enhanced semantic adaptive mapping for S5 and HLSL-to-SPIR-V compilation.

[0210] S5.1 The HLSL system value semantic recognition module has been optimized. The VKD3D HLSL compiler extension module has been modified, and the D3D12SystemValueDetector submodule now recognizes semantics related to multi-view system values ​​and nested indirect commands.

[0211] Expanded recognition scope: In addition to SV_DrawID / SV_InstanceID / SV_VertexID, SV_ViewID (multi-view) and SV_IndirectDrawArgs (indirect command parameters) are now recognized.

[0212] Enhanced recognition logic: By traversing the AST, the semantic annotations of function parameters and structure fields are checked, such as uintviewID : SV_ViewID; and DrawArgs args : SV_IndirectDrawArgs;, and the field offset and data type corresponding to the semantics are recorded.

[0213] Requirement type association: The identified system value dependencies are mapped to metadata requirement types (e.g., if SV_ViewID is identified, it is mapped to Type D), and stored in the SystemValueMap dictionary for use by the grouping modules.

[0214] The S5.2 SPIR-V code generation rule extensions are shown in the table below:

[0215] Table 1 SPIR-V Code Generation Rule Extension Table

[0216] D3D12 system value SPIR-V code generation logic SV_DrawID 1. Declare a push constant variable: `OpVariable %PushConstantType %PushConstantSet %vkPushConstant(offset 0, uint32_t)`; 2. Declare a UBO variable: `OpVariable %MetaUBOType %MetaUBOSet %vkDescriptorSet1(binding slot 1, D3D12DrawMetadata array)`; 3. Extract indices: `OpLoad %uint %PushConstant 0` (group index), `OpLoad %uint %PushConstant 4` (intra-group index), `OpLoad %uint %PushConstant 8` (view index, multi-view scenario); 4. Calculate array indices: `OpIMul %uint %GroupIndex %GROUP_SIZE → OpIAdd %uint %Result %GroupInnerIndex` (single view); multi-view scenarios additionally execute `OpIMul %uint %ViewIndex`. 5. Access UBO: OpAccessChain %MetaPtr %MetaUBO %ArrayIndex → ​​OpLoad %uint %MetaPtr 0 (offset 0 is DrawID) SV_ViewID Similar to steps 1-4 of SV_DrawID, the offset in step 5 is 12 (the offset of ViewID in D3D12DrawMetadata). SV_IndirectDrawArgs 1. Calculate the array index according to steps 1-4 of SV_DrawID; 2. Access the RawIndirectCmd field of UBO: OpAccessChain %IndirectCmdPtr %MetaUBO %ArrayIndex 10 (offset 40 is RawIndirectCmd); 3. Extract indirect command parameters: OpLoad %VkDrawIndirectCommand %IndirectCmdPtr 0 → access fields such as vertexCount.

[0217] S5.3, Push Constant Layout Extension for Multi-View Adaptation: Defines an extended pushconstant layout, occupying the first 12 bytes (still below the Vulkan standard 128-byte limit):

[0218] OpTypeStruct %uint %uint %uint / / Three uint32_t fields: GroupIndex (offset 0), GroupInnerIndex (offset 4), ViewIndex (offset 8, for multi-view scenarios)

[0219] OpConstant %uint 0 %OffsetGroupIndex

[0220] OpConstant %uint 4 %OffsetGroupInnerIndex

[0221] OpConstant %uint 8 %OffsetViewIndex

[0222] The compiler automatically enables or disables the generation of the ViewIndex field based on whether it is a multi-view scenario, thus avoiding resource waste.

[0223] S5.4 Optimization of metadata passing in the multi-shader stage.

[0224] Vertex Shader (VS): In addition to retrieving metadata, a new metadata validity check instruction has been added. It checks whether the metadata is valid by accessing the DrawID of UBO and whether it is a non-zero value. If invalid, it returns a default value (such as 0).

[0225] Geometry Shader (GS): When handling nested indirect drawing, it automatically reads nestedDrawCount from the metadata to control the number of times EmitVertex is called, thus avoiding incorrect drawing counts.

[0226] Subdivision Surface Shader (TCS and TES): In multi-view scenarios, when TCS passes the ViewID to TES, it copies the metadata through the OpCopyObject instruction to avoid repeated access to UBO;

[0227] Fragment Shader (PS): If the PS relies on SV_DrawID to switch between multiple materials, the compiler automatically associates the DrawID with the material array index and generates the OpVectorShuffle instruction to optimize the index calculation.

[0228] S5.5 Enhanced compatibility verification of semantic mapping.

[0229] Add a new validation item:

[0230] In a multi-view scenario, check if ViewIndex is less than NumViews (verify by reading the NumViews field from UBO).

[0231] In nested indirect drawing scenarios, check if nestedDrawCount matches NumInstances;

[0232] Check if the total size of the push constant (12 bytes) does not exceed maxPushConstantSize;

[0233] Verification failure handling: In addition to outputting error logs, automatically downgrade to single-view or non-nested mode to ensure that basic rendering functions are available and avoid application crashes.

[0234] S6. Optimization of drawing call submission and metadata index transmission.

[0235] S6.1, Push Constant Data Packaging Extension: Before recording drawing commands, VKD3D executes the following packaging logic:

[0236] In a single-view scenario: the GlobalIndex is obtained from MetaIndexTableManager, parsed as GroupIndex = GlobalIndex >> 10 and GroupInnerIndex = GlobalIndex & 0x3FF, and packaged into 8-byte data;

[0237] In multi-view scenarios: additionally obtain the ViewIndex, parse it as ViewIndex = (GlobalIndex >> 7) & 0x7 (3-bit view index), and pack it into 12 bytes of data;

[0238] Nested indirection scenario: Mark the IsNested bit (31st bit, 1 indicates nesting) in the packaged data so that the shader can determine whether it is necessary to read nestedDrawCount.

[0239] S6.2 Enhanced recording of push constant update commands: When calling vkCmdPushConstants, the parameters are dynamically adjusted according to the scenario.

[0240] In a single-view scenario: size = 8, pData points to 8 bytes of packed data;

[0241] In a multi-view scenario: size = 12, pData points to 12 bytes of packed data;

[0242] Stage Flags: In multi-view scenarios, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT is added to cover the metadata access requirements of the TES stage.

[0243] S6.3, Refined control over the timing of UBO metadata updates.

[0244] Directly drawing the scene: Metadata is synchronously written to the UBO (through the MetaGroup method pMappedMemory) when the drawing call is recorded. After writing, vkFlushMappedMemoryRanges is called (only the current write range is refreshed to optimize performance).

[0245] In a typical indirect drawing scenario: After the user space writes the basic metadata, it waits for the kernel to complete the parsing (indirectParsed is 1) before writing the parsed indirect command parameters.

[0246] Nested indirect drawing scenario: First wait for the count buffer to be parsed (nestedIndirectValid is 1), then parse the nested indirect commands, and finally update the metadata to ensure the integrity of the metadata of the nested level.

[0247] S6.4, Optimized extension for multiple DrawGroup submissions.

[0248] Merging DrawGroups with the same MetaGroup: When multiple consecutive DrawGroups belong to the same MetaGroup, vkCmdBindDescriptorSets is recorded only once, reducing the number of commands;

[0249] Synchronous submission of DrawGroup for multiple views: In a multi-view scenario, the command buffer is submitted only after the DrawGroup of all views has been recorded, and the metadata UBO of all views is updated through vkCmdWaitEvents;

[0250] Nested indirect DrawGroup priority: Nested indirectly drawn DrawGroups have higher priority than ordinary DrawGroups. During recording, a barrier is inserted in the VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT stage to ensure that indirect commands are parsed before execution.

[0251] S7 enhances metadata consistency guarantees for the shader pipeline.

[0252] S7.1, Refinement of Vertex Shader Metadata Access Implementation.

[0253] Metadata read optimization: Insert UBO access instructions (OpAccessChain, OpLoad) at the very beginning of the shader entry function, in parallel with vertex data read instructions, to hide UBO access latency;

[0254] Multi-view metadata processing: After reading the ViewID, the OpBranchConditional directive is used to determine the view index range. If the range is exceeded, the default view (ViewID = 0) is used to avoid rendering errors.

[0255] Output struct extension: In multi-view scenarios, the VS output struct adds a ViewID field, such as:

[0256] struct VSOutput {

[0257] float4 pos : SV_POSITION;

[0258] uint DrawID : TEXCOORD0;

[0259] uint InstanceID : TEXCOORD1;

[0260] uint ViewID : TEXCOORD2; / / Multi-view metadata passing

[0261] };

[0262] S7.2 Enhanced geometry shader metadata processing for nested indirect scenes.

[0263] Nested drawing count control: GS reads nestedDrawCount from the metadata and controls the number of loops through the OpLoopMerge instruction to ensure that the number of EmitVertex calls is consistent with nestedDrawCount, thus avoiding model duplication and missing data.

[0264] Topology adaptation: Based on the PrimitiveTopology field in the metadata, dynamically adjust GS_INPUT_PRIMITIVE and GS_OUTPUT_PRIMITIVE. For example, when "triangle strip" is read, set [maxvertexcount(3)].

[0265] S7.3 Optimization of metadata passing for subdivision surface shaders.

[0266] TCS phase: ViewID is used as additional data for control points, with each control point carrying an independent ViewID to avoid subdivision misalignment under multiple views;

[0267] TES phase: Read the ViewID from the input control point through OpLoad, combine it with the subdivision factor (read from the metadata UBO), adjust the position of the subdivided vertices, and ensure that the subdivision results of multiple views are synchronized.

[0268] S7.4, Performance optimization extensions for metadata access.

[0269] Register caching: Store read metadata fields (DrawID, InstanceID, etc.) in shader general-purpose registers (such as %r1, %r2), and subsequent accesses can directly use the registers to avoid repeated access to the UBO;

[0270] Constant folding: For metadata calculations that can be determined at compile time (such as GroupIndex * GROUP_SIZE), the compiler calculates the results at compile time using the OpConstantComposite instruction, reducing the number of runtime instructions;

[0271] Multi-view instruction reuse: In multi-view scenarios, metadata access instructions for the same view are reused, distinguished only by the difference in ViewID offset, reducing SPIR-V code size.

[0272] S8, memory optimization for instantiation drawing and enhanced buffer reuse.

[0273] S8.1, Instance Index Remapping Channel Design Refinement.

[0274] Remapping table format extension: Supports two remapping table formats:

[0275] Format 1 (continuous instances): remapTable[i] = BaseInstanceLocation + i (suitable for scenarios where instance indexes are continuous);

[0276] Format 2 (discrete instances): remapTable[i] = InstanceOffsetArray[i] (suitable for scenarios where instance indices are discrete, such as sparse instantiation);

[0277] Format selection logic: VKD3D analyzes the relationship between BaseInstanceLocation and NumInstances to automatically select the format (format 1 for continuous instances and format 2 for discrete instances), reducing memory usage.

[0278] S8.2 Optimization of the association between remapping channels and metadata.

[0279] Multi-view remapping: In a multi-view scenario, each view corresponds to an independent remapping table, which is stored in the viewRemapTables field (dynamic array) of InstanceRemapChannel and indexed by ViewID;

[0280] Nested indirect remapping: In nested indirect drawing scenarios, the length of the remapping table is nestedDrawCount * NumInstances, ensuring that the instance index for each nested drawing call is correct;

[0281] Access logic: Shaders index the remapping table using InstanceID and ViewID, such as:

[0282] OpLoad %uint %InstanceID / / Read InstanceID

[0283] OpLoad %uint %ViewID / / Read ViewID

[0284] OpIMul %uint %ViewID %RemapTableSize / / Calculate view offset

[0285] OpIAdd %uint %Result %InstanceID / / Total Index

[0286] OpAccessChain %uintPtr %RemapBuffer %TotalIndex / / Access remapping table

[0287] S8.3, Extension of the pooling reuse mechanism for remapping channels.

[0288] Pool classification optimization: InstanceRemapBufferPool is divided into continuous instance pools and discrete instance pools according to the remapping table format. Each pool contains buffers of different sizes (128, 256, 512, 1024, 2048, and 4096 instances).

[0289] Buffer reuse priority: Prioritize reusing the buffer that exactly matches the current drawing call format and size; if no match is found, reuse the closest buffer that is larger than the current size (e.g., if 200 instances are needed, reuse a buffer of size 256).

[0290] Expired buffer reclamation: Periodically (such as after the command buffer is executed) check the buffers in the pool. Buffers that have not been reused for more than 10 minutes are automatically destroyed and the video memory is released.

[0291] S8.4, optimized video memory usage and multi-format adaptation.

[0292] Compressed storage: For the remap table of consecutive instances, only BaseInstanceLocation and NumInstances are stored. The shader obtains remapTable[i] by calculation, without needing to store the complete array, reducing memory usage by 99% (e.g., 1024 instances only require 8 bytes of storage instead of 4096 bytes).

[0293] Multi-instance data format adaptation: Supports instance data formats such as float2, float3, float4, uint4, etc. The remapping channel automatically matches the memory alignment requirements of the data format to avoid accessing out of bounds;

[0294] Sparse memory support: For ultra-large instantiation rendering (such as 1 million instances), the remapping channel uses Vulkan sparse memory (VK_MEMORY_PROPERTY_SPARSE_BINDING_BIT), allocating memory only for the instances that are actually used, reducing video memory waste.

[0295] The following terms are used in this embodiment, and their specific explanations are as follows:

[0296] The ViewMetaSubtable is a substructure of the MetaGroup. Each subtable uniquely corresponds to a view (ViewID). It stores the metadata offsets (byte offsets in MetaGroup UBO) of all drawing calls under that view and maintains an independent atomic synchronization flag (viewMetaValid) for independent synchronization and fast positioning of metadata in multi-view scenarios, ensuring that the metadata of each view does not conflict when rendering multiple views.

[0297] The drawing parameter feature code is a 64-bit numerical identifier generated based on the fixed parameters of the D3D12 drawing call. The fields include NumVertices (lower 16 bits), NumInstances (lower 16 bits), PrimitiveTopology (lower 8 bits), IndirectType (lower 4 bits, such as normal indirection = 0, counting indirection = 1), and ViewCount (lower 8 bits). It is generated by directly concatenating the field values ​​without hash calculation. The drawing call can be directly compared to determine whether it meets the fixed parameter grouping conditions.

[0298] The resource binding topology describes the slot and type distribution relationship of non-metadata resources (textures, samplers, user UBOs, etc.) bound to the drawing call. The generation rule is as follows: for each resource slot, generate an 8-bit code by combining the slot number (4 bits) and the resource type code (4 bits, such as texture 2D=01, sampler=02, UBO=03). Then, concatenate all codes in ascending order of slot number to form a topology identifier to ensure that the resource binding layout is consistent within the same group and avoid UBO access conflicts.

[0299] Metadata requirement types are categorized into four types based on the system values ​​that D3D12 shaders depend on for drawing calls: Type A (SV_VertexID only), Type B (SV_VertexID+SV_InstanceID), Type C (SV_VertexID+SV_DrawID), and Type D (SV_VertexID+SV_InstanceID+SV_DrawID+SV_ViewID). These types are used to prioritize aggregating drawing calls with the same metadata dependencies when grouping data, thus avoiding UBO storage redundancy caused by mixing metadata with different dependencies.

[0300] The InstanceRemapChannel is an independent VkBuffer structure in the instantiated drawing scene, used to store the remapping table of instance indices. It supports two formats: continuous instances (remapTable [i] = BaseInstanceLocation + i, storing only basic parameters to obtain the index through calculation) and discrete instances (remapTable [i] = InstanceOffsetArray [i], storing discrete offsets). It obtains the actual instance data index through the InstanceID index remapping table in the metadata, avoiding duplicate storage of instance data.

[0301] Nested indirect command cache (vkd3d_indirect_cmd_cache) is a structure in the Linux kernel used to cache parsed indirect commands. It uses the indirect command buffer handle and offset as unique keys to store the parsed VkDrawIndirectCommand and VkDrawIndirectCountCommand parameters. Subsequent commands with the same key can directly reuse the cached results without repeatedly mapping the buffer and parsing, thus reducing kernel-level CPU overhead.

[0302] Command list reuse and recycling is a metadata recycling mechanism for D3D12 command list reset and reuse scenarios (ID3D12GraphicsCommandList method Reset). It records the previously recorded metadata index through the metaIndexCache field of the command list. During reset, these indexes are marked as idle in batches. At the same time, the storage structure of MetaGroup and ViewMetaSubtable is retained, and only the metadata content is cleared to avoid the overhead of recreating the storage structure.

[0303] Experiments have verified that this embodiment achieves high-efficiency compatibility with VKD3D on GPUs that do not support shaderDrawParameters through multi-dimensional deterministic grouping, end-to-end process completion, and fine-grained metadata management. Compared with existing technologies, it has the following advantages:

[0304] Improved grouping efficiency and scenario coverage: Four deterministic grouping methods cover pipeline status, drawing parameters, resource binding, metadata requirements, etc. The draw call merging rate is improved by 30% to 50% compared to single hash grouping, and it is adapted to complex scenarios such as multiple views, nested indirect drawing, and sparse instantiation.

[0305] The conversion integrity is fully covered, and omissions such as root signature reservation, resource barrier synchronization, nested indirect parsing, and command list reuse are filled. The functional coverage of D3D12 to Vulkan conversion has been increased from 90% to 99.5%, supporting previously incompatible scenarios such as VR games and large open-world games.

[0306] Performance overhead is further reduced; multi-view metadata synchronization optimization reduces GPU access latency by 20% to 30%; nested indirect command caching reduces kernel parsing overhead by more than 40%; dynamic expansion / shrinkage of metadata UBO reduces memory usage by 25% to 40%.

[0307] Significant improvements in video memory optimization: compressed storage of instance index remapping channels reduces video memory usage by 90% to 99% in sparse instantiation scenarios; multi-format adaptation support reduces instance data format conversion overhead by more than 35%.

[0308] Enhanced stability and compatibility include mechanisms such as multi-view metadata verification, nesting depth limits, and dynamic state validity checks, reducing the application crash rate from 0.1% to below 0.01%; the automatic degradation function ensures that even low-spec GPUs can run complex games, improving compatibility to over 99%.

[0309] It offers high deployment flexibility, requiring only modifications to the VKD3D source code and the Vulkan command processing module of the Linux kernel. No modifications are needed to the GPU driver or game code. It can be directly integrated into compatibility layers such as Proton and Wine, and is compatible with mainstream Linux distributions such as Ubuntu and Fedora.

[0310] In summary, the above are merely preferred embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.< / bool>

Claims

1. A method for mapping Direct3D 12 to rendering metadata based on kernel-level nested parsing, characterized in that, Specifically, the following steps are included: During the VKD3D compilation phase, the structure of D3D metadata, the global index format of single view and multi-view are established. At startup, D3D metadata UBOs and metadata groups storing D3D metadata UBOs are created, and the metadata groups, view metadata sub-tables and metadata items are initialized. When a D3D application creates a root signature, VKD3D reserves a setting slot in the root signature; When setting the viewport, capture viewport parameters; when setting the clipping rectangle, capture the clipping rectangle; when setting the view instance mask, parse the view index parameter to extract the view index, and extract the number of views from the multi-view interface parameters; when executing a direct drawing scene, extract the vertex index, vertex start position, instance start position, number of vertices, and number of instances, and generate a DrawID from a global atomic counter; when executing an indirect drawing scene, extract the offset of the indirect command in the buffer, parse the indirect command buffer to generate a Vulkan indirect command structure; when executing a nested indirect drawing scene, extract the offset of the indirect command count buffer, recursively parse the nested parameters to generate a Vulkan indirect count command structure, add a nesting marker, parse the count buffer to obtain the number of nested drawings, and construct D3D metadata; Establish a mapping dictionary between system values ​​that D3D12 shaders depend on and metadata requirement types. When continuously drawing and generating D3D metadata, determine the grouping conditions of D3D metadata based on the mapping dictionary, and determine the metadata group corresponding to the D3D metadata accordingly. Add D3D metadata to a metadata group, merge metadata items in the same metadata group into the same drawing group, bind the corresponding D3D metadata UBO of the drawing group to the set slot, record drawing commands in batches according to the metadata items in the drawing group, add the metadata group index and view index of the drawing group to the command buffer, submit the command buffer to the GPU, and the GPU executes the drawing commands in the command buffer to complete the rendering.

2. The Direct3D 12 to rendering metadata mapping method according to claim 1, characterized in that, The method for adding D3D metadata to a metadata group is as follows: If there are idle metadata items in the metadata group, the metadata is added to the idle metadata item. When the number of views is greater than 1, the offset of the metadata item is recorded in the view metadata sub-table of the current metadata group, written to the D3D metadata UBO, the number of used metadata items is incremented by 1, and a global index is allocated to it. When the number of views is 1, it is written to the D3D metadata UBO, the number of used metadata items is incremented by 1, and a global index is allocated to it. If a metadata group has no free metadata items, a new metadata group is created, its index is set to the previous group's index incremented by 1, the metadata group is initialized, and then the metadata items are written to the corresponding UBO of the new metadata group according to the value of its view count, and a global index is allocated.

3. The Direct3D 12 to rendering metadata mapping method according to claim 2, characterized in that, The global index includes a globally unique identifier for the metadata group, a view index, and an intra-group index. If the number of views in the D3D metadata is greater than 1, the intra-group index is not empty; otherwise, no intra-group index is set.

4. The Direct3D 12 to rendering metadata mapping method according to claim 2, characterized in that, The method of writing it into the D3D metadata UBO is as follows: the writing address is pMappedMemory + usedCount * sizeof(D3D12DrawMetadata), where pMappedMemory is the virtual address of the UBO mapped to the CPU, usedCount is the number of used metadata items, and sizeof(D3D12DrawMetadata) is the size of the metadata.

5. The Direct3D 12 to rendering metadata mapping method according to claim 1, characterized in that, The method of batch recording drawing commands based on metadata items within the drawing group is as follows: If the dynamic state of all metadata items in the drawing group is the same, the dynamic state setting command is recorded only once; otherwise, the dynamic state setting commands are recorded sequentially according to the drawing call order. For direct drawing scenarios, non-indexed direct drawing commands or indexed direct drawing commands are recorded in batches according to the metadata items, and the continuous drawing calls of the current drawing group are merged into batch commands. For indirect drawing scenarios, non-indexed indirect drawing commands or indexed indirect drawing commands are recorded, along with the associated information of the indirect command buffer.

6. The Direct3D 12 to rendering metadata mapping method according to claim 1, characterized in that, After the D3D metadata UBO is updated, insert a resource barrier and add the resource barrier entry mark to the command buffer.

7. The Direct3D 12 to rendering metadata mapping method according to claim 1, characterized in that, When the kernel receives a command buffer containing non-indexed indirect drawing commands or indexed indirect drawing commands, it extracts the indirect command buffer handle, offset, number of drawing calls, and command step size from the command parameters; maps the memory of the indirect command buffer to the kernel address space, obtains the kernel virtual address, and sets the mapping permission to read-only; it traverses each command in the indirect command buffer according to the command step size, extracts the total number of vertices, total number of instances, starting vertex, and starting instance required for the current indirect drawing; and supplements the obtained data into the original Vulkan indirect command structure fields of the D3D metadata. When the kernel receives a command buffer containing non-indexed nested indirect drawing commands or indexed nested indirect drawing commands, it extracts the indirect command buffer handle, offset, number of drawing calls, command step size, count buffer handle, count offset, and count type from the command parameters, maps the count buffer to read the actual number of drawing calls, recursively parses the nested indirect command buffers, and marks in the D3D metadata whether the current drawing call is a nested indirect scene and the parsing status of the count buffer and the indirect command buffer.

8. The Direct3D 12 to rendering metadata mapping method according to claim 1, characterized in that, For the vertex shader to execute metadata read instructions and vertex data read instructions in parallel, in multi-view scenarios, the extended output structure adds a view identifier field, and uses the default view when the view identifier goes out of bounds. For geometry shaders, the nested drawing count is read from the metadata, and the input or output topology type and maximum number of vertices are dynamically adjusted based on the primitive topology type in the metadata. For tessellation surface shaders, the TCS stage uses the view identifier as additional data for control points, so that each control point independently carries view information. The TES stage reads the view identifier and combines it with the tessellation factor in the metadata to adjust the vertex position.

9. The Direct3D 12 to rendering metadata mapping method according to claim 1, characterized in that, The mapping dictionary is established as follows: Traverse the abstract syntax tree of the HLSL shader, identify the system values ​​that the D3D12 shader depends on, and map them to class A of metadata requirements when only SV_VertexID is depended on, class B of metadata requirements when SV_VertexID and SV_InstanceID are depended on, class C of metadata requirements when SV_VertexID and SV_DrawID are depended on, and class D of metadata requirements when SV_VertexID, SV_InstanceID, SV_DrawID and SV_ViewID are depended on.

10. The Direct3D 12 to rendering metadata mapping method according to claim 1, characterized in that, The method for determining the grouping conditions of D3D metadata based on the mapping dictionary, and thereby determining the metadata group corresponding to the D3D metadata, is as follows: When the higher priority grouping conditions are the same, and the lower priority grouping conditions are different and there is no conflict, the D3D metadata is grouped according to the highest priority grouping condition, and the metadata group to which the D3D metadata belongs is determined. The grouped D3D metadata needs to be supplemented with the difference information related to the lower priority grouping conditions in its D3D metadata UBO. When the newly generated D3D metadata does not meet the currently selected grouping conditions or cannot supplement the difference information related to lower priority grouping conditions, or when the number of used metadata items in the metadata group reaches the maximum value, or when the newly generated D3D metadata is nested indirect drawing while the current metadata group is indirect or direct drawing, the current grouping process is terminated and a new metadata group is created. The grouping conditions, in descending order of priority, include metadata requirement type, pipeline status hash, resource binding topology, and drawing parameter feature code.