google / amber

Amber is a multi-API shader test framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use Visual Studio Code debug AmberScript

kimown opened this issue · comments

My command

➜  sw git:(master) ✗ ./amber ../../tests/cases/debugger_spirv_line_stepping.amber
Waiting for debugger connection...



Debugger connection established
launch.json { "version": "0.2.0", "configurations": [ { "name": "Vulkan Shader Debugger", "type": "node", "request": "launch", "debugServer": 19020 } ] }

But in VSC, I didn't see any variable i can inspect, here is my screenshot

Hi @kimown,

Sorry for the delay on replying, I've just returned from vacation.

The debugger_spirv_line_stepping.amber file is one of the amber scripts for testing the SwiftShader DAP-based debugger functionality. Amber is setting breakpoints, single line stepping and inspecting variables as part of the test script. The debug session only permits one connection at any time, so you will be unable to connect VSC for these debugger tests.

If you are interested in using SwiftShader's debugger functionality, there is documentation here describing how to use this. Please note however, that this is work in progress.

Many thanks,
Ben

Hi @kimown,

Sorry for the delay on replying, I've just returned from vacation.

The debugger_spirv_line_stepping.amber file is one of the amber scripts for testing the SwiftShader DAP-based debugger functionality. Amber is setting breakpoints, single line stepping and inspecting variables as part of the test script. The debug session only permits one connection at any time, so you will be unable to connect VSC for these debugger tests.

If you are interested in using SwiftShader's debugger functionality, there is documentation here describing how to use this. Please note however, that this is work in progress.

Many thanks,
Ben

Thanks for creating this functionality, I did follow the doc, you can check out the attachment in the issue, it's a gif recording my operation, maybe I missing some important steps.

Hi @kimown,

The tests/cases/debugger_*.amber scripts are not intended to be debugged with an IDE. They exist to testing the debugger functionality itself.

These tests/cases/debugger_*.amber script files contain instructions for amber to control and test the debug session, not an external debugger.

The SwiftShader debugger functionality can be used with an IDE for regular Vulkan applications.

It is possible you may be able to use the debugger functionality on Vulkan amber scripts that are not prefixed with debugger_* using the VK_WAIT_FOR_DEBUGGER environment var (otherwise the test will likely complete before the debugger gets an opportunity to attach), but you're likely to run into test timeout issues.

Cheers,
Ben

Hi @kimown,

The tests/cases/debugger_*.amber scripts are not intended to be debugged with an IDE. They exist to testing the debugger functionality itself.

These tests/cases/debugger_*.amber script files contain instructions for amber to control and test the debug session, not an external debugger.

The SwiftShader debugger functionality can be used with an IDE for regular Vulkan applications.

It is possible you may be able to use the debugger functionality on Vulkan amber scripts that are not prefixed with debugger_* using the VK_WAIT_FOR_DEBUGGER environment var (otherwise the test will likely complete before the debugger gets an opportunity to attach), but you're likely to run into test timeout issues.

Cheers,
Ben

I see, I will try another amber script tomorrow.
Just another question, can I print variable in glsles shader in webgl, recently I begin learning webgl, but I found it hard to study because I can't inspect or print variable in glsles, so I am finding some ways helping me debug. I found latest vulkan support printf, I install Nvidia beta driver and it really works, but the problem is vulkan glsl is not webgl glsl, another way I can draw text in fragment shader like this, does other ways helping debug glsles?

@ben-clayton
I can't see any breakpoint when I set VK_WAIT_FOR_DEBUGGER env, the test just exit. when I run ./amber -d ../../tests/cases/clear_color.amber,
the consule output Waiting for debugger connection..., but when I click the VSC, the test exit and show

Debugger connection established

Summary: 1 pass, 0 fail

Here is my command

mkdir out/sw
cd out/sw
VK_DEBUGGER_PORT=19020
VK_WAIT_FOR_DEBUGGER=1

cmake -GNinja -DAMBER_USE_SWIFTSHADER=1 -DAMBER_ENABLE_SWIFTSHADER=1 -DAMBER_ENABLE_VK_DEBUGGING=1 ../..
export VK_ICD_FILENAMES=$PWD/Darwin/vk_swiftshader_icd.json
./amber -d ../../tests/cases/clear_color.amber

Before attaching the VSC debugger, did you set the function breakpoints as documented here?

These need to be set before attaching the debugger as the tests run and complete extremely quickly.

@ben-clayton

I added the function names but still the same problem, here is my steps:

  1. add function names in VSC image
  2. run ./amber -d ../../tests/cases/clear_color.amber
  3. click Start Debugging, the command still exit.

So I just tried to reproduce, and I think there are two things that are likely stopping this for working for you:

Above you use:

VK_DEBUGGER_PORT=19020
VK_WAIT_FOR_DEBUGGER=1

These need to be exported:

export VK_DEBUGGER_PORT=19020
export VK_WAIT_FOR_DEBUGGER=1

The second issue is that the tests/cases/clear_color.amber script declares a passthrough vertex and dummy fragment shader to build a pipeline, but doesn't actually draw anything wtih those shaders, so you're not going to have a breakpoint hit.

Try something like tests/cases/draw_polygon_mode.amber instead.

@ben-clayton
Many thanks, the debug works when I run ./amber -d ../../tests/cases/draw_polygon_mode.amber, below is my screenshot.

image

I have two questions, how can I change the default value of timeout, and what is OpenCL.DebugInfo.100, sorry I don't know much about this.

Glad it now works.

how can I change the default value of timeout

You can use the SET ENGINE_DATA fence_timeout_ms amberscript command. Example here.

what is OpenCL.DebugInfo.100

It is an SPIR-V extended instruction set used to add rich debug info to a shader, so the original high-level source code can be debugged instead of the SPIR-V. The spec is here.

We're currently in the process of adding support for this into the DXC shader compiler, but this is work in progress, and is not ready for use just yet.

Glad it now works.

how can I change the default value of timeout

You can use the SET ENGINE_DATA fence_timeout_ms amberscript command. Example here.

what is OpenCL.DebugInfo.100

It is an SPIR-V extended instruction set used to add rich debug info to a shader, so the original high-level source code can be debugged instead of the SPIR-V. The spec is here.

We're currently in the process of adding support for this into the DXC shader compiler, but this is work in progress, and is not ready for use just yet.

Many thanks your help, I think I should focus the study of glsl afterwards, I am closing this issue, thanks.