Alu, processor, chip, device and texel index calculation method
By designing the ALU and using comparators, dividers, and adders to reduce the bit width of the computational unit for converting texture coordinates to texel indices, the problem of excessively large computational unit bit width in existing technologies is solved, and efficient texel index computation is achieved.
Patent Information
- Application Number
- CN202511431359.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-09
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2045-10-09
AI Technical Summary
Existing technologies require large bit widths in the computational units during the conversion from texture coordinates to texel indices, resulting in complex physical implementation, high area and power consumption overhead, and difficulty in meeting the needs of high-precision computing.
An ALU design is adopted, including a first comparator, a first divider, a first adder, and a texel adjustment unit. By determining the relationship between the integer part of the input texture coordinates and the maximum offset, the bit width of the calculation unit is reduced, and the target texel index is accurately determined in combination with the addressing mode.
It achieves high-precision calculation while reducing computational overhead, simplifying timing and area design, and improving the efficiency of computing units.
Smart Images

Figure CN120894222B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of chip technology, and in particular to an ALU (Arithmetic Logic Unit), processor, chip, device, and texel index calculation method. Background Technology
[0002] Texture coordinates are a coordinate system in computer graphics used to locate the mapping of textures on the surface of an object. The coordinates indicate from which position in the texture image the object's vertices should read data. The texel index is used to precisely locate texels within the texture image.
[0003] In related technologies, the conversion from texture coordinates to texel indices is typically implemented in the Texture Processing Unit (TPU) of the Texture Coordinate ALU. The general calculation formula is: texel_index = input_coord * texture size + offset, where input_coord is the input texture coordinate in floating-point format, texture size is the texture size, and offset is the configured or calculated offset, which typically includes sampling offset, coordinate offset, pixel offset, etc. Offset is usually a series of non-normalized fixed-point numbers. The output texel index is in signed fixed-point format.
[0004] The above calculation process involves data format conversion and alignment, along with precision calculation and rounding. The calculation units used, such as adders, multipliers, and dividers, have relatively large bit widths, making their physical implementation complex. Summary of the Invention
[0005] This application provides an ALU, processor, chip, device, and texel index calculation method. The technical solution provided by this application is as follows:
[0006] According to one aspect of the embodiments of this application, an ALU is provided, the ALU comprising: a first comparator, a first divider, a first adder, and a texel adjustment unit;
[0007] The first comparator is used to determine a first value, which is determined based on the smaller of the integer part of the input texture coordinates and the maximum offset;
[0008] The first divider is used to calculate the ratio between the input offset and the first divisor to obtain the first ratio, wherein the input offset is used to indicate the offset of the texel relative to at least one texture image, and the first divisor is determined based on the texture size or the maximum offset, wherein the texture size is used to indicate the size of the texture image, and the first ratio includes the quotient and the remainder.
[0009] The first adder is used to calculate the sum of the quotient of the first ratio, the first value, and the second value to obtain a first calculation result. The second value is determined based on the remainder of the first ratio and the decimal part of the input texture coordinates.
[0010] The texel adjustment unit is used to determine the target texel index corresponding to the input texture coordinates based on at least one of the first calculation result and the addressing mode.
[0011] According to one aspect of the embodiments of this application, a processor is provided, the processor including the ALU described above.
[0012] According to one aspect of the embodiments of this application, a chip product is provided, the chip product including a processor, the processor including the above-described ALU.
[0013] According to one aspect of the embodiments of this application, a computer device is provided, the computer device including a processor, the processor including the ALU described above.
[0014] According to one aspect of the embodiments of this application, a texel index calculation method applied to an ALU is provided, the ALU comprising: a first comparator, a first divider, a first adder, and a texel adjustment unit; the method comprising:
[0015] The first comparator determines a first value, which is based on the smaller of the integer part of the input texture coordinates and the maximum offset;
[0016] The first divider calculates the ratio between the input offset and the first divisor to obtain a first ratio, wherein the input offset is used to indicate the offset of a texel relative to at least one texture image, and the first divisor is determined based on the texture size or the maximum offset, wherein the texture size is used to indicate the size of the texture image, and the first ratio includes a quotient and a remainder.
[0017] The first adder calculates the sum of the quotient of the first ratio, the first value, and the second value to obtain a first calculation result. The second value is determined based on the remainder of the first ratio and the decimal part of the input texture coordinates.
[0018] The texel adjustment unit determines the target texel index corresponding to the input texture coordinates based on at least one of the first calculation result and the addressing mode.
[0019] The technical solutions provided in this application have at least the following beneficial effects:
[0020] It can combine the first calculation result with the addressing mode to flexibly and accurately determine the target texel index under different addressing modes. Furthermore, in the calculation process of the first calculation result, the relationship between the absolute value of the integer part of the input texture coordinate and the absolute value of the maximum offset is considered, so that the first calculation result can be determined based on the smaller of the two values. For example, when the absolute value of the maximum offset is small, the value of the integer part of the input texture coordinate can be reduced within a certain limit, thereby reducing the number of bits it occupies and thus reducing the bit width of the calculation unit. Attached Figure Description
[0021] Figure 1 This is a schematic diagram of at least one texture image in one possible implementation of this application;
[0022] Figure 2 This is a schematic diagram of the ALU in one possible implementation of this application;
[0023] Figure 3 This is a schematic diagram of the ALU in another possible implementation of this application;
[0024] Figure 4 This is a flowchart of a texel index calculation method applied to the ALU in one possible implementation of this application. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0026] Before introducing and explaining the technical solution of this application, some concepts involved in this application will be defined and explained.
[0027] 1. TPU (Texture Processing Unit)
[0028] The TPU (Graphics Processing Unit) is a module within the GPU specifically responsible for texture mapping and processing. It can perform operations such as rotating, resizing, and distorting bitmap images to place them as textures on any plane of a given model, playing a crucial role in graphics processing. The texture coordinate ALU (Arithmetic Logic Unit) within the TPU is used to convert input texture coordinates into target texel indices. The ALU includes different types of computation units, such as adders, multipliers, and dividers.
[0029] 2. Texture
[0030] A texture is typically a two-dimensional image containing multiple texels, used to provide surface detail and color information for three-dimensional objects. Textures can also be called texture images. In computer graphics, textures are mapped onto the surface of three-dimensional objects to increase the realism and detail of a scene. The width of a texture image (also called the texture size) is denoted by the texture size and is measured in texels. Texture coordinates are a coordinate system used in computer graphics to locate the mapping of a texture on an object's surface. The coordinates indicate where the object's vertices should read data from the texture image. For example, texture coordinates can be uv coordinates, where u and v correspond to the width and height directions of the texture, respectively. The values of uv coordinates typically range from [0, 1].
[0031] 3. Texel
[0032] A texel is the smallest unit of texture that can be read or written, representing a single pixel in a texture image. A texel contains information such as chroma and transparency, which are used during graphics rendering to determine the appearance of an object's surface and to determine the detail and resolution of the texture image. A texel is the basic unit of a texture image; that is, a texture image is composed of multiple texels, equivalent to pixels in an image. The target texel index is used to precisely locate texels within a texture image.
[0033] 4. Pixel Coordinate and Texture Coordinate
[0034] The pixel coordinate system is the coordinate system of the imaging plane, used to represent the position of a pixel in the image. The texel coordinate system is represented by a normalized number or a scale number, and each texture coordinate is mapped to a specific texel.
[0035] 5. Floating-point numbers
[0036] Floating-point numbers include fp32, which refers to a 32-bit single-precision floating-point number. It's a way of approximating real numbers in computers. The highest bit of fp32 is the sign bit (0 for positive, 1 for negative); the middle 8 bits represent the exponent, ranging from 0 to 255, corresponding to the actual exponent range of -126 to 127; the lower 23 bits represent the mantissa. The decimal value represented by an fp32 number can be calculated using the following expression: .
[0037] 6. Integers
[0038] Integers are used to represent numerical values without a decimal part. Integer values can be integers, negative numbers, or 0. They are divided into signed integers (signed int) and unsigned integers (unsigned int), and the range of values depends on the actual number of bits. The highest bit of a signed int is used as the sign bit, with 0 representing a positive number and 1 representing a negative number. Unsigned int can only represent non-negative integers. Because it has no sign bit, it can represent a larger range of positive numbers with the same number of bits.
[0039] 7. Texture Coordinate ALU
[0040] The arithmetic logic unit in the TPU is used to convert input texture coordinates into target texel indices. The general formula for calculating universally normalized coordinates is:
[0041] `texel_index` = (conv_input_coord + offset) / texture size, where `conv_input_coord` is the initial calculated value for converting texture coordinates to texel indices, obtained by multiplying the input texture coordinates (in floating-point format) by the texture size. `offset` is the configured or calculated offset, typically including sampling offset, coordinate offset, pixel offset, etc., and is usually a series of non-normalized fixed-point numbers. The output texel index is in signed fixed-point number format.
[0042] The following example uses a 2D texture type, a mirror addressing mode, an input texture coordinate of 1.75, an input offset of 18.75, and a texture size of 10 to illustrate the process of solving the texel index corresponding to the input texture coordinate of 1.75 in the u direction.
[0043] According to the formula texel_index = (conv_input_coord + offset) / texturesize, we can calculate (1.75 * 10 + 18.75) / 10, which has a quotient of 3 and a remainder of 6.25. Without considering bilinearity, the decimal part can be ignored (resulting in some loss of precision), thus the remainder is determined to be 6.
[0044] Based on the above results, the texel indicated by the input texture coordinates can be determined using the quotient and remainder of the texel index. The quotient (i.e., the integer) of the texel index is used to determine the target texture image from multiple texture images; the target texture image refers to the texture image corresponding to the input texture coordinates. To further determine the target texel index, the remainder of the calculated texel index is used as the initial texel index. The initial texel index is used to determine the initial texel from the multiple texels contained in the target texture image. For example... Figure 1 As shown, a texel index quotient of 3 indicates that the position of the texel in the texture image needs to move 3 texture images forward in the positive direction of u from the first texture image (i.e., texture image 0), i.e., texture image 3. Therefore, the target texture image is texture image 3. An initial texel index of 6 indicates that the specific texel position in the determined texture image is the 6th texel in the positive direction of u, based on the current position of texture image 3 (e.g., the position of the texel in the texture image 0). Figure 1 (As indicated by the arrow in the image), the initial texel is the 6th texel in texture image 3. It should be noted that in this application, for the texels included in a single texture image, the starting position of the texel is 0. Therefore, when the texture size is 10, the texel numbers are recorded as the 0th to the 9th texels.
[0045] Considering the current addressing mode is mirrored, and the calculated texture coordinates fall within the interval [3.0, 4.0], i.e., within an odd multiple of the texture image, a mirror flip is needed compared to the original texture image. To determine the index of the initial texel in the original texture image, the actual texel index (target texel index) should be: texture_size – 1 – remainder (i.e., the calculated texel_index) = 10 - 1 - 6 = 3. This represents the texture coordinates being the 3rd texel in the original texture image.
[0046] In the above calculation process, each step involves different overflow and rounding judgments, and the rounding mode needs to be configured, with the configuration result affecting the final calculation accuracy. Furthermore, for different addressing modes, the parity of the input texture coordinates also needs to be considered. Each step of the calculation involves data format conversion and alignment. Along with precision calculation and rounding, the adders, multipliers, and dividers used have relatively large bit widths, resulting in complex physical implementation and potentially requiring multiple output cycles. Therefore, existing solutions retain relatively large data bit widths in the conversion from texture coordinates to target texel indices, and the data bit width determines the combinational logic complexity of the calculation unit. Large bit width calculation units often mean larger areas, longer computational latency, more difficult physical routing, and higher power consumption. This application aims to minimize computational overhead while pursuing high-precision calculations, achieving a more timing- and area-friendly design.
[0047] Therefore, we will further study the calculation method of the target texel.
[0048] For the input texture coordinates, both the integer and decimal parts are considered; this article only processes the integer part. It can be understood that, according to the formula: texel_index = input_coord * texture size + offset, the integer part of input_coord affects how many complete textures are offset backward from the starting point, while the decimal part of input_coord affects the final texel value. The offset is the overall offset of the sampling point relative to the entire display plane, which can affect both the texel value and the number of complete textures offset backward from the starting point.
[0049] If we calculate offset / texture size, the quotient represents the number of textures to offset backward from the current point, and the remainder represents the number of extra texels to offset. However, we still need to consider further: the result of processing the decimal part of input_coord plus the remainder of offset / texture size may still be located in [texture size, 2*texture size) or [-2*texture size, -texture size). In this case, the ratio between the calculated result and texture size may be greater than 1 or less than -1, so we still need to offset backward or forward by a complete texture.
[0050] Therefore, calculating which texture the texel falls on requires four steps:
[0051] stage1, based on the integer part of input_coord, determines s0;
[0052] Stage 2: Confirm the offset / texture size quotient s1;
[0053] In stage 3, confirm the result of processing the decimal part of input_coord plus the remainder of offset / texture size. Based on this result, determine whether s2 is 0, 1, or -1.
[0054] In stage 4, the three parts s0 + s1 + s2 are added together to determine the final value of the integer part of the target texel index. In this application, s0 + s1 + s2 is used as the integer of the target texel index. Then, based on the addressing mode, it is determined whether the current input texture coordinates belong to an out-of-bounds or odd / even texture image.
[0055] Further analysis of the impact of different addressing modes on computation reveals that texture coordinates can be assigned to any vertex of any primitive, typically with the u and v texture coordinates of a vertex falling within the range of [0,1]. However, when a specific addressing mode is enabled, texture coordinates can be assigned outside this range, thus creating certain special texture effects. Common addressing modes include wrap, mirror, clamp, and border color.
[0056] Wrap: The texture image repeats continuously without any boundary concept; whether the texture image is an odd or even multiple of the original, the texel corresponding to the same point is always the same. Therefore, when the addressing mode is wrap, the value of the quotient in the target texel index is not important.
[0057] Mirroring: The texture is continuously mirror-flipped repeatedly without any out-of-bounds concept. When the integer index of the target texel (i.e., s0 + s1 + s2 above) is located in [0, 1), it is considered an even multiple of the texture plane; [1, 2) is considered an odd multiple of the texture plane; [2, 3) is considered an even multiple of the texture plane, and so on. When it is located in an even multiple of the texture image, the calculated initial texel index does not require any additional operation. The initial texel index calculated for an odd multiple of the texture plane needs to be mirror-flipped, i.e., the result output is (texture size - 1 - initial texel index).
[0058] `clamp`: When the integer value of the target texel index is in the range [0, 1), an initial texel index needs to be calculated, which becomes the final target texel index. For values outside this range, if the quotient of the target texel index is less than 0, it is considered a negative out-of-bounds error, and texel 0 is returned; if the quotient of the target texel index is greater than 1, it is considered a positive out-of-bounds error, and texel texture size - 1 is returned. The initial texel is 0, therefore the right boundary is texture size - 1.
[0059] Border color: When the integer of the target texel index falls within the range [0, 1), the initial texel index needs to be calculated, which is the final target texel index; any texel outside this range is considered out of bounds, and the result returns the set border texel.
[0060] In summary, it can be understood that when determining the target texel index, we are actually concerned with the parity of the result (s0 + s1 + s2) and the comparison result with the two boundary values 0 and 1 (judging out of bounds). In this context, this scheme utilizes the characteristic that what is truly important in different addressing modes is not always the exact value of s0 + s1 + s2, but rather the parity of its result and out-of-bounds judgment. Within certain limits, the integer part of the input texture coordinates can be reduced, thereby reducing the number of bits it occupies, and thus reducing the bit width of the computation unit.
[0061] Please refer to Figure 2 The diagram illustrates an ALU provided in one possible implementation of this application. The ALU 20 includes: a first comparator 21, a first divider 22, a first adder 23, and a texel adjustment unit 24.
[0062] A first comparator 21 is used to determine a first value, which is determined based on the smaller of the integer part of the input texture coordinates and the maximum offset.
[0063] The first divider 22 is used to calculate the ratio between the input offset and the first divisor to obtain the first ratio. The input offset is used to indicate the offset of the texel relative to at least one texture image. The first divisor is determined based on the texture size or the maximum offset. The texture size is used to indicate the size of the texture image. The first ratio includes the quotient and the remainder.
[0064] The first adder 23 is used to calculate the sum of the quotient of the first ratio, the first value, and the second value to obtain the first calculation result. The second value is determined based on the remainder of the first ratio and the decimal part of the input texture coordinates.
[0065] The texel adjustment unit 24 is used to determine the target texel index corresponding to the input texture coordinates based on at least one of the first calculation result and the addressing mode.
[0066] A comparator is a logic circuit or arithmetic unit used to compare the magnitude of two numerical values. In some embodiments, the input texture coordinates can be positive or negative. When the input texture coordinates are positive, their integer and fractional parts are also positive. When the input texture coordinates are negative, their integer and fractional parts are also negative.
[0067] The maximum offset refers to the maximum value of the pre-configured input offset in a given calculation or processing procedure. In some embodiments, the maximum offset can be either positive or negative, and this application does not limit this. The number of bits corresponding to the maximum offset refers to the number of binary bits occupied when the maximum offset is represented in binary form in a computer. It includes a sign bit for indicating positive or negative and numeric bits for indicating the magnitude of the value. For example, the number of bits corresponding to the maximum offset can be n, where the highest bit can represent the sign bit, and the lower n-1 bits can represent the number of numeric bits. The absolute value of the maximum offset is 2^n. n-1 The sign of the maximum offset depends on the sign indicated by the highest bit. If the sign bit is 1, it means the maximum offset is negative, in which case the maximum offset is -2. n-1 If the sign bit is 0, it indicates that the maximum offset is positive, in which case the maximum offset is +2. n-1 .
[0068] In some embodiments, the first comparator 21 is used to compare the absolute value of the integer part of the input texture coordinates with the absolute value of the maximum offset to obtain a first comparison result; based on the first comparison result, a first numerical value is determined. In some embodiments, the first comparison result includes: the absolute value of the integer part of the input texture coordinates is greater than the absolute value of the maximum offset, and the absolute value of the integer part of the input texture coordinates is less than or equal to the absolute value of the maximum offset.
[0069] In some embodiments, if the absolute value of the integer part of the input texture coordinates is greater than the absolute value of the maximum offset, then regardless of the sign of the input texture coordinates and s1 (i.e., the quotient of the input offset to the texture size) or the value of s1, the sum of the integer part of the input texture coordinates and the processing result of the input offset (i.e., the quotient of the input offset to the texture size, s1) will always be greater than 1, less than -1, or equal to 1. This means the integer part of the target texel index is definitely out of bounds. In this case, the value of the integer part of the input texture coordinates is not important and can be reduced to a certain extent to obtain the first value (i.e., s0). This method reduces the number of bits in the integer part of the input texture coordinates, thereby reducing the bit width of subsequent calculation units. In some embodiments, when reducing the value of the integer part of the input texture coordinates, its corresponding parity can be preserved. This facilitates the accurate determination of the parity of the texture image where the integer part of the target texel index is located. The aforementioned reduction of the integer part of the input texture coordinates refers to the integer part itself, not the sign. For example, the number of bits corresponding to the integer part can be m, where m is an integer greater than 1. The lower m-1 bits indicate the integer part's value, and the highest bit indicates its sign. Reducing the integer part of the input texture coordinates means shrinking the lower m-1 bits of the value while keeping the sign bit unchanged. This results in the reduced number of bits occupied by the integer part being less than m-1, thus reducing the bit width of the corresponding computational unit during subsequent calculations.
[0070] In some embodiments, the absolute value of the integer part of the input texture coordinates is less than or equal to the absolute value of the maximum offset. In this case, determining whether the integer part of the target texel index is out of bounds also requires combining s2, which is determined by the result of processing the fractional part of input_coord plus the remainder of offset / texture size. In this case, the original value of the integer part can be retained to ensure the accuracy of subsequent calculation results.
[0071] A divider is a hardware unit in the ALU used to perform division operations. The first divider 22 is used to calculate the first ratio between the input offset and the first divisor to obtain the first ratio.
[0072] Input offsets can include at least one of the following: sampling offset, coordinate offset, and pixel offset. Sampling offset refers to the positional offset of a sampling point relative to the original texture coordinates during texture sampling, and can be used to achieve various texture effects, such as blurring, sharpening, and edge detection filters. Coordinate offset refers to the positional offset of texture coordinates relative to the model surface during texture mapping, and can be used to achieve transformations such as translation, rotation, and scaling of the texture, allowing the texture to adjust its position and orientation as needed. Pixel offset refers to the positional offset of a pixel relative to the texture coordinates during rasterization, and can be used to achieve anti-aliasing, texture smoothing, and other effects, improving the accuracy and quality of texture mapping.
[0073] A texture image is an image used to apply textures to the surface of a 3D model. Texture images typically contain information such as color, material, and lighting to enhance the visual effect of the 3D model. Texture images can be photographs, paintings, or other forms of images. In some embodiments, texture images can be regular images, such as rectangles or squares, or irregular images; this application does not limit this. Texture size is typically expressed in texels. For any given texture image, the texture size in different directions can be the same or different. For example, a texture image can be a 1024×1024 texel square image, indicating that the texture size in both the horizontal and vertical directions is 1024 texels. A texture image can also be a 512×2048 texel rectangular image, indicating that the texture size in the horizontal direction is 512 texels and the texture size in the vertical direction is 2048 texels.
[0074] An adder refers to a hardware unit in the ALU used to perform addition operations. The first adder 23 is used to calculate the sum of the quotient of a first ratio (i.e., s1), a first value (i.e., s0), and a second value (i.e., s2). In some embodiments, the second value takes the values 0, -1, and 1. In some embodiments, the second value is used to indicate the quotient of the calculated result of (the fractional part of input_coord + the remainder of offset / texture size) / texture size.
[0075] In some embodiments, the addressing mode may include at least one of the following: repeat, mirror, pinch, and border color. In some embodiments, the target texel index value is determined differently for different input texture coordinates under different addressing modes.
[0076] In some embodiments, the integer portion of the target texel index can be determined to be located in an odd-multiple texture image or an even-multiple texture image based on the parity of the first calculation result, to determine whether a mirror flip needs to be performed. In some embodiments, the out-of-bounds condition of the integer portion of the target texel index is determined based on the relationship between the first calculation result and 0 and 1. The out-of-bounds condition can include positive and negative out-of-bounds. A negative out-of-bounds condition occurs when the first calculation result is less than 0, and a positive out-of-bounds condition occurs when the first calculation result is greater than or equal to 1.
[0077] In some embodiments, the input texture coordinates are floating-point numbers, and the ALU 20 also includes a format conversion unit ( Figure 2 (Not shown in the image). This format conversion unit is used to convert the input texture coordinates from floating-point format to fixed-point format, where the fixed-point format input texture coordinates are used to determine the fractional and integer parts of the input texture coordinates.
[0078] In some embodiments, the sign bit, exponent, and mantissa of the input texture coordinates in floating-point format are determined; the input texture coordinates in fixed-point format are determined based on the sign bit, exponent, and mantissa of the floating-point number, and the input texture coordinates in fixed-point format include an integer part and a fractional part. In some embodiments, the decimal value corresponding to the floating-point number is calculated based on the sign bit, exponent, and mantissa, and the decimal value may include an integer and a fractional part; based on the bit width and format of the fixed-point number (including the number of bits occupied by the integer part and the fractional part respectively), the integer and fractional parts of the decimal value are converted into the integer part and fractional part of the fixed-point number, respectively. The bit width occupied by the integer part and the fractional part of the fixed-point number can be configured according to the precision requirements, and this application does not limit it in this regard.
[0079] In summary, the technical solution provided by the embodiments of this application can flexibly and accurately determine the target texel index under different addressing modes by combining the first calculation result and the addressing mode. Furthermore, during the calculation of the first calculation result, the relationship between the absolute value of the integer part of the input texture coordinates and the absolute value of the maximum offset is considered, allowing the first calculation result to be determined based on the smaller of the two values. For example, when the absolute value of the maximum offset is small, the value of the integer part of the input texture coordinates can be reduced within a certain limit, thereby reducing the number of bits it occupies and thus reducing the bit width of the calculation unit.
[0080] The following describes the specific implementation method for determining the first value.
[0081] In some embodiments, such as Figure 2 As shown, the first comparator 21 is further configured to determine that the value of the first value is greater than 2 if the absolute value of the integer part of the input texture coordinates is greater than the absolute value of the maximum offset. n-1 And less than 2n The first value is the sign of the input texture coordinate, and n is the number of bits corresponding to the maximum offset.
[0082] In some embodiments, since the absolute value of the integer part of the input texture coordinates is greater than the absolute value of the maximum offset, regardless of the sign or value of the input texture coordinates and the maximum offset, the sum of the processed result of the integer part of the input texture coordinates and the input offset will always be greater than 1, less than -1, or equal to 1. That is, the integer part of the target texel index will always be out of bounds.
[0083] In this case, the integer part of the input texture coordinates is not important and can be reduced to any integer greater than the absolute value of the maximum offset. Since n is the number of bits corresponding to the maximum offset, with 1 bit used to indicate the sign of the offset, the absolute value of the maximum offset is 2. n-1 .
[0084] In some embodiments, the value of the first numerical value is determined to be greater than 2. n-1 And less than 2 n This satisfies the condition that the absolute value of the integer part of the input texture coordinates is greater than the absolute value of the maximum offset, while limiting the number of bits corresponding to the first value to n bits. In other words, it prevents the value of the first value from becoming too large, thus avoiding a larger bit width for subsequent calculation units.
[0085] For example, assuming the maximum offset corresponds to 5 bits n, then the absolute value of the maximum offset is 2. 4 =16, the integer part of the input texture coordinates can be 65, which corresponds to 7 bits. Since the absolute value of the integer part is greater than the absolute value of the maximum offset, the first value is determined to be greater than 2. 4 And less than 2 5 Any positive number, such as 18. In this case, the number of bits corresponding to the first value is 5, which is two bits less than the 7 bits corresponding to the integer part 65.
[0086] In some embodiments, the first comparator 21 is further configured to determine that the first value is the integer part of the input texture coordinates if the absolute value of the integer part of the input texture coordinates is less than or equal to the absolute value of the maximum offset. In some embodiments, the value of the first value is determined to be the value of the integer part of the input texture coordinates, and the sign of the first value is the sign of the integer part of the input texture coordinates.
[0087] In some embodiments, when the absolute value of the integer part of the input texture coordinates is less than or equal to the absolute value of the maximum offset, the value of the integer part of the target texel index also needs to consider the fractional part of the input texture coordinates and the remainder of the first ratio. In this case, in order to ensure the accuracy of the subsequent calculation results, the first value is determined to be the original integer part of the input texture coordinates.
[0088] The above method, when the absolute value of the integer part of the input texture coordinates is greater than the absolute value of the maximum offset, reduces the value of the integer part of the input texture coordinates, so that the bit width corresponding to the reduced integer part (i.e., the first value) is limited to n bits. This reduces the number of bits occupied by the integer part, thereby reducing the bit width of the computation unit during subsequent calculations. Furthermore, when the absolute value of the integer part of the input texture coordinates is less than or equal to the absolute value of the maximum offset, the first value is determined to be the original integer part of the input texture coordinates, facilitating accurate calculation of the target texel index.
[0089] In some embodiments, such as Figure 2 As shown, the first comparator 21 is further configured to determine that the value of the first value is greater than 2 when the absolute value of the integer part of the input texture coordinates is greater than the absolute value of the maximum offset and the integer part of the input texture coordinates is even. n-1 And less than 2 n Even numbers. In some embodiments, the first comparator 21 is further configured to determine that the first value is greater than 2 if the absolute value of the integer part of the input texture coordinate is greater than the absolute value of the maximum offset and the integer part of the input texture coordinate is odd. n-1 And less than 2 n Odd numbers.
[0090] In some embodiments, the parity of the integer portion of the input texture coordinates is determined based on the least significant bit of the integer portion. In some embodiments, the integer portion is determined to be even when the least significant bit is bit 0, and odd when the least significant bit is bit 1.
[0091] In the above method, under different addressing modes, the parity of the integer part of the target texel index will affect the final determined target texel. By preserving the corresponding parity in the first value, the accuracy of subsequent target texel selection is ensured.
[0092] The following describes the specific implementation method for determining the second value.
[0093] In some embodiments, such as Figure 3 As shown, ALU20 also includes a multiplier 25, a second adder 26, and a second comparator 27.
[0094] Multiplier 25 is used to calculate the product of the fractional part of the input texture coordinates and the texture size to obtain the first product;
[0095] The second adder 26 is used to calculate the sum of the remainders of the first product and the first ratio to obtain the second calculation result;
[0096] The second comparator 27 is used to calculate the absolute value of the second calculation result and the size of the texture to obtain a second comparison result; based on the second comparison result, a second value is determined, which is used to indicate whether to offset a complete texture image.
[0097] A multiplier refers to a hardware unit in the ALU used to perform multiplication operations. Here, it is used to calculate the product of the fractional part of the input texture coordinates and the texture size to obtain the first product. The first product can include both integers and fractions. The number of decimal places retained in the first product can be configured according to precision requirements, and this application does not limit this. For example, the texture size can be x bits, the fractional part of the input texture coordinates can be q bits, and the fractional part of the first product can also be q bits, where x and q are positive integers, and this application does not limit this.
[0098] At least one texture image is used to indicate a texture surface; that is, a texture surface can include multiple texture images. The input offset is used to indicate the offset of the texel relative to the texture surface. The decimal part of the input texture coordinates can be understood as the offset relative to a single texture image. In other words, the calculation granularity of the input offset and the decimal part of the input texture coordinates is different, resulting in calculation errors. To facilitate the subsequent calculation of the second result, the decimal part of the input texture coordinates needs to be enlarged here, that is, multiplied by the texel size to obtain the first product, thereby ensuring the accuracy of the subsequent second calculation result.
[0099] In some embodiments, the second comparison result includes a second calculation result whose absolute value is greater than or equal to the texture size, and a second calculation result whose absolute value is less than the texture size. In some embodiments, when the absolute value of the second calculation result is greater than or equal to the texture size, it indicates an offset of a complete texture image, in which case the second value affects the integer part of the target texel index. In some embodiments, when the absolute value of the second calculation result is less than the texture size, it indicates that no complete texture image has been offset, in which case the second value does not affect the integer part of the target texel index.
[0100] In the above method, when the integer part of the target texel index goes out of bounds in different addressing modes, the remainder (i.e., the initial texel index) in the calculation result of (the remainder of the first ratio + the fractional part of the input texture coordinates * texture size) / texture size may not be considered during the determination of the target texel index. The second comparator can avoid unnecessary division operations, thereby simplifying the computational complexity of the system's computing unit.
[0101] In some embodiments, the second comparator 27 is further configured to determine that the second value is 0 if the absolute value of the second calculation result is less than the texture size.
[0102] In some embodiments, when the absolute value of the second calculation result is less than the texture size, the ratio of the second calculation result to the texture size must be 0, therefore the second value is 0.
[0103] In some embodiments, the second comparator 27 is further configured to determine the second value as 1 or -1 if the absolute value of the second calculation result is greater than or equal to the texture size.
[0104] In some embodiments, when the absolute value of the second calculation result is greater than or equal to the texture size, the ratio of the absolute value of the second calculation result to the texture size is always greater than or equal to 1. Since the output offset can be negative or positive, and the decimal part of the input texture coordinates can be negative or positive, the second calculation result can be -1 or 1.
[0105] The above method can quickly determine the value of the second numerical value through the second comparator.
[0106] In some embodiments, the second comparator 27 is further configured to determine the second value as -1 when the absolute value of the second calculation result is greater than or equal to the texture size and the second calculation result is negative.
[0107] The second comparator 27 is also used to determine the second value as 1 when the absolute value of the second calculation result is greater than or equal to the texture size and the second calculation result is a positive number.
[0108] In some embodiments, the sign of the second calculation result is determined by the sign bit of the first calculation result. For example, the sign bit of the second calculation result may be located at the highest bit of its corresponding bit sequence. For example, when the highest bit is bit 1, it is determined to be a negative number; when the highest bit is bit 0, it is determined to be a positive number.
[0109] In some embodiments, the second comparator 27 is further configured to determine the second value as -1 if the absolute value of the second calculation result is greater than or equal to the texture size and the remainders of the first product and the first ratio are both negative.
[0110] In some embodiments, the remainder of the first ratio is signified by the input offset; in other words, the remainder of the first ratio is negative when the input offset is negative, and positive when the input offset is positive. In some embodiments, the first product is signified by the input texture coordinates; in other words, the first product is negative when the input texture coordinates are negative, and positive when the input texture coordinates are positive.
[0111] In some embodiments, the second value is determined to be 0 when the remainder of the first product and the first ratio has opposite signs. It is understood that the absolute value of the first product is always less than the texture size, and the absolute value of the remainder of the first ratio is also always less than the texture size. In this case, the sum of the absolute values of the first product and the remainder of the first ratio will be greater than or equal to the texture size only if the signs of their respective remainders are the same. When the signs of the remainder of the first product and the first ratio are opposite, for example, the first product may be positive and the remainder of the first ratio may be negative; or the first product may be negative and the remainder of the first ratio may be positive. In both cases, the sum of their values is always less than the texture size.
[0112] The method described above can determine whether the second value is 1 or -1 based on the sign of the second calculation result. This method only requires a basic sign judgment on the second calculation result, reducing the amount of calculation and improving the efficiency of determining the second value.
[0113] In some embodiments, the ALU20 may further include a second divider ( Figure 2 and Figure 3 (Not shown in the diagram) A second divider is used to calculate a second ratio between the second calculation result and the texture size. The second ratio includes a quotient and a remainder. The quotient of the second ratio can take the values 0, -1, and 1. The quotient of the second ratio is determined as the second numerical value. In this method, the aforementioned second comparator is not required.
[0114] The following describes how to determine the first divisor.
[0115] In some embodiments, such as Figure 3 As shown, ALU20 also includes a third comparator 28.
[0116] The third comparator 28 is used to determine the first divisor as the texture size when the texture size is less than or equal to the absolute value of the maximum offset;
[0117] The third comparator 28 is also used to determine the first divisor as the absolute value of the maximum offset when the texture size is greater than the absolute value of the maximum offset.
[0118] In some embodiments, the third comparator 28 is further configured to compare the number of bits corresponding to the maximum offset with the number of bits corresponding to the texture size; when the number of bits corresponding to the maximum offset is less than the number of bits corresponding to the texture size, the absolute values of the texture size and the maximum offset are compared.
[0119] In some embodiments, when the texture size is less than or equal to the absolute value of the maximum offset, the ratio between the input offset and the texture size may be greater than or equal to 1, or less than or equal to -1, depending on the sign of the input offset. In other words, the offset may span one or more texture images. In this case, determining the texture size as the first divisor serves two purposes. First, since the texture size is less than or equal to the absolute value of the maximum offset, the bit width occupied by the texture size will be less than the bit width occupied by the maximum offset (excluding the sign bit), thus further reducing the bit width of the first divider. Second, the remainder of the ratio can be used to determine the specific number of texels the input offset covers in a texture image, and the quotient can be used to determine the specific number of texture images the input offset covers.
[0120] In some embodiments, when the texture size is greater than the absolute value of the maximum offset, it is easy to see that the ratio between the input offset and the texture size is always less than 1, that is, the quotient of the two is 0 and the remainder is the input offset. In other words, the offset crosses at most the boundary of one texture image, but not the entire texture image. In this case, the first divisor is determined to be the maximum offset. It is understandable that since the maximum offset is less than the texture size, the bit width occupied by the maximum offset will be less than the bit width occupied by the texture size.
[0121] The above method reduces the number of bits occupied by the first divisor by determining the first divisor to be the smaller of the absolute values of the texture size and the maximum offset, thereby reducing the bit width of the first divider.
[0122] The following describes how to determine the target texel in different addressing modes. The target texel refers to the texel corresponding to the input texture coordinates.
[0123] (1) Mirror image
[0124] In some embodiments, such as Figure 3 As shown, the addressing mode is mirrored, the target texel index is used to indicate the target texel, the target texel is determined based on the first texture image, and the target texel refers to the texel corresponding to the input texture coordinates.
[0125] The texel adjustment unit 24 is also used to determine an initial texel index, which is determined based on the remainder of the first ratio, the fractional part of the input texture coordinates, and the texture size;
[0126] The texel adjustment unit 24 is also used to determine that the target texel belongs to an even multiple texture image when the first calculation result is even, and to determine the target texel index as the initial texel index. The even multiple texture image is used to indicate that no mirror flip needs to be performed relative to the first texture image.
[0127] The texel adjustment unit 24 is also used to determine that the target texel belongs to an odd multiple texture image when the first calculation result is odd, and to determine that the target texel index is the texture size minus 1 minus the initial texel index. The odd multiple texture image is used to indicate that a mirror flip needs to be performed relative to the first texture image.
[0128] The first texture image refers to the original texture image used as the basis and reference in the texture mapping process. It contains a series of texels arranged in a specific manner, where each texel carries visual information such as color and brightness, collectively forming a complete texture pattern. In the mirror addressing mode of this embodiment, the first texture image is the starting point for the entire texture processing flow. The target texel corresponding to the input texture coordinates is determined from the multiple texels contained in this first texture image. It has a defined texture size, which specifies the number of texels in the horizontal and vertical directions of the texture, and is an important parameter for subsequent calculations and processing.
[0129] In some embodiments, the initial texel index is the remainder of the calculation result of (the remainder of the first ratio + the decimal part of the input texture coordinates * texture size) / texture size. Wherein, the decimal part of the input texture coordinates * texture size is the first product described above, and the remainder of the first ratio + the decimal part of the input texture coordinates * texture size is the second calculation result described above. In some embodiments, the texel adjustment unit 24 is further configured to calculate the ratio of the second calculation result to the texture size to obtain a second ratio, which includes a quotient and a remainder. The remainder of the second ratio is determined as the initial texel index. In some embodiments, when the absolute value of the second calculation result is less than the texture size, the initial texel index is the second calculation result.
[0130] Mirroring refers to the operation of symmetrically transforming a texture image along a specific axis during texture mapping. In mirror addressing mode, when the input texture coordinates exceed the range of the first texture image, the system will determine whether to perform mirroring on the original texture image (i.e., the first texture image) based on the calculation result of the input texture coordinates (such as the parity of the first calculation result), thereby obtaining an odd-multiple texture image.
[0131] In some embodiments, mirror flipping can be divided into horizontal mirror flipping and vertical mirror flipping. In a two-dimensional texture space, horizontal mirror flipping is a symmetrical transformation of the texture image along the vertical axis (usually the y-axis), so that texels originally located on the left side of the image move to the right side, and texels on the right side move to the left side; vertical mirror flipping is a symmetrical transformation of the texture image along the horizontal axis (usually the x-axis), so that texels originally located at the top of the image move to the bottom, and texels at the bottom move to the top.
[0132] In some embodiments, the target texel belongs to an even-number multiple of the texture image, in which case there is no need to perform a mirror flip operation on the first texture image. That is, in this case, the even-number multiple texture image refers to the first texture image itself. When the first calculation result is odd, the target texel belongs to an odd-number multiple texture image, in which case a mirror flip operation on the first texture image is required to obtain an odd-number multiple texture image. Specifically, by setting the target texel index to the texture size minus 1 and then minus the initial texel index, symmetrical adjustment of the texel position is achieved. For example, assuming the texture size is 10 texels (index from 0 to 9), if the initial texel index is 3, after mirror flipping, the target texel index becomes 10 - 1 - 3 = 6.
[0133] The above method can accurately determine the target texel index in mirror addressing mode by combining the parity of the first calculation result with the initial texel index and the differentiation processing of texture images with even multiples and odd multiples.
[0134] (2) Clamping
[0135] In some embodiments, such as Figure 3 As shown, the addressing mode is gripping, the target texel index is used to indicate the target texel, the target texel is determined from the multiple texels contained in the second texture image, and the target texel refers to the texel corresponding to the input texture coordinates;
[0136] The texel adjustment unit 24 is also used to determine an initial texel index when the first calculation result is greater than or equal to 0 and less than 1. The initial texel index is determined based on the remainder of the first ratio, the fractional part of the input texture coordinates, and the texture size.
[0137] The texel adjustment unit 24 is also used to determine the target texel index as index 0 when the first calculation result is less than 0.
[0138] The texel adjustment unit 24 is also used to determine the target texel index as the texture size minus 1 if the first calculation result is greater than or equal to 1.
[0139] In some embodiments, the texel adjustment unit 24 is further configured to compare the first calculation result with the magnitudes of 0 and 1; if the first calculation result is less than 0 or greater than or equal to 1, there is no need to determine the initial texel index. If the first calculation result is greater than or equal to 0 and less than 1, the initial texel index is determined. This method ensures that the initial texel index is determined only when the first calculation result is greater than or equal to 0 and less than 1, avoiding unnecessary calculations by the texel adjustment unit.
[0140] The second texture image refers to the base image that serves as the source of texture data in pinch-address mode. It is a collection of multiple texels arranged in a specific way to form a complete texture pattern, storing visual information such as color and brightness required for graphics rendering.
[0141] For example, suppose the second texture image is a 2D texture with a width and height of 10 texels, meaning the target texel index ranges from 0 to 9 in both the horizontal and vertical directions. The operation of the texel adjustment unit 24 is illustrated using the processing of texture coordinates in the horizontal direction as an example. During texture mapping, the input texture coordinates undergo a series of calculations to obtain a first calculation result. If the first calculation result is less than 0, for example, -1, the texel adjustment unit 24 determines the target texel index to be index 0, where index 0 indicates texel 0 in the second texture image. This means that in the horizontal direction, regardless of how much the input texture coordinates extend beyond the left boundary, the leftmost texel (index 0) will ultimately be used as the target texel. For example, when rendering an object surface, if the input texture coordinates cause the first calculation result in the horizontal direction to be less than 0, then the texture at the corresponding position on the object surface will be filled with the color of the leftmost texel in the second texture image. For example, if the first calculation result is greater than or equal to 1, for example, 2. At this point, the texel adjustment unit 24 determines the target texel index to be the texture size minus 1. In this example, the texture size is 10, so the target texel index is 10 - 1 = 9. That is, when the input texture coordinates exceed the right boundary, regardless of how much they exceed, the rightmost texel (index 9) will ultimately be used as the target texel. For example, when drawing a large wall texture, if the input texture coordinates make the first calculation result in the horizontal direction greater than or equal to 1, the corresponding position on the wall will be mapped using the color of the rightmost texel in the second texture image.
[0142] In the above method, when the first calculation result obtained from the input texture coordinates falls within different ranges, the texel adjustment unit 24 will process the target texel differently according to the rules of the gripping addressing mode. When the first calculation result is greater than or equal to 0 and less than 1, the target texel index needs to be obtained based on the initial texel index; when the first calculation result is less than 0, the target texel index is directly determined as index 0; when the first calculation result is greater than or equal to 1, the target texel index is determined as the texture size minus 1. In this way, the second texture image can flexibly cope with different input texture coordinates in the gripping addressing mode, ensuring the accuracy and effectiveness of texture mapping.
[0143] (3) Border color
[0144] In some embodiments, such as Figure 3 As shown, the addressing mode is border color, the target texel index is used to indicate the target texel, the target texel is determined based on the third texture image, and the target texel refers to the texel corresponding to the input texture coordinates;
[0145] The texel adjustment unit 24 is also used to determine an initial texel index when the first calculation result is greater than or equal to 0 and less than 1. The initial texel index is determined based on the remainder of the first ratio, the fractional part of the input texture coordinates, and the texture size; and to determine the target texel index as the initial texel index.
[0146] The texel adjustment unit 24 is also used to determine the target texel index as the index of the border texel if the first calculation result is less than 0 or greater than 1 or equal to 1.
[0147] Similarly, in some embodiments, the texel adjustment unit 24 is also used to compare the first calculation result with the magnitudes of 0 and 1; if the first calculation result is less than 0 or greater than or equal to 1, there is no need to determine the initial texel index. If the first calculation result is greater than or equal to 0 and less than 1, the initial texel index is determined. This method ensures that the initial texel index is determined only when the first calculation result is greater than or equal to 0 and less than 1, avoiding unnecessary calculations by the texel adjustment unit.
[0148] The third texture image refers to the base image that serves as the primary source of texture data in the border color addressing mode. It consists of multiple texels arranged in an orderly manner, each carrying visual information such as color and brightness, which together form a specific texture pattern. It is the basic range for looking up the corresponding texels at the input texture coordinates during the entire texture mapping process.
[0149] Border texels are special texels used when the input texture coordinates exceed the effective range of the third texture image during texture mapping using border color addressing mode. Border texels have a specific color, called the border color. The border color can be flexibly set according to specific application needs. For example, in rendering serious scenes, the border color might be set to black to create a calm and simple visual effect; while in cartoon-style scenes or scenes requiring emphasis, vibrant colors such as red or yellow might be chosen. Border texels maintain a consistent color characteristic throughout the area exceeding the boundary; that is, regardless of the distance or position beyond the boundary, the same border texel is used to fill it, thus ensuring the consistency and regularity of the rendering results. Border texels supplement the third texture image. The third texture image provides the main texel data required for normal texture mapping, used to fill the portion of the object's surface within the effective texture range; while border texels handle the portion exceeding this range. Together, they complete the texture mapping process for the entire object's surface.
[0150] When the first calculation result is greater than or equal to 0 and less than 1, the texel adjustment unit 24 uses the initial texel index as the target texel index. This means that the input texture coordinates are within the valid range of the third texture image, and the corresponding texel is selected from within the image for rendering to ensure normal texture display. When the first calculation result is less than 0 or greater than or equal to 1, it indicates that the input texture coordinates exceed the boundary range of the third texture image. In this case, the texel adjustment unit 24 determines the target texel index as the index of the border texel. The border texel usually has a pre-defined color, i.e., the border color, which can be configured according to specific needs, such as being set to black, white, or other specific colors. During rendering, the portion exceeding the boundary of the third texture image is filled with the border texel color, thereby avoiding texture loss or abnormal display, making the overall graphics rendering effect more complete and aesthetically pleasing.
[0151] The above method can flexibly handle different input texture coordinates in the border color addressing mode, ensuring the accuracy of texture mapping.
[0152] (4) Repetition
[0153] In some embodiments, such as Figure 3 As shown, the addressing mode is repeating, the target texel index is used to indicate the target texel, the target texel is determined from the multiple texels contained in the fourth texture image, and the target texel refers to the texel corresponding to the input texture coordinates;
[0154] The texel adjustment unit is also used to determine the initial texel index, which is determined based on the remainder of the first ratio, the fractional part of the input texture coordinates, and the texture size; and to determine the target texel index as the initial texel index.
[0155] The fourth texture image refers to the image resource that serves as the foundation for texture data in repetitive addressing mode. It consists of a series of texels arranged according to a specific pattern. Each texel has different visual attributes such as color and brightness, which together form a specific texture pattern. In the graphics rendering process, it is the core data set used to find the target texel corresponding to the input texture coordinates when implementing texture mapping.
[0156] In some embodiments, the characteristic of the repeating addressing mode is that when the input texture coordinates exceed the boundary of the texture image, the texture continues to extend in a seamless repeating manner. This means that the texture is spatially periodic, and the texture information in the excess portion is repeated with the information inside the texture image. By using the remainder of the first ratio, the fractional part of the input texture coordinates, and the texture size to determine the initial texel index, the texture coordinates exceeding the boundary are actually mapped back to the corresponding texel position inside the texture image. Because the texture is repeating, this mapped initial texel index is visually equivalent to the texel that should have been at the excess boundary position, i.e., the target texel. This mapping method ensures the continuity and consistency of the texture throughout the entire space. Regardless of where the input texture coordinates are located, the corresponding texel can be found through a unified calculation rule, so the initial texel index can be directly determined as the target texel index.
[0157] The above method can directly determine the initial texel index as the target texel index in repeated addressing mode, ensuring the accuracy of texture mapping.
[0158] It should be noted that the first texture image, the second texture image, the third texture image, and the fourth texture image mentioned above are the original texture images used for texture mapping in different addressing modes. They can all be the same (i.e., the same texture image) or they can be different (i.e., different texture images).
[0159] The following is an embodiment of the texel index calculation method applied to the above-mentioned ALU 20. For details, please refer to the relevant content on the ALU side above. This application will not repeat it here.
[0160] Please refer to Figure 4This document illustrates a flowchart of a texel index calculation method applied to an ALU, as provided in one possible implementation of this application. This application provides a texel index calculation method applied to an ALU. The ALU includes: a first comparator, a first divider, a first adder, and a texel adjustment unit; the method may include at least one of the following steps 410-440. It should be noted that this application does not limit the execution order of steps 410-440.
[0161] Step 410, the first comparator determines a first value, which is determined based on the smaller of the integer part of the input texture coordinates and the maximum offset.
[0162] Step 420: The first divider calculates the ratio between the input offset and the first divisor to obtain the first ratio. The input offset is used to indicate the offset of the texel relative to at least one texture image. The first divisor is determined based on the texture size or the maximum offset. The texture size is used to indicate the size of the texture image. The first ratio includes the quotient and the remainder.
[0163] Step 430: The first adder calculates the sum of the quotient of the first ratio, the first value, and the second value to obtain the first calculation result. The second value is determined based on the remainder of the first ratio and the decimal part of the input texture coordinates.
[0164] Step 440: The texel adjustment unit determines the target texel index corresponding to the input texture coordinates based on at least one of the first calculation result and the addressing mode.
[0165] In some embodiments, the first comparator is used to compare the absolute value of the integer part of the input texture coordinate with the absolute value of the maximum offset to obtain a first comparison result; and to determine the first value based on the first comparison result.
[0166] In some embodiments, if the absolute value of the integer part of the input texture coordinate is greater than the absolute value of the maximum offset, the first comparator determines that the value of the first value is greater than 2. n-1 And less than 2 n The sign of the first value is the sign of the input texture coordinate, and n is the number of bits corresponding to the maximum offset; if the absolute value of the integer part of the input texture coordinate is less than or equal to the absolute value of the maximum offset, the first value is determined to be the integer part of the input texture coordinate.
[0167] In some embodiments, the first comparator determines that the first value is greater than 2 if the absolute value of the integer part of the input texture coordinates is greater than the absolute value of the maximum offset, and the integer part of the input texture coordinates is even. n-1 And less than 2n If the integer part of the input texture coordinates is even, and the absolute value of the integer part of the input texture coordinates is greater than the absolute value of the maximum offset, and the integer part of the input texture coordinates is odd, then the first value is determined to be greater than 2. n-1 And less than 2 n Odd numbers.
[0168] In some embodiments, the ALU further includes a multiplier, a second adder, and a second comparator; the multiplier calculates the product of the fractional part of the input texture coordinates and the texture size to obtain a first product; the second adder calculates the sum of the remainders of the first product and the first ratio to obtain a second calculation result; the second comparator compares the absolute value of the second calculation result with the size of the texture size to obtain a second comparison result; based on the second comparison result, a second value is determined, the second value being used to indicate whether a complete texture image is offset.
[0169] In some embodiments, the second comparator determines the second value to be 0 if the absolute value of the second calculation result is less than the texture size; the second comparator determines the second value to be 1 or -1 if the absolute value of the second calculation result is greater than or equal to the texture size.
[0170] In some embodiments, the second comparator determines the second value to be 1 when the absolute value of the second calculation result is greater than or equal to the texture size and the second calculation result is positive; and determines the second value to be -1 when the absolute value of the second calculation result is greater than or equal to the texture size and the second calculation result is negative.
[0171] In some embodiments, the ALU further includes a third comparator; the third comparator determines the first divisor to be the texture size when the texture size is less than or equal to the absolute value of the maximum offset; and determines the first divisor to be the absolute value of the maximum offset when the texture size is greater than the absolute value of the maximum offset.
[0172] In some embodiments, the addressing mode is mirroring, the target texel index is used to indicate the target texel, the target texel is determined based on the first texture image, and the target texel refers to the texel corresponding to the input texture coordinates; the texel adjustment unit determines the initial texel index, which is determined based on the remainder of the first ratio, the fractional part of the input texture coordinates, and the texture size; when the first calculation result is even, it is determined that the target texel belongs to an even multiple texture image, and the target texel index is determined to be the initial texel index, the even multiple texture image is used to indicate that no mirror flip needs to be performed relative to the first texture image; when the first calculation result is odd, it is determined that the target texel belongs to an odd multiple texture image, and the target texel index is determined to be the texture size minus 1 minus the initial texel index, the odd multiple texture image is used to indicate that a mirror flip needs to be performed relative to the first texture image.
[0173] In some embodiments, the addressing mode is a pinch-to-grid, the target texel index is used to indicate a target texel, the target texel is determined from a plurality of texels contained in the second texture image, and the target texel refers to the texel corresponding to the input texture coordinates; when the first calculation result is greater than or equal to 0 and less than 1, an initial texel index is determined, the initial texel index is determined based on the remainder of the first ratio, the fractional part of the input texture coordinates and the texture size; the target texel index is determined as the initial texel index; when the first calculation result is less than 0, the target texel index is determined as index 0; when the first calculation result is greater than or equal to 1, the target texel index is determined as the texture size minus 1.
[0174] In some embodiments, the addressing mode is border color, the target texel index is used to indicate the target texel, the target texel is determined based on a third texture image, and the target texel refers to the texel corresponding to the input texture coordinates; the texel adjustment unit determines an initial texel index when the first calculation result is greater than or equal to 0 and less than 1, the initial texel index is determined based on the remainder of the first ratio, the fractional part of the input texture coordinates, and the texture size; the target texel index is determined as the initial texel index; when the first calculation result is less than 0 or greater than 1 or equal to 1, the target texel index is determined as the index of the border texel.
[0175] In some embodiments, the addressing mode is repeating, the target texel index is used to indicate a target texel, the target texel is determined from a plurality of texels contained in the fourth texture image, and the target texel refers to the texel corresponding to the input texture coordinates; the texel adjustment unit determines an initial texel index, the initial texel index is determined based on the remainder of the first ratio, the fractional part of the input texture coordinates and the texture size; the target texel index is determined as the initial texel index.
[0176] An exemplary embodiment of this application also provides a chip product, which includes a processor that includes the ALU described above. Optionally, the chip product may be a GPU chip product, with the processor being a GPU that includes the ALU described above. Optionally, the above-described chip product may be implemented as a graphics card, which includes a processor that includes the ALU described above.
[0177] An exemplary embodiment of this application also provides a computer device, which includes a processor including the ALU described above. Optionally, the computer device may be a personal computer, workstation, game console, and some mobile devices (such as tablet computers, smartphones, etc.), or it may be an in-vehicle terminal device, smart home device, smart TV, smart robot, etc., or it may be a server, server cluster, artificial intelligence computing cluster, cloud computing cluster, etc., wherein the artificial intelligence computing cluster may also be simply referred to as an intelligent computing cluster or smart computing cluster, and this application does not limit it in this regard.
[0178] It should be understood that "multiple" as used herein refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. Furthermore, the step numbers described herein are merely illustrative of one possible execution order. In some other embodiments, the steps may not be executed in numerical order, such as two steps with different numbers being executed simultaneously, or two steps with different numbers being executed in the reverse order of the illustration. This application does not limit this.
[0179] The above description is merely an exemplary embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. An arithmetic logic unit (ALU), characterized in that, The ALU includes: a first comparator, a first divider, a first adder, and a texel adjustment unit; The first comparator is used to determine a first value, which is determined based on the smaller of the integer part of the input texture coordinates and the maximum offset; The first divider is used to calculate the ratio between the input offset and the first divisor to obtain the first ratio, wherein the input offset is used to indicate the offset of the texel relative to at least one texture image, and the first divisor is determined based on the texture size or the maximum offset, wherein the texture size is used to indicate the size of the texture image, and the first ratio includes the quotient and the remainder. The first adder is used to calculate the sum of the quotient of the first ratio, the first value, and the second value to obtain a first calculation result. The second value is determined based on the remainder of the first ratio and the decimal part of the input texture coordinates. The texel adjustment unit is used to determine the target texel index corresponding to the input texture coordinates based on at least one of the first calculation result and the addressing mode.
2. The ALU according to claim 1, characterized in that, The first comparator is used to compare the absolute value of the integer part of the input texture coordinate with the absolute value of the maximum offset to obtain a first comparison result; based on the first comparison result, the first value is determined.
3. The ALU according to claim 2, characterized in that, The first comparator is further configured to determine that the value of the first numerical value is greater than 2 if the absolute value of the integer part of the input texture coordinates is greater than the absolute value of the maximum offset. n-1 And less than 2 n The sign of the first value is the sign of the input texture coordinate, and n is the number of bits corresponding to the maximum offset; The first comparator is further configured to determine that the first value is the integer part of the input texture coordinates if the absolute value of the integer part of the input texture coordinates is less than or equal to the absolute value of the maximum offset.
4. The ALU according to claim 3, characterized in that, The first comparator is further configured to determine that the value of the first numerical value is greater than 2 if the absolute value of the integer part of the input texture coordinates is greater than the absolute value of the maximum offset, and the integer part of the input texture coordinates is even. n-1 And less than 2 n Even numbers; The first comparator is further configured to determine that the first value is greater than 2 if the absolute value of the integer part of the input texture coordinates is greater than the absolute value of the maximum offset, and the integer part of the input texture coordinates is odd. n-1 And less than 2 n Odd numbers.
5. The ALU according to claim 1, characterized in that, The ALU also includes a multiplier, a second adder, and a second comparator; The multiplier is used to calculate the product of the fractional part of the input texture coordinates and the texture size to obtain a first product; The second adder is used to calculate the sum of the remainders of the first product and the first ratio to obtain a second calculation result; The second comparator is used to compare the absolute value of the second calculation result with the size of the texture to obtain a second comparison result; Based on the second comparison result, a second value is determined, which is used to indicate whether a complete texture image is offset.
6. The ALU according to claim 5, characterized in that, The second comparator is further configured to determine that the second value is 0 if the absolute value of the second calculation result is less than the texture size; The second comparator is further configured to determine that the second value is 1 or -1 if the absolute value of the second calculation result is greater than or equal to the texture size.
7. The ALU according to claim 6, characterized in that, The second comparator is further configured to determine that the second value is 1 when the absolute value of the second calculation result is greater than or equal to the texture size and the second calculation result is a positive number; The second comparator is further configured to determine the second value as -1 when the absolute value of the second calculation result is greater than or equal to the texture size and the second calculation result is negative.
8. The ALU according to claim 1, characterized in that, The ALU also includes a third comparator; The third comparator is used to determine the first divisor as the texture size when the texture size is less than or equal to the absolute value of the maximum offset; The third comparator is further configured to determine that the first divisor is the absolute value of the maximum offset when the texture size is greater than the absolute value of the maximum offset.
9. The ALU according to claim 1, characterized in that, The addressing mode is mirrored, the target texel index is used to indicate the target texel, the target texel is determined based on the first texture image, and the target texel refers to the texel corresponding to the input texture coordinates; The texel adjustment unit is further configured to determine an initial texel index, which is determined based on the remainder of the first ratio, the fractional part of the input texture coordinates, and the texture size. The texel adjustment unit is further configured to determine that the target texel belongs to an even-multiple texture image when the first calculation result is even, and to determine that the target texel index is the initial texel index, wherein the even-multiple texture image is used to indicate that no mirror flip needs to be performed relative to the first texture image; The texel adjustment unit is further configured to determine that the target texel belongs to an odd-multiple texture image when the first calculation result is odd, and to determine that the target texel index is the texture size minus 1 minus the initial texel index, wherein the odd-multiple texture image is used to indicate that a mirror flip needs to be performed relative to the first texture image.
10. The ALU according to claim 1, characterized in that, The addressing mode is gripping, the target texel index is used to indicate the target texel, the target texel is determined from a plurality of texels contained in the second texture image, and the target texel refers to the texel corresponding to the input texture coordinates; The texel adjustment unit is further configured to determine an initial texel index when the first calculation result is greater than or equal to 0 and less than 1, wherein the initial texel index is determined based on the remainder of the first ratio, the fractional part of the input texture coordinates, and the texture size; and to determine the target texel index as the initial texel index. The texel adjustment unit is further configured to determine the target texel index as index 0 when the first calculation result is less than 0. The texel adjustment unit is further configured to determine the target texel index as the texture size minus 1 if the first calculation result is greater than or equal to 1.
11. The ALU according to claim 1, characterized in that, The addressing mode is border color, the target texel index is used to indicate the target texel, the target texel is determined based on the third texture image, and the target texel refers to the texel corresponding to the input texture coordinates; The texel adjustment unit is further configured to determine an initial texel index when the first calculation result is greater than or equal to 0 and less than 1, wherein the initial texel index is determined based on the remainder of the first ratio, the fractional part of the input texture coordinates, and the texture size; and to determine the target texel index as the initial texel index. The texel adjustment unit is further configured to determine the target texel index as the index of the border texel when the first calculation result is less than 0, greater than 1, or equal to 1.
12. The ALU according to claim 1, characterized in that, The addressing mode is repeating, the target texel index is used to indicate the target texel, the target texel is determined from multiple texels contained in the fourth texture image, and the target texel refers to the texel corresponding to the input texture coordinates; The texel adjustment unit is further configured to determine an initial texel index, which is determined based on the remainder of the first ratio, the fractional part of the input texture coordinates, and the texture size; and to determine the target texel index as the initial texel index.
13. A method for calculating texel indexes applied to an arithmetic logic unit (ALU), characterized in that, The ALU includes: a first comparator, a first divider, a first adder, and a texel adjustment unit; the method includes: The first comparator determines a first value, which is based on the smaller of the integer part of the input texture coordinates and the maximum offset; The first divider calculates the ratio between the input offset and the first divisor to obtain a first ratio, wherein the input offset is used to indicate the offset of a texel relative to at least one texture image, and the first divisor is determined based on the texture size or the maximum offset, wherein the texture size is used to indicate the size of the texture image, and the first ratio includes a quotient and a remainder. The first adder calculates the sum of the quotient of the first ratio, the first value, and the second value to obtain a first calculation result. The second value is determined based on the remainder of the first ratio and the decimal part of the input texture coordinates. The texel adjustment unit determines the target texel index corresponding to the input texture coordinates based on at least one of the first calculation result and the addressing mode.
14. A processor, characterized in that, The processor includes an ALU as described in any one of claims 1 to 12.
15. A chip product, characterized in that, The chip product includes a processor, the processor including an ALU as described in any one of claims 1 to 12.
16. A computer device, characterized in that, The computer device includes a processor, the processor including an ALU as described in any one of claims 1 to 12.
Citation Information
Patent Citations
Cache architecture for efficiently accessing texture data using buffers
CN107153617A
Input / output filter unit for use in graphics processing unit
CN113888389A