From 9c154122d38c4bcdd2157ff9a7744d713ba253b9 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 18 May 2017 13:08:13 -0700 Subject: [PATCH] Introdicing the format factor and merging with master becasue of protocol change... --- libraries/gpu/src/gpu/Format.h | 75 ++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 8 deletions(-) diff --git a/libraries/gpu/src/gpu/Format.h b/libraries/gpu/src/gpu/Format.h index 8b7bbdcbed..729a1bbdc0 100644 --- a/libraries/gpu/src/gpu/Format.h +++ b/libraries/gpu/src/gpu/Format.h @@ -21,7 +21,7 @@ namespace gpu { class Backend; // Description of a scalar type -enum Type { +enum Type : uint8_t { FLOAT = 0, INT32, @@ -39,6 +39,8 @@ enum Type { NINT8, NUINT8, + COMPRESSED, + NUM_TYPES, BOOL = UINT8, @@ -80,11 +82,13 @@ static const bool TYPE_IS_INTEGER[NUM_TYPES] = { false, false, false, - false + false, + + false, }; // Dimension of an Element -enum Dimension { +enum Dimension : uint8_t { SCALAR = 0, VEC2, VEC3, @@ -92,6 +96,7 @@ enum Dimension { MAT2, MAT3, MAT4, + BLOB, // Blob element's size is defined from the type and semantic, it s counted as 1 component NUM_DIMENSIONS, }; @@ -104,6 +109,7 @@ static const int LOCATION_COUNT[NUM_DIMENSIONS] = { 1, 3, 4, + 1, }; // Count (of scalars) in an Element for a given Dimension's location @@ -115,6 +121,7 @@ static const int SCALAR_COUNT_PER_LOCATION[NUM_DIMENSIONS] = { 4, 3, 4, + 1, }; // Count (of scalars) in an Element for a given Dimension @@ -126,11 +133,12 @@ static const int SCALAR_COUNT[NUM_DIMENSIONS] = { 4, 9, 16, + 1, }; // Semantic of an Element // Provide information on how to use the element -enum Semantic { +enum Semantic : uint8_t { RAW = 0, // used as RAW memory RED, @@ -156,6 +164,8 @@ enum Semantic { SBGRA, // These are generic compression format smeantic for images + // THey must be used with Dim = BLOB and Type = Compressed + // THe size of a compressed element is defined from the semantic _FIRST_COMPRESSED, COMPRESSED_BC1_SRGB, @@ -174,9 +184,58 @@ enum Semantic { SAMPLER, SAMPLER_MULTISAMPLE, SAMPLER_SHADOW, - - - NUM_SEMANTICS, + + + NUM_SEMANTICS, // total Number of semantics (not a valid Semantic)! +}; + +// Array providing the scaling factor to size in bytes depending on a given semantic +static const int SEMANTIC_SIZE_FACTOR[NUM_SEMANTICS] = { + 1, //RAW = 0, // used as RAW memory + + 1, //RED, + 1, //RGB, + 1, //RGBA, + 1, //BGRA, + + 1, //XY, + 1, //XYZ, + 1, //XYZW, + 1, //QUAT, + 1, //UV, + 1, //INDEX, //used by index buffer of a mesh + 1, //PART, // used by part buffer of a mesh + + 1, //DEPTH, // Depth only buffer + 1, //STENCIL, // Stencil only buffer + 1, //DEPTH_STENCIL, // Depth Stencil buffer + + 1, //SRED, + 1, //SRGB, + 1, //SRGBA, + 1, //SBGRA, + + // These are generic compression format smeantic for images + // THey must be used with Dim = BLOB and Type = Compressed + // THe size of a compressed element is defined from the semantic + 1, //_FIRST_COMPRESSED, + + 1, //COMPRESSED_BC1_SRGB, + 1, //COMPRESSED_BC1_SRGBA, + 1, //COMPRESSED_BC3_SRGBA, + 1, //COMPRESSED_BC4_RED, + 1, //COMPRESSED_BC5_XY, + + 1, //_LAST_COMPRESSED, + + 1, //R11G11B10, + + 1, //UNIFORM, + 1, //UNIFORM_BUFFER, + 1, //RESOURCE_BUFFER, + 1, //SAMPLER, + 1, //SAMPLER_MULTISAMPLE, + 1, //SAMPLER_SHADOW, }; // Element is a simple 16bit value that contains everything we need to know about an element @@ -206,7 +265,7 @@ public: bool isInteger() const { return TYPE_IS_INTEGER[getType()]; } uint8 getScalarCount() const { return SCALAR_COUNT[(Dimension)_dimension]; } - uint32 getSize() const { return SCALAR_COUNT[_dimension] * TYPE_SIZE[_type]; } + uint32 getSize() const { return (SCALAR_COUNT[_dimension] * TYPE_SIZE[_type] * SEMANTIC_SIZE_FACTOR[_semantic]); } uint8 getLocationCount() const { return LOCATION_COUNT[(Dimension)_dimension]; } uint8 getLocationScalarCount() const { return SCALAR_COUNT_PER_LOCATION[(Dimension)_dimension]; }