Skip to content

Commit fcb8dce

Browse files
committed
[12/n][ET-VK] Introduce rgba <-> image conversion shaders
Pull Request resolved: #5994 This one is fun. ghstack-source-id: 246208087 @exported-using-ghexport Differential Revision: [D63860585](https://our.internmc.facebook.com/intern/diff/D63860585/)
1 parent 7c2ac70 commit fcb8dce

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#version 450 core
10+
11+
#define PRECISION highp
12+
13+
#include "indexing_utils.h"
14+
15+
layout(std430) buffer;
16+
17+
layout(set = 0, binding = 0, rgba8) uniform PRECISION restrict writeonly image2D rgba_out;
18+
layout(set = 0, binding = 1) uniform PRECISION sampler3D t_in;
19+
20+
layout(set = 0, binding = 2) uniform PRECISION restrict readonly limits_UBO {
21+
ivec3 limits;
22+
};
23+
24+
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in;
25+
26+
void main() {
27+
const ivec3 pos = ivec3(gl_GlobalInvocationID);
28+
29+
if (any(greaterThanEqual(pos, limits))) {
30+
return;
31+
}
32+
33+
imageStore(rgba_out, pos.xy, texelFetch(t_in, pos, 0));
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#version 450 core
10+
11+
#define PRECISION highp
12+
13+
#include "indexing_utils.h"
14+
15+
layout(std430) buffer;
16+
17+
layout(set = 0, binding = 0, rgba32f) uniform PRECISION restrict writeonly image3D t_out;
18+
layout(set = 0, binding = 1) uniform PRECISION sampler2D rgba_in;
19+
20+
layout(set = 0, binding = 2) uniform PRECISION restrict readonly limits_UBO {
21+
ivec3 limits;
22+
};
23+
24+
layout(local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in;
25+
26+
void main() {
27+
const ivec3 pos = ivec3(gl_GlobalInvocationID);
28+
29+
if (any(greaterThanEqual(pos, limits))) {
30+
return;
31+
}
32+
33+
imageStore(t_out, pos, texelFetch(rgba_in, pos.xy, 0));
34+
}

backends/vulkan/runtime/utils/AhbUtils.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#include <executorch/backends/vulkan/runtime/api/api.h>
1414

15+
#include <executorch/backends/vulkan/runtime/graph/ComputeGraph.h>
16+
#include <executorch/backends/vulkan/runtime/graph/ops/utils/ShaderNameUtils.h>
1517
#include <executorch/backends/vulkan/runtime/vk_api/VkUtils.h>
1618

1719
namespace vkcompute {
@@ -181,5 +183,47 @@ vkapi::VulkanImage create_image_from_ahb(
181183
context->device(), image_props, image, image_view, sampler);
182184
}
183185

186+
void add_rgba_to_image_node(
187+
ComputeGraph& graph,
188+
const ValueRef in_rgba,
189+
const ValueRef out_tensor) {
190+
std::string kernel_name("rgba_to_image");
191+
kernel_name.reserve(kShaderNameReserve);
192+
193+
const auto global_wg_size = graph.create_global_wg_size(out_tensor);
194+
195+
graph.execute_nodes().emplace_back(new ExecuteNode(
196+
graph,
197+
VK_KERNEL_FROM_STR(kernel_name),
198+
global_wg_size,
199+
graph.create_local_wg_size(global_wg_size),
200+
// Input and Outputs
201+
{{out_tensor, vkapi::MemoryAccessType::WRITE},
202+
{in_rgba, vkapi::MemoryAccessType::READ}},
203+
// Parameter Buffers
204+
{graph.logical_limits_ubo(out_tensor)}));
205+
}
206+
207+
void add_image_to_rgba_node(
208+
ComputeGraph& graph,
209+
const ValueRef in_tensor,
210+
const ValueRef out_rgba) {
211+
std::string kernel_name("image_to_rgba");
212+
kernel_name.reserve(kShaderNameReserve);
213+
214+
const auto global_wg_size = graph.create_global_wg_size(out_rgba);
215+
216+
graph.execute_nodes().emplace_back(new ExecuteNode(
217+
graph,
218+
VK_KERNEL_FROM_STR(kernel_name),
219+
global_wg_size,
220+
graph.create_local_wg_size(global_wg_size),
221+
// Input and Outputs
222+
{{out_rgba, vkapi::MemoryAccessType::WRITE},
223+
{in_tensor, vkapi::MemoryAccessType::READ}},
224+
// Parameter Buffers
225+
{graph.logical_limits_ubo(out_rgba)}));
226+
}
227+
184228
} // namespace utils
185229
} // namespace vkcompute

0 commit comments

Comments
 (0)