Fixed the code path with tseparate vertex format, still broken otherwise in the case of primitive instanced

This commit is contained in:
samcake 2015-09-23 15:20:39 -07:00
parent acfb5a32bc
commit 83116fdd85
5 changed files with 54 additions and 24 deletions

View file

@ -120,7 +120,28 @@ public:
void setIndexBuffer(Type type, const BufferPointer& buffer, Offset offset);
void setIndexBuffer(const BufferView& buffer); // not a command, just a shortcut from a BufferView
// Indirect buffer is used by the multiDrawXXXIndirect calls
// The indirect buffer contains the command descriptions to execute multiple drawcalls in a single call
void setIndirectBuffer(const BufferPointer& buffer, Offset offset = 0, Offset stride = 0);
// multi command desctription for multiDrawIndexedIndirect
class DrawIndirectCommand {
public:
uint _count{ 0 };
uint _instanceCount{ 0 };
uint _firstIndex{ 0 };
uint _baseInstance{ 0 };
};
// multi command desctription for multiDrawIndexedIndirect
class DrawIndexedIndirectCommand {
public:
uint _count{ 0 };
uint _instanceCount{ 0 };
uint _firstIndex{ 0 };
uint _baseVertex{ 0 };
uint _baseInstance{ 0 };
};
// Transform Stage
// Vertex position is transformed by ModelTransform from object space to world space

View file

@ -130,8 +130,8 @@ static const int LOCATION_COUNT[NUM_DIMENSIONS] = {
4,
};
// Count (of scalars) in an Element for a given Dimension
static const int DIMENSION_COUNT[NUM_DIMENSIONS] = {
// Count (of scalars) in an Element for a given Dimension's location
static const int SCALAR_COUNT_PER_LOCATION[NUM_DIMENSIONS] = {
1,
2,
3,
@ -141,6 +141,17 @@ static const int DIMENSION_COUNT[NUM_DIMENSIONS] = {
4,
};
// Count (of scalars) in an Element for a given Dimension
static const int SCALAR_COUNT[NUM_DIMENSIONS] = {
1,
2,
3,
4,
4,
9,
16,
};
// Semantic of an Element
// Provide information on how to use the element
enum Semantic {
@ -194,14 +205,18 @@ public:
Semantic getSemantic() const { return (Semantic)_semantic; }
Dimension getDimension() const { return (Dimension)_dimension; }
uint8 getDimensionCount() const { return DIMENSION_COUNT[(Dimension)_dimension]; }
uint8 getLocationCount() const { return LOCATION_COUNT[(Dimension)_dimension]; }
Type getType() const { return (Type)_type; }
bool isNormalized() const { return (getType() >= NORMALIZED_START); }
bool isInteger() const { return TYPE_IS_INTEGER[getType()]; }
uint32 getSize() const { return DIMENSION_COUNT[_dimension] * TYPE_SIZE[_type]; }
uint8 getScalarCount() const { return SCALAR_COUNT[(Dimension)_dimension]; }
uint32 getSize() const { return SCALAR_COUNT[_dimension] * TYPE_SIZE[_type]; }
uint8 getLocationCount() const { return LOCATION_COUNT[(Dimension)_dimension]; }
uint8 getLocationScalarCount() const { return SCALAR_COUNT_PER_LOCATION[(Dimension)_dimension]; }
uint32 getLocationSize() const { return SCALAR_COUNT_PER_LOCATION[_dimension] * TYPE_SIZE[_type]; }
uint16 getRaw() const { return *((uint16*) (this)); }

View file

@ -88,11 +88,11 @@ void GLBackend::syncInputStateCache() {
// Core 41 doesn't expose the features to really separate the vertex format from the vertex buffers binding
// Core 43 does :)
#if (GPU_INPUT_PROFILE == GPU_CORE_41)
//#if (GPU_INPUT_PROFILE == GPU_CORE_41)
#define NO_SUPPORT_VERTEX_ATTRIB_FORMAT
#else
/*#else
#define SUPPORT_VERTEX_ATTRIB_FORMAT
#endif
#endif*/
void GLBackend::updateInput() {
#if defined(SUPPORT_VERTEX_ATTRIB_FORMAT)
@ -106,17 +106,18 @@ void GLBackend::updateInput() {
const Stream::Attribute& attrib = (it).second;
GLuint slot = attrib._slot;
GLuint count = attrib._element.getDimensionCount();
GLuint count = attrib._element.getLocationScalarCount();
uint8_t locationCount = attrib._element.getLocationCount();
GLenum type = _elementTypeToGLType[attrib._element.getType()];
GLuint offset = attrib._offset;;
GLboolean isNormalized = attrib._element.isNormalized();
GLenum perLocationSize = attrib._element.getLocationSize();
for (int j = 0; j < locationCount; ++j) {
newActivation.set(slot + j);
glVertexAttribFormat(slot + j, count, type, isNormalized, offset);
glVertexAttribFormat(slot + j, count, type, isNormalized, offset + j * perLocationSize);
glVertexAttribDivisor(slot + j, attrib._frequency);
glVertexAttribBinding(slot + j, attrib._channel);
}
}
@ -225,11 +226,12 @@ void GLBackend::updateInput() {
for (unsigned int i = 0; i < channel._slots.size(); i++) {
const Stream::Attribute& attrib = attributes.at(channel._slots[i]);
GLuint slot = attrib._slot;
GLuint count = attrib._element.getDimensionCount();
GLuint count = attrib._element.getLocationScalarCount();
uint8_t locationCount = attrib._element.getLocationCount();
GLenum type = _elementTypeToGLType[attrib._element.getType()];
GLenum perLocationStride = strides[bufferNum];
GLuint stride = perLocationStride * locationCount;
// GLenum perLocationStride = strides[bufferNum];
GLenum perLocationStride = attrib._element.getLocationSize();
GLuint stride = strides[bufferNum];
GLuint pointer = attrib._offset + offsets[bufferNum];
GLboolean isNormalized = attrib._element.isNormalized();

View file

@ -629,7 +629,7 @@ bool sphericalHarmonicsFromTexture(const gpu::Texture& cubeTexture, std::vector<
// for each face of cube texture
for(int face=0; face < gpu::Texture::NUM_CUBE_FACES; face++) {
auto numComponents = cubeTexture.accessStoredMipFace(0,face)->_format.getDimensionCount();
auto numComponents = cubeTexture.accessStoredMipFace(0,face)->_format.getScalarCount();
auto data = cubeTexture.accessStoredMipFace(0,face)->_sysmem.readData();
if (data == nullptr) {
continue;

View file

@ -102,14 +102,6 @@ float getSeconds(quint64 start = 0) {
return seconds;
}
struct DrawElementsIndirectCommand {
uint _count{ 0 };
uint _instanceCount{ 0 };
uint _firstIndex{ 0 };
uint _baseVertex{ 0 };
uint _baseInstance{ 0 };
};
static const size_t TYPE_COUNT = 4;
static GeometryCache::Shape SHAPE[TYPE_COUNT] = {
GeometryCache::Icosahedron,
@ -300,7 +292,7 @@ public:
GeometryCache::Shape shape = SHAPE[i];
GeometryCache::ShapeData shapeData = geometryCache->_shapes[shape];
{
DrawElementsIndirectCommand indirectCommand;
gpu::Batch::DrawIndexedIndirectCommand indirectCommand;
indirectCommand._count = shapeData._indexCount;
indirectCommand._instanceCount = ITEM_COUNT;
indirectCommand._baseInstance = i * ITEM_COUNT;