forked from red-prig/fpPS4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrUniform.pas
452 lines (399 loc) · 10.1 KB
/
srUniform.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
unit srUniform;
{$mode ObjFPC}{$H+}
interface
uses
sysutils,
spirv,
ginodes,
srNode,
srRefId,
srType,
srTypes,
srLayout,
srVariable,
srCapability,
srDecorate,
srConfig;
type
ntRegUniform=class(TsrNodeVmt)
class function Down (node:PsrNode):Pointer; override;
class Procedure SetWriter (node,w,line:PsrNode); override;
class Procedure ResetWriter (node,w:PsrNode); override;
class Function pwrite_count(node:PsrNode):PDWORD; override;
class function GetPrintName(node:PsrNode):RawByteString; override;
class function GetRef (node:PsrNode):Pointer; override;
end;
ntUniform=class(ntDescriptor)
class Function pwrite_count (node:PsrNode):PDWORD; override;
class function GetStorageName(node:PsrNode):RawByteString; override;
end;
String2=String[2];
PsrRegUniform=^TsrRegUniform;
TsrRegUniform=packed object(TsrNode)
private
fwrite_count:DWORD;
ID:TsrRefId; //post id
//
FWriter:PsrNode;
FVar:PsrVariable;
Procedure SetWriter(t:PsrNode);
public
property pLine:PsrNode read FWriter;
Procedure Init(pVar:PsrVariable); inline;
function GetPrintName:RawByteString;
end;
PsrUniform=^TsrUniform;
TsrUniform=object(TsrDescriptor)
private
pLeft,pRight:PsrUniform;
//----
pLayout:PsrDataLayout;
//
fwrite_count:DWORD;
//
FReg:TsrRegUniform;
function c(n1,n2:PsrUniform):Integer; static;
public
Procedure Init; inline;
function pReg:PsrRegUniform; inline;
function GetStorageName:RawByteString;
function GetTypeChar:String2;
function GetString:RawByteString;
end;
PsrUniformList=^TsrUniformList;
TsrUniformList=object
type
TNodeFetch=specialize TNodeFetch<PsrUniform,TsrUniform>;
var
FEmit:TCustomEmit;
FNTree:TNodeFetch;
procedure Init(Emit:TCustomEmit); inline;
function Fetch(s:PsrDataLayout;t:PsrType):PsrUniform;
Function First:PsrUniform;
Function Next(node:PsrUniform):PsrUniform;
procedure AllocBinding(Var FBinding:Integer);
procedure AllocSourceExtension;
end;
implementation
class function ntRegUniform.Down(node:PsrNode):Pointer;
begin
Result:=PsrRegUniform(node)^.FVar;
end;
class Procedure ntRegUniform.SetWriter(node,w,line:PsrNode);
begin
With PsrRegUniform(node)^ do
begin
SetWriter(w);
end;
end;
class Procedure ntRegUniform.ResetWriter(node,w:PsrNode);
begin
With PsrRegUniform(node)^ do
if (FWriter=w) then
begin
SetWriter(nil);
end;
end;
class Function ntRegUniform.pwrite_count(node:PsrNode):PDWORD;
begin
Result:=@PsrRegUniform(node)^.fwrite_count;
end;
class function ntRegUniform.GetPrintName(node:PsrNode):RawByteString;
begin
Result:=PsrRegUniform(node)^.GetPrintName;
end;
class function ntRegUniform.GetRef(node:PsrNode):Pointer;
begin
Result:=@PsrRegUniform(node)^.ID;
end;
//
class Function ntUniform.pwrite_count(node:PsrNode):PDWORD;
begin
Result:=@PsrUniform(node)^.fwrite_count;
end;
class function ntUniform.GetStorageName(node:PsrNode):RawByteString;
begin
Result:=PsrUniform(node)^.GetStorageName;
end;
//
Procedure TsrRegUniform.Init(pVar:PsrVariable); inline;
begin
fntype:=ntRegUniform;
FVar:=pVar;
end;
Procedure TsrRegUniform.SetWriter(t:PsrNode);
begin
if (FWriter=t) then Exit;
if isUsed then
begin
t^.mark_read (@Self);
FWriter^.mark_unread(@Self);
end;
FWriter:=t;
end;
function TsrRegUniform.GetPrintName:RawByteString;
begin
Result:=FVar^.GetStorageName;
if (Result<>'') then
begin
Result:='r_'+Result;
end else
begin
Assert(ID.Alloc);
Result:='r'+IntToStr(ID.ID);
end;
end;
//
function TsrUniform.c(n1,n2:PsrUniform):Integer;
begin
//first pLayout
Result:=Integer(n1^.pLayout>n2^.pLayout)-Integer(n1^.pLayout<n2^.pLayout);
if (Result<>0) then Exit;
//second pType
Result:=Integer(n1^.FType>n2^.FType)-Integer(n1^.FType<n2^.FType);
end;
Procedure TsrUniform.Init; inline;
begin
fntype :=ntUniform;
FStorage:=StorageClass.UniformConstant;
FBinding:=-1;
end;
function TsrUniform.pReg:PsrRegUniform; inline;
begin
Result:=@FReg;
end;
function TsrUniform.GetStorageName:RawByteString;
var
image_info:TsrTypeImageInfo;
begin
Result:='';
if (FType<>nil) then
Case FType^.dtype of
dtTypeImage:
begin
image_info:=FType^.image_info;
if (image_info.Dim=Dim.Buffer) then
begin
Case image_info.Sampled of
1:Result:='uTex'+IntToStr(FBinding);
2:Result:='sTex'+IntToStr(FBinding);
else Result:='rTex'+IntToStr(FBinding);
end;
end else
begin
Case image_info.Sampled of
1:Result:='uImg'+IntToStr(FBinding);
2:Result:='sImg'+IntToStr(FBinding);
else Result:='rImg'+IntToStr(FBinding);
end;
end;
end;
dtTypeSampler:Result:='uSmp'+IntToStr(FBinding);
else;
end;
end;
function TsrUniform.GetTypeChar:String2;
var
image_info:TsrTypeImageInfo;
begin
Result:='';
if (FType<>nil) then
Case FType^.dtype of
dtTypeImage:
begin
image_info:=FType^.image_info;
if (image_info.Dim=Dim.Buffer) then
begin
Case image_info.Sampled of
1:Result:='UB'; //VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
2:Result:='SB'; //VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
else Result:='RB'; //runtime texel buffer
end;
end else
begin
Case image_info.Sampled of
1:Result:='UI'; //VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
2:Result:='SI'; //VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
else Result:='RI'; //runtime image
end;
end;
end;
dtTypeSampler:Result:='US'; //VK_DESCRIPTOR_TYPE_SAMPLER
else;
end;
end;
function TsrUniform.GetString:RawByteString;
var
PID:DWORD;
begin
PID:=0;
if (pLayout<>nil) then
begin
PID:=pLayout^.FID;
end;
Result:=GetTypeChar+
';PID='+HexStr(PID,8)+
';BND='+HexStr(FBinding,8);
end;
procedure TsrUniformList.Init(Emit:TCustomEmit); inline;
begin
FEmit:=Emit;
end;
function TsrUniformList.Fetch(s:PsrDataLayout;t:PsrType):PsrUniform;
var
node:TsrUniform;
begin
node:=Default(TsrUniform);
node.Init;
node.pLayout:=s;
node.FType :=t;
Result:=FNTree.Find(@node);
if (Result=nil) then
begin
Result:=FEmit.Alloc(SizeOf(TsrUniform));
Move(node,Result^,SizeOf(TsrUniform));
//
Result^.InitVar(FEmit);
Result^.FReg.Init(Result^.FVar);
//
FNTree.Insert(Result);
end;
end;
Function TsrUniformList.First:PsrUniform;
begin
Result:=FNTree.Min;
end;
Function TsrUniformList.Next(node:PsrUniform):PsrUniform;
begin
Result:=FNTree.Next(node);
end;
procedure TsrUniformList.AllocBinding(Var FBinding:Integer);
var
pConfig:PsrConfig;
pDecorateList:PsrDecorateList;
pCapabilityList:PsrCapabilityList;
//
node:PsrUniform;
pVar:PsrVariable;
//
FType:PsrType;
image_info:TsrTypeImageInfo;
begin
pConfig :=FEmit.GetConfig;
pDecorateList :=FEmit.GetDecorateList;
pCapabilityList:=FEmit.GetCapabilityList;
node:=First;
While (node<>nil) do
begin
pVar:=node^.pVar;
if (pVar<>nil) and node^.IsUsed and (node^.FBinding=-1) then
begin
pDecorateList^.OpDecorate(pVar,Decoration.Binding,FBinding);
pDecorateList^.OpDecorate(pVar,Decoration.DescriptorSet,pConfig^.DescriptorSet);
node^.FBinding:=FBinding;
Inc(FBinding);
FType:=node^.pType;
if (FType<>nil) then
begin
Case FType^.dtype of
dtTypeImage:
begin
image_info:=FType^.image_info;
if (image_info.Sampled=2) then //storage image
begin
if (node^.FReg.read_count=0) then
begin
pDecorateList^.OpDecorate(pVar,Decoration.NonReadable,0);
end;
if (node^.FReg.write_count=0) then
begin
pDecorateList^.OpDecorate(pVar,Decoration.NonWritable,0);
end;
end;
Case image_info.Dim of
Dim.Dim1D:
Case image_info.Sampled of
1:pCapabilityList^.Add(Capability.Sampled1D); //sampling
2:pCapabilityList^.Add(Capability.Image1D); //read/write
else;
end;
Dim.Buffer:
Case image_info.Sampled of
1:pCapabilityList^.Add(Capability.SampledBuffer); //sampling
2:pCapabilityList^.Add(Capability.ImageBuffer); //read/write
else;
end;
else;
end;
if (image_info.Sampled=2) and
(image_info.Arrayed=1) then
begin
pCapabilityList^.Add(Capability.ImageMSArray);
end;
Case image_info.Format of
ImageFormat.Unknown:
begin
if (node^.FReg.read_count<>0) then
begin
pCapabilityList^.Add(Capability.StorageImageWriteWithoutFormat);
end;
if (node^.FReg.write_count<>0) then
begin
pCapabilityList^.Add(Capability.StorageImageWriteWithoutFormat);
end;
end;
ImageFormat.Rg32f ,
ImageFormat.Rg16f ,
ImageFormat.R11fG11fB10f,
ImageFormat.R16f ,
ImageFormat.Rgba16 ,
ImageFormat.Rgb10A2 ,
ImageFormat.Rg16 ,
ImageFormat.Rg8 ,
ImageFormat.R16 ,
ImageFormat.R8 ,
ImageFormat.Rgba16Snorm ,
ImageFormat.Rg16Snorm ,
ImageFormat.Rg8Snorm ,
ImageFormat.R16Snorm ,
ImageFormat.R8Snorm ,
ImageFormat.Rg32i ,
ImageFormat.Rg16i ,
ImageFormat.Rg8i ,
ImageFormat.R16i ,
ImageFormat.R8i ,
ImageFormat.Rgb10a2ui ,
ImageFormat.Rg32ui ,
ImageFormat.Rg16ui ,
ImageFormat.Rg8ui ,
ImageFormat.R16ui ,
ImageFormat.R8ui :pCapabilityList^.Add(Capability.StorageImageExtendedFormats);
else;
end;
end;
else;
end;
end;
end;
node:=Next(node);
end;
end;
procedure TsrUniformList.AllocSourceExtension;
var
pDebugInfoList:PsrDebugInfoList;
node:PsrUniform;
pVar:PsrVariable;
begin
pDebugInfoList:=FEmit.GetDebugInfoList;
node:=First;
While (node<>nil) do
begin
pVar:=node^.pVar;
if (pVar<>nil) and node^.IsUsed then
begin
pDebugInfoList^.OpSource(node^.GetString);
end;
node:=Next(node);
end;
end;
end.