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

fd2_resource.c 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2018 Jonathan Marek <jonathan@marek.ca>
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. *
  23. * Authors:
  24. * Jonathan Marek <jonathan@marek.ca>
  25. */
  26. #include "fd2_resource.h"
  27. uint32_t
  28. fd2_setup_slices(struct fd_resource *rsc)
  29. {
  30. struct pipe_resource *prsc = &rsc->base;
  31. enum pipe_format format = rsc->base.format;
  32. uint32_t level, size = 0;
  33. uint32_t width = prsc->width0;
  34. uint32_t height = prsc->height0;
  35. uint32_t depth = prsc->depth0;
  36. for (level = 0; level <= prsc->last_level; level++) {
  37. struct fd_resource_slice *slice = fd_resource_slice(rsc, level);
  38. uint32_t blocks;
  39. /* 32 * 32 block alignment */
  40. switch (prsc->target) {
  41. default: assert(0);
  42. case PIPE_TEXTURE_2D:
  43. case PIPE_TEXTURE_2D_ARRAY:
  44. case PIPE_TEXTURE_RECT:
  45. case PIPE_TEXTURE_CUBE:
  46. height = align(height, 32 * util_format_get_blockheight(format));
  47. case PIPE_TEXTURE_1D:
  48. case PIPE_TEXTURE_1D_ARRAY:
  49. width = align(width, 32 * util_format_get_blockwidth(format));
  50. case PIPE_BUFFER:
  51. break;
  52. }
  53. /* mipmaps have power of two sizes in memory */
  54. if (level) {
  55. width = util_next_power_of_two(width);
  56. height = util_next_power_of_two(height);
  57. }
  58. slice->pitch = width;
  59. slice->offset = size;
  60. blocks = util_format_get_nblocks(format, width, height);
  61. /* 4k aligned size */
  62. slice->size0 = align(blocks * rsc->cpp, 4096);
  63. size += slice->size0 * depth * prsc->array_size;
  64. width = u_minify(width, 1);
  65. height = u_minify(height, 1);
  66. depth = u_minify(depth, 1);
  67. }
  68. return size;
  69. }