A vertex shading method based on vertex buffer
By introducing vertex buffers in the GPU, storing and reusing the rendered vertex data, the poor performance problem caused by repeated vertex rendering in the prior art is solved, and more efficient rendering performance and stronger system scalability are achieved.
Patent Information
- Application Number
- CN202210022711.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-10
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2042-01-10
AI Technical Summary
In the existing GPU vertex shading process, vertex shading is performed linearly, resulting in the input of the same vertex needs to be rendered repeatedly, and the performance is poor.
By introducing a vertex buffer into the GPU, vertex data that has been rendered is stored and the rendered vertices are directly obtained from the buffer when needed, avoiding repeated rendering.
Improves the rendering performance of the GPU, reduces hardware blockage caused by repeated vertex rendering, and enhances the scalability of the system.
Smart Images

Figure CN114359432B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of graphics rendering, and in particular to a vertex shading method implemented based on a vertex buffer. Background Art
[0002] The existing GPU vertex shading process is: the vertices to be rendered are input into the GPU vertex shading module, and the hardware performs vertex shading on each vertex. After shading is completed, the vertex data is directly transmitted to the subsequent processing module.
[0003] The advantage of this process is the low hardware cost; but the disadvantage is that vertex shading is executed linearly, and the same vertex needs to be rendered repeatedly, resulting in poor performance. Summary of the invention
[0004] The present invention provides a vertex shading method based on vertex buffer, aiming to add a storage area for vertex buffer to solve the problem of repeated rendering of vertices and poor performance.
[0005] The present invention provides a vertex shading method based on a vertex buffer, comprising the following steps:
[0006] S1. After the vertex data preparation stage, the hardware module obtains the vertex data required for vertex shading and the vertex index corresponding to the vertex data;
[0007] S2. Send the vertex index that needs to be vertex colored to the vertex coloring module and the subsequent processing module;
[0008] S3. The subsequent processing module queries the vertex buffer area according to the vertex index. If a vertex of the desired state is found, the subsequent processing module directly obtains the vertex and ends the process; if no vertex of the desired state is found, step S4 is executed;
[0009] S4. The vertex shading module queries the vertices in the vertex buffer area according to the received vertex index and renders the unshaded vertices;
[0010] S5. The subsequent processing module queries the vertices in the vertex buffer area according to the vertex index and obtains the rendered vertices to perform subsequent processing.
[0011] As a further improvement of the present invention, step S3 specifically includes:
[0012] The subsequent processing module queries the vertex buffer area according to the vertex index. If the vertex corresponding to the vertex index is found in the vertex buffer area and the vertex is in a completed state, the subsequent processing module directly obtains the vertex and ends the process; if the vertex in the required state is not found, step S4 is executed.
[0013] As a further improvement of the present invention, step S4 includes:
[0014] S41. The vertex shading module queries the vertex buffer area according to the vertex index. If the vertex in the completed state already exists in the vertex buffer area, the work of the vertex shading module is completed; otherwise, it searches for an unused area in the vertex buffer area, pre-stores the vertex coordinate data and vertex index that need to be shaded in the vertex buffer area, and converts the state of this vertex in the vertex buffer area from the idle state to the initiated state.
[0015] As a further improvement of the present invention, the step S4 further includes:
[0016] S42. After a certain amount of vertices that need vertex shading are received in the vertex buffer area, the vertex data preparation stage sends a signal to the vertex shading module. The vertex shading module queries and obtains the vertex coordinate data corresponding to the vertex index in the vertex buffer based on the received vertex index, and converts the state of the vertex from the initiating state to the working state. The vertex shading module performs vertex shading on the corresponding vertex.
[0017] As a further improvement of the present invention, the step S4 further includes:
[0018] S43. After the vertex shading module completes the vertex shading work of a vertex, it stores the vertex coordinate data back to the location of the original vertex coordinate data in the vertex buffer area, and converts the state of the vertex from the working state to the completed state.
[0019] As a further improvement of the present invention, in the vertex pre-storage process of step S41, if the vertex buffer area is full, the vertex with a less number of accesses in the vertex buffer area is replaced with a new vertex.
[0020] As a further improvement of the present invention, step S5 specifically includes:
[0021] The subsequent processing module continuously queries whether the vertex corresponding to the vertex index in the vertex buffer area is in a completed state based on the received vertex index; if the vertex cannot be found or the vertex state is not in a completed state, the subsequent processing module will continue to wait for a period of time and then re-initiate a query on the vertex buffer; if the vertex corresponding to the vertex index is in a completed state, the subsequent processing module will obtain the vertex and end the process.
[0022] The beneficial effects of the present invention are:
[0023] (1) Performance improvement: the GPU only needs to render different vertices, which can fully utilize the hardware performance and reduce the congestion caused by the GPU needing to color vertices;
[0024] (2) Strong scalability. Through software development, users can directly capture vertex data after shading, reducing the pressure on users to build vertex attribute matrices, which can be used for the next rendering command.
[0025] (3) Reduce the GPU's read and write operations on the video memory. If the subsequent processing module obtains duplicate vertex data, the vertex processing module no longer needs to read and write vertex data. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 The present invention is a flow chart of a method for implementing vertex shading based on a vertex buffer. DETAILED DESCRIPTION
[0027] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments.
[0028] like Figure 1 As shown, the present invention provides a vertex shading method based on a vertex buffer, adds a storage area for vertex buffer, stores the rendered vertices, and the hardware module retrieves vertex data from the vertex buffer as needed, including the following steps:
[0029] S1. After the vertex data preparation stage, the hardware obtains the vertex data required for vertex shading and the vertex indexes of these vertex data.
[0030] S2. Send the index of the vertex that needs to be vertex colored to the vertex coloring module and the subsequent processing module.
[0031] S3. The subsequent processing module queries the vertex buffer according to the vertex index. If the vertex corresponding to the vertex index exists in the vertex buffer and the vertex is in a completed state, the subsequent processing module directly obtains the vertex and the process ends. If the vertex in the required state cannot be found, execute step S4.
[0032] S41. The vertex shading module will also query the vertex buffer according to the vertex index. If the vertex buffer already has the completed vertex, the vertex shading module is done. Otherwise, it will search for some unused areas in the vertex buffer, pre-store the vertex coordinate data and vertex index that need to be shaded in the vertex buffer, and convert the status of these vertices in the vertex buffer from the idle state to the initiated state. If the vertex buffer is full, replace the vertex with the less visited times in the vertex buffer with the new vertex.
[0033] S42. After the vertex buffer receives a certain amount of vertices that need vertex shading, the vertex data preparation stage sends a signal to the vertex shading module. Then the vertex shading module queries and obtains the vertex coordinate data of the corresponding vertex index in the vertex buffer based on the received vertex index, and converts the state of the vertex from the initiating state to the working state. Then the vertex shading module performs vertex shading on the corresponding vertex.
[0034] S43. After the vertex shading module completes the vertex shading work of a vertex, it stores the vertex coordinate data back to the location of the original vertex coordinate data in the vertex buffer, and converts the state of the vertex from the working state to the completed state.
[0035] S5. The subsequent processing module continuously queries the vertex buffer for the vertex corresponding to the vertex index based on the received vertex index to see if it is in the completed state. If the vertex cannot be found or the vertex state is not in the completed state, the subsequent processing module will continue to wait for a while and then re-initiate a query on the vertex buffer; if the vertex corresponding to the vertex index is in the completed state, the subsequent processing module will obtain the vertex and this process ends.
[0036] The vertex index will be sent to the vertex shading module and the subsequent processing module at the same time. The subsequent processing module will continuously query the vertex buffer according to the vertex index until the vertex shading module completes the vertex shading of the corresponding vertex and stores the vertex data in the vertex buffer. The subsequent processing module obtains the vertex data it needs and starts subsequent processing.
[0037] The present invention is applied to OpenGL applications that need to render a large number of repeated vertices and want to improve rendering performance. It has the following advantages:
[0038] Performance is improved, and the GPU only needs to render different vertices. It can fully utilize the hardware performance and reduce the congestion caused by the GPU needing to color vertices; it has strong scalability. Through software development, the use of vertex buffers can realize the transform feedback function, allowing users to directly capture the vertex data that has been colored, reducing the pressure on users to build vertex attribute matrices, and can be used for the next rendering command; reducing the GPU's read and write operations on the video memory. If the subsequent processing module obtains duplicate vertex data, the vertex processing module no longer needs to read and write vertex data.
[0039] The above contents are further detailed descriptions of the present invention in combination with specific preferred embodiments, and it cannot be determined that the specific implementation of the present invention is limited to these descriptions. For ordinary technicians in the technical field to which the present invention belongs, several simple deductions or substitutions can be made without departing from the concept of the present invention, which should be regarded as falling within the protection scope of the present invention.
Claims
1. A vertex shading method based on a vertex buffer, characterized in that: The following steps are involved: S1. After the vertex data preparation stage, the hardware module obtains the vertex data required for vertex shading and the vertex index corresponding to the vertex data; S2. Send the vertex index that needs to be vertex colored to the vertex coloring module and the subsequent processing module; S3. The subsequent processing module queries the vertex buffer area according to the vertex index. If a vertex of the required state is found, the subsequent processing module directly obtains the vertex and ends the process; if no vertex of the required state is found, step S4 is executed; S4. The vertex shading module queries the vertices in the vertex buffer area according to the received vertex index and renders the unshaded vertices; S5. The subsequent processing module queries the vertices in the vertex buffer area according to the vertex index and obtains the vertices after rendering to perform subsequent processing; The step S3 specifically includes: The subsequent processing module queries the vertex buffer area according to the vertex index. If the vertex corresponding to the vertex index is found in the vertex buffer area and the vertex is in a completed state, the subsequent processing module directly obtains the vertex and ends the process. If the vertex in the required state cannot be found, step S4 is executed. The step S5 specifically includes: The subsequent processing module continuously queries whether the vertex corresponding to the vertex index in the vertex buffer area is in a completed state based on the received vertex index; if the vertex cannot be found or the vertex state is not in a completed state, the subsequent processing module will continue to wait for a period of time and then re-initiate a query on the vertex buffer; if the vertex corresponding to the vertex index is in a completed state, the subsequent processing module will obtain the vertex and end the process.
2. The vertex shading method based on the vertex buffer according to claim 1, characterized in that: The step S4 comprises: S41. The vertex shading module queries the vertex buffer area according to the vertex index. If the vertex in the completed state already exists in the vertex buffer area, the work of the vertex shading module is completed; otherwise, it searches for an unused area in the vertex buffer area, pre-stores the vertex coordinate data and vertex index that need to be shaded in the vertex buffer area, and converts the state of this vertex in the vertex buffer area from the idle state to the initiated state.
3. The vertex shading method based on vertex buffer according to claim 2, characterized in that: The step S4 further comprises: S42. After a certain amount of vertices that need vertex shading are received in the vertex buffer area, the vertex data preparation stage sends a signal to the vertex shading module. The vertex shading module queries and obtains the vertex coordinate data corresponding to the vertex index in the vertex buffer based on the received vertex index, and converts the state of the vertex from the initiating state to the working state. The vertex shading module performs vertex shading on the corresponding vertex.
4. The vertex shading method based on vertex buffer according to claim 3 is characterized in that: The step S4 further comprises: S43. After the vertex shading module completes the vertex shading work of a vertex, it stores the vertex coordinate data back to the location of the original vertex coordinate data in the vertex buffer area, and converts the state of the vertex from the working state to the completed state.
5. The vertex shading method based on vertex buffer according to claim 2, characterized in that: In the vertex pre-storage process of step S41, if the vertex buffer area is full, the vertex with a less number of accesses in the vertex buffer area is replaced with a new vertex.
Citation Information
Patent Citations
Surface object rendering method, device and equipment and storage medium
CN109712225A
Image rendering method and device
CN110544291A