renderer: refactor draw time sampler binding.

This pulls the per shader type code out into a separate function.
This is prep work for adding compute shaders.

Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Dave Airlie 7 years ago
parent 9c902a90f5
commit b624bc65ff
  1. 116
      src/vrend_renderer.c

@ -2953,70 +2953,76 @@ static void vrend_draw_bind_vertex_binding(struct vrend_context *ctx,
} }
} }
static void vrend_draw_bind_samplers(struct vrend_context *ctx) static void vrend_draw_bind_samplers_shader(struct vrend_context *ctx,
int shader_type,
int *sampler_id)
{ {
int sampler_id; int index = 0;
int i; for (int i = 0; i < ctx->sub->views[shader_type].num_views; i++) {
int shader_type; struct vrend_resource *texture = NULL;
sampler_id = 0; if (ctx->sub->views[shader_type].views[i]) {
for (shader_type = PIPE_SHADER_VERTEX; shader_type <= ctx->sub->last_shader_idx; shader_type++) { texture = ctx->sub->views[shader_type].views[i]->texture;
int index = 0; }
for (i = 0; i < ctx->sub->views[shader_type].num_views; i++) {
struct vrend_resource *texture = NULL;
if (ctx->sub->views[shader_type].views[i]) { if (!(ctx->sub->prog->samplers_used_mask[shader_type] & (1 << i)))
texture = ctx->sub->views[shader_type].views[i]->texture; continue;
}
if (!(ctx->sub->prog->samplers_used_mask[shader_type] & (1 << i))) if (ctx->sub->prog->samp_locs[shader_type])
continue; glUniform1i(ctx->sub->prog->samp_locs[shader_type][index], *sampler_id);
if (ctx->sub->prog->shadow_samp_mask[shader_type] & (1 << i)) {
struct vrend_sampler_view *tview = ctx->sub->views[shader_type].views[i];
glUniform4f(ctx->sub->prog->shadow_samp_mask_locs[shader_type][index],
(tview->gl_swizzle_r == GL_ZERO || tview->gl_swizzle_r == GL_ONE) ? 0.0 : 1.0,
(tview->gl_swizzle_g == GL_ZERO || tview->gl_swizzle_g == GL_ONE) ? 0.0 : 1.0,
(tview->gl_swizzle_b == GL_ZERO || tview->gl_swizzle_b == GL_ONE) ? 0.0 : 1.0,
(tview->gl_swizzle_a == GL_ZERO || tview->gl_swizzle_a == GL_ONE) ? 0.0 : 1.0);
glUniform4f(ctx->sub->prog->shadow_samp_add_locs[shader_type][index],
tview->gl_swizzle_r == GL_ONE ? 1.0 : 0.0,
tview->gl_swizzle_g == GL_ONE ? 1.0 : 0.0,
tview->gl_swizzle_b == GL_ONE ? 1.0 : 0.0,
tview->gl_swizzle_a == GL_ONE ? 1.0 : 0.0);
}
glActiveTexture(GL_TEXTURE0 + *sampler_id);
if (texture) {
GLuint id;
GLenum target = texture->target;
if (texture->is_buffer) {
id = texture->tbo_tex_id;
target = GL_TEXTURE_BUFFER;
} else
id = texture->id;
if (ctx->sub->prog->samp_locs[shader_type]) glBindTexture(target, id);
glUniform1i(ctx->sub->prog->samp_locs[shader_type][index], sampler_id); if (ctx->sub->views[shader_type].old_ids[i] != id || ctx->sub->sampler_state_dirty) {
vrend_apply_sampler_state(ctx, texture, shader_type, i, *sampler_id, ctx->sub->views[shader_type].views[i]->srgb_decode);
if (ctx->sub->prog->shadow_samp_mask[shader_type] & (1 << i)) { ctx->sub->views[shader_type].old_ids[i] = id;
struct vrend_sampler_view *tview = ctx->sub->views[shader_type].views[i];
glUniform4f(ctx->sub->prog->shadow_samp_mask_locs[shader_type][index],
(tview->gl_swizzle_r == GL_ZERO || tview->gl_swizzle_r == GL_ONE) ? 0.0 : 1.0,
(tview->gl_swizzle_g == GL_ZERO || tview->gl_swizzle_g == GL_ONE) ? 0.0 : 1.0,
(tview->gl_swizzle_b == GL_ZERO || tview->gl_swizzle_b == GL_ONE) ? 0.0 : 1.0,
(tview->gl_swizzle_a == GL_ZERO || tview->gl_swizzle_a == GL_ONE) ? 0.0 : 1.0);
glUniform4f(ctx->sub->prog->shadow_samp_add_locs[shader_type][index],
tview->gl_swizzle_r == GL_ONE ? 1.0 : 0.0,
tview->gl_swizzle_g == GL_ONE ? 1.0 : 0.0,
tview->gl_swizzle_b == GL_ONE ? 1.0 : 0.0,
tview->gl_swizzle_a == GL_ONE ? 1.0 : 0.0);
} }
if (ctx->sub->rs_state.point_quad_rasterization) {
glActiveTexture(GL_TEXTURE0 + sampler_id); if (vrend_state.use_core_profile == false) {
if (texture) { if (ctx->sub->rs_state.sprite_coord_enable & (1 << i))
GLuint id; glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
GLenum target = texture->target; else
glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_FALSE);
if (texture->is_buffer) {
id = texture->tbo_tex_id;
target = GL_TEXTURE_BUFFER;
} else
id = texture->id;
glBindTexture(target, id);
if (ctx->sub->views[shader_type].old_ids[i] != id || ctx->sub->sampler_state_dirty) {
vrend_apply_sampler_state(ctx, texture, shader_type, i, sampler_id, ctx->sub->views[shader_type].views[i]->srgb_decode);
ctx->sub->views[shader_type].old_ids[i] = id;
}
if (ctx->sub->rs_state.point_quad_rasterization) {
if (vrend_state.use_core_profile == false) {
if (ctx->sub->rs_state.sprite_coord_enable & (1 << i))
glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
else
glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_FALSE);
}
} }
sampler_id++;
} }
index++; (*sampler_id)++;
} }
index++;
}
}
static void vrend_draw_bind_samplers(struct vrend_context *ctx)
{
int sampler_id;
int shader_type;
sampler_id = 0;
for (shader_type = PIPE_SHADER_VERTEX; shader_type <= ctx->sub->last_shader_idx; shader_type++) {
vrend_draw_bind_samplers_shader(ctx, shader_type, &sampler_id);
} }
if (vrend_state.use_core_profile && ctx->sub->prog->fs_stipple_loc != -1) { if (vrend_state.use_core_profile && ctx->sub->prog->fs_stipple_loc != -1) {

Loading…
Cancel
Save