You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

padding_pack4.comp 2.3 kB

7 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
  4. //
  5. // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // https://opensource.org/licenses/BSD-3-Clause
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed
  11. // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12. // CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13. // specific language governing permissions and limitations under the License.
  14. #version 450
  15. layout (constant_id = 0) const int top = 0;
  16. layout (constant_id = 1) const int bottom = 0;
  17. layout (constant_id = 2) const int left = 0;
  18. layout (constant_id = 3) const int right = 0;
  19. layout (constant_id = 4) const int type = 1;
  20. layout (constant_id = 5) const float value = 0;
  21. layout (local_size_x_id = 233) in;
  22. layout (local_size_y_id = 234) in;
  23. layout (local_size_z_id = 235) in;
  24. layout (binding = 0) readonly buffer bottom_blob { vec4 bottom_blob_data[]; };
  25. layout (binding = 1) writeonly buffer top_blob { vec4 top_blob_data[]; };
  26. layout (push_constant) uniform parameter
  27. {
  28. int dims;
  29. int w;
  30. int h;
  31. int c;
  32. int cstep;
  33. int outdims;
  34. int outw;
  35. int outh;
  36. int outc;
  37. int outcstep;
  38. } p;
  39. void main()
  40. {
  41. int gx = int(gl_GlobalInvocationID.x);
  42. int gy = int(gl_GlobalInvocationID.y);
  43. int gz = int(gl_GlobalInvocationID.z);
  44. if (gx >= p.outw || gy >= p.outh || gz >= p.outc)
  45. return;
  46. vec4 res;
  47. int x = gx - left;
  48. int y = gy - top;
  49. if (type == 0)
  50. {
  51. if (x >= 0 && x < p.w && y >= 0 && y < p.h)
  52. {
  53. int v_offset = gz * p.cstep + y * p.w + x;
  54. res = bottom_blob_data[v_offset];
  55. }
  56. else
  57. {
  58. res = vec4(value);
  59. }
  60. }
  61. else if (type == 1)
  62. {
  63. x = clamp(x, 0, p.w - 1);
  64. y = clamp(y, 0, p.h - 1);
  65. int v_offset = gz * p.cstep + y * p.w + x;
  66. res = bottom_blob_data[v_offset];
  67. }
  68. top_blob_data[gz * p.outcstep + gy * p.outw + gx] = res;
  69. }