Commit Graph

64388 Commits

Author SHA1 Message Date
Kenneth Graunke 378eea9708 i965: Push computation for sampler state batch offsets up a level.
Other than this, brw_update_sampler_state only deals with a single
SAMPLER_STATE structure, and doesn't need to know which position it is
in the table.  The caller takes care of dealing with multiple surface
states.

Pushing this up a level allows us to drop the ss_index parameter.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
2014-08-02 05:14:42 -07:00
Kenneth Graunke 7efa183e8f i965: Drop unused 'ss_index' parameter from gen7_update_sampler_state.
This was copied from the Gen4-6 code, but is unused.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
2014-08-02 05:14:42 -07:00
Kenneth Graunke a381592a8e i965: Stop storing sdc_offset in brw_stage_state.
sdc_offset is produced and consumed in the same function, so there's no
need to store it in the context, nor pass pointers to it through various
call chains.

Saves 128 bytes per brw_stage_state structure, and makes the code
clearer as well.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
2014-08-02 05:14:42 -07:00
Kenneth Graunke 9a1a8cb84d i965: Drop the degenerate brw_sampler_default_color structure.
It's just an array of four floats, and we have an array of four floats,
so this is literally just a memcpy...but with custom structs and strange
macros to give the appearance of doing something more.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
2014-08-02 05:14:42 -07:00
Kenneth Graunke c8e2549785 i965: Write a better file comment for brw_sampler_state.c.
The old one has been inaccurate for years.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
2014-08-02 05:14:42 -07:00
Kenneth Graunke 3f67fb4dc3 i965: Rename brw_wm_sampler_state.c to brw_sampler_state.c.
When the driver was originally written, it only supported texturing in
the pixel shader backend; vertex and geometry shader texturing came much
later.  Originally, the pixel shader was referred to as "WM" (the
Windowizer/Masker unit).  So, this code happened to only be relevant for
the WM stage, at the time.

However, sampler state really applies to all stages, so putting "wm" in
the filename doesn't make sense.  I dropped it in gen7_sampler_state.c;
at this point the asymmetry just trips people up.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
2014-08-02 05:14:42 -07:00
Kenneth Graunke 6e12035834 i965/blorp: Don't set min_mag_neq bit in Gen6 SAMPLER_STATE.
The "Min/Mag State Not Equal" bit is supposed to be set when the min/mag
filters or address rounding modes differ.  BLORP uses identical min/mag
settings, so the bit should be unset.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
2014-08-02 05:14:42 -07:00
Kevin Rogovin e41cc45361 define GL_OES_standard_derivatives if extension is supported
Define the macro GL_OES_standard_derivatives as 1 if the extension
GL_OES_standard_derivatives is supported.

V2 [Chris]: Correct trailing whitespace

Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
2014-08-02 11:52:41 +12:00
Roland Scheidegger 3b69347efc llvmpipe: don't store number of layers per level
This could be recalculated, though it turns out the only use of it after
resource allocation is for calculating whole resource size (for scene size
accounting though that isn't quite ideal neither). Thus, instead just store
the whole resource size and drop it (saving a couple bytes of storage per
resource). It makes things simpler too. Note that for the accounting winsys
resources always come back with size 0 but this is unchanged (we don't actually
know the size in any case).
Also reformat llvmpipe_texture_layout (drop unneded indentation).

v2: adapt to previous changes.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-08-01 23:31:11 +02:00
Roland Scheidegger 7e7aebbbd0 llvmpipe: integrate memory allocation into llvmpipe_texture_layout
Seems pointless to just duplicate some of the calculations (the calculation
of actual memory used compared to what was predicted in llvmpipe_texture_layout
actually could have differed slightly in some cases due to different alignment
rules used though this should have been of no consequence).

v2: keep the previous mip alignment of MAX2(64, cacheline). This was added for
ARB_map_buffer_alignment - I'm not convinced it's needed for textures, but
it was supposed to be cleanup without functional change. Also replace div
with 64bit mul / comparison.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-08-01 23:31:11 +02:00
Roland Scheidegger 47096fbb5d llvmpipe: get rid of impossible code in alloc_image_data
Only used for non display target resources.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
2014-08-01 23:31:11 +02:00
Jordan Justen c860a379d2 i965/miptree: Layout 1D Array as 2D Array with height of 1
1D array miptrees were being laid out as a 2D texture with 1 slice.
This happened due to the mesa core storing the 1D array slice count in
the height field. On Intel hardware, we want to create a 2D array with
a height of 1 for the 1D array case.

Fixes assertion failure in piglit (gen6, gen8):
spec/glsl-1.30/execution/tex-miplevel-selection textureOffset 1DArrayShadow

In release builds of Mesa, this test was observed to cause a GPU hang
on gen8.

Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Cc: "10.2" <mesa-stable@lists.freedesktop.org>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=81450
Tested-by: Ben Widawsky <ben@bwidawsk.net>
Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
2014-08-01 11:13:07 -07:00
Glenn Kennard 3a9278b92c r600g: Implement gpu_shader5 textureGather
Adds 0-3 textureGather component selection and non-constant offsets

Caveat: 0 and 1 texture swizzles only work if textureGather component
select is 3 or a component that does not exist in the sampler texture
format. This is a hardware limitation, any other value returns
128/255=0.501961 for both 0 and 1.

Passes all textureGather piglit tests on radeon 6670, except for those
using 0/1 texture swizzles due to aforementioned reason.

Signed-off-by: Glenn Kennard <glenn.kennard@gmail.com>
Signed-off-by: Marek Olšák <marek.olsak@amd.com>
2014-08-01 16:19:47 +02:00
Aditya Atluri f455f34ab9 mesa: Add missing atomic buffer bindings and unbindings
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2014-08-01 15:50:26 +02:00
Michel Dänzer 150ac07b85 r600g/radeonsi: Prefer VRAM for CPU -> GPU streaming buffers
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2014-08-01 11:25:27 +09:00
Michel Dänzer 8898fff46c r600g/radeonsi: Reduce or even drop special treatment of persistent mappings
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2014-08-01 11:04:16 +09:00
Jon TURNEY 095c37e472 target-helpers: Do not build kms_dri on libdrm-less platforms.
Fix build since 3b176c441b for
dri_platform=none hosts.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2014-08-01 01:31:58 +01:00
Glenn Kennard b1eb00cd40 r600g: gpu_shader5 gl_SampleMaskIn support
Map TGSI_SEMANTIC_SAMPLEMASK to register/component.
Enable face register when sample mask is needed by shader.
Requires Evergreen/Cayman

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2014-07-31 11:51:05 +02:00
Glenn Kennard 2768a56f58 r600g: Implement gpu_shader5 integer ops
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2014-07-31 11:51:04 +02:00
Glenn Kennard 2133a1aedf r600g: Add IMUL_HI/UMUL_HI support
Fixes fs-imulExtended, fs-imulExtended-only-msb, fs-umulExtended,
fs-umulExtended-only-msb piglit tests.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2014-07-31 11:51:04 +02:00
Glenn Kennard a48b615006 r600g: Implement GL_ARB_texture_query_lod
Requires Evergreen or later

v2 (Andreas): Update relnotes/10.3

Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v1)
2014-07-31 11:51:04 +02:00
Eric Anholt 1da4bb5b97 gbm: Log at least one dlerror() when we fail to open any drivers.
We don't want to log every single error (such as all the ones where the file
wasn't even present in our list of search paths), but if you didn't find any
driver, then seeing at least one error is useful (since the common case as a
developer is a single DEFAULT_DRIVER_DIR or GBM_DRIVERS_PATH entry).

v2: Rebase on swrast changes.

Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2014-07-30 22:31:30 -07:00
Eric Anholt ef81ce9909 gbm: Fix a debug log message
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2014-07-30 22:30:19 -07:00
Eric Anholt bfb0da9fa7 gallium: Add a uif() helper function to complement fui()
I found myself often wanting this when I'm printing out a uint32_t mapping
of some GPU data, and I want to put in an interpretation of that value as
a float.

Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2014-07-30 22:30:19 -07:00
Vinson Lee bf3a26266d glapi: Do not use backtrace on DragonFly.
execinfo.h is not available on DragonFly.

Fixes this build error.

  CC       glapi_gentable.lo
glapi_gentable.c:44:22: fatal error: execinfo.h: No such file or directory

Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-07-30 21:48:09 -07:00
Roland Scheidegger 5a12155503 gallivm: fix up out-of-bounds level when using conformant out-of-bound behavior
When using (d3d10) conformant out-of-bound behavior for texel fetching
(currently always enabled) the level still needs to be set to a safe value
even though the offset in the end won't get used because the level is used
to look up the mip offset itself and the actual strides, which might otherwise
crash.
For simplicity, we'll use level 0 in this case (this ought to be safe, llvmpipe
does not actually fill in level 0 information if first_level is larger, but
some random strides / offsets shouldn't hurt as ultimately we always use
offset 0 in this case).
Fixes a crash in some in-house test where random huge levels appear in
lp_build_fetch_texel() (the test actually uses level 0 always but if the
fetching happens in a block with a execution mask random values may appear).

CC: <mesa-stable@lists.freedesktop.org>

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
2014-07-31 01:31:06 +02:00
Giovanni Campagna e57ad3d38c dri: Add a new capabilities for drivers that can't share buffers
The kms-dri swrast driver cannot share buffers using the GEM,
so it must tell the loader to disable extensions relying on
that, without disabling the image DRI extension altogether
(which would prevent the loader from working at all).
This requires a new gallium capability (which is queried on
the pipe_screen and for swrast drivers it's forwarded to the
winsys), and requires a new version of the DRI image extension.

[Emil Velikov]
 - Rebased on top of gallium-dri megadrivers.
 - Drop PIPE_CAP_BUFFER_SHARE and sw_winsys::get_param hook.
The can_share_buffer cap is set at InitScreen. We use a different
InitScreen (and thus value for the cap) function for kms_dri, due to
deeper differences originating from dri megadrivers.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2014-07-30 16:43:41 +01:00
Giovanni Campagna 3b176c441b gallium: Add a dumb drm/kms winsys backed swrast provider
Add a new winsys and target that can be used with a dri2 state tracker
and loader instead of drisw. This allows to use gbm as a dri2/image
loader and avoid the extra copy from the backbuffer to the shadow
frontbuffer.

The new driver is called "kms_swrast", and is loaded by gbm as a
fallback, because it is only useful with the gbm platform (as no buffer
sharing is possible)

To force select the driver set the environment variable
GBM_ALWAYS_SOFTWARE

[Emil Velikov]
 - Rebase on top of gallium megadriver.
 - s/text/test/ in configure.ac (Spotted by Andreas Pokorny).
 - Add scons support for winsys/sw/kms-dri and fix the build.
 - Provide separate DriverAPI, due to different InitScreen hook.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2014-07-30 16:33:09 +01:00
Giovanni Campagna 8430af5ebe Add support for swrast to the DRM EGL platform
Turn GBM into a swrast loader (providing putimage/getimage backed
by a dumb KMS buffer). This allows to run KMS+DRM GL applications
(such as weston or mutter-wayland) unmodified on cards that don't
have any client side HW acceleration component but that can do
modeset (examples include simpledrm and qxl)

[Emil Velikov]
 - Fix make check.
 - Split dri_open_driver() from dri_load_driver().
 - Don't try to bind the swrast extensions when using dri.
 - Handle swrast->CreateNewScreen() failure.
 - strdup the driver_name, as it's free'd at destruction.
 - s/LIBGL_ALWAYS_SOFTWARE/GBM_ALWAYS_SOFTWARE/
 - Move gbm_dri_bo_map/unmap to gbm_driiint.h.
 - Correct swrast fallback logic.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2014-07-30 16:33:09 +01:00
Emil Velikov e3a3dbe940 st/gbm: don't segfault if the fail to create the screen
Whenever dd_create_screen/pipe_loader_* fails, gdrm->dev may be NULL.
Thus peeking inside the struct will lead to a crash.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2014-07-30 16:33:09 +01:00
Emil Velikov d93ae21939 st/gbm: retrieve the driver-name via dd_driver_name()
... on static targets. Otherwise we'll crash badly as gdrm->dev is
NULL when we try to copy the string driver_name.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2014-07-30 16:33:09 +01:00
Brian Paul 85109bc507 glsl/glcpp: rename ERROR to ERROR_TOKEN to fix MSVC build
ERROR is a #define in the MSVC WinGDI.h header file.
Add the _TOKEN suffix as we do for a few other lexer tokens.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2014-07-30 08:12:03 -06:00
Ian Romanick 66decc7efa configure: Don't override user -g or -O options for debug builds
Principle of least surprise: --enable-debug should enable debugging.
Ages ago, Mesa's build system only added -g in dri-debug builds (yay for
the static Makefiles).  If you forgot to change it (or wrap the build
with custom scripts), you would often be disappointed when trying to gdb
Mesa bugs.  New developers, that may not yet have custom scripts, will
have this same issue.

I think we should enable experienced developers to do what they want,
and make things easier for new developers.  I already pass '-ggdb3 -O1'
or '-ggdb3 -Og' for CFLAGS, and I don't want configure to change them
for me.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
2014-07-29 15:49:27 -07:00
Carl Worth a62354a987 glsl: Add flex options to eliminate the default rule
We've had bugs in the past where we have been inadvertently matching the
default rule.

Just as we did in the pre-processor in the previous commit, we can use:

	%option warn nodefault

in the compiler to instruct flex to not generate the default rule, and
further to warn if our set of rules could let any characters go unmatched.

With this warning active, flex actually warns that the catch-all rule we
recently added to the compiler could never be matched. Since that is all
safely determined at compile time now, we can safely drop this run-time
compiler error message, (as we do in this commit).

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
2014-07-29 15:11:51 -07:00
Carl Worth bc8721f16f glsl/glcpp: Add flex options to eliminate the default rule.
We've had multiple bugs in the past where we have been inadvertently matching
the default rule, (which we never want to do). We recently added a catch-all
rule to avoid this, (and made this rule robust for future start conditions).

Kristian pointed out that flex allows us to go one step better. This syntax:

	%option warn nodefault

instructs flex to not generate the default rule at all. Further, flex will
generate a warning at compile time if the set of rules we provide are
inadequate, (such that it would be possible for the default rule to be
matched).

With this warning in place, I found that the catch-all rule was in fact
missing something. The catch-all rule uses a pattern of "." which doesn't
match newlines. So here we extend the newline-matching rule to all start
conditions. That is enough to convince flex that it really doesn't need
any default rule.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
2014-07-29 15:11:51 -07:00
Carl Worth 4ebff9bca6 glsl/glcpp: Combine the two rules matching any character
Using a single rule here means that we can use the <*> syntax to match
all start conditions. This makes the catch-all rule more robust against
the addition of future start conditions, (no need to maintain an ever-
growing list of start conditions for this rul).

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
2014-07-29 15:11:51 -07:00
Carl Worth 80e9301d9b glsl/glcpp: Alphabetize lists of start conditions
There is no behavioral change here. It's just easier to verify that lists
of start conditions include all expected conditions when they appear in a
consistent order.

The <INITIAL> state is special, so it appears first in all lists. All others
appear in alphabetical order.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
2014-07-29 15:11:51 -07:00
Carl Worth f9c99aefea glsl/glcpp: Add a catch-all rule for unexpected characters.
In some of the recent glcpp bug-fixing, we found that glcpp was emitting
unrecognized characters from the input source file to stdout, and dropping
them from the source passed onto the compiler proper.

This was obviously confusing, and totally undesired.

The bogus behavior comes from an implicit default rule in flex, which is
that any unmatched character is implicitly matched and printed to stdout.

To avoid this implicit matching and printing, here we add an explicit
catch-all rule. If this rule ever matches it prints an internal compiler
error. The correct response for any such error is fixing glcpp to handle
the unexpected character in the correct way.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-07-29 15:11:51 -07:00
Carl Worth 4757c74c84 glsl/glcpp: Treat carriage return as equivalent to line feed.
Previously, the '\r' character was not explicitly matched by any lexer
rule. This means that glcpp would have been using the default flex rule to
match '\r' characters, (where they would have been printed to stdout rather
than actually correctly handled).

With this commit, we treat '\r' as equivalent to '\n'. This is clearly an
improvement the bogus printing to stdout. The resulting behavior is compliant
with the GLSL specification for any source file that uses exclusively '\r' or
'\n' to separate lines.

For shaders that use a multiple-character line separator, (such as "\r\n"),
glcpp won't be precisely compliant with the specification, (treating these as
two newline characters rather than one), but this should not introduce any
semantic changes to the shader programs.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-07-29 15:11:51 -07:00
Carl Worth 12d583b21a glsl/glcpp: Add test for a multi-line comment within an #if 0 block
This test is written to exercise a bug which I recently wrote, (but
fortunately caught and fixed before ever committing it).

For the curious:

  The bug happened when the NEWLINE_CATCHUP code didn't actually return the
  NEWLINE token (due to the skipping). This resulted in the lexer continuing
  on through all the subsequent rules while still in the NEWLINE_CATCHUP start
  condition, (which then triggered the internal-compiler-error catch-all
  rule).

  What is intended is for the return of the NEWLINE token to start a new
  iteration of the lexer loop, at which time the NEWLINE_CATCHUP-handling code
  will reset from the <NEWLINE_CATCHUP> to the <INITIAL> start condition.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-07-29 15:11:50 -07:00
Carl Worth 346d712e87 glsl/glcpp: Test that macro parameters substitute immediately after periods
At one point while rewriting the lexing rule for pre-processing numbers, I
made it a bit too aggressive and within a replacement list sucked up a
parameter name that appeared immediately after a period. This caused the
parameter name to be unreplaced when the macro was expanded.

It was in some piglit tests that I originally found this issue. Here, I'm
adding a test to "make check" to ensure that this behavior remains correct.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-07-29 15:11:50 -07:00
Carl Worth 285c9392ad glsl/glcpp: Add (non)-support for ++ and -- operators
These operators aren't defined for preprocessor expressions, so we never
implemented them. This led them to be misinterpreted as strings of unary
'+' or '-' operators.

In fact, what is actually desired is to generate an error if these operators
appear in any preprocessor condition.

So this commit looks like it is strictly adding support for these
operators. And it is supporting them as far as passing them through to the
subsequent compiler, (which was already happening anyway).

What's less apparent in the commit is that with these tokens now being lexed,
but with no change to the grammar for preprocessor expressions, these
operators will now trigger errors there.

A new "make check" test is added to verify the desired behavior.

This commit fixes the following Khronos GLES3 CTS test:

	invalid_op_1_vertex
	invalid_op_1_fragment
	invalid_op_2_vertex
	invalid_op_2_fragment

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-07-29 15:11:50 -07:00
Carl Worth 34cd293c8a glsl/glcpp: Emit error for duplicate parameter name in function-like macro
This will emit an error for something like:

	#define FOO(x,x) ...

Obviously, it's not a legal thing to do, and it's easy to check.

Add a "make check" test for this as well.

This fixes the following Khronos GLES3 CTS tests:

	invalid_function_definitions.unique_param_name_vertex
	invalid_function_definitions.unique_param_name_fragment

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-07-29 15:11:50 -07:00
Carl Worth fe1e0ac852 glsl/glcpp: Add an explanatory comment for "loc != NULL" check
Just reading the code, it looked like a bug that _define_object_macro had this
check, but _define_function_macro did not. Upon further reading, that's
because the check is to allow for our builtins to be defined, (and there are
no builtin function-like macros).

Add my new understanding as a comment to help the next reader.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-07-29 15:11:50 -07:00
Carl Worth 18c589d20e glsl/glcpp: Drop the HASH_ prefix from token names like HASH_IF
Previously, we had a single token for "#if" but now that we have two separate
tokens, it looks much better to see:

	HASH_TOKEN IF

than:

	HASH_TOKEN HASH_IF

(Note, that for the same reason we use HASH_TOKEN instead of HASH, we also use
DEFINE_TOKEN instead of DEFINE to avoid a conflict with the <DEFINE> start
condition in the lexer.)

There should be no behavioral change from this commit.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-07-29 15:11:50 -07:00
Kenneth Graunke de0b4b6607 glsl: Properly lex extra tokens when handling # directives.
Without this, in the <PP> state, we would hit Flex's default rule, which
prints tokens to stdout, rather than returning them as tokens. (Or, after the
previous commit, we would hit the new catch-all rule and generate an internal
compiler error.)

With this commit in place, we generate the desired syntax error.

This manifested as a weird bug where shaders with semicolons after
extension directives, such as:

   #extension GL_foo_bar : enable;

would print semicolons to the screen, but otherwise compile just fine
(even though this is illegal).

Fixes Piglit's extension-semicolon.frag test.

This also fixes the following Khronos GLES3 conformance tests, (and for real
this time):

	invalid_char_in_name_vertex
	invalid_char_in_name_fragment

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Carl Worth <cworth@cworth.org>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-07-29 15:11:50 -07:00
Carl Worth f196eb2d39 glsl: Add an internal-error catch-all rule
This is to avoid the default, silent flex rule which simply prints the
character to stdout.

For the following Khronos GLES3 conformance tests:

	invalid_char_in_name_vertex
	invalid_char_in_name_fragment

With this commit, these tests now report Pass where they previously reported
Fail, but Mesa isn't behaving correctly yet. It's now reporting the internal
error where what is really desired is a syntax error.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-07-29 15:11:50 -07:00
Carl Worth f062f0506a glsl/glcpp: Correctly parse directives with intervening comments
It's legal (though highly bizarre) for a pre-processor directive to look like
this:

	#  /* why? */ define FOO bar

This behavior comes about since the specification defines separate logical
phases in a precise order, and comment-removal occurs in a phase before the
identification of directives.

Our implementation does not use an actual separate phase for comment removal,
so some extra care is necessary to correctly parse this. What we want is for
'#' to introduce a directive iff it is the first token on a line, (ignoring
whitespace and comments). Previously, we had a lexical rule that worked only
for whitespace (not comments) with the following regular expression to find a
directive-introducing '#' at the beginning of a line:

	HASH		^{HSPACE}*#{HSPACE}*

In this commit, we switch to instead use a simple literal match of '#' to
return a HASH_TOKEN token and add a new <HASH> start condition for whenever
the HASH_TOKEN is the first non-space token of a line. This requires the
addition of the new bit of state: first_non_space_token_this_line.

This approach has a couple of implications on the glcpp parser:

	1. The parser now sees two separate tokens, (such as HASH_TOKEN and
	   HASH_DEFINE) where it previously saw one token (HASH_DEFINE) for
	   the sequence "#define". This is a straightforward change throughout
	   the grammar.

	2. The parser may now see a SPACE token before the HASH_TOKEN token of
	   a directive. Previously the lexical regular expression for {HASH}
	   would eat up the space and there would be no SPACE token.

This second implication is a bit of a nuisance for the parser. It causes a
SPACE token to appear in a production of the grammar with the following two
definitions of a control_line:

	control_line
	SPACE control_line

This is really ugly, since normally a space would simply be a token
separator, so it wouldn't appear in the tokens of a production. This leads to
a further problem with interleaved spaces and comments:

	/* ... */    /* ... */ #define /* ..*/

For this, we must not return several consecutive SPACE tokens, or else we would need an arbitrary number of new productions:

	SPACE SPACE control_line
	SPACE SPACE SPACE control_line
	ad nauseam

To avoid this problem, in this commit we also change the lexer to emit only a
single SPACE token for any series of consecutive spaces, (whether from actual
whitespace or comments). For this compression, we add a new bit of parser
state: last_token_was_space. And we also update the expected results of all
necessary test cases for the new compression of space tokens.

Fortunately, the compression of spaces should not lead to any semantic changes
in terms of what the eventual GLSL compiler sees.

So there's a lot happening in this commit, (particularly for such a tiny
feature). But fortunately, the lexer itself is looking cleaner than ever. The
only ugly bit is all the state updating, but it is at least isolated to a
single shared function.

Of course, a new "make check" test is added for the new feature, (directives
with comments and whitespace interleaved in many combinations).

And this commit fixes the following Khronos GLES3 CTS tests:

	function_definition_with_comments_vertex
	function_definition_with_comments_fragment

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-07-29 15:11:50 -07:00
Carl Worth dfdf9dc082 glsl/glcpp: Rename HASH token to HASH_TOKEN
This is in preparation for the planned addition of a new <HASH> start
condition to the lexer. Both start conditions and token types are, of course,
in the same default C namespace, so a start condition and a token type with
the same name will collide. (And unfortunately, they are both apparently
implemented as equivalent numeric types so the collision is undetected at
compile time and simply leads to unpredictable behavior at run time.)

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-07-29 15:11:49 -07:00
Carl Worth 0d5f5d127b glsl/glcpp: Don't use start-condition stack when switching to/from <DEFINE>
This commit does not cause any behavioral change for any valid program. Prior
to entering the <DEFINE> start condition, the only valid start condition is
<INITIAL>, so whether pushing/popping <DEFINE> onto the stack or explicit
returning to <INITIAL> is equivalent.

The reason for this change is that we are planning to soon add a start
condition for <HASH> with the following semantics:

	<HASH>: We just saw a directive-introducing '#'

	<DEFINE>: We just saw "#define" starting a directive

With these two start conditions in place, the only correct behavior is to
leave <DEFINE> by returning to <INITIAL>. But the old push/pop code would have
returned to the <HASH> start condition which would then cause an error when
the next directive-introducing '#' would be encountered.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2014-07-29 15:11:49 -07:00