/**
* Convert from PIPE_SHADER_* to SVGA3D_SHADERTYPE_*
*/
-static int
+static unsigned
svga_shader_type(unsigned shader)
{
- assert(PIPE_SHADER_VERTEX + 1 == SVGA3D_SHADERTYPE_VS);
- assert(PIPE_SHADER_FRAGMENT + 1 == SVGA3D_SHADERTYPE_PS);
- assert(shader <= PIPE_SHADER_FRAGMENT);
- return shader + 1;
+ switch (shader) {
+ case PIPE_SHADER_VERTEX:
+ return SVGA3D_SHADERTYPE_VS;
+ case PIPE_SHADER_FRAGMENT:
+ return SVGA3D_SHADERTYPE_PS;
+ default:
+ assert(!"Unexpected shader type");
+ return SVGA3D_SHADERTYPE_VS;
+ }
}
static enum pipe_error
emit_fs_consts(struct svga_context *svga, unsigned dirty)
{
- const struct svga_shader_result *result = svga->state.hw_draw.fs;
- const struct svga_fs_compile_key *key = &result->key.fkey;
+ const struct svga_shader_variant *variant = svga->state.hw_draw.fs;
enum pipe_error ret = PIPE_OK;
ret = emit_consts( svga, PIPE_SHADER_FRAGMENT );
return ret;
/* The internally generated fragment shader for xor blending
- * doesn't have a 'result' struct. It should be fixed to avoid
+ * doesn't have a 'variant' struct. It should be fixed to avoid
* this special case, but work around it with a NULL check:
*/
- if (result != NULL && key->num_unnormalized_coords) {
- unsigned offset = result->shader->info.file_max[TGSI_FILE_CONSTANT] + 1;
- int 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.0 / (float)tex->width0;
- data[1] = 1.0 / (float)tex->height0;
- data[2] = 1.0;
- data[3] = 1.0;
-
- ret = emit_const( svga,
- PIPE_SHADER_FRAGMENT,
- key->tex[i].width_height_idx + offset,
- data );
- if (ret != PIPE_OK)
- return ret;
+ if (variant) {
+ const struct svga_fs_compile_key *key = &variant->key.fkey;
+ if (key->num_unnormalized_coords) {
+ const unsigned offset =
+ variant->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;
+ }
+ }
}
}
-
- offset += key->num_unnormalized_coords;
}
return PIPE_OK;
}
-struct svga_tracked_state svga_hw_fs_parameters =
+struct svga_tracked_state svga_hw_fs_constants =
{
"hw fs params",
(SVGA_NEW_FS_CONST_BUFFER |
- SVGA_NEW_FS_RESULT |
+ SVGA_NEW_FS_VARIANT |
SVGA_NEW_TEXTURE_BINDING),
emit_fs_consts
};
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;
+ const struct svga_vs_compile_key *key;
enum pipe_error ret = PIPE_OK;
unsigned offset;
- /* SVGA_NEW_VS_RESULT
+ /* SVGA_NEW_VS_VARIANT
*/
- if (result == NULL)
+ if (variant == NULL)
return PIPE_OK;
+ key = &variant->key.vkey;
+
/* SVGA_NEW_VS_CONST_BUFFER
*/
ret = emit_consts( svga, PIPE_SHADER_VERTEX );
return ret;
/* offset = number of constants in the VS const buffer */
- offset = result->shader->info.file_max[TGSI_FILE_CONSTANT] + 1;
+ offset = variant->shader->info.file_max[TGSI_FILE_CONSTANT] + 1;
- /* SVGA_NEW_VS_RESULT
+ /* SVGA_NEW_VS_PRESCALE
* Put the viewport pre-scale/translate values into the const buffer.
*/
if (key->need_prescale) {
return ret;
}
- /* SVGA_NEW_ZERO_STRIDE
- * Put the zero-stride vertex array attributes into the const buffer.
- */
- if (key->zero_stride_vertex_elements) {
- unsigned i, curr_zero_stride = 0;
- for (i = 0; i < PIPE_MAX_ATTRIBS; ++i) {
- if (key->zero_stride_vertex_elements & (1 << i)) {
- ret = emit_const( svga, PIPE_SHADER_VERTEX, offset++,
- svga->curr.zero_stride_constants +
- 4 * curr_zero_stride );
- if (ret != PIPE_OK)
- return ret;
- ++curr_zero_stride;
- }
- }
- }
-
return PIPE_OK;
}
-struct svga_tracked_state svga_hw_vs_parameters =
+struct svga_tracked_state svga_hw_vs_constants =
{
"hw vs params",
(SVGA_NEW_PRESCALE |
SVGA_NEW_VS_CONST_BUFFER |
- SVGA_NEW_ZERO_STRIDE |
- SVGA_NEW_VS_RESULT),
+ SVGA_NEW_VS_VARIANT),
emit_vs_consts
};