HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_Type.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: RV_Type.h ( RV Library, C++)
7  *
8  * COMMENTS:
9  * shared types for RV library
10  */
11 
12 #ifndef RV_Type_h
13 #define RV_Type_h
14 
15 #include "RV_API.h"
16 
17 #include <RE/RE_Types.h>
18 #include <RE/RE_TextureTypes.h>
19 
20 #include <UT/UT_ComputeGPU.h>
21 #include <UT/UT_Matrix4.h>
22 #include <UT/UT_StringArray.h>
23 #include <UT/UT_SharedPtr.h>
24 
25 #include <SYS/SYS_AtomicInt.h>
26 
27 // indices for specific Descriptor Sets
28 // must match shaders
30 {
37 };
38 
39 
41 {
44 
48 
52 
57 
58  // These can only be used in the context of a GLSL shader.
62 
64 
65 };
66 
68 {
69  // Currently this is a pretty trivial transform.
70  return RV_GPUType(t);
71 }
72 
74 {
75  // Currently this is a pretty trivial transform.
76  return RE_GPUType(t);
77 }
78 
80 {
82 
85  RV_DEVICE_INTEL_GMA = 0x4, // Intel GMA (not supported)
86  RV_DEVICE_INTEL_HD = 0x8, // Intel HD graphics
87  RV_DEVICE_GDI = 0x10, // Software OGL on Windows
89 
90  RV_DEVICE_PRO = 0x100, // Professional series
91  RV_DEVICE_MAC = 0x200, // Mac versions of drivers
92  RV_DEVICE_MAC_SILICON = 0x600, // ARM-based Macs
93 
97 };
98 
100 {
104  // RV_ATTRIBUTE_INSTANCE,
106  RV_ATTRIBUTE_RANDOM, // randomly sampled NOTE: also used for INSTANCE-level
108 };
109 
110 
112 {
118 };
119 
121 {
132 
134 };
135 
137 {
138  RV_FILTER_NEAREST, // no filtering
139  RV_FILTER_LINEAR, // bi-linear filtering
140  RV_FILTER_CUBIC, // bi-cubic filtering NOTE: requires extension
141 };
142 
144 {
145  RV_MIPMAP_DISABLED, // No Mip filtering
146  RV_MIPMAP_NEAREST, // nearest mip level
147  RV_MIPMAP_LINEAR // linear blending
148 };
149 
151 {
152  RV_TEX_WRAP_REPEAT, // texture repeats, tiling
153  RV_TEX_WRAP_CLAMP, // edge pixel is stretched
154  RV_TEX_WRAP_BORDER, // outside pixels are a const colour
155  RV_TEX_WRAP_MIRROR // texture repeats, mirrored tiling
156 };
157 
159 {
160 public:
161  UT_StringHolder Layer; // Layer name within a deep raster file. C if ""
162  UT_StringHolder ColorSpace; // OCIO colorspace of the source, auto if ""
163  fpreal ImageScale = 1.0; // Scale to apply to loaded images
164  exint MaxWidth = 0; // 0 = no limit
169  bool MipMap = false;
170  fpreal MinLOD = 0.0;
171  fpreal MaxLOD = -1.0; // Default no limit to mip levels
172  bool LinearInterp = true; // Use bilinear or trilinear interpolation
173  bool IntTexture = false; // If INT/UINT 8/16 is normalized or as-is
174  bool SampleTexels = false; // if UV is [0,1] (false) or [0,res) (true).
175  bool CheckAlpha = false; // check for detailed info about alpha
176  int Anisotropy = 4;
177  RV_TextureWrap WrapU = RV_TEX_WRAP_REPEAT; // behaviour outside (0,1) uv
180  fpreal32 BorderColor[4] = { 0.0, 0.0, 0.0, 0.0 };
181  bool IsData = false;
182 };
183 
184 /// ID used to individually identify Vulkan Resources, and an
185 /// index used for fast-lookup inside RV_Instance
187 {
188  exint id = 0;
190 
191  operator bool() const
192  { return id != 0; }
193 
194  bool operator==(const RV_ResourceID &other) const
195  { return other.id == id; }
196 
197  RV_ResourceID() = default;
198  RV_ResourceID& operator=(const RV_ResourceID &other) = default;
199  RV_ResourceID(const RV_ResourceID &other) = default;
200 };
201 
202 /// Opaque reference to a texture stored in the RV_TextureCache
204 {
205 public:
206  ~RV_TextureRef() { if(myRef) myRef->refCount.add(-1); }
207 
208  /// Reference to a valid texture
209  bool isValid() const
210  { return myTexID != -1 && !myIsMissingTex; }
211 
212  /// Texture is missing; a default color used instead
213  bool isPlaceholder() const
214  { return myIsPlaceholder; }
215  /// Texture couldn't be found or resolved
216  bool isMissingTex() const
217  { return myIsMissingTex; }
218  /// Texture is currently loading in the background
219  bool isLoading() const
220  { return myIsLoading; }
221  /// Texture has been changed since last check
222  bool isDirty() const
223  { return myIsDirty; }
224 
225  /// Reset the reference to a null handle.
226  void reset()
227  {
228  myTexID = -1;
229  myIsMissingTex = false;
230  myIsPlaceholder = false;
231  myIsDirty = true;
232  myIsLoading = false;
233  myCacheVersion = 0;
234  myCacheRefresh = 0;
235  }
236 
237  /// Returns true if the reference is to a series of UDIM texture files
238  bool isUDIM() const { return myUDIMW > 0; }
239  /// Returns the UDIM range of the texture files (eg. (0,0) -> (3,2))
240  void getUDIMParms(int &x, int &y, int &w, int &h) const
241  {
242  x = myUDIMX;
243  y = myUDIMY;
244  w = myUDIMW;
245  h = myUDIMH;
246  }
247 
248  void getRes(int *w, int *h = nullptr, int *d = nullptr) const
249  {
250  if(w)
251  *w = myWidth;
252  if(h)
253  *h = myHeight;
254  if(d)
255  *d = myDepth;
256  }
257 
258  /// Returns texture dimension
259  RV_ImageDim getImageDim() const { return myTexType; }
260 
261  exint id() const { return myTexID; }
262 
263  struct CacheData
264  {
265  CacheData() : refCount(0), isValid(false) {}
266 
268  bool isValid;
269  };
270 
271 private:
272  exint myTexID = -1;
273  exint myCacheVersion = 0;
274  exint myCacheRefresh = 0;
275  bool myIsMissingTex = false;
276  bool myIsPlaceholder = false;
277  bool myIsLoading = false;
278  bool myIsDirty = false;
279 
281 
282  int8 myUDIMX = 0;
283  int8 myUDIMY = 0;
284  int8 myUDIMW = 0;
285  int8 myUDIMH = 0;
286  int myWidth = 1;
287  int myHeight = 1;
288  int myDepth = 1;
289 
290  RV_ImageDim myTexType = RV_IMAGE_UNKNOWN;
291 
292  friend class RV_TextureCache;
293 };
294 
296 {
305 };
306 
308 {
315  //RV_UNIFORM_IMAGE_UNTYPED, // for `shaderStorageImageReadWithoutFormat`
319 };
320 
321 // Testing using a struct type instead of giant enum
322 // -- worried the helper functions for the giant enum
323 // will be fragile when we want to add new types
325 {
326  unsigned int vecsize : 2;
330 };
331 
333 {
336 
366 
369 
416 
418 
420 
422 };
423 
425 {
428 
430 
433  RV_PRIM_LINE_LOOPS, // NOTE: no direct Vk analogue
434 
438 
439  RV_PRIM_LINES_ADJACENT, // for geometry shaders; includes
440  RV_PRIM_LINE_STRIP_ADJACENT, // extra vertices outside the primitive
441  RV_PRIM_TRIANGLES_ADJACENT, // for curvature
443 
444  RV_PRIM_POLYGONS, // NOTE: no direct Vk analogue
445 
446  RV_PRIM_PATCHES, // Patches sent to tessellation shaders
447 
449 };
450 
452 {
459 };
460 
462 {
466  // RV_RESOLVE_BUFFER, // for now uneeded; we handle resolve in shader
467 };
468 
470 {
474 };
475 
477 {
482 };
483 
485 {
490 };
491 
493 {
497 };
498 
500 {
506 };
507 
509 {
511  RV_STAGE_ANY = 0, // ALWAYS need to be execute
516  RV_STAGE_ANY_SHADER, // will be run for UBOs/SSBOs which can be consumed by compute or graphics pipelines
518 };
519 
521 {
525 };
526 
528 {
531 };
532 
534 {
537 
539 };
540 
542 
545  RV_GPUType &out_type,
546  int &out_vecsize);
548 
549 inline bool RVisUIntGPUType(RV_GPUType gpu_type)
550 {
551  return gpu_type >= RV_GPU_UINT8 && gpu_type <= RV_GPU_UINT32;
552 }
553 
554 inline bool RVisIntGPUType(RV_GPUType gpu_type)
555 {
556  return gpu_type >= RV_GPU_INT8 && gpu_type <= RV_GPU_INT32;
557 }
558 
559 inline bool RVisFloatGPUType(RV_GPUType gpu_type)
560 {
561  return gpu_type >= RV_GPU_FLOAT16 && gpu_type <= RV_GPU_FLOAT64;
562 }
563 
564 inline bool RVisMatrixGPUType(RV_GPUType gpu_type)
565 {
566  return gpu_type >= RV_GPU_MATRIX2 && gpu_type <= RV_GPU_MATRIX4;
567 }
568 
569 inline uint32_t RVsizeOfGPUType(RV_GPUType gpu_type)
570 {
571  int bpp = 32;
572 
573  switch (gpu_type)
574  {
575  // NOTE: that int-1 and int-4 don't correspond to
576  // actual Vulkan types
577  case RV_GPU_UINT1:
578  bpp = 1; break;
579  case RV_GPU_UINT4:
580  bpp = 4; break;
581 
582  case RV_GPU_INT8:
583  case RV_GPU_UINT8:
584  bpp = 8; break;
585 
586  case RV_GPU_INT16:
587  case RV_GPU_UINT16:
588  case RV_GPU_FLOAT16:
589  bpp = 16; break;
590 
591  case RV_GPU_INT32:
592  case RV_GPU_UINT32:
593  case RV_GPU_FLOAT32:
594  case RV_GPU_FLOAT24:
595  bpp = 32; break;
596 
597  case RV_GPU_FLOAT64:
598  bpp = 64; break;
599 
600  case RV_GPU_MATRIX2:
601  bpp = 32 * 4; break;
602  case RV_GPU_MATRIX3:
603  bpp = 32 * 9; break;
604  case RV_GPU_MATRIX4:
605  bpp = 32 * 16; break;
606  default:
607  bpp = 32;
608  UT_ASSERT_MSG(0, "RVsizeOfGPUType(): Unrecognized RV_GPUType");
609  }
610 
611  return bpp;
612 }
613 
615 {
616  switch(type)
617  {
618  case RE_CLAMP_REPEAT : return RV_TEX_WRAP_REPEAT;
619  case RE_CLAMP_BORDER : return RV_TEX_WRAP_BORDER;
620  case RE_CLAMP_EDGE : return RV_TEX_WRAP_CLAMP;
621  case RE_CLAMP_MIRROR : return RV_TEX_WRAP_MIRROR;
622  }
623  return RV_TEX_WRAP_REPEAT;
624 }
625 
627 {
628  switch (t)
629  {
630  case RV_PRIM_POINTS :
631  return RV_TOPOLOGY_POINT;
632  case RV_PRIM_LINES:
633  case RV_PRIM_LINE_STRIP:
636  return RV_TOPOLOGY_LINE;
637  case RV_PRIM_TRIANGLES:
642  return RV_TOPOLOGY_TRIANGLE;
643  case RV_PRIM_PATCHES:
644  return RV_TOPOLOGY_PATCH;
645  default: break;
646  }
647  UT_ASSERT(false && "Unrecognized Topology Type used for Pipeline");
648  return RV_TOPOLOGY_UNKNOWN;
649 }
650 
652 {
653  switch(type)
654  {
655  case RE_PRIM_POINTS : return RV_PRIM_POINTS;
656  case RE_PRIM_LINES : return RV_PRIM_LINES;
658  case RE_PRIM_TRIANGLES : return RV_PRIM_TRIANGLES;
665  case RE_PRIM_POLYGONS : return RV_PRIM_POLYGONS;
666  case RE_PRIM_PATCHES : return RV_PRIM_PATCHES;
667  case RE_PRIM_NONE :
668  case RE_NUM_PRIM_TYPES :
669  case RE_PRIM_LINE_LOOP :
670  default : break;
671  }
672  return RV_PRIM_NONE;
673 }
674 
675 const char *RVgetTypeName(RV_GPUType t);
676 
677 const char *RVgetPrimName(RV_PrimType p);
678 
680 
682 {
684 }
685 
687 {
689 }
690 
692 
693 int RVgetNumberOfPrim(RV_PrimType p, int num_verts);
694 
695 #endif
RV_TextureSwizzle
Definition: RV_Type.h:295
RV_TextureWrap WrapW
Definition: RV_Type.h:179
RV_UniformVarType
Definition: RV_Type.h:307
bool CheckAlpha
Definition: RV_Type.h:175
exint id() const
Definition: RV_Type.h:261
RE_GPUType RVgetREType(RV_GPUType t)
Definition: RV_Type.h:73
RV_ImageOp
Definition: RV_Type.h:469
exint MaxWidth
Definition: RV_Type.h:164
RV_ImageDim image_dim
Definition: RV_Type.h:329
RV_PrimType RVconvertToRVPrim(RE_PrimType type)
Definition: RV_Type.h:651
bool IntTexture
Definition: RV_Type.h:173
bool RVisFloatGPUType(RV_GPUType gpu_type)
Definition: RV_Type.h:559
bool isDirty() const
Texture has been changed since last check.
Definition: RV_Type.h:222
bool LinearInterp
Definition: RV_Type.h:172
bool isValid() const
Reference to a valid texture.
Definition: RV_Type.h:209
exint id
Definition: RV_Type.h:188
RV_GPUType data_type
Definition: RV_Type.h:327
int64 exint
Definition: SYS_Types.h:125
RV_StageGroup
Definition: RV_Type.h:508
UT_StringHolder Layer
Definition: RV_Type.h:161
bool RVisIntGPUType(RV_GPUType gpu_type)
Definition: RV_Type.h:554
Opaque reference to a texture stored in the RV_TextureCache.
Definition: RV_Type.h:203
int RVgetPointsPerPrim(RV_PrimType p)
const char * RVgetTypeName(RV_GPUType t)
GLint y
Definition: glcorearb.h:103
void getUDIMParms(int &x, int &y, int &w, int &h) const
Returns the UDIM range of the texture files (eg. (0,0) -> (3,2))
Definition: RV_Type.h:240
RV_API RV_ImageDim RVgetUniformTypeImageDim(RV_UniformType t)
float fpreal32
Definition: SYS_Types.h:200
RV_TextureMipMode
Definition: RV_Type.h:143
OutGridT const XformOp bool bool
fpreal ImageScale
Definition: RV_Type.h:163
UT_StringArray RV_OverrideList
Definition: RV_Type.h:541
exint MaxMemoryMB
Definition: RV_Type.h:168
#define UT_ASSERT_MSG(ZZ,...)
Definition: UT_Assert.h:159
RV_AttachmentType
Definition: RV_Type.h:461
exint MaxComponents
Definition: RV_Type.h:167
RE_GPUType
Definition: RE_Types.h:52
UT_StringHolder ColorSpace
Definition: RV_Type.h:162
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
RV_SetType
Definition: RV_Type.h:29
SYS_AtomicInt32 refCount
Definition: RV_Type.h:267
RV_ResourceID()=default
RV_TextureWrap WrapU
Definition: RV_Type.h:177
RV_GraphicsDevice
Definition: RV_Type.h:79
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
RV_AccelStructTag
Definition: RV_Type.h:527
RV_AttributeType
Definition: RV_Type.h:99
RV_UniformVarType var_type
Definition: RV_Type.h:328
RV_UniformType
Definition: RV_Type.h:332
void reset()
Reset the reference to a null handle.
Definition: RV_Type.h:226
bool isMissingTex() const
Texture couldn't be found or resolved.
Definition: RV_Type.h:216
RV_PolygonMode
Definition: RV_Type.h:492
RE_TexClampType
RV_TextureWrap RVconvertToTextureWrap(RE_TexClampType type)
Definition: RV_Type.h:614
#define RV_API
Definition: RV_API.h:10
bool RVisBasicType(RV_UniformType t)
Definition: RV_Type.h:681
bool isUDIM() const
Returns true if the reference is to a series of UDIM texture files.
Definition: RV_Type.h:238
RV_TextureWrap
Definition: RV_Type.h:150
RV_AccelStructBuildPref
Definition: RV_Type.h:520
const char * RVgetPrimName(RV_PrimType p)
int RVgetNumberOfPrim(RV_PrimType p, int num_verts)
fpreal MinLOD
Definition: RV_Type.h:170
signed char int8
Definition: SYS_Types.h:35
bool RVisUIntGPUType(RV_GPUType gpu_type)
Definition: RV_Type.h:549
GLint GLenum GLint x
Definition: glcorearb.h:409
RV_TextureFilter
Definition: RV_Type.h:136
bool SampleTexels
Definition: RV_Type.h:174
RV_ImageDim getImageDim() const
Returns texture dimension.
Definition: RV_Type.h:259
GLdouble t
Definition: glad.h:2397
RV_GPUType RVgetFromREType(RE_GPUType t)
Definition: RV_Type.h:67
RV_ShaderType
Definition: RV_Type.h:484
void getRes(int *w, int *h=nullptr, int *d=nullptr) const
Definition: RV_Type.h:248
RV_TextureWrap WrapV
Definition: RV_Type.h:178
bool isPlaceholder() const
Texture is missing; a default color used instead.
Definition: RV_Type.h:213
RV_PrimType
Definition: RV_Type.h:424
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
uint32_t RVsizeOfGPUType(RV_GPUType gpu_type)
Definition: RV_Type.h:569
Global cache of vulkan textures sourced from files.
const char * RVgetUniformTypeName(RV_UniformType t)
RV_TopologyClass RVgetTopologyClass(RV_PrimType t)
Definition: RV_Type.h:626
bool RVisMatrixGPUType(RV_GPUType gpu_type)
Definition: RV_Type.h:564
bool isLoading() const
Texture is currently loading in the background.
Definition: RV_Type.h:219
exint MaxDepth
Definition: RV_Type.h:166
RV_TopologyClass
Definition: RV_Type.h:451
RV_GPUType
Definition: RV_Type.h:40
fpreal64 fpreal
Definition: SYS_Types.h:278
RV_LogicOp
Definition: RV_Type.h:499
GLuint index
Definition: glcorearb.h:786
RV_MemType
Definition: RV_Type.h:111
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
~RV_TextureRef()
Definition: RV_Type.h:206
bool RVisOpaqueType(RV_UniformType t)
Definition: RV_Type.h:686
RV_RenderPassType
Definition: RV_Type.h:476
bool operator==(const RV_ResourceID &other) const
Definition: RV_Type.h:194
unsigned int vecsize
Definition: RV_Type.h:326
RV_ResourceID & operator=(const RV_ResourceID &other)=default
RV_ImageDim
Definition: RV_Type.h:120
RE_PrimType
Definition: RE_Types.h:199
fpreal32 BorderColor[4]
Definition: RV_Type.h:180
RV_API bool RVgetUniformFormat(RV_UniformType t, RV_GPUType &out_type, int &out_vecsize)
fpreal MaxLOD
Definition: RV_Type.h:171
exint MaxHeight
Definition: RV_Type.h:165
RV_AccelStructVisibility
Definition: RV_Type.h:533