#include "pipe/p_defines.h"
#include "util/u_bitmask.h"
-#include "util/u_format.h"
+#include "util/format/u_format.h"
#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
uint8 compare_func;
SVGA3dFilter filter;
SVGA3dRGBAFloat bcolor;
- unsigned try;
float min_lod, max_lod;
assert(svga_have_vgpu10(svga));
COPY_4V(bcolor.value, ps->border_color.f);
- ss->id = util_bitmask_add(svga->sampler_object_id_bm);
-
assert(ps->min_lod <= ps->max_lod);
if (ps->min_mip_filter == PIPE_TEX_MIPFILTER_NONE) {
max_lod = ps->max_lod;
}
- /* Loop in case command buffer is full and we need to flush and retry */
- for (try = 0; try < 2; try++) {
- enum pipe_error ret =
- SVGA3D_vgpu10_DefineSamplerState(svga->swc,
- ss->id,
- filter,
- ss->addressu,
- ss->addressv,
- ss->addressw,
- ss->lod_bias, /* float */
- max_aniso,
- compare_func,
- bcolor,
- min_lod, /* float */
- max_lod); /* float */
- if (ret == PIPE_OK)
- return;
- svga_context_flush(svga, NULL);
+ /* If shadow comparisons are enabled, create two sampler states: one
+ * with the given shadow compare mode, another with shadow comparison off.
+ * We need the later because in some cases, we have to do the shadow
+ * compare in the shader. So, we don't want to do it twice.
+ */
+ STATIC_ASSERT(PIPE_TEX_COMPARE_NONE == 0);
+ STATIC_ASSERT(PIPE_TEX_COMPARE_R_TO_TEXTURE == 1);
+ ss->id[1] = SVGA3D_INVALID_ID;
+
+ unsigned i;
+ for (i = 0; i <= ss->compare_mode; i++) {
+ ss->id[i] = util_bitmask_add(svga->sampler_object_id_bm);
+
+ SVGA_RETRY(svga, SVGA3D_vgpu10_DefineSamplerState
+ (svga->swc,
+ ss->id[i],
+ filter,
+ ss->addressu,
+ ss->addressv,
+ ss->addressw,
+ ss->lod_bias, /* float */
+ max_aniso,
+ compare_func,
+ bcolor,
+ min_lod, /* float */
+ max_lod)); /* float */
+
+ /* turn off the shadow compare option for second iteration */
+ filter &= ~SVGA3D_FILTER_COMPARE;
}
}
define_sampler_state_object(svga, cso, sampler);
}
- SVGA_DBG(DEBUG_VIEWS, "min %u, view(min %u, max %u) lod, mipfilter %s\n",
+ SVGA_DBG(DEBUG_SAMPLERS,
+ "New sampler: min %u, view(min %u, max %u) lod, mipfilter %s\n",
cso->min_lod, cso->view_min_lod, cso->view_max_lod,
cso->mipfilter == SVGA3D_TEX_FILTER_NONE ? "SVGA3D_TEX_FILTER_NONE" : "SOMETHING");
static void
svga_bind_sampler_states(struct pipe_context *pipe,
- unsigned shader,
+ enum pipe_shader_type shader,
unsigned start,
unsigned num,
void **samplers)
struct svga_context *svga = svga_context(pipe);
if (svga_have_vgpu10(svga)) {
- enum pipe_error ret;
-
- svga_hwtnl_flush_retry(svga);
-
- ret = SVGA3D_vgpu10_DestroySamplerState(svga->swc, ss->id);
- if (ret != PIPE_OK) {
- svga_context_flush(svga, NULL);
- ret = SVGA3D_vgpu10_DestroySamplerState(svga->swc, ss->id);
+ unsigned i;
+ for (i = 0; i < 2; i++) {
+ if (ss->id[i] != SVGA3D_INVALID_ID) {
+ svga_hwtnl_flush_retry(svga);
+
+ SVGA_RETRY(svga, SVGA3D_vgpu10_DestroySamplerState(svga->swc,
+ ss->id[i]));
+ util_bitmask_clear(svga->sampler_object_id_bm, ss->id[i]);
+ }
}
- util_bitmask_clear(svga->sampler_object_id_bm, ss->id);
}
FREE(sampler);
struct svga_pipe_sampler_view *sv = svga_pipe_sampler_view(view);
if (svga_have_vgpu10(svga) && sv->id != SVGA3D_INVALID_ID) {
- if (view->context != pipe) {
- /* The SVGA3D device will generate an error (and on Linux, cause
- * us to abort) if we try to destroy a shader resource view from
- * a context other than the one it was created with. Skip the
- * SVGA3D_vgpu10_DestroyShaderResourceView() and leak the sampler
- * view for now. This should only sometimes happen when a shared
- * texture is deleted.
- */
- _debug_printf("context mismatch in %s\n", __func__);
- }
- else {
- enum pipe_error ret;
+ assert(view->context == pipe);
- svga_hwtnl_flush_retry(svga); /* XXX is this needed? */
+ svga_hwtnl_flush_retry(svga);
- ret = SVGA3D_vgpu10_DestroyShaderResourceView(svga->swc, sv->id);
- if (ret != PIPE_OK) {
- svga_context_flush(svga, NULL);
- ret = SVGA3D_vgpu10_DestroyShaderResourceView(svga->swc, sv->id);
- }
- util_bitmask_clear(svga->sampler_view_id_bm, sv->id);
- }
+ SVGA_RETRY(svga, SVGA3D_vgpu10_DestroyShaderResourceView(svga->swc,
+ sv->id));
+ util_bitmask_clear(svga->sampler_view_id_bm, sv->id);
}
pipe_resource_reference(&sv->base.texture, NULL);
static void
svga_set_sampler_views(struct pipe_context *pipe,
- unsigned shader,
+ enum pipe_shader_type shader,
unsigned start,
unsigned num,
struct pipe_sampler_view **views)
struct svga_context *svga = svga_context(pipe);
unsigned flag_1d = 0;
unsigned flag_srgb = 0;
- unsigned flag_rect = 0;
- unsigned flag_buf = 0;
uint i;
boolean any_change = FALSE;
*/
if (start == 0 && num == 0 && svga->curr.num_sampler_views[shader] > 0) {
for (i = 0; i < svga->curr.num_sampler_views[shader]; i++) {
- pipe_sampler_view_release(pipe, &svga->curr.sampler_views[shader][i]);
+ pipe_sampler_view_reference(&svga->curr.sampler_views[shader][i],
+ NULL);
}
any_change = TRUE;
}
enum pipe_texture_target target;
if (svga->curr.sampler_views[shader][start + i] != views[i]) {
- /* Note: we're using pipe_sampler_view_release() here to work around
- * a possible crash when the old view belongs to another context that
- * was already destroyed.
- */
- pipe_sampler_view_release(pipe, &svga->curr.sampler_views[shader][start + i]);
pipe_sampler_view_reference(&svga->curr.sampler_views[shader][start + i],
views[i]);
any_change = TRUE;
if (util_format_is_srgb(views[i]->format))
flag_srgb |= 1 << (start + i);
- target = views[i]->texture->target;
- if (target == PIPE_TEXTURE_1D)
+ target = views[i]->target;
+ if (target == PIPE_TEXTURE_1D) {
flag_1d |= 1 << (start + i);
- else if (target == PIPE_TEXTURE_RECT)
- flag_rect |= 1 << (start + i);
- else if (target == PIPE_BUFFER)
- flag_buf |= 1 << (start + i);
+ } else if (target == PIPE_TEXTURE_RECT) {
+ /* If the size of the bound texture changes, we need to emit new
+ * const buffer values.
+ */
+ svga->dirty |= SVGA_NEW_TEXTURE_CONSTS;
+ } else if (target == PIPE_BUFFER) {
+ /* If the size of the bound buffer changes, we need to emit new
+ * const buffer values.
+ */
+ svga->dirty |= SVGA_NEW_TEXTURE_CONSTS;
+ }
}
if (!any_change) {
svga->curr.tex_flags.flag_srgb = flag_srgb;
}
- if (flag_rect != svga->curr.tex_flags.flag_rect ||
- flag_buf != svga->curr.tex_flags.flag_buf)
- {
- /* Need to re-emit texture constants */
- svga->dirty |= SVGA_NEW_TEXTURE_CONSTS;
- svga->curr.tex_flags.flag_rect = flag_rect;
- svga->curr.tex_flags.flag_buf = flag_buf;
- }
-
/* Check if any of the sampler view resources collide with the framebuffer
- * color buffers or depth stencil resource. If so, enable the NEW_FRAME_BUFFER
+ * color buffers or depth stencil resource. If so, set the NEW_FRAME_BUFFER
* dirty bit so that emit_framebuffer can be invoked to create backed view
* for the conflicted surface view.
*/
- for (i = 0; i < svga->curr.framebuffer.nr_cbufs; i++) {
- if (svga->curr.framebuffer.cbufs[i]) {
- struct svga_surface *s = svga_surface(svga->curr.framebuffer.cbufs[i]);
- if (svga_check_sampler_view_resource_collision(svga, s->handle, shader)) {
- svga->dirty |= SVGA_NEW_FRAME_BUFFER;
- break;
- }
- }
- }
-
- if (svga->curr.framebuffer.zsbuf) {
- struct svga_surface *s = svga_surface(svga->curr.framebuffer.zsbuf);
- if (s) {
- if (svga_check_sampler_view_resource_collision(svga, s->handle, shader)) {
- svga->dirty |= SVGA_NEW_FRAME_BUFFER;
- }
- }
+ if (svga_check_sampler_framebuffer_resource_collision(svga, shader)) {
+ svga->dirty |= SVGA_NEW_FRAME_BUFFER;
}
done:
SVGA_STATS_TIME_POP(svga_sws(svga));
}
+/**
+ * Clean up sampler, sampler view state at context destruction time
+ */
+void
+svga_cleanup_sampler_state(struct svga_context *svga)
+{
+ enum pipe_shader_type shader;
+
+ for (shader = 0; shader <= PIPE_SHADER_TESS_EVAL; shader++) {
+ unsigned i;
+
+ for (i = 0; i < svga->state.hw_draw.num_sampler_views[shader]; i++) {
+ pipe_sampler_view_reference(&svga->state.hw_draw.sampler_views[shader][i],
+ NULL);
+ }
+ }
+
+ /* free polygon stipple state */
+ if (svga->polygon_stipple.sampler) {
+ svga->pipe.delete_sampler_state(&svga->pipe, svga->polygon_stipple.sampler);
+ }
+
+ if (svga->polygon_stipple.sampler_view) {
+ svga->pipe.sampler_view_destroy(&svga->pipe,
+ &svga->polygon_stipple.sampler_view->base);
+ }
+ pipe_resource_reference(&svga->polygon_stipple.texture, NULL);
+}
void
svga_init_sampler_functions( struct svga_context *svga )