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 \
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 );
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)
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);
} 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];
#include "svga_hw_reg.h"
#include "svga_cmd.h"
#include "svga_debug.h"
+#include "svga_shader.h"
static void *
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
#include "svga_hw_reg.h"
#include "svga_cmd.h"
#include "svga_debug.h"
+#include "svga_shader.h"
/**
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
--- /dev/null
+/**********************************************************
+ * 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;
+}
--- /dev/null
+/**********************************************************
+ * 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 */
#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"
}
}
- 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;
}
#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"
}
}
- 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;
}
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);
-}
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);