Add integer vectors to GrSLType
BUG=skia: Change-Id: I4a4a50e214f2240d83f6f0b02cf43e695c067933 Reviewed-on: https://skia-review.googlesource.com/8122 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
parent
119fb2b950
commit
b37cb236c3
@ -54,6 +54,9 @@ enum GrSLType {
|
||||
kVec2f_GrSLType,
|
||||
kVec3f_GrSLType,
|
||||
kVec4f_GrSLType,
|
||||
kVec2i_GrSLType,
|
||||
kVec3i_GrSLType,
|
||||
kVec4i_GrSLType,
|
||||
kMat22f_GrSLType,
|
||||
kMat33f_GrSLType,
|
||||
kMat44f_GrSLType,
|
||||
@ -133,6 +136,9 @@ static inline bool GrSLTypeIsFloatType(GrSLType type) {
|
||||
case kBool_GrSLType:
|
||||
case kInt_GrSLType:
|
||||
case kUint_GrSLType:
|
||||
case kVec2i_GrSLType:
|
||||
case kVec3i_GrSLType:
|
||||
case kVec4i_GrSLType:
|
||||
case kTexture2D_GrSLType:
|
||||
case kSampler_GrSLType:
|
||||
case kImageStorage2D_GrSLType:
|
||||
@ -156,6 +162,9 @@ static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) {
|
||||
case kVec2f_GrSLType:
|
||||
case kVec3f_GrSLType:
|
||||
case kVec4f_GrSLType:
|
||||
case kVec2i_GrSLType:
|
||||
case kVec3i_GrSLType:
|
||||
case kVec4i_GrSLType:
|
||||
case kMat22f_GrSLType:
|
||||
case kMat33f_GrSLType:
|
||||
case kMat44f_GrSLType:
|
||||
@ -187,6 +196,9 @@ static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
|
||||
case kVec2f_GrSLType:
|
||||
case kVec3f_GrSLType:
|
||||
case kVec4f_GrSLType:
|
||||
case kVec2i_GrSLType:
|
||||
case kVec3i_GrSLType:
|
||||
case kVec4i_GrSLType:
|
||||
case kMat22f_GrSLType:
|
||||
case kMat33f_GrSLType:
|
||||
case kMat44f_GrSLType:
|
||||
@ -214,6 +226,9 @@ static inline bool GrSLTypeIsImageStorage(GrSLType type) {
|
||||
case kVec2f_GrSLType:
|
||||
case kVec3f_GrSLType:
|
||||
case kVec4f_GrSLType:
|
||||
case kVec2i_GrSLType:
|
||||
case kVec3i_GrSLType:
|
||||
case kVec4i_GrSLType:
|
||||
case kMat22f_GrSLType:
|
||||
case kMat33f_GrSLType:
|
||||
case kMat44f_GrSLType:
|
||||
@ -241,6 +256,9 @@ static inline bool GrSLTypeAcceptsPrecision(GrSLType type) {
|
||||
case kVec2f_GrSLType:
|
||||
case kVec3f_GrSLType:
|
||||
case kVec4f_GrSLType:
|
||||
case kVec2i_GrSLType:
|
||||
case kVec3i_GrSLType:
|
||||
case kVec4i_GrSLType:
|
||||
case kMat22f_GrSLType:
|
||||
case kMat33f_GrSLType:
|
||||
case kMat44f_GrSLType:
|
||||
@ -274,6 +292,10 @@ enum GrVertexAttribType {
|
||||
kVec3f_GrVertexAttribType,
|
||||
kVec4f_GrVertexAttribType,
|
||||
|
||||
kVec2i_GrVertexAttribType, // vector of 2 32-bit ints
|
||||
kVec3i_GrVertexAttribType, // vector of 3 32-bit ints
|
||||
kVec4i_GrVertexAttribType, // vector of 4 32-bit ints
|
||||
|
||||
kUByte_GrVertexAttribType, // unsigned byte, e.g. coverage
|
||||
kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
|
||||
|
||||
@ -300,6 +322,12 @@ static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
|
||||
return 3*sizeof(float);
|
||||
case kVec4f_GrVertexAttribType:
|
||||
return 4*sizeof(float);
|
||||
case kVec2i_GrVertexAttribType:
|
||||
return 2*sizeof(int32_t);
|
||||
case kVec3i_GrVertexAttribType:
|
||||
return 3*sizeof(int32_t);
|
||||
case kVec4i_GrVertexAttribType:
|
||||
return 4*sizeof(int32_t);
|
||||
case kUByte_GrVertexAttribType:
|
||||
return 1*sizeof(char);
|
||||
case kVec4ub_GrVertexAttribType:
|
||||
@ -328,6 +356,12 @@ static inline bool GrVertexAttribTypeIsIntType(GrVertexAttribType type) {
|
||||
return false;
|
||||
case kVec4f_GrVertexAttribType:
|
||||
return false;
|
||||
case kVec2i_GrVertexAttribType:
|
||||
return true;
|
||||
case kVec3i_GrVertexAttribType:
|
||||
return true;
|
||||
case kVec4i_GrVertexAttribType:
|
||||
return true;
|
||||
case kUByte_GrVertexAttribType:
|
||||
return false;
|
||||
case kVec4ub_GrVertexAttribType:
|
||||
@ -359,6 +393,12 @@ static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) {
|
||||
case kVec4ub_GrVertexAttribType:
|
||||
case kVec4f_GrVertexAttribType:
|
||||
return kVec4f_GrSLType;
|
||||
case kVec2i_GrVertexAttribType:
|
||||
return kVec2i_GrSLType;
|
||||
case kVec3i_GrVertexAttribType:
|
||||
return kVec3i_GrSLType;
|
||||
case kVec4i_GrVertexAttribType:
|
||||
return kVec4i_GrSLType;
|
||||
case kInt_GrVertexAttribType:
|
||||
return kInt_GrSLType;
|
||||
case kUint_GrVertexAttribType:
|
||||
|
@ -95,6 +95,12 @@ static inline const char* GrGLSLTypeString(GrSLType t) {
|
||||
return "vec3";
|
||||
case kVec4f_GrSLType:
|
||||
return "vec4";
|
||||
case kVec2i_GrSLType:
|
||||
return "ivec2";
|
||||
case kVec3i_GrSLType:
|
||||
return "ivec3";
|
||||
case kVec4i_GrSLType:
|
||||
return "ivec4";
|
||||
case kMat22f_GrSLType:
|
||||
return "mat2";
|
||||
case kMat33f_GrSLType:
|
||||
|
@ -10,32 +10,43 @@
|
||||
#include "GrGLGpu.h"
|
||||
|
||||
struct AttribLayout {
|
||||
GrGLint fCount;
|
||||
GrGLenum fType;
|
||||
GrGLboolean fNormalized; // Only used by floating point types.
|
||||
bool fNormalized; // Only used by floating point types.
|
||||
uint8_t fCount;
|
||||
uint16_t fType;
|
||||
};
|
||||
|
||||
static const AttribLayout gLayouts[kGrVertexAttribTypeCount] = {
|
||||
{1, GR_GL_FLOAT, false}, // kFloat_GrVertexAttribType
|
||||
{2, GR_GL_FLOAT, false}, // kVec2f_GrVertexAttribType
|
||||
{3, GR_GL_FLOAT, false}, // kVec3f_GrVertexAttribType
|
||||
{4, GR_GL_FLOAT, false}, // kVec4f_GrVertexAttribType
|
||||
{1, GR_GL_UNSIGNED_BYTE, true}, // kUByte_GrVertexAttribType
|
||||
{4, GR_GL_UNSIGNED_BYTE, true}, // kVec4ub_GrVertexAttribType
|
||||
{2, GR_GL_UNSIGNED_SHORT, true}, // kVec2s_GrVertexAttribType
|
||||
{1, GR_GL_INT, false}, // kInt_GrVertexAttribType
|
||||
{1, GR_GL_UNSIGNED_INT, false}, // kUint_GrVertexAttribType
|
||||
};
|
||||
GR_STATIC_ASSERT(4 == sizeof(AttribLayout));
|
||||
|
||||
GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType);
|
||||
static AttribLayout attrib_layout(GrVertexAttribType type) {
|
||||
switch (type) {
|
||||
case kFloat_GrVertexAttribType:
|
||||
return {false, 1, GR_GL_FLOAT};
|
||||
case kVec2f_GrVertexAttribType:
|
||||
return {false, 2, GR_GL_FLOAT};
|
||||
case kVec3f_GrVertexAttribType:
|
||||
return {false, 3, GR_GL_FLOAT};
|
||||
case kVec4f_GrVertexAttribType:
|
||||
return {false, 4, GR_GL_FLOAT};
|
||||
case kVec2i_GrVertexAttribType:
|
||||
return {false, 2, GR_GL_INT};
|
||||
case kVec3i_GrVertexAttribType:
|
||||
return {false, 3, GR_GL_INT};
|
||||
case kVec4i_GrVertexAttribType:
|
||||
return {false, 4, GR_GL_INT};
|
||||
case kUByte_GrVertexAttribType:
|
||||
return {true, 1, GR_GL_UNSIGNED_BYTE};
|
||||
case kVec4ub_GrVertexAttribType:
|
||||
return {true, 4, GR_GL_UNSIGNED_BYTE};
|
||||
case kVec2us_GrVertexAttribType:
|
||||
return {true, 2, GR_GL_UNSIGNED_SHORT};
|
||||
case kInt_GrVertexAttribType:
|
||||
return {false, 1, GR_GL_INT};
|
||||
case kUint_GrVertexAttribType:
|
||||
return {false, 1, GR_GL_UNSIGNED_INT};
|
||||
}
|
||||
SkFAIL("Unknown vertex attrib type");
|
||||
return {false, 0, 0};
|
||||
};
|
||||
|
||||
void GrGLAttribArrayState::set(GrGLGpu* gpu,
|
||||
int index,
|
||||
@ -55,7 +66,7 @@ void GrGLAttribArrayState::set(GrGLGpu* gpu,
|
||||
array->fStride != stride ||
|
||||
array->fOffset != offset) {
|
||||
gpu->bindBuffer(kVertex_GrBufferType, vertexBuffer);
|
||||
const AttribLayout& layout = gLayouts[type];
|
||||
const AttribLayout& layout = attrib_layout(type);
|
||||
if (!GrVertexAttribTypeIsIntType(type)) {
|
||||
GR_GL_CALL(gpu->glInterface(), VertexAttribPointer(index,
|
||||
layout.fCount,
|
||||
|
@ -14,26 +14,35 @@
|
||||
#include "GrVkRenderTarget.h"
|
||||
#include "GrVkUtil.h"
|
||||
|
||||
static inline const VkFormat& attrib_type_to_vkformat(GrVertexAttribType type) {
|
||||
SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount);
|
||||
static const VkFormat kFormats[kGrVertexAttribTypeCount] = {
|
||||
VK_FORMAT_R32_SFLOAT, // kFloat_GrVertexAttribType
|
||||
VK_FORMAT_R32G32_SFLOAT, // kVec2f_GrVertexAttribType
|
||||
VK_FORMAT_R32G32B32_SFLOAT, // kVec3f_GrVertexAttribType
|
||||
VK_FORMAT_R32G32B32A32_SFLOAT, // kVec4f_GrVertexAttribType
|
||||
VK_FORMAT_R8_UNORM, // kUByte_GrVertexAttribType
|
||||
VK_FORMAT_R8G8B8A8_UNORM, // kVec4ub_GrVertexAttribType
|
||||
VK_FORMAT_R16G16_UNORM, // kVec2us_GrVertexAttribType
|
||||
};
|
||||
GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType);
|
||||
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFormats) == kGrVertexAttribTypeCount);
|
||||
return kFormats[type];
|
||||
static inline VkFormat attrib_type_to_vkformat(GrVertexAttribType type) {
|
||||
switch (type) {
|
||||
case kFloat_GrVertexAttribType:
|
||||
return VK_FORMAT_R32_SFLOAT;
|
||||
case kVec2f_GrVertexAttribType:
|
||||
return VK_FORMAT_R32G32_SFLOAT;
|
||||
case kVec3f_GrVertexAttribType:
|
||||
return VK_FORMAT_R32G32B32_SFLOAT;
|
||||
case kVec4f_GrVertexAttribType:
|
||||
return VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||
case kVec2i_GrVertexAttribType:
|
||||
return VK_FORMAT_R32G32_SINT;
|
||||
case kVec3i_GrVertexAttribType:
|
||||
return VK_FORMAT_R32G32B32_SINT;
|
||||
case kVec4i_GrVertexAttribType:
|
||||
return VK_FORMAT_R32G32B32A32_SINT;
|
||||
case kUByte_GrVertexAttribType:
|
||||
return VK_FORMAT_R8_UNORM;
|
||||
case kVec4ub_GrVertexAttribType:
|
||||
return VK_FORMAT_R8G8B8A8_UNORM;
|
||||
case kVec2us_GrVertexAttribType:
|
||||
return VK_FORMAT_R16G16_UNORM;
|
||||
case kInt_GrVertexAttribType:
|
||||
return VK_FORMAT_R32_SINT;
|
||||
case kUint_GrVertexAttribType:
|
||||
return VK_FORMAT_R32_UINT;
|
||||
}
|
||||
SkFAIL("Unknown vertex attrib type");
|
||||
return VK_FORMAT_UNDEFINED;
|
||||
}
|
||||
|
||||
static void setup_vertex_input_state(const GrPrimitiveProcessor& primProc,
|
||||
|
@ -28,6 +28,12 @@ uint32_t grsltype_to_alignment_mask(GrSLType type) {
|
||||
return 0xF;
|
||||
case kVec4f_GrSLType:
|
||||
return 0xF;
|
||||
case kVec2i_GrSLType:
|
||||
return 0x7;
|
||||
case kVec3i_GrSLType:
|
||||
return 0xF;
|
||||
case kVec4i_GrSLType:
|
||||
return 0xF;
|
||||
case kMat22f_GrSLType:
|
||||
return 0x7;
|
||||
case kMat33f_GrSLType:
|
||||
@ -59,9 +65,9 @@ uint32_t grsltype_to_alignment_mask(GrSLType type) {
|
||||
static inline uint32_t grsltype_to_vk_size(GrSLType type) {
|
||||
switch(type) {
|
||||
case kInt_GrSLType:
|
||||
return 4;
|
||||
return sizeof(int32_t);
|
||||
case kUint_GrSLType:
|
||||
return 4;
|
||||
return sizeof(int32_t);
|
||||
case kFloat_GrSLType:
|
||||
return sizeof(float);
|
||||
case kVec2f_GrSLType:
|
||||
@ -70,6 +76,12 @@ static inline uint32_t grsltype_to_vk_size(GrSLType type) {
|
||||
return 3 * sizeof(float);
|
||||
case kVec4f_GrSLType:
|
||||
return 4 * sizeof(float);
|
||||
case kVec2i_GrSLType:
|
||||
return 2 * sizeof(int32_t);
|
||||
case kVec3i_GrSLType:
|
||||
return 3 * sizeof(int32_t);
|
||||
case kVec4i_GrSLType:
|
||||
return 4 * sizeof(int32_t);
|
||||
case kMat22f_GrSLType:
|
||||
//TODO: this will be 4 * szof(float) on std430.
|
||||
return 8 * sizeof(float);
|
||||
|
@ -21,6 +21,12 @@ static inline int grsltype_to_location_size(GrSLType type) {
|
||||
return 1;
|
||||
case kVec4f_GrSLType:
|
||||
return 1;
|
||||
case kVec2i_GrSLType:
|
||||
return 1;
|
||||
case kVec3i_GrSLType:
|
||||
return 1;
|
||||
case kVec4i_GrSLType:
|
||||
return 1;
|
||||
case kMat22f_GrSLType:
|
||||
return 2;
|
||||
case kMat33f_GrSLType:
|
||||
|
Loading…
Reference in New Issue
Block a user