intel: fix and clean up shader cache
intel_cmd_bind is zeroed in cmd_reset(). cmd->bind.shaderCache.shaderList
needs to be freed in cmd_reset(), and cmd_clear_shader_cache() becomes
unnecessary.
cmd->bind.shaderCache.shaderList is an array of intel_cmd_shader, yet the
memory allocated is for an array of intel_shader. Fix it, and delay the
allocation to emit_shader(), which also takes care of XGL_ERROR_OUT_OF_MEMORY.
Rename shaderList to shaderArray and size to count for clarify.
Do not unconstify things because intel_cmd_shader failed to consitify pointers
in it.
diff --git a/icd/intel/cmd_pipeline.c b/icd/intel/cmd_pipeline.c
index dd0cbf6..aa0fd9c 100644
--- a/icd/intel/cmd_pipeline.c
+++ b/icd/intel/cmd_pipeline.c
@@ -977,75 +977,53 @@
/* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
cmd_batch_reserve(cmd, msaa->cmd_len);
cmd_batch_write_n(cmd, msaa->cmd, msaa->cmd_len);
-
- /* 3DSTATE_CONSTANT_GS */
- if (cmd->bind.pipeline.graphics->active_shaders & SHADER_GEOMETRY_FLAG) {
-
- } else {
-
- }
-}
-
-void cmd_clear_shader_cache(struct intel_cmd *cmd)
-{
- uint32_t i;
- struct intel_cmd_shader *cmdShader;
-
- for (i=0; i<cmd->bind.shaderCache.used; i++) {
- cmdShader = &cmd->bind.shaderCache.shaderList[i];
- cmdShader->shader = NULL;
- }
- cmd->bind.shaderCache.used = 0;
}
static void emit_shader(struct intel_cmd *cmd,
- struct intel_pipe_shader *shader)
+ const struct intel_pipe_shader *shader)
{
uint32_t i;
struct intel_cmd_shader *cmdShader;
for (i=0; i<cmd->bind.shaderCache.used; i++) {
- if (cmd->bind.shaderCache.shaderList[i].shader == shader) {
+ if (cmd->bind.shaderCache.shaderArray[i].shader == shader) {
/* shader is already part of pipeline */
return;
}
}
- if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.size) {
- cmdShader = &cmd->bind.shaderCache.shaderList[0];
- cmd->bind.shaderCache.size += 16;
- cmd->bind.shaderCache.shaderList = icd_alloc(sizeof(struct intel_shader) * cmd->bind.shaderCache.size,
- sizeof(struct intel_shader *),
- XGL_SYSTEM_ALLOC_INTERNAL_SHADER);
- if (cmd->bind.shaderCache.shaderList == NULL) {
- cmd->bind.shaderCache.shaderList = cmdShader;
+ if (cmd->bind.shaderCache.used == cmd->bind.shaderCache.count) {
+ const XGL_UINT new_count = cmd->bind.shaderCache.count + 16;
+
+ cmdShader = cmd->bind.shaderCache.shaderArray;
+
+ cmd->bind.shaderCache.shaderArray =
+ icd_alloc(sizeof(*cmdShader) * new_count,
+ 0, XGL_SYSTEM_ALLOC_INTERNAL);
+ if (cmd->bind.shaderCache.shaderArray == NULL) {
+ cmd->bind.shaderCache.shaderArray = cmdShader;
cmd->result = XGL_ERROR_OUT_OF_MEMORY;
return;
}
- memcpy(cmd->bind.shaderCache.shaderList,
- cmdShader,
- sizeof(struct intel_cmd_shader) * cmd->bind.shaderCache.used);
- icd_free(cmdShader);
+
+ if (cmdShader) {
+ memcpy(cmd->bind.shaderCache.shaderArray, cmdShader,
+ sizeof(*cmdShader) * cmd->bind.shaderCache.used);
+ icd_free(cmdShader);
+ }
+
+ cmd->bind.shaderCache.count = new_count;
}
- cmdShader = &cmd->bind.shaderCache.shaderList[cmd->bind.shaderCache.used];
+ cmdShader = &cmd->bind.shaderCache.shaderArray[cmd->bind.shaderCache.used];
cmdShader->shader = shader;
cmdShader->kernel_pos = cmd_kernel_copy(cmd, shader->pCode, shader->codeSize);
cmd->bind.shaderCache.used++;
return;
}
-static void emit_pipeline_state(struct intel_cmd *cmd,
- const struct intel_pipeline *pipeline)
-{
- if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
-
- }
-
-}
-
static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
- struct intel_pipeline *pipeline)
+ const struct intel_pipeline *pipeline)
{
cmd->bind.pipeline.graphics = pipeline;
if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
@@ -1063,8 +1041,6 @@
if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
emit_shader(cmd, &pipeline->tess_eval);
}
-
- emit_pipeline_state(cmd, pipeline);
}
static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,