History

drm/vc4: Add fragment shader threading support

FS threading brings performance improvements of 0-20% in glmark2. The validation code checks for thread switch signals and ensures that the registers of the other thread are not touched, and that our clamps are not live across thread switches. It also checks that the threading and branching instructions do not interfere. (Original patch by Jonas, changes by anholt for style cleanup, removing validation the kernel doesn't need to do, and adding the flag for userspace). v2: Minor style fixes from checkpatch.

Jonas Pfeil committed 10 years ago

Commit c778cc51 parent 3a622345 files · +79 −5Browse files

Unified · Split

5 files
  1. drivers/gpu/drm/vc4/vc4_drv.c +1 −0
  2. drivers/gpu/drm/vc4/vc4_drv.h +2 −0
  3. drivers/gpu/drm/vc4/vc4_validate.c +12 −5
  4. drivers/gpu/drm/vc4/vc4_validate_shaders.c +63 −0
  5. include/uapi/drm/vc4_drm.h +1 −0
drivers/gpu/drm/vc4/vc4_drv.c+1−0
@@ -82,6 +82,7 @@ static int vc4_get_param_ioctl(struct drm_device *dev, void *data, · 81 unmodified lines
8282 break;
8383 case DRM_VC4_PARAM_SUPPORTS_BRANCHES:
8484 case DRM_VC4_PARAM_SUPPORTS_ETC1:
85+ case DRM_VC4_PARAM_SUPPORTS_THREADED_FS:
8586 args->value = true;
8687 break;
8788 default:
drivers/gpu/drm/vc4/vc4_drv.h+2−0
@@ -381,6 +381,8 @@ struct vc4_validated_shader_info { · 380 unmodified lines
381381
382382 uint32_t num_uniform_addr_offsets;
383383 uint32_t *uniform_addr_offsets;
384+
385+ bool is_threaded;
384386 };
385387
386388 /**
drivers/gpu/drm/vc4/vc4_validate.c+12−5
@@ -789,11 +789,6 @@ validate_gl_shader_rec(struct drm_device *dev, · 788 unmodified lines
789789 exec->shader_rec_v += roundup(packet_size, 16);
790790 exec->shader_rec_size -= packet_size;
791791
792− if (!(*(uint16_t *)pkt_u & VC4_SHADER_FLAG_FS_SINGLE_THREAD)) {
793− DRM_ERROR("Multi-threaded fragment shaders not supported.\n");
794− return -EINVAL;
795− }
796−
797792 for (i = 0; i < shader_reloc_count; i++) {
798793 if (src_handles[i] > exec->bo_count) {
799794 DRM_ERROR("Shader handle %d too big\n", src_handles[i]);
@@ -810,6 +805,18 @@ validate_gl_shader_rec(struct drm_device *dev, · 10 unmodified lines
810805 return -EINVAL;
811806 }
812807
808+ if (((*(uint16_t *)pkt_u & VC4_SHADER_FLAG_FS_SINGLE_THREAD) == 0) !=
809+ to_vc4_bo(&bo[0]->base)->validated_shader->is_threaded) {
810+ DRM_ERROR("Thread mode of CL and FS do not match\n");
811+ return -EINVAL;
812+ }
813+
814+ if (to_vc4_bo(&bo[1]->base)->validated_shader->is_threaded ||
815+ to_vc4_bo(&bo[2]->base)->validated_shader->is_threaded) {
816+ DRM_ERROR("cs and vs cannot be threaded\n");
817+ return -EINVAL;
818+ }
819+
813820 for (i = 0; i < shader_reloc_count; i++) {
814821 struct vc4_validated_shader_info *validated_shader;
815822 uint32_t o = shader_reloc_offsets[i];
drivers/gpu/drm/vc4/vc4_validate_shaders.c+63−0
@@ -83,6 +83,13 @@ struct vc4_shader_validation_state { · 82 unmodified lines
8383 * basic blocks.
8484 */
8585 bool needs_uniform_address_for_loop;
86+
87+ /* Set when we find an instruction writing the top half of the
88+ * register files. If we allowed writing the unusable regs in
89+ * a threaded shader, then the other shader running on our
90+ * QPU's clamp validation would be invalid.
91+ */
92+ bool all_registers_used;
8693 };
8794
8895 static uint32_t
@@ -118,6 +125,13 @@ raddr_add_a_to_live_reg_index(uint64_t inst) · 29 unmodified lines
118125 return ~0;
119126 }
120127
128+static bool
129+live_reg_is_upper_half(uint32_t lri)
130+{
131+ return (lri >= 16 && lri < 32) ||
132+ (lri >= 32 + 16 && lri < 32 + 32);
133+}
134+
121135 static bool
122136 is_tmu_submit(uint32_t waddr)
123137 {
@@ -390,6 +404,9 @@ check_reg_write(struct vc4_validated_shader_info *validated_shader, · 266 unmodified lines
390404 } else {
391405 validation_state->live_immediates[lri] = ~0;
392406 }
407+
408+ if (live_reg_is_upper_half(lri))
409+ validation_state->all_registers_used = true;
393410 }
394411
395412 switch (waddr) {
@@ -598,6 +615,11 @@ check_instruction_reads(struct vc4_validated_shader_info *validated_shader, · 202 unmodified lines
598615 }
599616 }
600617
618+ if ((raddr_a >= 16 && raddr_a < 32) ||
619+ (raddr_b >= 16 && raddr_b < 32 && sig != QPU_SIG_SMALL_IMM)) {
620+ validation_state->all_registers_used = true;
621+ }
622+
601623 return true;
602624 }
603625
@@ -753,6 +775,7 @@ vc4_validate_shader(struct drm_gem_cma_object *shader_obj) · 149 unmodified lines
753775 {
754776 bool found_shader_end = false;
755777 int shader_end_ip = 0;
778+ uint32_t last_thread_switch_ip = -3;
756779 uint32_t ip;
757780 struct vc4_validated_shader_info *validated_shader = NULL;
758781 struct vc4_shader_validation_state validation_state;
@@ -785,6 +808,17 @@ vc4_validate_shader(struct drm_gem_cma_object *shader_obj) · 26 unmodified lines
785808 if (!vc4_handle_branch_target(&validation_state))
786809 goto fail;
787810
811+ if (ip == last_thread_switch_ip + 3) {
812+ /* Reset r0-r3 live clamp data */
813+ int i;
814+
815+ for (i = 64; i < LIVE_REG_COUNT; i++) {
816+ validation_state.live_min_clamp_offsets[i] = ~0;
817+ validation_state.live_max_clamp_regs[i] = false;
818+ validation_state.live_immediates[i] = ~0;
819+ }
820+ }
821+
788822 switch (sig) {
789823 case QPU_SIG_NONE:
790824 case QPU_SIG_WAIT_FOR_SCOREBOARD:
@@ -794,6 +828,8 @@ vc4_validate_shader(struct drm_gem_cma_object *shader_obj) · 3 unmodified lines
794828 case QPU_SIG_LOAD_TMU1:
795829 case QPU_SIG_PROG_END:
796830 case QPU_SIG_SMALL_IMM:
831+ case QPU_SIG_THREAD_SWITCH:
832+ case QPU_SIG_LAST_THREAD_SWITCH:
797833 if (!check_instruction_writes(validated_shader,
798834 &validation_state)) {
799835 DRM_ERROR("Bad write at ip %d\n", ip);
@@ -809,6 +845,18 @@ vc4_validate_shader(struct drm_gem_cma_object *shader_obj) · 9 unmodified lines
809845 shader_end_ip = ip;
810846 }
811847
848+ if (sig == QPU_SIG_THREAD_SWITCH ||
849+ sig == QPU_SIG_LAST_THREAD_SWITCH) {
850+ validated_shader->is_threaded = true;
851+
852+ if (ip < last_thread_switch_ip + 3) {
853+ DRM_ERROR("Thread switch too soon after "
854+ "last switch at ip %d\n", ip);
855+ goto fail;
856+ }
857+ last_thread_switch_ip = ip;
858+ }
859+
812860 break;
813861
814862 case QPU_SIG_LOAD_IMM:
@@ -823,6 +871,13 @@ vc4_validate_shader(struct drm_gem_cma_object *shader_obj) · 8 unmodified lines
823871 if (!check_branch(inst, validated_shader,
824872 &validation_state, ip))
825873 goto fail;
874+
875+ if (ip < last_thread_switch_ip + 3) {
876+ DRM_ERROR("Branch in thread switch at ip %d",
877+ ip);
878+ goto fail;
879+ }
880+
826881 break;
827882 default:
828883 DRM_ERROR("Unsupported QPU signal %d at "
@@ -844,6 +899,14 @@ vc4_validate_shader(struct drm_gem_cma_object *shader_obj) · 15 unmodified lines
844899 goto fail;
845900 }
846901
902+ /* Might corrupt other thread */
903+ if (validated_shader->is_threaded &&
904+ validation_state.all_registers_used) {
905+ DRM_ERROR("Shader uses threading, but uses the upper "
906+ "half of the registers, too\n");
907+ goto fail;
908+ }
909+
847910 /* If we did a backwards branch and we haven't emitted a uniforms
848911 * reset since then, we still need the uniforms stream to have the
849912 * uniforms address available so that the backwards branch can do its
include/uapi/drm/vc4_drm.h+1−0
@@ -287,6 +287,7 @@ struct drm_vc4_get_hang_state { · 286 unmodified lines
287287 #define DRM_VC4_PARAM_V3D_IDENT2 2
288288 #define DRM_VC4_PARAM_SUPPORTS_BRANCHES 3
289289 #define DRM_VC4_PARAM_SUPPORTS_ETC1 4
290+#define DRM_VC4_PARAM_SUPPORTS_THREADED_FS 5
290291
291292 struct drm_vc4_get_param {
292293 __u32 param;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t