A Direct3D 12 sampler addressing mode compatible method based on double-buffer preprocessing

By establishing a preprocessing parameter cache pool and association table, and combining it with a branchless formula for coordinate preprocessing, the performance loss and insufficient coverage of fixed function scenes in the conversion from Direct3D 12 to Vulkan interface are solved, and low-overhead, high-fidelity MIRROR_ONCE mode simulation is achieved.

CN121704853BActive Publication Date: 2026-04-17北京麟卓信息科技有限公司
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-04-17

AI Technical Summary

Technical Problem

Existing technologies for implementing the interface conversion from Direct3D 12 to Vulkan suffer from significant performance losses, insufficient coverage of fixed functional scenarios, and inconsistent interface conversion timing. In particular, on GPU devices compatible with Vulkan versions 1.0 to 1.2, the MIRROR_ONCE sampler addressing mode cannot be effectively supported.

Method used

By establishing a preprocessing parameter buffer pool, a first association table between samplers and textures, a second association table between pipelines and preprocessing parameters, and a resource management linked list, the texture coordinate range is expanded and MSAA sampling point offset marking is implemented. A branchless formula is used for coordinate preprocessing, and the command buffers are merged into a command chain. The native hardware sampling capability of Vulkan's CLAMP_TO_EDGE is utilized to avoid additional shader overhead.

Benefits of technology

It achieves low-overhead, high-fidelity simulation of MIRROR_ONCE mode without modifying the GPU chip driver, improving performance and ensuring full coverage of fixed functional scenarios and consistency of interface conversion timing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121704853B_ABST
    Figure CN121704853B_ABST
Patent Text Reader

Abstract

This invention discloses a Direct3D12 sampler addressing mode compatible method based on double-buffered preprocessing. During system initialization and startup, a preprocessing parameter cache pool, a first association table, a second association table, and a resource management linked list are established. A Vulkan extension structure for expanding texture coordinate range and marking MSAA sample point offsets is registered. When creating a texture, VKD3D determines whether it is a MIRROR_ONCE related texture. For related textures, resource tags are allocated, dependency tags are set, double buffers are allocated, and coordinate ranges are expanded. If not related, standard conversion is performed. When creating a sampler, the simulated sampler is marked, a Vulkan sampler structure is constructed and configured, and the association table and resource management linked list are updated. When creating a pipeline, the D3D12 shader is converted to SPIR-V and the second association table is updated. When applying the recorded command list, a command buffer is generated, and the command buffer is submitted to complete rendering.
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, and specifically relates to a Direct3D 12 sampler addressing mode compatibility method based on double buffering preprocessing. Background Technology

[0002] VKD3D is an open-source project that emulates Direct3D 12 (D3D12) based on Vulkan. Its core mission is to build a seamless translation layer between D3D12 and Vulkan, enabling applications that rely on D3D12 to run without differences in the Vulkan ecosystem, such as Linux. According to the D3D12 specification, D3D12_TEXTURE_ADDRESS_MODE_MIRROR_ONCE is a mandatory sampler addressing mode. Its behavior is defined as follows: when the texture coordinate t is in the range [-1,0), it is mirrored to (0,1]; when it is in the range (1,2), it is mirrored to (0,1); and when it exceeds the range [-1,2], it is directly clamped to 0 or 1. Essentially, it is a combination of single mirroring and edge clamping logic.

[0003] Vulkan 1.3 provides native hardware support for this feature through the samplerMirrorClampToEdge. Its VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE mode is completely aligned with the behavior of D3D12 MIRROR_ONCE without requiring additional computational overhead, making it the optimal path for VKD3D to implement this mode mapping. However, many existing GPUs, such as those compatible with Vulkan versions 1.0 to 1.2, lack this native feature, resulting in a compatibility bottleneck for VKD3D.

[0004] Existing solutions mainly fall into two categories: one is to rewrite coordinates at runtime, i.e., insert MIRROR_ONCE logic code during the HLSL to SPIR-V conversion process. However, this approach has obvious drawbacks. First, it incurs significant performance overhead, requiring an additional 3 to 5 arithmetic instructions to be executed for each texture sample. In complex scenes, the frame rate drops by 15% to 30%, and GPU warp fragmentation further exacerbates pipeline congestion. Second, the lack of fixed-function pipeline coverage prevents support for scenarios without programmable shader intervention, such as depth texture sampling, MSAA fixed-function filtering, and cube map face selection. Finally, there are risks to accuracy and compatibility, i.e., differences in SPIR-V compilation optimization strategies of different GPUs can lead to coordinate calculation deviations, resulting in anomalies such as jagged texture edges and color shifts. The second approach is texture preprocessing stretching, which simulates a mirror region by expanding the texture size. However, this doubles the texture memory usage and cannot adapt to dynamic textures, such as runtime-modified rendering target textures.

[0005] Therefore, it is urgent to solve core issues such as performance overhead control, full coverage of fixed functional scenarios, and consistency of interface conversion timing, under the constraints of not modifying the GPU chip driver and only allowing modification of the VKD3D source code and Linux kernel source code, and strictly following the interface conversion process from D3D12 to Vulkan. Summary of the Invention

[0006] In view of this, the present invention provides a Direct3D 12 sampler addressing mode compatible method based on double buffering preprocessing, which realizes low-overhead, high-fidelity simulation of MIRROR_ONCE mode.

[0007] This invention provides a Direct3D 12 sampler addressing mode compatibility method based on double buffering preprocessing, which specifically includes the following steps:

[0008] During kernel initialization, a first cache pool is established to store sampler identifiers and MIRROR_ONCE preprocessing parameters. During VKD3D initialization, a first association table between samplers and textures, a second association table between pipelines and preprocessing parameters, and a resource management linked list are created. The resource management linked list records attributes and associated configurations using the texture resource handles related to MIRROR_ONCE as indexes. At startup, a first structure is registered to record the texture logical coordinate range and MSAA sampling point offset markers. The first cache pool is initialized to enable cross-application reuse.

[0009] When a D3D application creates a texture, VKD3D obtains the texture resource information. If it is related to MIRROR_ONCE and already exists in the resource management list, the resource management list is updated. If it is related but does not exist in the resource management list, a MIRROR_ONCE resource tag is allocated, a dependency tag is set, a preprocessing coordinate buffer with a double buffer structure is allocated, and it is added to the resource management list. The texture logical coordinate range is expanded by the first structure. When it is an MSAA texture, the number of MSAA sampling points is set to the original value, and an MSAA sampling point offset tag is added to the first structure. If it is not related, a standard texture conversion is performed.

[0010] When creating a sampler, if the 3D texture coordinate addressing mode is single mirror and edge clamping, the sampler is marked as a simulated sampler. The sampler parameters are recorded to generate simulated markers. The Vulkan sampler is constructed with the MIRROR_ONCE dimension addressing mode set to CLAMP_TO_EDGE to complete the sampler and boundary color mapping. The texture resource and sampler are bound and added to the first association table. The MIRROR_ONCE activation status of the texture resource in the resource management chain is set to TRUE.

[0011] When creating the pipeline, the D3D12 shader is converted to a Vulkan shader, and the association between the pipeline handle and preprocessing parameters is added to the second association table. When executing command recording, the first and second association tables are queried. When the pipeline is associated with MIRROR_ONCE and the texture is in the MIRROR_ONCE active state, the parameters required for coordinate preprocessing are extracted, and the coordinate preprocessing of the original texture coordinates is completed to obtain the Vulkan command buffer to be submitted. The command buffer is submitted to the GPU, and the GPU completes the rendering.

[0012] Furthermore, when creating texture resources after the D3D application starts, VKD3D obtains the texture type, dimension, format, sample count, and resource purpose of the texture resource, and determines whether the texture resource is a MIRROR_ONCE related texture resource based on the resource purpose.

[0013] Furthermore, the method for setting the dependency flag is as follows: when the texture resource is in a depth template format or a compressed format, its dependency flag is set to a fixed function sampling dependency; when the texture resource is a dynamically updated texture, its dependency flag is set to a real-time preprocessing dependency.

[0014] Furthermore, the method for updating the resource management list is as follows: match the resource handle of the corresponding texture in the resource management list, and verify the validity of the existing MIRROR_ONCE resource flag; update the parameters in the table entry, and if the texture purpose, format, or sample count changes, synchronously update the flags of fixed function sampling dependencies or real-time preprocessing dependencies; if the texture size remains unchanged, retain the original preprocessing coordinate buffer and only update the buffer association state; if the texture size changes, reallocate the buffer according to the new size and update the buffer handle and activation index in the resource management list; if the original associated sampler remains unchanged, maintain the binding relationship; otherwise, update the texture handle list and dynamic switching flag in the first association table.

[0015] Furthermore, the method for converting the D3D12 shader to a Vulkan shader during pipeline creation and adding the association between the pipeline handle and preprocessing parameters to the second association table is as follows:

[0016] The texture sampling instructions in the shader are parsed, and the first association table is queried. If the sampler associated with the texture sampling instruction is the MIRROR_ONCE simulated sampler, a preprocessing coordinate buffer binding flag is added to the SPIR-V shader. The preprocessing coordinate buffer slot is then created by adding a set value based on the current sampler's binding slot, removing redundant coordinate calculation code, modifying the SPIR-V resource decoration instruction OpDecorate to bind the preprocessing coordinate buffer to the default slot of each shader, and adding a read-only access permission flag. The coordinate input of the texture sampling instructions in SPIR-V is changed from the original coordinates to the reading result of the preprocessing coordinate buffer. Otherwise, the standard sampling process is followed, and no binding flag is added.

[0017] Meanwhile, VKD3D parses all configuration parameters of the D3D12 graphics pipeline state. If depth comparison is enabled and the depth texture is associated with the MIRROR_ONCE sampler, MSAA is enabled and the rendering target is associated with the MIRROR_ONCE sampler, or the cube map is bound to a fixed function unit and associated with the MIRROR_ONCE sampler, then the pipeline is marked as a fixed function MIRROR_ONCE pipeline, and a dual trigger point is added to it in the pipeline state management module to create a Vulkan native hardware-level synchronization event.

[0018] Write the simulation tag ID, preprocessing coordinate buffer binding slot, timing synchronization event handle, and MSAA sampling point offset tag into the additional data field of the preprocessing coordinate buffer, and add the association between the pipeline handle and the preprocessing parameters to the second association table.

[0019] Furthermore, when the application executes the D3D12 command list recording, VKD3D queries the first and second association tables. When the pipeline is related to MIRROR_ONCE and the texture is in the MIRROR_ONCE active state, it extracts the data required for coordinate preprocessing, including the original texture coordinates, texture type and size, the sampler's MIRROR_ONCE enabled dimension, precision calibration parameters, and preprocessing block size. For the dimensions in the original texture coordinates where MIRROR_ONCE is enabled, the CPU SIMD instruction set is used to clamp the original texture coordinates to the effective mirror interval using a branchless mathematical formula. The branchless mirror factor is calculated to distinguish between negative and positive intervals. The branchless mirror factor is used to perform mirror calculations to map the invalid interval results to the effective interval, and then the clamping operation is performed. For the dimensions in the original texture coordinates where MIRROR_ONCE is not enabled, the original coordinates are not changed. After completing the coordinate preprocessing, the Vulkan command buffer to be submitted is obtained.

[0020] Furthermore, the coordinate preprocessing method for special texture types is as follows: For cube maps, the face index is first determined based on the original coordinates during preprocessing for the coordinates of the six faces, and then a branchless mirror factor is used to perform mirror calculations on the face coordinates to map the invalid interval results to the valid interval; For 3D textures, a branchless mirror factor is used to perform mirror calculations on the Z-axis coordinates to map the invalid interval results to the valid interval, while the clamping parameters are adjusted according to the texture depth; For MSAA textures, the offset coordinates of each MSAA sampling point are obtained and then superimposed on the preprocessed coordinates.

[0021] Furthermore, when VKD3D submits a Vulkan command buffer to the kernel, it parses the command buffer. If the bound buffer contains a preprocessed coordinate buffer flag, the sampler is in CLAMP_TO_EDGE mode, or there is a pipeline barrier or event wait for MIRROR_ONCE, the Vulkan command buffer is marked as a MIRROR_ONCE related command buffer.

[0022] When the Vulkan command processor identifies consecutive MIRROR_ONCE-related command buffers in the same rendering batch, it merges them into a command chain, allocates an independent DMA transfer channel for the command chain, and enables DMA interrupt merging. When the DMA transfer is completed or the command chain execution ends, the kernel triggers an interrupt. The interrupt handler only performs status updates and semaphore notifications.

[0023] Furthermore, the commands in the command chain are arranged in the following order from front to back: double buffer status check command, DMA transfer command, cache synchronization command, pipeline barrier command, batch rendering command, and Fence signal command.

[0024] Furthermore, when VKD3D starts up, it extracts the precision parameters of the physical device, texture format, and sampler, and sets matching preprocessing precision levels for different types of textures and samplers based on these parameters;

[0025] Based on the GPU manufacturer's calibration parameter table, the default precision offset and scaling parameters are initialized; then, the extreme coordinates of the texture are sampled and verified, and the calibration parameters are dynamically adjusted according to the deviation threshold. When the deviation is too large, FP64 high-precision calculation is enabled for extreme areas; at the same time, precision calibration is performed for depth textures and MSAA scenes with fixed function pipelines to correct the deviation of depth sampling and sampling point offset.

[0026] When the preprocessing accuracy level fails, batch preprocessing is disabled or rolled back to clamping mode according to programmable and fixed function scenarios respectively; when the performance loss exceeds the limit, the processing block size is adjusted or the performance priority mode is enabled; when the GPU is found to be unsupported by the critical Vulkan extension, a prompt is made at the start of the application and the selection of compatibility mode and performance mode is provided, while the reason for the downgrade is recorded and a prompt window pops up.

[0027] Beneficial effects:

[0028] In the system initialization and startup phases, this invention establishes a preprocessing parameter cache pool, a first association table between samplers and textures, a second association table between pipelines and preprocessing parameters, and a resource management linked list. It also registers a Vulkan extension structure for expanding texture coordinate ranges and marking MSAA sample point offsets. When an application creates a texture, VKD3D parsing parameters determine whether it is a MIRROR_ONCE related texture. For related textures, resource tags are allocated, dependency tags are set, double buffers are allocated, and coordinate ranges are expanded to adapt to MSAA texture parameters. For unrelated textures, standard conversion is performed. When an application creates a sampler, those with an addressing mode of MIRROR_ONCE are marked as analog samplers. A Vulkan sampler-related structure is constructed and configured, and linked to the texture. The process involves binding and updating the association table and resource management linked list. When an application creates a pipeline, VKD3D converts the D3D12 shader to SPIR-V, adds a preprocessing buffer binding flag, modifies resource decoration instructions, parses pipeline parameters to determine if it is a fixed-function MIRROR_ONCE pipeline, creates a synchronization tool, and updates the second association table. When an application records a command list, VKD3D queries the association table, performs preprocessing on MIRROR_ONCE-related coordinates using a branchless formula, and generates a Vulkan command buffer. When submitting the command buffer, it marks MIRROR_ONCE-related command buffers, merges them into a command chain, allocates a DMA transfer channel, and updates the status and notifies semaphores via kernel interrupts after execution, completing the entire adaptation process. Attached Figure Description

[0029] Figure 1 This is a flowchart illustrating a Direct3D 12 sampler addressing mode compatibility method based on double buffering preprocessing provided by the present invention. Detailed Implementation

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

[0031] This invention provides a Direct3D12 sampler addressing mode compatibility method based on double-buffered preprocessing. The core idea is as follows: During initialization and startup, a preprocessing parameter buffer pool, a first association table between samplers and textures, a second association table between pipelines and preprocessing parameters, and a resource management linked list are established. A Vulkan extension structure for expanding texture coordinate range and marking MSAA sample point offsets is registered. When an application creates a texture, VKD3D parsing parameters determine whether it is a MIRROR_ONCE related texture. For related textures, resource markers are allocated, dependency markers are set, double buffering is allocated, and coordinate ranges are expanded to adapt to MSAA texture parameters. For unrelated textures, standard conversion is performed. When an application creates a sampler, those with an addressing mode of MIRROR_ONCE are marked as analog samplers, and VKD3D is constructed and configured. The VKD3D process involves: constructing the Ulkan sampler-related structures, binding them to textures, and updating the association table and resource management linked list; when the application creates a pipeline, VKD3D converts the D3D12 shader to SPIR-V, adds preprocessing buffer binding markers, modifies resource decoration instructions, parses pipeline parameters to determine if it is a fixed-function MIRROR_ONCE pipeline, creates a synchronization tool, and updates the second association table; when the application records a command list, VKD3D queries the association table, performs preprocessing on MIRROR_ONCE-related coordinates using a branchless formula, and generates a Vulkan command buffer; when submitting the command buffer, it marks the MIRROR_ONCE-related command buffers, merges them into a command chain, allocates a DMA transfer channel, and updates the status and notifies semaphores via kernel interrupts after execution, completing the entire adaptation process.

[0032] This invention provides a Direct3D12 sampler addressing mode compatibility method based on double buffering preprocessing, the processing flow of which is as follows: Figure 1 As shown, the specific steps include:

[0033] Step 1: During kernel initialization, a MIRROR_ONCE preprocessing parameter cache pool is established and designated as the first cache pool. This pool is used to store sampler identifiers and their corresponding preprocessing parameters, supporting cross-process sharing and concurrent access control. During VKD3D initialization, a first association table for the relationship between samplers and textures, a second association table for the relationship between pipelines and preprocessing parameters, and a resource management linked list are created. All tables are initialized to an empty state. The resource management linked list is maintained by the VKD3D user space and is used to manage texture resources related to MIRROR_ONCE. Its attributes and associated configurations are recorded using texture resource handles as indexes.

[0034] The first association table is a data table in the VKD3D sampler management module. Its entries include the simulation tag ID, sampler handle, list of associated texture handles, MIRROR_ONCE dimension enable flag, preprocessing coordinate buffer handle, currently active buffer index, and dynamic switching flag. The simulation tag ID is the identifier of the MIRROR_ONCE simulation sampler, consisting of the sampler identifier and a resource management linked list index. The preprocessing coordinate buffer is double-buffered and used to store texture coordinates preprocessed by the CPU for direct sampling by the GPU. For example, the MIRROR_ONCE simulation sampler is a sampler whose AddressU, V, or W in D3D12_SAMPLER_DESC contains MIRROR_ONCE.

[0035] Furthermore, the cache item structure of the first cache pool includes sampler identifier and preprocessing parameters. The preprocessing parameters include simulation tag ID, texture type, precision calibration parameters, preprocessing coordinate buffer alignment requirements, coordinate preprocessing block size, last access timestamp, and fixed function synchronization barrier configuration. The capacity of the first cache pool is set to 1024 items, and a least recently used eviction policy is adopted. When the cache is full, the cache item with the earliest last access time is removed.

[0036] The entries in the resource management linked list include the MIRROR_ONCE resource flag, resource parameters, dependency flags, and MIRROR_ONCE activation status. Among them, the dependency flags include fixed function sampling dependencies and real-time preprocessing dependencies.

[0037] The MIRROR_ONCE resource marker consists of a resource handle and a marker bit. It is used to mark the texture that needs to simulate the MIRROR_ONCE mode and record it in the resource management linked list. Subsequent steps can identify it through this marker.

[0038] Step 2: When VKD3D starts, it registers a Vulkan extended structure (referred to as the first structure) to record the texture logical coordinate range and MSAA sampling point offset markers, thereby expanding the texture logical coordinate space and providing a foundation for MIRROR_ONCE simulation. It then starts the kernel-level Vulkan command processor, enables MIRROR_ONCE command recognition and command chain merging, and sets a high-priority scheduling strategy. It creates kernel-level synchronization tool templates such as VkEvent and VkFence for CPU and GPU timing control. It initializes a cross-process sharing mechanism to support cross-application reuse of the first cache pool. Finally, it creates an independent MIRROR_ONCE preprocessing thread, setting it to high Linux priority to prevent preemption by low-priority tasks.

[0039] Step 3: When the D3D application creates a texture resource after it starts, VKD3D parses the resource parameters to obtain the texture type, dimension, format, sample count and resource purpose. Based on the resource purpose, it determines whether the texture resource is a MIRROR_ONCE related texture resource. If it is related and already exists in the resource management list, it updates the entries and associated configurations of the resource management list.

[0040] If the texture resource is relevant and does not exist in the resource management list, a unique MIRROR_ONCE resource tag is assigned to it. When the texture resource is a depth template or compressed format, its dependency tag is set to a fixed-function sampling dependency. When the texture resource is a dynamically updated texture, its dependency tag is set to a real-time preprocessing dependency. Its MIRROR_ONCE activation state is set to the default value FALSE. A double-buffered preprocessing coordinate buffer is allocated. The MIRROR_ONCE resource tag, resource parameters, dependency tag, preprocessing coordinate buffer handle, and MIRROR_ONCE activation state are added to the resource management list. The texture logical coordinate range is extended from [0,1] to [0,2] through the first structure, and all sub-resource ranges are associated. When the texture resource is an MSAA texture, the MSAA sampling point count field of the Vulkan-defined image creation parameter structure VkImageCreateInfo is set to be consistent with D3D12, and an MSAA sampling point offset tag is added to the first structure.

[0041] If not relevant, standard D3D12 to Vulkan texture conversion is performed.

[0042] The method for updating the entries and associated configurations of the resource management list is as follows: match the resource handles of the corresponding textures in the resource management list, and verify the validity of the existing MIRROR_ONCE resource flags; update the parameters in the entries, and if the texture usage, format, or sample count changes, synchronously update the flags of fixed function sampling dependencies or real-time preprocessing dependencies; if the texture size remains unchanged, retain the original preprocessing coordinate buffers and only update the buffer association status; if the texture size changes, reallocate the buffers according to the new size and update the buffer handles and activation indexes in the resource management list; if the original associated samplers remain unchanged, maintain the binding relationship; otherwise, update the texture handle list and dynamic switching flags in the first association table.

[0043] Furthermore, the method for allocating a preprocessing coordinate buffer for a texture resource to be created with the MIRROR_ONCE resource flag is as follows: a double buffering method is used, with BufferA for CPU preprocessing and BufferB for GPU rendering; the size of the preprocessing coordinate buffer is calculated based on the dimension of the texture resource, specifically: buffer size = texture coordinate dimension × 4 bytes × 2; the purpose of the buffer is set.

[0044] Furthermore, the allocated preprocessed coordinate buffer is bound to the same memory block as the texture resource, and the buffer offset is allocated according to the maximum memory alignment granularity required by the GPU using an offset-aligned allocation method.

[0045] Step 4: When the application creates a sampler, VKD3D parses the sampler creation parameters. When the 3D texture coordinate addressing mode is single mirror and edge clamping, the sampler to be created is marked as MIRROR_ONCE simulated sampler. The sampler parameters are recorded, including the filtering mode, anisotropic filtering switch, comparison sampling switch, MipmapLOD range, boundary color, etc., and a unique simulated tag ID is generated.

[0046] Construct a VkSamplerCreateInfo structure to define the behavior of the Vulkan sampler. First, map the filter mode of the sampler parameters to Vulkan's zoom-in, zoom-out, or Mipmap filter mode. Then, set the dimension addressing mode corresponding to MIRROR_ONCE to CLAMP_TO_EDGE. Map the other dimensions according to standard rules. Synchronously set the corresponding parameters of the Vulkan sampler according to the anisotropic filter switch and the comparison sampling switch. Finally, complete the mapping of the boundary colors.

[0047] Bind the texture resource to the created sampler, add the binding relationship to the first association table, including entering the simulation tag ID, sampler handle and preprocessing coordinate buffer handle, and add the texture handle to the associated texture list; set the MIRROR_ONCE activation status of the texture resource in the resource management chain to TRUE.

[0048] The simulated tag ID consists of sampler parameter hash and resource management linked list index. The sampler parameter hash is the hash value of sampler parameters including filtering mode, anisotropic filtering switch, comparison sampling switch, MipmapLOD range, boundary color, etc.

[0049] Step 5: When the application creates the pipeline, VKD3D converts the D3D12 shader to a Vulkan SPIR-V shader, parses the texture sampling instructions in the shader, and queries the first association table. If the sampler associated with the texture sampling instruction is the MIRROR_ONCE simulated sampler, a preprocessed coordinate buffer binding flag is added to the SPIR-V shader to determine that the texture coordinates corresponding to the sampling instruction need to be read from the preprocessed coordinate buffer. The preprocessed coordinate buffer slot is then added with a set value based on the current sampler's binding slot. Redundant coordinate calculation code is removed, and the SPIR-V resource decoration instruction OpDecorate is modified to bind the preprocessed coordinate buffer to the default slot of each shader. A read-only access permission flag is added, and the coordinate input of the texture sampling instruction in SPIR-V is changed from the original coordinates to the reading result of the preprocessed coordinate buffer, ensuring that the shader directly uses the preprocessed coordinates to perform sampling. Otherwise, the standard sampling process is followed, and no binding flag is added.

[0050] Meanwhile, VKD3D parses all configuration parameters of the D3D12 graphics pipeline state. If depth comparison is enabled and the depth texture is associated with the MIRROR_ONCE sampler, MSAA is enabled and the rendering target is associated with the MIRROR_ONCE sampler, or the cube map is bound to a fixed function unit and associated with the MIRROR_ONCE sampler, then the pipeline is marked as a fixed function MIRROR_ONCE pipeline. In the pipeline state management module, dual trigger points are added to it, and Vulkan native hardware-level synchronization events are created to achieve timing synchronization of confirming the completion of preprocessing before GPU sampling and waiting for the GPU sampling to end before CPU switching double buffers.

[0051] Write the simulation tag ID, preprocessing coordinate buffer binding slot, timing synchronization event handle, and MSAA sampling point offset tag into the additional data field of the preprocessing coordinate buffer, and add the association between the pipeline handle and the preprocessing parameters to the second association table.

[0052] Furthermore, when an application creates a pipeline, VKD3D detects whether the application's root signature has a dynamic flag. If it does, it indicates that the application will dynamically switch samplers in this way. In the first association table, the sampler is marked as a dynamically switched sampler so that VKD3D can recognize this type of sampler in subsequent processes. Instead of using the one-time binding buffer logic of static samplers, it enables a real-time update and dynamic binding process for it. When the application executes the sampler switching operation at runtime, VKD3D intercepts the call and updates the currently active sampler ID and associated texture handle in the first association table in real time based on the information of the newly switched sampler. It also triggers the dynamic binding of the preprocessing coordinate buffer, switching the preprocessing coordinate buffer that the GPU needs to read in the current rendering process from the originally bound texture buffer to the dedicated double-buffered preprocessing coordinate buffer of the texture associated with the newly active sampler.

[0053] The setting value can be set to 1024.

[0054] Specifically, modifying the SPIR-V resource decorator instruction OpDecorate binds the preprocessed coordinate buffer to the default slot of each shader. When it is a vertex shader, its default slot is the vertex input slot, so the preprocessed coordinate buffer is decorated to the vertex input slot; when it is a pixel and compute shader, its default slot is the storage buffer slot, so the preprocessed coordinate buffer is decorated to the storage buffer slot.

[0055] The dual trigger points include a command recording stage trigger to start the coordinate preprocessing command, and a submission stage trigger to verify the preprocessing completion status.

[0056] Furthermore, for the fixed-function MIRROR_ONCE pipeline, a pipeline barrier is inserted in the Vulkan command buffer to control the memory access order and pipeline stage transitions.

[0057] Furthermore, during the operation of the D3D application, when the application dynamically updates texture resources, VKD3D parses the texture resources and queries the resource management linked list. At the same time, it extracts the specific region and data of the texture update. When the texture has the MIRROR_ONCE resource mark and the real-time preprocessing dependency mark, it only performs incremental coordinate preprocessing on the texture update region, modifies the preprocessing coordinate buffer, and inserts a synchronization command in the corresponding command buffer to ensure that the preprocessed coordinates and texture update data are synchronized and effective. When the application modifies the texture size, it reallocates the preprocessing coordinate buffer according to the new size, updates the relevant parameters of the resource management linked list and the first association table, then performs full coordinate preprocessing and submits the synchronization command to complete the update.

[0058] Step 6: When the application executes the D3D12 command list recording, VKD3D queries the first and second association tables. When the pipeline is related to MIRROR_ONCE and the texture is in the MIRROR_ONCE active state, it extracts the data required for coordinate preprocessing, including the original texture coordinates, texture type and size, the sampler's MIRROR_ONCE enabled dimension, precision calibration parameters, and preprocessing block size. For the dimensions in the original texture coordinates that have MIRROR_ONCE enabled, the CPU SIMD instruction set is used to clamp the original texture coordinates to the effective mirror interval using a branchless mathematical formula. The branchless mirror factor is calculated to distinguish between negative and positive intervals. The branchless mirror factor is used to perform mirror calculations to map the invalid interval results to the effective interval, and then the clamping operation is performed to ensure that the coordinates are clamped to the effective interval. For the dimensions in the original texture coordinates that do not have MIRROR_ONCE enabled, the original coordinates are not changed. The coordinate preprocessing is completed to obtain the Vulkan command buffer to be submitted.

[0059] Furthermore, the implementation of coordinate preprocessing for special texture types is as follows: For cube maps, during preprocessing, the face index is first determined based on the original coordinates for the coordinates of the six faces. Then, a mirror calculation is performed on the face coordinates using a branchless mirror factor to map the invalid interval results to the valid interval, ensuring the continuity of coordinates when switching faces. For 3D textures, a mirror calculation is performed on the Z-axis coordinates using a branchless mirror factor to map the invalid interval results to the valid interval, while adjusting the clamping parameters according to the texture depth. For MSAA textures, the offset coordinates of each MSAA sampling point are obtained and then superimposed on the preprocessed coordinates to ensure that the sampling point position is consistent with the native MIRROR_ONCE of D3D12.

[0060] Furthermore, to address the latency issue between the CPU and GPU in the MIRROR_ONCE coordinate preprocessing, this invention achieves efficient and low-power interaction between the coordinate preprocessing process and the GPU from several aspects, including thread scheduling, computation acceleration, parallel execution, and data transmission. Specifically:

[0061] A dedicated MIRROR_ONCE preprocessing thread is created and set to high priority on Linux. Vectorized batch processing of coordinates is performed using AVX2 or AVX512 instruction sets, while data prefetching and cache line alignment optimization are executed simultaneously. Double buffering enables full parallelism between the CPU preprocessing thread and the GPU rendering thread, and buffer switching timing is determined using buffer indexing and VulkanFence to eliminate data waiting time. Preprocessed coordinate buffers and textures are preferentially bound to the same GPU's local memory block, achieving microsecond-level in-memory copying. Furthermore, if binding to the same memory block is not supported, direct DMA transfer is enabled.

[0062] Step 7: When VKD3D submits the Vulkan command buffer to the kernel, it parses the command buffer. If the bound buffer contains a preprocessed coordinate buffer flag, the sampler is in CLAMP_TO_EDGE mode, or there is a pipeline barrier or event wait for MIRROR_ONCE, the Vulkan command buffer is marked as a MIRROR_ONCE related command buffer.

[0063] When the Vulkan command processor identifies consecutive MIRROR_ONCE-related command buffers in the same rendering batch, it merges them into a command chain, allocates an independent DMA transfer channel for the command chain, and enables DMA interrupt merging. When the DMA transfer is completed or the command chain execution ends, the kernel triggers an interrupt. The interrupt handler only performs status updates and semaphore notifications. The command buffer is then submitted to the GPU for rendering.

[0064] The merged command chain is arranged in the following order to ensure timing and data consistency: double buffer status check command, DMA transfer command, cache synchronization command, pipeline barrier command, batch rendering command, and Fence signal command. The double buffer status check command is used to verify the GPU occupancy status of the currently active buffer. The DMA transfer command is used to transfer the data from the preprocessed coordinate buffer to the GPU texture cache. The cache synchronization command is used to ensure that the data is visible after the DMA transfer is completed. The pipeline barrier command is used to control the memory access order, i.e., CPU write and GPU read. The batch rendering command is the merged vkCmdDraw and vkCmdDispatch instructions. The Fence signal command is used to mark the completion of the command chain.

[0065] Furthermore, after VKD3D executes the Vulkan command, to eliminate differences in different GPU architectures and ensure that the rendering results in MIRROR_ONCE mode are completely consistent with D3D12, this invention adds rendering result verification and dynamic precision calibration, specifically as follows:

[0066] When VKD3D starts, it calls the relevant Vulkan interfaces to extract the core precision parameters of physical devices, texture formats, and samplers. Based on these parameters, it sets matching preprocessing precision levels for different types of textures and samplers, such as using FP32 for depth textures and adapting low-precision samplers to the corresponding calculation formats.

[0067] Based on the built-in calibration parameter tables of mainstream GPU manufacturers, the default precision offset and scaling parameters are initialized; then, the extreme coordinates of the texture are sampled and verified, and the calibration parameters are dynamically adjusted according to the deviation threshold. When the deviation is too large, FP64 high-precision calculation is enabled for extreme areas; at the same time, dedicated precision calibration is performed for depth textures and MSAA scenes with fixed function pipelines to correct the deviation of depth sampling and sampling point offset.

[0068] A tiered degradation strategy is designed to address abnormal situations. When preprocessing fails, batch preprocessing is disabled or rolled back to clamping mode according to programmable and fixed function scenarios, respectively. When preprocessing performance loss exceeds the limit, the processing block size is adjusted or the performance priority mode is recommended. When it is detected that the GPU does not support critical Vulkan extensions, a prompt is made at application startup, and compatibility mode and performance mode are provided for selection. At the same time, the reason for degradation is recorded and a prompt window pops up, taking into account both adaptation compatibility and user experience.

[0069] Example:

[0070] This embodiment employs a Direct3D12 sampler addressing mode compatibility method based on double-buffered preprocessing provided by the present invention. It decomposes the core logic of MIRROR_ONCE into the entire interface conversion chain, utilizing Vulkan CLAMP_TO_EDGE's native hardware sampling capability to avoid additional shader overhead, achieving full-scene, low-latency, and high-precision simulation. The specific process includes:

[0071] The translation of the S1 and D3D12 texture resource creation interfaces and the adaptation of Vulkan resources correspond to the translation process of the CreateCommittedResource and CreatePlacedResource interfaces of D3D12 ID3D12Device. By expanding the logical coordinate range of textures and configuring efficient memory layout, hardware-level support is provided for subsequent MIRROR_ONCE coordinate preprocessing and low-latency data transmission.

[0072] S1.1 and D3D12 texture resource parameter parsing and marking.

[0073] VKD3D reimplements the resource creation interface called by D3D12 applications, parses the input D3D12_RESOURCE_DESC structure, and extracts key parameters: texture type (2D, 3D, cube map, array texture), dimensions (width W, height, depth D), format (e.g., DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_D32_FLOAT), sample count (number of MSAA sample points, e.g., 1x, 4x, 8x), and resource purpose (rendering target, depth stencil, normal texture sampling, dynamic texture update).

[0074] Associating sampler pre-creation status: Query the sampler and texture association table maintained internally by VKD3D. If the texture will be bound to a sampler in MIRROR_ONCE mode in the future, it can be predicted by applying the pre-created sampler tag, or by recording the texture's purpose as potentially bound to a MIRROR_ONCE sampler. Then, a unique MIRROR_ONCE resource tag is assigned to the texture, in the format of resource handle and 0x80000000 tag bit, and recorded in the resource management chain of VKD3D.

[0075] Special texture format and usage adaptation determination: For depth template formats (such as DXGI_FORMAT_D32_FLOAT) and compressed texture formats (such as DXGI_FORMAT_BC7_UNORM), additional markers are added to indicate fixed function sampling dependencies; for dynamically updated textures (such as resources marked with D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS), additional markers are added to indicate real-time preprocessing dependencies, and subsequent adaptation to runtime coordinate update logic is required.

[0076] S1.2, Vulkan texture resource coordinate range extension and memory configuration.

[0077] When VKD3D converts texture creation parameters to the Vulkan underlying layer, the key configuration of the VkImageCreateInfo structure is modified: For textures marked as MIRROR_ONCE resources, the extent field (texture physical size) is kept consistent with D3D12, but a custom VkImageCoordinateRangeExtension structure is added to the pNext extension chain. This structure can be registered through the Vulkan extension mechanism for use only in VKD3D internal translation adaptation, and the logicalCoordinateRange is set to {0.0f, 2.0f}, with the default logical coordinate range extended from [0,1] to [0,2].

[0078] Configure VkImageSubresourceRange: Associate all sub-resource ranges from baseMipLevel to levelCount and from baseArrayLayer to layerCount with the extended [0,2] logical coordinates to ensure that the GPU can recognize the extended coordinate space when accessing any sub-resource of the texture;

[0079] Special configuration for MSAA textures: For MSAA textures, keep the samples field of VkImageCreateInfo consistent with D3D12 (e.g., VK_SAMPLE_COUNT_4_BIT), and add the msaaSampleOffsetEnable flag to VkImageCoordinateRangeExtension. Subsequent coordinate preprocessing must include the offset coordinate correction of MSAA sampling points.

[0080] Memory layout optimization: The `vkGetImageMemoryRequirements` function retrieves the memory requirements of the texture, prioritizing device-local memory and host-visible and host-contiguous memory types such as `VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT`, `VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT`, and `VK_MEMORY_PROPERTY_HOST_COHERENT_BIT`. This avoids the need for manual cache flushing (`vkFlushMappedMemoryRanges`) after CPU writes, reducing data transfer latency. If the GPU does not support this memory type, a cache consistency synchronization mechanism is enabled, automatically triggering cache flushing during subsequent data transfers.

[0081] S1.3, Preprocessing coordinate buffer and double buffer design.

[0082] Allocate a preprocessed coordinate buffer for textures marked MIRROR_ONCE: Buffer size = texture coordinate dimension (2×W×H for 2D, 3×W×H×D for 3D) × 4 bytes (FP32 precision) × 2; Buffer usage is set to VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT to ensure compatibility with both programmable and fixed-function scenarios.

[0083] Buffer memory binding optimization: Bind the preprocessed coordinate buffer and texture resources to the same memory block (if the memory type supports it), and use offset alignment allocation method to allocate buffer offset according to the maximum memory alignment granularity required by the GPU (such as 256 bytes) to reduce memory fragmentation and GPU memory access conflicts;

[0084] Persistent memory mapping configuration: When performing vkMapMemory on the preprocessed coordinate buffer, set the flags of vkMapMemoryInfo to VK_MEMORY_MAP_PERSISTENT_BIT (persistent mapping) to avoid the overhead caused by frequent calls to vkMapMemory / vkUnmapMemory. After mapping, the buffer memory address is valid for a long time and can be read and written directly by the CPU. It only needs to be synchronized to the GPU through vkFlushMappedMemoryRanges after the data is updated. This operation is only required for dynamically updated scenes.

[0085] The translation of the S2 and D3D12 sampler creation interface and its binding with the Vulkan sampler, corresponding to the translation process of the CreateSampler method of the D3D12 ID3D12Device, maps the D3D12 MIRROR_ONCE mode to the Vulkan CLAMP_TO_EDGE mode, establishes a strong association between the sampler and the texture, and adapts to dynamic sampler switching scenarios.

[0086] S2.1, D3D12 Sampler Parameter Analysis and MIRROR_ONCE Determination.

[0087] Parse the AddressU, AddressV, and AddressW fields of the D3D12_SAMPLER_DESC structure. If any dimension is D3D12_TEXTURE_ADDRESS_MODE_MIRROR_ONCE, then mark the sampler as a MIRROR_ONCE simulated sampler and generate a unique simulated tag ID. The calculation method is the sampler parameter hash value and the resource management linked list index, ensuring global uniqueness. The sampler parameter hash value includes AddressMode, Filter, MipLODBias, AnisotropyEnable, etc.

[0088] Record the complete parameter set of the sampler, including the filtering mode (such as D3D12_FILTER_MIN_MAG_MIP_LINEAR), anisotropy filtering switch (AnisotropyEnable), comparison sampling switch (ComparisonEnable), MipmapLOD range (MinLOD / MaxLOD), and border color (BorderColor). Subsequent Vulkan sampler creations must fully align these parameters, only modifying the address mode.

[0089] S2.2, Vulkan sampler CLAMP_TO_EDGE mode binding.

[0090] Construct a VkSamplerCreateInfo structure and map magFilter, minFilter, and mipmapMode according to the D3D12 parameters, such as mapping D3D12_FILTER_MIN_MAG_MIP_LINEAR to VK_FILTER_LINEAR, VK_FILTER_LINEAR, and VK_SAMPLER_MIPMAP_MODE_LINEAR.

[0091] Key mapping: Force the dimensions corresponding to MIRROR_ONCE in addressModeU, addressModeV, and addressModeW to VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, and map the other dimensions normally according to the D3D12 parameters (e.g., map D3D12_TEXTURE_ADDRESS_MODE_WRAP to VK_SAMPLER_ADDRESS_MODE_REPEAT).

[0092] Comparison sampling and anisotropy configuration: If ComparisonEnable is enabled for the D3D12 sampler, set compareOp to the corresponding mapping (e.g., D3D12_COMPARISON_FUNC_LESS is mapped to VK_COMPARE_OP_LESS); if AnisotropyEnable is enabled, set maxAnisotropy to the MaxAnisotropy field value and anisotropyEnable to VK_TRUE to ensure that all behaviors of the sampler except for address mode are consistent with D3D12.

[0093] Border color adaptation: If the BorderColor of the D3D12 sampler is non-transparent black (such as white), then set the borderColor to the corresponding mapping in VkSamplerCreateInfo (such as the white mapping of D3D12 is VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE) to avoid the border color being inconsistent with D3D12 in CLAMP_TO_EDGE mode.

[0094] S2.3, Sampler and texture association table construction and dynamic switching adaptation.

[0095] In the VKD3D sampler management module, a new MIRROR_ONCE sampler and texture association table has been added. The table entries include: simulation tag ID, sampler handle, list of associated texture handles, UVW dimension MIRROR_ONCE enable flag, preprocessing coordinate buffer handle (Buffer A and Buffer B), currently active buffer index, and dynamic switching flag.

[0096] Static binding association: When an application binds a sampler to a texture using the SetGraphicsRootSignature method of ID3D12GraphicsCommandList, VKD3D intercepts the call, queries the association table, adds the currently bound texture handle to the list of associated texture handles of the corresponding sampler, and marks the MIRROR_ONCE activation state of the texture as TRUE.

[0097] Dynamic sampler switching adaptation: If the application uses dynamic root signature (D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT) to dynamically switch samplers, then the sampler is marked as a dynamically switched sampler in the association table, and when the SetGraphicsRootDescriptorTable method of ID3D12GraphicsCommandList is called, the currently active sampler ID and associated texture handle in the association table are updated in real time, triggering the dynamic binding of the preprocessed coordinate buffer (switching to the buffer of the corresponding texture).

[0098] The translation of the S3 and D3D12 rendering pipeline construction interface and the embedding of preprocessing logic, corresponding to the D3D12 ID3D12Device methods CreateGraphicsPipelineState / CreateComputePipelineState, is to distinguish between programmable shaders and fixed-function pipeline scenes, and to embed coordinate preprocessing triggering logic and timing synchronization mechanisms.

[0099] S3.1 Preprocessing triggering and binding of programmable shader scenes (VS, PS, GS, CS).

[0100] When VKD3D converts the DXIL shader of D3D12 to SPIR-V using the dxil-spirv tool, it parses the texture sampling instructions (such as tex2D, tex3D, texCube) in the shader and queries the association table: if the sampler used by the sampling instruction is the MIRROR_ONCE simulated sampler, then a preprocessed coordinate buffer binding mark is added in SPIR-V, specifying the binding slot as the sum of the sampler binding slot and 1024, to avoid conflicts with the original binding of the application.

[0101] Remove redundant coordinate calculation logic: If the DXIL shader contains manually implemented MIRROR_ONCE coordinate processing code (identifying the combination logic of OpFAdd, OpFClamp, OpFAbs, and OpFSign), VKD3D will automatically remove this part of the code to ensure that only the pre-processed coordinates are used and avoid double calculation.

[0102] Shader Resource Binding Table (SRB) adaptation: Modify the SPIR-V OpDecorate instruction to bind the preprocessed coordinate buffer to the corresponding slot, that is: bind the VS scene to the vertex input slot (OpDecorate %coordBuffer Location10), and bind the PS / CS scene to the storage buffer slot (OpDecorate %coordBuffer DescriptorSet 0Binding N), and add the NonWritable flag to prevent the shader from accidentally modifying the preprocessed data.

[0103] Rewrite sampling instructions: Change the coordinate input of texture sampling instructions (such as OpImageSampleImplicitLod) in SPIR-V from the original coordinates to the reading result of the preprocessed coordinate buffer (such as OpLoad %vec2 %coordBuffer %index), so that the shader can directly use the preprocessed coordinates to perform sampling.

[0104] S3.2 Timing synchronization and preprocessing linkage for fixed function pipeline scenarios.

[0105] Fixed-function pipeline determination: Analyze D3D12_GRAPHICS_PIPELINE_STATE_DESC in D3D12. If one of the following conditions is met, the pipeline is marked as a fixed-function MIRROR_ONCE pipeline: DepthStencilState enables depth comparison, and the depth texture is associated with a MIRROR_ONCE sampler; MultisampleState has Count > 1 (MSAA), and the render target is associated with a MIRROR_ONCE sampler; The cubemap texture is bound to a fixed-function texture unit (such as for environment mapping) and associated with a MIRROR_ONCE sampler.

[0106] Preprocessing trigger timing and synchronization mechanisms to solve timing consistency issues:

[0107] Trigger point settings: In the VKD3D pipeline state management module, add two trigger points for this pipeline: trigger during the command recording phase (before the ID3D12CommandList method DrawInstanced or Dispatch is called) to start coordinate preprocessing; trigger during the command submission phase (before vkQueueSubmit) to verify the preprocessing completion status.

[0108] Timing synchronization tool creation: Create a Vulkan event (VkEvent) for each fixed-function MIRROR_ONCE pipeline, and set the flags of VkEventCreateInfo to VK_EVENT_CREATE_SIGNALED_BIT to mark the preprocessing completion status; at the same time, create a VkFence to allow the CPU to wait for the GPU to complete sampling and avoid double-buffer switching conflicts;

[0109] Precise configuration of pipeline barriers: Pipeline barriers (vkCmdPipelineBarrier) are inserted into the Vulkan command buffer to control the order of memory accesses and pipeline stage transitions, such as:

[0110] / / Barrier parameter example (depth texture sampling scenario)

[0111] srcStageMask = VK_PIPELINE_STAGE_HOST_BIT; / / Source stage: CPU preprocessing

[0112] dstStageMask = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT; / / Target phase: Deep testing (fixed functionality)

[0113] srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; / / Source access: CPU writes preprocessed coordinates

[0114] dstAccessMask = VK_ACCESS_SAMPLED_IMAGE_READ_BIT; / / Target access: GPU-sampled depth texture

[0115] dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT; / / Dependencies by region, improving parallelism

[0116] This barrier ensures that the GPU's fixed-function pipeline can only read the data and perform sampling after the CPU has completed coordinate preprocessing (writing to the buffer), completely avoiding timing conflicts.

[0117] S3.3, Pipeline cache and preprocessing parameters are associated.

[0118] When calling vkCreatePipelineCache to create a Vulkan pipeline cache, the MIRROR_ONCE simulation flag ID, the preprocessed coordinate buffer binding slot, the timing synchronization event handle, and the MSAA sampling point offset parameters are written to the cache's additional data field (pInitialData). This eliminates the need for repeated parsing and configuration when the pipeline is reused (e.g., when the application rebuilds the same pipeline).

[0119] Establish a pipeline and preprocessing parameter association table: The table entries include pipeline handle, simulation tag ID, texture type, coordinate preprocessing block size (default 64×64 pixels, dynamically adjusted according to texture size: set to 128×128 when texture size > 2048×2048, and set to 32×32 when texture size < 512×512), precision calibration parameters, and fixed function synchronization barrier configuration.

[0120] S4 and D3D12 dynamic resource update interface adaptation, the translation process of the corresponding D3D12 ID3D12CommandList methods CopyResource, CopyTextureRegion, and UpdateSubresource interfaces, complete the coordinate preprocessing logic for dynamic texture update scenes, and ensure that the MIRROR_ONCE behavior remains consistent after runtime texture data changes.

[0121] S4.1 Dynamic resource update interception and judgment.

[0122] VKD3D intercepts the D3D12 dynamic resource update interface called by the application and queries the resource management linked list: if the updated texture is marked as MIRROR_ONCE resource and the real-time preprocessing dependency is marked as TRUE, the dynamic coordinate preprocessing process is triggered; extract the update range and data: parse the D3D12_BOX structure (the update range of CopyTextureRegion) or the pData pointer of UpdateSubresource to obtain the updated texture region (such as X0-X1, Y0-Y1, Z0-Z1) and the original coordinate data, avoiding full preprocessing of the coordinates of the entire texture, and only updating the coordinates of the changed region.

[0123] S4.2 Incremental coordinate preprocessing and synchronization.

[0124] Incremental preprocessing logic: Branchless formula calculation is performed only on the coordinates of the updated region (see step 4.2.2 below). The preprocessing range is equal to the coordinate range of the updated region (e.g., the U coordinate range corresponding to X0-X1). The processing efficiency is 5-10 times higher than that of full preprocessing.

[0125] Double buffer switching and conflict avoidance: During dynamic updates, if the currently active buffer is Buffer B (which is being used by the GPU), the CPU writes the incrementally preprocessed coordinates to Buffer A and resets the preprocessing completion event via vkResetEvent. After preprocessing is complete, vkFlushMappedMemoryRanges is called to synchronize the data of Buffer A to the GPU, and then the event is triggered via vkSetEvent.

[0126] Command buffer insertion synchronization instructions: In the Vulkan command buffer corresponding to the D3D12 update command, insert the vkCmdWaitEvents instruction. After the preprocessing completion event is triggered, execute vkCmdCopyBufferToImage (texture data update) and subsequent sampling commands to ensure that the updated coordinates and texture data are synchronized and effective.

[0127] S4.3, Dynamic texture size change adaptation.

[0128] If an application modifies the texture size using the ID3D12Device method CreateResizedTargetView, VKD3D automatically reallocates the preprocessing coordinate buffer (calculating the buffer size according to the new size) and updates the buffer handle and texture size parameters in the association table; it then re-executes full coordinate preprocessing. After the size change, a full coordinate preprocessing is triggered, writing all coordinates under the new size into the buffer, and submitting a synchronization command via vkQueueSubmit to ensure that the GPU uses the new buffer data.

[0129] S5 and D3D12 command list recording and coordinate batch preprocessing correspond to the recording process of D3D12 ID3D12CommandList (such as DrawInstanced or Dispatch), batch execution of MIRROR_ONCE coordinate preprocessing, and avoid CPU-GPU data transfer latency through SIMD acceleration, data prefetching, double buffering and parallelism.

[0130] S5.1 Command list interception and MIRROR_ONCE scene activation determination.

[0131] VKD3D intercepts the D3D12 command list recording interface called by the application and queries the currently bound pipeline status and sampler-texture association table: if the current pipeline is a MIRROR_ONCE related pipeline (programmable or fixed function), and the texture is in the MIRROR_ONCE active state, then the coordinate preprocessing process is triggered; extract the core data required for preprocessing: including the original texture coordinate data (from the vertex buffer submitted by the application, the texture resource itself, or the default coordinates of the fixed function pipeline), texture type and size, the sampler's MIRROR_ONCE enabled dimensions (U, V, W), precision calibration parameters, and preprocessing block size.

[0132] S5.2 Batch coordinate preprocessing based on the MIRROR_ONCE rule.

[0133] S5.2.1, Preprocessing logic derivation: Based on the behavior rules of D3D12 MIRROR_ONCE, derive the equivalent mapping relationship with VulkanCLAMP_TO_EDGE:

[0134] Original coordinates t ∈ [-1, 0): MIRROR_ONCE behavior is -t (mirrored to (0,1]), after preprocessing the coordinates t' = -t (∈(0,1]), CLAMP_TO_EDGE sampling directly takes t', consistent with MIRROR_ONCE;

[0135] Original coordinates t ∈ [0, 1]: MIRROR_ONCE is t, preprocessed coordinates t' = t, CLAMP_TO_EDGE sampling is consistent;

[0136] Original coordinates t ∈ (1, 2]: MIRROR_ONCE behavior is 2 - t (mirrored to (0,1]), preprocessed coordinates t' = 2 - t (∈(0,1]), CLAMP_TO_EDGE sampling consistent;

[0137] Original coordinates t < -1 or t > 2: MIRROR_ONCE behavior clamps to 0 or 1. After preprocessing, coordinates t' = clamp(t, -1, 2), and the above mapping is performed again. Finally, t' ∈ [0,1]. The clamping result during CLAMP_TO_EDGE sampling is consistent with MIRROR_ONCE.

[0138] S5.2.2, Branchless Mathematical Formula Solidification: The above mapping relationship is converted into a branchless arithmetic expression to ensure high efficiency during CPU batch processing. The formula for a single-dimensional coordinate t is as follows:

[0139] / / Step 1: Clamp the coordinates to the range [-1, 2], covering the valid mirrored region of MIRROR_ONCE.

[0140] float clampedT = clamp(t, -1.0f, 2.0f);

[0141] / / Step 2: Calculate the mirror factor and distinguish the mirror logic between the negative and positive intervals.

[0142] float mirrorFactor = sign(clampedT) * 2.0f - 1.0f;

[0143] / / Step 3: Perform mirror calculation to ensure the result is mapped to [0,1]

[0144] float mirroredT = abs(clampedT - 1.0f) * mirrorFactor + 1.0f;

[0145] / / Step 4: Finally clamp to [0,1] to ensure a perfect match with the CLAMP_TO_EDGE sample.

[0146] float finalT = clamp(mirroredT, 0.0f, 1.0f);

[0147] / / Step 5: Apply accuracy calibration parameters (from the dynamic calibration results in Step 7)

[0148] finalT = finalT + precisionOffset;

[0149] The formula has no branching decisions and contains only 6 floating-point arithmetic instructions, which can process 16 or 32 coordinate values ​​in parallel through the CPU SIMD instruction set (AVX2, AVX512).

[0150] S5.2.3 Multi-dimensional coordinate processing: For the U, V, and W three-dimensional coordinates, execute the above formula to calculate respectively. For dimensions where MIRROR_ONCE is not enabled, directly output the original coordinates (if only the U dimension is enabled, the V and W coordinates remain unchanged).

[0151] S5.2.4, Adaptation to special texture types.

[0152] Cube mapping: For the coordinates of the 6 faces (such as X + face, X - face, etc.), the face index is first determined based on the original coordinates during preprocessing (such as when t_U > 2, the face index remains unchanged), and then the above formula is applied to the U and V coordinates of the face to ensure the continuity of coordinates when switching faces;

[0153] 3D texture: Perform the same preprocessing logic on the Z-axis coordinate, and adjust the clamp parameter according to the texture depth D (e.g., if the depth coordinate range is [-1, 2], it is mapped to [0,1] after preprocessing);

[0154] MSAA texture: For each MSAA sampling point (e.g., 4 sampling points of 4xMSAA), obtain the offset coordinates of the sampling point, such as (0.25, 0.25), and overlay them into the preprocessed coordinates. The formula is finalUV = finalUV + msaaOffset, ensuring that the sampling point position is consistent with the native MIRROR_ONCE of D3D12.

[0155] S5.3, Low-latency preprocessing and data transmission optimization.

[0156] S5.3.1 Preprocessing task priority scheduling: VKD3D creates an independent MIRROR_ONCE preprocessing thread and sets the thread priority to high priority (in Linux, it is set to PRIO_PROCESS via setpriority, with a priority value of 10) to avoid being preempted by other low-priority tasks and to ensure the real-time performance of preprocessing.

[0157] S5.3.2, SIMD instruction acceleration and data prefetching.

[0158] Vectorization processing: The original coordinates are packaged into groups of 16 into the __m256 register (each register stores 8 float values, and the two groups are processed in parallel) using the CPU's AVX2 instruction set. Vectorized instructions such as _mm256_clamp_ps, _mm256_abs_ps, and _mm256_sign_ps are then called to perform formula calculations, which improves the processing efficiency by 8 to 16 times compared to scalar calculations. If the CPU supports AVX512, the coordinates are packaged into groups of 32, which further improves the efficiency by 2 times.

[0159] Data prefetch optimization: Before preprocessing, the raw coordinate data is prefetched from main memory to the CPU L1 / L2 cache using the _mm_prefetch instruction (e.g., _mm_prefetch((const char*)coordData, _MM_HINT_T0)), reducing the waiting latency caused by CPU cache misses; at the same time, the raw data and preprocessed results are aligned according to the cache line size (64 bytes) to ensure that the complete cache line can be loaded for each memory access, improving access efficiency.

[0160] S5.3.3, Double-buffered parallel execution.

[0161] Parallel mechanism: The CPU preprocessing thread and the GPU rendering thread collaborate through a producer-consumer model. The CPU (producer) writes the preprocessed coordinates into the free buffer (such as Buffer A) in the double buffer and notifies the GPU (consumer) through a semaphore. The GPU reads the ready buffer (such as Buffer B) to perform rendering, while the CPU starts the next batch of preprocessing and writes it into Buffer A, achieving complete parallelism between preprocessing and rendering and eliminating data transmission waiting time.

[0162] Buffer switching determination: The timing of the switch is determined by the index of the currently active buffer in the association table and the Vulkan Fence status. When vkGetFenceStatus returns VK_SUCCESS (the GPU has completed rendering of Buffer B), the active index is switched to Buffer A, and the Fence is reset to prepare for the next batch of rendering.

[0163] S5.3.4 Zero-copy data transfer: If the preprocessed coordinate buffer and texture resource are bound to the same GPU local memory block, the preprocessed coordinate data is directly copied to the texture sampling unit's cache (L1 or L2 cache) via the in-memory copy method of vkCmdCopyBufferToImage, without going through the CPU main memory, reducing the transmission latency to the microsecond level; if the same memory block binding is not supported, DMA direct transfer is enabled, and vkCmdPipelineBarrier ensures the timing consistency between DMA transfer and GPU sampling.

[0164] S6. Linux kernel-level Vulkan command optimization and submission: This corresponds to the process of VKD3D submitting Vulkan commands to the Linux kernel (the ID3D12CommandQueue method ExecuteCommandLists is translated into vkQueueSubmit). By modifying the Linux kernel drm_vulkan subsystem, the scheduling, merging, and transmission of MIRROR_ONCE related commands are optimized, further reducing system overhead.

[0165] S6.1 Kernel-level MIRROR_ONCE command identification and marking.

[0166] Modify the Vulkan-related modules of the Linux kernel DRM to add MIRROR_ONCE command identification logic: When the kernel receives the Vulkan command buffer (VkCommandBuffer) submitted by VKD3D, it parses the vkCmdBindVertexBuffers, vkCmdDraw, vkCmdBindSamplers, and vkCmdWaitEvents instructions in the command buffer. If the following conditions are met, the command buffer is marked as a MIRROR_ONCE related command buffer: the bound buffer contains a preprocessed coordinate buffer marker, the sampler is in CLAMP_TO_EDGE mode, and there is a pipeline barrier or event wait for MIRROR_ONCE.

[0167] A new kernel-level command association table has been added: the table entries include command buffer handle, preprocessing coordinate buffer handle, sampler tag ID, GPU execution priority (set to high priority, value is 1, default priority is 5), double buffer switching status, and DMA transfer channel ID.

[0168] S6.2 Command Buffer Merging and Chaining Optimization.

[0169] The command merging logic is as follows: The kernel's Vulkan command processor (drm_vulkan_process_cmd) identifies consecutive MIRROR_ONCE related command buffers in the same rendering batch (such as vertex binding, sampler binding, and drawing commands called in the same DrawInstanced), and merges them into a single command chain, reducing the context switching overhead of GPU command scheduling. Each context switch takes about 1 to 2 microseconds, and merging can reduce the number of switches by more than 90%.

[0170] Command chain structure: The merged command chain is arranged in the following order to ensure timing and data consistency:

[0171] Double buffer status check command: Verifies the GPU occupancy status of the currently active buffer;

[0172] DMA transfer command: Transfers data from the preprocessed coordinate buffer to the GPU texture buffer;

[0173] Cache synchronization command: Ensures data is visible after DMA transfer is complete;

[0174] Pipeline barrier command: controls memory access order (CPU write → GPU read);

[0175] Batch rendering commands: the merged vkCmdDraw / vkCmdDispatch commands;

[0176] Fence signal command: Marks the completion of the command chain.

[0177] DMA transfer channel exclusivity and optimization: Allocate an independent DMA transfer channel (through the drm_dma_reserve_channel interface) for the MIRROR_ONCE command chain to avoid DMA transfer conflicts with other applications; set the transfer block size to 64KB (matching the GPU cache line size), and enable DMA interrupt merging, triggering an interrupt once every 16 blocks (1MB of data) transferred, reducing CPU interrupt handling overhead. Each interrupt processing takes about 0.5 microseconds, and the number of interrupts is reduced by 15 to 16 after merging.

[0178] S6.3, kernel-level parameter caching and cross-process sharing.

[0179] A new MIRROR_ONCE preprocessing parameter cache pool has been added to the drm_vulkan subsystem. The cache item structure is defined as follows:

[0180] struct mirror_once_cache_entry {

[0181] uint64_t sampler_hash; / / Sampler parameter hash value (associated with tag ID)

[0182] uint32_t texture_type; / / Texture type (2D / 3D / cube map)

[0183] uint32_t precision_param; / / Precision calibration parameters (such as FP32 compensation factor)

[0184] uint32_t buffer_alignment; / / Preprocessing buffer alignment requirements

[0185] uint32_t block_size; / / Preprocessing block size (64 / 128, etc.)

[0186] uint64_t last_access_time; / / Last access timestamp (used for LRU eviction)

[0187] struct list_head list; / / Linked list nodes (used for LRU management)

[0188] struct rw_semaphore lock; / / Read-write lock, supports concurrent access across processes

[0189] };

[0190] The cache pool size is set to 1024 items, and the LRU (Least Recently Used) eviction policy is adopted. When the cache is full, the item with the earliest last access time is removed.

[0191] User-space parameter upload and cache hit: When VKD3D processes a sampler for the first time, it uploads the sampler parameters, texture type, precision parameters, block size, etc. to the kernel cache pool through the extended ioctl command (adding the command code DRM_VK_MIRROR_ONCE_CACHE_UPLOAD). The kernel calculates sampler_hash as an index. When VKD3D processes the same sampler subsequently, it only needs to upload sampler_hash. The kernel queries the cache pool through the hash index. If a cache hit occurs, it directly returns the cached preprocessed parameters without recalculation. Cache hits can save 80% of parameter configuration overhead.

[0192] Cross-process cache sharing: Through the kernel's file descriptor passing mechanism (SCM_RIGHTS), multiple VKD3D processes are allowed to share the cache pool. Cache items uploaded by process A can be queried and reused by process B through the same sampler_hash. Access permissions for cache items are controlled by the kernel through read-write locks (shared read, exclusive write) to avoid concurrency conflicts. Cross-process sharing can reduce system-level parameter storage overhead by 30%.

[0193] S6.4 Command execution timing calibration and delay control.

[0194] The kernel adds precise timing control to the MIRROR_ONCE command chain: it obtains the command execution timestamp through the GPU's hardware timer (such as AMD's CPTimer and NVIDIA's GPU Timer), dynamically adjusts the scheduling priority of the command chain, and if the command execution delay is detected to exceed 5 microseconds, the priority is increased by 1 level (up to 0) to ensure that MIRROR_ONCE related commands are executed before other non-critical commands.

[0195] Lightweight interrupt handling: When a DMA transfer is completed or the command chain finishes execution, the kernel triggers an interrupt. The interrupt handler only performs status updates and semaphore notifications (such as setting the command chain status to complete and waking up the waiting thread of VKD3D). It does not perform complex calculations and delays the status feedback to the next vkGetFenceStatus call of the user-space VKD3D, reducing the impact of interrupt handling on command execution.

[0196] S7, Rendering Result Verification and Dynamic Precision Calibration, corresponds to the rendering result feedback process after the Vulkan command is executed (vkGetFenceStatus or vkQueueWaitIdle). Through regularized precision calibration, it eliminates the differences between different GPU architectures and ensures that the rendering results are consistent with D3D12.

[0197] S7.1, GPU precision characteristic detection and basic parameter configuration.

[0198] When VKD3D starts, it calls vkGetPhysicalDeviceProperties2 to obtain the VkPhysicalDeviceLimits structure and extracts key precision parameters: maxTextureCoordinateRange (texture coordinate range), minSamplerLodBias (minimum LOD deviation), textureCoordinatePrecisionBits (texture coordinate precision bits), and maxComputeWorkGroupCount (calculates the number of shader workgroups, used for CS scene precision adaptation).

[0199] Call vkGetPhysicalDeviceFormatProperties to obtain the precision support of the texture format: for example, the depth format VK_FORMAT_D32_SFLOAT has a precision of 32 bits, and the color precision of the compression format VK_FORMAT_BC7_UNORM is 8 bits per channel. Set the precision level of the preprocessing accordingly. The depth texture uses FP32, and the color texture is calculated using FP32 and stored according to the format precision (e.g., when storing in BC7 format, convert it to 8 bits).

[0200] Sampler precision characteristic detection: Call vkGetPhysicalDeviceSamplerProperties to obtain the sampler's precision parameters (such as minFilterPrecision). If the sampler's filtering precision is low (such as only supporting FP16), then during preprocessing, finalT will be forcibly converted to FP16 before being stored in the buffer to avoid precision waste and incompatibility.

[0201] S7.2, Regularized accuracy calibration.

[0202] S7.2.1 Initialization of calibration parameters according to GPU manufacturer classification: VKD3D has a built-in manufacturer calibration parameter table, which includes the default calibration parameters for mainstream GPUs such as AMD, NVIDIA, and Intel (based on a large amount of hardware test data), for example:

[0203] NVIDIA GPUs (such as GTX 1060, RTX 2060): FP32 computational precision is complete, with calibration parameters precisionOffset set to 0.0f and precisionScale set to 1.0f (no compensation).

[0204] AMD GPUs (such as RX 580, RX 6600): FP16 optimization is aggressive, with some models having a deviation of 0.00001f. The calibration parameters precisionOffset and precisionScale should be set to 0.00001f and 0.99999f, respectively.

[0205] Intel integrated graphics (such as UHD 630, Iris Xe): The texture coordinate sampling accuracy is low, with a deviation of 0.00002f. Set the calibration parameter precisionOffset to 0.00002f and precisionScale to 1.0f.

[0206] Unknown GPU: The default calibration parameter precisionOffset is set to 0.0f, and will be dynamically adjusted through subsequent edge scene verification.

[0207] S7.2.2, Edge Scene Accuracy Verification and Calibration:

[0208] Sampling coordinate selection: For each MIRROR_ONCE activated texture, four extreme coordinates are sampled and verified during preprocessing (t = -0.999999f, t = 1.999999f, t = -1.000001f, t = 2.000001f). The deviation delta = |finalT - expectedT| between the preprocessed coordinate finalT and the native D3D12 MIRROR_ONCE result is calculated.

[0209] Calibration logic:

[0210] If delta ≤ 1e-5: Keep the current calibration parameters;

[0211] If 1e-5 < delta ≤ 5e-5: Double the precisionOffset (e.g., change it from 0.00001f to 0.00002f), and recalculate the sampling coordinate until delta ≤ 1e-5;

[0212] If delta > 5e-5: Enable high-precision preprocessing mode, which increases the coordinate calculation precision of the texture from FP32 to FP64. Only for extreme coordinate regions, the coordinates are marked in the range of [-1.0001, -0.9999] and [1.9999, 2.0001]. Only coordinates within this range are calculated using FP64 to avoid global performance loss.

[0213] S7.2.3, Fixed function pipeline accuracy calibration.

[0214] Depth texture scene: Sample and verify the depth value comparison results. Obtain the depth value depthSample obtained from preprocessed coordinate sampling and compare it with the depth value depthExpected sampled by D3D12 native MIRROR_ONCE. If the deviation |depthSample - depthExpected| > 1e-6 (the smallest precision unit of D32_FLOAT), then adjust the clampedT parameter in the preprocessing formula (e.g., change clamp(t, -1.0f, 2.0f) to clamp(t, -1.000001f,2.000001f)) to correct the depth sampling deviation.

[0215] MSAA scenario: Perform precision verification on the offset coordinates of each MSAA sampling point. If the color deviation of the sampling point exceeds 1 (8-bit color channel), adjust the msaaOffset parameter, such as changing (0.25, 0.25) to (0.25001, 0.25001).

[0216] S7.3, Compatibility Degradation Mechanism and Error Handling.

[0217] Preprocessing failure downgrade: If the CPU detects corrupted texture coordinate data during preprocessing (e.g., coordinate values ​​exceeding the reasonable range of [-1e6, 1e6]), or the GPU returns VK_ERROR_MEMORY_MAP_FAILED / VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS when executing commands, it will automatically downgrade to lightweight mode.

[0218] For programmable scenes, disable batch preprocessing, enable simplified shader coordinate processing, insert only core unbranched formulas, and remove the precision verification step; for fixed-function scenes, fallback to D3D12_TEXTURE_ADDRESS_MODE_CLAMP_TO_EDGE, and record the reason for the downgrade through VKD3D logs (such as memory mapping failure, downgrade to CLAMP mode).

[0219] Performance Over-Limit Degradation: If the preprocessing performance loss exceeds 30% (e.g., single-frame preprocessing time > 5 milliseconds) detected by the kernel command chain timestamp, the preprocessing block size will be automatically adjusted (e.g., from 64×64 to 128×128) to reduce the number of CPU processing times; if the loss still exceeds 50%, a prompt window will pop up, suggesting that the user enable performance priority mode (disable MIRROR_ONCE simulation for fixed function scenarios).

[0220] GPU Incompatibility Warning: If the GPU is detected to not support the Vulkan extension VK_KHR_buffer_device_address (used for DMA transfer optimization) and not support persistent memory mapping, a warning window will pop up when the application starts, informing the user that the current GPU does not support efficient MIRROR_ONCE emulation, which may result in a drop in frame rate, and providing a choice between compatibility mode (enabling full shader emulation) and performance mode (disabling MIRROR_ONCE).

[0221] Experiments have verified that this invention has the following characteristics:

[0222] With performance overhead approaching that of native GPUs, the extra overhead of shaders is completely eliminated through multi-layer optimizations such as batch SIMD preprocessing, double buffering parallelism, persistent memory mapping, direct DMA transfer, and kernel command merging. The performance loss in the preprocessing stage is controlled within 2% to 3%, and the overall rendering performance is less than 2% different from that of the GPU natively supported by samplerMirrorClampToEdge, far exceeding existing software simulation solutions.

[0223] It achieves full coverage and timing consistency of fixed function scenes, realizing MIRROR_ONCE simulation of all fixed function scenes such as depth texture sampling, MSAA fixed function filtering, cube map face selection, and 3D texture depth sampling, with a scene coverage of 100%. Through synchronization mechanisms such as pipeline barriers, Vulkan events, and Fence, it ensures that the timing of coordinate preprocessing and hardware sampling is completely consistent, with no data read / write conflicts.

[0224] The interface conversion process is complete and without omissions. The steps strictly follow the complete interface conversion process from resource creation, sampler binding, pipeline construction, dynamic resource adaptation, command recording, kernel submission to result verification. It fills in key scenarios that were previously ignored, such as dynamic resource updates, dynamic sampler switching, and texture size changes, and ensures the consistency of the entire interface conversion process.

[0225] The data transfer latency between the CPU and GPU approaches zero. Through optimizations such as persistent memory mapping, double buffering parallelism, DMA exclusive channels, and data prefetching, the data transfer latency between the CPU and GPU is reduced to the microsecond level (<10 microseconds). Preprocessing and rendering are completely parallel with no waiting overhead.

[0226] The cross-GPU accuracy consistency is high. Through the regularized manufacturer calibration parameter table and edge scene verification, the rendering results of different GPU architectures deviate from native D3D12 by less than 1e-5, with no abnormalities such as texture stretching, edge jaggedness, color shift, or depth deviation.

[0227] Kernel-level optimizations reduce system overhead, command chain merging reduces GPU context switching by more than 90%, kernel parameter caching and cross-process sharing reduce system resource consumption by 30%, and performance degradation during concurrent multi-D3D12 application runtime is less than 5%;

[0228] It boasts strong compatibility and no driver dependency, requiring no modification to the GPU chip driver. It is implemented solely through modifications to the VKD3D source code and Linux kernel source code, supporting all versions of Vulkan 1.0 and above, covering over 95% of existing GPU devices, and does not alter the application layer interface, requiring no additional application adaptation.

[0229] 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.

Claims

1. A Direct3D 12 sampler addressing mode compatible method based on double buffering pre-processing, characterized in that, Specifically, the following steps are included: During kernel initialization, a first cache pool is established to store sampler identifiers and MIRROR_ONCE preprocessing parameters. During VKD3D initialization, a first association table between samplers and textures, a second association table between pipelines and preprocessing parameters, and a resource management linked list are created. The resource management linked list records attributes and associated configurations using the texture resource handles related to MIRROR_ONCE as indexes. At startup, a first structure is registered to record the texture logical coordinate range and MSAA sampling point offset markers. The first cache pool is initialized to enable cross-application reuse. When a D3D application creates a texture, VKD3D obtains the texture resource information. If it is related to MIRROR_ONCE and already exists in the resource management list, the resource management list is updated. If it is related but does not exist in the resource management list, a MIRROR_ONCE resource tag is allocated, a dependency tag is set, a preprocessing coordinate buffer with a double buffer structure is allocated, and it is added to the resource management list. The texture logical coordinate range is expanded by the first structure. When it is an MSAA texture, the number of MSAA sampling points is set to the original value, and an MSAA sampling point offset tag is added to the first structure. If it is not related, a standard texture conversion is performed. When creating a sampler, if the 3D texture coordinate addressing mode is single mirror and edge clamping, the sampler is marked as a simulated sampler. The sampler parameters are recorded to generate simulated markers. The Vulkan sampler is constructed with the MIRROR_ONCE dimension addressing mode set to CLAMP_TO_EDGE to complete the sampler and boundary color mapping. The texture resource and sampler are bound and added to the first association table. The MIRROR_ONCE activation status of the texture resource in the resource management chain is set to TRUE. When creating the pipeline, the D3D12 shader is converted to a Vulkan shader, and the association between the pipeline handle and preprocessing parameters is added to the second association table. When executing command recording, the first and second association tables are queried. When the pipeline is associated with MIRROR_ONCE and the texture is in the MIRROR_ONCE active state, the parameters required for coordinate preprocessing are extracted, and the coordinate preprocessing of the original texture coordinates is completed to obtain the Vulkan command buffer to be submitted. The command buffer is submitted to the GPU, and the GPU completes the rendering.

2. The Direct3D 12 sampler addressing mode compatible method of claim 1, wherein, When a texture resource is created after the D3D application starts, VKD3D obtains the texture type, dimensions, format, sample count, and resource purpose of the texture resource, and determines whether the texture resource is a MIRROR_ONCE related texture resource based on the resource purpose.

3. The Direct3D 12 sampler addressing mode compatible method according to claim 1, characterized in that, The method for setting the dependency flag is as follows: when the texture resource is in a depth template format or a compressed format, its dependency flag is set to a fixed function sampling dependency; when the texture resource is a dynamically updated texture, its dependency flag is set to a real-time preprocessing dependency.

4. The Direct3D 12 sampler addressing mode compatible method according to claim 1, characterized in that, The method for updating the resource management list is as follows: match the resource handle of the corresponding texture in the resource management list, and verify the validity of the existing MIRROR_ONCE resource flag; update the parameters in the table entry, and if the texture purpose, format, or sample count changes, synchronously update the flags of fixed function sampling dependencies or real-time preprocessing dependencies; if the texture size remains unchanged, retain the original preprocessing coordinate buffer and only update the buffer association state; if the texture size changes, reallocate the buffer according to the new size and update the buffer handle and activation index in the resource management list; if the original associated sampler remains unchanged, maintain the binding relationship; otherwise, update the texture handle list and dynamic switching flag in the first association table.

5. The Direct3D 12 sampler addressing mode compatible method according to claim 1, characterized in that, The method for converting the D3D12 shader to a Vulkan shader during pipeline creation and adding the association between the pipeline handle and preprocessing parameters to the second association table is as follows: The texture sampling instructions in the shader are parsed, and the first association table is queried. If the sampler associated with the texture sampling instruction is the MIRROR_ONCE simulated sampler, a preprocessing coordinate buffer binding flag is added to the SPIR-V shader. The preprocessing coordinate buffer slot is then created by adding a set value based on the current sampler's binding slot, removing redundant coordinate calculation code, modifying the SPIR-V resource decoration instruction OpDecorate to bind the preprocessing coordinate buffer to the default slot of each shader, and adding a read-only access permission flag. The coordinate input of the texture sampling instructions in SPIR-V is changed from the original coordinates to the reading result of the preprocessing coordinate buffer. Otherwise, the standard sampling process is followed, and no binding flag is added. Meanwhile, VKD3D parses all configuration parameters of the D3D12 graphics pipeline state. If depth comparison is enabled and the depth texture is associated with the MIRROR_ONCE sampler, MSAA is enabled and the rendering target is associated with the MIRROR_ONCE sampler, or the cube map is bound to a fixed function unit and associated with the MIRROR_ONCE sampler, then the pipeline is marked as a fixed function MIRROR_ONCE pipeline, and a dual trigger point is added to it in the pipeline state management module to create a Vulkan native hardware-level synchronization event. Write the simulation tag ID, preprocessing coordinate buffer binding slot, timing synchronization event handle, and MSAA sampling point offset tag into the additional data field of the preprocessing coordinate buffer, and add the association between the pipeline handle and the preprocessing parameters to the second association table.

6. The Direct3D 12 sampler addressing mode compatible method according to claim 1, characterized in that, When the application executes the D3D12 command list recording, VKD3D queries the first and second association tables. When the pipeline is associated with MIRROR_ONCE and the texture is in the MIRROR_ONCE active state, it extracts the data required for coordinate preprocessing, including the original texture coordinates, texture type and size, the sampler's MIRROR_ONCE enabled dimension, precision calibration parameters, and preprocessing block size. For the dimensions in the original texture coordinates where MIRROR_ONCE is enabled, the CPU SIMD instruction set is used to clamp the original texture coordinates to the effective mirror interval using a branchless mathematical formula. The branchless mirror factor is calculated to distinguish between negative and positive intervals. The branchless mirror factor is used to perform mirror calculations to map the invalid interval results to the effective interval, and then the clamping operation is performed. For the dimensions in the original texture coordinates where MIRROR_ONCE is not enabled, the original coordinates are not changed. After completing the coordinate preprocessing, the Vulkan command buffer to be submitted is obtained.

7. The Direct3D 12 sampler addressing mode compatible method according to claim 1, characterized in that, For special texture types, the coordinate preprocessing method is as follows: For cube maps, the face index is first determined based on the original coordinates during preprocessing, and then the invalid interval results are mapped to the valid interval by performing a mirror calculation using a branchless mirror factor on the face coordinates; For 3D textures, the invalid interval results are mapped to the valid interval by performing a mirror calculation using a branchless mirror factor on the Z-axis coordinates, and the clamping parameters are adjusted according to the texture depth; For MSAA textures, the offset coordinates of each MSAA sampling point are obtained and then superimposed on the preprocessed coordinates.

8. The Direct3D 12 sampler addressing mode compatible method according to claim 1, characterized in that, When VKD3D submits a Vulkan command buffer to the kernel, it parses the command buffer. If the bound buffer contains a preprocessed coordinate buffer flag, the sampler is in CLAMP_TO_EDGE mode, or there is a pipeline barrier or event wait for MIRROR_ONCE, the Vulkan command buffer is marked as a MIRROR_ONCE related command buffer. When the Vulkan command processor identifies consecutive MIRROR_ONCE-related command buffers in the same rendering batch, it merges them into a command chain, allocates an independent DMA transfer channel for the command chain, and enables DMA interrupt merging. When the DMA transfer is completed or the command chain execution ends, the kernel triggers an interrupt. The interrupt handler only performs status updates and semaphore notifications.

9. The Direct3D 12 sampler addressing mode compatible method according to claim 8, characterized in that, The commands in the command chain are arranged in the following order from front to back: double buffer status check command, DMA transfer command, cache synchronization command, pipeline barrier command, batch rendering command, and Fence signal command.

10. The Direct3D 12 sampler addressing mode compatible method according to claim 1, characterized in that, When VKD3D starts, it extracts the precision parameters of physical devices, texture formats, and samplers, and sets matching preprocessing precision levels for different types of textures and samplers based on these parameters. Based on the GPU manufacturer's calibration parameter table, the default precision offset and scaling parameters are initialized; then, the extreme coordinates of the texture are sampled and verified, and the calibration parameters are dynamically adjusted according to the deviation threshold. When the deviation is too large, FP64 high-precision calculation is enabled for extreme areas; at the same time, precision calibration is performed for depth textures and MSAA scenes with fixed function pipelines to correct the deviation of depth sampling and sampling point offset. When the preprocessing accuracy level fails, batch preprocessing is disabled or rolled back to clamping mode according to programmable and fixed function scenarios respectively; when the performance loss exceeds the limit, the processing block size is adjusted or the performance priority mode is enabled; when it is detected that the GPU does not support the critical Vulkan extension, a prompt is made at the start of the application and the selection of compatibility mode and performance mode is provided, while the reason for the downgrade is recorded and a prompt window pops up.

Citation Information

Patent Citations

  • 3D graphics driver for segmenting frame into plurality of command buffer submissions based on analysis of previous frame

    CN116071489A

  • Kernel source adaptation for execution on graphics processing unit

    CN116339739A