A Direct3D memory model compatible method based on adaptive placeholder resource
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, improving execution efficiency and stability, and enabling high-performance compatible operation of Direct3D applications on the Vulkan platform.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 北京麟卓信息科技有限公司
- Filing Date
- 2026-01-19
- Publication Date
- 2026-04-10
AI Technical Summary
In GPU environments that do not support the VK_EXT_robustness2 extension, Direct3D applications suffer from compatibility issues such as 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 rendering anomalies.
An adaptive resource allocation method is adopted. This method involves creating dual sandboxes, allocating independent virtual address spaces, optimizing SPIR-V instructions, implementing resource mapping and binding, inserting inspection instructions, adapting format and version semantics, monitoring anomalies in real time and adjusting strategies, and building a GPU driver feature fingerprint library to achieve compatibility and stability.
In environments where the VK_EXT_robustness2 extension is not supported, the GPU execution efficiency of Direct3D applications is improved, memory overhead is reduced, pipeline compatibility and driver adaptation are enhanced, and the stability and performance of the rendering process are ensured.
Smart Images

Figure CN121542055B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of computer software development, and particularly relates to a Direct3D memory model compatible method based on adaptive placeholder resources. BACKGROUND
[0002] DXVK, as a key conversion layer from Direct3D (D3D) to Vulkan, its core functions rely on two core capabilities of the VK_EXT_robustness2 extension: one is to accurately reproduce the memory access semantics of D3D, including out-of-bound read returning zero value and out-of-bound write silently discarding, and the other is to natively support the null descriptor feature of D3D. Among them, the VK_EXT_robustness2 extension is an extension for enhancing memory access security and adapting D3D semantics.
[0003] However, in the GPU environment without supporting the extension, there are still many difficult problems in the compatibility of D3D applications, mainly including: boundary check problem, the existing way of inserting boundary check instructions globally will cause the number of shader instructions to increase by 30% to 50%, the execution efficiency of GPU will be significantly reduced, especially the frame rate of complex games will be reduced by 5% to 20%, and a large number of redundant checks will be generated due to the failure to distinguish the resource types, access scenarios and version differences of D3D; null descriptor simulation problem, the existing method needs to create a placeholder resource for each D3D resource format, type and sampling mode, which will increase the video memory overhead by more than 30%, and the format compatibility is poor, such as D3D special compression format and multi-sampling texture cannot be adapted, and the frequent creation and destruction of placeholder resources will also increase the CPU descriptor set update overhead; pipeline compatibility problem, the existing method does not consider the shader interface matching problem in the pipeline state object (PSO) creation stage, and after inserting the boundary check instruction, the PSO creation may fail, such as shader resource binding slot mismatch; driver adaptation problem, different GPU manufacturers and different driver versions have great differences in handling Vulkan undefined behaviors, and the existing scheme lacks a fine driver feature adaptation mechanism, resulting in frequent compatibility problems; cache management problem, the shader cache is not fully associated with the driver characteristics and the check template version, resulting in cache pollution after the driver updates or check logic adjustment, causing rendering abnormalities.
[0004] In summary, it is urgent to build a complete conversion process based on DXVK with consistent semantics, low performance loss, high compatibility and strong stability, to solve the compatibility running problem of DXVK without the VK_EXT_robustness2 extension. SUMMARY
[0005] Therefore, the application provides a Direct3D memory model compatible method based on adaptive placeholder resources, which realizes compatible running of a D3D application on a Vulkan supporting operating system platform without supporting a VK_EXT_robustness2 extension.
[0006] The application provides a Direct3D memory model compatible method based on adaptive placeholder resources, and specifically comprises the following steps:
[0007] When DXVK is started, a scene library of a metadata and an access scene containing basic attributes, access features, associated resources and a life cycle is established, the associated access scene is associated with D3D semantic requirements, check instruction templates are established for the access scene according to the D3D semantic requirements, and basic placeholder resources are created; two types of sandboxes are created, independent virtual address spaces and page tables are allocated, and real resources and placeholder resources are respectively stored; resource binding slot positions and auxiliary mappings of rendering pipeline stages to the metadata are established;
[0008] When a D3D application is started to create a D3D resource, DXVK parses a resource descriptor, initializes basic attributes of metadata thereof, maps the D3D resource into a Vulkan resource, binds a memory handle and a shader slot position of the metadata and the Vulkan resource, and allocates a sandbox to update a page table mapping; when the resource is updated, DXVK corrects the metadata, and for dynamic index access, the access features are updated; when the resource is bound, DXVK sets a binding slot position of the basic attributes to update the auxiliary mapping, and when a resource handle is empty, a placeholder resource ID of an associated resource is set as a default value; when the resource is destroyed and a resource reference count is zero, the life cycle is set and then destroyed;
[0009] DXVK compiles a D3D application shader, identifies a resource access instruction as a target instruction between generation of a SPIR-V instruction and optimization of the SPIR-V instruction; the metadata and the access scene are read from a binding slot position and a pipeline stage, a determined check instruction template is instantiated and added in front of the target instruction; when the placeholder resource ID is the default value, a corresponding basic placeholder resource is adapted as a placeholder resource of the D3D resource, and a corresponding sandbox is set as read-only; the placeholder resource and a general sampler are bound to a Vulkan descriptor set, and a pipeline state object is created;
[0010] DXVK intercepts a rendering instruction of the D3D application, transmits instruction parameters into a Vulkan core command to build a command buffer, submits the command buffer to a Vulkan queue, and triggers GPU to execute a rendering process to complete rendering.
[0011] Further, DXVK implements zero initialization on-demand allocation when a D3D resource is created, specifically: for a sandbox of a placeholder resource, a page fault interrupt is triggered when the sandbox is accessed for the first time, a physical page is allocated by a kernel and filled with zero values, and then marked as initialized; for a sandbox of a real resource, the sandbox is initialized to zero values when the sandbox is mapped for the first time.
[0012] Further, the metadata is stored by using double hash mapping, a primary mapping of Vulkan memory handle to the pointer of the metadata is established at the same time of establishing the auxiliary mapping, a shared lock which can be acquired by multiple threads at the same time is constructed to realize the read operation of the metadata, an exclusive lock which can be acquired by only a single thread at the same time is constructed to realize the write operation of the metadata, the auxiliary mapping is updated in the resource binding stage, and the mapping entry is deleted in the resource destroying stage.
[0013] Further, the check instruction template comprises a condition judgment instruction, a semantic adaptation instruction and an exception handling instruction, the condition judgment instruction comprises a Null Descriptor scene check instruction, and the processing process is to determine whether to execute or shield the target instruction according to the execution result of the condition judgment instruction.
[0014] Further, after the instantiation-determined check instruction template is determined, the instruction obtained by instantiating the check instruction template is recorded as a first check instruction, the first check instruction related to the target instruction which continuously accesses the same resource is extracted to the nearest common predecessor basic block, the semantic adaptation instructions in the first check instructions related to the target instructions which access multiple resources in the same scene are merged, the condition judgment instruction in the first check instruction of the target instruction with the effective execution result is deleted, and the first check instruction is deleted when the resource is a static resource and the access is non-dynamic index access.
[0015] Further, the way of adapting the corresponding basic placeholder resource to the placeholder resource of the D3D resource is as follows:
[0016] 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 used, 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 later;
[0017] Multi-sampling adaptation, the input is the sample number of the D3D resource and the D3D format, 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 initialized to zero and then added to the pooling management;
[0018] Version semantics adaptation, for D3D9 fixed function pipeline resources, use D3D9 special base texture; for D3D11 adaptation, create D3D format UAV view based on general buffer for typed UAV; depth buffer adaptation, use general depth buffer base placeholder resource for depth stencil resource, create target depth format view.
[0019] Further, for all placeholder resources of D3D application, create view pool for placeholder resources with the same format, sampling mode and purpose, realize view reuse; create temporary resource pool for dynamically created placeholder resources with special format or high sampling number, and destroy the placeholder resources not used within the set number of frames; record the used placeholder resources in each frame, which contain the same format, sampling mode and purpose in the same frame, reuse the same placeholder resource, and form frame-level reuse resources.
[0020] Further, the GPU executes the rendering process in the following way:
[0021] The vertex shader processes vertex data, and the pixel shader and the compute shader execute resource access logic; before each resource access instruction is executed, the injected instantiation check instruction template is executed to obtain the instruction, and the legality of access is judged according to the metadata; if it is legal, the real resource or the placeholder resource is read; if it is out-of-bound access, zero value or black color is returned as a substitute value according to D3D semantics, or the write operation is silently discarded; depth test and color blending are completed according to the configuration of the pipeline state object.
[0022] Further, the execution state of Vulkan is monitored in real time, and exceptions such as device loss and invalid memory access are captured, and the cause of the exception is located according to the out-of-bound counter and the kernel sandbox fault log of the metadata; the recovery strategy is triggered according to the type of the exception, including improving the resource check strength, recompiling the shader, rebuilding the descriptor set and the pipeline state object, and if it is a continuous exception, switching to a safe mode.
[0023] Further, when DXVK starts, the core characteristics of the GPU are collected and encoded as fingerprint information, and the fingerprint information of the mainstream driver 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, and the check strength is adjusted according to the adaptation strategy, including injecting enhanced checks for all dynamic index accesses, injecting checks only for high-risk resources, and injecting checks only for dynamic resources; adjust the format adaptation mode, prefer to adapt the format through the image view, use temporary conversion buffer; adapt the memory allocation, adjust the allocation alignment mode of the placeholder resource according to the memory alignment requirement of the driver, and allocate the placeholder resource to the system memory and initialize it to zero value through memory mapping when the local memory of the GPU is insufficient.
[0025] Beneficial effects:
[0026] The application establishes resource metadata, accesses a scene library, checks an instruction template and double sandbox when DXVK starts, DXVK describes various resources of the D3D application through the resource metadata after the D3D application starts, completes resource mapping and dynamic update of the metadata, and allocates the resources to corresponding sandboxes; DXVK compiles application shader code, identifies resource access instructions, matches access scenes and checks templates in combination with pipeline stages and binding slot position to query metadata, instantiates check instructions to be added in front of target instructions, simultaneously adds compatibility adaptation instructions to optimize SPIR-V instructions; for unbound resources, corresponding placeholder resources are generated and configured with permissions and states, the resources are bound to Vulkan descriptor sets to replace VK_NULL_HANDLE, shader interfaces and pipeline state parameters are adapted to create PSO; application rendering instructions are intercepted to parse parameters and build a command buffer, the command buffer is submitted to a Vulkan queue to trigger GPU to execute rendering, and finally complete complete conversion and adaptation of D3D rendering logic to Vulkan. BRIEF DESCRIPTION OF DRAWINGS
[0027] Figure 1 A flowchart of a Direct3D memory model compatibility method based on adaptive placeholder resources is provided. DETAILED DESCRIPTION
[0028] The application will be described in detail below with reference to the embodiments and the accompanying drawings.
[0029] The Direct3D memory model compatibility method based on adaptive placeholder resources provided by the application has the core idea that: resource metadata, access scene library, check instruction template and double sandbox are established when DXVK starts, DXVK describes various resources of the D3D application through the resource metadata after the D3D application starts, completes resource mapping and dynamic update of the metadata, and allocates the resources to corresponding sandboxes; DXVK compiles application shader code, identifies resource access instructions, matches access scenes and checks templates in combination with pipeline stages and binding slot position to query metadata, instantiates check instructions to be added in front of target instructions, simultaneously adds compatibility adaptation instructions to optimize SPIR-V instructions; for unbound resources, corresponding placeholder resources are generated and configured with permissions and states, the resources are bound to Vulkan descriptor sets to replace VK_NULL_HANDLE, shader interfaces and pipeline state parameters are adapted to create PSO; application rendering instructions are intercepted to parse parameters and build a command buffer, the command buffer is submitted to a Vulkan queue to trigger GPU to execute rendering, and finally complete complete conversion and adaptation of D3D rendering logic to Vulkan.
[0030] The Direct3D memory model compatibility method based on adaptive placeholder resources provided by the application has the core idea that: resource metadata, access scene library, check instruction template and double sandbox are established when DXVK starts, DXVK describes various resources of the D3D application through the resource metadata after the D3D application starts, completes resource mapping and dynamic update of the metadata, and allocates the resources to corresponding sandboxes; DXVK compiles application shader code, identifies resource access instructions, matches access scenes and checks templates in combination with pipeline stages and binding slot position to query metadata, instantiates check instructions to be added in front of target instructions, simultaneously adds compatibility adaptation instructions to optimize SPIR-V instructions; for unbound resources, corresponding placeholder resources are generated and configured with permissions and states, the resources are bound to Vulkan descriptor sets to replace VK_NULL_HANDLE, shader interfaces and pipeline state parameters are adapted to create PSO; application rendering instructions are intercepted to parse parameters and build a command buffer, the command buffer is submitted to a Vulkan queue to trigger GPU to execute rendering, and finally complete complete conversion and adaptation of D3D rendering logic to Vulkan. Figure 1As shown, specifically comprising the following steps:
[0031] Step 1, when DXVK starts, resource metadata containing basic attributes, access features, associated resources, life cycle and versioning extensions are established, the values of the attributes in the resource metadata are set, a scene library containing multiple resource access scenarios across D3D versions is established, the scene library realizes the association of the access scenario and the D3D semantic requirement through the attributes, and then the checking instruction template is established for each access scenario according to the D3D semantic requirement; the basic placeholder resource is created according to the high-frequency resource type of D3D, which is used to replace the VK_NULL_HANDLE that is not allowed to be bound in Vulkan, and provides a legal Vulkan resource carrier for the unbound resource of the D3D application; two independent sandboxes including a real resource sandbox and a placeholder resource sandbox are created, the page table permission of the real resource sandbox is read and write for storing the real resource of the D3D application, and the page table permission of the placeholder resource sandbox is read for storing the placeholder resource, the independent virtual address space and the page table are allocated to the sandbox, the sandbox ID is saved in the resource metadata, and the GPU access to the resource is prohibited to cross the sandbox; the auxiliary mapping of the slot of the resource bound shader and the resource metadata to the resource metadata is established.
[0032] Wherein, the basic attribute is the inherent attribute and format mapping relationship of the D3D resource, including the effective size, the D3D dimension, the D3D format, the corresponding Vulkan format, the use mark, the access type mark, the binding slot, the related D3D version, the multi-sampling resource mark and the multi-sampling sample number; the access feature is the dynamic behavior feature in the resource access process, including the dynamic index access mark, the historical maximum access offset, the out-of-bound trigger counter and the static resource mark; the associated resource is the association relationship between the D3D resource and the Vulkan resource, including the Vulkan buffer handle, the Vulkan image handle, the Vulkan memory handle, the placeholder resource ID and the sandbox ID; the life cycle is the use state of the resource, including the number of in-frame uses, the number of idle frames and the to-be-destroyed mark; the versioning extension is used for adapting the differences between different versions of D3D, and contains extensions for different versions, for example, the fixed-function pipeline resource mark, the returned color of the unbound resource, the typed UAV mark and the support atomic operation mark.
[0033] Further, the present application realizes zero initialization on-demand allocation when the resource is created, specifically: the physical page of the placeholder resource sandbox adopts the on-demand allocation strategy, triggers the page fault interrupt when accessed for the first time, and the kernel allocates the physical page and fills in the zero value after marking it as initialized; the dynamic resource of the real resource sandbox is initialized to zero when it is first mapped, to ensure that the out-of-bound read returns zero value.
[0034] Further, the resource metadata is stored by using double hash mapping, efficient query and multi-thread concurrent read and write of the resource metadata are realized, a primary mapping of Vulkan memory handle to resource metadata pointer is established, an auxiliary mapping with the specific slot of the bound shader of the resource and the rendering pipeline stage as the key and the resource metadata pointer as the value is established, a shared lock that can be acquired by multiple threads at the same time is established to realize the read operation of the resource metadata, an exclusive lock that can be acquired by only one thread at the same time is established to realize the write operation of the resource metadata, the auxiliary mapping is updated in the resource binding stage, and the mapping entry is deleted in the resource destruction stage.
[0035] In the present application, the scene library is established according to the value of the attribute in the resource metadata, and an example of the scene library is shown in Table 1.
[0036] Table 1: Scene library example table
[0037] Scene ID Scene Description Core metadata features D3D semantic requirements 1 D3D11 static buffer and static index reads D3D version 11, static resource marked as static resource, dynamic index access marked as non-dynamic index access Out of bounds read returns zero 2 D3D11 dynamic buffer and dynamic index reads D3D version 11, static resource marked as non-static resource, dynamic index access marked as dynamic index access Out of bounds read returns zero 3 D3D11 typed UAV and dynamic index writes D3D version 11, typed UAV marked as typed UAV, access type marked as write Out of bounds write silently discarded 4 D3D11 UAV atomic operations D3D version 11, atomic operations support marked as supported Out of bounds atomic operations have no effect 5 D3D9 fixed function pipeline texture sampling D3D version 9, fixed function pipeline resource marked as fixed function pipeline resource Unbound / out of bounds returns black 6 D3D9 dynamic texture and dynamic index reads D3D version 9, dynamic index access marked as dynamic index access Out of bounds read returns black 7 D3D10 multisample textures D3D version 10, multisample resource marked as multisample resource Out of bounds read returns zero (MSAA mode preserved) 8 D3D11 depth buffer reads D3D version 11, usage marked as depth stencil, access type marked as read Out of bounds read returns 0.0 (depth test passes) 9 D3D11 depth buffer writes D3D version 11, usage marked as depth stencil, access type marked as write Out of bounds write silently discarded 10 D3D10 static texture and static index sampling D3D version 10, static resource marked as static resource, dynamic index access marked as non-dynamic index access Out of bounds read returns zero 11 D3D11 untyped UAV writes D3D version 11, typed UAV marked as untyped UAV, access type marked as write Out of bounds write silently discarded 12 Unbound resource access (null descriptor) Placeholder resource ID is non-zero Return zero / black per D3D version
[0038] The present application establishes a check instruction template for each access scene according to the D3D semantic requirements in the scene library, the template includes condition judgment instructions, semantic adaptation instructions and exception handling instructions, and the generated SPIR-V memory access instruction is ensured to be completely consistent with the D3D semantics through the check, for example, the versioning check instruction template corresponding to scene 2 is as follows:
[0039] / / Metadata effective size (compile-time constant injection through metadata interface)
[0040] %effectiveSize = OpConstant %uint 4096 / / For example, the effective size is 4KB
[0041] %zero = OpConstantNull %float
[0042] / / Dynamic index acquisition
[0043] %index = OpLoad %uint %indexVar
[0044] / / Boundary judgment (index < effective size -> legal)
[0045] %valid = OpICompare %bool OpSLT %index %effectiveSize
[0046] / / If legal, load data, otherwise return zero value
[0047] %data = OpLoad %float %buffer %index
[0048] result = OpSelect %float %valid %data %zero
[0049] For the scene of multi-sampling texture, OpImageQuerySize is used in the version check instruction template to obtain the actual sampling dimension; for the scene of atomic operation, the branch jump is used in the version check instruction template to shield the execution of the atomic instruction, so as to ensure no effect when the boundary is crossed.
[0050] According to the high-frequency resource type of D3D, the application creates a basic placeholder resource, as shown in Table 2.
[0051] Table 2 Basic placeholder resource example table
[0052] Base resource type Specification parameters Initialization mode Adaptation scenarios Generic buffer Size is 64MB (covers D3D max UAV buffer + max constant buffer), alignment is 64 bytes Zero initialization (vkMapMemory + memset(0)) Null descriptor for all buffer types Generic single sample texture 1x1 pixels, 2D, 1 layer, 1 mipmap, format is VK_FORMAT_R8G8B8A8_UNORM vkCmdClearColorImage (RGBA(0,0,0,0)) Null descriptor for single sample texture Generic multisample texture 1x1 pixels, 2D, 1 layer, 1 mipmap, format is VK_FORMAT_R8G8B8A8_UNORM, number of samples is 8x (covers mainstream MSAA) vkCmdClearColorImage(RGBA(0,0,0,0)) Multisample texture's null descriptor D3D9 special purpose 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's null descriptor General depth buffer 1x1 pixel, 2D, 1 layer, 1 mipmap, format: VK_FORMAT_D32_FLOAT vkCmdClearDepthStencilImage(depth = 0.0, stencil = 0) Depth stencil resource's null descriptor General sampler Address mode: VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, filter mode: VK_FILTER_LINEAR, comparison mode: VK_COMPARE_OP_ALWAYS vkCreateSampler(global reuse) All unbound samplers' null descriptor
[0053] Step 2, after the D3D application is started, the resource metadata of the D3D application is described by DXVK, including buffer, texture, depth template and the like; when the D3D resource is created, the D3D resource descriptor is parsed by DXVK, the basic attributes of the resource metadata are initialized, the D3D resource is mapped as a Vulkan resource, the resource metadata is bound with the memory handle of the Vulkan resource and the slot of the shader, the sandbox ID is allocated according to the resource type, the memory is allocated to the corresponding sandbox, the page table mapping of the corresponding sandbox is updated; when the D3D resource is updated, the effective size in the resource basic attribute is dynamically corrected, the static resource flag is set, and the dynamic index access flag in the resource access feature is updated when the dynamic index access is detected; when the D3D resource is bound, the binding slot is parsed by DXVK, the binding slot in the resource basic attribute is set, the auxiliary mapping from the binding slot and the pipeline stage to the resource metadata is recorded, and when the resource handle is empty, the placeholder resource ID in the associated resource of the resource is set as the default ID; when the D3D resource is destroyed and the reference count of the D3D resource saved by DXVK is zero, the to-be-destroyed flag in the resource life cycle is set as to-be-destroyed, and the resource is added to the delayed destruction queue, the resource is deleted in the frame recycling stage to release the memory, and the corresponding memory sandbox resource is released synchronously, so as to avoid memory leakage.
[0054] Step 3, the shader code of the D3D application is compiled by DXVK, and after the corresponding Vulkan compatible SPIR-V instruction is generated, the SPIR-V instruction is optimized, the resource access instruction including buffer access, texture access and depth template access is identified by scanning the SPIR-V instruction, and the obtained resource access instruction is taken as the target instruction.
[0055] The binding slot of a rendering pipeline stage where the shader is located and a target instruction related resource is acquired, resource metadata of the resource is read according to the binding slot and the pipeline stage, an access scene is acquired from a scene library according to the attribute value in the resource metadata, a check instruction template is determined, the check instruction template is instantiated into a first check instruction, and the first check instruction is added before the target instruction as a front-end check and semantic adaptation layer of the target instruction.
[0056] Compatibility adaptation instructions are added between the first check instruction and the target instruction, GPU driver incompatible instructions are replaced by equivalent basic instruction combinations, GPU driver unsupported image format hardware conversion is replaced by software format conversion, and GPU driver unsupported multi-sampling texture implicit LOD sampling instructions are replaced by single-sampling explicit LOD sampling instructions.
[0057] The first check instruction includes a conditional judgment instruction, a semantic adaptation instruction and an exception handling instruction, the conditional judgment instruction includes a Null Descriptor scene check instruction, 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.
[0058] Further, the performance loss of the first check instruction is minimized through redundancy merging and instruction simplification, specifically:
[0059] When the same resource is continuously accessed, the first check instruction is extracted to the nearest common predecessor basic block; for access to multiple resources of the same scene, the semantic adaptation instructions in the first check instructions of different target instructions are merged; for the target instruction with a valid execution result of the first check instruction, the conditional judgment instruction in the first check instruction is deleted; for the target instruction with a static resource and non-dynamic index access, when the execution result of the first check instruction of the target instruction is valid, the first check instruction is deleted.
[0060] Step 4, DXVK identifies the D3D resource of the D3D application, obtains the resource metadata of the resource according to the pipeline stage and the binding slot, 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 the selected placeholder resource is obtained according to the resource metadata of the D3D 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 corresponding to the sandbox of the placeholder resource is set to write protection; the placeholder resource and the general sampler are bound to the descriptor set of Vulkan to replace the original VK_NULL_HANDLE, and for the placeholder resource of the unordered access view type, the write operation to it is shielded, and for the placeholder resource of the depth stencil type, the corresponding image layout state is configured according to the actual access purpose, and the type of the placeholder resource is verified to be consistent with the type declared in the descriptor layout, and if not, the descriptor layout is modified.
[0061] Further, the way of dynamically adapting the selected placeholder resource to the resource format, sampling mode and version semantics of the D3D resource in the application is:
[0062] Format adaptation, input is the D3D format, resource type and D3D version of the D3D resource, query the compatibility of the D3D resource format and the basic resource format, if compatible, use the view of the basic resource, if can be adapted through the view, create a view of the target format based on the basic resource, if data conversion is needed, check whether the driver supports format conversion, if supported, create an image view of the target format using the format conversion capability of the GPU hardware, if not supported, create a temporary conversion buffer, convert the zero value data of the basic resource to the target format and copy it to the temporary conversion buffer, and reuse the temporary resource later;
[0063] Multi-sampling adaptation, input is the sample number and 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, an image view corresponding to the sample number is created; if the target sample number is greater than the threshold, a temporary multi-sampling texture of the target sample number is dynamically created, and after zero initialization of the multi-sampling texture, it is added to the pooling management and reused next time;
[0064] Version semantic adaptation, for D3D9 fixed function pipeline resources, use D3D9 special basic texture, ensure that the unbound resource access returns black; for D3D11 adaptation, for typed UAV, create a target format UAV view based on a general buffer;
[0065] Depth buffer adaptation, for depth stencil resource, use general depth buffer basic resource to create a view of the target depth format, ensure that the out-of-bound read returns zero value.
[0066] 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.
[0067] 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.
[0068] 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.
[0069] Furthermore, the adaptation of pipeline state parameters, including depth template state, blend state, rasterization state, and atomic operations, can be completed, specifically as follows:
[0070] 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.
[0071] 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;
[0072] Rasterization state adaptation, for D3D9 fixed function pipeline resources, adjust rasterizationState.polygonMode to VK_POLYGON_MODE_FILL, cullMode to VK_CULL_MODE_BACK_BIT, reproduce the default rasterization behavior of D3D9.
[0073] Atomic operation adaptation, if the resource metadata is marked supportAtomicOps=true (typed UAV), enable the corresponding memory semantics in the depthStencilState or blendState of the PSO, ensure atomic operation compatibility.
[0074] Step 6, DXVK intercepts the rendering instruction of the D3D application, parses the instruction parameters, passes the instruction parameters into the Vulkan core command, inserts the memory barrier and rendering target clearing instruction, and completes the construction of the command buffer; the constructed command buffer is submitted to the Vulkan queue to trigger the GPU to execute the rendering process to complete the rendering.
[0075] Specifically, the process of GPU executing the rendering process to complete the rendering includes:
[0076] The vertex shader processes vertex data, and the pixel shader and the compute shader execute resource access logic; before each resource access instruction, the injected boundary check instruction is executed first, and the legality of access is judged according to the resource metadata, if it is a legal access, the real resource or the placeholder resource is read normally, if it is an out-of-bound access, zero value or black color is returned as a substitute value or the write operation is silently discarded according to the D3D semantics;
[0077] According to the rasterization, depth template, and mixing states configured by the pipeline state object, depth test, color mixing, and other operations are completed, wherein the state corresponding to the placeholder resource has been adapted;
[0078] When the GPU accesses the resource, the kernel controls address translation through an independent page table, and only allows access to the corresponding sandbox resource, avoiding cross-sandbox pollution; the write protection mechanism of the placeholder resource sandbox shields illegal writing, and triggers kernel zero value filling for an out-of-bound read that is not captured.
[0079] Further, in order to ensure the stability of rendering, the present application monitors the execution state of Vulkan in real time, captures device loss, invalid memory access and other exceptions, locates the cause of the exception according to the out-of-bound counter of the resource metadata and the kernel sandbox fault log; according to the type of the exception, a recovery strategy is triggered, including improving resource checking strength, recompiling the shader, rebuilding the descriptor set and the pipeline state object, and continuously switching to the safe mode to ensure that the rendering process is not interrupted.
[0080] Further, the application constructs a GPU driver feature fingerprint library to realize whole-process adaptive adjustment based on fingerprints, covering mainstream GPU manufacturers and driver versions, specifically including:
[0081] Step 1.1, collect the core features of the GPU when DXVK starts, ensure that the fingerprint can accurately represent the driving ability, and the specific information is shown in Table 3.
[0082] Table 3: Example of core features of GPU
[0083] Feature category Enumerated fields Enumerated interfaces / ways Base identity Vendor ID (vendorID), device ID (deviceID), driver version (driverVersion), Vulkan version (apiVersion) VkPhysicalDeviceProperties Format support Support for common D3D formats (sampled / written / converted), support for compressed formats, support for multisample formats vkGetPhysicalDeviceFormatProperties2 Instruction support SPIR-V core instruction support (OpIsValid / OpSelect / OpMux), extended instruction support vkGetPhysicalDeviceFeatures2, vkGetPhysicalDeviceShaderFeatures Memory properties Memory type (device-local memory / system memory), memory alignment requirement, maximum memory allocation size VkPhysicalDeviceMemoryProperties Robustness behavior Out-of-bound read behavior (return zero / random value), out-of-bound write behavior (silently discarded / memory corruption) Precompiled test shader execution (e.g. intentional out-of-bound read, detect return value) Descriptor support Maximum number of descriptor bindings, descriptor update frequency limit VkPhysicalDeviceDescriptorPoolProperties PSO compatibility Error behavior when shader interface does not match, multisample mode compatibility range Pre-created test PSO (different format / sampler combinations) Cache properties Shader cache support types, cache size limits VkPhysicalDevicePipelineCacheProperties
[0084] Step 1.2, encode the collected core features of the GPU into a 128-bit fingerprint, precompile the fingerprint of the mainstream driver and the adaptation strategy to form an internal fingerprint library;
[0085] Step 1.3, obtain the corresponding adaptation strategy through fingerprint matching, adjust the check intensity according to the adaptation strategy, including inserting enhanced checks for all dynamic index accesses, inserting checks only for high-risk resources, and inserting checks only for dynamic resources; adjust the format adaptation mode, preferentially adapt the format through the image view, use temporary conversion buffers, etc.; adapt the video memory allocation, adjust the allocation alignment mode of placeholder resources according to the memory alignment requirements of the driver, and allocate the placeholder resources to the system memory and initialize the zero value through memory mapping for the GPU with insufficient local memory of the device.
[0086] Embodiment:
[0087] This embodiment takes Linux system as an example to adopt a Direct3D memory model compatible method based on adaptive placeholder resources provided by the application, which realizes the compatible running of D3D application without VK_EXT_robustness2 extension on the basis of following the core conversion process of DXVK and making modifications, and the specific process includes:
[0088] The terms used in this embodiment include: resource metadata DxvkResourceMetadata; metadata management singleton class DxvkResourceMetadataManager for metadata registration, query, update and destruction, using double hash mapping storage to support thread safety concurrent read and write, providing getMetadataByMemoryHandle or updateEffectiveSize interfaces; boundary check injection Pass SpirvBoundaryCheckInjectionPass; placeholder resource management class DxvkDummyResourceFactory for creating, adapting, reusing and destroying placeholder resources; memory sandbox submodule vk_sandbox for creating real resource sandbox and placeholder resource sandbox; driver adaptation policy structure DxvkDriverAdaptPolicy containing check intensity, format adaptation mode, driver robustness dependency field, stored in the driver fingerprint library, used to dynamically adjust the adaptation logic according to the characteristics of the GPU driver; whole-process state consistency check module dxvk_resource_consistency_check, which performs lightweight checking in the frame recycling stage.
[0089] S1, D3D resource to Vulkan resource mapping stage, for each D3D resource, bind the full-dimensional metadata of the overlay basic attribute, access feature, version semantics, binding information and associated resource, deeply integrate with the existing resource management process of DXVK, ensure the real-time, accuracy and accessibility of metadata.
[0090] S1.1, full-dimensional metadata structure definition. In the core resource header file dxvk_resource.h of DXVK, add DxvkResourceMetadata structure, use fixed fields and versioned extension fields to ensure adaptation to all resource types from D3D9 to D3D11, the specific definition is as follows:
[0091] struct DxvkResourceMetadata {
[0092] / / 1. Basic identification field (all versions are universal)
[0093] VkDeviceSize effectiveSize; / / Resource effective size (buffer byte number / texture pixel total number)
[0094] D3D_RESOURCE_DIMENSION d3dDimension; / / D3D resource dimension (buffer / 1D / 2D / 3D / multi-sampling)
[0095] DXGI_FORMAT d3dFormat; / / D3D resource format (e.g. DXGI_FORMAT_R8G8B8A8_UNORM, D3DFMT_A8R8G8B8)
[0096] VkFormat vkFormat; / / Corresponding Vulkan format (e.g. VK_FORMAT_R8G8B8A8_UNORM)
[0097] DxvkResourceUsage usageFlags; / / Resource usage flags (SRV / UAV / render target / depth stencil / atomic operations)
[0098] uint32_t accessFlags; / / Access type flags (read / write / read-write)
[0099] uint32_t bindSlot; / / Resource bind slot (e.g. shader SRV slot 0-15)
[0100] D3D_VERSION d3dVersion; / / Associated D3D version (9 / 10 / 11) to adapt semantic differences
[0101] bool isMultisampled; / / Whether it's a multisampled resource (MSAA texture / depth buffer)
[0102] uint32_t sampleCount; / / Multisample count (e.g. 4x MSAA, 8x MSAA)
[0103] / / 2. Access feature fields (dynamically updated)
[0104] bool hasDynamicIndex; / / Whether there's dynamic index access (e.g. array indexing based on vertex IDs)
[0105] VkDeviceSize maxAccessOffset; / / Historical maximum access offset (optimization check range)
[0106] uint32_t outOfBoundsCount; / / Out-of-bounds trigger counter (adjust check intensity)
[0107] bool isStaticResource; / / Whether it's a static resource (e.g. D3D11_USAGE_IMMUTABLE)
[0108] / / 3. Associated resource fields (cross-module reference)
[0109] VkBuffer vkBuffer; / / Corresponding Vulkan buffer handle (buffer resource valid)
[0110] VkImage vkImage; / / Corresponding Vulkan image handle (texture resource valid)
[0111] VkDeviceMemory vkMemoryHandle; / / Corresponding Vulkan memory handle (metadata query index)
[0112] uint32_t dummyResourceId; / / Associated dummy resource ID (null descriptor simulation)
[0113] uint64_t sandboxId; / / Associated kernel memory sandbox ID (memory isolation)
[0114] / / 4. Lifecycle fields (recycle management)
[0115] uint32_t frameUsageCount; / / Frame usage count
[0116] uint32_t idleFrameCount; / / Idle frame count (recycle threshold: 10 frames)
[0117] bool isPendingDestruction; / / Pending destruction flag (delayed recycle flag)
[0118] / / 5. Versioned extension fields (adapt to D3D versions)
[0119] union {
[0120] struct D3D9Extension {
[0121] bool isFixedPipeline; / / Fixed pipeline resource flag (e.g., D3D9 vertex texture)
[0122] bool useBlackForUnbound; / / Unbound resource black return flag (D3D9 texture sampling semantics)
[0123] } d3d9;
[0124] struct D3D11Extension {
[0125] bool isTypedUAV; / / Whether it is a typed UAV (e.g. R32_UINT UAV)
[0126] bool supportAtomicOps; / / Whether it supports atomic operations (e.g. InterlockedAdd)
[0127] } d3d11;
[0128] } ext;
[0129] };
[0130] Meanwhile, a DxvkResourceMetadataManager singleton class is added, which uses a double hash mapping storage mechanism: the main mapping is std::unordered_map<VkDeviceMemory, DxvkResourceMetadata*>, which quickly queries the metadata through the Vulkan memory handle, with O (1) complexity; the auxiliary mapping is std::unordered_map<uint32_t, DxvkResourceMetadata*>, which is queried through the binding slot and pipeline stage, and is adapted to the resource association in the shader compilation stage; std::shared_mutex is used to realize read-write separation lock, supporting multi-thread concurrent reading and single-thread writing, to ensure the performance in high concurrency scenarios.
[0131] S1.2, metadata full life cycle synchronization mechanism. The key interfaces of D3D resource creation, update, binding and destruction in DXVK are modified to realize real-time synchronization of metadata and resource state, covering all resource operation scenarios of D3D 9-11.
[0132] S1.2.1, resource creation stage CreateBuffer / CreateTexture / CreateDepthStencilView interface. When DXVK receives the resource creation call of the D3D application, such as ID3D11Device::CreateBuffer, IDirect3DDevice9::CreateTexture, the D3D resource descriptor is parsed, including D3D11_BUFFER_DESC, D3DTEXTURE_DESC, D3D11_DEPTH_STENCIL_VIEW_DESC.
[0133] Initialize the d3dDimension, d3dFormat, usageFlags, isMultisampled, sampleCount fields; if it is a D3D9 resource, initialize the fixed function pipeline flag ext.d3d9.isFixedPipeline, unbound return black ext.d3d9.useBlackForUnbound; if it is a D3D11 resource, initialize the typed UAV flag ext.d3d11.isTypedUAV, atomic operation support ext.d3d11.supportAtomicOps; get the corresponding vkFormat through the dxvkMapFormat function of the format conversion module of DXVK, and call vkGetPhysicalDeviceFormatProperties2 to verify format compatibility; initialize effectiveSize, set the size of the static resource as declared, and set the size of the dynamic resource as 0 initially, which will be updated later through the Map interface; call DxvkResourceMetadataManager::registerMetadata to bind the metadata with the memory handle vkMemoryHandle and the binding slot bindSlot of the Vulkan resource, and allocate a unique sandboxId kernel sandbox association.
[0134] S1.2.2, resource update phase Map / Unmap / UpdateSubresource / UpdateSubresourceUP interface, when the D3D application calls Map to map the resource to the CPU memory, record the offset pOffset and the row pitch pRowPitch, calculate the actual write length when Unmap, take the larger value of the current write length and the historical maximum value to update the effectiveSize of the metadata; for UpdateSubresource / UpdateSubresourceUP calls, parse the update area pSrcBox or the source data pSrcData, and synchronize the correction of effectiveSize to ensure that the entire update range is covered; if the resource is a dynamic buffer such as D3D11_D3D11_BIND_CONSTANT_BUFFER+D3D11_USAGE_DYNAMIC of D3D11, mark isStaticResource as false; when the shader compilation phase detects dynamic index access, set hasDynamicIndex to true through the DxvkResourceMetadataManager::setDynamicIndexFlag interface by the compilation module.
[0135] S1.2.3, Resource binding stage VSSetShaderResources / PSSetShaderResources / CSSetUnorderedAccessViews interface, when the D3D application calls the resource binding interface, parse the binding slot, update the bindSlot field of the metadata; if the bound resource handle is NULL, mark dummyResourceId as the default ID of the placeholder resource pool, trigger the subsequent null descriptor simulation process; record the bound pipeline stage, including vertex shader, pixel shader and compute shader, update the auxiliary mapping.
[0136] S1.2.4, Resource destruction stage Release interface, when the reference count of D3D resource is zero, set isPendingDestruction as true, join the delayed destruction queue to avoid the resource being released in advance; frame recycling stage, call DxvkResourceMetadataManager::unregisterMetadata, remove the metadata entry in the double hash mapping, release the metadata memory; synchronize the kernel video memory sandbox module to release the isolated page table entry and physical memory corresponding to the resource, avoid memory leakage.
[0137] S1.3, Metadata high-availability access interface, add the following thread-safe interfaces in DxvkResourceMetadataManager, which are called by the compilation, descriptor management, PSO creation, pipeline execution module, covering the metadata access requirements throughout the process:
[0138] getMetadataByMemoryHandle(VkDeviceMemory memoryHandle): get metadata pointer by Vulkan memory handle and safe for concurrent read; getMetadataByBindSlot(uint32_t bindSlot, VkShaderStageFlagBits stage): get metadata by bind slot and pipeline stage for shader compilation; updateEffectiveSize(VkDeviceMemory memoryHandle, VkDeviceSize newSize): atomically update resource effective size; incrementOutOfBoundsCount(VkDeviceMemory memoryHandle): atomically increment out-of-bounds counter to trigger check intensity adjustment; getDummyResourceId(VkDeviceMemory memoryHandle): get associated dummy resource ID to simulate null descriptor; isD3D9FixedPipelineResource(VkDeviceMemory memoryHandle): judge whether it is a D3D9 fixed function pipeline resource to implement semantic adaptation; isMultisampledResource(VkDeviceMemory memoryHandle): judge whether it is a multisampled resource to implement placeholder resource adaptation; markPendingDestruction(VkDeviceMemory memoryHandle): mark resource to be destroyed to delay recycling.
[0139] S2, the HLSL to SPIR-V compilation stage is the core of simulating D3D memory access semantics. By modifying the HLSL-SPIR-V compilation pipeline of DXVK, inserting versioned and scenario-based boundary check instructions, and accurately matching the semantic differences of D3D 9-10-11, the performance loss is maximally reduced through instruction optimization.
[0140] S2.1, modification of the compilation pipeline and insertion of the check Pass.
[0141] The original compilation process of DXVK is HLSL syntax analysis, HLSL IR generation, SPIR-V instruction generation, SPIR-V optimization, and cache storage. The embodiment inserts a boundary check injection PassSpirvBoundaryCheckInjectionPass between SPIR-V instruction generation and SPIR-V optimization, and adds a check instruction optimization PassSpirvCheckOptimizationPass and a version compatibility adaptation Pass SpirvVersionCompatibilityPass after SPIR-V optimization. The specific process is as follows:
[0142] The compileShader function is modified, and the process is adjusted to be: 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. New modules are added to implement the core logic of the above three Passes, which are decoupled from the existing compilation modules for easy maintenance.
[0143] S2.2, resource access scene fine classification and versioned check template library, the core logic of SpirvBoundaryCheckInjectionPass is to identify all resource access instructions in the shader, combined with the D3D version, resource type and access characteristics of the metadata to classify the scene, match the corresponding versioned check template, and ensure semantic consistency.
[0144] S2.2.1, access instruction scanning and 12-scene classification, all instructions in the SPIR-V module are traversed, and resource access related instructions are filtered out, including: buffer access, read OpLoad, write OpStore, atomic operation OpAtomicAdd / OpAtomicCompareExchange; image access, sampling OpImageSampleImplicitLod / OpImageSampleExplicitLod, writing OpImageWrite, depth reference aggregation OpImageDrefGather; depth template access, depth value read OpLoad, depth value write OpStore; for each access instruction, call the getMetadataByBindSlot interface to query the metadata through the binding slot and the pipeline stage, and combine the metadata fields to subdivide the access scene into 12 categories, covering all core scenes of D3D 9-10-11, as shown in Table 4.
[0145] Table 4 Core Scene Information Table
[0146] Scene ID Scene description Core metadata features D3D semantics requirements 1 D3D11 Static Buffer + Static Index Read d3dVersion=11, isStaticResource=true, hasDynamicIndex=false Out-of-bounds read returns zero value 2 D3D11 Dynamic Buffer + Dynamic Index Read d3dVersion=11, isStaticResource=false, hasDynamicIndex=true Out-of-bounds read returns zero value 3 D3D11 Typed UAV + Dynamic Index Write d3dVersion=11, ext.d3d11.isTypedUAV=true, accessFlags = Write Out-of-bounds write silently discarded 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 returns black 6 D3D9 Dynamic Texture + Dynamic Index Read d3dVersion=9, hasDynamicIndex=true Out-of-bounds read returns black 7 D3D10 Multisampled Texture Sampling d3dVersion=10, isMultisampled=true Out-of-bounds read returns zero value (MSAA mode preserved) 8 D3D11 Depth Buffer Read d3dVersion=11, usageFlags = Depth Stencil, accessFlags = Read Out-of-bounds read returns 0.0 (Depth test passes) 9 D3D11 Depth Buffer Write d3dVersion=11, usageFlags = Depth Stencil, accessFlags = Write Out-of-bounds write silently discarded 10 D3D10 Static Texture + Static Index Sampling d3dVersion=10, isStaticResource=true, hasDynamicIndex=false Out-of-bounds read returns zero value 11 D3D11 Untyped UAV Write d3dVersion=11, ext.d3d11.isTypedUAV=false, accessFlags = Write Out-of-bounds write silently discarded 12 Unbound resource access (null descriptor) dummyResourceId!= 0 Return zero value / black by D3D version
[0147] 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:
[0148] The template for Scene 2 is:
[0149] / / Obtain the valid size from metadata; inject constants at compile time via the metadata interface.
[0150] %effectiveSize = OpConstant %uint 4096 / / Example: Effective size 4KB
[0151] %zero = OpConstantNull %float
[0152] / / Dynamic index retrieval
[0153] %index = OpLoad %uint %indexVar
[0154] / / Boundary checks
[0155] %valid = OpICompare %bool OpSLT %index %effectiveSize
[0156] / / Load data if valid, otherwise return zero.
[0157] %data = OpLoad %float %buffer %index
[0158] %result = OpSelect %float %valid %data %zero
[0159] The template for Scene 5 is:
[0160] / / Black constant, D3D9 unbounded and out-of-bounds sampling return black.
[0161] %black = OpConstantComposite %vec4 (OpConstant %float 0.0, OpConstant%float 0.0, OpConstant %float 0.0, OpConstant %float 1.0)
[0162] / / Texture validity check (valid if binding a placeholder resource)
[0163] %image = OpLoad %sampledImage %imageVar
[0164] %valid = OpIsValid %bool %image
[0165] / / Sample if valid, else return black
[0166] %coord = OpLoad %vec2 %coordVar
[0167] %sampledColor = OpImageSampleImplicitLod %vec4 %image %coord
[0168] %result = OpSelect %vec4 %valid %sampledColor %black
[0169] Scene 7 template is:
[0170] / / Zero constant, adapts to multisample formats
[0171] %zeroMsaa = OpConstantComposite %vec4 %float 0.0
[0172] / / Multisample texture valid dimension check
[0173] %image = OpLoad %sampledImage %imageVar
[0174] %coord = OpLoad %vec2 %coordVar
[0175] %imageExtent = OpImageQuerySize %uvec2 %image
[0176] %validX = OpICompare %bool OpSLT (OpConvertFToU %uint(OpCompositeExtract %float %coord 0)) (OpCompositeExtract %uint %imageExtent0)
[0177] %validY = OpICompare %bool OpSLT (OpConvertFToU %uint(OpCompositeExtract %float %coord 1)) (OpCompositeExtract %uint %imageExtent1)
[0178] %valid = OpLogicalAnd %bool %validX %validY
[0179] / / Legal if more than one sample, otherwise return zero value
[0180] %sampledColor = OpImageSampleImplicitLod %vec4 %image %coord
[0181] %result = OpSelect %vec4 %valid %sampledColor %zeroMsaa
[0182] Scene 4 template is:
[0183] / / Atomic operation has no effect if out of bounds
[0184] %effectiveSize = OpConstant %uint 65536
[0185] %index = OpLoad %uint %indexVar
[0186] %valid = OpICompare %bool OpSLT %index %effectiveSize
[0187] OpBranchConditional %valid %atomicBlock %endBlock
[0188] %atomicBlock = OpLabel
[0189] %oldValue = OpAtomicAdd %uint %uav %index %memoryScope %memorySemantics %addValue
[0190] OpBranch %endBlock
[0191] %endBlock = OpLabel
[0192] S2.2.3, check instruction injection and format and version adaptation, match the corresponding template according to the scene ID for each access instruction, instantiate the template through the Builder interface of SPIRV-Cross, insert it into the SPIR-V instruction stream immediately before the access instruction, format adaptation, format difference between D3D and Vulkan, such as D3DFMT_A8R8G8B8 of D3D9 and VK_FORMAT_B8G8R8A8_UNORM of Vulkan, insert OpImageConvert or OpVectorShuffle instructions after the check instruction to adjust the color channel order and data type, and ensure that the return value format is consistent; multi-sampling adaptation, for multi-sampling resources such as scene 7, check the actual sampling dimension in the template using OpImageQuerySize to avoid invalid judgment based on fixed dimension; atomic operation adaptation, for resources supporting atomic operations such as scene 4, shield atomic instruction execution through branch jump to ensure no effect when out of bounds; zero value precision adaptation, for floating point resources such as VK_FORMAT_R32G32B32_FLOAT, use OpConstantNull to ensure that the returned value is exactly zero; for integer type resources such as VK_FORMAT_R32_UINT, use OpConstant %uint 0 to return zero value to avoid precision deviation.
[0193] S2.3, check instruction optimization pass, the core goal of SpirvCheckOptimizationPass is to reduce the performance loss of check instructions to the minimum through redundancy merging, instruction simplification, and flow optimization, specifically:
[0194] Redundant check merging, continuous access to the same resource, such as array access in a loop and multiple texture sampling, extract the check instruction to the nearest common predecessor basic block such as the loop entry OpLabel, and only perform the judgment once, for example, 3 times of buffer[index] access in a loop is converted to insert %valid =OpICompare at the loop entry, and directly reuse %valid judgment in the loop; batch access to the same scene, such as static index reading of multiple static buffers in the same shader, merge format adaptation instructions such as one format conversion covering multiple accesses.
[0195] Check instruction simplification, static condition folding, checking instructions whose condition judgment result is constant, such as static index access, can be verified at compile time that the index is legal, and directly folded into core access instructions, deleting condition judgment and branch jump, for example, index = 5 and effectiveSize = 10 are converted to directly reserve OpLoad, delete %valid judgment and OpSelect; Instruction replacement optimization, for OpSelect instructions, if one branch is constant such as zero value, and the target type supports, then replace it with OpMux instruction, some GPUs have higher execution efficiency for OpMux; Invalid check deletion, for resources with isStaticResource = true and hasDynamicIndex = false, if all access indexes are within the effectiveSize range verified at compile time, then directly delete the check instruction.
[0196] Flow optimization, branch structure optimization, linear structure of check instructions and core access instructions are adjusted to conditional judgment and branch execution structure, only when out of bounds, zero value return is legal, and access is directly executed, and the optimization performance of branch prediction of GPU is utilized; Instruction scheduling optimization, OpConstant, OpConstantNull and other constant instructions in the check instruction are moved to the beginning of the module to avoid repeated generation, and OpImageQuerySize and other time-consuming instructions are scheduled in parallel with other instructions by using the instruction-level parallelism of GPU.
[0197] S2.4, version compatibility adaptation Pass SpirvVersionCompatibilityPass, for early GPU such as Vulkan1.0 level or early driver instruction support limitation, downgrading adaptation is performed to ensure compatibility of the compiled product.
[0198] Instruction degradation, if the driver does not support OpIsValid (Vulkan 1.0), replace it with placeholder resource validity flag loading, store the isValid field in the placeholder resource metadata, and judge it through OpLoad; Format degradation, if the driver does not support OpImageConvert of a certain format, adjust the channel order through OpVectorShuffle, OpConvertFToU and OpConvertUToF convert data types, and replace it with software format conversion; Function degradation, if the driver does not support OpImageSampleImplicitLod of multi-sampling texture, downgrade it to single-sampling sampling, specify lod = 0 through OpImageSampleExplicitLod, and cooperate with the multi-sampling simulation of the placeholder resource.
[0199] S2.5, Compile cache association management, modify the shader cache module of DXVK, optimize the cache key design, and avoid cache pollution and repeated compilation.
[0200] Cache key new fields:
[0201] extSupported (1 bit): Whether to support VK_EXT_robustness2;
[0202] checkTemplateVersion (8 bits): Check the template library version (cache invalidation when the template is updated);
[0203] driverFingerprint (64 bits): Driver characteristic fingerprint (cache invalidation when the driver is updated);
[0204] vulkanApiVersion (16 bits): Vulkan API version (adapt instruction support difference);
[0205] Cache partitioning, cache partitioning according to driver manufacturer and GPU architecture such as AMD Polaris, NVIDIA Turing, and Intel Xe, to avoid mixing of caches for different architectures; cache cleaning, new cache cleaning interface, when the driver fingerprint is updated or the template version is changed, automatically clean up the old cache entries of the corresponding partition.
[0206] S3, Descriptor set construction phase, through the placeholder resource factory of basic resource pre-creation, dynamic adaptation and pool reuse, replace the null descriptor support of VK_EXT_robustness2, ensure that the access behavior of D3D unbound resources is consistent with the original, and minimize the memory overhead and CPU descriptor update cost.
[0207] S3.1, Placeholder resource factory core, add the DxvkDummyResourceFactory class to the descriptor management module of DXVK, responsible for the creation, format adaptation, multi-sampling adaptation, pool reuse and destruction of placeholder resources, and the core is divided into three modules: basic placeholder resource pre-creation, dynamic adaptation layer and pool management.
[0208] S3.1.1, Basic placeholder resource pre-creation, reduce dynamic overhead through global reuse.
[0209] According to the high-frequency resource types of D3D 9 to 11, 6 types of basic placeholder resources are pre-created and stored in DxvkDummyResourcePool, as shown in Table 5.
[0210] Table 5 Basic resource information table
[0211] Base resource type Spec parameter Initialization mode Adaptation scenario Generic buffer Size = 64MB (covers D3D max UAV buffer + max constant buffer), Alignment = 64 bytes Zero initialization (vkMapMemory + memset (0)) Null descriptor for all buffer types General single-sampled texture 1x1 pixel, 2D, 1 layer, 1 mipmap, format = VK_FORMAT_R8G8B8A8_UNORM vkCmdClearColorImage (RGBA (0,0,0,0)) Null descriptor for single-sampled texture General multi-sampled texture 1x1 pixel, 2D, 1 layer, 1 mipmap, format = VK_FORMAT_R8G8B8A8_UNORM, number of samples = 8x (covers mainstream MSAA) vkCmdClearColorImage (RGBA (0,0,0,0)) Null descriptor for multi-sampled texture D3D9-specific texture 1x1 pixel, 2D, 1 layer, 1 mipmap, format = VK_FORMAT_B8G8R8A8_UNORM vkCmdClearColorImage (RGBA (0,0,0,1), i.e. black) Null descriptor for D3D9 fixed-function pipeline texture General depth buffer 1x1 pixel, 2D, 1 layer, 1 mipmap, format = VK_FORMAT_D32_FLOAT vkCmdClearDepthStencilImage (depth = 0.0, stencil = 0) Null descriptor for depth stencil resource General sampler Address mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, filter mode = VK_FILTER_LINEAR, comparison mode = VK_COMPARE_OP_ALWAYS vkCreateSampler (global reuse) Null descriptor for all unbound samplers
[0212] S3.1.2, dynamically adapt the layer, add DxvkDummyFormatAdapter class and DxvkDummyMsaaAdapter class, responsible for dynamically adapting the basic placeholder resource to the target resource format, sampling mode and version semantics required by the D3D application, the specific adaptation process is as follows:
[0213] Input target D3D format (d3dFormat), target resource type (buffer or texture), D3D version; format conversion judgment, call vkGetPhysicalDeviceFormatProperties2 to query the compatibility of target format and basic resource format, which can be divided into the following cases:
[0214] Directly compatible, such as DXGI_FORMAT_R8G8B8A8_UNORM of D3D11 is consistent with the basic texture format, then directly use the view VkBufferView or VkImageView of the basic resource; can be adapted through the view, such as DXGI_FORMAT_R32_UINT of D3D11 is compatible with the basic buffer format, then call vkCreateBufferView / vkCreateImageView to create a view of the target format based on the basic resource; data conversion is required, such as D3DFMT_A8R8G8B8 of D3D9 and basic texture format VK_FORMAT_B8G8R8A8_UNORM, then check whether the driver supports format conversion vkGetPhysicalDeviceFormatFeatures2 formatFeatures field, if supported, create an image view of the target format, use the format conversion capability of GPU hardware, and automatically convert zero value when accessing, if not supported, create a temporary conversion buffer, convert the zero value data of the basic resource to the target format and copy it to the temporary placeholder resource, and then reuse the temporary resource.
[0215] Multi-sampling adaptation, input target sample count sampleCount, target format d3dFormat; processing logic is, if the target sample count is not greater than the sample count of the basic multi-sampling texture 8x, call vkCreateImageView to create an image view corresponding to the sample count, such as target 4xMSAA, create a 4x view based on an 8xMSAA basic resource; otherwise, dynamically create a temporary multi-sampling texture of the target sample count, initialize to zero and add to the pool management, next time reuse; ensure that the sampleCount of the multi-sampling placeholder resource is consistent with the rendering target sample count of the D3D application, to avoid mismatch of multi-sampling mode when creating PSO.
[0216] Version semantics adaptation, D3D9 adaptation, for scene 5 corresponding to D3D9 fixed-function pipeline resources, use D3D9 special base texture, black initialization, ensure that the unbound resource access returns black; D3D11 adaptation, for scene 3 corresponding to typed UAV, create a target format UAV view based on a general buffer, set the range of VkDescriptorBufferInfo to 1 byte, and cooperate with the shader check instruction to shield the out-of-bound write; Depth buffer adaptation, for scenes 8 and 9 corresponding to depth stencil resources, use a general depth buffer base resource, create a view of the target depth format (such as VK_FORMAT_D24_UNORM_S8_UINT), and ensure that the out-of-bound read returns 0.0.
[0217] S3.1.3, Pooling management mechanism, view pooling for placeholder resource views VkBufferView and VkImageView of the same format, the same sampling mode, and the same purpose, maintains a view pool std::unordered_map<DummyViewKey, VkImageView>, DummyViewKey contains format, sampling number, and purpose fields, to avoid repeated creation of views; Temporary resource pooling: for dynamically created special format / high sampling number placeholder resources, maintain a temporary resource pool, record its idleFrameCount, and destroy it if it is not used for more than 5 frames, and release the video memory; Frame-level multiplexing, add a DxvkDummyResourceFrameTracker class to record the placeholder resources and views used in each frame, and multiplex the same view for the same DummyViewKey request in the same frame, reducing the number of descriptor set update times.
[0218] S3.2, null descriptor mapping and descriptor set construction, modify the updateDescriptorSet function of DXVK, add null descriptor mapping logic, and ensure that the descriptor set state is legal, that is, Vulkan does not allow binding VK_NULL_HANDLE:
[0219] Null resource identification and placeholder resource matching, when the resource handle passed by the D3D application is NULL, such as ID3D11DeviceContext: PSSetShaderResources ppShaderResourceViews contains nullptr, the null descriptor mapping process is triggered; according to the resource binding slot and pipeline stage query metadata, get d3dVersion, d3dFormat, isMultisampled, sampleCount and other information; call the DxvkDummyResourceFactory: getAdaptedResource interface, pass in the above information, get the adapted placeholder resource and view.
[0220] Descriptor set update and compatibility check, bind the adapted placeholder resource view VkBufferView and VkImageView to the Vulkan descriptor set with the general sampler, replace the original VK_NULL_HANDLE; for the UAV type placeholder resource, set the offset of VkDescriptorBufferInfo to 0 and the range to 1, cooperate with the shader check instruction to ensure that the write operation is shielded; for the depth stencil type placeholder resource, set the imageLayout of VkDescriptorImageInfo to VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL read or VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL write, ensure pipeline compatibility; add descriptor layout compatibility check, verify that the type of placeholder resource view such as VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE is consistent with the type declared in the descriptor layout, avoid PSO creation failure.
[0221] S3.3, placeholder resource life cycle management, basic resource life cycle, global resident only calls vkDestroyBuffer, vkDestroyImage and vkDestroySampler to destroy when DXVK exits; view life cycle, views in the view pool are destroyed when DXVK exits; frame-level reused views are destroyed when the frame is recycled, if the reference count is 1, indicating that only the current frame is used, then destroy; temporary resource life cycle, resources in the temporary resource pool, idleFrameCount is incremented after each frame ends, and if it exceeds 5 frames, it is destroyed, and the corresponding view and memory are released synchronously.
[0222] 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.
[0223] 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.
[0224] 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.
[0225] 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.
[0226] PSO cache association management, modify the PSO cache module of DXVK, add placeholder resource format, multi-sampling number and driver fingerprint fields in the cache key to ensure that the PSO cache does not conflict in different driver and null descriptor adaptation scenarios.
[0227] S4.2, Linux kernel level GPU memory isolation mechanism, modify the GPU memory management module of the Linux kernel to add a vk_sandbox submodule, provide independent memory isolation space for DXVK real resources and placeholder resources, and ensure that boundary access does not pollute other resources, as follows:
[0228] S4.2.1, sandbox creation and resource binding, when DXVK is initialized, call the newly added system call sys_vk_sandbox_create to create real resource sandbox REAL_RESOURCE_SANDBOX and placeholder resource sandbox DUMMY_RESOURCE_SANDBOX; the kernel allocates independent virtual address space and page table struct vm_area_struct for each sandbox, and binds the sandbox ID sandboxId to the sandboxId of the DXVK resource metadata; when a resource is created, its memory is allocated to the corresponding sandbox according to the resource type real resource or placeholder resource, and the sandbox's page table mapping is updated.
[0229] S4.2.2, memory access isolation and boundary processing, address translation isolation, when GPU accesses a resource, the kernel queries the corresponding page table through the sandbox ID, only allows access to the physical pages within the sandbox, and prohibits cross-sandbox access; if the shader check instruction is missed, causing real resource boundary access, the kernel triggers page table protection and returns zero value to fill zero value to 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 tries to write to the placeholder resource, the kernel triggers write protection fault, shielding the write operation, simulating the write discard semantics of D3D.
[0230] S4.2.3, zero initialization on-demand allocation, the physical pages of the placeholder resource sandbox use on-demand allocation strategy: trigger page fault when accessed for the first time, the kernel allocates physical pages and fills zero value through memset, and then marks it as initialized; the physical pages of the real resource sandbox are allocated when the resource is created, if it is a dynamic resource, initialize zero value when Map for the first time to ensure that the boundary read returns zero value.
[0231] S4.3, driver feature fingerprint library and fine adaptation, add a module to build a driver feature fingerprint library to realize adaptive adjustment based on fingerprints, covering mainstream GPU manufacturers and driver versions.
[0232] S4.3.1, Full-dimension collection of driver characteristics, when DXVK is initialized, call the Vulkan interface to collect the following 8 categories of core characteristics to ensure that the fingerprint can accurately represent the driver capability.
[0233] S4.3.2, Fingerprint encoding and fingerprint library construction.
[0234] Fingerprint encoding, the collected 8 categories of characteristics are encoded into a 128-bit fingerprint (uint128_t driverFingerprint), the encoding rule is composed of vendor ID (8 bits), device ID (16 bits), driver major version (8 bits) and driver minor version (8 bits), Vulkan version (16 bits), format support mask (32 bits) and instruction support mask (32 bits); Built-in fingerprint library, pre-compiled fingerprints and adaptation strategies of mainstream drivers are stored in dxvk_driver_fingerprint_db.h, for example:
[0235] static const DxvkDriverAdaptPolicy s_driverPolicies[] = {
[0236] / / NVIDIA 535.98 driver (Turing architecture)
[0237] { 0x10DE0TU128, {.checkIntensity = CHECK_INTENSITY_HIGH,.formatAdaptMode = FORMAT_ADAPT_TEMP_BUFFER,.relyOnDriverRobustness = false}},
[0238] / / AMD 22.10.3 driver (RDNA architecture)
[0239] { 0x10020RDNA128, {.checkIntensity = CHECK_INTENSITY_MEDIUM,.formatAdaptMode = FORMAT_ADAPT_VIEW,.relyOnDriverRobustness = true}},
[0240] / / Intel 31.0.101.4032 driver (Xe architecture)
[0241] { 0x80860Xe128, {.checkIntensity = CHECK_INTENSITY_MEDIUM,.formatAdaptMode = FORMAT_ADAPT_VIEW,.relyOnDriverRobustness = true}},
[0242] };
[0243] Dynamic update, support to add new driver fingerprint and adaptation strategy manually through DXVK configuration file dxvk.conf or environment variable DXVK_DRIVER_POLICY, without modifying the source code.
[0244] S4.3.3, fingerprint-based fine adaptation strategy, obtain the corresponding adaptation strategy DxvkDriverAdaptPolicy through fingerprint matching at initialization, and perform adaptive adjustment in the whole process:
[0245] Check intensity adjustment, high intensity CHECK_INTENSITY_HIGH, insert enhanced checks for all dynamic index access, such as NVIDIA driver, out-of-bound read returns random value; medium intensity CHECK_INTENSITY_MEDIUM, only insert checks for high-risk resources, such as AMD / Intel driver, out-of-bound read returns zero value; low intensity CHECK_INTENSITY_LOW, only insert checks for dynamic resources, suitable for drivers supporting old robustness extension;
[0246] Format adaptation mode adjustment, FORMAT_ADAPT_VIEW preferentially adapts the format through the image view, and is suitable for drivers supporting 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;
[0247] Driver robustness adjustment, relyOnDriverRobustness=true, turn off software checks for low-risk resources including static resources and static indexes, and rely on the robustness of the driver, such as AMD driver; relyOnDriverRobustness=false, forcibly turn on full software checks, such as NVIDIA driver;
[0248] Memory allocation adaptation, according to the memory alignment requirements of the driver, such as NVIDIA requires buffer alignment by 64 bytes, Intel alignment by 32 bytes, adjust the allocation alignment mode of placeholder resources; for GPUs with insufficient local memory, such as early integrated graphics cards, allocate placeholder resources to system memory VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, initialize zero value through memory mapping.
[0249] S4.4, pipeline execution exception handling, modify the DXVK error handling module handleDeviceLost function, add pipeline execution exception handling to ensure stability.
[0250] Exception capture, capture Vulkan's VK_ERROR_DEVICE_LOST device lost, VK_ERROR_MEMORY_MAP_FAILED memory mapping failed, VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS address access invalid and other errors;
[0251] Exception diagnosis, combined with the outOfBoundsCount of the metadata, the fault log of the kernel sandbox including the out-of-bound address and the sandbox ID, and the driver fingerprint, to determine whether it is an uncaptured out-of-bound access;
[0252] Recovery strategy, improve the checking strength of the corresponding resources, such as from medium strength to high strength; recompile the shader and enable enhanced check template; rebuild the descriptor set and PSO to ensure that the placeholder resources are correctly adapted; if the same exception is triggered for three times in a row, switch to safe mode, that is, full check and strict isolation of kernel sandbox; log output, record exception details including driver version, GPU model, out-of-bound resource information, for problem troubleshooting.
[0253] S5, frame resource recycling, update the state of metadata, placeholder resources and shader cache after the end of the frame to ensure efficient resource recycling and avoid leakage, redundant overhead and cache pollution.
[0254] S5.1, metadata state synchronization and recycling, add metadata synchronization logic in the endFrame function to cover the lifecycle management requirements.
[0255] Frame usage statistics, all resources used in the current frame are traversed by the DXVK resource tracking module, the DxvkResourceMetadataManager::updateFrameUsage interface is called, and the frameUsageCount is incremented; idle state update, for resources with frameUsageCount of 0, the idleFrameCount is incremented, and if the idleFrameCount exceeds 10 frames, it is marked for destruction;
[0256] Out-of-bound counter reset, reset the outOfBoundsCount of all resources to 0 to avoid excessive check intensity due to long-term accumulation; pending destruction resource processing, traverse the pending destruction resource list, call DxvkResourceMetadataManager::unregisterMetadata to release the metadata and associated kernel sandbox resources.
[0257] S5.2, placeholder resource and view recycling, frame-level view recycling, traverse the placeholder resource views in DxvkDummyResourceFrameTracker, decrement the reference count; if the reference count is 0, call vkDestroyBufferView / vkDestroyImageView to destroy the view; temporary resource recycling, traverse the temporary placeholder resource pool, for resources with idleFrameCount exceeding 5 frames, call vkDestroyBuffer / vkDestroyImage to destroy and release the video memory; sandbox memory recycling, notify the kernel vk_sandbox module to recycle unused physical pages in the placeholder resource sandbox, and allocate zero-initialized pages on demand.
[0258] S5.3, shader cache and PSO cache cleaning. Cache validity check, 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 not, mark it as invalid; invalid cache cleaning, perform invalid cache cleaning every 10 frames to release the disk space and memory occupied by the cache; hot cache reservation, mark the cache entries frequently used in the last 10 frames (hot cache) as reserved to avoid false cleaning.
[0259] 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).
[0260] Experimental testing has shown that this embodiment has the following characteristics:
[0261] 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.
[0262] To sum up, the above is only the preferred embodiment of the present application, and is not used to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
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 automatically drawing OpenGL program by using Vulkan
CN121169663A