Tally/Readback cleanup;

This commit is contained in:
bjorn 2022-07-17 09:50:15 -07:00
parent faa690b7f0
commit 32346796ef
6 changed files with 25 additions and 12 deletions

View File

@ -680,6 +680,7 @@ static int l_lovrGraphicsGetFeatures(lua_State* L) {
lua_pushboolean(L, features.wireframe), lua_setfield(L, -2, "wireframe");
lua_pushboolean(L, features.depthClamp), lua_setfield(L, -2, "depthClamp");
lua_pushboolean(L, features.indirectDrawFirstInstance), lua_setfield(L, -2, "indirectDrawFirstInstance");
lua_pushboolean(L, features.stageTally), lua_setfield(L, -2, "stageTally");
lua_pushboolean(L, features.float64), lua_setfield(L, -2, "float64");
lua_pushboolean(L, features.int64), lua_setfield(L, -2, "int64");
lua_pushboolean(L, features.int16), lua_setfield(L, -2, "int16");

View File

@ -1,5 +1,6 @@
#include "api.h"
#include "graphics/graphics.h"
#include "data/blob.h"
#include "data/image.h"
#include "util.h"
#include <lua.h>
@ -35,7 +36,7 @@ static int l_lovrReadbackGetData(lua_State* L) {
int count = (int) info->tally.count;
if (lovrTallyGetInfo(info->tally.object)->type == TALLY_STAGE) {
count *= 6; // The number of pipeline statistics that are tracked
count *= 4; // The number of pipeline statistics that are tracked
}
lua_createtable(L, count, 0);
@ -49,9 +50,9 @@ static int l_lovrReadbackGetData(lua_State* L) {
}
static int l_lovrReadbackGetBlob(lua_State* L) {
//Readback* readback = luax_checktype(L, 1, Readback);
//void* data = lovrReadbackGetData(readback);
lua_pushnil(L);
Readback* readback = luax_checktype(L, 1, Readback);
Blob* blob = lovrReadbackGetBlob(readback);
luax_pushtype(L, Blob, blob);
return 1;
}

View File

@ -454,7 +454,7 @@ void gpu_pipeline_destroy(gpu_pipeline* pipeline);
typedef enum {
GPU_TALLY_TIMER,
GPU_TALLY_PIXEL,
GPU_TALLY_PIPELINE
GPU_TALLY_STAGE
} gpu_tally_type;
typedef struct {
@ -604,6 +604,7 @@ typedef struct {
bool wireframe;
bool depthClamp;
bool indirectDrawFirstInstance;
bool stageTally;
bool float64;
bool int64;
bool int16;

View File

@ -1367,14 +1367,14 @@ bool gpu_tally_init(gpu_tally* tally, gpu_tally_info* info) {
VkQueryType queryTypes[] = {
[GPU_TALLY_TIMER] = VK_QUERY_TYPE_TIMESTAMP,
[GPU_TALLY_PIXEL] = VK_QUERY_TYPE_OCCLUSION,
[GPU_TALLY_PIPELINE] = VK_QUERY_TYPE_PIPELINE_STATISTICS
[GPU_TALLY_STAGE] = VK_QUERY_TYPE_PIPELINE_STATISTICS
};
VkQueryPoolCreateInfo createInfo = {
.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,
.queryType = queryTypes[info->type],
.queryCount = info->count,
.pipelineStatistics = info->type == GPU_TALLY_PIPELINE ? (
.pipelineStatistics = info->type == GPU_TALLY_STAGE ? (
VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT |
VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT |
VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT |
@ -1865,7 +1865,6 @@ bool gpu_init(gpu_config* config) {
enable->shaderClipDistance = supports->shaderClipDistance;
enable->shaderCullDistance = supports->shaderCullDistance;
enable->largePoints = supports->largePoints;
enable->pipelineStatisticsQuery = supports->pipelineStatisticsQuery;
// Optional features (currently always enabled when supported)
config->features->textureBC = enable->textureCompressionBC = supports->textureCompressionBC;
@ -1873,6 +1872,7 @@ bool gpu_init(gpu_config* config) {
config->features->wireframe = enable->fillModeNonSolid = supports->fillModeNonSolid;
config->features->depthClamp = enable->depthClamp = supports->depthClamp;
config->features->indirectDrawFirstInstance = enable->drawIndirectFirstInstance = supports->drawIndirectFirstInstance;
config->features->stageTally = enable->pipelineStatisticsQuery = supports->pipelineStatisticsQuery;
config->features->float64 = enable->shaderFloat64 = supports->shaderFloat64;
config->features->int64 = enable->shaderInt64 = supports->shaderInt64;
config->features->int16 = enable->shaderInt16 = supports->shaderInt16;

View File

@ -222,6 +222,7 @@ struct Readback {
gpu_buffer* buffer;
void* pointer;
Image* image;
Blob* blob;
void* data;
};
@ -2734,6 +2735,7 @@ Readback* lovrReadbackCreate(const ReadbackInfo* info) {
readback->size = info->buffer.extent;
readback->data = malloc(readback->size);
lovrAssert(readback->data, "Out of memory");
readback->blob = lovrBlobCreate(readback->data, readback->size, "Readback");
break;
case READBACK_TEXTURE:
lovrRetain(info->texture.object);
@ -2743,10 +2745,11 @@ Readback* lovrReadbackCreate(const ReadbackInfo* info) {
break;
case READBACK_TALLY:
lovrRetain(info->tally.object);
uint32_t stride = info->tally.object->info.type == TALLY_STAGE ? 24 : 4;
uint32_t stride = info->tally.object->info.type == TALLY_STAGE ? 16 : 4;
readback->size = info->tally.count * stride;
readback->data = malloc(readback->size);
lovrAssert(readback->data, "Out of memory");
readback->blob = lovrBlobCreate(readback->data, readback->size, "Readback");
break;
}
@ -2773,7 +2776,7 @@ void lovrReadbackDestroy(void* ref) {
case READBACK_TALLY: lovrRelease(readback->info.tally.object, lovrTallyDestroy); break;
}
lovrRelease(readback->image, lovrImageDestroy);
free(readback->data);
lovrRelease(readback->blob, lovrBlobDestroy);
free(readback);
}
@ -2803,6 +2806,10 @@ void* lovrReadbackGetData(Readback* readback) {
return lovrReadbackIsComplete(readback) ? readback->data : NULL;
}
Blob* lovrReadbackGetBlob(Readback* readback) {
return lovrReadbackIsComplete(readback) ? readback->blob : NULL;
}
Image* lovrReadbackGetImage(Readback* readback) {
return lovrReadbackIsComplete(readback) ? readback->image : NULL;
}
@ -2813,6 +2820,7 @@ Tally* lovrTallyCreate(const TallyInfo* info) {
lovrCheck(info->count > 0, "Tally count must be greater than zero");
lovrCheck(info->count <= 4096, "Maximum Tally count is 4096");
lovrCheck(info->views <= state.limits.renderSize[2], "Tally view count can not exceed the maximum view count");
lovrCheck(info->type != TALLY_STAGE || state.features.stageTally, "This GPU does not support the 'stage' Tally type");
Tally* tally = calloc(1, sizeof(Tally) + gpu_sizeof_tally());
lovrAssert(tally, "Out of memory");
tally->ref = 1;
@ -4864,7 +4872,7 @@ void lovrPassCopyTallyToBuffer(Pass* pass, Tally* tally, Buffer* buffer, uint32_
lovrTallyResolve(tally, srcIndex, count, buffer->gpu, dstOffset, pass->stream);
trackBuffer(pass, buffer, GPU_PHASE_SHADER_COMPUTE, GPU_CACHE_STORAGE_WRITE);
} else {
uint32_t stride = tally->info.type == TALLY_STAGE ? 24 : 4;
uint32_t stride = tally->info.type == TALLY_STAGE ? 16 : 4;
gpu_copy_tally_buffer(pass->stream, tally->gpu, buffer->gpu, srcIndex, dstOffset, count, stride);
trackBuffer(pass, buffer, GPU_PHASE_TRANSFER, GPU_CACHE_TRANSFER_WRITE);
}
@ -5005,7 +5013,7 @@ Readback* lovrPassReadTally(Pass* pass, Tally* tally, uint32_t index, uint32_t c
if (tally->info.type == TALLY_TIMER) {
lovrTallyResolve(tally, index, count, readback->buffer, 0, pass->stream);
} else {
uint32_t stride = tally->info.type == TALLY_STAGE ? 24 : 4;
uint32_t stride = tally->info.type == TALLY_STAGE ? 16 : 4;
gpu_copy_tally_buffer(pass->stream, tally->gpu, readback->buffer, index, 0, count, stride);
}

View File

@ -35,6 +35,7 @@ typedef struct {
bool wireframe;
bool depthClamp;
bool indirectDrawFirstInstance;
bool stageTally;
bool float64;
bool int64;
bool int16;
@ -462,6 +463,7 @@ const ReadbackInfo* lovrReadbackGetInfo(Readback* readback);
bool lovrReadbackIsComplete(Readback* readback);
bool lovrReadbackWait(Readback* readback);
void* lovrReadbackGetData(Readback* readback);
struct Blob* lovrReadbackGetBlob(Readback* readback);
struct Image* lovrReadbackGetImage(Readback* readback);
// Tally