Fix push constants;

This commit is contained in:
bjorn 2022-07-01 18:34:31 -07:00
parent d9d54ce348
commit 56a9d81254
2 changed files with 28 additions and 3 deletions

View File

@ -500,10 +500,35 @@ static spv_result spv_parse_push_constants(spv_context* spv, const uint32_t* op,
}
break;
case 72: // OpMemberDecorate
if (length < 5 || op[1] > spv->bound) {
if (op[1] > spv->bound) {
return SPV_INVALID;
} else if (op[1] == structure[1] && op[2] < info->pushConstantCount && op[3] == 35) { // Offset
} else if (length == 5 && op[1] == structure[1] && op[2] < info->pushConstantCount && op[3] == 35) { // Offset
info->pushConstants[op[2]].offset = op[4];
uint32_t size = 0;
switch (info->pushConstants[op[2]].type) {
case SPV_B32: size = 4; break;
case SPV_I32: size = 4; break;
case SPV_I32x2: size = 8; break;
case SPV_I32x3: size = 12; break;
case SPV_I32x4: size = 16; break;
case SPV_U32: size = 4; break;
case SPV_U32x2: size = 8; break;
case SPV_U32x3: size = 12; break;
case SPV_U32x4: size = 16; break;
case SPV_F32: size = 4; break;
case SPV_F32x2: size = 8; break;
case SPV_F32x3: size = 12; break;
case SPV_F32x4: size = 16; break;
case SPV_MAT2: size = 16; break;
case SPV_MAT3: size = 36; break;
case SPV_MAT4: size = 64; break;
default: break;
}
if (info->pushConstantSize < op[4] + size) {
info->pushConstantSize = op[4] + size;
}
}
break;
case 59: // OpVariable, can exit

View File

@ -1433,7 +1433,6 @@ Shader* lovrShaderCreate(ShaderInfo* info) {
lovrAssert(shader->constants && shader->resources && shader->attributes, "Out of memory");
lovrAssert(shader->flags && shader->flagLookup, "Out of memory");
// Push constants
for (uint32_t i = 0; i < spv[constantStage].pushConstantCount; i++) {
static const FieldType constantTypes[] = {
@ -2828,6 +2827,7 @@ void lovrPassSendValue(Pass* pass, const char* name, size_t length, void** data,
*data = (char*) pass->constants + shader->constants[i].offset;
*type = shader->constants[i].type;
pass->constantsDirty = true;
return;
}
}