int unit,
int ss_index,
struct brw_sampler_state *sampler,
+ uint32_t sampler_state_table_offset,
uint32_t *sdc_offset)
{
struct gl_context *ctx = &brw->ctx;
*sdc_offset) >> 5;
drm_intel_bo_emit_reloc(brw->batch.bo,
- brw->sampler.offset +
+ sampler_state_table_offset +
ss_index * sizeof(struct brw_sampler_state) +
offsetof(struct brw_sampler_state, ss2),
brw->batch.bo, *sdc_offset,
static void
-brw_upload_samplers(struct brw_context *brw)
+brw_upload_sampler_state_table(struct brw_context *brw,
+ struct gl_program *prog,
+ uint32_t sampler_count,
+ uint32_t *sst_offset,
+ uint32_t *sdc_offset)
{
struct gl_context *ctx = &brw->ctx;
struct brw_sampler_state *samplers;
- /* BRW_NEW_VERTEX_PROGRAM and BRW_NEW_FRAGMENT_PROGRAM */
- struct gl_program *vs = (struct gl_program *) brw->vertex_program;
- struct gl_program *fs = (struct gl_program *) brw->fragment_program;
+ GLbitfield SamplersUsed = prog->SamplersUsed;
- GLbitfield SamplersUsed = vs->SamplersUsed | fs->SamplersUsed;
-
- /* ARB programs use the texture unit number as the sampler index, so we
- * need to find the highest unit used. A bit-count will not work.
- */
- brw->wm.sampler_count = _mesa_fls(SamplersUsed);
- /* Currently we only use one sampler state table. Mirror the count. */
- brw->vs.sampler_count = brw->wm.sampler_count;
-
- if (brw->wm.sampler_count == 0)
+ if (sampler_count == 0)
return;
samplers = brw_state_batch(brw, AUB_TRACE_SAMPLER_STATE,
- brw->wm.sampler_count * sizeof(*samplers),
- 32, &brw->sampler.offset);
- memset(samplers, 0, brw->wm.sampler_count * sizeof(*samplers));
+ sampler_count * sizeof(*samplers),
+ 32, sst_offset);
+ memset(samplers, 0, sampler_count * sizeof(*samplers));
- for (unsigned s = 0; s < brw->wm.sampler_count; s++) {
+ for (unsigned s = 0; s < sampler_count; s++) {
if (SamplersUsed & (1 << s)) {
- const unsigned unit = (fs->SamplersUsed & (1 << s)) ?
- fs->SamplerUnits[s] : vs->SamplerUnits[s];
+ const unsigned unit = prog->SamplerUnits[s];
if (ctx->Texture.Unit[unit]._ReallyEnabled)
brw_update_sampler_state(brw, unit, s, &samplers[s],
- &brw->wm.sdc_offset[s]);
+ *sst_offset, &sdc_offset[s]);
}
}
brw->state.dirty.cache |= CACHE_NEW_SAMPLER;
}
-const struct brw_tracked_state brw_samplers = {
+static void
+brw_upload_fs_samplers(struct brw_context *brw)
+{
+ /* BRW_NEW_FRAGMENT_PROGRAM */
+ struct gl_program *fs = (struct gl_program *) brw->fragment_program;
+ brw->vtbl.upload_sampler_state_table(brw, fs,
+ brw->wm.sampler_count,
+ &brw->wm.sampler_offset,
+ brw->wm.sdc_offset);
+}
+
+const struct brw_tracked_state brw_fs_samplers = {
.dirty = {
.mesa = _NEW_TEXTURE,
.brw = BRW_NEW_BATCH |
- BRW_NEW_VERTEX_PROGRAM |
BRW_NEW_FRAGMENT_PROGRAM,
.cache = 0
},
- .emit = brw_upload_samplers,
+ .emit = brw_upload_fs_samplers,
+};
+
+static void
+brw_upload_vs_samplers(struct brw_context *brw)
+{
+ /* BRW_NEW_VERTEX_PROGRAM */
+ struct gl_program *vs = (struct gl_program *) brw->vertex_program;
+ brw->vtbl.upload_sampler_state_table(brw, vs,
+ brw->vs.sampler_count,
+ &brw->vs.sampler_offset,
+ brw->vs.sdc_offset);
+}
+
+
+const struct brw_tracked_state brw_vs_samplers = {
+ .dirty = {
+ .mesa = _NEW_TEXTURE,
+ .brw = BRW_NEW_BATCH |
+ BRW_NEW_VERTEX_PROGRAM,
+ .cache = 0
+ },
+ .emit = brw_upload_vs_samplers,
};
+void
+gen4_init_vtable_sampler_functions(struct brw_context *brw)
+{
+ brw->vtbl.upload_sampler_state_table = brw_upload_sampler_state_table;
+}