mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-29 01:30:08 +01:00
lvp: use stage iterator macros instead of explicit loops
This cleans up the compute checks Reviewed-by: Brian Paul <brianp@vmware.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23065>
This commit is contained in:
parent
7bd41840a4
commit
aedbc35857
4 changed files with 35 additions and 46 deletions
|
|
@ -98,7 +98,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDescriptorSetLayout(
|
|||
else
|
||||
set_layout->size += binding->descriptorCount;
|
||||
|
||||
for (gl_shader_stage stage = MESA_SHADER_VERTEX; stage < LVP_SHADER_STAGES; stage++) {
|
||||
lvp_forall_stage(stage) {
|
||||
set_layout->binding[b].stage[stage].const_buffer_index = -1;
|
||||
set_layout->binding[b].stage[stage].shader_buffer_index = -1;
|
||||
set_layout->binding[b].stage[stage].sampler_index = -1;
|
||||
|
|
@ -193,7 +193,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDescriptorSetLayout(
|
|||
VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
};
|
||||
for (unsigned i = 0; i < LVP_SHADER_STAGES; i++) {
|
||||
lvp_forall_stage(i) {
|
||||
uint16_t const_buffer_count = 0;
|
||||
uint16_t shader_buffer_count = 0;
|
||||
uint16_t sampler_count = 0;
|
||||
|
|
@ -237,7 +237,7 @@ lvp_pipeline_layout_create(struct lvp_device *device,
|
|||
const struct lvp_descriptor_set_layout *set_layout =
|
||||
vk_to_lvp_descriptor_set_layout(layout->vk.set_layouts[set]);
|
||||
|
||||
for (unsigned i = 0; i < LVP_SHADER_STAGES; i++) {
|
||||
lvp_forall_stage(i) {
|
||||
layout->stage[i].uniform_block_size += set_layout->stage[i].uniform_block_size;
|
||||
for (unsigned j = 0; j < set_layout->stage[i].uniform_block_count; j++) {
|
||||
assert(layout->stage[i].uniform_block_count + j < MAX_PER_STAGE_DESCRIPTOR_UNIFORM_BLOCKS * MAX_SETS);
|
||||
|
|
@ -257,7 +257,8 @@ lvp_pipeline_layout_create(struct lvp_device *device,
|
|||
VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
};
|
||||
for (unsigned i = 0; i < LVP_SHADER_STAGES; i++) {
|
||||
|
||||
lvp_forall_stage(i) {
|
||||
uint16_t const_buffer_count = 0;
|
||||
uint16_t shader_buffer_count = 0;
|
||||
uint16_t sampler_count = 0;
|
||||
|
|
@ -291,7 +292,7 @@ lvp_pipeline_layout_create(struct lvp_device *device,
|
|||
const VkPushConstantRange *range = pCreateInfo->pPushConstantRanges + i;
|
||||
layout->push_constant_size = MAX2(layout->push_constant_size,
|
||||
range->offset + range->size);
|
||||
layout->push_constant_stages |= (range->stageFlags & BITFIELD_MASK(LVP_SHADER_STAGES));
|
||||
layout->push_constant_stages |= (range->stageFlags & LVP_STAGE_MASK);
|
||||
}
|
||||
layout->push_constant_size = align(layout->push_constant_size, 16);
|
||||
return layout;
|
||||
|
|
@ -318,7 +319,7 @@ lvp_descriptor_set_create(struct lvp_device *device,
|
|||
struct lvp_descriptor_set *set;
|
||||
size_t base_size = sizeof(*set) + layout->size * sizeof(set->descriptors[0]);
|
||||
size_t size = base_size;
|
||||
for (unsigned i = 0; i < LVP_SHADER_STAGES; i++)
|
||||
lvp_forall_stage(i)
|
||||
size += layout->stage[i].uniform_block_size;
|
||||
set = vk_alloc(&device->vk.alloc /* XXX: Use the pool */, size, 8,
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||
|
|
|
|||
|
|
@ -527,9 +527,7 @@ static void emit_state(struct rendering_state *state)
|
|||
bool constbuf_dirty[LVP_SHADER_STAGES] = {false};
|
||||
bool pcbuf_dirty[LVP_SHADER_STAGES] = {false};
|
||||
|
||||
for (unsigned sh = 0; sh < LVP_SHADER_STAGES; sh++) {
|
||||
if (sh == MESA_SHADER_COMPUTE)
|
||||
continue;
|
||||
lvp_forall_gfx_stage(sh) {
|
||||
constbuf_dirty[sh] = state->constbuf_dirty[sh];
|
||||
if (state->constbuf_dirty[sh]) {
|
||||
for (unsigned idx = 0; idx < state->num_const_bufs[sh]; idx++)
|
||||
|
|
@ -539,24 +537,18 @@ static void emit_state(struct rendering_state *state)
|
|||
state->constbuf_dirty[sh] = false;
|
||||
}
|
||||
|
||||
for (unsigned sh = 0; sh < LVP_SHADER_STAGES; sh++) {
|
||||
if (sh == MESA_SHADER_COMPUTE)
|
||||
continue;
|
||||
lvp_forall_gfx_stage(sh) {
|
||||
pcbuf_dirty[sh] = state->pcbuf_dirty[sh];
|
||||
if (state->pcbuf_dirty[sh])
|
||||
update_pcbuf(state, sh);
|
||||
}
|
||||
|
||||
for (unsigned sh = 0; sh < LVP_SHADER_STAGES; sh++) {
|
||||
if (sh == MESA_SHADER_COMPUTE)
|
||||
continue;
|
||||
lvp_forall_gfx_stage(sh) {
|
||||
if (state->inlines_dirty[sh])
|
||||
update_inline_shader_state(state, sh, pcbuf_dirty[sh], constbuf_dirty[sh]);
|
||||
}
|
||||
|
||||
for (unsigned sh = 0; sh < LVP_SHADER_STAGES; sh++) {
|
||||
if (sh == MESA_SHADER_COMPUTE)
|
||||
continue;
|
||||
lvp_forall_gfx_stage(sh) {
|
||||
if (state->sb_dirty[sh]) {
|
||||
state->pctx->set_shader_buffers(state->pctx, sh,
|
||||
0, state->num_shader_buffers[sh],
|
||||
|
|
@ -564,9 +556,7 @@ static void emit_state(struct rendering_state *state)
|
|||
}
|
||||
}
|
||||
|
||||
for (unsigned sh = 0; sh < LVP_SHADER_STAGES; sh++) {
|
||||
if (sh == MESA_SHADER_COMPUTE)
|
||||
continue;
|
||||
lvp_forall_gfx_stage(sh) {
|
||||
if (state->iv_dirty[sh]) {
|
||||
state->pctx->set_shader_images(state->pctx, sh,
|
||||
0, state->num_shader_images[sh], 0,
|
||||
|
|
@ -574,9 +564,7 @@ static void emit_state(struct rendering_state *state)
|
|||
}
|
||||
}
|
||||
|
||||
for (unsigned sh = 0; sh < LVP_SHADER_STAGES; sh++) {
|
||||
if (sh == MESA_SHADER_COMPUTE)
|
||||
continue;
|
||||
lvp_forall_gfx_stage(sh) {
|
||||
if (state->sv_dirty[sh]) {
|
||||
state->pctx->set_sampler_views(state->pctx, sh, 0, state->num_sampler_views[sh],
|
||||
0, false, state->sv[sh]);
|
||||
|
|
@ -584,9 +572,7 @@ static void emit_state(struct rendering_state *state)
|
|||
}
|
||||
}
|
||||
|
||||
for (unsigned sh = 0; sh < LVP_SHADER_STAGES; sh++) {
|
||||
if (sh == MESA_SHADER_COMPUTE)
|
||||
continue;
|
||||
lvp_forall_gfx_stage(sh) {
|
||||
if (state->ss_dirty[sh]) {
|
||||
cso_set_samplers(state->cso, sh, state->num_sampler_states[sh], state->cso_ss_ptr[sh]);
|
||||
state->ss_dirty[sh] = false;
|
||||
|
|
@ -816,18 +802,14 @@ static void handle_graphics_pipeline(struct vk_cmd_queue_entry *cmd,
|
|||
lvp_pipeline_shaders_compile(pipeline);
|
||||
bool dynamic_tess_origin = BITSET_TEST(ps->dynamic, MESA_VK_DYNAMIC_TS_DOMAIN_ORIGIN);
|
||||
unbind_graphics_stages(state, (~pipeline->graphics_state.shader_stages) & VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
for (enum pipe_shader_type sh = MESA_SHADER_VERTEX; sh < LVP_SHADER_STAGES; sh++) {
|
||||
if (sh == MESA_SHADER_COMPUTE)
|
||||
continue;
|
||||
lvp_forall_gfx_stage(sh) {
|
||||
if (pipeline->graphics_state.shader_stages & mesa_to_vk_shader_stage(sh))
|
||||
state->shaders[sh] = &pipeline->shaders[sh];
|
||||
}
|
||||
|
||||
handle_graphics_stages(state, pipeline->graphics_state.shader_stages, dynamic_tess_origin);
|
||||
for (unsigned i = 0; i < LVP_SHADER_STAGES; i++) {
|
||||
if (i == MESA_SHADER_COMPUTE)
|
||||
continue;
|
||||
handle_graphics_layout(state, i, pipeline->layout);
|
||||
lvp_forall_gfx_stage(sh) {
|
||||
handle_graphics_layout(state, sh, pipeline->layout);
|
||||
}
|
||||
|
||||
/* rasterization state */
|
||||
|
|
@ -1147,10 +1129,8 @@ static void handle_pipeline(struct vk_cmd_queue_entry *cmd,
|
|||
handle_pipeline_access(state, MESA_SHADER_COMPUTE);
|
||||
} else {
|
||||
handle_graphics_pipeline(cmd, state);
|
||||
for (unsigned i = 0; i < LVP_SHADER_STAGES; i++) {
|
||||
if (i == MESA_SHADER_COMPUTE)
|
||||
continue;
|
||||
handle_pipeline_access(state, i);
|
||||
lvp_forall_gfx_stage(sh) {
|
||||
handle_pipeline_access(state, sh);
|
||||
}
|
||||
}
|
||||
state->push_size[pipeline->is_compute_pipeline] = pipeline->layout->push_constant_size;
|
||||
|
|
@ -1372,7 +1352,7 @@ static void increment_dyn_info(struct dyn_info *dyn_info,
|
|||
const struct lvp_descriptor_set_layout *layout =
|
||||
vk_to_lvp_descriptor_set_layout(vk_layout);
|
||||
|
||||
for (gl_shader_stage stage = MESA_SHADER_VERTEX; stage < LVP_SHADER_STAGES; stage++) {
|
||||
lvp_forall_stage(stage) {
|
||||
dyn_info->stage[stage].const_buffer_count += layout->stage[stage].const_buffer_count;
|
||||
dyn_info->stage[stage].shader_buffer_count += layout->stage[stage].shader_buffer_count;
|
||||
dyn_info->stage[stage].sampler_count += layout->stage[stage].sampler_count;
|
||||
|
|
@ -4589,7 +4569,7 @@ VkResult lvp_execute_cmds(struct lvp_device *device,
|
|||
state->rs_state.scissor = true;
|
||||
state->rs_state.no_ms_sample_mask_out = true;
|
||||
|
||||
for (enum pipe_shader_type s = MESA_SHADER_VERTEX; s < LVP_SHADER_STAGES; s++) {
|
||||
lvp_forall_stage(s) {
|
||||
for (unsigned i = 0; i < ARRAY_SIZE(state->cso_ss_ptr[s]); i++)
|
||||
state->cso_ss_ptr[s][i] = &state->ss[s][i];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ shader_destroy(struct lvp_device *device, struct lvp_shader *shader)
|
|||
void
|
||||
lvp_pipeline_destroy(struct lvp_device *device, struct lvp_pipeline *pipeline)
|
||||
{
|
||||
for (unsigned i = 0; i < LVP_SHADER_STAGES; i++)
|
||||
lvp_forall_stage(i)
|
||||
shader_destroy(device, &pipeline->shaders[i]);
|
||||
|
||||
if (pipeline->layout)
|
||||
|
|
@ -835,9 +835,7 @@ lvp_graphics_pipeline_init(struct lvp_pipeline *pipeline,
|
|||
pipeline->disable_multisample = p->disable_multisample;
|
||||
pipeline->line_rectangular = p->line_rectangular;
|
||||
memcpy(pipeline->shaders, p->shaders, sizeof(struct lvp_shader) * 4);
|
||||
for (unsigned i = 0; i < LVP_SHADER_STAGES; i++) {
|
||||
if (i == MESA_SHADER_COMPUTE)
|
||||
continue;
|
||||
lvp_forall_gfx_stage(i) {
|
||||
copy_shader_sanitized(&pipeline->shaders[i], &p->shaders[i]);
|
||||
}
|
||||
}
|
||||
|
|
@ -910,8 +908,8 @@ lvp_graphics_pipeline_init(struct lvp_pipeline *pipeline,
|
|||
lvp_pipeline_nir_ref(&pipeline->shaders[MESA_SHADER_FRAGMENT].pipeline_nir, p->shaders[MESA_SHADER_FRAGMENT].pipeline_nir);
|
||||
}
|
||||
if (p->stages & VK_GRAPHICS_PIPELINE_LIBRARY_PRE_RASTERIZATION_SHADERS_BIT_EXT) {
|
||||
for (unsigned j = MESA_SHADER_VERTEX; j < LVP_SHADER_STAGES; j++) {
|
||||
if (j == MESA_SHADER_COMPUTE || j == MESA_SHADER_FRAGMENT)
|
||||
lvp_forall_gfx_stage(j) {
|
||||
if (j == MESA_SHADER_FRAGMENT)
|
||||
continue;
|
||||
if (p->shaders[j].pipeline_nir)
|
||||
lvp_pipeline_nir_ref(&pipeline->shaders[j].pipeline_nir, p->shaders[j].pipeline_nir);
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ void __lvp_finishme(const char *file, int line, const char *format, ...)
|
|||
|
||||
#define LVP_SHADER_STAGES MESA_SHADER_STAGES
|
||||
#define LVP_STAGE_MASK BITFIELD_MASK(LVP_SHADER_STAGES)
|
||||
#define LVP_STAGE_MASK_GFX (BITFIELD_MASK(LVP_SHADER_STAGES) & ~BITFIELD_BIT(MESA_SHADER_COMPUTE))
|
||||
|
||||
#define lvp_foreach_stage(stage, stage_bits) \
|
||||
for (gl_shader_stage stage, \
|
||||
|
|
@ -122,6 +123,15 @@ void __lvp_finishme(const char *file, int line, const char *format, ...)
|
|||
stage = ffs(__tmp) - 1, __tmp; \
|
||||
__tmp &= ~(1 << (stage)))
|
||||
|
||||
#define lvp_forall_stage(stage) \
|
||||
for (gl_shader_stage stage = MESA_SHADER_VERTEX; stage < LVP_SHADER_STAGES; stage++)
|
||||
|
||||
#define lvp_forall_gfx_stage(stage) \
|
||||
for (gl_shader_stage stage, \
|
||||
__tmp = (gl_shader_stage)(LVP_STAGE_MASK_GFX); \
|
||||
stage = ffs(__tmp) - 1, __tmp; \
|
||||
__tmp &= ~(1 << (stage)))
|
||||
|
||||
struct lvp_physical_device {
|
||||
struct vk_physical_device vk;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue