Direct3D memory model compatible method based on adaptive occupied resources
By using an adaptive resource allocation method, the compatibility issues of Direct3D applications in GPU environments that do not support the VK_EXT_robustness2 extension were resolved, enabling efficient and stable operation of Direct3D applications on the Vulkan platform and improving compatibility and execution efficiency.
Patent Information
- Application Number
- CN202610065077.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-19
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2046-01-19
AI Technical Summary
In GPU environments that do not support the VK_EXT_robustness2 extension, Direct3D applications suffer from compatibility issues including low boundary checking efficiency, high memory overhead, poor pipeline compatibility, difficulty in driver adaptation, and unstable cache management, leading to decreased GPU execution efficiency and frequent compatibility problems.
An adaptive resource placement method is adopted to establish resource metadata, access scene library and inspection instruction template, create dual sandboxes, map through resource binding slots and rendering pipeline stages, optimize SPIR-V instructions, insert inspection instructions, dynamically adjust resource allocation and format adaptation, monitor Vulkan execution status in real time, and build a GPU driver feature fingerprint library to achieve adaptive adjustment.
It improves the compatibility and execution efficiency of Direct3D applications on the Vulkan platform, reduces memory overhead, ensures the stability and compatibility of the rendering process, and reduces the performance loss of GPU execution.
Smart Images

Figure CN121542055A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer software development technology, specifically relating to a Direct3D memory model compatibility method based on adaptive placeholder resources. Background Technology
[0002] As a crucial transformation layer from Direct3D (D3D) to Vulkan, DXVK's core functionality relies on two core capabilities of the VK_EXT_robustness2 extension: first, accurate reproduction of D3D memory access semantics, including returning zero for out-of-bounds reads and silently discarding out-of-bounds writes; and second, native support for D3D's null descriptor feature. The VK_EXT_robustness2 extension specifically enhances memory access safety and adapts to D3D semantics.
[0003] However, in GPU environments that do not support this extension, compatibility issues for D3D applications remain numerous and difficult to resolve. These primarily include: boundary check problems; the existing method of globally inserting boundary check instructions leads to a 30% to 50% surge in shader instruction count, significantly reducing GPU execution efficiency, especially in complex games where frame rates drop by 5% to 20%. Furthermore, the failure to differentiate between D3D resource types, access scenarios, and version differences results in a large number of redundant checks. Descriptor simulation issues: Existing methods require creating separate placeholder resources for each D3D resource format, type, and sampling mode, leading to a more than 30% increase in GPU memory overhead. Furthermore, format compatibility is poor, as special D3D compression formats and multi-sampled textures cannot be adapted. Frequent creation and destruction of placeholder resources also increases CPU-side descriptor set update overhead. Pipeline compatibility issues: Existing methods do not consider shader interface matching during the pipeline state object (PSO) creation phase. Inserting boundary check instructions may cause PSO creation failures, such as shader resource binding slot mismatches. Driver adaptation issues: Different GPU manufacturers and driver versions handle Vulkan undefined behaviors very differently. Existing solutions lack a fine-grained driver feature adaptation mechanism, leading to frequent compatibility problems. Cache management issues: Shader caches are not fully associated with driver features and check template versions, resulting in cache pollution after driver updates or check logic adjustments, causing rendering anomalies.
[0004] In summary, there is an urgent need to construct a complete DXVK-based conversion process that is semantically consistent, has low performance overhead, high compatibility, and strong stability, in order to solve the compatibility issues of DXVK without the VK_EXT_robustness2 extension. Summary of the Invention
[0005] In view of this, the present invention provides a Direct3D memory model compatibility method based on adaptive placeholder resources, which enables D3D applications to run compatiblely on operating system platforms that support Vulkan without supporting the VK_EXT_robustness2 extension.
[0006] This invention provides a Direct3D memory model compatibility method based on adaptive placeholder resources, which specifically includes the following steps:
[0007] When DXVK starts, it establishes a scene library containing metadata and access scenarios that include basic attributes, access characteristics, associated resources and lifecycles. It associates access scenarios with D3D semantic requirements, creates check instruction templates for access scenarios based on D3D semantic requirements, and creates basic placeholder resources. It creates two types of sandboxes, allocates independent virtual address spaces and page tables, and stores real resources and placeholder resources respectively. It establishes resource binding slots and auxiliary mappings from rendering pipeline stages to metadata.
[0008] When a D3D application starts and D3D resources are created, DXVK parses the resource descriptor, initializes its basic metadata attributes, maps the D3D resource to a Vulkan resource, binds the metadata to the memory handle and shader slot of the Vulkan resource, and allocates sandboxes to update page table mappings. When resources are updated, DXVK corrects the metadata and updates access characteristics for dynamic index access. When resources are bound, DXVK sets the binding slots of basic attributes and updates the auxiliary mapping. When the resource handle is empty, it sets the placeholder resource ID of the associated resource to the default value. When a resource is destroyed and its reference count is zero, it is destroyed after setting its lifecycle.
[0009] DXVK compiles D3D application shaders, identifying resource access instructions as target instructions between generating and optimizing SPIR-V instructions; it reads metadata and access scenarios during the slot binding and pipeline stages, instantiates the determined check instruction template, and adds it before the target instructions; when the placeholder resource ID is a default value, it adapts the corresponding basic placeholder resource to a D3D resource placeholder resource and sets the corresponding sandbox to read-only; it binds placeholder resources and general samplers to the Vulkan descriptor set and creates pipeline state objects;
[0010] DXVK intercepts rendering commands from D3D applications, passes the command parameters to the Vulkan core command build command buffer, submits them to the Vulkan queue, and triggers the GPU to execute the rendering process to complete the rendering.
[0011] Furthermore, DXVK implements zero-initialization on-demand allocation when D3D resources are created. Specifically, for sandboxes of placeholder resources, a page fault is triggered on the first access, the kernel allocates a physical page and fills it with zero values before marking it as initialized; for sandboxes of real resources, they are initialized to zero values on the first mapping.
[0012] Furthermore, a dual hash mapping is used to store metadata. While establishing the auxiliary mapping, a main mapping from Vulkan memory handles to metadata pointers is established. A shared lock that can be acquired by multiple threads simultaneously is constructed to enable read operations on metadata. An exclusive lock that can be acquired by only a single thread at a time is constructed to enable write operations on metadata. The auxiliary mapping is updated during the resource binding phase and the mapping entries are deleted during the resource destruction phase.
[0013] Furthermore, the inspection instruction template includes condition judgment instructions, semantic adaptation instructions, and exception handling instructions. The condition judgment instructions include Null Descriptor scene inspection instructions, and the processing procedure is to determine whether to execute or block the target instruction based on the execution result of the condition judgment instructions.
[0014] Further, after instantiating the determined inspection instruction template, the instruction obtained from the instantiated inspection instruction template is recorded as the first inspection instruction. The first inspection instructions related to the target instructions that continuously access the same resource are extracted to the nearest common predecessor basic block. For the first inspection instructions related to the target instructions that access multiple resources in the same scenario, the semantic adaptation instructions in the instructions are merged. For the target instructions whose execution result of the first inspection instruction is valid, the condition judgment instructions in the first inspection instruction are deleted. For the target instructions whose resources are static resources and are not accessed by dynamic indexes, the first inspection instruction is deleted when the execution result of its corresponding first inspection instruction is valid.
[0015] Furthermore, the method for adapting the corresponding basic placeholder resource to a D3D resource placeholder resource is as follows:
[0016] Format adaptation takes the D3D format, resource type, and D3D version of the D3D resource as input. If the D3D format is compatible with the format of the basic placeholder resource, the view of the basic placeholder resource is used. If it is not compatible through view adaptation, a D3D format view is created based on the basic placeholder resource. If conversion is required, a D3D format view is created using hardware format conversion if the GPU driver supports format conversion. If it is not supported, a temporary conversion buffer is created. The zero-value data of the basic placeholder resource is converted to D3D format and copied to the temporary conversion buffer, which is then reused later.
[0017] Multisampling adaptation takes the number of samples and D3D format of the D3D resource as input. If the target number of samples is not greater than the number of samples of the multisampling texture of the basic placeholder resource, a view with the corresponding number of samples is created. If the target number of samples is greater than the threshold, a temporary multisampling texture with the target number of samples is created and pooling is added after zero initialization of the multisampling texture.
[0018] Version semantic adaptation: For D3D9 fixed-function pipeline resources, D3D9-specific base textures are used; for D3D11 adaptation, for typed UAVs, a D3D format UAV view is created based on a generic buffer; for depth buffer adaptation, a generic depth buffer base placeholder resource is used for depth template resources to create a view of the target depth format.
[0019] Furthermore, for all placeholder resources in the D3D application, a view pool is created for placeholder resources with the same format, sampling mode, and purpose to achieve view reuse; a temporary resource pool is created for dynamically created placeholder resources with special formats or high sampling numbers, and the placeholder resources that are not used within a set number of frames are destroyed; requests for placeholder resources used in each frame to contain the same format, sampling mode, and purpose within the same frame are recorded, and the same placeholder resource is reused to form frame-level reused resources.
[0020] Furthermore, the GPU executes the rendering process to complete the rendering in the following way:
[0021] The vertex shader processes vertex data, while the pixel shader and compute shader execute resource access logic. Before each resource access instruction is executed, the instruction obtained from the injected instantiation check instruction template is executed first. The access validity is determined based on the metadata. If valid, the real resource or placeholder resource is read or written. If it is an out-of-bounds access, zero or black is returned as a substitute value according to D3D semantics, or the write operation is silently discarded. Depth testing and color blending are completed according to the configuration of the pipeline state object.
[0022] Furthermore, the execution status of Vulkan is monitored in real time, and exceptions such as device loss and invalid memory access are captured. The cause of the exception is located based on the out-of-bounds counter of the metadata and the kernel sandbox fault log. Recovery strategies are triggered according to the exception type, including increasing the intensity of resource checks, recompiling shaders, rebuilding descriptor sets and pipeline state objects. If there are consecutive exceptions, the system switches to safe mode.
[0023] Furthermore, the core characteristics of the GPU are collected when DXVK starts, and they are encoded into fingerprint information. The fingerprint information of mainstream drivers and the adaptation strategy are pre-compiled to form a fingerprint library.
[0024] The corresponding adaptation strategy is obtained by matching the fingerprint information of the current GPU. The inspection intensity is adjusted according to the adaptation strategy, including enhanced inspection for all dynamic index access injection, inspection only for high-risk resources, and inspection only for dynamic resources. The format adaptation mode is adjusted, prioritizing the adaptation of the format through the image view and using a temporary conversion buffer. The memory allocation is adapted by adjusting the allocation alignment of placeholder resources according to the memory alignment requirements of the driver. When the GPU local memory is insufficient, the placeholder resources are allocated to the system memory and initialized to zero value through memory mapping.
[0025] Beneficial effects:
[0026] This invention establishes resource metadata, access scene library, inspection instruction template, and dual sandboxes when DXVK starts. After the D3D application starts, DXVK describes its various resources through resource metadata, completes resource mapping and dynamic metadata updates, and allocates resources to the corresponding sandboxes. DXVK compiles the application shader code, identifies resource access instructions, and combines pipeline stages and bound slots to query metadata to match access scenes and inspection templates. It instantiates inspection instructions and adds them before target instructions, while adding compatibility adaptation instructions to optimize SPIR-V instructions. For unbound resources, it adapts and generates corresponding placeholder resources and configures permissions and states, binds them to the Vulkan descriptor set to replace VK_NULL_HANDLE, and completes the adaptation of shader interface and pipeline state parameters to create PSO. It intercepts application rendering instructions, parses parameters to build a command buffer, submits it to the Vulkan queue to trigger GPU execution rendering, and finally completes the complete conversion and adaptation of D3D rendering logic to Vulkan. Attached Figure Description
[0027] Figure 1 This is a flowchart illustrating a Direct3D memory model compatibility method based on adaptive placeholder resources provided by the present invention. Detailed Implementation
[0028] The present invention will be described in detail below with reference to the accompanying drawings and embodiments.
[0029] This invention provides a Direct3D memory model compatibility method based on adaptive placeholder resources. The core idea is as follows: When DXVK starts, it establishes resource metadata, accesses the scene library, checks instruction templates, and establishes dual sandboxes. After the D3D application starts, DXVK describes its various resources through resource metadata, completes resource mapping and dynamic metadata updates, and allocates resources to the corresponding sandboxes. DXVK compiles the application shader code, identifies resource access instructions, and combines pipeline stages and bound slot queries to match access scenes and check templates with metadata. It instantiates check instructions and adds them before target instructions, while simultaneously adding compatibility adaptation instructions to optimize SPIR-V instructions. For unbound resources, it adapts and generates corresponding placeholder resources, configures permissions and states, binds them to the Vulkan descriptor set to replace VK_NULL_HANDLE, and completes the adaptation of shader interface and pipeline state parameters to create PSOs. It intercepts application rendering instructions, parses parameters to build a command buffer, submits it to the Vulkan queue to trigger GPU rendering, and finally completes the full conversion and adaptation of D3D rendering logic to Vulkan.
[0030] This invention provides a Direct3D memory model compatibility method based on adaptive placeholder resources, the process of which is as follows: Figure 1As shown, the specific steps include:
[0031] Step 1: When DXVK starts, establish resource metadata containing basic attributes, access characteristics, associated resources, lifecycle, and versioning extensions. Set the attribute values in the resource metadata to create a scene library containing multiple resource access scenarios across D3D versions. The scene library associates access scenarios with D3D semantic requirements through attributes. Then, based on D3D semantic requirements, create check instruction templates for each access scenario. Create basic placeholder resources based on high-frequency D3D resource types to replace VK_NULL_HANDLE, which Vulkan does not allow binding, providing a legal Vulkan resource carrier for unbound resources of D3D applications. Create two independent sandboxes: a real resource sandbox and a placeholder resource sandbox. The page table permissions of the real resource sandbox are read and write, used to store real resources of D3D applications. The page table permissions of the placeholder resource sandbox are read, used to store placeholder resources. Allocate independent virtual address spaces and page tables for the sandboxes. Store the sandbox ID in the resource metadata. Cross-sandbox access is prohibited when the GPU accesses resources. Establish auxiliary mappings from resource-bound shader slots and rendering pipeline stages to resource metadata.
[0032] The basic attributes are the inherent attributes and format mapping relationships of D3D resources, including effective size, D3D dimensions, D3D format, corresponding Vulkan format, purpose flag, access type flag, binding slot, related D3D version, multisampled resource flag, and number of multisampled samples; access characteristics are the dynamic behavior characteristics during resource access, including dynamic index access flag, historical maximum access offset, out-of-bounds trigger counter, and static resource flag; associated resources are the association relationships between D3D resources and Vulkan resources, including Vulkan buffer handle, Vulkan image handle, Vulkan memory handle, placeholder resource ID, and sandbox ID; lifecycle is the resource usage status, including intra-frame usage count, idle frame count, and pending destruction flag; versioning extensions are used to adapt to differences between different D3D versions, including extensions for different versions, such as fixed-function pipeline resource flags, return colors for unbound resources, typed UAV flags, and atomic operation support flags.
[0033] Furthermore, the present invention achieves zero initialization and on-demand allocation when resources are created. Specifically, the physical pages of the placeholder resource sandbox adopt an on-demand allocation strategy. When accessed for the first time, a page fault is triggered, the kernel allocates the physical page, fills it with zero values, and marks it as initialized. The dynamic resources of the real resource sandbox are initialized to zero values when mapped for the first time to ensure that out-of-bounds reads return zero values.
[0034] Furthermore, a double hash mapping is used to store resource metadata, enabling efficient querying and multi-threaded concurrent read and write operations on resource metadata. A primary mapping is established from Vulkan memory handles to resource metadata pointers. An auxiliary mapping is established with the specific slot of the shader to which the resource is bound and the rendering pipeline stage it belongs to as the key, and the resource metadata pointer as the value. A shared lock that can be acquired by multiple threads simultaneously is established to enable read operations on resource metadata. An exclusive lock that can be acquired by only one thread at a time is established to enable write operations on resource metadata. The auxiliary mapping is updated during the resource binding stage, and the mapping entries are deleted during the resource destruction stage.
[0035] Table 1 shows an example of the scenario library established by this invention based on the values of attributes in resource metadata.
[0036] Table 1 Example Table of Scene Library Scene ID Scene Description Core metadata features D3D semantic requirements 1 D3D11 Static Buffer and Static Index Read The relevant D3D version is 11, static resources are marked as static resources, and dynamic index access is marked as non-dynamic index access. Out-of-bounds read returns zero. 2 D3D11 Dynamic Buffer and Dynamic Index Read The relevant D3D version is 11, static resources are marked as non-static resources, and dynamic index access is marked as dynamic index access. Out-of-bounds read returns zero. 3 D3D11 Typed UAV and Dynamic Index Writing The relevant D3D version is 11, the typed UAV is marked as typed UAV, and the access type is marked as write. Write out of bounds and discard silently 4 D3D11 UAV atomic operations The relevant D3D version is 11, and atomic operations are marked as supported. Out-of-bounds atomic operations have no effect 5 D3D9 Fixed Function Pipeline Texture Sampling The relevant D3D version is 9, and the fixed-function pipeline resource is marked as a fixed-function pipeline resource. Unbound / Out of bounds return black 6 D3D9 dynamic textures and dynamic index reading The relevant D3D version is 9, and the dynamic index access is marked as dynamic index access. Reading out of bounds returns to black 7 D3D10 Multisampling Texture The relevant D3D version is 10, and the multisampled resource is marked as a multisampled resource. Out-of-bounds reads return zero (maintaining MSAA mode). 8 D3D11 Deep Buffer Read The relevant D3D version is 11, the purpose is marked as depth template, and the access type is marked as read. Out-of-bounds read returns 0.0 (depth test passed) 9 D3D11 deep buffer write The relevant D3D version is 11, the purpose is marked as depth template, and the access type is marked as write. Write out of bounds and discard silently 10 D3D10 static textures and static index sampling The relevant D3D version is 10, static resources are marked as static resources, and dynamic index access is marked as non-dynamic index access. Out-of-bounds read returns zero. 11 D3D11 Untyped UAV Writing The relevant D3D version is 11, the typed UAV is marked as untyped UAV, and the access type is marked as write. Write out of bounds and discard silently 12 Unbound resource access (nulldescriptor) The placeholder resource ID is not zero. Returns zero value / black based on D3D version
[0037] This invention establishes a check instruction template for each access scenario based on the D3D semantic requirements in the scene library. The template includes condition judgment instructions, semantic adaptation instructions, and exception handling instructions. The check ensures that the generated SPIR-V memory access instructions are completely consistent with the D3D semantics. For example, the versioned check instruction template for scenario 2 is as follows:
[0038] / / Obtain the valid size of metadata (inject constants at compile time via the metadata interface)
[0039] %effectiveSize = OpConstant %uint 4096 / / For example, effective size is 4KB
[0040] %zero = OpConstantNull %float
[0041] / / Dynamic index retrieval
[0042] %index = OpLoad %uint %indexVar
[0043] / / Boundary check (index < valid size → valid)
[0044] %valid = OpICompare %bool OpSLT %index %effectiveSize
[0045] / / If valid, load the data; otherwise, return zero.
[0046] %data = OpLoad %float %buffer %index
[0047] %result = OpSelect %float %valid %data %zero
[0048] For scenarios with multi-sampled textures, the version check instruction template uses OpImageQuerySize to obtain the actual sampling dimension; for scenarios with atomic operations, the version check instruction template uses branch jumps to block the execution of atomic instructions, ensuring that there is no effect when the boundary is exceeded.
[0049] This invention creates basic placeholder resources based on high-frequency resource types in D3D, as shown in Table 2.
[0050] Table 2 Examples of Basic Space-Occupying Resources Basic resource types Specifications Initialization method Adapted scenarios General Buffer The size is 64MB (covering the maximum D3D UAV buffer + the maximum constant buffer), and the alignment is 64 bytes. Zero initialization (vkMapMemory + memset (0)) null descriptor for all buffer types General single-sample texture 1x1 pixel, 2D, 1 layer, 1 mipmap, format VK_FORMAT_R8G8B8A8_UNORM vkCmdClearColorImage(RGBA(0,0,0,0)) nulldescriptor for single-sampled textures General Multisampling Texture 1x1 pixel, 2D, 1 layer, 1 mipmap, format VK_FORMAT_R8G8B8A8_UNORM, sample size 8x (covering mainstream MSAA). vkCmdClearColorImage(RGBA(0,0,0,0)) nulldescriptor for multisampled textures D3D9 Dedicated Texture 1x1 pixel, 2D, 1 layer, 1 mipmap, format VK_FORMAT_B8G8R8A8_UNORM vkCmdClearColorImage(RGBA (0,0,0,1), i.e., black) D3D9 Fixed Function Pipeline Texture nulldescriptor General-purpose depth buffer 1x1 pixel, 2D, 1 layer, 1 mipmap, format VK_FORMAT_D32_FLOAT vkCmdClearDepthStencilImage(depth=0.0, stencil=0) null descriptor of deep template resources Universal Sampler The address mode is VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, the filter mode is VK_FILTER_LINEAR, and the comparison mode is VK_COMPARE_OP_ALWAYS. vkCreateSampler (global reuse) nulldescriptor for all unbound samplers
[0051] Step 2: After the D3D application starts, DXVK uses resource metadata to describe the D3D resources of the application, including buffers, textures, depth templates, etc. When D3D resources are created, DXVK parses the D3D resource descriptor, initializes the basic attributes of the resource metadata, maps the D3D resources to Vulkan resources, binds the resource metadata to the memory handles and shader slots of the Vulkan resources, allocates sandbox IDs according to the resource type, allocates memory to the corresponding sandbox, and updates the page table mapping of the corresponding sandbox. When D3D resources are updated, DXVK dynamically corrects the effective size in the resource's basic attributes, sets static resource flags, and detects dynamic changes. When a resource is accessed, the dynamic index access flag in the resource access characteristics is updated. When a D3D resource is bound, DXVK parses the binding slot, sets the binding slot in the resource's basic attributes, records the pipeline stage of the binding, updates the auxiliary mapping from the binding slot and pipeline stage to the resource metadata, and sets the placeholder resource ID in the associated resource to the default ID when the resource handle is empty. When a D3D resource is destroyed and the reference count of the D3D resource saved by DXVK is zero, the pending destruction flag in the resource's lifecycle is set to pending destruction, and the resource is added to the delayed destruction queue. During the frame recycling phase, the resource is deleted to release memory, and its corresponding video memory sandbox resources are released simultaneously to avoid memory leaks.
[0052] Step 3: DXVK compiles the shader code for the D3D application. After generating the corresponding Vulkan-compatible SPIR-V instructions and before optimizing the SPIR-V instructions, it scans the SPIR-V instructions to identify all resource access instructions, including buffer access, texture access, and depth stencil access, and uses the obtained resource access instructions as target instructions.
[0053] Obtain the binding slots of the rendering pipeline stage where the shader is located and the resources related to the target instruction. Read the resource metadata of the resource according to the binding slots and pipeline stage. Then, obtain the access scene from the scene library according to the value of the attribute in the resource metadata, determine the inspection instruction template, instantiate the inspection instruction template as the first inspection instruction, and add the first inspection instruction before the target instruction as the pre-verification and semantic adaptation layer of the target instruction.
[0054] Add compatibility adaptation instructions between the first check instruction and the target instruction, replace instructions that are incompatible with the GPU driver with equivalent combinations of basic instructions, replace hardware conversion of image formats that are not supported by the GPU driver with software format conversion, and replace multi-sample texture implicit LOD sampling instructions that are not supported by the GPU driver with single-sample explicit LOD sampling instructions.
[0055] The first inspection instruction includes a condition judgment instruction, a semantic adaptation instruction, and an exception handling instruction. The condition judgment instruction includes a Null Descriptor scene inspection instruction. The processing procedure is to determine whether to execute or block the target instruction based on the execution result of the condition judgment instruction.
[0056] Furthermore, the present invention minimizes the performance loss of the first check instruction through redundancy merging and instruction simplification, specifically as follows:
[0057] When accessing the same resource consecutively, the first check instruction is extracted to the nearest common predecessor basic block; for accessing multiple resources in the same scenario, the semantic adaptation instructions in the first check instructions of different target instructions are merged; for target instructions whose execution result of the first check instruction is valid, the condition judgment instructions in the first check instruction are deleted; for target instructions whose resources are static resources and are not accessed by dynamic indexes, the first check instruction is deleted when the execution result of the first check instruction of the target instruction is valid.
[0058] Step 4: DXVK identifies the D3D resources of the D3D application. Based on the pipeline stage and bound slots, it obtains the resource metadata. When the placeholder resource ID in the resource metadata is the default ID, it indicates that the resource handle of the current D3D resource is empty. Then, based on the resource metadata of the D3D resource, it obtains the basic placeholder resource adapted to the scene and records it as the selected placeholder resource. The selected placeholder resource is dynamically adapted to the resource format, sampling mode, and version semantics of the D3D resource to form a placeholder resource. The physical page of the sandbox corresponding to the placeholder resource is set to write protection. The placeholder resource and the general sampler are bound to the Vulkan descriptor set to replace the original VK_NULL_HANDLE. For placeholder resources of unordered access view type, write operations on them are blocked. For placeholder resources of depth template type, the corresponding image layout state is configured according to their actual access purpose. It verifies whether the type of the placeholder resource is consistent with the type declared in the descriptor layout. If they are inconsistent, the declaration in the descriptor layout is modified.
[0059] Furthermore, in this invention, the method for dynamically adapting the selected placeholder resource to the resource format, sampling mode, and version semantics of the D3D resource is as follows:
[0060] Format adaptation takes the D3D format, resource type, and D3D version of the D3D resource as input. It checks the compatibility between the D3D resource format and the base resource format. If they are compatible, it uses the view of the base resource. If they can be adapted through view, it creates a view of the target format based on the base resource. If data conversion is required, it checks whether the driver supports format conversion. If it does, it uses the format conversion capability of the GPU hardware to create an image view of the target format. If it does not support it, it creates a temporary conversion buffer, converts the zero-value data of the base resource to the target format, copies it to the temporary conversion buffer, and reuses the temporary resource later.
[0061] Multisampling adaptation takes the number of samples and D3D format of the D3D resource as input. If the target number of samples is not greater than the number of samples of the multisampling texture of the basic placeholder resource, an image view with the corresponding number of samples is created. If the target number of samples is greater than the threshold, a temporary multisampling texture with the target number of samples is dynamically created. After zero initialization of the multisampling texture, it is added to pooling management and reused next time.
[0062] For version semantic adaptation, D3D9-specific base textures are used for D3D9 fixed-function pipeline resources to ensure that access to unbound resources returns black; when adapting to D3D11, UAV views of the target format are created based on a generic buffer for typed UAVs.
[0063] Depth buffer adaptation uses a generic depth buffer base resource to create a view of the target depth format, ensuring that out-of-bounds reads return zero values.
[0064] Furthermore, for all selected placeholder resources related to the D3D application, a view pool is created for placeholder resources with the same format, sampling mode, and purpose to achieve view reuse; a temporary resource pool is created for dynamically created placeholder resources with special formats or high sampling numbers, and the placeholder resources that are not used within a set number of frames are destroyed; requests for placeholder resources used in each frame to contain the same format, sampling mode, and purpose within the same frame are recorded, and the same placeholder resource is reused to form frame-level reused resources.
[0065] Furthermore, basic placeholder resources are destroyed when DXVK exits, and frame-level reused resources are destroyed when the reference count is 1 during frame reclamation; for placeholder resources in the temporary resource pool, their empty frame count is incremented after each frame is processed, and the placeholder resource and its corresponding video memory are released when the empty frame count exceeds the threshold.
[0066] Step 5: Ensure that the resource binding slots of the shader after inserting the first check instruction are consistent with the descriptor layout declaration, the format of the placeholder resources is consistent with the format required by the shader, and the number of multisample samples of the placeholder resources of multisample texture types is consistent with the number of samples of the rendering target, thus completing the shader interface adaptation; complete the adaptation of pipeline state parameters including depth stencil state, blend state, rasterization state, and atomic operations; create graphics pipeline state objects and computation pipeline state objects using the rendering pipeline stage as shader stage parameters, the descriptor set layout as pipeline layout parameters, and the adapted pipeline state parameters. If creation fails, trigger a retry mechanism.
[0067] Furthermore, the adaptation of pipeline state parameters, including depth template state, blending state, rasterization state, and atomic operations, can be completed, specifically as follows:
[0068] Depth template state adaptation: For scenes without a bound depth buffer, set depthStencilState.depthTestEnable=false and depthStencilState.depthWriteEnable=false to match the default D3D behavior.
[0069] For blend state adaptation, in scenarios where placeholder color resources are used without a bound rendering target, set blendState.attachment[0].blendEnable=false to avoid rendering errors caused by blending operations;
[0070] Rasterization state adaptation: For D3D9 fixed function pipeline resources, adjust rasterizationState.polygonMode to VK_POLYGON_MODE_FILL and cullMode to VK_CULL_MODE_BACK_BIT to reproduce the default rasterization behavior of D3D9;
[0071] Atomic operation adaptation: If the resource metadata flag supportAtomicOps=true (typed UAV), enable the corresponding memory semantics in the depthStencilState or blendState of the PSO to ensure atomic operation compatibility.
[0072] Step 6: After DXVK intercepts the rendering instructions of the D3D application, it parses the instruction parameters, passes the instruction parameters to the Vulkan core command, inserts memory barriers and render target clearing instructions, and completes the construction of the command buffer; it submits the constructed command buffer to the Vulkan queue, triggering the GPU to execute the rendering process to complete the rendering.
[0073] Specifically, the GPU's rendering process includes the following steps:
[0074] The vertex shader processes vertex data, while the pixel shader and compute shader execute resource access logic. Before each resource access instruction, an injected boundary check instruction is executed to determine the access validity based on the resource metadata. If the access is valid, the real resource or placeholder resource is read and written normally. If the access is out of bounds, zero or black is returned as a substitute value or the write operation is silently discarded according to D3D semantics.
[0075] Based on the rasterization, depth template, blending and other states configured for the pipeline state object, perform operations such as depth testing and color blending, where the states corresponding to placeholder resources have been adapted.
[0076] When the GPU accesses resources, the kernel controls address translation through an independent page table, allowing access only to resources within the corresponding sandbox and avoiding cross-sandbox pollution. The write protection mechanism of the placeholder resource sandbox blocks illegal writes, and triggers kernel zero-filling for uncaught out-of-bounds reads.
[0077] Furthermore, to ensure rendering stability, this invention monitors the execution status of Vulkan in real time, captures anomalies such as device loss and invalid memory access, locates the cause of the anomaly based on the out-of-bounds counter of resource metadata and kernel sandbox fault logs, and triggers recovery strategies based on the anomaly type, including increasing the intensity of resource checks, recompiling shaders, rebuilding descriptor sets and pipeline state objects, and switching to safe mode for continuous anomalies to ensure that the rendering process is not interrupted.
[0078] Furthermore, this invention constructs a GPU driver feature fingerprint library to achieve fingerprint-based adaptive adjustment throughout the entire process, covering mainstream GPU manufacturers and driver versions, specifically including:
[0079] Step 1.1: Collect the core characteristics of the GPU when DXVK starts to ensure that the fingerprint can accurately represent the driving capability. Specific information is shown in Table 3.
[0080] Table 3. Examples of Core GPU Features Feature Category Collection Fields Data collection interface / method Basic Identifiers Vendor ID, Device ID, Driver Version, Vulkan Version VkPhysicalDeviceProperties Format support Support for common D3D formats (sampling / writing / conversion), compression format support, and multi-sampling format support. vkGetPhysicalDeviceFormatProperties2 Command support SPIR-V core instruction support (OpIsValid / OpSelect / OpMux), extended instruction support vkGetPhysicalDeviceFeatures2, vkGetPhysicalDeviceShaderFeatures Memory characteristics Video memory type (device local memory / system memory), memory alignment requirements, maximum memory allocation size VkPhysicalDeviceMemoryProperties robust performance Out-of-bounds read behavior (returns zero / random value), out-of-bounds write behavior (silently discards / pollutes memory) Pre-compiled test shader execution (e.g., for intentional out-of-bounds reads, to check return values). Descriptor support Maximum number of descriptor bindings, descriptor update frequency limit VkPhysicalDeviceDescriptorPoolProperties PSO compatibility Error behavior when shader interfaces are incompatible, and the compatibility range of multisampling mode. Pre-create test PSOs (different formats / sample number combinations) caching features Shader cache supported types and cache size limits VkPhysicalDevicePipelineCacheProperties
[0081] Step 1.2: Encode the core features of the collected GPU into a 128-bit fingerprint, and pre-compile the fingerprints of mainstream drivers and adaptation strategies to form a built-in fingerprint library;
[0082] Step 1.3: Obtain the corresponding adaptation strategy through fingerprint matching, and adjust the inspection intensity according to the adaptation strategy, including enhanced inspection of all dynamic index access insertions, inspection of high-risk resource insertions only, and inspection of dynamic resource insertions only; adjust the format adaptation mode, prioritize image view format adaptation, and use temporary conversion buffers, etc.; adapt the video memory allocation, adjust the allocation alignment of placeholder resources according to the driver's memory alignment requirements, and allocate placeholder resources to system memory for GPUs with insufficient local memory and initialize zero values through memory mapping.
[0083] Example:
[0084] This embodiment uses a Linux system as an example and employs a Direct3D memory model compatibility method based on adaptive placeholder resources provided by this invention. It achieves compatible operation of D3D applications without the VK_EXT_robustness2 extension by following and modifying the core DXVK conversion process. The specific process includes:
[0085] The terms used in this embodiment include: resource metadata DxvkResourceMetadata; metadata management singleton class DxvkResourceMetadataManager, used for metadata registration, querying, updating and destroying, using double hash mapping storage to support thread-safe concurrent read and write, and providing interfaces such as getMetadataByMemoryHandle or updateEffectiveSize; boundary check injection Pass SpirvBoundaryCheckInjectionPass; placeholder resource management class DxvkDummyResourceFactory, used for the creation, adaptation, reuse and destruction of placeholder resources; video memory sandbox module vk_sandbox, used to create real resource sandboxes and placeholder resource sandboxes; driver adaptation policy structure DxvkDriverAdaptPolicy, containing check strength, format adaptation mode, and driver robustness dependency fields, stored in the driver fingerprint library, used to dynamically adjust the adaptation logic according to GPU driver characteristics; and full-process state consistency verification module dxvk_resource_consistency_check, which performs lightweight verification during the frame recycling phase.
[0086] In the S1 and D3D resource to Vulkan resource mapping stage, each D3D resource is bound with full-dimensional metadata covering basic attributes, access characteristics, version semantics, binding information, and associated resources. This is deeply integrated with the existing DXVK resource management process to ensure the real-time, accuracy, and accessibility of metadata.
[0087] S1.1 Definition of Full-Dimensional Metadata Structure. In the core resource header file dxvk_resource.h of DXVK, a new DxvkResourceMetadata structure is added. It uses fixed fields and versioned extended fields to ensure compatibility with all resource types from D3D9 to 11. The specific definition is as follows:
[0088] struct DxvkResourceMetadata {
[0089] / / 1. Basic Identifier Fields (Universal Across All Versions)
[0090] VkDeviceSize effectiveSize; / / Effective size of the resource (number of bytes in the buffer / total number of pixels in the texture)
[0091] D3D_RESOURCE_DIMENSION d3dDimension; / / D3D resource dimension (buffer / 1D / 2D / 3D / multisampling)
[0092] DXGI_FORMAT d3dFormat; / / D3D resource format (such as DXGI_FORMAT_R8G8B8A8_UNORM, D3DFMT_A8R8G8B8)
[0093] VkFormat vkFormat; / / Corresponding Vulkan format (e.g., VK_FORMAT_R8G8B8A8_UNORM)
[0094] DxvkResourceUsage usageFlags; / / Resource usage flags (SRV / UAV / rendering target / depth template / atomic operation)
[0095] uint32_t accessFlags; / / Access type flags (read / write / read-write)
[0096] uint32_t bindSlot; / / Resource binding slot (e.g., shader SRV slots 0-15)
[0097] D3D_VERSION d3dVersion; / / Associates the D3D version (9 / 10 / 11) to accommodate semantic differences.
[0098] bool isMultisampled; / / Whether it is a multisampled resource (MSAA texture / depth buffer)
[0099] uint32_t sampleCount; / / Number of samples for multiple sampling (e.g., 4xMSAA, 8xMSAA)
[0100] / / 2. Access feature fields (dynamically updated)
[0101] bool hasDynamicIndex; / / Checks if dynamic index access (such as array indexing based on vertex ID) exists.
[0102] VkDeviceSize maxAccessOffset; / / Maximum historical access offset (optimizes the check range)
[0103] uint32_t outOfBoundsCount; / / Out-of-bounds trigger counter (adjusts the check strength)
[0104] bool isStaticResource; / / Whether it is a static resource (e.g., D3D11_USAGE_IMMUTABLE)
[0105] / / 3. Associated resource fields (cross-module references)
[0106] VkBuffer vkBuffer; / / Handle to the corresponding Vulkan buffer (buffer resource valid)
[0107] VkImage; / / The corresponding Vulkan image handle (valid for texture resources)
[0108] VkDeviceMemory vkMemoryHandle; / / Corresponding Vulkan memory handle (metadata query index)
[0109] uint32_t dummyResourceId; / / The associated placeholder resource ID (used for null descriptor simulation)
[0110] uint64_t sandboxId; / / The associated kernel memory sandbox ID (used for memory isolation)
[0111] / / 4. Lifecycle Fields (Recycling Management)
[0112] uint32_t frameUsageCount; / / Number of times the frame is used
[0113] uint32_t idleFrameCount; / / Number of idle frames (reclaiming threshold: 10 frames)
[0114] bool isPendingDestruction; / / Whether it is pending destruction (delayed garbage collection flag)
[0115] / / 5. Versioned extended fields (adapted to D3D version)
[0116] union {
[0117] struct D3D9Extension {
[0118] bool isFixedPipeline; / / Whether it is a fixed-function pipeline resource (such as a D3D9 vertex texture)
[0119] bool useBlackForUnbound; / / Whether to return black for unbound resources (D3D9 texture sampling semantics)
[0120] } d3d9;
[0121] struct D3D11Extension {
[0122] bool isTypedUAV; / / Whether it is a typed UAV (e.g., R32_UINT UAV)
[0123] bool supportAtomicOps; / / Whether atomic operations (such as InterlockedAdd) are supported.
[0124] } d3d11;
[0125] } ext;
[0126] };
[0127] Additionally, a new singleton class, DxvkResourceMetadataManager, has been added, employing a double hash mapping storage mechanism: the primary mapping is std::unordered_map.<VkDeviceMemory, DxvkResourceMetadata*> Metadata can be quickly queried using Vulkan memory handles, with a time complexity of O(1); the auxiliary map is std::unordered_map.<uint32_t,DxvkResourceMetadata*> By binding slots and querying pipeline stages, it adapts to resource associations during the shader compilation stage; it uses std::shared_mutex to implement a read-write separation lock, supporting multi-threaded concurrent reads and single-threaded writes, ensuring performance in high-concurrency scenarios.
[0128] S1.2 Metadata Lifecycle Synchronization Mechanism. Key interfaces for creating, updating, binding, and destroying D3D resources in DXVK have been modified to achieve real-time synchronization of metadata and resource status, covering all resource operation scenarios in D3D 9-11.
[0129] S1.2.1 Resource Creation Phase: CreateBuffer / CreateTexture / CreateDepthStencilView Interfaces. When DXVK receives a resource creation call from a D3D application, such as ID3D11Device::CreateBuffer or IDirect3DDevice9::CreateTexture, it parses the D3D resource descriptors, including D3D11_BUFFER_DESC, D3DTEXTURE_DESC, and D3D11_DEPTH_STENCIL_VIEW_DESC.
[0130] Initialize the d3dDimension, d3dFormat, usageFlags, isMultisampled, and sampleCount fields; if it is a D3D9 resource, initialize the fixed-function pipeline flag ext.d3d9.isFixedPipeline, and return black for unbound resources ext.d3d9.useBlackForUnbound; if it is a D3D11 resource, initialize the typed UAV flag ext.d3d11.isTypedUAV, and enable atomic operation support ext.d3d11.supportAtomicOps; and use the dxvk format conversion module of DXVK. The `MapFormat` function retrieves the corresponding `vkFormat` and calls `vkGetPhysicalDeviceFormatProperties2` to verify format compatibility; it initializes `effectiveSize`, setting static resources to the declared resource size and dynamic resources to 0 initially, which is subsequently updated via the `Map` interface; it calls `DxvkResourceMetadataManager::registerMetadata` to bind metadata to the Vulkan resource's memory handle `vkMemoryHandle` and binding slot `bindSlot`, and assigns a unique `sandboxId` associated with the kernel sandbox.
[0131] S1.2.2, During the resource update phase, the Map / Unmap / UpdateSubresource / UpdateSubresourceUP interfaces record the offset pOffset and line spacing pRowPitch when the D3D application calls Map to map resources to CPU memory. During Unmap, the actual write length is calculated, and the larger of the current write length and the historical maximum value is used to update the effectiveSize of the metadata. For UpdateSubresource / UpdateSubresourceUP calls, the update region pSrcBox or source data pSrcData is parsed, and the effectiveSize is synchronously corrected to ensure coverage of the entire update range. If the resource is a dynamic buffer such as D3D11_BIND_CONSTANT_BUFFER+D3D11_USAGE_DYNAMIC in D3D11, isStaticResource is marked as false. When dynamic index access is detected during the shader compilation phase, the compilation module sets hasDynamicIndex to true through the DxvkResourceMetadataManager::setDynamicIndexFlag interface.
[0132] S1.2.3, Resource Binding Phase: VSSetShaderResources / PSSetShaderResources / CSSetUnorderedAccessViews interfaces. When the D3D application calls the resource binding interface, it parses the binding slot and updates the bindSlot field of the metadata. If the bound resource handle is NULL, it marks dummyResourceId as the default ID of the placeholder resource pool, triggering the subsequent null descriptor simulation process. It records the pipeline phases of binding, including vertex shaders, pixel shaders, and compute shaders, and updates the auxiliary mapping.
[0133] S1.2.4, during the resource destruction phase, the Release interface sets isPendingDestruction to true when the reference count of a D3D resource reaches zero, adding it to the delayed destruction queue to prevent in-frame resources from being released prematurely. During the frame reclamation phase, DxvkResourceMetadataManager::unregisterMetadata is called to remove metadata entries from the double hash map and release metadata memory. The kernel memory sandbox module is also notified synchronously to release the isolation page table entry and physical memory corresponding to the resource to prevent memory leaks.
[0134] S1.3, High-Availability Metadata Access Interfaces: The following thread-safe interfaces have been added to DxvkResourceMetadataManager for use by the compilation, descriptor management, PSO creation, and pipeline execution modules, covering the entire metadata access process:
[0135] `getMetadataByMemoryHandle(VkDeviceMemory memoryHandle)`: Retrieves a metadata pointer via a Vulkan memory handle for safe concurrent reads; `getMetadataByBindSlot(uint32_t bindSlot, VkShaderStageFlagBits stage)`: Retrieves metadata via binding slots and pipeline stages to adapt to shader compilation; `updateEffectiveSize(VkDeviceMemory memoryHandle, VkDeviceSize newSize)`: Atomically updates the effective size of the resource; `incrementOutOfBoundsCount(VkDeviceMemory memoryHandle)`: Atomically increments the out-of-bounds counter to trigger check strength adjustment; `getDummyResourceId(VkDeviceMemory memoryHandle)`: Retrieves the associated placeholder resource ID to simulate a null descriptor; `isD3D9FixedPipelineResource(VkDeviceMemory...` `memoryHandle`: Determines whether it is a D3D9 fixed-function pipeline resource to achieve semantic adaptation; `isMultisampledResource(VkDeviceMemory memoryHandle)`: Determines whether it is a multisampled resource to achieve placeholder resource adaptation; `markPendingDestruction(VkDeviceMemory memoryHandle)`: Marks the resource to be destroyed for delayed reclamation.
[0136] The S2 and HLSL to SPIR-V compilation stages are the core of simulating D3D memory access semantics. By modifying the DXVK HLSL-SPIR-V compilation pipeline and inserting versioned and scene-specific boundary check instructions, the semantic differences between D3D 9-10-11 can be accurately matched. At the same time, performance loss can be minimized through instruction optimization.
[0137] S2.1, Compilation pipeline modification and check pass insertion.
[0138] The original DXVK compilation process involves HLSL syntax analysis, HLSL IR generation, SPIR-V instruction generation, SPIR-V optimization, and then cache storage. This embodiment inserts a boundary check injection pass (SpirvBoundaryCheckInjectionPass) between SPIR-V instruction generation and SPIR-V optimization. After SPIR-V optimization, it adds a check for instruction optimization (SpirvCheckOptimizationPass) and version compatibility (SpirvVersionCompatibilityPass), as detailed below:
[0139] The compileShader function was modified, and the process was adjusted to: HLSL syntax analysis, HLSL IR generation, SPIR-V instruction generation, boundary check injection, SPIR-V optimization, check instruction optimization, version compatibility adaptation, and cache storage; a new module was added to implement the core logic of the above three passes, decoupled from the existing compilation module, and made easier to maintain.
[0140] S2.2, the resource access scenario fine-grained classification and version check template library, the core logic of SpirvBoundaryCheckInjectionPass is to identify all resource access instructions in the shader, combine the D3D version of the metadata, resource type and access characteristics to classify the scenario, match the corresponding version check template, and ensure semantic consistency.
[0141] S2.2.1 Access Command Scanning and 12 Scene Classification: This involves traversing all commands in the SPIR-V module and filtering out resource access-related commands, including: buffer access (read OpLoad, write OpStore, atomic operations OpAtomicAdd / OpAtomicCompareExchange); image access (sample OpImageSampleImplicitLod / OpImageSampleExplicitLod, write OpImageWrite, depth reference aggregation OpImageDrefGather); and depth template access (read depth value OpLoad, write depth value OpStore). For each access command, the getMetadataByBindSlot interface is called to query metadata by binding slots and pipeline stages. Based on the metadata fields, the access scenes are subdivided into 12 categories, covering all core scenes of D3D 9-10-11, as shown in Table 4.
[0142] Table 4 Core Scene Information Table Scene ID Scene Description Core metadata features D3D semantic requirements 1 D3D11 static buffer + static index read d3dVersion=11, isStaticResource=true, hasDynamicIndex=false Out-of-bounds read returns zero. 2 D3D11 dynamic buffer + dynamic index read d3dVersion=11, isStaticResource=false, hasDynamicIndex=true Out-of-bounds read returns zero. 3 D3D11 typed UAV + dynamic indexed write d3dVersion=11, ext.d3d11.isTypedUAV=true, accessFlags = write Write out of bounds and discard silently 4 D3D11 UAV atomic operations d3dVersion=11, ext.d3d11.supportAtomicOps=true Out-of-bounds atomic operations have no effect 5 D3D9 Fixed Function Pipeline Texture Sampling d3dVersion=9, ext.d3d9.isFixedPipeline=true Unbound / Out of bounds return black 6 D3D9 dynamic textures + dynamic index reading d3dVersion=9, hasDynamicIndex=true Reading out of bounds returns to black 7 D3D10 Multisampling Texture Sampling d3dVersion=10, isMultisampled=true Out-of-bounds reads return zero (maintaining MSAA mode). 8 D3D11 Deep Buffer Read d3dVersion=11, usageFlags=Depth Template, accessFlags=Read Out-of-bounds read returns 0.0 (depth test passed) 9 D3D11 deep buffer write d3dVersion=11, usageFlags=Depth Template, accessFlags=Write Write out of bounds and discard silently 10 D3D10 static textures + static index sampling d3dVersion=10, isStaticResource=true, hasDynamicIndex=false Out-of-bounds read returns zero. 11 D3D11 Untyped UAV Writing d3dVersion=11, ext.d3d11.isTypedUAV=false, accessFlags = write Write out of bounds and discard silently 12 Unbound resource access (nulldescriptor) dummyResourceId≠0 Returns zero value / black according to D3D version.
[0143] S2.2.2 Version Check Template Library Design and Instantiation: A version check instruction template library, SpirvCheckTemplateLibrary, is predefined for 12 scene types. Each template contains conditional judgment instructions, semantic adaptation instructions, and exception handling instructions to ensure complete consistency with D3D semantics. Some core template designs are as follows:
[0144] The template for Scene 2 is:
[0145] / / Obtain the valid size from metadata; inject constants at compile time via the metadata interface.
[0146] %effectiveSize = OpConstant %uint 4096 / / Example: Effective size 4KB
[0147] %zero = OpConstantNull %float
[0148] / / Dynamic index retrieval
[0149] %index = OpLoad %uint %indexVar
[0150] / / Boundary judgment
[0151] %valid = OpICompare %bool OpSLT %index %effectiveSize
[0152] / / If valid, load the data; otherwise, return zero.
[0153] %data = OpLoad %float %buffer %index
[0154] %result = OpSelect %float %valid %data %zero
[0155] The template for Scene 5 is:
[0156] / / Black constant, D3D9 unbounded and out-of-bounds sampling return black.
[0157] %black = OpConstantComposite %vec4 (OpConstant %float 0.0, OpConstant%float 0.0, OpConstant %float 0.0, OpConstant %float 1.0)
[0158] / / Texture validity check (valid if bound to placeholder resources)
[0159] %image = OpLoad %sampledImage %imageVar
[0160] %valid = OpIsValid %bool %image
[0161] / / Sample if valid, otherwise return black.
[0162] %coord = OpLoad %vec2 %coordVar
[0163] %sampledColor = OpImageSampleImplicitLod %vec4 %image %coord
[0164] %result = OpSelect %vec4 %valid %sampledColor %black
[0165] The template for Scene 7 is:
[0166] / / Zero-value constant, adaptable to multiple sampling formats
[0167] %zeroMsaa = OpConstantComposite %vec4 %float 0.0
[0168] / / Determining the effective dimension of multi-sampled textures
[0169] %image = OpLoad %sampledImage %imageVar
[0170] %coord = OpLoad %vec2 %coordVar
[0171] %imageExtent = OpImageQuerySize %uvec2 %image
[0172] %validX = OpICompare %bool OpSLT (OpConvertFToU %uint(OpCompositeExtract %float %coord 0)) (OpCompositeExtract %uint %imageExtent0)
[0173] %validY = OpICompare %bool OpSLT (OpConvertFToU %uint(OpCompositeExtract %float %coord 1)) (OpCompositeExtract %uint %imageExtent1)
[0174] %valid = OpLogicalAnd %bool %validX %validY
[0175] / / If valid, sample more; otherwise, return zero.
[0176] %sampledColor = OpImageSampleImplicitLod %vec4 %image %coord
[0177] %result = OpSelect %vec4 %valid %sampledColor %zeroMsaa
[0178] The template for Scene 4 is:
[0179] / / Atomic operations have no effect when they go out of bounds
[0180] %effectiveSize = OpConstant %uint 65536
[0181] %index = OpLoad %uint %indexVar
[0182] %valid = OpICompare %bool OpSLT %index %effectiveSize
[0183] OpBranchConditional %valid %atomicBlock %endBlock
[0184] %atomicBlock = OpLabel
[0185] %oldValue = OpAtomicAdd %uint %uav %index %memoryScope %memorySemantics %addValue
[0186] OpBranch %endBlock
[0187] %endBlock = OpLabel
[0188] S2.2.3. Check instruction injection, format, and version compatibility. For each access instruction, match the corresponding template based on the scene ID, instantiate the template using the SPIRV-Cross Builder interface, and insert it into the SPIR-V instruction stream immediately before the access instruction. For format compatibility, address the format differences between D3D and Vulkan, such as D3D9's D3DFMT_A8R8G8B8 and Vulkan's VK_FORMAT_B8G8R8A8_UNORM, inserting OpImageConvert or OpVectorShuffle instructions after the checked instructions to adjust the color channel order and data class. To ensure consistent return value format, the following measures are implemented: For multi-sampling resources (e.g., Scene 7), OpImageQuerySize is used in the template to obtain the actual sampling dimension, preventing judgments based on fixed dimensions from failing; For atomic operations, branch jumps are used to shield atomic instruction execution for resources supporting atomic operations (e.g., Scene 4), ensuring no effect when out of bounds occurs; For zero-precision, OpConstantNull is used to ensure precise zero values are returned for floating-point resources (e.g., VK_FORMAT_R32G32B32_FLOAT), and OpConstant %uint 0 is used to return zero values for integer resources (e.g., VK_FORMAT_R32_UINT), avoiding precision deviations.
[0189] S2.3, Check Instruction Optimization Pass: The core objective of SpirvCheckOptimizationPass is to minimize the performance overhead of check instructions through redundancy merging, instruction simplification, and process optimization. Specifically:
[0190] Redundancy checks are merged, and continuous accesses to the same resource are merged. For continuous accesses to the same resource, such as array accesses within a loop or multiple texture samplings, the check instructions are extracted to the nearest common predecessor basic block, such as after the loop entry OpLabel, and only one judgment is performed. For example, three accesses to buffer[index] within a loop are converted to inserting %valid = OpICompare at the loop entry, and the %valid judgment is directly reused within the loop. Batch accesses to the same scene are merged. For multiple resource accesses in the same scene, such as static index reads of multiple static buffers in the same shader, format adaptation instructions are merged, such as a single format conversion covering multiple accesses.
[0191] The inspection instructions are streamlined, and static conditions are folded. For inspection instructions whose conditional judgment results are constants, such as static index access where the index validity can be verified at compile time, they are directly folded into core access instructions. Conditional judgments and branch jumps are removed. For example, index=5 and effectiveSize=10 is converted to directly retain OpLoad, and %valid judgments and OpSelect are removed. Instruction replacement optimization: For the OpSelect instruction, if one of the branches is a constant such as zero value and the target type supports it, it is replaced with the OpMux instruction. Some GPUs have higher execution efficiency for OpMux. Invalidity checks are removed: For resources with isStaticResource=true and hasDynamicIndex=false, if all access indices are verified to be within the effectiveSize range at compile time, the inspection instructions are directly removed.
[0192] Process optimization and branch structure optimization: The linear structure of inspection instructions and core access instructions is adjusted to a structure of conditional judgment and branch execution. The zero value is returned only when the boundary is exceeded, and the access is directly executed when it is legal. The branch prediction of the GPU is used to optimize performance. Instruction scheduling optimization: Constant instructions such as OpConstant and OpConstantNull in the inspection instructions are moved to the beginning of the module to avoid repeated generation. Time-consuming instructions such as OpImageQuerySize are scheduled in parallel with other instructions using the instruction-level parallelism of the GPU.
[0193] S2.4 Version Compatibility Pass: SpirvVersionCompatibilityPass performs downgrade adaptation for instruction support limitations of earlier GPUs such as Vulkan 1.0 or earlier drivers, ensuring compatibility of compiled artifacts.
[0194] Command degradation: If the driver does not support OpIsValid (Vulkan 1.0), it is replaced by loading a placeholder resource validity flag, storing the isValid field in the placeholder resource metadata, and determining it through OpLoad; Format degradation: If the driver does not support a certain format of OpImageConvert, the channel order is adjusted through OpVectorShuffle, and the data types are converted using OpConvertFToU and OpConvertUToF, replacing it with software format conversion; Function degradation: If the driver does not support OpImageSampleImplicitLod for multi-sample textures, it is downgraded to single-sample sampling, specifying lod=0 through OpImageSampleExplicitLod, in conjunction with the multi-sample simulation of placeholder resources.
[0195] S2.5 Compilation cache association management: Modify the DXVK shader cache module, optimize cache key design, and avoid cache pollution and duplicate compilation.
[0196] Add a new field to the cache key:
[0197] extSupported (1 bit): Whether VK_EXT_robustness2 is supported;
[0198] checkTemplateVersion (8-bit): Checks the template library version (caching is invalidated when the template is updated);
[0199] driverFingerprint (64-bit): Driver feature fingerprint (cached invalidation during driver update);
[0200] vulkanApiVersion (16-bit): Vulkan API version (adapts to differences in command support).
[0201] Cache partitioning: Partition the cache according to driver vendor and GPU architecture, such as AMD Polaris, NVIDIA Turing, and Intel Xe, to avoid mixing caches of different architectures; Cache cleanup: Add a cache cleanup interface to automatically clean up old cache entries in the corresponding partition when the driver fingerprint is updated or the check template version changes.
[0202] S3, the descriptor set construction stage, replaces the null descriptor support of VK_EXT_robustness2 by pre-creating basic resources, dynamically adapting and pooling reuse of placeholder resources, ensuring that the access behavior of D3D unbound resources is consistent with the native one, while minimizing the overhead of video memory and the cost of updating descriptors on the CPU side.
[0203] S3.1, the core of the placeholder resource factory, adds the DxvkDummyResourceFactory class to the DXVK descriptor management module. It is responsible for the creation, format adaptation, multi-sampling adaptation, pooling reuse and destruction of placeholder resources. The core is divided into three major modules: basic placeholder resource pre-creation, dynamic adaptation layer and pooling management.
[0204] S3.1.1 Pre-creation of basic placeholder resources reduces dynamic overhead through global reuse.
[0205] Based on the high-frequency resource types of D3D 9 to 11, six types of basic placeholder resources are pre-created and stored in DxvkDummyResourcePool, as shown in Table 5.
[0206] Table 5 Basic Resource Information Table Basic resource types Specifications Initialization method Adapted scenarios General Buffer Size = 64MB (covers D3D's maximum UAV buffer + maximum constant buffer), Alignment = 64 bytes Zero initialization (vkMapMemory + memset (0)) null descriptor for all buffer types General single-sample texture 1x1 pixel, 2D, 1 layer, 1 mipmap, format = VK_FORMAT_R8G8B8A8_UNORM vkCmdClearColorImage(RGBA(0,0,0,0)) nulldescriptor for single-sampled textures General Multisampling Texture 1x1 pixel, 2D, 1 layer, 1 mipmap, format = VK_FORMAT_R8G8B8A8_UNORM, number of samples = 8x (covering mainstream MSAA). vkCmdClearColorImage(RGBA(0,0,0,0)) nulldescriptor for multisampled textures D3D9 Dedicated Texture 1x1 pixel, 2D, 1 layer, 1 mipmap, format = VK_FORMAT_B8G8R8A8_UNORM vkCmdClearColorImage(RGBA (0,0,0,1), i.e., black) D3D9 Fixed Function Pipeline Texture nulldescriptor General-purpose depth buffer 1x1 pixel, 2D, 1 layer, 1 mipmap, format = VK_FORMAT_D32_FLOAT vkCmdClearDepthStencilImage(depth=0.0, stencil=0) null descriptor of deep template resources Universal Sampler Address mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, Filter mode = VK_FILTER_LINEAR, Compare mode = VK_COMPARE_OP_ALWAYS vkCreateSampler (global reuse) nulldescriptor for all unbound samplers
[0207] S3.1.2 Dynamic Adaptation Layer: Two new classes, DxvkDummyFormatAdapter and DxvkDummyMsaaAdapter, are added to dynamically adapt basic placeholder resources to the target resource format, sampling mode, and version semantics required by the D3D application. The specific adaptation process is as follows:
[0208] The input includes the target D3D format (d3dFormat), the target resource type (buffer or texture), and the D3D version. For format conversion, vkGetPhysicalDeviceFormatProperties2 is called to check the compatibility between the target format and the underlying resource format, and the following cases are considered:
[0209] For direct compatibility, such as D3D11's DXGI_FORMAT_R8G8B8A8_UNORM being consistent with the base texture format, the view VkBufferView or VkImageView of the base resource can be used directly. For compatibility through view adaptation, such as D3D11's DXGI_FORMAT_R32_UINT being compatible with the base buffer format, vkCreateBufferView / vkCreateImageView can be called to create a view of the target format based on the base resource. For data conversion, such as D3D9's D3DFMT_A8R8G8B8 being compatible with the base texture format VK_FORMAT_B8G8R8A8_UNORM, the driver's format conversion (vkGetPhysicalDeviceFormatFeatures2) field is checked. If supported, an image view of the target format is created, utilizing the GPU hardware's format conversion capabilities to automatically convert zero values during access. If not supported, a temporary conversion buffer is created, converting the zero-value data of the base resource to the target format and copying it to a temporary placeholder resource for subsequent reuse.
[0210] Multisampling adaptation takes the target sample count (sampleCount) and target format (d3dFormat) as inputs. The processing logic is as follows: if the target sample count is not greater than the sample count of the base multisampling texture (8x), then vkCreateImageView is called to create an image view with the corresponding sample count. For example, if the target is 4xMSAA, a 4x view is created based on the 8xMSAA base resource. Otherwise, a temporary multisampling texture with the target sample count is dynamically created, zero-initialized, and added to pooling management for reuse. This ensures that the sampleCount of the multisampling placeholder resource is consistent with the target sample count of the D3D application's rendering, avoiding multisampling mode mismatch when creating PSO.
[0211] Version semantic adaptation: D3D9 adaptation: For D3D9 fixed-function pipeline resources corresponding to scene 5, use D3D9-specific base textures, initialize with black, and ensure that access to unbounded resources returns black; D3D11 adaptation: For typed UAV corresponding to scene 3, create a UAV view of the target format based on a general buffer, set the range of VkDescriptorBufferInfo to 1 byte, and use shader check instructions to prevent out-of-bounds writes; Depth buffer adaptation: For depth stencil resources corresponding to scenes 8 and 9, use general depth buffer base resources to create a view of the target depth format (such as VK_FORMAT_D24_UNORM_S8_UINT), and ensure that out-of-bounds reads return 0.0.
[0212] S3.1.3 Pooling Management Mechanism: View pooling maintains a view pool std::unordered_map for placeholder resource views (VkBufferView and VkImageView) with the same format, sampling mode, and purpose.<DummyViewKey,VkImageView> The DummyViewKey contains fields for format, sample count, and purpose, avoiding duplicate view creation; Temporary resource pooling: For dynamically created special format / high sample count placeholder resources, a temporary resource pool is maintained, recording its idle frame count (idleFrameCount). If it is not used for more than 5 frames, it is destroyed to release video memory; Frame-level reuse: A new DxvkDummyResourceFrameTracker class is added to record the placeholder resources and views used in each frame. Requests with the same DummyViewKey within the same frame reuse the same view, reducing the number of descriptor set updates.
[0213] S3.2 Null descriptor mapping and descriptor set construction: Modify the DXVK's updateDescriptorSet function to add null descriptor mapping logic to ensure the descriptor set state is valid, i.e., Vulkan does not allow binding to VK_NULL_HANDLE:
[0214] Null resource identification and placeholder resource matching: When the resource handle passed by the D3D application is NULL, such as when ppShaderResourceViews of ID3D11DeviceContext::PSSetShaderResources contains nullptr, the null descriptor mapping process is triggered; based on the resource binding slot and pipeline stage, metadata is queried to obtain information such as d3dVersion, d3dFormat, isMultisampled, and sampleCount; the DxvkDummyResourceFactory::getAdaptedResource interface is called, passing in the above information, to obtain the adapted placeholder resource and view.
[0215] The descriptor set is updated and compatibility checks are performed. The adapted placeholder resource views VkBufferView and VkImageView are bound to the Vulkan descriptor set with the generic sampler, replacing the original VK_NULL_HANDLE. For UAV type placeholder resources, VkDescriptorBufferInfo's offset=0 and range=1 are set, and shader check instructions are used to ensure that write operations are masked. For depth template type placeholder resources, VkDescriptorImageInfo's imageLayout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL (read) or VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL (write) is set to ensure pipeline compatibility. A new descriptor layout compatibility check is added to verify that the type of the placeholder resource view, such as VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, is consistent with the type declared in the descriptor layout to avoid PSO creation failure.
[0216] S3.3, Placeholder resource lifecycle management: Basic resource lifecycle: Globally resident, only destroyed when DXVK exits by calling vkDestroyBuffer, vkDestroyImage, and vkDestroySampler; View lifecycle: Views in the view pool are destroyed when DXVK exits; Frame-reused views are destroyed when frames are recycled if the reference count is 1, indicating that they are only used in the current frame; Temporary resource lifecycle: Resources in the temporary resource pool are incremented by idleFrameCount after each frame ends, and destroyed after more than 5 frames, simultaneously releasing the corresponding view and video memory.
[0217] S4, Pipeline State Object (PSO) creation and pipeline execution, solves PSO creation compatibility issues, avoids Vulkan undefined behavior through Linux kernel-level video memory isolation, and achieves cross-driver adaptation by combining driver feature fingerprint library to ensure stable pipeline execution.
[0218] S4.1 Compatibility adaptation during the Pipeline State Object (PSO) creation phase: A new module modifies the DXVK's createGraphicsPipeline / createComputePipeline functions to ensure that PSO is compatible with boundary check commands and placeholder resources.
[0219] Shader interface compatibility checks and adjustments, resource binding slot checks, and verification that the resource binding slots of the shader after inserting the boundary check instruction are consistent with the slots declared in the VkDescriptorSetLayout to avoid PSO creation failure due to slot mismatch; format compatibility checks, verifying that the format of placeholder resources, such as texture view format, is consistent with the shader's expected format. If inconsistent, adjust the shader's format declaration before PSO creation by modifying the resource format using the SPIR-V OpDecorate instruction; multisampling mode matching, since Vulkan requires that the PSO's rasterizationState.sampleCount be consistent with the number of samples in the rendering target, it is necessary to ensure that the number of samples in the placeholder multisampling texture is consistent with the number of samples in the rendering target to avoid PSO creation failure due to multisampling mode mismatch.
[0220] PSO creation parameter adaptation, depth template state adaptation, for scenes without bound depth buffers such as placeholder depth resources, set depthStencilState.depthTestEnable=false and depthStencilState.depthWriteEnable=false to match the default behavior of D3D; blend state adaptation, for scenes without bound rendering targets such as placeholder color resources, set blendState.attachment[0].blendEnable=false to avoid rendering abnormalities caused by blending operations; rasterization state adaptation, for D3D9 fixed function pipeline resources, adjust rasterizationState.polygonMode and rasterizationState.cullMode to the default values of D3D9, such as VK_POLYGON_MODE_FILL and VK_CULL_MODE_BACK_BIT.
[0221] PSO cache association management was improved by modifying the PSO cache module of DXVK. Fields such as placeholder resource format, multiple sampling number and driver fingerprint were added to the cache key to ensure that PSO caches do not conflict under different drivers and different null descriptor adaptation scenarios.
[0222] S4.2, Linux kernel-level video memory isolation mechanism: Modify the Linux kernel's video memory management module to add the vk_sandbox submodule, providing independent memory isolation space for DXVK's actual resources and placeholder resources, ensuring that out-of-bounds access will not pollute other resources, as detailed below:
[0223] S4.2.1 Sandbox Creation and Resource Binding: During DXVK initialization, the newly added system call sys_vk_sandbox_create is invoked to create the real resource sandbox REAL_RESOURCE_SANDBOX and the placeholder resource sandbox DUMMY_RESOURCE_SANDBOX. The kernel allocates an independent virtual address space and page table struct vm_area_struct for each sandbox, and the sandbox ID sandboxId is bound to the sandboxId of the DXVK resource metadata. When a resource is created, its memory is allocated to the corresponding sandbox according to whether it is a real resource or a placeholder resource, and the page table mapping of the sandbox is updated.
[0224] S4.2.2 Memory Access Isolation and Out-of-Bounds Handling: Address translation isolation. When the GPU accesses resources, the kernel queries the corresponding page table through the sandbox ID, allowing access only to physical pages within that sandbox and prohibiting cross-sandbox access. If a shader check instruction is missed, causing out-of-bounds access to a real resource, the kernel triggers page table protection, returning a zero value to fill the fault page instead of executing undefined behavior. Placeholder resource write protection: The physical pages of the placeholder resource sandbox are set to write protection. If the shader attempts to write to the placeholder resource, the kernel triggers a write protection fault, blocking the write operation and simulating D3D's write-discard semantics.
[0225] S4.2.3 Zero initialization on-demand allocation: Physical pages of placeholder resource sandboxes adopt an on-demand allocation strategy: When accessing for the first time, a page fault is triggered, the kernel allocates a physical page and fills it with a zero value through memset, and then marks it as initialized; Physical pages of real resource sandboxes are allocated when the resource is created. If it is a dynamic resource, it is initialized to a zero value during the first Map operation to ensure that out-of-bounds reads return a zero value.
[0226] S4.3, Driver Feature Fingerprint Library and Refined Adaptation: A new module is added to build a driver feature fingerprint library, enabling fingerprint-based adaptive adjustment that covers mainstream GPU manufacturers and driver versions.
[0227] S4.3.1. Full-dimensional collection of driver characteristics: During DXVK initialization, the Vulkan interface is called to collect the following 8 core characteristics to ensure that the fingerprint can accurately represent the driver capabilities.
[0228] S4.3.2 Fingerprint Encoding and Fingerprint Database Construction.
[0229] Fingerprint encoding encodes the collected 8 types of characteristics into a 128-bit fingerprint (uint128_tdriverFingerprint). The encoding rules consist of the vendor ID (8 bits), device ID (16 bits), driver major version (8 bits), driver minor version (8 bits), Vulkan version (16 bits), format support mask (32 bits), and instruction support mask (32 bits). A built-in fingerprint library, pre-compiling fingerprints and adaptation strategies for mainstream drivers, is stored in dxvk_driver_fingerprint_db.h, as shown in the example below:
[0230] static const DxvkDriverAdaptPolicy s_driverPolicies[] = {
[0231] / / NVIDIA 535.98 driver (Turing architecture)
[0232] { 0x10DE0TU128, { .checkIntensity = CHECK_INTENSITY_HIGH, .formatAdaptMode = FORMAT_ADAPT_TEMP_BUFFER, .relyOnDriverRobustness = false}},
[0233] / / AMD 22.10.3 driver (RDNA architecture)
[0234] { 0x10020RDNA128, { .checkIntensity = CHECK_INTENSITY_MEDIUM, .formatAdaptMode = FORMAT_ADAPT_VIEW, .relyOnDriverRobustness = true}},
[0235] / / Intel 31.0.101.4032 driver (Xe architecture)
[0236] { 0x80860Xe128, { .checkIntensity = CHECK_INTENSITY_MEDIUM, .formatAdaptMode = FORMAT_ADAPT_VIEW, .relyOnDriverRobustness = true}},
[0237] };
[0238] Dynamic updates are supported, allowing manual addition of fingerprints and adaptation strategies for new drivers via the DXVK configuration file dxvk.conf or the environment variable DXVK_DRIVER_POLICY, without requiring modification of the source code.
[0239] S4.3.3 Fingerprint-based fine-grained adaptation strategy: During initialization, the corresponding adaptation strategy DxvkDriverAdaptPolicy is obtained through fingerprint matching, and adaptive adjustments are performed throughout the entire process.
[0240] The strength of the check is adjusted as follows: High strength CHECK_INTENSITY_HIGH provides enhanced checks for all dynamic index access inserts, such as those in NVIDIA drivers, where out-of-bounds reads return a random value; Medium strength CHECK_INTENSITY_MEDIUM checks only for high-risk resource inserts, such as those in AMD / Intel drivers, where out-of-bounds reads return zero; Low strength CHECK_INTENSITY_LOW checks only for dynamic resource inserts and is suitable for drivers that support legacy robustness extensions.
[0241] The format adaptation mode has been adjusted. FORMAT_ADAPT_VIEW prioritizes format adaptation through the image view, which has the best performance and is suitable for drivers that support format conversion; FORMAT_ADAPT_TEMP_BUFFER uses a temporary conversion buffer and is suitable for drivers that do not support format conversion, such as some early NVIDIA drivers.
[0242] Driver robustness depends on tuning. `relyOnDriverRobustness=true` disables software checks for low-risk resources, including static resources and static indexes, and depends on the robustness of the driver, such as AMD drivers. `relyOnDriverRobustness=false` forces full software checks to be enabled, such as NVIDIA drivers.
[0243] For memory allocation adaptation, adjust the allocation alignment of placeholder resources according to the memory alignment requirements of the driver. For example, NVIDIA requires buffers to be aligned to 64 bytes, while Intel requires them to be aligned to 32 bytes. For GPUs with insufficient local memory, such as early integrated graphics cards, allocate placeholder resources to system memory VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT and initialize them to zero values through memory mapping.
[0244] S4.4 Pipeline execution exception handling: Modify the handleDeviceLost function in the DXVK error handling module to add pipeline execution exception handling to ensure operational stability.
[0245] Error capture, including Vulkan errors such as VK_ERROR_DEVICE_LOST device loss, VK_ERROR_MEMORY_MAP_FAILED memory mapping failure, and VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS invalid address access;
[0246] Anomaly diagnosis combines metadata out-of-bounds counter outOfBoundsCount, kernel sandbox fault logs including out-of-bounds address and sandbox ID, and driver fingerprint to determine whether it is an uncaught out-of-bounds access.
[0247] Recovery strategies include increasing the intensity of checks on corresponding resources, such as changing from medium to high intensity; recompiling shaders and enabling enhanced check templates; rebuilding descriptor sets and PSOs to ensure correct adaptation of placeholder resources; if the same exception is triggered three times consecutively, switching to safe mode, i.e., full check and strict isolation by the kernel sandbox; and logging to record exception details, including driver version, GPU model, and out-of-bounds resource information, to facilitate troubleshooting.
[0248] S5, Frame Resource Reclamation, synchronously updates metadata, placeholder resources, and shader cache status after the frame ends, ensuring efficient resource reclamation and avoiding leaks, redundant overhead, and cache pollution.
[0249] S5.1 Metadata Status Synchronization and Recycling: Add metadata synchronization logic to the endFrame function to cover lifecycle management requirements.
[0250] Frame usage statistics are performed by iterating through all resources used in the current frame using the DXVK resource tracking module, calling the DxvkResourceMetadataManager::updateFrameUsage interface, and incrementing frameUsageCount. Idle status updates are performed by incrementing idleFrameCount for unused resources with a frameUsageCount of 0. If idleFrameCount exceeds 10 frames, it is marked as pending destruction.
[0251] The out-of-bounds counter is reset, setting the outOfBoundsCount of all resources to 0 to prevent excessive checks due to long-term accumulation. Resources to be destroyed are processed by iterating through the list of resources to be destroyed and calling DxvkResourceMetadataManager::unregisterMetadata to release metadata and associated kernel sandbox resources.
[0252] S5.2 Placeholder resource and view reclamation: Frame-level view reclamation: Traverse the placeholder resource views in DxvkDummyResourceFrameTracker and decrement the reference count; if the reference count is 0, call vkDestroyBufferView / vkDestroyImageView to destroy the view; Temporary resource reclamation: Traverse the temporary placeholder resource pool, and for resources with idleFrameCount exceeding 5 frames, call vkDestroyBuffer / vkDestroyImage to destroy them and release video memory; Sandbox memory reclamation: Notify the kernel vk_sandbox module to reclaim unused physical pages in the placeholder resource sandbox and allocate zero-initialized pages as needed.
[0253] S5.3 Shader Cache and PSO Cache Cleanup. Cache validity verification: Traverse the shader cache and PSO cache, check the driver fingerprint in the cache key, and check if the template version matches the current environment. If they do not match, mark them as invalid. Invalid cache cleanup: Perform invalid cache cleanup every 10 frames to release disk space and memory occupied by the cache. Hotspot cache retention: Mark frequently used cache entries (hotspot cache) in the last 10 frames as retained to avoid accidental cleanup.
[0254] S5.4, End-to-End State Consistency Verification: A new module performs lightweight verification during the frame recycling phase to ensure end-to-end state consistency. This includes: Metadata consistency (verifying that the effectiveSize of metadata matches the actual size of Vulkan resources, and that the sandboxId matches the sandbox allocation record); Placeholder resource consistency (verifying that the reference count of placeholder resources matches the frame usage record to avoid reference count leaks); Sandbox consistency (verifying that the resource mapping of the kernel sandbox matches the resource allocation record of DXVK to avoid memory isolation failures); Cache consistency (verifying that the driver fingerprint of the shader cache matches the current driver to avoid cache pollution); and Verification Repair (if verification fails, triggering warning logs and automatically repairing the process, such as resynchronizing metadata, forcibly releasing leaked placeholder resources, and cleaning up invalid caches).
[0255] Experimental testing has shown that this embodiment has the following characteristics:
[0256] Semantic consistency is achieved through versioned modular checks and adaptive placeholder resources via formatting and sampling, 100% replicating D3D 9-10-11 memory access semantics (out-of-bounds reads of zero or black, write discard) and null descriptor behavior. Testing shows compatibility with over 99.8% of games relying on this semantics, with no rendering anomalies, geometric distortions, or color deviations. Performance overhead is significantly reduced, decreasing by 70% to 90% compared to traditional global check solutions, with frame rate drops in complex games controlled to 1% to 4%, meeting smooth gameplay requirements. Memory overhead is greatly optimized through basic resource reuse, view pooling, and on-demand allocation, increasing memory overhead by no more than 2%, allowing stable operation even on early GPUs with 1GB of memory (such as GTX 750Ti and AMD R7 260X). Comprehensive compatibility is ensured, supporting all AMD, NVIDIA, and Intel GPUs, adapting to Vulkan 1.0 and above, and supporting driver versions spanning from 2020 to the present (such as NVIDIA 450.x+, AMD 20.45+, and Intel). Version 27.20+ requires no modification to the GPU driver source code; stability is significantly improved, with no crashes, memory leaks, or device loss after 100 hours of operation; undetected out-of-bounds access triggers a fallback mechanism that automatically recovers, achieving stability close to environments supporting VK_EXT_robustness2; low code invasiveness: core modifications are concentrated in 6 DXVK modules, without disrupting the original DXVK architecture, facilitating subsequent maintenance and upgrades; strong extensibility, supporting the extension of the driver fingerprint library via configuration files or environment variables to adapt to newly released GPUs and drivers without recompiling the DXVK source code.
[0257] 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 memory model compatibility method based on adaptive placeholder resources, characterized in that, Specifically comprising the following steps: DXVK establishes a scene library containing metadata of basic attributes, access features, associated resources and life cycles and access scenes when starting, associates the access scenes with D3D semantic requirements, establishes check instruction templates for the access scenes according to the D3D semantic requirements, and creates basic placeholder resources; Two types of sandboxes are created, and independent virtual address spaces and page tables are allocated to store real resources and placeholder resources respectively; An auxiliary mapping of resource binding slots and rendering pipeline stages to metadata is established; When a D3D application is started to create a D3D resource, DXVK parses the resource descriptor, initializes the basic attributes of the metadata, maps the D3D resource to a Vulkan resource, binds the metadata to the memory handle and shader slot of the Vulkan resource, and allocates a sandbox to update the page table mapping; when the resource is updated, DXVK corrects the metadata, and updates the access features for dynamic index access; When the resource is bound, DXVK updates the auxiliary mapping of the binding slot of the basic attributes, and sets the placeholder resource ID of the associated resource to a default value when the resource handle is empty; when the resource is destroyed and the resource reference count is zero, the life cycle is set and then destroyed; DXVK compiles the D3D application shader, identifies the resource access instruction as a target instruction between generating SPIR-V instructions and optimizing SPIR-V instructions; the metadata and access scenes are read from the binding slot and pipeline stage, the determined check instruction template is instantiated and added to the target instruction; When the placeholder resource ID is the default value, the corresponding basic placeholder resource is adapted as the placeholder resource of the D3D resource, and the corresponding sandbox is set to read-only; the placeholder resource and the general sampler are bound to the Vulkan descriptor set, and the pipeline state object is created; DXVK intercepts the rendering instruction of the D3D application, passes the instruction parameters into the Vulkan core command to build a command buffer, submits it to the Vulkan queue, and triggers the GPU to execute the rendering process to complete the rendering.
2. The Direct3D memory model compatible method of claim 1, wherein, DXVK implements zero initialization on-demand allocation when creating a D3D resource, specifically: for the sandbox of the placeholder resource, a page fault interrupt is triggered when accessed for the first time, the kernel allocates a physical page and fills it with zero values, and then marks it as initialized; for the sandbox of the real resource, it is initialized to zero when it is first mapped.
3. The Direct3D memory model compatible method of claim 1, wherein, The metadata is stored using double hash mapping, the main mapping of the pointer of the Vulkan memory handle to the metadata is established at the same time as the auxiliary mapping is established, a shared lock is constructed which can be acquired by multiple threads simultaneously to enable read operations on the metadata, and an exclusive lock is constructed which can be acquired by only a single thread at the same time to enable write operations on the metadata, the auxiliary mapping is updated in the resource binding stage, and the mapping entry is deleted in the resource destruction stage.
4. The Direct3D memory model compatible method of claim 1, wherein, The check instruction template includes conditional judgment instructions, semantic adaptation instructions and exception handling instructions, the NullDescriptor scene check instruction is included in the conditional judgment instructions, and the processing process is to determine whether to execute or shield the target instruction according to the execution result of the conditional judgment instruction.
5. The Direct3D memory model compatibility method of claim 1, wherein, After the instantiation-determined check instruction template is checked, the instruction obtained by instantiating the instantiation-determined check instruction template is recorded as a first check instruction, the first check instruction related to a target instruction accessing the same resource continuously is extracted to the nearest common predecessor basic block, for the first check instruction related to a target instruction accessing multiple resources in the same scene, the semantic adaptation instruction in the instruction is merged, for the target instruction whose execution result of the first check instruction is valid, the conditional judgment instruction in the first check instruction is deleted, and for the target instruction accessing a static resource and being non-dynamic index access, when the execution result of the corresponding first check instruction is valid, the first check instruction is deleted.
6. The Direct3D memory model compatibility method of claim 1, wherein, The way of adapting the corresponding basic placeholder resource to the placeholder resource of the D3D resource is: format adaptation, the input is the D3D format, resource type and D3D version of the D3D resource, if the D3D format is compatible with the format of the basic placeholder resource, the view of the basic placeholder resource is adopted, if the view adaptation is needed, the view of the D3D format is created based on the basic placeholder resource, if the conversion is needed, the view of the D3D format is created by using the hardware format conversion when the GPU driver supports the format conversion, if the support is not available, a temporary conversion buffer is created, the zero value data of the basic placeholder resource is converted to the D3D format and then copied to the temporary conversion buffer, and the temporary conversion buffer is reused subsequently; multi-sampling adaptation, the input is the sample number and the D3D format of the D3D resource, if the target sample number is not greater than the sample number of the multi-sampling texture of the basic placeholder resource, the view corresponding to the sample number is created; if the target sample number is greater than a threshold, a temporary multi-sampling texture with the target sample number is created, and the multi-sampling texture is zero initialized and then added to the pooling management; version semantic adaptation, for the D3D9 fixed function pipeline resource, the D3D9 special basic texture is adopted; when the D3D11 adaptation is needed, the UAV view of the D3D format is created based on the general buffer for the typed UAV; depth buffer adaptation, the general depth buffer basic placeholder resource is used for the depth template resource, and the view of the target depth format is created.
7. The Direct3D memory model compatible method of claim 6, wherein, For all placeholder resources of the D3D application, the view pool is created for the placeholder resources with the same format, sampling mode and purpose, the view reuse is realized, the temporary resource pool is created for the dynamically created placeholder resources with special format or high sampling number, and the placeholder resources not used within the set number of frames are destroyed, and the request of the placeholder resources used in the same frame is recorded, the same placeholder resource is reused, and the frame-level reuse resource is formed.
8. The Direct3D memory model compatibility method of claim 1, wherein, The way of completing the rendering by the GPU executing the rendering process is: the vertex shader processes the vertex data, the pixel shader and the compute shader execute the resource access logic, before each resource access instruction is executed, the instruction obtained by the instantiated instantiation check instruction template is executed first, the access legality is judged according to the metadata, if the access is legal, the real resource or the placeholder resource is read, if the access is out of bounds, the zero value or the black color is returned as the replacement value according to the D3D semantics, or the write operation is discarded silently; the depth test and the color blending are completed according to the configuration of the pipeline state object.
9. The Direct3D memory model compatibility method of claim 1, wherein, Real-time monitoring of Vulkan execution state, capturing device loss and memory access invalid exceptions, locating the cause of the exception according to the metadata of the out-of-bound counter and the kernel sandbox failure log; Trigger recovery strategies according to exception types, including increasing resource inspection intensity, recompiling shaders, rebuilding descriptor sets and pipeline state objects, and switching to safe mode if there are continuous exceptions.
10. The Direct3D memory model compatibility method of claim 1, wherein, Collect GPU core characteristics when DXVK starts, encode them as fingerprint information, and pre-compile the fingerprint information of mainstream drivers and adaptation strategies to form a fingerprint library; Match the corresponding adaptation strategy by matching the current GPU's fingerprint information, and adjust the inspection intensity according to the adaptation strategy, including injecting enhanced checks for all dynamic index accesses, only injecting checks for high-risk resources, and only injecting checks for dynamic resources. Adjust the format adaptation mode, prefer image view adaptation format, use temporary conversion buffer; Adapt the video memory allocation, adjust the allocation alignment method of placeholder resources according to the memory alignment requirements of the driver, and allocate placeholder resources to system memory and initialize them to zero value through memory mapping when GPU local memory is insufficient.
Citation Information
Patent Citations
Method and device for creating sandbox environment for plug-in operation and computing equipment
CN114816707A
Method for converting Vulkan ray tracing pipeline into calculation pipeline
CN116596738A
Method for automatically drawing OpenGL program by using Vulkan
CN121169663A
Graphics processing device and method
US20240177263A1
Cited By
Direct3D 12 descriptor compatible method based on address homologous mapping
CN121722440A
Direct3D 12 descriptor compatible method based on address homomorphism mapping
CN121722440B
Direct3D 12 resource management method based on virtual universal layout
CN121785805A
Direct3D 12 view implementation method based on LOD state dynamic injection
CN121785822A
Direct3D 12 depth migration semantic implementation method based on shader compensation
CN121833044A