diff options
author | José Fonseca <[email protected]> | 2008-07-14 10:45:40 +0900 |
---|---|---|
committer | José Fonseca <[email protected]> | 2008-07-14 12:41:06 +0900 |
commit | 05a23e6c6f08d4d901dc9fc9995b3444fa6355dd (patch) | |
tree | d9c399afb7cad207eb2100198526457c0a48ce3d /src | |
parent | 16c2267d55fb14d0ffcb676540345a14ecc0f323 (diff) |
python: Allow to create/specify shaders.
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/state_trackers/python/gallium.i | 88 | ||||
-rw-r--r-- | src/gallium/state_trackers/python/samples/simple.py | 29 | ||||
-rw-r--r-- | src/gallium/state_trackers/python/st_device.c | 20 |
3 files changed, 97 insertions, 40 deletions
diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i index d6594f3a87a..53d160ef6c4 100644 --- a/src/gallium/state_trackers/python/gallium.i +++ b/src/gallium/state_trackers/python/gallium.i @@ -44,9 +44,11 @@ #include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "pipe/p_shader_tokens.h" +#include "cso_cache/cso_context.h" #include "util/u_draw_quad.h" #include "util/p_tile.h" -#include "cso_cache/cso_context.h" +#include "tgsi/util/tgsi_text.h" +#include "tgsi/util/tgsi_dump.h" #include "st_device.h" @@ -201,29 +203,32 @@ struct st_context { cso_set_depth_stencil_alpha($self->cso, state); } - - void * create_fs( const struct pipe_shader_state *state ) { - return $self->pipe->create_fs_state($self->pipe, state); - } - - void bind_fs( void *state_obj ) { - $self->pipe->bind_fs_state($self->pipe, state_obj); - } - - void delete_fs( void *state_obj ) { - $self->pipe->delete_fs_state($self->pipe, state_obj); - } + void set_fragment_shader( const struct pipe_shader_state *state ) { + void *fs; + + fs = $self->pipe->create_fs_state($self->pipe, state); + if(!fs) + return; + + if(cso_set_fragment_shader_handle($self->cso, fs) != PIPE_OK) + return; - void * create_vs( const struct pipe_shader_state *state ) { - return $self->pipe->create_vs_state($self->pipe, state); - } - - void bind_vs( void *state_obj ) { - $self->pipe->bind_vs_state($self->pipe, state_obj); + cso_delete_fragment_shader($self->cso, $self->fs); + $self->fs = fs; } - - void delete_vs( void *state_obj ) { - $self->pipe->delete_vs_state($self->pipe, state_obj); + + void set_vertex_shader( const struct pipe_shader_state *state ) { + void *vs; + + vs = $self->pipe->create_vs_state($self->pipe, state); + if(!vs) + return; + + if(cso_set_vertex_shader_handle($self->cso, vs) != PIPE_OK) + return; + + cso_delete_vertex_shader($self->cso, $self->vs); + $self->vs = vs; } /* @@ -446,3 +451,42 @@ error1: } }; + + +%extend pipe_shader_state { + + pipe_shader_state(const char *text, unsigned num_tokens = 1024) { + struct tgsi_token *tokens; + struct pipe_shader_state *shader; + + tokens = MALLOC(num_tokens * sizeof(struct tgsi_token)); + if(!tokens) + goto error1; + + if(tgsi_text_translate(text, tokens, num_tokens ) != TRUE) + goto error2; + + shader = CALLOC_STRUCT(pipe_shader_state); + if(!shader) + goto error3; + + shader->tokens = tokens; + + return shader; + +error3: +error2: + FREE(tokens); +error1: + return NULL; + } + + ~pipe_shader_state() { + FREE((void*)$self->tokens); + FREE($self); + } + + void dump(unsigned flags = 0) { + tgsi_dump($self->tokens, flags); + } +}
\ No newline at end of file diff --git a/src/gallium/state_trackers/python/samples/simple.py b/src/gallium/state_trackers/python/samples/simple.py index 77e182b6447..6e90eec28ae 100644 --- a/src/gallium/state_trackers/python/samples/simple.py +++ b/src/gallium/state_trackers/python/samples/simple.py @@ -103,7 +103,9 @@ def test(dev): ctx.set_sampler(0, sampler) # texture - texture = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM, width, height, usage=PIPE_TEXTURE_USAGE_RENDER_TARGET) + texture = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM, + width, height, + usage=PIPE_TEXTURE_USAGE_RENDER_TARGET) ctx.set_sampler_texture(0, texture) # drawing dest @@ -116,12 +118,29 @@ def test(dev): ctx.set_framebuffer(fb) # vertex shader - # vs = Shader() - #ctx.set_vertex_shader(vs) + vs = Shader(''' + VERT1.1 + DCL IN[0], POSITION, CONSTANT + DCL IN[1], GENERIC[0], CONSTANT + DCL OUT[0], POSITION, CONSTANT + DCL OUT[1], GENERIC[0], CONSTANT + 0:MOV OUT[0], IN[0] + 1:MOV OUT[1], IN[1] + 2:END + ''') + #vs.dump() + ctx.set_vertex_shader(vs) # fragment shader - #fs = Shader() - #ctx.set_fragment_shader(fs) + fs = Shader(''' + FRAG1.1 + DCL IN[0], COLOR, CONSTANT + DCL OUT[0], COLOR, CONSTANT + 0:MOV OUT[0], IN[0] + 1:END + ''') + #fs.dump() + ctx.set_fragment_shader(fs) if 0: nverts = 4 diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c index 430a7af1765..e9002b493de 100644 --- a/src/gallium/state_trackers/python/st_device.c +++ b/src/gallium/state_trackers/python/st_device.c @@ -99,18 +99,12 @@ st_context_destroy(struct st_context *st_ctx) if(st_ctx) { struct st_device *st_dev = st_ctx->st_dev; - if(st_ctx->vs) { - st_ctx->pipe->bind_vs_state(st_ctx->pipe, NULL); - st_ctx->pipe->delete_vs_state(st_ctx->pipe, st_ctx->vs); - } - - if(st_ctx->fs) { - st_ctx->pipe->bind_fs_state(st_ctx->pipe, NULL); - st_ctx->pipe->delete_fs_state(st_ctx->pipe, st_ctx->fs); - } - - if(st_ctx->cso) + if(st_ctx->cso) { + cso_delete_vertex_shader(st_ctx->cso, st_ctx->vs); + cso_delete_fragment_shader(st_ctx->cso, st_ctx->fs); + cso_destroy_context(st_ctx->cso); + } if(st_ctx->pipe) st_ctx->st_dev->st_ws->context_destroy(st_ctx->pipe); @@ -162,8 +156,8 @@ st_context_create(struct st_device *st_dev) st_ctx->fs = util_make_fragment_passthrough_shader(st_ctx->pipe, &st_ctx->frag_shader); - st_ctx->pipe->bind_fs_state(st_ctx->pipe, st_ctx->fs); - st_ctx->pipe->bind_vs_state(st_ctx->pipe, st_ctx->vs); + cso_set_fragment_shader_handle(st_ctx->cso, st_ctx->fs); + cso_set_vertex_shader_handle(st_ctx->cso, st_ctx->vs); return st_ctx; } |