1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-02 20:43:35 +00:00

Make builtin layouts constant instead of variable;

This commit is contained in:
bjorn 2023-04-14 21:27:47 -07:00
parent 70e5a69576
commit 56851fd0f2

View file

@ -29,6 +29,8 @@ const char** os_vk_get_instance_extensions(uint32_t* count);
#define MAX_PIPELINES 4 #define MAX_PIPELINES 4
#define MAX_SHADER_RESOURCES 32 #define MAX_SHADER_RESOURCES 32
#define MAX_CUSTOM_ATTRIBUTES 10 #define MAX_CUSTOM_ATTRIBUTES 10
#define LAYOUT_BUILTIN 0
#define LAYOUT_MATERIAL 1
#define FLOAT_BITS(f) ((union { float f; uint32_t u; }) { f }).u #define FLOAT_BITS(f) ((union { float f; uint32_t u; }) { f }).u
typedef struct { typedef struct {
@ -422,8 +424,6 @@ static struct {
map_t pipelineLookup; map_t pipelineLookup;
arr_t(gpu_pipeline*) pipelines; arr_t(gpu_pipeline*) pipelines;
arr_t(Layout) layouts; arr_t(Layout) layouts;
size_t builtinLayout;
size_t materialLayout;
Allocator allocator; Allocator allocator;
} state; } state;
@ -526,7 +526,8 @@ bool lovrGraphicsInit(GraphicsConfig* config) {
{ 3, GPU_SLOT_SAMPLER, GPU_STAGE_GRAPHICS } // Default sampler { 3, GPU_SLOT_SAMPLER, GPU_STAGE_GRAPHICS } // Default sampler
}; };
state.builtinLayout = getLayout(builtinSlots, COUNTOF(builtinSlots)); size_t builtinLayout = getLayout(builtinSlots, COUNTOF(builtinSlots));
if (builtinLayout != LAYOUT_BUILTIN) lovrUnreachable();
gpu_slot materialSlots[] = { gpu_slot materialSlots[] = {
{ 0, GPU_SLOT_UNIFORM_BUFFER, GPU_STAGE_GRAPHICS }, // Data { 0, GPU_SLOT_UNIFORM_BUFFER, GPU_STAGE_GRAPHICS }, // Data
@ -539,7 +540,8 @@ bool lovrGraphicsInit(GraphicsConfig* config) {
{ 7, GPU_SLOT_SAMPLED_TEXTURE, GPU_STAGE_GRAPHICS } // Normal { 7, GPU_SLOT_SAMPLED_TEXTURE, GPU_STAGE_GRAPHICS } // Normal
}; };
state.materialLayout = getLayout(materialSlots, COUNTOF(materialSlots)); size_t materialLayout = getLayout(materialSlots, COUNTOF(materialSlots));
if (materialLayout != LAYOUT_MATERIAL) lovrUnreachable();
float data[] = { 0.f, 0.f, 0.f, 0.f, 1.f, 1.f, 1.f, 1.f }; float data[] = { 0.f, 0.f, 0.f, 0.f, 1.f, 1.f, 1.f, 1.f };
@ -2071,8 +2073,8 @@ Shader* lovrShaderCreate(const ShaderInfo* info) {
} }
if (info->type == SHADER_GRAPHICS) { if (info->type == SHADER_GRAPHICS) {
gpu.layouts[0] = state.layouts.data[state.builtinLayout].gpu; gpu.layouts[0] = state.layouts.data[LAYOUT_BUILTIN].gpu;
gpu.layouts[1] = state.layouts.data[state.materialLayout].gpu; gpu.layouts[1] = state.layouts.data[LAYOUT_MATERIAL].gpu;
} }
gpu.layouts[userSet] = shader->resourceCount > 0 ? state.layouts.data[shader->layout].gpu : NULL; gpu.layouts[userSet] = shader->resourceCount > 0 ? state.layouts.data[shader->layout].gpu : NULL;
@ -2224,7 +2226,7 @@ Material* lovrMaterialCreate(const MaterialInfo* info) {
gpu_bundle_pool_info poolInfo = { gpu_bundle_pool_info poolInfo = {
.bundles = block->bundles, .bundles = block->bundles,
.layout = state.layouts.data[state.materialLayout].gpu, .layout = state.layouts.data[LAYOUT_MATERIAL].gpu,
.count = MATERIALS_PER_BLOCK .count = MATERIALS_PER_BLOCK
}; };
@ -2284,7 +2286,7 @@ Material* lovrMaterialCreate(const MaterialInfo* info) {
} }
gpu_bundle_info bundleInfo = { gpu_bundle_info bundleInfo = {
.layout = state.layouts.data[state.materialLayout].gpu, .layout = state.layouts.data[LAYOUT_MATERIAL].gpu,
.bindings = bindings, .bindings = bindings,
.count = COUNTOF(bindings) .count = COUNTOF(bindings)
}; };
@ -4669,12 +4671,12 @@ static void bindBundles(Pass* pass, Draw* draw, Shader* shader) {
if (builtinsDirty) { if (builtinsDirty) {
gpu_bundle_info bundleInfo = { gpu_bundle_info bundleInfo = {
.layout = state.layouts.data[state.builtinLayout].gpu, .layout = state.layouts.data[LAYOUT_BUILTIN].gpu,
.bindings = pass->builtins, .bindings = pass->builtins,
.count = COUNTOF(pass->builtins) .count = COUNTOF(pass->builtins)
}; };
bundles[0] = getBundle(state.builtinLayout); bundles[0] = getBundle(LAYOUT_BUILTIN);
gpu_bundle_write(&bundles[0], &bundleInfo, 1); gpu_bundle_write(&bundles[0], &bundleInfo, 1);
bundleMask |= (1 << 0); bundleMask |= (1 << 0);
} }