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
82 break;82 break;
83 case DRM_VC4_PARAM_SUPPORTS_BRANCHES:83 case DRM_VC4_PARAM_SUPPORTS_BRANCHES:
84 case DRM_VC4_PARAM_SUPPORTS_ETC1:84 case DRM_VC4_PARAM_SUPPORTS_ETC1:
85 case DRM_VC4_PARAM_SUPPORTS_THREADED_FS:
85 args->value = true;86 args->value = true;
86 break;87 break;
87 default:88 default:
drivers/gpu/drm/vc4/vc4_drv.h+2−0
@@ -381,6 +381,8 @@ struct vc4_validated_shader_info { · 380 unmodified lines
381 381
382 uint32_t num_uniform_addr_offsets;382 uint32_t num_uniform_addr_offsets;
383 uint32_t *uniform_addr_offsets;383 uint32_t *uniform_addr_offsets;
384
385 bool is_threaded;
384};386};
385 387
386/**388/**
drivers/gpu/drm/vc4/vc4_validate.c+12−5
@@ -789,11 +789,6 @@ validate_gl_shader_rec(struct drm_device *dev, · 788 unmodified lines
789 exec->shader_rec_v += roundup(packet_size, 16);789 exec->shader_rec_v += roundup(packet_size, 16);
790 exec->shader_rec_size -= packet_size;790 exec->shader_rec_size -= packet_size;
791 791
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
797 for (i = 0; i < shader_reloc_count; i++) {792 for (i = 0; i < shader_reloc_count; i++) {
798 if (src_handles[i] > exec->bo_count) {793 if (src_handles[i] > exec->bo_count) {
799 DRM_ERROR("Shader handle %d too big\n", src_handles[i]);794 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
810 return -EINVAL;805 return -EINVAL;
811 }806 }
812 807
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
813 for (i = 0; i < shader_reloc_count; i++) {820 for (i = 0; i < shader_reloc_count; i++) {
814 struct vc4_validated_shader_info *validated_shader;821 struct vc4_validated_shader_info *validated_shader;
815 uint32_t o = shader_reloc_offsets[i];822 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
83 * basic blocks.83 * basic blocks.
84 */84 */
85 bool needs_uniform_address_for_loop;85 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;
86};93};
87 94
88static uint32_t95static uint32_t
@@ -118,6 +125,13 @@ raddr_add_a_to_live_reg_index(uint64_t inst) · 29 unmodified lines
118 return ~0;125 return ~0;
119}126}
120 127
128static bool
129live_reg_is_upper_half(uint32_t lri)
130{
131 return (lri >= 16 && lri < 32) ||
132 (lri >= 32 + 16 && lri < 32 + 32);
133}
134
121static bool135static bool
122is_tmu_submit(uint32_t waddr)136is_tmu_submit(uint32_t waddr)
123{137{
@@ -390,6 +404,9 @@ check_reg_write(struct vc4_validated_shader_info *validated_shader, · 266 unmodified lines
390 } else {404 } else {
391 validation_state->live_immediates[lri] = ~0;405 validation_state->live_immediates[lri] = ~0;
392 }406 }
407
408 if (live_reg_is_upper_half(lri))
409 validation_state->all_registers_used = true;
393 }410 }
394 411
395 switch (waddr) {412 switch (waddr) {
@@ -598,6 +615,11 @@ check_instruction_reads(struct vc4_validated_shader_info *validated_shader, · 202 unmodified lines
598 }615 }
599 }616 }
600 617
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
601 return true;623 return true;
602}624}
603 625
@@ -753,6 +775,7 @@ vc4_validate_shader(struct drm_gem_cma_object *shader_obj) · 149 unmodified lines
753{775{
754 bool found_shader_end = false;776 bool found_shader_end = false;
755 int shader_end_ip = 0;777 int shader_end_ip = 0;
778 uint32_t last_thread_switch_ip = -3;
756 uint32_t ip;779 uint32_t ip;
757 struct vc4_validated_shader_info *validated_shader = NULL;780 struct vc4_validated_shader_info *validated_shader = NULL;
758 struct vc4_shader_validation_state validation_state;781 struct vc4_shader_validation_state validation_state;
@@ -785,6 +808,17 @@ vc4_validate_shader(struct drm_gem_cma_object *shader_obj) · 26 unmodified lines
785 if (!vc4_handle_branch_target(&validation_state))808 if (!vc4_handle_branch_target(&validation_state))
786 goto fail;809 goto fail;
787 810
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
788 switch (sig) {822 switch (sig) {
789 case QPU_SIG_NONE:823 case QPU_SIG_NONE:
790 case QPU_SIG_WAIT_FOR_SCOREBOARD:824 case QPU_SIG_WAIT_FOR_SCOREBOARD:
@@ -794,6 +828,8 @@ vc4_validate_shader(struct drm_gem_cma_object *shader_obj) · 3 unmodified lines
794 case QPU_SIG_LOAD_TMU1:828 case QPU_SIG_LOAD_TMU1:
795 case QPU_SIG_PROG_END:829 case QPU_SIG_PROG_END:
796 case QPU_SIG_SMALL_IMM:830 case QPU_SIG_SMALL_IMM:
831 case QPU_SIG_THREAD_SWITCH:
832 case QPU_SIG_LAST_THREAD_SWITCH:
797 if (!check_instruction_writes(validated_shader,833 if (!check_instruction_writes(validated_shader,
798 &validation_state)) {834 &validation_state)) {
799 DRM_ERROR("Bad write at ip %d\n", ip);835 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
809 shader_end_ip = ip;845 shader_end_ip = ip;
810 }846 }
811 847
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
812 break;860 break;
813 861
814 case QPU_SIG_LOAD_IMM:862 case QPU_SIG_LOAD_IMM:
@@ -823,6 +871,13 @@ vc4_validate_shader(struct drm_gem_cma_object *shader_obj) · 8 unmodified lines
823 if (!check_branch(inst, validated_shader,871 if (!check_branch(inst, validated_shader,
824 &validation_state, ip))872 &validation_state, ip))
825 goto fail;873 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
826 break;881 break;
827 default:882 default:
828 DRM_ERROR("Unsupported QPU signal %d at "883 DRM_ERROR("Unsupported QPU signal %d at "
@@ -844,6 +899,14 @@ vc4_validate_shader(struct drm_gem_cma_object *shader_obj) · 15 unmodified lines
844 goto fail;899 goto fail;
845 }900 }
846 901
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
847 /* If we did a backwards branch and we haven't emitted a uniforms910 /* If we did a backwards branch and we haven't emitted a uniforms
848 * reset since then, we still need the uniforms stream to have the911 * reset since then, we still need the uniforms stream to have the
849 * uniforms address available so that the backwards branch can do its912 * 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
287#define DRM_VC4_PARAM_V3D_IDENT2 2287#define DRM_VC4_PARAM_V3D_IDENT2 2
288#define DRM_VC4_PARAM_SUPPORTS_BRANCHES 3288#define DRM_VC4_PARAM_SUPPORTS_BRANCHES 3
289#define DRM_VC4_PARAM_SUPPORTS_ETC1 4289#define DRM_VC4_PARAM_SUPPORTS_ETC1 4
290#define DRM_VC4_PARAM_SUPPORTS_THREADED_FS 5
290 291
291struct drm_vc4_get_param {292struct drm_vc4_get_param {
292 __u32 param;293 __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