A Direct3D 12 view implementation method based on LOD state dynamic injection

By creating a shared memory area and a sampler reuse pool when the GPU does not support the VK_EXT_image_view_min_lod extension, the problems of the number of Sampler instances exploding and the rendering frame rate dropping are solved, achieving efficient resource management and rendering consistency.

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

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
北京麟卓信息科技有限公司
Filing Date
2026-03-04
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

In the absence of GPU support for the VK_EXT_image_view_min_lod extended feature, existing technical solutions suffer from problems such as an explosive increase in the number of Sampler instances, excessive GPU memory usage, complex resource management, decreased rendering frame rate, high compatibility risks, and difficulty in balancing LOD semantic consistency with performance overhead.

Method used

By creating a shared memory area and a sampler reuse pool, a multi-layered mapping relationship is established. The creation, update, and destruction operations of SRV and samplers are intercepted and synchronized. Resource reuse is managed using hash values, metadata status is updated synchronously, LOD limit status is forced to be synchronized, and an effective minLod value injection command is constructed to ensure rendering consistency.

Benefits of technology

It achieves efficient management of SRV and sampler resources on GPUs that do not support the VK_EXT_image_view_min_lod extension, reduces memory usage, avoids deadlock and resource leaks, and ensures consistent rendering results and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121785822B_ABST
    Figure CN121785822B_ABST
Patent Text Reader

Abstract

The application discloses a Direct3D 12 view implementation method based on LOD state dynamic injection, and creates shared memory mapping containing a metadata area and a first cache area to a VKD3D user state when VK_EXT_image_view_min_lod is not supported, establishes third and fourth mappings and creates a sampler multiplexing pool after the VKD3D is started; intercepts and processes the creation of an SRV and a D3D12 sampler and the like, maintains cross-layer mapping and metadata, triggers cache invalidation; establishes mapping and binding context when the SRV is bound with the sampler, enhances the metadata hash carried by the descriptor set and the like, checks the metadata, recalculates the effective minLod and constructs injection commands to reconstruct and bind commands when submitting, and after the command buffer is submitted, the GPU executes the reconstructed command stream to realize the native D3D12 rendering effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer software development technology, specifically relating to a Direct3D 12 view implementation method based on dynamic injection of LOD state. Background Technology

[0002] VKD3D is an open-source project that simulates Direct3D 12 (hereinafter referred to as D3D12) based on the Vulkan 1.3 standard. Its core workflow is to translate D3D12 API calls on the Windows platform into Vulkan API calls on the Linux platform. In the D3D12 rendering architecture, the texture shader resource view (SRV) is the key interface connecting texture data and shaders. Its minLod parameter is an inherent property of the SRV, used to limit the minimum level of detail (LOD) during sampling. That is, when the sampled LOD value calculated by the shader is lower than minLod, minLod will be forced to be used as the final sampled LOD to achieve specific visual effects or bandwidth optimization. However, in the native Vulkan architecture, the semantics of minLod are fundamentally different from those in D3D12: Vulkan defines minLod as an independent property of the sampler, completely decoupled from the image view (VkImageView). During sampling, LOD constraints are only enforced through the bound sampler. The core value of the VK_EXT_image_view_min_lod extension lies in bridging this semantic gap, allowing the addition of a minLod parameter to VkImageView. During sampling, the maximum value of the ImageView's minLod and the Sampler's minLod is taken as the effective LOD, thereby achieving a restored mapping with the semantics of D3D12 SRVminLod.

[0003] However, existing technical solutions have insurmountable drawbacks when the GPU does not support this extension: When using the sampler pooling scheme, due to the dynamic binding relationship between SRV and Sampler in D3D12, a dedicated Sampler needs to be created for each combination of SRV minLod and Sampler parameters. This leads to an explosive increase in the number of Sampler instances, consuming a large amount of video memory and driver resources. Moreover, the synchronization management in multi-threaded scenarios is prone to deadlock or resource leaks. When using the shader rewriting scheme, it is necessary to intercept the D3D12 shader bytecode and inject LOD calculation logic. This not only faces the complex adaptation problem of HLSL and SPIR-V instruction sets, but also increases the additional GPU instruction execution overhead, resulting in a decrease in rendering frame rate. At the same time, the modified shader is difficult to debug, and the compatibility risk is extremely high.

[0004] Furthermore, existing solutions have failed to address the core contradiction between LOD semantic consistency and performance overhead in dynamically bound scenarios: how to quickly synchronize LOD constraint states when dynamically switching SRVs or Samplers without introducing significant CPU / GPU performance overhead; how to ensure that metadata synchronization and LOD states take effect in real time when D3D12 applications dynamically update SRV attributes; and how to accurately map SRVminLod semantics for special texture types such as multi-sampled textures MSAA and texture arrays. These issues have become key bottlenecks restricting VKD3D's compatibility with low-specification GPUs. Summary of the Invention

[0005] In view of this, the present invention provides a Direct3D 12 view implementation method based on dynamic injection of LOD state, which enables the compatible operation of D3D12 applications even when the GPU does not support the VK_EXT_image_view_min_lod extension feature.

[0006] This invention provides a Direct3D 12 view implementation method based on dynamic injection of LOD state, which specifically includes the following steps:

[0007] After system startup, an independent shared memory area is created, including a metadata area that stores the first mapping between Vulkan image view and SRV metadata, and a first cache area that stores the second mapping between Vulkan image view handles and sampler handles and valid minLod values. The shared memory area is then mapped to the user space of VKD3D. After VKD3D starts, a third mapping is established between SRV handles and SRV metadata pointers, and a fourth mapping is established between descriptor heap handles and heap indexes and SRV handles. A sampler multiplexing pool is also established, with the sampler parameter hash value as the key and the sampler metadata value as the value.

[0008] When a D3D application creates a D3D12 sampler, VKD3D converts the creation parameters into Vulkan sampler creation parameters, calculates the sampler parameter hash value, and if it exists in the sampler reuse pool and the related sampler metadata is already created, it reuses the sampler handle; otherwise, it creates a Vulkan sampler, initializes the sampler metadata, sets its status to "created," adds it to the sampler reuse pool, and establishes a fifth mapping between the sampler handle and the sampler metadata. When modifying sampler parameters, it modifies the sampler metadata in the fifth mapping, sets the validity flag of the SRV cache bound to it to invalid, calculates the sampler parameter hash value, and updates the entry if it has changed; otherwise, it remains unchanged. When binding an SRV to a sampler, it establishes a mapping relationship between the SRV and the sampler according to different binding modes, and then creates a binding context.

[0009] When VKD3D creates a Vulkan descriptor set layout, it adds the hash value of SRV metadata, the hash value of Vulkan sampler metadata, and the identifier of the binding context. When submitting the D3D12 descriptor set, it synchronously updates the SRV and sampler metadata status, verifies the metadata according to the first mapping, and if they are inconsistent, it forces synchronization and calculates a valid minLod value; otherwise, it obtains a valid minLod value from the first buffer. It constructs a valid minLod value, injects commands to reconstruct the binding commands of SRV and sampler, submits the command buffer to the GPU queue, and the GPU executes the command stream to complete the rendering.

[0010] Furthermore, the sampler parameter hash value is the hash value of the immutable parameters set when the Vulkan sampler is created.

[0011] Furthermore, the method of verifying metadata based on the first mapping, and forcibly synchronizing and calculating a valid minLod value if inconsistent, is as follows:

[0012] Step 5.1: For Vulkan image view handles, search for the corresponding SRV metadata in the first mapping, calculate its hash value. If it is the same as the hash value of existing SRV metadata, reuse the current valid minLod value; otherwise, for SRV metadata of type texture array, execute step 5.2 after extracting the array size, and for other types, execute step 5.2. For corresponding sampler handles, search for the corresponding Vulkan sampler metadata in the fifth mapping, calculate its hash value. If it is the same as the hash value of existing Vulkan sampler metadata, reuse the current valid minLod value; otherwise, execute step 5.2.

[0013] Step 5.2: If the SRV metadata type is MSAA texture, mark its effective minLod value as having no view-level restriction and end the calculation process; otherwise, for the Vulkan image view and sampler binding pair, take the larger value of view minLod and sampler minLod as the effective minLod value. When view minLod has no view-level restriction, set the effective minLod value to sampler minLod. When sampler minLod is not set, set the effective minLod value to view minLod. When the effective minLod value is greater than sampler maxLod, set it to sampler maxLod.

[0014] Furthermore, the method of verifying metadata based on the first mapping and forcing synchronization and calculating a valid minLod value if inconsistent is as follows: for texture array types, an independent valid minLod value is calculated for each array unit.

[0015] Furthermore, the method for constructing the effective minLod value injection command to reconstruct the binding command between the SRV and the sampler is as follows:

[0016] Construct a valid minLod value injection command. The command data includes the target sampler handle, valid minLod value, bound shader stage mask and injection effective range. The valid minLod value validity flag and metadata version number are the verification field and extension field, respectively. The command data is encapsulated into a Vulkan command as the injection command using the same binary format as the native command according to the Vulkan command buffer encoding method. The command flow is reconstructed in the order of the original bound command, memory barrier, injection command and then subsequent commands.

[0017] Furthermore, VKD3D traverses the command buffer, checks the cache validity flag of the SRV metadata, and if it is invalid, waits for the cache to be written before committing; it verifies the construction status and pre-verification results of the injected command, and allows submission after confirming that there are no errors.

[0018] Furthermore, VKD3D submits the processed command buffer to the GPU queue. When the driver does not support dynamic state expansion, the injected command pre-verification fails, or the metadata synchronization continues to fail, a degradation is triggered. The sampler is first replaced with a temporary sampler in the temporary sampler pool, bound to the descriptor set, and then submitted. After execution, the temporary sampler is recycled back to the temporary sampler pool. The temporary sampler pool is a temporary sampler created by VKD3D that contains valid minLod values.

[0019] Furthermore, a dynamic state snapshot is maintained for each command buffer to record the injected minLod state, ensuring state isolation between command buffers; after the GPU finishes executing the command buffer, the sampler's original minLod state is restored; in multi-command buffer scenarios, queue-level synchronization is achieved through the VkSemaphore command.

[0020] Furthermore, when the SRV and sampler metadata status are updated synchronously during the submission of the D3D12 descriptor set, a metadata update notification containing the SRV handle and SRV metadata version is generated, and the corresponding cache item invalidation operation is triggered by the metadata update notification.

[0021] Furthermore, when the D3D application destroys an SRV, VKD3D looks up the corresponding SRV metadata based on the SRV handle, sets the binding status in its binding attribute to unbound, sets the SRV metadata version to 0, deletes the corresponding entry in the first mapping, and generates a metadata destruction notification. The metadata destruction notification triggers the cleanup operation of the corresponding cache items and parsing results.

[0022] Beneficial effects:

[0023] This invention creates shared memory containing a metadata area and a first cache area after system startup and maps it to the VKD3D user space. After VKD3D starts, it establishes and locks the third and fourth mappings, and simultaneously creates a sampler reuse pool. When a D3D application performs creation, update, or destruction operations on an SRV, VKD3D intercepts and completes the initialization, modification, and cleanup of the SRV metadata, synchronously maintaining cross-layer mapping relationships and kernel-level synchronization markers, triggering corresponding cache invalidation. When an application performs creation, modification, or destruction operations on a D3D12 sampler, VKD3D converts the parameters to Vulkan format, achieves resource reuse through the sampler reuse pool, maintains the fifth mapping, synchronously updates metadata, adjusts reference counts, and... The process involves triggering cache cleanup; when applying the binding SRV and sampler, VKD3D establishes a mapping relationship between them based on the descriptor heap or root signature binding mode and creates a binding context, enhancing the Vulkan descriptor set layout and entries to carry metadata hashes and binding context identifiers, synchronously updating the SRV and sampler metadata status when submitting the descriptor set, verifying metadata consistency, forcing synchronization and recalculating the valid minLod value in cases of hash inconsistency, and finally constructing and injecting the command with that value to reconstruct the binding command; finally, completing the command buffer verification and submitting it to the GPU queue, the GPU executes the reconstructed command stream, and completes texture sampling based on the injected valid minLod value to achieve the same rendering effect as native D3D12. Attached Figure Description

[0024] Figure 1 This is a flowchart illustrating a Direct3D 12 view implementation method based on dynamic injection of LOD state provided by the present invention. Detailed Implementation

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

[0026] This invention provides a Direct3D 12 view implementation method based on LOD state dynamic injection. The core idea is as follows: After system startup, a shared memory containing a metadata area and a first cache area is created and mapped to the VKD3D user space; after VKD3D starts, it establishes and locks the third and fourth mappings, and simultaneously creates a sampler reuse pool; when the D3D application performs creation, update, and destruction operations on SRVs, VKD3D intercepts and completes the initialization, modification, and cleanup of SRV metadata, synchronously maintains cross-layer mapping relationships and kernel-level synchronization markers, and triggers corresponding cache invalidation; when the application performs creation, modification, and destruction operations on D3D12 samplers, VKD3D converts the parameters to Vulkan format, achieves resource reuse through the sampler reuse pool, maintains the fifth mapping, and synchronously updates metadata and calls... The reference count is incremented and cache cleanup is triggered. When the application binds the SRV and the sampler, VKD3D establishes a mapping relationship between the two based on the descriptor heap or root signature binding mode and creates a binding context. The Vulkan descriptor set layout and entries are enhanced to carry metadata hashes and binding context identifiers. When the descriptor set is submitted, the SRV and sampler metadata status are updated synchronously, metadata consistency is checked, and synchronization is forced and a valid minLod value is recalculated in the case of inconsistent hashes. Finally, a command with this value is constructed and injected to reconstruct the binding command. Finally, the command buffer is checked and submitted to the GPU queue. The GPU executes the reconstructed command stream and completes texture sampling based on the injected valid minLod value to achieve the same rendering effect as native D3D12.

[0027] This invention provides a Direct3D 12 view implementation method based on dynamic injection of LOD state, the processing flow of which is as follows: Figure 1 As shown, the specific steps include:

[0028] Step 1: After system startup, detect whether the device supports the VK_EXT_image_view_min_lod extension feature. If it does, use the native adaptation logic of VKD3D and end this process; otherwise, create independent shared memory areas, including a metadata area and a first cache area. The metadata area is used to store the first mapping between the Vulkan image view and SRV metadata, and the first cache area is used to store the second mapping between the Vulkan image view handle and sampler handle and the valid minLod value and cache item status. Map the shared memory area to the VKD3D user-mode address space and set memory protection attributes, then proceed to Step 2.

[0029] The SRV metadata includes fields such as basic identifier, LOD attribute, texture attribute, binding attribute, and caching and synchronization. The basic identifier includes the SRV handle, descriptor heap index, and associated D3D12 texture handle. The LOD attribute includes the view-level minLod value, minLod source, and MSAA texture tag. The texture attribute includes the texture type, mipmap level range, and array texture length. The binding attribute includes the binding status, the last bound sampler handle, and the bound shader stage mask. The caching and synchronization includes the cached valid minLod value, cache validity flag, metadata version number, and last update timestamp.

[0030] The Vulkan image view wrapper also includes fields such as association identifier, texture properties, and lifecycle and synchronization. The association identifier includes the associated D3D12 SRV handle, the associated Vulkan image handle, and a pointer to the SRV metadata. The texture properties include the MSAA flag inherited from the SRV metadata and the Vulkan image view type. The lifecycle and synchronization include the image view status flag, the synchronization to kernel flag, and the mutex. The image view status flag includes uninitialized, created, pending destruction, and destroyed.

[0031] Step 2: After VKD3D starts, a hash table is created as the third mapping, with the key being the SRV handle and the value being a pointer to SRV metadata. A hash table is created as the fourth mapping, with the key being the descriptor heap handle and heap index and the value being the SRV handle. Independent read-write locks are allocated to the third and fourth mappings. Read operations use shared locks and write operations use exclusive locks. A sampler multiplexing pool is created, with the key being the sampler parameter hash value and the value being the sampler metadata.

[0032] Step 3: When the D3D application starts and creates an SRV, VKD3D intercepts and extracts parameters such as the texture resource handle associated with the SRV, the access rule descriptor, the descriptor stack to which the SRV needs to be bound, and the offset of the SRV in the descriptor stack. It parses the associated texture and access rules of the SRV, creates SRV metadata, and completes initialization. When the texture associated with the SRV has a corresponding Vulkan image, the SRV is associated with the corresponding Vulkan image view wrapper through the texture handle, and the SRV metadata is associated with the Vulkan image view and added to the first mapping. When the texture associated with the SRV does not have a corresponding Vulkan image, a native Vulkan image and image view are created based on the SRV metadata, the handle of the Vulkan image and image view is obtained, the corresponding Vulkan image view wrapper is created, and the SRV metadata is associated with the Vulkan image view and added to the first mapping.

[0033] When a D3D application updates an SRV, VKD3D parses the new SRV descriptor to extract the updated minLod value, modifies the LOD attribute and cache and synchronization information of the corresponding SRV metadata, and generates a metadata update notification containing the SRV handle and SRV metadata version. The metadata update notification triggers the corresponding cache item invalidation operation. It then iterates through the Vulkan image view wrapper corresponding to the SRV in the first mapping, sets its lifecycle and synchronization field to the kernel synchronization flag to be synchronized, and then synchronizes it to the kernel layer in batches.

[0034] When a D3D application destroys an SRV, VKD3D looks up the corresponding SRV metadata based on the SRV handle, sets the binding status in its binding attribute to unbound, sets the SRV metadata version to 0, deletes the corresponding entry in the first mapping, and generates a metadata destruction notification. The metadata destruction notification triggers the cleanup of the corresponding cache items and parsing results.

[0035] Step 4: When the D3D application creates a D3D12 sampler, VKD3D converts the creation parameters into a Vulkan sampler structure and calculates the hash value of the immutable parameters set when creating the Vulkan sampler as the sampler parameter hash value. If the sampler parameter hash value exists in the sampler reuse pool and the corresponding Vulkan sampler metadata is in the created state, then its sampler handle is reused and its reference count is incremented by 1. If not, a native Vulkan sampler is created, the Vulkan sampler metadata is initialized, its reference count is set to 1, its state is set to created, the sampler parameter hash value is associated with the Vulkan sampler metadata and added to the sampler reuse pool, and the Vulkan sampler handle is associated with the Vulkan sampler metadata and added to the fifth mapping.

[0036] When modifying the D3D12 sampler parameters, VKD3D parses the new parameters, looks up the corresponding Vulkan sampler metadata in the fifth mapping, modifies the minLod related fields, increments the metadata version by 1, sets the cache validity flag of the SRV bound to it to invalid, generates a sampler metadata update notification, triggers the invalidation operation of related cache items by the sampler metadata update notification, calculates the sampler parameter hash value, if it changes, removes the corresponding entry from the sampler reuse pool and adds the new entry, otherwise it remains unchanged;

[0037] When a D3D12 sampler is destroyed, VKD3D decrements the reference count of its corresponding Vulkan sampler metadata by 1. When the reference count is 0 and there is no SRV bound to it, its status is marked as pending destruction. After the current command buffer is executed, the corresponding entry is deleted from the fifth mapping and sampler reuse pool, and a sampler destruction notification is generated. The sampler destruction notification triggers the cleanup operation of the corresponding cache item.

[0038] The Vulkan sampler metadata designed in this invention includes fields such as basic identifier, LOD attribute, reuse and binding, and status. The basic identifier field contains the native Vulkan sampler handle and sampler name. The LOD attribute field contains the native minLod value, native maxLod value, and mipmap filtering mode. The reuse and binding field contains the sampler parameter hash value, reference count, and the set of bound SRV handles. The status field contains the status and metadata version number, and the status can be created, bound, or to be destroyed.

[0039] The immutable parameters set when creating a Vulkan sampler include magFilter, minFilter, mipmapMode, addressMode, maxAnisotropy, samplerMinLod, and samplerMaxLod.

[0040] Step 5: When binding SRVs and samplers in D3D applications, for descriptor heap binding mode, VKD3D obtains the SRV descriptor heap, sampler array, starting descriptor index, and number of descriptors. It then establishes a mapping relationship between the SRV descriptor heap index and the sampler index according to the D3D12 SRV register and sampler register binding rules. For root signature binding mode, VKD3D obtains the root signature parameter index and descriptor table pointer, parses the descriptor range array in the descriptor table, distinguishes between SRV ranges and sampler ranges, and establishes a mapping relationship between SRVs and samplers based on the range offset and range size. A binding context is created based on the mapping relationship, including the shader stage, binding mode, SRV sampler mapping relationship list, and binding timestamp.

[0041] When VKD3D creates a Vulkan descriptor set layout, it adds the hash values ​​of SRV metadata, Vulkan sampler metadata, and the identifier of the binding context to the Vulkan descriptor set layout. In a full binding scenario, it populates standard fields such as Vulkan image view handle, sampler handle, and texture layout, as well as extended fields such as the hash values ​​of SRV metadata, Vulkan sampler metadata, and the identifier of the binding context, and calculates the effective minLod value to add to the second mapping.

[0042] When submitting the D3D12 descriptor set, for each bound SRV, the corresponding SRV metadata is looked up through the third mapping, its status is set to "bound to pipeline", the currently bound shader stage is added, the last bound sampler handle is updated to the currently bound sampler handle, and the SRV metadata synchronization is completed. For each bound sampler, the corresponding Vulkan sampler metadata is looked up through the fifth mapping, its reference count is incremented by 1, the SRV handle is added to the bound SRV handle set, the cache validity flag of the bound SRV is set to invalid, and the metadata is validated. When the metadata hash is inconsistent, the latest metadata is forcibly synchronized and the valid minLod value is recalculated, the second mapping is updated, and a valid minLod value injection command is constructed and executed to reconstruct the binding command between the SRV and the sampler.

[0043] Furthermore, the cache validity flag bound to the SRV is set to invalid, and the metadata is validated. When the metadata hash is inconsistent, the latest metadata is forcibly synchronized and the valid minLod value is recalculated. The specific method is as follows:

[0044] Step 5.1: For Vulkan image view handles, search for the corresponding SRV metadata in the first mapping and calculate its hash value. If it is the same as the hash value of existing SRV metadata, reuse the currently valid minLod value in the second mapping; otherwise, for SRV metadata of type texture array, execute step 5.2 after extracting the array size, and for other types, directly execute step 5.2. For the corresponding sampler handles, search for the corresponding Vulkan sampler metadata in the fifth mapping and calculate its hash value. If it is the same as the hash value of existing Vulkan sampler metadata, reuse the currently valid minLod value in the second mapping; otherwise, execute step 5.2.

[0045] Step 5.2: If the SRV metadata type is MSAA texture, mark its effective minLod value as having no view-level limitation and end the calculation process; otherwise, for the Vulkan image view and sampler binding pair, take the larger value of view minLod and sampler minLod as the effective minLod value. When view minLod has no view-level limitation, set the effective minLod value to sampler minLod. When sampler minLod is not set, set the effective minLod value to view minLod. When the effective minLod value is greater than sampler maxLod, set it to sampler maxLod.

[0046] In addition, for texture array types, an independent effective minLod value is calculated for each array cell to ensure that the LOD limit is consistent for all texture cells in the array.

[0047] Furthermore, the method for constructing and executing the valid minLod value injection command to reconstruct the binding command between the SRV and the sampler is as follows:

[0048] Construct a valid minLod value injection command. The command data includes core parameters such as the target sampler handle, valid minLod value, bound shader stage mask, and injection effective range, as well as validation fields and extended fields such as valid minLod value validity flag and metadata version number. The command data is encapsulated into a Vulkan command as the injection command using the same binary format as the native command according to the Vulkan command buffer encoding method. The command flow is reconstructed in the order of the original binding command, memory barrier, injection command and then subsequent commands, where the injection command of each binding pair follows the binding command of its corresponding descriptor set.

[0049] Furthermore, for multiple command buffers in the same queue, a state inheritance mechanism is used to allow subsequent command buffers to reuse the valid minLod value of the preceding command buffer adjacent to them, and to overwrite the original valid minLod value when the binding is changed.

[0050] Furthermore, for consecutive descriptor set binding commands, their corresponding injection commands are merged into a batch of injection commands and then executed in batches.

[0051] Step 6: After verifying the command buffer, submit it to the GPU queue. The GPU receives the submitted command buffer, executes the reconstructed Vulkan command stream, and completes texture sampling based on the injected valid minLod value to achieve rendering consistent with native D3D12 GPU.

[0052] Furthermore, the verification method for the command buffer is as follows: VKD3D traverses the command buffer, checks the cache validity flag of the SRV metadata, and if it is invalid, waits for the cache to be written before submitting; verifies the construction status and pre-verification results of the injected command, and allows submission after confirming that there are no errors.

[0053] Furthermore, VKD3D calls vkQueueSubmit to submit the processed command buffer to the GPU queue. When the driver does not support any dynamic state extensions, injected command pre-verification fails, or metadata synchronization continues to fail, automatic degradation is triggered. The sampler is first replaced with a temporary sampler from the temporary sampler pool, bound to the descriptor set, and then submitted. After execution, the temporary sampler is returned to the temporary sampler pool. The temporary sampler pool consists of temporary samplers created by VKD3D that contain valid minLod values.

[0054] Furthermore, this invention maintains a dynamic state snapshot for each command buffer, recording the injected minLod state to ensure state isolation between command buffers; after the GPU finishes executing the command buffer, the sampler's original minLod state is restored; in multi-command buffer scenarios, queue-level synchronization is achieved through the VkSemaphore command to ensure that the LOD state of the previous buffer takes effect before the subsequent buffer is executed.

[0055] Example:

[0056] This embodiment employs a Direct3D 12 view implementation method based on dynamic LOD state injection provided by the present invention. It achieves normal operation of D3D 12 applications in a GPU hardware environment that does not support the VK_EXT_image_view_min_lod extended feature. The specific process includes:

[0057] S1, D3D12 SRV creation and dynamic update interface interception and minLod metadata full lifecycle management.

[0058] S1.1, Intercepting D3D12 SRV Core Interfaces: Modify the VKD3D D3D12 core interface implementation module to comprehensively intercept SRV creation, update, and destruction related interfaces initiated by D3D12 applications, including:

[0059] The interface ID used for SRV creation is 3D12Device::CreateShaderResourceView;

[0060] The interface ID3D12Device::UpdateShaderResourceView used for updating SRV attributes, including minLod modification;

[0061] The interface ID used for SRV destruction is 3D12DescriptorHeap::ReleaseDescriptorRange;

[0062] Ensure that the entire lifecycle of SRV operations is covered, from creation to destruction.

[0063] S1.2, Extend the SRV descriptor parsing logic to support minLod extraction for all texture types:

[0064] S1.2.1 Added a texture type adaptation unit to adapt the corresponding SRV descriptor structure parsing logic for all texture types supported by D3D12 (2D textures, 3D textures, texture arrays, cube textures, cube texture arrays, multisampled textures (MSAA), MSAA textures with mipmaps, etc.):

[0065] For basic types such as D3D12_TEX2D_SRV, D3D12_TEX3D_SRV, and D3D12_TEXCUBE_SRV, the minLod field built into the structure is read directly.

[0066] For array types such as D3D12_TEX2D_ARRAY_SRV and D3D12_TEXCUBE_ARRAY_SRV, after extracting the minLod field, it is associated with the metadata of all texture units in the array;

[0067] For MSAA textures (D3D12_TEX2DMS_SRV, D3D12_TEX2DMS_ARRAY_SRV), since MSAA textures do not have a mipmap level by default, minLod is forcibly set to -FLT_MAX (unrestricted), and the isMSAATexture flag is set.

[0068] S1.2.2 For SRV descriptor types without an explicit minLod field (such as some legacy formats), minLod is set to -FLT_MAX by default, and the minLodSource field is recorded in the metadata (marked as default); for scenarios where the application explicitly sets minLod, minLodSource is marked as user-configured.

[0069] S1.3 Define an enhanced SRV metadata structure D3D12SRVMetadataEx, covering the entire lifecycle state:

[0070] Basic identification fields: srvHandle (unique handle to D3D12 SRV), descriptorHeapIndex (descriptor heap index), textureHandle (associated D3D12 texture handle);

[0071] LOD attribute fields: viewMinLod (view-level minLod value, floating-point type, precision retained to 6 decimal places), minLodSource (minLod source: default, user configuration, dynamic update), isMSAATexture (whether it is an MSAA texture, boolean type).

[0072] Texture attribute fields: textureType (texture type enumeration), mipRange (mipmap level range: baseMipLevel / levelCount), arraySize (array texture length, 1 for non-array types);

[0073] Binding property fields: bindState (unbound, bound to pipeline, unbound), lastBindSamplerHandle (handle of the last bound Sampler), boundShaderStages (mask of the bound shader stage, such as vertex shader, pixel shader).

[0074] Cache and synchronization fields: validMinLodCache (valid minLod value of the cache), cacheValidFlag (cache validity flag), metadataVersion (metadata version number, incremented with each update), updateTimestamp (last update timestamp).

[0075] S1.4 Creation and initialization of SRV metadata:

[0076] When the application calls CreateShaderResourceView, it allocates a D3D12SRVMetadataEx structure for each new SRV instance, initializes fields such as viewMinLod and textureType according to the parsing results, initializes metadataVersion to 1, and records the current system timestamp using updateTimestamp.

[0077] If the texture associated with the SRV already has a corresponding Vulkan Image (such as in a texture reuse scenario), then the texture handle is associated with the corresponding VkImageViewWrapper to complete the metadata binding in advance.

[0078] S1.5, Dynamic update processing of SRV metadata for the UpdateShaderResourceView interface:

[0079] S1.5.1 When the application calls UpdateShaderResourceView to modify the SRV property, parse the new SRV descriptor and extract the updated minLod value;

[0080] S1.5.2 Lock the corresponding D3D12SRVMetadataEx structure (using fine-grained locking), update the viewMinLod field, set minLodSource to dynamic update, atomically increment metadataVersion by 1, and updateupdateTimestamp;

[0081] S1.5.3 Synchronize the cacheValidFlag to invalid and send a metadata update notification to the VKSL layer through the user-space to kernel-space shared channel, carrying srvHandle and the new metadataVersion, triggering the invalidation of the corresponding cache item in the VKSL layer.

[0082] S1.6 Destruction and cleanup of SRV metadata for the ReleaseDescriptorRange interface:

[0083] S1.6.1 When an SRV is destroyed, the corresponding D3D12SRVMetadataEx is found through srvHandle, bindState is marked as unbound, and metadataVersion is set to 0 (invalid flag).

[0084] S1.6.2 Notify VkImageViewWrapper to remove the metadata association and delete the corresponding entry from imageViewToMetadataMap;

[0085] S1.6.3 Send a metadata destruction notification to the VKSL layer. The VKSL layer cleans up the corresponding cached items and parsing results to avoid accessing invalid metadata.

[0086] S1.7 Establish a high-concurrency and secure metadata mapping system:

[0087] S1.7.1 Global hash table srvMetadataMap: The key is srvHandle, and the value is a pointer to D3D12SRVMetadataEx. It adopts a hash bucket and red-black tree structure, supports lookup and update with O (log n) time complexity, and is suitable for high-concurrency scenarios.

[0088] S1.7.2, Auxiliary index table descriptorHeapToSrvMap: The key is the descriptor heap handle and heap index, and the value is srvHandle, which is used to quickly locate SRV metadata by descriptor heap location;

[0089] S1.7.3 Fine-grained locking mechanism: Each hash bucket is allocated an independent read-write lock. Read operations (queries) use shared locks, while write operations (creation, update, destruction) use exclusive locks. This supports multi-threaded concurrent access to metadata of different buckets, improving concurrency efficiency.

[0090] S2, Vulkan ImageView creation, special texture adaptation, and strong binding with SRV metadata.

[0091] S2.1, a Vulkan ImageView wrapper layer, supports association of special textures and metadata:

[0092] S2.1.1 Modify the VkImageViewWrapperEx struct (enhanced ImageView wrapper class), adding the following core fields:

[0093] Associated identifier fields: associatedSrvHandle (associated D3D12 SRV handle), associatedTextureHandle (associated Vulkan Image handle), metadataPtr (pointer to D3D12SRVMetadataEx).

[0094] Texture attribute fields: isMSAATexture (MSAA tag inherited from SRV metadata), imageViewType (Vulkan ImageView type, such as VK_IMAGE_VIEW_TYPE_2D_ARRAY);

[0095] Lifecycle and synchronization fields: imageViewLifetimeFlag (uninitialized, created, pending destruction, destroyed), metadataSyncFlag (whether metadata has been synchronized to the kernel layer), lock (mutex lock, protecting metadata access);

[0096] S2.1.2. Add an additional msaaSampleCount field (to record the number of MSAA samples, such as 4x or 8x) to the VkImageViewWrapperEx corresponding to the MSAA texture. This is used to skip LOD-related processing during subsequent dynamic injection (MSAA has no mipmap).

[0097] S2.2 Deep integration of ImageView creation process and metadata binding:

[0098] S2.2.1 When VKD3D processes a CreateShaderResourceView request, it synchronously performs the creation of a Vulkan Image or ImageView:

[0099] VkImageCreateInfo is generated based on D3D12 texture parameter conversion. For MSAA textures, mipLevels=1 is forcibly set and arrayLayers is matched to the length of D3D12 texture array.

[0100] When generating VkImageViewCreateInfo, set the viewType according to the textureType of D3D12SRVMetadataEx (e.g., the D3D12 texture array corresponds to VK_IMAGE_VIEW_TYPE_2D_ARRAY).

[0101] Call vkCreateImage and vkCreateImageView to create native Vulkan resources and obtain handles to VkImage and VkImageView.

[0102] S2.2.2 Initialize VkImageViewWrapperEx:

[0103] Assign values ​​to associatedSrvHandle and metadataPtr (looked up via srvMetadataMap);

[0104] Inherit isMSAATexture and msaaSampleCount (if it is an MSAA texture) from D3D12SRVMetadataEx.

[0105] Mark imageViewLifetimeFlag as created and metadataSyncFlag as not synchronized;

[0106] S2.2.3 If the texture associated with the SRV already exists as a Vulkan Image (texture reuse scenario), the existing Image is reused directly. Only a new ImageView is created and its metadata is bound to it, avoiding the duplication of resource creation.

[0107] S2.3 Establish a bidirectional metadata mapping table to support fast reverse lookups:

[0108] S2.3.1, imageViewToMetadataMap: The key is the native handle of Vulkan ImageView (VkImageView), and the value is a pointer to D3D12SRVMetadataEx, which is used by the kernel layer to quickly query SRV metadata through ImageView;

[0109] S2.3.2, srvToImageViewMap: The key is srvHandle, and the value is an array of pointers to VkImageViewWrapperEx (an SRV may correspond to multiple ImageViews, such as a multi-texture array unit), used to synchronize the state of all associated ImageViews when the SRV is updated.

[0110] S2.4 Metadata Synchronization Mechanism:

[0111] S2.4.1 After VkImageViewWrapperEx is initialized, VKD3D synchronizes the new entries in imageViewToMetadataMap to the VKSL layer through user-kernel shared memory. After synchronization is complete, metadataSyncFlag is marked as synchronized.

[0112] S2.4.2 When SRV metadata is updated via UpdateShaderResourceView, VKD3D iterates through all VkImageViewWrapperEx corresponding to the SRV in srvToImageViewMap, marks its metadataSyncFlag as pending synchronization, and triggers batch synchronization to the kernel layer to ensure that the kernel layer obtains the latest metadata.

[0113] S2.5 Lifecycle Binding and Resource Leakage Protection:

[0114] S2.5.1 Establish SRV-ImageView reference count association: VkImageViewWrapperEx maintains the srvReferenceCount field to record the number of associated SRVs; when an SRV is bound to an ImageView, the count is incremented, and when the SRV is destroyed, the count is decremented;

[0115] S2.5.2 When srvReferenceCount drops to 0 and imageViewLifetimeFlag is set to be destroyed, VKD3D calls vkDestroyImageView and vkDestroyImage (if the Image has no other references) to release Vulkan native resources and remove the corresponding entry from the bidirectional mapping table to avoid memory leaks.

[0116] S3, Vulkan Sampler creation, reuse, and full lifecycle management of native minLod metadata.

[0117] S3.1, Intercepting the entire lifecycle interface of VKD3D's Sampler: Modifying the Sampler-related encapsulation implementation in VKD3D, including:

[0118] vk3dCreateSampler (Sampler creation, corresponding to D3D12 sampler parameter conversion);

[0119] vk3dDestroySampler (Sampler destruction);

[0120] vk3dResetSampler (Resets the Sampler parameter if the application supports dynamic modification of the sampler).

[0121] Ensure coverage of the entire process of Sampler creation, updating, and destruction.

[0122] S3.2 Define the enhanced Sampler metadata structure VkSamplerMetadataEx:

[0123] Basic identifier fields: samplerHandle (Vulkan Sampler native handle), samplerName (debugging name, optional);

[0124] LOD attribute fields: samplerMinLod (native minLod value), samplerMaxLod (native maxLod value), mipmapMode (mipmap filtering mode, such as VK_SAMPLER_MIPMAP_MODE_LINEAR).

[0125] Reuse and bind fields: samplerParamsHash (hash value of sampler core parameters, 32-bit MurmurHash3 result), referenceCount (binding reference count), boundSrvHandles (set of bound SRV handles, hash table);

[0126] Status fields: samplerState (created, bound, awaiting destruction), metadataVersion (metadata version number, incremented during updates).

[0127] S3.3 Sampler Creation and Metadata Initialization:

[0128] When an application creates a D3D12 sampler, VKD3D converts its parameters into a VkSamplerCreateInfo structure and extracts core fields such as minLod, maxLod, and mipmapMode.

[0129] Calculate samplerParamsHash: Calculate the hash value based on immutable parameters such as magFilter, minFilter, mipmapMode, addressModeU, addressModeV, addressModeW, maxAnisotropy, samplerMinLod, and samplerMaxLod, which is used for Sampler reuse judgment;

[0130] Check the Sampler reuse pool: VKD3D maintains a Sampler reuse pool samplerReusePool with the key samplerParamsHash and the value a VkSamplerMetadataEx pointer; if a Sampler with a matching hash value exists and its status is already created, its samplerHandle is reused directly and its referenceCount is atomically incremented by 1, without needing to be recreated.

[0131] If no reusable Sampler is available, vkCreateSampler is called to create a native Vulkan Sampler, initializing the VkSamplerMetadataEx structure, setting referenceCount to 1, samplerState to "created", and adding samplerReusePool and samplerMetadataMap.

[0132] S3.4, Sampler metadata mapping table:

[0133] samplerMetadataMap: The key is samplerHandle, and the value is a pointer to VkSamplerMetadataEx, which is used to quickly query native metadata such as minLod through the Sampler handle;

[0134] samplerHashToMetadataMap: The key is samplerParamsHash, and the value is a list of pointers to VkSamplerMetadataEx. It is used for reusable pool queries and supports multiple Samplers corresponding to the same hash value (such as different debug names).

[0135] S3.5, Dynamic update handling of Sampler for vk3dResetSampler:

[0136] When the application dynamically modifies the Sampler parameters, parse the new VkSamplerCreateInfo and extract the updated samplerMinLod and other fields.

[0137] Lock the corresponding VkSamplerMetadataEx, update fields such as samplerMinLod and samplerMaxLod, and atomically increment metadataVersion by 1;

[0138] Iterate through all SRVs bound to the Sampler in the boundSrvHandles collection, mark the cacheValidFlag of these SRVs as invalid, and send a Sampler metadata update notification to the VKSL layer to trigger the invalidation of the relevant cache items;

[0139] Recalculate samplerParamsHash. If the hash value changes, remove the original reuse pool entry and add it to the entry corresponding to the new hash value to ensure the correctness of subsequent reuse logic.

[0140] S3.6, Sampler destruction and resource cleanup for vk3dDestroySampler:

[0141] When the application calls the destruction interface, look up the corresponding VkSamplerMetadataEx and atomically decrement its referenceCount by 1.

[0142] If referenceCount drops to 0 and boundSrvHandles is empty, then samplerState is marked as pending destruction. VKD3D delays the call to vkDestroySampler, waits for the current command buffer to finish executing, and deletes the corresponding entry from samplerMetadataMap and samplerReusePool.

[0143] A Sampler destruction notification is sent to the VKSL layer, and the VKSL layer cleans up the corresponding cached entries to prevent the kernel layer from accessing invalid Sampler metadata.

[0144] S4, D3D12 binding command conversion, and full-scenario construction of Vulkan descriptor sets.

[0145] S4.1, Intercept D3D12 full binding and dynamic update commands, modify the VKD3D command logging module to intercept all SRV and Sampler binding related commands initiated by D3D12 applications, including:

[0146] Full binding commands: IASetShaderResources, PSSetShaderResources, CSSetShaderResources, GSSetShaderResources (corresponding to different shader stages);

[0147] Dynamic update commands: ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable, SetComputeRootDescriptorTable (update the root signature descriptor table);

[0148] Ensure coverage of both full data binding and dynamic partial update scenarios.

[0149] S4.2 Parse the SRV-Sampler mapping in the binding command, supporting two binding modes: root signature and descriptor stack.

[0150] S4.2.1 Descriptor Heap Binding Mode Resolution:

[0151] Extract the SRV descriptor heap pDescriptorHeaps and Sampler array pSamplers, and obtain the starting descriptor index BaseDescriptor and the number of descriptors NumDescriptors;

[0152] Based on the binding rules of SRV registers and Sampler registers in D3D12 (e.g., t0 corresponds to s0), a one-to-one mapping relationship is established between the SRV descriptor heap index and the Sampler index, ensuring that each SRV matches a unique Sampler.

[0153] S4.2.2 Root Signature Binding Mode Parsing:

[0154] Extract the root signature parameter index RootParameterIndex and the descriptor table pointer pDescriptorTable;

[0155] Parse the DescriptorRange array in the descriptor table to distinguish between SRV ranges and Sampler ranges, and establish an SRV-Sampler mapping relationship based on RangeOffset and RangeSize.

[0156] S4.2.3 Record Binding Context: Create a binding context structure for each binding command, which includes the shader stage, binding mode, SRV-Sampler mapping list, and binding timestamp, for subsequent descriptor set construction and state synchronization.

[0157] S4.3 extends the Vulkan descriptor set layout and descriptor entries, supporting metadata carrying and partial updates:

[0158] S4.3.1, Descriptor Set Layout Enhancement: Modify the VkDescriptorSetLayout construction logic of VKD3D to add extended metadata fields to each entry of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, including:

[0159] srvMetadataHash: The hash value of D3D12SRVMetadataEx, used by the kernel layer to verify metadata consistency;

[0160] samplerMetadataHash: The hash value of VkSamplerMetadataEx;

[0161] bindingContextId: A unique identifier for the binding context;

[0162] These fields are attached via Vulkan's extended structure mechanism (pNext pointer chain), which does not affect the driver's parsing of standard fields and is only used for kernel-level adaptation.

[0163] S4.3.2, Descriptor entry construction:

[0164] Full binding scenario: When constructing the VkWriteDescriptorSet structure, populate standard fields such as imageView, sampler, and imageLayout, and write srvMetadataHash, samplerMetadataHash, and bindingContextId into the extended fields;

[0165] In some update scenarios: when updating the descriptor set via vkUpdateDescriptorSets, only the VkWriteDescriptorSet entries for the changed parts are constructed, and the metadata hash values ​​in the extended fields are updated synchronously to ensure that the kernel layer is aware of the changes.

[0166] S4.4, Full-Scene Management of Descriptor Sets:

[0167] Full binding scenario: A descriptor set cache pool and LRU eviction policy are adopted. The cache key is the binding context ID, SRV set hash and Sampler set hash. The default size of the cache pool is 2048 entries. When the pool is full, the least used descriptor set is evicted to reduce creation and destruction overhead.

[0168] Partial update scenarios: Maintain descriptor set update logs to record the scope of changes (such as specific entry indexes) and change types (SRV changes, Sampler changes, or both) of each vkUpdateDescriptorSets update. This is used by the kernel layer to accurately parse the changed binding pairs and avoid full parsing.

[0169] Descriptor set compatibility check: Before building the descriptor set, check the compatibility between VkDescriptorSetLayout and pipeline layout to ensure that extended metadata fields do not affect the layout check of the driver and avoid creation failure.

[0170] S4.5 State synchronization before descriptor set commit:

[0171] SRV metadata synchronization: For each bound SRV, look up D3D12SRVMetadataEx through srvMetadataMap, update its bindState to "bound to pipeline", add the currently bound shader stage to boundShaderStages, and update lastBindSamplerHandle to the currently bound Sampler handle.

[0172] Sampler metadata synchronization: For each bound Sampler, look up VkSamplerMetadataEx through samplerMetadataMap, atomically increment its referenceCount by 1, and add srvHandle to the boundSrvHandles collection;

[0173] Cache invalidation: Mark all cacheValidFlags bound to SRVs as invalid, triggering a recalculation of subsequent valid minLods;

[0174] Additional processing for partial update scenarios: If a partial update only changes the Sampler, then the lastBindSamplerHandle in the SRV metadata is updated synchronously, and the referenceCount of the original Sampler is decremented while the referenceCount of the new Sampler is incremented.

[0175] S5, Linux kernel Vulkan State Adaptation Layer (VKSL) enhanced initialization and command interception.

[0176] S5.1, Enhanced VKSL Layer Architecture: Modified the Linux kernel's Vulkan driver subsystem, upgrading the VKSL layer to a modular architecture, including:

[0177] Detection module: Responsible for GPU extension support detection and VKSL layer enablement control;

[0178] Shared memory management module: manages the metadata sharing channel from user space to kernel space;

[0179] Command interception module: Precisely intercepts target Vulkan commands;

[0180] Metadata parsing module: Parses the metadata mapping table in shared memory;

[0181] Effective minLod calculation module: executes the max(viewMinLod, samplerMinLod) logic;

[0182] Dynamic State Injection Module: Constructs and injects dynamic LOD commands;

[0183] Cache management module: manages the effective minLod cache at the kernel layer;

[0184] Error handling and degradation module: handles driver compatibility issues and degradation logic;

[0185] The modules communicate with each other through kernel-mode message queues, supporting parallel processing.

[0186] S5.2 Enhanced Initialization Process:

[0187] S5.2.1 Startup Detection: After the VKSL layer is enabled by the kernel module parameter (vksl_enable=1), it calls vkGetPhysicalDeviceFeatures2 and vkEnumerateDeviceExtensionProperties to detect whether the current GPU supports VK_EXT_image_view_min_lod and dynamic state extension (VK_EXT_dynamic_state2 or VK_KHR_dynamic_state).

[0188] S5.2.2, Adaptation Mode Selection:

[0189] If the GPU does not support VK_EXT_image_view_min_lod but does support VK_EXT_dynamic_state2: Enable dynamic state injection mode (main mode);

[0190] If the GPU does not support VK_EXT_dynamic_state2 but does support VK_KHR_dynamic_state: Enable the compatible dynamic state injection mode (adapting to older extensions).

[0191] If none of them are supported: Enable the degraded sampler pooling mode (backup mode).

[0192] S5.2.3 Shared memory initialization:

[0193] Create two independent shared memory regions: a metadata region (4MB, storing imageViewToMetadataMap and samplerMetadataMap) and a cache region (8MB, storing the kernel layer validMinLodCacheTable).

[0194] The shared memory is mapped to the user-space address space of VKD3D using mmap, and memory protection attributes are set (read-only in user space, read-write in kernel space) to prevent user-space tampering.

[0195] Establish a shared memory version synchronization mechanism: maintain metadataVersion and cacheVersion counters, increment the corresponding version after the user space updates the metadata, and the kernel layer determines whether it needs to be read again by the version number, thereby reducing invalid access.

[0196] S5.3, Precise Command Interception Rules:

[0197] Core command interception: Hooks are distributed via kernel-mode Vulkan commands to intercept the vkCmdBindDescriptorSets (full binding) and vkUpdateDescriptorSets (partial update) commands. Other commands (such as vkCmdDraw and vkCmdDispatch) are directly passed to the driver to ensure execution efficiency.

[0198] Interception and Filtering: Only commands initiated by VKD3D are intercepted (by checking the PID or process name of the process initiating the command), without affecting the normal operation of other Vulkan applications (such as native Linux Vulkan games);

[0199] Command queue management: Creates command queues for intercepted commands, categorized by command type (full binding, partial update), supports batch processing, and reduces interception overhead.

[0200] S6, VKSL layer command parsing, metadata verification, and precise minLod metadata query.

[0201] S6.1 Enhanced command parsing:

[0202] Full binding command (vkCmdBindDescriptorSets) analysis:

[0203] Parse command parameters: extract parameters such as commandBuffer, pipelineBindPoint, layout, descriptorSetCount, and pDescriptorSets;

[0204] Descriptor set traversal: For each descriptor set, obtain the memory region corresponding to the descriptor set through the kernel-mode Vulkan resource management interface, and traverse all entries of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER in it;

[0205] Extended field extraction: Extract srvMetadataHash, samplerMetadataHash, and bindingContextId from the extended structure of each entry;

[0206] Parsing of some update commands (vkUpdateDescriptorSets):

[0207] Parse parameters such as descriptorSetCount, pDescriptorSets, writeCount, and pWrites;

[0208] Based on dstBinding and dstArrayElement in pWrites, locate the changed descriptor entries and extract only the extended fields and standard fields (imageView, sampler) of the changed entries.

[0209] Associated descriptor set update log: Use bindingContextId to find the VKD3D synchronized descriptor set update log and verify the consistency of the change scope.

[0210] S6.2 Metadata Validation and Query:

[0211] S6.2.1, Metadata Consistency Verification:

[0212] For each parsed imageView handle, find D3D12SRVMetadataEx in the shared memory imageViewToMetadataMap, calculate its hash value and compare it with srvMetadataHash;

[0213] For the sampler handle, look up VkSamplerMetadataEx in samplerMetadataMap, calculate the hash value and compare it with samplerMetadataHash;

[0214] If the hash value does not match, it means that the metadata has been updated but not synchronized. In this case, a forced synchronization process is triggered to reread the latest metadata from the user-space shared memory to ensure the accuracy of the query.

[0215] S6.2.2 Special Texture Metadata Processing:

[0216] If D3D12SRVMetadataEx's isMSAATexture is true, then directly mark viewMinLod = -FLT_MAX and skip subsequent valid minLod calculations (MSAA has no mipmap).

[0217] For texture array types, extract the arraySize field to ensure that the effective minLod calculation covers all cells in the array;

[0218] S6.2.3 Metadata Query Failure Handling: If the query fails due to unsynchronized metadata or an invalid handle, the default values ​​are viewMinLod = -FLT_MAX and samplerMinLod = 0.0f (Vulkan Sampler default values), and a warning log is recorded to ensure downgrade compatibility.

[0219] S6.3 Structured Storage of Parsing Results: The VKSL layer creates a parsing result structure for each completed command, containing:

[0220] Basic command information: command type, command buffer handle, binding context ID;

[0221] List of binding pairs: handle, viewMinLod, samplerMinLod, isMSAATexture, and metadata version number for each imageView-sampler binding pair;

[0222] Verification status: Metadata verification result (passed, forced synchronization, downgraded compatibility);

[0223] The parsing results are stored in the kernel-mode cache for subsequent use by valid minLod calculation modules.

[0224] S7, efficient minLod calculation, multi-dimensional cache optimization, and adaptation to special scenarios.

[0225] S7.1, core computing logic precisely replicated:

[0226] Basic calculations: For each imageView-sampler binding pair of a non-MSAA texture, the VKSL layer executes validMinLod = max(viewMinLod, samplerMinLod), fully conforming to the extended semantics of VK_EXT_image_view_min_lod;

[0227] Boundary condition handling:

[0228] If viewMinLod = -FLT_MAX (no view-level limit), then validMinLod = samplerMinLod;

[0229] If samplerMinLod is not explicitly set (default value - FLT_MAX), then validMinLod = viewMinLod;

[0230] If validMinLod exceeds samplerMaxLod of the Sampler, then it is clamped to samplerMaxLod (following the native Vulkan sampler LOD range limit).

[0231] Special texture calculation: For texture array types, calculate an independent validMinLod for each array cell to ensure that the LOD limit is consistent for all texture cells in the array.

[0232] S7.2 Multi-dimensional caching system design improves cache hit rate:

[0233] Level 1 cache (bound to cache): validMinLodCacheTable, the cache key is a 64-bit combined hash value of the imageView handle and sampler handle, and the cache value is validMinLod and the cache item status (valid or invalid); the default size is 1024 entries, and it supports dynamic expansion (expansion by 50% when the hit rate is < 80%).

[0234] Second-level cache (binding context cache): contextValidMinLodCache, the cache key is the binding context ID and shader stage, and the cache value is the collection of validMinLod values ​​for all binding pairs under this context; suitable for scenarios where the same context is bound multiple times, avoiding duplicate calculations;

[0235] Level 3 caching (application-level hot spot caching): appHotValidMinLodCache, based on the access frequency of the binding pairs during application runtime, caches high-frequency combinations (accessed ≥ 5 times), and clears it when the application exits. It is suitable for long-running applications (such as games).

[0236] S7.3 Cache Management Mechanism:

[0237] Cache write strategy: After calculating the validMinLod, write the cache data in the order of first-level cache to second-level cache and then to third-level cache to ensure data consistency at each level of cache.

[0238] Cache invalidation mechanism:

[0239] Metadata update invalidation: When VKD3D sends an SRV metadata update notification or a Sampler metadata update notification, the VKSL layer marks the corresponding first-level cache item as invalid based on the handle, and cascades the invalidation of the associated entries in the second-level and third-level caches;

[0240] Timeout invalidation: The timeout period for first-level cache items is set to 5 seconds, for second-level cache items to 30 seconds, and for third-level cache items to 5 minutes. If the items are not accessed within the timeout period, they will automatically expire to prevent cache bloat.

[0241] Batch invalidation optimization: For metadata updated in batches, prefix hash matching is used to mark batch invalidation, reducing traversal overhead.

[0242] S7.4, Preheating and Batch Calculation Optimization:

[0243] Cache preheating:

[0244] Application startup phase: The VKSL layer reads the application resource configuration summary synchronized by VKD3D (including commonly used SRV-Sampler binding combinations), calculates validMinLod in advance, and writes it to the three-level cache;

[0245] Before the command buffer is committed: all binding pairs in the command buffer are preloaded into the first-level cache to achieve caching upon commit;

[0246] Batch computation: For descriptor sets containing multiple binding pairs (such as texture arrays), SIMD instructions are used to perform max computation in batches to improve computation efficiency; for consecutive parsing commands, they are merged into computation batches to complete the effective minLod computation of all binding pairs in batches, reducing function call overhead.

[0247] S7.5, Special Scene Adaptation:

[0248] Dynamic LOD adjustment scenario: If the application dynamically adjusts the LOD through the shader (such as explicitly specifying the LOD in tex2Dlod), the VKSL layer ensures that validMinLod still clamps the explicit LOD by parsing the shader instructions (indirectly through the command buffer state), which is consistent with D3D12 semantics.

[0249] Multi-shader stage binding scenario: When the same imageView-sampler binding pair is bound to multiple shader stages, the same validMinLod calculation result is reused to avoid duplicate calculation.

[0250] S8, dynamic minLod state injection, command refactoring and compatibility adaptation.

[0251] S8.1 Compatibility Selection of Dynamic State Injection Carriers:

[0252] Prefer the VK_EXT_dynamic_state2 extension: This extension supports dynamic modification of VK_DYNAMIC_STATE_SAMPLER_MIN_LOD (custom dynamic state type, registered through the extension), with fine injection granularity and good compatibility;

[0253] Downgrade option: VK_KHR_dynamic_state extension. If the GPU does not support VK_EXT_dynamic_state2, then use VK_DYNAMIC_STATE_SAMPLER dynamic state. MinLod injection is achieved by rebinding the sampler state (the sampler state structure needs to be encapsulated).

[0254] Carrier detection and fallback: During VKSL layer initialization, the detection driver supports dynamic state extension, automatically selecting the optimal carrier without requiring user configuration.

[0255] S8.2, Enhanced Dynamic Injection Command Construction:

[0256] Injection command structure design:

[0257] Core parameters: target Sampler handle, validMinLod value, bound shader stage mask, injection effective scope (current command buffer, current draw call);

[0258] Validation fields: validMinLod validity flag (whether it is within a reasonable range), metadata version number (to ensure that the injected result is the latest calculation result);

[0259] Extended fields: Reserved fields are reserved for future feature expansions to maintain command structure compatibility;

[0260] Injection command encoding: Strictly follow the Vulkan command buffer encoding specification, using the same binary format as the native command to ensure that the driver can parse it correctly; for VK_EXT_dynamic_state2, it is injected through the vkCmdSetDynamicState command, and the parameters are encapsulated in the VkDynamicStateInfoEXT structure;

[0261] MSAA texture special handling: For binding pairs where isMSAATexture is true, skip the injection command construction and directly pass through the original command to avoid invalid operations.

[0262] S8.3 Command Refactoring and Dependency Handling:

[0263] Command sequence optimization: Reconstruct the command flow in the order of the original binding command, memory barrier, injection command, and subsequent drawing or computation commands.

[0264] Memory barrier: Add a memory barrier from VK_PIPELINE_STAGE_DESCRIPTOR_BINDING_BIT to VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT to ensure that dynamic state injection is performed only after the descriptor set is bound, thus avoiding delays in state effectiveness;

[0265] Injection command: The injection command for each binding pair is immediately followed by the corresponding descriptor set binding command to ensure a one-to-one correspondence between states;

[0266] Multi-command buffer dependency handling: For multiple command buffers in the same queue, the state inheritance mechanism allows the later command buffer to reuse the dynamic minLod state of the previous one (if the binding pair has not changed), reducing the number of injected commands; if the binding pair changes, the original state is overwritten to avoid state pollution.

[0267] Batch command reconstruction: For consecutive vkCmdBindDescriptorSets commands, merge their corresponding injection commands into a single injection command batch, reducing the command stream length and lowering driver parsing overhead.

[0268] S8.4 Security and compatibility assurance of injection commands:

[0269] Validity check: Before injection, check the validMinLod value (ranging from -FLT_MAX to FLT_MAX). If it is NaN or INF, replace it with the default value of 0.0f to avoid driver errors.

[0270] Driver compatibility testing: After the injected command is built, pre-validation is performed through the command validation interface provided by the driver (such as vkValidateCommandBuffer). If the validation fails, it will automatically switch to the degraded mode.

[0271] Log recording: Records detailed information of all injection commands (binding pairs, validMinLod, injection vector) for debugging and performance analysis.

[0272] S9, command buffer commit, state synchronization and degradation mechanism.

[0273] S9.1 Status verification before command buffer submission:

[0274] VKD3D side validation: Before submitting vkQueueSubmit, iterate through all bound commands in the command buffer and check the cacheValidFlag of the corresponding D3D12SRVMetadataEx. If it is invalid, wait for the VKSL layer to complete the valid minLod calculation and caching before submitting to avoid inconsistencies in state.

[0275] VKSL layer verification: After receiving the command buffer submission request, it verifies the status of all injected commands (whether they have been built and whether they have passed the driver pre-verification). If the verification fails, it triggers the degradation process.

[0276] S9.2, Synchronization and Coordination of Multiple Command Buffers:

[0277] Queue-level synchronization: Synchronization between command buffers is achieved through VkSemaphore, ensuring that the dynamic minLod state of the previous command buffer has taken effect before executing the binding and injection commands of the next command buffer;

[0278] State isolation: Maintain an independent dynamic state snapshot for each command buffer to record the injected minLod state; after the command buffer is executed, automatically restore the original Sampler state to avoid affecting subsequent command buffers.

[0279] S9.3, Metadata Reverse Synchronization:

[0280] The VKSL layer will synchronize the calculated validMinLod to the validMinLodCache field of VKD3D's D3D12SRVMetadataEx via shared memory;

[0281] VKD3D updates cacheValidFlag to be valid, allowing subsequent binding operations to reuse the cache and reduce redundant calculations.

[0282] S9.4 Enhanced Degradation Mechanism:

[0283] Degradation trigger conditions: Degradation is automatically triggered when the driver does not support any dynamic state extension, injection command pre-verification fails, or metadata synchronization continues to fail.

[0284] Degradation scheme (optimized sampler pooling):

[0285] Create a temporary Sampler pool: VKD3D quickly creates temporary Samplers containing validMinLod, using parameter hash and minLod as cache keys to reuse temporary Samplers with the same parameter combination, avoiding resource explosion;

[0286] Dynamic replacement binding: Before the command buffer is committed, VKD3D replaces the original Sampler with a temporary Sampler and binds it to the descriptor set; after execution, the temporary Sampler is recycled to the pool, and redundant Samplers are destroyed only when the pool is full.

[0287] Performance optimization: The temporary Sampler pool size is set to 256 entries, and LRU eviction is used to ensure that the performance loss in the degradation mode is controlled within 15%;

[0288] Degradation notification: Send degradation notifications to users via logs, recording the reasons for degradation and performance impact, which facilitates debugging and optimization.

[0289] S10, end-to-end performance optimization mechanism.

[0290] Meta data transmission optimization:

[0291] Zero-copy and incremental synchronization: Metadata data transmission between user space and kernel space is based on the mmap zero-copy mechanism. When metadata is updated, only the changed fields are transmitted (e.g., when viewMinLod changes, only srvHandle, newViewMinLod, and metadataVersion are transmitted), reducing bandwidth consumption.

[0292] Batch synchronization: VKD3D merges multiple metadata updates within a short period of time into a single synchronization batch and synchronizes them to the kernel layer in batches, reducing the number of synchronizations and lowering CPU overhead;

[0293] Command processing optimization:

[0294] Command interception and batch processing: The VKSL layer merges consecutive vkCmdBindDescriptorSets and vkUpdateDescriptorSets commands into command batches for batch parsing, batch calculation, and batch injection, reducing the number of interceptions and processing.

[0295] Kernel-mode parallel processing: Command parsing, effective minLod calculation, and injection command construction in the VKSL layer are processed in parallel using multi-threaded parallel processing (based on the kernel work queue), which is executed in parallel with the previous frame rendering of the GPU, avoiding the CPU waiting for the GPU;

[0296] Cache optimization:

[0297] Hotspot cache priority retention: Statistically analyze the access frequency of bound pairs, mark high-frequency combinations (access rate ≥1%) as hotspots, and prioritize their retention in caches at all levels, improving cache hit rate to over 95%;

[0298] Cache prefetching: Based on the sequence of bound commands in the command buffer, predict the binding pairs that may be used later and prefetch them into the cache in advance to reduce cache misses;

[0299] Multithreaded concurrency optimization:

[0300] Segmented Locking and Atomic Operations: VKD3D's metadata mapping table adopts a segmented locking design, with each segment locked independently, supporting simultaneous operations on different segments by multiple threads; core fields (such as referenceCount and metadataVersion) use atomic operations to avoid lock contention.

[0301] Kernel-level lock-free cache: The VKSL layer's first-level cache uses a lock-free hash table (based on RCU mechanism), which supports concurrent read and write operations and reduces lock overhead;

[0302] Hardware compatibility optimization:

[0303] Hardware characteristic awareness: The VKSL layer detects hardware characteristics of the GPU, such as the number of texture sampling units and cache size, and dynamically adjusts the cache size and batch processing threshold (e.g., increasing the cache for high-performance GPUs and reducing the batch size for low-power GPUs).

[0304] Instruction optimization: The injected commands are encoded using a GPU-friendly instruction format to reduce driver parsing and execution overhead; for GPUs that support SIMD, the instruction sequence for validMinLod computation is optimized to improve computational efficiency.

[0305] The following is an explanation of the terms used in this embodiment:

[0306] D3D12SRVMetadataEx: An enhanced D3D12 SRV metadata structure that integrates SRV identifiers (srvHandle), LOD core parameters (viewMinLod or minLodSource), texture attributes (textureType or isMSAATexture), binding states (bindState or boundShaderStages), and cache synchronization fields (validMinLodCache or metadataVersion). It covers the entire lifecycle of SRV and is the core carrier for transmitting minLod information across layers.

[0307] VkImageViewWrapperEx: An enhanced Vulkan ImageView wrapper structure that extends fields such as associatedSrvHandle (associated SRV handle), metadataPtr (pointer to D3D12SRVMetadataEx), isMSAATexture (MSAA marker), and srvReferenceCount (SRV reference count) to achieve strong binding between ImageView and SRV metadata, supporting lifecycle linkage and special texture adaptation.

[0308] VkSamplerMetadataEx: An enhanced Vulkan Sampler metadata structure that includes a Sampler identifier (samplerHandle), LOD parameters (samplerMinLod or samplerMaxLod), reusable fields (samplerParamsHash or referenceCount), and binding tracking (boundSrvHandles). It supports reuse based on parameter hashes and cache linkage during dynamic updates, solving the problems of sampler creation redundancy and uncontrolled binding states.

[0309] VKSL (Vulkan State Adaptation Layer): A new modular adaptation layer added to the Linux kernel, located between VKD3D (user space) and the GPU driver. Its core functions are to intercept Vulkan commands, parse cross-layer metadata, calculate valid minLod, and inject dynamic state. By simulating the semantics of VK_EXT_image_view_min_lod, it enables D3D12SRVminLod to take effect on GPUs that do not support this extension.

[0310] Descriptor set update log: VKD3D records the structured log of partial updates to Vulkan descriptor sets (vkUpdateDescriptorSets), including the changed descriptor set handle, the changed entry index, and the change type (SRV, Sampler, or double change). This allows the VKSL layer to accurately locate the changed imageView-sampler binding pair, avoiding the efficiency loss caused by parsing the entire descriptor set.

[0311] Multi-dimensional caching system: The VKSL layer features a three-level caching architecture designed for effective minLod: Level 1 cache (binding pair cache) uses imageView and sampler handle as keys to adapt to single binding; Level 2 cache (binding context cache) uses binding context ID and shader stage as keys to adapt to multiple bindings in the same context; Level 3 cache (application hotspot cache) uses high-frequency binding pairs as keys to adapt to long-running applications (such as games). By layering caching to cover different scenarios, the hit rate is improved.

[0312] Optimized sampler pooling: When dynamic state injection is unavailable, VKD3D creates a temporary Sampler pool, reuses the temporary Sampler with the Sampler parameter hash and validMinLod as the key, and uses an LRU eviction policy to control the pool size (default 256 entries), avoiding the resource explosion problem of traditional sampler pooling, and keeping the performance loss within 15%.

[0313] Metadata version synchronization mechanism: The metadata synchronization strategy between the VKSL layer and VKD3D uses metadataVersion (SRV or Sampler metadata version) and cacheVersion (effective minLod cache version) counters to mark the metadata update status; the kernel layer only rereads user-space metadata when the versions do not match, reducing invalid cross-layer data transmission.

[0314] State isolation snapshot: The VKSL layer maintains a dynamic minLod state record for each Vulkan command buffer, including the injected Sampler handle, validMinLod, and the effective stage; after the command buffer is executed, the original minLod state of the Sampler is automatically restored to avoid state pollution across command buffers.

[0315] Experiments have verified that this invention has the following performance advantages:

[0316] It replicates the core semantics of VK_EXT_image_view_min_lod and adapts to all scenarios. It dynamically calculates and injects data through max(viewMinLod,samplerMinLod), covering all types of SRVs such as basic textures, texture arrays, and MSAA textures. It supports full binding, partial updates, and dynamic attribute modifications across all scenarios, ensuring that the rendering effect of D3D12 applications is completely consistent with the native Windows environment and GPU environments that support this extension.

[0317] It solves the resource explosion problem, eliminates the need to create redundant Samplers, reuses the original Samplers through dynamic state injection, and combines an optimized degradation scheme, resulting in memory usage comparable to native Vulkan applications, thus avoiding resource waste caused by sampler pooling.

[0318] Performance has been optimized through end-to-end optimizations such as zero-copy metadata data transmission, multi-dimensional caching system, batch processing, and parallel execution. CPU overhead is controlled within 5% of native operation, GPU overhead is negligible, and rendering frame rate is basically unaffected.

[0319] It ensures stability throughout the entire lifecycle, covering the creation, update, binding, and destruction of SRV, ImageView, and Sampler. Through fine-grained locking, atomic operations, cache invalidation mechanisms, and resource leak protection, it ensures that there are no rendering errors, deadlocks, or crashes in multi-threaded concurrent scenarios.

[0320] Improved compatibility by modifying only the VKD3D source code and the Linux kernel Vulkan subsystem, without relying on GPU driver modifications. It is applicable to all GPU hardware that does not support VK_EXT_image_view_min_lod, and also supports VK_EXT_dynamic_state2 and VK_KHR_dynamic_state extensions, adapting to both new and old Vulkan versions.

[0321] It improves scalability, and the modular architecture design can be reused in other D3D12 and Vulkan semantic mapping scenarios. Only the metadata type and calculation logic need to be modified to quickly adapt to new API semantic differences.

[0322] 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 method for implementing Direct3D 12 views based on dynamic injection of LOD state, characterized in that, Specifically, the following steps are included: After system startup, an independent shared memory area is created, including a metadata area that stores the first mapping between Vulkan image view and SRV metadata, and a first cache area that stores the second mapping between Vulkan image view handles and sampler handles and valid minLod values. The shared memory area is then mapped to the user space of VKD3D. After VKD3D starts, a third mapping is established between SRV handles and SRV metadata pointers, and a fourth mapping is established between descriptor heap handles and heap indexes and SRV handles. A sampler multiplexing pool is also established, with the sampler parameter hash value as the key and the sampler metadata value as the value. When a D3D application creates a D3D12 sampler, VKD3D converts the creation parameters into Vulkan sampler creation parameters, calculates the sampler parameter hash value, and if it exists in the sampler reuse pool and the relevant sampler metadata is already created, then the sampler handle is reused; otherwise, a Vulkan sampler is created, the sampler metadata is initialized, the status is set to already created, it is added to the sampler reuse pool, and a fifth mapping is established between the sampler handle and the sampler metadata. When modifying sampler parameters, modify the sampler metadata of the fifth mapping, set the SRV cache validity flag bound to it to invalid, calculate the sampler parameter hash value, update the entry if it has changed, otherwise leave it unchanged; when binding SRV and sampler, establish the mapping relationship between SRV and sampler according to different binding modes, and then create a binding context. When creating a Vulkan descriptor set layout, VKD3D adds the hash value of SRV metadata, the hash value of Vulkan sampler metadata, and the identifier of the binding context. When submitting the D3D12 descriptor set, the SRV and sampler metadata status are updated synchronously. The metadata is verified according to the first mapping. If they are inconsistent, synchronization is forced and a valid minLod value is calculated. Otherwise, a valid minLod value is obtained from the first buffer. A valid minLod value is constructed and injected into the command to reconstruct the binding command between the SRV and the sampler. The command buffer is submitted to the GPU queue, and the GPU executes the command stream to complete the rendering.

2. The Direct3D 12 view implementation method according to claim 1, characterized in that, The sampler parameter hash value is the hash value of the immutable parameters set when the Vulkan sampler is created.

3. The Direct3D 12 view implementation method according to claim 1, characterized in that, The method for verifying metadata based on the first mapping, and then forcibly synchronizing and calculating a valid minLod value if inconsistent, is as follows: Step 5.1: For Vulkan image view handles, search for the corresponding SRV metadata in the first mapping, calculate its hash value. If it is the same as the hash value of existing SRV metadata, reuse the current valid minLod value; otherwise, for SRV metadata of type texture array, execute step 5.2 after extracting the array size, and for other types, execute step 5.

2. For corresponding sampler handles, search for the corresponding Vulkan sampler metadata in the fifth mapping, calculate its hash value. If it is the same as the hash value of existing Vulkan sampler metadata, reuse the current valid minLod value; otherwise, execute step 5.

2. Step 5.2: If the SRV metadata type is MSAA texture, mark its valid minLod value as having no view-level limitation and end the calculation process; Otherwise, for the Vulkan image view and sampler binding pair, the larger value between the view minLod and the sampler minLod is taken as the effective minLod value. When the view minLod has no view-level restrictions, the effective minLod value is set to the sampler minLod. When the sampler minLod is not set, the effective minLod value is set to the view minLod. When the effective minLod value is greater than the sampler maxLod, it is set to the sampler maxLod.

4. The Direct3D 12 view implementation method according to claim 1, characterized in that, The method of verifying metadata based on the first mapping and forcing synchronization and calculating a valid minLod value if there is inconsistency is as follows: for texture array types, an independent valid minLod value is calculated for each array unit.

5. The Direct3D 12 view implementation method according to claim 1, characterized in that, The method for constructing the effective minLod value injection command to reconstruct the binding command between SRV and sampler is as follows: Construct a valid minLod value injection command. The command data includes the target sampler handle, valid minLod value, bound shader stage mask and injection effective range. The valid minLod value validity flag and metadata version number are the verification field and extension field. The command data is encapsulated into a Vulkan command as the injection command using the same binary format as the native command according to the Vulkan command buffer encoding method. The command flow is reconstructed in the order of the original binding command, memory barrier, injection command, and subsequent commands.

6. The Direct3D 12 view implementation method according to claim 1, characterized in that, VKD3D traverses the command buffer, checks the cache validity flag of SRV metadata, and waits for the cache to be written before committing if it is invalid. It also verifies the build status and pre-verification results of the injected command, and allows submission after confirming that there are no errors.

7. The Direct3D 12 view implementation method according to claim 1, characterized in that, VKD3D submits the processed command buffer to the GPU queue. When the driver does not support dynamic state extension, the injected command pre-verification fails, or the metadata synchronization continues to fail, a degradation is triggered. The sampler is first replaced with a temporary sampler in the temporary sampler pool, bound to the descriptor set, and then submitted. After execution, the temporary sampler is recycled back to the temporary sampler pool. The temporary sampler pool is a temporary sampler created by VKD3D that contains valid minLod values.

8. The Direct3D 12 view implementation method according to claim 1, characterized in that, A dynamic state snapshot is maintained for each command buffer to record the injected minLod state, ensuring state isolation between command buffers. After the GPU finishes executing the command buffer, the sampler's original minLod state is restored. In multi-command buffer scenarios, queue-level synchronization is achieved through the VkSemaphore command.

9. The Direct3D 12 view implementation method according to claim 1, characterized in that, When submitting the D3D12 descriptor set, the SRV and sampler metadata status are updated synchronously, and a metadata update notification containing the SRV handle and SRV metadata version is generated. The metadata update notification triggers the corresponding cache item invalidation operation.

10. The Direct3D 12 view implementation method according to claim 1, characterized in that, When a D3D application destroys an SRV, VKD3D looks up the corresponding SRV metadata based on the SRV handle, sets the binding status in its binding attribute to unbound, sets the SRV metadata version to 0, deletes the corresponding entry in the first mapping, and generates a metadata destruction notification. The metadata destruction notification triggers the cleanup of the corresponding cache items and parsing results.