gallium: make p_winsys internal
[mesa.git] / src / gallium / drivers / nv10 / nv10_state.c
index 4dcb9a31ab185b460a457ae09227157c67686d21..119af66dfd054e357184c34602964e1c7f7b9e56 100644 (file)
@@ -1,9 +1,9 @@
 #include "draw/draw_context.h"
 #include "pipe/p_state.h"
 #include "pipe/p_defines.h"
-#include "pipe/p_util.h"
 #include "pipe/p_shader_tokens.h"
 
+#include "tgsi/tgsi_parse.h"
 
 #include "nv10_context.h"
 #include "nv10_state.h"
@@ -14,7 +14,7 @@ nv10_blend_state_create(struct pipe_context *pipe,
 {
        struct nv10_blend_state *cb;
 
-       cb = malloc(sizeof(struct nv10_blend_state));
+       cb = MALLOC(sizeof(struct nv10_blend_state));
 
        cb->b_enable = cso->blend_enable ? 1 : 0;
        cb->b_srcfunc = ((nvgl_blend_func(cso->alpha_src_factor)<<16) |
@@ -88,7 +88,7 @@ nv10_sampler_state_create(struct pipe_context *pipe,
        struct nv10_sampler_state *ps;
        uint32_t filter = 0;
 
-       ps = malloc(sizeof(struct nv10_sampler_state));
+       ps = MALLOC(sizeof(struct nv10_sampler_state));
 
        ps->wrap = ((wrap_mode(cso->wrap_s) << NV10TCL_TX_FORMAT_WRAP_S_SHIFT) |
                    (wrap_mode(cso->wrap_t) << NV10TCL_TX_FORMAT_WRAP_T_SHIFT));
@@ -249,7 +249,7 @@ nv10_rasterizer_state_create(struct pipe_context *pipe,
         *      multisample
         *      offset_units / offset_scale
         */
-       rs = malloc(sizeof(struct nv10_rasterizer_state));
+       rs = MALLOC(sizeof(struct nv10_rasterizer_state));
 
        rs->templ = cso;
        
@@ -335,24 +335,24 @@ nv10_depth_stencil_alpha_state_create(struct pipe_context *pipe,
 {
        struct nv10_depth_stencil_alpha_state *hw;
 
-       hw = malloc(sizeof(struct nv10_depth_stencil_alpha_state));
+       hw = MALLOC(sizeof(struct nv10_depth_stencil_alpha_state));
 
        hw->depth.func          = nvgl_comparison_op(cso->depth.func);
        hw->depth.write_enable  = cso->depth.writemask ? 1 : 0;
        hw->depth.test_enable   = cso->depth.enabled ? 1 : 0;
 
        hw->stencil.enable = cso->stencil[0].enabled ? 1 : 0;
-       hw->stencil.wmask = cso->stencil[0].write_mask;
+       hw->stencil.wmask = cso->stencil[0].writemask;
        hw->stencil.func = nvgl_comparison_op(cso->stencil[0].func);
        hw->stencil.ref = cso->stencil[0].ref_value;
-       hw->stencil.vmask = cso->stencil[0].value_mask;
+       hw->stencil.vmask = cso->stencil[0].valuemask;
        hw->stencil.fail = nvgl_stencil_op(cso->stencil[0].fail_op);
        hw->stencil.zfail = nvgl_stencil_op(cso->stencil[0].zfail_op);
        hw->stencil.zpass = nvgl_stencil_op(cso->stencil[0].zpass_op);
 
        hw->alpha.enabled = cso->alpha.enabled ? 1 : 0;
        hw->alpha.func = nvgl_comparison_op(cso->alpha.func);
-       hw->alpha.ref  = float_to_ubyte(cso->alpha.ref);
+       hw->alpha.ref  = float_to_ubyte(cso->alpha.ref_value);
 
        return (void *)hw;
 }
@@ -407,7 +407,7 @@ nv10_fp_state_create(struct pipe_context *pipe,
        struct nv10_fragment_program *fp;
 
        fp = CALLOC(1, sizeof(struct nv10_fragment_program));
-       fp->pipe = cso;
+       fp->pipe.tokens = tgsi_dup_tokens(cso->tokens);
        
        tgsi_scan_shader(cso->tokens, &fp->info);
 
@@ -431,6 +431,7 @@ nv10_fp_state_delete(struct pipe_context *pipe, void *hwcso)
        struct nv10_fragment_program *fp = hwcso;
 
        nv10_fragprog_destroy(nv10, fp);
+       FREE((void*)fp->pipe.tokens);
        FREE(fp);
 }
 
@@ -466,9 +467,12 @@ nv10_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
 
        if (buf) {
                void *mapped;
-               if (buf->size && (mapped = ws->buffer_map(ws, buf->buffer, PIPE_BUFFER_USAGE_CPU_READ)))
+               if (buf->buffer && buf->buffer->size &&
+                    (mapped = ws->buffer_map(ws, buf->buffer, PIPE_BUFFER_USAGE_CPU_READ)))
                {
-                       memcpy(nv10->constbuf[shader], mapped, buf->size);
+                       memcpy(nv10->constbuf[shader], mapped, buf->buffer->size);
+                       nv10->constbuf_nr[shader] =
+                               buf->buffer->size / (4 * sizeof(float));
                        ws->buffer_unmap(ws, buf->buffer);
                }
        }