+static void
+swr_update_constants(struct swr_context *ctx, enum pipe_shader_type shaderType)
+{
+ swr_draw_context *pDC = &ctx->swrDC;
+
+ const float **constant;
+ uint32_t *num_constants;
+ struct swr_scratch_space *scratch;
+
+ switch (shaderType) {
+ case PIPE_SHADER_VERTEX:
+ constant = pDC->constantVS;
+ num_constants = pDC->num_constantsVS;
+ scratch = &ctx->scratch->vs_constants;
+ break;
+ case PIPE_SHADER_FRAGMENT:
+ constant = pDC->constantFS;
+ num_constants = pDC->num_constantsFS;
+ scratch = &ctx->scratch->fs_constants;
+ break;
+ default:
+ debug_printf("Unsupported shader type constants\n");
+ return;
+ }
+
+ for (UINT i = 0; i < PIPE_MAX_CONSTANT_BUFFERS; i++) {
+ const pipe_constant_buffer *cb = &ctx->constants[shaderType][i];
+ num_constants[i] = cb->buffer_size;
+ if (cb->buffer) {
+ constant[i] =
+ (const float *)(swr_resource_data(cb->buffer) +
+ cb->buffer_offset);
+ } else {
+ /* Need to copy these constants to scratch space */
+ if (cb->user_buffer && cb->buffer_size) {
+ const void *ptr =
+ ((const uint8_t *)cb->user_buffer + cb->buffer_offset);
+ uint32_t size = AlignUp(cb->buffer_size, 4);
+ ptr = swr_copy_to_scratch_space(ctx, scratch, ptr, size);
+ constant[i] = (const float *)ptr;
+ }
+ }
+ }
+}
+