i915_state.c revision c0bf7322088715bb411068c3d631b0c4be8cdff5
101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell/**************************************************************************
201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell *
301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * All Rights Reserved.
501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell *
601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * copy of this software and associated documentation files (the
801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * "Software"), to deal in the Software without restriction, including
901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
1001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
1101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * permit persons to whom the Software is furnished to do so, subject to
1201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * the following conditions:
1301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell *
1401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * The above copyright notice and this permission notice (including the
1501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * next paragraph) shall be included in all copies or substantial portions
1601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * of the Software.
1701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell *
1801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
2101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
2201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell *
2601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell **************************************************************************/
2701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
2801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell/* Authors:  Keith Whitwell <keith@tungstengraphics.com>
2901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell */
300d9bcdbeb11ad1ce7e5257f652ccf9ebf1aa59a7Brian
3101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
3201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell#include "pipe/draw/draw_context.h"
33c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian#include "pipe/p_winsys.h"
3401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
3501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell#include "i915_context.h"
3601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell#include "i915_state.h"
3701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
3801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell/* None of this state is actually used for anything yet.
3901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell */
409780327c5d95586a88fce94d7b47342355ead118Zack Rusin
41c0bf7322088715bb411068c3d631b0c4be8cdff5Zack Rusinstatic void *
429780327c5d95586a88fce94d7b47342355ead118Zack Rusini915_create_blend_state(struct pipe_context *pipe,
439780327c5d95586a88fce94d7b47342355ead118Zack Rusin                        const struct pipe_blend_state *blend)
449780327c5d95586a88fce94d7b47342355ead118Zack Rusin{
459780327c5d95586a88fce94d7b47342355ead118Zack Rusin   struct pipe_blend_state *new_blend = malloc(sizeof(struct pipe_blend_state));
469780327c5d95586a88fce94d7b47342355ead118Zack Rusin   memcpy(new_blend, blend, sizeof(struct pipe_blend_state));
479780327c5d95586a88fce94d7b47342355ead118Zack Rusin
489780327c5d95586a88fce94d7b47342355ead118Zack Rusin   return new_blend;
499780327c5d95586a88fce94d7b47342355ead118Zack Rusin}
509780327c5d95586a88fce94d7b47342355ead118Zack Rusin
519780327c5d95586a88fce94d7b47342355ead118Zack Rusinstatic void i915_bind_blend_state( struct pipe_context *pipe,
52c0bf7322088715bb411068c3d631b0c4be8cdff5Zack Rusin                                   void *blend )
5301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
5401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   struct i915_context *i915 = i915_context(pipe);
5501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
56c0bf7322088715bb411068c3d631b0c4be8cdff5Zack Rusin   i915->blend = (struct pipe_blend_state *)blend;
5701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
5801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->dirty |= I915_NEW_BLEND;
5901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
6001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
6101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
629780327c5d95586a88fce94d7b47342355ead118Zack Rusinstatic void i915_delete_blend_state( struct pipe_context *pipe,
63c0bf7322088715bb411068c3d631b0c4be8cdff5Zack Rusin                                     void *blend )
649780327c5d95586a88fce94d7b47342355ead118Zack Rusin{
65c0bf7322088715bb411068c3d631b0c4be8cdff5Zack Rusin   free(blend);
669780327c5d95586a88fce94d7b47342355ead118Zack Rusin}
679780327c5d95586a88fce94d7b47342355ead118Zack Rusin
6801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwellstatic void i915_set_blend_color( struct pipe_context *pipe,
6901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell			     const struct pipe_blend_color *blend_color )
7001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
7101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   struct i915_context *i915 = i915_context(pipe);
7201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
7301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->blend_color = *blend_color;
7401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
7501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->dirty |= I915_NEW_BLEND;
7601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
7701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
78f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusinstatic const struct pipe_sampler_state *
79f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusini915_create_sampler_state(struct pipe_context *pipe,
80f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin                          const struct pipe_sampler_state *sampler)
81f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin{
82f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin   struct pipe_sampler_state *new_sampler = malloc(sizeof(struct pipe_sampler_state));
83f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin   memcpy(new_sampler, sampler, sizeof(struct pipe_sampler_state));
84f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin
85f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin   return new_sampler;
86f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin}
87f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin
88f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusinstatic void i915_bind_sampler_state(struct pipe_context *pipe,
89f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin                                    unsigned unit,
90f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin                                    const struct pipe_sampler_state *sampler)
91f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin{
92f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin   struct i915_context *i915 = i915_context(pipe);
93f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin
94f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin   assert(unit < PIPE_MAX_SAMPLERS);
95f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin   i915->sampler[unit] = sampler;
96f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin
97f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin   i915->dirty |= I915_NEW_SAMPLER;
98f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin}
99f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin
100f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusinstatic void i915_delete_sampler_state(struct pipe_context *pipe,
101f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin                                      const struct pipe_sampler_state *sampler)
102f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin{
103f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin   free((struct pipe_sampler_state*)sampler);
104f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin}
105f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin
10601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
10701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell/** XXX move someday?  Or consolidate all these simple state setters
10801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * into one file.
10901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell */
11001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
111d6ac959833a8e40a27907940969c622692f749b1Zack Rusinstatic const struct pipe_depth_stencil_state *
112d6ac959833a8e40a27907940969c622692f749b1Zack Rusini915_create_depth_stencil_state(struct pipe_context *pipe,
113d6ac959833a8e40a27907940969c622692f749b1Zack Rusin                           const struct pipe_depth_stencil_state *depth_stencil)
114d6ac959833a8e40a27907940969c622692f749b1Zack Rusin{
115d6ac959833a8e40a27907940969c622692f749b1Zack Rusin   struct pipe_depth_stencil_state *new_ds =
116d6ac959833a8e40a27907940969c622692f749b1Zack Rusin      malloc(sizeof(struct pipe_depth_stencil_state));
117d6ac959833a8e40a27907940969c622692f749b1Zack Rusin   memcpy(new_ds, depth_stencil, sizeof(struct pipe_depth_stencil_state));
11801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
119d6ac959833a8e40a27907940969c622692f749b1Zack Rusin   return new_ds;
12001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
12101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
122d6ac959833a8e40a27907940969c622692f749b1Zack Rusinstatic void i915_bind_depth_stencil_state(struct pipe_context *pipe,
123d6ac959833a8e40a27907940969c622692f749b1Zack Rusin                           const struct pipe_depth_stencil_state *depth_stencil)
12401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
12501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   struct i915_context *i915 = i915_context(pipe);
12601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
127d6ac959833a8e40a27907940969c622692f749b1Zack Rusin   i915->depth_stencil = depth_stencil;
12801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
129d6ac959833a8e40a27907940969c622692f749b1Zack Rusin   i915->dirty |= I915_NEW_DEPTH_STENCIL;
13001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
13101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
132d6ac959833a8e40a27907940969c622692f749b1Zack Rusinstatic void i915_delete_depth_stencil_state(struct pipe_context *pipe,
133d6ac959833a8e40a27907940969c622692f749b1Zack Rusin                           const struct pipe_depth_stencil_state *depth_stencil)
134d6ac959833a8e40a27907940969c622692f749b1Zack Rusin{
135d6ac959833a8e40a27907940969c622692f749b1Zack Rusin   free((struct pipe_depth_stencil_state *)depth_stencil);
136d6ac959833a8e40a27907940969c622692f749b1Zack Rusin}
137d6ac959833a8e40a27907940969c622692f749b1Zack Rusin
138d6ac959833a8e40a27907940969c622692f749b1Zack Rusinstatic void i915_set_alpha_test_state(struct pipe_context *pipe,
139d6ac959833a8e40a27907940969c622692f749b1Zack Rusin                              const struct pipe_alpha_test_state *alpha)
14001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
14101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   struct i915_context *i915 = i915_context(pipe);
14201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
143d6ac959833a8e40a27907940969c622692f749b1Zack Rusin   i915->alpha_test = *alpha;
14401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
145d6ac959833a8e40a27907940969c622692f749b1Zack Rusin   i915->dirty |= I915_NEW_ALPHA_TEST;
14601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
14701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
14801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwellstatic void i915_set_scissor_state( struct pipe_context *pipe,
14901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell                                 const struct pipe_scissor_state *scissor )
15001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
15101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   struct i915_context *i915 = i915_context(pipe);
15201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
15301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   memcpy( &i915->scissor, scissor, sizeof(*scissor) );
15401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->dirty |= I915_NEW_SCISSOR;
15501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
15601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
15701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
15801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwellstatic void i915_set_polygon_stipple( struct pipe_context *pipe,
15901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell                                   const struct pipe_poly_stipple *stipple )
16001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
16101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
16201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
16301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
164ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusinstatic const struct pipe_shader_state *
165ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusini915_create_shader_state( struct pipe_context *pipe,
166ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin                          const struct pipe_shader_state *templ )
167ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin{
168ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin
169ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin   struct pipe_shader_state *shader = malloc(sizeof(struct pipe_shader_state));
170ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin   memcpy(shader, templ, sizeof(struct pipe_shader_state));
171ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin
172ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin   return shader;
173ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin}
17401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
175ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusinstatic void i915_bind_fs_state( struct pipe_context *pipe,
176de653b4c9bddcec46f3ddf411ec082dd178d7b38Brian                               const struct pipe_shader_state *fs )
17701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
17801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   struct i915_context *i915 = i915_context(pipe);
17901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
180ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin   i915->fs = fs;
18101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
18201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->dirty |= I915_NEW_FS;
18301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
18401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
18501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
186ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusinstatic void i915_bind_vs_state( struct pipe_context *pipe,
1873239532795a027ddc578261f556e13e2c80f9676Brian                               const struct pipe_shader_state *vs )
1883239532795a027ddc578261f556e13e2c80f9676Brian{
1893239532795a027ddc578261f556e13e2c80f9676Brian   struct i915_context *i915 = i915_context(pipe);
1903239532795a027ddc578261f556e13e2c80f9676Brian
1913239532795a027ddc578261f556e13e2c80f9676Brian   /* just pass-through to draw module */
1923239532795a027ddc578261f556e13e2c80f9676Brian   draw_set_vertex_shader(i915->draw, vs);
1933239532795a027ddc578261f556e13e2c80f9676Brian}
1943239532795a027ddc578261f556e13e2c80f9676Brian
195ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusinstatic void i915_delete_shader_state( struct pipe_context *pipe,
196ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin                                      const struct pipe_shader_state *shader )
197ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin{
198ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin   free((struct pipe_shader_state*)shader);
199ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin}
2003239532795a027ddc578261f556e13e2c80f9676Brian
201c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrianstatic void i915_set_constant_buffer(struct pipe_context *pipe,
202c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian                                     uint shader, uint index,
203c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian                                     const struct pipe_constant_buffer *buf)
204c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian{
205c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian   struct i915_context *i915 = i915_context(pipe);
206c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian   struct pipe_winsys *ws = pipe->winsys;
207c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian
208c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian   assert(shader < PIPE_SHADER_TYPES);
209c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian   assert(index == 0);
210c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian
211c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian   /* Make a copy of shader constants.
212c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian    * During fragment program translation we may add additional
213c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian    * constants to the array.
214c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian    *
215c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian    * We want to consider the situation where some user constants
216c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian    * (ex: a material color) may change frequently but the shader program
217c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian    * stays the same.  In that case we should only be updating the first
218c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian    * N constants, leaving any extras from shader translation alone.
219c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian    */
220c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian   {
221c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian      void *mapped;
222c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian      if (buf->size &&
223c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian          (mapped = ws->buffer_map(ws, buf->buffer, PIPE_BUFFER_FLAG_READ))) {
224c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian         memcpy(i915->current.constants[shader], mapped, buf->size);
225c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian         ws->buffer_unmap(ws, buf->buffer);
226c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian         i915->current.num_user_constants[shader]
227c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian            = buf->size / (4 * sizeof(float));
228c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian      }
229c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian      else {
230c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian         i915->current.num_user_constants[shader] = 0;
231c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian      }
232c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian   }
233c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian
234c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian   i915->dirty |= I915_NEW_CONSTANTS;
235c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian}
236c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian
237c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian
23801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwellstatic void i915_set_texture_state(struct pipe_context *pipe,
23940a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell				   unsigned unit,
240dbb297fac6a9637cc7ee7ab2cf40f196048ba626Keith Whitwell				   struct pipe_mipmap_tree *texture)
24101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
24201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   struct i915_context *i915 = i915_context(pipe);
24301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
24401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->texture[unit] = texture;  /* ptr, not struct */
24501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
24601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->dirty |= I915_NEW_TEXTURE;
24701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
24801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
24901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
25001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
25101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwellstatic void i915_set_framebuffer_state(struct pipe_context *pipe,
25247fc2c4349746997704a7f81dffadd22363e0ff1Keith Whitwell				       const struct pipe_framebuffer_state *fb)
25301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
25401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   struct i915_context *i915 = i915_context(pipe);
25501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
25601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->framebuffer = *fb; /* struct copy */
25701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
25801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->dirty |= I915_NEW_FRAMEBUFFER;
25901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
26001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
26101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
26201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
26301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
26401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwellstatic void i915_set_clear_color_state(struct pipe_context *pipe,
26501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell                               const struct pipe_clear_color_state *clear)
26601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
26701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   struct i915_context *i915 = i915_context(pipe);
26801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
26901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->clear_color = *clear; /* struct copy */
27001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
27101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
27201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
27301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
27401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwellstatic void i915_set_clip_state( struct pipe_context *pipe,
27501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell			     const struct pipe_clip_state *clip )
27601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
27701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   struct i915_context *i915 = i915_context(pipe);
27801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
27901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   draw_set_clip_state(i915->draw, clip);
28001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
28101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->dirty |= I915_NEW_CLIP;
28201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
28301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
28401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
28501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
28601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell/* Called when driver state tracker notices changes to the viewport
28701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * matrix:
28801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell */
28901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwellstatic void i915_set_viewport_state( struct pipe_context *pipe,
29001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell				     const struct pipe_viewport_state *viewport )
29101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
29201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   struct i915_context *i915 = i915_context(pipe);
29301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
29401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->viewport = *viewport; /* struct copy */
29501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
29601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   /* pass the viewport info to the draw module */
297f1637e89ded7312a97dc0a8fdac74886d70766c0Brian   draw_set_viewport_state(i915->draw, &i915->viewport);
29801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
29901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   /* Using tnl/ and vf/ modules is temporary while getting started.
30001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell    * Full pipe will have vertex shader, vertex fetch of its own.
30101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell    */
30201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->dirty |= I915_NEW_VIEWPORT;
30301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
30401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
30501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
306294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin
307294401814d1d89cc731de1c22c25333aa5d59374Zack Rusinstatic const struct pipe_rasterizer_state *
308294401814d1d89cc731de1c22c25333aa5d59374Zack Rusini915_create_rasterizer_state(struct pipe_context *pipe,
309294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin                             const struct pipe_rasterizer_state *setup)
310294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin{
311294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin   struct pipe_rasterizer_state *raster =
312294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin      malloc(sizeof(struct pipe_rasterizer_state));
313294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin   memcpy(raster, setup, sizeof(struct pipe_rasterizer_state));
314294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin
315294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin   return raster;
316294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin}
317294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin
318294401814d1d89cc731de1c22c25333aa5d59374Zack Rusinstatic void i915_bind_rasterizer_state( struct pipe_context *pipe,
319294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin                                   const struct pipe_rasterizer_state *setup )
32001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
32101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   struct i915_context *i915 = i915_context(pipe);
32201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
323294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin   i915->rasterizer = setup;
32401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
32501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   /* pass-through to draw module */
326de69fc1703f79e5c97e66b654de7a93b7abce8f0Zack Rusin   draw_set_rasterizer_state(i915->draw, setup);
32701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
328294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin   i915->dirty |= I915_NEW_RASTERIZER;
32901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
33001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
331294401814d1d89cc731de1c22c25333aa5d59374Zack Rusinstatic void i915_delete_rasterizer_state( struct pipe_context *pipe,
332294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin                                     const struct pipe_rasterizer_state *setup )
333294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin{
334294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin   free((struct pipe_rasterizer_state*)setup);
335294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin}
33601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell
3373239532795a027ddc578261f556e13e2c80f9676Brianstatic void i915_set_vertex_buffer( struct pipe_context *pipe,
3383239532795a027ddc578261f556e13e2c80f9676Brian                                    unsigned index,
3393239532795a027ddc578261f556e13e2c80f9676Brian                                    const struct pipe_vertex_buffer *buffer )
3403239532795a027ddc578261f556e13e2c80f9676Brian{
3413239532795a027ddc578261f556e13e2c80f9676Brian   struct i915_context *i915 = i915_context(pipe);
3423239532795a027ddc578261f556e13e2c80f9676Brian   i915->vertex_buffer[index] = *buffer;
3433239532795a027ddc578261f556e13e2c80f9676Brian   /* pass-through to draw module */
3443239532795a027ddc578261f556e13e2c80f9676Brian   draw_set_vertex_buffer(i915->draw, index, buffer);
3453239532795a027ddc578261f556e13e2c80f9676Brian}
3463239532795a027ddc578261f556e13e2c80f9676Brian
3473239532795a027ddc578261f556e13e2c80f9676Brianstatic void i915_set_vertex_element( struct pipe_context *pipe,
3483239532795a027ddc578261f556e13e2c80f9676Brian                                     unsigned index,
3493239532795a027ddc578261f556e13e2c80f9676Brian                                     const struct pipe_vertex_element *element)
3503239532795a027ddc578261f556e13e2c80f9676Brian{
3513239532795a027ddc578261f556e13e2c80f9676Brian   struct i915_context *i915 = i915_context(pipe);
3523239532795a027ddc578261f556e13e2c80f9676Brian   /* pass-through to draw module */
3533239532795a027ddc578261f556e13e2c80f9676Brian   draw_set_vertex_element(i915->draw, index, element);
3543239532795a027ddc578261f556e13e2c80f9676Brian}
3553239532795a027ddc578261f556e13e2c80f9676Brian
3563239532795a027ddc578261f556e13e2c80f9676Brian
3573239532795a027ddc578261f556e13e2c80f9676Brian
35801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwellvoid
35901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwelli915_init_state_functions( struct i915_context *i915 )
36001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{
3619780327c5d95586a88fce94d7b47342355ead118Zack Rusin   i915->pipe.create_blend_state = i915_create_blend_state;
3629780327c5d95586a88fce94d7b47342355ead118Zack Rusin   i915->pipe.bind_blend_state = i915_bind_blend_state;
3639780327c5d95586a88fce94d7b47342355ead118Zack Rusin   i915->pipe.delete_blend_state = i915_delete_blend_state;
3649780327c5d95586a88fce94d7b47342355ead118Zack Rusin
365f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin   i915->pipe.create_sampler_state = i915_create_sampler_state;
366f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin   i915->pipe.bind_sampler_state = i915_bind_sampler_state;
367f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin   i915->pipe.delete_sampler_state = i915_delete_sampler_state;
368f117327a3f246713abfd4dc4320d4a1a7f1b811aZack Rusin
369d6ac959833a8e40a27907940969c622692f749b1Zack Rusin   i915->pipe.create_depth_stencil_state = i915_create_depth_stencil_state;
370d6ac959833a8e40a27907940969c622692f749b1Zack Rusin   i915->pipe.bind_depth_stencil_state = i915_bind_depth_stencil_state;
371d6ac959833a8e40a27907940969c622692f749b1Zack Rusin   i915->pipe.delete_depth_stencil_state = i915_delete_depth_stencil_state;
372d6ac959833a8e40a27907940969c622692f749b1Zack Rusin
373294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin   i915->pipe.create_rasterizer_state = i915_create_rasterizer_state;
374294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin   i915->pipe.bind_rasterizer_state = i915_bind_rasterizer_state;
375294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin   i915->pipe.delete_rasterizer_state = i915_delete_rasterizer_state;
376f22e920f478d8732695913ec0d1f7244b451a8f5Zack Rusin   i915->pipe.create_fs_state = i915_create_shader_state;
377ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin   i915->pipe.bind_fs_state = i915_bind_fs_state;
378f22e920f478d8732695913ec0d1f7244b451a8f5Zack Rusin   i915->pipe.delete_fs_state = i915_delete_shader_state;
379f22e920f478d8732695913ec0d1f7244b451a8f5Zack Rusin   i915->pipe.create_vs_state = i915_create_shader_state;
380ccd63b54cfbb6bb241d55f7ac95afcd14819f469Zack Rusin   i915->pipe.bind_vs_state = i915_bind_vs_state;
381f22e920f478d8732695913ec0d1f7244b451a8f5Zack Rusin   i915->pipe.delete_vs_state = i915_delete_shader_state;
382294401814d1d89cc731de1c22c25333aa5d59374Zack Rusin
38301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->pipe.set_alpha_test_state = i915_set_alpha_test_state;
38401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->pipe.set_blend_color = i915_set_blend_color;
38501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->pipe.set_clip_state = i915_set_clip_state;
38601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->pipe.set_clear_color_state = i915_set_clear_color_state;
387c0bb4ba9e665e40a325d82aa2ee48d7b8abd603bBrian   i915->pipe.set_constant_buffer = i915_set_constant_buffer;
38801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->pipe.set_framebuffer_state = i915_set_framebuffer_state;
38901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->pipe.set_polygon_stipple = i915_set_polygon_stipple;
39001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->pipe.set_scissor_state = i915_set_scissor_state;
39101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->pipe.set_texture_state = i915_set_texture_state;
39201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell   i915->pipe.set_viewport_state = i915_set_viewport_state;
3933239532795a027ddc578261f556e13e2c80f9676Brian   i915->pipe.set_vertex_buffer = i915_set_vertex_buffer;
3943239532795a027ddc578261f556e13e2c80f9676Brian   i915->pipe.set_vertex_element = i915_set_vertex_element;
39501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell}
396