- /* 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);
+
+ /* 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[i],
+ 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)
+ break;
+ svga_context_flush(svga, NULL);
+ }
+
+ /* turn off the shadow compare option for second iteration */
+ filter &= ~SVGA3D_FILTER_COMPARE;