龙书11_chapter_6 一:一般绘制流程

2023-11-16

先看BoxDemo的前几节,

1.vertex input  Layout

2.vertexBuffer

3.IndexBuffer

4.vertexShader

5.constant Buffer

6.pixelShader

7.renderState

8.effect

1.vertex input  Layout

Once we have defined a vertex structure, we need to provide Direct3D with a description of our vertex structure so that
it knows what to do with each component. This description is provided to Direct3D in the form of an input layout
(ID3D11InputLayout).

创建vertexStruct后,需要提供具体数据描述,告知渲染管线数据是啥。

1. SemanticName: A string to associate with the element. This can be any valid variable name. Semantics are used
to map elements in the vertex structure to elements in the vertex shader input signature

 

顶点结构每个语义和shader里参数的语义进行匹配。

当然了,vertexShader里不同语义的顺序并不是问题,比如说把

struct VertexIn
{
 float4 Color : COLOR;
 float3 PosL : POSITION;                 切换成Position在前,Color在后,也是可正确绘制出box的,实际上是每个语以对应一个寄存器,但需要注意标记同语义的顺序;
};

 

void BoxApp::BuildVertexLayout()
{
    // Create the vertex input layout.
    D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
    {
        {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
        {"COLOR",    0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}
    };
    // Create the input layout
//1. pInputElementDescs: An array of D3D11_INPUT_ELEMENT_DESC elements describing the vertex structure.

2. NumElements: The number of elements in the D3D11_INPUT_ELEMENT_DESC elements array.
3. pShaderBytecodeWithInputSignature: A pointer to the shader byte-code of the input signature of the
vertex shader.
4. BytecodeLength: The byte size of the vertex shader signature data passed into the previous parameter.
5. ppInputLayout: Returns a pointer to the created input layout

    D3DX11_PASS_DESC passDesc;
    mTech->GetPassByIndex(0)->GetDesc(&passDesc);
//1.描述vertex struct的数组 2.数组元素 3.对应的shader内参数指针 4.size 5.获取layout HR(md3dDevice
->CreateInputLayout(vertexDesc, 2, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &mInputLayout)); }

After an input layout has been created, it is still not bound to the device yet. The last step is to bind the input layout
you want to use to the device as the following code shows:

md3dImmediateContext->IASetInputLayout(mInputLayout);

 

 2.vertexBuffer

Direct3D buffers not only store data, but also describe how
the data will be accessed and where it will be bound to the rendering pipeline.

buffer不仅存数据,还描述了获取数据的方式和绑定到渲染管线的哪里

第四章已经描述过针对buffer的usage的四种类别

Usage:

1.default,GPU读和写,CPU可使用UpdateSubSource(不理解...待解释)

2.immuate:GPU只读, 本次boxDemo中,vertex和index都是使用的此usage,因为并没有改变vertexBuffer内的值

3.dynamic :CPU可写,GPU读,用于每帧app修改数据

4.staging : CPU可从GPU中Copy数据进行读写。

CPUAccessFlags:

If the CPU needs to read from the buffer, specify D3D11_CPU_ACCESS_READ. A buffer with read access must
have usage D3D11_USAGE_STAGING.

In general, the CPU reading
from a Direct3D resource is slow (GPUs are optimized to pump data through the pipeline, but not read back) and
can cause the GPU to stall (the GPU may need to wait for the resource being read from to finish before it can
continue its work). The CPU writing to a resource is faster, but there is still the overhead of having to transfer the
updated data back to video memory. It is best to not specify any of these flags (if possible), and let the resource sit
in video memory where only the GPU writes and reads to it.

就是说CPU读GPU数据可能会造成GPU的延迟,

    D3D11_BUFFER_DESC vbd;
    vbd.Usage = D3D11_USAGE_IMMUTABLE;
    vbd.ByteWidth = sizeof(Vertex) * 8;
    vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vbd.CPUAccessFlags = 0;
    vbd.MiscFlags = 0;
    vbd.StructureByteStride = 0;
    D3D11_SUBRESOURCE_DATA vinitData;
    vinitData.pSysMem = vertices;
    HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mBoxVB));

创建vertexBuffer后,为了输入到具体的pipeline,需要绑定buffer给设备:

    md3dImmediateContext->IASetVertexBuffers(0,1,&mBoxVB,&stride,&offset);

3.index和indexBuffer

Note that DXGI_FORMAT_R16_UINT and
DXGI_FORMAT_R32_UINT are the only formats supported for index buffers.

4.VertexShader

If there is no geometry shader, then the vertex shader must at least do the projection transformation because
this is the space the hardware expects the vertices to be in when leaving the vertex shader (if there is
no geometry shader). If there is a geometry shader, the job of projection can be deferred to the
geometry shader.

A vertex shader (or geometry shader) does not do the perspective divide; it just does the projection matrix part.
The perspective divide will be done later by the hardware.

VS没有进行坐标归一化,只转换到齐次坐标系,硬件做了除w操作,到NDC空间。

6.Pixel shader

occluded by another pixel
fragment with a smaller depth value, or the pixel fragment may be discarded by a later pipeline test like the stencil
buffer test. Therefore, a pixel on the back buffer may have several pixel fragment candidates; this is the distinction
between what is meant by “pixel fragment” and “pixel,” although sometimes the terms are used interchangeably, but
context usually makes it clear what is meant.

(区分pixel和psF,一个pixel可能包括几个pixel fragment,然后进行fragment的筛选)

sv_target:指出PS的返回值类型要和renderTarget类型一致 

 

7.renderState

D3D是典型的状态机。  状态一直保持不变,直到进行更新。inputLayout,vertex/index Buffer,

 

8.Effects

1. technique11: A technique consists of one or more passes which are used to create a specific rendering
technique. For each pass, the geometry is rendered in a different way, and the results of each pass are combined
in some way to achieve the desired result. For example, a terrain rendering technique may use a multi-pass
texturing technique. Note that multi-pass techniques are usually expensive because the geometry is redrawn for
each pass; however, multi-pass techniques are required to implement some rendering techniques.
2. pass: A pass consists of a vertex shader, optional geometry shader, optional tessellation related shaders, a pixel
shader, and render states. These components indicate how to process and shade the geometry for this pass. We
note that a pixel shader can be optional as well (rarely). For instance, we may just want to render to the depth
buffer and not the back buffer; in this case we do not need to shade any pixels with a pixel shader.

 

Creating Direct3D resources is expensive and should always be done at initialization time, and never at
runtime. That means creating input layouts, buffers, render state objects, and effects should always be
done at initialization time.

就是说 创建工作要在initialization时候。

 

 

    mTech = mFX->GetTechniqueByName("ColorTech");
    mfxWorldViewProj= mFX->GetVariableByName("gWorldViewProj")->AsMatrix();

Note that these calls update an internal cache in the effect object, and are not transferred over to GPU memory
until we apply the rendering pass . This ensures one update to GPU memory instead of many small updates,
which would be inefficient.

数据的更新是在Effect调用pass后,一次性进行的。instead of many small updates

    mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj));
       
    D3DX11_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );
  for(UINT p = 0; p < techDesc.Passes; ++p)
  {
        mTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
        // 36 indices for the box.
        md3dImmediateContext->DrawIndexed(36, 0, 0);
  }

When the geometry is drawn in a pass, it will be drawn with the shaders and render states set by that pass. The
ID3DX11EffectTechnique::GetPassByIndex method returns a pointer to an ID3DX11EffectPass
interface, which represents the pass with the specified index. The Apply method updates the constant buffers stored in
GPU memory, binds the shader programs to the pipeline, and applies any render states the pass sets. In the current
version of Direct3D 11, the first parameter of ID3DX11EffectPass::Apply is unused, and zero should be
specified; the second parameter is a pointer to the device context the pass will use.

GetPassByIndex 获取pass的index,Apply更新GPU中的constantBuffer,绑定shader程序到管线,应用renderState

 

书中有趣的还是shader中不同条件的pass选取;

Observe that we have added an additional uniform parameter to the pixel shader that denotes the quality level.
This parameter is different in that it does not vary per pixel, but is instead uniform/constant. Moreover, we do not
change it at runtime either, like we change constant buffer variables. Instead we set it at compile time, and since the
value is known at compile time, it allows the effects framework to generate different shader variations based on its
value. This enables us to create our low, medium, and high quality pixel shaders without us duplicating code (the
effects framework basically duplicates the code for us as a compile time process), and without using branching
instructions.

#define low 0

#define mid 1(...high..)

float4 PS(IN_P pin,unsigned int Quality)

{

     if(Quality==low){...}

    else if(Quality==mid){...}

}

techique11 techLow

{

  pass0

{

 SetPixelShader(compilerShader(PS_5_0,PS(low))) 

}

}

techique11 techMid

{

  pass0

{

 SetPixelShader(compilerShader(PS_5_0,PS(mid))) 

}

}

....

这种方式可以提高代码的利用率,同时编译时,根据PS的参数不同选择编译代码,不编译条件不满足的部分。也许相当于预编译把。

 

 

 

添加ESC退出:在D3DApp.MsgProc.switch 函数内添加:

  //增添esc退出操作
    case WM_KEYDOWN:
        if (GetAsyncKeyState(VK_ESCAPE) & 0x8000)
        {
            PostQuitMessage(0);
            return 0;
        }

 

转载于:https://www.cnblogs.com/dust-fly/p/4528370.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

龙书11_chapter_6 一:一般绘制流程 的相关文章

  • 尝试在java中执行命令时出错[重复]

    这个问题在这里已经有答案了 我正在尝试使用终端但从 java 运行 java 文件 意思是 我将使用 java 运行该命令 我正在尝试执行命令 cd Users apple Documents Documents workspace Use
  • 在QML中动态创建ListModel

    当我需要在运行时创建任何 QML 组件时 我可以使用该指南 http qt project org doc qt 5 qtqml javascript dynamicobjectcreation html http qt project o
  • 需要裁剪+调整大小约 300000 个文件。运行时间 = 4 天以上。如何加快 bash 脚本的速度?

    我正在努力创建视频间隔拍摄 我拍摄的所有照片都是以 4 3 宽高比拍摄的 jpg 图像 2592x1944 分辨率 我希望它们在 1920x1080 下均为 16 9 我写了一个小脚本来执行此操作 但过程不是很快 我花了大约 17 分钟来裁
  • 在Java中,类上的静态方法有什么缺点吗?

    让我们假设在我的编码环境中已经强加了一条规则 或者经验法则 即类上不使用 修改或以其他方式需要任何实例变量来完成其工作的任何方法都将被设为静态 这样做是否有任何固有的编译时间 运行时间或任何其他缺点 已编辑以进一步澄清 我知道这个问题有点开
  • 什么是运行时环境?

    有人可以用简单的术语解释一下这意味着什么吗 是指应用程序代码运行的环境 DOS Windows Linux 等 吗 将其与开发环境和构建环境区分开来 您往往会在这里找到层次结构 运行时环境 执行程序所需的一切 但没有工具可以更改它 构建环境
  • PyCharm:如何推断运行时创建的对象的类型

    我正在尝试使用一个创建对象的库 并在运行时将它们添加到全局命名空间 PyCharm 无法找到对对象的引用 因为它们最初不在命名空间中 如何让 PyC harm 内省不抱怨 找不到参考 我不想用noinspection tags 示例代码 为
  • Regd : Android Nougat 中接听电话的支持

    我想在 Android Nougat 中实现接听电话功能 Google Nexus 5x 不支持接听电话 我们尝试使用代码 Runtime getRuntime exec input keyevent Integer toString Ke
  • 将大文件作为流发送到 process.getOutputStream

    我在 Windows 机器中使用 gzip 实用程序 我压缩了一个文件并作为 blob 存储在数据库中 当我想使用 gzip 实用程序解压缩此文件时 我将此字节流写入 process getOutputStream 但超过30KB后 就无法
  • 需要特殊数组(线性场)的算法

    我有一个数组 线性场 与预先排序的数字 1 2 3 4 5 6 但这些数组向右移动 k次 now its 5 6 1 2 3 4 k 2 但我不知道k 只有数组A 现在我需要一个算法来找到 A 中的最大值 运行时间 O logn 我认为它是
  • 如何禁用java中的运行时警告?

    我在 java 程序中使用 jar 文件 它在运行时生成警告 但我不希望我的客户看到这些警告 我怎样才能禁用这些警告 警告如下 Sep 25 2009 10 10 33 PM com gargoylesoftware htmlunit In
  • 什么时候插入排序比合并排序快?

    对于家庭作业问题 我被告知插入排序以 8n 2 运行 合并排序以 64 n lg n 运行 作为我得到的解决方案的一部分 它说只要 n 它来自这个 代数 推理路线 steps in insertion sort lt steps in me
  • Objective-C 中的标记指针

    While 回答这个问题 https stackoverflow com a 20362087 115200我注意到现代 Objective C 运行时使用标记指针 这迈克 阿什 Mike Ash 的文章及其评论 http www mike
  • 创建“拼写检查”,以合理的运行时间检查数据库

    我不是在询问如何实现拼写检查算法本身 我有一个包含数十万条记录的数据库 我想要做的是针对所有这些记录的表中的特定列检查用户输入 并返回具有特定汉明距离的任何匹配项 同样 这个问题不是关于确定汉明距离等 当然 目的是创建一个 您的意思是 功能
  • 类型稳定性如何让 Julia 如此之快?

    我听说类型稳定性使 Julia 如此之快 同时仍然与其他解释语言 例如 Python 一样具有表达能力 类型稳定性允许编译器在编译时直接根据输入类型确定函数的输出类型 因为 Julia 专门针对每种输入类型进行编译 这意味着如果所有函数都是
  • 无法调试,致命信号 6 (SIGABRT) 位于 0x00007c37(代码=-6)

    我遇到了以下情况 无法调试 Android 应用程序 我可以运行它 但无法调试它 我开始了全新的项目 复制了所有内容并且它有效 意味着能够调试 但又得到了这个 我在模拟器和手机上都尝试过 但没有成功 我使用的是Android Studio
  • 如何加载使用 VaryByControl OutputCache 的控件,并指定属性值

    我有一个应该使用缓存的用户控件 其中VaryByControl The ascx文件看起来像这样 p Nothing p The TestControl代码隐藏文件中的类有一个int Test 财产和Page Load 填充的事件处理程序S
  • 从 IntelliJ Ultimate 外部运行时,Tomcat 的“服务器日志”在哪里?

    当运行我的Vaadin https en wikipedia org wiki Vaadin app on Tomcat https en wikipedia org wiki Apache Tomcat8 5 外部来自IntelliJ h
  • 在运行时添加路由 (ExpressJs)

    我想在运行时添加路线 我读到这是可能的 但我不太确定如何 目前我使用以下代码 var app express function CreateRoute route app use route require routes customcha
  • 流畅的界面是否会显着影响 .NET 应用程序的运行时性能?

    我目前正忙于为现有技术实现一个流畅的接口 这将允许类似于以下代码片段的代码 using var directory Open Directory path to some directory using var file Open File
  • 运行时 SQL 查询生成器

    我的问题类似于 Java中有什么好的动态SQL生成器库吗 https stackoverflow com questions 5620985 is there any good dynamic sql builder library in

随机推荐

  • AIGC用于智能写作的技术综述-达观数据

    导语 图1 ChatGPT生成的关于智能写作的介绍 智能写作指使用自然语言处理技术来自动生成文本内容 这种技术通过分析给定语料库 学习文本的结构和语法 然后利用这些信息来生成新的文本 智能写作可以用来快速生成高质量的文本内容 并且可以用来完
  • 基于python管理系统论文_基于Python网络爬虫的设计与实现毕业论文+源码-学生毕业作品网站...

    本课题的主要目的是设计面向定向网站的网络爬虫程序 同时需要满足不同的性能要求 详细涉及到定向网络爬虫的各个细节与应用环节 搜索引擎作为一个辅助人们检索信息的工具 但是 这些通用性搜索引擎也存在着一定的局限性 不同领域 不同背景的用户往往具有
  • 第1章-Java语言概述

    Java基础知识图解 1 Java语言概述 1 1 Java简史 是SUN Stanford University Network 斯坦福大学网络公司 1995年推出的一门高级编程语言 是一种面向Internet的编程语言 Java一开始富
  • Unity的 Input.GetAxis使用

    使用GetAxis可获得很多常用的设备输入 鼠标左右键 滚轮 鼠标移动增量 空格跳跃 WSAD 可用这些输入增量进行操作控制 比如物体的前后左右移动 镜头前进后退 缩放观察 物体拖拽旋转等 转载于 https www cnblogs com
  • postman 执行下载接口时闪退问题

    下载内容过多时容易导致postman闪退 在试验接口正确性时不要着急 可以对下载日志大小进行一个缩减
  • vmware14安装黑苹果max ox x 10.13懒人版教程

    准备材料 vmware 14 0 链接 https pan baidu com s 1 fjAngjUZ9HihzboBR0eJA 提取码 wwnn vmware文件名后面有永久可用的序列号 14 0目前最高支持mac10 13 故使用这个
  • UVA 10970 - Big Chocolate

    Root AOAPC I Beginning Algorithm Contests Training Guide Rujia Liu UVA 10970 Big Chocolate 题意 计算将一块n m的巧克力切成n m块所需的次数 方法
  • Android studio报错:e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error

    Android studio运行时报错 e org jetbrains kotlin codegen CompilationException Back end JVM Internal error wrong bytecode gener
  • mtu设置--解决部分网站打不开的问题

    资料一 一 常见问题介绍 1 什么情况下需要改MTU 如果您的动态域名网站不能被正常访问 很难连接 连接上也非常慢 请试试把DirectSend设为 总是关闭 如果关闭后可以正常访问 这种情况就需要修改MTU 如果您的网站连接正常 只是下载
  • 达尔文商品体系

    一 背景介绍 最初是由天猫发起的 针对天猫品牌混乱 原始商品信息错误和商家重复铺货 商家的宝贝 库存价格等信息杂乱无章 商家发布商品流程冗长 管理商品非常不便 消费者也很难找到确定的商品相关信息 前台的搜索应用困难等问题 旨在规范商品信息确
  • 批量爬虫采集大数据的技巧和策略分享

    作为一名专业的爬虫程序员 今天主要要和大家分享一些技巧和策略 帮助你在批量爬虫采集大数据时更高效 更顺利 批量爬虫采集大数据可能会遇到一些挑战 但只要我们掌握一些技巧 制定一些有效的策略 我们就能在数据采集的道路上一帆风顺 1 设立合理的请
  • 服务器虚拟机无法连接msk,无法连接mks【图文详解】

    喜欢使用电脑的小伙伴们一般都会遇到win7系统无法连接mks的问题 突然遇到win7系统无法连接mks的问题就不知道该怎么办了 其实win7系统无法连接mks的解决方法非常简单 按照1 首先检查了下 windows的防火墙设置 可以看到Vm
  • QT笔记——QProcess学习

    我们常常想通过某一个类 来启动一个外部进程 本文将讲解如何通过QProcess来进行启动外部进程 一 了解QProcess QProcess是Qt框架提供的一个类 用于在应用程序中执行外部进程 它提供了一系列函数来启动 控制和与外部进程进行
  • axios请求超时

    axios请求超时 设置重新请求的完美解决方法 自从使用Vue2之后 就使用官方推荐的axios的插件来调用API 在使用过程中 如果服务器或者网络不稳定掉包了 你们该如何处理呢 下面我给你们分享一下我的经历 具体原因 最近公司在做一个项目
  • Spring Cloud Gateway学习

    文章大纲 为什么需要网关 传统的单体架构只有一个服务开放给客户端调用 但是在微服务架构体系中是将一个系统拆分成多个微服务 那么作为客户端如何去调用这些微服务呢 如果没有网关的存在 就只能在本地记录每个微服务的调用地址 无网关的微服务架构存在
  • C++之MFC学习

    问题1 stdafx h是怎么引入进来的 define h与stdafx h之间的关系 为什么在MuisicPlayer cpp中引入stdafx h 问题2 enum class的使用 问题3 列表初始化 int window trans
  • linux重做系统分区,搜索所有硬盘分区上的linux系统,重新安装grub的方法

    电脑硬盘上 非vmware 安装了Ubuntu Fedora Debian openSUSE linuxMint Mageia elementaryOS PearOS ZorinOS Bodhi Manjaro Sparky linuxDe
  • 【星球精选】如何高效构建 Roam 与 theBrain 间细粒度双向链接?

    Roam Research 作为卡片盒很好用 只是目前缺乏中观网络可视化能力 老牌知识管理应用TheBrian 可以很好补充上这个短板 因此我希望将二者结合起来使用 只是这个过程 有些曲折 在 Obsidian 中的 excalibrain
  • redis可视工具AnotherRedisDesktopManager的使用

    redis可视工具AnotherRedisDesktopManager的使用 系列文章 macm1安装redis过程 springboot整合redis及set map list key value和实体类操作 redis可视工具Anoth
  • 龙书11_chapter_6 一:一般绘制流程

    先看BoxDemo的前几节 1 vertex input Layout 2 vertexBuffer 3 IndexBuffer 4 vertexShader 5 constant Buffer 6 pixelShader 7 render