Cross-platform rendering framework attempt-management of GPU buffer (1)

Source: Internet
Author: User

Buffer Resource

Let's talk about the management of buffer. The buffer resource is broadly defined as an array of C languages. As shown in.

Generalized model of Figure buffer

The following buffer types are available in the rendering pipeline, either OpenGL or DX or other rendering APIs.  Vertex buffer,index buffer,constant buffer,structured buffer,raw buffer with indirect arguments buffer. The difference between these buffer is two.

The first is the memory structure. There are streaming buffer, such as vertex buffer and index buffer, which behave more like data streams, the data is read sequentially, so the memory is distributed tightly and continuously. While structured Buffer,constatn buffer is a structured buffer, these are typically memory-aligned according to certain rules in order to satisfy the need for efficient, random-access buffer data in the GPU.

Second, what has been mentioned above is the difference in the way of access. Because of the different ways of access, the memory structure is different. Streaming data is often a large amount of data (tens of thousands of fixed points, hundreds of thousands of indexes of high modulus), only provides sequential access, and the work of access has been assisted by different stages in shader. And the structure of the buffer often shader the data in the program is not the same as the flow of data, but more efficient and convenient random access to the buffer data, they have in the shader program similar to operator[] (constant buffer), There is also a stack-like behavior (append & consume buffer).

The management of buffer resources basically follows two key points. 1. The size of an element and the number of elements 2. How to facilitate application initialization and access to buffer data on the CPU side. The first determines the size of the entire buffer, and the second is the interface in which buffer operates data in the application segment.

These buffer resources are discussed in detail in the latter space, and the management of buffer is more complex than texture, starting with vertex buffer and index buffer. As previously stated, vertex buffer and index buffer are streaming data. In general, their data is stored in the model file, and the program loads the data, creating VB and IB as input to the application. vertex buffer can also be used as the output of the geometry shader in addition to being input.

Vertex buffer

Figure Vertex Buffer

We borrowed the concept of input layout in the D3D API to manage the size of unit elements in VB. A unit element of VB, which is composed of several basic one-dimensional vector-type attributes (attribute), is arranged sequentially.

Input layout is provided by
1. Describe the type of each attribute;

Enum class DATA_FORMAT{FLOAT_,FLOAT2,        ///... float4x4,int_,/        /... uint4,structured,};;;..

  

2. Describes the offset of each property relative to the starting position of the element's memory

3. Describe the semantics of each attribute (useful in D3D)

Enum class data_semantic{position,normal,binormal,tangent,texcoord0,texcoord1,//... Texcoord7,color0,color1,} ;

  

In this way, input layout can fully calculate the size of VB unit elements, and assist in the application segment of VB initialization and access to data work.

In leaves: the implementation macro of the:p Ipeline::buffer, In addition to the ptr_as<t> () template member function provided by the Buffer<vertex_buffer> base class, facilitates direct memory copy, The VB we manage also provides an iterator similar to the STL access container, with the semantics to access the elements in VB.

Index buffer

Figure Index Buffer

The management of index buffer is slightly simpler than VB. A unit element is an shaping. So its iterators are also lightweight, using pointers directly. But index buffer also needs to manage a primitive type. It describes the topological relationship between the fixed-point indexes:

Diagram Basic topology

Figure Line_list_adj and Line_strip_adj

Figure Triangle_list_adj

Figure Triangle_strip_adj

Different topological relationships affect the number of index buffer elements, which can be implemented according to the relationship of the above graphs to a function that calculates the number of indices by the number of primitive.

The next article will detail the management of constant buffer and the remaining buffer.

Detailed implementation code hosting in https://github.com/IndignantAngel/modern-graphics-framework , welcome the great God to come to advise.

Cross-platform rendering framework attempt-management of GPU buffer (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.