projects
/
mesa.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
draw: (trivial) dump tgsi for geometry shaders with GALLIVM_DEBUG_TGSI
[mesa.git]
/
src
/
gallium
/
auxiliary
/
postprocess
/
pp_mlaa.c
diff --git
a/src/gallium/auxiliary/postprocess/pp_mlaa.c
b/src/gallium/auxiliary/postprocess/pp_mlaa.c
index 476502fca9322a7a3ec34d19abaf5fa2b0c95bfa..b299c66599c6318956250678f9a899e6d3691831 100644
(file)
--- a/
src/gallium/auxiliary/postprocess/pp_mlaa.c
+++ b/
src/gallium/auxiliary/postprocess/pp_mlaa.c
@@
-38,15
+38,16
@@
* policies, either expressed or implied, of the copyright holders.
*/
* policies, either expressed or implied, of the copyright holders.
*/
-#include
<stdio.h>
-#include <string.h>
+#include
"pipe/p_compiler.h"
+
#include "postprocess/postprocess.h"
#include "postprocess/pp_mlaa.h"
#include "postprocess/pp_filters.h"
#include "postprocess/postprocess.h"
#include "postprocess/pp_mlaa.h"
#include "postprocess/pp_filters.h"
-#include "util/u_blit.h"
#include "util/u_box.h"
#include "util/u_sampler.h"
#include "util/u_inlines.h"
#include "util/u_box.h"
#include "util/u_sampler.h"
#include "util/u_inlines.h"
+#include "util/u_memory.h"
+#include "util/u_string.h"
#include "pipe/p_screen.h"
#define IMM_SPACE 80
#include "pipe/p_screen.h"
#define IMM_SPACE 80
@@
-54,16
+55,16
@@
static float constants[] = { 1, 1, 0, 0 };
static unsigned int dimensions[2] = { 0, 0 };
static float constants[] = { 1, 1, 0, 0 };
static unsigned int dimensions[2] = { 0, 0 };
-static struct pipe_resource *constbuf, *areamaptex;
-
/** Upload the constants. */
static void
/** Upload the constants. */
static void
-up_consts(struct p
ipe_context *pipe
)
+up_consts(struct p
p_queue_t *ppq
)
{
{
+ struct pipe_context *pipe = ppq->p->pipe;
struct pipe_box box;
u_box_2d(0, 0, sizeof(constants), 1, &box);
struct pipe_box box;
u_box_2d(0, 0, sizeof(constants), 1, &box);
- pipe->transfer_inline_write(pipe, constbuf, 0, PIPE_TRANSFER_WRITE,
+
+ pipe->transfer_inline_write(pipe, ppq->constbuf, 0, PIPE_TRANSFER_WRITE,
&box, constants, sizeof(constants),
sizeof(constants));
}
&box, constants, sizeof(constants),
sizeof(constants));
}
@@
-79,26
+80,41
@@
pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in,
struct pipe_depth_stencil_alpha_state mstencil;
struct pipe_sampler_view v_tmp, *arr[3];
struct pipe_depth_stencil_alpha_state mstencil;
struct pipe_sampler_view v_tmp, *arr[3];
- unsigned int w =
p->framebuffer.width
;
- unsigned int h =
p->framebuffer.height
;
+ unsigned int w =
0
;
+ unsigned int h =
0
;
const struct pipe_stencil_ref ref = { {1} };
const struct pipe_stencil_ref ref = { {1} };
+
+ /* Insufficient initialization checks. */
+ assert(p);
+ assert(ppq);
+ assert(ppq->constbuf);
+ assert(ppq->areamaptex);
+ assert(ppq->inner_tmp);
+ assert(ppq->shaders[n]);
+
+ w = p->framebuffer.width;
+ h = p->framebuffer.height;
+
memset(&mstencil, 0, sizeof(mstencil));
memset(&mstencil, 0, sizeof(mstencil));
+
cso_set_stencil_ref(p->cso, &ref);
/* Init the pixel size constant */
if (dimensions[0] != p->framebuffer.width ||
dimensions[1] != p->framebuffer.height) {
cso_set_stencil_ref(p->cso, &ref);
/* Init the pixel size constant */
if (dimensions[0] != p->framebuffer.width ||
dimensions[1] != p->framebuffer.height) {
- constants[0] = 1.0 / p->framebuffer.width;
- constants[1] = 1.0 / p->framebuffer.height;
+ constants[0] = 1.0
f
/ p->framebuffer.width;
+ constants[1] = 1.0
f
/ p->framebuffer.height;
- up_consts(p
->pipe
);
+ up_consts(p
pq
);
dimensions[0] = p->framebuffer.width;
dimensions[1] = p->framebuffer.height;
}
dimensions[0] = p->framebuffer.width;
dimensions[1] = p->framebuffer.height;
}
- p->pipe->set_constant_buffer(p->pipe, PIPE_SHADER_VERTEX, 0, constbuf);
- p->pipe->set_constant_buffer(p->pipe, PIPE_SHADER_FRAGMENT, 0, constbuf);
+ cso_set_constant_buffer_resource(p->cso, PIPE_SHADER_VERTEX,
+ 0, ppq->constbuf);
+ cso_set_constant_buffer_resource(p->cso, PIPE_SHADER_FRAGMENT,
+ 0, ppq->constbuf);
mstencil.stencil[0].enabled = 1;
mstencil.stencil[0].valuemask = mstencil.stencil[0].writemask = ~0;
mstencil.stencil[0].enabled = 1;
mstencil.stencil[0].valuemask = mstencil.stencil[0].writemask = ~0;
@@
-121,11
+137,11
@@
pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in,
pp_filter_misc_state(p);
cso_set_depth_stencil_alpha(p->cso, &mstencil);
p->pipe->clear(p->pipe, PIPE_CLEAR_STENCIL | PIPE_CLEAR_COLOR,
pp_filter_misc_state(p);
cso_set_depth_stencil_alpha(p->cso, &mstencil);
p->pipe->clear(p->pipe, PIPE_CLEAR_STENCIL | PIPE_CLEAR_COLOR,
- p->clear_color, 0, 0);
+
&
p->clear_color, 0, 0);
- cso_single_sampler(p->cso, 0, &p->sampler_point);
- cso_single_sampler_done(p->cso);
- cso_set_
fragment_sampler_views(p->cso
, 1, &p->view);
+ cso_single_sampler(p->cso,
PIPE_SHADER_FRAGMENT,
0, &p->sampler_point);
+ cso_single_sampler_done(p->cso
, PIPE_SHADER_FRAGMENT
);
+ cso_set_
sampler_views(p->cso, PIPE_SHADER_FRAGMENT
, 1, &p->view);
cso_set_vertex_shader_handle(p->cso, ppq->shaders[n][1]); /* offsetvs */
cso_set_fragment_shader_handle(p->cso, ppq->shaders[n][2]);
cso_set_vertex_shader_handle(p->cso, ppq->shaders[n][1]); /* offsetvs */
cso_set_fragment_shader_handle(p->cso, ppq->shaders[n][2]);
@@
-140,7
+156,7
@@
pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in,
mstencil.stencil[0].zpass_op = PIPE_STENCIL_OP_KEEP;
cso_set_depth_stencil_alpha(p->cso, &mstencil);
mstencil.stencil[0].zpass_op = PIPE_STENCIL_OP_KEEP;
cso_set_depth_stencil_alpha(p->cso, &mstencil);
- pp_filter_setup_in(p, areamaptex);
+ pp_filter_setup_in(p,
ppq->
areamaptex);
pp_filter_setup_out(p, ppq->inner_tmp[1]);
u_sampler_view_default_template(&v_tmp, ppq->inner_tmp[0],
pp_filter_setup_out(p, ppq->inner_tmp[1]);
u_sampler_view_default_template(&v_tmp, ppq->inner_tmp[0],
@@
-150,13
+166,13
@@
pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in,
pp_filter_set_clear_fb(p);
pp_filter_set_clear_fb(p);
- cso_single_sampler(p->cso, 0, &p->sampler_point);
- cso_single_sampler(p->cso, 1, &p->sampler_point);
- cso_single_sampler(p->cso, 2, &p->sampler);
- cso_single_sampler_done(p->cso);
+ cso_single_sampler(p->cso,
PIPE_SHADER_FRAGMENT,
0, &p->sampler_point);
+ cso_single_sampler(p->cso,
PIPE_SHADER_FRAGMENT,
1, &p->sampler_point);
+ cso_single_sampler(p->cso,
PIPE_SHADER_FRAGMENT,
2, &p->sampler);
+ cso_single_sampler_done(p->cso
, PIPE_SHADER_FRAGMENT
);
arr[0] = p->view;
arr[0] = p->view;
- cso_set_
fragment_sampler_views(p->cso
, 3, arr);
+ cso_set_
sampler_views(p->cso, PIPE_SHADER_FRAGMENT
, 3, arr);
cso_set_vertex_shader_handle(p->cso, ppq->shaders[n][0]); /* passvs */
cso_set_fragment_shader_handle(p->cso, ppq->shaders[n][3]);
cso_set_vertex_shader_handle(p->cso, ppq->shaders[n][0]); /* passvs */
cso_set_fragment_shader_handle(p->cso, ppq->shaders[n][3]);
@@
-174,19
+190,19
@@
pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in,
pp_filter_set_fb(p);
/* Blit the input to the output */
pp_filter_set_fb(p);
/* Blit the input to the output */
-
util_blit_pixels(p->blitctx, in, 0
, 0, 0,
-
w, h, 0, p->framebuffer.cbufs[0],
-
0, 0, w, h, 0, PIPE_TEX_MIPFILTER_NEAREST
);
+
pp_blit(p->pipe, in
, 0, 0,
+ w, h, 0, p->framebuffer.cbufs[0],
+
0, 0, w, h
);
u_sampler_view_default_template(&v_tmp, in, in->format);
arr[0] = p->pipe->create_sampler_view(p->pipe, in, &v_tmp);
u_sampler_view_default_template(&v_tmp, in, in->format);
arr[0] = p->pipe->create_sampler_view(p->pipe, in, &v_tmp);
- cso_single_sampler(p->cso, 0, &p->sampler_point);
- cso_single_sampler(p->cso, 1, &p->sampler_point);
- cso_single_sampler_done(p->cso);
+ cso_single_sampler(p->cso,
PIPE_SHADER_FRAGMENT,
0, &p->sampler_point);
+ cso_single_sampler(p->cso,
PIPE_SHADER_FRAGMENT,
1, &p->sampler_point);
+ cso_single_sampler_done(p->cso
, PIPE_SHADER_FRAGMENT
);
arr[1] = p->view;
arr[1] = p->view;
- cso_set_
fragment_sampler_views(p->cso
, 2, arr);
+ cso_set_
sampler_views(p->cso, PIPE_SHADER_FRAGMENT
, 2, arr);
cso_set_vertex_shader_handle(p->cso, ppq->shaders[n][1]); /* offsetvs */
cso_set_fragment_shader_handle(p->cso, ppq->shaders[n][4]);
cso_set_vertex_shader_handle(p->cso, ppq->shaders[n][1]); /* offsetvs */
cso_set_fragment_shader_handle(p->cso, ppq->shaders[n][4]);
@@
-203,34
+219,37
@@
pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in,
}
/** The init function of the MLAA filter. */
}
/** The init function of the MLAA filter. */
-static
void
+static
bool
pp_jimenezmlaa_init_run(struct pp_queue_t *ppq, unsigned int n,
unsigned int val, bool iscolor)
{
struct pipe_box box;
struct pipe_resource res;
pp_jimenezmlaa_init_run(struct pp_queue_t *ppq, unsigned int n,
unsigned int val, bool iscolor)
{
struct pipe_box box;
struct pipe_resource res;
+ char *tmp_text = NULL;
-
char *tmp_text = calloc
(sizeof(blend2fs_1) + sizeof(blend2fs_2) +
-
IMM_SPACE, sizeof(char));
+
tmp_text = CALLOC
(sizeof(blend2fs_1) + sizeof(blend2fs_2) +
+ IMM_SPACE, sizeof(char));
- constbuf = pipe_buffer_create(ppq->p->screen, PIPE_BIND_CONSTANT_BUFFER,
- PIPE_USAGE_STATIC, sizeof(constants));
- if (!constbuf) {
- pp_debug("Failed to allocate constant buffer\n");
- return;
+ if (tmp_text == NULL) {
+ pp_debug("Failed to allocate shader space\n");
+ return FALSE;
}
}
+ ppq->constbuf = pipe_buffer_create(ppq->p->screen,
+ PIPE_BIND_CONSTANT_BUFFER,
+ PIPE_USAGE_STATIC,
+ sizeof(constants));
+ if (ppq->constbuf == NULL) {
+ pp_debug("Failed to allocate constant buffer\n");
+ goto fail;
+ }
pp_debug("mlaa: using %u max search steps\n", val);
pp_debug("mlaa: using %u max search steps\n", val);
- if (!tmp_text) {
- pp_debug("Failed to allocate shader space\n");
- return;
- }
- sprintf(tmp_text, "%s"
- "IMM FLT32 { %.8f, 0.0000, 0.0000, 0.0000}\n"
- "%s\n", blend2fs_1, (float) val, blend2fs_2);
+ util_sprintf(tmp_text, "%s"
+ "IMM FLT32 { %.8f, 0.0000, 0.0000, 0.0000}\n"
+ "%s\n", blend2fs_1, (float) val, blend2fs_2);
memset(&res, 0, sizeof(res));
memset(&res, 0, sizeof(res));
@@
-245,15
+264,19
@@
pp_jimenezmlaa_init_run(struct pp_queue_t *ppq, unsigned int n,
res.target, 1, res.bind))
pp_debug("Areamap format not supported\n");
res.target, 1, res.bind))
pp_debug("Areamap format not supported\n");
- areamaptex = ppq->p->screen->resource_create(ppq->p->screen, &res);
+ ppq->areamaptex = ppq->p->screen->resource_create(ppq->p->screen, &res);
+
+ if (ppq->areamaptex == NULL) {
+ pp_debug("Failed to allocate area map texture\n");
+ goto fail;
+ }
+
u_box_2d(0, 0, 165, 165, &box);
u_box_2d(0, 0, 165, 165, &box);
- ppq->p->pipe->transfer_inline_write(ppq->p->pipe, areamaptex, 0,
+ ppq->p->pipe->transfer_inline_write(ppq->p->pipe,
ppq->
areamaptex, 0,
PIPE_TRANSFER_WRITE, &box,
areamap, 165 * 2, sizeof(areamap));
PIPE_TRANSFER_WRITE, &box,
areamap, 165 * 2, sizeof(areamap));
-
-
ppq->shaders[n][1] = pp_tgsi_to_state(ppq->p->pipe, offsetvs, true,
"offsetvs");
if (iscolor)
ppq->shaders[n][1] = pp_tgsi_to_state(ppq->p->pipe, offsetvs, true,
"offsetvs");
if (iscolor)
@@
-267,24
+290,36
@@
pp_jimenezmlaa_init_run(struct pp_queue_t *ppq, unsigned int n,
ppq->shaders[n][4] = pp_tgsi_to_state(ppq->p->pipe, neigh3fs, false,
"neigh3fs");
ppq->shaders[n][4] = pp_tgsi_to_state(ppq->p->pipe, neigh3fs, false,
"neigh3fs");
- free(tmp_text);
+ FREE(tmp_text);
+
+ return TRUE;
+
+ fail:
+
+ FREE(tmp_text);
+
+ /*
+ * Call the common free function for destruction of partially initialized
+ * resources.
+ */
+ pp_jimenezmlaa_free(ppq, n);
+
+ return FALSE;
}
/** Short wrapper to init the depth version. */
}
/** Short wrapper to init the depth version. */
-void
+bool
pp_jimenezmlaa_init(struct pp_queue_t *ppq, unsigned int n, unsigned int val)
{
pp_jimenezmlaa_init(struct pp_queue_t *ppq, unsigned int n, unsigned int val)
{
-
- pp_jimenezmlaa_init_run(ppq, n, val, false);
+ return pp_jimenezmlaa_init_run(ppq, n, val, false);
}
/** Short wrapper to init the color version. */
}
/** Short wrapper to init the color version. */
-void
+bool
pp_jimenezmlaa_init_color(struct pp_queue_t *ppq, unsigned int n,
unsigned int val)
{
pp_jimenezmlaa_init_color(struct pp_queue_t *ppq, unsigned int n,
unsigned int val)
{
-
- pp_jimenezmlaa_init_run(ppq, n, val, true);
+ return pp_jimenezmlaa_init_run(ppq, n, val, true);
}
/** Short wrapper to run the depth version. */
}
/** Short wrapper to run the depth version. */
@@
-302,3
+337,23
@@
pp_jimenezmlaa_color(struct pp_queue_t *ppq, struct pipe_resource *in,
{
pp_jimenezmlaa_run(ppq, in, out, n, true);
}
{
pp_jimenezmlaa_run(ppq, in, out, n, true);
}
+
+
+/**
+ * Short wrapper to free the mlaa filter resources. Shaders are freed in
+ * the common code in pp_free.
+ */
+void
+pp_jimenezmlaa_free(struct pp_queue_t *ppq, unsigned int n)
+{
+ if (ppq->areamaptex) {
+ ppq->p->screen->resource_destroy(ppq->p->screen, ppq->areamaptex);
+ ppq->areamaptex = NULL;
+ }
+
+ if (ppq->constbuf) {
+ ppq->p->screen->resource_destroy(ppq->p->screen, ppq->constbuf);
+ ppq->constbuf = NULL;
+ }
+}
+