mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-27 10:30:08 +01:00
anv: move common shader code into header
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Reviewed-by: Ivan Briano <ivan.briano@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20497>
This commit is contained in:
parent
ac71719d4a
commit
b32303c369
5 changed files with 122 additions and 65 deletions
|
|
@ -161,6 +161,9 @@ compile_upload_spirv(struct anv_device *device,
|
|||
NIR_PASS_V(nir, nir_inline_functions);
|
||||
NIR_PASS_V(nir, nir_opt_deref);
|
||||
|
||||
/* Pick off the single entrypoint that we want */
|
||||
nir_remove_non_entrypoints(nir);
|
||||
|
||||
NIR_PASS_V(nir, nir_lower_vars_to_ssa);
|
||||
NIR_PASS_V(nir, nir_copy_prop);
|
||||
NIR_PASS_V(nir, nir_opt_dce);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
#define ANV_GENERATED_FLAG_INDEXED BITFIELD_BIT(0)
|
||||
#define ANV_GENERATED_FLAG_PREDICATED BITFIELD_BIT(1)
|
||||
|
||||
/* This needs to match gfx11_generated_draws.glsl :
|
||||
/* This needs to match common_generated_draws.glsl :
|
||||
*
|
||||
* layout(set = 0, binding = 2) uniform block
|
||||
*/
|
||||
|
|
|
|||
89
src/intel/vulkan/shaders/common_generated_draws.glsl
Normal file
89
src/intel/vulkan/shaders/common_generated_draws.glsl
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright © 2022 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#define BITFIELD_BIT(i) (1u << i)
|
||||
|
||||
#define ANV_GENERATED_FLAG_INDEXED BITFIELD_BIT(0)
|
||||
#define ANV_GENERATED_FLAG_PREDICATED BITFIELD_BIT(1)
|
||||
|
||||
/* These 2 bindings will be accessed through A64 messages */
|
||||
layout(set = 0, binding = 0, std430) buffer Storage0 {
|
||||
uint indirect_data[];
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 1, std430) buffer Storage1 {
|
||||
uint commands[];
|
||||
};
|
||||
|
||||
/* This data will be provided through push constants. */
|
||||
layout(set = 0, binding = 2) uniform block {
|
||||
uint64_t indirect_data_addr;
|
||||
uint indirect_data_stride;
|
||||
uint flags;
|
||||
uint draw_base;
|
||||
uint item_count;
|
||||
uint draw_count;
|
||||
uint max_draw_count;
|
||||
uint instance_multiplier;
|
||||
uint64_t end_addr;
|
||||
};
|
||||
|
||||
void write_3DPRIMITIVE_EXTENDED(uint write_offset,
|
||||
bool is_predicated,
|
||||
bool is_indexed,
|
||||
uint vertex_count_per_instance,
|
||||
uint start_vertex_location,
|
||||
uint instance_count,
|
||||
uint start_instance_location,
|
||||
uint base_vertex_location,
|
||||
uint param_base_vertex,
|
||||
uint param_base_instance,
|
||||
uint param_draw_id)
|
||||
{
|
||||
commands[write_offset + 0] = (3 << 29 | /* Command Type */
|
||||
3 << 27 | /* Command SubType */
|
||||
3 << 24 | /* 3D Command Opcode */
|
||||
1 << 11 | /* Extended Parameter Enable */
|
||||
uint(is_predicated) << 8 |
|
||||
8 << 0); /* DWord Length */
|
||||
commands[write_offset + 1] = uint(is_indexed) << 8;
|
||||
commands[write_offset + 2] = vertex_count_per_instance;
|
||||
commands[write_offset + 3] = start_vertex_location;
|
||||
commands[write_offset + 4] = instance_count;
|
||||
commands[write_offset + 5] = start_instance_location;
|
||||
commands[write_offset + 6] = base_vertex_location;
|
||||
commands[write_offset + 7] = param_base_vertex;
|
||||
commands[write_offset + 8] = param_base_instance;
|
||||
commands[write_offset + 9] = param_draw_id;
|
||||
}
|
||||
|
||||
void write_MI_BATCH_BUFFER_START(uint write_offset,
|
||||
uint64_t addr)
|
||||
{
|
||||
commands[write_offset + 0] = (0 << 29 | /* Command Type */
|
||||
49 << 23 | /* MI Command Opcode */
|
||||
1 << 8 | /* Address Space Indicator (PPGTT) */
|
||||
1 << 0); /* DWord Length */
|
||||
commands[write_offset + 1] = uint(addr & 0xffffffff);
|
||||
commands[write_offset + 2] = uint(addr >> 32);
|
||||
}
|
||||
|
|
@ -23,33 +23,9 @@
|
|||
|
||||
#version 450
|
||||
#extension GL_ARB_gpu_shader_int64 : enable
|
||||
#extension GL_GOOGLE_include_directive : enable
|
||||
|
||||
#define BITFIELD_BIT(i) (1u << (i))
|
||||
|
||||
#define ANV_GENERATED_FLAG_INDEXED BITFIELD_BIT(0)
|
||||
#define ANV_GENERATED_FLAG_PREDICATED BITFIELD_BIT(1)
|
||||
|
||||
/* These 2 bindings will be accessed through A64 messages */
|
||||
layout(set = 0, binding = 0, std430) buffer Storage0 {
|
||||
uint indirect_data[];
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 1, std430) buffer Storage1 {
|
||||
uint commands[];
|
||||
};
|
||||
|
||||
/* This data will be provided through push constants. */
|
||||
layout(set = 0, binding = 2) uniform block {
|
||||
uint64_t indirect_data_addr;
|
||||
uint indirect_data_stride;
|
||||
uint flags;
|
||||
uint draw_base;
|
||||
uint item_count;
|
||||
uint draw_count;
|
||||
uint max_draw_count;
|
||||
uint instance_multiplier;
|
||||
uint64_t end_addr;
|
||||
};
|
||||
#include "common_generated_draws.glsl"
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
@ -70,21 +46,17 @@ void main()
|
|||
uint vertex_offset = indirect_data[indirect_data_offset + 3];
|
||||
uint first_instance = indirect_data[indirect_data_offset + 4];
|
||||
|
||||
commands[cmd_idx + 0] = (3 << 29 | /* Command Type */
|
||||
3 << 27 | /* Command SubType */
|
||||
3 << 24 | /* 3D Command Opcode */
|
||||
1 << 11 | /* Extended Parameter Enable */
|
||||
uint(is_predicated) << 8 |
|
||||
8 << 0); /* DWord Length */
|
||||
commands[cmd_idx + 1] = 1 << 8; /* Indexed */
|
||||
commands[cmd_idx + 2] = index_count; /* Vertex Count Per Instance */
|
||||
commands[cmd_idx + 3] = first_index; /* Start Vertex Location */
|
||||
commands[cmd_idx + 4] = instance_count; /* Instance Count */
|
||||
commands[cmd_idx + 5] = first_instance; /* Start Instance Location */
|
||||
commands[cmd_idx + 6] = vertex_offset; /* Base Vertex Location */
|
||||
commands[cmd_idx + 7] = vertex_offset; /* gl_BaseVertex */
|
||||
commands[cmd_idx + 8] = first_instance; /* gl_BaseInstance */
|
||||
commands[cmd_idx + 9] = draw_id; /* gl_DrawID */
|
||||
write_3DPRIMITIVE_EXTENDED(cmd_idx,
|
||||
is_predicated,
|
||||
is_indexed,
|
||||
index_count,
|
||||
first_index,
|
||||
instance_count,
|
||||
first_instance,
|
||||
vertex_offset,
|
||||
vertex_offset,
|
||||
first_instance,
|
||||
draw_id);
|
||||
} else {
|
||||
/* Loading a VkDrawIndirectCommand structure */
|
||||
uint vertex_count = indirect_data[indirect_data_offset + 0];
|
||||
|
|
@ -92,31 +64,22 @@ void main()
|
|||
uint first_vertex = indirect_data[indirect_data_offset + 2];
|
||||
uint first_instance = indirect_data[indirect_data_offset + 3];
|
||||
|
||||
commands[cmd_idx + 0] = (3 << 29 | /* Command Type */
|
||||
3 << 27 | /* Command SubType */
|
||||
3 << 24 | /* 3D Command Opcode */
|
||||
1 << 11 | /* Extended Parameter Enable */
|
||||
uint(is_predicated) << 8 |
|
||||
8 << 0); /* DWord Length */
|
||||
commands[cmd_idx + 1] = 0;
|
||||
commands[cmd_idx + 2] = vertex_count; /* Vertex Count Per Instance */
|
||||
commands[cmd_idx + 3] = first_vertex; /* Start Vertex Location */
|
||||
commands[cmd_idx + 4] = instance_count; /* Instance Count */
|
||||
commands[cmd_idx + 5] = first_instance; /* Start Instance Location */
|
||||
commands[cmd_idx + 6] = 0; /* Base Vertex Location */
|
||||
commands[cmd_idx + 7] = first_vertex; /* gl_BaseVertex */
|
||||
commands[cmd_idx + 8] = first_instance; /* gl_BaseInstance */
|
||||
commands[cmd_idx + 9] = draw_id; /* gl_DrawID */
|
||||
write_3DPRIMITIVE_EXTENDED(cmd_idx,
|
||||
is_predicated,
|
||||
is_indexed,
|
||||
vertex_count,
|
||||
first_vertex,
|
||||
instance_count,
|
||||
first_instance,
|
||||
0 /* base_vertex_location */,
|
||||
first_vertex,
|
||||
first_instance,
|
||||
draw_id);
|
||||
}
|
||||
} else if (draw_id == draw_count && draw_id < max_draw_count) {
|
||||
/* Only write a jump forward in the batch if we have fewer elements than
|
||||
* the max draw count.
|
||||
*/
|
||||
commands[cmd_idx + 0] = (0 << 29 | /* Command Type */
|
||||
49 << 23 | /* MI Command Opcode */
|
||||
1 << 8 | /* Address Space Indicator (PPGTT) */
|
||||
1 << 0); /* DWord Length */
|
||||
commands[cmd_idx + 1] = uint(end_addr & 0xffffffff);
|
||||
commands[cmd_idx + 2] = uint(end_addr >> 32);
|
||||
write_MI_BATCH_BUFFER_START(cmd_idx, end_addr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,13 +34,15 @@ float64_spv_h = custom_target(
|
|||
|
||||
gfx11_generated_draws_spv_h = custom_target(
|
||||
'gfx11_generated_draws_spv.h',
|
||||
input : [glsl2spirv, 'gfx11_generated_draws.glsl'],
|
||||
input : [glsl2spirv, 'gfx11_generated_draws.glsl',
|
||||
files('common_generated_draws.glsl')],
|
||||
output : 'gfx11_generated_draws_spv.h',
|
||||
command : [
|
||||
prog_python, '@INPUT@', '@OUTPUT@',
|
||||
prog_python, '@INPUT0@', '@INPUT1@', '@OUTPUT@',
|
||||
prog_glslang,
|
||||
'--vn', 'gfx11_generated_draws_spv_source',
|
||||
'--glsl-version', '450',
|
||||
'--stage', 'frag',
|
||||
'-I' + meson.current_source_dir(),
|
||||
]
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue