1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Rob Clark <robclark@freedesktop.org>
29 #include "pipe/p_state.h"
30 #include "util/u_string.h"
31 #include "util/u_memory.h"
32 #include "util/u_inlines.h"
34 #include "freedreno_texture.h"
35 #include "freedreno_context.h"
36 #include "freedreno_util.h"
39 fd_sampler_state_delete(struct pipe_context
*pctx
, void *hwcso
)
45 fd_sampler_view_destroy(struct pipe_context
*pctx
,
46 struct pipe_sampler_view
*view
)
48 pipe_resource_reference(&view
->texture
, NULL
);
52 static void bind_sampler_states(struct fd_texture_stateobj
*prog
,
53 unsigned nr
, void **hwcso
)
58 for (i
= 0; i
< nr
; i
++) {
61 prog
->samplers
[i
] = hwcso
[i
];
62 prog
->dirty_samplers
|= (1 << i
);
65 for (; i
< prog
->num_samplers
; i
++) {
66 prog
->samplers
[i
] = NULL
;
67 prog
->dirty_samplers
|= (1 << i
);
70 prog
->num_samplers
= new_nr
;
73 static void set_sampler_views(struct fd_texture_stateobj
*prog
,
74 unsigned nr
, struct pipe_sampler_view
**views
)
79 for (i
= 0; i
< nr
; i
++) {
82 pipe_sampler_view_reference(&prog
->textures
[i
], views
[i
]);
83 prog
->dirty_samplers
|= (1 << i
);
86 for (; i
< prog
->num_textures
; i
++) {
87 pipe_sampler_view_reference(&prog
->textures
[i
], NULL
);
88 prog
->dirty_samplers
|= (1 << i
);
91 prog
->num_textures
= new_nr
;
95 fd_fragtex_sampler_states_bind(struct pipe_context
*pctx
,
96 unsigned nr
, void **hwcso
)
98 struct fd_context
*ctx
= fd_context(pctx
);
100 /* on a2xx, since there is a flat address space for textures/samplers,
101 * a change in # of fragment textures/samplers will trigger patching and
102 * re-emitting the vertex shader:
104 if (nr
!= ctx
->fragtex
.num_samplers
)
105 ctx
->dirty
|= FD_DIRTY_TEXSTATE
;
107 bind_sampler_states(&ctx
->fragtex
, nr
, hwcso
);
108 ctx
->dirty
|= FD_DIRTY_FRAGTEX
;
113 fd_fragtex_set_sampler_views(struct pipe_context
*pctx
, unsigned nr
,
114 struct pipe_sampler_view
**views
)
116 struct fd_context
*ctx
= fd_context(pctx
);
118 /* on a2xx, since there is a flat address space for textures/samplers,
119 * a change in # of fragment textures/samplers will trigger patching and
120 * re-emitting the vertex shader:
122 if (nr
!= ctx
->fragtex
.num_textures
)
123 ctx
->dirty
|= FD_DIRTY_TEXSTATE
;
125 set_sampler_views(&ctx
->fragtex
, nr
, views
);
126 ctx
->dirty
|= FD_DIRTY_FRAGTEX
;
130 fd_verttex_sampler_states_bind(struct pipe_context
*pctx
,
131 unsigned nr
, void **hwcso
)
133 struct fd_context
*ctx
= fd_context(pctx
);
134 bind_sampler_states(&ctx
->verttex
, nr
, hwcso
);
135 ctx
->dirty
|= FD_DIRTY_VERTTEX
;
140 fd_verttex_set_sampler_views(struct pipe_context
*pctx
, unsigned nr
,
141 struct pipe_sampler_view
**views
)
143 struct fd_context
*ctx
= fd_context(pctx
);
144 set_sampler_views(&ctx
->verttex
, nr
, views
);
145 ctx
->dirty
|= FD_DIRTY_VERTTEX
;
149 fd_texture_init(struct pipe_context
*pctx
)
151 pctx
->delete_sampler_state
= fd_sampler_state_delete
;
153 pctx
->sampler_view_destroy
= fd_sampler_view_destroy
;
155 pctx
->bind_fragment_sampler_states
= fd_fragtex_sampler_states_bind
;
156 pctx
->set_fragment_sampler_views
= fd_fragtex_set_sampler_views
;
158 pctx
->bind_vertex_sampler_states
= fd_verttex_sampler_states_bind
;
159 pctx
->set_vertex_sampler_views
= fd_verttex_set_sampler_views
;