Resource loading method and device of graphics processor, electronic equipment and storage medium
By constructing worker threads and task waiting loops to manage the loading of graphics processor resources, the problems of access conflicts and memory leaks caused by asynchronous execution of GPU and CPU are solved, achieving efficient and automated resource management and improving the development efficiency of 3D graphics APIs and the quality of software products.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CISDI ENGINEERING CO LTD
- Filing Date
- 2025-11-20
- Publication Date
- 2026-07-24
AI Technical Summary
In modern 3D graphics API systems, the asynchronous execution characteristics between GPUs and CPUs can lead to problems such as access conflicts, premature resource release, or memory leaks, affecting system stability and performance.
By constructing worker threads and starting a task waiting loop, resource loading task information for the graphics processor is generated and added to the task queue. The worker threads retrieve resource loading task information from the task queue, allocate and load temporary resources to the graphics processor, obtain the element fence value when resource loading is complete, and retrieve the current fence value according to a preset frequency to confirm that resource loading is complete and destroy the temporary resources when the resource loading is complete or the task queue is idle.
It enables efficient and automated management of the loading process of massive resources, reduces program complexity, and improves development efficiency and software product quality.
Smart Images

Figure CN121541939B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of resource loading technology, and in particular to a resource loading method, apparatus, electronic device and storage medium for a graphics processor. Background Technology
[0002] In the modern 3D graphics API (Application Programming Interface) system, loading resources such as models and textures from hard drive to video memory is a crucial and fundamental step, exhibiting high versatility and common characteristics. Because modern graphics interfaces are designed to achieve ultimate rendering performance and low-level hardware control capabilities, many resource operations that were automatically managed by drivers in traditional graphics APIs have been significantly decentralized to the application layer. This includes the allocation and release management of intermediate temporary resources such as page-locked memory. While this design improves the flexibility and efficiency of resource scheduling, it also significantly increases the programming burden on developers, making application structures based on these modern graphics APIs more complex and correspondingly more difficult to maintain.
[0003] In the resource loading process, the lifecycle management of intermediate temporary resources (such as memory areas used for temporary data storage and transfer) is particularly critical. The actual consumers of these resources are the graphics processing unit (GPU), while their creation and destruction are handled by the central processing unit (CPU). Due to the asynchronous execution characteristics between the GPU and CPU, failure to properly coordinate their access to and manipulation of resource states can easily lead to access conflicts, premature resource release, or memory leaks, thus affecting system stability and performance. Clearly, a new resource loading method for graphics processing units is urgently needed to address at least one of these problems.
[0004] It should be noted that the above content only provides background information related to this application and does not necessarily constitute prior art. Summary of the Invention
[0005] This application provides a resource loading method, apparatus, electronic device, and storage medium for a graphics processor to solve the technical problems that affect system stability and performance, such as access conflicts, premature resource release, or memory leaks caused by the asynchronous execution characteristics between the GPU and CPU.
[0006] Other features and advantages of this application will become apparent from the following detailed description, or may be learned in part from practice of this application.
[0007] This application provides a resource loading method for a graphics processing unit (GPU), comprising: constructing a worker thread and starting a task waiting loop until the worker thread receives a wake-up request; generating resource loading task information for the GPU and adding the resource loading task information to a task queue; the worker thread retrieving the resource loading task information from the task queue, allocating and loading temporary resources to the GPU according to the resource loading task information, and retrieving the element fence value of the GPU when resource loading is complete; the worker thread retrieving the current fence value of the GPU according to a preset frequency when resource loading is complete or when the task queue is idle, and if it is confirmed that resource loading is complete based on the current fence value and the element fence value, then destroying the temporary resources corresponding to the element fence value.
[0008] In one embodiment of this application, based on the aforementioned scheme, allocating and loading temporary resources to the graphics processor according to the resource loading task information, and obtaining the element fence value of the graphics processor when resource loading is completed, includes: reading the content of a resource file according to the resource loading task information; allocating temporary resources based on the resource basic information in the resource file content; reading preset resource data from the resource file content into the temporary resources based on the resource basic information; loading the temporary resources into the graphics processor's video memory; obtaining the element fence value of the graphics processor when resource loading is completed; and packaging the temporary resources and the element fence value into a temporary resource container corresponding to the worker thread.
[0009] In one embodiment of this application, based on the aforementioned scheme, if it is confirmed that resource loading is complete based on the current fence value and the element fence value, then the temporary resource corresponding to the element fence value is destroyed, including: the worker thread traverses each element fence value in the temporary resource container, compares the current fence value with each element fence value; if the current fence value is greater than or equal to the element fence value, it is confirmed that resource loading is complete, then the temporary resource corresponding to the element fence value is destroyed.
[0010] In one embodiment of this application, based on the foregoing scheme, the feature is that constructing a worker thread includes: constructing a thread object and a worker thread according to the characteristics of a 3D rendering program, wherein the thread object corresponds one-to-one with the worker thread, and the worker thread is started or stopped through the thread object.
[0011] In one embodiment of this application, based on the foregoing scheme, the wake-up request is generated in at least one of the following ways: automatically generating the wake-up request at preset intervals; or generating the wake-up request upon receiving a call request to invoke the worker thread.
[0012] In one embodiment of this application, based on the foregoing scheme, before the worker thread obtains the resource loading task information from the task queue, the method further includes: determining the task existence status of the task queue; if the task existence status is non-existent, controlling the worker thread to enter a waiting state until the task existence status is existent or the wake-up request is received; if the task existence status is existent, obtaining the resource loading task information from the task queue.
[0013] In one embodiment of this application, based on the aforementioned scheme, the main thread of the central processing unit is used to add the resource loading task information to the task queue, the worker thread is used to load preset resource data from the hard disk to the temporary resource, and the graphics processor is used to copy the preset resource data from the temporary resource to the graphics processor's video memory. The main thread of the central processing unit, the worker thread, and the graphics processor can work simultaneously.
[0014] This application also provides a resource loading device for a graphics processor, comprising: a construction module for constructing a worker thread and initiating a task waiting loop until the worker thread receives a wake-up request; a generation module for generating resource loading task information for the graphics processor and adding the resource loading task information to a task queue; a loading module for the worker thread to obtain the resource loading task information from the task queue, allocate and load temporary resources to the graphics processor according to the resource loading task information, and obtain the element fence value of the graphics processor when resource loading is completed; and a destruction module for the worker thread to obtain the current fence value of the graphics processor according to a preset frequency when resource loading is completed or when the task queue is idle, and if it is confirmed that resource loading is completed based on the current fence value and the element fence value, then destroy the temporary resources corresponding to the element fence value.
[0015] This application also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the resource loading method of the graphics processor as described in any of the above embodiments.
[0016] This application also provides a computer-readable storage medium storing a computer program that is executed by a processor to implement the resource loading method for a graphics processor as described in any of the above embodiments.
[0017] The beneficial effects of this application are as follows: By constructing worker threads and starting a task waiting loop until the worker thread receives a wake-up request, resource loading task information for the graphics processor is generated and added to the task queue. The worker thread retrieves the resource loading task information from the task queue, allocates and loads temporary resources to the graphics processor according to the resource loading task information, and obtains the element fence value of the graphics processor when the resource loading is completed. When the resource loading is completed or the task queue is idle, the worker thread retrieves the current fence value of the graphics processor according to a preset frequency. If the resource loading is confirmed to be completed based on the current fence value and the element fence value, the temporary resource corresponding to the element fence value is destroyed. This solves the program complexity and potential defects caused by the life cycle maintenance of temporary resources during resource loading, and realizes efficient and automated management of the massive resource loading process, thereby improving development efficiency and software product quality.
[0018] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description
[0019] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.
[0020] In the attached diagram: Figure 1 This is a schematic flowchart illustrating a resource loading method for a graphics processor, as shown in an exemplary embodiment of this application. Figure 2 This is a flowchart illustrating a resource loading method for a graphics processor, as shown in another exemplary embodiment of this application. Figure 3 This is a block diagram illustrating a resource loading apparatus for a graphics processor, as shown in an exemplary embodiment of this application. Figure 4 A schematic diagram of the structure of a computer system suitable for implementing the electronic device of the present application is shown. Detailed Implementation
[0021] The following specific examples illustrate the implementation of this application. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. This application can also be implemented or applied through other different specific embodiments. Various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0022] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of this application. The drawings only show the components related to this application and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the shape, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.
[0023] In the following description, numerous details are explored to provide a more thorough explanation of embodiments of the present application. However, it will be apparent to those skilled in the art that embodiments of the present application may be practiced without these specific details. In other embodiments, well-known structures and devices are shown in block diagram form rather than in detail to avoid obscuring embodiments of the present application.
[0024] First, it's important to clarify that a GPU (Graphics Processing Unit), also known as a display core, display chip, or video processor, is a coprocessor used for processing images and graphics calculations. It is widely used in personal computers, workstations, and some mobile devices (such as smartphones and tablets). As an important branch of hardware, GPUs are widely used in scientific computing, artificial intelligence, game development, and other fields.
[0025] GPU fencing is a mechanism for synchronizing GPU and CPU operations. By recording the status of tasks completed by the GPU, it ensures that the CPU responds correctly while waiting for the GPU to complete a specific operation. The fencing value represents the sequence number of the task completed by the GPU, typically a 64-bit integer. When the GPU completes an operation, it increments this value, and the CPU checks this value to determine if the task is complete. Monitored fencing is a shared memory value maintained by the operating system, recording the current minimum fencing value being waited for. The CPU polls this value to determine the GPU's progress, and the GPU triggers an interrupt to notify the CPU by writing a new value.
[0026] GPU memory (Video Random Access Memory), also known as video RAM (VRAM), is dedicated memory designed specifically for the graphics processing unit (GPU) and is independent of the host's main memory (RAM).
[0027] Page-locked memory is a memory management technique that locks specific memory pages to prevent them from being swapped out to the swap space by the operating system, ensuring that data always resides in physical memory.
[0028] Figure 1 This is a schematic flowchart illustrating a resource loading method for a graphics processor, as shown in an exemplary embodiment of this application. This resource loading method for a graphics processor can be executed by a computing device. (Refer to...) Figure 1 As shown, the resource loading method for this graphics processor includes at least steps S110 to S140, which are described in detail below: In step S110, a worker thread is constructed and a task waiting loop is started until the worker thread receives a wake-up request.
[0029] In one embodiment of this application, thread objects and worker threads are constructed based on the characteristics of a 3D rendering program, wherein the thread objects correspond one-to-one with the worker threads, and the start or stop of the worker threads is controlled by the thread objects.
[0030] In this embodiment, starting control, which controls the start or stop of worker threads through thread objects, refers to triggering the creation and start of worker threads by constructing thread objects. Stopping control refers to coordinating the termination of worker threads by setting flags and calling `join()`. This control mode ensures that the lifecycle management of multithreaded programs is controllable and safe, avoiding resource leaks or unpredictable thread behavior.
[0031] In one embodiment of this application, the wake-up request is generated in at least one of the following ways: automatically generating a wake-up request at preset intervals; or generating a wake-up request upon receiving a call request to invoke a worker thread.
[0032] In this embodiment, a thread object from the C++ standard or a thread object from the operating system's API can be used as the thread object, and a callback function can be passed in as the thread object's startup function.
[0033] Specifically, step S110 above includes the following steps: In step S111, the specific class form of the GPU resource loading task information is determined according to the way the pipeline to be rendered uses resources. The general form is: resource file name.
[0034] In step S112, a callback function is passed in as the thread object startup function of the worker thread and the worker thread is started. The function is characterized by: the outermost layer is a while loop, the termination condition of which is a preset boolean variable that marks program termination as true. In each loop, it attempts to obtain resources from the task queue to load tasks. If there are no tasks in the task queue, it enters a waiting state, waiting for tasks to be available in the task queue or being directly awakened by other program logic.
[0035] In step S113, after the worker thread enters the waiting state, its wake-up method should generally support two methods simultaneously: automatic wake-up after waiting for a preset interval, and wake-up by receiving APIs such as condition variable wake-up from other external program logic (i.e., receiving a call request to call the worker thread).
[0036] In step S120, resource loading task information for the graphics processor is generated and added to the task queue.
[0037] In this embodiment, a lock-free queue or a "mutex lock + non-thread-safe queue" is used as the task queue, and the main thread puts the GPU resource loading task information into the task queue.
[0038] In step S130, the worker thread obtains resource loading task information from the task queue, allocates and loads temporary resources to the graphics processor according to the resource loading task information, and obtains the element fence value of the graphics processor when the resource loading is completed.
[0039] In one embodiment of this application, allocating and loading temporary resources to the graphics processor according to resource loading task information, and obtaining the element fence value of the graphics processor when resource loading is completed, includes: reading the content of a resource file according to the resource loading task information, allocating temporary resources based on the resource basic information in the resource file content; reading preset resource data from the resource file content into the temporary resources based on the resource basic information; loading the temporary resources into the graphics processor's video memory, obtaining the element fence value of the graphics processor when resource loading is completed, and packaging the temporary resources and the element fence value into a temporary resource container corresponding to the worker thread.
[0040] In this embodiment, after the worker thread obtains GPU resource loading task information from the task queue, it allocates temporary resources such as page-locked memory according to the resource loading task information, and reads the resource data from the hard disk into the page-locked memory or other temporary resources. It then initiates a copy command from the page-locked memory or other temporary resources to the GPU memory (i.e., graphics processor memory), obtains the element fence value corresponding to the completion of the command, and packages the temporary resources and the element fence value as a single element into a temporary resource container maintained by this worker thread.
[0041] Specifically, step S130 above includes the following steps: In step S131, the contents of the resource file are read according to the GPU resource loading task information, and temporary resources such as page lock memory are allocated based on the basic resource information (such as resource size, block configuration, etc.) in the resource file contents.
[0042] In step S132, based on the basic resource information, the specific resource data (such as model data, texture data, etc.) in the resource file content is read into temporary resources such as page lock memory.
[0043] In step S133, a data copy command is submitted to the GPU to copy temporary resources such as page lock memory to the GPU video memory. The fence value that the GPU can reach when the command is completed (i.e., the element fence value) is obtained. The temporary resources and the fence value are packaged as an element and put into a temporary resource container maintained by the worker thread.
[0044] In one embodiment of this application, before the worker thread obtains resource loading task information from the task queue, the process further includes: determining the task existence status of the task queue; if the task existence status is non-existent, controlling the worker thread to enter a waiting state until the task existence status is existent or a wake-up request is received; if the task existence status is existent, obtaining resource loading task information from the task queue.
[0045] In step S140, when the resource loading is complete or the task queue is idle, the worker thread obtains the current fence value of the graphics processor according to a preset frequency. If it is confirmed that the resource loading is complete based on the current fence value and the element fence value, the temporary resource corresponding to the element fence value is destroyed.
[0046] In one embodiment of this application, if it is confirmed that the resource loading is complete based on the current fence value and the element fence value, the temporary resource corresponding to the element fence value is destroyed. This includes: the worker thread traverses each element fence value in the temporary resource container and compares the current fence value with each element fence value; if the current fence value is greater than or equal to the element fence value, it is confirmed that the resource loading is complete, and the temporary resource corresponding to the element fence value is destroyed.
[0047] In this embodiment, if the current fence value is less than the element fence value, the resource loading is confirmed to be complete, and the temporary resource corresponding to the element fence value is not destroyed for the time being.
[0048] In this embodiment, after completing each resource loading task or when the task queue is idle, the worker thread obtains the current fence value (i.e., the current fence value) reached by the GPU at a preset frequency, and compares the fence value with the fence value of each element in the temporary resource container maintained by the thread. If the current fence value of the GPU is greater than or equal to the fence value of the element, it proves that the resource loading is complete, and the temporary resources in the element are destroyed.
[0049] Specifically, step S140 above includes the following steps: In step S141, when the worker thread does not acquire a task from the task queue in the loop, it acquires the current fence value (i.e., the current fence value) reached by the GPU before entering the waiting state.
[0050] In step S142, the worker thread traverses each element in the temporary resource container it maintains and compares the current fence value reached by the GPU with the fence values of the elements in each element.
[0051] In step S143, if the current fence value of the GPU is greater than or equal to the fence value of the element, it proves that the resource loading is complete. Then, the temporary resources in the element are destroyed, and the element is removed from the temporary resource container.
[0052] In one embodiment of this application, the main thread of the central processing unit is used to add resource loading task information to the task queue, the worker thread is used to load preset resource data from the hard disk to temporary resources, and the graphics processor is used to copy preset resource data from the temporary resources to the graphics processor's video memory. The main thread of the central processing unit, the worker thread, and the graphics processor can work simultaneously.
[0053] In this embodiment, the CPU main thread, the resource loading worker thread, and the GPU can all work simultaneously. The CPU main thread is responsible for submitting GPU resource loading tasks, the worker thread is responsible for loading resource data from the hard drive to temporary resources and initiating GPU commands, and the GPU is responsible for copying resource data from the temporary resources to video memory. The three processes have clearly defined roles and their execution times can overlap. Therefore, this application can fully guarantee high-performance CPU-GPU collaboration, achieving efficient and automated management of the massive resource loading process, thereby improving the development efficiency of modern 3D graphics APIs and the quality of software products.
[0054] Figure 2 This is a flowchart illustrating a resource loading method for a graphics processor, as shown in another exemplary embodiment of this application. (Refer to...) Figure 2 As shown, in an exemplary embodiment, the resource loading method for a graphics processor includes at least steps S1 to S4, which are described in detail below: In step S1, a thread object is constructed based on the characteristics of the 3D rendering program, and a task waiting loop is started.
[0055] In step S2, GPU resource loading task information is generated and added to the task queue.
[0056] In step S3, the worker thread loads task information based on the resources in the task queue and performs resource loading operations such as I / O.
[0057] In step S4, if the resource loading is confirmed to be complete based on the GPU fence value, the temporary resource destruction process is initiated.
[0058] This application aims to ensure the stability and ease of use of modern graphics API development programs and improve the quality of software products.
[0059] It is understood that the resource loading method for the graphics processor provided in this embodiment is based on the same concept as the resource loading method for the graphics processor provided in the above embodiments. The specific execution method of each step has been described in detail in the foregoing embodiments and will not be repeated here.
[0060] This application proposes a resource loading method for graphics processors based on multithreading and GPU fence values for modern graphics API development programs. By using multithreaded loading and GPU fence value management of temporary resource lifecycles, it solves the program complexity and potential bugs (defects or vulnerabilities) caused by the lifecycle maintenance of temporary resources such as page-locked memory during resource loading in modern 3D graphics APIs. It achieves efficient and automated management of the massive resource loading process, thereby improving the development efficiency of modern 3D graphics APIs and the quality of software products.
[0061] Figure 3 This is a block diagram illustrating a resource loading apparatus for a graphics processor, as shown in an exemplary embodiment of this application. This apparatus can be configured in a computer device or other devices, and this embodiment does not limit the implementation environment to which this apparatus is applicable.
[0062] like Figure 3 As shown, the exemplary graphics processor resource loading device includes: a building module 310, a generating module 320, a loading module 330, and a destroying module 340.
[0063] The system includes a construction module 310 for building worker threads and starting a task waiting loop until the worker threads receive a wake-up request; a generation module 320 for generating resource loading task information for the graphics processor and adding the resource loading task information to the task queue; a loading module 330 for the worker threads to obtain resource loading task information from the task queue, allocate and load temporary resources to the graphics processor according to the resource loading task information, and obtain the element fence value of the graphics processor when the resource loading is completed; and a destruction module 340 for the worker threads to obtain the current fence value of the graphics processor according to a preset frequency when the resource loading is completed or when the task queue is idle. If the resource loading is confirmed to be completed based on the current fence value and the element fence value, the temporary resources corresponding to the element fence value are destroyed.
[0064] It should be noted that the graphics processor resource loading device and the graphics processor resource loading method provided in the above embodiments belong to the same concept. The specific ways in which each module and unit performs operations have been described in detail in the method embodiments, and will not be repeated here. In practical applications, the graphics processor resource loading device provided in the above embodiments can allocate the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not a limitation here.
[0065] Embodiments of this application also provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the resource loading method of a graphics processor as described in any of the above embodiments.
[0066] Figure 4 A schematic diagram of a computer system suitable for implementing the embodiments of this application is shown. It should be noted that... Figure 4 The computer system 400 of the electronic device shown is merely an example and should not impose any limitation on the functionality and scope of the embodiments of this application.
[0067] like Figure 4 As shown, the computer system 400 includes a Central Processing Unit (CPU) 401, which can perform various appropriate actions and processes, such as executing the methods provided in the various embodiments described above, based on a program stored in Read-Only Memory (ROM) 402 or a program loaded from Storage Unit 408 into Random Access Memory (RAM) 403. The RAM 403 also stores various programs and data required for system operation. The CPU 401, ROM 402, and RAM 403 are interconnected via a bus 404. An Input / Output (I / O) interface 405 is also connected to the bus 404.
[0068] The following components are connected to I / O interface 405: an input section 406 including a keyboard, mouse, etc.; an output section 407 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 408 including a hard disk, etc.; and a communication section 409 including a network interface card such as a LAN (Local Area Network) card, modem, etc. The communication section 409 performs communication processing via a network such as the Internet. A drive 410 is also connected to I / O interface 405 as needed. A removable medium 411, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 410 as needed so that computer programs read from it can be installed into storage section 408 as needed.
[0069] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 409, and / or installed from removable medium 411. When the computer program is executed by central processing unit (CPU) 401, it performs various functions defined in the system of this application.
[0070] It should be noted that the computer-readable medium shown in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.
[0071] 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 this application. Each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated 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 a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0072] The units described in the embodiments of this application can be implemented in software or hardware, and the described units can also be located in a processor. The names of these units do not necessarily limit the specific unit itself.
[0073] Another aspect of this application provides a computer-readable storage medium storing a computer program that is executed by a processor to implement the resource loading method for a graphics processor as described in any of the above embodiments. This computer-readable storage medium may be included in the electronic device described in the above embodiments, or it may exist independently and not incorporated into the electronic device.
[0074] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to the embodiments of this application, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0075] Another aspect of this application provides a computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the resource loading method for the graphics processor provided in the various embodiments described above.
[0076] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, touch terminal, or network device, etc.) to execute the method according to the embodiments of this application.
[0077] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the embodiments disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein.
[0078] The above embodiments are merely illustrative of the principles and effects of this application and are not intended to limit this application. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of this application. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in this application should still be covered by the claims of this application.
Claims
1. A method for loading resources for a graphics processor, characterized in that, include: Create a worker thread and start a task waiting loop until the worker thread receives a wake-up request; Generate resource loading task information for the graphics processor and add the resource loading task information to the task queue; The worker thread obtains the resource loading task information from the task queue, allocates and loads temporary resources to the graphics processor according to the resource loading task information, and obtains the element fence value of the graphics processor when the resource loading is completed. When the resource loading is complete or the task queue is idle, the worker thread obtains the current fence value of the graphics processor according to a preset frequency. If it is confirmed that the resource loading is complete based on the current fence value and the element fence value, the temporary resource corresponding to the element fence value is destroyed. Based on the resource loading task information, temporary resources are allocated and loaded to the graphics processor, and the element fence value of the graphics processor is obtained when resource loading is complete, including: Read the resource file content according to the resource loading task information, and allocate temporary resources based on the basic resource information in the resource file content; Based on the aforementioned basic resource information, the preset resource data in the content of the resource file is read into the temporary resource; The temporary resources are loaded into the graphics processor's video memory. The element fence value of the graphics processor is obtained when the resource loading is complete. The temporary resources and the element fence value are packaged into the temporary resource container corresponding to the worker thread.
2. The resource loading method for a graphics processor according to claim 1, characterized in that, If it is confirmed that resource loading is complete based on the current fence value and the element fence value, then the temporary resource corresponding to the element fence value is destroyed, including: The worker thread iterates through each element fence value in the temporary resource container and compares the current fence value with each element fence value. If the current fence value is greater than or equal to the element fence value, and the resource loading is confirmed to be complete, then the temporary resource corresponding to the element fence value will be destroyed.
3. The resource loading method for a graphics processor according to any one of claims 1 to 2, characterized in that, Constructing worker threads includes: Based on the characteristics of the 3D rendering program, thread objects and worker threads are constructed, wherein the thread objects correspond one-to-one with the worker threads, and the start or stop of the worker threads is controlled by the thread objects.
4. The resource loading method for a graphics processor according to any one of claims 1 to 2, characterized in that, The wake-up request is generated in at least one of the following ways: The wake-up request is automatically generated at preset intervals. Upon receiving a request to invoke the worker thread, the wake-up request is generated.
5. The resource loading method for a graphics processor according to any one of claims 1 to 2, characterized in that, Before the worker thread retrieves the resource loading task information from the task queue, the method further includes: Determine the task existence status of the task queue; If the task exists in a state of non-existence, the worker thread is controlled to enter a waiting state until the task exists or the wake-up request is received. If the task exists, the resource loading task information is retrieved from the task queue.
6. The resource loading method for a graphics processor according to any one of claims 1 to 2, characterized in that, The main thread of the central processing unit is used to add the resource loading task information to the task queue, the worker thread is used to load the preset resource data from the hard disk to the temporary resource, and the graphics processor is used to copy the preset resource data from the temporary resource to the graphics processor's video memory. The main thread of the central processing unit, the worker thread, and the graphics processor can work simultaneously.
7. A resource loading device for a graphics processor, characterized in that, include: The building module is used to build worker threads and start a task waiting loop until the worker thread receives a wake-up request; The generation module is used to generate resource loading task information for the graphics processor and add the resource loading task information to the task queue. The loading module is used by the worker thread to obtain the resource loading task information from the task queue, allocate and load temporary resources to the graphics processor according to the resource loading task information, and obtain the element fence value of the graphics processor when the resource loading is completed. Specifically, it is used to read the content of the resource file according to the resource loading task information, allocate temporary resources based on the resource basic information in the resource file content, read the preset resource data in the resource file content into the temporary resources based on the resource basic information, load the temporary resources into the graphics processor video memory, obtain the element fence value of the graphics processor when the resource loading is completed, and package the temporary resources and the element fence value into the temporary resource container corresponding to the worker thread. The destruction module is used to obtain the current fence value of the graphics processor according to a preset frequency when the worker thread completes resource loading or when the task queue is idle. If it is confirmed that resource loading is complete based on the current fence value and the element fence value, the temporary resource corresponding to the element fence value is destroyed.
8. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the resource loading method of the graphics processor as described in any one of claims 1 to 6.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the resource loading method of the graphics processor as described in any one of claims 1 to 6.