Bug 1857841 - pt 3. Add a new page kind named "fresh" r=glandium
[gecko.git] / gfx / wr / webrender / res / gpu_cache.glsl
blobcd5e41fec46b0bb3459d3f335d8a77d83b5b1883
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 uniform HIGHP_SAMPLER_FLOAT sampler2D sGpuCache;
7 #define VECS_PER_IMAGE_RESOURCE     2
9 // TODO(gw): This is here temporarily while we have
10 //           both GPU store and cache. When the GPU
11 //           store code is removed, we can change the
12 //           PrimitiveInstance instance structure to
13 //           use 2x unsigned shorts as vertex attributes
14 //           instead of an int, and encode the UV directly
15 //           in the vertices.
16 ivec2 get_gpu_cache_uv(HIGHP_FS_ADDRESS int address) {
17     return ivec2(uint(address) % WR_MAX_VERTEX_TEXTURE_WIDTH,
18                  uint(address) / WR_MAX_VERTEX_TEXTURE_WIDTH);
21 vec4[2] fetch_from_gpu_cache_2_direct(ivec2 address) {
22     return vec4[2](
23         TEXEL_FETCH(sGpuCache, address, 0, ivec2(0, 0)),
24         TEXEL_FETCH(sGpuCache, address, 0, ivec2(1, 0))
25     );
28 vec4[2] fetch_from_gpu_cache_2(HIGHP_FS_ADDRESS int address) {
29     ivec2 uv = get_gpu_cache_uv(address);
30     return vec4[2](
31         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0)),
32         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0))
33     );
36 vec4 fetch_from_gpu_cache_1_direct(ivec2 address) {
37     return texelFetch(sGpuCache, address, 0);
40 vec4 fetch_from_gpu_cache_1(HIGHP_FS_ADDRESS int address) {
41     ivec2 uv = get_gpu_cache_uv(address);
42     return texelFetch(sGpuCache, uv, 0);
45 #ifdef WR_VERTEX_SHADER
47 vec4[8] fetch_from_gpu_cache_8(int address) {
48     ivec2 uv = get_gpu_cache_uv(address);
49     return vec4[8](
50         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0)),
51         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0)),
52         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(2, 0)),
53         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(3, 0)),
54         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(4, 0)),
55         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(5, 0)),
56         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(6, 0)),
57         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(7, 0))
58     );
61 vec4[3] fetch_from_gpu_cache_3(int address) {
62     ivec2 uv = get_gpu_cache_uv(address);
63     return vec4[3](
64         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0)),
65         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0)),
66         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(2, 0))
67     );
70 vec4[3] fetch_from_gpu_cache_3_direct(ivec2 address) {
71     return vec4[3](
72         TEXEL_FETCH(sGpuCache, address, 0, ivec2(0, 0)),
73         TEXEL_FETCH(sGpuCache, address, 0, ivec2(1, 0)),
74         TEXEL_FETCH(sGpuCache, address, 0, ivec2(2, 0))
75     );
78 vec4[4] fetch_from_gpu_cache_4_direct(ivec2 address) {
79     return vec4[4](
80         TEXEL_FETCH(sGpuCache, address, 0, ivec2(0, 0)),
81         TEXEL_FETCH(sGpuCache, address, 0, ivec2(1, 0)),
82         TEXEL_FETCH(sGpuCache, address, 0, ivec2(2, 0)),
83         TEXEL_FETCH(sGpuCache, address, 0, ivec2(3, 0))
84     );
87 vec4[4] fetch_from_gpu_cache_4(int address) {
88     ivec2 uv = get_gpu_cache_uv(address);
89     return vec4[4](
90         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0)),
91         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0)),
92         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(2, 0)),
93         TEXEL_FETCH(sGpuCache, uv, 0, ivec2(3, 0))
94     );
97 //TODO: image resource is too specific for this module
99 struct ImageSource {
100     RectWithEndpoint uv_rect;
101     vec4 user_data;
104 ImageSource fetch_image_source(int address) {
105     //Note: number of blocks has to match `renderer::BLOCKS_PER_UV_RECT`
106     vec4 data[2] = fetch_from_gpu_cache_2(address);
107     RectWithEndpoint uv_rect = RectWithEndpoint(data[0].xy, data[0].zw);
108     return ImageSource(uv_rect, data[1]);
111 ImageSource fetch_image_source_direct(ivec2 address) {
112     vec4 data[2] = fetch_from_gpu_cache_2_direct(address);
113     RectWithEndpoint uv_rect = RectWithEndpoint(data[0].xy, data[0].zw);
114     return ImageSource(uv_rect, data[1]);
117 // Fetch optional extra data for a texture cache resource. This can contain
118 // a polygon defining a UV rect within the texture cache resource.
119 // Note: the polygon coordinates are in homogeneous space.
120 struct ImageSourceExtra {
121     vec4 st_tl;
122     vec4 st_tr;
123     vec4 st_bl;
124     vec4 st_br;
127 ImageSourceExtra fetch_image_source_extra(int address) {
128     vec4 data[4] = fetch_from_gpu_cache_4(address + VECS_PER_IMAGE_RESOURCE);
129     return ImageSourceExtra(
130         data[0],
131         data[1],
132         data[2],
133         data[3]
134     );
137 #endif //WR_VERTEX_SHADER