X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fsvga%2Fsvga_state_constants.c;h=8d6b46a1cae8545a98f6d69034bee2ed7eddd8d1;hb=a4ace98a9733b3e83d971f4871c2908749c0e5c8;hp=a871154177620d353063cc09f4523ab5022f1229;hpb=50188adf7d4ca12488a3cb4b70ffdedea2e9c9b1;p=mesa.git diff --git a/src/gallium/drivers/svga/svga_state_constants.c b/src/gallium/drivers/svga/svga_state_constants.c index a8711541776..8d6b46a1cae 100644 --- a/src/gallium/drivers/svga/svga_state_constants.c +++ b/src/gallium/drivers/svga/svga_state_constants.c @@ -1,3 +1,4 @@ + /********************************************************** * Copyright 2008-2009 VMware, Inc. All rights reserved. * @@ -23,8 +24,11 @@ * **********************************************************/ +#include "util/u_format.h" #include "util/u_inlines.h" +#include "util/u_memory.h" #include "pipe/p_defines.h" +#include "util/u_upload_mgr.h" #include "svga_screen.h" #include "svga_context.h" @@ -32,6 +36,8 @@ #include "svga_cmd.h" #include "svga_tgsi.h" #include "svga_debug.h" +#include "svga_resource_buffer.h" +#include "svga_shader.h" #include "svga_hw_reg.h" @@ -41,21 +47,223 @@ */ #define MAX_CONST_REG_COUNT 256 /**< number of float[4] constants */ +/** + * Extra space for svga-specific VS/PS constants (such as texcoord + * scale factors, vertex transformation scale/translation). + */ +#define MAX_EXTRA_CONSTS 32 + +/** Guest-backed surface constant buffers must be this size */ +#define GB_CONSTBUF_SIZE (SVGA3D_CONSTREG_MAX) /** - * Convert from PIPE_SHADER_* to SVGA3D_SHADERTYPE_* + * Emit any extra shader-type-independent shader constants into the buffer + * pointed to by 'dest'. + * \return number of float[4] constants put into the 'dest' buffer */ -static int -svga_shader_type(unsigned shader) +static unsigned +svga_get_extra_constants_common(struct svga_context *svga, + const struct svga_shader_variant *variant, + enum pipe_shader_type shader, float *dest) { - assert(PIPE_SHADER_VERTEX + 1 == SVGA3D_SHADERTYPE_VS); - assert(PIPE_SHADER_FRAGMENT + 1 == SVGA3D_SHADERTYPE_PS); - assert(shader <= PIPE_SHADER_FRAGMENT); - return shader + 1; + uint32_t *dest_u = (uint32_t *) dest; // uint version of dest + unsigned i; + unsigned count = 0; + + for (i = 0; i < variant->key.num_textures; i++) { + struct pipe_sampler_view *sv = svga->curr.sampler_views[shader][i]; + if (sv) { + struct pipe_resource *tex = sv->texture; + /* Scaling factors needed for handling unnormalized texture coordinates + * for texture rectangles. + */ + if (variant->key.tex[i].unnormalized) { + /* debug/sanity check */ + assert(variant->key.tex[i].width_height_idx == count); + + *dest++ = 1.0 / (float)tex->width0; + *dest++ = 1.0 / (float)tex->height0; + *dest++ = 1.0; + *dest++ = 1.0; + + count++; + } + + /* Store the sizes for texture buffers. + */ + if (tex->target == PIPE_BUFFER) { + unsigned bytes_per_element = util_format_get_blocksize(sv->format); + *dest_u++ = tex->width0 / bytes_per_element; + *dest_u++ = 1; + *dest_u++ = 1; + *dest_u++ = 1; + + count++; + } + } + } + + return count; } +/** + * Emit any extra fragment shader constants into the buffer pointed + * to by 'dest'. + * \return number of float[4] constants put into the dest buffer + */ +static unsigned +svga_get_extra_fs_constants(struct svga_context *svga, float *dest) +{ + const struct svga_shader_variant *variant = svga->state.hw_draw.fs; + unsigned count = 0; + + count += svga_get_extra_constants_common(svga, variant, + PIPE_SHADER_FRAGMENT, dest); + + assert(count <= MAX_EXTRA_CONSTS); + + return count; +} + +/** + * Emit extra constants needed for prescale computation into the + * the buffer pointed to by '*dest'. The updated buffer pointer + * will be returned in 'dest'. + */ +static unsigned +svga_get_prescale_constants(struct svga_context *svga, float **dest) +{ + memcpy(*dest, svga->state.hw_clear.prescale.scale, 4 * sizeof(float)); + *dest += 4; + + memcpy(*dest, svga->state.hw_clear.prescale.translate, 4 * sizeof(float)); + *dest += 4; + + return 2; +} + +/** + * Emit extra constants needed for point sprite emulation. + */ +static unsigned +svga_get_pt_sprite_constants(struct svga_context *svga, float **dest) +{ + struct svga_screen *screen = svga_screen(svga->pipe.screen); + float *dst = *dest; + + dst[0] = 1.0 / (svga->curr.viewport.scale[0] * 2); + dst[1] = 1.0 / (svga->curr.viewport.scale[1] * 2); + dst[2] = svga->curr.rast->pointsize; + dst[3] = screen->maxPointSize; + *dest = *dest + 4; + return 1; +} + +/** + * Emit user-defined clip plane coefficients into the buffer pointed to + * by '*dest'. The updated buffer pointer will be returned in 'dest'. + */ +static unsigned +svga_get_clip_plane_constants(struct svga_context *svga, + const struct svga_shader_variant *variant, + float **dest) +{ + unsigned count = 0; + + /* SVGA_NEW_CLIP */ + if (svga_have_vgpu10(svga)) { + /* append user-defined clip plane coefficients onto constant buffer */ + unsigned clip_planes = variant->key.clip_plane_enable; + while (clip_planes) { + int i = u_bit_scan(&clip_planes); + COPY_4V(*dest, svga->curr.clip.ucp[i]); + *dest += 4; + count += 1; + } + } + return count; +} + +/** + * Emit any extra vertex shader constants into the buffer pointed + * to by 'dest'. + * In particular, these would be the scale and bias factors computed + * from the framebuffer size which are used to copy with differences in + * GL vs D3D coordinate spaces. See svga_tgsi_insn.c for more info. + * \return number of float[4] constants put into the dest buffer + */ +static unsigned +svga_get_extra_vs_constants(struct svga_context *svga, float *dest) +{ + const struct svga_shader_variant *variant = svga->state.hw_draw.vs; + unsigned count = 0; + + /* SVGA_NEW_VS_VARIANT + */ + if (variant->key.vs.need_prescale) { + count += svga_get_prescale_constants(svga, &dest); + } + + if (variant->key.vs.undo_viewport) { + /* Used to convert window coords back to NDC coords */ + dest[0] = 1.0f / svga->curr.viewport.scale[0]; + dest[1] = 1.0f / svga->curr.viewport.scale[1]; + dest[2] = -svga->curr.viewport.translate[0]; + dest[3] = -svga->curr.viewport.translate[1]; + dest += 4; + count += 1; + } + + /* SVGA_NEW_CLIP */ + count += svga_get_clip_plane_constants(svga, variant, &dest); + + /* common constants */ + count += svga_get_extra_constants_common(svga, variant, + PIPE_SHADER_VERTEX, dest); + + assert(count <= MAX_EXTRA_CONSTS); + + return count; +} + +/** + * Emit any extra geometry shader constants into the buffer pointed + * to by 'dest'. + */ +static unsigned +svga_get_extra_gs_constants(struct svga_context *svga, float *dest) +{ + const struct svga_shader_variant *variant = svga->state.hw_draw.gs; + unsigned count = 0; + + /* SVGA_NEW_GS_VARIANT + */ + + /* Constants for point sprite + * These are used in the transformed gs that supports point sprite. + * They need to be added before the prescale constants. + */ + if (variant->key.gs.wide_point) { + count += svga_get_pt_sprite_constants(svga, &dest); + } + + if (variant->key.gs.need_prescale) { + count += svga_get_prescale_constants(svga, &dest); + } + + /* SVGA_NEW_CLIP */ + count += svga_get_clip_plane_constants(svga, variant, &dest); + + /* common constants */ + count += svga_get_extra_constants_common(svga, variant, + PIPE_SHADER_GEOMETRY, dest); + + assert(count <= MAX_EXTRA_CONSTS); + return count; +} + /** * Check and emit one shader constant register. * \param shader PIPE_SHADER_FRAGMENT or PIPE_SHADER_VERTEX @@ -63,13 +271,14 @@ svga_shader_type(unsigned shader) * \param value the new float[4] value */ static enum pipe_error -emit_const(struct svga_context *svga, unsigned shader, unsigned i, +emit_const(struct svga_context *svga, enum pipe_shader_type shader, unsigned i, const float *value) { enum pipe_error ret = PIPE_OK; assert(shader < PIPE_SHADER_TYPES); assert(i < SVGA3D_CONSTREG_MAX); + assert(!svga_have_vgpu10(svga)); if (memcmp(svga->state.hw_draw.cb[shader][i], value, 4 * sizeof(float)) != 0) { @@ -92,6 +301,8 @@ emit_const(struct svga_context *svga, unsigned shader, unsigned i, return ret; memcpy(svga->state.hw_draw.cb[shader][i], value, 4 * sizeof(float)); + + svga->hud.num_const_updates++; } return ret; @@ -105,7 +316,7 @@ emit_const(struct svga_context *svga, unsigned shader, unsigned i, */ static enum pipe_error emit_const_range(struct svga_context *svga, - unsigned shader, + enum pipe_shader_type shader, unsigned offset, unsigned count, const float (*values)[4]) @@ -113,10 +324,14 @@ emit_const_range(struct svga_context *svga, unsigned i, j; enum pipe_error ret; + assert(shader == PIPE_SHADER_VERTEX || + shader == PIPE_SHADER_FRAGMENT); + assert(!svga_have_vgpu10(svga)); + #ifdef DEBUG if (offset + count > SVGA3D_CONSTREG_MAX) { - debug_printf("svga: too many constants (offset + count = %u)\n", - offset + count); + debug_printf("svga: too many constants (offset %u + count %u = %u (max = %u))\n", + offset, count, offset + count, SVGA3D_CONSTREG_MAX); } #endif @@ -180,11 +395,21 @@ emit_const_range(struct svga_context *svga, /* Send them all together. */ - ret = SVGA3D_SetShaderConsts(svga->swc, - offset + i, j - i, - svga_shader_type(shader), - SVGA3D_CONST_TYPE_FLOAT, - values + i); + if (svga_have_gb_objects(svga)) { + ret = SVGA3D_SetGBShaderConstsInline(svga->swc, + offset + i, /* start */ + j - i, /* count */ + svga_shader_type(shader), + SVGA3D_CONST_TYPE_FLOAT, + values + i); + } + else { + ret = SVGA3D_SetShaderConsts(svga->swc, + offset + i, j - i, + svga_shader_type(shader), + SVGA3D_CONST_TYPE_FLOAT, + values + i); + } if (ret != PIPE_OK) { return ret; } @@ -197,6 +422,9 @@ emit_const_range(struct svga_context *svga, (j - i) * 4 * sizeof(float)); i = j + 1; + + svga->hud.num_const_updates++; + } else { ++i; } @@ -208,10 +436,12 @@ emit_const_range(struct svga_context *svga, /** * Emit all the constants in a constant buffer for a shader stage. + * On VGPU10, emit_consts_vgpu10 is used instead. */ static enum pipe_error -emit_consts(struct svga_context *svga, unsigned shader) +emit_consts_vgpu9(struct svga_context *svga, enum pipe_shader_type shader) { + const struct pipe_constant_buffer *cbuf; struct svga_screen *ss = svga_screen(svga->pipe.screen); struct pipe_transfer *transfer = NULL; unsigned count; @@ -221,87 +451,349 @@ emit_consts(struct svga_context *svga, unsigned shader) const unsigned offset = 0; assert(shader < PIPE_SHADER_TYPES); + assert(!svga_have_vgpu10(svga)); + /* Only one constant buffer per shader is supported before VGPU10. + * This is only an approximate check against that. + */ + assert(svga->curr.constbufs[shader][1].buffer == NULL); + + cbuf = &svga->curr.constbufs[shader][0]; - if (svga->curr.cb[shader] == NULL) - goto done; + if (svga->curr.constbufs[shader][0].buffer) { + /* emit user-provided constants */ + data = (const float (*)[4]) + pipe_buffer_map(&svga->pipe, svga->curr.constbufs[shader][0].buffer, + PIPE_TRANSFER_READ, &transfer); + if (!data) { + return PIPE_ERROR_OUT_OF_MEMORY; + } - count = svga->curr.cb[shader]->width0 / (4 * sizeof(float)); + /* sanity check */ + assert(cbuf->buffer->width0 >= + cbuf->buffer_size); - data = (const float (*)[4])pipe_buffer_map(&svga->pipe, - svga->curr.cb[shader], - PIPE_TRANSFER_READ, - &transfer); - if (data == NULL) { - ret = PIPE_ERROR_OUT_OF_MEMORY; - goto done; - } + /* Use/apply the constant buffer size and offsets here */ + count = cbuf->buffer_size / (4 * sizeof(float)); + data += cbuf->buffer_offset / (4 * sizeof(float)); - if (ss->hw_version >= SVGA3D_HWVERSION_WS8_B1) { - ret = emit_const_range( svga, shader, offset, count, data ); - if (ret != PIPE_OK) { - goto done; + if (ss->hw_version >= SVGA3D_HWVERSION_WS8_B1) { + ret = emit_const_range( svga, shader, offset, count, data ); } - } else { - for (i = 0; i < count; i++) { - ret = emit_const( svga, shader, offset + i, data[i] ); - if (ret != PIPE_OK) { - goto done; + else { + for (i = 0; i < count; i++) { + ret = emit_const( svga, shader, offset + i, data[i] ); + if (ret != PIPE_OK) { + break; + } } } - } -done: - if (data) pipe_buffer_unmap(&svga->pipe, transfer); + if (ret != PIPE_OK) { + return ret; + } + } + + /* emit extra shader constants */ + { + const struct svga_shader_variant *variant = NULL; + unsigned offset; + float extras[MAX_EXTRA_CONSTS][4]; + unsigned count, i; + + switch (shader) { + case PIPE_SHADER_VERTEX: + variant = svga->state.hw_draw.vs; + count = svga_get_extra_vs_constants(svga, (float *) extras); + break; + case PIPE_SHADER_FRAGMENT: + variant = svga->state.hw_draw.fs; + count = svga_get_extra_fs_constants(svga, (float *) extras); + break; + default: + assert(!"Unexpected shader type"); + count = 0; + } + + assert(variant); + offset = variant->shader->info.file_max[TGSI_FILE_CONSTANT] + 1; + assert(count <= ARRAY_SIZE(extras)); + + if (count > 0) { + if (ss->hw_version >= SVGA3D_HWVERSION_WS8_B1) { + ret = emit_const_range(svga, shader, offset, count, + (const float (*) [4])extras); + } + else { + for (i = 0; i < count; i++) { + ret = emit_const(svga, shader, offset + i, extras[i]); + if (ret != PIPE_OK) + return ret; + } + } + } + } + return ret; } + static enum pipe_error -emit_fs_consts(struct svga_context *svga, unsigned dirty) +emit_constbuf_vgpu10(struct svga_context *svga, enum pipe_shader_type shader) { - const struct svga_shader_result *result = svga->state.hw_draw.fs; + const struct pipe_constant_buffer *cbuf; + struct pipe_resource *dst_buffer = NULL; enum pipe_error ret = PIPE_OK; + struct pipe_transfer *src_transfer; + struct svga_winsys_surface *dst_handle; + float extras[MAX_EXTRA_CONSTS][4]; + unsigned extra_count, extra_size, extra_offset; + unsigned new_buf_size; + void *src_map = NULL, *dst_map; + unsigned offset; + const struct svga_shader_variant *variant; + unsigned alloc_buf_size; + + assert(shader == PIPE_SHADER_VERTEX || + shader == PIPE_SHADER_GEOMETRY || + shader == PIPE_SHADER_FRAGMENT); + + cbuf = &svga->curr.constbufs[shader][0]; + + switch (shader) { + case PIPE_SHADER_VERTEX: + variant = svga->state.hw_draw.vs; + extra_count = svga_get_extra_vs_constants(svga, (float *) extras); + break; + case PIPE_SHADER_FRAGMENT: + variant = svga->state.hw_draw.fs; + extra_count = svga_get_extra_fs_constants(svga, (float *) extras); + break; + case PIPE_SHADER_GEOMETRY: + variant = svga->state.hw_draw.gs; + extra_count = svga_get_extra_gs_constants(svga, (float *) extras); + break; + default: + assert(!"Unexpected shader type"); + /* Don't return an error code since we don't want to keep re-trying + * this function and getting stuck in an infinite loop. + */ + return PIPE_OK; + } + + assert(variant); + + /* Compute extra constants size and offset in bytes */ + extra_size = extra_count * 4 * sizeof(float); + extra_offset = 4 * sizeof(float) * variant->extra_const_start; + + if (cbuf->buffer_size + extra_size == 0) + return PIPE_OK; /* nothing to do */ + + /* Typically, the cbuf->buffer here is a user-space buffer so mapping + * it is really cheap. If we ever get real HW buffers for constants + * we should void mapping and instead use a ResourceCopy command. + */ + if (cbuf->buffer_size > 0) { + src_map = pipe_buffer_map_range(&svga->pipe, cbuf->buffer, + cbuf->buffer_offset, cbuf->buffer_size, + PIPE_TRANSFER_READ, &src_transfer); + assert(src_map); + if (!src_map) { + return PIPE_ERROR_OUT_OF_MEMORY; + } + } + + /* The new/dest buffer's size must be large enough to hold the original, + * user-specified constants, plus the extra constants. + * The size of the original constant buffer _should_ agree with what the + * shader is expecting, but it might not (it's not enforced anywhere by + * gallium). + */ + new_buf_size = MAX2(cbuf->buffer_size, extra_offset) + extra_size; + + /* According to the DX10 spec, the constant buffer size must be + * in multiples of 16. + */ + new_buf_size = align(new_buf_size, 16); + + /* Constant buffer size in the upload buffer must be in multiples of 256. + * In order to maximize the chance of merging the upload buffer chunks + * when svga_buffer_add_range() is called, + * the allocate buffer size needs to be in multiples of 256 as well. + * Otherwise, since there is gap between each dirty range of the upload buffer, + * each dirty range will end up in its own UPDATE_GB_IMAGE command. + */ + alloc_buf_size = align(new_buf_size, CONST0_UPLOAD_ALIGNMENT); + + u_upload_alloc(svga->const0_upload, 0, alloc_buf_size, + CONST0_UPLOAD_ALIGNMENT, &offset, + &dst_buffer, &dst_map); + if (!dst_map) { + if (src_map) + pipe_buffer_unmap(&svga->pipe, src_transfer); + return PIPE_ERROR_OUT_OF_MEMORY; + } - ret = emit_consts( svga, PIPE_SHADER_FRAGMENT ); - if (ret != PIPE_OK) + if (src_map) { + memcpy(dst_map, src_map, cbuf->buffer_size); + pipe_buffer_unmap(&svga->pipe, src_transfer); + } + + if (extra_size) { + assert(extra_offset + extra_size <= new_buf_size); + memcpy((char *) dst_map + extra_offset, extras, extra_size); + } + + /* Get winsys handle for the constant buffer */ + if (svga->state.hw_draw.const0_buffer == dst_buffer && + svga->state.hw_draw.const0_handle) { + /* re-reference already mapped buffer */ + dst_handle = svga->state.hw_draw.const0_handle; + } + else { + /* we must unmap the buffer before getting the winsys handle */ + u_upload_unmap(svga->const0_upload); + + dst_handle = svga_buffer_handle(svga, dst_buffer); + if (!dst_handle) { + pipe_resource_reference(&dst_buffer, NULL); + return PIPE_ERROR_OUT_OF_MEMORY; + } + + /* save the buffer / handle for next time */ + pipe_resource_reference(&svga->state.hw_draw.const0_buffer, dst_buffer); + svga->state.hw_draw.const0_handle = dst_handle; + } + + /* Issue the SetSingleConstantBuffer command */ + assert(new_buf_size % 16 == 0); + ret = SVGA3D_vgpu10_SetSingleConstantBuffer(svga->swc, + 0, /* index */ + svga_shader_type(shader), + dst_handle, + offset, + new_buf_size); + + if (ret != PIPE_OK) { + pipe_resource_reference(&dst_buffer, NULL); return ret; + } - /* The internally generated fragment shader for xor blending - * doesn't have a 'result' struct. It should be fixed to avoid - * this special case, but work around it with a NULL check: + /* Save this const buffer until it's replaced in the future. + * Otherwise, all references to the buffer will go away after the + * command buffer is submitted, it'll get recycled and we will have + * incorrect constant buffer bindings. */ - if (result) { - const struct svga_fs_compile_key *key = &result->key.fkey; - if (key->num_unnormalized_coords) { - const unsigned offset = - result->shader->info.file_max[TGSI_FILE_CONSTANT] + 1; - unsigned i; - - for (i = 0; i < key->num_textures; i++) { - if (key->tex[i].unnormalized) { - struct pipe_resource *tex = svga->curr.sampler_views[i]->texture; - float data[4]; - - data[0] = 1.0f / (float) tex->width0; - data[1] = 1.0f / (float) tex->height0; - data[2] = 1.0f; - data[3] = 1.0f; - - ret = emit_const(svga, - PIPE_SHADER_FRAGMENT, - key->tex[i].width_height_idx + offset, - data); - if (ret != PIPE_OK) { - return ret; - } - } + pipe_resource_reference(&svga->state.hw_draw.constbuf[shader], dst_buffer); + + svga->state.hw_draw.default_constbuf_size[shader] = new_buf_size; + + pipe_resource_reference(&dst_buffer, NULL); + + svga->hud.num_const_buf_updates++; + + return ret; +} + + +static enum pipe_error +emit_consts_vgpu10(struct svga_context *svga, enum pipe_shader_type shader) +{ + enum pipe_error ret; + unsigned dirty_constbufs; + unsigned enabled_constbufs; + + /* Emit 0th constant buffer (with extra constants) */ + ret = emit_constbuf_vgpu10(svga, shader); + if (ret != PIPE_OK) { + return ret; + } + + enabled_constbufs = svga->state.hw_draw.enabled_constbufs[shader] | 1u; + + /* Emit other constant buffers (UBOs) */ + dirty_constbufs = svga->state.dirty_constbufs[shader] & ~1u; + + while (dirty_constbufs) { + unsigned index = u_bit_scan(&dirty_constbufs); + unsigned offset = svga->curr.constbufs[shader][index].buffer_offset; + unsigned size = svga->curr.constbufs[shader][index].buffer_size; + struct svga_buffer *buffer = + svga_buffer(svga->curr.constbufs[shader][index].buffer); + struct svga_winsys_surface *handle; + + if (buffer) { + handle = svga_buffer_handle(svga, &buffer->b.b); + enabled_constbufs |= 1 << index; + } + else { + handle = NULL; + enabled_constbufs &= ~(1 << index); + assert(offset == 0); + assert(size == 0); + } + + if (size % 16 != 0) { + /* GL's buffer range sizes can be any number of bytes but the + * SVGA3D device requires a multiple of 16 bytes. + */ + const unsigned total_size = buffer->b.b.width0; + + if (offset + align(size, 16) <= total_size) { + /* round up size to multiple of 16 */ + size = align(size, 16); + } + else { + /* round down to mulitple of 16 (this may cause rendering problems + * but should avoid a device error). + */ + size &= ~15; } } + + assert(size % 16 == 0); + ret = SVGA3D_vgpu10_SetSingleConstantBuffer(svga->swc, + index, + svga_shader_type(shader), + handle, + offset, + size); + if (ret != PIPE_OK) + return ret; + + svga->hud.num_const_buf_updates++; } - return PIPE_OK; + svga->state.hw_draw.enabled_constbufs[shader] = enabled_constbufs; + svga->state.dirty_constbufs[shader] = 0; + + return ret; +} + +static enum pipe_error +emit_fs_consts(struct svga_context *svga, unsigned dirty) +{ + const struct svga_shader_variant *variant = svga->state.hw_draw.fs; + enum pipe_error ret = PIPE_OK; + + /* SVGA_NEW_FS_VARIANT + */ + if (!variant) + return PIPE_OK; + + /* SVGA_NEW_FS_CONST_BUFFER + */ + if (svga_have_vgpu10(svga)) { + ret = emit_consts_vgpu10(svga, PIPE_SHADER_FRAGMENT); + } + else { + ret = emit_consts_vgpu9(svga, PIPE_SHADER_FRAGMENT); + } + + return ret; } @@ -309,8 +801,8 @@ struct svga_tracked_state svga_hw_fs_constants = { "hw fs params", (SVGA_NEW_FS_CONST_BUFFER | - SVGA_NEW_FS_RESULT | - SVGA_NEW_TEXTURE_BINDING), + SVGA_NEW_FS_VARIANT | + SVGA_NEW_TEXTURE_CONSTS), emit_fs_consts }; @@ -319,41 +811,24 @@ struct svga_tracked_state svga_hw_fs_constants = static enum pipe_error emit_vs_consts(struct svga_context *svga, unsigned dirty) { - const struct svga_shader_result *result = svga->state.hw_draw.vs; - const struct svga_vs_compile_key *key = &result->key.vkey; + const struct svga_shader_variant *variant = svga->state.hw_draw.vs; enum pipe_error ret = PIPE_OK; - unsigned offset; - /* SVGA_NEW_VS_RESULT + /* SVGA_NEW_VS_VARIANT */ - if (result == NULL) + if (!variant) return PIPE_OK; /* SVGA_NEW_VS_CONST_BUFFER */ - ret = emit_consts( svga, PIPE_SHADER_VERTEX ); - if (ret != PIPE_OK) - return ret; - - /* offset = number of constants in the VS const buffer */ - offset = result->shader->info.file_max[TGSI_FILE_CONSTANT] + 1; - - /* SVGA_NEW_VS_PRESCALE - * Put the viewport pre-scale/translate values into the const buffer. - */ - if (key->need_prescale) { - ret = emit_const( svga, PIPE_SHADER_VERTEX, offset++, - svga->state.hw_clear.prescale.scale ); - if (ret != PIPE_OK) - return ret; - - ret = emit_const( svga, PIPE_SHADER_VERTEX, offset++, - svga->state.hw_clear.prescale.translate ); - if (ret != PIPE_OK) - return ret; + if (svga_have_vgpu10(svga)) { + ret = emit_consts_vgpu10(svga, PIPE_SHADER_VERTEX); + } + else { + ret = emit_consts_vgpu9(svga, PIPE_SHADER_VERTEX); } - return PIPE_OK; + return ret; } @@ -362,6 +837,45 @@ struct svga_tracked_state svga_hw_vs_constants = "hw vs params", (SVGA_NEW_PRESCALE | SVGA_NEW_VS_CONST_BUFFER | - SVGA_NEW_VS_RESULT), + SVGA_NEW_VS_VARIANT), emit_vs_consts }; + + +static enum pipe_error +emit_gs_consts(struct svga_context *svga, unsigned dirty) +{ + const struct svga_shader_variant *variant = svga->state.hw_draw.gs; + enum pipe_error ret = PIPE_OK; + + /* SVGA_NEW_GS_VARIANT + */ + if (!variant) + return PIPE_OK; + + /* SVGA_NEW_GS_CONST_BUFFER + */ + if (svga_have_vgpu10(svga)) { + /** + * If only the rasterizer state has changed and the current geometry + * shader does not emit wide points, then there is no reason to + * re-emit the GS constants, so skip it. + */ + if (dirty == SVGA_NEW_RAST && !variant->key.gs.wide_point) + return PIPE_OK; + + ret = emit_consts_vgpu10(svga, PIPE_SHADER_GEOMETRY); + } + + return ret; +} + + +struct svga_tracked_state svga_hw_gs_constants = +{ + "hw gs params", + (SVGA_NEW_GS_CONST_BUFFER | + SVGA_NEW_RAST | + SVGA_NEW_GS_VARIANT), + emit_gs_consts +};