-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
So far, it is complicated and time-consuming to test the behavior of certain instructions or their interactions. The easiest method to test a sequence of instructions to date, is to make a simple graphics test, disassemble the pipelines, edit the assembly, recompile them and use pipeline replacement to load the edited code. This patch adds a simpler and more robust way by letting one write inline assembly in glsl. glsl allows strings only in a single place, which is the debug print instruction. Using the special '%ra' format specifier [0] triggers llpc to interpret the second argument as an inline assembly string. The arguments to printf are: - "%ra" for radeon-assembly - assembly instructions - variable constraints - "no output" or a variable where the output is stored (optional if there are no further arguments) - zero or more arguments See the llvm reference for more details on how to write the constraint string: https://llvm.org/docs/LangRef.html#inline-assembler-expressions The added tests contain an example of how inline assembly can be used. [0]: The list of existing format specifiers does not include a %r: https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/master/docs/debug_printf.md#debug-printf-format-string
- Loading branch information
Showing
7 changed files
with
216 additions
and
4 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
llpc/test/shaderdb/extensions/OpExtInst_Print_InlineAsm.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
; RUN: amdllpc -spvgen-dir=%spvgendir% -v %gfxip %s | FileCheck -check-prefix=SHADERTEST %s | ||
; SHADERTEST-LABEL: {{^// LLPC}} SPIRV-to-LLVM translation results | ||
; SHADERTEST: = call float asm sideeffect "v_mul_f32 $0, $1, 2.0", "=v,r"(float | ||
; SHADERTEST: AMDLLPC SUCCESS | ||
*/ | ||
|
||
#version 450 | ||
|
||
#extension GL_EXT_debug_printf : enable | ||
|
||
layout(binding = 0) uniform Uniforms | ||
{ | ||
float x; | ||
}; | ||
|
||
layout(location = 0) out vec4 fragColor; | ||
|
||
void main() | ||
{ | ||
float x = x; | ||
|
||
debugPrintfEXT("%ra", "v_mul_f32 $0, $1, 2.0", "=v,r", x, x); | ||
|
||
fragColor = vec4(x); | ||
} |
18 changes: 18 additions & 0 deletions
18
llpc/test/shaderdb/extensions/OpExtInst_Print_InlineAsm_Error_NoArg.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
; RUN: not --crash amdllpc -spvgen-dir=%spvgendir% -v %gfxip %s 2>&1 | FileCheck -check-prefix=SHADERTEST %s | ||
; REQUIRES: assertions | ||
; | ||
; SHADERTEST: Not enough arguments for inline assembly {{.*}} 'my %ra' | ||
*/ | ||
|
||
#version 450 | ||
|
||
#extension GL_EXT_debug_printf : enable | ||
|
||
layout(location = 0) out vec4 fragColor; | ||
|
||
void main() | ||
{ | ||
debugPrintfEXT("my %ra"); | ||
fragColor = vec4(0.0); | ||
} |
18 changes: 18 additions & 0 deletions
18
llpc/test/shaderdb/extensions/OpExtInst_Print_InlineAsm_Error_NoOutput.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
; RUN: not --crash amdllpc -spvgen-dir=%spvgendir% -v %gfxip %s 2>&1 | FileCheck -check-prefix=SHADERTEST %s | ||
; REQUIRES: assertions | ||
; | ||
; SHADERTEST: Unexpected string 'v_another_inst' {{.*}} Expected a variable or 'no output' | ||
*/ | ||
|
||
#version 450 | ||
|
||
#extension GL_EXT_debug_printf : enable | ||
|
||
layout(location = 0) out vec4 fragColor; | ||
|
||
void main() | ||
{ | ||
debugPrintfEXT("%ra", "v_inst", "", "v_another_inst"); | ||
fragColor = vec4(0.0); | ||
} |
18 changes: 18 additions & 0 deletions
18
llpc/test/shaderdb/extensions/OpExtInst_Print_InlineAsm_Error_NoOutputVar.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
; RUN: not --crash amdllpc -spvgen-dir=%spvgendir% -v %gfxip %s 2>&1 | FileCheck -check-prefix=SHADERTEST %s | ||
; REQUIRES: assertions | ||
; | ||
; SHADERTEST: Unexpected value '' {{.*}} Expected a variable | ||
*/ | ||
|
||
#version 450 | ||
|
||
#extension GL_EXT_debug_printf : enable | ||
|
||
layout(location = 0) out vec4 fragColor; | ||
|
||
void main() | ||
{ | ||
debugPrintfEXT("%ra", "v_mov $0, 1.0", "", 1); | ||
fragColor = vec4(0.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!amber | ||
|
||
# RUN: run_amber_test.py --icd %icd %s | FileCheck %s | ||
# REQUIRES: gfx10.1.0 | ||
|
||
# Test that inline assembly from printf strings is executed. | ||
|
||
SHADER vertex vert_shader GLSL | ||
#version 430 | ||
|
||
layout(location = 0) in vec3 position_in; | ||
layout(location = 0) out vec2 position_out; | ||
|
||
void main() { | ||
gl_Position = vec4(position_in, 1.0); | ||
position_out = gl_Position.xy; | ||
} | ||
END | ||
|
||
SHADER fragment frag_shader GLSL | ||
#version 430 | ||
#extension GL_EXT_debug_printf : enable | ||
|
||
layout(location = 0) in vec2 position_in; | ||
layout(location = 0) out vec4 color_out; | ||
|
||
void main() { | ||
// FIXME Inline assembly doesn't appear in pipeline dumps, so we can't check for it here | ||
// CHECK-NOT: v_mul_f32 {{.*}}, 2.0 | ||
vec2 pos = (position_in + vec2(1.0)) / 2.0; | ||
color_out = vec4(pos, 0.0, 1.0); | ||
float x = color_out.x; | ||
debugPrintfEXT("%ra", "v_mul_f32 $0, $1, 2.0", "=v,r", x, x); | ||
color_out.x = x; | ||
} | ||
END | ||
|
||
BUFFER framebuffer FORMAT B8G8R8A8_UNORM | ||
|
||
PIPELINE graphics pipeline | ||
ATTACH vert_shader | ||
ATTACH frag_shader | ||
BIND BUFFER framebuffer AS color LOCATION 0 | ||
FRAMEBUFFER_SIZE 32 32 | ||
END | ||
|
||
CLEAR_COLOR pipeline 0 0 0 255 | ||
CLEAR pipeline | ||
RUN pipeline DRAW_RECT POS 0 0 SIZE 32 32 | ||
|
||
EXPECT framebuffer IDX 16 16 SIZE 1 1 EQ_RGB 255 131 0 |