glapi: add ARB_texture_multisample

Adds new enums, dispatch machinery, and stubs for the 4 new entrypoints.

V2: - Drop placeholder
    - Align enum values
    - Remove explicit exec=mesa; it *is* the dispatch flavor we want,
      but it's also the default. I misunderstood how this worked before;
      after actually reading the generator it makes good sense.

V3: - Squash in stubs for new entrypoints, and dispatch_sanity tweaks,
      so we don't get build breakage between those patches.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
[1/3 V2] Reviewed-by: Matt Turner <mattst88@gmail.com>
[V3] Reviewed-by: Eric Anholt <eric@anholt.net>
mesa: add texobj support for ARB_texture_multisample

Adds the new texture targets, and per-image state for GL_TEXTURE_SAMPLES
and GL_TEXTURE_FIXED_SAMPLE_LOCATIONS.

V2: - Allow multisample texture targets in glInvalidateTexSubImage too.
      This was already partly there, but I missed it the first time around
      since the interaction is defined in a newer extension. Fixed weird
      indentation.
    - Allow multisample array textures in glFramebufferTextureLayer.
      This was overlooked as the tests originally only used 2d
      multisample textures.

V3: - Set min/mag filters sensibly for multisample textures. This
      can't actually be changed by the user, so it's more sensible to
      initialize it correctly than to hack around it being bogus later.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
tests: add ARB_texture_multisample enums to table

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
Reviewed-by: Eric Anholt <eric@anholt.net>
glsl: add support for ARB_texture_multisample

V2: - emit `sample` parameter properly for multisample texelFetch()
    - fix spurious whitespace change
    - introduce a new opcode ir_txf_ms rather than overloading the
      existing ir_txf further. This makes doing the right thing in
      the driver somewhat simpler.

V3: - fix weird whitespace

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
Reviewed-by: Eric Anholt <eric@anholt.net>
mesa: add new max sample count state

- GL_MAX_COLOR_TEXTURE_SAMPLES
- GL_MAX_DEPTH_TEXTURE_SAMPLES
- GL_MAX_INTEGER_SAMPLES

V2: initialize limits to 1 in _mesa_init_constants as suggested by Brian
and Paul

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
i965: expose new max sample counts

V2: For now, only expose a depth sample count of 1, since there are
unresolved interactions with W-tiling for stencil textures and possibly
also HiZ for depth textures.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
mesa: implement GetMultisamplefv

Actual sample locations deferred to a driverfunc since only the driver
really knows where they will be.

V2: - pass the draw buffer to the driverfunc; don't fallback to pixel
      center if driverfunc is missing.
    - rename GetSampleLocation to GetSamplePosition
    - invert y sample position for winsys FBOs, at Paul's suggestion

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
mesa: implement sample mask

V2: - fix multiline comment style
    - stop using ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH since that
      doesn't exist anymore.

V3: - check for the extension being enabled
    - tidier flagging of _NEW_MULTISAMPLE
    - fix weird indentation in get.c

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
i965: add support for sample mask on Gen6+

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
Reviewed-by: Eric Anholt <eric@anholt.net>
i965: expose sample positions

Moves the definition of the sample positions out of
gen6_emit_3dstate_multisample, and unpacks them in
gen6_get_sample_position.

V2: Be consistent about `sample position` rather than `location`.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
mesa: support multisample textures in framebuffer completeness check

- sample count must be the same on all attachments
- fixedsamplepositions must be the same on all attachments
(renderbuffers have fixedsamplepositions=true implicitly; only
multisample textures can choose to have it false)

V2: - fix wrapping to 80 columns, debug message, fix for state moving
      from texobj to image.
    - stencil texturing tweaks tidied up and folded in here.

V3: - Removed silly stencil hacks entirely; the extension doesn't
      actually make stencil-only textures legal at all.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
mesa: implement TexImage*Multisample

V2: - fix formatting issues
    - generate GL_OUT_OF_MEMORY if teximage cannot be allocated
    - fix for state moving from texobj to image

V3: - remove ridiculous stencil hack

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
i965: add support for multisample textures

V2: - Fix for state moving from texobj to image
    - Rebased onto Paul's logical/physical cleanup
    - Fixed missing quantization of sample count
    - Fold in IMS renderbuffer wrapper fixes from later in the series
    - Use correct physical slice offset for UMS/CMS surfaces on Gen7

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
i965: Support multisampling in surface_state for textures

The surface_state setup for renderbuffers already worked; only the
texturing side needed work. BLORP does something similar, but does its
own surface_state setup.

On Gen6, we just need to set the correct sample count.

On Gen7: - set the correct sample count
         - set the correct layout mode
         - set GEN7_SURFACE_ARYSPC_LOD0 if it's set in the miptree.

V2: - Clarify commit message
    - Rebased onto Paul's physical/logical dims cleanup
    - Added Gen7 support

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
i965: take the target into account for Gen7 MSAA modes

Gen7 has an erratum affecting the ld_mcs message, making it unsafe to
use when the surface doesn't have an associated MCS.

To allow the shader to treat all surfaces uniformly, force UMS if the
surface is to be used as a multisample texture, even if CMS would have
been possible.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
i965: add a new virtual opcode: SHADER_OPCODE_TXF_MS

This is very similar to the TXF opcode, but lowers to `ld2dms` rather
than `ld` on Gen7.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
i965/vs: add support for ir_txf_ms on Gen6+

On Gen6, lower this to `ld` with lod=0 and an extra sample_index
parameter.

On Gen7, use `ld2dms`. This takes an additional MCS parameter to support
compressed multisample surfaces, but we're not enabling them for
multisample textures for now, so it's always zero and can be safely
omitted.

V2: Reworked completely, added support for Gen7.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
i965/fs: add support for ir_txf_ms on Gen6+

On Gen6, lower this to `ld` with lod=0 and an extra sample_index
parameter.

On Gen7, use `ld2dms`. We don't support CMS yet for multisample
textures, so we use MCS=0, which does the right thing for both IMS and
UMS surfaces.

Note: If we do end up emitting specialized shaders based on the MSAA
layout, we can emit a slightly shorter message here in the UMS case.

V2: Reworked completely, added support for Gen7.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
i965: enable ARB_texture_multisample on Gen6+

V2: Works on Ivy Bridge now too, so this can be 6+.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
mesa: add helper for checking sample count

The effective limit for a format depends on which extensions are
supported, and the errors vary.

On p205 of the GL3.1 spec:

   "If either <width> or <height> is greater than MAX_RENDERBUFFER_SIZE,
   or if samples is greater than MAX_SAMPLES, then the error
   INVALID_VALUE is generated."

In GL3.2, or with ARB_texture_multisample:

   "If either <width> or <height> is greater than the value of
   MAX_RENDERBUFFER_SIZE, or if <samples> is greater than the value of
   MAX_SAMPLES, then the error INVALID_VALUE is generated.
   If <internalformat> is a signed or unsigned integer format and
   <samples> is greater than the value of MAX_INTEGER_SAMPLES, then the
   error INVALID_OPERATION is generated.

In GL4.1, or with ARB_internalformat_query:

   "If <samples> is greater than the maximum number of samples supported
   for <internalformat> then the error INVALID_OPERATION is generated
   (see GetInternalformativ in section 6.X)."

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>