diff options
author | Michal Krol <michal@vmware.com> | 2010-01-12 13:38:57 +0100 |
---|---|---|
committer | Michal Krol <michal@vmware.com> | 2010-01-12 13:38:57 +0100 |
commit | 848226ee1d2a8a3aaf147cfe309641acef838968 (patch) | |
tree | 2554eea512dbbc2b80b059c822d5fdd25a50332e | |
parent | de1fb34223b82caf3805ebca9e1bb2fbc13c99fa (diff) |
softpipe: Implement resource fetches for fragment shaders.
-rw-r--r-- | src/gallium/drivers/softpipe/sp_context.c | 4 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_context.h | 1 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_quad_fs.c | 2 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_state_sampler.c | 16 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_tex_sample.c | 54 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_tex_sample.h | 21 |
6 files changed, 95 insertions, 3 deletions
diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index f3ac6760db..86ca0869ce 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -112,6 +112,10 @@ softpipe_destroy( struct pipe_context *pipe ) pipe_texture_reference(&softpipe->vertex_textures[i], NULL); } + for (i = 0; i < PIPE_MAX_SHADER_RESOURCES; i++) { + FREE(softpipe->tgsi.frag_res_list[i]); + } + for (i = 0; i < Elements(softpipe->constants); i++) { if (softpipe->constants[i].buffer) { pipe_buffer_reference(&softpipe->constants[i].buffer, NULL); diff --git a/src/gallium/drivers/softpipe/sp_context.h b/src/gallium/drivers/softpipe/sp_context.h index 73fa744f9d..4c4c1e7842 100644 --- a/src/gallium/drivers/softpipe/sp_context.h +++ b/src/gallium/drivers/softpipe/sp_context.h @@ -132,6 +132,7 @@ struct softpipe_context { struct { struct sp_sampler_varient *vert_samplers_list[PIPE_MAX_VERTEX_SAMPLERS]; struct sp_sampler_varient *frag_samplers_list[PIPE_MAX_SAMPLERS]; + struct sp_resource *frag_res_list[PIPE_MAX_SHADER_RESOURCES]; } tgsi; /** The primitive drawing context */ diff --git a/src/gallium/drivers/softpipe/sp_quad_fs.c b/src/gallium/drivers/softpipe/sp_quad_fs.c index 7a32b5f34c..df1fc14824 100644 --- a/src/gallium/drivers/softpipe/sp_quad_fs.c +++ b/src/gallium/drivers/softpipe/sp_quad_fs.c @@ -145,7 +145,7 @@ shade_begin(struct quad_stage *qs) softpipe->fs->prepare(softpipe->fs, qss->machine, (struct tgsi_sampler **)softpipe->tgsi.frag_samplers_list, - NULL); + (struct tgsi_resource **)softpipe->tgsi.frag_res_list); qs->next->begin(qs->next); } diff --git a/src/gallium/drivers/softpipe/sp_state_sampler.c b/src/gallium/drivers/softpipe/sp_state_sampler.c index ceb4e338f1..e70f8c05bf 100644 --- a/src/gallium/drivers/softpipe/sp_state_sampler.c +++ b/src/gallium/drivers/softpipe/sp_state_sampler.c @@ -232,8 +232,6 @@ get_sampler_varient( unsigned unit, } - - void softpipe_reset_sampler_varients(struct softpipe_context *softpipe) { @@ -270,6 +268,20 @@ softpipe_reset_sampler_varients(struct softpipe_context *softpipe) softpipe->texture[i] ); } } + + for (i = 0; i <= softpipe->fs->info.file_max[TGSI_FILE_RESOURCE]; i++) { + /* XXX: Separate samplers from textures. + */ + if (softpipe->sampler[i]) { + if (!softpipe->tgsi.frag_res_list[i]) { + softpipe->tgsi.frag_res_list[i] = sp_create_resource(); + } + + sp_resource_bind_texture(softpipe->tgsi.frag_res_list[i], + softpipe->tex_cache[i], + softpipe->texture[i]); + } + } } diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c b/src/gallium/drivers/softpipe/sp_tex_sample.c index 1ae8fecacf..f2a74ecc03 100644 --- a/src/gallium/drivers/softpipe/sp_tex_sample.c +++ b/src/gallium/drivers/softpipe/sp_tex_sample.c @@ -1956,3 +1956,57 @@ sp_create_sampler_varient( const struct pipe_sampler_state *sampler, return samp; } + +static void +sp_fetch3D(struct tgsi_resource *resource, + const int i[QUAD_SIZE], + const int j[QUAD_SIZE], + const int k[QUAD_SIZE], + const int lod[QUAD_SIZE], + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + const struct sp_resource *res = sp_resource(resource); + union tex_tile_address addr; + uint q; + + addr.value = 0; + + for (q = 0; q < QUAD_SIZE; q++) { + const struct softpipe_tex_cached_tile *tile; + const float *texel; + + addr.bits.level = lod[q]; + addr.bits.x = i[q] / TILE_SIZE; + addr.bits.y = j[q] / TILE_SIZE; + addr.bits.z = k[q]; + + tile = sp_get_cached_tile_tex(res->cache, addr); + texel = &tile->data.color[j[q] % TILE_SIZE][i[q] % TILE_SIZE][0]; + + rgba[0][q] = texel[0]; + rgba[1][q] = texel[1]; + rgba[2][q] = texel[2]; + rgba[3][q] = texel[3]; + } +} + +struct sp_resource * +sp_create_resource(void) +{ + struct sp_resource *res = CALLOC_STRUCT(sp_resource); + + if (res) { + res->base.fetch3D = sp_fetch3D; + } + + return res; +} + +void +sp_resource_bind_texture(struct sp_resource *resource, + struct softpipe_tex_tile_cache *cache, + const struct pipe_texture *texture) +{ + resource->texture = texture; + resource->cache = cache; +} diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.h b/src/gallium/drivers/softpipe/sp_tex_sample.h index b6e66c998a..c8aafdd00e 100644 --- a/src/gallium/drivers/softpipe/sp_tex_sample.h +++ b/src/gallium/drivers/softpipe/sp_tex_sample.h @@ -150,4 +150,25 @@ sp_get_samples(struct tgsi_sampler *tgsi_sampler, float rgba[NUM_CHANNELS][QUAD_SIZE]); +struct sp_resource { + struct tgsi_resource base; /**< base class */ + + const struct pipe_texture *texture; + struct softpipe_tex_tile_cache *cache; +}; + +static INLINE struct sp_resource * +sp_resource(const struct tgsi_resource *resource) +{ + return (struct sp_resource *)resource; +} + +struct sp_resource * +sp_create_resource(void); + +void +sp_resource_bind_texture(struct sp_resource *resource, + struct softpipe_tex_tile_cache *cache, + const struct pipe_texture *texture); + #endif /* SP_TEX_SAMPLE_H */ |