Clone of mesa.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

lp_bld_format_soa.c 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /**************************************************************************
  2. *
  3. * Copyright 2009 VMware, Inc.
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21. * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  22. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #include "util/u_format.h"
  28. #include "lp_bld_type.h"
  29. #include "lp_bld_const.h"
  30. #include "lp_bld_conv.h"
  31. #include "lp_bld_format.h"
  32. static LLVMValueRef
  33. lp_build_format_swizzle_chan_soa(struct lp_type type,
  34. const LLVMValueRef *unswizzled,
  35. enum util_format_swizzle swizzle)
  36. {
  37. switch (swizzle) {
  38. case UTIL_FORMAT_SWIZZLE_X:
  39. case UTIL_FORMAT_SWIZZLE_Y:
  40. case UTIL_FORMAT_SWIZZLE_Z:
  41. case UTIL_FORMAT_SWIZZLE_W:
  42. return unswizzled[swizzle];
  43. case UTIL_FORMAT_SWIZZLE_0:
  44. return lp_build_zero(type);
  45. case UTIL_FORMAT_SWIZZLE_1:
  46. return lp_build_one(type);
  47. case UTIL_FORMAT_SWIZZLE_NONE:
  48. return lp_build_undef(type);
  49. default:
  50. assert(0);
  51. return lp_build_undef(type);
  52. }
  53. }
  54. void
  55. lp_build_format_swizzle_soa(const struct util_format_description *format_desc,
  56. struct lp_type type,
  57. const LLVMValueRef *unswizzled,
  58. LLVMValueRef *swizzled)
  59. {
  60. if(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) {
  61. enum util_format_swizzle swizzle = format_desc->swizzle[0];
  62. LLVMValueRef depth = lp_build_format_swizzle_chan_soa(type, unswizzled, swizzle);
  63. swizzled[2] = swizzled[1] = swizzled[0] = depth;
  64. swizzled[3] = lp_build_one(type);
  65. }
  66. else {
  67. unsigned chan;
  68. for (chan = 0; chan < 4; ++chan) {
  69. enum util_format_swizzle swizzle = format_desc->swizzle[chan];
  70. swizzled[chan] = lp_build_format_swizzle_chan_soa(type, unswizzled, swizzle);
  71. }
  72. }
  73. }
  74. void
  75. lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
  76. const struct util_format_description *format_desc,
  77. struct lp_type type,
  78. LLVMValueRef packed,
  79. LLVMValueRef *rgba)
  80. {
  81. LLVMValueRef inputs[4];
  82. unsigned start;
  83. unsigned chan;
  84. /* FIXME: Support more formats */
  85. assert(format_desc->layout == UTIL_FORMAT_LAYOUT_ARITH ||
  86. (format_desc->layout == UTIL_FORMAT_LAYOUT_ARRAY &&
  87. format_desc->block.bits == format_desc->channel[0].size));
  88. assert(format_desc->block.width == 1);
  89. assert(format_desc->block.height == 1);
  90. assert(format_desc->block.bits <= 32);
  91. /* Decode the input vector components */
  92. start = 0;
  93. for (chan = 0; chan < 4; ++chan) {
  94. unsigned width = format_desc->channel[chan].size;
  95. unsigned stop = start + width;
  96. LLVMValueRef input;
  97. input = packed;
  98. switch(format_desc->channel[chan].type) {
  99. case UTIL_FORMAT_TYPE_VOID:
  100. input = NULL;
  101. break;
  102. case UTIL_FORMAT_TYPE_UNSIGNED:
  103. if(type.floating) {
  104. if(start)
  105. input = LLVMBuildLShr(builder, input, lp_build_int_const_scalar(type, start), "");
  106. if(stop < format_desc->block.bits) {
  107. unsigned mask = ((unsigned long long)1 << width) - 1;
  108. input = LLVMBuildAnd(builder, input, lp_build_int_const_scalar(type, mask), "");
  109. }
  110. if(format_desc->channel[chan].normalized)
  111. input = lp_build_unsigned_norm_to_float(builder, width, type, input);
  112. else
  113. input = LLVMBuildFPToSI(builder, input, lp_build_vec_type(type), "");
  114. }
  115. else {
  116. /* FIXME */
  117. assert(0);
  118. input = lp_build_undef(type);
  119. }
  120. break;
  121. default:
  122. /* fall through */
  123. input = lp_build_undef(type);
  124. break;
  125. }
  126. inputs[chan] = input;
  127. start = stop;
  128. }
  129. lp_build_format_swizzle_soa(format_desc, type, inputs, rgba);
  130. }