Skip to content

Commit 011668b

Browse files
committed
Implement .setf/.seti/.setb with documentation
1 parent fd8532c commit 011668b

4 files changed

Lines changed: 131 additions & 7 deletions

File tree

Manual.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,23 @@ Some source operands of instructions (called SRC1) support relative addressing.
5555

5656
Normal floating-point vector registers may also be negated by prepending a minus sign before it, e.g. `-r2` or `-someArray[lcnt+2]`.
5757

58+
## Command Line Usage
59+
60+
```
61+
Usage: picasso [options] files...
62+
Options:
63+
-o, --out=<file> Specifies the name of the SHBIN file to generate
64+
-h, --header=<file> Specifies the name of the header file to generate
65+
```
66+
5867
## Linking Model
5968

6069
`picasso` takes one or more source code files, and assembles them into a single `.shbin` file. A DVLE object is generated for each source code file, unless the `.nodvle` directive is used (see below). Procedures are shared amongst all source code files, and they may be defined and called wherever. Uniform space is also shared, that is, if two source code files declare the same uniform, they are assigned the same location. Constants however are not shared, and the same space is reused for the constants of each DVLE. Outputs and aliases are necessarily not shared either.
6170

6271
The entry point of a DVLE may be set with the `.entry` directive. If this directive is not used, `main` is assumed as the entrypoint.
6372

73+
Uniforms that start with the underscore (`_`) character are not exposed in the DVLE table of uniforms. This allows for creating private uniforms that can be internally used to configure the behaviour of shared procedures.
74+
6475
## Supported Directives
6576

6677
### .proc
@@ -173,6 +184,24 @@ Specifies the name of the procedure to use as the entrypoint of the current DVLE
173184
```
174185
This directive tells `picasso` not to generate a DVLE for the source code file that is being processed. This allows for writing files that contain shared procedures to be used by other files.
175186

187+
### .setf
188+
```
189+
.setf register(x, y, z, w)
190+
```
191+
Similar to `.constf`, this directive adds a DVLE constant entry for the specified floating-point vector uniform register to be loaded with the specified value. This is useful in order to instantiate a generalized shared procedure with the specified parameters.
192+
193+
### .seti
194+
```
195+
.seti register(x, y, z, w)
196+
```
197+
Similar to `.consti`, this directive adds a DVLE constant entry for the specified integer vector uniform register to be loaded with the specified value. This is useful in order to instantiate a generalized shared procedure with the specified parameters.
198+
199+
### .setb
200+
```
201+
.setb register value
202+
```
203+
This directive adds a DVLE constant entry for the specified boolean uniform register to be loaded with the specified value (which may be `true`, `false`, `on`, `off`, `1` or `0`). This is useful in order to control the flow of a generalized shared procedure.
204+
176205
## Supported Instructions
177206

178207
See [Shader Instruction Set](http://3dbrew.org/wiki/Shader_Instruction_Set) for more details.
@@ -221,7 +250,7 @@ Syntax | Description
221250
- In instructions that take one source operand, it is always wide.
222251
- In instructions that take two source operands, the first is wide and the second is narrow.
223252
- `dph`/`sge`/`slt` have a special form where the first operand is narrow and the second is wide. This usage is detected automatically by `picasso`.
224-
- `mad`, which takes three source operands, has two forms: the first is wide-wide-narrow, and the second is wide-narrow-wide. This is also detected automatically.
253+
- `mad`, which takes three source operands, has two forms: the first is wide-wide-narrow, and the second is wide-narrow-wide. This is also detected automatically. Additionally, relative addressing is not supported.
225254
- `iReg`: Represents an integer vector uniform source operand.
226255
- `bReg`: Represents a boolean uniform source operand.
227256
- `procName`: Represents the name of a procedure.

source/picasso.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ struct Constant
171171
{
172172
float fparam[4];
173173
u8 iparam[4];
174+
bool bparam;
174175
};
175176
};
176177

@@ -191,7 +192,6 @@ struct DVLEData
191192
#define MAX_CONSTANT 0x60
192193
Constant constantTable[MAX_CONSTANT];
193194
int constantCount;
194-
size_t constantSize;
195195

196196
// Outputs
197197
#define MAX_OUTPUT 8
@@ -201,5 +201,5 @@ struct DVLEData
201201
DVLEData(const char* filename) :
202202
filename(filename), entrypoint("main"),
203203
nodvle(false), isGeoShader(false),
204-
uniformCount(0), symbolSize(0), constantCount(0), constantSize(0), outputCount(0) { }
204+
uniformCount(0), symbolSize(0), constantCount(0), outputCount(0) { }
205205
};

source/picasso_assembler.cpp

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,14 +1361,12 @@ DEF_DIRECTIVE(const)
13611361
ct.fparam[1] = atof(arg1Text);
13621362
ct.fparam[2] = atof(arg2Text);
13631363
ct.fparam[3] = atof(arg3Text);
1364-
dvle->constantSize += 4 + 4*4;
13651364
} else if (dirParam == UTYPE_IVEC)
13661365
{
13671366
ct.iparam[0] = atoi(arg0Text) & 0xFF;
13681367
ct.iparam[1] = atoi(arg1Text) & 0xFF;
13691368
ct.iparam[2] = atoi(arg2Text) & 0xFF;
13701369
ct.iparam[3] = atoi(arg3Text) & 0xFF;
1371-
dvle->constantSize += 4 + 4;
13721370
}
13731371

13741372
g_aliases.insert( std::pair<std::string,int>(constName, ct.regId | (DEFAULT_OPSRC<<8)) );
@@ -1382,6 +1380,93 @@ DEF_DIRECTIVE(const)
13821380
return 0;
13831381
};
13841382

1383+
DEF_DIRECTIVE(setfi)
1384+
{
1385+
DVLEData* dvle = GetDvleData();
1386+
1387+
NEXT_ARG_CPAREN(constName);
1388+
NEXT_ARG(arg0Text);
1389+
NEXT_ARG(arg1Text);
1390+
NEXT_ARG(arg2Text);
1391+
char* arg3Text = mystrtok_pos;
1392+
if (!mystrtok_pos) return missingParam();
1393+
char* parenPos = strchr(arg3Text, ')');
1394+
if (!parenPos) return throwError("invalid syntax\n");
1395+
*parenPos = 0;
1396+
arg3Text = trim_whitespace(arg3Text);
1397+
1398+
ARG_TO_REG(constReg, constName);
1399+
if (dirParam == UTYPE_FVEC)
1400+
{
1401+
if (constReg < 0x20 || constReg >= 0x80)
1402+
return throwError("invalid floating point vector uniform: %s\n", constName);
1403+
} else if (dirParam == UTYPE_IVEC)
1404+
{
1405+
if (constReg < 0x80 || constReg >= 0x84)
1406+
return throwError("invalid integer vector uniform: %s\n", constName);
1407+
}
1408+
1409+
if (dvle->constantCount == MAX_CONSTANT)
1410+
return throwError("too many local constants\n");
1411+
1412+
Constant& ct = dvle->constantTable[dvle->constantCount++];
1413+
ct.regId = constReg;
1414+
ct.type = dirParam;
1415+
if (dirParam == UTYPE_FVEC)
1416+
{
1417+
ct.fparam[0] = atof(arg0Text);
1418+
ct.fparam[1] = atof(arg1Text);
1419+
ct.fparam[2] = atof(arg2Text);
1420+
ct.fparam[3] = atof(arg3Text);
1421+
} else if (dirParam == UTYPE_IVEC)
1422+
{
1423+
ct.iparam[0] = atoi(arg0Text) & 0xFF;
1424+
ct.iparam[1] = atoi(arg1Text) & 0xFF;
1425+
ct.iparam[2] = atoi(arg2Text) & 0xFF;
1426+
ct.iparam[3] = atoi(arg3Text) & 0xFF;
1427+
}
1428+
1429+
return 0;
1430+
}
1431+
1432+
int parseBool(bool& out, const char* text)
1433+
{
1434+
if (stricmp(text, "true")==0 || stricmp(text, "on")==0 || stricmp(text, "1")==0)
1435+
{
1436+
out = true;
1437+
return 0;
1438+
}
1439+
if (stricmp(text, "false")==0 || stricmp(text, "off")==0 || stricmp(text, "0")==0)
1440+
{
1441+
out = false;
1442+
return 0;
1443+
}
1444+
return throwError("invalid bool value: %s\n", text);
1445+
}
1446+
1447+
DEF_DIRECTIVE(setb)
1448+
{
1449+
DVLEData* dvle = GetDvleData();
1450+
1451+
NEXT_ARG_SPC(constName);
1452+
NEXT_ARG_SPC(valueText);
1453+
ENSURE_NO_MORE_ARGS();
1454+
ARG_TO_BREG(constReg, constName);
1455+
1456+
bool constVal = false;
1457+
safe_call(parseBool(constVal, valueText));
1458+
1459+
if (dvle->constantCount == MAX_CONSTANT)
1460+
return throwError("too many local constants\n");
1461+
1462+
Constant& ct = dvle->constantTable[dvle->constantCount++];
1463+
ct.regId = constReg;
1464+
ct.type = UTYPE_BOOL;
1465+
ct.bparam = constVal;
1466+
1467+
return 0;
1468+
}
1469+
13851470
static int parseOutType(const char* text)
13861471
{
13871472
if (stricmp(text,"pos")==0 || stricmp(text,"position")==0)
@@ -1487,6 +1572,9 @@ static const cmdTableType dirTable[] =
14871572
DEC_DIRECTIVE(out),
14881573
DEC_DIRECTIVE(entry),
14891574
DEC_DIRECTIVE(nodvle),
1575+
DEC_DIRECTIVE2(setf, setfi, UTYPE_FVEC),
1576+
DEC_DIRECTIVE2(seti, setfi, UTYPE_IVEC),
1577+
DEC_DIRECTIVE(setb),
14901578
{ NULL, NULL },
14911579
};
14921580

source/picasso_frontend.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ int main(int argc, char* argv[])
129129
if (dvle->nodvle) continue;
130130
f.WriteWord(curOff);
131131
curOff += 16*4; // Header
132-
curOff += dvle->constantSize;
132+
curOff += dvle->constantCount*20;
133133
curOff += dvle->outputCount*8;
134134
curOff += dvle->uniformCount*8;
135135
curOff += dvle->symbolSize;
@@ -171,7 +171,7 @@ int main(int argc, char* argv[])
171171
f.WriteWord(0); // ???
172172
f.WriteWord(curOff); // offset to constant table
173173
f.WriteWord(dvle->constantCount); // size of constant table
174-
curOff += dvle->constantSize;
174+
curOff += dvle->constantCount*5*4;
175175
f.WriteWord(curOff); // offset to label table (TODO)
176176
f.WriteWord(0); // size of label table (TODO)
177177
f.WriteWord(curOff); // offset to output table
@@ -199,7 +199,14 @@ int main(int argc, char* argv[])
199199
f.WriteHword(ct.regId-0x80);
200200
for (int j = 0; j < 4; j ++)
201201
f.WriteByte(ct.iparam[j]);
202+
} else if (ct.type == UTYPE_BOOL)
203+
{
204+
f.WriteHword(ct.regId-0x88);
205+
f.WriteWord(ct.bparam ? 1 : 0);
202206
}
207+
if (ct.type != UTYPE_FVEC)
208+
for (int j = 0; j < 3; j ++)
209+
f.WriteWord(0); // Padding
203210
}
204211

205212
// Write outputs

0 commit comments

Comments
 (0)