dx10 学习随笔(四)

    技术2022-05-20  43

    Input-Assemble (IA) Stage

    本文开始,从Input-Assemble Stage开始对Pipeline Stage进行全面详细的阐述。

     

    前面讲过,D3D10 API 把管线按照功能划分为若干个Stage,其中第一个Stage就是Input-Assemble (IA) Stage。

     

    IA Stage 的第一个目的是从用户定义填充好的buffer中读取数据,并把数据组装成管线中其他Stage可以使用的图元。IA Stage可以

     

    把顶点组装为不同的图元(line lists、triangle strips、primitive with adjacency)。新的图元类型(例,具有邻接信息的linelist和

     

    trianglelist)被添加,用来支持geometry shader。

     

    Adjacency information 只是对 GS 才有用。例如,如果 GS 用到了 triangle Adjacency ,则输入数据中除了每个三角形对应三个

     

    顶点外,每个 Adjacency triangle 也对应三个顶点。

     

    当 IA Stage 要求输出邻接信息时,其输入数据中必须先包含了邻接信息。这有可能会用到 dummy vertex (forming a

     

    degenerate  triangle)的概念,或者通过在顶点的属性中添加一个标记,用来标识该顶点是否真实的存在。这个标记或 dummy vertex

     

    要能被 GS 来识别,并且用来在 rasterizer Stage 时进行裁剪。

     

    IA Stage 的第二个目的是在组装图元时,使用 system-generated values 来使 shaders 更加高效。system-generated

     

    values其实就是被称作 semantics 的字符串。后续的三个 shader Stages 是基于 common shader core 的, comman shader

     

    core 使用system generated values (primitive id 、instance id 、vertex id),使得一个 shader Stage 只处理那些没有被处理

     

    的primitives、instances、vertexs,从而提高了 shader 的效率。

     

    初始化 IA Stage 可以通过以下几步来实现。

     

    1、Create Input Buffer。

     

         包括 vertexbuffer 和 indexbuffer。

     

    2、Create the Input-Layout Object。

     

        例,

     

                D3D10_INPUT_ELEMENT_DESC layout[] =

    { { L"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { L"TEXTURE0", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { L"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 1, 20, D3D10_INPUT_PER_VERTEX_DATA, 0 }, };

        ID3D10Device::CreateInputLayout

    3、Bind Objects to the Input-Assembler Stage。

     

         ID3D10Device::IASetVertexBuffers and ID3D10Device::IASetInputLayout.

     

    4、Specify the Primitive Type。

     

        ID3D10Device::IASetPrimitiveTopology

     

    5、Call Draw Methods。

     

       ID3D10Device::Draw Draw non-indexed, non-instanced primitives.

     

               ID3D10Device::DrawInstanced Draw non-indexed, instanced primitives.

     

               ID3D10Device::DrawIndexed Draw indexed, non-instanced primitives.

     

               ID3D10Device::DrawIndexedInstanced Draw indexed, instanced primitives.

     

               ID3D10Device::DrawAuto Draw non-indexed, non-instanced primitives from input data that comes from the

     

               streaming-output stage.

     

     


    最新回复(0)