"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/
Python
fix(renderdoc): compute PSO, REPL capture path cache, drop unused imports
alvinshi5e2a01e3797c
diff --git a/renderdoc/agent-harness/cli_anything/renderdoc/core/capture.py b/renderdoc/agent-harness/cli_anything/renderdoc/core/capture.pyindex 6c0098a44..15f2e4c62 100644--- a/renderdoc/agent-harness/cli_anything/renderdoc/core/capture.py+++ b/renderdoc/agent-harness/cli_anything/renderdoc/core/capture.py@@ -12,9 +12,7 @@ Every public function returns plain Python dicts/lists for JSON serialisation.from __future__ import annotationsimport os-import struct-import json-from typing import Any, Dict, List, Optional, Tuple+from typing import Any, Dict, List, Optional# ---------------------------------------------------------------------------# Import renderdoc – gracefully degrade if unavailablediff --git a/renderdoc/agent-harness/cli_anything/renderdoc/core/pipeline.py b/renderdoc/agent-harness/cli_anything/renderdoc/core/pipeline.pyindex f48eadffc..7ecbac475 100644--- a/renderdoc/agent-harness/cli_anything/renderdoc/core/pipeline.py+++ b/renderdoc/agent-harness/cli_anything/renderdoc/core/pipeline.py@@ -171,6 +171,13 @@ def _resolve_stage(stage_name: str):return STAGE_MAP.get(stage_name.lower())+def _pso_for_stage(pipe, stage):+ """PSO handle for DisassembleShader / GetCBufferVariableContents (compute vs graphics)."""+ if HAS_RD and stage == rd.ShaderStage.Compute:+ return pipe.GetComputePipelineObject()+ return pipe.GetGraphicsPipelineObject()++# ---------------------------------------------------------------------------# Rasterizer / Blend / Depth-Stencil state extraction# ---------------------------------------------------------------------------@@ -384,7 +391,7 @@ def get_shader_disasm(if refl is None:return {"error": "No shader bound at stage %s for event %d" % (stage_name, event_id)}- pso = pipe.GetGraphicsPipelineObject()+ pso = _pso_for_stage(pipe, stage)enc_str = _get_encoding_str(refl)enc_info = _get_encoding_info(enc_str)raw = bytes(refl.rawBytes) if refl.rawBytes else b""@@ -597,7 +604,7 @@ def get_cbuffer_contents(if cbuffer_index >= len(refl.constantBlocks):return {"error": f"CBuffer index {cbuffer_index} out of range (max {len(refl.constantBlocks) - 1})"}- pso = pipe.GetGraphicsPipelineObject()+ pso = _pso_for_stage(pipe, stage)entry = pipe.GetShaderEntryPoint(stage)cb = pipe.GetConstantBlock(stage, cbuffer_index, 0)@@ -903,7 +910,7 @@ def export_shader_reflection(if refl is None:return {"error": "No shader bound at stage %s for event %d" % (stage_name, event_id)}- pso = pipe.GetGraphicsPipelineObject()+ pso = _pso_for_stage(pipe, stage)entry = pipe.GetShaderEntryPoint(stage)# Build output directory@@ -1115,7 +1122,6 @@ def dump_pipeline_for_diff(controller, event_id: int) -> Dict[str, Any]:controller.SetFrameEvent(event_id, True)pipe = controller.GetPipelineState()- pso = pipe.GetGraphicsPipelineObject()stage_defs = [("Vertex", rd.ShaderStage.Vertex),@@ -1133,6 +1139,7 @@ def dump_pipeline_for_diff(controller, event_id: int) -> Dict[str, Any]:refl = pipe.GetShaderReflection(stage_enum)if refl is None:continue+ pso = _pso_for_stage(pipe, stage_enum)entry = pipe.GetShaderEntryPoint(stage_enum)cb_bindings = stage_data.get("bindings", {}).get("constantBlocks", [])for cb_entry in cb_bindings:@@ -1165,7 +1172,6 @@ def dump_pipeline(controller, event_id: int) -> Dict[str, Any]:"""controller.SetFrameEvent(event_id, True)pipe = controller.GetPipelineState()- pso = pipe.GetGraphicsPipelineObject()pipeline_type = str(controller.GetAPIProperties().pipelineType)@@ -1301,6 +1307,7 @@ def dump_pipeline(controller, event_id: int) -> Dict[str, Any]:refl = pipe.GetShaderReflection(stage_enum)if refl is None:continue+ pso = _pso_for_stage(pipe, stage_enum)stage_data = {"shader": str(refl.resourceId),"entryPoint": str(refl.entryPoint),diff --git a/renderdoc/agent-harness/cli_anything/renderdoc/renderdoc_cli.py b/renderdoc/agent-harness/cli_anything/renderdoc/renderdoc_cli.pyindex 1309ffaf6..78d787f65 100644--- a/renderdoc/agent-harness/cli_anything/renderdoc/renderdoc_cli.py+++ b/renderdoc/agent-harness/cli_anything/renderdoc/renderdoc_cli.py@@ -31,17 +31,20 @@ import click# ---------------------------------------------------------------------------_capture_handle = None # type: ignore+_capture_handle_path = None # type: ignore_repl_mode = Falsedef _close_all_captures():- global _capture_handle, _capture_handle_b+ global _capture_handle, _capture_handle_b, _capture_handle_path, _capture_handle_b_pathif _capture_handle is not None:_capture_handle.close()_capture_handle = None+ _capture_handle_path = Noneif _capture_handle_b is not None:_capture_handle_b.close()_capture_handle_b = None+ _capture_handle_b_path = Nonedef _get_export_dir(ctx: click.Context, subfolder: str = "") -> str:@@ -62,18 +65,24 @@ def _get_export_dir(ctx: click.Context, subfolder: str = "") -> str:def _get_handle(ctx: click.Context):"""Return the active CaptureHandle, opening it if needed."""- global _capture_handle- if _capture_handle is not None:- return _capture_handle+ global _capture_handle, _capture_handle_pathpath = ctx.obj.get("capture_path")if not path:click.echo("Error: No capture file specified. Use --capture <path>", err=True)ctx.exit(1)+ path_abs = os.path.abspath(path)+ if _capture_handle is not None:+ if _capture_handle_path == path_abs:+ return _capture_handle+ _capture_handle.close()+ _capture_handle = None+ _capture_handle_path = Nonefrom cli_anything.renderdoc.core.capture import CaptureHandlefrom cli_anything.renderdoc.utils.errors import handle_errortry:_capture_handle = CaptureHandle(path)+ _capture_handle_path = path_absexcept Exception as e:debug = ctx.obj.get("debug", False)err = handle_error(e, debug=debug)@@ -694,18 +703,25 @@ def counters_fetch(ctx, ids):# Secondary capture handle for diff B-side_capture_handle_b = None # type: ignore+_capture_handle_b_path = None # type: ignoredef _get_handle_b(ctx: click.Context, path: str):"""Open a second capture file for the B-side of a diff."""- global _capture_handle_b+ global _capture_handle_b, _capture_handle_b_path+ path_abs = os.path.abspath(path)if _capture_handle_b is not None:- return _capture_handle_b+ if _capture_handle_b_path == path_abs:+ return _capture_handle_b+ _capture_handle_b.close()+ _capture_handle_b = None+ _capture_handle_b_path = Nonefrom cli_anything.renderdoc.core.capture import CaptureHandlefrom cli_anything.renderdoc.utils.errors import handle_errortry:_capture_handle_b = CaptureHandle(path)+ _capture_handle_b_path = path_absexcept Exception as e:debug = ctx.obj.get("debug", False)err = handle_error(e, debug=debug)