/** * Pass the given program parameters to the graphics pipe as a * constant buffer. * \param shader_type either PIPE_SHADER_VERTEX or PIPE_SHADER_FRAGMENT */ void st_upload_constants( struct st_context *st, struct gl_program_parameter_list *params, unsigned shader_type) { assert(shader_type == PIPE_SHADER_VERTEX || shader_type == PIPE_SHADER_FRAGMENT || shader_type == PIPE_SHADER_GEOMETRY || shader_type == PIPE_SHADER_TESS_CTRL || shader_type == PIPE_SHADER_TESS_EVAL); /* update constants */ if (params && params->NumParameters) { struct pipe_constant_buffer cb; const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4; /* Update the constants which come from fixed-function state, such as * transformation matrices, fog factors, etc. The rest of the values in * the parameters list are explicitly set by the user with glUniform, * glProgramParameter(), etc. */ if (params->StateFlags) _mesa_load_state_parameters(st->ctx, params); /* We always need to get a new buffer, to keep the drivers simple and * avoid gratuitous rendering synchronization. * Let's use a user buffer to avoid an unnecessary copy. */ if (st->constbuf_uploader) { cb.buffer = NULL; cb.user_buffer = NULL; u_upload_data(st->constbuf_uploader, 0, paramBytes, params->ParameterValues, &cb.buffer_offset, &cb.buffer); u_upload_unmap(st->constbuf_uploader); } else { cb.buffer = NULL; cb.user_buffer = params->ParameterValues; cb.buffer_offset = 0; } cb.buffer_size = paramBytes; if (ST_DEBUG & DEBUG_CONSTANTS) { debug_printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n", __func__, shader_type, params->NumParameters, params->StateFlags); _mesa_print_parameter_list(params); } cso_set_constant_buffer(st->cso_context, shader_type, 0, &cb); pipe_resource_reference(&cb.buffer, NULL); st->state.constants[shader_type].ptr = params->ParameterValues; st->state.constants[shader_type].size = paramBytes; } else if (st->state.constants[shader_type].ptr) { /* Unbind. */ st->state.constants[shader_type].ptr = NULL; st->state.constants[shader_type].size = 0; cso_set_constant_buffer(st->cso_context, shader_type, 0, NULL); } }
void cso_set_constant_buffer_resource(struct cso_context *cso, unsigned shader_stage, unsigned index, struct pipe_resource *buffer) { if (buffer) { struct pipe_constant_buffer cb; cb.buffer = buffer; cb.buffer_offset = 0; cb.buffer_size = buffer->width0; cb.user_buffer = NULL; cso_set_constant_buffer(cso, shader_stage, index, &cb); } else { cso_set_constant_buffer(cso, shader_stage, index, NULL); } }
void cso_restore_constant_buffer_slot0(struct cso_context *cso, unsigned shader_stage) { cso_set_constant_buffer(cso, shader_stage, 0, &cso->aux_constbuf_saved[shader_stage]); pipe_resource_reference(&cso->aux_constbuf_saved[shader_stage].buffer, NULL); }
static void st_bind_ubos(struct st_context *st, struct gl_program *prog, unsigned shader_type) { unsigned i; struct pipe_constant_buffer cb = { 0 }; if (!prog) return; for (i = 0; i < prog->info.num_ubos; i++) { struct gl_buffer_binding *binding; struct st_buffer_object *st_obj; binding = &st->ctx->UniformBufferBindings[prog->sh.UniformBlocks[i]->Binding]; st_obj = st_buffer_object(binding->BufferObject); cb.buffer = st_obj->buffer; if (cb.buffer) { cb.buffer_offset = binding->Offset; cb.buffer_size = cb.buffer->width0 - binding->Offset; /* AutomaticSize is FALSE if the buffer was set with BindBufferRange. * Take the minimum just to be sure. */ if (!binding->AutomaticSize) cb.buffer_size = MIN2(cb.buffer_size, (unsigned) binding->Size); } else { cb.buffer_offset = 0; cb.buffer_size = 0; } cso_set_constant_buffer(st->cso_context, shader_type, 1 + i, &cb); } }
/** * Pass the given program parameters to the graphics pipe as a * constant buffer. */ void st_upload_constants(struct st_context *st, struct gl_program *prog) { gl_shader_stage stage = prog->info.stage; struct gl_program_parameter_list *params = prog->Parameters; enum pipe_shader_type shader_type = pipe_shader_type_from_mesa(stage); assert(shader_type == PIPE_SHADER_VERTEX || shader_type == PIPE_SHADER_FRAGMENT || shader_type == PIPE_SHADER_GEOMETRY || shader_type == PIPE_SHADER_TESS_CTRL || shader_type == PIPE_SHADER_TESS_EVAL || shader_type == PIPE_SHADER_COMPUTE); /* update the ATI constants before rendering */ if (shader_type == PIPE_SHADER_FRAGMENT && st->fp->ati_fs) { struct ati_fragment_shader *ati_fs = st->fp->ati_fs; unsigned c; for (c = 0; c < MAX_NUM_FRAGMENT_CONSTANTS_ATI; c++) { if (ati_fs->LocalConstDef & (1 << c)) memcpy(params->ParameterValues[c], ati_fs->Constants[c], sizeof(GLfloat) * 4); else memcpy(params->ParameterValues[c], st->ctx->ATIFragmentShader.GlobalConstants[c], sizeof(GLfloat) * 4); } } /* Make all bindless samplers/images bound texture/image units resident in * the context. */ st_make_bound_samplers_resident(st, prog); st_make_bound_images_resident(st, prog); /* update constants */ if (params && params->NumParameters) { struct pipe_constant_buffer cb; const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4; /* Update the constants which come from fixed-function state, such as * transformation matrices, fog factors, etc. The rest of the values in * the parameters list are explicitly set by the user with glUniform, * glProgramParameter(), etc. */ if (params->StateFlags) _mesa_load_state_parameters(st->ctx, params); _mesa_shader_write_subroutine_indices(st->ctx, stage); cb.buffer = NULL; cb.user_buffer = params->ParameterValues; cb.buffer_offset = 0; cb.buffer_size = paramBytes; if (ST_DEBUG & DEBUG_CONSTANTS) { debug_printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n", __func__, shader_type, params->NumParameters, params->StateFlags); _mesa_print_parameter_list(params); } cso_set_constant_buffer(st->cso_context, shader_type, 0, &cb); pipe_resource_reference(&cb.buffer, NULL); st->state.constants[shader_type].ptr = params->ParameterValues; st->state.constants[shader_type].size = paramBytes; } else if (st->state.constants[shader_type].ptr) { /* Unbind. */ st->state.constants[shader_type].ptr = NULL; st->state.constants[shader_type].size = 0; cso_set_constant_buffer(st->cso_context, shader_type, 0, NULL); } }
/* Setup all vertex pipeline state, rasterizer state, and fragment shader * constants, and issue the draw call for PBO upload/download. * * The caller is responsible for saving and restoring state, as well as for * setting other fragment shader state (fragment shader, samplers), and * framebuffer/viewport/DSA/blend state. */ bool st_pbo_draw(struct st_context *st, const struct st_pbo_addresses *addr, unsigned surface_width, unsigned surface_height) { struct cso_context *cso = st->cso_context; /* Setup vertex and geometry shaders */ if (!st->pbo.vs) { st->pbo.vs = st_pbo_create_vs(st); if (!st->pbo.vs) return false; } if (addr->depth != 1 && st->pbo.use_gs && !st->pbo.gs) { st->pbo.gs = st_pbo_create_gs(st); if (!st->pbo.gs) return false; } cso_set_vertex_shader_handle(cso, st->pbo.vs); cso_set_geometry_shader_handle(cso, addr->depth != 1 ? st->pbo.gs : NULL); cso_set_tessctrl_shader_handle(cso, NULL); cso_set_tesseval_shader_handle(cso, NULL); /* Upload vertices */ { struct pipe_vertex_buffer vbo = {0}; struct pipe_vertex_element velem; float x0 = (float) addr->xoffset / surface_width * 2.0f - 1.0f; float y0 = (float) addr->yoffset / surface_height * 2.0f - 1.0f; float x1 = (float) (addr->xoffset + addr->width) / surface_width * 2.0f - 1.0f; float y1 = (float) (addr->yoffset + addr->height) / surface_height * 2.0f - 1.0f; float *verts = NULL; vbo.stride = 2 * sizeof(float); u_upload_alloc(st->pipe->stream_uploader, 0, 8 * sizeof(float), 4, &vbo.buffer_offset, &vbo.buffer.resource, (void **) &verts); if (!verts) return false; verts[0] = x0; verts[1] = y0; verts[2] = x0; verts[3] = y1; verts[4] = x1; verts[5] = y0; verts[6] = x1; verts[7] = y1; u_upload_unmap(st->pipe->stream_uploader); velem.src_offset = 0; velem.instance_divisor = 0; velem.vertex_buffer_index = 0; velem.src_format = PIPE_FORMAT_R32G32_FLOAT; cso_set_vertex_elements(cso, 1, &velem); cso_set_vertex_buffers(cso, velem.vertex_buffer_index, 1, &vbo); pipe_resource_reference(&vbo.buffer.resource, NULL); } /* Upload constants */ { struct pipe_constant_buffer cb; cb.buffer = NULL; cb.user_buffer = &addr->constants; cb.buffer_offset = 0; cb.buffer_size = sizeof(addr->constants); cso_set_constant_buffer(cso, PIPE_SHADER_FRAGMENT, 0, &cb); pipe_resource_reference(&cb.buffer, NULL); } /* Rasterizer state */ cso_set_rasterizer(cso, &st->pbo.raster); /* Disable stream output */ cso_set_stream_outputs(cso, 0, NULL, 0); if (addr->depth == 1) { cso_draw_arrays(cso, PIPE_PRIM_TRIANGLE_STRIP, 0, 4); } else { cso_draw_arrays_instanced(cso, PIPE_PRIM_TRIANGLE_STRIP, 0, 4, 0, addr->depth); } return true; }
/** * Pass the given program parameters to the graphics pipe as a * constant buffer. * \param shader_type either PIPE_SHADER_VERTEX or PIPE_SHADER_FRAGMENT */ void st_upload_constants( struct st_context *st, struct gl_program_parameter_list *params, gl_shader_stage stage) { enum pipe_shader_type shader_type = st_shader_stage_to_ptarget(stage); assert(shader_type == PIPE_SHADER_VERTEX || shader_type == PIPE_SHADER_FRAGMENT || shader_type == PIPE_SHADER_GEOMETRY || shader_type == PIPE_SHADER_TESS_CTRL || shader_type == PIPE_SHADER_TESS_EVAL || shader_type == PIPE_SHADER_COMPUTE); /* update the ATI constants before rendering */ if (shader_type == PIPE_SHADER_FRAGMENT && st->fp->ati_fs) { struct ati_fragment_shader *ati_fs = st->fp->ati_fs; unsigned c; for (c = 0; c < MAX_NUM_FRAGMENT_CONSTANTS_ATI; c++) { if (ati_fs->LocalConstDef & (1 << c)) memcpy(params->ParameterValues[c], ati_fs->Constants[c], sizeof(GLfloat) * 4); else memcpy(params->ParameterValues[c], st->ctx->ATIFragmentShader.GlobalConstants[c], sizeof(GLfloat) * 4); } } /* update constants */ if (params && params->NumParameters) { struct pipe_constant_buffer cb; const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4; /* Update the constants which come from fixed-function state, such as * transformation matrices, fog factors, etc. The rest of the values in * the parameters list are explicitly set by the user with glUniform, * glProgramParameter(), etc. */ if (params->StateFlags) _mesa_load_state_parameters(st->ctx, params); _mesa_shader_write_subroutine_indices(st->ctx, stage); /* We always need to get a new buffer, to keep the drivers simple and * avoid gratuitous rendering synchronization. * Let's use a user buffer to avoid an unnecessary copy. */ if (st->constbuf_uploader) { cb.buffer = NULL; cb.user_buffer = NULL; u_upload_data(st->constbuf_uploader, 0, paramBytes, st->ctx->Const.UniformBufferOffsetAlignment, params->ParameterValues, &cb.buffer_offset, &cb.buffer); u_upload_unmap(st->constbuf_uploader); } else { cb.buffer = NULL; cb.user_buffer = params->ParameterValues; cb.buffer_offset = 0; } cb.buffer_size = paramBytes; if (ST_DEBUG & DEBUG_CONSTANTS) { debug_printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n", __func__, shader_type, params->NumParameters, params->StateFlags); _mesa_print_parameter_list(params); } cso_set_constant_buffer(st->cso_context, shader_type, 0, &cb); pipe_resource_reference(&cb.buffer, NULL); st->state.constants[shader_type].ptr = params->ParameterValues; st->state.constants[shader_type].size = paramBytes; } else if (st->state.constants[shader_type].ptr) { /* Unbind. */ st->state.constants[shader_type].ptr = NULL; st->state.constants[shader_type].size = 0; cso_set_constant_buffer(st->cso_context, shader_type, 0, NULL); } }