GrVkVaryingHandler.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/gpu/vk/GrVkVaryingHandler.h"
  8. /** Returns the number of locations take up by a given GrSLType. We assume that all
  9. scalar values are 32 bits. */
  10. static inline int grsltype_to_location_size(GrSLType type) {
  11. switch(type) {
  12. case kVoid_GrSLType:
  13. return 0;
  14. case kFloat_GrSLType: // fall through
  15. case kHalf_GrSLType:
  16. return 1;
  17. case kFloat2_GrSLType: // fall through
  18. case kHalf2_GrSLType:
  19. return 1;
  20. case kFloat3_GrSLType:
  21. case kHalf3_GrSLType:
  22. return 1;
  23. case kFloat4_GrSLType:
  24. case kHalf4_GrSLType:
  25. return 1;
  26. case kUint2_GrSLType:
  27. return 1;
  28. case kInt2_GrSLType:
  29. case kShort2_GrSLType:
  30. case kUShort2_GrSLType:
  31. case kByte2_GrSLType:
  32. case kUByte2_GrSLType:
  33. return 1;
  34. case kInt3_GrSLType:
  35. case kShort3_GrSLType:
  36. case kUShort3_GrSLType:
  37. case kByte3_GrSLType:
  38. case kUByte3_GrSLType:
  39. return 1;
  40. case kInt4_GrSLType:
  41. case kShort4_GrSLType:
  42. case kUShort4_GrSLType:
  43. case kByte4_GrSLType:
  44. case kUByte4_GrSLType:
  45. return 1;
  46. case kFloat2x2_GrSLType:
  47. case kHalf2x2_GrSLType:
  48. return 2;
  49. case kFloat3x3_GrSLType:
  50. case kHalf3x3_GrSLType:
  51. return 3;
  52. case kFloat4x4_GrSLType:
  53. case kHalf4x4_GrSLType:
  54. return 4;
  55. case kTexture2DSampler_GrSLType:
  56. return 0;
  57. case kTextureExternalSampler_GrSLType:
  58. return 0;
  59. case kTexture2DRectSampler_GrSLType:
  60. return 0;
  61. case kBool_GrSLType:
  62. return 1;
  63. case kInt_GrSLType: // fall through
  64. case kShort_GrSLType:
  65. case kByte_GrSLType:
  66. return 1;
  67. case kUint_GrSLType: // fall through
  68. case kUShort_GrSLType:
  69. case kUByte_GrSLType:
  70. return 1;
  71. }
  72. SK_ABORT("Unexpected type");
  73. return -1;
  74. }
  75. static void finalize_helper(GrVkVaryingHandler::VarArray& vars) {
  76. int locationIndex = 0;
  77. for (int i = 0; i < vars.count(); ++i) {
  78. GrShaderVar& var = vars[i];
  79. SkString location;
  80. location.appendf("location = %d", locationIndex);
  81. var.addLayoutQualifier(location.c_str());
  82. int elementSize = grsltype_to_location_size(var.getType());
  83. SkASSERT(elementSize > 0);
  84. int numElements = 1;
  85. if (var.isArray() && !var.isUnsizedArray()) {
  86. numElements = var.getArrayCount();
  87. }
  88. SkASSERT(numElements > 0);
  89. locationIndex += elementSize * numElements;
  90. }
  91. // Vulkan requires at least 64 locations to be supported for both vertex output and fragment
  92. // input. If we ever hit this assert, then we'll need to add a cap to actually check the
  93. // supported input and output values and adjust our supported shaders based on those values.
  94. SkASSERT(locationIndex <= 64);
  95. }
  96. void GrVkVaryingHandler::onFinalize() {
  97. finalize_helper(fVertexInputs);
  98. finalize_helper(fVertexOutputs);
  99. finalize_helper(fGeomInputs);
  100. finalize_helper(fGeomOutputs);
  101. finalize_helper(fFragInputs);
  102. finalize_helper(fFragOutputs);
  103. }