r300: stub derivatives on r300 and r400 hardware
authorFilip Gawin <filip.gawin@zoho.com>
Wed, 3 Nov 2021 10:42:18 +0000 (11:42 +0100)
committerMarge Bot <emma+marge@anholt.net>
Wed, 3 Nov 2021 21:56:19 +0000 (21:56 +0000)
There are three approaches for problem:
- use dummy shader (current solution)
- use software rendering
- stub

First option always gonna give bad results, second one
gonna be slideshow (r300/r400 at best are running with
old 2 cores cpu), third one can sometimes give graphical
gliches.

IMHO third one is least annoying option.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13642>

src/gallium/drivers/r300/compiler/r3xx_fragprog.c
src/gallium/drivers/r300/compiler/radeon_program_alu.c
src/gallium/drivers/r300/compiler/radeon_program_alu.h

index d03462c..b3ccb7a 100644 (file)
@@ -109,6 +109,7 @@ void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c)
 
        struct radeon_program_transformation native_rewrite_r300[] = {
                { &radeonTransformALU, 0 },
+               { &radeonStubDeriv, 0 },
                { &r300_transform_trig_simple, 0 },
                { 0, 0 }
        };
index 5178da1..3a2aecf 100644 (file)
@@ -1186,6 +1186,25 @@ int r300_transform_trig_scale_vertex(struct radeon_compiler *c,
 }
 
 /**
+ * Replaces DDX/DDY instructions with MOV 0 to avoid using dummy shaders on r300/r400.
+ *
+ * @warning This explicitly changes the form of DDX and DDY!
+ */
+
+int radeonStubDeriv(struct radeon_compiler* c,
+       struct rc_instruction* inst,
+       void* unused)
+{
+       if (inst->U.I.Opcode != RC_OPCODE_DDX && inst->U.I.Opcode != RC_OPCODE_DDY)
+               return 0;
+
+       inst->U.I.Opcode = RC_OPCODE_MOV;
+       inst->U.I.SrcReg[0].Swizzle = RC_SWIZZLE_0000;
+
+       return 1;
+}
+
+/**
  * Rewrite DDX/DDY instructions to properly work with r5xx shaders.
  * The r5xx MDH/MDV instruction provides per-quad partial derivatives.
  * It takes the form A*B+C. A and C are set by setting src0. B should be -1.
index d100682..6f347d1 100644 (file)
@@ -55,6 +55,11 @@ int r300_transform_trig_scale_vertex(
        struct rc_instruction *inst,
        void*);
 
+int radeonStubDeriv(
+       struct radeon_compiler * c,
+       struct rc_instruction * inst,
+       void*);
+
 int radeonTransformDeriv(
        struct radeon_compiler * c,
        struct rc_instruction * inst,