3 using System.Collections.Generic;
4 using SiliconStudio.Shaders.Ast;
5 using SiliconStudio.Shaders.Ast.Hlsl;
7 namespace SiliconStudio.Shaders.Writer.Hlsl
14 #region Constructors and Destructors
22 public HlslWriter(
bool useNodeStack =
false) : base(useNodeStack)
28 #region Public Methods
37 if (annotations.
Variables.Count == 0)
return;
39 Write(
"<").WriteSpace();
41 foreach (var variable
in annotations.Variables)
43 VisitDynamic(variable);
46 WriteSpace().Write(
">");
58 Write(
"class").Write(
" ").Write(classType.
Name);
63 for (
int i = 0; i < classType.GenericParameters.Count; i++)
65 var genericArgument = classType.GenericParameters[i];
66 if (i > 0) Write(
", ");
67 Write(genericArgument.Name);
74 WriteSpace().Write(
":").WriteSpace();
75 for (
int i = 0; i < classType.BaseClasses.Count; i++)
77 var baseClass = classType.BaseClasses[i];
80 Write(
",").WriteSpace();
83 Write(baseClass.Name);
95 VisitDynamicList(classType.
Members);
97 CloseBrace(
false).Write(
";").WriteLine();
108 Write(
"interface").Write(
" ").Write(interfaceType.
Name);
111 VisitDynamicList(interfaceType.
Methods);
112 CloseBrace(
false).Write(
";").WriteLine();
125 Write(asmExpression.
Text);
138 Write(constantBuffer.
Type.
Key.ToString());
140 if (constantBuffer.
Name != null)
142 Write(
" ").Write(constantBuffer.Name);
146 VisitDynamic(constantBuffer.
Register);
148 VisitDynamicList(constantBuffer.
Members);
149 CloseBrace(
false).Write(
";").WriteLine();
159 Write(
"typedef").Write(
" ");
160 Write(
typedef.Qualifiers,
true);
161 VisitDynamic(
typedef.Type);
166 for (
int i = 0; i < typedef.SubDeclarators.Count; i++)
168 var declarator = typedef.SubDeclarators[i];
171 Write(
",").WriteSpace();
174 Write(declarator.Name);
193 Write(
"[").Write(attributeDeclaration.Name);
194 if (attributeDeclaration.
Parameters.Count > 0)
197 for (
int i = 0; i < attributeDeclaration.Parameters.Count; i++)
199 var parameter = attributeDeclaration.Parameters[i];
202 Write(
",").WriteSpace();
205 VisitDynamic(parameter);
222 VisitDynamic(castExpression.
Target);
224 VisitDynamic(castExpression.
From);
256 Write(
"compile").Write(
" ");
257 Write(compileExpression.
Profile);
259 VisitDynamic(compileExpression.
Function);
270 Write(technique.
Type);
271 if (technique.
Name != null)
273 Write(
" ").Write(technique.Name);
279 VisitDynamicList(technique.
Passes);
292 if (pass.
Name != null)
294 Write(
" ").Write(pass.Name);
300 foreach (var expression
in pass.Items)
302 VisitDynamic(expression);
314 for (
int i = 0; i < stateInitializer.Items.Count; i++)
316 var item = stateInitializer.Items[i];
336 if (expression == null)
return;
339 WriteSpace().Write(
"=");
341 VisitDynamic(expression);
348 Write(
":").WriteSpace();
349 Write(semantic.
Name);
356 Write(
":").WriteSpace();
357 Write(
"packoffset(");
366 Write(
":").WriteSpace();
368 if (registerLocation.
Profile != null)
370 Write(registerLocation.
Profile);
371 Write(
",").WriteSpace();
389 Write(identifier.
Text);
398 var compositeIdentifier = (CompositeIdentifier)identifier;
399 for (
int i = 0; i < compositeIdentifier.Identifiers.Count; i++)
401 var subIdentifier = compositeIdentifier.Identifiers[i];
402 if (i > 0) Write(compositeIdentifier.Separator);
403 Write(subIdentifier);
409 WriteRankSpecifiers(identifier.
Indices);
virtual void Visit(Technique technique)
Visits the specified technique.
virtual void Visit(Semantic semantic)
object Key
Gets or sets the key.
virtual void Visit(Pass pass)
Visits the specified pass.
bool IsSpecialReference
Gets or sets a value indicating whether this instance is a special reference using < > ...
RegisterLocation Register
Gets or sets the register.
virtual void Visit(Annotations annotations)
Visits the specified Annotations.
string Text
Gets or sets the asm expression in raw text form.
List< AttributeBase > Attributes
Gets or sets the attributes.
string Text
Gets or sets the name.
override ShaderWriter Write(Identifier identifier)
Writes the specified identifier.
HlslWriter(bool useNodeStack=false)
Initializes a new instance of the HlslWriter class.
A state expresion in the form: sampler {...}.
List< AttributeBase > Attributes
Gets or sets the attributes.
List< Literal > Parameters
Gets or sets the parameters.
Identifier Name
Gets or sets the name of this declaration
virtual void Visit(StateInitializer stateInitializer)
virtual void Visit(Typedef typedef)
Visits the specified typedef.
Identifier Name
Gets or sets the name.
List< MethodDeclaration > Methods
Gets or sets the methods.
List< Pass > Passes
Gets or sets the passes.
TypeBase StateType
Gets or sets the type of the sampler.
Identifier Name
Gets or sets the name.
List< TypeBase > GenericParameters
override void WriteInitializer(Expression expression)
Writes the initializer. The expression.
virtual void Visit(InterfaceType interfaceType)
Visits the specified interface type.
List< AttributeBase > Attributes
Gets or sets the attributes.
Identifier Name
Gets or sets the name.
Describes a packoffset(value).
virtual void Visit(PackOffset packOffset)
Identifier Profile
Gets or sets the profile.
Identifier Profile
Gets or sets the profile.
List< Node > Members
Gets or sets the members.
ConstantBufferType Type
Gets or sets a value indicating whether this instance is texture buffer.
Identifier Type
Gets or sets the type.
StateInitializer Initializer
Gets or sets the initializer.
Expression From
Gets or sets from.
Declaration of a constant buffer.
List< Node > Members
Gets or sets the members.
Describe a register location
List< Variable > Variables
Gets or sets the variable.
List< AttributeBase > Attributes
Gets or sets the attributes.
virtual void Visit(CompileExpression compileExpression)
Visits the specified compile expression.
Identifier Name
Gets or sets the name.
List< Expression > Indices
Gets or sets the indices.
virtual void Visit(ClassType classType)
Visits the specified class type.
Identifier Value
Gets or sets the value.
bool HasIndices
Gets a value indicating whether this instance has indices.
virtual void Visit(AsmExpression asmExpression)
Visits the specified asm expression.
virtual void Visit(CastExpression castExpression)
Visits the specified cast expression.
virtual void Visit(CompositeIdentifier compositeIdentifier)
Visits the specified composite identifier.
virtual void Visit(AttributeDeclaration attributeDeclaration)
Visits the specified attribute declaration.
TypeBase Target
Gets or sets the target.
virtual void Visit(RegisterLocation registerLocation)
virtual void Visit(StateExpression stateExpression)
Visits the specified state expression.
virtual void Visit(ConstantBuffer constantBuffer)
Visits the specified constant buffer.
Expression Function
Gets or sets the function.
List< TypeName > BaseClasses
Gets or sets the base classes.
Identifier Register
Gets or sets the register.