1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
32 #include "util/u_memory.h"
33 #include "util/u_inlines.h"
35 #include "draw/draw_context.h"
37 #include "sp_context.h"
39 #include "sp_texture.h"
40 #include "sp_tex_sample.h"
41 #include "sp_tex_tile_cache.h"
45 * Bind a range [start, start+num-1] of samplers for a shader stage.
48 softpipe_bind_sampler_states(struct pipe_context
*pipe
,
54 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
57 assert(shader
< PIPE_SHADER_TYPES
);
58 assert(start
+ num
<= Elements(softpipe
->samplers
[shader
]));
60 draw_flush(softpipe
->draw
);
62 /* set the new samplers */
63 for (i
= 0; i
< num
; i
++) {
64 softpipe
->samplers
[shader
][start
+ i
] = samplers
[i
];
67 /* find highest non-null samplers[] entry */
69 unsigned j
= MAX2(softpipe
->num_samplers
[shader
], start
+ num
);
70 while (j
> 0 && softpipe
->samplers
[shader
][j
- 1] == NULL
)
72 softpipe
->num_samplers
[shader
] = j
;
75 if (shader
== PIPE_SHADER_VERTEX
|| shader
== PIPE_SHADER_GEOMETRY
) {
76 draw_set_samplers(softpipe
->draw
,
78 softpipe
->samplers
[shader
],
79 softpipe
->num_samplers
[shader
]);
82 softpipe
->dirty
|= SP_NEW_SAMPLER
;
87 softpipe_sampler_view_destroy(struct pipe_context
*pipe
,
88 struct pipe_sampler_view
*view
)
90 pipe_resource_reference(&view
->texture
, NULL
);
96 softpipe_set_sampler_views(struct pipe_context
*pipe
,
100 struct pipe_sampler_view
**views
)
102 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
105 assert(shader
< PIPE_SHADER_TYPES
);
106 assert(start
+ num
<= Elements(softpipe
->sampler_views
[shader
]));
108 draw_flush(softpipe
->draw
);
110 /* set the new sampler views */
111 for (i
= 0; i
< num
; i
++) {
112 struct sp_sampler_view
*sp_sviewsrc
;
113 struct sp_sampler_view
*sp_sviewdst
=
114 &softpipe
->tgsi
.sampler
[shader
]->sp_sview
[start
+ i
];
115 struct pipe_sampler_view
**pview
= &softpipe
->sampler_views
[shader
][start
+ i
];
116 pipe_sampler_view_reference(pview
, views
[i
]);
117 sp_tex_tile_cache_set_sampler_view(softpipe
->tex_cache
[shader
][start
+ i
],
120 * We don't really have variants, however some bits are different per shader,
123 sp_sviewsrc
= (struct sp_sampler_view
*)*pview
;
125 memcpy(sp_sviewdst
, sp_sviewsrc
, sizeof(*sp_sviewsrc
));
126 sp_sviewdst
->compute_lambda
= softpipe_get_lambda_func(&sp_sviewdst
->base
, shader
);
127 sp_sviewdst
->cache
= softpipe
->tex_cache
[shader
][start
+ i
];
130 memset(sp_sviewdst
, 0, sizeof(*sp_sviewsrc
));
135 /* find highest non-null sampler_views[] entry */
137 unsigned j
= MAX2(softpipe
->num_sampler_views
[shader
], start
+ num
);
138 while (j
> 0 && softpipe
->sampler_views
[shader
][j
- 1] == NULL
)
140 softpipe
->num_sampler_views
[shader
] = j
;
143 if (shader
== PIPE_SHADER_VERTEX
|| shader
== PIPE_SHADER_GEOMETRY
) {
144 draw_set_sampler_views(softpipe
->draw
,
146 softpipe
->sampler_views
[shader
],
147 softpipe
->num_sampler_views
[shader
]);
150 softpipe
->dirty
|= SP_NEW_TEXTURE
;
155 softpipe_delete_sampler_state(struct pipe_context
*pipe
,
163 softpipe_init_sampler_funcs(struct pipe_context
*pipe
)
165 pipe
->create_sampler_state
= softpipe_create_sampler_state
;
166 pipe
->bind_sampler_states
= softpipe_bind_sampler_states
;
167 pipe
->delete_sampler_state
= softpipe_delete_sampler_state
;
169 pipe
->create_sampler_view
= softpipe_create_sampler_view
;
170 pipe
->set_sampler_views
= softpipe_set_sampler_views
;
171 pipe
->sampler_view_destroy
= softpipe_sampler_view_destroy
;