Shader dynamic modification method, graphics rendering method and device, and related equipment

CN120687099BActive Publication Date: 2026-09-22MOORE THREADS TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510812077.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-17
Publication Date
2026-09-22
Estimated Expiration
2045-06-17

AI Technical Summary

Technical Problem

[0003]在实际应用中,往往通过获取着色器的源代码进行编辑修改,但对着色器的源代码进行编辑修改往往存在着色器的源代码难以获取,以及反复对着色器的源代码进行编辑修改的效率低等问题,因此,如何提高对着色器进行编辑修改的效率和灵活性是至关重要的

Benefits of technology

[0026]本公开所提供的实施例,能够在图形处理应用的运行过程中,对图形处理应用所调用的资源创建接口进行判断,在确定资源创建接口是用于创建管线状态对象的接口的情况下,进一步确定资源创建接口中的创建参数是否包含需要进行修改的第一着色器。若包含,则可以响应于对第一着色器的修改操作,确定修改后的第二着色器,从而实现在图形处理应用的运行过程中,对需要进行修改的着色器进行动态修改。在确定修改后的第二着色器后,根据第二着色器创建第二管线状态对象,以使得图形处理应用在后续过程中可以基于新创建的第二管线状态对象调用图形接口事件,并执行图形接口事件对应的图形渲染任务。通过在图形处理应用运行过程中,对图形处理应用的行为进行检测,以及时确定图形处理应用调用的接口是否与管线状态对象相关,并在管线状态对象的创建参数中存在需要进行修改的着色器的情况下,对着色器进行动态编辑和修改,提高了对着色器进行编辑修改的效率和灵活性。为保证修改后的着色器可用,还可以根据修改后的着色器创建新的管线状态对象,以使图形处理应用基于新的管线状态对象执行图形渲染任务。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120687099B_ABST
    Figure CN120687099B_ABST
Patent Text Reader

Abstract

The present disclosure provides a shader dynamic modification method, a graphics rendering method and device, and related equipment. The method comprises: in the case that a graphics processing application calls a resource creation interface and the resource creation interface is used to create a pipeline state object, obtaining a creation parameter in the resource creation interface, wherein the creation parameter comprises a plurality of shaders, and the plurality of shaders are represented in the form of a first intermediate language code; in the case that there is a first shader to be modified in the creation parameter, determining a second shader modified in response to a modification operation on the first shader; and creating a second pipeline state object according to the second shader, wherein the second pipeline state object is used for the graphics processing application to call a graphics interface event, and perform a graphics rendering task of the graphics interface event. The embodiments of the present disclosure can realize dynamic modification of the shader, and improve the efficiency and flexibility of modifying the shader.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to a method for dynamically modifying shaders, a graphics rendering method and apparatus, a system for dynamically modifying shaders, electronic devices, computer-readable storage media, and computer program products. Background Technology

[0002] In modern computer graphics, shaders need to be compiled multiple times to run on a graphics processing unit (GPU) and be translated into a machine-executable language. With the development of computer technology and the increasing demands of users, developers need to optimize the rendering behavior of applications or debug shaders, which usually requires editing and modifying the shaders.

[0003] In practical applications, the source code of the shader is often obtained and edited. However, editing the source code of the shader often presents problems such as difficulty in obtaining the source code and low efficiency of repeatedly editing the source code. Therefore, it is crucial to improve the efficiency and flexibility of editing and modifying shaders. Summary of the Invention

[0004] This disclosure provides a method for dynamically modifying shaders, a method and apparatus for graphics rendering, a system for dynamically modifying shaders, an electronic device, a computer-readable storage medium, and a computer program product.

[0005] Firstly, this disclosure provides a method for dynamically modifying shaders, including:

[0006] When it is detected that a graphics processing application calls a resource creation interface, and the resource creation interface is used to create a pipeline state object, the creation parameters in the resource creation interface are obtained, wherein the creation parameters include multiple shaders, and the multiple shaders are represented in the form of a first intermediate language code;

[0007] If a first shader to be modified exists in the creation parameters, a modified second shader is determined in response to the modification operation on the first shader;

[0008] A second pipeline state object is created based on the second shader, wherein the second pipeline state object is used by the graphics processing application to invoke a graphics interface event and execute the graphics rendering task of the graphics interface event.

[0009] Secondly, this disclosure provides a graphics rendering method, including:

[0010] In response to a graphics rendering command, obtain the second pipeline state object and the root signature corresponding to the second pipeline state object, wherein the second pipeline state object is created based on the above-described shader dynamic modification method;

[0011] Based on the second pipeline state object and the root signature corresponding to the second pipeline state object, the graphics interface event corresponding to the second pipeline state object is invoked, wherein the graphics interface event is used to render and generate the target graphic corresponding to the graphics rendering instruction.

[0012] Thirdly, this disclosure provides a shader dynamic modification system, including: a graphics processing application and a hook control layer;

[0013] The graphics processing application is configured to: receive graphics rendering instructions from a graphics rendering task, and invoke a resource creation interface in response to the graphics rendering instructions;

[0014] The hook control layer is configured to: when it detects that the graphics processing application calls the resource creation interface, and the resource creation interface is used to create a pipeline state object, obtain creation parameters from the resource creation interface, wherein the creation parameters include multiple shaders, and the multiple shaders are represented in the form of a first intermediate language code; if there is a first shader to be modified in the creation parameters, in response to the modification operation of the first shader, determine a modified second shader; and create a second pipeline state object based on the second shader.

[0015] The graphics processing application is also used to: call the graphics interface event corresponding to the second pipeline state object based on the second pipeline state object, and execute the graphics rendering task of the graphics interface event.

[0016] Fourthly, this disclosure provides a shader dynamic modification apparatus, comprising:

[0017] The detection module is configured to, when it detects that a graphics processing application calls a resource creation interface and the resource creation interface is used to create a pipeline state object, obtain creation parameters in the resource creation interface, wherein the creation parameters include multiple shaders and the multiple shaders are represented in the form of a first intermediate language code;

[0018] The response module is configured to determine a modified second shader in response to a modification operation on the first shader if a first shader to be modified exists in the creation parameters.

[0019] A creation module is configured to create a second pipeline state object based on the second shader, wherein the second pipeline state object is used by the graphics processing application to invoke a graphics interface event and execute the graphics rendering task of the graphics interface event.

[0020] Fifthly, this disclosure provides a graphics rendering apparatus, comprising:

[0021] The acquisition module is configured to, in response to a graphics rendering instruction, acquire a second pipeline state object and the root signature corresponding to the second pipeline state object, wherein the second pipeline state object is created based on the aforementioned shader dynamic modification method;

[0022] The calling module is configured to invoke the graphics interface event corresponding to the second pipeline state object based on the second pipeline state object and the root signature corresponding to the second pipeline state object, wherein the graphics interface event is used to render and generate the target graphics corresponding to the graphics rendering instruction.

[0023] In a sixth aspect, this disclosure provides an electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores one or more computer programs executable by the at least one processor, the one or more computer programs being executed by the at least one processor to enable the at least one processor to perform the aforementioned shader dynamic modification method or graphics rendering method.

[0024] In a seventh aspect, this disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the above-described shader dynamic modification method or graphics rendering method.

[0025] Eighthly, this disclosure provides a computer program product including computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code, wherein when the computer-readable code is run in a processor of an electronic device, the processor in the electronic device executes the above-described shader dynamic modification method or graphics rendering method.

[0026] The embodiments provided in this disclosure can determine the resource creation interface called by the graphics processing application during its operation. If the resource creation interface is determined to be an interface used to create pipeline state objects, it can further determine whether the creation parameters in the resource creation interface contain a first shader that needs to be modified. If so, a modified second shader can be determined in response to the modification operation of the first shader, thereby enabling dynamic modification of the shader that needs to be modified during the operation of the graphics processing application. After determining the modified second shader, a second pipeline state object is created based on the second shader, so that the graphics processing application can call graphics interface events based on the newly created second pipeline state object in subsequent processes and execute the graphics rendering tasks corresponding to the graphics interface events. By detecting the behavior of the graphics processing application during its operation, and timely determining whether the interface called by the graphics processing application is related to the pipeline state object, and dynamically editing and modifying the shader when the creation parameters of the pipeline state object contain a shader that needs to be modified, the efficiency and flexibility of editing and modifying the shader are improved. To ensure the modified shader is usable, a new pipeline state object can be created based on the modified shader, allowing the graphics application to perform graphics rendering tasks based on the new pipeline state object.

[0027] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0028] The accompanying drawings are provided to further illustrate the present disclosure and form part of the specification. They are used together with the embodiments of the present disclosure to explain the disclosure and do not constitute a limitation thereof. The above and other features and advantages will become more apparent to those skilled in the art from the detailed description of exemplary embodiments with reference to the accompanying drawings, in which:

[0029] Figure 1 A flowchart of a method for dynamically modifying a shader provided in this embodiment of the disclosure;

[0030] Figure 2 A flowchart for creating a second pipeline state object is provided as an embodiment of this disclosure;

[0031] Figure 3 A flowchart of an event invoking a graphical interface is provided as an embodiment of this disclosure;

[0032] Figure 4 A flowchart illustrating a method for dynamically modifying shaders provided in this embodiment of the disclosure;

[0033] Figure 5 A flowchart of a graphics rendering method provided in an embodiment of this disclosure;

[0034] Figure 6 An application flowchart of a shader dynamic modification system provided in this embodiment of the disclosure;

[0035] Figure 7 A block diagram of a shader dynamic modification apparatus provided in an embodiment of this disclosure;

[0036] Figure 8 A block diagram of a graphics rendering apparatus provided in an embodiment of this disclosure;

[0037] Figure 9 This is a block diagram of an electronic device provided in an embodiment of the present disclosure. Detailed Implementation

[0038] To enable those skilled in the art to better understand the technical solutions of this disclosure, exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments of this disclosure to aid understanding. These should be considered merely exemplary. Therefore, those skilled in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0039] Where there is no conflict, the various embodiments of this disclosure and the features thereof in the embodiments may be combined with each other.

[0040] As used herein, the term “and / or” includes any and all combinations of one or more related enumerated entries.

[0041] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit this disclosure. As used herein, the singular forms “a” and “the” are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will also be understood that when the terms “comprising” and / or “made of” are used in this specification, the presence of the stated feature, integral, step, operation, element, and / or component is specified, but the presence or addition of one or more other features, integrals, steps, operations, elements, components, and / or groups thereof is not excluded. Words such as “connected” or “linked” are not limited to physical or mechanical connections but can include electrical connections, whether direct or indirect.

[0042] Unless otherwise specified, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and this disclosure, and will not be interpreted as having an idealized or overly formal meaning, unless expressly so defined herein.

[0043] In DirectX 12 (DX12) applications, because HLSL (High-Level Shader Language) is developed using a high-level language, the HLSL code is highly readable, and it is relatively easy to directly edit and modify HLSL and then compile and replace it. However, it is difficult to obtain the HLSL source code, which results in poor versatility of modifying shaders by editing HLSL.

[0044] Comparatively, in DX12 applications, DXIL (DirectX Intermediate Language) code, which is intermediate code optimized by the front-end compiler, is relatively easy to obtain. Therefore, editing DXIL code to modify shaders is also relatively easy and convenient. However, in current practical applications, editing DXIL code is often achieved through static editing. Static editing requires directly modifying the DXIL source code using DXIL syntax and then replacing the original DXIL file. Every time there is DXIL code that needs to be modified, the DXIL file must be edited again and then replaced. This results in low efficiency and poor flexibility in modifying shaders.

[0045] Based on this, the present disclosure provides a shader dynamic modification method, a graphics rendering method, a shader dynamic modification apparatus, a graphics rendering apparatus, a shader dynamic modification system, an electronic device, a computer-readable storage medium, and a computer program product, which will be described in detail in the following embodiments.

[0046] The shader dynamic modification method or graphics rendering method according to embodiments of this disclosure can be executed by electronic devices such as terminal devices or servers. The terminal device can be an in-vehicle device, user equipment (UE), mobile device, user terminal, terminal, cellular phone, cordless phone, personal digital assistant (PDA), handheld device, computing device, in-vehicle device, wearable device, etc. The method can be implemented by a processor calling computer-readable program instructions stored in memory. Alternatively, the method can be executed by a server.

[0047] See Figure 1 , Figure 1A flowchart of a method for dynamically modifying a shader provided in this embodiment of the disclosure specifically includes the following steps:

[0048] Step 102: If it is detected that a graphics processing application calls the resource creation interface, and the resource creation interface is used to create a pipeline state object, obtain the creation parameters in the resource creation interface.

[0049] In practical applications, the process of writing and executing shaders on the GPU in graphics processing applications (such as DX12 applications) is roughly as follows: shaders are written in HLSL, then compiled into intermediate language code (DXIL) by a front-end compiler, and finally processed and compiled into machine-executable language by a compiler in the User Mode Driver (UMD). Since obtaining HLSL source code is difficult, while obtaining DXIL code is relatively easy, the dynamic shader modification method disclosed herein achieves dynamic shader modification by obtaining the DXIL code from the graphics processing application and dynamically modifying the DXIL code during the application's runtime.

[0050] Specifically, the graphics processing application can be a DX12 application or other types of graphics processing applications; this disclosure does not limit the specific type of graphics processing application. The resource creation interface refers to the interface used in the graphics processing application to create resources. The resource creation interface includes interfaces for creating pipeline state objects, as well as interfaces for creating other resources. The pipeline state object, or PSO (Pipeline State Object), encapsulates all state information related to the rendering pipeline, including shaders, rasterization settings, blending modes, depth / stencil tests, etc.

[0051] Specifically, the dynamic shader modification method provided in this disclosure is applied to the Hook Layer. During the operation of the graphics processing application, the Hook Layer monitors the application's behavior in real time. When it detects that the graphics processing application is calling a resource creation interface, the resource creation interface is intercepted through the resource management part of the Hook Layer. Since the shader data used for the rendering pipeline is included in the creation parameters of the pipeline state object, it is necessary to determine whether the intercepted resource creation interface is used to create the pipeline state object, so as to facilitate subsequent shader modifications.

[0052] This embodiment of the disclosure implements the insertion of a hook layer in the front end of a graphics processing application. During the operation of the graphics processing application, the hook layer intercepts the resource creation interface called by the graphics processing application to determine whether the intercepted resource creation interface is used to create a pipeline state object, thereby improving the efficiency of modifying shaders in subsequent processes.

[0053] Furthermore, after determining that the intercepted resource creation interface is used to create pipeline state objects, the creation parameters in the resource creation interface are obtained to determine whether there are any shaders in the creation parameters that need to be modified.

[0054] The creation parameters are used to create the first pipeline state object. These parameters include multiple shaders, which are shaders at different stages, such as vertex shaders, pixel shaders, and geometry shaders. In practical applications, developers have different optimization needs for the rendering behavior of graphics processing applications, which leads to different needs for editing and modifying shaders. For example, if a developer needs to modify the position or geometry of an object, they will need to modify the vertex position coordinates of the vertex shader.

[0055] Based on this, after obtaining the creation parameters from the resource creation interface, it is necessary to determine whether there are any shaders that need to be modified among the multiple shaders in the creation parameters.

[0056] In one specific embodiment provided in this disclosure, after obtaining the creation parameters from the resource creation interface, the method further includes:

[0057] Based on the shader data of the multiple shaders, generate shader identifiers for the multiple shaders respectively;

[0058] In the case where a first shader to be modified exists in the creation parameters, including:

[0059] If the shader identifier of the first shader exists among multiple shader identifiers, it is determined that the first shader exists in the creation parameters.

[0060] Shader data refers to the data related to the shader, such as the shader's source code. The shader identifier is a unique identifier for each shader, used to distinguish different shaders. The shader identifier can be a hash value of the shader or other data used to identify the shader. The shader identifier can be generated from the shader's shader data; for example, a hash value can be generated from the shader's source code using a hash function. The first shader refers to the shader that needs to be dynamically modified.

[0061] Specifically, after obtaining the creation parameters from the resource creation interface, based on the shader data of multiple shaders in the creation parameters, shader identifiers for multiple shaders are generated respectively. It is then determined whether the shader identifier of the first shader exists among the multiple shader identifiers. If it does, it is determined that the first shader exists in the creation parameters.

[0062] This embodiment of the disclosure implements a method that, after obtaining the creation parameters in the resource creation interface, determines whether there is a first shader that needs to be modified in the creation parameters by judging whether there is a shader identifier of a first shader that needs to be modified among the shader identifiers of multiple shaders, so as to make corresponding modifications to the first shader in subsequent processes.

[0063] Step 104: If a first shader to be modified exists in the creation parameters, in response to the modification operation on the first shader, determine the modified second shader.

[0064] After determining that there is a first shader in the creation parameters that needs to be modified, the hook control layer can display the shader data of the first shader to the developer so that the developer can edit and modify the shader data of the first shader; the hook control layer can also obtain the developer's modification requirements and edit and modify the shader data of the first shader according to the modification requirements, which can be determined according to the actual application situation.

[0065] In practical applications, the LLVM (Low Level Virtual Machine) compilation framework can be used to modify the first shader. The specific implementation method is as follows:

[0066] In one specific embodiment provided in this disclosure, the method further includes:

[0067] Call the dynamic editing interface to convert the first intermediate language code of the first shader into the second intermediate language code;

[0068] In response to a modification operation on the first shader, determining a modified second shader includes:

[0069] In response to the modification operation on the second intermediate language code, the modified third intermediate language code is obtained;

[0070] The dynamic editing interface is called to convert the third intermediate language code into the fourth intermediate language code, thereby obtaining the second shader corresponding to the fourth intermediate language code, wherein the first intermediate language code and the fourth intermediate language code are of the same type.

[0071] The dynamic editing interface specifically refers to the LLVM shader dynamic editing interface. LLVM supports compilation and optimization of multiple programming languages, enabling the generation of efficient machine code on different hardware platforms. The first intermediate language code refers to the DXIL code of the first shader; the second intermediate language code refers to the first shader code in LLVM IR form; LLVMIR (LLVM Intermediate Representation) is the LLVM intermediate representation, representing the program code in the intermediate stage of the LLVM compilation framework during the compilation process. It is independent of any hardware or operating system and can be used on various platforms. The third intermediate language code refers to the first shader code in modified LLVM IR form; the fourth intermediate language code refers to the DXIL code of the modified first shader. The second shader is the shader obtained by modifying the first shader.

[0072] Specifically, after determining that there is a first shader in the creation parameters that needs to be modified, the LLVM shader dynamic editing interface is called to convert the first intermediate language code (i.e., DXIL code) of the first shader into the second intermediate language code (i.e., LLVM IR). In response to the developer's modification operation on the second intermediate language code, the modified third intermediate language code (i.e., the modified LLVM IR) can be obtained. Then, the LLVM shader dynamic editing interface is called again to convert the third intermediate language code into the fourth intermediate language code (i.e., the modified DXIL code). Thus, the second shader corresponding to the fourth intermediate language code can be obtained.

[0073] The embodiments provided in this disclosure can call a dynamic editing interface to perform a formal transformation on the code of the shader that needs to be modified, so that developers can dynamically edit the shader that needs to be modified according to their editing needs to obtain a modified second shader.

[0074] Furthermore, after modifying the first shader and obtaining the fourth intermediate language code, it is necessary to perform a validity check on the fourth intermediate language code to ensure that it conforms to the operating specifications and can run successfully in graphics processing applications.

[0075] Based on this, in a specific embodiment provided in this disclosure, after calling the dynamic editing interface to convert the third intermediate language code into the fourth intermediate language code, the method further includes:

[0076] Perform a validity check on the fourth intermediate language code;

[0077] If the validity check of the fourth intermediate language code passes, the second shader corresponding to the fourth intermediate language code is obtained.

[0078] The validity checks include, but are not limited to, syntax checks and logic checks. Specifically, the converted fourth intermediate language code undergoes syntax and logic checks for validity. For example, syntax checks can detect missing symbols or misspelled variable names, while logic checks can verify that the fourth intermediate language code performs the expected function (e.g., whether the loop count meets expectations). If the validity checks of the fourth intermediate language code pass, the corresponding second shader can be obtained; if the validity checks fail, the fourth intermediate language code needs to be modified until it passes the validity checks.

[0079] By performing a validity check on the modified fourth intermediate language code, the validity of the second shader corresponding to the fourth intermediate language code is ensured, so that the second shader can run successfully in the graphics processing application in subsequent processes.

[0080] Furthermore, since the root signature defines how the shader accesses resources during runtime, after obtaining the second shader corresponding to the fourth intermediate language code, it is also necessary to determine whether the parameters used to create the root signature in the shader have been modified. If modified, the root signature needs to be recreated based on the modified parameters to redefine how the second shader accesses the required resources during runtime; if not modified, the original root signature can continue to be used.

[0081] Therefore, in one specific embodiment provided in this disclosure, after determining the modified second shader, the method further includes:

[0082] Obtain a first parameter of the first shader and a second parameter of the second shader, wherein the first parameter includes resources required for the first shader to run, and the second parameter includes resources required for the second shader to run;

[0083] If the first parameter is different from the second parameter, a new root signature corresponding to the second pipeline state object is created based on the second parameter. The new root signature is used by the graphics processing application to call the graphics interface event based on the second pipeline state object and the new root signature.

[0084] The first parameter refers to the Signature parameter in the first shader, which includes the resources required for the first shader to run. The second parameter refers to the Signature parameter in the second shader, which also includes the resources required for the second shader to run. In practical applications, the Signature parameter can specifically include parameters such as Sampler, texture, RWBuffer, and cbuffer. The Sampler parameter defines the texture sampling method; the texture parameter provides image data or other types of datasets (such as normal maps, height maps, etc.) used in the rendering process; textures can be one-dimensional, two-dimensional, three-dimensional, or cube maps, etc.; the RWBuffer parameter allows the types of resources that can be read and written in the shader program; the cbuffer parameter is used to store various constant data required by the shader, such as transformation matrices, material properties, lighting parameters, etc. The root signature, or RootSignature, defines how the shader accesses resources (constant buffer, texture, sampler, etc.).

[0085] Specifically, after determining the modified second shader, it is necessary to determine whether the Signature parameter in the shader has been modified during this dynamic modification. If the shader's Signature parameter has not been modified (i.e., the first parameter of the first shader is the same as the second parameter of the second shader), then there is no need to create a new root signature; if the shader's Signature parameter has been modified (i.e., the first parameter of the first shader is different from the second parameter of the second shader), then a new root signature needs to be created based on the modified Signature parameter (i.e., the second parameter), and the new root signature is stored in the resource management part of the hook control layer, so that the graphics processing application can call the corresponding graphics interface event to perform graphics rendering tasks based on the new root signature in subsequent processes.

[0086] The embodiments provided in this disclosure, after determining that there is a first shader in the creation parameters that needs to be modified, can call the dynamic editing interface to convert the code form of the first shader, so that developers can dynamically edit and modify the first shader according to their editing needs, thereby improving the flexibility of dynamically modifying the first shader; after obtaining the modified fourth intermediate language code, the legality of the fourth intermediate language code is checked so that the second shader corresponding to the fourth intermediate language code can run successfully in the graphics processing application; and further, by determining whether the Signature parameter has been modified, it is determined whether a new root signature needs to be created, thereby further improving the usability of the second shader.

[0087] Step 106: Create a second pipeline state object based on the second shader, wherein the second pipeline state object is used by the graphics processing application to call the graphics interface event and execute the graphics rendering task of the graphics interface event.

[0088] Since the first shader has been modified, a new pipeline state object, namely the second pipeline state object, needs to be created based on the modified second shader. The second pipeline state object is then stored in the resource management section of the hook control layer for use by the graphics processing application when calling graphics interface events.

[0089] See Figure 2 , Figure 2 This is a flowchart illustrating the creation of a second pipeline state object, provided as an embodiment of this disclosure. Figure 2 As shown, during the operation of the graphics processing application, the hook control layer performs real-time monitoring of the application's execution. When it detects that the graphics processing application is calling the resource creation interface, the resource management component of the hook control layer intercepts the resource creation interface. Figure 2 (Not shown in the image). Upon intercepting a resource creation interface used to create a PSO (Pipeline State Object), the creation parameters from the resource creation interface are retrieved, and it is determined whether the first shader to be modified exists in the creation parameters. If not, the PSO is created according to the normal process, such as... Figure 2 The process shown ends. If so, the dynamic editing interface is called to convert the DXIL code of the first shader into an LLVM IR. In response to the editing operation on the LLVM IR, the edited LLVM IR is obtained, and then converted back to DXIL code. A validity check is performed on the edited DXIL code. If the validity check passes, the DXIL code result is obtained, which is the second shader corresponding to the DXIL code. Further, it is determined whether the first parameter in the first shader is the same as the second parameter in the second shader. If they are the same, it means the first parameter has not been modified, and there is no need to create a new root signature. A new second PSO is created directly based on the second shader and stored in the resource management section of the hook control layer. If they are different, it means the first parameter has been modified to the second parameter. A new root signature needs to be created based on the second parameter, and a new second PSO needs to be created based on the second shader. The new root signature and the second PSO are stored in the resource management section of the hook control layer.

[0090] This disclosure implements a method to detect the behavior of a graphics processing application during its operation. This allows for timely determination of whether the interfaces called by the graphics processing application are related to a pipeline state object. Furthermore, if the creation parameters of the pipeline state object contain shaders that need modification, the shaders can be dynamically edited and modified, improving the efficiency and flexibility of shader editing. To ensure the usability of the modified shaders, a new pipeline state object can be created based on the modified shaders, enabling the graphics processing application to perform graphics rendering tasks based on the new pipeline state object.

[0091] Furthermore, after obtaining the modified second shader and second pipeline state objects, it is necessary to run the second shader and second pipeline state objects and execute the corresponding graphics rendering tasks based on the second shader and second pipeline state objects. Specifically, the pipeline state objects originally called by the graphics processing application can be replaced with the newly created second pipeline state objects. If a new root signature has been created, the original root signature used should be replaced with the newly created root signature; if no new root signature has been created, no replacement is required.

[0092] Based on this, in a specific embodiment provided in this disclosure, after creating the second pipeline state object according to the second shader, the method further includes:

[0093] Upon detecting that the graphics processing application calls the state setting interface, the object state information in the state setting interface is obtained and stored;

[0094] When a graphics processing application calls a graphics interface event, the first shader is determined to exist among the multiple shaders corresponding to the graphics interface event based on the object state information.

[0095] In the presence of the first shader, the second pipeline state object is determined as the pipeline state object corresponding to the graphics interface event, and the new root signature is determined as the root signature corresponding to the graphics interface event.

[0096] The state setting interfaces are used to set the state of the rendering pipeline, such as `SetPipelineState` and `SetRootSignature`. The `SetPipelineState` interface is specifically used to set the pipeline state object; the `SetRootSignature` interface is specifically used to set the root signature. Object state information refers to the state information of the set rendering pipeline, including the set pipeline state object, root signature, parameters at different positions of the root signature, viewport size, etc. Graphics interface events are graphics API (Application Programming Interface) events, such as the `Draw` event and the `Dispatch` event. The `Draw` event is mainly used in the graphics rendering process, responsible for converting geometric shapes into image frames; the `Dispatch` event focuses on utilizing the parallel computing capabilities of the GPU to perform computational tasks and does not directly involve graphics output.

[0097] Specifically, when the hook control layer detects that a graphics processing application is calling the state setting interface, the state management part of the hook control layer will intercept the state setting interface, obtain the object state information in the state setting interface, including the set pipeline state object, root signature, parameters at different positions of the root signature, viewport size, etc., and store the obtained object state information in the state management part of the hook control layer.

[0098] When the Hook Control Layer detects a graphics interface call event from a graphics processing application, its state management section intercepts the event and, based on the object state information stored in the state management section, determines whether a first shader among the multiple shaders executed by the graphics interface event needs editing. If so, it retrieves the second pipeline state object and the new root signature stored in the Hook Control Layer's resource management section, identifying the second pipeline state object as the pipeline state object corresponding to the graphics interface event and the new root signature as the root signature corresponding to the graphics interface event. If the Hook Control Layer's resource management section does not store a new root signature, meaning no new root signature has been created, the existing root signature can continue to be used without replacement.

[0099] It should be noted that after resetting the second pipeline state object and the corresponding root signature, the graphics interface events called by the graphics processing application can be either the original graphics interface events or new graphics interface events, depending on the developer's actual needs.

[0100] The following explains the specific implementation of determining whether there is a first shader that needs to be edited among the multiple shaders executed by the graphical interface event based on the object state information.

[0101] In a specific embodiment provided in this disclosure, determining whether the first shader exists among multiple shaders corresponding to the graphics interface event based on the object state information includes:

[0102] Based on the object state information, determine the original first pipeline state object of the graphical interface event from among multiple pipeline state objects;

[0103] Determine whether the shader identifier of the first shader exists among the shader identifiers of the multiple shaders of the first pipeline state object;

[0104] If the shader identifier of the first shader exists among the multiple shader identifiers, it is determined that the first shader exists among the multiple shaders of the first pipeline state object.

[0105] Specifically, based on the object state information stored in the state management section, the first pipeline state object corresponding to it is determined from among the multiple pipeline state objects that the graphics processing application needs to execute. That is, the original first pipeline state object of the current graphics interface event is invoked. It is then determined whether the shader identifier of the first shader exists among the multiple shaders of the first pipeline state object. If it does, it is determined that the first shader exists among the multiple shaders of the first pipeline state object.

[0106] It should be noted that after obtaining the modified second shader, the backend compiler can be called to compile the modified fourth intermediate language code. This disclosure does not limit the compilation process; it is sufficient to complete the editing before using the second pipeline state object.

[0107] Furthermore, in one specific embodiment provided in this disclosure, the method further includes:

[0108] Upon detecting that the graphics processing application has finished calling the graphics interface event, the second pipeline state object is restored to the original first pipeline state object of the graphics interface event, and the new root signature is restored to the original root signature of the graphics interface event.

[0109] Specifically, after the hook control layer detects that the graphics processing application has finished calling the graphics interface event, it needs to restore the state of the graphics interface event, that is, restore the second pipeline state object to the first pipeline state object, and restore the new root signature to the original root signature.

[0110] See Figure 3 , Figure 3 This is a flowchart illustrating an event invocation of a graphical interface, provided as an embodiment of this disclosure. Figure 3As shown, during the operation of the graphics processing application, the hook control layer performs real-time monitoring of the application's execution. When the application calls the state setting interface, the state management part of the hook control layer intercepts the interface, obtains the object state information, and stores it in the state management part. When the application calls a graphics API event, the state management part intercepts the event and, based on the object state information stored in the state management part, determines the first PSO from among the multiple PSOs required by the application. It then checks if the shader identifier of the first shader exists among the shader identifiers of the multiple shaders in the first PSO; if not, the interception is ignored. Figure 3 The process shown ends; if so, the newly created second PSO is designated as the PSO corresponding to the graphics API event (i.e., the second PSO replaces the original PSO), and the new root signature (if a new root signature has been created) or the old root signature (if no new root signature has been created) is designated as the root signature corresponding to the graphics API event, so that the graphics processing application can call the graphics API event based on the second PSO and the corresponding root signature. If the completion of the graphics API event call by the graphics processing application is detected, the state of the graphics API event is restored.

[0111] This disclosure enables a graphics processing application to call graphics interface events based on a recreated second pipeline state object (including a modified second shader), thereby achieving real-time debugging of the modified second shader; by dynamically modifying the shader and integrating it with the execution of graphics interface events, the graphics processing application can adjust the graphics interface events during runtime.

[0112] The method for dynamically modifying shaders disclosed herein includes: upon detecting that a graphics processing application calls a resource creation interface, and the resource creation interface is used to create a pipeline state object, obtaining creation parameters from the resource creation interface, wherein the creation parameters include multiple shaders, and the multiple shaders are represented in the form of a first intermediate language code; if a first shader to be modified exists in the creation parameters, in response to a modification operation on the first shader, determining a modified second shader; and creating a second pipeline state object based on the second shader, wherein the second pipeline state object is used by the graphics processing application to call a graphics interface event and execute the graphics rendering task of the graphics interface event.

[0113] This disclosure implements a method to detect the behavior of a graphics processing application during its runtime, promptly determining whether the interfaces called by the application are related to a pipeline state object. If a shader requiring modification exists in the creation parameters of the pipeline state object, a dynamic editing interface is invoked to perform a formal conversion on the first intermediate language code of the shader to be modified. This allows developers to dynamically edit and modify the shader according to their editing needs, resulting in a modified second shader, thus improving the efficiency and flexibility of shader editing. To ensure the usability of the modified shader, a new pipeline state object can be created based on the modified shader, enabling the graphics processing application to perform graphics rendering tasks based on the new pipeline state object.

[0114] The following is in conjunction with the appendix Figure 4 Taking a DX12 graphics processing application as an example, the method for dynamically modifying shaders provided in this disclosure will be further explained and illustrated. Figure 4 A flowchart of a method for dynamically modifying a shader provided in this embodiment of the present disclosure includes the following steps:

[0115] Step 402: If a DX12 application is detected calling the resource creation interface, determine whether the resource creation interface is used to create a PSO.

[0116] Specifically, during the operation of a DX12 application, the Hook Layer monitors the behavior of the DX12 application in real time. When it detects that the DX12 application is calling the resource creation interface, it intercepts the resource creation interface and determines whether the resource creation interface is used to create a PSO.

[0117] Step 404: If it is determined that the resource creation interface is used to create a PSO, obtain the creation parameters in the resource creation interface.

[0118] Step 406: Determine if the first shader to be modified exists in the creation parameters.

[0119] Specifically, based on the shader data of multiple shaders in the creation parameters, hash values ​​for multiple shaders are generated respectively. It is then determined whether the hash value of the first shader exists among the hash values ​​of the multiple shaders. If it does, it is determined that the first shader exists in the creation parameters.

[0120] Step 408: If the first shader exists in the creation parameters, call the dynamic editing interface to convert the first intermediate language code into the second intermediate language code.

[0121] Specifically, if a first shader exists in the creation parameters, the LLVM shader dynamic editing interface is called to convert the first intermediate language code (i.e., DXIL code) of the first shader into the second intermediate language code (i.e., LLVMIR).

[0122] Step 410: In response to the modification operation on the second intermediate language code, obtain the modified third intermediate language code.

[0123] Step 412: Call the dynamic editing interface to convert the third intermediate language code into the fourth intermediate language code.

[0124] Specifically, the LLVM shader dynamic editing interface is called to convert the third intermediate language code (i.e., the modified LLVMIR) into the fourth intermediate language code (i.e., the modified DXIL code).

[0125] Step 414: Perform a validity check on the fourth intermediate language code. If the validity check of the fourth intermediate language code passes, obtain the second shader corresponding to the fourth intermediate language code.

[0126] Specifically, if the validity check of the fourth intermediate language code fails, the fourth intermediate language code will be modified until the validity check passes.

[0127] Step 416: Create a new PSO based on the second shader.

[0128] Determine whether the Signature parameter in the first shader is the same as the Signature parameter in the second shader. If they are the same, it means that the Signature parameter has not been modified, so there is no need to create a new root signature. Instead, create a new PSO based on the second shader and store the PSO in the resource management part of the Hook Layer. If they are different, it means that the Signature parameter has been modified. In this case, create a new root signature based on the modified Signature parameter, create a new PSO based on the second shader, and store the new root signature and the new PSO in the resource management part of the Hook Layer.

[0129] Step 418: If a DX12 application calls the state setting interface, obtain and store the object state information in the state setting interface.

[0130] Specifically, when the Hook Layer detects a DX12 application calling the state setting interface, it intercepts the state setting interface, obtains the object state information from the state setting interface, including the set PSO, root signature, parameters at different positions of the root signature, viewport size, etc., and stores the obtained object state information in the state management part of the Hook Layer.

[0131] Step 420: If a DX12 application calls a graphics API event, determine whether a first shader exists among the multiple shaders corresponding to the graphics API event based on the object state information.

[0132] Specifically, when the Hook Layer detects a DX12 application calling a graphics API event, it intercepts the graphics API event and determines whether the first shader exists among the multiple shaders that the graphics API event needs to execute, based on the object state information stored in the Hook Layer's state management section.

[0133] Step 422: If a first shader exists, determine the new PSO as the PSO corresponding to the graphics API event.

[0134] Specifically, if it exists, retrieve the new PSO and root signature stored in the state management section of the Hook Layer, set the new PSO as the PSO corresponding to the graph API event, and set the retrieved root signature as the root signature corresponding to the graph API event.

[0135] Step 424: If the DX12 application's call to the graphics API event has ended, restore the state of the graphics API event.

[0136] Specifically, the Hook Layer restores the state of the graphics API event when it detects that the DX12 application's call to the graphics API event has ended.

[0137] This embodiment of the disclosure implements a method whereby, during the execution of a DX12 application, a Hook Layer is inserted to intercept the resource creation interface called by the DX12 application. If it is determined that the resource creation interface is used to create a PSO (Personal Software Object), it further determines whether the creation parameters in the resource creation interface contain a first shader that needs modification. If so, a modified second shader can be obtained in response to the modification operation of the first shader, thereby enabling dynamic modification of the shader that needs modification during the execution of the DX12 application. After obtaining the modified second shader, a new PSO is created based on the second shader, so that the DX12 application can subsequently call graphics API events based on the newly created PSO and execute the corresponding graphics rendering tasks. By detecting the behavior of the DX12 application during its execution, promptly determining whether the interface called by the DX12 application is related to a PSO, and dynamically editing and modifying the shader when the creation parameters of the PSO contain a shader that needs modification, the efficiency and flexibility of shader editing and modification are improved. You can also create a new PSO based on the modified shader, so that DX12 applications can perform graphics rendering tasks based on the new PSO, ensuring the availability of the modified shader.

[0138] See Figure 5 , Figure 5 A flowchart of a graphics rendering method provided in this disclosure embodiment specifically includes the following steps:

[0139] Step 502: In response to a graphics rendering instruction, obtain the second pipeline state object and the root signature corresponding to the second pipeline state object, wherein the second pipeline state object is created based on the above-described shader dynamic modification method.

[0140] The graphics rendering method described herein applies graphics processing applications. An image rendering instruction refers to an instruction initiated by the terminal device to render a target graphic. The target graphic refers to a graphic generated based on the root signature corresponding to the second pipeline state object.

[0141] Specifically, upon receiving a graphics rendering instruction, the graphics processing application responds to the instruction by obtaining the second pipeline state object created by the hook control layer and the root signature corresponding to the second pipeline state object. The second pipeline state object is created based on the aforementioned shader dynamic modification method.

[0142] Step 504: Based on the second pipeline state object and the root signature corresponding to the second pipeline state object, call the graphics interface event corresponding to the second pipeline state object, wherein the graphics interface event is used to render and generate the target graphics corresponding to the graphics rendering instruction.

[0143] Specifically, the graphics processing application, based on the obtained second pipeline state object and the root signature corresponding to the second pipeline state object, calls the graphics interface event corresponding to the second pipeline state object to render and generate the target graphics.

[0144] The graphics rendering method disclosed herein can call the corresponding graphics interface event based on the second pipeline state object created by the hook control layer and the root signature corresponding to the second pipeline state object, and render and generate the target graphics, thereby realizing real-time rendering after dynamic modification of the shader.

[0145] It is understood that the various method embodiments mentioned above in this disclosure can be combined with each other to form combined embodiments without violating the principle and logic. Due to space limitations, this disclosure will not elaborate further. Those skilled in the art will understand that in the above methods of specific implementation, the specific execution order of each step should be determined by its function and possible internal logic.

[0146] See Figure 6 , Figure 6 An application flowchart of a dynamic shader modification system provided in this disclosure is shown. An embodiment of the dynamic shader modification system provided in this disclosure is as follows:

[0147] The shader dynamic modification system includes: a graphics processing application 601 and a hook control layer 602;

[0148] The graphics processing application 601 is configured to: receive graphics rendering instructions from a graphics rendering task, and call a resource creation interface in response to the graphics rendering instructions;

[0149] The hook control layer 602 is configured to: when it detects that the graphics processing application calls the resource creation interface, and the resource creation interface is used to create a pipeline state object, obtain creation parameters from the resource creation interface, wherein the creation parameters include multiple shaders, and the multiple shaders are represented in the form of a first intermediate language code; if there is a first shader to be modified in the creation parameters, in response to the modification operation of the first shader, determine a modified second shader; and create a second pipeline state object based on the second shader.

[0150] The graphics processing application 601 is further configured to: invoke the graphics interface event corresponding to the second pipeline state object based on the second pipeline state object, and execute the graphics rendering task of the graphics interface event.

[0151] Specifically, the dynamic shader modification system comprises a graphics processing application and a hook control layer. In practice, the graphics processing application receives rendering instructions from graphics rendering tasks and calls the resource creation interface in response to these instructions. During the operation of the graphics processing application, the hook control layer detects its behavior. If it detects that the graphics processing application is calling the resource creation interface, it intercepts and determines whether the resource creation interface is used to create a pipeline state object. If it is determined that the resource creation interface is used to create a pipeline state object, it obtains the creation parameters used to create the pipeline state object from the resource creation interface and determines whether a first shader that needs to be modified exists in the creation parameters. If it does, in response to the modification operation on the first shader, it determines the modified second shader and creates a new second pipeline state object based on the second shader. The graphics processing application obtains the second pipeline state object, calls a graphics interface event based on the second pipeline state object, and executes the graphics rendering task of the graphics interface event.

[0152] The specific applications of graphics processing and hook control layers in the dynamic shader modification system can be found in the aforementioned dynamic shader modification method or graphics rendering method, and will not be repeated here.

[0153] The dynamic shader modification system disclosed herein intercepts resource creation interfaces called by a graphics processing application during its runtime via a hook layer. If the resource creation interface is determined to be used to create a pipeline state object, the system further determines whether a first shader requiring modification exists in the creation parameters of the resource creation interface. If so, a modified second shader is obtained in response to the modification operation on the first shader. This enables dynamic modification of the shader requiring modification during the runtime of the graphics processing application through interaction between the graphics processing application and the hook layer. After obtaining the modified second shader, a new pipeline state object is created based on the second shader, allowing the graphics processing application to subsequently call graphics interface events based on the newly created pipeline state object and execute the corresponding graphics rendering tasks.

[0154] In addition, this disclosure also provides a shader dynamic modification apparatus, a graphics rendering apparatus, an electronic device, a computer-readable storage medium, and a computer program product, all of which can be used to implement any of the shader dynamic modification methods or graphics rendering methods provided in this disclosure. The corresponding technical solutions and descriptions are described in the corresponding records in the method section and will not be repeated here.

[0155] Figure 7 This is a block diagram of a shader dynamic modification apparatus provided in an embodiment of this disclosure. See also... Figure 7 This disclosure provides a shader dynamic modification apparatus, which includes:

[0156] The detection module 702 is configured to obtain creation parameters in the resource creation interface when it detects that a graphics processing application calls a resource creation interface and the resource creation interface is used to create a pipeline state object. The creation parameters include multiple shaders, and the multiple shaders are represented in the form of a first intermediate language code.

[0157] The response module 704 is configured to determine a modified second shader in response to a modification operation on the first shader if a first shader to be modified exists in the creation parameters.

[0158] Creation module 706 is configured to create a second pipeline state object based on the second shader, wherein the second pipeline state object is used by the graphics processing application to invoke a graphics interface event and execute the graphics rendering task of the graphics interface event.

[0159] Optionally, the apparatus further includes a generation module configured to:

[0160] Based on the shader data of the multiple shaders, generate shader identifiers for the multiple shaders respectively;

[0161] The response module 704 is further configured as follows:

[0162] If the shader identifier of the first shader exists among multiple shader identifiers, it is determined that the first shader exists in the creation parameters.

[0163] Optionally, the device further includes an interface calling module, configured to:

[0164] Call the dynamic editing interface to convert the first intermediate language code of the first shader into the second intermediate language code;

[0165] The response module 704 is further configured as follows:

[0166] In response to the modification operation on the second intermediate language code, the modified third intermediate language code is obtained;

[0167] The dynamic editing interface is called to convert the third intermediate language code into the fourth intermediate language code, thereby obtaining the second shader corresponding to the fourth intermediate language code, wherein the first intermediate language code and the fourth intermediate language code are of the same type.

[0168] Optionally, the device further includes an inspection module configured to:

[0169] Perform a validity check on the fourth intermediate language code;

[0170] If the validity check of the fourth intermediate language code passes, the second shader corresponding to the fourth intermediate language code is obtained.

[0171] Optionally, the device further includes a signature creation module configured to:

[0172] Obtain a first parameter of the first shader and a second parameter of the second shader, wherein the first parameter includes resources required for the first shader to run, and the second parameter includes resources required for the second shader to run;

[0173] If the first parameter is different from the second parameter, a new root signature corresponding to the second pipeline state object is created based on the second parameter. The new root signature is used by the graphics processing application to call the graphics interface event based on the second pipeline state object and the new root signature.

[0174] Optionally, the device further includes a determining module configured to:

[0175] Upon detecting that the graphics processing application calls the state setting interface, the object state information in the state setting interface is obtained and stored;

[0176] When a graphics processing application calls a graphics interface event, the first shader is determined to exist among the multiple shaders corresponding to the graphics interface event based on the object state information.

[0177] In the presence of the first shader, the second pipeline state object is determined as the pipeline state object corresponding to the graphics interface event, and the new root signature is determined as the root signature corresponding to the graphics interface event.

[0178] Optionally, the determining module is further configured to:

[0179] Based on the object state information, determine the original first pipeline state object of the graphical interface event from among multiple pipeline state objects;

[0180] Determine whether the shader identifier of the first shader exists among the shader identifiers of the multiple shaders of the first pipeline state object;

[0181] If the shader identifier of the first shader exists among the multiple shader identifiers, it is determined that the first shader exists among the multiple shaders of the first pipeline state object.

[0182] Optionally, the device further includes a recovery module configured to:

[0183] Upon detecting that the graphics processing application has finished calling the graphics interface event, the second pipeline state object is restored to the original first pipeline state object of the graphics interface event, and the new root signature is restored to the original root signature of the graphics interface event.

[0184] The shader dynamic modification apparatus provided in this disclosure includes: a detection module configured to, when detecting that a graphics processing application calls a resource creation interface and the resource creation interface is used to create a pipeline state object, obtain creation parameters in the resource creation interface, wherein the creation parameters include multiple shaders, and the multiple shaders are represented in the form of a first intermediate language code; a response module configured to, in response to a modification operation on the first shader, determine a modified second shader if a first shader to be modified exists in the creation parameters; and a creation module configured to create a second pipeline state object based on the second shader, wherein the second pipeline state object is used by the graphics processing application to call a graphics interface event and execute the graphics rendering task of the graphics interface event.

[0185] This disclosure implements a method to detect the behavior of a graphics processing application during its runtime, promptly determining whether the interfaces called by the application are related to a pipeline state object. If a shader requiring modification exists in the creation parameters of the pipeline state object, a dynamic editing interface is invoked to formally transform the code of the shader to be modified. This allows developers to dynamically edit and modify the shader according to their editing needs, resulting in a modified second shader. This improves the efficiency and flexibility of shader editing. To ensure the usability of the modified shader, a new pipeline state object can be created based on the modified shader, enabling the graphics processing application to perform graphics rendering tasks based on the new pipeline state object.

[0186] Figure 8 This is a block diagram of a graphics rendering apparatus provided in an embodiment of this disclosure. See also... Figure 8 This disclosure provides a graphics rendering apparatus, which includes:

[0187] The acquisition module 802 is configured to, in response to a graphics rendering instruction, acquire a second pipeline state object and the root signature corresponding to the second pipeline state object, wherein the second pipeline state object is created based on the aforementioned shader dynamic modification method;

[0188] The calling module 804 is configured to call the graphics interface event corresponding to the second pipeline state object based on the second pipeline state object and the root signature corresponding to the second pipeline state object, wherein the graphics interface event is used to render and generate the target graphics corresponding to the graphics rendering instruction.

[0189] This embodiment of the disclosure enables the invocation of corresponding graphics interface events based on the second pipeline state object created by the hook control layer and the root signature corresponding to the second pipeline state object, and the rendering of the target graphics, thereby achieving real-time rendering of the dynamically modified shader.

[0190] Figure 9 This is a block diagram of an electronic device provided in an embodiment of the present disclosure.

[0191] See Figure 9 This disclosure provides an electronic device, which includes: at least one processor 901; at least one memory 902; and one or more I / O interfaces 903 connected between the processor 901 and the memory 902; wherein the memory 902 stores one or more computer programs that can be executed by the at least one processor 901, and the one or more computer programs are executed by the at least one processor 901 to enable the at least one processor 901 to perform the above-described shader dynamic modification method or graphics rendering method.

[0192] This disclosure also provides a computer-readable storage medium storing a computer program thereon, wherein the computer program, when executed by a processor, implements the aforementioned shader dynamic modification method or graphics rendering method. The computer-readable storage medium may be volatile or non-volatile.

[0193] This disclosure also provides a computer program product, including computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code. When the computer-readable code is run in a processor of an electronic device, the processor in the electronic device executes the above-described shader dynamic modification method or graphics rendering method.

[0194] Those skilled in the art will understand that all or some of the steps, systems, and apparatuses disclosed above, and their functional modules / units, can be implemented as software, firmware, hardware, or suitable combinations thereof. In hardware implementations, the division between functional modules / units mentioned above does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed collaboratively by several physical components. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit (ASIC). Such software can be distributed on a computer-readable storage medium, which may include computer storage media (or non-transitory media) and communication media (or transient media).

[0195] As is known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable program instructions, data structures, program modules, or other data). Computer storage media includes, but is not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), static random access memory (SRAM), flash memory or other memory technologies, portable compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. Furthermore, it is known to those skilled in the art that communication media typically contain computer-readable program instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.

[0196] The computer-readable program instructions described herein can be downloaded from computer-readable storage media to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to the computer-readable storage media in the respective computing / processing device.

[0197] Computer program instructions used to perform the operations of this disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, status setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Smalltalk, C++, etc., and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing the status information of the computer-readable program instructions to implement various aspects of this disclosure.

[0198] The computer program product described herein can be implemented specifically through hardware, software, or a combination thereof. In one alternative embodiment, the computer program product is specifically embodied in a computer storage medium; in another alternative embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.

[0199] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.

[0200] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that, when executed by the processor of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner; thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of the flowchart and / or block diagram.

[0201] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.

[0202] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than those shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0203] Example embodiments have been disclosed herein, and while specific terminology has been used, it is for illustrative purposes only and should be construed as such, and is not intended to be limiting. In some instances, it will be apparent to those skilled in the art that features, characteristics, and / or elements described in connection with particular embodiments may be used alone, or in combination with features, characteristics, and / or elements described in connection with other embodiments, unless otherwise expressly indicated. Therefore, those skilled in the art will understand that various changes in form and detail may be made without departing from the scope of this disclosure as set forth by the appended claims.

Claims

1. A method for dynamically modifying a shader, characterized in that, include: When it is detected that a graphics processing application calls a resource creation interface, and the resource creation interface is used to create a pipeline state object, the creation parameters in the resource creation interface are obtained, wherein the creation parameters include multiple shaders, and the multiple shaders are represented in the form of a first intermediate language code; If a first shader to be modified exists in the creation parameters, a modified second shader is determined in response to the modification operation on the first shader, wherein the first shader is determined based on the optimization requirements of the rendering behavior of the graphics processing application. A second pipeline state object is created based on the second shader, wherein the second pipeline state object is used by the graphics processing application to invoke a graphics interface event and execute the graphics rendering task of the graphics interface event.

2. The method as described in claim 1, characterized in that, The method further includes: Based on the shader data of the multiple shaders, generate shader identifiers for the multiple shaders respectively; In the case where a first shader to be modified exists in the creation parameters, including: If the shader identifier of the first shader exists among multiple shader identifiers, it is determined that the first shader exists in the creation parameters.

3. The method as described in claim 1, characterized in that, The method further includes: Call the dynamic editing interface to convert the first intermediate language code of the first shader into the second intermediate language code; In response to a modification operation on the first shader, determining a modified second shader includes: In response to the modification operation on the second intermediate language code, the modified third intermediate language code is obtained; The dynamic editing interface is called to convert the third intermediate language code into the fourth intermediate language code, thereby obtaining the second shader corresponding to the fourth intermediate language code, wherein the first intermediate language code and the fourth intermediate language code are of the same type.

4. The method as described in claim 3, characterized in that, The method further includes: Perform a validity check on the fourth intermediate language code; If the validity check of the fourth intermediate language code passes, the second shader corresponding to the fourth intermediate language code is obtained.

5. The method as described in claim 1, characterized in that, The method further includes: Obtain a first parameter of the first shader and a second parameter of the second shader, wherein the first parameter includes resources required for the first shader to run, and the second parameter includes resources required for the second shader to run; If the first parameter is different from the second parameter, a new root signature corresponding to the second pipeline state object is created based on the second parameter. The new root signature is used by the graphics processing application to call the graphics interface event based on the second pipeline state object and the new root signature.

6. The method as described in claim 5, characterized in that, The method further includes: Upon detecting that the graphics processing application calls the state setting interface, the object state information in the state setting interface is obtained and stored; When a graphics processing application calls a graphics interface event, the first shader is determined to exist among the multiple shaders corresponding to the graphics interface event based on the object state information. In the presence of the first shader, the second pipeline state object is determined as the pipeline state object corresponding to the graphics interface event, and the new root signature is determined as the root signature corresponding to the graphics interface event.

7. The method as described in claim 6, characterized in that, Determining whether the first shader exists among the multiple shaders corresponding to the graphics interface event based on the object state information includes: Based on the object state information, determine the original first pipeline state object of the graphical interface event from among multiple pipeline state objects; Determine whether the shader identifier of the first shader exists among the shader identifiers of the multiple shaders of the first pipeline state object; If the shader identifier of the first shader exists among the multiple shader identifiers, it is determined that the first shader exists among the multiple shaders of the first pipeline state object.

8. The method as described in claim 6, characterized in that, The method further includes: Upon detecting that the graphics processing application has finished calling the graphics interface event, the second pipeline state object is restored to the original first pipeline state object of the graphics interface event, and the new root signature is restored to the original root signature of the graphics interface event.

9. A graphics rendering method, characterized in that, include: In response to a graphics rendering command, a second pipeline state object and a root signature corresponding to the second pipeline state object are obtained, wherein the second pipeline state object is created based on the method described in any one of claims 1-8. Based on the second pipeline state object and the root signature corresponding to the second pipeline state object, the graphics interface event corresponding to the second pipeline state object is invoked, wherein the graphics interface event is used to render and generate the target graphic corresponding to the graphics rendering instruction.

10. A shader dynamic modification system, characterized in that, include: Graphics processing applications and hook control layers; The graphics processing application is configured to: receive graphics rendering instructions from a graphics rendering task, and invoke a resource creation interface in response to the graphics rendering instructions; The hook control layer is configured to: upon detecting that the graphics processing application calls the resource creation interface, and the resource creation interface is used to create a pipeline state object, obtain creation parameters from the resource creation interface, wherein the creation parameters include multiple shaders, and the multiple shaders are represented in the form of a first intermediate language code; if a first shader to be modified exists in the creation parameters, in response to a modification operation on the first shader, determine a modified second shader; create a second pipeline state object based on the second shader; the first shader is determined based on the optimization requirements of the rendering behavior of the graphics processing application; The graphics processing application is also used to: call the graphics interface event corresponding to the second pipeline state object based on the second pipeline state object, and execute the graphics rendering task of the graphics interface event.

11. A shader dynamic modification apparatus, characterized in that, include: The detection module is configured to, when it detects that a graphics processing application calls a resource creation interface and the resource creation interface is used to create a pipeline state object, obtain creation parameters in the resource creation interface, wherein the creation parameters include multiple shaders and the multiple shaders are represented in the form of a first intermediate language code; A response module is configured to determine a modified second shader in response to a modification operation on the first shader if a first shader to be modified exists in the creation parameters, wherein the first shader is determined based on optimization requirements for the rendering behavior of the graphics processing application. A creation module is configured to create a second pipeline state object based on the second shader, wherein the second pipeline state object is used by the graphics processing application to invoke a graphics interface event and execute the graphics rendering task of the graphics interface event.

12. A graphics rendering apparatus, characterized in that, include: The acquisition module is configured to acquire a second pipeline state object and a root signature corresponding to the second pipeline state object in response to a graphics rendering instruction, wherein the second pipeline state object is created based on the method described in any one of claims 1-8. The calling module is configured to invoke the graphics interface event corresponding to the second pipeline state object based on the second pipeline state object and the root signature corresponding to the second pipeline state object, wherein the graphics interface event is used to render and generate the target graphics corresponding to the graphics rendering instruction.

13. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores one or more computer programs that can be executed by the at least one processor, the one or more computer programs being executed by the at least one processor to enable the at least one processor to perform the method as described in any one of claims 1-9.

14. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-9.

15. A computer program product, characterized in that, Includes computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code, wherein when the computer-readable code is executed in a processor of an electronic device, the processor in the electronic device performs the method as described in any one of claims 1-9.

Citation Information

Patent Citations

  • Debugging method and device for rendering problem, equipment and storage medium

    CN115357516A