summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2014-01-31 17:23:11 -0700
committerBrian Paul <[email protected]>2014-02-03 12:40:13 -0700
commit4686f610b18a04bc6213ccadf7be1176bbda3e34 (patch)
treef3465d5134ec8c0d4f029f87d894f3ce2d6dff99 /src/gallium/drivers
parent9bace99d77642f8fbd46b1f0be025ad758f83f5e (diff)
svga: refactor some shader code
Put common code in new svga_shader.c file. Considate separate vertex/ fragment shader ID generation. Reviewed-by: Jose Fonseca <[email protected]>
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r--src/gallium/drivers/svga/Makefile.sources1
-rw-r--r--src/gallium/drivers/svga/svga_context.c19
-rw-r--r--src/gallium/drivers/svga/svga_context.h3
-rw-r--r--src/gallium/drivers/svga/svga_pipe_fs.c14
-rw-r--r--src/gallium/drivers/svga/svga_pipe_vs.c14
-rw-r--r--src/gallium/drivers/svga/svga_shader.c101
-rw-r--r--src/gallium/drivers/svga/svga_shader.h44
-rw-r--r--src/gallium/drivers/svga/svga_state_fs.c20
-rw-r--r--src/gallium/drivers/svga/svga_state_vs.c20
-rw-r--r--src/gallium/drivers/svga/svga_tgsi.c8
-rw-r--r--src/gallium/drivers/svga/svga_tgsi.h3
11 files changed, 171 insertions, 76 deletions
diff --git a/src/gallium/drivers/svga/Makefile.sources b/src/gallium/drivers/svga/Makefile.sources
index de4622b0a27..525cb91a4e0 100644
--- a/src/gallium/drivers/svga/Makefile.sources
+++ b/src/gallium/drivers/svga/Makefile.sources
@@ -24,6 +24,7 @@ C_SOURCES := \
svga_pipe_vs.c \
svga_screen.c \
svga_screen_cache.c \
+ svga_shader.c \
svga_state.c \
svga_state_need_swtnl.c \
svga_state_constants.c \
diff --git a/src/gallium/drivers/svga/svga_context.c b/src/gallium/drivers/svga/svga_context.c
index 21fe73ad152..c32051a41db 100644
--- a/src/gallium/drivers/svga/svga_context.c
+++ b/src/gallium/drivers/svga/svga_context.c
@@ -68,8 +68,7 @@ static void svga_destroy( struct pipe_context *pipe )
svga_destroy_swtnl( svga );
- util_bitmask_destroy( svga->vs_bm );
- util_bitmask_destroy( svga->fs_bm );
+ util_bitmask_destroy( svga->shader_id_bm );
for(shader = 0; shader < PIPE_SHADER_TYPES; ++shader)
pipe_resource_reference( &svga->curr.cb[shader], NULL );
@@ -124,13 +123,9 @@ struct pipe_context *svga_context_create( struct pipe_screen *screen,
svga->debug.no_line_width = debug_get_option_no_line_width();
svga->debug.force_hw_line_stipple = debug_get_option_force_hw_line_stipple();
- svga->fs_bm = util_bitmask_create();
- if (svga->fs_bm == NULL)
- goto no_fs_bm;
-
- svga->vs_bm = util_bitmask_create();
- if (svga->vs_bm == NULL)
- goto no_vs_bm;
+ svga->shader_id_bm = util_bitmask_create();
+ if (svga->shader_id_bm == NULL)
+ goto no_shader_bm;
svga->hwtnl = svga_hwtnl_create(svga);
if (svga->hwtnl == NULL)
@@ -164,10 +159,8 @@ no_state:
no_swtnl:
svga_hwtnl_destroy( svga->hwtnl );
no_hwtnl:
- util_bitmask_destroy( svga->vs_bm );
-no_vs_bm:
- util_bitmask_destroy( svga->fs_bm );
-no_fs_bm:
+ util_bitmask_destroy( svga->shader_id_bm );
+no_shader_bm:
svga->swc->destroy(svga->swc);
no_swc:
FREE(svga);
diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h
index f75fac5a1cc..71d4014170d 100644
--- a/src/gallium/drivers/svga/svga_context.h
+++ b/src/gallium/drivers/svga/svga_context.h
@@ -347,8 +347,7 @@ struct svga_context
} swtnl;
/* Bitmask of used shader IDs */
- struct util_bitmask *fs_bm;
- struct util_bitmask *vs_bm;
+ struct util_bitmask *shader_id_bm;
struct {
unsigned dirty[SVGA_STATE_MAX];
diff --git a/src/gallium/drivers/svga/svga_pipe_fs.c b/src/gallium/drivers/svga/svga_pipe_fs.c
index 7bdcd8eb4bb..75299c50db7 100644
--- a/src/gallium/drivers/svga/svga_pipe_fs.c
+++ b/src/gallium/drivers/svga/svga_pipe_fs.c
@@ -35,6 +35,7 @@
#include "svga_hw_reg.h"
#include "svga_cmd.h"
#include "svga_debug.h"
+#include "svga_shader.h"
static void *
@@ -98,17 +99,8 @@ svga_delete_fs_state(struct pipe_context *pipe, void *shader)
for (variant = fs->base.variants; variant; variant = tmp) {
tmp = variant->next;
- ret = SVGA3D_DestroyShader(svga->swc, variant->id, SVGA3D_SHADERTYPE_PS);
- if (ret != PIPE_OK) {
- svga_context_flush(svga, NULL);
- ret = SVGA3D_DestroyShader(svga->swc, variant->id,
- SVGA3D_SHADERTYPE_PS);
- assert(ret == PIPE_OK);
- }
-
- util_bitmask_clear(svga->fs_bm, variant->id);
-
- svga_destroy_shader_variant(variant);
+ ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant);
+ (void) ret; /* PIPE_ERROR_ not handled yet */
/*
* Remove stale references to this variant to ensure a new variant on the
diff --git a/src/gallium/drivers/svga/svga_pipe_vs.c b/src/gallium/drivers/svga/svga_pipe_vs.c
index fd132ebf280..c3ac663b4a2 100644
--- a/src/gallium/drivers/svga/svga_pipe_vs.c
+++ b/src/gallium/drivers/svga/svga_pipe_vs.c
@@ -36,6 +36,7 @@
#include "svga_hw_reg.h"
#include "svga_cmd.h"
#include "svga_debug.h"
+#include "svga_shader.h"
/**
@@ -158,17 +159,8 @@ svga_delete_vs_state(struct pipe_context *pipe, void *shader)
for (variant = vs->base.variants; variant; variant = tmp) {
tmp = variant->next;
- ret = SVGA3D_DestroyShader(svga->swc, variant->id, SVGA3D_SHADERTYPE_VS);
- if (ret != PIPE_OK) {
- svga_context_flush(svga, NULL);
- ret = SVGA3D_DestroyShader(svga->swc, variant->id,
- SVGA3D_SHADERTYPE_VS);
- assert(ret == PIPE_OK);
- }
-
- util_bitmask_clear(svga->vs_bm, variant->id);
-
- svga_destroy_shader_variant(variant);
+ ret = svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_VS, variant);
+ (void) ret; /* PIPE_ERROR_ not handled yet */
/*
* Remove stale references to this variant to ensure a new variant on the
diff --git a/src/gallium/drivers/svga/svga_shader.c b/src/gallium/drivers/svga/svga_shader.c
new file mode 100644
index 00000000000..88877b27e98
--- /dev/null
+++ b/src/gallium/drivers/svga/svga_shader.c
@@ -0,0 +1,101 @@
+/**********************************************************
+ * Copyright 2008-2012 VMware, Inc. All rights reserved.
+ *
+ * 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 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.
+ *
+ **********************************************************/
+
+#include "util/u_bitmask.h"
+#include "util/u_memory.h"
+#include "svga_context.h"
+#include "svga_cmd.h"
+#include "svga_shader.h"
+
+
+
+/**
+ * Issue the SVGA3D commands to define a new shader.
+ * \param result contains the shader tokens, etc. The result->id field will
+ * be set here.
+ */
+enum pipe_error
+svga_define_shader(struct svga_context *svga,
+ SVGA3dShaderType type,
+ struct svga_shader_variant *variant)
+{
+ unsigned codeLen = variant->nr_tokens * sizeof(variant->tokens[0]);
+
+ {
+ enum pipe_error ret;
+
+ /* Allocate an integer ID for the shader */
+ variant->id = util_bitmask_add(svga->shader_id_bm);
+ if (variant->id == UTIL_BITMASK_INVALID_INDEX) {
+ return PIPE_ERROR_OUT_OF_MEMORY;
+ }
+
+ /* Issue SVGA3D device command to define the shader */
+ ret = SVGA3D_DefineShader(svga->swc,
+ variant->id,
+ type,
+ variant->tokens,
+ codeLen);
+ if (ret != PIPE_OK) {
+ /* free the ID */
+ assert(variant->id != UTIL_BITMASK_INVALID_INDEX);
+ util_bitmask_clear(svga->shader_id_bm, variant->id);
+ variant->id = UTIL_BITMASK_INVALID_INDEX;
+ return ret;
+ }
+ }
+
+ return PIPE_OK;
+}
+
+
+
+enum pipe_error
+svga_destroy_shader_variant(struct svga_context *svga,
+ SVGA3dShaderType type,
+ struct svga_shader_variant *variant)
+{
+ enum pipe_error ret = PIPE_OK;
+
+ /* first try */
+ if (variant->id != UTIL_BITMASK_INVALID_INDEX) {
+ ret = SVGA3D_DestroyShader(svga->swc, variant->id, type);
+
+ if (ret != PIPE_OK) {
+ /* flush and try again */
+ svga_context_flush(svga, NULL);
+
+ ret = SVGA3D_DestroyShader(svga->swc, variant->id, type);
+ assert(ret == PIPE_OK);
+ }
+
+ util_bitmask_clear(svga->shader_id_bm, variant->id);
+ }
+
+ FREE((unsigned *)variant->tokens);
+ FREE(variant);
+
+ return ret;
+}
diff --git a/src/gallium/drivers/svga/svga_shader.h b/src/gallium/drivers/svga/svga_shader.h
new file mode 100644
index 00000000000..348dc0c59e2
--- /dev/null
+++ b/src/gallium/drivers/svga/svga_shader.h
@@ -0,0 +1,44 @@
+/**********************************************************
+ * Copyright 2008-2012 VMware, Inc. All rights reserved.
+ *
+ * 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 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.
+ *
+ **********************************************************/
+
+#ifndef SVGA_SHADER_H
+#define SVGA_SHADER_H
+
+#include "svga3d_reg.h"
+
+struct svga_shader_variant;
+
+enum pipe_error
+svga_define_shader(struct svga_context *svga,
+ SVGA3dShaderType type,
+ struct svga_shader_variant *variant);
+
+enum pipe_error
+svga_destroy_shader_variant(struct svga_context *svga,
+ SVGA3dShaderType type,
+ struct svga_shader_variant *variant);
+
+
+#endif /* SVGA_SHADER_H */
diff --git a/src/gallium/drivers/svga/svga_state_fs.c b/src/gallium/drivers/svga/svga_state_fs.c
index 1afdae95e0f..860a0c8e0cf 100644
--- a/src/gallium/drivers/svga/svga_state_fs.c
+++ b/src/gallium/drivers/svga/svga_state_fs.c
@@ -33,6 +33,7 @@
#include "svga_context.h"
#include "svga_state.h"
#include "svga_cmd.h"
+#include "svga_shader.h"
#include "svga_resource_texture.h"
#include "svga_tgsi.h"
@@ -134,30 +135,21 @@ compile_fs(struct svga_context *svga,
}
}
- variant->id = util_bitmask_add(svga->fs_bm);
- if(variant->id == UTIL_BITMASK_INVALID_INDEX) {
- ret = PIPE_ERROR_OUT_OF_MEMORY;
- goto fail;
- }
-
- ret = SVGA3D_DefineShader(svga->swc,
- variant->id,
- SVGA3D_SHADERTYPE_PS,
- variant->tokens,
- variant->nr_tokens * sizeof variant->tokens[0]);
+ ret = svga_define_shader(svga, SVGA3D_SHADERTYPE_PS, variant);
if (ret != PIPE_OK)
goto fail;
*out_variant = variant;
+
+ /* insert variants at head of linked list */
variant->next = fs->base.variants;
fs->base.variants = variant;
+
return PIPE_OK;
fail:
if (variant) {
- if (variant->id != UTIL_BITMASK_INVALID_INDEX)
- util_bitmask_clear( svga->fs_bm, variant->id );
- svga_destroy_shader_variant( variant );
+ svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_PS, variant);
}
return ret;
}
diff --git a/src/gallium/drivers/svga/svga_state_vs.c b/src/gallium/drivers/svga/svga_state_vs.c
index 208bdd3626a..aaef17ef35f 100644
--- a/src/gallium/drivers/svga/svga_state_vs.c
+++ b/src/gallium/drivers/svga/svga_state_vs.c
@@ -35,6 +35,7 @@
#include "svga_context.h"
#include "svga_state.h"
#include "svga_cmd.h"
+#include "svga_shader.h"
#include "svga_tgsi.h"
#include "svga_hw_reg.h"
@@ -128,30 +129,21 @@ compile_vs(struct svga_context *svga,
}
}
- variant->id = util_bitmask_add(svga->vs_bm);
- if(variant->id == UTIL_BITMASK_INVALID_INDEX) {
- ret = PIPE_ERROR_OUT_OF_MEMORY;
- goto fail;
- }
-
- ret = SVGA3D_DefineShader(svga->swc,
- variant->id,
- SVGA3D_SHADERTYPE_VS,
- variant->tokens,
- variant->nr_tokens * sizeof variant->tokens[0]);
+ ret = svga_define_shader(svga, SVGA3D_SHADERTYPE_VS, variant);
if (ret != PIPE_OK)
goto fail;
*out_variant = variant;
+
+ /* insert variants at head of linked list */
variant->next = vs->base.variants;
vs->base.variants = variant;
+
return PIPE_OK;
fail:
if (variant) {
- if (variant->id != UTIL_BITMASK_INVALID_INDEX)
- util_bitmask_clear( svga->vs_bm, variant->id );
- svga_destroy_shader_variant( variant );
+ svga_destroy_shader_variant(svga, SVGA3D_SHADERTYPE_VS, variant);
}
return ret;
}
diff --git a/src/gallium/drivers/svga/svga_tgsi.c b/src/gallium/drivers/svga/svga_tgsi.c
index 368f131c6b2..9aafd851264 100644
--- a/src/gallium/drivers/svga/svga_tgsi.c
+++ b/src/gallium/drivers/svga/svga_tgsi.c
@@ -381,11 +381,3 @@ svga_translate_vertex_program(const struct svga_vertex_shader *vs,
return svga_tgsi_translate(&vs->base, &key, PIPE_SHADER_VERTEX);
}
-
-
-void
-svga_destroy_shader_variant(struct svga_shader_variant *variant)
-{
- FREE((unsigned *) variant->tokens);
- FREE(variant);
-}
diff --git a/src/gallium/drivers/svga/svga_tgsi.h b/src/gallium/drivers/svga/svga_tgsi.h
index b32b7081e9a..9a0c7b8f41e 100644
--- a/src/gallium/drivers/svga/svga_tgsi.h
+++ b/src/gallium/drivers/svga/svga_tgsi.h
@@ -154,9 +154,6 @@ svga_translate_vertex_program( const struct svga_vertex_shader *fs,
const struct svga_vs_compile_key *vkey );
-void
-svga_destroy_shader_variant(struct svga_shader_variant *variant);
-
unsigned
svga_get_generic_inputs_mask(const struct tgsi_shader_info *info);