#include "ir3_compiler.h"
#include "ir3_shader.h"
-static void ir3_setup_const_state(struct ir3_shader *shader, nir_shader *nir);
-
static const nir_shader_compiler_options options = {
.lower_fpow = true,
.lower_scmp = true,
* analysis.
*/
if (!key) {
- ir3_setup_const_state(shader, s);
+ ir3_setup_const_state(shader, s, &shader->const_state);
}
}
}
}
-static void
-ir3_setup_const_state(struct ir3_shader *shader, nir_shader *nir)
+/* Sets up the non-variant-dependent constant state for the ir3_shader. Note
+ * that it is also used from ir3_nir_analyze_ubo_ranges() to figure out the
+ * maximum number of driver params that would eventually be used, to leave
+ * space for this function to allocate the driver params.
+ */
+void
+ir3_setup_const_state(struct ir3_shader *shader, nir_shader *nir,
+ struct ir3_const_state *const_state)
{
struct ir3_compiler *compiler = shader->compiler;
- struct ir3_const_state *const_state = &shader->const_state;
memset(&const_state->offsets, ~0, sizeof(const_state->offsets));
}
const_state->offsets.immediate = constoff;
+
+ assert(constoff <= compiler->max_const);
}
void ir3_optimize_nir(struct ir3_shader *shader, nir_shader *s,
const struct ir3_shader_key *key);
+void ir3_setup_const_state(struct ir3_shader *shader, nir_shader *nir,
+ struct ir3_const_state *const_state);
+
bool ir3_nir_analyze_ubo_ranges(nir_shader *nir, struct ir3_shader *shader);
nir_ssa_def *
* dynamically accessed ranges separately and upload static rangtes
* first.
*/
- const uint32_t max_upload = shader->compiler->max_const * 16;
+
+ /* Limit our uploads to the amount of constant buffer space available in
+ * the hardware, minus what the shader compiler may need for various
+ * driver params. We do this UBO-to-push-constant before the real
+ * allocation of the driver params' const space, because UBO pointers can
+ * be driver params but this pass usually eliminatings them.
+ */
+ struct ir3_const_state worst_case_const_state = { };
+ ir3_setup_const_state(shader, nir, &worst_case_const_state);
+ const uint32_t max_upload = (shader->compiler->max_const -
+ worst_case_const_state.offsets.immediate) * 16;
+
uint32_t offset = shader->const_state.num_reserved_user_consts * 16;
state->num_enabled = ARRAY_SIZE(state->range);
for (uint32_t i = 0; i < ARRAY_SIZE(state->range); i++) {