精华内容
下载资源
问答
  • direct3d 12

    2018-07-14 21:48:30
    direct3D 12的api,离线的,可以从msdn上下载,不过方便离线使用
  • Direct3d12-Engine:帮助学习Direct 3D 12的游戏引擎
  • 本编程指南包含有关如何使用Direct3D 12可编程管道创建自定义图形引擎的信息。 Direct3D 12标头和库是Windows 10 SDK的一部分。使用Direct3D 12无需单独下载或安装。 在这个部分 话题 描述 Direct3D 12编程...

    本编程指南包含有关如何使用Direct3D 12可编程管道创建自定义图形引擎的信息。

    Direct3D 12标头和库是Windows 10 SDK的一部分。使用Direct3D 12无需单独下载或安装。

    在这个部分

    话题 描述
    Direct3D 12编程指南 Direct3D 12提供了一个API和平台,允许应用程序利用配备一个或多个Direct3D 12兼容GPU的PC的图形和计算功能。
    Direct3D 12参考 本节介绍基于Direct3D 12的图形编程的API。
    Direct3D 12词汇表 这些术语在Direct3D 12中含义不同。

    原文链接:Direct3D 12 graphics

    展开全文
  • Direct3D 12简介

    2021-04-12 16:20:26
    Direct3D 12简介 DirectX 12是Microsoft最新的DirectX API版本。 Direct3D随DirectX 12一起提供,Direct3D 12是DirectX API集合中的图形API(其他API包括DirectSound,DirectInput,DirectDraw等)。 Direct3D 12...

    Direct3D 12简介

    DirectX 12是Microsoft最新的DirectX API版本。 Direct3D随DirectX 12一起提供,Direct3D 12是DirectX API集合中的图形API(其他API包括DirectSound,DirectInput,DirectDraw等)。

    Direct3D 12的性能比Direct3D的任何以前的迭代要好得多。 Direct3D提供了对图形硬件的较低级别控制,从而可以更有效地使用线程。我们能够使用多个线程来填充命令列表。拥有更多控制权的另一方面意味着我们现在要承担更多责任,例如CPU / GPU同步和内存管理。

    Direct3D还通过使用预编译的管道状态对象和命令列表(bundles)来最大程度地减少CPU开销。在应用程序的初始化阶段,我们将创建许多管线状态对象,这些对象由着色器(顶点,像素等)和其他管线状态(混合,光栅化器,基本拓扑等)组成。然后,在运行时,驱动程序不必像在Direct3D 11中那样更改管道的状态,就可以创建管道状态。相反,我们提供了一个管道状态对象,当我们调用draw时,它将使用管道,而且我们没有动态创建管道状态的开销。我们还可以在初始化期间创建一组命令,这些命令可以反复使用称为Bundles的命令。

    关于Direct3D的另一件很酷的事情是,它的API调用少得多,根据MSDN,它的调用数约为200(而其中大约三分之一完成了所有艰苦的工作)。

    我们将在本教程中学习以下内容:

    图形管道概述

    • The Compute Shader
    • Input Assembler (IA) Stage
    • Vertex Shader (VS) Stage
    • Hull Shader (HS) Stage
    • Tessellator (TS) Stage
    • Domain Shader (DS) Stage
    • Geometry Shader (GS) Stage
    • Stream Output (SO) Stage
    • Rasterizer Stage (RS)
    • Pixel Shader (PS) Stage
    • Output Merger (OM) Stage

    Direct3D 12工作原理概述

    • The Device
    • Pipeline State Objects
    • Command Lists - Bundles
    • Command Queues
    • Command Allocators
    • Resources
    • Descriptors (Resource Views)
    • Descriptor Tables
    • Descriptor Heaps
    • Root Signatures
    • Resource Barriers
    • Fences and Fence Events
    • Overview of Application Flow Control for Direct3D 12
    • Multithreading in Direct3D 12

    初始化Direct3D 12

    •  Creating a device 
    • Creating a command queue
    • Creating a swap chain
    • Creating a descriptor heap
    • Creating a command allocator
    • Creating a root signature
    • Compiling and Creating shader bytecode
    • Creating a pipeline state object
    • Creating a command list
    • Creating a fence and fence event

     

    参考链接:

    1. https://docs.microsoft.com/en-us/windows/win32/direct3d12/directx-12-programming-guide
    2. http://www.d3dcoder.net/
    3. https://www.braynzarsoft.net/viewtutorial/q16390-04-directx-12-braynzar-soft-tutorials
    4. https://developer.nvidia.com/dx12-dos-and-donts
    5. https://www.3dgep.com/learning-directx-12-1/
    6. https://gpuopen.com/learn/lets-learn-directx12/
    7. https://alain.xyz/blog/raw-directx12
    8. https://www.rastertek.com/tutdx12.html
    9. https://digitalerr0r.net/2015/08/19/quickstart-directx-12-programming/
    10. https://walbourn.github.io/getting-started-with-direct3d-12/
    11. https://docs.aws.amazon.com/lumberyard/latest/userguide/graphics-rendering-directx.html
    12. http://diligentgraphics.com/diligent-engine/samples/
    13. https://www.programmersought.com/article/2904113865/
    14. https://www.tutorialspoint.com/directx/directx_first_hlsl.htm
    15. http://rbwhitaker.wikidot.com/hlsl-tutorials
    16. https://digitalerr0r.net/2015/08/19/quickstart-directx-12-programming/
    17. https://www.ronja-tutorials.com/post/002-hlsl/

     

    展开全文
  • 注:以下内容参考自 书籍:《DirectX 12 3D》游戏开发实战, 微软官方的 DirectX样例程序;... ...Direct3D 12对于开发者来说,就是一个SDK, 这篇文章就来讲一讲这个SDK的初始化流程,以及我在...

    注:以下内容参考自
    书籍:《DirectX 12 3D》游戏开发实战,
    微软官方的 DirectX样例程序;DirectX-Graphics-Samples, 参见github链接:https://github.com/Microsoft/DirectX-Graphics-Samples

    Direct3D 12对于开发者来说,就是一个SDK, 这篇文章就来讲一讲这个SDK的初始化流程,以及我在实践的过程中遇到的一些问题;
    

    这是我实践时写的代码的GitHub链接:https://github.com/blowingBreeze/D3D12Guide,持续更新

    1. 创建Direct3D设备,ICreateD3D12Device

    • Direct3D是我们操控显卡的一个抽象层,学习过面向对象的同学应该很熟悉,在将一个现实中的对象(也就是这里的显卡),往往会将该对象分解为代码中的多个对象,由这些对象对外部系统提供接口;

    • D3D12Device就是Direct3D中用于提供显卡控制接口的对象,它代表着当前系统中的显示适配器,一般来说,它是一个3D图形硬件(如显卡), 但是,操作系统在没有显卡的时候也能正常的显示图像,这时候使用的就是软件显示适配器,如(WARP适配器),

    可以在不急着使用电脑的时候折腾一下,将操作系统的显卡设备全部卸载,观察一下电脑的情况

    通过这个函数即可创建一个D3D12的设备对象

    HRESULT D3D12CreateDevice(
      IUnknown          *pAdapter,  //想为哪个显示适配器创建一个设备对象,传递nullptr则使用系统中的默认适配器
      D3D_FEATURE_LEVEL MinimumFeatureLevel,  //指定支持的最低版本的Direct3D版本
      REFIID            riid,  //GUID
      void              **ppDevice  //用于接收设备对象所在的内存的指针
    );
    

    为了简单起见,这里使用系统默认的显示适配器

    hResult = D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&mD3DDevice)); 
    

    其中IID_PPV_ARGS是Direct3D为我们提供的一个工具宏,IID_PPV_macro,它为我们生成了后面接口中的后两个参数

    1.1 获取显示适配器

    显示适配器是真正实现了图形处理能力的对象,上面的D3D12Device是对显示适配器的进一步封装.
    一个系统中可能会有多个显示适配器,比如我就有两个显示适配器;
    在这里插入图片描述
    那么在程序中我们怎么才能知道使用的是哪个适配器呢,毕竟游戏的使用性能较高的适配较好。

    下面简单提一下DXGI的概念,现在仅知道有这么个东西就行了,以后慢慢就理解了

    DXGI是一种与Direct3D配合使用的API,设计DXGI的基本理念是使得多种图形API中的底层任务能够使用通用的API,比如3D和2D的图形API在底层都可以使用相同的,比如Direct3D和Direct2D内部实现交换链时可以使用同一套接口

    我们在获取系统的可用显示适配器时,会使用到 IDXGIFactory,主要用于创建SwapChain以及枚举显示适配器
    我们可以使用下面的代码来枚举系统中的显示适配器

    ComPtr<IDXGIFactory4> factory;    
    UINT dxgiFactoryFlags = 0;
    #if defined(_DEBUG)    
    // Enable the debug layer (requires the Graphics Tools "optional feature").    
    // NOTE: Enabling the debug layer after device creation will invalidate the active device.    
    {        
    	ComPtr<ID3D12Debug> debugController;        
    	if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)))        
    	{            
    		debugController->EnableDebugLayer();
    	        // Enable additional debug layers.            
    	        dxgiFactoryFlags |= DXGI_CREATE_FACTORY_DEBUG;       
    	}    
    }
    #endif    
     CreateDXGIFactory2(dxgiFactoryFlags, IID_PPV_ARGS(&factory));    
     UINT i = 0;   
     ComPtr<IDXGIAdapter> adapter = nullptr;    
     while (factory->EnumAdapters(i, &adapter) != DXGI_ERROR_NOT_FOUND)   
      {        
    	DXGI_ADAPTER_DESC desc;        
    	adapter->GetDesc(&desc);
    	std::wcout << desc.Description<<std::endl;        
    	++i;   
    }
    

    系统不单单可以有多个显示适配器,每个显示适配器也可以连接多个显示输出(显示屏),我们可以通过获取到的adapter对象进一步获取更详细的显示信息,这里就不进行介绍了

    2.创建命令队列和命令列表

    • 在《DirectX 12 3D游戏开发实战》中,第二步是创建 ID3D12Fence对象,并查询描述符大小
    • 我这里不这么做,是因为我觉得,Fence是一个用来同步CPU,GPU的,但是目前为止还没有提 到CPU与GPU的交互,在第二步创建会显得很奇怪;当然,对新手来说(比如我)是这样的,熟悉以后可以依据实际情况调换初始化顺序;
    • 这里你也可以直接先跳到创建 ID3D12Fence对象 的部分进行阅读

    2.1 命令队列和命令列表

    • 进行图形编程的时候,是有两种处理器在进行工作的,CPU和GPU,他们之间没有绝对的从属关系,并行工作,但GPU需要CPU告诉它,该画什么东西;
    • CPU和GPU的执行命令的速度是不一样的,如果使用同步的方式执行,那么CPU势必需要等待 GPU执行完命令才能给GPU下达下一个绘制指令,而GPU做完绘制工作后在CPU没有下达指令前也必须 等待 CPU下达指令,这样就会导致处理器有一定的空转状态,不利于最大程度的发挥出处理器的性能;
    • 那么我们可以参考异步事件和缓冲池的方式进行处理,每个CPU命令看作一个一条指令,放入指令池中,而GPU不停的从这个指令池中读取CPU下达的指令,进行绘制工作;这样就能将两个处理器进行分离,互不相干(当然,不管怎么样,这两个处理器都是需要做一些同步操作的,这个会在讲Fence的时候说明),GPU可以最大限度的执行绘制任务直到没有指令需要执行,而CPU也不需要等待GPU绘制完成就可以继续下发任务

    这里面有一点很重要,指令的执行是异步的,CPU下发的指令不会立即执行,直到GPU执行到了指令池中的对应指令

    在这里插入图片描述

    • 在《DirectX 12 3D游戏开发实战》中有提到,指令池满了或者空了之后,CPU和GPU必然有一个处于空闲状态,但是我并未在书中看到相应的解决方案,
    • 我的一个想法是,指令池满了或者空了之后,可以将一部分GPU或CPU中的任务移交到CPU或GPU中,当然,这个在具体实现时难度是很大的
    • 在Direct3D 中,使用的是命令队列和命令列表的方式对CPU和GPU的交互进行缓冲

    《DirectX 12 3D游戏开发实战》 4.2.1节中:

    • 每个GPU都至少维护着一个命令队列(command queue, 本质上是环形缓冲区,即ring buffer)
    • 借助Direct3D API,CPU可以利用命令列表(command list)将命令提交到这个队列中去
    • 在Direct3D 11中,有立即渲染(immediate rendering)延迟渲染(deferred rendering),前者是将缓冲区的命令之间借驱动层发往GPU执行,后者则与Direct3D 12中的命令列表模型类似,而在Direct 3D 12中则完全采取了 "命令列表->命令队列的方式"是多个命令列表同时记录命令,借此充分发挥多核心处理器的性能

    2.2 命令队列和命令列表代码示例

    在Direct3D 12中,命令队列使用 ID3D12CommandQueue接口进行表示,通过ID3D12Device::CreateCommandQueue方法创建队列(还记得1.1中的D3D12Device吗?)
    创建命令队列时,需要通过填写D3D12_COMMAND_QUEUE_DESC queueDesc结构体来描述队列
    MSDN上的 ID3D12Device::CreateCommandQueue method

    D3D12_COMMAND_QUEUE_DESC queueDesc = {};
    queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
    queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
    ThrowIfFailed(mD3DDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&mCommandQueue)));
    ThrowIfFailed(mD3DDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, 
                       IID_PPV_ARGS(mDirectCmdListAlloc.GetAddressOf())));
    ThrowIfFailed(mD3DDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, 
                        mDirectCmdListAlloc.Get(), nullptr, IID_PPV_ARGS(mCommandList.GetAddressOf())));
    
    //下面是ThrowIfFailed的定义
    inline void ThrowIfFailed(HRESULT hr)
    {
        if (FAILED(hr))
        {
            throw HrException(hr);
        }
    }
    

    这里我们提到的三个函数

    • CreateCommandQueue:这个用于创建命令队列,很好理解
    • CreateCommandAllocator:用于创建命令分配器(command allocator),这个用于记录在命令列表中的命令,在执行命令列表时,命令队列会引用命令分配器中的命令; 我目前对这个对象的理解是,用于保存命令队列中指令的内存地址的,方便命令队列在执行命令列表时进行引用
    • CreateCommandList:用于创建命令队列,这个很好理解了,真实的管理命令的添加删除的对象

    CommandList有一系列的方法用于向队列中添加命令,MSDN上的 ID3D12GraphicsCommandList interface

    在添加完命令后一定要调用 ID3D12GraphicsCommandList::Close方法结束命令的记录,命令列表添加完成后,需要使用ID3D12CommandQueu::ExecuteCommandLists方法将命令列表送入命令队列中,还记得之前提到的命令缓冲吗,这里的执行其实对于CPU来说是以及执行了,但实际上GPU并不一定马上执行指令

    • 我们可以创建多个关联与同一个命令分配器的命令列表,但是不能同时用他们记录命令,即必须保证其中一个命令列表在记录命令时,必须关闭同一个命令分配器的其他命令列表,
    • 换句话说,必须保证命令列表中的所有命令都会按顺序地添加到命令分配器中
    • 当创建或重置一个命令列表的时候,它会处于一种“打开“的状态,所以当尝试为同一个命令分配器连续创建两个命令列表时会报错
    • 在调用ID3D12CommandQueue::ExcuteCommandList方法后,就可以通过ID3D12GraphicsCommandList::Reset方法,安全地服用命令列表占用的底层内存来记录新的命令集,Reset命令列表并不会英雄命令队列中的命令,因为相关的命令分配器依然维护者其内存中被命令队列引用的系列命令
    • 在向GPU提交了一帧的渲染命令后,我们可能需要为了绘制下一帧而复用命令分配器中的内存,可以使用ID3D12CommandAllocator::Reset方法,这种方法的功能类似与std::vector::clear方法,使得命命令分配器种的命令清空,但保存内存不释放,**注意,在不确定GPU执行完命令分配器中所有的命令之前,不要Reset命令分配器,因为命令队列可能还引用着命令分配器中的数据**

    3.创建Fence(围栏)

    前面有提到,CPU和GPU的指令执行是异步的,并且他们可能会同时访问同一块内存(指令分配器),也就有可能发生访问冲突,考虑以下情况,

    • CPU向GPU发送了A,B,C三条指令,其中B引用了dataB对象,而在CPU中,发送ABC指令的同时也在执行D指令,D指令可能会修改dataB对象;

    这种情况下,GPU在执行B指令时,获取的dataB有可能不是CPU发送B指令时的dataB,可能导致很奇怪的程序异常,这种由于访问冲突导致的异常很难进行排查;

    这时候我们需要做的,就是让CPU在执行B指令前,不执行D指令,也就是CPU和GPU需要进行状态同步;

    • 在进程和线程的同步方式中,可以选择锁,信号量,互斥量等方式进行同步,在这里,也可以参考这种方式进行实现,

    Drect3D 12中,提供了一种 Fence对象,可以在命令队列中,设置一条围栏指令,当GPU执行到围栏指令时,触发某个事件,而在GPU中则等待事件的发生,这样就达到了同步的目的,这种方法也称作刷新命令队列(flushing the command queue)

    ThrowIfFailed(mD3DDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&mD3DFence)));
    
    const UINT64 fence = mFenceValue;     
    //向命令队列中添加一条用于设置新的围栏的命令
    ThrowIfFailed(mCommandQueue->Signal(mD3DFence.Get(), fence));     
    mFenceValue++;     
    // Wait until the previous frame is finished.  
    if (mD3DFence->GetCompletedValue() < fence)   
    {       
    	ThrowIfFailed(mD3DFence->SetEventOnCompletion(fence, mFenceEvent)); 
    	WaitForSingleObject(mFenceEvent, INFINITE);   
    }
    

    4.创建交换链

    4.1 什么是交换链?

    • 最终展现在屏幕上的图像数据,必定是要保存在某块内存中的,也就是缓冲区中。
    • 想象一下,若我们只创建一个缓冲区,那么每次画面的更新和屏幕图像的更新便是混在一起的,帧率不高(也就是绘制速度不够)时,能看出画面的撕裂(旧的图像和新绘制的图像混在了一起),
    • 为了解决这个问题,Direct3D中采用了双缓冲区的做法:前台缓冲区和后台缓冲区,前台缓冲区存储屏幕上展示的图像数据,而后台缓冲区存储绘制中的数据,用于下一次展示,当后台缓冲区的图像绘制完成时,前后台缓冲区角色互换,这种互换操作称为呈现(presenting),前后台缓冲区构成的交换链(swap chain),他们每帧都需要进行互换;

    在这里插入图片描述

    4.2 创建

    mSwapChain.Reset();
    mSwapChainDesc.BufferDesc.Width = 1366;
    mSwapChainDesc.BufferDesc.Height = 768;
    mSwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    mSwapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
    mSwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
    mSwapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER::DXGI_MODE_SCANLINE_ORDER_LOWER_FIELD_FIRST;
    mSwapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING::DXGI_MODE_SCALING_CENTERED;
    mSwapChainDesc.Windowed = true;
    mSwapChainDesc.OutputWindow = mhMainWind;
    mSwapChainDesc.BufferCount = BUFFER_COUNT;
    mSwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    mSwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT::DXGI_SWAP_EFFECT_FLIP_DISCARD;
    mSwapChainDesc.SampleDesc.Count = 1;
    //这里要填0,不然会报错,原因是不支持该功能,具体的还不清楚
    mSwapChainDesc.SampleDesc.Quality = 0;
    
    ComPtr<IDXGISwapChain> swapChain;
    ThrowIfFailed(mD3DFactory->CreateSwapChain(
    	mCommandQueue.Get(), // Swap chain needs the queue so that it can force a flush on it.
    	&mSwapChainDesc,
     	swapChain.GetAddressOf()
    ));
    ThrowIfFailed(swapChain.As(&mSwapChain));
    

    和以前一样,你需要先填写一个描述交换链的结构体,然后进行创建,具体可以参考:MSDN , IDXGIFactory::CreateSwapChain method

    5. 创建描述符堆

    5.1 什么是描述符?

    • 在渲染的过程中,GPU需要对资源进行读写操作,我们需要将与本次绘制调用(draw call)相关的绑定(bind,或称链接,link)到流水线上,而部分资源可能在每次绘制调用时都有所变化,因此我们需要每次按需更新绑定资源到渲染流水线中。
    • 但是GPU资源并非直接和渲染流水线绑定的,而是需要通过一种名为描述符(descriptor)的对象来对它进行间接引用,可以把描述符看作时一种对GPU资源的内容声明,告诉GPU,这个资源是什么东西,什么格式,什么类型;
    • 每个描述符都有一种具体的类型,这个类型指定了资源的具体作用,常见的有:
      • CBV:常量缓冲区视图(constant buffer view),
      • SRV:着色资源视图(shader resource view)
      • UAV:无序访问视图(unordered access view),
      • sampler:采样器资源
      • RTV:渲染目标视图(render targe view),
      • DSV:深度/模板视图(depth/stencil view)
        这里面每种视图对应的都是一种资源;

    5.2 什么是描述符堆?

    • 描述符堆(descriptor heap)中存有一系列描述符(可以看作是描述符数组),本质上是存放某种特定类型描述符的一块内存,我们需要为每一种类型的描述符都创建出单独的描述符堆,也可以为同一种描述符类型创建多个描述符堆;

    5.3创建

    D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc;
    rtvHeapDesc.NumDescriptors = mSwapChainDesc.BufferCount;
    rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
    rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
    rtvHeapDesc.NodeMask = 0;
    ThrowIfFailed(mD3DDevice->CreateDescriptorHeap(&rtvHeapDesc, 
    	IID_PPV_ARGS(mRtvHeap.GetAddressOf())));
    
    D3D12_DESCRIPTOR_HEAP_DESC dsvHeapDesc;
    dsvHeapDesc.NumDescriptors = 1;
    dsvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
    dsvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
    dsvHeapDesc.NodeMask = 0;
    ThrowIfFailed(mD3DDevice->CreateDescriptorHeap(&dsvHeapDesc, 	
    	IID_PPV_ARGS(mDsvHeap.GetAddressOf())));
    

    可参考:MSDN,ID3D12Device::CreateDescriptorHeap method


    6.创建渲染目标视图(Render Target View,RTV)

    前面我们已经创建好了描述符堆,接下来应该为后台缓冲区创建一个渲染目标视图,这样才能将缓冲区绑定到渲染流水线中,使得Direct3D向缓冲区中渲染图像,可以理解为,本来内存中有一块缓冲区,但是GPU看不到它,我们创建一个视图,绑定到渲染流水线中,这样GPU就能看到这个缓冲区并往里面写东西了。

    //获取描述符堆的首地址(句柄)
    D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle(mRtvHeap->GetCPUDescriptorHandleForHeapStart());    
    // Create a RTV for each frame.     
    for (UINT n = 0; n < BUFFER_COUNT; n++) 
     {        
     	ThrowIfFailed(mSwapChain->GetBuffer(n, IID_PPV_ARGS(&mRenderTargets[n])));        
     	mD3DDevice->CreateRenderTargetView(mRenderTargets[n].Get(), nullptr, rtvHandle);        
     	rtvHandle.ptr += mRtvDescriptorSize;    //每次偏移每个描述符的大小,
     }
    

    7.设置视口

    这个比较简单,

    D3D12_VIEWPORT mViewport; //视口信息描述
    mViewport.TopLeftX = 0;
    mViewport.TopLeftY = 0;
    mViewport.Width = 1366;
    mViewport.Height = 768;
    mViewport.MinDepth = D3D12_MIN_DEPTH;
    mViewport.MaxDepth = D3D12_MAX_DEPTH;
    
    mCommandList->RSSetViewports(1, &mViewport); //向命令列表添加命令
    

    8.尾声

    到这里整个Direct3D 12的初始化基本就完成了,当然,这里只是简单的介绍了初始化过程中的一些关键步骤,如果希望完整的学习整个流程,可以去我的GitHub上看完整的代码:https://github.com/blowingBreeze/D3D12Guide接下来我会尝试将整个流程进行封装,以免除每次都得写一串冗长的初始化代码,并开始学习渲染流水线部分;

    展开全文
  • Swift的Direct3D12 该软件包向Swift公开了Direct X 12低级API。 该软件包正在大力开发中。 欢迎反馈。 对源文件进行分区和命名,以反映原始API的位置和命名。 这使得根据官方文档更容易找到所有内容。 笔记: ...
  • Direct3D12基本呈现

    2015-03-29 21:25:49
    Direct3D 12 尝鲜: 基本呈现》附带资源
  • Direct3D12基本渲染

    2015-04-01 15:08:00
    Direct3D 12 尝鲜(三): Pipeline State Object》附带资源
  • Direct3D 12 In Depth

    千次阅读 2020-03-13 21:05:15
    Direct3D 12 In Depth This brings us to Direct3D 12, which is Microsoft’s entry in...

    https://www.anandtech.com/show/7889/microsoft-announces-directx-12-low-level-graphics-programming-comes-to-directx/2

    Direct3D 12 In Depth

    This brings us to Direct3D 12, which is Microsoft’s entry into the world of low level graphics programming. Microsoft is still neck-deep in development of Direct3D 12 so far – they’re currently targeting it for game releases in Holiday 2015, roughly 18 months off – and as such Microsoft hasn’t released a ton of details about the API to the public yet. But they have given us a broad overview of what the plan to accomplish, with a couple of technical details on how they will be doing this.

    At a high level there is no denying the fact that Direct3D 12 looks a lot like Mantle. Microsoft has set out with the same basic goals as AMD did with Mantle and looks to be achieving some of them in the same manner. Which to no surprise then that the end products are going to be similar as a result.

    As with Mantle, the primary goal for Direct3D 12 is to greatly reduce the CPU overhead that we’ve talked about previously. As the biggest source of CPU overhead is having Direct3D assemble the command lists/buffers for a GPU, Direct3D 12 will be moving that job over to developers. By assembling their own command lists developers can more easily spread out the task over multiple cores, and this alone will have a significant impact on CPU utilization. At this point we don’t know what Direct3D 12 command lists will look like, and this will likely be one of the design choices that separates Direct3D 12 from Mantle, but there’s no reason at this time to expect them to be much different.

    D3DCommand_buffer_575px.pnguploading.4e448015.gif正在上传…重新上传取消
    For Comparison: D3D11 Command Buffer

    Microsoft will also be introducing a similar concept, a bundle, which is functionally a form of a reusable command list. This again is another CPU saving step, as using a bundle in place of multiple command lists further cuts down on the amount of CPU time spent making submissions. In this case the idea behind a bundle is to submit work once, and then allow the bundle to be executed multiple times with minor variations. Microsoft specifically notes having a character drawn twice with different textures as being a use case for this structure.

    Meanwhile it’s interesting to note that with this change Microsoft has admitted that Direct3D 11 style immediate/deferred command lists haven’t lived up to their goals, stating “deferred contexts also do not map perfectly to hardware, and so relatively little work can be done in them.” To our knowledge the only game able to make significant use of the feature was Civilization V, and even then we’ve seen AMD video cards perform very well without supporting the feature.

    Moving on, Direct3D 12 will also be introducing pipeline state objects. With pipeline state objects we’re really getting into the nitty-gritty of command buffer execution and how the various graphics architectures differ, but the important bit to take away is that most architectures don’t have the ability to freely transition between pipeline states as much as Direct3D 11 would like. This leads to problems for how quickly the hardware state can be set, as Direct3D must go back and take into account these hardware limitations.

    The solution to this will be the aforementioned pipeline state objects (PSOs). PSOs bypass some of these pipeline limitations by using objects that are finalized on creation. Nitty-gritty details aside, the outcome from this is that it further reduces CPU overhead, once again increasing the number of draw calls the CPU can submit or freeing it up for other tasks.

    The final major addition to Direct3D 12 is descriptor heaps. Going back to 2012, one of the features introduced on NVIDIA’s then-new Kepler architecture was bindless resources, which bypassed the previous 128 slot limitation on resources (textures, etc). Through bindless an essentially infinite number of resources could be addressed, at a performance penalty, though an additional layer of indirection in memory accesses.

    NV_Bindless_575px.jpguploading.4e448015.gif正在上传…重新上传取消

    Descriptor heaps in turn appear to be the integration of bindless resources in Direct3D 12. Microsoft does not specifically call descriptor heaps bindless, but the description of slots and draw calls makes it clear that they’re intending to solve the problem with the bindless solution. With descriptor heaps and descriptor tables to reside in those heaps, Direct3D 12 will be able to perform bindless operations, both expanding the number of resources available to shader programs, and even outright dynamic indexing of resources.

    Finally, there are a few miscellaneous features that have popped up in Microsoft’s slides that have caught our attention, if only due to the lack of details provided. Specifically, the mention of compressed resources stands out. The resources mentioned, ASTC and JPEG, are not resources formats that we know to be supported on any current PC GPU. In the case of ASTC, Khronos’s next generation texture compression format, it is a finalized standard that will be supported on all GPUs in time as a core part of the OpenGL standard. Meanwhile JPEG is not a feature we’ve seen on any API roadmaps before.

    ASTC_JPEG_575px.jpguploading.4e448015.gif正在上传…重新上传取消
    Image Courtesy PC Perspective

    To that end, the addition of ASTC is not all that surprising. Since it is royalty free and not otherwise restricted to OpenGL-only, there’s no reason not to support it when all of the underlying hardware will (eventually) support it anyhow.

    ASTCSlide_575px.jpguploading.4e448015.gif正在上传…重新上传取消

    JPEG on the other hand is a very curious thing to mention, as its lack of existence on any API roadmaps goes along with the fact that we’re not aware of anyone having announced plans to support JPEG in hardware. Furthermore JPEG is not a fixed ratio compressor – the number of bits a given sized input will generate can vary – which for GPUs would typically be a bad thing. It stands to reason then that Microsoft knows a bit more about what features are in the R&D pipelines for the GPU makers, and that someone will be implementing hardware JPEG support. So we’ll have to keep an eye on this and see what pops up.

    Making a Common Low Level API

    The need for a low level graphics API like Direct3D 12 is clear, but establishing a common API is no easy task. Abstraction is both what gives Direct3D 11 its ability to work on multiple platforms and robs Direct3D 11 of some of its performance. So to make a low level API that works across AMD, NVIDIA, Intel, Qualcomm, and others’ GPUs requires a careful balancing act to bring low level API improvements while adding no more abstraction than is necessary.

    At this stage in development Microsoft is not ready to talk about that aspect of API development; for the moment that level of access is restricted to a small group of approved developers. But given their hardware requirements we can make a few educated guesses about what’s going on behind the scenes.

    Of the big 3 GPU vendors, all of them have confirmed what GPUs will be supported. For Intel their Gen 7.5 GPUs (Haswell generation) will support Direct3D 12. As for NVIDIA, Fermi, Kepler, and Maxwell will support Direct3D 12. And for AMD, GCN 1.0 and GCN 1.1 will support Direct3D 12.

    Direct3D 12 Confirmed Supported GPUs
    AMD GCN 1.0 (Radeon 7000/8000/200)
    GCN 1.1 (Radeon 200)
    Intel Gen 7.5 (Haswell/4th Gen Core)
    NVIDIA Fermi (GeForce 400/500)
    Kepler (GeForce 600/700/800)
    Maxwell (GeForce 700/800)

    The interesting thing about all of this is what’s excluded: namely, AMD’s D3D11 VLIW5 and VLIW4 architectures. We’ve written about VLIW in comparison to GCN in great depth, and the takeaway from that is that unlike any of the other architectures here, only AMD was using a VLIW design. Every architecture has its strengths and weaknesses, and while VLIW could pack a lot of hardware in a small amount of space, the inflexible scheduling inherent to the execution model was a very big part of the reason that AMD moved to GCN, along with a number of special cases regarding pipeline and memory operations.

    Now why do we bring this up? Because with GCN, Fermi, and Gen 7.5, all PC GPUs suddenly started looking a lot more alike. To be clear there are still a number of differences between these architectures, from their warp/wavefront size to how their SIMDs are organized and what they’re capable of. But the important point is that with each successive generation, driven by the flexibility required for efficient GPU computing, these architectures have become more and more alike. They’re far more similar now than they have been since even the earliest days of programmable GPUs.

    Wavefront_575px.pnguploading.4e448015.gif正在上传…重新上传取消
    Wavefront Execution Example: SIMD vs. VLIW. Not To Scale - Wavefront Size 16

    Ultimately, all of this is a long-winded way of saying that a bit part of the reason that there can even be a common low level graphics API is because the hardware has homogenized to the point where less and less abstraction is necessary. On a spectrum ranging from a shared ISA (e.g. x86) to widely divergent designs, we’re nowhere near the former, but importantly we’re also nowhere near the latter. This is a subject we’re going to have to watch with great interest, because MS and the GPU vendors (through their drivers) are still going to have to introduce some level of abstraction to make everyone work together through a single common low level API. But the situation with modern hardware means that (with any luck) the additional abstraction with Direct3D 12 over something like Mantle will prove to be insignificant.

    Finally, it’s worth pointing out that last week’s developments with Direct3D couldn’t be happening without a degree of political backbone, too. The problem in introducing any new graphics standard is not just technical, but in bringing together companies with differing interests and whose best interests don’t necessarily involve fast-tracking every technology proposed.

    Microsoft to that end currently holds a very interesting spot in the world of PC graphics, being the maintainer of the most popular PC graphics API. And unlike the designed-by-committee OpenGL, Microsoft has some (but not complete) leverage to push new technologies through when the GPU vendors and software vendors would otherwise be at loggerheads with each other. So while Microsoft is being clear this is a joint effort between all of the involved parties, there’s still something to be said for having the influence and power to bring down changes that may not be popular with everyone.

     

    展开全文
  • 本文介绍如何使用Direct 3D12 API使用环形缓冲区来实现动态资源。
  • 管道状态对象由ID3D12PipelineState接口表示,并由设备接口通过CreateGraphicsPipelineState()方法创建。若要设置管道状态对象,可以调用命令列表的SetPipelineState() 方法。 该接口是使Direct3D 12表现出色的一...
  • Direct3D12基本呈现Ex

    2015-03-30 22:44:32
    Direct3D 12 尝鲜 二 : Fence》所附带资源
  • 本文介绍了一种用于管理Direct3D12中资源生命周期的低开销策略。
  • Direct3D 12基础关系逻辑图
  • 该库可以通过提供类似于标准ID3D12Device::CreateCommittedResource功能Allocator::CreateResource来帮助开发人员管理内存分配和资源创建。 在内部: 分配并跟踪更大的内存堆,其中的已使用和未使用范围
  • VKD3D-Proton是VKD3D的分支,其目的是在Vulkan之上实现完整的Direct3D 12 API。该项目是Direct3D 12支持的开发工作。 上游 原始项目可在。 优先事项 性能和游戏兼容性是重要的目标,但要以与较旧的驱动程序和系统的...
  • Import Changes from Direct3D 11 to Direct3D 12

    千次阅读 2016-01-28 15:00:17
     这是微软公布的Direct3D 12文档的其中一篇,此翻译留作学习记录备忘,水平有限,错漏难免,还望海涵。   原文链接是https://msdn.microsoft.com/en-us/library/windows/desktop/dn899194(v=vs.85).aspx   ...
  • 开始学习Direct3D12(D3D12)的项目。 :创建一个用于显示的窗口 :渲染窗口的背景色 发展 平台:Windows 10 32位和64位(Windows API + Direct3D 12) 引擎编程语言:ISO C ++最新草案标准(> C ++ 17) 脚本...
  • <div><p>This PR brings Direct3D 12 GPU support for Halide.</p><p>该提问来源于开源项目:halide/Halide</p></div>
  • 这是微软公布的Direct3D 12文档的其中一篇,此翻译留作学习记录备忘,水平有限,错漏难免,还望海涵。   原文链接是https://msdn.microsoft.com/en-us/library/windows/desktop/dn899194(v=vs.85).aspx ...
  • Direct3D 12的应用程序流控制概述 当然,有很多方法可以完成工作,这是Direct3d应用程序的典型大纲: 初始化应用程序 启动主循环 设置场景(如果是新场景) 更新游戏逻辑 如果需要,加载/释放资源 等待GPU ...
  • Direct3D12 中使用 Stream Output一. 引子二.一切从 CreateGeometryShaderWithStreamOutput 说起1. D3D11 和 D3D102. D3D12三. 在 D3D12 中使用 Stream Output1. Error2. 解决方法3. Debug四. 总结新的改变功能...
  • 本文介绍了Direct3D12和Vulkan等现代图形API中的资源状态管理和同步问题,并介绍了Diligent Engine提供的解决方案。
  • Direct3D 12 support

    2020-12-02 12:42:42
    <div><p>Hi, I just see 11.3 support was added recently.. can we expect D3D12 soon? or it's lots of work? thanks</p><p>该提问来源于开源项目:apitrace/apitrace</p></div>
  • http://timjones.io/blog/archive/2015/09/05/comparing-api-footprints-of-direct3d-12-11-10-and-9 ...I’ve spent some time during the last few days reading through theDirect3D 12 docu...
  • Direct3D 12 尝鲜: 基本呈现

    千次阅读 2015-03-29 18:38:10
    微软前几天发布了Win10的开发工具,进行Direct3D12的尝鲜
  • <div><p>Current system configuration: Windows 10 17763.134 Visual Studio 2017 15.9.2 ... Direct3D12 code crashes easily.</p><p>该提问来源于开源项目:walbourn/directx-vs-templates</p></div>
  • 以及微软官方的Direct3D 12示例:DirectX-Graphics-Samples 渲染流水线:又称渲染管线,指的是将3D场景变换至2D场景的处理流程,具体由以下流程: 这幅图就展示了整个Direct3D的渲染流程,有必要记住图内的...
  • Direct3D 12 尝鲜(三): Pipeline State Object

    千次阅读 2015-03-31 23:07:54
    简答介绍Direct3D12中的渲染管线状态对象: Pipeline State Object
  • Direct3d 12概念点

    2019-12-19 22:12:31
    ID3D12Pageable *const *ppObjects //ID3D12Pageable资源数组 ); HRESULT ID3D12Device::Evict ( UINT NumObjects, ID3D12Pageable *const *ppObjects ); 程序应该避免在短时间内于显存中交换进出相同的资源...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 904
精华内容 361
关键字:

direct3d12