Semantics

반응형

Semantics

A semantic is a string attached to a shader input or output that conveys information about the intended use of a parameter. Semantics are required on all variables passed between shader stages. The syntax for adding a semantic to a shader variable is shown here (Variable Syntax (DirectX HLSL)).


semantic은 파라미터의 용도에 대한 정보를 전달하기 위해 shader의 
입력이나 출력에 붙여지는 문자열이다.
shader stage들에서 오고가는 모든 변수들은 semantic이 필요하다
shader 변수에 semantic를 붙이는 문법에 대한 내용은 이곳을 참고하면 된다.

In general, data passed between pipeline stages is completely generic and is not uniquely interpreted by the system; arbitrary semantics are allowed which have no special meaning. Parameters (in Direct3D 10 and later) which contain these special semantics are referred to as System-Value Semantics.


일반적으로, 파이프라인 스테이지간에 전달되는 데이터는 시스템에 의해
generic하고 특별하지 않게 해석되어지며 특별한 의미가 없는 semantic은 허용된다.
direct3d 10 이후부터 System-Value Semantics라고 불려지는 
이런 특별한 semantic들을 인자로 포함한다.


Semantics Supported in Direct3D 9 and Direct3D 10 and later

The following types of semantics are supported in both Direct3D 9 and Direct3D 10 and later.

Vertex Shader Semantics

These semantics have meaning when attached to a vertex-shader parameter. These semantics are supported in both Direct3D 9 and Direct3D 10 and later.


이러한 semantic들은 vertex shader 인자에 붙여질 때 의미를 가진다.
semantic들은 direct3d9부터 지원된다.
InputDescriptionType
BINORMAL[n]Binormalfloat4
BLENDINDICES[n]Blend indicesuint
BLENDWEIGHT[n]Blend weightsfloat
COLOR[n]Diffuse and specular colorfloat4
NORMAL[n]Normal vectorfloat4
POSITION[n]Vertex position in object space.float4
POSITIONTTransformed vertex position.float4
PSIZE[n]Point sizefloat
TANGENT[n]Tangentfloat4
TEXCOORD[n]Texture coordinatesfloat4
OutputDescriptionType
COLOR[n]Diffuse or specular colorfloat4
FOGVertex fogfloat
POSITION[n]Position of a vertex in homogenous space. Compute position in screen-space by dividing (x,y,z) by w. Every vertex shader must write out a parameter with this semantic.float4
PSIZEPoint sizefloat
TESSFACTOR[n]Tessellation factorfloat
TEXCOORD[n]Texture coordinatesfloat4

 

n is an optional integer between 0 and the number of resources supported. For example, POSITION0, TEXCOOR1, etc.

Pixel Shader Semantics

These semantics have meaning when attached to a pixel-shader input parameter. These semantics are supported in both Direct3D 9 and Direct3D 10 and later.


이러한 semantic들은 pixel shader 인자에 붙여질 때 의미를 가진다.
semantic들은 direct3d9부터 지원된다.
InputDescriptionType
COLOR[n]Diffuse or specular color.float4
TEXCOORD[n]Texture coordinatesfloat4
VFACEFloating-point scalar that indicates a back-facing primitive. A negative value faces backwards, while a positive value faces the camera.
Note  This semantic is available in Direct3D 9 Shader Model 3.0. For Direct3D 10 and later, use SV_IsFrontFace instead.
 
float
VPOSThe pixel location (x,y) in screen space. To convert a Direct3D 9 shader (that uses this semantic) to a Direct3D 10 and later shader, see Direct3D 9 VPOS and Direct3D 10 SV_Position)float2
OutputDescriptionType
COLOR[n]Output colorfloat4
DEPTH[n]Output depthfloat

 

n is an optional integer between 0 and the number of resources supported. For example, PSIZE0, COLOR1, etc.

The COLOR semantic is only valid in shader compatibility mode (that is, when the shader is created using D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY).


COLOR semantic은 호환이 되는 셰이더 모드에서만 유효하다.
(셰이더가 D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY를 사용해서 만들어질 때)
참고로 D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY 옵션은 
예전버전 셰이더를 shader 4.0으로 컴파일 할 수 있게 해 준다.

Semantics Supported Only for Direct3D 10 and Newer.

The following types of semantics have been newly introduced for Direct3D 10 and are not available to Direct3D 9.

아래의 semantic들은 direct3d 10에서 새로 추가되었고 direct3d 9에서는 사용할 수 없는
semantic들이다.

System-Value Semantics

System-value semantics are new to Direct3D 10. All system-values begin with an SV_ prefix, a common example is SV_POSITION, which is interpreted by the rasterizer stage. The system-values are valid at other parts of the pipeline. For instance, SV_Position can be specified as an input to a vertex shader as well as an output. Pixel shaders can only write to parameters with the SV_Depth and SV_Target system-value semantics.


system value semantic들은 direct3d 10에서 새로 추가되었다.
모든 system value들은 첨자로 SV_가 붙으며(ex : SV_POSITION), 래스터라이저 
스테이지에서 해석되어진다.
system value들은 파이프라인의 다른 부분에서 유효하다.
예를 들어보자면, SV_Position은 vertex shader의 입력과 출력에서 특별한 의미를 가진다.
pixel shader는 파라미터에 오로지 SV_Depth와 SV_Target system value semantic들만 
사용이 가능하다.

Other system values (SV_VertexID, SV_InstanceID, SV_IsFrontFace) can only be input into the first active shader in the pipeline that can interpret the particular value; after that the shader function must pass the values to subsequent stages.


다른 system value들(SV_VertexID, SV_InstanceID, SV_IsFrontFace)은 오로지
특정값을 해석할 수 있는 파이프라인의 첫 번째 활성 셰이더에의 
입력값으로만 사용될 수 있다.
그 이후의 셰이더 함수들은 반드시 다음 스테이지로 값을 전달해야 하기 때문이다.

SV_PrimitiveID is an exception to this rule of only being input into the first active shader in the pipeline that can interpret the particular value; the hardware can provide the same ID value as input to the hull-shader stage, domain-shader stage, and after that whichever stage is the first enabled: geometry-shader stage or pixel-shader stage.


SV_PrimitiveID는 파이프라인의 첫 번째 활성 셰이더의 입력값으로 사용할 수 있다는
규칙에서 예외이다. 하드웨어는 같은 아이디 값을 hull shader, domain shader stage,
그리고 그 이후로 geometry shader 이나 pixel shader 스테이지중 첫번째로 이용할 수 있는
하나에 입력으로 넣을 수 있다.

If tessellation is enabled, the hull-shader stage and domain-shader stage are present. For a given patch, the same PrimitiveID applies to the patch's hull-shader invocation, and all tessellated domain shader invocations. The same PrimitiveID also propagates to the next active stage; geometry-shader stage or pixel-shader stage if enabled.


tessellaction이 사용 가능해지면 hull shader 스테이지와 domain shader 스테이지가 생긴다.
(참고로 테셀레이션은 dx11에서 추가되었고 hull - tessellator - domain 순이다.)
정점 셰이더에서 넘겨받은 조각들에서 같은 PrimitiveID가 hull shader 호출에 적용되고,
그리고 모두 테셀레이트되어 domain shader가 호출된다.
같은 PrimitiveID들은 또한 다음 활성화 스테이지로 전달된다;geometry shader나 
pixel shader중 확성화 되어있는 스테이지.


If the geometry shader inputs SV_PrimitiveID and because it can output zero or one or more primitives per invocation, the shader must program its own choice of SV_PrimitiveID value for each output primitive if a subsequent pixel shader inputs SV_PrimtiveID.


만약 geometry shader의 입력으로 SV_PrimitiveID을 넣을경우 매 호출마다
0개나 하나 또는 더 많은 프리미티브들이 출력되기 때문에 만약 다음 스테이지인 
pixel shader의 입력으로 SV_PrimitiveID가 들어온다면 매번 primitive을 출력하기 위해
geometry shader 에서 SV_PrimitiveID 값을 선택해서 가지고 있도록 프로그램 해야한다.

As another example, SV_PrimitiveID cannot be interpreted by the vertex-shader stage because a vertex can be a member of multiple primitives.

These semantics have been added to Direct3D 10; they are not available in Direct3D 9.


또 다른 예로, 정점은 여러개의 primitive에서 사용될 수 있기 때문에 
SV_PrimitiveID는 vertex shader 스테이지에서 사용할 수 없다.
이러한 semantic들은 direct3d 10에서 추가되었기 때문에 direct3d 9에서 사용할 수 없다.

System-value semantics for the rasterizer stage.

레스터라이저 스테이지를 위한 System-value semantic들

System-Value SemanticDescriptionType
SV_ClipDistance[n]Clip distance data. SV_ClipDistance values are each assumed to be a float32 signed distance to a plane. Primitive setup only invokes rasterization on pixels for which the interpolated plane distance(s) are >= 0. Multiple clip planes can be implemented simultaneously, by declaring multiple component(s) of one or more vertex elements as the SV_ClipDistance. The combined clip and cull distance values are at most D3D#_CLIP_OR_CULL_DISTANCE_COUNT components in at most D3D#_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT registers.

Available to all shaders to be read or written to, except the vertex shader which can write the value but not take it as input.

The clipplanes attribute works like SV_ClipDistance but works on all hardware feature level 9_x and higher. For more info, see User clip planes on feature level 9 hardware.

float
SV_CullDistance[n]Cull distance data. When component(s) of vertex Element(s) are given this label, these values are each assumed to be a float32 signed distance to a plane. Primitives will be completely discarded if the plane distance(s) for all of the vertices in the primitive are < 0. Multiple cull planes can be used simultaneously, by declaring multiple component(s) of one or more vertex elements as the SV_CullDistance. The combined clip and cull distance values are at most D3D#_CLIP_OR_CULL_DISTANCE_COUNT components in at most D3D#_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT registers.

Available to all shaders to be read or written to, except the vertex shader which can write the value but not take it as input.

float
SV_Coverage

A mask that can be specified on input, output, or both of a pixel shader.

For SV_Coverage on a pixel shader, OUTPUT is supported on ps_4_1 or higher.

For SV_Coverage on a pixel shader, INPUT requires ps_5_0 or higher.

uint
SV_DepthDepth buffer data. Can be written or read by any shader.float
SV_DepthGreaterEqual(n)Valid in any shader, tests whether the value is greater than or equal to the depth data value.unknown
SV_DepthLessEqual(n)Valid in any shader, tests whether the value is less than or equal to the depth data value.unknown
SV_DispatchThreadIDDefines the global thread offset within the Dispatch call, per dimension of the group. Available as input to compute shader. (read only)uint3
SV_DomainLocationDefines the location on the hull of the current domain point being evaluated. Available as input to the domain shader. (read only)float2|3
SV_GroupIDDefines the group offset within a Dispatch call, per dimension of the dispatch call. Available as input to the compute shader. (read only)uint3
SV_GroupIndexProvides a flattened index for a given thread within a given group. Available as input to the compute shader. (read only)uint
SV_GroupThreadIDDefines the thread offset within the group, per dimension of the group. Available as input to the compute shader. (read only)uint3
SV_GSInstanceIDDefines the instance of the geometry shader. Available as input to the geometry shader. The instance is needed as a geometry shader can be invoked up to 32 times on the same geometry primitive.uint
SV_InnerCoverageRepresents underestimated conservative rasterization information (i.e. whether a pixel is guaranteed-to-be-fully covered). Can be read or written by the pixel shader.
SV_InsideTessFactorDefines the tessellation amount within a patch surface. Available in the hull shader for writing, and available in the domain shader for reading.float|float[2]
SV_InstanceIDPer-instance identifier automatically generated by the runtime (see Using System-Generated Values (Direct3D 10)). Available to all shaders.
SV_IsFrontFaceSpecifies whether a triangle is front facing. For lines and points, IsFrontFace has the value true. The exception is lines drawn out of triangles (wireframe mode), which sets IsFrontFace the same way as rasterizing the triangle in solid mode. Can be written to by the geometry shader, and read by the pixel shader.bool
SV_OutputControlPointIDDefines the index of the control point ID being operated on by an invocation of the main entry point of the hull shader. Can be read by the hull shader only.uint
SV_PositionWhen SV_Position is declared for input to a shader, it can have one of two interpolation modes specified: linearNoPerspective or linearNoPerspectiveCentroid, where the latter causes centroid-snapped xyzw values to be provided when multisample antialiasing. When used in a shader, SV_Position describes the pixel location. Available in all shaders to get the pixel center with a 0.5 offset.float4
SV_PrimitiveIDPer-primitive identifier automatically generated by the runtime (see Using System-Generated Values (Direct3D 10)). Can be written to by the geometry or pixel shaders, and read by the geometry, pixel, hull or domain shaders.uint
SV_RenderTargetArrayIndexRender-target array index. Applied to geometry shader output and indicates the render target array slice that the primitive will be drawn to by the pixel shader. SV_RenderTargetArrayIndex is only valid if the render target is an array resource. This semantic applies only to primitives, if a primitive has more than one vertex the value from the leading vertex will be used.

This value also indicates which array slice of a depthstencilview is used for read/write purposes.

Can be written from the geometry shader and read or written by the pixel shader.
uint
SV_SampleIndexSample frequency index data. Available to be read or written to by the pixel shader only.uint
SV_StencilRefRepresents the current pixel shader stencil reference value. Can be written by the pixel shader only.uint
SV_Target[n],

where 0 <= n <= 7
The output value that will be stored in a render target. The index indicates which of the 8 possibly bound render targets to write to. The value is available to all shaders.float
SV_TessFactorDefines the tessellation amount on each edge of a patch. Available for writing in the hull shader and reading in the domain shader.float[2|3|4]
SV_VertexIDPer-vertex identifier automatically generated by the runtime (see Using System-Generated Values (Direct3D 10)). Available as the input to the vertex shader only.uint
SV_ViewportArrayIndexViewport array index. Applied to geometry shader output and indicates which viewport to use for the primitive currently being written out. Can be read or written by the pixel shader. The primitive will be transformed and clipped against the viewport specified by the index before it is passed to the rasterizer. This semantic applies only to primitives, if a primitive has more than one vertex the value from the leading vertex will be used.uint

 

Limitations when writing SV_Depth:

SV_Depth을 사용할 때의 제한사항:
  • When multisampling (MultisampleEnable is TRUE in D3D10_RASTERIZER_DESC) and writing a depth value (using a pixel shader), the single value written out is also used in the depth test; so the ability to render primitive edges at higher resolution is lost when multisampling. 
  • When using dynamic-flow control, it is impossible to determine at compile time whether a shader that writes SV_Depth in some paths will be guaranteed to write SV_Depth in every execution. Failure to write SV_Depth when declared results in undefined behavior (which may or may not include discard of the pixel).
  • Any float32 value including +/-INF and NaN can be written to SV_Depth.
  • Writing SV_Depth is still valid when performing Dual Source Color Blending.


1. 멀티샘플링(D3D10_RASTERIZER_DESC에서 MultisampleEnable TRUE)이고 depth값을 
쓴다면(pixel shader에서), 자세하게 작성되어지는 단일 값 또한 depth test에서 사용된다.
그래서 멀티샘플링에서 높은 해상도에서 프리미티브 외곽을 그리는 능력을 잃게된다.
2. 동적 흐름 제어를 사용하면, 모든 실행에서 SV_Depth을 쓰도록 보장되어져 있는
몇몇 패스에서 SV_Depth를 쓰는 셰이더인지 아닌지 컴파일 시간에 결정하는게 불가능하다.
정의되지 않은 행동의 결과를 선언할 때 SV_Depth 쓰는것은 실패한다.
(픽셀의 discard에 포함될 수도 있고 안될수도 있다.)
3. 어떤 float32 변수라도 +/-INF 와 NAN을 포함해서 SV_Depth에 쓸수 있다.
4. SV_Depth을 쓰는것은 여전히 두 소스를 혼합하는 색상 블랜딩 효과에 유효하다

Migration from Direct3D 9 to Direct3D 10 and later

The following issues should be considered when migrating code from Direct3D 9 to Direct3D 10 and later:

다음의 사항들은 direct3d9에서 direct3d10 이상의 버전으로 변경하고자 할 때 고려되어야 하는 사항들이다. 

Mapping to Direct3D 9 Semantics

A few of the Direct3D 10 and later semantics map directly to Direct3D 9 semantics.

Direct3D 10 SemanticDirect3D 9 Equivalent Semantic
SV_DepthDEPTH
SV_PositionPOSITION
SV_TargetCOLOR

 

Note to Direct3D 9 developers:

For Direct3D 9 targets, shader semantics must map to valid Direct3D 9 semantics. For backwards compatibility POSITION0 (and its variant names) is treated as SV_Position, COLOR is treated as SV_TARGET.


Direct3D 9 개발자들에게 알림.
Direct3D 9을 타겟으로 한다면, 셰이더 semantic들은 반드시 Direct3D 9 semantic에 
유효하게 매핑해야 한다.
이전 버전과의 호환성을 위해 POSITION은 SV_Position, COLOR은 SV_TARGET로
대체되어졌다.

 

Direct3D 9 VPOS and Direct3D 10 SV_Position

The D3D10 semantic SV_Position provides similar functionality to the Direct3D 9 shader model 3 VPOS semantic. For instance, in Direct3D 9 the following syntax is used for a pixel shader using screen space coordinates:


D3D10 semantic SV_Position은 Direct3D 9 shader model 3의 VPOS semantic과
비슷한 기능을 제공한다.
예를 들면, Direct3D 9 이 문법은 pixel shader에서 화면좌표을 위해 사용되었다.

float4 psMainD3D9( float4 screenSpace : VPOS ) : COLOR
{
  // code here	
}
	      

VPOS was added for shader model 3 support, to specify screen space coordinates, since the POSITION semantic was intended for object-space coordinates.


POSITON semantic이 오브젝트 공간 좌표를 위해 추가된 이후로,
VPOS는 shader model 3에서 화면공간 좌표를 지원하기 위해 추가되어졌다.

In Direct3D 10 and later, the SV_Position semantic (when used in the context of a pixel shader) specifies screen space coordinates (offset by 0.5). Therefore, the Direct3D 9 shader would be roughly equivalent (without accounting for the 0.5 offset) to the following:


Direct3D 10 이상의 버전에서, SV_Position semantic(픽셀 셰이더의 문맥으로 사용됨)은
(0.5 오프셋)화면 공간 좌표를 지정한다. 
그러므로, Direct3D 9 shader는 아래의 예와 같을 것이다.(0.5 offset 수치 없이)

float4 psMainD3D10( float4 screenSpace : SV_Position ) : COLOR
{
  // code here
}
	      

When migrating from Direct3D 9 to Direct3D 10 and later, you will need to be aware of this when translating your shaders.


Direct3D 에서 10 이상버전으로 변경시 셰이더를 번역할 때 알고있어야 한다.

User clip planes in HLSL

Starting with Windows 8, you can use the clipplanes function attribute in an HLSL function declaration rather than SV_ClipDistance to make your shader work on feature level 9_x as well as feature level 10 and higher. For more info, see User clip planes on feature level 9 hardware.


윈도우8에서부터 shader가 9_x 레벨 뿐만 아니라 level10 이상에서도 동작하도록 
하기 위해 SV_ClipDistance 보다 HLSL 함수 선언에 있는 clipplanes 기능 속성을 
사용할 수 있다.

Double Binding Semantics

You can apply the same semantic to more than one parameter. For instance:

같은 semantic를 하나이상 인자로 적용할 수 있다. 아래 예를 보자.
float4x4 WorldView[60] : WORLDVIEW : register(c16);
 
float4 main( float3 Pos : SV_POSITION, int4 IPos : SV_POSITION ) : SV_POSITION
{
    float3 P = mul(float4(Pos, 1), (float4x3)WorldView[IPos.w]);
    return float4(P,1);        
}
      

This function takes two arguments: a three-component, floating-point position and a four-component, integer position. The integer position is used as an index into the array of world-view matrices.

두 인자를 받는 함수 : float3 위치값, float4 인트형 위치값.
int형 위치값은 월드 뷰 행렬의 배열의 이인덱스로 사용되어 진다.


Reference Link

- Microsoft Semantics

- 라이푸_[D3D10] System Values

- 셰이더 개론

-


'Study > Graphics ' 카테고리의 다른 글

UV Texture Coordinates and Texture Mapping - OpenGL / DirectX  (0) 2016.08.14
normal map compression  (0) 2016.06.13
normal mapping artifacts  (0) 2014.12.10
tangent space, 접선 공간  (0) 2014.04.07
DXT 압축  (0) 2013.03.15
TAGS.

Comments