mirror of https://github.com/bjornbytes/lovr.git
Use push constant instead of BaseInstance for DrawID;
This is a little slower, but means indirect draws can use Transform and Color. There are other solutions for this. For example LÖVR could reserve BaseInstance and use a compute shader to rewrite indirect buffers. For now we choose to be correct and a little slower.
This commit is contained in:
parent
875a7f8237
commit
81ef58d032
|
@ -63,6 +63,10 @@ layout(set = 1, binding = 4) uniform texture2D RoughnessTexture;
|
|||
layout(set = 1, binding = 5) uniform texture2D ClearcoatTexture;
|
||||
layout(set = 1, binding = 6) uniform texture2D OcclusionTexture;
|
||||
layout(set = 1, binding = 7) uniform texture2D NormalTexture;
|
||||
|
||||
layout(push_constant) uniform PushConstants {
|
||||
uint DrawID;
|
||||
};
|
||||
#endif
|
||||
|
||||
// Attributes
|
||||
|
@ -116,7 +120,7 @@ layout(location = 14) in vec4 Tangent;
|
|||
#define BaseInstance gl_BaseInstance
|
||||
#define BaseVertex gl_BaseVertex
|
||||
#define DrawIndex gl_DrawIndex
|
||||
#define InstanceIndex (gl_InstanceIndex - gl_BaseInstance)
|
||||
#define InstanceIndex gl_InstanceIndex
|
||||
#define PointSize gl_PointSize
|
||||
#define Position gl_Position
|
||||
#define VertexIndex gl_VertexIndex
|
||||
|
@ -156,7 +160,6 @@ layout(location = 14) in vec4 Tangent;
|
|||
#endif
|
||||
|
||||
#ifdef GL_VERTEX_SHADER
|
||||
#define DrawID gl_BaseInstance
|
||||
#define Transform mat4(Draws[DrawID].transform)
|
||||
#define NormalMatrix (cofactor3(Draws[DrawID].transform))
|
||||
#define PassColor Draws[DrawID].color
|
||||
|
|
|
@ -1451,6 +1451,9 @@ static void recordRenderPass(Pass* pass, gpu_stream* stream) {
|
|||
indexBuffer = draw->indexBuffer;
|
||||
}
|
||||
|
||||
uint32_t drawId = i & 0xff;
|
||||
gpu_push_constants(stream, draw->shader->gpu, &drawId, sizeof(drawId));
|
||||
|
||||
if (draw->flags & DRAW_INDIRECT) {
|
||||
if (draw->indexBuffer) {
|
||||
gpu_draw_indirect_indexed(stream, draw->indirect.buffer, draw->indirect.offset, draw->indirect.count, draw->indirect.stride);
|
||||
|
@ -1459,9 +1462,9 @@ static void recordRenderPass(Pass* pass, gpu_stream* stream) {
|
|||
}
|
||||
} else {
|
||||
if (draw->indexBuffer) {
|
||||
gpu_draw_indexed(stream, draw->count, draw->instances, draw->start, draw->baseVertex, i & 0xff);
|
||||
gpu_draw_indexed(stream, draw->count, draw->instances, draw->start, draw->baseVertex, 0);
|
||||
} else {
|
||||
gpu_draw(stream, draw->count, draw->instances, draw->start, i & 0xff);
|
||||
gpu_draw(stream, draw->count, draw->instances, draw->start, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue