[Mesa-dev] [PATCH 5/8] i965: Implement FS backend for ARB_sample_shading

Anuj Phogat anuj.phogat at gmail.com
Wed Oct 16 03:23:23 CEST 2013


On Tue, Oct 15, 2013 at 3:28 PM, Kenneth Graunke <kenneth at whitecape.org> wrote:
> On 10/14/2013 10:12 AM, Anuj Phogat wrote:
>> Implement the FS backend for new builtins added by the extension:
>> in vec2 gl_SamplePosition
>> in int gl_SampleID
>> in int gl_NumSamples
>> out int gl_SampleMask[]
>>
>> Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
>> ---
>>  src/mesa/drivers/dri/i965/brw_fs.cpp         | 109 +++++++++++++++++++++++++++
>>  src/mesa/drivers/dri/i965/brw_fs.h           |   4 +
>>  src/mesa/drivers/dri/i965/brw_fs_visitor.cpp |  23 ++++++
>>  src/mesa/drivers/dri/i965/brw_wm.h           |   1 +
>>  4 files changed, 137 insertions(+)
>>
>> diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
>> index e5d6e4b..e4f7745 100644
>> --- a/src/mesa/drivers/dri/i965/brw_fs.cpp
>> +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
>> @@ -1115,6 +1115,109 @@ fs_visitor::emit_frontfacing_interpolation(ir_variable *ir)
>>     return reg;
>>  }
>>
>> +void
>> +fs_visitor::compute_sample_position(fs_reg dst, fs_reg int_sample_pos)
>> +{
>> +   int num_samples = ctx->DrawBuffer->Visual.samples;
>> +   assert(num_samples >= 0 && num_samples <= 8);
>> +
>> +   /* From arb_sample_shading specification:
>> +    * "When rendering to a non-multisample buffer, or if multisample
>> +    *  rasterization is disabled, gl_SamplePosition will always be
>> +    *  (0.5, 0.5).
>> +    */
>> +   if (!ctx->Multisample.Enabled || num_samples == 0) {
>> +      emit(BRW_OPCODE_MOV, dst, fs_reg(0.5f));
>> +   }
>> +   else {
>> +      /* For num_samples = {4, 8} */
>> +      emit(BRW_OPCODE_MOV, dst, int_sample_pos);
>> +      emit(BRW_OPCODE_MUL, dst, dst, fs_reg(1 / 16.0f));
>> +   }
>> +}
>
>> +fs_reg *
>> +fs_visitor::emit_sampleid_interpolation(ir_variable *ir)
>> +{
>> +   assert(brw->gen >= 6);
>> +   bool multisampled_fbo = ctx->DrawBuffer->Visual.samples > 1;
>> +
>> +   this->current_annotation = "compute sample id";
>> +   fs_reg *reg = new(this->mem_ctx) fs_reg(this, ir->type);
>> +
>> +   if (multisampled_fbo && ctx->Multisample.Enabled) {
>
> One more thing.  These two blocks have different conditions.  For
> gl_SamplePosition, num_samples == 1 hits the MSAA case.  For
> gl_SampleId, num_samples == 1 hits the non-MSAA case.
>
> I don't know which is right, but they should match.
we use num_samples > 1 to identify a multisample_fbo. I'll make
changes in gl_SamplePosition to match gl_SampleId.

Thanks
Anuj


More information about the mesa-dev mailing list