Bug 189125

Summary: [WHLSL] Implement dynamically uniform expression restrictions
Product: WebKit Reporter: Myles C. Maxfield <mmaxfield>
Component: WebGPUAssignee: Myles C. Maxfield <mmaxfield>
Status: RESOLVED MOVED    
Severity: Normal CC: jonlee, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=189122
https://bugs.webkit.org/show_bug.cgi?id=189123
Bug Depends on:    
Bug Blocks: 176199, 189202    
Attachments:
Description Flags
WIP
none
WIP
none
WIP
none
WIP none

Description Myles C. Maxfield 2018-08-29 16:36:49 PDT
Implement dynamically uniform expression restrictions
Comment 1 Radar WebKit Bug Importer 2018-09-12 18:50:51 PDT
<rdar://problem/44403002>
Comment 2 Myles C. Maxfield 2018-09-24 10:37:06 PDT
Ever value (lvalue and rvalue) will be associated with a "uniformity" attribute, which will be assigned by the compiler. These attributes can even survive being assigned to a variable, if the variable is marked as "uniform" in the program source.

Then, after we know whether or not each value is uniform, we can associate each nested scope with a similar uniformity attribute. This is true iff the condition leading to that scope is uniform.

We apply the restriction that any AssignmentExpression inside a non-uniform scope must never assign to a uniform variable that is declared in the non-innermost scope. This should guarantee that all uniform variables are, indeed, uniform.

Then, we can require any IndexExpression that indexes into an array which contains textures to use a uniform index.
Comment 3 Myles C. Maxfield 2018-09-24 11:14:24 PDT
Functions that return uniform variables must only have a single return point
Comment 4 Myles C. Maxfield 2018-09-24 11:18:09 PDT
UAVs can't hold uniform values
Comment 5 Myles C. Maxfield 2018-09-24 11:25:41 PDT
Conditional continues and breaks should contribute to the uniformity of the blocks they target
Comment 6 Myles C. Maxfield 2018-09-24 11:28:16 PDT
(In reply to Myles C. Maxfield from comment #5)
> Conditional continues and breaks should contribute to the uniformity of the
> blocks they target

This isn't quite right - the continue & break can affect just the remainder of the scope.

Also, uniforms should only exist in thread / constant address space.
Comment 7 Myles C. Maxfield 2018-09-24 11:37:48 PDT
(In reply to Myles C. Maxfield from comment #6)
> (In reply to Myles C. Maxfield from comment #5)
> > Conditional continues and breaks should contribute to the uniformity of the
> > blocks they target
> 
> This isn't quite right - the continue & break can affect just the remainder
> of the scope.
> 

and "return"

In general, returns should be modeled as an assignment to a variable that's outside the function scope.
Comment 8 Myles C. Maxfield 2018-09-24 11:41:52 PDT
(In reply to Myles C. Maxfield from comment #3)
> Functions that return uniform variables must only have a single return point

Actually, we can do better - just treat early returns as marking the rest of the scope non-uniform, and treating the return as writing to a value that's outside the scope
Comment 9 Myles C. Maxfield 2018-10-04 19:45:53 PDT
*** Bug 189123 has been marked as a duplicate of this bug. ***
Comment 10 Myles C. Maxfield 2018-10-04 19:47:32 PDT
Created attachment 351650 [details]
WIP
Comment 11 Myles C. Maxfield 2018-10-05 19:35:24 PDT
Created attachment 351711 [details]
WIP
Comment 12 Myles C. Maxfield 2018-10-09 00:07:01 PDT
Created attachment 351866 [details]
WIP
Comment 13 Myles C. Maxfield 2018-10-09 00:25:46 PDT
Created attachment 351868 [details]
WIP
Comment 14 Myles C. Maxfield 2018-10-13 14:48:27 PDT
Migrated to https://github.com/gpuweb/WHLSL/issues/56