Bug 28517

Summary: [r300g] loop unrolling fails (was: Savage 2 : characters are not rendered + another corruptions)
Product: Mesa Reporter: Pavel Ondračka <pavel.ondracka>
Component: Drivers/DRI/r300Assignee: Default DRI bug account <dri-devel>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium CC: sa
Version: gitKeywords: NEEDINFO
Hardware: Other   
OS: All   
URL: http://www.savage2.com/en/download.php
Whiteboard:
i915 platform: i915 features:
Attachments: full terminal output
screenshot
RADEON_DEBUG=vp log
RADEON_DEBUG=vp log with patch from 29363
RADEON_DEBUG=vp log with vs-if-loop.patch
Screenshot of oversized character
Reduce the number of loop iterations
Screenshot of smearing in menu
RADEON_DEBUG=vp output with mesa 79088746a231d361232fc87ab4d578b08c7ce2a7

Description Pavel Ondračka 2010-06-13 02:58:24 UTC
Created attachment 36242 [details]
full terminal output

While in menu or in-game, characters are not rendered and there are many other problems (top half of the screen is almost white etc.).

Some selected terminal output:

r300 VP: Compiler error:
rc_dataflow_deadcode: Unexpected control flow instruction
Using a dummy shader instead.
If there's an 'unknown opcode' message, please file a bug report and attach this log.
When I tried this some time ago there were missing opcodes (BGNLOOP, BRK, ENDLOOP), it looks like they are implemented now however this error is new. This may interest Tom Stellard. 

Another problem:
Failed to allocate :
   size      : 16777216 bytes
   alignment : 2048 bytes
   domains   : 2
r300: Failed to create a transfer object, praise.
This is bug 28443

And lot of those:
Out of hw temporaries
Comment 1 Pavel Ondračka 2010-06-13 02:59:33 UTC
Created attachment 36243 [details]
screenshot
Comment 2 Pavel Ondračka 2010-06-13 04:18:23 UTC
I forgot to mention, all game graphic settings are set to lowest possible.
Comment 3 Pavel Ondračka 2010-06-24 01:38:30 UTC
With current mesa git compiler error looks different:

r300 VP: Compiler error:
Ran out of temporary registers
Using a dummy shader instead.
If there's an 'unknown opcode' message, please file a bug report and attach this log.

However rendering problems still remain.
Comment 4 Sven Arvidsson 2010-06-26 12:27:38 UTC
FWIW: the problem with the white top of the screen is the same on Intel with the i965 driver, so it's probably a general problem with Mesa.
Comment 5 Pavel Ondračka 2010-06-26 13:25:40 UTC
(In reply to comment #4)
> FWIW: the problem with the white top of the screen is the same on Intel with
> the i965 driver, so it's probably a general problem with Mesa.

Maybe this bug needs splitting, or is there already bug opened about this problem with i965 driver?
However I'm not sure if this is the same issue, I think the DRI and gallium drivers use different codepaths?
Comment 6 Sven Arvidsson 2010-06-26 14:12:54 UTC
(In reply to comment #5)
> Maybe this bug needs splitting, or is there already bug opened about this
> problem with i965 driver?
> However I'm not sure if this is the same issue, I think the DRI and gallium
> drivers use different codepaths?

Well, there's bug 27028, a general bug for getting Savage 2 running on Intel (at the moment it's only possible by increasing the loop unrolling limits).
Comment 7 Tom Stellard 2010-08-05 23:37:28 UTC
Can you try again with the latest git code and post the output with RADEON_DEBUG=vp
Comment 8 Sven Arvidsson 2010-08-06 03:33:54 UTC
Created attachment 37624 [details]
RADEON_DEBUG=vp log

(In reply to comment #7)
> Can you try again with the latest git code and post the output with
> RADEON_DEBUG=vp

Sure! Attaching a gzipped log.
Comment 9 Tom Stellard 2010-08-06 11:27:49 UTC
This patch: https://bugs.freedesktop.org/attachment.cgi?id=37644 from bug 29363 should help with this bug too.
Comment 10 Sven Arvidsson 2010-08-06 11:42:49 UTC
Created attachment 37647 [details]
RADEON_DEBUG=vp log with patch from 29363

(In reply to comment #9)
> This patch: https://bugs.freedesktop.org/attachment.cgi?id=37644 from bug 29363
> should help with this bug too.

There's not much of a difference visually, it might actually be a little worse with this patch. Not sure if that's much to go on though.

I'm also getting a lot of "Out of hw temporaries" warnings.

Attaching a new log with RADEON_DEBUG=vp if that's of any use.
Comment 11 Tom Stellard 2010-08-09 22:48:42 UTC
Can you try this patch https://bugs.freedesktop.org/attachment.cgi?id=37755 from bug 29363 and post the output of RADEON_DEBUG=vp.
Comment 12 Pavel Ondračka 2010-08-10 01:33:26 UTC
Created attachment 37759 [details]
RADEON_DEBUG=vp log with vs-if-loop.patch

Characters are being rendered now with your patch, but they are completely wrong, I would say they are too big and there are many another problems.
Comment 13 Sven Arvidsson 2010-08-10 07:51:36 UTC
Created attachment 37768 [details]
Screenshot of oversized character

I added a screenshot of the character, if that's helpful.

The slowdown mentioned in bug 29363 is also present in this game, but I guess that might be secondary issue.
Comment 14 Sven Arvidsson 2010-08-19 07:39:50 UTC
The bug with the character might be something general in Mesa, and not in r300g since it's almost the same in i965.
Comment 15 Pavel Ondračka 2010-08-25 01:49:54 UTC
With latest mesa git problem with top half of the screen being white is fixed, however characters are still corrupted, this is even worse than before glsl2 merge. As Sven Arvidsson said this may be a more generic problem, see similar problems described in bug 27028. However I suspect r300 compiler to also have some troubles because of the big slowdown introduced with Tom Stellards vertex shader loops patches.
Comment 16 Marek Olšák 2010-08-25 06:46:52 UTC
Can you point to the vertex shader loops patches which cause problems for you? Does reverting them help?
Comment 17 Tom Stellard 2010-08-25 07:20:15 UTC
(In reply to comment #13)
> Created an attachment (id=37768) [details]
> Screenshot of oversized character
> 
> I added a screenshot of the character, if that's helpful.
> 
> The slowdown mentioned in bug 29363 is also present in this game, but I guess
> that might be secondary issue.

The performance decrease you are seeing is because the correct vertex shaders are being used now instead of dummy shaders.
Comment 18 Tom Stellard 2010-08-25 07:32:59 UTC
(In reply to comment #17)
> The performance decrease you are seeing is because the correct vertex shaders
> are being used now instead of dummy shaders.

I should add that there are still some optimizations that can be done with vertex shader loops, but I can't really predict how much these optimizations will improve performance.
Comment 19 Pavel Ondračka 2010-08-25 08:09:00 UTC
(In reply to comment #17)
> (In reply to comment #13)
> > Created an attachment (id=37768) [details] [details]
> > Screenshot of oversized character
> > 
> > I added a screenshot of the character, if that's helpful.
> > 
> > The slowdown mentioned in bug 29363 is also present in this game, but I guess
> > that might be secondary issue.
> 
> The performance decrease you are seeing is because the correct vertex shaders
> are being used now instead of dummy shaders.

OK this explains everything, except that at this point the vertex shaders are not correct... do you need any more logs? However there is probably no rush to fix this, since the game wont be playable anyway, unless the possible optimization  speedup is really huge :-(
Comment 20 Sven Arvidsson 2010-08-25 13:55:55 UTC
With latest git master (commit b5c07b9226d8e7de78f6367b5799b39caf820ef3) I only get a black background and a mouse cursor. 

As for performance, it is much much slower than on my Intel IGP, slow enough that you need to wait for the mouse cursor to move, so something seems to be wrong.
Comment 21 Marek Olšák 2010-08-25 18:20:27 UTC
That doesn't sound good. Is there anything in dmesg? Perhaps you are just being successfully recovered from a hard lockup every frame.
Comment 22 Sven Arvidsson 2010-08-26 06:38:10 UTC
No, nothing in dmesg. And just to clarify, it's only the game that's black, X is unaffected.

I'll see if I can figure out where it broke, as it was working at least a little bit better before.
Comment 23 Sven Arvidsson 2010-08-26 14:09:58 UTC
Dunno why, but the black screen was caused by libtxc_dxtn, removing it made the problem go away. Anyway, some more observations about the performance problem: 

* It's not CPU-related, the game is only using about 60-70% on my system, so shouldn't be a problem. 

* If run the game in a window, all other graphics related operations (such as moving windows) slows to a crawl. 

* There's no significant difference in performance if I set all video options in the game to their lowest setting.


Another game (from the same developers) that's having the same problem, is Heroes of Newerth.
http://www.heroesofnewerth.com/download.php
Comment 24 Sven Arvidsson 2010-08-26 14:32:38 UTC
(Sorry for the bug spam)

The performance problem I'm having seems to be a result of the glsl2 merge, and not from the vs loops. So I guess that's a different problem than what Pavel have described.
Comment 25 Ian Romanick 2010-08-26 15:41:05 UTC
(In reply to comment #20)
> With latest git master (commit b5c07b9226d8e7de78f6367b5799b39caf820ef3) I only
> get a black background and a mouse cursor. 
> 
> As for performance, it is much much slower than on my Intel IGP, slow enough
> that you need to wait for the mouse cursor to move, so something seems to be
> wrong.

Is the rendering correct on Intel hardware?  If the rendering isn't correct anywhere, then the performance issues are irrelevant.  The performance will change, one way or the other, when the correctness is fixed.
Comment 26 Sven Arvidsson 2010-08-26 16:09:38 UTC
(In reply to comment #25)
> Is the rendering correct on Intel hardware?  If the rendering isn't correct
> anywhere, then the performance issues are irrelevant.  The performance will
> change, one way or the other, when the correctness is fixed.

No, it isn't correct on i965 either. Last word was that it was a bug in the preprocessor, see bug 27028.
Comment 27 Ian Romanick 2010-08-26 16:31:51 UTC
(In reply to comment #26)
> (In reply to comment #25)
> > Is the rendering correct on Intel hardware?  If the rendering isn't correct
> > anywhere, then the performance issues are irrelevant.  The performance will
> > change, one way or the other, when the correctness is fixed.
> 
> No, it isn't correct on i965 either. Last word was that it was a bug in the
> preprocessor, see bug 27028.

The preprocessor test mentioned in that bug seems to work correctly now.  I believe that one is fixed.
Comment 28 Pavel Ondračka 2010-08-27 00:37:49 UTC
(In reply to comment #24)
> (Sorry for the bug spam)
> 
> The performance problem I'm having seems to be a result of the glsl2 merge, and
> not from the vs loops. So I guess that's a different problem than what Pavel
> have described.

Hm, I don't really get this, I thought you also suffered from the slowdown problem with vs loops patches long before glsl2 was merged (as indicated in comment 13)? Never mind, I'll repeat my bisecting later today, maybe I did something wrong last time.
Comment 29 Tom Stellard 2010-08-30 09:08:21 UTC
Created attachment 38306 [details] [review]
Reduce the number of loop iterations

Does this patch impact performance at all?
Comment 30 Pavel Ondračka 2010-08-30 12:01:04 UTC
(In reply to comment #29)
> Created an attachment (id=38306) [details]
> Reduce the number of loop iterations
> 
> Does this patch impact performance at all?

No noticeable difference with you patch. BTW I did repeat bisecting and it again showed commit c298bab60ea63882f34825a35cbc60f662783e64 as the one introducing this slowness. So indeed your analysis in comment 17 looks right. I wasn't able to bisect any further slowdown with glsl2 merge which Sven mentioned in comment 24. However we might have different setups because for example I don't have any troubles with libtxc_dxtn.so
Comment 31 Sven Arvidsson 2010-08-30 12:24:37 UTC
(In reply to comment #29)
> Created an attachment (id=38306) [details]
> Reduce the number of loop iterations
> 
> Does this patch impact performance at all?

No noticeable difference here either.

I did notice a few compile errors though:
 r300 FP: Compiler Error:
 Fragment program does not support relative addressing  of source operands. 
 Using a dummy shader instead

And I'm getting these errors:
 radeon: The kernel rejected CS, see dmesg for more information.

dmesg:
 [340535.918564] [drm:radeon_cs_ioctl] *ERROR* Invalid command stream !
 [340536.199125] [drm:r100_cs_track_check] *ERROR* [drm] Buffer too small for color buffer 0 (need 4194304 have 3145728) !
 [340536.199129] [drm:r100_cs_track_check] *ERROR* [drm] color buffer 0 (1024 4 0 1024)

This behaviour is the same with or without the patch.
Comment 32 Sven Arvidsson 2010-09-01 14:21:15 UTC
Interesting, the game seems to be rendering fine when llvmpipe is used.
Comment 33 Ian Romanick 2010-09-03 12:19:34 UTC
(In reply to comment #31)
> (In reply to comment #29)
> > Created an attachment (id=38306) [details] [details]
> > Reduce the number of loop iterations
> > 
> > Does this patch impact performance at all?
> 
> No noticeable difference here either.
> 
> I did notice a few compile errors though:
>  r300 FP: Compiler Error:
>  Fragment program does not support relative addressing  of source operands. 
>  Using a dummy shader instead

This may be fixed now that loop unrolling is merged.  Can you retest?
Comment 34 Sven Arvidsson 2010-09-03 13:48:30 UTC
Created attachment 38409 [details]
Screenshot of smearing in menu

(In reply to comment #33)
> 
> This may be fixed now that loop unrolling is merged.  Can you retest?

It is if not fixed, at least a whole lot better now! :)

Fixed:
* The model in the menu and the player character is rendered correctly as far as I can tell. 
* The horrible slowdown is gone.

Remaining problems are: 
* "Smearing" in the menu (see screenshot for a better explanation) probably because I'm still getting "radeon: The kernel rejected CS, see dmesg for more information." errors logged in the terminal.
* Ingame, all textures seems to be white, not sure if this is related to my problems with S3TC or something else.

So the GLSL side of things seems to have been taken care of!
Comment 35 Tom Stellard 2010-09-03 23:14:37 UTC
Can you repost the output of RADEON_DEBUG=vp with the latest git version?  I want to see what the shaders look like with loop unrolling.
Comment 36 Pavel Ondračka 2010-09-04 02:49:20 UTC
Created attachment 38421 [details]
RADEON_DEBUG=vp output with mesa 79088746a231d361232fc87ab4d578b08c7ce2a7

This is with latest mesa and graphic settings set to lowest possible (no glitches with lowest settings).
Comment 37 Sven Arvidsson 2010-09-04 05:12:48 UTC
(In reply to comment #36)
> 
> This is with latest mesa and graphic settings set to lowest possible (no
> glitches with lowest settings).

Good catch, it's seems to be working well on lowest settings here too!

Maybe we should consider this bug done and file new reports for the remaining issues?
Comment 38 Pavel Ondračka 2010-09-04 05:59:43 UTC
(In reply to comment #37)
> (In reply to comment #36)
> > 
> > This is with latest mesa and graphic settings set to lowest possible (no
> > glitches with lowest settings).
> 
> Good catch, it's seems to be working well on lowest settings here too!
> 
> Maybe we should consider this bug done and file new reports for the remaining
> issues?

OK, closing, we spammed this report too much already. File new bugs if you want. I'm not interested in higher settings since the game isn't fast enough to be playable even with lowest settings here with my RV530 :-(
Comment 39 Sven Arvidsson 2010-09-05 13:02:28 UTC
Remaining issue filed as bug 30036.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.