HLSL Asm Shader Reference

1623 篇文章 22 订阅
1277 篇文章 12 订阅

Asm Shader Reference

Shaders drive the programmable graphics pipeline.

Vertex Shader Reference

Vertex Shader Differences summarizes the differences between vertex shader versions.

Pixel Shader Reference

Pixel Shader Differences summarizes the differences between pixel shader versions.

Shader Model 4 and 5 Reference

The Shader Model 4 Assembly and Shader Model 5 Assembly sections describe the instructions that shader model 4 and 5 support.

Behavior of Constant Registers in Assembly Shaders

There are two ways to set constant registers in an assembly shader:

  • Declare a shader constant in assembly code using one of the def* instructions.
  • Use one of the Set***ShaderConstant* API methods.

Direct3D 9 Shader Constants

In Direct3D 9 the lifetime of defined constants in a given shader is confined to the execution of that shader only (and is non-overridable). Defined constants in Direct3D 9 have no side effects outside of the shader.

Here's an example using Direct3D 9:

Given: 
    Create shader1 which references c4 and defines it with the def instruction

Scenario 1:
	Call Set***Shader shader1
	Call Set***ShaderConstant* to set c4
	Call Draw
	Result: The shader will see the def'd value in c4

	
Given: 
    Scenario 1 has just completed
    Create shader2 (which references c4 but does not use the def instruction
	  to define it)	

Scenario 2:	
	Call Set***Shader shader2
	Call Draw
	Result: The shader will see the value last set in c4 by 
	 Set***ShaderConstant* in scenario 1. This is because shader 2 
	 didn't def c4.


In Direct3D 9, calling Get***ShaderConstant* will only retrieve constant values set via Set***ShaderConstant*.

Direct3D 8 Shader Constants

This behavior is different in Direct3D 8.x.

Given:
	Create shader1 which references c4 and defines it with the def instruction

Scenario 1 (repeated with Direct3D 8):
	Call Set***Shader with shader1
	Call Set***ShaderConstant to set c4
	Call Draw
	Result: The shader will see the value in c4 from Set***ShaderConstant


In Direct3D 8.x Set***ShaderConstant takes effect immediately. Consider this scenario:

Given:
	Create shader1 which references c4 and defines it with the def instruction
	
Scenario 3:
	Call Set***Shader with shader1
	Call Draw
	Result: The shader will see the def'd value in c4

Given:
	Scenario 3 has just completed
	Create shader2 (which references c4 but does not use the def instruction 
	  to define it)		
	
Scenario 4 :	
	Call Set***Shader with shader2
	Call Draw
	Result: The shader will see the def'd value in c4 (set by def in shader 1)


The undesirable result is that the order in which the shaders are set could affect the observed behavior of individual shaders.

Shader Driver Model Requirements

Direct3D 9 interfaces are restricted to device driver interface (DDI) drivers that are DirectX 7-level and above. To check the DDI level, run the DirectX Diagnostic Tool and examine the saved text file.

For reference, Direct3D 8 interfaces work only on DDI drivers that are DirectX 6-level and above.

Shader Binary Format

The bitwise layout of the shader instruction stream is defined in D3d9types.h. If you want to design your own shader compiler or construction tools and you want more information about the shader token stream, refer to the Direct3D 9 Driver Development Kit (DDK).

C-like Shader Language

See HLSL Reference to experience a C-like shader language.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值