Shader:getLocalWorkgroupSize;

This commit is contained in:
bjorn 2022-07-09 23:39:03 -07:00
parent 886bfe18c1
commit 8e89026678
5 changed files with 42 additions and 0 deletions

View File

@ -64,10 +64,27 @@ static int l_lovrShaderHasAttribute(lua_State* L) {
return 1;
}
static int l_lovrShaderGetLocalWorkgroupSize(lua_State* L) {
Shader* shader = luax_checktype(L, 1, Shader);
if (!lovrShaderHasStage(shader, STAGE_COMPUTE)) {
lua_pushnil(L);
return 1;
}
uint32_t size[3];
lovrShaderGetLocalWorkgroupSize(shader, size);
lua_pushinteger(L, size[0]);
lua_pushinteger(L, size[1]);
lua_pushinteger(L, size[2]);
return 3;
}
const luaL_Reg lovrShader[] = {
{ "clone", l_lovrShaderClone },
{ "getType", l_lovrShaderGetType },
{ "hasStage", l_lovrShaderHasStage },
{ "hasAttribute", l_lovrShaderHasAttribute },
{ "getLocalWorkgroupSize", l_lovrShaderGetLocalWorkgroupSize },
{ NULL, NULL }
};

View File

@ -49,6 +49,7 @@ typedef struct {
#define OP_LENGTH(op) (op[0] >> 16)
static spv_result spv_parse_capability(spv_context* spv, const uint32_t* op, spv_info* info);
static spv_result spv_parse_execution_mode(spv_context* spv, const uint32_t* op, spv_info* info);
static spv_result spv_parse_name(spv_context* spv, const uint32_t* op, spv_info* info);
static spv_result spv_parse_decoration(spv_context* spv, const uint32_t* op, spv_info* info);
static spv_result spv_parse_type(spv_context* spv, const uint32_t* op, spv_info* info);
@ -104,6 +105,8 @@ spv_result spv_parse(const void* source, uint32_t size, spv_info* info) {
case 17: // OpCapability
result = spv_parse_capability(&spv, op, info);
break;
case 16: // OpExecutionMode
result = spv_parse_execution_mode(&spv, op, info);
case 5: // OpName
result = spv_parse_name(&spv, op, info);
break;
@ -179,6 +182,17 @@ static spv_result spv_parse_capability(spv_context* spv, const uint32_t* op, spv
return SPV_OK;
}
static spv_result spv_parse_execution_mode(spv_context* spv, const uint32_t* op, spv_info* info) {
if (OP_LENGTH(op) != 6 || op[2] != 17) { // LocalSize
return SPV_OK;
}
info->localWorkgroupSize[0] = op[3];
info->localWorkgroupSize[1] = op[4];
info->localWorkgroupSize[2] = op[5];
return SPV_OK;
}
static spv_result spv_parse_name(spv_context* spv, const uint32_t* op, spv_info* info) {
if (OP_LENGTH(op) < 3 || op[1] > spv->bound) {
return SPV_INVALID;

View File

@ -56,6 +56,7 @@ typedef struct {
typedef struct {
uint32_t version;
uint32_t localWorkgroupSize[3];
uint32_t featureCount;
uint32_t specConstantCount;
uint32_t pushConstantCount;

View File

@ -105,6 +105,7 @@ struct Shader {
ShaderInfo info;
uint32_t layout;
uint32_t computePipeline;
uint32_t localWorkgroupSize[3];
uint32_t bufferMask;
uint32_t textureMask;
uint32_t samplerMask;
@ -1505,6 +1506,10 @@ Shader* lovrShaderCreate(ShaderInfo* info) {
checkShaderFeatures(spv[i].features, spv[i].featureCount);
}
if (info->type == SHADER_COMPUTE) {
memcpy(shader->localWorkgroupSize, spv[0].localWorkgroupSize, 3 * sizeof(uint32_t));
}
uint32_t constantStage = spv[0].pushConstantSize > spv[1].pushConstantSize ? 0 : 1;
uint32_t maxFlags = spv[0].specConstantCount + spv[1].specConstantCount;
shader->constantCount = spv[constantStage].pushConstantCount;
@ -1764,6 +1769,10 @@ bool lovrShaderHasAttribute(Shader* shader, const char* name, uint32_t location)
return false;
}
void lovrShaderGetLocalWorkgroupSize(Shader* shader, uint32_t size[3]) {
memcpy(size, shader->localWorkgroupSize, 3 * sizeof(uint32_t));
}
// Material
Material* lovrMaterialCreate(MaterialInfo* info) {

View File

@ -304,6 +304,7 @@ void lovrShaderDestroy(void* ref);
const ShaderInfo* lovrShaderGetInfo(Shader* shader);
bool lovrShaderHasStage(Shader* shader, ShaderStage stage);
bool lovrShaderHasAttribute(Shader* shader, const char* name, uint32_t location);
void lovrShaderGetLocalWorkgroupSize(Shader* shader, uint32_t size[3]);
// Material