Texture resource loading method and device, computer equipment and computer readable storage medium

Through reloading texture resources and adjusting memory layout, the problem of texture array occupies a lot of memory and video memory is solved, and resource optimization is achieved when device resources are limited, reducing loading time and usage.

CN119292687APending Publication Date: 2025-01-10BEIJING PERFECT WORLD SOFTWARE TECH DEV CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202311774615.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-21
Publication Date
2025-01-10

AI Technical Summary

Technical Problem

In game development, texture arrays occupy a lot of memory and video memory space when the game is running, and cannot handle a large number of high-resolution texture resources when the device resources are limited.

Method used

By reloading texture resources, the resource information of the texture array is obtained, the byte address range of each texture is relocated according to the resource information of the texture array, the memory layout of the texture array is determined, and the memory layout is used for memory allocation, and dynamic adjustment is made. Texture resolution to reduce memory and video memory usage.

Benefits of technology

When device resources are limited, reduce the memory and video memory usage of texture resources, reduce the loading time of texture resources, and optimize the storage space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119292687A_ABST
    Figure CN119292687A_ABST
Patent Text Reader

Abstract

The invention discloses a texture resource loading method and device, computer equipment and a computer readable storage medium, and relates to the technical field of computers.The method comprises the steps that in response to reloading of texture resources, resource information of a texture array is obtained, and repositioning the byte address range of each texture in the texture array according to the resource information of the texture array, determining the memory layout of the texture array, and performing traversal memory allocation on each texture in the texture array by using the memory layout of the texture array so as to reload the texture array according to the byte address range pointed by the traversal memory allocation. According to the scheme, the byte address range of each texture in the texture array is repositioned through reloading of the texture resources, so that the texture resolution in the texture array is dynamically adjusted according to hardware configuration, and part of pixel information in the texture array is cut off under the condition that the equipment resources are limited; the memory and video memory occupation of the texture resources is reduced, and the loading time of the texture resources is shortened.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a texture resource loading method, device, computer equipment and computer-readable storage medium. Background Art

[0002] In game development, texture resources occupy a large proportion of memory. As the game quality improves, the texture resolution also increases, resulting in a sharp increase in texture resources. On low-end and mid-range devices, high-resolution texture resources not only increase loading time, but also seriously occupy limited hardware space.

[0003] In related technologies, texture streaming, virtual texture and other technologies are usually used to optimize the memory usage of texture resources, thereby saving more memory space. However, the texture resource processing flow in the game development engine is only for texture type texture resources. The memory and video memory structure of texture array type texture resources cannot be dynamically adjusted when the game is running, so that the texture array takes up a lot of memory and video memory space when the game is running, and it is impossible to process a large number of high-resolution texture resources when the device resources are limited. Summary of the invention

[0004] In view of this, the present application provides a method and device for loading texture resources, the main purpose of which is to solve the problem that the texture array in the prior art occupies a large amount of memory and video memory space when the game is running, and cannot process a large amount of high-resolution texture resources when the device resources are limited.

[0005] According to a first aspect of the present application, a method for loading a texture resource is provided, comprising:

[0006] In response to reloading of the texture resource, obtaining resource information of the texture array;

[0007] Relocating the byte address range of each texture in the texture array according to the resource information of the texture array to determine the memory layout of the texture array;

[0008] The memory layout of the texture array is used to perform traversal memory allocation on each texture in the texture array, so as to reload the texture array according to the byte address range pointed to by the traversal memory allocation.

[0009] Furthermore, before acquiring resource information of the texture array in response to reloading the texture resource, the method further includes:

[0010] Get the newly added member variable of the texture array;

[0011] When the value of the newly added member variable changes, reloading of the texture resource is triggered.

[0012] Furthermore, when the value of the newly added member variable changes, reloading of the texture resource is triggered, including:

[0013] Receiving an array element passed in by the texture array, comparing the array element with the newly added member variable, so as to obtain a value change of the newly added member variable according to the comparison result;

[0014] If the value of the newly added member variable changes, reloading of the texture resource is triggered.

[0015] Further, in response to the reloading of the texture resource, obtaining the resource information of the texture array includes:

[0016] In response to the reloading of the texture resource, re-reading the texture data from the preset storage location through an asynchronous loading operation;

[0017] The read texture data is stored according to the set array format to obtain the resource information of the texture array.

[0018] Furthermore, the relocating the byte address range of each texture in the texture array according to the resource information of the texture array to determine the memory layout of the texture array includes:

[0019] Determine, according to the resource information of the texture array, a first occupied length of each texture in the input memory, wherein the first occupied length is the byte size of each texture before offset;

[0020] Calculate the second occupied length of each texture in the input memory according to the first occupied length, where the second occupied length is the byte size of the texture after the texture is offset;

[0021] The byte address range of each texture in the texture array is relocated using the first occupied length and the second occupied length to determine the memory layout of the texture array.

[0022] Further, determining the first occupied length of each texture in the input memory according to the resource information of the texture array includes:

[0023] According to the resource information of the texture array, the byte information occupied by each texture in the texture array is obtained, wherein the byte information is the byte size occupied by each texture mapped to all resolution levels;

[0024] Determine the first occupied length of each texture in the input memory according to the byte information occupied by each texture in the texture array;

[0025] Correspondingly, calculating the second occupied length of each texture in the input memory according to the first occupied length includes:

[0026] Determine pixel array information composed of texture mapping to each resolution level according to the byte information occupied by each texture in the texture array;

[0027] According to the attribute information of each texture, pixel information with a resolution level greater than a preset level is selected from the pixel array information as target pixel information to be intercepted;

[0028] The first occupied length and the target pixel information to be intercepted are subjected to difference calculation to obtain a second occupied length of each texture in the input memory.

[0029] Further, the relocating the byte address range of each texture in the texture array by using the first occupied length and the second occupied length to determine the memory layout of the texture array includes:

[0030] Determine a first adjustment byte address of each texture based on the initial byte address corresponding to the input memory by using the first occupied length and the second occupied length;

[0031] Based on the initial byte address corresponding to the output memory, a second adjusted byte address of each texture is synchronously generated;

[0032] According to the first adjustment byte address and the second adjustment byte address, the byte address range of each texture in the texture array is relocated to determine the memory layout of the texture array.

[0033] Further, relocating the byte address range of each texture in the texture array according to the first adjustment byte address and the second adjustment byte address to determine the memory layout of the texture array includes:

[0034] intercepting a byte range of the second occupied length in the input memory according to the first adjustment byte address;

[0035] The byte range of the second occupied length is copied to the position pointed to by the second adjusted byte address in the output memory to relocate the byte address range of each texture in the texture array and determine the memory layout of the texture array.

[0036] Furthermore, after relocating the byte address range of each texture in the texture array according to the first adjustment byte address and the second adjustment byte address to determine the memory layout of the texture array, the method further includes:

[0037] In the input memory, the first adjustment byte address is shifted rightward by a byte range of the first occupied length, so that the current address in the input memory is positioned at the first starting byte address of the next texture;

[0038] The second adjustment byte address is shifted rightwards in the output memory by a byte range of the second occupied length, so that the current address in the output memory is positioned at the second starting byte address of the next texture.

[0039] Furthermore, after relocating the byte address range of each texture in the texture array according to the resource information of the texture array to determine the memory layout of the texture array, the method further includes:

[0040] According to the memory layout of the texture array, the video memory layout of the texture array is determined, so as to release the unloaded texture array according to the video memory layout of the texture array.

[0041] According to a second aspect of the present application, a texture resource loading device is provided, comprising:

[0042] A first acquisition unit, configured to acquire resource information of a texture array in response to reloading of the texture resource;

[0043] A determination unit, configured to relocate the byte address range of each texture in the texture array according to the resource information of the texture array, and determine the memory layout of the texture array;

[0044] The loading unit is used to perform traversal memory allocation on each texture in the texture array by using the memory layout of the texture array, so as to reload the texture array according to the byte address range pointed to by the traversal memory allocation.

[0045] Furthermore, the device also includes:

[0046] A second acquisition unit, configured to acquire a newly added member variable of the texture array before acquiring resource information of the texture array in response to reloading of the texture resource;

[0047] The trigger unit is used to trigger the reloading of the texture resource when the value of the newly added member variable changes.

[0048] Furthermore, the trigger unit is specifically used to receive array elements transmitted from the texture array, compare the array elements with the newly added member variables, and obtain the numerical change of the newly added member variables according to the comparison results; if the numerical value of the newly added member variables changes, the reloading of the texture resources is triggered.

[0049] Furthermore, the first acquisition unit is specifically used to re-read texture data from a preset storage location through an asynchronous loading operation in response to reloading of texture resources; and store the read texture data according to a set array format to obtain resource information of the texture array.

[0050] Furthermore, the determining unit includes:

[0051] A determination module, used to determine a first occupied length of each texture in the input memory according to the resource information of the texture array, wherein the first occupied length is the byte size of each texture before offset;

[0052] A calculation module, used for calculating a second occupied length of each texture in the input memory according to the first occupied length, wherein the second occupied length is a byte size of the texture after the texture is offset;

[0053] A relocation module is used to relocate the byte address range of each texture in the texture array by using the first occupied length and the second occupied length to determine the memory layout of the texture array.

[0054] Further, the determination module is specifically used to obtain byte information occupied by each texture in the texture array according to the resource information of the texture array, wherein the byte information is the byte size occupied by each texture mapped to all resolution levels; and determine the first occupied length of each texture in the input memory according to the byte information occupied by each texture in the texture array;

[0055] Correspondingly, the calculation module is specifically used to determine the pixel array information composed of the texture mapping to each resolution level according to the byte information occupied by each texture in the texture array; select the pixel information with a resolution level greater than a preset level in the pixel array information as the target pixel information to be intercepted according to the attribute information of each texture; and perform a difference calculation between the first occupied length and the target pixel information to be intercepted to obtain the second occupied length of each texture in the input memory.

[0056] Furthermore, the relocation module is specifically used to determine the first adjustment byte address of each texture based on the initial byte address corresponding to the input memory by using the first occupied length and the second occupied length; synchronously generate the second adjustment byte address of each texture based on the initial byte address corresponding to the output memory; and relocate the byte address range of each texture in the texture array according to the first adjustment byte address and the second adjustment byte address to determine the memory layout of the texture array.

[0057] Furthermore, the relocation module is specifically used to intercept the byte range of the second occupied length in the input memory according to the first adjustment byte address; copy the byte range of the second occupied length to the position pointed to by the second adjustment byte address in the output memory, so as to relocate the byte address range of each texture in the texture array and determine the memory layout of the texture array.

[0058] Furthermore, the relocation module is specifically used to, after relocating the byte address range of each texture in the texture array according to the first adjustment byte address and the second adjustment byte address and determining the memory layout of the texture array, shift the first adjustment byte address to the right by the byte range of the first occupied length in the input memory so that the current address in the input memory is positioned to the first starting byte address of the next texture; and shift the second adjustment byte address to the right by the byte range of the second occupied length in the output memory so that the current address in the output memory is positioned to the second starting byte address of the next texture.

[0059] Furthermore, the device also includes:

[0060] A release unit is used to determine the video memory layout of the texture array according to the memory layout of the texture array after relocating the byte address range of each texture in the texture array according to the resource information of the texture array and determining the memory layout of the texture array, so as to release the unloaded texture array according to the video memory layout of the texture array.

[0061] According to a third aspect of the present application, a computer device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method described in the first aspect when executing the computer program.

[0062] According to a fourth aspect of the present application, a readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method described in the first aspect are implemented.

[0063] By means of the above technical scheme, the present application provides a method and device for loading texture resources. Compared with the existing method of loading texture resources using technologies such as texture streams and virtual textures, the present application obtains resource information of the texture array in response to the reloading of the texture resources, and then relocates the byte address range of each texture in the texture array according to the resource information of the texture array, determines the memory layout of the texture array, and uses the memory layout of the texture array to traverse the memory allocation for each texture in the texture array, so as to reload the texture array according to the byte address range pointed to by the traversed memory allocation. The whole process relocates the byte address range of each texture in the texture array by reloading the texture resources, so as to dynamically adjust the texture resolution in the texture array according to the hardware configuration, thereby cutting off part of the pixel information in the texture array when the device resources are limited, reducing the memory and video memory occupation of the texture resources, and reducing the loading time of the texture resources.

[0064] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0065] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0066] Figure 1 It is a flowchart of a texture resource loading method provided in an embodiment of the present application;

[0067] Figure 2 yes Figure 1 Schematic diagram of the process before step 101;

[0068] Figure 3 yes Figure 1 A schematic flow chart of a specific implementation of step 101;

[0069] Figure 4 yes Figure 1 Schematic diagram of the process of step 102;

[0070] Figure 5 It is a flowchart of a method for loading texture resources provided in an embodiment of the application;

[0071] Figure 6 It is a structural schematic diagram of a texture resource loading device provided in an embodiment of the present application;

[0072] Figure 7 It is a schematic diagram of the device structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0073] Now the content of the present invention will be discussed with reference to several exemplary embodiments. It should be understood that these embodiments are discussed only to enable those skilled in the art to better understand and thus implement the content of the present invention, rather than implying any limitation on the scope of the present invention.

[0074] As used herein, the term "including" and variations thereof are to be interpreted as open-ended terms meaning "including but not limited to." The term "based on" is to be interpreted as "based, at least in part, on." The terms "one embodiment" and "an embodiment" are to be interpreted as "at least one embodiment." The term "another embodiment" is to be interpreted as "at least one other embodiment."

[0075] Related technologies usually use texture streaming, virtual texture and other technologies to optimize the memory usage of texture resources, thereby saving more memory space. However, the texture resource processing flow in the game development engine is only for texture type texture resources. The memory and video memory structure of texture array type texture resources cannot be dynamically adjusted when the game is running, so the texture array takes up a lot of memory and video memory space when the game is running, and it is impossible to process a large number of high-resolution texture resources when the device resources are limited.

[0076] In order to solve this problem, this embodiment provides a method for loading texture resources, such as Figure 1 As shown, the method comprises the following steps:

[0077] 101. In response to reloading of texture resources, obtain resource information of the texture array.

[0078] Objects in the real world are made up of different materials and may have different patterns on their surfaces. These characteristics cannot be represented by simple planes in the 3D game world. In order to better simulate real objects in the 3D world, texture resources can be used to draw images similar to the surface of a certain material through pictures, and the pictures can be attached to the plane to form a surface similar to real objects.

[0079] Texture arrays are a type of texture used in computer graphics, including two-dimensional texture arrays and three-dimensional texture arrays. Texture arrays are equivalent to arrays composed of different types of textures. Each texture is a layer in the texture array. The textures of each layer have the same size and pixel format, but can contain different image data. When using texture arrays, different layers can be accessed through indexes, so that different image data can be easily switched and used during the rendering process. Texture arrays are usually used to process multiple similar images at the same time, for example, rendering animation frames of multiple characters in a game or rendering textures of multiple terrains. Texture arrays can be used to store multiple image data in one texture object, thereby reducing memory overhead and the number of objects called for rendering.

[0080] In this embodiment, texture resources are stored in memory in the form of an array. The size of the texture memory depends on the resolution and pixel format of the texture. Textures with higher resolutions and complex pixel formats will use more memory space. For example, a 1024×1024 pixel RGB texture will occupy 1024×1024×3 bytes of memory space.

[0081] Normally, during graphics rendering, a computer can load texture arrays from texture memory. However, in some scenarios, texture resources may be reloaded. For example, when the scene contains high-resolution textures that exceed the processing capacity of the memory, the loaded texture array may appear blurry or not loaded at all. This indicates that there are textures in the loading of texture resources, which may trigger the reloading of texture resources. For example, when a program is started or restarted, all texture resources are usually reloaded to ensure that the texture resources can be used for subsequent rendering operations. For example, when texture resources are lost or inaccessible in memory due to insufficient memory, video memory overflow, device reset, etc., texture resources need to be reloaded. For example, in some cases, in order to save memory or optimize performance, some texture resources may be released. When these released texture resources need to be used, the corresponding texture resources can be reloaded. For example, when switching between different levels or scenes in the game, it is necessary to switch between different texture resources, and texture resources may need to be reloaded.

[0082] The executor of this embodiment can be a texture resource loading device or equipment, which can be configured on the game server or client. During the texture resource reloading process, the resource information of the texture array is obtained, and the byte address range of the texture array is relocated according to the resource information of the texture array, so as to reload the texture array through the relocated byte address range, thereby improving the loading effect of the texture resource.

[0083] 102. Relocate the byte address range of each texture in the texture array according to the resource information of the texture array to determine the memory layout of the texture array.

[0084] It is understandable that, during the reloading process of the texture resource, the texture file can be re-read from the preset storage location through an asynchronous loading operation, and the resource information of the texture array read can be stored, where the resource information of the texture array includes but is not limited to the pixel array composed of the texture mapping to each resolution level, texture attributes, texture format, etc. The occupancy information of the texture in the memory space can be determined through the resource information of the texture array, and the memory layout of the texture array can be determined according to the occupancy information of the texture in the memory.

[0085] Considering that the occupancy information of the texture in the memory mainly includes the address occupation interval of the texture mapped to the pixel array composed of each resolution level, specifically in the process of determining the memory layout of the texture array, the byte address range of each texture in the texture array can be relocated within the occupation interval. Here, the pixel information of a set length can be cut off in the occupied space of the pixel array composed of the texture mapped to each resolution level. The pixel information of the set length here can be the pixel information of the high-resolution level in the texture array, and can also be the pixel information of the larger texture size in the texture array. The byte address range of each texture is relocated according to the remaining address interval in the address occupation interval after cutting, and the memory layout of the texture array is determined by relocation.

[0086] It should be noted that the memory layout of the texture array here is not the memory layout of the initial texture array, but the actual memory layout of the texture array is determined by reloading the texture resources and performing secondary processing of the memory space of the texture according to the resource information of the texture array. The actual memory layout reduces the memory space reserved for each texture by dynamically adjusting the byte address range of each texture in the texture array, thereby achieving storage space optimization.

[0087] 103. Perform traversal memory allocation on each texture in the texture array using the memory layout of the texture array, so as to reload the texture array according to the byte address range pointed to by the traversal memory allocation.

[0088] In this embodiment, the byte address range of each texture in the texture array can be determined specifically through the memory layout of the texture array, and then continuous memory space is allocated in the memory space according to the byte address range of each texture to store the texture array. This can be achieved by using the memory allocation function provided by the graphics interface or manually allocating memory. The texture array is further stored in the memory space in a certain order according to the memory layout rules. Accordingly, when the texture is reloaded, it is necessary to read the texture array from the memory space and reload the texture array according to the address byte range pointed to by the traversal memory allocation.

[0089] Compared with the current existing method of loading texture resources using technologies such as texture streaming and virtual texture, the texture resource loading method provided in the embodiment of the present application obtains the resource information of the texture array in response to the reloading of the texture resources, and then relocates the byte address range of each texture in the texture array according to the resource information of the texture array, determines the memory layout of the texture array, and uses the memory layout of the texture array to traverse the memory allocation for each texture in the texture array, so as to reload the texture array according to the byte address range pointed to by the traversed memory allocation. The whole process relocates the byte address range of each texture in the texture array by reloading the texture resources, so as to dynamically adjust the texture resolution in the texture array according to the hardware configuration, thereby cutting off part of the pixel information in the texture array when the device resources are limited, reducing the memory and video memory usage of the texture resources, and reducing the loading time of the texture resources.

[0090] In actual application scenarios, reloading of texture resources may involve operations such as file reading, memory allocation, and data transfer. In order to illustrate the triggering mechanism for reloading texture resources, further, such as Figure 2 As shown, before step 101, the method further includes the following steps:

[0091] 201. Get the newly added member variable of the texture array.

[0092] 202. When the value of the newly added member variable changes, reloading of the texture resource is triggered.

[0093] It is understandable that the content of texture resources can be changed according to actual needs. For example, the image data in the texture array is modified, the texture parameters are updated, etc., and the corresponding texture array will also have new member variables. At this time, the newly added member variables can be used to detect whether the content of the texture resource has changed. If the content has changed, the texture resource may need to be reloaded to reflect the change in the texture resource.

[0094] When array elements are passed into the texture array, content changes of the texture resources can be detected by comparing newly added variable members. Specifically, the array elements passed into the texture array can be received, and the array elements can be compared with the newly added member variables to obtain the value changes of the newly added member variables based on the comparison results. If the value of the newly added member variables changes, the reloading of the texture resources is triggered.

[0095] Considering that the video memory corresponding to the texture array will be released and recreated during the reloading process of the texture resource, the texture data is re-read from the preset storage location through the asynchronous loading operation. Specifically, Figure 3 As shown, step 101 in the above method may further include the following steps:

[0096] 301. In response to reloading of a texture resource, re-read texture data from a preset storage location through an asynchronous loading operation.

[0097] 302. Store the read texture data according to a set array format to obtain resource information of the texture array.

[0098] It should be noted that if there is a problem with the texture array, the loading method can be further called to re-read the texture data from the preset storage location through the loading method. The preset storage location here can be any storage space in the hard disk file or any storage space on the network.

[0099] Specifically, an asynchronous loading task can be created in the program to load the texture file in the background thread. This can be achieved by using multi-threaded programming or asynchronous programming models. Then, the path of the texture file to be loaded is passed to the asynchronous loading task. The asynchronous loading task will open the specified texture file and read the content of the texture file. Then, according to the format and structure of the texture file, the texture data is parsed and the required texture information is extracted, such as the width, height, pixel format, etc. of the image. This can be achieved by using the corresponding parsing algorithm and data structure. Finally, the parsed texture information is stored as the resource information of the texture array in the preset position of the texture memory.

[0100] Specifically, Figure 4 As shown, step 102 in the above method may further include the following steps:

[0101] 401. Determine a first occupied length of each texture in an input memory according to resource information of the texture array.

[0102] 402. Calculate a second occupied length of each texture in the input memory according to the first occupied length.

[0103] 403. Relocate the byte address range of each texture in the texture array by using the first occupied length and the second occupied length to determine the memory layout of the texture array.

[0104] Among them, the input memory is a memory area used to store input data. When texture resources need to be read from an external source (for example, a file, a network, etc.), these texture resources will be read into the input memory, and then the program can read the texture resources from the input memory for processing.

[0105] In this embodiment, the first occupied length is the byte size of each texture before offset. Specifically, the byte information occupied by each texture in the texture array can be obtained according to the resource information of the texture array, and the first occupied length of each texture in the input memory can be determined according to the byte information occupied by each texture in the texture array. In computer graphics, textures are usually displayed in a reduced size at a distance and in an enlarged size at a close distance. When the texture is displayed in a reduced size, the details of the original texture may be lost, causing the image to look blurred or distorted. In order to solve this problem, the texture mapping technology can generate a series of textures of different resolution levels from the original texture, and each resolution is called a resolution level. Here, the byte information is the byte size occupied by each texture mapped to all resolution levels. The resolution levels represent different levels of detail of the texture from high to low, wherein a resolution level of 0 represents the original texture, a resolution level of 1 represents half the resolution of the original texture, and so on. When the rendering engine selects the appropriate resolution level according to the distance of the object, the rendering performance can be improved and the distortion can be reduced.

[0106] In this embodiment, the second occupied length is the byte size of the texture after the offset. Specifically, the pixel array information of the texture mapped to each resolution level can be determined according to the byte information occupied by each texture in the texture array. According to the attribute information of each texture, the pixel information with a resolution level greater than the preset level is selected in the pixel array information as the target pixel information to be intercepted, and the first occupied length and the target pixel information to be intercepted are calculated by difference, so as to obtain the second occupied length of each texture in the input memory. Here, the attribute information of the texture may include the length and format of the texture. In the process of selecting the target pixel information to be intercepted, the width and height of the texture at each resolution level can be calculated according to the relationship between the original size of the texture and each resolution level. Usually, the size of each resolution level is half of the previous resolution level. Then, the number of resolution levels is cut off as needed, and the number of pixels to be cut off is calculated. For each resolution level, the target pixel information to be cut off is equal to the width of the level multiplied by the height. Finally, the new texture array size is calculated according to the target pixel information to be cut off as needed. The new texture array size is equal to the original texture array size minus the target pixel information to be cut off, so as to update the pixel array information of the texture mapped to each resolution level.

[0107] The output memory corresponding to the input memory is a memory area used to store output data. When the program needs to send texture resources to an external target (for example, a file, a network, etc.), these texture resources will be written to the output memory, and then the texture resources will be sent to the target location from the output memory. By using input memory and output memory, the reading and writing efficiency of texture resources can be improved. By storing texture resources in input memory and output memory first, frequent access to external sources or targets can be reduced, thereby improving the transmission efficiency of texture resources.

[0108] Specifically, in the process of determining the memory layout of the texture array, the first occupied length and the second occupied length can be used to determine the first adjustment byte address of each texture based on the initial byte address corresponding to the input memory, where the first adjustment address is equivalent to the starting byte address before the texture is relocated, and the second adjustment byte address of each texture is synchronously generated based on the initial byte address corresponding to the output memory, where the first adjustment address is equivalent to the starting byte address of the texture relocation, and the byte address range of each texture in the texture array is relocated according to the first adjustment byte address and the second adjustment byte address to determine the memory layout of the texture array. By relocating the byte address range of the texture, the memory layout of the texture array can be changed, and the texture address range remaining after the target pixel information is cut off in the input memory is copied to the output memory.

[0109] In one feasible implementation, a byte range of a second occupied length can be intercepted in the input memory according to the first adjustment byte address, and the byte range of the second occupied length can be copied to the position pointed to by the second adjustment byte address in the output memory, so as to relocate the byte address range of each texture in the texture array and determine the memory layout of the texture array.

[0110] It can be understood that each texture in the texture array will go through the relocation process of the byte address range. After the current texture completes the relocation of the byte address range, the first adjustment byte address is offset to the right by the byte range of the first occupied length in the input memory, so that the current address in the input memory is positioned to the first starting byte address of the next texture, where the first starting address is the starting byte address of the next texture in the input memory before relocation; accordingly, the second adjustment byte address is offset to the right by the byte range of the second occupied length in the output memory, so that the current address in the output memory is positioned to the second starting byte address of the next texture, where the second starting address is the starting byte address of the next texture in the output memory after relocation.

[0111] Exemplarily, in the texture array, the byte size of each texture before offset is obtained, recorded as srclmgSize, and the byte size of each texture after offset is calculated accordingly, recorded as dstlmgSize, and the texture array is traversed to obtain the initial byte address inbuf of each texture in the input memory and the initial byte address outbuf of each texture in the output memory, and a second adjusted byte address dst of the copy target byte is synchronously generated in the output memory, and the second adjusted byte address dst is equivalent to the tracking address for relocating the byte address range of each texture, and the tracking address dst points to the same position of outbuf, through the formula inbuf+srclmg Size-dstlmgSize can obtain the first adjustment byte address src of each texture in the input memory. By copying the byte segment with a length of srclmgSize starting from the first byte adjustment address src to the position pointed to by the current second byte adjustment address dst in the output memory, the byte address range of each texture can be relocated. The first adjustment byte address src in the input memory is further offset to the right by srclmgSize to align it to the initial position of the next texture in the input memory. At the same time, the second adjustment byte dst in the output memory is offset to the right by dstlmgSize to align it to the initial position of the next texture in the output memory.

[0112] Furthermore, after determining the memory layout of the texture array, each texture in the texture array is traversed to perform memory allocation until all textures in the texture array are traversed and memory allocation is completed. The byte address range of each texture is relocated through the memory allocation process to load the texture array.

[0113] For example, for a texture array containing several 2D textures, the size of each 2D texture is srcImgSize; after cutting off the first several resolution levels of pixels in each 2D texture, the size of a single texture is dstImgSize. The section between srcImgSize and dstImgSize is the pixel section that is cut off from each texture. Finally, the reserved parts of each 2D texture are pieced together, which can optimize the storage space compared to the initial state.

[0114] After step 102, the method further includes the following step: determining a video memory layout of the texture array according to the memory layout of the texture array, so as to release the unloaded texture array according to the video memory layout of the texture array.

[0115] Specifically in the memory layout of the texture array, each texture has a different format, for example, RGB, RGBA, grayscale, etc. Different formats will affect the bytes occupied by each pixel in each texture, thereby affecting the video memory layout. Each texture also has a different size. The size of the texture determines the number of elements in the texture array. Usually, the elements in the texture array are arranged in a certain order, for example, from left to right, from top to bottom.

[0116] Considering that data in the video memory usually needs to be stored in a certain byte alignment, for example, some video memories require that the starting address of texture data must be 4-byte aligned, which may result in certain padding bytes in the video memory layout. The video memory requires that the texture set the row order, which requires the pixel rows of the texture array in the video memory to be adjusted. Specifically, in the process of determining the video memory layout of the texture array, the number of bytes occupied by each pixel in the texture array can be determined according to the format of each texture in the memory layout, and the number of bytes occupied by each pixel in the texture array is calculated according to the size of each texture in the memory layout and the number of bytes occupied by each pixel. According to the alignment requirements of the video memory, the number of bytes required to be filled in each row is calculated, and the total number of bytes occupied by the texture array in the video memory is calculated according to the number of bytes in each row and the number of bytes required to be filled in each row. According to the total number of bytes, the starting address and arrangement of the texture array in the video memory are determined. It should be noted that different graphics cards and graphics interfaces may have different requirements for the video memory layout. Therefore, in practical applications, the video memory layout of the texture array needs to be determined according to the specific hardware and image interface.

[0117] In actual application scenarios, the specific texture resource loading process is as follows Figure 5As shown, firstly, a newly added member variable of the texture array is obtained. When the value of the newly added member variable changes, the asynchronous read callback function is called to reload the texture resource, the byte size before / after the offset of each texture in the texture resource is calculated, all textures in the texture array are traversed, and the second adjustment byte address is synchronously generated based on the initial byte address corresponding to the output memory, and the first adjustment byte address of the current texture is determined based on the initial address byte corresponding to the input memory. Starting from the first adjustment byte address in the input memory, a specified number of byte address ranges are copied to the position pointed to by the second adjustment byte address in the output memory, and finally the first adjustment byte in the input memory is moved. The node address and the second adjustment byte address in the mobile output memory are moved to the initial position of the next texture, and it is determined whether there is a next texture in the texture array. If so, the second adjustment byte address of the next texture is synchronously generated based on the initial byte address corresponding to the output memory to perform the byte address range relocation process for the next texture. Otherwise, the memory layout of the texture array is determined according to the byte address range of each texture in the texture array after relocation, and the memory layout is used to traverse the memory allocation. The texture of the texture array is reloaded according to the byte address range pointed to by the traversed memory allocation, and the video memory is reloaded using the memory layout to release unnecessary texture resources.

[0118] Further, as Figure 1-Figure 5 The specific implementation of the method, the embodiment of the present application provides a texture resource loading device, such as Figure 6 As shown, the device includes: a first acquiring unit 51, a determining unit 52, and a loading unit 53.

[0119] A first acquisition unit 51 is used to acquire resource information of a texture array in response to reloading of the texture resource;

[0120] A determination unit 52, configured to relocate the byte address range of each texture in the texture array according to the resource information of the texture array, and determine the memory layout of the texture array;

[0121] The loading unit 53 is used to perform traversal memory allocation on each texture in the texture array by using the memory layout of the texture array, so as to reload the texture array according to the byte address range pointed to by the traversal memory allocation.

[0122] Compared with the current existing method of loading texture resources using technologies such as texture streaming and virtual texture, the texture resource loading device provided in the embodiment of the present application obtains the resource information of the texture array in response to the reloading of the texture resources, and then relocates the byte address range of each texture in the texture array according to the resource information of the texture array, determines the memory layout of the texture array, and uses the memory layout of the texture array to traverse the memory allocation for each texture in the texture array, so as to reload the texture array according to the byte address range pointed to by the traversed memory allocation. The entire process relocates the byte address range of each texture in the texture array by reloading the texture resources, so as to dynamically adjust the texture resolution in the texture array according to the hardware configuration, thereby cutting off part of the pixel information in the texture array when the device resources are limited, reducing the memory and video memory usage of the texture resources, and reducing the loading time of the texture resources.

[0123] In a specific application scenario, the device further includes:

[0124] A second acquisition unit, configured to acquire a newly added member variable of the texture array before acquiring resource information of the texture array in response to reloading of the texture resource;

[0125] The trigger unit is used to trigger the reloading of the texture resource when the value of the newly added member variable changes.

[0126] In a specific application scenario, the trigger unit is specifically used to receive array elements passed in by the texture array, compare the array elements with the newly added member variables, and obtain the numerical changes of the newly added member variables according to the comparison results; if the numerical changes of the newly added member variables occur, the reloading of the texture resources is triggered.

[0127] In a specific application scenario, the first acquisition unit is specifically used to re-read texture data from a preset storage location through an asynchronous loading operation in response to reloading of texture resources; and store the read texture data according to a set array format to obtain resource information of the texture array.

[0128] In a specific application scenario, the determining unit includes:

[0129] A determination module, used to determine a first occupied length of each texture in the input memory according to the resource information of the texture array, wherein the first occupied length is the byte size of each texture before offset;

[0130] A calculation module, used for calculating a second occupied length of each texture in the input memory according to the first occupied length, wherein the second occupied length is a byte size of the texture after the texture is offset;

[0131] A relocation module is used to relocate the byte address range of each texture in the texture array by using the first occupied length and the second occupied length to determine the memory layout of the texture array.

[0132] In a specific application scenario, the determination module is specifically used to obtain the byte information occupied by each texture in the texture array according to the resource information of the texture array, wherein the byte information is the byte size occupied by each texture mapped to all resolution levels; and determine the first occupied length of each texture in the input memory according to the byte information occupied by each texture in the texture array;

[0133] Correspondingly, the calculation module is specifically used to determine the pixel array information composed of the texture mapping to each resolution level according to the byte information occupied by each texture in the texture array; select the pixel information with a resolution level greater than a preset level in the pixel array information as the target pixel information to be intercepted according to the attribute information of each texture; and perform a difference calculation between the first occupied length and the target pixel information to be intercepted to obtain the second occupied length of each texture in the input memory.

[0134] In a specific application scenario, the relocation module is specifically used to use the first occupied length and the second occupied length to determine the first adjustment byte address of each texture based on the initial byte address corresponding to the input memory; based on the initial byte address corresponding to the output memory, synchronously generate the second adjustment byte address of each texture; according to the first adjustment byte address and the second adjustment byte address, relocate the byte address range of each texture in the texture array to determine the memory layout of the texture array.

[0135] In a specific application scenario, the relocation module is further used to intercept the byte range of the second occupied length in the input memory according to the first adjustment byte address; copy the byte range of the second occupied length to the position pointed to by the second adjustment byte address in the output memory, so as to relocate the byte address range of each texture in the texture array and determine the memory layout of the texture array.

[0136] In a specific application scenario, the relocation module is further used to relocate the byte address range of each texture in the texture array according to the first adjustment byte address and the second adjustment byte address, and after determining the memory layout of the texture array, offset the first adjustment byte address to the right by the byte range of the first occupied length in the input memory so that the current address in the input memory is positioned to the first starting byte address of the next texture; and offset the second adjustment byte address to the right by the byte range of the second occupied length in the output memory so that the current address in the output memory is positioned to the second starting byte address of the next texture.

[0137] In a specific application scenario, the device further includes:

[0138] A release unit is used to determine the video memory layout of the texture array according to the memory layout of the texture array after relocating the byte address range of each texture in the texture array according to the resource information of the texture array and determining the memory layout of the texture array, so as to release the unloaded texture array according to the video memory layout of the texture array.

[0139] It should be noted that for other corresponding descriptions of the functional units involved in the texture resource loading device provided in this embodiment, reference can be made to Figure 1-Figure 5 The corresponding description in will not be repeated here.

[0140] Based on the above Figure 1-Figure 5 The method shown in the embodiment of the present application accordingly provides a storage medium on which a computer program is stored, and when the program is executed by a processor, the above-mentioned Figure 1-Figure 5 The texture resource loading method shown.

[0141] Based on this understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each implementation scenario of the present application.

[0142] Based on the above Figure 1-Figure 5 The method shown, and Figure 6 In order to achieve the above-mentioned purpose, the embodiment of the present application also provides a physical device for loading texture resources, which can be a computer, a smart phone, a tablet computer, a smart watch, a server, or a network device, etc. The physical device includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to achieve the above-mentioned Figure 1-Figure 5 The texture resource loading method shown.

[0143] Optionally, the physical device may also include a user interface, a network interface, a camera, a radio frequency (RF) circuit, a sensor, an audio circuit, a WI-FI module, etc. The user interface may include a display, an input unit such as a keyboard, etc., and the optional user interface may also include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), etc.

[0144] In an exemplary embodiment, see Figure 7 The physical device includes a communication bus, a processor, a memory and a communication interface, and may also include an input / output interface and a display device, wherein each functional unit can communicate with each other through the bus. The memory stores a computer program, and the processor is used to execute the program stored in the memory and execute the texture resource loading method in the above embodiment.

[0145] Those skilled in the art will appreciate that the physical device structure for loading a texture resource provided in this embodiment does not constitute a limitation on the physical device, and may include more or fewer components, or a combination of certain components, or different arrangements of components.

[0146] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages the hardware and software resources of the physical device for the store search information processing, and supports the operation of the information processing program and other software and / or programs. The network communication module is used to realize the communication between the components inside the storage medium, and the communication with other hardware and software in the physical device for information processing.

[0147] Through the description of the above implementation methods, those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform, or by hardware. By applying the technical solution of the present application, compared with the current existing methods, the present application relocates the byte address range of each texture in the texture array by reloading the texture resources, so as to dynamically adjust the texture resolution in the texture array according to the hardware configuration, thereby cutting off part of the pixel information in the texture array when the device resources are limited, reducing the memory and video memory usage of the texture resources, and reducing the loading time of the texture resources.

[0148] Those skilled in the art will appreciate that the accompanying drawings are only schematic diagrams of a preferred implementation scenario, and the modules or processes in the accompanying drawings are not necessarily necessary for implementing the present application. Those skilled in the art will appreciate that the modules in the devices in the implementation scenario can be distributed in the devices of the implementation scenario according to the description of the implementation scenario, or can be changed accordingly and located in one or more devices different from the present implementation scenario. The modules of the above-mentioned implementation scenario can be combined into one module, or can be further split into multiple submodules.

[0149] The above serial numbers of this application are only for description and do not represent the advantages and disadvantages of the implementation scenarios. The above disclosure is only a few specific implementation scenarios of this application, but this application is not limited to them, and any changes that can be thought of by technicians in this field should fall within the scope of protection of this application.

Claims

1. A method for loading texture resources, characterized in that: include: In response to reloading of the texture resource, obtaining resource information of the texture array; Relocating the byte address range of each texture in the texture array according to the resource information of the texture array to determine the memory layout of the texture array; The memory layout of the texture array is used to perform traversal memory allocation on each texture in the texture array, so as to reload the texture array according to the byte address range pointed to by the traversal memory allocation.

2. The method according to claim 1, characterized in that Before acquiring resource information of the texture array in response to reloading the texture resource, the method further includes: Get the newly added member variable of the texture array; When the value of the newly added member variable changes, reloading of the texture resource is triggered.

3. The method according to claim 2, characterized in that When the value of the newly added member variable changes, reloading of the texture resource is triggered, including: Receiving an array element passed in by the texture array, comparing the array element with the newly added member variable, so as to obtain a value change of the newly added member variable according to the comparison result; If the value of the newly added member variable changes, reloading of the texture resource is triggered.

4. The method according to claim 1, characterized in that The step of obtaining resource information of a texture array in response to reloading the texture resource comprises: In response to the reloading of the texture resource, re-reading the texture data from the preset storage location through an asynchronous loading operation; The read texture data is stored according to the set array format to obtain the resource information of the texture array.

5. The method according to claim 1, characterized in that The step of relocating the byte address range of each texture in the texture array according to the resource information of the texture array to determine the memory layout of the texture array includes: Determine, according to the resource information of the texture array, a first occupied length of each texture in the input memory, wherein the first occupied length is the byte size of each texture before offset; Calculate the second occupied length of each texture in the input memory according to the first occupied length, where the second occupied length is the byte size of the texture after the texture is offset; The byte address range of each texture in the texture array is relocated using the first occupied length and the second occupied length to determine the memory layout of the texture array.

6. The method according to claim 5, characterized in that Determining a first occupied length of each texture in the input memory according to the resource information of the texture array includes: According to the resource information of the texture array, the byte information occupied by each texture in the texture array is obtained, wherein the byte information is the byte size occupied by each texture mapped to all resolution levels; Determine the first occupied length of each texture in the input memory according to the byte information occupied by each texture in the texture array; Correspondingly, calculating the second occupied length of each texture in the input memory according to the first occupied length includes: Determine pixel array information composed of texture mapping to each resolution level according to the byte information occupied by each texture in the texture array; According to the attribute information of each texture, pixel information with a resolution level greater than a preset level is selected from the pixel array information as target pixel information to be intercepted; The first occupied length and the target pixel information to be intercepted are difference calculated to obtain a second occupied length of each texture in the input memory.

7. The method according to claim 5, characterized in that The step of relocating the byte address range of each texture in the texture array by using the first occupied length and the second occupied length to determine the memory layout of the texture array includes: Determine a first adjustment byte address of each texture based on the initial byte address corresponding to the input memory by using the first occupied length and the second occupied length; Based on the initial byte address corresponding to the output memory, a second adjusted byte address of each texture is synchronously generated; According to the first adjustment byte address and the second adjustment byte address, the byte address range of each texture in the texture array is relocated to determine the memory layout of the texture array.

8. The method according to claim 7, characterized in that The step of relocating the byte address range of each texture in the texture array according to the first adjustment byte address and the second adjustment byte address to determine the memory layout of the texture array includes: intercepting a byte range of the second occupied length in the input memory according to the first adjustment byte address; The byte range of the second occupied length is copied to the location pointed to by the second adjustment byte address in the output memory, so as to determine the memory layout of the texture array in the texture array.

9. The method according to claim 7, characterized in that: After relocating the byte address range of each texture in the texture array according to the first adjustment byte address and the second adjustment byte address to determine the memory layout of the texture array, the method further includes: In the input memory, the first adjustment byte address is shifted rightward by a byte range of the first occupied length, so that the current address in the input memory is positioned at the first starting byte address of the next texture; The second adjustment byte address is shifted rightwards in the output memory by a byte range of the second occupied length, so that the current address in the output memory is positioned at the second starting byte address of the next texture.

10. The method according to any one of claims 1 to 9, characterized in that After relocating the byte address range of each texture in the texture array according to the resource information of the texture array to determine the memory layout of the texture array, the method further includes: According to the memory layout of the texture array, the video memory layout of the texture array is determined, so as to release the unloaded texture array according to the video memory layout of the texture array.

11. A texture resource loading device, characterized in that: include: An acquisition unit, configured to acquire resource information of a texture array in response to reloading of the texture resource; A determination unit, configured to relocate the byte address range of each texture in the texture array according to the resource information of the texture array, and determine the memory layout of the texture array; The loading unit is used to perform traversal memory allocation on each texture in the texture array by using the memory layout of the texture array, so as to reload the texture array according to the byte address range pointed to by the traversal memory allocation.

12. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the texture resource loading method according to any one of claims 1 to 10 are implemented.

13. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the texture resource loading method according to any one of claims 1 to 10 are implemented.

Citation Information

Cited By

  • Graphics processor, texture loading method, texture processing unit, equipment and medium

    CN121169664A