#include "main/macros.h"
#include "shader/prog_instruction.h"
#include "st_atom.h"
-#include "st_cache.h"
#include "st_context.h"
+#include "st_cb_accum.h"
#include "st_cb_clear.h"
#include "st_cb_fbo.h"
#include "st_draw.h"
#include "st_program.h"
#include "st_public.h"
+#include "st_mesa_to_tgsi.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
#include "pipe/p_winsys.h"
-#include "pipe/tgsi/mesa/mesa_to_tgsi.h"
-
-#include "vf/vf.h"
+#include "cso_cache/cso_context.h"
+/* XXX for testing draw module vertex passthrough: */
+#define TEST_DRAW_PASSTHROUGH 0
static GLuint
-color_value(GLuint pipeFormat, const GLfloat color[4])
+color_value(enum pipe_format pipeFormat, const GLfloat color[4])
{
GLubyte r, g, b, a;
UNCLAMPED_FLOAT_TO_UBYTE(a, color[3]);
switch (pipeFormat) {
- case PIPE_FORMAT_U_R8_G8_B8_A8:
+ case PIPE_FORMAT_R8G8B8A8_UNORM:
return (r << 24) | (g << 16) | (b << 8) | a;
- case PIPE_FORMAT_U_A8_R8_G8_B8:
+ case PIPE_FORMAT_A8R8G8B8_UNORM:
return (a << 24) | (r << 16) | (g << 8) | b;
- case PIPE_FORMAT_U_R5_G6_B5:
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ return (b << 24) | (g << 16) | (r << 8) | a;
+ case PIPE_FORMAT_R5G6B5_UNORM:
return ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3);
default:
+ assert(0);
return 0;
}
}
-static GLuint
-depth_value(GLuint pipeFormat, GLfloat value)
+static uint
+depth_value(enum pipe_format pipeFormat, GLfloat value)
{
- GLuint val;
switch (pipeFormat) {
- case PIPE_FORMAT_U_Z16:
- val = (GLuint) (value * 0xffffff);
- break;
- case PIPE_FORMAT_U_Z32:
- val = (GLuint) (value * 0xffffffff);
- break;
- case PIPE_FORMAT_S8_Z24:
- /*case PIPE_FORMAT_Z24_S8:*/
- val = (GLuint) (value * 0xffffff);
- break;
+ case PIPE_FORMAT_Z16_UNORM:
+ return (uint) (value * 0xffff);
+ case PIPE_FORMAT_Z32_UNORM:
+ /* special-case to avoid overflow */
+ if (value == 1.0)
+ return 0xffffffff;
+ else
+ return (uint) (value * 0xffffffff);
+ case PIPE_FORMAT_S8Z24_UNORM:
+ return (uint) (value * 0xffffff);
+ case PIPE_FORMAT_Z24S8_UNORM:
+ return ((uint) (value * 0xffffff)) << 8;
default:
- val = 0;
assert(0);
+ return 0;
}
- return val;
}
static GLboolean
-is_depth_stencil_format(GLuint pipeFormat)
+is_depth_stencil_format(enum pipe_format pipeFormat)
{
switch (pipeFormat) {
- case PIPE_FORMAT_S8_Z24:
- /*case PIPE_FORMAT_Z24_S8:*/
+ case PIPE_FORMAT_S8Z24_UNORM:
+ case PIPE_FORMAT_Z24S8_UNORM:
return GL_TRUE;
default:
return GL_FALSE;
* Create a simple fragment shader that just passes through the fragment color.
*/
static struct st_fragment_program *
-make_color_shader(struct st_context *st)
+make_frag_shader(struct st_context *st)
{
GLcontext *ctx = st->ctx;
struct st_fragment_program *stfp;
struct gl_program *p;
- GLboolean b;
+ GLuint interpMode[16];
+ GLuint i;
+
+ /* XXX temporary */
+ for (i = 0; i < 16; i++)
+ interpMode[i] = TGSI_INTERPOLATE_LINEAR;
p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
if (!p)
p->OutputsWritten = (1 << FRAG_RESULT_COLR);
stfp = (struct st_fragment_program *) p;
- /* compile into tgsi format */
- b = tgsi_mesa_compile_fp_program(&stfp->Base,
- stfp->tokens, ST_FP_MAX_TOKENS);
- assert(b);
+ st_translate_fragment_program(st, stfp, NULL);
return stfp;
}
GLcontext *ctx = st->ctx;
struct st_vertex_program *stvp;
struct gl_program *p;
- GLboolean b;
p = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
if (!p)
(1 << VERT_RESULT_HPOS));
stvp = (struct st_vertex_program *) p;
- /* compile into tgsi format */
- b = tgsi_mesa_compile_vp_program(&stvp->Base,
- stvp->tokens, ST_FP_MAX_TOKENS);
- assert(b);
+ st_translate_vertex_program(st, stvp, NULL);
+#if 0
+ assert(stvp->cso);
+#endif
return stvp;
}
float x0, float y0, float x1, float y1, GLfloat z,
const GLfloat color[4])
{
- static const GLuint attribs[2] = {
- 0, /* pos */
- 3 /* color */
- };
GLfloat verts[4][2][4]; /* four verts, two attribs, XYZW */
GLuint i;
+#if TEST_DRAW_PASSTHROUGH
+ /* invert Y coords (may be off by one pixel) */
+ y0 = ctx->DrawBuffer->Height - y0;
+ y1 = ctx->DrawBuffer->Height - y1;
+#endif
+
/* positions */
verts[0][0][0] = x0;
verts[0][0][1] = y0;
verts[i][1][3] = color[3];
}
- st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2, attribs);
+ st_draw_vertices(ctx, PIPE_PRIM_QUADS, 4, (float *) verts, 2, GL_FALSE);
}
GLboolean color, GLboolean depth, GLboolean stencil)
{
struct st_context *st = ctx->st;
- struct pipe_context *pipe = ctx->st->pipe;
+ struct pipe_context *pipe = st->pipe;
const GLfloat x0 = ctx->DrawBuffer->_Xmin;
const GLfloat y0 = ctx->DrawBuffer->_Ymin;
const GLfloat x1 = ctx->DrawBuffer->_Xmax;
const GLfloat y1 = ctx->DrawBuffer->_Ymax;
- /* alpha state: disabled */
- {
- struct pipe_alpha_test_state alpha_test;
- memset(&alpha_test, 0, sizeof(alpha_test));
- pipe->set_alpha_test_state(pipe, &alpha_test);
- }
+ /*
+ printf("%s %s%s%s %f,%f %f,%f\n", __FUNCTION__,
+ color ? "color, " : "",
+ depth ? "depth, " : "",
+ stencil ? "stencil" : "",
+ x0, y0,
+ x1, y1);
+ */
/* blend state: RGBA masking */
{
if (st->ctx->Color.DitherFlag)
blend.dither = 1;
}
- const struct pipe_blend_state *state = st_cached_blend_state(st, &blend);
- pipe->bind_blend_state(pipe, state);
+ cso_set_blend(st->cso_context, &blend);
}
- /* depth state: always pass */
+ /* depth_stencil state: always pass/set to ref value */
{
- struct pipe_depth_state depth_test;
- memset(&depth_test, 0, sizeof(depth_test));
+ struct pipe_depth_stencil_alpha_state depth_stencil;
+ memset(&depth_stencil, 0, sizeof(depth_stencil));
if (depth) {
- depth_test.enabled = 1;
- depth_test.writemask = 1;
- depth_test.func = PIPE_FUNC_ALWAYS;
+ depth_stencil.depth.enabled = 1;
+ depth_stencil.depth.writemask = 1;
+ depth_stencil.depth.func = PIPE_FUNC_ALWAYS;
}
- pipe->set_depth_state(pipe, &depth_test);
+
+ if (stencil) {
+ depth_stencil.stencil[0].enabled = 1;
+ depth_stencil.stencil[0].func = PIPE_FUNC_ALWAYS;
+ depth_stencil.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE;
+ depth_stencil.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
+ depth_stencil.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE;
+ depth_stencil.stencil[0].ref_value = ctx->Stencil.Clear;
+ depth_stencil.stencil[0].value_mask = 0xff;
+ depth_stencil.stencil[0].write_mask = ctx->Stencil.WriteMask[0] & 0xff;
+ }
+
+ cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil);
}
- /* setup state: nothing */
+ /* rasterizer state: nothing */
{
- struct pipe_setup_state setup;
- memset(&setup, 0, sizeof(setup));
+ struct pipe_rasterizer_state raster;
+ memset(&raster, 0, sizeof(raster));
#if 0
/* don't do per-pixel scissor; we'll just draw a PIPE_PRIM_QUAD
* that matches the scissor bounds.
*/
if (ctx->Scissor.Enabled)
- setup.scissor = 1;
+ raster.scissor = 1;
#endif
- pipe->set_setup_state(pipe, &setup);
- }
-
- /* stencil state: always set to ref value */
- {
- struct pipe_stencil_state stencil_test;
- memset(&stencil_test, 0, sizeof(stencil_test));
- if (stencil) {
- stencil_test.front_enabled = 1;
- stencil_test.front_func = PIPE_FUNC_ALWAYS;
- stencil_test.front_fail_op = PIPE_STENCIL_OP_REPLACE;
- stencil_test.front_zpass_op = PIPE_STENCIL_OP_REPLACE;
- stencil_test.front_zfail_op = PIPE_STENCIL_OP_REPLACE;
- stencil_test.ref_value[0] = ctx->Stencil.Clear;
- stencil_test.value_mask[0] = 0xff;
- stencil_test.write_mask[0] = ctx->Stencil.WriteMask[0] & 0xff;
- }
- pipe->set_stencil_state(pipe, &stencil_test);
+#if TEST_DRAW_PASSTHROUGH
+ raster.bypass_clipping = 1;
+ raster.bypass_vs = 1;
+#endif
+ cso_set_rasterizer(st->cso_context, &raster);
}
/* fragment shader state: color pass-through program */
{
static struct st_fragment_program *stfp = NULL;
- struct pipe_shader_state fs;
if (!stfp) {
- stfp = make_color_shader(st);
+ stfp = make_frag_shader(st);
}
- memset(&fs, 0, sizeof(fs));
- fs.inputs_read = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead);
- fs.outputs_written = tgsi_mesa_translate_fragment_output_mask(stfp->Base.Base.OutputsWritten);
- fs.tokens = &stfp->tokens[0];
- pipe->set_fs_state(pipe, &fs);
+ pipe->bind_fs_state(pipe, stfp->driver_shader);
}
+#if !TEST_DRAW_PASSTHROUGH
/* vertex shader state: color/position pass-through */
{
static struct st_vertex_program *stvp = NULL;
- struct pipe_shader_state vs;
if (!stvp) {
stvp = make_vertex_shader(st);
}
- memset(&vs, 0, sizeof(vs));
- vs.inputs_read = stvp->Base.Base.InputsRead;
- vs.outputs_written = stvp->Base.Base.OutputsWritten;
- vs.tokens = &stvp->tokens[0];
- pipe->set_vs_state(pipe, &vs);
+ pipe->bind_vs_state(pipe, stvp->driver_shader);
}
+#endif
+#if !TEST_DRAW_PASSTHROUGH
/* viewport state: viewport matching window dims */
{
const float width = ctx->DrawBuffer->Width;
struct pipe_viewport_state vp;
vp.scale[0] = 0.5 * width;
vp.scale[1] = -0.5 * height;
- vp.scale[2] = 0.5;
+ vp.scale[2] = 1.0;
vp.scale[3] = 1.0;
vp.translate[0] = 0.5 * width;
vp.translate[1] = 0.5 * height;
- vp.translate[2] = 0.5;
+ vp.translate[2] = 0.0;
vp.translate[3] = 0.0;
pipe->set_viewport_state(pipe, &vp);
}
+#endif
/* draw quad matching scissor rect (XXX verify coord round-off) */
draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor);
- /* Restore pipe state */
- pipe->set_alpha_test_state(pipe, &st->state.alpha_test);
- pipe->bind_blend_state(pipe, st->state.blend);
- pipe->set_depth_state(pipe, &st->state.depth);
- pipe->set_fs_state(pipe, &st->state.fs);
- pipe->set_vs_state(pipe, &st->state.vs);
- pipe->set_setup_state(pipe, &st->state.setup);
- pipe->set_stencil_state(pipe, &st->state.stencil);
- pipe->set_viewport_state(pipe, &ctx->st->state.viewport);
- /* OR:
+#if 0
+ /* Can't depend on old state objects still existing -- may have
+ * been deleted to make room in the hash, etc. (Should get
+ * fixed...)
+ */
st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL);
- */
+#else
+ /* Restore pipe state */
+ cso_set_rasterizer(st->cso_context, &st->state.rasterizer);
+ pipe->bind_fs_state(pipe, st->fp->driver_shader);
+ pipe->bind_vs_state(pipe, st->vp->driver_shader);
+#endif
+ pipe->set_viewport_state(pipe, &st->state.viewport);
}
* Determine if we need to clear the depth buffer by drawing a quad.
*/
static INLINE GLboolean
-check_clear_color_with_quad(GLcontext *ctx)
+check_clear_color_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb)
+{
+ const struct st_renderbuffer *strb = st_renderbuffer(rb);
+
+ if (strb->surface->status == PIPE_SURFACE_STATUS_UNDEFINED)
+ return FALSE;
+
+ if (ctx->Scissor.Enabled)
+ return TRUE;
+
+ if (!ctx->Color.ColorMask[0] ||
+ !ctx->Color.ColorMask[1] ||
+ !ctx->Color.ColorMask[2] ||
+ !ctx->Color.ColorMask[3])
+ return TRUE;
+
+ return FALSE;
+}
+
+
+static INLINE GLboolean
+check_clear_depth_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb)
{
- return !(ctx->Color.ColorMask[0] &&
- ctx->Color.ColorMask[1] &&
- ctx->Color.ColorMask[2] &&
- ctx->Color.ColorMask[3] &&
- !ctx->Scissor.Enabled);
+ const struct st_renderbuffer *strb = st_renderbuffer(rb);
+ const GLuint stencilMax = (1 << rb->StencilBits) - 1;
+ GLboolean maskStencil
+ = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax;
+
+ if (strb->surface->status == PIPE_SURFACE_STATUS_UNDEFINED)
+ return FALSE;
+
+ if (ctx->Scissor.Enabled)
+ return TRUE;
+
+ if (maskStencil)
+ return TRUE;
+
+ return FALSE;
}
{
const struct st_renderbuffer *strb = st_renderbuffer(rb);
const GLboolean isDS = is_depth_stencil_format(strb->surface->format);
- return ctx->Scissor.Enabled
- || (isDS && ctx->DrawBuffer->Visual.stencilBits > 0);
+
+ if (strb->surface->status == PIPE_SURFACE_STATUS_UNDEFINED)
+ return FALSE;
+
+ if (ctx->Scissor.Enabled)
+ return TRUE;
+
+ if (isDS &&
+ strb->surface->status == PIPE_SURFACE_STATUS_DEFINED &&
+ ctx->DrawBuffer->Visual.stencilBits > 0)
+ return TRUE;
+
+ return FALSE;
}
const GLuint stencilMax = (1 << rb->StencilBits) - 1;
const GLboolean maskStencil
= (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax;
- return maskStencil
- || ctx->Scissor.Enabled
- || (isDS && ctx->DrawBuffer->Visual.depthBits > 0);
+
+ if (strb->surface->status == PIPE_SURFACE_STATUS_UNDEFINED)
+ return FALSE;
+
+ if (maskStencil)
+ return TRUE;
+
+ if (ctx->Scissor.Enabled)
+ return TRUE;
+
+ /* This is correct, but it is necessary to look at the depth clear
+ * value held in the surface when it comes time to issue the clear,
+ * rather than taking depth and stencil clear values from the
+ * current state.
+ */
+ if (isDS &&
+ strb->surface->status == PIPE_SURFACE_STATUS_DEFINED &&
+ ctx->DrawBuffer->Visual.depthBits > 0)
+ return TRUE;
+
+ return FALSE;
}
static void
clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
{
- struct st_renderbuffer *strb = st_renderbuffer(rb);
-
- if (ctx->Color.ColorMask[0] &&
- ctx->Color.ColorMask[1] &&
- ctx->Color.ColorMask[2] &&
- ctx->Color.ColorMask[3] &&
- !ctx->Scissor.Enabled)
- {
- /* clear whole buffer w/out masking */
- GLuint clearValue
- = color_value(strb->surface->format, ctx->Color.ClearColor);
- ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
- }
- else {
+ if (check_clear_color_with_quad( ctx, rb )) {
/* masking or scissoring */
clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE);
}
-}
-
-
-static void
-clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
-{
- struct st_renderbuffer *strb = st_renderbuffer(rb);
+ else {
+ struct st_renderbuffer *strb = st_renderbuffer(rb);
- if (!ctx->Scissor.Enabled) {
/* clear whole buffer w/out masking */
- GLuint clearValue
- = color_value(strb->surface->format, ctx->Accum.ClearColor);
- /* Note that clearValue is 32 bits but the accum buffer will
- * typically be 64bpp...
- */
+ uint clearValue = color_value(strb->surface->format, ctx->Color.ClearColor);
ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
}
- else {
- /* scissoring */
- /* XXX point framebuffer.cbufs[0] at the accum buffer */
- clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE);
- }
}
static void
clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
{
- struct st_renderbuffer *strb = st_renderbuffer(rb);
- const GLboolean isDS = is_depth_stencil_format(strb->surface->format);
-
- assert(strb->surface->format);
-
- if (ctx->Scissor.Enabled ||
- (isDS && ctx->DrawBuffer->Visual.stencilBits > 0)) {
+ if (check_clear_depth_with_quad(ctx, rb)) {
/* scissoring or we have a combined depth/stencil buffer */
clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE);
}
else {
+ struct st_renderbuffer *strb = st_renderbuffer(rb);
+
/* simple clear of whole buffer */
- GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear);
+ uint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear);
ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
}
}
static void
clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
{
- struct st_renderbuffer *strb = st_renderbuffer(rb);
- const GLboolean isDS = is_depth_stencil_format(strb->surface->format);
- const GLuint stencilMax = (1 << rb->StencilBits) - 1;
- GLboolean maskStencil
- = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax;
-
- if (maskStencil ||
- ctx->Scissor.Enabled ||
- (isDS && ctx->DrawBuffer->Visual.depthBits > 0)) {
+ if (check_clear_stencil_with_quad(ctx, rb)) {
/* masking or scissoring or combined depth/stencil buffer */
clear_with_quad(ctx, GL_FALSE, GL_FALSE, GL_TRUE);
}
else {
+ struct st_renderbuffer *strb = st_renderbuffer(rb);
+
/* simple clear of whole buffer */
GLuint clearValue = ctx->Stencil.Clear;
+
+ switch (strb->surface->format) {
+ case PIPE_FORMAT_S8Z24_UNORM:
+ clearValue <<= 24;
+ break;
+ default:
+ ; /* no-op, stencil value is in least significant bits */
+ }
+
ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
}
}
static void
clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
{
- struct st_renderbuffer *strb = st_renderbuffer(rb);
- const GLuint stencilMax = (1 << rb->StencilBits) - 1;
- GLboolean maskStencil
- = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax;
- assert(is_depth_stencil_format(strb->surface->format));
+ if (check_clear_depth_stencil_with_quad(ctx, rb)) {
+ /* masking or scissoring */
+ clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_TRUE);
+ }
+ else {
+ struct st_renderbuffer *strb = st_renderbuffer(rb);
- if (!maskStencil && !ctx->Scissor.Enabled) {
/* clear whole buffer w/out masking */
GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear);
switch (strb->surface->format) {
- case PIPE_FORMAT_S8_Z24:
+ case PIPE_FORMAT_S8Z24_UNORM:
clearValue |= ctx->Stencil.Clear << 24;
break;
-#if 0
- case PIPE_FORMAT_Z24_S8:
- clearValue = (clearValue << 8) | clearVal;
+ case PIPE_FORMAT_Z24S8_UNORM:
+ clearValue |= ctx->Stencil.Clear;
break;
-#endif
default:
assert(0);
}
ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
}
- else {
- /* masking or scissoring */
- clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_TRUE);
- }
}
}
if (mask & BUFFER_BIT_ACCUM) {
- clear_accum_buffer(ctx,
- ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
+ st_clear_accum_buffer(ctx,
+ ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
}
if ((mask & BUFFER_BITS_DS) == BUFFER_BITS_DS && depthRb == stencilRb) {