the complete hlsl reference - attila project - attilawiki

20
The COMPLETE HLSL Reference Sebastien St-Laurent All the information developers need from shader assembly instruction to a complete HLSL intrinsic function overview covering up to shader model 3.0. Presented in a quick and easy to access format!

Upload: others

Post on 16-Oct-2021

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Complete HLSL Reference - Attila Project - AttilaWiki

The COMPLETEHLSL Reference

Sebastien St-Laurent

All the information developers need from shader assembly instruction

to a complete HLSL intrinsic function overview covering

up to shader model 3.0. Presented in a quick and

easy to access format!

Page 2: The Complete HLSL Reference - Attila Project - AttilaWiki

� TheCOMPLETEHLSLReference

Vertex and Pixel Shader Assembly Language

AlthoughthedevelopmentofassemblylevelshadersisraretodaybecauseoftheHLSLlanguage,aproperunderstand-

ingoftheunderlayingassemblyinstructionsetsiscoretothedevelopmentanddebuggingofefficientshaders.

Both the vertex and pixel shader assembly languages arecomposed of setup and assembly instructions. Throughoutthefollowingpagesyouwillfindtablescontainingasummatyofbothtypesofinstructionsalongwithadescriptionoftheirfunction, parameter information, performance indicationsandsupportofvariousshaderversions.

Beforestarting,Ihavetomakeanoteinregardstosomeoftheflowcontrolinstructions.Forexample,theif_compin-struction defines flow control based on a comparison wherethe_compcomponentwillbereplacedbyacomparisonopera-tion.Thetablebelowsummarizesalltheoperationswhichcanbeusedwithinflowcontrol:

Flow Control Comparison ModesMode Description_gt Greater_lt Lesser_ge Greaterorequal_le Lesserorequal_eq Equal_ne Notequal

Inaddition,thefollowingtablescontainsomeindicationof the support of each instruction on every vertex and pixelshader version using a color coded system. The table belowsummarizesthecoding:

Color DescriptionRequireslessthan4instructionsslots.Requiresbetween4and7instructionslots.Required8ormoreinstructionslots.Unsupported.

Imustalsomakeafinalnoteinregardstotheperformancevalues indicated over the next pages. The quoted values arebasedontheDirectXspecificationsandindicatetheworstcaseperformancethatmustbeensuredbytherenderinghardware.This means that certain hardware implementations may ex-ecutecertaininstructionsfasterthanperscribedbythespeci-fications.

Page 3: The Complete HLSL Reference - Attila Project - AttilaWiki

TheCOMPLETEHLSLReference �

Vertex Shader AssemblyName Description 1.1 �.0 �.x �.0

dcl_usage Declareinputregisters.

def Defineconstants.

defb Definebooleanconstants.

defi Defineintegerconstants.

label Defineflowcontrollabels.

vs Retrievetheshaderversion.

Name 1.1 �.0 �.x �.0

Description

AdditionalParameterInfo

abs dst, src 1 1 1

Absolutevalueofthesrc.

add dst, src0, src1 1 1 1 1

Addsrc0andsrc1together.

break 1 1

Breakoutofalooporrepblock.

break_comp src0, src1

� �

Conditionallybreakoutofalooporrepblockbasedonascalarconditional.

_comp=comparisonmode.src0,src1=sourceregisters.

breakp [!]p0.{x|y|z|w}

� �

Breakoutofalooporrepblockbasedonapredicate.

[!]=optionalNOToperator.p0=isapredicateregister.{x|y|z|w}=requiredreplicateswizzle.

call l# � � �

Callasubroutinedefinedbyalabel.

l#=labeltosubroutine.

callnz_bool l#, [!]b#

� � �

Callasubroutineifregisterisnonzero.

l#=labeltocall.[!]=optionalNOToperator.b#=booleanregister.

callnz_pred l#, [!]p0.{x|y|z|w}

� �

Callasubroutinebasedonapredicate.

l#=labeltocall.[!]=optionalNOToperator.p0=predicateregister.{x|y|z|w}=requiredreplicateswizzle.

crs dst, src0, src1 � � �

Crossproductofsrc0andsrc1.

dp3 dst, src0, src1 1 1 1 1

Three-componentdotproduct.

dp4 dst, src0, src1 1 1 1 1

Four-componentdotproduct.

Page 4: The Complete HLSL Reference - Attila Project - AttilaWiki

4 TheCOMPLETEHLSLReference

Name 1.1 �.0 �.x �.0

Description

AdditionalParameterInfo

dst dst, src0, src1 1 1 1 1

Calculatelightingattenuationvector.

src0=(ignored,d×d,d×d,ignored).src1=(ignored,1/d,ignored,1/d).dst=(1,d,d×d,1/d).

else 1 1 1

Beginanelseblock.

endif 1 1 1

Endanif/elseblock.

endloop � � �

Endaloopblock.

endrep � � �

Endarepblock.

exp dst, src 10 1 1 1

Fullprecision�x.

expp dst, src 1 1 1 1

Partialprecision(16-bits)�x.

frc dst, src 1 1 1 1

Fractionalcomponentofinput.vs_1_1 can only write to .y and .xy.

if bool � � �

Beginanif/else/endifblock.

bool=booleanregister.

if_comp src0, src1 � �

Beginanifblockwithacomparison.

_comp=comparisonmode.src0,src1=sourceregisters.

if [!]pred.{x|y|z|w} � �

Beginanifblockwithapredicate.

[!]=optionalNOToperator.pred=predicateregister.{x|y|z|w}=requiredreplicateswizzle.

lit dst, src 1 � � �

Partiallightingcalculation.

dst=destinationregister.src=(N•L,N•H,unused,exponent).

log dst, src 10 1 1 1

Fullprecisionlog�(x).

logp dst, src 1 1 1 1

Partialprecision(16-bits)log�(x).

loop aL, i# � � �

Startaloopblock.

aL=loopcountingregister.i#=constantintegerregister.

lrp dst, src0, src1, src2

� � �

Linearlyinterpolatesbetweensrc1andsrc2usingsrc0([0..1]range).

m3x2 dst, src0, src1

� � � �

Productofvectoranda��matrix.

Page 5: The Complete HLSL Reference - Attila Project - AttilaWiki

TheCOMPLETEHLSLReference �

Name 1.1 �.0 �.x �.0

Description

AdditionalParameterInfo

m3x3 dst, src0, src1

� � � �

Productofavectoranda��matrix.

m3x4 dst, src0, src1

4 4 4 4

Productofavectoranda4�matrix.

m4x3 dst, src0, src1

� � � �

Productofavectoranda�×4matrix.

m4x4 dst, src0, src1

4 4 4 4

Productofavectoranda4×4matrix.

mad dst, src0, src1, src2

1 1 1 1

Multipliessrc0andsrc1thenaddssrc2.

max dst, src0, src1 1 1 1 1

Maximumofsrc0andsrc1.

min dst, src0, src1 1 1 1 1

Minimumofsrc0andsrc1.

mov dst, src 1 1 1 1

Movedatafromoneregistertoanother.

mova dst, src 1 1 1

Movedatatoanaddressregister.

mul dst, src0, src1 1 1 1 1

Multipliessrc0andsrc1together.

nop 1 1 1 1

Nooperation.

nrm dst, src � � �

Normalizestheinput(src/length(src)).

pow dst, src0, src1 � � �

Returnssrc0src1.

rcp dst, src 1 1 1 1

Reciprocaloftheinput(1/src).

rep i# � � �

Startsarepblock.

I#=integerregisterwithrepeatcountinxcomponent.

ret 1 1 1

Endsubroutineormain.

rsq dst, src 1 1 1 1

Reciprocalsquareroot(1/sqrt(src)).

setp_comp dst, src0, src1

1 1

Setthepredicateregister.

_comp=comparisonmode.dst=destinationpredicateregister.src0,src1=sourceregisters.

sge dst, src0, src1 1 1 1 1

Greaterthanorequalcompare.

sgn dst, src0, src1, src2

� � �

Returnsthesignofthesrc0.

dst=-1fornegativeand1forpositive.src0=sourceregisters.src1,src�=temporaryregistersusedforcalculation.

Page 6: The Complete HLSL Reference - Attila Project - AttilaWiki

6 TheCOMPLETEHLSLReference

Name 1.1 �.0 �.x �.0

Description

AdditionalParameterInfo

sincos dst.{x|y|xy}, src0.{x|y|z|w}, src1, src2

8 8 8

Computesboththesineandcosine.

dst=destinationregister(.xcontainssinand.ycontainscosandhastopointtoatemporaryregister).src0=inputanglesourceregister.src1=D3DSINCOSCONST1.src�=D3DSINCOSCONST2.

slt dst, src0, src1 1 1 1 1

Lessthancompare.

sub dst, sub0, sub1 1 1 1 1

Subtractssrc1fromsrc0.

texldl dst, src0, src1 �,�forCubemap

Loadsatexturesample.

dst=destinationregister.src0=texturecoordinate.src1=texturesampler.

Pixel Shader AssemblyName Description 1.x �.0 �.x �.0

dcl Declareinputregisters.

dcl_samplerType Declaretexturedimensionsforasampler.

phase Transitionbetweenphase1andphase�shadercode.

def Defineconstants.

defb Definebooleanconstants.

defi Defineintegerconstants.

label Definelabels.

ps Retrievetheshaderversion.

Name 1.1 1.� 1.� 1.4 �.0 �.x �.0

Description

ParameterInformation

abs dst, src 1 1 1Returntheabsolutevalueofsrc.

add dst, src0, src1

1 1 1 1 1 1 1Addsrc0andsrc1together.

bem dst.rg, src0, src1

�Applyafakebumpmapingtransform.dst=destinationregister(.rgonly).src0,src1=sourceregisters.

break 1 1Breakoutofalooporrepblock.

Page 7: The Complete HLSL Reference - Attila Project - AttilaWiki

TheCOMPLETEHLSLReference 7

Name 1.1 1.� 1.� 1.4 �.0 �.x �.0

Description

ParameterInformation

break_comp src0, src1

� �Conditionalbreakoutofalooporrep.comp=comparisonmode.src0,src1=sourceregisters.

breakp [!]p0.{x|y|z|w}

� �Predicatebreakoutofalooporrep.[!]=optionalNOToperator.p0=predicateregister.{x|y|z|w}=requiredreplicateswizzle.

call l# � �Callthespecifiedsubroutine.l#=labeltocall

callnz l#, [!]b# � �Callasubroutineonanonzeroboolean.l#=labeltocall.[!]=optionalNOToperator.b#=booleanregister.

callnz l#, [!]p0.{x|y|z|w}

� �Callasubroutineonapredicate.l#=labeltocall.[!]=optionalNOToperator.p0=predicateregister.{x|y|z|w}=requiredreplicate.

cmp dst, src0, src1

� � 1 1 1 1Comparesourcevectorto0.

cnd dst, src0, src1, src2

1 1 1 1Comparesrc0vectorto0.�,returningeithersrc1orsrc2.

crs dst, src0, src1

� � �Crossproductofsrc0andsrc1.

dp2add dst, src0, src1, src2.{x|y|z|w}

� � ��Ddotproductwithscalaradditiontotheresult.

dp3 dst, src0, src1

1 1 1 1 1 1 1Three-componentvectordotproduct.

dp4 dst, src0, src1

� � 1 1 1 1Four-componentdotproduct.

dsx dst, src 1 1Rateofchangeinthexdirection.

dsy dst, src 1 1Rateofchangeintheydirection.

else 1 1Beginanelseblock.

endif 1 1Endanif/elseblock.

Page 8: The Complete HLSL Reference - Attila Project - AttilaWiki

8 TheCOMPLETEHLSLReference

Name 1.1 1.� 1.� 1.4 �.0 �.x �.0

Description

ParameterInformation

endloop � �Endaloop/endloopblock.

endrep � �Endarepeatblock.

exp dst, src 1 1 1Fullprecision�x.

frc dst, src 1 1 1Returnthefractionalofsrc.

if bool � �Beginanif /else/endifblock.bool=booleanregister.

if_comp src0, src1

� �Beginanifblock,withacomparison._comp=comparisonmode.src0,src1=sourceregisters.

if_pred [!]pred.{x|y|z|w}

� �Beginanifblockwithapredicate.[!]=optionalNOToperator.pred=predicateregister.{x|y|z|w}=requiredreplicateswizzle.

log dst, src 1 1 1Fullprecisionlog�(x).

lrp dst, src0, src1, src2

1 1 1 1 � � �Interpolationofsrc1andsrc2basedonsrc0(inthe[0..1]range).

m3x2 dst, src0, src1

� � �Productofavectoranda��matrix.

m3x3 dst, src0, src1

� � �Productofavectoranda��matrix.

m3x4 dst, src0, src1

4 4 4Productofavectoranda4�matrix.

m4x3 dst, src0, src1

� � �Productofavectoranda�×4matrix.

m4x4 dst, src0, src1

4 4 4Productofavectoranda4×4matrix.

mad dst, src0, src1, src2

1 1 1 1 1 1 1Multiplysrc0andsrc1togetheraddingsrc2totheresult.

max dst, src0, src1

1 1 1Maximumbetweensrc0andsrc1.

min dst, src0, src1

1 1 1Minimumbetweensrc0andsrc1.

mov dst, src 1 1 1 1 1 1 1Movedatafromoneregistertoanother.

Page 9: The Complete HLSL Reference - Attila Project - AttilaWiki

TheCOMPLETEHLSLReference �

Name 1.1 1.� 1.� 1.4 �.0 �.x �.0

Description

ParameterInformation

mul dst, src0, src1

1 1 1 1 1 1 1Multipliessrc0andsrc1together.

nop 1 1 1 1 1 1 1Nooperation.

nrm dst, src � � �Normalizeavector.(src/length(src)).

pow dst, src0, src1

� � �Returnsrc0src1.

rcp dst, src 1 1 1Returnthereciprocalofsrc.

rep i# � �Startarepblock.i#=integerregisterspecifyingtheloopcountinthexcomponent.

ret 1 1Endasubroutineormain.

rsq dst, src 1 1 1Reciprocalsquareroot,or1/sqrt(src).

setp_comp dst, src0, src1

1 1Setthepredicateregister._comp=comparisonmode.dst=destinationpredicateregister.src0,src1=sourceregisters.

sincos dst.{x|y|xy}, src0.{x|y|z|w}, src1, src2

8 8 8Computeboththesineandcosine.dst=destinationregister(.xcontainssinand.ycontainscosandhastopointtoatemporaryregister).src0=inputangle.src1=D3DSINCOSCONST1.src�=D3DSINCOSCONST2.

sub dst, src0, src1

1 1 1 1 1 1 1Subtractsrc1fromsrc0.

tex dst 1 1 1Sampleatexture.

texbem dst, src 1 1 1Applyafakebumpmaptransform.

texbeml dst, src � � �Applyabumpmapwithluminance.

texcoord dst 1 1 1Treattexturecoordinatesascolordata.

texcrd dst, src 1Copytexturecoordinateascolordata.

texdepth dst 1Calculatedepthvalues.

Page 10: The Complete HLSL Reference - Attila Project - AttilaWiki

10 TheCOMPLETEHLSLReference

Name 1.1 1.� 1.� 1.4 �.0 �.x �.0

Description

ParameterInformation

texdp3 dst, src 1 1Three-componentdotproductbetweentextureandthetexturecoordinates.

texdp3tex dst, src

1 1Three-componentdotproductand1Dtexturelookup.

texkill src 1 1 1 1 1 Note1 �Cancelrenderingofpixelsbasedonacomparison.src0=killpixelifanycomponent<0.

texld dst, src 1 1 Note� Note�

Sampleatexture.texldb dst, src0, src1

1 Note� 6Sampletexturewithlevelofdetailbiasfromw-componentofthetexturecoordinates.dst=destinationregister.src0=texturecoordinates.src1=sampler.

texldd dst, src0, src1, src2, src3

� �Sampletexturewithgradient.dst=destinationregister.src0=texturecoordinates.src1=sampler.src�=xgradient.src�=ygradient.

texldl dst, src0, src1

Note6

SampletexturewithLODfromw-component.dst=destinationregister.src0=texturecoordinates.src1=sampler.

Texldp dst, src0, src1

1 Note4 Note7

Sampletexturewithprojectivedividebyw-component.dst=destinationregister.src0=texturecoordinates.src1=sampler.

texm3x2depth dst, src

1Calculateper-pixeldepthvalues.

texm3x2pad dst, src

1 1 1Firstrowmatrixmultiplyofatwo.

texm3x2tex dst, src

1 1 1Finalrowmatrixmultiplyofatwo.

texm3x3 dst, src 1 1��matrixmultiply.

Page 11: The Complete HLSL Reference - Attila Project - AttilaWiki

TheCOMPLETEHLSLReference 11

Name 1.1 1.� 1.� 1.4 �.0 �.x �.0

Description

ParameterInformation

texm3x3pad dst, src

1 1 1Firstorsecondrowmultiplyofthree.

texm3x3spec dst, src0, src1

1 1 1Finalrowmultiplyofthree.

texm3x3tex dst, src

1 1 1Texturelookupusinga��matrixmultiply.

texm3x3vspec dst, src

1 1 1Texturelookupusinga��matrixmultiply,withnonconstanteye-rayvector.

texreg2ar dst, src

1 1 1Sampleatextureusingthealphaandredcomponents.

texreg2gb dst, src

1 1 1Sampleatextureusingthegreenandbluecomponents.

texreg2rgb dst, src

1 1Sampleatextureusingthered,greenandbluecomponents.

Note 1:IfD3DPS20CAPS_NOTEXINSTRUCTIONLIMITisset,slots=�;otherwiseslots=1.

Note 2: If D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT is set andthetextureisacubemap,slots=4;otherwiseslot=1.

Note 3:IfD3DPS20CAPS_NOTEXINSTRUCTIONLIMITisset,slots=6;otherwiseslots=1.

Note 4: IfD3DPS20CAPS_NOTEXINSTRUCTIONLIMIT isnot set,slots=1;otherwise: if the texture is a cubemap, slots=4; if thetextureisnotacubemap,slots=�.

Note 5:Ifthetextureisacubemap,slots=4;otherwiseslots=1.

Note 6:Ifthetextureisacubemap,slots=�;otherwiseslots=�.

Note 7:Ifthetextureisacubemap,slots=4;otherwiseslots=�.

Page 12: The Complete HLSL Reference - Attila Project - AttilaWiki

1� TheCOMPLETEHLSLReference

HLSL Intrinsic Functions

Tosimplifythedevelopmentofshaders,theHLSLshadinglanguage introduces a high-level programming scheme

similartoC.Thissimplifiesthedeveloperstasksandtaketheirburdenawayfrommanual instructionoptimizationandreg-isterallocation.

ThefollowingtablecontainsacompleteoverviewofalltheHLSL intrinsic functionality.The table contains informationaboutthefunctionsuchasadescriptionofitsuse,parameteroverview,performanceconsiderationandanindicationoftheminimalshaderversionrequiredtoexecutethefunction.

Keep in mind that performance figures given below arebasedonasimpleshaderusingonlythespecifiedinstructioninordertoavoidoptimizations.Thisshouldserveasaworstcasescenarioas realusecaseswillgenerally result inbetterperformingshaders.

Name VS PS Performance

Parameters

Description

ret abs(x) 1.1 1.4 Implementedinoneinstructionslot.

x | in | scalar, vector or matrix | float, intret | out | same as input x | same as input x

Returntheabsolutevalueofx.

ret acos(x) 1.1 �.0 Taylorseriestaking17instructionslots.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnthearccosinevaluex(validfor[-1,1]).

ret all(x) 1.1 1.4 Implementedusing�instructionslots.

x | in | scalar, vector or matrix | float, int, boolret | out | scalar | bool

Testifallthecomponentsofxarenonzero.

ret any(x) 1.1 1.4 Implementedusing�instructionslots.

x | in | scalar, vector or matrix | float, int, boolret | out | scalar | bool

Testsifanyofthecomponentsofxarenonzero.

ret asin(x) 1.1 �.0 Taylorseriesusing18instructionslots.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnthearcsinevalueofx (validfor[-π/�,π/�]).

ret atan(x) 1.1 �.0 Taylorseriesusing�1instructionslots.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnthearctanvalueofx(resultrange[-π/�,π/�]).

ret atan2(x, y) 1.1 �.0 Taylorseriesusing��instructionslots.

x | in | scalar, vector or matrix | floaty | in | same as input x | floatret | out | same as input x | float

Returnthearctanofx/y(resultrange[-π/�,π/�]).

Page 13: The Complete HLSL Reference - Attila Project - AttilaWiki

TheCOMPLETEHLSLReference 1�

Name VS PS Performance

Parameters

Description

ret ceil(x) 1.1 �.0 Implementedwiththefrcinstructionandtakes�instructionslotsbutmaytakemoreon1.xhardware.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returntheintegergreaterorequaltox.

ret clamp(ret, min, max)

1.1 1.4 Implementedusingtheminandmaxinstructionstaking�instructionslots.

x | in | scalar, vector or matrix | float, intmin | in | same as input x | same as input xmax | in | same as input x | same as input xret | out | same as input x | same as input x

Returnstheinputxclampedtotherange[min,max].

clip(x) N/A 1.1 RemovesthebenefitsofearlyZrejection.

x | in | scalar, vector or matrix | float

Thisfunctionwilldiscardthecurrentpixelifanyofcomponentsofxarelessthanzero.

ret cos(x) 1.1 �.0 Taylorseriesusing1�instructionslots.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnthecosineofx.

ret cosh(x) 1.1 �.0 Numericalapproximationusingtheexpinstruction.Uses8�instructionsslotson1.xhardware,11slotson�.0+hardware.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnthehyperboliccosineofx.

ret cross(x,y) 1.1 1.4 Emulatedon1.xhardwareusing4slots.

x | in | vector | floaty | in | vector | floatret | out | vector | float

Executethecrossproductbetweenxandy.

ret ddx(x) N/A �.x Verifycapabilitiesbeforeusing.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Partialderivateinthescreenspacexcoordinate.

ret ddy(x) N/A �.x Verifycapabilitiesbeforeusing.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Partialderivateofxinthescreenspaceycoordinate.

ret degrees(x) 1.1 �.0 N/A

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Convertxfromradianstodegrees.

ret determinant(x)

1.1 1.4 Implementedusingtheproperequationstakingabout1�instructionslots.

x | in | matrix | floatret | out | scalar | float

Returnthedeterminantofthesquarematrixx.

Page 14: The Complete HLSL Reference - Attila Project - AttilaWiki

14 TheCOMPLETEHLSLReference

Name VS PS Performance

Parameters

Description

ret distance(x, y) 1.1 �.0 Implementedin�instructionsslots.

x | in | vector | floaty | in | vector | floatret | out | scalar | float

Computethedistancebetweenxandy.

ret dot(x, y) 1.1 �.0 N/A

x | in | vector | float, inty | in | vector | float, intret | out | scalar | float, int

Computethedotproductbetweenxandy.

ret exp(x) 1.1 �.0 Excecutesin�instructionsslotsand41slotson1.xhardware.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnbase-eexponentialofx.

ret exp2(x) 1.1 �.0 Executesin4instructionsslotsand40slotson1.xhardware.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnbase-�exponentialofx.

ret faceforward(n, i, ng)

1.1 1.4 Implementedin7instructionslots.

n | in | vector | floati | in | vector | floatng | in | vector | floatret | out | vector | float

Testifafaceisvisibleusingthefollowingequation:ret = -n * sign( dot( i, ng ) ).

ret floor(x) 1.1 �.0 Implementedusingthefrcfunctionintwoinstructionslotsbutmaytakemoreon1.xhardware.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnthelargestintegerthatislesserthanx.

ret fmod(x, y) 1.1 �.0 Implementedin11instructionslotsand1�slotson1.xhardware.

x | in | scalar, vector or matrix | float, inty | in | same as input x | same as input xret | out | same as input x | same as input x

Returnthefloating-pointreminderfofx/y.

ret frac(x) 1.1 �.0 Implementedin�instructionsslotsusingthefrcinstructionsandissubjecttorestrictionson1.xhardware.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnthefractionalpartofx.

ret frexp(x, out exp)

1.1 �.0 Implementedusingasequenceofexp,logandrcpinstructionsrequiring1�instruc-tionsslotsand�7slotson1.xhardware.

x | in | scalar, vector or matrix | floatexp | out | same as input x | floatret | out | same as input x | float

Separatexintomantissaandexponentcomponents.

Page 15: The Complete HLSL Reference - Attila Project - AttilaWiki

TheCOMPLETEHLSLReference 1�

Name VS PS Performance

Parameters

Description

ret fwidth(x) N/A �.x Seeddxandddyformoreinformation.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Computethepartialderivateofx.Thisfunctiones-sentiallycomputesabs(ddx(x)) + abs(ddy(x)).

ret isfinite(x) 1.1 �.0 Implementedusing�instructionslots.

x | in | scalar, vector or matrix | floatret | out | scalar | bool

Returntrueifxisfinite,falseotherwise.

ret isinf(x) 1.1 �.0 Seeisfinite.

x | in | scalar, vector or matrix | floatret | out | scalar | bool

Returntrueifxisnotfinite,falseotherwise.

ret isnan(x) 1.1 �.0 Seeisfinite.

x | in | scalar, vector or matrix | floatret | out | scalar | bool

ReturntrueifxiseitherNANorQNAN.

ret ldexp(x, exp) 1.1 �.0 Implementedusingexp.

x | in | scalar, vector or matrix | floatexp | in | scalar, vector or matrix | floatret | out | same as input x | float

Performthereverseoperationoffrexpandreturnsx*�exp.

ret length(x) 1.1 �.0 Implementedin�instructionslots.

x | in | vector | floatret | out | scalar | float

Returnthelengthoftheinputvectorx.

ret lerp(x, y, s) 1.1 1.4 Implementedin4instructionslots.

x | in | scalar, vector or matrix | floaty | in | scalar, vector or matrix | floats | in | scalar, vector or matrix | floatret | out | same as input x | same as input x

Linearinterpolationbetweenxandybasedons,interpolationfactorintherange[0,1].

ret lit(n dot l, n dot h, m)

1.1 �.0 Implementedusingthelitinstructionandtakes4instructionslots.

l | in | scalar | floath | in | scalar | floatm | in | scalar | floatret | out | vector | float

Calculatesalightingvectorcontainingtheambient,diffuseandspecularlightingcomponents.

ret log(x) 1.1 �.0 Implementedusingtheloginstructiontak-ing�slotsand41slotson1.xhardware.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnsthebase-elogarithmoftheinputx.

ret log2(x) 1.1 �.0 Implementedusingtheloginstructiontak-ing4slotsand40slotson1.xhardware.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnsthebase-�logarithmoftheinputx.

Page 16: The Complete HLSL Reference - Attila Project - AttilaWiki

16 TheCOMPLETEHLSLReference

Name VS PS Performance

Parameters

Description

ret log10(x) 1.1 �.0 Implementedusingtheloginstructiontak-ing�slotsand41slotson1.xhardware.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnsthebase-10logarithmoftheinputx.

ret max(x, y) 1.1 1.4 N/A

x | in | scalar, vector or matrix | float, inty | in | same as input x | same as input xret | out | same as input x | same as input x

Returnsthemaximumofbothxandy.

ret min(x, y) 1.1 1.4 N/A

x | in | scalar, vector or matrix | float, inty | in | same as input x | same as input xret | out | same as input x | same as input x

Returntheminimumofbothxandy.

ret modf(x, out ip)

1.1 �.0 Implementedusingthefrcusing7instruc-tionslotsand1�on1.1hardware.

x | in | scalar, vector or matrix | float, intip | out | same as input x | same as input xret | out | same as input x | same as input x

Separatesxintoitsfractionalandintegerpart.

ret mul(x, y) 1.1 1.1 Dependantontheinputtypes.

x | in | scalar | float, inty | in | scalar | same as input xret | out | scalar | same as input x

x | in | scalar | float, inty | in | vector | float, intret | out | vector | float, int

x | in | scalar | float, inty | in | matrix | float, intret | out | matrix | float, int

x | in | vector | float, inty | in | scalar | float, intret | out | vector | float, int

x | in | vector | float, inty | in | vector | float, intret | out | scalar | float, int

x | in | vector | float, inty | in | matrix | float, intret | out | vector | float, int

x | in | matrix | float, inty | in | scalar | float, intret | out | matrix | float, int

x | in | matrix | float, inty | in | vector | float, intret | out | vector | float, int

x | in | matrix | float, inty | in | matrix | float, intret | out | matrix | float, int

Performamultiplicationbetweenxandy.

ret noise(x) N/A N/A Onlyoperatesontextureshaders.

x | in | vector | floatret | out | scalar | float

GeneratesPerlinnoisevaluesbasedonx.

Page 17: The Complete HLSL Reference - Attila Project - AttilaWiki

TheCOMPLETEHLSLReference 17

Name VS PS Performance

Parameters

Description

ret normalize(x) 1.1 �.0 Implementedin�instructionslots.

x | in | vector | floatret | out | same as input x | float

Returnsanormalizedversionofx.

ret pow(x, y) 1.1 �.0 Implementedusingexpandlogtaking�slotsand81on1.xhardware.

x | in | scalar, vector or matrix | floaty | in | same as input x | floatret | out | same as input x | float

Returnsxtothepowerofy.

ret radians(x) 1.1 1.1 N/A

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Convertxfromdegreestoradians.

ret reflect(i, n) 1.1 1.1 Implementedin�instructionslots.

i | in | vector | floatn | out | vector | floatret | out | vector | float

Computeareflectionvectorgiventheincidentvectoriandareflectionsurfacenormaln.

ret refract(i, n, ri) 1.1 �.0 Implementedin1�instructionslots.

i | in | vector | floatn | in | vector | floatri | in | scalar | floatret | out | vector | float

Computesarefractedvectorgivenanincidentvectori,asurfacenormalnandarefractionindexri.

ret round(x) 1.1 �.0 Implementedusingfrcinstructionandislimitedon1.xhardware.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Roundstheinputxtoitsnearestinteger.

ret rsqrt(x) 1.1 �.0 N/A

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnsthereciprocalsquarerootofx.

ret saturate(x) 1.1 1.1 Seeclamp.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnstheabsoluteofxclampedtotherange[0,1].

ret sign(x) 1.1 1.4 Implementedin�instructionslots.

x | in | scalar, vector or matrix | float, intret | out | same as input x | int

Returnsthesignofx.

ret sin(x) 1.1 �.0 Taylorseriesusing1�instructionslots.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnsthesineofx.

Page 18: The Complete HLSL Reference - Attila Project - AttilaWiki

18 TheCOMPLETEHLSLReference

Name VS PS Performance

Parameters

Description

ret sincos(x, out s, out c)

1.1 �.0 Taylorseriesusing�4instructionslots.

x | in | scalar, vector or matrix | floats | out | same as input x | floatc | out | same as input x | floatret | out | same as input x | float

Returnsboththesineandcosineofx.

ret sinh(x) 1.1 �.0 Numericalapproximationusingexpusing11instructionslotsor8�on1.xhardware.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnsthehyperbolicsineofx.

ret smoothstep(min, max, x)

1.1 �.0 Implementedusing14instrucitonslots.

x | in | scalar, vector or matrix | floatmin | in | same as input x | floatmax | in | same as input x | floatret | out | same as input x | float

ReturnsasmoothHermiteinterpolationbetween0and1iftheinputxisintherangeof[min,max].

ret sqrt(x) 1.1 �.0 N/A

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnsthesquarerootofx.

ret step(y, x) 1.1 1.4 Implementedusingthesgeinstruction.

x | in | scalar, vector or matrix | floaty | in | same as input x | floatret | out | same as input x | float

Returns(x >= y ) ? 1 : 0.

ret tan(x) 1.1 �.0 Taylorseriesyielding��instructionslotsand��on1.xhardware.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnsthetangentofx.

ret tanh(x) 1.1 �.0 Numericalapproximationwithexpresultingin16slotsand88on1.xshaderhardware.

x | in | scalar, vector or matrix | floatret | out | same as input x | float

Returnsthehyperbolictangentofx.

ret transpose(x) 1.1 1.1 N/A

x | in | matrix | float, int, boolret | out | matrix | float, int, bool

Returnsthetransposeoftheinputmatrixx.

Page 19: The Complete HLSL Reference - Attila Project - AttilaWiki

TheCOMPLETEHLSLReference 1�

HLSL Texture Functions

There are several flavors of texture access functions serv-ing different purposes. However, each of them exists for

several typesof textures.Thevarietyof texture functionwillbepresentedintheform texXX,whereXXcanbeoneof thefollowing:

• 1D:Textureaccesstoa1Dtexture

• �D:Textureaccesstoa�Dtexture.

• �D:Textureaccesstoa�Dtexture.

• CUBE:Textureaccesstoacubemaptexture.

Name PS Performance

Parameters

Description

ret texXX(s, t) 1.1 N/A

s | in | object | samplert | in | vector | floatret | out | vector | float

Performsasimpletexturelookup.

ret texXX(s, t, ddx, ddy) 1.1 N/A

s | in | object | samplert | in | vector | floatddx | in | scalar | floatddy | in | scalar | floatret | out | vector | float

Performs a texture lookup using the derivatesddxandddytopickthepropertexturemipmap.

ret texXXbias(s, t) �.0 N/A

s | in | object | samplert | in | scalar, vector | floatret | out | vector | float

Performsatexturelookupusingthewcompo-nenttobiasmipnapping.

ret texXXlod(s, t) �.0 N/A

s | in | object | samplert | in | scalar, vector | floatret | out | vector | float

Performsatexturelookupusingthewcompo-nenttodeterminethemipmap.

ret texXXgrad(s, t, ddx, ddy)

�.0 Underps_3_x,thetextureaccessmustbedoneoutsideofflowcontrol.

s | in | object | samplert | in | vector | floatddx | in | scalar | floatddy | in | scalar | floatret | out | vector | float

Performs a texture lookup using the derivatesddxandddytopickthepropertexturemipmap.

ret texXXproj(s, t) 1.4 N/A

s | in | object | samplert | in | scalar, vector | floatret | out | vector | float

Performsaprojectivetexturelookup.

Page 20: The Complete HLSL Reference - Attila Project - AttilaWiki

©�00�byParadoxalPress.

All rights reserved. No part of this bookletmay be reproduced or transmitted in anyformorbyanymeans,electronicormechani-cal,includingphotocopying,recording,orbyany information storage or retrieval systemwithout written permission from ParadoxalPress,exceptfortheinclusionofbriefquota-tionsinareview.

The Paradoxal Press logo and related tradedressaretrademarksofParadoxalPressandmaynotbeusedwithoutwrittenpermission.

Frontcoverandbackgroundillustrationcon-tainsscreenshotsofvariousdemoscreatedbyATITechnologiesInc,usedwiththeirpremis-sion.

Author:SebastienSt-LaurentTechnical Review:WolfgangEngelLayout & Design:SebastienSt-LaurentProofreader:NicoleSt-Laurent

PRINTEDINTHEU.S.A.

$7.99 USA / $9.99 CANADA

ParadoxalPress��81AvondaleRd.NERedmond,WA�80��[email protected]

Use

vel

cro

to a

ffix

this

bo

okle

t to

the

side

of

your

mon

itor.