DirectX-Specs 学习系列 (1) :HLSL Shader Mode

0. 简介

图形软件栈分为两个流派:Windows & Khronos. Windows 流派使用的shader语言是HLSL , HLSL 在迭代更新的过程中使用Shader Model x.0号代表其所支持的功能 , 目前有SM1.0~SM6.0共6个版本,具体可参阅文献1. 本系列文献关注HLSL SM6.0以后的Feature , API 对应DX12, SM6.0 以上引入的主要Feature有以下几点:

  • Wave-level Operations
  • Raytracing Shaders
  • Mesh and Amplification Shaders
  • New data-formats

1. Wave-level Operations

SM6.0 以前的版本,用户编写的shader都是单线程模式,GPU的并行执行对用户是透明的,DX12的API的宗旨是:尽可能的发掘底层性能,释放更多权限给用户层。Wave-Level的指令就是想暴露一些并行执行的接口,同时通过这些指令,对于Driver-Compiler代码来说,也可以消除一些不必要的Barrier操作,只要能够确认SIMD的各个线程没有Divergence, 如何确认SIMD有没有Divergence,可以参看我的另外一篇博文:divergency analysis. 大部分Wave-Level 指令只可以在PS 和CS Stage使用。 使用Wave指令前,有几个相关概念需要解释一下:

  • Lane: A single thread of execution.
  • Wave: A set of lanes executed simultaneously in the processor.
  • Helper Lane: A lane which is executed solely for the purpose of gradients in pixel shader quads.
  • Inactive Lane / Active Lane: a lane which is not being executed at this point in the code. (条件分支引起的控制流不同,不同的控制流,线程会呈现Active Or Inactive状态,如下图)
  • Quad: A set of 4 adjacent lanes corresponding to pixels arranged in a 2x2 square. (Quad模式,4个lane形成一个Quad)

在这里插入图片描述

Wave Query

NameDescriptionShader Model
WaveGetLaneCountReturns the number of lanes in the current wave.SM6.0
WaveGetLaneIndexReturns the index of the current lane within the current wave.SM6.0
WaveIsFirstLaneReturns true only for the active lane in the current wave with the smallest indexSM6.0
IsHelperLaneReturns true if a given lane in a pixel shader is a helper lane.SM6.6

Wave Vote

NameDescriptionShader Model
WaveActiveAnyTrueReturns true if the expression is true in any active lane in the current wave.SM6.0
WaveActiveAllTrueReturns true if the expression is true in all active lanes in the current wave.SM6.0
WaveActiveBallotReturns a 64-bit unsigned integer bitmask of the evaluation of the Boolean expression for all active lanes in the specified wave.SM6.0

Wave Broadcast

NameDescriptionShader Model
WaveReadLaneAtReturns the value of the expression for the given lane index within the specified wave.SM6.0
WaveReadLaneFirstReturns the value of the expression for the active lane of the current wave with the smallest index.SM6.0

Wave Reduction

NameDescriptionShader Model
WaveActiveAllEqualReturns true if the expression is the same for every active lane in the current wave (and thus uniform across it).SM6.0
WaveActiveBitAndReturns the bitwise AND of all the values of the expression across all active lanes in the current wave, and replicates the result to all lanes in the wave.SM6.0
WaveActiveBitOrReturns the bitwise OR of all the values of the expression across all active lanes in the current wave, and replicates the result to all lanes in the wave.SM6.0
WaveActiveBitXorReturns the bitwise Exclusive OR of all the values of the expression across all active lanes in the current wave, and replicates the result to all lanes in the wave.SM6.0
WaveActiveCountBitsCounts the number of boolean variables which evaluate to true across all active lanes in the current wave, and replicates the result to all lanes in the wave.SM6.0
WaveActiveMaxComputes the maximum value of the expression across all active lanes in the current wave, and replicates the result to all lanes in the wave.SM6.0
WaveActiveMinComputes the minimum value of the expression across all active lanes in the current wave, and replicates the result to all lanes in the wave.SM6.0
WaveActiveProductMultiplies the values of the expression together across all active lanes in the current wave, and replicates the result to all lanes in the wave.SM6.0
WaveActiveSumSums up the value of the expression across all active lanes in the current wave and replicates it to all lanes in the current wave, and replicates the result to all lanes in the wave.SM6.0

Wave Scan and Prefix

NameDescriptionShader Model
WavePrefixCountBitsReturns the sum of all the specified boolean variables set to true across all active lanes with indices smaller than the current lane.SM6.0
WavePrefixSumReturnsthe sum of all of the values in the active lanes with smaller indices than this one.SM6.0
WavePrefixProductReturns the product of all of the values in the lanes before this one of the specified wave.SM6.0

Quad-wide Shuffle operations (Only PS)

NameDescriptionShader Model
QuadReadLaneAtReturns the specified source value read from the lane of the current quad identified by quadLaneID [0…3] which must be uniform across the quad.SM6.0
QuadReadAcrossDiagonalReturns the specified local value which is read from the diagonally opposite lane in this quad.SM6.0
QuadReadAcrossXReturns the specified source value read from the other lane in this quad in the X direction.SM6.0
QuadReadAcrossYReturns the specified source value read from the other lane in this quad in the Y direction.SM6.0

2. Raytracing Shaders

3. Mesh and Amplification Shaders

4. New data-formats

x. 参考资料

  1. https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-models
  2. https://microsoft.github.io/DirectX-Specs/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值