-
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
11 changed files
with
314 additions
and
5 deletions.
There are no files selected for viewing
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,20 @@ | ||
/* | ||
************************************************************************************************************************ | ||
* | ||
* Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved. | ||
* | ||
***********************************************************************************************************************/ | ||
/** | ||
*********************************************************************************************************************** | ||
* @file NonSemanticDebugPrintf.h | ||
* @brief SPIR-V header file: proxy to the real Khronos SPIR-V header. | ||
*********************************************************************************************************************** | ||
*/ | ||
|
||
#pragma once | ||
|
||
#if EXTERNAL_SPIRV_HEADERS | ||
#include "spirv/unified1/NonSemanticDebugPrintf.h" | ||
#else | ||
#include "spirv/NonSemanticDebugPrintf.h" | ||
#endif |
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,50 @@ | ||
// Copyright (c) 2020 The Khronos Group Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and/or associated documentation files (the | ||
// "Materials"), to deal in the Materials without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Materials, and to | ||
// permit persons to whom the Materials are furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Materials. | ||
// | ||
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS | ||
// KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS | ||
// SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT | ||
// https://www.khronos.org/registry/ | ||
// | ||
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. | ||
// | ||
|
||
#ifndef SPIRV_UNIFIED1_NonSemanticDebugPrintf_H_ | ||
#define SPIRV_UNIFIED1_NonSemanticDebugPrintf_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
enum { | ||
NonSemanticDebugPrintfRevision = 1, | ||
NonSemanticDebugPrintfRevision_BitWidthPadding = 0x7fffffff | ||
}; | ||
|
||
enum NonSemanticDebugPrintfInstructions { | ||
NonSemanticDebugPrintfDebugPrintf = 1, | ||
NonSemanticDebugPrintfInstructionsMax = 0x7fffffff | ||
}; | ||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // SPIRV_UNIFIED1_NonSemanticDebugPrintf_H_ |
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); | ||
} |
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
/* | ||
; RUN: not amdllpc -spvgen-dir=%spvgendir% %gfxip %s 2>&1 | FileCheck -check-prefix=SHADERTEST %s | ||
; | ||
; 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); | ||
} |
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
/* | ||
; RUN: not amdllpc -spvgen-dir=%spvgendir% %gfxip %s 2>&1 | FileCheck -check-prefix=SHADERTEST %s | ||
; | ||
; 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); | ||
} |
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
/* | ||
; RUN: not amdllpc -spvgen-dir=%spvgendir% %gfxip %s 2>&1 | FileCheck -check-prefix=SHADERTEST %s | ||
; | ||
; 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
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 |