Skip to content

Commit 217a3cf

Browse files
committed
Support [unroll] before for loops.
1 parent e60032d commit 217a3cf

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

Applications/Sfx/Sfx.lpp

+1
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ FLOAT_BLCK [0-9]*((\.[0-9])|([0-9]\.))[0-9]*([eE][+-]?[0-9]+)?f?
806806
<IN_SHADER>"continue" stdReturn(CONTINUE);
807807
<IN_SHADER>"do" stdReturn(DO);
808808
<IN_SHADER>"for" stdReturn(FOR);
809+
<IN_SHADER>"unroll" stdReturn(UNROLL);
809810
<IN_SHADER>"goto" stdReturn(GOTO);
810811
<IN_SHADER>"if" stdReturn(IF);
811812
<IN_SHADER>"switch" stdReturn(SWITCH);

Applications/Sfx/Sfx.ypp

+33-8
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,17 @@
9191
{
9292
write_line_number_next=true;
9393
}
94-
void WriteLineNumber(std::ostringstream &str,const std::string &filename,int lineno)
94+
bool WriteLineNumber(std::ostringstream &str,const std::string &filename,int lineno)
9595
{
96-
if(!lineno)
97-
return;
96+
if(lineno==0)
97+
{
98+
return true;
99+
}
100+
if(lineno<0)
101+
{
102+
std::cerr<<"line: "<<lineno<<" not valid for #line directive.\n";
103+
return false;
104+
}
98105
std::string f=filename;
99106
size_t p=f.find("\\");
100107
while(p<f.length())
@@ -105,16 +112,20 @@
105112
if (gEffect->GetOptions()->disableLineWrites)
106113
str<<"//";
107114
str<<"#line "<<lineno<<" "<<gEffect->GetFilenameOrNumber(f)<<endl;
115+
return true;
108116
}
109-
void WriteLineNumber(std::ostringstream &str,int lineno)
117+
bool WriteLineNumber(std::ostringstream &str,int lineno)
110118
{
111-
WriteLineNumber(str,current_filename,lineno);//.c_str()<<"\""<<endl;
119+
return WriteLineNumber(str,current_filename,lineno);//.c_str()<<"\""<<endl;
112120
}
113121
std::string CreateLineStatement(int lineno)
114122
{
115123
ostringstream ostr;
116124
ostr<<"\n";
117-
WriteLineNumber(ostr,current_filename,lineno+last_linenumber-global_linenumber);
125+
if(!WriteLineNumber(ostr,current_filename,lineno+last_linenumber-global_linenumber))
126+
{
127+
std::cerr<<"lineno: "<<lineno<<" last_linenumber: "<<last_linenumber<<", global_linenumber: "<<global_linenumber<<".\n";
128+
}
118129
return ostr.str();
119130
}
120131
void stringReplaceAll(std::string& str, const std::string& from, const std::string& to)
@@ -616,6 +627,7 @@
616627
%token SET_RAY_GENERATION SET_MISS SET_CALLABLE SET_HIT_GROUP SET_CLOSEST_HIT SET_ANY_HIT SET_INTERSECTION SET_MISS_SHADERS SET_CALLABLE_SHADERS SET_RAY_TRACING_SHADER_CONFIG SET_RAY_TRACING_PIPELINE_CONFIG SET_MAX_PAYLOAD_SIZE SET_MAX_ATTRIBUTE_SIZE SET_MAX_TRACE_RECURSION_DEPTH
617628
%token SFX_VARIANT SFX_VARIANT_IF SFX_VARIANT_ELSE SFX_VARIANT_END
618629

630+
%token UNROLL
619631
%%
620632

621633
prog : prog tok
@@ -1056,6 +1068,13 @@ gslayout : '[' MAX_VERTEX_COUNT '(' NUM ')' ']'
10561068
$$.strs[0]=$1.strs[0]+$2.strs[0]+$3.strs[0]+$4.strs[0]+$5.strs[0]+$6.strs[0];
10571069
}
10581070

1071+
optional_unroll : '[' UNROLL ']'
1072+
{
1073+
$$.strs[0]=$1.strs[0]+$2.strs[0]+$3.strs[0]+" ";
1074+
} | %empty
1075+
{
1076+
$$.strs[0] = "";
1077+
}
10591078
optional_expression : expression
10601079
{
10611080
$$.strs[0]=$1.strs[0];
@@ -2598,7 +2617,7 @@ statement : COMMENT
25982617
$$.strs[0]=$1.strs[0]+$2.strs[0]+$3.strs[0]+$4.strs[0]+$5.strs[0]+$6.strs[0]+$7.strs[0];
25992618
$$.strs[1]="";
26002619
}
2601-
| FOR '(' for_init_statement ';' optional_expression ';' optional_expression ')' statement
2620+
| for '(' for_init_statement ';' optional_expression ';' optional_expression ')' statement
26022621
{
26032622
string statement=$9.strs[0];
26042623
$$.strs[0]=$1.strs[0]+$2.strs[0]+$3.strs[0]+$4.strs[0]+$5.strs[0]+$6.strs[0]+$7.strs[0]+$8.strs[0]+statement;
@@ -2644,7 +2663,13 @@ statement : COMMENT
26442663
$$.strs[1]="";
26452664
$$.lineno=$1.lineno;
26462665
}
2647-
2666+
for: optional_unroll FOR
2667+
{
2668+
int line=$2.lineno;
2669+
$$.lineno=line;
2670+
$$.strs[0] = $1.strs[0] + $2.strs[0] ;
2671+
$$.strs[1] = "";
2672+
}
26482673
variant_conditional_expression: SFX_VARIANT_IF '(' conditional_exp ')'
26492674
{
26502675
// TODO: Properly change the identifiers, instead of this hack.

Vulkan/Sfx/Vulkan.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"pixelOutputDeclaration": "[layout(location = {slot}) out {type} {name};]",
5858
"pixelOutputDeclarationDSB": "[layout(location = {slot}, index = {id}) out {type} {name};]",
5959
"compilerMessageRegex": [ "(ERROR|WARNING):[\\S]*(.*):[\\S]*([0-9]+)[\\S]*:[ ]*(.*)", "$2($3): $1: $4" ],
60-
"preamble": "#version 450\n#extension GL_EXT_debug_printf : enable\n#extension GL_GOOGLE_cpp_style_line_directive : enable\n#extension GL_EXT_samplerless_texture_functions : enable\n#extension GL_EXT_shader_io_blocks : enable\n#extension GL_ARB_enhanced_layouts : enable\n#extension GL_EXT_multiview : enable\n#extension GL_EXT_shader_explicit_arithmetic_types_float16 : enable\n#extension GL_EXT_shader_explicit_arithmetic_types_int16 : enable\n",
60+
"preamble": "#version 450\n#extension GL_EXT_debug_printf : enable\n#extension GL_GOOGLE_cpp_style_line_directive : enable\n#extension GL_EXT_samplerless_texture_functions : enable\n#extension GL_EXT_shader_io_blocks : enable\n#extension GL_ARB_enhanced_layouts : enable\n#extension GL_EXT_multiview : enable\n#extension GL_EXT_shader_explicit_arithmetic_types_float16 : enable\n#extension GL_EXT_shader_explicit_arithmetic_types_int16 : enable\n#extension GL_EXT_control_flow_attributes: enable\n",
6161
"computePreamble": "#extension GL_KHR_shader_subgroup_quad : enable\n#extension GL_KHR_shader_subgroup_shuffle: enable\n#extension GL_KHR_shader_subgroup_vote : enable\n#extension GL_KHR_shader_subgroup_ballot : enable\n#extension GL_KHR_shader_subgroup_arithmetic : enable\n#extension GL_KHR_shader_subgroup_basic : enable\n#extension GL_ARB_gpu_shader_int64 : enable\n#extension GL_ARB_compute_shader : enable\n#extension GL_ARB_shader_image_load_store : enable\n#extension GL_ARB_gpu_shader_int64 : enable\n",
6262
"vertexSemantics": {
6363
"SV_VertexId": "gl_VertexIndex",
@@ -274,6 +274,7 @@
274274
"._m33": "[3][3]",
275275
"round": "roundEven",
276276
"roundNearest": "round",
277-
"firstbitlow": "findLSB"
277+
"firstbitlow": "findLSB",
278+
"unroll": "[unroll]"
278279
}
279280
}

0 commit comments

Comments
 (0)