xref: /aosp_15_r20/external/skia/resources/sksl/errors/ReadonlyWriteonly.compute (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1layout(binding=0, rgba32f) readonly texture2D src;
2layout(binding=1, rgba32f) writeonly texture2D dest;
3//layout(binding=2, rgba32f) texture2D multipurpose;
4
5// If we add support for read-write textures in SkSL, uncomment `needs_all_access`.
6//void needs_all_access(texture2D t) {}
7
8void overload(layout(rgba32f) readonly texture2D t)       {}
9void overload(layout(rgba32f) writeonly texture2D t, int) {}
10
11void main() {
12    //needs_all_access(src);                          // BAD
13    //needs_all_access(dest);                         // BAD
14    //needs_all_access(multipurpose);                 // OK
15
16    textureRead(dest, sk_GlobalInvocationID.xy);           // BAD
17    textureWrite(src, sk_GlobalInvocationID.xy, half4(1)); // BAD
18
19    overload(src);     //  OK: overload(readonly texture2D t)      exists
20    overload(src, 1);  // BAD: overload(readonly texture2D t, int) missing
21    overload(dest);    // BAD: overload(writeonly texture2D t)      missing
22    overload(dest, 1); //  OK: overload(writeonly texture2D t, int) exists
23}
24
25// If we add support for read-write textures in SkSL, uncomment `function_param_honors_all_access`.
26//void function_param_honors_all_access(texture2D t) {
27//    //needs_all_access(t);                               // OK
28//    textureWidth(t);                                     // OK
29//    textureRead(t, sk_GlobalInvocationID.xy);            // OK
30//    textureWrite(t, sk_GlobalInvocationID.xy, half4(1)); // OK
31//}
32
33void function_param_honors_readonly(layout(rgba32f) readonly texture2D t) {
34    //needs_all_access(t);                               // BAD
35    textureWidth(t);                                     // OK
36    textureRead(t, sk_GlobalInvocationID.xy);            // OK
37    textureWrite(t, sk_GlobalInvocationID.xy, half4(1)); // BAD
38}
39
40void function_param_honors_writeonly(layout(rgba32f) writeonly texture2D t) {
41    //needs_all_access(t);                               // BAD
42    textureWidth(t);                                     // OK
43    textureRead(t, sk_GlobalInvocationID.xy);            // BAD
44    textureWrite(t, sk_GlobalInvocationID.xy, half4(1)); // OK
45}
46
47/*%%*
48no match for textureRead(writeonlyTexture2D, uint2)
49no match for textureWrite(readonlyTexture2D, uint2, half4)
50no match for overload(readonlyTexture2D, int)
51no match for overload(writeonlyTexture2D)
52no match for textureWrite(readonlyTexture2D, uint2, half4)
53no match for textureRead(writeonlyTexture2D, uint2)
54*%%*/
55