svga: Use a shader id as low as possible.
This commit is contained in:
parent
904917dcc6
commit
cdb445f3a9
|
@ -29,6 +29,7 @@
|
|||
#include "pipe/p_inlines.h"
|
||||
#include "pipe/p_screen.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "util/u_bitmask.h"
|
||||
#include "util/u_upload_mgr.h"
|
||||
|
||||
#include "svga_context.h"
|
||||
|
@ -61,6 +62,9 @@ static void svga_destroy( struct pipe_context *pipe )
|
|||
u_upload_destroy( svga->upload_vb );
|
||||
u_upload_destroy( svga->upload_ib );
|
||||
|
||||
util_bitmask_destroy( svga->vs_bm );
|
||||
util_bitmask_destroy( svga->fs_bm );
|
||||
|
||||
for(shader = 0; shader < PIPE_SHADER_TYPES; ++shader)
|
||||
pipe_buffer_reference( &svga->curr.cb[shader], NULL );
|
||||
|
||||
|
@ -167,6 +171,14 @@ struct pipe_context *svga_context_create( struct pipe_screen *screen )
|
|||
if (!svga_init_swtnl(svga))
|
||||
goto no_swtnl;
|
||||
|
||||
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->upload_ib = u_upload_create( svga->pipe.screen,
|
||||
32 * 1024,
|
||||
16,
|
||||
|
@ -216,6 +228,10 @@ no_hwtnl:
|
|||
no_upload_vb:
|
||||
u_upload_destroy( svga->upload_ib );
|
||||
no_upload_ib:
|
||||
util_bitmask_destroy( svga->vs_bm );
|
||||
no_vs_bm:
|
||||
util_bitmask_destroy( svga->fs_bm );
|
||||
no_fs_bm:
|
||||
svga_destroy_swtnl(svga);
|
||||
no_swtnl:
|
||||
svga->swc->destroy(svga->swc);
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
struct draw_vertex_shader;
|
||||
struct svga_shader_result;
|
||||
struct SVGACmdMemory;
|
||||
struct util_bitmask;
|
||||
struct u_upload_mgr;
|
||||
|
||||
|
||||
|
@ -321,12 +322,14 @@ struct svga_context
|
|||
boolean new_vdecl;
|
||||
} swtnl;
|
||||
|
||||
/* Bitmask of used shader IDs */
|
||||
struct util_bitmask *fs_bm;
|
||||
struct util_bitmask *vs_bm;
|
||||
|
||||
struct {
|
||||
unsigned dirty[4];
|
||||
|
||||
unsigned texture_timestamp;
|
||||
unsigned next_fs_id;
|
||||
unsigned next_vs_id;
|
||||
|
||||
/* Internally generated shaders:
|
||||
*/
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "pipe/p_inlines.h"
|
||||
#include "util/u_math.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "util/u_bitmask.h"
|
||||
#include "tgsi/tgsi_parse.h"
|
||||
#include "tgsi/tgsi_text.h"
|
||||
|
||||
|
@ -107,6 +108,8 @@ void svga_delete_fs_state(struct pipe_context *pipe, void *shader)
|
|||
assert(ret == PIPE_OK);
|
||||
}
|
||||
|
||||
util_bitmask_clear( svga->fs_bm, result->id );
|
||||
|
||||
svga_destroy_shader_result( result );
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "pipe/p_inlines.h"
|
||||
#include "util/u_math.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "util/u_bitmask.h"
|
||||
#include "tgsi/tgsi_parse.h"
|
||||
#include "tgsi/tgsi_text.h"
|
||||
|
||||
|
@ -172,6 +173,8 @@ static void svga_delete_vs_state(struct pipe_context *pipe, void *shader)
|
|||
assert(ret == PIPE_OK);
|
||||
}
|
||||
|
||||
util_bitmask_clear( svga->vs_bm, result->id );
|
||||
|
||||
svga_destroy_shader_result( result );
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "pipe/p_inlines.h"
|
||||
#include "pipe/p_defines.h"
|
||||
#include "util/u_math.h"
|
||||
#include "util/u_bitmask.h"
|
||||
|
||||
#include "svga_context.h"
|
||||
#include "svga_state.h"
|
||||
|
@ -74,9 +75,12 @@ static enum pipe_error compile_fs( struct svga_context *svga,
|
|||
goto fail;
|
||||
}
|
||||
|
||||
result->id = util_bitmask_add(svga->fs_bm);
|
||||
if(result->id == UTIL_BITMASK_INVALID_INDEX)
|
||||
goto fail;
|
||||
|
||||
ret = SVGA3D_DefineShader(svga->swc,
|
||||
svga->state.next_fs_id,
|
||||
result->id,
|
||||
SVGA3D_SHADERTYPE_PS,
|
||||
result->tokens,
|
||||
result->nr_tokens * sizeof result->tokens[0]);
|
||||
|
@ -84,14 +88,16 @@ static enum pipe_error compile_fs( struct svga_context *svga,
|
|||
goto fail;
|
||||
|
||||
*out_result = result;
|
||||
result->id = svga->state.next_fs_id++;
|
||||
result->next = fs->base.results;
|
||||
fs->base.results = result;
|
||||
return PIPE_OK;
|
||||
|
||||
fail:
|
||||
if (result)
|
||||
if (result) {
|
||||
if (result->id != UTIL_BITMASK_INVALID_INDEX)
|
||||
util_bitmask_clear( svga->fs_bm, result->id );
|
||||
svga_destroy_shader_result( result );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -116,7 +122,7 @@ fail:
|
|||
*/
|
||||
static int emit_white_fs( struct svga_context *svga )
|
||||
{
|
||||
int ret;
|
||||
int ret = PIPE_ERROR;
|
||||
|
||||
/* ps_3_0
|
||||
* def c0, 1.000000, 0.000000, 0.000000, 1.000000
|
||||
|
@ -137,16 +143,26 @@ static int emit_white_fs( struct svga_context *svga )
|
|||
0x0000ffff,
|
||||
};
|
||||
|
||||
assert(SVGA3D_INVALID_ID == UTIL_BITMASK_INVALID_INDEX);
|
||||
svga->state.white_fs_id = util_bitmask_add(svga->fs_bm);
|
||||
if(svga->state.white_fs_id == SVGA3D_INVALID_ID)
|
||||
goto no_fs_id;
|
||||
|
||||
ret = SVGA3D_DefineShader(svga->swc,
|
||||
svga->state.next_fs_id,
|
||||
svga->state.white_fs_id,
|
||||
SVGA3D_SHADERTYPE_PS,
|
||||
white_tokens,
|
||||
sizeof(white_tokens));
|
||||
if (ret)
|
||||
return ret;
|
||||
goto no_definition;
|
||||
|
||||
svga->state.white_fs_id = svga->state.next_fs_id++;
|
||||
return 0;
|
||||
|
||||
no_definition:
|
||||
util_bitmask_clear(svga->fs_bm, svga->state.white_fs_id);
|
||||
svga->state.white_fs_id = SVGA3D_INVALID_ID;
|
||||
no_fs_id:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -251,12 +267,14 @@ static int emit_hw_fs( struct svga_context *svga,
|
|||
|
||||
assert(id != SVGA3D_INVALID_ID);
|
||||
|
||||
if (result != svga->state.hw_draw.fs) {
|
||||
if (id != svga->state.hw_draw.shader_id[PIPE_SHADER_FRAGMENT]) {
|
||||
ret = SVGA3D_SetShader(svga->swc,
|
||||
SVGA3D_SHADERTYPE_PS,
|
||||
id );
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
svga->dirty |= SVGA_NEW_FS_RESULT;
|
||||
svga->state.hw_draw.shader_id[PIPE_SHADER_FRAGMENT] = id;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "pipe/p_inlines.h"
|
||||
#include "pipe/p_defines.h"
|
||||
#include "util/u_math.h"
|
||||
#include "util/u_bitmask.h"
|
||||
#include "translate/translate.h"
|
||||
|
||||
#include "svga_context.h"
|
||||
|
@ -77,8 +78,12 @@ static enum pipe_error compile_vs( struct svga_context *svga,
|
|||
goto fail;
|
||||
}
|
||||
|
||||
result->id = util_bitmask_add(svga->vs_bm);
|
||||
if(result->id == UTIL_BITMASK_INVALID_INDEX)
|
||||
goto fail;
|
||||
|
||||
ret = SVGA3D_DefineShader(svga->swc,
|
||||
svga->state.next_vs_id,
|
||||
result->id,
|
||||
SVGA3D_SHADERTYPE_VS,
|
||||
result->tokens,
|
||||
result->nr_tokens * sizeof result->tokens[0]);
|
||||
|
@ -86,14 +91,16 @@ static enum pipe_error compile_vs( struct svga_context *svga,
|
|||
goto fail;
|
||||
|
||||
*out_result = result;
|
||||
result->id = svga->state.next_vs_id++;
|
||||
result->next = vs->base.results;
|
||||
vs->base.results = result;
|
||||
return PIPE_OK;
|
||||
|
||||
fail:
|
||||
if (result)
|
||||
if (result) {
|
||||
if (result->id != UTIL_BITMASK_INVALID_INDEX)
|
||||
util_bitmask_clear( svga->vs_bm, result->id );
|
||||
svga_destroy_shader_result( result );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -141,12 +148,14 @@ static int emit_hw_vs( struct svga_context *svga,
|
|||
id = result->id;
|
||||
}
|
||||
|
||||
if (result != svga->state.hw_draw.vs) {
|
||||
if (id != svga->state.hw_draw.shader_id[PIPE_SHADER_VERTEX]) {
|
||||
ret = SVGA3D_SetShader(svga->swc,
|
||||
SVGA3D_SHADERTYPE_VS,
|
||||
id );
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
svga->dirty |= SVGA_NEW_VS_RESULT;
|
||||
svga->state.hw_draw.shader_id[PIPE_SHADER_VERTEX] = id;
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "tgsi/tgsi_dump.h"
|
||||
#include "tgsi/tgsi_scan.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "util/u_bitmask.h"
|
||||
|
||||
#include "svgadump/svga_shader_dump.h"
|
||||
|
||||
|
@ -221,6 +222,7 @@ svga_tgsi_translate( const struct svga_shader *shader,
|
|||
result->tokens = (const unsigned *)emit.buf;
|
||||
result->nr_tokens = (emit.ptr - emit.buf) / sizeof(unsigned);
|
||||
memcpy(&result->key, &key, sizeof key);
|
||||
result->id = UTIL_BITMASK_INVALID_INDEX;
|
||||
|
||||
if (SVGA_DEBUG & DEBUG_TGSI)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue