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
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) {
23 TEXEL_FETCH(sGpuCache, address, 0, ivec2(0, 0)),
24 TEXEL_FETCH(sGpuCache, address, 0, ivec2(1, 0))
28 vec4[2] fetch_from_gpu_cache_2(HIGHP_FS_ADDRESS int address) {
29 ivec2 uv = get_gpu_cache_uv(address);
31 TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0)),
32 TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0))
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);
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))
61 vec4[3] fetch_from_gpu_cache_3(int address) {
62 ivec2 uv = get_gpu_cache_uv(address);
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))
70 vec4[3] fetch_from_gpu_cache_3_direct(ivec2 address) {
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))
78 vec4[4] fetch_from_gpu_cache_4_direct(ivec2 address) {
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))
87 vec4[4] fetch_from_gpu_cache_4(int address) {
88 ivec2 uv = get_gpu_cache_uv(address);
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))
97 //TODO: image resource is too specific for this module
100 RectWithEndpoint uv_rect;
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 {
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(
137 #endif //WR_VERTEX_SHADER