diff --git a/docs/imgs/icons/filter.png b/docs/imgs/icons/filter.png new file mode 100644 index 00000000000..227e8436ca3 Binary files /dev/null and b/docs/imgs/icons/filter.png differ diff --git a/docs/window/buffer_viewer.rst b/docs/window/buffer_viewer.rst index 259e9e5db06..1fc0a32abfe 100644 --- a/docs/window/buffer_viewer.rst +++ b/docs/window/buffer_viewer.rst @@ -9,7 +9,7 @@ When opening a buffer for view, it can display both fixed non-repeating "struct- The format is defined initially by whatever reflection data is available. The format can be customised, as detailed in :doc:`../how/how_buffer_format`. -Constant buffers are assumed to be AoS data in all cases. Other views of buffers via non-constant bindings such as UAVs and storage buffers, or views opened directly from a buffer from the resource inspector, will default towards SoA data unless the layout explicitly declares a fixed set of SoA data. +Constant buffers are assumed to be SoA data in all cases. Other views of buffers via non-constant bindings such as UAVs and storage buffers, or views opened directly from a buffer from the resource inspector, will default towards AoS data unless the layout explicitly declares a fixed set of SoA data. .. figure:: ../imgs/Screenshots/AOSBuffer.png @@ -28,6 +28,15 @@ The initial values of the offset and length will be taken from the relevant bind In addition to this, you can specify a row offset which is useful in remaining at the same row while watching the change in a buffer between different events. +Filtering in constant buffer view +--------------------------------- + +.. |filter| image:: ../imgs/icons/filter.png + +When viewing a constant buffer and it is known that the data is only a small set of fixed data, an additional |filter| option is available. + +This will add a filtering toolbar that allows a subset of the variables to be shown. The filter is a set of words, space separated, that by default match case insensitively against variables in the declared structure. Any variable that matches any of the words will be displayed. If the name of a structure is matched, all children of that structure will be displayed. + Exporting and display --------------------- diff --git a/qrenderdoc/Code/Interface/QRDInterface.h b/qrenderdoc/Code/Interface/QRDInterface.h index 6b853a47436..920615f2e38 100644 --- a/qrenderdoc/Code/Interface/QRDInterface.h +++ b/qrenderdoc/Code/Interface/QRDInterface.h @@ -2111,42 +2111,32 @@ If no tag is present, the callback will be processed as normal. // Returns false when capture access is unavailable, or an async request has // no running worker. Synchronous access also works before replay starts. // - // Hidden from swig: Python uses a force-blocking capture-access invoker. + // this is hidden from swig as for python the threading is less controlled there so we wrap the + // ICaptureAccess with a force-blocking invoker + virtual bool AccessInvoke(std::function callback, bool blocking, + bool forceReplay, rdcstr tag) = 0; + + // Capture operations can use a replay-worker tag for progress reporting. bool AccessInvoke(std::function callback, bool blocking, rdcstr tag) { - if(!GetCaptureAccess()) - return false; - - auto invoke = [this, callback](IReplayController *) { - if(ICaptureAccess *access = GetCaptureAccess()) - callback(access); - }; - - if(!blocking) - { - if(!IsRunning()) - return false; - AsyncInvoke(invoke, tag); - } - else if(CurrentRemote().IsConnected() && IsRunning()) - { - BlockInvoke(invoke); - } - else - { - // GPU enumeration must also work before a remote capture starts a worker. - callback(GetCaptureAccess()); - } - - return true; + return AccessInvoke(callback, blocking, !blocking, tag); } + + // simple blocking access bool BlockAccessInvoke(std::function callback) { - return AccessInvoke(callback, true, ""); + return AccessInvoke(callback, true, false, ""); } + // Asynchronous access on the replay worker. bool AsyncAccessInvoke(std::function callback) { - return AccessInvoke(callback, false, ""); + return AccessInvoke(callback, false, false, ""); + } + // async access, will always be on the replay thread even locally so the UI thread can e.g. + // display a progress spinner + bool SlowAsyncAccessInvoke(std::function callback) + { + return AccessInvoke(callback, false, true, ""); } #endif diff --git a/qrenderdoc/Code/ReplayManager.cpp b/qrenderdoc/Code/ReplayManager.cpp index 0397ab0f8eb..71252eccfad 100644 --- a/qrenderdoc/Code/ReplayManager.cpp +++ b/qrenderdoc/Code/ReplayManager.cpp @@ -303,6 +303,36 @@ void ReplayManager::BlockInvoke(ReplayManager::ReplayInvokeCallback m) delete cmd; } +bool ReplayManager::AccessInvoke(std::function callback, bool blocking, + bool forceReplay, rdcstr tag) +{ + if(!GetCaptureAccess()) + return false; + + auto invoke = [this, callback](IReplayController *) { + if(ICaptureAccess *access = GetCaptureAccess()) + callback(access); + }; + + if(!blocking) + { + if(!IsRunning()) + return false; + AsyncInvoke(invoke, tag); + } + else if((CurrentRemote().IsConnected() || forceReplay) && IsRunning()) + { + BlockInvoke(invoke); + } + else + { + // Synchronous queries such as GPU enumeration also run before replay starts. + callback(GetCaptureAccess()); + } + + return true; +} + void ReplayManager::CancelReplayLoop() { m_Renderer->CancelReplayLoop(); diff --git a/qrenderdoc/Code/ReplayManager.h b/qrenderdoc/Code/ReplayManager.h index d2582007495..ccb6367cece 100644 --- a/qrenderdoc/Code/ReplayManager.h +++ b/qrenderdoc/Code/ReplayManager.h @@ -69,6 +69,9 @@ class ReplayManager : public IReplayManager using IReplayManager::AsyncInvoke; void BlockInvoke(ReplayInvokeCallback m); + bool AccessInvoke(std::function callback, bool blocking, bool forceReplay, + rdcstr tag); + void CancelReplayLoop(); void CloseThread(); diff --git a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp index 4ec20db8af9..d1303d34315 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp +++ b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp @@ -1767,14 +1767,16 @@ QWidget *PythonContext::QWidgetFromPy(PyObject *widget) void PythonContext::reflectSource(QString src) { - if(!m_Reflector) + if(m_DeferredInit == 0) { for(int i = 0; i < 50 && m_DeferredInit == 0; i++) QThread::msleep(20); - m_DeferredInit = 1; if(!m_Reflector) + { + m_DeferredInit = 1; return; + } } PyGILState_STATE gil = PyGILState_Ensure(); @@ -1799,15 +1801,16 @@ void PythonContext::reflectSource(QString src) void PythonContext::makeHelpContext() { // expand out members of renderdoc and qrenderdoc using the stubs - if(!m_StubRD || !m_StubQRD) + if(m_DeferredInit == 0) { for(int i = 0; i < 50 && m_DeferredInit == 0; i++) QThread::msleep(20); - m_DeferredInit = 1; - if(!m_StubRD || !m_StubQRD) + { + m_DeferredInit = 1; return; + } } PyGILState_STATE gil = PyGILState_Ensure(); diff --git a/qrenderdoc/Code/pyrenderdoc/PythonInvokers.cpp b/qrenderdoc/Code/pyrenderdoc/PythonInvokers.cpp index 58541e7d5ef..a77bee8b28b 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonInvokers.cpp +++ b/qrenderdoc/Code/pyrenderdoc/PythonInvokers.cpp @@ -1043,6 +1043,13 @@ struct ReplayInvoker : IReplayManager } void BlockInvoke(ReplayInvokeCallback method) { return m_Replay.BlockInvoke(method); } + + // won't be available to python but we implement this for compile time matching + bool AccessInvoke(std::function callback, bool blocking, bool forceReplay, + rdcstr tag) + { + return m_Replay.AccessInvoke(callback, blocking, forceReplay, tag); + } }; struct IMainWindowInvoker : UIThreadInvoker diff --git a/qrenderdoc/Widgets/Extended/RDTreeView.cpp b/qrenderdoc/Widgets/Extended/RDTreeView.cpp index 5185e30cf18..bf252694787 100644 --- a/qrenderdoc/Widgets/Extended/RDTreeView.cpp +++ b/qrenderdoc/Widgets/Extended/RDTreeView.cpp @@ -454,6 +454,52 @@ void RDTreeView::applyExpansion(const RDTreeViewExpansionState &state, const Exp applyExpansionToRow(state, model()->index(i, 0), 0, keygen); } +RDTreeViewSelectedItemState RDTreeView::saveSelectedItemState() +{ + RDTreeViewSelectedItemState ret; + QModelIndexList sel = selectionModel()->selectedIndexes(); + if(!sel.empty()) + { + QModelIndex i = sel[0].sibling(sel[0].row(), 0); + while(i.isValid()) + { + ret.insert(0, qHash(i.data(Qt::DisplayRole).toString())); + i = i.parent(); + } + } + + return ret; +} + +void RDTreeView::applySelectedItemState(RDTreeViewSelectedItemState state) +{ + QModelIndex cur; + + for(int i = 0; i < state.count(); i++) + { + bool found = false; + + for(int row = 0, count = model()->rowCount(cur); row < count; row++) + { + QModelIndex check = model()->index(row, 0, cur); + if(qHash(model()->data(check).toString()) == state[i]) + { + found = true; + cur = check; + break; + } + } + + if(!found) + return; + } + + QItemSelection sel(cur, cur.sibling(cur.row(), model()->columnCount() - 1)); + + scrollTo(cur); + selectionModel()->select(sel, QItemSelectionModel::ClearAndSelect); +} + void RDTreeView::copySelection() { QModelIndexList sel = selectionModel()->selectedRows(); diff --git a/qrenderdoc/Widgets/Extended/RDTreeView.h b/qrenderdoc/Widgets/Extended/RDTreeView.h index b8cadc8c844..0fa3dac4a75 100644 --- a/qrenderdoc/Widgets/Extended/RDTreeView.h +++ b/qrenderdoc/Widgets/Extended/RDTreeView.h @@ -33,6 +33,7 @@ class RDTreeView; typedef QSet RDTreeViewExpansionState; +typedef QList RDTreeViewSelectedItemState; class RDTreeViewDelegate : public RichTextViewDelegate { @@ -129,6 +130,9 @@ class RDTreeView : public QTreeView }); } + RDTreeViewSelectedItemState saveSelectedItemState(); + void applySelectedItemState(RDTreeViewSelectedItemState state); + // Internally tracked expansions RDTreeViewExpansionState &getInternalExpansion(uint expansionID) { diff --git a/qrenderdoc/Widgets/PixelDebugSelector.cpp b/qrenderdoc/Widgets/PixelDebugSelector.cpp new file mode 100644 index 00000000000..3c2f2918826 --- /dev/null +++ b/qrenderdoc/Widgets/PixelDebugSelector.cpp @@ -0,0 +1,105 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2021-2026 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * 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 Software. + * + * THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "PixelDebugSelector.h" +#include "Code/QRDUtils.h" +#include "ui_PixelDebugSelector.h" + +PixelDebugSelector::PixelDebugSelector(ICaptureContext &ctx, QWidget *parent) + : QDialog(parent), ui(new Ui::PixelDebugSelector), m_Ctx(ctx) +{ + ui->setupUi(this); + + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + + ui->x->setFont(Formatter::PreferredFont()); + ui->y->setFont(Formatter::PreferredFont()); + ui->primitive->setFont(Formatter::PreferredFont()); + ui->sample->setFont(Formatter::PreferredFont()); + ui->view->setFont(Formatter::PreferredFont()); +} + +PixelDebugSelector::~PixelDebugSelector() +{ + delete ui; +} + +void PixelDebugSelector::UpdateTarget() +{ + const ActionDescription *action = m_Ctx.CurAction(); + + if(!action) + return; + + const PipeState &pipe = m_Ctx.CurPipelineState(); + + ui->view->setMaximum(pipe.MultiviewBroadcastCount() - 1); + ui->viewLabel->setVisible(ui->view->maximum() > 1); + ui->view->setVisible(ui->view->maximum() > 1); + + uint32_t sampleCount = pipe.GetOverrideSampleCount(); + + if(sampleCount == 0) + { + for(const Descriptor &d : pipe.GetOutputTargets()) + { + const TextureDescription *tex = m_Ctx.GetTexture(d.resource); + if(tex) + sampleCount = qMax(sampleCount, tex->msSamp); + } + } + + ui->sample->setMaximum(pipe.GetOverrideSampleCount() - 1); + ui->sampleLabel->setVisible(ui->sample->maximum() > 1); + ui->sample->setVisible(ui->sample->maximum() > 1); +} + +void PixelDebugSelector::on_selectedPixel_clicked() +{ + rdcpair sel = m_Ctx.GetTextureViewer()->GetPickedLocation(); + + ui->x->setValue(sel.first); + ui->y->setValue(sel.second); +} + +void PixelDebugSelector::on_beginDebug_clicked() +{ + DebugPixelInputs inputs; + + bool ok = false; + inputs.primitive = ui->primitive->text().toUInt(&ok); + if(!ok) + inputs.primitive = ~0U; + + inputs.sample = ui->sample->value(); + inputs.view = ui->view->value(); + + emit beginDebug(ui->x->value(), ui->y->value(), inputs); + close(); +} + +void PixelDebugSelector::on_cancelDebug_clicked() +{ + close(); +} diff --git a/qrenderdoc/Widgets/PixelDebugSelector.h b/qrenderdoc/Widgets/PixelDebugSelector.h new file mode 100644 index 00000000000..036be63781b --- /dev/null +++ b/qrenderdoc/Widgets/PixelDebugSelector.h @@ -0,0 +1,63 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2021-2026 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * 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 Software. + * + * THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#pragma once + +#include +#include "Code/Interface/QRDInterface.h" + +namespace Ui +{ +class PixelDebugSelector; +} + +class PixelDebugSelector : public QDialog +{ + Q_OBJECT + +public: + explicit PixelDebugSelector(ICaptureContext &ctx, QWidget *parent = 0); + ~PixelDebugSelector(); + + void UpdateTarget(); + +public slots: + +signals: + void beginDebug(uint32_t x, uint32_t y, const DebugPixelInputs &inputs); + +private slots: + // automatic slots + void on_selectedPixel_clicked(); + void on_beginDebug_clicked(); + void on_cancelDebug_clicked(); + +private: + void SyncGroupThreadValue(); + void SyncDispatchThreadValue(); + + Ui::PixelDebugSelector *ui; + + ICaptureContext &m_Ctx; +}; diff --git a/qrenderdoc/Widgets/PixelDebugSelector.ui b/qrenderdoc/Widgets/PixelDebugSelector.ui new file mode 100644 index 00000000000..9ead7c760fb --- /dev/null +++ b/qrenderdoc/Widgets/PixelDebugSelector.ui @@ -0,0 +1,164 @@ + + + PixelDebugSelector + + + Qt::ApplicationModal + + + + 0 + 0 + 176 + 274 + + + + + 0 + 0 + + + + Debug Pixel Shader + + + false + + + true + + + + QLayout::SetFixedSize + + + + + Pixel co-ordinate + + + + 3 + + + + + X: + + + + + + + 16384 + + + + + + + Y: + + + + + + + 16384 + + + + + + + Use Selected Pixel + + + + :/wand.png:/wand.png + + + + + + + + + + Disambiguation + + + + + + Primitive: + + + + + + + + + + + + + Sample: + + + + + + + Multiview: + + + + + + + Any + + + + + + + + + + + + Debug + + + + :/wrench.png:/wrench.png + + + + + + + Cancel + + + + + + + + + + RDLineEdit + QLineEdit +
Widgets/Extended/RDLineEdit.h
+
+
+ + + + +
diff --git a/qrenderdoc/Windows/APIInspector.cpp b/qrenderdoc/Windows/APIInspector.cpp index 9df833c35bd..fe2b93ad183 100644 --- a/qrenderdoc/Windows/APIInspector.cpp +++ b/qrenderdoc/Windows/APIInspector.cpp @@ -180,17 +180,24 @@ void APIInspector::on_apiEvents_itemSelectionChanged() if(chunk && !chunk->metadata.callstack.isEmpty()) { + ui->callstack->setUpdatesEnabled(false); + ui->callstack->clear(); + ui->callstack->addItem(tr("Loading...")); + if(!m_Ctx.Replay().AsyncAccessInvoke([this, chunk](ICaptureAccess *access) { rdcarray stack = access->GetResolve(chunk->metadata.callstack); GUIInvoke::call(this, [this, stack]() { addCallstack(stack); }); })) { - ui->callstack->setUpdatesEnabled(false); ui->callstack->clear(); ui->callstack->addItem(tr("Callstack resolution not available.")); ui->callstack->setUpdatesEnabled(true); } + else + { + ui->callstack->setUpdatesEnabled(true); + } } else { diff --git a/qrenderdoc/Windows/BufferViewer.cpp b/qrenderdoc/Windows/BufferViewer.cpp index bbb7ecc262e..df621684f35 100644 --- a/qrenderdoc/Windows/BufferViewer.cpp +++ b/qrenderdoc/Windows/BufferViewer.cpp @@ -41,6 +41,7 @@ #include "Widgets/CollapseGroupBox.h" #include "Widgets/ComputeDebugSelector.h" #include "Widgets/Extended/RDLabel.h" +#include "Widgets/Extended/RDLineEdit.h" #include "Widgets/Extended/RDSplitter.h" #include "Windows/Dialogs/AxisMappingDialog.h" #include "Windows/Dialogs/CameraControlsDialog.h" @@ -1875,8 +1876,18 @@ static void ConfigureColumnsForVertexPipe(ICaptureContext &ctx, PopulateBufferDa // for a non-indexed draw, we take the largest vertex buffer rdcarray VBs = ctx.CurPipelineState().GetVBuffers(); - for(const BoundVBuffer &vb : VBs) + rdcarray usedVBs; + + for(const VertexInputAttribute &attr : ctx.CurPipelineState().GetVertexInputs()) + usedVBs.push_back(attr.vertexBuffer); + + for(int i = 0; i < VBs.count(); i++) { + if(!usedVBs.contains(i)) + continue; + + const BoundVBuffer &vb = VBs[i]; + if(vb.byteStride == 0) continue; @@ -2619,6 +2630,33 @@ BufferViewer::BufferViewer(ICaptureContext &ctx, bool meshview, QWidget *parent) ui->setFormat->setVisible(false); + QObject::connect(ui->fixedVars, &RDTreeWidget::keyPress, [this](QKeyEvent *ev) { + if(!IsCBufferView()) + return; + + if((ev->modifiers() & Qt::ControlModifier) && ev->key() == Qt::Key_F) + { + ui->filterCBuffer->setChecked(true); + } + }); + + ui->filterStrip->setVisible(false); + + QObject::connect(ui->filterExpression, &RDLineEdit::keyPress, [this](QKeyEvent *event) { + if(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) + OnEventChanged(m_Ctx.CurEvent()); + if(event->key() == Qt::Key_Escape) + ui->filterCBuffer->setChecked(false); + }); + + m_FilterTimeout = new QTimer(this); + m_FilterTimeout->setInterval(600); + m_FilterTimeout->setSingleShot(true); + connect(m_FilterTimeout, &QTimer::timeout, [this]() { OnEventChanged(m_Ctx.CurEvent()); }); + + QObject::connect(ui->filterExpression, &RDLineEdit::textChanged, + [this](const QString &) { m_FilterTimeout->start(); }); + ui->controlType->setCurrentIndex(0); on_controlType_currentIndexChanged(0); @@ -2821,7 +2859,17 @@ void BufferViewer::SetupRawView() m_InnerSplitter->addWidget(m_FixedGroup); m_InnerSplitter->addWidget(m_RepeatedGroup); - m_VLayout->addWidget(ui->meshToolbar); + QFrame *meshToolbar = new QFrame(this); + meshToolbar->setFrameShape(QFrame::Panel); + meshToolbar->setFrameShadow(QFrame::Plain); + + QVBoxLayout *meshToolbarLayout = new QVBoxLayout(meshToolbar); + meshToolbarLayout->setSpacing(2); + meshToolbarLayout->setContentsMargins(0, 0, 0, 0); + meshToolbarLayout->addWidget(ui->mainMeshToolbar); + meshToolbarLayout->addWidget(ui->filterStrip); + + m_VLayout->addWidget(meshToolbar); // 0 will be variable, but set it to something here so QSplitter doesn't barf m_OuterSplitter->insertWidget(0, ui->inTable); m_OuterSplitter->insertWidget(1, ui->formatSpecifier); @@ -2965,12 +3013,22 @@ void BufferViewer::SetupMeshView() QObject::connect(ui->out2Table->horizontalHeader(), &QHeaderView::customContextMenuRequested, [this](const QPoint &pos) { meshHeaderMenu(MeshDataStage::GSOut, pos); }); + QFrame *meshToolbar = new QFrame(this); + meshToolbar->setFrameShape(QFrame::Panel); + meshToolbar->setFrameShadow(QFrame::Plain); + + QVBoxLayout *meshToolbarLayout = new QVBoxLayout(meshToolbar); + meshToolbarLayout->setSpacing(2); + meshToolbarLayout->setContentsMargins(0, 0, 0, 0); + meshToolbarLayout->addWidget(ui->mainMeshToolbar); + meshToolbarLayout->addWidget(ui->filterStrip); + QVBoxLayout *vertical = new QVBoxLayout(this); vertical->setSpacing(3); vertical->setContentsMargins(3, 3, 3, 3); - vertical->addWidget(ui->meshToolbar); + vertical->addWidget(meshToolbar); vertical->addWidget(ui->dockarea); QTimer *renderTimer = new QTimer(this); @@ -3268,6 +3326,8 @@ BufferViewer::~BufferViewer() m_Ctx.Replay().BlockInvoke([this](IReplayController *r) { m_Output->Shutdown(); }); } + delete m_Scrolls; + delete m_Arcball; delete m_Flycam; @@ -3525,6 +3585,12 @@ void BufferViewer::OnEventChanged(uint32_t eventId) ui->viewIndex->setValue(0); } + // no data to fetch if we don't have a buffer yet. This happens when BufferViewer() is created + // because the capture viewer being registered automatically calls OnEventChanged but we haven't + // had ViewBuffer() etc yet + if(!m_MeshView && m_BufferID == ResourceId() && (!bufdata->cb.valid || bufdata->cb.bytesBacked)) + return; + QPointer me(this); m_Ctx.Replay().AsyncInvoke([this, me, bufdata](IReplayController *r) { @@ -3744,7 +3810,6 @@ void BufferViewer::OnEventChanged(uint32_t eventId) if(!me) { - delete buf; delete bufdata; return; } @@ -3964,6 +4029,8 @@ void BufferViewer::OnEventChanged(uint32_t eventId) RDTreeViewExpansionState state; ui->fixedVars->saveExpansion(state, 0); + RDTreeViewSelectedItemState selItemState = ui->fixedVars->saveSelectedItemState(); + ui->fixedVars->beginUpdate(); ui->fixedVars->clear(); @@ -3971,7 +4038,7 @@ void BufferViewer::OnEventChanged(uint32_t eventId) if(!vars.isEmpty()) { UI_AddFixedVariables(ui->fixedVars->invisibleRootItem(), 0, - bufdata->inConfig.fixedVars.type.members, vars); + bufdata->inConfig.fixedVars.type.members, vars, false); if(IsCBufferView() && !bufdata->cb.bytesBacked) UI_RemoveOffsets(ui->fixedVars->invisibleRootItem()); @@ -3996,6 +4063,8 @@ void BufferViewer::OnEventChanged(uint32_t eventId) ui->fixedVars->getInternalExpansion(qHash(ToQStr(m_CurCBuffer.shader))), 0); else ui->fixedVars->applyExpansion(state, 0); + + ui->fixedVars->applySelectedItemState(selItemState); } on_rowOffset_valueChanged(ui->rowOffset->value()); @@ -4275,11 +4344,19 @@ void BufferViewer::UI_AddTaskPayloads(RDTreeWidgetItem *root, size_t baseOffset, } } -void BufferViewer::UI_AddFixedVariables(RDTreeWidgetItem *root, uint32_t baseOffset, +bool BufferViewer::UI_AddFixedVariables(RDTreeWidgetItem *root, uint32_t baseOffset, const rdcarray &consts, - const rdcarray &vars) + const rdcarray &vars, bool ignoreFilter) { + bool ret = false; + + Qt::CaseSensitivity filterCase = + ui->filterCaseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive; + const bool showPadding = ui->showPadding->isChecked() && m_CurCBuffer.bytesBacked; + const QString filterExpression = ignoreFilter ? QString() : ui->filterExpression->text(); + const QStringList filterWords = + filterExpression.split(QRegularExpression(lit("\\s+")), QString::SkipEmptyParts); if(consts.size() != vars.size()) qCritical() << "Shader variable mismatch"; @@ -4291,7 +4368,7 @@ void BufferViewer::UI_AddFixedVariables(RDTreeWidgetItem *root, uint32_t baseOff const ShaderConstant &c = consts[idx]; const ShaderVariable &v = vars[idx]; - if(showPadding && c.byteOffset > offset) + if(showPadding && c.byteOffset > offset && filterWords.isEmpty()) { uint32_t size = c.byteOffset - offset; @@ -4306,6 +4383,7 @@ void BufferViewer::UI_AddFixedVariables(RDTreeWidgetItem *root, uint32_t baseOff pad->setTag(QVariant::fromValue(FixedVarTag(size))); root->addChild(pad); + ret = true; offset = c.byteOffset; } @@ -4348,10 +4426,18 @@ void BufferViewer::UI_AddFixedVariables(RDTreeWidgetItem *root, uint32_t baseOff n->setTag(QVariant::fromValue(FixedVarTag(v.name, baseOffset + c.byteOffset))); - root->addChild(n); - UI_FixedAddMatrixRows(n, c, v); + bool anyPassFilter = filterWords.empty(); + QString filterName = v.name; + for(QString filter : filterWords) + { + if(filterName.contains(filter, filterCase)) + anyPassFilter = true; + } + + const bool rootPassFilter = anyPassFilter; + // if it's an array the value (v) will be expanded with one element in each of v.members, but // the constant (c) will just have the type with a number of elements if(c.type.elements > 1) @@ -4380,7 +4466,9 @@ void BufferViewer::UI_AddFixedVariables(RDTreeWidgetItem *root, uint32_t baseOff // because v.members[...].members will be the actual struct members because of the expansion if(c.type.baseType == VarType::Struct) { - UI_AddFixedVariables(el, elOffset, c.type.members, v.members[e].members); + if(UI_AddFixedVariables(el, elOffset, c.type.members, v.members[e].members, + rootPassFilter || ignoreFilter)) + anyPassFilter = true; } else { @@ -4396,7 +4484,7 @@ void BufferViewer::UI_AddFixedVariables(RDTreeWidgetItem *root, uint32_t baseOff if(c.type.baseType == VarType::Struct && e + 1 == v.members.size()) break; - if(showPadding && c.type.arrayByteStride > elSize) + if(showPadding && c.type.arrayByteStride > elSize && filterWords.isEmpty()) { uint32_t size = c.type.arrayByteStride - elSize; @@ -4417,12 +4505,23 @@ void BufferViewer::UI_AddFixedVariables(RDTreeWidgetItem *root, uint32_t baseOff // for single structs, recurse else if(v.type == VarType::Struct) { - UI_AddFixedVariables(n, c.byteOffset, c.type.members, v.members); + if(UI_AddFixedVariables(n, c.byteOffset, c.type.members, v.members, + rootPassFilter || ignoreFilter)) + anyPassFilter = true; } + ret = ret || anyPassFilter; + + if(anyPassFilter) + root->addChild(n); + else + delete n; + // advance by the tight scalar-packed advance, so we can detect padding offset += BufferFormatter::GetVarAdvance(PackingRules::Scalar(), c); } + + return ret; } void BufferViewer::UI_RemoveOffsets(RDTreeWidgetItem *root) @@ -5454,6 +5553,8 @@ void BufferViewer::updateLabelsAndLayout() { setWindowTitle(tr("Mesh Viewer")); + ui->filterCBuffer->setVisible(false); + if(m_Ctx.IsCaptureLoaded()) { GraphicsAPI pipeType = m_Ctx.APIProps().pipelineType; @@ -5592,10 +5693,14 @@ void BufferViewer::updateLabelsAndLayout() title += QFormatStr(" - %1").arg(bufName); + ui->filterCBuffer->setVisible(true); + setWindowTitle(title); } else { + ui->filterCBuffer->setVisible(false); + setWindowTitle(m_Ctx.GetResourceName(m_BufferID) + lit(" - Contents")); } } @@ -6161,6 +6266,30 @@ void BufferViewer::on_setFormat_toggled(bool checked) reflection->constantBlocks[m_CBufferSlot.slot].variables, 0)); } +void BufferViewer::on_filterCBuffer_toggled(bool checked) +{ + if(!checked) + { + ui->filterExpression->setText(QString()); + ui->filterStrip->setVisible(false); + } + else + { + ui->filterStrip->setVisible(true); + ui->filterExpression->setFocus(Qt::OtherFocusReason); + } + + if(m_FilterTimeout->isActive()) + m_FilterTimeout->stop(); + + OnEventChanged(m_Ctx.CurEvent()); +} + +void BufferViewer::on_filterCaseSensitive_toggled(bool checked) +{ + OnEventChanged(m_Ctx.CurEvent()); +} + void BufferViewer::on_resetMeshFilterButton_clicked() { SetMeshFilter(MeshFilter::None); @@ -6250,9 +6379,9 @@ void BufferViewer::processFormat(const QString &format) ui->rowOffsetLabel->setVisible(true); ui->rowOffset->setVisible(true); // insert after the offsetLine - if(ui->rowOffset->parentWidget() != ui->meshToolbar) + if(ui->rowOffset->parentWidget() != ui->mainMeshToolbar) { - QHBoxLayout *hbox = qobject_cast(ui->meshToolbar->layout()); + QHBoxLayout *hbox = qobject_cast(ui->mainMeshToolbar->layout()); int i = 0; for(; i < hbox->count(); i++) @@ -6303,14 +6432,22 @@ void BufferViewer::processFormat(const QString &format) { qulonglong stride = qMax(1U, parsed.repeating.type.arrayByteStride); - byteRangeStart->setSingleStep(stride); - byteRangeLength->setSingleStep(stride); + m_PagingByteOffset = 0; + + // normally these would call into processFormat() again if the user updated them, we don't want to do that + { + QSignalBlocker block1(byteRangeStart); + QSignalBlocker block2(byteRangeLength); - byteRangeStart->setMaximum((qulonglong)m_ObjectByteSize); - byteRangeLength->setMaximum((qulonglong)m_ObjectByteSize); + byteRangeStart->setSingleStep(stride); + byteRangeLength->setSingleStep(stride); - byteRangeStart->setValue(m_ByteOffset); - byteRangeLength->setValue(m_ByteSize); + byteRangeStart->setMaximum((qulonglong)m_ObjectByteSize); + byteRangeLength->setMaximum((qulonglong)m_ObjectByteSize); + + byteRangeStart->setValue(m_ByteOffset); + byteRangeLength->setValue(m_ByteSize); + } if(!m_IsBuffer) { @@ -7324,6 +7461,9 @@ void BufferViewer::on_viewIndex_valueChanged(int value) void BufferViewer::SetMeshFilter(MeshFilter filter, uint32_t taskGroup, uint32_t meshGroup) { + if(!isMeshDraw() || m_CurMeshFilter == filter) + return; + // calculate new scrolls manually to keep the same logical item selected m_Scrolls = new PopulateBufferData; FillScrolls(m_Scrolls); diff --git a/qrenderdoc/Windows/BufferViewer.h b/qrenderdoc/Windows/BufferViewer.h index 1f97e27d3d6..e7c30560fd6 100644 --- a/qrenderdoc/Windows/BufferViewer.h +++ b/qrenderdoc/Windows/BufferViewer.h @@ -40,6 +40,7 @@ class RDSpinBox64; class QItemSelection; class QMenu; class QPushButton; +class QTimer; class QVBoxLayout; class RDLabel; class RDTableView; @@ -146,6 +147,8 @@ private slots: void on_axisMappingCombo_currentIndexChanged(int index); void on_axisMappingButton_clicked(); void on_setFormat_toggled(bool checked); + void on_filterCBuffer_toggled(bool checked); + void on_filterCaseSensitive_toggled(bool checked); void on_resetMeshFilterButton_clicked(); void on_camParameters_clicked(); void on_guessButton_clicked(); @@ -213,9 +216,9 @@ private slots: void UI_AddTaskPayloads(RDTreeWidgetItem *root, size_t baseOffset, const rdcarray &consts, BufferData *buffer); - void UI_AddFixedVariables(RDTreeWidgetItem *root, uint32_t baseOffset, + bool UI_AddFixedVariables(RDTreeWidgetItem *root, uint32_t baseOffset, const rdcarray &consts, - const rdcarray &vars); + const rdcarray &vars, bool ignoreFilter); void UI_RemoveOffsets(RDTreeWidgetItem *root); void UI_FixedAddMatrixRows(RDTreeWidgetItem *n, const ShaderConstant &c, const ShaderVariable &v); @@ -339,6 +342,8 @@ private slots: QAction *m_RemoveFilter = NULL; QAction *m_GotoTask = NULL; + QTimer *m_FilterTimeout = NULL; + RDSpinBox64 *byteRangeStart = NULL; RDSpinBox64 *byteRangeLength = NULL; diff --git a/qrenderdoc/Windows/BufferViewer.ui b/qrenderdoc/Windows/BufferViewer.ui index 46de460fdff..ab3d98a62cf 100644 --- a/qrenderdoc/Windows/BufferViewer.ui +++ b/qrenderdoc/Windows/BufferViewer.ui @@ -545,7 +545,7 @@ 0 0 - 267 + 257 321 @@ -795,12 +795,87 @@ false - + + + + 700 + 50 + 223 + 24 + + + + + 3 + + + 6 + + + 0 + + + 6 + + + 2 + + + + + + + + :/filter.png + + + + + + + Filter + + + Qt::PlainText + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 0 + + + + + + + + + + Filter with case-sensitivity + + + Aa + + + true + + + Qt::ToolButtonTextOnly + + + true + + + + + + 0 10 - 767 + 1137 28 @@ -816,12 +891,6 @@ 28 - - QFrame::Panel - - - QFrame::Raised - 2 @@ -946,6 +1015,29 @@ + + + + Filter constants by name + + + + + + + :/filter.png:/filter.png + + + true + + + Qt::ToolButtonIconOnly + + + true + + + @@ -1154,6 +1246,11 @@
Widgets/BufferFormatSpecifier.h
1 + + RDLineEdit + QLineEdit +
Widgets/Extended/RDLineEdit.h
+
diff --git a/qrenderdoc/Windows/EventBrowser.cpp b/qrenderdoc/Windows/EventBrowser.cpp index 5bdc0b954bb..1dc621ec37e 100644 --- a/qrenderdoc/Windows/EventBrowser.cpp +++ b/qrenderdoc/Windows/EventBrowser.cpp @@ -4016,6 +4016,7 @@ EventBrowser::EventBrowser(ICaptureContext &ctx, QWidget *parent) ui->bookmarkStrip->hide(); m_BookmarkStripLayout = new FlowLayout(ui->bookmarkStrip, 0, 3, 3); + m_BookmarkStripLayout->setContentsMargins(6, 0, 6, 2); m_BookmarkSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); ui->bookmarkStrip->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); @@ -4024,9 +4025,9 @@ EventBrowser::EventBrowser(ICaptureContext &ctx, QWidget *parent) { QHBoxLayout *box = new QHBoxLayout(ui->breadcrumbStrip); - box->setContentsMargins(QMargins(0, 0, 0, 0)); box->setMargin(0); box->setSpacing(0); + box->setContentsMargins(QMargins(0, 0, 6, 2)); m_Breadcrumbs = new MarkerBreadcrumbs(m_Ctx, this, this); box->addWidget(m_Breadcrumbs); @@ -4266,6 +4267,8 @@ void EventBrowser::OnCaptureLoaded() ui->exportActions->setEnabled(true); ui->stepPrev->setEnabled(true); ui->stepNext->setEnabled(true); + + updateStepNextPrevButtonState(); } void EventBrowser::OnCaptureClosed() @@ -4359,21 +4362,7 @@ void EventBrowser::events_currentChanged(const QModelIndex ¤t, const QMode m_Model->RefreshCache(); m_Breadcrumbs->OnEventChanged(effectiveEID); - const ActionDescription *action = m_Ctx.GetAction(selectedEID); - - if(action && action->IsFakeMarker()) - action = &action->children.back(); - - ui->stepPrev->setEnabled(action && action->previousAction); - ui->stepNext->setEnabled(action && action->nextAction); - - // special case for the first action in the frame - if(selectedEID == 0) - ui->stepNext->setEnabled(true); - - // special case for the first 'virtual' action at EID 0 - if(m_Ctx.GetFirstAction() && selectedEID == m_Ctx.GetFirstAction()->eventId) - ui->stepPrev->setEnabled(true); + updateStepNextPrevButtonState(); highlightBookmarks(); } @@ -5527,9 +5516,24 @@ void EventBrowser::on_stepNext_clicked() if(!m_Ctx.IsCaptureLoaded() || !ui->stepNext->isEnabled()) return; + const ActionDescription *action = NULL; + uint32_t selectedEID = 0; QModelIndex idx = ui->events->currentIndex(); - uint32_t selectedEID = GetSelectedEID(idx); - const ActionDescription *action = m_Ctx.GetAction(selectedEID); + if(idx.isValid()) + { + selectedEID = GetSelectedEID(idx); + action = m_Ctx.GetAction(selectedEID); + } + else + { + // No selected action use the current action + if(!action) + action = m_Ctx.CurAction(); + } + + // special case for the first 'virtual' action at EID 0 + if(m_Ctx.CurEvent() == 0) + action = m_Ctx.GetFirstAction(); if(action) { @@ -5539,8 +5543,7 @@ void EventBrowser::on_stepNext_clicked() action = action->nextAction; } - // special case for the first 'virtual' action at EID 0 - if(m_Ctx.CurEvent() == 0) + if(selectedEID == 0) action = m_Ctx.GetFirstAction(); while(action) @@ -5553,8 +5556,6 @@ void EventBrowser::on_stepNext_clicked() // which isn't action = action->nextAction; } - // special case for the first 'virtual' action at EID 0 - SelectEvent(0); } void EventBrowser::on_stepPrev_clicked() @@ -5562,9 +5563,17 @@ void EventBrowser::on_stepPrev_clicked() if(!m_Ctx.IsCaptureLoaded() || !ui->stepPrev->isEnabled()) return; + const ActionDescription *action = NULL; QModelIndex idx = ui->events->currentIndex(); - uint32_t selectedEID = GetSelectedEID(idx); - const ActionDescription *action = m_Ctx.GetAction(selectedEID); + if(idx.isValid()) + { + uint32_t selectedEID = GetSelectedEID(idx); + action = m_Ctx.GetAction(selectedEID); + } + + // No selected action use the current action + if(!action) + action = m_Ctx.CurAction(); if(action) { @@ -6788,6 +6797,24 @@ void EventBrowser::UpdateDurationColumn() m_Model->UpdateDurationColumn(); } +void EventBrowser::updateStepNextPrevButtonState() +{ + QModelIndex current = ui->events->currentIndex(); + if(current.isValid()) + { + uint32_t selectedEID = GetSelectedEID(current); + const ActionDescription *action = m_Ctx.GetAction(selectedEID); + if(action && action->IsFakeMarker()) + action = &action->children.back(); + + ui->stepPrev->setEnabled(action && action->previousAction); + ui->stepNext->setEnabled(action && action->nextAction); + // special case for the first action in the frame + if(selectedEID == 0) + ui->stepNext->setEnabled(true); + } +} + APIEvent EventBrowser::GetAPIEventForEID(uint32_t eid) { const ActionDescription *action = GetActionForEID(eid); diff --git a/qrenderdoc/Windows/EventBrowser.h b/qrenderdoc/Windows/EventBrowser.h index 131e9014bcc..b2b920a0962 100644 --- a/qrenderdoc/Windows/EventBrowser.h +++ b/qrenderdoc/Windows/EventBrowser.h @@ -207,6 +207,7 @@ private slots: void jumpToBookmark(int idx); void repopulateBookmarks(); void highlightBookmarks(); + void updateStepNextPrevButtonState(); void bookmarkContextMenu(QRClickToolButton *button, uint32_t EID); int FindEvent(QModelIndex parent, QString filter, uint32_t after, bool forward); diff --git a/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.cpp index 428242ba9fe..71bf4c470e5 100644 --- a/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.cpp @@ -29,7 +29,6 @@ #include #include #include "Code/Resources.h" -#include "Widgets/ComputeDebugSelector.h" #include "Widgets/Extended/RDHeaderView.h" #include "flowlayout/FlowLayout.h" #include "toolwindowmanager/ToolWindowManager.h" @@ -78,8 +77,6 @@ D3D11PipelineStateViewer::D3D11PipelineStateViewer(ICaptureContext &ctx, { ui->setupUi(this); - m_ComputeDebugSelector = new ComputeDebugSelector(this); - const QIcon &action = Icons::action(); const QIcon &action_hover = Icons::action_hover(); @@ -158,8 +155,10 @@ D3D11PipelineStateViewer::D3D11PipelineStateViewer(ICaptureContext &ctx, for(RDLabel *b : objectLabels) m_Common.SetupSummaryLabel(b, QSize(250, 0)); - QObject::connect(m_ComputeDebugSelector, &ComputeDebugSelector::beginDebug, this, - &D3D11PipelineStateViewer::computeDebugSelector_beginDebug); + QObject::connect(ui->computeDebugSelector, &QToolButton::clicked, &m_Common, + &PipelineStateViewer::computeDebugSelector_clicked); + QObject::connect(ui->pixelDebugSelector, &QToolButton::clicked, &m_Common, + &PipelineStateViewer::pixelDebugSelector_clicked); for(QToolButton *b : editButtons) QObject::connect(b, &QToolButton::clicked, &m_Common, &PipelineStateViewer::shaderEdit_clicked); @@ -476,7 +475,6 @@ D3D11PipelineStateViewer::D3D11PipelineStateViewer(ICaptureContext &ctx, D3D11PipelineStateViewer::~D3D11PipelineStateViewer() { delete ui; - delete m_ComputeDebugSelector; } void D3D11PipelineStateViewer::OnCaptureLoaded() @@ -1185,6 +1183,7 @@ void D3D11PipelineStateViewer::clearState() ui->predicateGroup->setVisible(false); ui->computeDebugSelector->setEnabled(false); + ui->pixelDebugSelector->setEnabled(false); } void D3D11PipelineStateViewer::setShaderState(const D3D11Pipe::Shader &stage, RDLabel *shader, @@ -2089,56 +2088,7 @@ void D3D11PipelineStateViewer::setState() ui->stencils->clearSelection(); ui->stencils->endUpdate(); - // set up thread debugging inputs - bool enableDebug = m_Ctx.APIProps().shaderDebugging && state.computeShader.reflection && - state.computeShader.reflection->debugInfo.debuggable && action && - (action->flags & ActionFlags::Dispatch); - if(enableDebug) - { - // Validate dispatch/threadgroup dimensions - enableDebug &= action->dispatchDimension[0] > 0; - enableDebug &= action->dispatchDimension[1] > 0; - enableDebug &= action->dispatchDimension[2] > 0; - - const rdcfixedarray &threadDims = - (action->dispatchThreadsDimension[0] == 0) - ? state.computeShader.reflection->dispatchThreadsDimension - : action->dispatchThreadsDimension; - enableDebug &= threadDims[0] > 0; - enableDebug &= threadDims[1] > 0; - enableDebug &= threadDims[2] > 0; - } - - if(enableDebug) - { - ui->computeDebugSelector->setEnabled(true); - - // set maximums for CS debugging - m_ComputeDebugSelector->SetThreadBounds( - action->dispatchDimension, (action->dispatchThreadsDimension[0] == 0) - ? state.computeShader.reflection->dispatchThreadsDimension - : action->dispatchThreadsDimension); - - ui->computeDebugSelector->setToolTip( - tr("Debug this compute shader by specifying group/thread ID or dispatch ID")); - } - else - { - ui->computeDebugSelector->setEnabled(false); - - if(!m_Ctx.APIProps().shaderDebugging) - ui->computeDebugSelector->setToolTip(tr("This API does not support shader debugging")); - else if(!action || !(action->flags & ActionFlags::Dispatch)) - ui->computeDebugSelector->setToolTip(tr("No dispatch selected")); - else if(!state.computeShader.reflection) - ui->computeDebugSelector->setToolTip(tr("No compute shader bound")); - else if(!state.computeShader.reflection->debugInfo.debuggable) - ui->computeDebugSelector->setToolTip( - tr("This shader doesn't support debugging: %1") - .arg(state.computeShader.reflection->debugInfo.debugStatus)); - else - ui->computeDebugSelector->setToolTip(tr("Invalid dispatch/threadgroup dimensions.")); - } + m_Common.SetupDebugSelectors(ui->computeDebugSelector, ui->pixelDebugSelector); // highlight the appropriate stages in the flowchart if(action == NULL) @@ -3427,93 +3377,3 @@ void D3D11PipelineStateViewer::on_meshView_clicked() m_Ctx.ShowMeshPreview(); ToolWindowManager::raiseToolWindow(m_Ctx.GetMeshPreview()->Widget()); } - -void D3D11PipelineStateViewer::on_computeDebugSelector_clicked() -{ - // Check whether debugging is valid for this event before showing the dialog - if(!m_Ctx.IsCaptureLoaded()) - return; - - const ActionDescription *action = m_Ctx.CurAction(); - - if(!action) - return; - - const ShaderReflection *shaderDetails = - m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Compute); - - if(!shaderDetails) - return; - - RDDialog::show(m_ComputeDebugSelector); -} - -void D3D11PipelineStateViewer::computeDebugSelector_beginDebug( - const rdcfixedarray &group, const rdcfixedarray &thread) -{ - const ActionDescription *action = m_Ctx.CurAction(); - - if(!action) - return; - - const ShaderReflection *shaderDetails = - m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Compute); - - if(!shaderDetails) - return; - - struct threadSelect - { - rdcfixedarray g; - rdcfixedarray t; - } debugThread = { - // g[] - {group[0], group[1], group[2]}, - // t[] - {thread[0], thread[1], thread[2]}, - }; - - bool done = false; - ShaderDebugTrace *trace = NULL; - - m_Ctx.Replay().AsyncInvoke([&trace, &done, debugThread](IReplayController *r) { - trace = r->DebugThread(debugThread.g, debugThread.t); - - if(trace->debugger == NULL) - { - r->FreeTrace(trace); - trace = NULL; - } - - done = true; - }); - - QString debugContext = lit("Group [%1,%2,%3] Thread [%4,%5,%6]") - .arg(group[0]) - .arg(group[1]) - .arg(group[2]) - .arg(thread[0]) - .arg(thread[1]) - .arg(thread[2]); - - // wait a short while before displaying the progress dialog (which won't show if we're already - // done by the time we reach it) - for(int i = 0; !done && i < 100; i++) - QThread::msleep(5); - - ShowProgressDialog(this, tr("Debugging %1").arg(debugContext), [&done]() { return done; }); - - if(!trace) - { - RDDialog::critical( - this, tr("Error debugging"), - tr("Error debugging thread - make sure a valid group and thread is selected")); - return; - } - - // viewer takes ownership of the trace - IShaderViewer *s = m_Ctx.DebugShader( - shaderDetails, m_Ctx.CurPipelineState().GetComputePipelineObject(), trace, debugContext); - - m_Ctx.AddDockWindow(s->Widget(), DockReference::AddTo, this); -} diff --git a/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.h b/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.h index b8b5b934e05..820f079d886 100644 --- a/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.h +++ b/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.h @@ -34,7 +34,6 @@ class D3D11PipelineStateViewer; class QXmlStreamWriter; -class ComputeDebugSelector; class RDLabel; class RDTreeWidget; class RDTreeWidgetItem; @@ -79,15 +78,10 @@ private slots: void cbuffer_itemActivated(RDTreeWidgetItem *item, int column); void vertex_leave(QEvent *e); - void on_computeDebugSelector_clicked(); - void computeDebugSelector_beginDebug(const rdcfixedarray &group, - const rdcfixedarray &thread); - private: Ui::D3D11PipelineStateViewer *ui; ICaptureContext &m_Ctx; PipelineStateViewer &m_Common; - ComputeDebugSelector *m_ComputeDebugSelector; void setShaderState(const D3D11Pipe::Shader &stage, RDLabel *shader, RDLabel *shaderDebug, RDTreeWidget *tex, RDTreeWidget *samp, RDTreeWidget *cbuffer, diff --git a/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.ui b/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.ui index 3efd6cd6df1..8d06b5396fe 100644 --- a/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.ui +++ b/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.ui @@ -3010,6 +3010,23 @@
+ + + + Debug + + + + :/wrench.png:/wrench.png + + + Qt::ToolButtonTextBesideIcon + + + true + + + diff --git a/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.cpp index 21f568d57a5..81664b7cfae 100644 --- a/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.cpp @@ -29,7 +29,6 @@ #include #include #include "Code/Resources.h" -#include "Widgets/ComputeDebugSelector.h" #include "Widgets/Extended/RDHeaderView.h" #include "Windows/DescriptorViewer.h" #include "flowlayout/FlowLayout.h" @@ -100,8 +99,6 @@ D3D12PipelineStateViewer::D3D12PipelineStateViewer(ICaptureContext &ctx, { ui->setupUi(this); - m_ComputeDebugSelector = new ComputeDebugSelector(this); - const QIcon &action = Icons::action(); const QIcon &action_hover = Icons::action_hover(); @@ -202,8 +199,10 @@ D3D12PipelineStateViewer::D3D12PipelineStateViewer(ICaptureContext &ctx, m_Common.SetupSummaryLabel(ui->predicate, QSize(250, 0)); - QObject::connect(m_ComputeDebugSelector, &ComputeDebugSelector::beginDebug, this, - &D3D12PipelineStateViewer::computeDebugSelector_beginDebug); + QObject::connect(ui->computeDebugSelector, &QToolButton::clicked, &m_Common, + &PipelineStateViewer::computeDebugSelector_clicked); + QObject::connect(ui->pixelDebugSelector, &QToolButton::clicked, &m_Common, + &PipelineStateViewer::pixelDebugSelector_clicked); for(QToolButton *b : editButtons) QObject::connect(b, &QToolButton::clicked, &m_Common, &PipelineStateViewer::shaderEdit_clicked); @@ -495,7 +494,6 @@ D3D12PipelineStateViewer::D3D12PipelineStateViewer(ICaptureContext &ctx, D3D12PipelineStateViewer::~D3D12PipelineStateViewer() { delete ui; - delete m_ComputeDebugSelector; } void D3D12PipelineStateViewer::OnCaptureLoaded() @@ -1181,6 +1179,7 @@ void D3D12PipelineStateViewer::clearState() ui->predicateGroup->setVisible(false); ui->computeDebugSelector->setEnabled(false); + ui->pixelDebugSelector->setEnabled(false); } void D3D12PipelineStateViewer::setShaderState(const D3D12Pipe::Shader &stage, RDLabel *pipeline, @@ -2292,56 +2291,7 @@ void D3D12PipelineStateViewer::setState() ui->stencils->clearSelection(); ui->stencils->endUpdate(); - // set up thread debugging inputs - bool enableDebug = m_Ctx.APIProps().shaderDebugging && state.computeShader.reflection && - state.computeShader.reflection->debugInfo.debuggable && action && - (action->flags & ActionFlags::Dispatch); - if(enableDebug) - { - // Validate dispatch/threadgroup dimensions - enableDebug &= action->dispatchDimension[0] > 0; - enableDebug &= action->dispatchDimension[1] > 0; - enableDebug &= action->dispatchDimension[2] > 0; - - const rdcfixedarray &threadDims = - (action->dispatchThreadsDimension[0] == 0) - ? state.computeShader.reflection->dispatchThreadsDimension - : action->dispatchThreadsDimension; - enableDebug &= threadDims[0] > 0; - enableDebug &= threadDims[1] > 0; - enableDebug &= threadDims[2] > 0; - } - - if(enableDebug) - { - ui->computeDebugSelector->setEnabled(true); - - // set maximums for CS debugging - m_ComputeDebugSelector->SetThreadBounds( - action->dispatchDimension, (action->dispatchThreadsDimension[0] == 0) - ? state.computeShader.reflection->dispatchThreadsDimension - : action->dispatchThreadsDimension); - - ui->computeDebugSelector->setToolTip( - tr("Debug this compute shader by specifying group/thread ID or dispatch ID")); - } - else - { - ui->computeDebugSelector->setEnabled(false); - - if(!m_Ctx.APIProps().shaderDebugging) - ui->computeDebugSelector->setToolTip(tr("This API does not support shader debugging")); - else if(!action || !(action->flags & ActionFlags::Dispatch)) - ui->computeDebugSelector->setToolTip(tr("No dispatch selected")); - else if(!state.computeShader.reflection) - ui->computeDebugSelector->setToolTip(tr("No compute shader bound")); - else if(!state.computeShader.reflection->debugInfo.debuggable) - ui->computeDebugSelector->setToolTip( - tr("This shader doesn't support debugging: %1") - .arg(state.computeShader.reflection->debugInfo.debugStatus)); - else - ui->computeDebugSelector->setToolTip(tr("Invalid dispatch/threadgroup dimensions.")); - } + m_Common.SetupDebugSelectors(ui->computeDebugSelector, ui->pixelDebugSelector); } void D3D12PipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, int column) @@ -3686,96 +3636,3 @@ void D3D12PipelineStateViewer::on_meshView_clicked() m_Ctx.ShowMeshPreview(); ToolWindowManager::raiseToolWindow(m_Ctx.GetMeshPreview()->Widget()); } - -void D3D12PipelineStateViewer::on_computeDebugSelector_clicked() -{ - // Check whether debugging is valid for this event before showing the dialog - if(!m_Ctx.APIProps().shaderDebugging) - return; - - if(!m_Ctx.IsCaptureLoaded()) - return; - - const ActionDescription *action = m_Ctx.CurAction(); - - if(!action) - return; - - const ShaderReflection *shaderDetails = - m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Compute); - - if(!shaderDetails) - return; - - RDDialog::show(m_ComputeDebugSelector); -} - -void D3D12PipelineStateViewer::computeDebugSelector_beginDebug( - const rdcfixedarray &group, const rdcfixedarray &thread) -{ - const ActionDescription *action = m_Ctx.CurAction(); - - if(!action) - return; - - const ShaderReflection *shaderDetails = - m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Compute); - - if(!shaderDetails) - return; - - struct threadSelect - { - rdcfixedarray g; - rdcfixedarray t; - } debugThread = { - // g[] - {group[0], group[1], group[2]}, - // t[] - {thread[0], thread[1], thread[2]}, - }; - - bool done = false; - ShaderDebugTrace *trace = NULL; - - m_Ctx.Replay().AsyncInvoke([&trace, &done, debugThread](IReplayController *r) { - trace = r->DebugThread(debugThread.g, debugThread.t); - - if(trace->debugger == NULL) - { - r->FreeTrace(trace); - trace = NULL; - } - - done = true; - }); - - QString debugContext = lit("Group [%1,%2,%3] Thread [%4,%5,%6]") - .arg(group[0]) - .arg(group[1]) - .arg(group[2]) - .arg(thread[0]) - .arg(thread[1]) - .arg(thread[2]); - - // wait a short while before displaying the progress dialog (which won't show if we're already - // done by the time we reach it) - for(int i = 0; !done && i < 100; i++) - QThread::msleep(5); - - ShowProgressDialog(this, tr("Debugging %1").arg(debugContext), [&done]() { return done; }); - - if(!trace) - { - RDDialog::critical( - this, tr("Error debugging"), - tr("Error debugging thread - make sure a valid group and thread is selected")); - return; - } - - // viewer takes ownership of the trace - IShaderViewer *s = m_Ctx.DebugShader( - shaderDetails, m_Ctx.CurPipelineState().GetComputePipelineObject(), trace, debugContext); - - m_Ctx.AddDockWindow(s->Widget(), DockReference::AddTo, this); -} diff --git a/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.h b/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.h index 2500ce4451d..60252bede15 100644 --- a/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.h +++ b/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.h @@ -34,7 +34,6 @@ class D3D12PipelineStateViewer; class QXmlStreamWriter; -class ComputeDebugSelector; class RDLabel; class RDTreeWidget; class RDTreeWidgetItem; @@ -81,15 +80,10 @@ private slots: void cbuffer_itemActivated(RDTreeWidgetItem *item, int column); void vertex_leave(QEvent *e); - void on_computeDebugSelector_clicked(); - void computeDebugSelector_beginDebug(const rdcfixedarray &group, - const rdcfixedarray &thread); - private: Ui::D3D12PipelineStateViewer *ui; ICaptureContext &m_Ctx; PipelineStateViewer &m_Common; - ComputeDebugSelector *m_ComputeDebugSelector; void setOldMeshPipeFlow(); void setNewMeshPipeFlow(); diff --git a/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.ui b/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.ui index ea54329d0f1..72898bb2363 100644 --- a/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.ui +++ b/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.ui @@ -3126,6 +3126,23 @@
+ + + + Debug + + + + :/wrench.png:/wrench.png + + + Qt::ToolButtonTextBesideIcon + + + true + + + diff --git a/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.cpp index 0c7d7f1150a..16ce842680c 100644 --- a/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.cpp @@ -29,7 +29,6 @@ #include #include #include "Code/Resources.h" -#include "Widgets/ComputeDebugSelector.h" #include "Widgets/Extended/RDHeaderView.h" #include "flowlayout/FlowLayout.h" #include "toolwindowmanager/ToolWindowManager.h" @@ -87,8 +86,6 @@ GLPipelineStateViewer::GLPipelineStateViewer(ICaptureContext &ctx, PipelineState { ui->setupUi(this); - m_ComputeDebugSelector = new ComputeDebugSelector(this); - const QIcon &action = Icons::action(); const QIcon &action_hover = Icons::action_hover(); @@ -200,8 +197,10 @@ GLPipelineStateViewer::GLPipelineStateViewer(ICaptureContext &ctx, PipelineState QObject::connect(res, &RDTreeWidget::itemActivated, this, &GLPipelineStateViewer::resource_itemActivated); - QObject::connect(m_ComputeDebugSelector, &ComputeDebugSelector::beginDebug, this, - &GLPipelineStateViewer::computeDebugSelector_beginDebug); + QObject::connect(ui->computeDebugSelector, &QToolButton::clicked, &m_Common, + &PipelineStateViewer::computeDebugSelector_clicked); + QObject::connect(ui->pixelDebugSelector, &QToolButton::clicked, &m_Common, + &PipelineStateViewer::pixelDebugSelector_clicked); { QMenu *extensionsMenu = new QMenu(this); @@ -1271,6 +1270,7 @@ void GLPipelineStateViewer::clearState() ui->stencils->clear(); ui->computeDebugSelector->setEnabled(false); + ui->pixelDebugSelector->setEnabled(false); } void GLPipelineStateViewer::setShaderState(const GLPipe::Shader &stage, RDLabel *pipeline, @@ -2589,56 +2589,7 @@ void GLPipelineStateViewer::setState() ui->stencils->clearSelection(); ui->stencils->endUpdate(); - // set up thread debugging inputs - bool enableDebug = m_Ctx.APIProps().shaderDebugging && state.computeShader.reflection && - state.computeShader.reflection->debugInfo.debuggable && action && - (action->flags & ActionFlags::Dispatch); - if(enableDebug) - { - // Validate dispatch/threadgroup dimensions - enableDebug &= action->dispatchDimension[0] > 0; - enableDebug &= action->dispatchDimension[1] > 0; - enableDebug &= action->dispatchDimension[2] > 0; - - const rdcfixedarray &threadDims = - (action->dispatchThreadsDimension[0] == 0) - ? state.computeShader.reflection->dispatchThreadsDimension - : action->dispatchThreadsDimension; - enableDebug &= threadDims[0] > 0; - enableDebug &= threadDims[1] > 0; - enableDebug &= threadDims[2] > 0; - } - - if(enableDebug) - { - ui->computeDebugSelector->setEnabled(true); - - // set maximums for CS debugging - m_ComputeDebugSelector->SetThreadBounds( - action->dispatchDimension, (action->dispatchThreadsDimension[0] == 0) - ? state.computeShader.reflection->dispatchThreadsDimension - : action->dispatchThreadsDimension); - - ui->computeDebugSelector->setToolTip( - tr("Debug this compute shader by specifying group/thread ID or dispatch ID")); - } - else - { - ui->computeDebugSelector->setEnabled(false); - - if(!m_Ctx.APIProps().shaderDebugging) - ui->computeDebugSelector->setToolTip(tr("This API does not support shader debugging")); - else if(!action || !(action->flags & ActionFlags::Dispatch)) - ui->computeDebugSelector->setToolTip(tr("No dispatch selected")); - else if(!state.computeShader.reflection) - ui->computeDebugSelector->setToolTip(tr("No compute shader bound")); - else if(!state.computeShader.reflection->debugInfo.debuggable) - ui->computeDebugSelector->setToolTip( - tr("This shader doesn't support debugging: %1") - .arg(state.computeShader.reflection->debugInfo.debugStatus)); - else - ui->computeDebugSelector->setToolTip(tr("Invalid dispatch/threadgroup dimensions.")); - } + m_Common.SetupDebugSelectors(ui->computeDebugSelector, ui->pixelDebugSelector); // highlight the appropriate stages in the flowchart if(action == NULL) @@ -3991,93 +3942,3 @@ void GLPipelineStateViewer::on_meshView_clicked() m_Ctx.ShowMeshPreview(); ToolWindowManager::raiseToolWindow(m_Ctx.GetMeshPreview()->Widget()); } - -void GLPipelineStateViewer::on_computeDebugSelector_clicked() -{ - // Check whether debugging is valid for this event before showing the dialog - if(!m_Ctx.IsCaptureLoaded()) - return; - - const ActionDescription *action = m_Ctx.CurAction(); - - if(!action) - return; - - const ShaderReflection *shaderDetails = - m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Compute); - - if(!shaderDetails) - return; - - RDDialog::show(m_ComputeDebugSelector); -} - -void GLPipelineStateViewer::computeDebugSelector_beginDebug(const rdcfixedarray &group, - const rdcfixedarray &thread) -{ - const ActionDescription *action = m_Ctx.CurAction(); - - if(!action) - return; - - const ShaderReflection *shaderDetails = - m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Compute); - - if(!shaderDetails) - return; - - struct threadSelect - { - rdcfixedarray g; - rdcfixedarray t; - } debugThread = { - // g[] - {group[0], group[1], group[2]}, - // t[] - {thread[0], thread[1], thread[2]}, - }; - - bool done = false; - ShaderDebugTrace *trace = NULL; - - m_Ctx.Replay().AsyncInvoke([&trace, &done, debugThread](IReplayController *r) { - trace = r->DebugThread(debugThread.g, debugThread.t); - - if(trace->debugger == NULL) - { - r->FreeTrace(trace); - trace = NULL; - } - - done = true; - }); - - QString debugContext = lit("Group [%1,%2,%3] Thread [%4,%5,%6]") - .arg(group[0]) - .arg(group[1]) - .arg(group[2]) - .arg(thread[0]) - .arg(thread[1]) - .arg(thread[2]); - - // wait a short while before displaying the progress dialog (which won't show if we're already - // done by the time we reach it) - for(int i = 0; !done && i < 100; i++) - QThread::msleep(5); - - ShowProgressDialog(this, tr("Debugging %1").arg(debugContext), [&done]() { return done; }); - - if(!trace) - { - RDDialog::critical( - this, tr("Error debugging"), - tr("Error debugging thread - make sure a valid group and thread is selected")); - return; - } - - // viewer takes ownership of the trace - IShaderViewer *s = m_Ctx.DebugShader( - shaderDetails, m_Ctx.CurPipelineState().GetComputePipelineObject(), trace, debugContext); - - m_Ctx.AddDockWindow(s->Widget(), DockReference::AddTo, this); -} diff --git a/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.h b/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.h index 6e7ee8e0406..eae9ec1c9a7 100644 --- a/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.h +++ b/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.h @@ -34,7 +34,6 @@ class GLPipelineStateViewer; class QXmlStreamWriter; -class ComputeDebugSelector; class RDLabel; class RDTreeWidget; class RDTreeWidgetItem; @@ -84,15 +83,10 @@ private slots: void ubo_itemActivated(RDTreeWidgetItem *item, int column); void vertex_leave(QEvent *e); - void on_computeDebugSelector_clicked(); - void computeDebugSelector_beginDebug(const rdcfixedarray &group, - const rdcfixedarray &thread); - private: Ui::GLPipelineStateViewer *ui; ICaptureContext &m_Ctx; PipelineStateViewer &m_Common; - ComputeDebugSelector *m_ComputeDebugSelector; QString MakeGenericValueString(uint32_t compCount, CompType compType, const GLPipe::VertexAttribute &val); diff --git a/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.ui b/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.ui index 06f4caa9677..950635dcb55 100644 --- a/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.ui +++ b/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.ui @@ -3720,6 +3720,23 @@ + + + + Debug + + + + :/wrench.png:/wrench.png + + + Qt::ToolButtonTextBesideIcon + + + true + + + diff --git a/qrenderdoc/Windows/PipelineState/PipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/PipelineStateViewer.cpp index 4237307b917..a56b6ae107d 100644 --- a/qrenderdoc/Windows/PipelineState/PipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/PipelineStateViewer.cpp @@ -33,8 +33,10 @@ #include #include "Code/QRDUtils.h" #include "Code/Resources.h" +#include "Widgets/ComputeDebugSelector.h" #include "Widgets/Extended/RDLabel.h" #include "Widgets/Extended/RDTreeWidget.h" +#include "Widgets/PixelDebugSelector.h" #include "toolwindowmanager/ToolWindowManager.h" #include "D3D11PipelineStateViewer.h" #include "D3D12PipelineStateViewer.h" @@ -185,6 +187,15 @@ PipelineStateViewer::PipelineStateViewer(ICaptureContext &ctx, QWidget *parent) { ui->setupUi(this); + m_ComputeDebugSelector = new ComputeDebugSelector(this); + m_PixelDebugSelector = new PixelDebugSelector(m_Ctx, this); + + QObject::connect(m_ComputeDebugSelector, &ComputeDebugSelector::beginDebug, this, + &PipelineStateViewer::computeDebugSelector_beginDebug); + + QObject::connect(m_PixelDebugSelector, &PixelDebugSelector::beginDebug, this, + &PipelineStateViewer::pixelDebugSelector_beginDebug); + ui->thumbnail->SetContext(m_Ctx); ui->layout->removeWidget(ui->thumbnail); @@ -218,6 +229,9 @@ PipelineStateViewer::~PipelineStateViewer() m_Ctx.BuiltinWindowClosed(this); m_Ctx.RemoveCaptureViewer(this); + delete m_ComputeDebugSelector; + delete m_PixelDebugSelector; + delete m_Tooltip; delete ui; @@ -948,6 +962,259 @@ void PipelineStateViewer::shaderEdit_clicked() menu->actions()[0]->trigger(); } +void PipelineStateViewer::SetupDebugSelectors(QToolButton *computeDebugSelector, + QToolButton *pixelDebugSelector) +{ + const ShaderReflection *csRefl = m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Compute); + const ShaderReflection *psRefl = m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Pixel); + const ActionDescription *action = m_Ctx.CurAction(); + + // set up thread debugging inputs + bool enableComputeDebug = m_Ctx.APIProps().shaderDebugging && csRefl && + csRefl->debugInfo.debuggable && action && + (action->flags & ActionFlags::Dispatch); + if(enableComputeDebug) + { + // Validate dispatch/threadgroup dimensions + enableComputeDebug &= action->dispatchDimension[0] > 0; + enableComputeDebug &= action->dispatchDimension[1] > 0; + enableComputeDebug &= action->dispatchDimension[2] > 0; + + const rdcfixedarray &threadDims = (action->dispatchThreadsDimension[0] == 0) + ? csRefl->dispatchThreadsDimension + : action->dispatchThreadsDimension; + enableComputeDebug &= threadDims[0] > 0; + enableComputeDebug &= threadDims[1] > 0; + enableComputeDebug &= threadDims[2] > 0; + } + + if(enableComputeDebug) + { + computeDebugSelector->setEnabled(true); + + // set maximums for CS debugging + m_ComputeDebugSelector->SetThreadBounds(action->dispatchDimension, + (action->dispatchThreadsDimension[0] == 0) + ? csRefl->dispatchThreadsDimension + : action->dispatchThreadsDimension); + + computeDebugSelector->setToolTip( + tr("Debug this compute shader by specifying group/thread ID or dispatch ID")); + } + else + { + computeDebugSelector->setEnabled(false); + + if(!m_Ctx.APIProps().shaderDebugging) + computeDebugSelector->setToolTip(tr("This API does not support shader debugging")); + else if(!action || !(action->flags & ActionFlags::Dispatch)) + computeDebugSelector->setToolTip(tr("No dispatch selected")); + else if(!csRefl) + computeDebugSelector->setToolTip(tr("No compute shader bound")); + else if(!csRefl->debugInfo.debuggable) + computeDebugSelector->setToolTip( + tr("This shader doesn't support debugging: %1").arg(csRefl->debugInfo.debugStatus)); + else + computeDebugSelector->setToolTip(tr("Invalid dispatch/threadgroup dimensions.")); + } + + // set up thread debugging inputs + bool enablePixelDebug = m_Ctx.APIProps().shaderDebugging && psRefl && + psRefl->debugInfo.debuggable && action && + (action->flags & ActionFlags::Drawcall); + if(enablePixelDebug) + { + pixelDebugSelector->setEnabled(true); + + pixelDebugSelector->setToolTip( + tr("Debug this pixel shader by manually selecting a co-ordinate")); + } + else + { + pixelDebugSelector->setEnabled(false); + + if(!m_Ctx.APIProps().shaderDebugging) + pixelDebugSelector->setToolTip(tr("This API does not support shader debugging")); + else if(!action || !(action->flags & ActionFlags::Drawcall)) + pixelDebugSelector->setToolTip(tr("No draw selected")); + else if(!psRefl) + pixelDebugSelector->setToolTip(tr("No pixel shader bound")); + else if(!psRefl->debugInfo.debuggable) + pixelDebugSelector->setToolTip( + tr("This shader doesn't support debugging: %1").arg(psRefl->debugInfo.debugStatus)); + } +} + +void PipelineStateViewer::computeDebugSelector_clicked() +{ + // Check whether debugging is valid for this event before showing the dialog + if(!m_Ctx.APIProps().shaderDebugging) + return; + + if(!m_Ctx.IsCaptureLoaded()) + return; + + const ActionDescription *action = m_Ctx.CurAction(); + + if(!action) + return; + + const ShaderReflection *shaderDetails = + m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Compute); + + if(!shaderDetails) + return; + + RDDialog::show(m_ComputeDebugSelector); +} + +void PipelineStateViewer::computeDebugSelector_beginDebug(const rdcfixedarray &group, + const rdcfixedarray &thread) +{ + const ActionDescription *action = m_Ctx.CurAction(); + + if(!action) + return; + + const ShaderReflection *shaderDetails = + m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Compute); + + if(!shaderDetails) + return; + + struct threadSelect + { + rdcfixedarray g; + rdcfixedarray t; + } debugThread = { + // g[] + {group[0], group[1], group[2]}, + // t[] + {thread[0], thread[1], thread[2]}, + }; + + bool done = false; + ShaderDebugTrace *trace = NULL; + + m_Ctx.Replay().AsyncInvoke([&trace, &done, debugThread](IReplayController *r) { + trace = r->DebugThread(debugThread.g, debugThread.t); + + if(trace->debugger == NULL) + { + r->FreeTrace(trace); + trace = NULL; + } + + done = true; + }); + + QString debugContext = lit("Group [%1,%2,%3] Thread [%4,%5,%6]") + .arg(group[0]) + .arg(group[1]) + .arg(group[2]) + .arg(thread[0]) + .arg(thread[1]) + .arg(thread[2]); + + // wait a short while before displaying the progress dialog (which won't show if we're already + // done by the time we reach it) + for(int i = 0; !done && i < 100; i++) + QThread::msleep(5); + + ShowProgressDialog(this, tr("Debugging %1").arg(debugContext), [&done]() { return done; }); + + if(!trace) + { + RDDialog::critical( + this, tr("Error debugging"), + tr("Error debugging thread - make sure a valid group and thread is selected")); + return; + } + + // viewer takes ownership of the trace + IShaderViewer *s = m_Ctx.DebugShader( + shaderDetails, m_Ctx.CurPipelineState().GetComputePipelineObject(), trace, debugContext); + + m_Ctx.AddDockWindow(s->Widget(), DockReference::AddTo, this); +} + +void PipelineStateViewer::pixelDebugSelector_clicked() +{ + // Check whether debugging is valid for this event before showing the dialog + if(!m_Ctx.APIProps().shaderDebugging) + return; + + if(!m_Ctx.IsCaptureLoaded()) + return; + + const ActionDescription *action = m_Ctx.CurAction(); + + if(!action) + return; + + const ShaderReflection *shaderDetails = + m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Pixel); + + if(!shaderDetails) + return; + + m_PixelDebugSelector->UpdateTarget(); + + RDDialog::show(m_PixelDebugSelector); +} + +void PipelineStateViewer::pixelDebugSelector_beginDebug(uint32_t x, uint32_t y, + const DebugPixelInputs &inputs) +{ + const ActionDescription *action = m_Ctx.CurAction(); + + if(!action) + return; + + const ShaderReflection *shaderDetails = + m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Pixel); + + if(!shaderDetails) + return; + + bool done = false; + ShaderDebugTrace *trace = NULL; + + m_Ctx.Replay().AsyncInvoke([&trace, &done, x, y, &inputs](IReplayController *r) { + trace = r->DebugPixel(x, y, inputs); + + if(trace->debugger == NULL) + { + r->FreeTrace(trace); + trace = NULL; + } + + done = true; + }); + + QString debugContext = QFormatStr("Pixel %1,%2 @ %3").arg(x).arg(y).arg(action->eventId); + + // wait a short while before displaying the progress dialog (which won't show if we're already + // done by the time we reach it) + for(int i = 0; !done && i < 100; i++) + QThread::msleep(5); + + ShowProgressDialog(this, tr("Debugging %1").arg(debugContext), [&done]() { return done; }); + + if(!trace) + { + RDDialog::critical(this, tr("Error debugging"), + tr("Error debugging pixel - make sure a valid co-ordinate is selected.")); + return; + } + + // viewer takes ownership of the trace + IShaderViewer *s = m_Ctx.DebugShader( + shaderDetails, m_Ctx.CurPipelineState().GetGraphicsPipelineObject(), trace, debugContext); + + m_Ctx.AddDockWindow(s->Widget(), DockReference::AddTo, this); +} + IShaderViewer *PipelineStateViewer::EditShader(ResourceId id, ShaderStage shaderType, const rdcstr &entry, ShaderCompileFlags compileFlags, KnownShaderTool knownTool, diff --git a/qrenderdoc/Windows/PipelineState/PipelineStateViewer.h b/qrenderdoc/Windows/PipelineState/PipelineStateViewer.h index f24b8363000..ca5a5f1d386 100644 --- a/qrenderdoc/Windows/PipelineState/PipelineStateViewer.h +++ b/qrenderdoc/Windows/PipelineState/PipelineStateViewer.h @@ -36,6 +36,9 @@ class PipelineStateViewer; class QXmlStreamWriter; +class ComputeDebugSelector; +class PixelDebugSelector; + class QToolButton; class QMenu; class RDLabel; @@ -116,6 +119,8 @@ class PipelineStateViewer : public QFrame, public IPipelineStateViewer, public I void SetupResourceView(RDTreeWidget *view); void SetupSummaryLabel(RDLabel *label, const QSize &minimumSize); + void SetupDebugSelectors(QToolButton *computeSelector, QToolButton *pixelSelector); + QString GetVBufferFormatString(uint32_t slot); QColor GetViewDetailsColor(); @@ -135,12 +140,23 @@ class PipelineStateViewer : public QFrame, public IPipelineStateViewer, public I public slots: void shaderEdit_clicked(); + void computeDebugSelector_clicked(); + void computeDebugSelector_beginDebug(const rdcfixedarray &group, + const rdcfixedarray &thread); + + void pixelDebugSelector_clicked(); + void pixelDebugSelector_beginDebug(uint32_t x, uint32_t y, const DebugPixelInputs &inputs); + + private: void showEvent(QShowEvent *event) override; Ui::PipelineStateViewer *ui; ICaptureContext &m_Ctx; + ComputeDebugSelector *m_ComputeDebugSelector; + PixelDebugSelector *m_PixelDebugSelector; + QMenu *editMenus[NumShaderStages] = {}; RDPreviewTooltip *m_Tooltip = NULL; diff --git a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp index ad996ae85d8..beebbc0c66e 100644 --- a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp @@ -30,7 +30,6 @@ #include #include #include "Code/Resources.h" -#include "Widgets/ComputeDebugSelector.h" #include "Widgets/Extended/RDHeaderView.h" #include "flowlayout/FlowLayout.h" #include "toolwindowmanager/ToolWindowManager.h" @@ -142,8 +141,6 @@ VulkanPipelineStateViewer::VulkanPipelineStateViewer(ICaptureContext &ctx, { ui->setupUi(this); - m_ComputeDebugSelector = new ComputeDebugSelector(this); - const QIcon &action = Icons::action(); const QIcon &action_hover = Icons::action_hover(); @@ -257,8 +254,10 @@ VulkanPipelineStateViewer::VulkanPipelineStateViewer(ICaptureContext &ctx, ui->tsDescGroup->setCollapsed(true); ui->msDescGroup->setCollapsed(true); - QObject::connect(m_ComputeDebugSelector, &ComputeDebugSelector::beginDebug, this, - &VulkanPipelineStateViewer::computeDebugSelector_beginDebug); + QObject::connect(ui->computeDebugSelector, &QToolButton::clicked, &m_Common, + &PipelineStateViewer::computeDebugSelector_clicked); + QObject::connect(ui->pixelDebugSelector, &QToolButton::clicked, &m_Common, + &PipelineStateViewer::pixelDebugSelector_clicked); for(QToolButton *b : editButtons) QObject::connect(b, &QToolButton::clicked, &m_Common, &PipelineStateViewer::shaderEdit_clicked); @@ -556,7 +555,6 @@ VulkanPipelineStateViewer::~VulkanPipelineStateViewer() { m_CombinedImageSamplers.clear(); delete ui; - delete m_ComputeDebugSelector; } void VulkanPipelineStateViewer::OnCaptureLoaded() @@ -1105,6 +1103,7 @@ void VulkanPipelineStateViewer::clearState() ui->stencils->clear(); ui->computeDebugSelector->setEnabled(false); + ui->pixelDebugSelector->setEnabled(false); ui->conditionalRenderingGroup->setVisible(false); ui->csConditionalRenderingGroup->setVisible(false); @@ -3166,56 +3165,7 @@ void VulkanPipelineStateViewer::setState() ui->stencils->clearSelection(); ui->stencils->endUpdate(); - // set up thread debugging inputs - bool enableDebug = m_Ctx.APIProps().shaderDebugging && state.computeShader.reflection && - state.computeShader.reflection->debugInfo.debuggable && action && - (action->flags & ActionFlags::Dispatch); - if(enableDebug) - { - // Validate dispatch/threadgroup dimensions - enableDebug &= action->dispatchDimension[0] > 0; - enableDebug &= action->dispatchDimension[1] > 0; - enableDebug &= action->dispatchDimension[2] > 0; - - const rdcfixedarray &threadDims = - (action->dispatchThreadsDimension[0] == 0) - ? state.computeShader.reflection->dispatchThreadsDimension - : action->dispatchThreadsDimension; - enableDebug &= threadDims[0] > 0; - enableDebug &= threadDims[1] > 0; - enableDebug &= threadDims[2] > 0; - } - - if(enableDebug) - { - ui->computeDebugSelector->setEnabled(true); - - // set maximums for CS debugging - m_ComputeDebugSelector->SetThreadBounds( - action->dispatchDimension, (action->dispatchThreadsDimension[0] == 0) - ? state.computeShader.reflection->dispatchThreadsDimension - : action->dispatchThreadsDimension); - - ui->computeDebugSelector->setToolTip( - tr("Debug this compute shader by specifying group/thread ID or dispatch ID")); - } - else - { - ui->computeDebugSelector->setEnabled(false); - - if(!m_Ctx.APIProps().shaderDebugging) - ui->computeDebugSelector->setToolTip(tr("This API does not support shader debugging")); - else if(!action || !(action->flags & ActionFlags::Dispatch)) - ui->computeDebugSelector->setToolTip(tr("No dispatch selected")); - else if(!state.computeShader.reflection) - ui->computeDebugSelector->setToolTip(tr("No compute shader bound")); - else if(!state.computeShader.reflection->debugInfo.debuggable) - ui->computeDebugSelector->setToolTip( - tr("This shader doesn't support debugging: %1") - .arg(state.computeShader.reflection->debugInfo.debugStatus)); - else - ui->computeDebugSelector->setToolTip(tr("Invalid dispatch/threadgroup dimensions.")); - } + m_Common.SetupDebugSelectors(ui->computeDebugSelector, ui->pixelDebugSelector); } void VulkanPipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, int column) @@ -5545,96 +5495,3 @@ void VulkanPipelineStateViewer::on_meshView_clicked() m_Ctx.ShowMeshPreview(); ToolWindowManager::raiseToolWindow(m_Ctx.GetMeshPreview()->Widget()); } - -void VulkanPipelineStateViewer::on_computeDebugSelector_clicked() -{ - // Check whether debugging is valid for this event before showing the dialog - if(!m_Ctx.APIProps().shaderDebugging) - return; - - if(!m_Ctx.IsCaptureLoaded()) - return; - - const ActionDescription *action = m_Ctx.CurAction(); - - if(!action) - return; - - const ShaderReflection *shaderDetails = - m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Compute); - - if(!shaderDetails) - return; - - RDDialog::show(m_ComputeDebugSelector); -} - -void VulkanPipelineStateViewer::computeDebugSelector_beginDebug( - const rdcfixedarray &group, const rdcfixedarray &thread) -{ - const ActionDescription *action = m_Ctx.CurAction(); - - if(!action) - return; - - const ShaderReflection *shaderDetails = - m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Compute); - - if(!shaderDetails) - return; - - struct threadSelect - { - rdcfixedarray g; - rdcfixedarray t; - } debugThread = { - // g[] - {group[0], group[1], group[2]}, - // t[] - {thread[0], thread[1], thread[2]}, - }; - - bool done = false; - ShaderDebugTrace *trace = NULL; - - m_Ctx.Replay().AsyncInvoke([&trace, &done, debugThread](IReplayController *r) { - trace = r->DebugThread(debugThread.g, debugThread.t); - - if(trace->debugger == NULL) - { - r->FreeTrace(trace); - trace = NULL; - } - - done = true; - }); - - QString debugContext = lit("Group [%1,%2,%3] Thread [%4,%5,%6]") - .arg(group[0]) - .arg(group[1]) - .arg(group[2]) - .arg(thread[0]) - .arg(thread[1]) - .arg(thread[2]); - - // wait a short while before displaying the progress dialog (which won't show if we're already - // done by the time we reach it) - for(int i = 0; !done && i < 100; i++) - QThread::msleep(5); - - ShowProgressDialog(this, tr("Debugging %1").arg(debugContext), [&done]() { return done; }); - - if(!trace) - { - RDDialog::critical( - this, tr("Error debugging"), - tr("Error debugging thread - make sure a valid group and thread is selected")); - return; - } - - // viewer takes ownership of the trace - IShaderViewer *s = m_Ctx.DebugShader( - shaderDetails, m_Ctx.CurPipelineState().GetComputePipelineObject(), trace, debugContext); - - m_Ctx.AddDockWindow(s->Widget(), DockReference::AddTo, this); -} diff --git a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.h b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.h index 5be6dc15a0e..ee6f3fbdc35 100644 --- a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.h +++ b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.h @@ -35,7 +35,6 @@ class VulkanPipelineStateViewer; class QXmlStreamWriter; -class ComputeDebugSelector; class RDLabel; class RDTreeWidget; class RDTreeWidgetItem; @@ -89,10 +88,6 @@ private slots: void descSet_itemActivated(RDTreeWidgetItem *item, int column); void vertex_leave(QEvent *e); - void on_computeDebugSelector_clicked(); - void computeDebugSelector_beginDebug(const rdcfixedarray &group, - const rdcfixedarray &thread); - void exportHTML_clicked(); void exportFOZ_clicked(); @@ -100,7 +95,6 @@ private slots: Ui::VulkanPipelineStateViewer *ui; ICaptureContext &m_Ctx; PipelineStateViewer &m_Common; - ComputeDebugSelector *m_ComputeDebugSelector; void setOldMeshPipeFlow(); void setNewMeshPipeFlow(); diff --git a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.ui b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.ui index 8f1433a9ffd..9456123f6e7 100644 --- a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.ui +++ b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.ui @@ -3486,6 +3486,23 @@ + + + + Debug + + + + :/wrench.png:/wrench.png + + + Qt::ToolButtonTextBesideIcon + + + true + + + diff --git a/qrenderdoc/Windows/ShaderViewer.cpp b/qrenderdoc/Windows/ShaderViewer.cpp index e62cb051e9e..a8b839f4a15 100644 --- a/qrenderdoc/Windows/ShaderViewer.cpp +++ b/qrenderdoc/Windows/ShaderViewer.cpp @@ -1107,7 +1107,7 @@ void ShaderViewer::debugShader(const ShaderReflection *shader, ResourceId pipeli // we do updateDebugging() again because the first call finds the scintilla for the current // source file, the second time jumps to it. - if(preferSourceDebug) + if(preferSourceDebug && !m_States.empty()) { // if we're not on a source line, move forward to the first source line while(!m_CurInstructionScintilla) @@ -2517,7 +2517,7 @@ bool ShaderViewer::IsFirstState() const bool ShaderViewer::IsLastState() const { - return m_CurrentStateIdx == m_States.size() - 1; + return m_CurrentStateIdx == m_States.size() - 1 || m_States.empty(); } const ShaderDebugState &ShaderViewer::GetPreviousState() const diff --git a/qrenderdoc/Windows/TextureViewer.cpp b/qrenderdoc/Windows/TextureViewer.cpp index ae4c59de07a..d8ac775c0ca 100644 --- a/qrenderdoc/Windows/TextureViewer.cpp +++ b/qrenderdoc/Windows/TextureViewer.cpp @@ -402,18 +402,33 @@ void TextureViewer::UI_UpdateCachedTexture() return; } + bool debugOutput = false; + ResourceId id = m_LockedId; if(id == ResourceId()) + { + debugOutput = m_Following.Type == FollowType::OutputColor || + m_Following.Type == FollowType::OutputDepth || + m_Following.Type == FollowType::OutputDepthResolve; id = m_Following.GetResourceId(m_Ctx); + } if(id == ResourceId()) + { + debugOutput = false; id = m_TexDisplay.resourceId; + } m_CachedTexture = m_Ctx.GetTexture(id); if(m_CachedTexture != NULL) { - if(m_Ctx.APIProps().shaderDebugging) + if(!debugOutput) + { + ui->debugPixelContext->setEnabled(false); + ui->debugPixelContext->setToolTip(tr("No output texture selected")); + } + else if(m_Ctx.APIProps().shaderDebugging) { const ShaderReflection *shaderDetails = m_Ctx.CurPipelineState().GetShaderReflection(ShaderStage::Pixel); diff --git a/qrenderdoc/qrenderdoc.pro b/qrenderdoc/qrenderdoc.pro index d75dfb53124..3ab4067905a 100644 --- a/qrenderdoc/qrenderdoc.pro +++ b/qrenderdoc/qrenderdoc.pro @@ -211,6 +211,7 @@ SOURCES += Code/qrenderdoc.cpp \ Widgets/Extended/RDDoubleSpinBox.cpp \ Widgets/Extended/RDListView.cpp \ Widgets/ComputeDebugSelector.cpp \ + Widgets/PixelDebugSelector.cpp \ Widgets/CustomPaintWidget.cpp \ Widgets/ResourcePreview.cpp \ Widgets/ThumbnailStrip.cpp \ @@ -303,6 +304,7 @@ HEADERS += Code/CaptureContext.h \ Widgets/Extended/RDDoubleSpinBox.h \ Widgets/Extended/RDListView.h \ Widgets/ComputeDebugSelector.h \ + Widgets/PixelDebugSelector.h \ Widgets/CustomPaintWidget.h \ Widgets/ResourcePreview.h \ Widgets/ThumbnailStrip.h \ @@ -377,6 +379,7 @@ FORMS += Windows/Dialogs/AboutDialog.ui \ Windows/PipelineState/GLPipelineStateViewer.ui \ Widgets/BufferFormatSpecifier.ui \ Widgets/ComputeDebugSelector.ui \ + Widgets/PixelDebugSelector.ui \ Windows/BufferViewer.ui \ Windows/ShaderViewer.ui \ Windows/ShaderMessageViewer.ui \ diff --git a/qrenderdoc/qrenderdoc_local.vcxproj b/qrenderdoc/qrenderdoc_local.vcxproj index b7860b9682d..7e69ebdc7cd 100644 --- a/qrenderdoc/qrenderdoc_local.vcxproj +++ b/qrenderdoc/qrenderdoc_local.vcxproj @@ -611,6 +611,7 @@ + @@ -710,6 +711,7 @@ + @@ -965,6 +967,7 @@ + @@ -1043,6 +1046,12 @@ MOC %(Filename).h $(IntDir)generated\moc_%(Filename).cpp + + %(Fullpath);$(QtBinDir)\moc.exe;%(AdditionalInputs) + "$(QtBinDir)\moc.exe" -DUNICODE -DWIN32 -DWIN64 -D_WIN32 -D_WIN64 -DDCOMP_PLATFORM_WIN32 -DSCINTILLA_QT=1 -DSCI_LEXER=1 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -D_MSC_VER=1900 -I"$(ProjectDir)." -I"$(SolutionDir)\renderdoc\api\replay" -I"$(QtIncludeDir)" -I"$(QtIncludeDir)\QtWidgets" -I"$(QtIncludeDir)\QtGui" -I"$(QtIncludeDir)\QtCore" "%(Fullpath)" -o "$(IntDir)generated\moc_%(Filename).cpp" + MOC %(Filename).h + $(IntDir)generated\moc_%(Filename).cpp + %(Fullpath);$(QtBinDir)\moc.exe;%(AdditionalInputs) "$(QtBinDir)\moc.exe" -DUNICODE -DWIN32 -DWIN64 -D_WIN32 -D_WIN64 -DDCOMP_PLATFORM_WIN32 -DSCINTILLA_QT=1 -DSCI_LEXER=1 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -D_MSC_VER=1900 -I"$(ProjectDir)." -I"$(SolutionDir)\renderdoc\api\replay" -I"$(QtIncludeDir)" -I"$(QtIncludeDir)\QtWidgets" -I"$(QtIncludeDir)\QtGui" -I"$(QtIncludeDir)\QtCore" "%(Fullpath)" -o "$(IntDir)generated\moc_%(Filename).cpp" @@ -1494,6 +1503,12 @@ UIC %(Filename).ui $(IntDir)generated\ui_%(Filename).h + + %(Fullpath);$(QtBinDir)\uic.exe;%(AdditionalInputs) + "$(QtBinDir)\uic.exe" "%(Fullpath)" -o "$(IntDir)generated\ui_%(Filename).h" + UIC %(Filename).ui + $(IntDir)generated\ui_%(Filename).h + %(Fullpath);$(QtBinDir)\uic.exe;%(AdditionalInputs) "$(QtBinDir)\uic.exe" "%(Fullpath)" -o "$(IntDir)generated\ui_%(Filename).h" diff --git a/qrenderdoc/qrenderdoc_local.vcxproj.filters b/qrenderdoc/qrenderdoc_local.vcxproj.filters index 748c49f817b..f1b706c7459 100644 --- a/qrenderdoc/qrenderdoc_local.vcxproj.filters +++ b/qrenderdoc/qrenderdoc_local.vcxproj.filters @@ -804,6 +804,12 @@ Code\Interface + + Generated Files + + + Widgets + @@ -1196,6 +1202,9 @@ Code\Interface + + Generated Files + @@ -1640,6 +1649,12 @@ Widgets\Extended + + Widgets + + + Widgets + diff --git a/renderdoc/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp b/renderdoc/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp index b8d0707e671..5e5c05818eb 100644 --- a/renderdoc/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp +++ b/renderdoc/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp @@ -85,7 +85,7 @@ int NumberOfClients = 0; #ifndef DISABLE_THREAD_SUPPORT std::mutex &init_lock() { - std::mutex *lock = new std::mutex; + static std::mutex *lock = new std::mutex; return *lock; } #endif diff --git a/renderdoc/api/replay/gl_pipestate.h b/renderdoc/api/replay/gl_pipestate.h index 02b9eebb7ba..ec1b4e025b1 100644 --- a/renderdoc/api/replay/gl_pipestate.h +++ b/renderdoc/api/replay/gl_pipestate.h @@ -723,6 +723,12 @@ struct FBO :type: int )"); int32_t readBuffer = 0; + + DOCUMENT(R"(The default sample count to use if the framebuffer has no attachments + +:type: int +)"); + uint32_t defaultSampleCount = 0; }; DOCUMENT(R"( diff --git a/renderdoc/api/replay/pipestate.h b/renderdoc/api/replay/pipestate.h index e259766a0dd..022fd9a7bf7 100644 --- a/renderdoc/api/replay/pipestate.h +++ b/renderdoc/api/replay/pipestate.h @@ -176,6 +176,12 @@ struct PipeState )"); uint32_t MultiviewBroadcastCount() const; + DOCUMENT(R"( +:return: The number of multisample samples to use when not implicit from output targets. +:rtype: int +)"); + uint32_t GetOverrideSampleCount() const; + DOCUMENT(R"(Determines whether or not the current capture supports binding arrays of resources. :return: A boolean indicating if binding arrays of resources is supported. diff --git a/renderdoc/api/replay/pipestate.inl b/renderdoc/api/replay/pipestate.inl index 6e2bf6a3a8c..ef944a614fd 100644 --- a/renderdoc/api/replay/pipestate.inl +++ b/renderdoc/api/replay/pipestate.inl @@ -397,6 +397,31 @@ uint32_t PipeState::MultiviewBroadcastCount() const return 1; } +uint32_t PipeState::GetOverrideSampleCount() const +{ + if(IsCaptureLoaded()) + { + if(IsCaptureD3D11()) + { + return m_D3D11->rasterizer.state.forcedSampleCount; + } + else if(IsCaptureD3D12()) + { + return m_D3D11->rasterizer.state.forcedSampleCount; + } + else if(IsCaptureGL()) + { + return m_GL->framebuffer.drawFBO.defaultSampleCount; + } + else if(IsCaptureVK()) + { + return m_Vulkan->multisample.rasterSamples; + } + } + + return 0; +} + rdcstr PipeState::GetShaderEntryPoint(ShaderStage stage) const { if(IsCaptureLoaded() && IsCaptureVK()) diff --git a/renderdoc/api/replay/version.h b/renderdoc/api/replay/version.h index 90723b80b09..30d5219e48c 100644 --- a/renderdoc/api/replay/version.h +++ b/renderdoc/api/replay/version.h @@ -94,7 +94,7 @@ extern "C" const char GitVersionHash[41]; // compatibility version here; reviewed maintenance patches do not claim the next upstream release. // DISTRIBUTION_VERSION can still include an arbitrary package-specific release marker. #define RENDERDOC_VERSION_MAJOR 1 -#define RENDERDOC_VERSION_MINOR 47 +#define RENDERDOC_VERSION_MINOR 48 #define RDOC_INTERNAL_VERSION_STRINGIZE2(a) #a #define RDOC_INTERNAL_VERSION_STRINGIZE(a) RDOC_INTERNAL_VERSION_STRINGIZE2(a) diff --git a/renderdoc/core/core.cpp b/renderdoc/core/core.cpp index 2e11c4eae2b..f2ed29531e8 100644 --- a/renderdoc/core/core.cpp +++ b/renderdoc/core/core.cpp @@ -817,9 +817,7 @@ RenderDoc::~RenderDoc() UnloadCrashHandler(); } - for(auto it = m_ShutdownFunctions.begin(); it != m_ShutdownFunctions.end(); ++it) - (*it)(); - m_ShutdownFunctions.clear(); + ShutdownReplay(); for(size_t i = 0; i < m_Captures.size(); i++) { @@ -1077,13 +1075,21 @@ void RenderDoc::ShutdownReplay() // call shutdown functions early, as we only want to do these in the RenderDoc destructor if we // have no other choice (i.e. we're capturing). - for(auto it = m_ShutdownFunctions.begin(); it != m_ShutdownFunctions.end(); ++it) + rdcarray funcs; + { + SCOPED_LOCK(m_ShutdownLock); + funcs.swap(m_ShutdownFunctions); + } + + for(auto it = funcs.begin(); it != funcs.end(); ++it) (*it)(); - m_ShutdownFunctions.clear(); + funcs.clear(); } void RenderDoc::RegisterShutdownFunction(ShutdownFunction func) { + SCOPED_LOCK(m_ShutdownLock); + auto it = std::lower_bound(m_ShutdownFunctions.begin(), m_ShutdownFunctions.end(), func); if(it == m_ShutdownFunctions.end() || *it != func) m_ShutdownFunctions.insert(it - m_ShutdownFunctions.begin(), func); @@ -2511,9 +2517,9 @@ bool RenderDoc::DoesTrackedFileExist(const rdcstr &nickname) const // return false if the nickname already exists bool RenderDoc::AddTrackedFileReference(const rdcstr &nickname, const rdcstr &filepath) { - if(DoesTrackedFileExist(nickname)) - return false; SCOPED_WRITELOCK(m_TrackedFilesLock); + // do not allow duplicates, overwrite with latest if we add the same one + m_TrackedFiles.removeIf([nickname](const TrackedFile &f) { return f.nickname == nickname; }); m_TrackedFiles.emplace_back(nickname, filepath); return true; } diff --git a/renderdoc/core/core.h b/renderdoc/core/core.h index 57b44a429da..8af98c98ac9 100644 --- a/renderdoc/core/core.h +++ b/renderdoc/core/core.h @@ -738,6 +738,7 @@ class RenderDoc VulkanLayerCheck m_VulkanCheck; VulkanLayerInstall m_VulkanInstall; + Threading::CriticalSection m_ShutdownLock; rdcarray m_ShutdownFunctions; rdcarray m_EnvSetups; diff --git a/renderdoc/core/replay_proxy.cpp b/renderdoc/core/replay_proxy.cpp index d17cc6b195d..c9836f10ded 100644 --- a/renderdoc/core/replay_proxy.cpp +++ b/renderdoc/core/replay_proxy.cpp @@ -222,6 +222,8 @@ ReplayProxy::ReplayProxy(ReadSerialiser &reader, WriteSerialiser &writer, IRemot m_APIProps = m_Remote->GetAPIProperties(); + m_APIProps.rgpCapture = false; + InitRemoteExecutionThread(); if(m_Replay) @@ -367,6 +369,7 @@ APIProperties ReplayProxy::Proxied_GetAPIProperties(ParamSerialiser ¶mser, { ret.localRenderer = m_Proxy->GetAPIProperties().localRenderer; ret.remoteReplay = true; + ret.rgpCapture = false; } m_APIProps = ret; diff --git a/renderdoc/data/glsl/debug_sample.frag b/renderdoc/data/glsl/debug_sample.frag index 8117585da5d..31391dd684c 100644 --- a/renderdoc/data/glsl/debug_sample.frag +++ b/renderdoc/data/glsl/debug_sample.frag @@ -105,7 +105,7 @@ uniform PRECISION sampler2DRectShadow tex2DRectShadow; #endif -in vec4 input_uvwa; +in vec4 v2f_uvwa; out RESULT Output; #ifdef GATHER_OFFSETS @@ -204,12 +204,12 @@ RESULT DoFetch2DMSArray() RESULT DoSampleBias2D() { - return textureOffset(tex2D, input_uvwa.xy, fetch_offset.xy, debugsample.gles_bias); + return textureOffset(tex2D, v2f_uvwa.xy, fetch_offset.xy, debugsample.gles_bias); } RESULT DoSampleBias3D() { - return textureOffset(tex3D, input_uvwa.xyz, fetch_offset.xyz, debugsample.gles_bias); + return textureOffset(tex3D, v2f_uvwa.xyz, fetch_offset.xyz, debugsample.gles_bias); } RESULT DoSampleBiasCube() @@ -217,7 +217,7 @@ RESULT DoSampleBiasCube() #if FLOAT_TEX // no offsets for cubes - return texture(texCube, input_uvwa.xyz, debugsample.gles_bias); + return texture(texCube, v2f_uvwa.xyz, debugsample.gles_bias); #else // cubes are only handled on float type @@ -227,7 +227,7 @@ RESULT DoSampleBiasCube() RESULT DoSampleBias2DArray() { - return textureOffset(tex2DArray, input_uvwa.xyz, fetch_offset.xy, debugsample.gles_bias); + return textureOffset(tex2DArray, v2f_uvwa.xyz, fetch_offset.xy, debugsample.gles_bias); } #ifdef TEXSAMPLE_CUBE_ARRAY @@ -236,7 +236,7 @@ RESULT DoSampleBiasCubeArray() #if FLOAT_TEX // no offsets for cubes - return texture(texCubeArray, input_uvwa.xyzw, debugsample.gles_bias); + return texture(texCubeArray, v2f_uvwa.xyzw, debugsample.gles_bias); #else // cubes are only handled on float type @@ -249,7 +249,7 @@ RESULT DoSampleDrefBias2D() { #if FLOAT_TEX - return vec4(textureOffset(tex2DShadow, vec3(input_uvwa.xy, debugsample.compare), fetch_offset.xy, + return vec4(textureOffset(tex2DShadow, vec3(v2f_uvwa.xy, debugsample.compare), fetch_offset.xy, debugsample.gles_bias), 0, 0, 0); @@ -265,23 +265,23 @@ RESULT DoSampleDrefBias2D() #ifdef OPENGL_CORE RESULT DoQueryLod1D() { - return RESULT(FLOAT_CONV(textureQueryLod(tex1D, input_uvwa.x)), 0, 0); + return RESULT(FLOAT_CONV(textureQueryLod(tex1D, v2f_uvwa.x)), 0, 0); } RESULT DoQueryLod2D() { - return RESULT(FLOAT_CONV(textureQueryLod(tex2D, input_uvwa.xy)), 0, 0); + return RESULT(FLOAT_CONV(textureQueryLod(tex2D, v2f_uvwa.xy)), 0, 0); } RESULT DoQueryLod3D() { - return RESULT(FLOAT_CONV(textureQueryLod(tex3D, input_uvwa.xyz)), 0, 0); + return RESULT(FLOAT_CONV(textureQueryLod(tex3D, v2f_uvwa.xyz)), 0, 0); } RESULT DoQueryLodCube() { #if FLOAT_TEX - return RESULT(FLOAT_CONV(textureQueryLod(texCube, input_uvwa.xyz)), 0, 0); + return RESULT(FLOAT_CONV(textureQueryLod(texCube, v2f_uvwa.xyz)), 0, 0); #else // cubes are only handled on float type return RESULT(0, 0, 0, 0); @@ -290,19 +290,19 @@ RESULT DoQueryLodCube() RESULT DoQueryLod1DArray() { - return RESULT(FLOAT_CONV(textureQueryLod(tex1DArray, input_uvwa.x)), 0, 0); + return RESULT(FLOAT_CONV(textureQueryLod(tex1DArray, v2f_uvwa.x)), 0, 0); } RESULT DoQueryLod2DArray() { - return RESULT(FLOAT_CONV(textureQueryLod(tex2DArray, input_uvwa.xy)), 0, 0); + return RESULT(FLOAT_CONV(textureQueryLod(tex2DArray, v2f_uvwa.xy)), 0, 0); } #ifdef TEXSAMPLE_CUBE_ARRAY RESULT DoQueryLodCubeArray() { #if FLOAT_TEX - return RESULT(FLOAT_CONV(textureQueryLod(texCubeArray, input_uvwa.xyz)), 0, 0); + return RESULT(FLOAT_CONV(textureQueryLod(texCubeArray, v2f_uvwa.xyz)), 0, 0); #else // cubes are only handled on float type return RESULT(0, 0, 0, 0); diff --git a/renderdoc/data/glsl/shaderdebug_sample.vert b/renderdoc/data/glsl/shaderdebug_sample.vert index 60a38ea25c5..91a70c38728 100644 --- a/renderdoc/data/glsl/shaderdebug_sample.vert +++ b/renderdoc/data/glsl/shaderdebug_sample.vert @@ -24,7 +24,10 @@ #include "glsl_globals.h" -layout(location = 0) out vec4 uvwa; +#ifdef VULKAN +layout(location = 0) +#endif + out vec4 v2f_uvwa; #ifdef VULKAN @@ -59,9 +62,9 @@ void main(void) #endif gl_Position = verts[VERTEX_ID]; - uvwa = in_uvwa; + v2f_uvwa = in_uvwa; if(VERTEX_ID == 1) - uvwa.xyz += in_ddx.xyz; + v2f_uvwa.xyz += in_ddx.xyz; else if(VERTEX_ID == 2) - uvwa.xyz += in_ddy.xyz; + v2f_uvwa.xyz += in_ddy.xyz; } diff --git a/renderdoc/data/glsl/texdisplay.frag b/renderdoc/data/glsl/texdisplay.frag index 25cce28700e..b0298da3ec3 100644 --- a/renderdoc/data/glsl/texdisplay.frag +++ b/renderdoc/data/glsl/texdisplay.frag @@ -244,19 +244,19 @@ void main(void) if(ucol.x > range_min) col.x = (float(ucol.x - range_min) * texdisplay.InverseRangeSize); else - col.x = 0; + col.x = 0.0; if(ucol.y > range_min) col.y = (float(ucol.y - range_min) * texdisplay.InverseRangeSize); else - col.y = 0; + col.y = 0.0; if(ucol.z > range_min) col.z = (float(ucol.z - range_min) * texdisplay.InverseRangeSize); else - col.z = 0; + col.z = 0.0; if(ucol.w > range_min) col.w = (float(ucol.w - range_min) * texdisplay.InverseRangeSize); else - col.w = 0; + col.w = 0.0; } else if(sintTex) { diff --git a/renderdoc/driver/d3d11/d3d11_resources.cpp b/renderdoc/driver/d3d11/d3d11_resources.cpp index 29d46bd595c..d93511fc3eb 100644 --- a/renderdoc/driver/d3d11/d3d11_resources.cpp +++ b/renderdoc/driver/d3d11/d3d11_resources.cpp @@ -163,14 +163,15 @@ void WrappedShader::ShaderEntry::Reload() m_Built = false; *m_Details = ShaderReflection(); m_Access.clear(); - if(m_Bytecode.empty() && m_DXBCFile) + + if(m_DXBCFile) { - m_Bytecode = m_DXBCFile->GetInitialShaderBlob(); - if(m_Bytecode.empty()) - m_Bytecode = m_DXBCFile->GetShaderBlob(); + // recreate the DXBC file, this will pull any old debug info over + m_DXBCFile = new DXBC::DXBCContainer(m_DXBCFile, m_DebugInfoPath); + m_DXBCFile->SetShaderExts(GraphicsAPI::D3D11, m_ShaderExtSlot, ~0U); } - SAFE_DELETE(m_DXBCFile); - if(wasBuilt && (GetDXBC() != NULL)) + + if(wasBuilt) { BuildReflection(); m_Built = true; diff --git a/renderdoc/driver/d3d11/d3d11_resources.h b/renderdoc/driver/d3d11/d3d11_resources.h index c16e426b75d..4ffd6c9aca3 100644 --- a/renderdoc/driver/d3d11/d3d11_resources.h +++ b/renderdoc/driver/d3d11/d3d11_resources.h @@ -1000,8 +1000,8 @@ class WrappedShader { if(m_DXBCFile == NULL && !m_Bytecode.empty()) { - m_DXBCFile = new DXBC::DXBCContainer(m_Bytecode, m_DebugInfoPath, GraphicsAPI::D3D11, - m_ShaderExtSlot, ~0U); + m_DXBCFile = new DXBC::DXBCContainer(std::move(m_Bytecode), m_DebugInfoPath); + m_DXBCFile->SetShaderExts(GraphicsAPI::D3D11, m_ShaderExtSlot, ~0U); m_Bytecode.clear(); } return m_DXBCFile; diff --git a/renderdoc/driver/d3d12/d3d12_command_list1_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list1_wrap.cpp index 722a3296c5e..9ab7d4c6f79 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list1_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list1_wrap.cpp @@ -54,32 +54,21 @@ bool WrappedID3D12GraphicsCommandList::Serialise_AtomicCopyBufferUINT( m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - rdcarray deps; - deps.resize(Dependencies); - for(size_t i = 0; i < deps.size(); i++) - deps[i] = Unwrap(ppDependentResources[i]); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - ID3D12GraphicsCommandList1 *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); - Unwrap1(list)->AtomicCopyBufferUINT(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), - SrcOffset, Dependencies, deps.data(), - pDependentSubresourceRanges); - } - } - else - { rdcarray deps; deps.resize(Dependencies); for(size_t i = 0; i < deps.size(); i++) deps[i] = Unwrap(ppDependentResources[i]); - Unwrap1(pCommandList) - ->AtomicCopyBufferUINT(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), SrcOffset, - Dependencies, deps.data(), pDependentSubresourceRanges); - + Unwrap1(list)->AtomicCopyBufferUINT(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), + SrcOffset, Dependencies, deps.data(), + pDependentSubresourceRanges); + if(loading) { m_Cmd->AddEvent(); @@ -95,14 +84,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_AtomicCopyBufferUINT( if(pSrcBuffer == pDstBuffer) { - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(pSrcBuffer), ResourceUsage::Copy)); + eventNode.AddResourceUsage(GetResID(pSrcBuffer), ResourceUsage::Copy); } else { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pSrcBuffer), ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pDstBuffer), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(pSrcBuffer), ResourceUsage::CopySrc); + eventNode.AddResourceUsage(GetResID(pDstBuffer), ResourceUsage::CopyDst); } } } @@ -166,32 +153,21 @@ bool WrappedID3D12GraphicsCommandList::Serialise_AtomicCopyBufferUINT64( m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) - { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - rdcarray deps; - deps.resize(Dependencies); - for(size_t i = 0; i < deps.size(); i++) - deps[i] = Unwrap(ppDependentResources[i]); - - ID3D12GraphicsCommandList1 *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); - Unwrap1(list)->AtomicCopyBufferUINT64(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), - SrcOffset, Dependencies, deps.data(), - pDependentSubresourceRanges); - } - } - else + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; + rdcarray deps; deps.resize(Dependencies); for(size_t i = 0; i < deps.size(); i++) deps[i] = Unwrap(ppDependentResources[i]); - Unwrap1(pCommandList) - ->AtomicCopyBufferUINT64(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), SrcOffset, - Dependencies, deps.data(), pDependentSubresourceRanges); - + Unwrap1(list)->AtomicCopyBufferUINT64(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), + SrcOffset, Dependencies, deps.data(), + pDependentSubresourceRanges); + if(loading) { m_Cmd->AddEvent(); @@ -207,14 +183,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_AtomicCopyBufferUINT64( if(pSrcBuffer == pDstBuffer) { - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(pSrcBuffer), ResourceUsage::Copy)); + eventNode.AddResourceUsage(GetResID(pSrcBuffer), ResourceUsage::Copy); } else { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pSrcBuffer), ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pDstBuffer), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(pSrcBuffer), ResourceUsage::CopySrc); + eventNode.AddResourceUsage(GetResID(pDstBuffer), ResourceUsage::CopyDst); } } } @@ -289,23 +263,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_OMSetDepthBounds(SerialiserType bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap1(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->OMSetDepthBounds(Min, Max); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap1(list)->OMSetDepthBounds(Min, Max); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap1(pCommandList)->OMSetDepthBounds(Min, Max); - stateUpdate = true; } @@ -377,24 +346,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetSamplePositions( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap1(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetSamplePositions(NumSamplesPerPixel, NumPixels, pSamplePositions); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap1(list)->SetSamplePositions(NumSamplesPerPixel, NumPixels, pSamplePositions); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap1(pCommandList)->SetSamplePositions(NumSamplesPerPixel, NumPixels, pSamplePositions); - stateUpdate = true; } @@ -457,23 +420,16 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ResolveSubresourceRegion( m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) - { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandList1 *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); - Unwrap1(list)->ResolveSubresourceRegion(Unwrap(pDstResource), DstSubresource, DstX, DstY, - Unwrap(pSrcResource), SrcSubresource, pSrcRect, - Format, ResolveMode); - } - } - else + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - Unwrap1(pCommandList) - ->ResolveSubresourceRegion(Unwrap(pDstResource), DstSubresource, DstX, DstY, - Unwrap(pSrcResource), SrcSubresource, pSrcRect, Format, - ResolveMode); - + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; + + Unwrap1(list)->ResolveSubresourceRegion(Unwrap(pDstResource), DstSubresource, DstX, DstY, + Unwrap(pSrcResource), SrcSubresource, pSrcRect, + Format, ResolveMode); + if(loading) { m_Cmd->AddEvent(); @@ -489,15 +445,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ResolveSubresourceRegion( if(pSrcResource == pDstResource) { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pSrcResource), ResourceUsage::Resolve)); + eventNode.AddResourceUsage(GetResID(pSrcResource), ResourceUsage::Resolve); } else { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pSrcResource), ResourceUsage::ResolveSrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pDstResource), ResourceUsage::ResolveDst)); + eventNode.AddResourceUsage(GetResID(pSrcResource), ResourceUsage::ResolveSrc); + eventNode.AddResourceUsage(GetResID(pDstResource), ResourceUsage::ResolveDst); } } } @@ -564,23 +517,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetViewInstanceMask(SerialiserT bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap1(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->SetViewInstanceMask(Mask); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap1(list)->SetViewInstanceMask(Mask); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap1(pCommandList)->SetViewInstanceMask(Mask); - stateUpdate = true; } diff --git a/renderdoc/driver/d3d12/d3d12_command_list2_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list2_wrap.cpp index d1736b4a3fc..5e2f64f1e7a 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list2_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list2_wrap.cpp @@ -48,17 +48,13 @@ bool WrappedID3D12GraphicsCommandList::Serialise_WriteBufferImmediate( m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap2(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->WriteBufferImmediate(Count, pParams, pModes); - } - } - else - { - Unwrap2(pCommandList)->WriteBufferImmediate(Count, pParams, pModes); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; + + Unwrap2(list)->WriteBufferImmediate(Count, pParams, pModes); } } diff --git a/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp index 4ab2b1af092..deaf4316d22 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list4_wrap.cpp @@ -213,161 +213,106 @@ bool WrappedID3D12GraphicsCommandList::Serialise_BeginRenderPass( m_Cmd->m_LastCmdListID = GetResID(pCommandList); - // patch the parameters so that we point into our local CPU descriptor handles that are up - // to date + bool stateUpdate = false; + + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - D3D12_RENDER_PASS_RENDER_TARGET_DESC *rts = - (D3D12_RENDER_PASS_RENDER_TARGET_DESC *)pRenderTargets; - D3D12_RENDER_PASS_DEPTH_STENCIL_DESC *ds = - (D3D12_RENDER_PASS_DEPTH_STENCIL_DESC *)pDepthStencil; + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - for(UINT i = 0; i < NumRenderTargets; i++) - rts[i].cpuDescriptor = Unwrap(m_pDevice->GetDebugManager()->GetTempDescriptor(RTVs[i], i)); + // patch the parameters so that we point into our local CPU descriptor handles that are up + // to date + { + D3D12_RENDER_PASS_RENDER_TARGET_DESC *rts = + (D3D12_RENDER_PASS_RENDER_TARGET_DESC *)pRenderTargets; + D3D12_RENDER_PASS_DEPTH_STENCIL_DESC *ds = + (D3D12_RENDER_PASS_DEPTH_STENCIL_DESC *)pDepthStencil; - if(ds) - ds->cpuDescriptor = Unwrap(m_pDevice->GetDebugManager()->GetTempDescriptor(DSV)); - } + for(UINT i = 0; i < NumRenderTargets; i++) + rts[i].cpuDescriptor = Unwrap(m_pDevice->GetDebugManager()->GetTempDescriptor(RTVs[i], i)); - bool stateUpdate = false; + if(ds) + ds->cpuDescriptor = Unwrap(m_pDevice->GetDebugManager()->GetTempDescriptor(DSV)); + } - if(IsActiveReplaying(m_State)) - { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + // perform any clears needed + if((Flags & D3D12_RENDER_PASS_FLAG_RESUMING_PASS) == 0) { - // perform any clears needed - - if((Flags & D3D12_RENDER_PASS_FLAG_RESUMING_PASS) == 0) + for(UINT i = 0; i < NumRenderTargets; i++) { - for(UINT i = 0; i < NumRenderTargets; i++) + if(pRenderTargets[i].BeginningAccess.Type == D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR) { - if(pRenderTargets[i].BeginningAccess.Type == D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->ClearRenderTargetView(pRenderTargets[i].cpuDescriptor, - pRenderTargets[i].BeginningAccess.Clear.ClearValue.Color, - 0, NULL); - } + Unwrap(list)->ClearRenderTargetView( + pRenderTargets[i].cpuDescriptor, + pRenderTargets[i].BeginningAccess.Clear.ClearValue.Color, 0, NULL); } + } - if(pDepthStencil) - { - D3D12_CLEAR_FLAGS flags = {}; + if(pDepthStencil) + { + D3D12_CLEAR_FLAGS flags = {}; - if(pDepthStencil->DepthBeginningAccess.Type == - D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR) - flags |= D3D12_CLEAR_FLAG_DEPTH; - if(pDepthStencil->StencilBeginningAccess.Type == - D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR) - flags |= D3D12_CLEAR_FLAG_STENCIL; + if(pDepthStencil->DepthBeginningAccess.Type == D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR) + flags |= D3D12_CLEAR_FLAG_DEPTH; + if(pDepthStencil->StencilBeginningAccess.Type == + D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR) + flags |= D3D12_CLEAR_FLAG_STENCIL; - if(flags != 0) - { - // we can safely read from either depth/stencil clear values because if the access - // type isn't clear the corresponding flag will be unset - so whatever garbage value - // we have isn't used. - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->ClearDepthStencilView( - pDepthStencil->cpuDescriptor, flags, - pDepthStencil->DepthBeginningAccess.Clear.ClearValue.DepthStencil.Depth, - pDepthStencil->StencilBeginningAccess.Clear.ClearValue.DepthStencil.Stencil, - 0, NULL); - } + if(flags != 0) + { + // we can safely read from either depth/stencil clear values because if the access + // type isn't clear the corresponding flag will be unset - so whatever garbage value + // we have isn't used. + Unwrap(list)->ClearDepthStencilView( + pDepthStencil->cpuDescriptor, flags, + pDepthStencil->DepthBeginningAccess.Clear.ClearValue.DepthStencil.Depth, + pDepthStencil->StencilBeginningAccess.Clear.ClearValue.DepthStencil.Stencil, 0, NULL); } } + } - { - D3D12_CPU_DESCRIPTOR_HANDLE rtHandles[8]; - D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = {}; + { + D3D12_CPU_DESCRIPTOR_HANDLE rtHandles[8]; + D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = {}; - if(pDepthStencil) - dsvHandle = pDepthStencil->cpuDescriptor; + if(pDepthStencil) + dsvHandle = pDepthStencil->cpuDescriptor; - for(UINT i = 0; i < NumRenderTargets; i++) - rtHandles[i] = pRenderTargets[i].cpuDescriptor; + for(UINT i = 0; i < NumRenderTargets; i++) + rtHandles[i] = pRenderTargets[i].cpuDescriptor; - // need to unwrap here, as FromPortableHandle unwraps too. - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->OMSetRenderTargets(NumRenderTargets, rtHandles, FALSE, - dsvHandle.ptr ? &dsvHandle : NULL); - } - - // Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->BeginRenderPass(NumRenderTargets, - // pRenderTargets, pDepthStencil, Flags); + // need to unwrap here, as FromPortableHandle unwraps too. + Unwrap(list)->OMSetRenderTargets(NumRenderTargets, rtHandles, FALSE, + dsvHandle.ptr ? &dsvHandle : NULL); + } - if(m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - m_Cmd->m_Partial[D3D12CommandData::Primary].renderPassActive = true; - } + // Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->BeginRenderPass(NumRenderTargets, + // pRenderTargets, pDepthStencil, Flags); - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } - } - else - { - for(UINT i = 0; i < NumRenderTargets; i++) + if(m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - if(pRenderTargets[i].BeginningAccess.Type == D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR) - { - Unwrap(pCommandList) - ->ClearRenderTargetView(pRenderTargets[i].cpuDescriptor, - pRenderTargets[i].BeginningAccess.Clear.ClearValue.Color, 0, - NULL); - } + m_Cmd->m_Partial[D3D12CommandData::Primary].renderPassActive = true; } - if(pDepthStencil) + if(loading) { - D3D12_CLEAR_FLAGS flags = {}; + m_Cmd->AddEvent(); - if(pDepthStencil->DepthBeginningAccess.Type == D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR) - flags |= D3D12_CLEAR_FLAG_DEPTH; - if(pDepthStencil->StencilBeginningAccess.Type == D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR) - flags |= D3D12_CLEAR_FLAG_STENCIL; + ActionDescription action; + action.customName = StringFormat::Fmt( + "BeginRenderPass(%s)", + MakeRenderPassOpString(false, NumRenderTargets, pRenderTargets, pDepthStencil, Flags) + .c_str()); + action.flags |= ActionFlags::BeginPass | ActionFlags::PassBoundary; - if(flags != 0) - { - // we can safely read from either depth/stencil clear values because if the access - // type isn't clear the corresponding flag will be unset - so whatever garbage value - // we have isn't used. - Unwrap(pCommandList) - ->ClearDepthStencilView( - pDepthStencil->cpuDescriptor, flags, - pDepthStencil->DepthBeginningAccess.Clear.ClearValue.DepthStencil.Depth, - pDepthStencil->StencilBeginningAccess.Clear.ClearValue.DepthStencil.Stencil, 0, - NULL); - } + m_Cmd->AddAction(action); } - D3D12_CPU_DESCRIPTOR_HANDLE rtHandles[8]; - D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = {}; - - if(pDepthStencil) - dsvHandle = pDepthStencil->cpuDescriptor; - - for(UINT i = 0; i < NumRenderTargets; i++) - rtHandles[i] = pRenderTargets[i].cpuDescriptor; - - // need to unwrap here, as FromPortableHandle unwraps too. - Unwrap(pCommandList) - ->OMSetRenderTargets(NumRenderTargets, rtHandles, FALSE, dsvHandle.ptr ? &dsvHandle : NULL); - - // Unwrap4(pCommandList)->BeginRenderPass(NumRenderTargets, pRenderTargets, pDepthStencil, - // Flags); - - m_Cmd->AddEvent(); - - ActionDescription action; - action.customName = StringFormat::Fmt( - "BeginRenderPass(%s)", - MakeRenderPassOpString(false, NumRenderTargets, pRenderTargets, pDepthStencil, Flags).c_str()); - action.flags |= ActionFlags::BeginPass | ActionFlags::PassBoundary; - - m_Cmd->AddAction(action); - + stateUpdate = true; + } + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) + { stateUpdate = true; } @@ -559,128 +504,123 @@ bool WrappedID3D12GraphicsCommandList::Serialise_EndRenderPass(SerialiserType &s bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - const D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - // perform any resolves requested. We assume the presence of List1 to do the subregion - // resolve - for(size_t i = 0; i < state.rpRTs.size(); i++) - { - if(state.rpRTs[i].EndingAccess.Type == D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE) - { - const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS &r = - state.rpRTs[i].EndingAccess.Resolve; - - D3D12_RESOURCE_BARRIER barrier = {}; - barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; - barrier.Transition.pResource = Unwrap(r.pSrcResource); - barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET; - barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RESOLVE_SOURCE; - - Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->ResourceBarrier(1, &barrier); - - for(UINT s = 0; s < r.SubresourceCount; s++) - { - const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS &sub = - r.pSubresourceParameters[s]; - Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->ResolveSubresourceRegion(Unwrap(r.pDstResource), sub.DstSubresource, sub.DstX, - sub.DstY, Unwrap(r.pSrcResource), sub.SrcSubresource, - (D3D12_RECT *)&sub.SrcRect, r.Format, r.ResolveMode); - } - - std::swap(barrier.Transition.StateBefore, barrier.Transition.StateAfter); - - Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->ResourceBarrier(1, &barrier); - } - } + const D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; - if(state.rpDSV.cpuDescriptor.ptr != 0 && - (state.rpDSV.DepthEndingAccess.Type == D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE || - state.rpDSV.StencilEndingAccess.Type == D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE)) + // perform any resolves requested. We assume the presence of List1 to do the subregion resolve + for(size_t i = 0; i < state.rpRTs.size(); i++) + { + if(state.rpRTs[i].EndingAccess.Type == D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE) { + const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS &r = + state.rpRTs[i].EndingAccess.Resolve; + D3D12_RESOURCE_BARRIER barrier = {}; barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; - barrier.Transition.pResource = Unwrap(state.rpDSV.DepthEndingAccess.Resolve.pSrcResource); - barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_DEPTH_WRITE; + barrier.Transition.pResource = Unwrap(r.pSrcResource); + barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET; barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RESOLVE_SOURCE; - Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->ResourceBarrier(1, &barrier); + Unwrap4(list)->ResourceBarrier(1, &barrier); - if(state.rpDSV.DepthEndingAccess.Type == D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE) + for(UINT s = 0; s < r.SubresourceCount; s++) { - const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS &r = - state.rpDSV.DepthEndingAccess.Resolve; - - for(UINT s = 0; s < r.SubresourceCount; s++) - { - const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS &sub = - r.pSubresourceParameters[s]; - Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->ResolveSubresourceRegion(Unwrap(r.pDstResource), sub.DstSubresource, sub.DstX, - sub.DstY, Unwrap(r.pSrcResource), sub.SrcSubresource, - (D3D12_RECT *)&sub.SrcRect, r.Format, r.ResolveMode); - } - } - - if(state.rpDSV.StencilEndingAccess.Type == D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE) - { - const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS &r = - state.rpDSV.StencilEndingAccess.Resolve; - - for(UINT s = 0; s < r.SubresourceCount; s++) - { - const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS &sub = - r.pSubresourceParameters[s]; - Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->ResolveSubresourceRegion(Unwrap(r.pDstResource), sub.DstSubresource, sub.DstX, - sub.DstY, Unwrap(r.pSrcResource), sub.SrcSubresource, - (D3D12_RECT *)&sub.SrcRect, r.Format, r.ResolveMode); - } + const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS &sub = + r.pSubresourceParameters[s]; + Unwrap4(list)->ResolveSubresourceRegion(Unwrap(r.pDstResource), sub.DstSubresource, + sub.DstX, sub.DstY, Unwrap(r.pSrcResource), + sub.SrcSubresource, (D3D12_RECT *)&sub.SrcRect, + r.Format, r.ResolveMode); } std::swap(barrier.Transition.StateBefore, barrier.Transition.StateAfter); - Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->ResourceBarrier(1, &barrier); + Unwrap4(list)->ResourceBarrier(1, &barrier); } + } + + if(state.rpDSV.cpuDescriptor.ptr != 0 && + (state.rpDSV.DepthEndingAccess.Type == D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE || + state.rpDSV.StencilEndingAccess.Type == D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE)) + { + D3D12_RESOURCE_BARRIER barrier = {}; + barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + barrier.Transition.pResource = Unwrap(state.rpDSV.DepthEndingAccess.Resolve.pSrcResource); + barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_DEPTH_WRITE; + barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RESOLVE_SOURCE; - // Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->EndRenderPass(); + Unwrap4(list)->ResourceBarrier(1, &barrier); - if(m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) + if(state.rpDSV.DepthEndingAccess.Type == D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE) { - m_Cmd->m_Partial[D3D12CommandData::Primary].renderPassActive = false; + const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS &r = + state.rpDSV.DepthEndingAccess.Resolve; + + for(UINT s = 0; s < r.SubresourceCount; s++) + { + const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS &sub = + r.pSubresourceParameters[s]; + Unwrap4(list)->ResolveSubresourceRegion(Unwrap(r.pDstResource), sub.DstSubresource, + sub.DstX, sub.DstY, Unwrap(r.pSrcResource), + sub.SrcSubresource, (D3D12_RECT *)&sub.SrcRect, + r.Format, r.ResolveMode); + } + } + + if(state.rpDSV.StencilEndingAccess.Type == D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE) + { + const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS &r = + state.rpDSV.StencilEndingAccess.Resolve; + + for(UINT s = 0; s < r.SubresourceCount; s++) + { + const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS &sub = + r.pSubresourceParameters[s]; + Unwrap4(list)->ResolveSubresourceRegion(Unwrap(r.pDstResource), sub.DstSubresource, + sub.DstX, sub.DstY, Unwrap(r.pSrcResource), + sub.SrcSubresource, (D3D12_RECT *)&sub.SrcRect, + r.Format, r.ResolveMode); + } } - stateUpdate = true; + std::swap(barrier.Transition.StateBefore, barrier.Transition.StateAfter); + + Unwrap4(list)->ResourceBarrier(1, &barrier); } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) + + // Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->EndRenderPass(); + + if(m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - stateUpdate = true; + m_Cmd->m_Partial[D3D12CommandData::Primary].renderPassActive = false; } - } - else - { - // Unwrap4(pCommandList)->EndRenderPass(); - - m_Cmd->AddEvent(); - D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state; + if(loading) + { + m_Cmd->AddEvent(); - ActionDescription action; - action.customName = StringFormat::Fmt( - "EndRenderPass(%s)", - MakeRenderPassOpString(true, (UINT)state.rpRTs.size(), state.rpRTs.data(), - state.rpDSV.cpuDescriptor.ptr ? &state.rpDSV : NULL, state.rpFlags) - .c_str()); - action.flags |= ActionFlags::EndPass | ActionFlags::PassBoundary; + ActionDescription action; + action.customName = StringFormat::Fmt( + "EndRenderPass(%s)", + MakeRenderPassOpString(true, (UINT)state.rpRTs.size(), state.rpRTs.data(), + state.rpDSV.cpuDescriptor.ptr ? &state.rpDSV : NULL, state.rpFlags) + .c_str()); + action.flags |= ActionFlags::EndPass | ActionFlags::PassBoundary; - m_Cmd->AddAction(action); + m_Cmd->AddAction(action); + } stateUpdate = true; } + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) + { + stateUpdate = true; + } if(stateUpdate) { @@ -1372,40 +1312,37 @@ bool WrappedID3D12GraphicsCommandList::Serialise_EmitRaytracingAccelerationStruc m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->EmitRaytracingAccelerationStructurePostbuildInfo( - &Desc, NumSourceAccelerationStructures, pSourceAccelerationStructureData); - } - } - else - { - Unwrap4(pCommandList) - ->EmitRaytracingAccelerationStructurePostbuildInfo(&Desc, NumSourceAccelerationStructures, - pSourceAccelerationStructureData); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - m_Cmd->AddEvent(); + Unwrap4(list)->EmitRaytracingAccelerationStructurePostbuildInfo( + &Desc, NumSourceAccelerationStructures, pSourceAccelerationStructureData); - ActionDescription action; - action.copyDestination = WrappedID3D12Resource::GetResIDFromAddr(Desc.DestBuffer); - action.copyDestinationSubresource = Subresource(); + if(loading) + { + m_Cmd->AddEvent(); - action.flags |= ActionFlags::Copy; + ActionDescription action; + action.copyDestination = WrappedID3D12Resource::GetResIDFromAddr(Desc.DestBuffer); + action.copyDestinationSubresource = Subresource(); - m_Cmd->AddAction(action); + action.flags |= ActionFlags::Copy; - D3D12EventNode &eventNode = m_Cmd->GetLastEventNode(); + m_Cmd->AddAction(action); - eventNode.resourceUsage.push_back(make_rdcpair( - WrappedID3D12Resource::GetResIDFromAddr(Desc.DestBuffer), ResourceUsage::CopyDst)); - for(UINT i = 0; i < NumSourceAccelerationStructures; i++) - { - eventNode.resourceUsage.push_back(make_rdcpair( - WrappedID3D12Resource::GetResIDFromAddr(pSourceAccelerationStructureData[i]), - ResourceUsage::CopySrc)); + D3D12EventNode &eventNode = m_Cmd->GetLastEventNode(); + + eventNode.AddResourceUsage(WrappedID3D12Resource::GetResIDFromAddr(Desc.DestBuffer), + ResourceUsage::CopyDst); + for(UINT i = 0; i < NumSourceAccelerationStructures; i++) + { + eventNode.AddResourceUsage( + WrappedID3D12Resource::GetResIDFromAddr(pSourceAccelerationStructureData[i]), + ResourceUsage::CopySrc); + } } } } @@ -1479,37 +1416,17 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyRaytracingAccelerationStruc .Important(); SERIALISE_ELEMENT(Mode); + SERIALISE_CHECK_READ_ERRORS(); + if(IsReplayingAndReading()) { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandList4 *list = Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)); - - if(D3D12_Debug_RT_Auditing()) - { - RDCLOG("Recording copy from %llx to %llx on %s", SourceAccelerationStructureData, - DestAccelerationStructureData, ToStr(m_Cmd->m_LastCmdListID).c_str()); - } - - if(!D3D12_Debug_RT_Auditing()) - { - list->CopyRaytracingAccelerationStructure(DestAccelerationStructureData, - SourceAccelerationStructureData, Mode); - } - } - } - else - { - if(!D3D12_Debug_RT_Auditing()) - { - Unwrap4(pCommandList) - ->CopyRaytracingAccelerationStructure(DestAccelerationStructureData, - SourceAccelerationStructureData, Mode); - } + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; if(D3D12_Debug_RT_Auditing()) { @@ -1517,15 +1434,23 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyRaytracingAccelerationStruc DestAccelerationStructureData, ToStr(m_Cmd->m_LastCmdListID).c_str()); } - m_Cmd->AddEvent(); + if(!D3D12_Debug_RT_Auditing()) + { + Unwrap4(list)->CopyRaytracingAccelerationStructure(DestAccelerationStructureData, + SourceAccelerationStructureData, Mode); + } - ActionDescription actionDesc; - actionDesc.flags |= ActionFlags::BuildAccStruct; - m_Cmd->AddAction(actionDesc); + if(loading) + { + m_Cmd->AddEvent(); + + ActionDescription actionDesc; + actionDesc.flags |= ActionFlags::BuildAccStruct; + m_Cmd->AddAction(actionDesc); + } } } - SERIALISE_CHECK_READ_ERRORS(); return true; } @@ -1742,23 +1667,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetPipelineState1(SerialiserTyp bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap4(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->SetPipelineState1(Unwrap(pStateObject)); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap4(list)->SetPipelineState1(Unwrap(pStateObject)); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap4(pCommandList)->SetPipelineState1(Unwrap(pStateObject)); - stateUpdate = true; } @@ -1826,67 +1746,48 @@ bool WrappedID3D12GraphicsCommandList::Serialise_DispatchRays(SerialiserType &se Desc.Width = Desc.Height = Desc.Depth = 0; } - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - // this call will copy the specified buffers containing shader records and patch them. We get - // a reference to the lookup buffer used as well as a reference to the scratch buffer - // containing the patched shader records. - PatchedRayDispatch patchedDispatch = - GetResourceManager()->GetRTManager()->PatchRayDispatch(Unwrap4(list), state.heaps, Desc); + // this call will copy the specified buffers containing shader records and patch them. + // We get a reference to the lookup buffer used as well as a reference to the scratch + // buffer containing the patched shader records. + PatchedRayDispatch patchedDispatch = + GetResourceManager()->GetRTManager()->PatchRayDispatch(Unwrap4(list), state.heaps, Desc); - // restore state that would have been mutated by the patching process - Unwrap4(list)->SetComputeRootSignature( - Unwrap(GetResourceManager()->GetResAs(state.compute.rootsig))); - Unwrap4(list)->SetPipelineState1( - Unwrap(GetResourceManager()->GetResAs(state.stateobj))); - state.ApplyComputeRootElementsUnwrapped(Unwrap4(list)); + // restore state that would have been mutated by the patching process + Unwrap4(list)->SetComputeRootSignature( + Unwrap(GetResourceManager()->GetResAs(state.compute.rootsig))); + Unwrap4(list)->SetPipelineState1( + Unwrap(GetResourceManager()->GetResAs(state.stateobj))); + state.ApplyComputeRootElementsUnwrapped(Unwrap4(list)); - m_Cmd->m_RayDispatches.push_back(std::move(patchedDispatch)); + m_Cmd->m_RayDispatches.push_back(std::move(patchedDispatch)); - uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::DispatchRay); + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::DispatchRay) : 0; + Unwrap4(list)->DispatchRays(&patchedDispatch.desc); + if(eventId && m_Cmd->m_ActionCallback->PostDispatch(eventId, list)) + { Unwrap4(list)->DispatchRays(&patchedDispatch.desc); - if(eventId && m_Cmd->m_ActionCallback->PostDispatch(eventId, list)) - { - Unwrap4(list)->DispatchRays(&patchedDispatch.desc); - m_Cmd->m_ActionCallback->PostRedispatch(eventId, list); - } + m_Cmd->m_ActionCallback->PostRedispatch(eventId, list); } - } - else - { - // this call will copy the specified buffers containing shader records and patch them. We get - // a reference to the lookup buffer used as well as a reference to the scratch buffer - // containing the patched shader records. - PatchedRayDispatch patchedDispatch = GetResourceManager()->GetRTManager()->PatchRayDispatch( - Unwrap4(pCommandList), state.heaps, Desc); - - // restore state that would have been mutated by the patching process - Unwrap4(pCommandList) - ->SetComputeRootSignature( - Unwrap(GetResourceManager()->GetResAs(state.compute.rootsig))); - Unwrap4(pCommandList) - ->SetPipelineState1( - Unwrap(GetResourceManager()->GetResAs(state.stateobj))); - state.ApplyComputeRootElementsUnwrapped(Unwrap4(pCommandList)); - m_Cmd->m_RayDispatches.push_back(patchedDispatch); - - Unwrap4(pCommandList)->DispatchRays(&patchedDispatch.desc); - - m_Cmd->AddEvent(); + if(loading) + { + m_Cmd->AddEvent(); - ActionDescription action; - action.dispatchDimension[0] = Desc.Width; - action.dispatchDimension[1] = Desc.Height; - action.dispatchDimension[2] = Desc.Depth; + ActionDescription action; + action.dispatchDimension[0] = Desc.Width; + action.dispatchDimension[1] = Desc.Height; + action.dispatchDimension[2] = Desc.Depth; - action.flags |= ActionFlags::DispatchRay; + action.flags |= ActionFlags::DispatchRay; - m_Cmd->AddAction(action); + m_Cmd->AddAction(action); + } } } @@ -1895,9 +1796,9 @@ bool WrappedID3D12GraphicsCommandList::Serialise_DispatchRays(SerialiserType &se void WrappedID3D12GraphicsCommandList::DispatchRays(_In_ const D3D12_DISPATCH_RAYS_DESC *pDesc) { - // this call will copy the specified buffers containing shader records and patch them. We get a - // reference to the lookup buffer used as well as a reference to the scratch buffer containing the - // patched shader records. + // this call will copy the specified buffers containing shader records and patch them. We get + // a reference to the lookup buffer used as well as a reference to the scratch buffer + // containing the patched shader records. PatchedRayDispatch patchedDispatch = GetResourceManager()->GetRTManager()->PatchRayDispatch( m_pList4, m_CaptureComputeState.heaps, *pDesc); diff --git a/renderdoc/driver/d3d12/d3d12_command_list5_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list5_wrap.cpp index 9bafc58ad06..ff20042cb33 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list5_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list5_wrap.cpp @@ -69,24 +69,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_RSSetShadingRate( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap5(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->RSSetShadingRate(baseShadingRate, combiners); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap5(list)->RSSetShadingRate(baseShadingRate, combiners); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap5(pCommandList)->RSSetShadingRate(baseShadingRate, combiners); - stateUpdate = true; } @@ -163,24 +157,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_RSSetShadingRateImage(Serialise bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap5(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->RSSetShadingRateImage(Unwrap(shadingRateImage)); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap5(list)->RSSetShadingRateImage(Unwrap(shadingRateImage)); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap5(pCommandList)->RSSetShadingRateImage(Unwrap(shadingRateImage)); - stateUpdate = true; } diff --git a/renderdoc/driver/d3d12/d3d12_command_list6_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list6_wrap.cpp index 5182caeb858..81c076eeef7 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list6_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list6_wrap.cpp @@ -56,35 +56,33 @@ bool WrappedID3D12GraphicsCommandList::Serialise_DispatchMesh(SerialiserType &se m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::MeshDispatch); + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::MeshDispatch) : 0; + Unwrap6(list)->DispatchMesh(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); + if(eventId && m_Cmd->m_ActionCallback->PostDraw(eventId, list)) + { Unwrap6(list)->DispatchMesh(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); - if(eventId && m_Cmd->m_ActionCallback->PostDraw(eventId, list)) - { - Unwrap6(list)->DispatchMesh(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); - m_Cmd->m_ActionCallback->PostRedraw(eventId, list); - } + m_Cmd->m_ActionCallback->PostRedraw(eventId, list); } - } - else - { - Unwrap6(pCommandList)->DispatchMesh(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); - m_Cmd->AddEvent(); + if(loading) + { + m_Cmd->AddEvent(); - ActionDescription action; - action.dispatchDimension[0] = ThreadGroupCountX; - action.dispatchDimension[1] = ThreadGroupCountY; - action.dispatchDimension[2] = ThreadGroupCountZ; + ActionDescription action; + action.dispatchDimension[0] = ThreadGroupCountX; + action.dispatchDimension[1] = ThreadGroupCountY; + action.dispatchDimension[2] = ThreadGroupCountZ; - action.flags |= ActionFlags::MeshDispatch; + action.flags |= ActionFlags::MeshDispatch; - m_Cmd->AddAction(action); + m_Cmd->AddAction(action); + } } } diff --git a/renderdoc/driver/d3d12/d3d12_command_list7_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list7_wrap.cpp index 79a4baf0826..9917b935a54 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list7_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list7_wrap.cpp @@ -47,136 +47,117 @@ bool WrappedID3D12GraphicsCommandList::Serialise_Barrier(SerialiserType &ser, UI m_Cmd->m_LastCmdListID = GetResID(pCommandList); - rdcarray filteredUnwrappedBuf; - rdcarray filteredUnwrappedTex; - rdcarray filteredUnwrapped; - - // resize so we can take pointers - for(UINT i = 0; i < NumBarrierGroups; i++) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(pBarrierGroups[i].Type == D3D12_BARRIER_TYPE_BUFFER) - filteredUnwrappedBuf.resize(filteredUnwrappedBuf.size() + pBarrierGroups[i].NumBarriers); - else if(pBarrierGroups[i].Type == D3D12_BARRIER_TYPE_TEXTURE) - filteredUnwrappedTex.resize(filteredUnwrappedTex.size() + pBarrierGroups[i].NumBarriers); - } + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - D3D12_TEXTURE_BARRIER *tex = filteredUnwrappedTex.data(); - D3D12_BUFFER_BARRIER *buf = filteredUnwrappedBuf.data(); + rdcarray filteredUnwrappedBuf; + rdcarray filteredUnwrappedTex; + rdcarray filteredUnwrapped; - D3D12EventNode &eventNode = m_Cmd->m_LoadingEventNode; + // resize so we can take pointers + for(UINT i = 0; i < NumBarrierGroups; i++) + { + if(pBarrierGroups[i].Type == D3D12_BARRIER_TYPE_BUFFER) + filteredUnwrappedBuf.resize(filteredUnwrappedBuf.size() + pBarrierGroups[i].NumBarriers); + else if(pBarrierGroups[i].Type == D3D12_BARRIER_TYPE_TEXTURE) + filteredUnwrappedTex.resize(filteredUnwrappedTex.size() + pBarrierGroups[i].NumBarriers); + } - // filter out any barriers that reference a NULL resource - this means the resource wasn't used - // elsewhere so was discarded from the capture - for(UINT i = 0; i < NumBarrierGroups; i++) - { - D3D12_BARRIER_GROUP group = pBarrierGroups[i]; + D3D12_TEXTURE_BARRIER *tex = filteredUnwrappedTex.data(); + D3D12_BUFFER_BARRIER *buf = filteredUnwrappedBuf.data(); - if(pBarrierGroups[i].Type == D3D12_BARRIER_TYPE_BUFFER) + // filter out any barriers that reference a NULL resource - this means the resource wasn't + // used elsewhere so was discarded from the capture + for(UINT i = 0; i < NumBarrierGroups; i++) { - const UINT num = group.NumBarriers; + D3D12_BARRIER_GROUP group = pBarrierGroups[i]; - group.NumBarriers = 0; - - for(UINT b = 0; b < num; b++) + if(pBarrierGroups[i].Type == D3D12_BARRIER_TYPE_BUFFER) { - ID3D12Resource *res = group.pBufferBarriers[b].pResource; - if(res) + const UINT num = group.NumBarriers; + + group.NumBarriers = 0; + + for(UINT b = 0; b < num; b++) { - buf[group.NumBarriers] = group.pBufferBarriers[b]; - buf[group.NumBarriers].pResource = Unwrap(res); - group.NumBarriers++; + ID3D12Resource *res = group.pBufferBarriers[b].pResource; + if(res) + { + buf[group.NumBarriers] = group.pBufferBarriers[b]; + buf[group.NumBarriers].pResource = Unwrap(res); + group.NumBarriers++; - if(IsLoading(m_State)) - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(res), ResourceUsage::Barrier)); + if(IsLoading(m_State)) + m_Cmd->AddEventResourceUsage(GetResID(res), ResourceUsage::Barrier); + } } - } - group.pBufferBarriers = buf; - buf += group.NumBarriers; + group.pBufferBarriers = buf; + buf += group.NumBarriers; - if(group.NumBarriers > 0) - filteredUnwrapped.push_back(group); - } - else if(pBarrierGroups[i].Type == D3D12_BARRIER_TYPE_TEXTURE) - { - const UINT num = group.NumBarriers; + if(group.NumBarriers > 0) + filteredUnwrapped.push_back(group); + } + else if(pBarrierGroups[i].Type == D3D12_BARRIER_TYPE_TEXTURE) + { + const UINT num = group.NumBarriers; - group.NumBarriers = 0; + group.NumBarriers = 0; - for(UINT b = 0; b < num; b++) - { - ID3D12Resource *res = group.pTextureBarriers[b].pResource; - if(res) + for(UINT b = 0; b < num; b++) { - tex[group.NumBarriers] = group.pTextureBarriers[b]; - tex[group.NumBarriers].pResource = Unwrap(res); - group.NumBarriers++; + ID3D12Resource *res = group.pTextureBarriers[b].pResource; + if(res) + { + tex[group.NumBarriers] = group.pTextureBarriers[b]; + tex[group.NumBarriers].pResource = Unwrap(res); + group.NumBarriers++; - if(IsLoading(m_State)) - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(res), ResourceUsage::Barrier)); + if(IsLoading(m_State)) + m_Cmd->AddEventResourceUsage(GetResID(res), ResourceUsage::Barrier); + } } - } - group.pTextureBarriers = tex; - tex += group.NumBarriers; + group.pTextureBarriers = tex; + tex += group.NumBarriers; - if(group.NumBarriers > 0) + if(group.NumBarriers > 0) + filteredUnwrapped.push_back(group); + } + else + { filteredUnwrapped.push_back(group); + } } - else - { - filteredUnwrapped.push_back(group); - } - } - if(IsActiveReplaying(m_State)) - { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + if(!filteredUnwrapped.empty()) { - ID3D12GraphicsCommandListX *rerecord = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); - pCommandList = rerecord; + Unwrap7(list)->Barrier((UINT)filteredUnwrapped.size(), filteredUnwrapped.data()); - if(!filteredUnwrapped.empty()) + if(!loading && m_pDevice->GetReplayOptions().optimisation != ReplayOptimisationLevel::Fastest) { - Unwrap7(pCommandList)->Barrier((UINT)filteredUnwrapped.size(), filteredUnwrapped.data()); - - if(m_pDevice->GetReplayOptions().optimisation != ReplayOptimisationLevel::Fastest) + for(UINT i = 0; i < NumBarrierGroups; i++) { - for(UINT i = 0; i < NumBarrierGroups; i++) + if(pBarrierGroups[i].Type == D3D12_BARRIER_TYPE_TEXTURE) { - if(pBarrierGroups[i].Type == D3D12_BARRIER_TYPE_TEXTURE) + for(UINT b = 0; b < pBarrierGroups[i].NumBarriers; b++) { - for(UINT b = 0; b < pBarrierGroups[i].NumBarriers; b++) + const D3D12_TEXTURE_BARRIER &barrier = pBarrierGroups[i].pTextureBarriers[b]; + if(barrier.pResource && (barrier.Flags & D3D12_TEXTURE_BARRIER_FLAG_DISCARD)) { - const D3D12_TEXTURE_BARRIER &barrier = pBarrierGroups[i].pTextureBarriers[b]; - if(barrier.pResource && (barrier.Flags & D3D12_TEXTURE_BARRIER_FLAG_DISCARD)) - { - m_pDevice->GetDebugManager()->FillWithDiscardPattern( - rerecord, m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state, - DiscardType::UndefinedTransition, barrier.pResource, NULL, - barrier.LayoutAfter); - } + m_pDevice->GetDebugManager()->FillWithDiscardPattern( + list, m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state, + DiscardType::UndefinedTransition, barrier.pResource, NULL, barrier.LayoutAfter); } } } } } } - else - { - pCommandList = NULL; - } - } - else - { - if(!filteredUnwrapped.empty()) - { - Unwrap7(pCommandList)->Barrier((UINT)filteredUnwrapped.size(), filteredUnwrapped.data()); - } - } - if(pCommandList) - { ResourceId cmd = GetResID(pCommandList); for(UINT i = 0; i < NumBarrierGroups; i++) diff --git a/renderdoc/driver/d3d12/d3d12_command_list8_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list8_wrap.cpp index 7ee0aba48d0..0fc6ee4c05c 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list8_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list8_wrap.cpp @@ -49,24 +49,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_OMSetFrontAndBackStencilRef(Ser bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap8(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->OMSetFrontAndBackStencilRef(FrontStencilRef, BackStencilRef); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap8(list)->OMSetFrontAndBackStencilRef(FrontStencilRef, BackStencilRef); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap8(pCommandList)->OMSetFrontAndBackStencilRef(FrontStencilRef, BackStencilRef); - stateUpdate = true; } diff --git a/renderdoc/driver/d3d12/d3d12_command_list9_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list9_wrap.cpp index ed97181417d..b1f4b9009f5 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list9_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list9_wrap.cpp @@ -50,24 +50,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_RSSetDepthBias(SerialiserType & bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap9(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->RSSetDepthBias(DepthBias, DepthBiasClamp, SlopeScaledDepthBias); - - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; + + Unwrap9(list)->RSSetDepthBias(DepthBias, DepthBiasClamp, SlopeScaledDepthBias); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap9(pCommandList)->RSSetDepthBias(DepthBias, DepthBiasClamp, SlopeScaledDepthBias); - stateUpdate = true; } @@ -122,24 +116,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_IASetIndexBufferStripCutValue( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap9(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->IASetIndexBufferStripCutValue(IBStripCutValue); - - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; + + Unwrap9(list)->IASetIndexBufferStripCutValue(IBStripCutValue); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap9(pCommandList)->IASetIndexBufferStripCutValue(IBStripCutValue); - stateUpdate = true; } diff --git a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp index 03e8509d81a..882311c475b 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp @@ -471,82 +471,63 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ResourceBarrier( { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - rdcarray filtered; + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - filtered.reserve(NumBarriers); + bool loading = IsLoading(m_State); + if(!loading) + pCommandList = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); - // non-transition barriers allow NULLs, but for transition barriers filter out any that - // reference the NULL resource - this means the resource wasn't used elsewhere so was - // discarded from the capture - for(UINT i = 0; i < NumBarriers; i++) + rdcarray filtered; { - if(pBarriers[i].Type != D3D12_RESOURCE_BARRIER_TYPE_TRANSITION || - pBarriers[i].Transition.pResource) - { - filtered.push_back(pBarriers[i]); - - // unwrap it - D3D12_RESOURCE_BARRIER &b = filtered.back(); + filtered.reserve(NumBarriers); - ID3D12Resource *res1 = NULL, *res2 = NULL; - - if(b.Type == D3D12_RESOURCE_BARRIER_TYPE_TRANSITION) - { - res1 = b.Transition.pResource; - b.Transition.pResource = Unwrap(b.Transition.pResource); - } - else if(b.Type == D3D12_RESOURCE_BARRIER_TYPE_ALIASING) - { - res1 = b.Aliasing.pResourceBefore; - res2 = b.Aliasing.pResourceAfter; - b.Aliasing.pResourceBefore = Unwrap(b.Aliasing.pResourceBefore); - b.Aliasing.pResourceAfter = Unwrap(b.Aliasing.pResourceAfter); - } - else if(b.Type == D3D12_RESOURCE_BARRIER_TYPE_UAV) + // non-transition barriers allow NULLs, but for transition barriers filter out any that + // reference the NULL resource - this means the resource wasn't used elsewhere so was + // discarded from the capture + for(UINT i = 0; i < NumBarriers; i++) + { + if(pBarriers[i].Type != D3D12_RESOURCE_BARRIER_TYPE_TRANSITION || + pBarriers[i].Transition.pResource) { - res1 = b.UAV.pResource; - b.UAV.pResource = Unwrap(b.UAV.pResource); - } + filtered.push_back(pBarriers[i]); - if(IsLoading(m_State) && (res1 || res2)) - { - D3D12EventNode &eventNode = m_Cmd->m_LoadingEventNode; + // unwrap it + D3D12_RESOURCE_BARRIER &b = filtered.back(); - if(res1) + ID3D12Resource *res1 = NULL, *res2 = NULL; + + if(b.Type == D3D12_RESOURCE_BARRIER_TYPE_TRANSITION) + { + res1 = b.Transition.pResource; + b.Transition.pResource = Unwrap(b.Transition.pResource); + } + else if(b.Type == D3D12_RESOURCE_BARRIER_TYPE_ALIASING) { - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(res1), ResourceUsage::Barrier)); + res1 = b.Aliasing.pResourceBefore; + res2 = b.Aliasing.pResourceAfter; + b.Aliasing.pResourceBefore = Unwrap(b.Aliasing.pResourceBefore); + b.Aliasing.pResourceAfter = Unwrap(b.Aliasing.pResourceAfter); } - if(res2) + else if(b.Type == D3D12_RESOURCE_BARRIER_TYPE_UAV) { - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(res2), ResourceUsage::Barrier)); + res1 = b.UAV.pResource; + b.UAV.pResource = Unwrap(b.UAV.pResource); + } + + if(loading && (res1 || res2)) + { + if(res1) + m_Cmd->AddEventResourceUsage(GetResID(res1), ResourceUsage::Barrier); + if(res2) + m_Cmd->AddEventResourceUsage(GetResID(res2), ResourceUsage::Barrier); } } } } - } - if(IsActiveReplaying(m_State)) - { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - pCommandList = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); - - if(!filtered.empty()) - Unwrap(pCommandList)->ResourceBarrier((UINT)filtered.size(), &filtered[0]); - } - else - { - pCommandList = NULL; - } - } - else - { if(!filtered.empty()) Unwrap(pCommandList)->ResourceBarrier((UINT)filtered.size(), &filtered[0]); - } - if(pCommandList) - { ResourceId cmd = GetResID(pCommandList); for(UINT i = 0; i < NumBarriers; i++) @@ -700,23 +681,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_IASetPrimitiveTopology( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->IASetPrimitiveTopology(PrimitiveTopology); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->IASetPrimitiveTopology(PrimitiveTopology); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->IASetPrimitiveTopology(PrimitiveTopology); - stateUpdate = true; } @@ -763,23 +739,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_RSSetViewports(SerialiserType & bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->RSSetViewports(NumViewports, pViewports); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->RSSetViewports(NumViewports, pViewports); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->RSSetViewports(NumViewports, pViewports); - stateUpdate = true; } @@ -830,23 +801,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_RSSetScissorRects(SerialiserTyp bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->RSSetScissorRects(NumRects, pRects); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->RSSetScissorRects(NumRects, pRects); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->RSSetScissorRects(NumRects, pRects); - stateUpdate = true; } @@ -895,23 +861,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_OMSetBlendFactor(SerialiserType bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->OMSetBlendFactor(BlendFactor); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->OMSetBlendFactor(BlendFactor); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->OMSetBlendFactor(BlendFactor); - stateUpdate = true; } @@ -952,23 +913,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_OMSetStencilRef(SerialiserType bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->OMSetStencilRef(StencilRef); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->OMSetStencilRef(StencilRef); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->OMSetStencilRef(StencilRef); - stateUpdate = true; } @@ -1023,24 +979,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetDescriptorHeaps( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetDescriptorHeaps(NumDescriptorHeaps, heaps.data()); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetDescriptorHeaps(NumDescriptorHeaps, heaps.data()); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->SetDescriptorHeaps(NumDescriptorHeaps, heaps.data()); - stateUpdate = true; } @@ -1096,25 +1046,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_IASetIndexBuffer(SerialiserType bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->IASetIndexBuffer(pView); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->IASetIndexBuffer(pView); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - ID3D12GraphicsCommandList *list = pCommandList; - - list->IASetIndexBuffer(pView); - stateUpdate = true; } @@ -1176,24 +1119,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_IASetVertexBuffers( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->IASetVertexBuffers(StartSlot, NumViews, pViews); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->IASetVertexBuffers(StartSlot, NumViews, pViews); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->IASetVertexBuffers(StartSlot, NumViews, pViews); - stateUpdate = true; } @@ -1255,23 +1192,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SOSetTargets( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->SOSetTargets(StartSlot, NumViews, pViews); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SOSetTargets(StartSlot, NumViews, pViews); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->SOSetTargets(StartSlot, NumViews, pViews); - stateUpdate = true; } @@ -1334,23 +1266,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetPipelineState(SerialiserType bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID))->SetPipelineState(Unwrap(pPipelineState)); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetPipelineState(Unwrap(pPipelineState)); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->SetPipelineState(Unwrap(pPipelineState)); - stateUpdate = true; } @@ -1516,27 +1443,19 @@ bool WrappedID3D12GraphicsCommandList::Serialise_OMSetRenderTargets( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->OMSetRenderTargets((UINT)unwrappedRTs.size(), unwrappedRTs.data(), FALSE, - unwrappedDSV.ptr ? &unwrappedDSV : NULL); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->OMSetRenderTargets((UINT)unwrappedRTs.size(), unwrappedRTs.data(), FALSE, + unwrappedDSV.ptr ? &unwrappedDSV : NULL); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList) - ->OMSetRenderTargets((UINT)unwrappedRTs.size(), unwrappedRTs.data(), FALSE, - unwrappedDSV.ptr ? &unwrappedDSV : NULL); - stateUpdate = true; } @@ -1627,24 +1546,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootSignature( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetComputeRootSignature(Unwrap(pRootSignature)); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetComputeRootSignature(Unwrap(pRootSignature)); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->SetComputeRootSignature(Unwrap(pRootSignature)); - stateUpdate = true; } @@ -1714,24 +1627,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootDescriptorTable( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetComputeRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetComputeRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->SetComputeRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); - stateUpdate = true; } @@ -1829,25 +1736,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRoot32BitConstant( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetComputeRoot32BitConstant(RootParameterIndex, SrcData, DestOffsetIn32BitValues); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetComputeRoot32BitConstant(RootParameterIndex, SrcData, DestOffsetIn32BitValues); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList) - ->SetComputeRoot32BitConstant(RootParameterIndex, SrcData, DestOffsetIn32BitValues); - stateUpdate = true; } @@ -1910,27 +1810,19 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRoot32BitConstants( UINT dummyData; // nVidia driver crashes if pSrcData is NULL even with Num32BitValuesToSet = 0 const UINT *pValidSrcData = (Num32BitValuesToSet > 0) ? pSrcData : &dummyData; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetComputeRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, pValidSrcData, - DestOffsetIn32BitValues); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetComputeRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, + pValidSrcData, DestOffsetIn32BitValues); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList) - ->SetComputeRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, pValidSrcData, - DestOffsetIn32BitValues); - stateUpdate = true; } @@ -2000,24 +1892,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootConstantBufferVie bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetComputeRootConstantBufferView(RootParameterIndex, BufferLocation); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetComputeRootConstantBufferView(RootParameterIndex, BufferLocation); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->SetComputeRootConstantBufferView(RootParameterIndex, BufferLocation); - stateUpdate = true; } @@ -2085,24 +1971,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootShaderResourceVie bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetComputeRootShaderResourceView(RootParameterIndex, BufferLocation); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetComputeRootShaderResourceView(RootParameterIndex, BufferLocation); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->SetComputeRootShaderResourceView(RootParameterIndex, BufferLocation); - stateUpdate = true; } @@ -2170,24 +2050,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootUnorderedAccessVi bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetComputeRootUnorderedAccessView(RootParameterIndex, BufferLocation); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetComputeRootUnorderedAccessView(RootParameterIndex, BufferLocation); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->SetComputeRootUnorderedAccessView(RootParameterIndex, BufferLocation); - stateUpdate = true; } @@ -2250,24 +2124,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootSignature( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetGraphicsRootSignature(Unwrap(pRootSignature)); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetGraphicsRootSignature(Unwrap(pRootSignature)); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->SetGraphicsRootSignature(Unwrap(pRootSignature)); - stateUpdate = true; } @@ -2326,24 +2194,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootDescriptorTable( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetGraphicsRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetGraphicsRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->SetGraphicsRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor)); - stateUpdate = true; } @@ -2433,25 +2295,19 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRoot32BitConstant( bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetGraphicsRoot32BitConstant(RootParameterIndex, SrcData, DestOffsetIn32BitValues); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetGraphicsRoot32BitConstant(RootParameterIndex, SrcData, + DestOffsetIn32BitValues); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList) - ->SetGraphicsRoot32BitConstant(RootParameterIndex, SrcData, DestOffsetIn32BitValues); - stateUpdate = true; } @@ -2508,27 +2364,19 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRoot32BitConstants( UINT dummyData; // nVidia driver crashes if pSrcData is NULL even with Num32BitValuesToSet = 0 const UINT *pValidSrcData = (Num32BitValuesToSet > 0) ? pSrcData : &dummyData; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetGraphicsRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, pValidSrcData, - DestOffsetIn32BitValues); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetGraphicsRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, + pValidSrcData, DestOffsetIn32BitValues); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList) - ->SetGraphicsRoot32BitConstants(RootParameterIndex, Num32BitValuesToSet, pValidSrcData, - DestOffsetIn32BitValues); - stateUpdate = true; } @@ -2592,24 +2440,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootConstantBufferVi bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetGraphicsRootConstantBufferView(RootParameterIndex, BufferLocation); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetGraphicsRootConstantBufferView(RootParameterIndex, BufferLocation); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->SetGraphicsRootConstantBufferView(RootParameterIndex, BufferLocation); - stateUpdate = true; } @@ -2671,24 +2513,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootShaderResourceVi bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetGraphicsRootShaderResourceView(RootParameterIndex, BufferLocation); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetGraphicsRootShaderResourceView(RootParameterIndex, BufferLocation); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->SetGraphicsRootShaderResourceView(RootParameterIndex, BufferLocation); - stateUpdate = true; } @@ -2750,24 +2586,18 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootUnorderedAccessV bool stateUpdate = false; - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->SetGraphicsRootUnorderedAccessView(RootParameterIndex, BufferLocation); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - stateUpdate = true; - } - else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) - { - stateUpdate = true; - } + Unwrap(list)->SetGraphicsRootUnorderedAccessView(RootParameterIndex, BufferLocation); + + stateUpdate = true; } - else + else if(!m_Cmd->IsPartialCmdList(m_Cmd->m_LastCmdListID)) { - Unwrap(pCommandList)->SetGraphicsRootUnorderedAccessView(RootParameterIndex, BufferLocation); - stateUpdate = true; } @@ -3017,8 +2847,7 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ResolveQueryData( m_Cmd->AddAction(action); D3D12EventNode &eventNode = m_Cmd->GetLastEventNode(); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pDestinationBuffer), ResourceUsage::ResolveDst)); + eventNode.AddResourceUsage(GetResID(pDestinationBuffer), ResourceUsage::ResolveDst); } } } @@ -3145,29 +2974,27 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetMarker(SerialiserType &ser, { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - D3D12MarkerRegion::Set(list, MarkerText); - } - } - else - { - D3D12MarkerRegion::Set(pCommandList, MarkerText); + D3D12MarkerRegion::Set(list, MarkerText); - ActionDescription action; - action.customName = MarkerText.empty() ? "" : MarkerText; - if(Color != 0) + if(loading) { - action.markerColor = DecodePIXColor(Color); - } - action.flags |= ActionFlags::SetMarker; + ActionDescription action; + action.customName = MarkerText.empty() ? "" : MarkerText; + if(Color != 0) + { + action.markerColor = DecodePIXColor(Color); + } + action.flags |= ActionFlags::SetMarker; - m_Cmd->AddEvent(); - m_Cmd->AddAction(action); + m_Cmd->AddEvent(); + m_Cmd->AddAction(action); + } } } @@ -3217,31 +3044,30 @@ bool WrappedID3D12GraphicsCommandList::Serialise_BeginEvent(SerialiserType &ser, { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; + if(!loading) m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].markerCount++; - D3D12MarkerRegion::Begin(list, MarkerText); - } - } - else - { - D3D12MarkerRegion::Begin(pCommandList, MarkerText); + D3D12MarkerRegion::Begin(list, MarkerText); - ActionDescription action; - action.customName = MarkerText.empty() ? "" : MarkerText; - if(Color != 0) + if(loading) { - action.markerColor = DecodePIXColor(Color); - } - action.flags |= ActionFlags::PushMarker; + ActionDescription action; + action.customName = MarkerText.empty() ? "" : MarkerText; + if(Color != 0) + { + action.markerColor = DecodePIXColor(Color); + } + action.flags |= ActionFlags::PushMarker; - m_Cmd->AddEvent(); - m_Cmd->AddAction(action); + m_Cmd->AddEvent(); + m_Cmd->AddAction(action); + } } } @@ -3279,27 +3105,28 @@ bool WrappedID3D12GraphicsCommandList::Serialise_EndEvent(SerialiserType &ser) { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; + if(!loading) + { int &markerCount = m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].markerCount; markerCount = RDCMAX(0, markerCount - 1); - - D3D12MarkerRegion::End(list); } - } - else - { - D3D12MarkerRegion::End(pCommandList); - ActionDescription action; - action.flags = ActionFlags::PopMarker; + D3D12MarkerRegion::End(list); + + if(loading) + { + ActionDescription action; + action.flags = ActionFlags::PopMarker; - m_Cmd->AddEvent(); - m_Cmd->AddAction(action); + m_Cmd->AddEvent(); + m_Cmd->AddAction(action); + } } } @@ -3384,44 +3211,40 @@ bool WrappedID3D12GraphicsCommandList::Serialise_DrawInstanced(SerialiserType &s { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - if(!m_Cmd->IsActionDisabled()) + if(loading || !m_Cmd->IsActionDisabled()) + { + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::Drawcall) : 0; + Unwrap(list)->DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation, + StartInstanceLocation); + if(eventId && m_Cmd->m_ActionCallback->PostDraw(eventId, list)) { - uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Drawcall); Unwrap(list)->DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation, StartInstanceLocation); - if(eventId && m_Cmd->m_ActionCallback->PostDraw(eventId, list)) - { - Unwrap(list)->DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation, - StartInstanceLocation); - m_Cmd->m_ActionCallback->PostRedraw(eventId, list); - } + m_Cmd->m_ActionCallback->PostRedraw(eventId, list); } } - } - else - { - Unwrap(pCommandList) - ->DrawInstanced(VertexCountPerInstance, InstanceCount, StartVertexLocation, - StartInstanceLocation); - m_Cmd->AddEvent(); + if(loading) + { + m_Cmd->AddEvent(); - ActionDescription action; - action.numIndices = VertexCountPerInstance; - action.numInstances = InstanceCount; - action.indexOffset = 0; - action.vertexOffset = StartVertexLocation; - action.instanceOffset = StartInstanceLocation; + ActionDescription action; + action.numIndices = VertexCountPerInstance; + action.numInstances = InstanceCount; + action.indexOffset = 0; + action.vertexOffset = StartVertexLocation; + action.instanceOffset = StartInstanceLocation; - action.flags |= ActionFlags::Drawcall | ActionFlags::Instanced; + action.flags |= ActionFlags::Drawcall | ActionFlags::Instanced; - m_Cmd->AddAction(action); + m_Cmd->AddAction(action); + } } } @@ -3466,45 +3289,40 @@ bool WrappedID3D12GraphicsCommandList::Serialise_DrawIndexedInstanced( { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - if(!m_Cmd->IsActionDisabled()) + if(loading || !m_Cmd->IsActionDisabled()) + { + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::Drawcall) : 0; + Unwrap(list)->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation, + BaseVertexLocation, StartInstanceLocation); + if(eventId && m_Cmd->m_ActionCallback->PostDraw(eventId, list)) { - uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Drawcall); Unwrap(list)->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation, BaseVertexLocation, StartInstanceLocation); - if(eventId && m_Cmd->m_ActionCallback->PostDraw(eventId, list)) - { - Unwrap(list)->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, - StartIndexLocation, BaseVertexLocation, - StartInstanceLocation); - m_Cmd->m_ActionCallback->PostRedraw(eventId, list); - } + m_Cmd->m_ActionCallback->PostRedraw(eventId, list); } } - } - else - { - Unwrap(pCommandList) - ->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation, - BaseVertexLocation, StartInstanceLocation); - m_Cmd->AddEvent(); + if(loading) + { + m_Cmd->AddEvent(); - ActionDescription action; - action.numIndices = IndexCountPerInstance; - action.numInstances = InstanceCount; - action.indexOffset = StartIndexLocation; - action.baseVertex = BaseVertexLocation; - action.instanceOffset = StartInstanceLocation; + ActionDescription action; + action.numIndices = IndexCountPerInstance; + action.numInstances = InstanceCount; + action.indexOffset = StartIndexLocation; + action.baseVertex = BaseVertexLocation; + action.instanceOffset = StartInstanceLocation; - action.flags |= ActionFlags::Drawcall | ActionFlags::Instanced | ActionFlags::Indexed; + action.flags |= ActionFlags::Drawcall | ActionFlags::Instanced | ActionFlags::Indexed; - m_Cmd->AddAction(action); + m_Cmd->AddAction(action); + } } } @@ -3550,38 +3368,37 @@ bool WrappedID3D12GraphicsCommandList::Serialise_Dispatch(SerialiserType &ser, U { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; + + if(loading || !m_Cmd->IsActionDisabled()) { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::Dispatch) : 0; - if(!m_Cmd->IsActionDisabled()) + Unwrap(list)->Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); + if(eventId && m_Cmd->m_ActionCallback->PostDispatch(eventId, list)) { - uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Dispatch); Unwrap(list)->Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); - if(eventId && m_Cmd->m_ActionCallback->PostDispatch(eventId, list)) - { - Unwrap(list)->Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); - m_Cmd->m_ActionCallback->PostRedispatch(eventId, list); - } + m_Cmd->m_ActionCallback->PostRedispatch(eventId, list); } } - } - else - { - Unwrap(pCommandList)->Dispatch(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ); - m_Cmd->AddEvent(); + if(loading) + { + m_Cmd->AddEvent(); - ActionDescription action; - action.dispatchDimension[0] = ThreadGroupCountX; - action.dispatchDimension[1] = ThreadGroupCountY; - action.dispatchDimension[2] = ThreadGroupCountZ; + ActionDescription action; + action.dispatchDimension[0] = ThreadGroupCountX; + action.dispatchDimension[1] = ThreadGroupCountY; + action.dispatchDimension[2] = ThreadGroupCountZ; - action.flags |= ActionFlags::Dispatch; + action.flags |= ActionFlags::Dispatch; - m_Cmd->AddAction(action); + m_Cmd->AddAction(action); + } } } @@ -3620,31 +3437,28 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ExecuteBundle(SerialiserType &s m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::CmdList); + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::CmdList) : 0; + Unwrap(list)->ExecuteBundle(Unwrap(pBundle)); + if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::CmdList, list)) + { Unwrap(list)->ExecuteBundle(Unwrap(pBundle)); - if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::CmdList, list)) - { - Unwrap(list)->ExecuteBundle(Unwrap(pBundle)); - m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::CmdList, list); - } + m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::CmdList, list); } - } - else - { - Unwrap(pCommandList)->ExecuteBundle(Unwrap(pBundle)); - - m_Cmd->AddEvent(); + if(loading) + { + m_Cmd->AddEvent(); - ActionDescription action; - action.flags |= ActionFlags::CmdList; + ActionDescription action; + action.flags |= ActionFlags::CmdList; - m_Cmd->AddAction(action); + m_Cmd->AddAction(action); + } } } @@ -4578,12 +4392,10 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ExecuteIndirect( eventNode.hasExecuteData = true; cmdInfo.hasExecuteDatas = true; - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pArgumentBuffer), ResourceUsage::Indirect)); + eventNode.AddResourceUsage(GetResID(pArgumentBuffer), ResourceUsage::Indirect); if(pCountBuffer) { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pCountBuffer), ResourceUsage::Indirect)); + eventNode.AddResourceUsage(GetResID(pCountBuffer), ResourceUsage::Indirect); } } @@ -4744,32 +4556,25 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ClearDepthStencilView( { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - uint32_t eventId = - m_Cmd->HandlePreCallback(list, ActionFlags::Clear | ActionFlags::ClearDepthStencil); + uint32_t eventId = + !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::ClearDepthStencil) : 0; + Unwrap(list)->ClearDepthStencilView(Unwrap(DepthStencilView), ClearFlags, Depth, Stencil, + NumRects, pRects); + if(eventId && m_Cmd->m_ActionCallback->PostMisc( + eventId, ActionFlags::Clear | ActionFlags::ClearDepthStencil, list)) + { Unwrap(list)->ClearDepthStencilView(Unwrap(DepthStencilView), ClearFlags, Depth, Stencil, NumRects, pRects); - if(eventId && m_Cmd->m_ActionCallback->PostMisc( - eventId, ActionFlags::Clear | ActionFlags::ClearDepthStencil, list)) - { - Unwrap(list)->ClearDepthStencilView(Unwrap(DepthStencilView), ClearFlags, Depth, Stencil, - NumRects, pRects); - m_Cmd->m_ActionCallback->PostRemisc( - eventId, ActionFlags::Clear | ActionFlags::ClearDepthStencil, list); - } + m_Cmd->m_ActionCallback->PostRemisc( + eventId, ActionFlags::Clear | ActionFlags::ClearDepthStencil, list); } - } - else - { - Unwrap(pCommandList) - ->ClearDepthStencilView(Unwrap(DepthStencilView), ClearFlags, Depth, Stencil, NumRects, - pRects); - + if(loading) { m_Cmd->AddEvent(); @@ -4783,8 +4588,7 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ClearDepthStencilView( m_Cmd->AddAction(action); D3D12EventNode &eventNode = m_Cmd->GetLastEventNode(); - eventNode.resourceUsage.push_back( - make_rdcpair(descriptor->GetResResourceId(), ResourceUsage::Clear)); + eventNode.AddResourceUsage(descriptor->GetResResourceId(), ResourceUsage::Clear); } } } @@ -4847,28 +4651,22 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ClearRenderTargetView( { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - uint32_t eventId = - m_Cmd->HandlePreCallback(list, ActionFlags::Clear | ActionFlags::ClearColor); + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::ClearColor) : 0; + Unwrap(list)->ClearRenderTargetView(Unwrap(RenderTargetView), ColorRGBA, NumRects, pRects); + if(eventId && m_Cmd->m_ActionCallback->PostMisc( + eventId, ActionFlags::Clear | ActionFlags::ClearColor, list)) + { Unwrap(list)->ClearRenderTargetView(Unwrap(RenderTargetView), ColorRGBA, NumRects, pRects); - if(eventId && m_Cmd->m_ActionCallback->PostMisc( - eventId, ActionFlags::Clear | ActionFlags::ClearColor, list)) - { - Unwrap(list)->ClearRenderTargetView(Unwrap(RenderTargetView), ColorRGBA, NumRects, pRects); - m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear | ActionFlags::ClearColor, - list); - } + m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear | ActionFlags::ClearColor, + list); } - } - else - { - Unwrap(pCommandList)->ClearRenderTargetView(Unwrap(RenderTargetView), ColorRGBA, NumRects, pRects); - + if(loading) { m_Cmd->AddEvent(); @@ -4882,8 +4680,7 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ClearRenderTargetView( m_Cmd->AddAction(action); D3D12EventNode &eventNode = m_Cmd->GetLastEventNode(); - eventNode.resourceUsage.push_back( - make_rdcpair(descriptor->GetResResourceId(), ResourceUsage::Clear)); + eventNode.AddResourceUsage(descriptor->GetResResourceId(), ResourceUsage::Clear); } } } @@ -4948,31 +4745,24 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ClearUnorderedAccessViewUint( { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Clear); + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::Clear) : 0; + Unwrap(list)->ClearUnorderedAccessViewUint(Unwrap(ViewGPUHandleInCurrentHeap), + Unwrap(ViewCPUHandle), Unwrap(pResource), Values, + NumRects, pRects); + if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Clear, list)) + { Unwrap(list)->ClearUnorderedAccessViewUint(Unwrap(ViewGPUHandleInCurrentHeap), Unwrap(ViewCPUHandle), Unwrap(pResource), Values, NumRects, pRects); - if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Clear, list)) - { - Unwrap(list)->ClearUnorderedAccessViewUint(Unwrap(ViewGPUHandleInCurrentHeap), - Unwrap(ViewCPUHandle), Unwrap(pResource), - Values, NumRects, pRects); - m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, list); - } + m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, list); } - } - else - { - Unwrap(pCommandList) - ->ClearUnorderedAccessViewUint(Unwrap(ViewGPUHandleInCurrentHeap), Unwrap(ViewCPUHandle), - Unwrap(pResource), Values, NumRects, pRects); - + if(loading) { m_Cmd->AddEvent(); @@ -4984,7 +4774,7 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ClearUnorderedAccessViewUint( m_Cmd->AddAction(action); D3D12EventNode &eventNode = m_Cmd->GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(pResource), ResourceUsage::Clear)); + eventNode.AddResourceUsage(GetResID(pResource), ResourceUsage::Clear); } } } @@ -5057,31 +4847,24 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ClearUnorderedAccessViewFloat( { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Clear); + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::Clear) : 0; + Unwrap(list)->ClearUnorderedAccessViewFloat(Unwrap(ViewGPUHandleInCurrentHeap), + Unwrap(ViewCPUHandle), Unwrap(pResource), Values, + NumRects, pRects); + if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Clear, list)) + { Unwrap(list)->ClearUnorderedAccessViewFloat(Unwrap(ViewGPUHandleInCurrentHeap), Unwrap(ViewCPUHandle), Unwrap(pResource), Values, NumRects, pRects); - if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Clear, list)) - { - Unwrap(list)->ClearUnorderedAccessViewFloat(Unwrap(ViewGPUHandleInCurrentHeap), - Unwrap(ViewCPUHandle), Unwrap(pResource), - Values, NumRects, pRects); - m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, list); - } + m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, list); } - } - else - { - Unwrap(pCommandList) - ->ClearUnorderedAccessViewFloat(Unwrap(ViewGPUHandleInCurrentHeap), Unwrap(ViewCPUHandle), - Unwrap(pResource), Values, NumRects, pRects); - + if(loading) { m_Cmd->AddEvent(); @@ -5093,7 +4876,7 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ClearUnorderedAccessViewFloat( m_Cmd->AddAction(action); D3D12EventNode &eventNode = m_Cmd->GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(pResource), ResourceUsage::Clear)); + eventNode.AddResourceUsage(GetResID(pResource), ResourceUsage::Clear); } } } @@ -5149,26 +4932,22 @@ bool WrappedID3D12GraphicsCommandList::Serialise_DiscardResource(SerialiserType { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - Unwrap(m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID)) - ->DiscardResource(Unwrap(pResource), pRegion); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - if(m_pDevice->GetReplayOptions().optimisation != ReplayOptimisationLevel::Fastest) - { - m_pDevice->GetDebugManager()->FillWithDiscardPattern( - m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID), - m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state, DiscardType::DiscardCall, - pResource, pRegion, D3D12_BARRIER_LAYOUT_UNDEFINED); - } - } - } - else - { - Unwrap(pCommandList)->DiscardResource(Unwrap(pResource), pRegion); + Unwrap(list)->DiscardResource(Unwrap(pResource), pRegion); + if(!loading && m_pDevice->GetReplayOptions().optimisation != ReplayOptimisationLevel::Fastest) + { + m_pDevice->GetDebugManager()->FillWithDiscardPattern( + m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID), + m_Cmd->m_BakedCmdListInfo[m_Cmd->m_LastCmdListID].state, DiscardType::DiscardCall, + pResource, pRegion, D3D12_BARRIER_LAYOUT_UNDEFINED); + } + if(loading) { m_Cmd->AddEvent(); @@ -5180,7 +4959,7 @@ bool WrappedID3D12GraphicsCommandList::Serialise_DiscardResource(SerialiserType m_Cmd->AddAction(action); D3D12EventNode &eventNode = m_Cmd->GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(pResource), ResourceUsage::Discard)); + eventNode.AddResourceUsage(GetResID(pResource), ResourceUsage::Discard); } } } @@ -5229,28 +5008,22 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyBufferRegion(SerialiserType { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Copy); + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::Copy) : 0; + Unwrap(list)->CopyBufferRegion(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), SrcOffset, + NumBytes); + if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, list)) + { Unwrap(list)->CopyBufferRegion(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), SrcOffset, NumBytes); - if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, list)) - { - Unwrap(list)->CopyBufferRegion(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), - SrcOffset, NumBytes); - m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, list); - } + m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, list); } - } - else - { - Unwrap(pCommandList) - ->CopyBufferRegion(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), SrcOffset, NumBytes); - + if(loading) { m_Cmd->AddEvent(); @@ -5268,14 +5041,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyBufferRegion(SerialiserType if(pSrcBuffer == pDstBuffer) { - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(pSrcBuffer), ResourceUsage::Copy)); + eventNode.AddResourceUsage(GetResID(pSrcBuffer), ResourceUsage::Copy); } else { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pSrcBuffer), ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pDstBuffer), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(pSrcBuffer), ResourceUsage::CopySrc); + eventNode.AddResourceUsage(GetResID(pDstBuffer), ResourceUsage::CopyDst); } } } @@ -5324,30 +5095,25 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyTextureRegion( { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - D3D12_TEXTURE_COPY_LOCATION unwrappedDst = dst; - unwrappedDst.pResource = Unwrap(unwrappedDst.pResource); - D3D12_TEXTURE_COPY_LOCATION unwrappedSrc = src; - unwrappedSrc.pResource = Unwrap(unwrappedSrc.pResource); - - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Copy); + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::Copy) : 0; + D3D12_TEXTURE_COPY_LOCATION unwrappedDst = dst; + unwrappedDst.pResource = Unwrap(unwrappedDst.pResource); + D3D12_TEXTURE_COPY_LOCATION unwrappedSrc = src; + unwrappedSrc.pResource = Unwrap(unwrappedSrc.pResource); + + Unwrap(list)->CopyTextureRegion(&unwrappedDst, DstX, DstY, DstZ, &unwrappedSrc, pSrcBox); + if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, list)) + { Unwrap(list)->CopyTextureRegion(&unwrappedDst, DstX, DstY, DstZ, &unwrappedSrc, pSrcBox); - if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, list)) - { - Unwrap(list)->CopyTextureRegion(&unwrappedDst, DstX, DstY, DstZ, &unwrappedSrc, pSrcBox); - m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, list); - } + m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, list); } - } - else - { - Unwrap(pCommandList)->CopyTextureRegion(&unwrappedDst, DstX, DstY, DstZ, &unwrappedSrc, pSrcBox); - + if(loading) { m_Cmd->AddEvent(); @@ -5384,12 +5150,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyTextureRegion( if(origSrc == origDst) { - eventNode.resourceUsage.push_back(make_rdcpair(liveSrc, ResourceUsage::Copy)); + eventNode.AddResourceUsage(liveSrc, ResourceUsage::Copy); } else { - eventNode.resourceUsage.push_back(make_rdcpair(liveSrc, ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back(make_rdcpair(liveDst, ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(liveSrc, ResourceUsage::CopySrc); + eventNode.AddResourceUsage(liveDst, ResourceUsage::CopyDst); } } } @@ -5440,25 +5206,20 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyResource(SerialiserType &se { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Copy); + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::Copy) : 0; + Unwrap(list)->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource)); + if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, list)) + { Unwrap(list)->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource)); - if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, list)) - { - Unwrap(list)->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource)); - m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, list); - } + m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, list); } - } - else - { - Unwrap(pCommandList)->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource)); - + if(loading) { m_Cmd->AddEvent(); @@ -5476,14 +5237,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyResource(SerialiserType &se if(pSrcResource == pDstResource) { - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(pSrcResource), ResourceUsage::Copy)); + eventNode.AddResourceUsage(GetResID(pSrcResource), ResourceUsage::Copy); } else { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pSrcResource), ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pDstResource), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(pSrcResource), ResourceUsage::CopySrc); + eventNode.AddResourceUsage(GetResID(pDstResource), ResourceUsage::CopyDst); } } } @@ -5529,28 +5288,22 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ResolveSubresource( { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; + + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::Resolve) : 0; + Unwrap(list)->ResolveSubresource(Unwrap(pDstResource), DstSubresource, Unwrap(pSrcResource), + SrcSubresource, Format); + if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Resolve, list)) { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); - uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Resolve); Unwrap(list)->ResolveSubresource(Unwrap(pDstResource), DstSubresource, Unwrap(pSrcResource), SrcSubresource, Format); - if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Resolve, list)) - { - Unwrap(list)->ResolveSubresource(Unwrap(pDstResource), DstSubresource, - Unwrap(pSrcResource), SrcSubresource, Format); - m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Resolve, list); - } + m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Resolve, list); } - } - else - { - Unwrap(pCommandList) - ->ResolveSubresource(Unwrap(pDstResource), DstSubresource, Unwrap(pSrcResource), - SrcSubresource, Format); - + if(loading) { m_Cmd->AddEvent(); @@ -5573,15 +5326,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ResolveSubresource( if(pSrcResource == pDstResource) { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pSrcResource), ResourceUsage::Resolve)); + eventNode.AddResourceUsage(GetResID(pSrcResource), ResourceUsage::Resolve); } else { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pSrcResource), ResourceUsage::ResolveSrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pDstResource), ResourceUsage::ResolveDst)); + eventNode.AddResourceUsage(GetResID(pSrcResource), ResourceUsage::ResolveSrc); + eventNode.AddResourceUsage(GetResID(pDstResource), ResourceUsage::ResolveDst); } } } @@ -5634,29 +5384,22 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyTiles( { m_Cmd->m_LastCmdListID = GetResID(pCommandList); - if(IsActiveReplaying(m_State)) + if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) { - if(m_Cmd->InRerecordRange(m_Cmd->m_LastCmdListID)) - { - ID3D12GraphicsCommandListX *list = m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID); + bool loading = IsLoading(m_State); + ID3D12GraphicsCommandListX *list = !loading ? m_Cmd->RerecordCmdList(m_Cmd->m_LastCmdListID) + : (ID3D12GraphicsCommandListX *)pCommandList; - uint32_t eventId = m_Cmd->HandlePreCallback(list, ActionFlags::Copy); + uint32_t eventId = !loading ? m_Cmd->HandlePreCallback(list, ActionFlags::Copy) : 0; + Unwrap(list)->CopyTiles(Unwrap(pTiledResource), &TileRegionStartCoordinate, &TileRegionSize, + Unwrap(pBuffer), BufferStartOffsetInBytes, Flags); + if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, list)) + { Unwrap(list)->CopyTiles(Unwrap(pTiledResource), &TileRegionStartCoordinate, &TileRegionSize, Unwrap(pBuffer), BufferStartOffsetInBytes, Flags); - if(eventId && m_Cmd->m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, list)) - { - Unwrap(list)->CopyTiles(Unwrap(pTiledResource), &TileRegionStartCoordinate, - &TileRegionSize, Unwrap(pBuffer), BufferStartOffsetInBytes, Flags); - m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, list); - } + m_Cmd->m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, list); } - } - else - { - Unwrap(pCommandList) - ->CopyTiles(Unwrap(pTiledResource), &TileRegionStartCoordinate, &TileRegionSize, - Unwrap(pBuffer), BufferStartOffsetInBytes, Flags); - + if(loading) { m_Cmd->AddEvent(); @@ -5687,8 +5430,8 @@ bool WrappedID3D12GraphicsCommandList::Serialise_CopyTiles( m_Cmd->AddAction(action); D3D12EventNode &eventNode = m_Cmd->GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(liveSrc, ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back(make_rdcpair(liveDst, ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(liveSrc, ResourceUsage::CopySrc); + eventNode.AddResourceUsage(liveDst, ResourceUsage::CopyDst); } } } diff --git a/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp index 5f41107d236..d630bb8ce61 100644 --- a/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp @@ -460,7 +460,7 @@ bool WrappedID3D12CommandQueue::Serialise_ExecuteCommandLists(SerialiserType &se if(m_pDevice->GetReplayOptions().apiValidation) DebugMessages.clear(); - D3D12EventNode &eventNode = m_Cmd.m_LoadingEventNode; + D3D12EventNode &eventNode = m_Cmd.GetLoadingEventNode(); for(const DebugMessage &msg : DebugMessages) eventNode.debugMessages.push_back(msg); } diff --git a/renderdoc/driver/d3d12/d3d12_commands.cpp b/renderdoc/driver/d3d12/d3d12_commands.cpp index cd0c7293ed8..1f221c83d73 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.cpp +++ b/renderdoc/driver/d3d12/d3d12_commands.cpp @@ -747,6 +747,7 @@ bool WrappedID3D12CommandQueue::ProcessChunk(ReadSerialiser &ser, D3D12Chunk chu m_Cmd.m_AddedEventNode = false; m_Cmd.m_LoadingEventNode = D3D12EventNode(); } + m_Cmd.m_Loading = IsLoading(m_State); bool ret = false; @@ -1147,6 +1148,7 @@ RDResult WrappedID3D12CommandQueue::ReplayLog(CaptureState readType, uint32_t st uint32_t endEventID, bool partial) { m_State = readType; + m_Cmd.m_Loading = IsLoading(m_State); if(!partial) { @@ -1805,6 +1807,7 @@ D3D12CommandData::D3D12CommandData() m_ActionCallback = NULL; m_AddedEventNode = false; + m_Loading = false; } void D3D12CommandData::GetIndirectBuffer(size_t size, ID3D12Resource **buf, uint64_t *offs) @@ -1933,6 +1936,10 @@ uint32_t D3D12CommandData::HandlePreCallback(ID3D12GraphicsCommandListX *list, A bool D3D12CommandData::InRerecordRange(ResourceId cmdid) { + // loading will replay all events + if(m_Loading) + return true; + // if we have an outside command list, assume the range is valid and we're replaying all events // onto it. if(m_OutsideCmdList != NULL) @@ -1964,6 +1971,9 @@ bool D3D12CommandData::HasRerecordCmdList(ResourceId cmdid) bool D3D12CommandData::IsPartialCmdList(ResourceId cmdid) { + if(m_Loading) + return false; + if(m_OutsideCmdList != NULL) return true; @@ -2023,19 +2033,6 @@ void D3D12CommandData::AddEvent() m_AddedEventNode = true; } -void D3D12CommandData::AddResourceUsage(D3D12EventNode &eventNode, ResourceId id, ResourceUsage usage) -{ - if(id == ResourceId()) - return; - - eventNode.resourceUsage.push_back(make_rdcpair(id, usage)); -} - -void D3D12CommandData::AddCPUUsage(ResourceId id, ResourceUsage usage) -{ - m_LoadingEventNode.resourceUsage.push_back(make_rdcpair(id, usage)); -} - void D3D12CommandData::AddUsageForBindInRootSig(const D3D12RenderState &state, D3D12EventNode &eventNode, const D3D12RenderState::RootSignature *rootsig, @@ -2274,25 +2271,22 @@ void D3D12CommandData::AddUsage(const D3D12RenderState &state, D3D12EventNode &e } if(a.flags & ActionFlags::Indexed && state.ibuffer.buf != ResourceId()) - eventNode.resourceUsage.push_back(make_rdcpair(state.ibuffer.buf, ResourceUsage::IndexBuffer)); + eventNode.AddResourceUsage(state.ibuffer.buf, ResourceUsage::IndexBuffer); if(a.flags & ActionFlags::Drawcall) { for(size_t i = 0; i < state.vbuffers.size(); i++) { if(state.vbuffers[i].buf != ResourceId()) - eventNode.resourceUsage.push_back( - make_rdcpair(state.vbuffers[i].buf, ResourceUsage::VertexBuffer)); + eventNode.AddResourceUsage(state.vbuffers[i].buf, ResourceUsage::VertexBuffer); } for(size_t i = 0; i < state.streamouts.size(); i++) { if(state.streamouts[i].buf != ResourceId()) - eventNode.resourceUsage.push_back( - make_rdcpair(state.streamouts[i].buf, ResourceUsage::StreamOut)); + eventNode.AddResourceUsage(state.streamouts[i].buf, ResourceUsage::StreamOut); if(state.streamouts[i].countbuf != ResourceId()) - eventNode.resourceUsage.push_back( - make_rdcpair(state.streamouts[i].countbuf, ResourceUsage::StreamOut)); + eventNode.AddResourceUsage(state.streamouts[i].countbuf, ResourceUsage::StreamOut); } } @@ -2301,12 +2295,12 @@ void D3D12CommandData::AddUsage(const D3D12RenderState &state, D3D12EventNode &e for(size_t i = 0; i < rts.size(); i++) { if(rts[i] != ResourceId()) - eventNode.resourceUsage.push_back(make_rdcpair(rts[i], ResourceUsage::ColorTarget)); + eventNode.AddResourceUsage(rts[i], ResourceUsage::ColorTarget); } ResourceId id = state.GetDSVID(); if(id != ResourceId()) - eventNode.resourceUsage.push_back(make_rdcpair(id, ResourceUsage::DepthStencilTarget)); + eventNode.AddResourceUsage(id, ResourceUsage::DepthStencilTarget); } if(rootsig) diff --git a/renderdoc/driver/d3d12/d3d12_commands.h b/renderdoc/driver/d3d12/d3d12_commands.h index 1f556c831dc..e416e064aab 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.h +++ b/renderdoc/driver/d3d12/d3d12_commands.h @@ -50,11 +50,28 @@ struct D3D12EventNode { event = a.event; action = a.action; + SAFE_DELETE(state); if(a.state) - { - state = new D3D12RenderState(); - *state = *a.state; - } + state = new D3D12RenderState(*a.state); + executeData = a.executeData; + resourceUsage = a.resourceUsage; + debugMessages = a.debugMessages; + annotations = a.annotations; + cmdListID = a.cmdListID; + primaryCmdId = a.primaryCmdId; + childCmdBufId = a.childCmdBufId; + addActionUse = a.addActionUse; + addPrimaryExecute = a.addPrimaryExecute; + hasExecuteData = a.hasExecuteData; + return *this; + } + D3D12EventNode &operator=(D3D12EventNode &&a) + { + event = a.event; + action = a.action; + SAFE_DELETE(state); + state = a.state; + a.state = NULL; executeData = a.executeData; resourceUsage = a.resourceUsage; debugMessages = a.debugMessages; @@ -67,6 +84,10 @@ struct D3D12EventNode hasExecuteData = a.hasExecuteData; return *this; } + void AddResourceUsage(ResourceId id, ResourceUsage usage) + { + resourceUsage.push_back(make_rdcpair(id, usage)); + } // eventId is not used APIEvent event; @@ -348,6 +369,7 @@ struct D3D12CommandData D3D12EventNode m_LoadingEventNode; rdcarray m_EventNodes; bool m_AddedEventNode; + bool m_Loading; uint64_t m_CurChunkOffset; SDChunkMetaData m_ChunkMetadata; @@ -395,6 +417,7 @@ struct D3D12CommandData : m_EventNodes); return eventNodes.back(); } + D3D12EventNode &GetLoadingEventNode() { return m_LoadingEventNode; } void BakeEventNodes(ActionDescription &rootAction); @@ -405,6 +428,15 @@ struct D3D12CommandData D3D12_DESCRIPTOR_RANGE_TYPE type, uint32_t space, uint32_t bind, uint32_t rangeSize); - void AddResourceUsage(D3D12EventNode &eventNode, ResourceId id, ResourceUsage usage); - void AddCPUUsage(ResourceId id, ResourceUsage usage); + void AddResourceUsage(D3D12EventNode &eventNode, ResourceId id, ResourceUsage usage) + { + if(id == ResourceId()) + return; + + eventNode.AddResourceUsage(id, usage); + } + void AddEventResourceUsage(ResourceId id, ResourceUsage usage) + { + m_LoadingEventNode.AddResourceUsage(id, usage); + } }; diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index 8d6af8d0e45..7b016992438 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -2270,7 +2270,7 @@ bool WrappedID3D12Device::Serialise_MapDataWrite(SerialiserType &ser, ID3D12Reso if(IsLoading(m_State)) { - cmd.AddCPUUsage(GetResID(Resource), ResourceUsage::CPUWrite); + cmd.AddEventResourceUsage(GetResID(Resource), ResourceUsage::CPUWrite); // when CPU uploading we just save the range (wouldn't be necessary if the range was // serialised before the blob) @@ -2445,7 +2445,7 @@ bool WrappedID3D12Device::Serialise_WriteToSubresource(SerialiserType &ser, ID3D D3D12CommandData &cmd = *m_Queue->GetCommandData(); if(IsLoading(m_State)) - cmd.AddCPUUsage(GetResID(Resource), ResourceUsage::CPUWrite); + cmd.AddEventResourceUsage(GetResID(Resource), ResourceUsage::CPUWrite); ResourceId id = GetResID(Resource); if(m_UploadResourceIds.find(id) != m_UploadResourceIds.end()) @@ -5825,6 +5825,7 @@ void WrappedID3D12Device::ReplayLog(uint32_t startEventID, uint32_t endEventID, { D3D12CommandData &cmd = *m_Queue->GetCommandData(); + cmd.m_Loading = false; if(!partial) { diff --git a/renderdoc/driver/d3d12/d3d12_overlay.cpp b/renderdoc/driver/d3d12/d3d12_overlay.cpp index 7cfaf874e92..9427e094ca8 100644 --- a/renderdoc/driver/d3d12/d3d12_overlay.cpp +++ b/renderdoc/driver/d3d12/d3d12_overlay.cpp @@ -401,7 +401,7 @@ void D3D12Replay::PatchQuadWritePS(D3D12_EXPANDED_PIPELINE_STATE_STREAM_DESC &pi bytebuf rastFeedingBytes((const byte *)rastFeeding->pShaderBytecode, rastFeeding->BytecodeLength); // get the DXBC for the previous stage - DXBC::DXBCContainer rastFeedingDXBC(rastFeedingBytes, rdcstr(), GraphicsAPI::D3D12, ~0U, ~0U); + DXBC::DXBCContainer rastFeedingDXBC(rastFeedingBytes); bytebuf patchedDXBC((const byte *)quadWriteBlob->GetBufferPointer(), quadWriteBlob->GetBufferSize()); @@ -422,7 +422,7 @@ void D3D12Replay::PatchQuadWritePS(D3D12_EXPANDED_PIPELINE_STATE_STREAM_DESC &pi if(!D3D12_Debug_OverlayDumpDirPath().empty()) FileIO::WriteAll(D3D12_Debug_OverlayDumpDirPath() + "/before_quadps.dxbc", patchedDXBC); - DXBC::DXBCContainer quadOverdrawDXBC(patchedDXBC, rdcstr(), GraphicsAPI::D3D12, ~0U, ~0U); + DXBC::DXBCContainer quadOverdrawDXBC(patchedDXBC); if(dxil) { diff --git a/renderdoc/driver/d3d12/d3d12_resources.cpp b/renderdoc/driver/d3d12/d3d12_resources.cpp index ac73c2a81f0..224e04d36fc 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.cpp +++ b/renderdoc/driver/d3d12/d3d12_resources.cpp @@ -653,8 +653,15 @@ void WrappedID3D12PipelineState::ShaderEntry::Reload() bool wasBuilt = m_Built; m_Built = false; *m_Details = ShaderReflection(); - SAFE_DELETE(m_DXBCFile); - if(wasBuilt && (GetDXBC() != NULL)) + + if(m_DXBCFile) + { + // recreate the DXBC file, this will pull any old debug info over + m_DXBCFile = new DXBC::DXBCContainer(m_DXBCFile, rdcstr()); + m_DXBCFile->SetShaderExts(GraphicsAPI::D3D12, m_ShaderExtSlot, m_ShaderExtSpace); + } + + if(wasBuilt) { BuildReflection(); m_Built = true; @@ -1000,8 +1007,7 @@ void D3D12ShaderExportDatabase::PopulateDatabase(size_t NumSubobjects, RDCERR("Falling back to expensive container-based enumeration of entry points"); DXBC::DXBCContainer container( - bytebuf((byte *)dxil->DXILLibrary.pShaderBytecode, dxil->DXILLibrary.BytecodeLength), - rdcstr(), GraphicsAPI::D3D12, ~0U, ~0U); + bytebuf((byte *)dxil->DXILLibrary.pShaderBytecode, dxil->DXILLibrary.BytecodeLength)); entries = container.GetEntryPoints(); } diff --git a/renderdoc/driver/d3d12/d3d12_resources.h b/renderdoc/driver/d3d12/d3d12_resources.h index e1c4c6fceff..403afd32d6d 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.h +++ b/renderdoc/driver/d3d12/d3d12_resources.h @@ -992,8 +992,14 @@ class WrappedID3D12PipelineState D3D12_SHADER_BYTECODE GetDesc() { D3D12_SHADER_BYTECODE ret; - ret.BytecodeLength = m_Bytecode.size(); - ret.pShaderBytecode = (const void *)&m_Bytecode[0]; + + // once we've processed into the DXBC file, it owns the blob + const bytebuf &bytecode = + m_Bytecode.empty() && m_DXBCFile ? m_DXBCFile->GetShaderBlob() : m_Bytecode; + + ret.BytecodeLength = bytecode.size(); + ret.pShaderBytecode = (const void *)&bytecode[0]; + return ret; } @@ -1002,8 +1008,9 @@ class WrappedID3D12PipelineState { if(m_DXBCFile == NULL && !m_Bytecode.empty()) { - m_DXBCFile = new DXBC::DXBCContainer(m_Bytecode, rdcstr(), GraphicsAPI::D3D12, - m_ShaderExtSlot, m_ShaderExtSpace); + m_DXBCFile = new DXBC::DXBCContainer(std::move(m_Bytecode)); + m_DXBCFile->SetShaderExts(GraphicsAPI::D3D12, m_ShaderExtSlot, m_ShaderExtSpace); + m_Bytecode.clear(); } return m_DXBCFile; } diff --git a/renderdoc/driver/gl/egl_dispatch_table.h b/renderdoc/driver/gl/egl_dispatch_table.h index 4cbc7c229f0..6b3e59a94ae 100644 --- a/renderdoc/driver/gl/egl_dispatch_table.h +++ b/renderdoc/driver/gl/egl_dispatch_table.h @@ -31,6 +31,8 @@ typedef EGLenum(EGLAPIENTRY *PFN_eglQueryAPI)(); typedef EGLDisplay(EGLAPIENTRY *PFN_eglGetDisplay)(EGLNativeDisplayType display_id); typedef EGLDisplay(EGLAPIENTRY *PFN_eglGetPlatformDisplay)(EGLenum platform, void *native_display, const EGLAttrib *attrib_list); +typedef EGLDisplay(EGLAPIENTRY *PFN_eglGetPlatformDisplayEXT)(EGLenum platform, void *native_display, + const EGLAttrib *attrib_list); typedef EGLContext(EGLAPIENTRY *PFN_eglCreateContext)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list); @@ -49,6 +51,10 @@ typedef EGLSurface(EGLAPIENTRY *PFN_eglCreateWindowSurface)(EGLDisplay dpy, EGLC typedef EGLSurface(EGLAPIENTRY *PFN_eglCreatePlatformWindowSurface)(EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list); +typedef EGLSurface(EGLAPIENTRY *PFN_eglCreatePlatformWindowSurfaceEXT)(EGLDisplay dpy, + EGLConfig config, + void *native_window, + const EGLAttrib *attrib_list); typedef EGLBoolean(EGLAPIENTRY *PFN_eglChooseConfig)(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); @@ -68,20 +74,22 @@ typedef PFNEGLPOSTSUBBUFFERNVPROC PFN_eglPostSubBufferNV; typedef PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC PFN_eglSwapBuffersWithDamageEXT; typedef PFNEGLSWAPBUFFERSWITHDAMAGEKHRPROC PFN_eglSwapBuffersWithDamageKHR; -#define EGL_HOOKED_SYMBOLS(FUNC) \ - FUNC(BindAPI, false, true); \ - FUNC(GetProcAddress, false, true); \ - FUNC(GetDisplay, false, true); \ - FUNC(GetPlatformDisplay, false, false); \ - FUNC(CreateContext, false, true); \ - FUNC(DestroyContext, false, true); \ - FUNC(CreateWindowSurface, false, true); \ - FUNC(CreatePlatformWindowSurface, false, false); \ - FUNC(MakeCurrent, false, true); \ - FUNC(SwapBuffers, false, true); \ - FUNC(QueryString, false, true); \ - FUNC(PostSubBufferNV, true, false); \ - FUNC(SwapBuffersWithDamageEXT, true, false); \ +#define EGL_HOOKED_SYMBOLS(FUNC) \ + FUNC(BindAPI, false, true); \ + FUNC(GetProcAddress, false, true); \ + FUNC(GetDisplay, false, true); \ + FUNC(GetPlatformDisplay, false, false); \ + FUNC(CreateContext, false, true); \ + FUNC(DestroyContext, false, true); \ + FUNC(CreateWindowSurface, false, true); \ + FUNC(CreatePlatformWindowSurface, false, false); \ + FUNC(MakeCurrent, false, true); \ + FUNC(SwapBuffers, false, true); \ + FUNC(QueryString, false, true); \ + FUNC(PostSubBufferNV, true, false); \ + FUNC(GetPlatformDisplayEXT, true, false); \ + FUNC(CreatePlatformWindowSurfaceEXT, true, false); \ + FUNC(SwapBuffersWithDamageEXT, true, false); \ FUNC(SwapBuffersWithDamageKHR, true, false); #define EGL_NONHOOKED_SYMBOLS(FUNC) \ diff --git a/renderdoc/driver/gl/egl_hooks.cpp b/renderdoc/driver/gl/egl_hooks.cpp index 993dd83b60d..619b876a2a7 100644 --- a/renderdoc/driver/gl/egl_hooks.cpp +++ b/renderdoc/driver/gl/egl_hooks.cpp @@ -226,6 +226,12 @@ HOOK_EXPORT EGLDisplay EGLAPIENTRY eglGetPlatformDisplay_renderdoc_hooked(EGLenu return EGL.GetPlatformDisplay(platform, native_display, attrib_list); } +HOOK_EXPORT EGLDisplay EGLAPIENTRY eglGetPlatformDisplayEXT_renderdoc_hooked( + EGLenum platform, void *native_display, const EGLAttrib *attrib_list) +{ + return eglGetPlatformDisplay_renderdoc_hooked(platform, native_display, attrib_list); +} + HOOK_EXPORT EGLBoolean EGLAPIENTRY eglBindAPI_renderdoc_hooked(EGLenum api) { if(RenderDoc::Inst().IsReplayApp()) @@ -461,6 +467,12 @@ HOOK_EXPORT EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurface_renderdoc_hook return ret; } +HOOK_EXPORT EGLDisplay EGLAPIENTRY eglCreatePlatformWindowSurfaceEXT_renderdoc_hooked( + EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list) +{ + return eglCreatePlatformWindowSurface_renderdoc_hooked(dpy, config, native_window, attrib_list); +} + HOOK_EXPORT EGLBoolean EGLAPIENTRY eglMakeCurrent_renderdoc_hooked(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext ctx) diff --git a/renderdoc/driver/gl/gl_common.h b/renderdoc/driver/gl/gl_common.h index d0d073b4d55..792abaf122c 100644 --- a/renderdoc/driver/gl/gl_common.h +++ b/renderdoc/driver/gl/gl_common.h @@ -769,6 +769,7 @@ extern bool IsGLES; EXT_TO_CHECK(43, 31, ARB_program_interface_query) \ EXT_TO_CHECK(43, 31, ARB_shader_storage_buffer_object) \ EXT_TO_CHECK(43, 31, ARB_stencil_texturing) \ + EXT_TO_CHECK(43, 31, ARB_framebuffer_no_attachments) \ /* See above with ARB_texture_multisample_no_array */ \ EXT_TO_CHECK(43, 32, ARB_texture_storage_multisample_no_array) \ EXT_TO_CHECK(43, 99, ARB_texture_storage_multisample) \ diff --git a/renderdoc/driver/gl/gl_debug.cpp b/renderdoc/driver/gl/gl_debug.cpp index efe8d82a6a4..7b25d613b5e 100644 --- a/renderdoc/driver/gl/gl_debug.cpp +++ b/renderdoc/driver/gl/gl_debug.cpp @@ -1484,9 +1484,9 @@ GLuint GLReplay::MakeShaderDebugSampleProg(const SamplingProgramConfig &config) } rdcstr vs = - GenerateGLSLShader(GetEmbeddedResource(glsl_shaderdebug_sample_vert), shaderType, glslCSVer); - rdcstr ps = GenerateGLSLShader(GetEmbeddedResource(glsl_debug_sample_frag), shaderType, glslCSVer, - defines + DebugData.texSampleDefines); + GenerateGLSLShader(GetEmbeddedResource(glsl_shaderdebug_sample_vert), shaderType, glslVersion); + rdcstr ps = GenerateGLSLShader(GetEmbeddedResource(glsl_debug_sample_frag), shaderType, + glslVersion, defines + DebugData.texSampleDefines); GLuint prog = CreateShaderProgram(vs, ps, ""); if(config.op == SamplingProgramConfig::SampleDref || config.op == SamplingProgramConfig::GatherDref) @@ -1494,9 +1494,15 @@ GLuint GLReplay::MakeShaderDebugSampleProg(const SamplingProgramConfig &config) dim = "tex" + dim; - BindUBO(prog, "debugsample", 0); + GLuint prevProg = 0; + GL.glGetIntegerv(eGL_CURRENT_PROGRAM, (GLint *)&prevProg); + + BindUBO(prog, "DebugSampleUBO", 0); + GL.glUseProgram(prog); GL.glUniform1i(GL.glGetUniformLocation(prog, dim.c_str()), 0); + GL.glUseProgram(prevProg); + return m_ShaderDebugSampleProg[hash] = prog; } diff --git a/renderdoc/driver/gl/gl_replay.cpp b/renderdoc/driver/gl/gl_replay.cpp index c38fb5e5e0a..559d96a8eeb 100644 --- a/renderdoc/driver/gl/gl_replay.cpp +++ b/renderdoc/driver/gl/gl_replay.cpp @@ -1884,6 +1884,14 @@ void GLReplay::SavePipelineState(uint32_t eventId) pipe.framebuffer.drawFBO.readBuffer = b - eGL_COLOR_ATTACHMENT0; else pipe.framebuffer.drawFBO.readBuffer = -1; + + if(HasExt[ARB_framebuffer_no_attachments]) + { + drv.glGetFramebufferParameteriv(eGL_READ_FRAMEBUFFER, eGL_FRAMEBUFFER_DEFAULT_SAMPLES, + (GLint *)&pipe.framebuffer.readFBO.defaultSampleCount); + drv.glGetFramebufferParameteriv(eGL_DRAW_FRAMEBUFFER, eGL_FRAMEBUFFER_DEFAULT_SAMPLES, + (GLint *)&pipe.framebuffer.drawFBO.defaultSampleCount); + } } pipe.framebuffer.blendState.blendFactor = rs.BlendColor; @@ -2377,7 +2385,8 @@ rdcarray GLReplay::GetSamplerDescriptors(ResourceId descripto // GL has separate sampler objects but they don't exist as separate sampler descriptors ret[dst].type = DescriptorType::ImageSampler; - if(target != eGL_TEXTURE_2D_MULTISAMPLE && target != eGL_TEXTURE_2D_MULTISAMPLE_ARRAY) + if(target != eGL_TEXTURE_2D_MULTISAMPLE && target != eGL_TEXTURE_2D_MULTISAMPLE_ARRAY && + target != eGL_TEXTURE_BUFFER) { if(samp != 0) drv.glGetSamplerParameterfv(samp, eGL_TEXTURE_BORDER_COLOR, diff --git a/renderdoc/driver/gl/gl_replay.h b/renderdoc/driver/gl/gl_replay.h index 51b2b65fa41..160e51f8a29 100644 --- a/renderdoc/driver/gl/gl_replay.h +++ b/renderdoc/driver/gl/gl_replay.h @@ -349,6 +349,7 @@ class GLReplay : public IReplayDriver void SetReplayData(GLWindowingData data); void UseReplayContext() { MakeCurrentReplayContext(&m_ReplayCtx); } + void UseDebugContext() { MakeCurrentReplayContext(m_DebugCtx); } bool IsReplayContext(void *ctx) { return m_ReplayCtx.ctx == NULL || ctx == m_ReplayCtx.ctx; } bool HasDebugContext() { return m_DebugCtx != NULL; } void FillWithDiscardPattern(DiscardType type, GLuint framebuffer, GLsizei numAttachments, diff --git a/renderdoc/driver/gl/gl_shaderdebug.cpp b/renderdoc/driver/gl/gl_shaderdebug.cpp index 71a000b05dd..244cf7f00f6 100644 --- a/renderdoc/driver/gl/gl_shaderdebug.cpp +++ b/renderdoc/driver/gl/gl_shaderdebug.cpp @@ -164,6 +164,7 @@ class GLAPIWrapper : public rdcspv::DebugAPIWrapper CHECK_DEVICE_THREAD(); if(!m_ResourcesDirty) { + m_pDriver->GetReplay()->UseReplayContext(); GLMarkerRegion region("ResetReplay"); // replay the action to get back to 'normal' state for this event, and mark that we need to // replay back to pristine state next time we need to fetch data. @@ -684,8 +685,6 @@ class GLAPIWrapper : public rdcspv::DebugAPIWrapper return false; } - GLMarkerRegion markerRegion("QueueSampleGather"); - GLResource texture = m_pDriver->GetResourceManager()->GetResource(imageDescriptor.resource); GLResource bufTexture = m_pDriver->GetResourceManager()->GetResource(bufferViewDescriptor.resource); @@ -1155,6 +1154,8 @@ class GLAPIWrapper : public rdcspv::DebugAPIWrapper uniformParams.dynoffset.z = offset.value.s32v[2]; } + m_pDriver->GetReplay()->UseReplayContext(); + GLuint prog = m_pDriver->GetReplay()->MakeShaderDebugSampleProg(config); if(prog == 0) @@ -1165,7 +1166,7 @@ class GLAPIWrapper : public rdcspv::DebugAPIWrapper return false; } - m_pDriver->GetReplay()->UseReplayContext(); + GLMarkerRegion markerRegion("QueueSampleGather"); GLRenderState rs; rs.FetchState(m_pDriver); @@ -1287,9 +1288,9 @@ class GLAPIWrapper : public rdcspv::DebugAPIWrapper RDCASSERTEQUAL(params[0].type, VarType::Float); - GLMarkerRegion markerRegion("QueueCalculateMathOp"); + m_pDriver->GetReplay()->UseDebugContext(); - m_pDriver->GetReplay()->UseReplayContext(); + GLMarkerRegion markerRegion("QueueCalculateMathOp"); GLRenderState rs; rs.FetchState(m_pDriver); @@ -1380,6 +1381,9 @@ class GLAPIWrapper : public rdcspv::DebugAPIWrapper { CHECK_DEVICE_THREAD(); + GLuint oldbuf = 0; + GL.glGetIntegerv(eGL_COPY_READ_BUFFER_BINDING, (GLint *)&oldbuf); + bytebuf gpuResults; gpuResults.resize(m_MathBufferSize + m_SampleBufferSize); if(m_MathBuffer) @@ -1434,6 +1438,8 @@ class GLAPIWrapper : public rdcspv::DebugAPIWrapper gpuSampleGatherOpResults += sampleGatherOpResultByteSize; } + GL.glBindBuffer(eGL_COPY_READ_BUFFER, oldbuf); + return true; } @@ -1723,6 +1729,7 @@ class GLAPIWrapper : public rdcspv::DebugAPIWrapper // before it. if(m_ResourcesDirty) { + m_pDriver->GetReplay()->UseReplayContext(); GLMarkerRegion region("un-dirtying resources"); m_pDriver->GetReplay()->ReplayLog(m_EventID, eReplay_WithoutDraw); m_ResourcesDirty = false; @@ -1756,6 +1763,7 @@ class GLAPIWrapper : public rdcspv::DebugAPIWrapper // before it. if(m_ResourcesDirty) { + m_pDriver->GetReplay()->UseReplayContext(); GLMarkerRegion region("un-dirtying resources"); m_pDriver->GetReplay()->ReplayLog(m_EventID, eReplay_WithoutDraw); m_ResourcesDirty = false; @@ -4294,6 +4302,8 @@ rdcarray GLReplay::ContinueDebug(ShaderDebugger *debugger) if(!spvDebugger) return {}; + m_pDriver->GetReplay()->UseReplayContext(); + GLMarkerRegion region("ContinueDebug Simulation Loop"); rdcarray ret = spvDebugger->ContinueDebug(); @@ -4301,6 +4311,8 @@ rdcarray GLReplay::ContinueDebug(ShaderDebugger *debugger) GLAPIWrapper *api = (GLAPIWrapper *)spvDebugger->GetAPIWrapper(); api->ResetReplay(); + m_pDriver->GetReplay()->UseReplayContext(); + return ret; } diff --git a/renderdoc/driver/shaders/dxbc/dxbc_bytecode_editor.cpp b/renderdoc/driver/shaders/dxbc/dxbc_bytecode_editor.cpp index 334700c779a..68222d50759 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_bytecode_editor.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_bytecode_editor.cpp @@ -540,7 +540,7 @@ ret.zw += tex.Load(ret.xyz).yz; { bytebuf bytecode = dxbccompile(make_source(snippet), profile); - DXBC::DXBCContainer container(bytecode, rdcstr(), GraphicsAPI::D3D11, ~0U, ~0U); + DXBC::DXBCContainer container(bytecode); bytebuf edited; { @@ -578,7 +578,7 @@ ret.zw += tex.Load(ret.xyz).yz; { bytebuf bytecode = dxbccompile(make_source(snippets[i]), profile); - DXBC::DXBCContainer container(bytecode, rdcstr(), GraphicsAPI::D3D11, ~0U, ~0U); + DXBC::DXBCContainer container(bytecode); rdcstr disasm_before = container.GetDXBCByteCode()->GetDisassembly(); uint32_t temp_index = 123456; @@ -590,7 +590,7 @@ ret.zw += tex.Load(ret.xyz).yz; temp_index = editor.AddTemp(); } - DXBC::DXBCContainer container2(edited, rdcstr(), GraphicsAPI::D3D11, ~0U, ~0U); + DXBC::DXBCContainer container2(edited); rdcstr disasm_after = container2.GetDXBCByteCode()->GetDisassembly(); @@ -615,7 +615,7 @@ ret.zw += tex.Load(ret.xyz).yz; { bytebuf bytecode = dxbccompile(make_source(""), profile); - DXBC::DXBCContainer container(bytecode, rdcstr(), GraphicsAPI::D3D11, ~0U, ~0U); + DXBC::DXBCContainer container(bytecode); rdcstr disasm_before = container.GetDXBCByteCode()->GetDisassembly(); uint32_t t = 123456; @@ -655,7 +655,7 @@ ret.zw += tex.Load(ret.xyz).yz; op.operands[1].comps[2], op.operands[1].comps[3]); } - DXBC::DXBCContainer container2(edited, rdcstr(), GraphicsAPI::D3D11, ~0U, ~0U); + DXBC::DXBCContainer container2(edited); rdcstr disasm_after = container2.GetDXBCByteCode()->GetDisassembly(); @@ -685,7 +685,7 @@ ret += tex2.Load(uvm); )"), profile); - DXBC::DXBCContainer container(bytecode, rdcstr(), GraphicsAPI::D3D11, ~0U, ~0U); + DXBC::DXBCContainer container(bytecode); rdcstr disasm_before = container.GetDXBCByteCode()->GetDisassembly(); @@ -728,7 +728,7 @@ ret += tex2.Load(uvm); } } - DXBC::DXBCContainer container2(edited, rdcstr(), GraphicsAPI::D3D11, ~0U, ~0U); + DXBC::DXBCContainer container2(edited); rdcstr disasm_after = container2.GetDXBCByteCode()->GetDisassembly(); diff --git a/renderdoc/driver/shaders/dxbc/dxbc_container.cpp b/renderdoc/driver/shaders/dxbc/dxbc_container.cpp index c4d7338bf00..70cc3474c33 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_container.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_container.cpp @@ -1484,282 +1484,289 @@ rdcstr DXBCContainer::GetDebugBinaryPath(const void *ByteCode, size_t ByteCodeLe return debugPath; } -void DXBCContainer::TryFetchSeparateDebugInfo(bytebuf &byteCode, const rdcstr &debugInfoPath) +bool DXBCContainer::TryFetchSeparateDebugInfo(const rdcstr &debugInfoPath) { - rdcstr loadingLog; - if(!CheckForDebugInfo((const void *)&byteCode[0], byteCode.size())) - { - rdcstr originalPath = debugInfoPath; - - rdcfixedarray desiredHash; - GetHash(desiredHash, true, byteCode.data(), byteCode.size()); - - if(originalPath.empty()) - originalPath = GetDebugBinaryPath((const void *)&byteCode[0], byteCode.size()); - - if(originalPath.empty() && - (desiredHash[0] != 0 || desiredHash[1] != 0 || desiredHash[2] != 0 || desiredHash[3] != 0)) - { - byte *h = (byte *)desiredHash.data(); - for(uint32_t i = 0; i < desiredHash.byteSize(); i++) - originalPath += StringFormat::Fmt("%02x", h[i]); - originalPath += ".pdb"; - loadingLog += StringFormat::Fmt("No shader PDB filename specified using default '%s'\n\n", - originalPath.c_str()); - RDCDEBUG("No shader pdb filename specified - assuming default '%s'", originalPath.c_str()); - } - - if(!originalPath.empty()) - { - bool lz4 = false; + rdcstr originalPath = debugInfoPath; + if(CheckForDebugInfo((const void *)&m_ShaderBlob[0], m_ShaderBlob.size())) + return true; - // DComp extension to allow lz4 compression - if(!strncmp(originalPath.c_str(), "lz4#", 4)) - { - originalPath = originalPath.substr(4); - lz4 = true; - } - // could support more if we're willing to compile in the decompressor + m_DebugInfoLoadingLog = + "Details\n" + "-------\n\n"; - const rdcarray &searchPaths = DXBC_Debug_SearchDirPaths(); + rdcfixedarray desiredHash; + GetHash(desiredHash, true, m_ShaderBlob.data(), m_ShaderBlob.size()); - size_t numSearchPaths = searchPaths.size(); + if(originalPath.empty()) + originalPath = GetDebugBinaryPath((const void *)&m_ShaderBlob[0], m_ShaderBlob.size()); - const rdcarray nonRecursiveSearchPaths = Replay_Shader_LimitedSearchDirPaths(); - loadingLog += StringFormat::Fmt("Shader filepath '%s'\n", originalPath.c_str()); - if(searchPaths.size() > nonRecursiveSearchPaths.size()) - { - loadingLog += rdcstr("\nRecursive Search Path(s):\n"); - for(const rdcstr &path : searchPaths) - { - if(nonRecursiveSearchPaths.contains(path)) - continue; - loadingLog += StringFormat::Fmt("'%s'\n", path.c_str()); - } - } - else - { - loadingLog += rdcstr("\nNo Recursive Search Paths\n"); - } - if(!nonRecursiveSearchPaths.empty()) - { - loadingLog += rdcstr("\nNon-Recursive Search Path(s):\n"); - for(const rdcstr &path : nonRecursiveSearchPaths) - loadingLog += StringFormat::Fmt("'%s'\n", path.c_str()); - } - else - { - loadingLog += rdcstr("\nNo Non-Recursive Search Paths\n"); - } - - DebugFile found; - - rdcstr nickname = originalPath; - // keep searching until we've exhausted all possible path options, or we've found a file that - // opens and (optionally if we have it matches the hash we're looking for) - rdcstr tempPath = originalPath; - - // if the path specified does not end in a .pdb it seems like PIX appends that, so do this just - // to match. It's really fun matching behaviour in an application that is deliberately undocumented - bool hasSuffix = tempPath.endsWith(".pdb") || tempPath.endsWith(".PDB"); + if(originalPath.empty() && + (desiredHash[0] != 0 || desiredHash[1] != 0 || desiredHash[2] != 0 || desiredHash[3] != 0)) + { + byte *h = (byte *)desiredHash.data(); + for(uint32_t i = 0; i < desiredHash.byteSize(); i++) + originalPath += StringFormat::Fmt("%02x", h[i]); + originalPath += ".pdb"; + m_DebugInfoLoadingLog += StringFormat::Fmt( + "No shader PDB filename specified. Using default '%s'\n\n", originalPath.c_str()); + RDCDEBUG("No shader pdb filename specified - assuming default '%s'", originalPath.c_str()); + } - while(found.empty() && !tempPath.empty()) - { - // while we haven't found a file, keep trying through the search paths. For i==0 - // check the path on its own, in case it's an absolute path. - for(size_t i = 0; found.empty() && i <= numSearchPaths; i++) - { - if(i == 0) - { - loadingLog += rdcstr("\n"); - if(FileIO::exists(tempPath)) - found.path = tempPath; - else if(!hasSuffix && FileIO::exists(tempPath + ".pdb")) - found.path = tempPath + ".pdb"; + if(originalPath.empty()) + return false; - if(!found.empty()) - { - RDCDEBUG("Found %s (matched using leaf %s) when looking for %s", found.path.c_str(), - tempPath.c_str(), originalPath.c_str()); + bool lz4 = false; - // this may empty out found, if the hash doesn't match - found.ReadAndProcess(lz4, desiredHash, loadingLog); - loadingLog += StringFormat::Fmt("File found using filepath '%s'\n", found.path.c_str()); - } - else - { - loadingLog += - StringFormat::Fmt("File not found using filepath '%s'\n", tempPath.c_str()); - if(!hasSuffix) - loadingLog += - StringFormat::Fmt("File not found using filepath '%s.pdb'\n", tempPath.c_str()); - } - } - else - { - const rdcstr &searchPath = searchPaths[i - 1]; + // DComp extension to allow lz4 compression + if(!strncmp(originalPath.c_str(), "lz4#", 4)) + { + originalPath = originalPath.substr(4); + lz4 = true; + } + // could support more if we're willing to compile in the decompressor - rdcstr checkPath = searchPath + "/" + tempPath; + const rdcarray &searchPaths = DXBC_Debug_SearchDirPaths(); - if(FileIO::exists(checkPath)) - found.path = checkPath; - else if(!hasSuffix && FileIO::exists(checkPath + ".pdb")) - found.path = checkPath + ".pdb"; + size_t numSearchPaths = searchPaths.size(); - if(!found.empty()) - { - RDCDEBUG("Found %s (matched using leaf %s) when looking for %s", found.path.c_str(), - tempPath.c_str(), originalPath.c_str()); + const rdcarray nonRecursiveSearchPaths = Replay_Shader_LimitedSearchDirPaths(); + m_DebugInfoLoadingLog += StringFormat::Fmt("Shader filepath '%s'\n", originalPath.c_str()); + if(searchPaths.size() > nonRecursiveSearchPaths.size()) + { + m_DebugInfoLoadingLog += rdcstr("\nRecursive Search Path(s):\n"); + for(const rdcstr &path : searchPaths) + { + if(nonRecursiveSearchPaths.contains(path)) + continue; + m_DebugInfoLoadingLog += StringFormat::Fmt("'%s'\n", path.c_str()); + } + } + else + { + m_DebugInfoLoadingLog += rdcstr("\nNo Recursive Search Paths\n"); + } + if(!nonRecursiveSearchPaths.empty()) + { + m_DebugInfoLoadingLog += rdcstr("\nNon-Recursive Search Path(s):\n"); + for(const rdcstr &path : nonRecursiveSearchPaths) + m_DebugInfoLoadingLog += StringFormat::Fmt("'%s'\n", path.c_str()); + } + else + { + m_DebugInfoLoadingLog += rdcstr("\nNo Non-Recursive Search Paths\n"); + } - // this may empty out found, if the hash doesn't match - found.ReadAndProcess(lz4, desiredHash, loadingLog); - loadingLog += StringFormat::Fmt( - "File found in search directory using filepath '%s'\n", found.path.c_str()); - } - else - { - loadingLog += StringFormat::Fmt( - "File not found in search directory using filepath '%s'\n", checkPath.c_str()); - if(!hasSuffix) - loadingLog += StringFormat::Fmt( - "File not found in search directory using filepath '%s.pdb'\n", - checkPath.c_str()); - } - } - } + DebugFile found; - if(found.empty()) - { - // the "documented" behaviour for D3D debug info names is that when presented with a - // relative path containing subfolders like foo/bar/blah.pdb then we should first try to - // append it to all search paths as-is, then strip off the top-level subdirectory to get - // bar/blah.pdb and try that in all search directories, and keep going. So if we got here - // and didn't open a file, try to strip off the the top directory and continue. - int32_t offs = tempPath.find_first_of("\\/"); - - // if we couldn't find a directory separator there's nothing to do, stop looking - if(offs == -1) - break; + rdcstr nickname = originalPath; + // keep searching until we've exhausted all possible path options, or we've found a file that + // opens and (optionally if we have it matches the hash we're looking for) + rdcstr tempPath = originalPath; - // otherwise strip up to there and keep going - tempPath.erase(0, offs + 1); - } - } + // if the path specified does not end in a .pdb it seems like PIX appends that, so do this just + // to match. It's really fun matching behaviour in an application that is deliberately undocumented + bool hasSuffix = tempPath.endsWith(".pdb") || tempPath.endsWith(".PDB"); - // the "undocumented" behaviour for PIX is to recursively search in search paths subfolders - // for the file. Since it's unclear exactly how this interacts with search priorities and - // subfolders, we only do this if the path is a single filename with no subfolders, and we - // assume the filename is unique so pick the first match. To reduce disk churn O(N^2) style we - // cache the recursive contents of the search folders. This will be cleared by the replay code - // on each replay. - if(found.empty() && !originalPath.contains('/') && !originalPath.contains('\\')) + while(found.empty() && !tempPath.empty()) + { + // while we haven't found a file, keep trying through the search paths. For i==0 + // check the path on its own, in case it's an absolute path. + for(size_t i = 0; found.empty() && i <= numSearchPaths; i++) + { + if(i == 0) { - loadingLog += rdcstr("\n"); - CacheSearchDirDebugPaths(); + m_DebugInfoLoadingLog += rdcstr("\n"); + if(FileIO::exists(tempPath)) + found.path = tempPath; + else if(!hasSuffix && FileIO::exists(tempPath + ".pdb")) + found.path = tempPath + ".pdb"; - auto it = cachedDebugFilesLookup.find(originalPath); - if(it == cachedDebugFilesLookup.end() && !hasSuffix) - it = cachedDebugFilesLookup.find(originalPath + ".pdb"); - if(it != cachedDebugFilesLookup.end()) + if(!found.empty()) { - found.path = it->second; - RDCDEBUG("Found %s recursively as %s", originalPath.c_str(), found.path.c_str()); + RDCDEBUG("Found %s (matched using leaf %s) when looking for %s", found.path.c_str(), + tempPath.c_str(), originalPath.c_str()); - found.ReadAndProcess(lz4, desiredHash, loadingLog); - loadingLog += StringFormat::Fmt( - "File found in recursive directory search using filepath '%s'\n", found.path.c_str()); + // this may empty out found, if the hash doesn't match + found.ReadAndProcess(lz4, desiredHash, m_DebugInfoLoadingLog); + m_DebugInfoLoadingLog += + StringFormat::Fmt("File found using filepath '%s'\n", found.path.c_str()); } else { - loadingLog += StringFormat::Fmt( - "File not found in recursive directory search using filepath '%s'\n", - originalPath.c_str()); + m_DebugInfoLoadingLog += + StringFormat::Fmt("File not found using filepath '%s'\n", tempPath.c_str()); if(!hasSuffix) - loadingLog += StringFormat::Fmt( - "File not found in recursive directory search using filepath '%s.pdb'\n", - originalPath.c_str()); + m_DebugInfoLoadingLog += + StringFormat::Fmt("File not found using filepath '%s.pdb'\n", tempPath.c_str()); } } - else if(found.empty()) + else { - loadingLog += StringFormat::Fmt( - "\nNot performing a recursive directory search because filepath contains directory " - "information '%s'\n", - originalPath.c_str()); - } + const rdcstr &searchPath = searchPaths[i - 1]; - // Try to retrieve debug file from the externally referenced files in the capture - if(found.empty()) - { - if(RenderDoc::Inst().GetTrackedFileData(nickname, found.contents)) + rdcstr checkPath = searchPath + "/" + tempPath; + + if(FileIO::exists(checkPath)) + found.path = checkPath; + else if(!hasSuffix && FileIO::exists(checkPath + ".pdb")) + found.path = checkPath + ".pdb"; + + if(!found.empty()) { - loadingLog += StringFormat::Fmt( - "\nFound debug data from files embedded in the capture using nickname '%s'\n", - nickname.c_str()); - found.path = nickname; - found.Process(lz4, desiredHash, loadingLog); + RDCDEBUG("Found %s (matched using leaf %s) when looking for %s", found.path.c_str(), + tempPath.c_str(), originalPath.c_str()); + + // this may empty out found, if the hash doesn't match + found.ReadAndProcess(lz4, desiredHash, m_DebugInfoLoadingLog); + m_DebugInfoLoadingLog += StringFormat::Fmt( + "File found in search directory using filepath '%s'\n", found.path.c_str()); } else { - loadingLog += StringFormat::Fmt( - "\nFile not found in files embedded in the capture using nickname '%s'\n", - nickname.c_str()); + m_DebugInfoLoadingLog += StringFormat::Fmt( + "File not found in search directory using filepath '%s'\n", checkPath.c_str()); + if(!hasSuffix) + m_DebugInfoLoadingLog += StringFormat::Fmt( + "File not found in search directory using filepath '%s.pdb'\n", checkPath.c_str()); } } + } - if(found.empty()) - { - RDCDEBUG("Couldn't find pdb for %s", originalPath.c_str()); - m_DebugInfoLoadingLog = - StringFormat::Fmt("Did not find debug data for '%s'\n\n", originalPath.c_str()); - if(!loadingLog.empty()) - { - m_DebugInfoLoadingLog += StringFormat::Fmt("Details\n"); - m_DebugInfoLoadingLog += StringFormat::Fmt("-------\n\n"); - m_DebugInfoLoadingLog += loadingLog; - } - return; - } + if(found.empty()) + { + // the "documented" behaviour for D3D debug info names is that when presented with a + // relative path containing subfolders like foo/bar/blah.pdb then we should first try to + // append it to all search paths as-is, then strip off the top-level subdirectory to get + // bar/blah.pdb and try that in all search directories, and keep going. So if we got here + // and didn't open a file, try to strip off the the top directory and continue. + int32_t offs = tempPath.find_first_of("\\/"); - RenderDoc::Inst().AddTrackedFileReference(nickname, found.path); + // if we couldn't find a directory separator there's nothing to do, stop looking + if(offs == -1) + break; - if(found.pdb) - { - m_DebugShaderBlob = found.contents; - } - else if(CheckForDebugInfo(found.contents.data(), found.contents.size())) - { - if(m_InitialShaderBlob.isEmpty()) - m_InitialShaderBlob = byteCode; - byteCode.swap(found.contents); - } - m_DebugInfoLoadingLog = - StringFormat::Fmt("Found debug data using filepath '%s'\n\n", found.path.c_str()); + // otherwise strip up to there and keep going + tempPath.erase(0, offs + 1); } } - else + + // the "undocumented" behaviour for PIX is to recursively search in search paths subfolders + // for the file. Since it's unclear exactly how this interacts with search priorities and + // subfolders, we only do this if the path is a single filename with no subfolders, and we + // assume the filename is unique so pick the first match. To reduce disk churn O(N^2) style we + // cache the recursive contents of the search folders. This will be cleared by the replay code + // on each replay. + if(found.empty() && !originalPath.contains('/') && !originalPath.contains('\\')) + { + m_DebugInfoLoadingLog += rdcstr("\n"); + CacheSearchDirDebugPaths(); + + auto it = cachedDebugFilesLookup.find(originalPath); + if(it == cachedDebugFilesLookup.end() && !hasSuffix) + it = cachedDebugFilesLookup.find(originalPath + ".pdb"); + if(it != cachedDebugFilesLookup.end()) + { + found.path = it->second; + RDCDEBUG("Found %s recursively as %s", originalPath.c_str(), found.path.c_str()); + + found.ReadAndProcess(lz4, desiredHash, m_DebugInfoLoadingLog); + m_DebugInfoLoadingLog += StringFormat::Fmt( + "File found in recursive directory search using filepath '%s'\n", found.path.c_str()); + } + else + { + m_DebugInfoLoadingLog += StringFormat::Fmt( + "File not found in recursive directory search using filepath '%s'\n", originalPath.c_str()); + if(!hasSuffix) + m_DebugInfoLoadingLog += StringFormat::Fmt( + "File not found in recursive directory search using filepath '%s.pdb'\n", + originalPath.c_str()); + } + } + else if(found.empty()) + { + m_DebugInfoLoadingLog += StringFormat::Fmt( + "\nNot performing a recursive directory search because filepath contains directory " + "information '%s'\n", + originalPath.c_str()); + } + + // Try to retrieve debug file from the externally referenced files in the capture + if(found.empty()) + { + if(RenderDoc::Inst().GetTrackedFileData(nickname, found.contents)) + { + m_DebugInfoLoadingLog += StringFormat::Fmt( + "\nFound debug data from files embedded in the capture using nickname '%s'\n", + nickname.c_str()); + found.path = nickname; + found.Process(lz4, desiredHash, m_DebugInfoLoadingLog); + } + else + { + m_DebugInfoLoadingLog += StringFormat::Fmt( + "\nFile not found in files embedded in the capture using nickname '%s'\n", + nickname.c_str()); + } + } + + if(found.empty()) { - m_DebugInfoLoadingLog = - StringFormat::Fmt("Found debug data in the shader\n\n", debugInfoPath.c_str()); + RDCDEBUG("Couldn't find pdb for %s", originalPath.c_str()); + return false; } - if(!loadingLog.empty()) + + RenderDoc::Inst().AddTrackedFileReference(nickname, found.path); + + if(found.pdb) { - m_DebugInfoLoadingLog += StringFormat::Fmt("Details\n"); - m_DebugInfoLoadingLog += StringFormat::Fmt("-------\n\n"); - m_DebugInfoLoadingLog += loadingLog; + m_DebugShaderBlob = found.contents; } + else if(CheckForDebugInfo(found.contents.data(), found.contents.size())) + { + m_ShaderBlob.swap(found.contents); + m_ReplacedBlob = true; + } + + m_DebugInfoLoadingLog += StringFormat::Fmt("Found debug data in '%s'\n\n", found.path.c_str()); + + return true; } -DXBCContainer::DXBCContainer(const bytebuf &ByteCode, const rdcstr &debugInfoPath, GraphicsAPI api, - uint32_t shaderExtReg, uint32_t shaderExtSpace) +DXBCContainer::DXBCContainer(bytebuf &&ByteCode, const rdcstr &debugInfoPath) { - RDCEraseEl(m_ShaderStats); - - m_ShaderBlob = ByteCode; + m_ShaderBlob = std::move(ByteCode); if(RenderDoc::Inst().IsReplayApp()) - TryFetchSeparateDebugInfo(m_ShaderBlob, debugInfoPath); + TryFetchSeparateDebugInfo(debugInfoPath); + + Init(); +} + +DXBCContainer::DXBCContainer(DXBCContainer *oldToRecreate, const rdcstr &debugInfoPath) +{ + m_ShaderBlob = oldToRecreate->m_ShaderBlob; + + // try as much as possible to search again from scratch - if we replaced the whole m_ShaderBlob + // before then we are searching based on new information but that's fine (and only happens in the + // super-legacy path with PRIV sections that is likely not used anywhere anymore) + if(!TryFetchSeparateDebugInfo(debugInfoPath)) + { + // if we failed to get debug info but the old container has it, then steal it and its loading log + if(oldToRecreate->HasDebugInfo()) + { + m_DebugShaderBlob.swap(oldToRecreate->m_DebugShaderBlob); + m_DebugInfoLoadingLog.swap(oldToRecreate->m_DebugInfoLoadingLog); + } + } + + SAFE_DELETE(oldToRecreate); + + Init(); +} +void DXBCContainer::Init() +{ // just for convenience byte *data = (byte *)m_ShaderBlob.data(); byte *debugData = (byte *)m_DebugShaderBlob.data(); @@ -2201,6 +2208,7 @@ DXBCContainer::DXBCContainer(const bytebuf &ByteCode, const rdcstr &debugInfoPat if(*fourcc == FOURCC_ILDB) { dxilILDBProgram = new DXIL::Program((const byte *)chunkContents, *chunkSize); + m_HasDebugInfo = true; } } @@ -2252,6 +2260,7 @@ DXBCContainer::DXBCContainer(const bytebuf &ByteCode, const rdcstr &debugInfoPat SAFE_DELETE(dxilSTATProgram); SAFE_DELETE(dxilDXILProgram); dxilReflectProgram = m_DXILByteCode = dxilILDBProgram; + m_HasDebugInfo = true; } else if(dxilDXILProgram) { @@ -2587,7 +2596,10 @@ DXBCContainer::DXBCContainer(const bytebuf &ByteCode, const rdcstr &debugInfoPat if(m_DebugInfo) { if(m_DXBCByteCode) + { m_DXBCByteCode->SetDebugInfo(m_DebugInfo); + m_HasDebugInfo = true; + } PreprocessLineDirectives(m_DebugInfo->Files); } @@ -2624,7 +2636,13 @@ DXBCContainer::DXBCContainer(const bytebuf &ByteCode, const rdcstr &debugInfoPat if(m_DXBCByteCode || m_DXILByteCode) { RDCASSERT(m_Reflection); + } +} +void DXBCContainer::SetShaderExts(GraphicsAPI api, uint32_t shaderExtReg, uint32_t shaderExtSpace) +{ + if(m_DXBCByteCode || m_DXILByteCode) + { if(shaderExtReg != ~0U) { bool found = false; @@ -3157,7 +3175,7 @@ TEST_CASE("DO NOT COMMIT - convenience test", "[dxbc]") bytebuf buf; FileIO::ReadAll("/path/to/container_file.dxbc", buf); - DXBC::DXBCContainer container(buf, rdcstr(), GraphicsAPI::D3D11, ~0U, ~0U); + DXBC::DXBCContainer container(buf, rdcstr()); // the only thing fetched lazily is the disassembly, so grab that here diff --git a/renderdoc/driver/shaders/dxbc/dxbc_container.h b/renderdoc/driver/shaders/dxbc/dxbc_container.h index 9b7c91a4479..614e0994b17 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_container.h +++ b/renderdoc/driver/shaders/dxbc/dxbc_container.h @@ -190,26 +190,33 @@ void EncodeDXCFlags(uint32_t flags, rdcarray &args); class DXBCContainer { public: - DXBCContainer(const bytebuf &ByteCode, const rdcstr &debugInfoPath, GraphicsAPI api, - uint32_t shaderExtReg, uint32_t shaderExtSpace); + DXBCContainer(bytebuf &&ByteCode, const rdcstr &debugInfoPath = rdcstr()); + DXBCContainer(const bytebuf &ByteCode, const rdcstr &debugInfoPath = rdcstr()) + : DXBCContainer(bytebuf(ByteCode), debugInfoPath) + { + } + DXBCContainer(DXBCContainer *oldToRecreate, const rdcstr &debugInfoPath); ~DXBCContainer(); DXBCContainer(const DXBCContainer &o) = delete; DXBCContainer(DXBCContainer &&o) = delete; DXBCContainer &operator=(const DXBCContainer &o) = delete; + void SetShaderExts(GraphicsAPI api, uint32_t shaderExtReg, uint32_t shaderExtSpace); + DXBC::ShaderType m_Type = DXBC::ShaderType::Max; struct { uint32_t Major = 0, Minor = 0; } m_Version; - const bytebuf &GetInitialShaderBlob() const { return m_InitialShaderBlob; } const bytebuf &GetShaderBlob() const { return m_ShaderBlob; } const IDebugInfo *GetDebugInfo() const { return m_DebugInfo; } const Reflection *GetReflection() const { return m_Reflection; } void CacheOutputTopology(); D3D_PRIMITIVE_TOPOLOGY GetOutputTopology() const { return m_OutputTopology; } ThreadScope GetThreadScope() const { return m_Threadscope; } + bool LoadedDebugBlob() const { return !m_DebugShaderBlob.empty() || m_ReplacedBlob; } + bool HasDebugInfo() const { return m_HasDebugInfo; } const rdcstr &GetDebugInfoLoadingLog() const { return m_DebugInfoLoadingLog; } CBufferVariableType GetRayPayload(const ShaderEntryPoint &entry) @@ -265,10 +272,8 @@ class DXBCContainer static bool UsesExtensionUAV(uint32_t slot, uint32_t space, const void *ByteCode, size_t BytecodeLength); - static bool CheckForDebugInfo(const void *ByteCode, size_t ByteCodeLength); static bool CheckForDXIL(const void *ByteCode, size_t ByteCodeLength); static bool CheckForRootSig(const void *ByteCode, size_t ByteCodeLength); - static rdcstr GetDebugBinaryPath(const void *ByteCode, size_t ByteCodeLength); static D3D_PRIMITIVE_TOPOLOGY GetOutputTopology(const void *ByteCode, size_t ByteCodeLength); bool GetPipelineValidation(DXIL::PSVData &psv) const; @@ -280,13 +285,19 @@ class DXBCContainer static void SetRuntimeData(bytebuf &ByteCode, const DXIL::RDATData &rdat); private: - void TryFetchSeparateDebugInfo(bytebuf &byteCode, const rdcstr &debugInfoPath); + static bool CheckForDebugInfo(const void *ByteCode, size_t ByteCodeLength); + static rdcstr GetDebugBinaryPath(const void *ByteCode, size_t ByteCodeLength); + + void Init(); + + bool TryFetchSeparateDebugInfo(const rdcstr &debugInfoPath); void ProcessSourceInfo(const byte *chunkContents, uint32_t size); bytebuf m_DebugShaderBlob; bytebuf m_ShaderBlob; - // Only set when separate debug data is found - bytebuf m_InitialShaderBlob; + + bool m_HasDebugInfo = false; + bool m_ReplacedBlob = false; rdcstr m_Disassembly; rdcstr m_DebugInfoLoadingLog; @@ -315,7 +326,7 @@ class DXBCContainer rdcflatmap> m_RayPayloads; ThreadScope m_Threadscope = ThreadScope::Thread; - ShaderStatistics m_ShaderStats; + ShaderStatistics m_ShaderStats = {}; DXBCBytecode::Program *m_DXBCByteCode = NULL; DXIL::Program *m_DXILByteCode = NULL; IDebugInfo *m_DebugInfo = NULL; diff --git a/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp b/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp index 3ccf7a254b8..7eb214c85ec 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp @@ -2209,7 +2209,7 @@ void ThreadState::StepNext(ShaderDebugState *state, DebugAPIWrapper *apiWrapper, for(int i = 0; i < 4; i++) src[i] = (uint64_t)srcOpers[1].value.u32v[i]; for(int i = 0; i < 4; i++) - src[i] = (uint64_t)srcOpers[2].value.u32v[i]; + src[i] += (uint64_t)srcOpers[2].value.u32v[i]; // set the rounded result uint32_t dst[4]; diff --git a/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp b/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp index 0ea6d8a229e..ab4ac8753fe 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_reflect.cpp @@ -320,7 +320,21 @@ void MakeShaderReflection(DXBC::DXBCContainer *dxbc, const ShaderEntryPoint &ent } refl->debugInfo.entrySourceName = refl->entryPoint = "main"; - refl->debugInfo.debugInfoLoadingLog = dxbc->GetDebugInfoLoadingLog(); + + if(!dxbc->HasDebugInfo()) + { + refl->debugInfo.debugInfoLoadingLog = "Did not find debug data.\n\n"; + } + else if(!dxbc->LoadedDebugBlob()) + { + refl->debugInfo.debugInfoLoadingLog = "Shader contained debug data.\n\n"; + } + else + { + refl->debugInfo.debugInfoLoadingLog = "Found separate debug data.\n\n"; + } + + refl->debugInfo.debugInfoLoadingLog += dxbc->GetDebugInfoLoadingLog(); if(dxbc->GetDebugInfo()) { diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.h b/renderdoc/driver/shaders/spirv/spirv_debug.h index 36452744fa0..6fe65cad86b 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.h +++ b/renderdoc/driver/shaders/spirv/spirv_debug.h @@ -811,6 +811,7 @@ class Debugger : public Processor, public ShaderDebugger rdcstr name; }; + std::set usedNames; DenseIdMap strings; rdcarray memberNames; std::map entryLookup; @@ -841,10 +842,6 @@ class Debugger : public Processor, public ShaderDebugger rdcarray instructionOffsets; - mutable std::set usedNames; - mutable Threading::RWLock dynamicNamesLock; - mutable std::map dynamicNames; - struct { bool valid = false; diff --git a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp index e698af3718b..628b99b63ae 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp @@ -2953,13 +2953,7 @@ void Debugger::FillDefaultSourceVars(rdcarray &instInfo) // one exists. if(id != Id() && idLiveRange[id].first == offs) { - rdcstr name; - - auto dyn = dynamicNames.find(id); - if(dyn != dynamicNames.end()) - name = dyn->second; - else - name = strings[id]; + rdcstr name = strings[id]; if(!name.empty()) { @@ -4144,14 +4138,6 @@ DeviceOpResult Debugger::WriteThroughPointer(ShaderVariable &ptr, const ShaderVa rdcstr Debugger::GetHumanName(Id id) const { - { - SCOPED_READLOCK(dynamicNamesLock); - // see if we have a dynamic name assigned (to disambiguate), if so use that - auto it = dynamicNames.find(id); - if(it != dynamicNames.end()) - return it->second; - } - // otherwise try the string first rdcstr name = strings[id]; @@ -4159,25 +4145,6 @@ rdcstr Debugger::GetHumanName(Id id) const if(name.empty()) return GetRawName(id); - rdcstr basename = name; - - // otherwise check to see if it's been used before. If so give it a new name - { - SCOPED_READLOCK(dynamicNamesLock); - int alias = 2; - while(usedNames.find(name) != usedNames.end()) - { - name = basename + "@" + ToStr(alias); - alias++; - } - } - - { - SCOPED_WRITELOCK(dynamicNamesLock); - usedNames.insert(name); - dynamicNames[id] = name; - } - return name; } @@ -4995,8 +4962,21 @@ void Debugger::RegisterOp(Iter it) OpName name(it); // technically you could name a string - in that case we ignore the name - if(strings[name.target].empty()) - strings[name.target] = name.name; + if(strings[name.target].empty() && !name.name.empty()) + { + rdcstr nameStr = name.name; + + int alias = 2; + while(usedNames.find(nameStr) != usedNames.end()) + { + nameStr = name.name + "@" + ToStr(alias); + alias++; + } + + usedNames.insert(nameStr); + + strings[name.target] = nameStr; + } } else if(opdata.op == Op::MemberName) { diff --git a/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp b/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp index 4e3a82bd3ae..d5238c23a71 100644 --- a/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp @@ -143,8 +143,7 @@ namespace rdcspv rdcstr Reflector::Disassemble(const rdcstr &entryPoint, const rdcarray &specInfo, std::map &instructionLines) const { - std::set usedNames; - std::map dynamicNames; + SparseIdMap dynamicNames; auto idName = [this, &dynamicNames, &specInfo](Id id) -> rdcstr { // see if we have a dynamic name assigned (to disambiguate), if so use that @@ -182,7 +181,7 @@ rdcstr Reflector::Disassemble(const rdcstr &entryPoint, const rdcarray rdcstr { + auto declName = [this, &idName](Id typeId, Id id) -> rdcstr { if(typeId == Id()) return idName(id); @@ -195,23 +194,9 @@ rdcstr Reflector::Disassemble(const rdcstr &entryPoint, const rdcarray rdcstr { if(!dec.HasDecorations()) diff --git a/renderdoc/driver/shaders/spirv/spirv_reflect.cpp b/renderdoc/driver/shaders/spirv/spirv_reflect.cpp index 3bb78d7da2c..aab8d2c2c61 100644 --- a/renderdoc/driver/shaders/spirv/spirv_reflect.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_reflect.cpp @@ -620,8 +620,21 @@ void Reflector::RegisterOp(Iter it) OpName name(it); // technically you could name a string - in that case we ignore the name - if(strings[name.target].empty()) - strings[name.target] = name.name; + if(strings[name.target].empty() && !name.name.empty()) + { + rdcstr nameStr = name.name; + + int alias = 2; + while(usedNames.find(nameStr) != usedNames.end()) + { + nameStr = name.name + "@" + ToStr(alias); + alias++; + } + + usedNames.insert(nameStr); + + strings[name.target] = nameStr; + } } else if(opdata.op == Op::MemberName) { diff --git a/renderdoc/driver/shaders/spirv/spirv_reflect.h b/renderdoc/driver/shaders/spirv/spirv_reflect.h index 2a710f4463a..13a33e7bfde 100644 --- a/renderdoc/driver/shaders/spirv/spirv_reflect.h +++ b/renderdoc/driver/shaders/spirv/spirv_reflect.h @@ -156,6 +156,7 @@ class Reflector : public Processor const rdcarray &specInfo) const; rdcstr cmdline; + std::set usedNames; DenseIdMap strings; SourceLanguage sourceLanguage = SourceLanguage::Unknown; rdcarray sources; diff --git a/renderdoc/driver/vulkan/vk_core.cpp b/renderdoc/driver/vulkan/vk_core.cpp index 31677cbad02..1f3cdedac40 100644 --- a/renderdoc/driver/vulkan/vk_core.cpp +++ b/renderdoc/driver/vulkan/vk_core.cpp @@ -3816,13 +3816,8 @@ RDResult WrappedVulkan::ReadLogInitialisation(RDCFile *rdc, bool storeStructured uint64_t offsetEnd = reader->GetOffset(); - // only set progress after we've initialised the debug manager, to prevent progress jumping - // backwards. - if(m_DebugManager || IsStructuredExporting(m_State)) - { - RenderDoc::Inst().SetProgress(LoadProgress::FileInitialRead, - float(offsetEnd) / float(reader->GetSize())); - } + RenderDoc::Inst().SetProgress(LoadProgress::FileInitialRead, + float(offsetEnd) / float(reader->GetSize())); if((SystemChunk)context == SystemChunk::CaptureScope) { @@ -5655,7 +5650,7 @@ void WrappedVulkan::AddDebugMessage(MessageCategory c, MessageSeverity sv, Messa void WrappedVulkan::AddDebugMessage(DebugMessage msg) { if(IsLoading(m_State)) - m_LoadingEventNode.debugMessages.push_back(msg); + GetLoadingEventNode().debugMessages.push_back(msg); else m_DebugMessages.push_back(msg); } @@ -6053,6 +6048,10 @@ bool WrappedVulkan::IsPartialRenderPassActiveUnsuspended() bool WrappedVulkan::ShouldUpdateRenderpassActive(ResourceId cmdId, bool dynamicRendering) { + // loading will replay all events + if(IsLoading(m_State)) + return false; + if(m_OutsideCmdBuffer != VK_NULL_HANDLE) return true; @@ -6066,6 +6065,10 @@ bool WrappedVulkan::ShouldUpdateRenderpassActive(ResourceId cmdId, bool dynamicR bool WrappedVulkan::InRerecordRange(ResourceId cmdid) { + // loading will replay all events + if(IsLoading(m_State)) + return true; + // if we have an outside command buffer, assume the range is valid and we're replaying all events // onto it. if(m_OutsideCmdBuffer != VK_NULL_HANDLE) @@ -6380,25 +6383,19 @@ void WrappedVulkan::AddUsage(VulkanEventNode &eventNode) if(action.flags & ActionFlags::Drawcall) { if(action.flags & ActionFlags::Indexed && state.ibuffer.buf != ResourceId()) - eventNode.resourceUsage.push_back(make_rdcpair(state.ibuffer.buf, ResourceUsage::IndexBuffer)); + eventNode.AddResourceUsage(state.ibuffer.buf, ResourceUsage::IndexBuffer); for(size_t i = 0; i < state.vbuffers.size(); i++) { if(state.vbuffers[i].buf != ResourceId()) - { - eventNode.resourceUsage.push_back( - make_rdcpair(state.vbuffers[i].buf, ResourceUsage::VertexBuffer)); - } + eventNode.AddResourceUsage(state.vbuffers[i].buf, ResourceUsage::VertexBuffer); } for(uint32_t i = state.firstxfbcounter; i < state.firstxfbcounter + state.xfbcounters.size() && i < state.xfbbuffers.size(); i++) { if(state.xfbbuffers[i].buf != ResourceId()) - { - eventNode.resourceUsage.push_back( - make_rdcpair(state.xfbbuffers[i].buf, ResourceUsage::StreamOut)); - } + eventNode.AddResourceUsage(state.xfbbuffers[i].buf, ResourceUsage::StreamOut); } } @@ -6483,7 +6480,6 @@ void WrappedVulkan::AddUsageForDescriptorBuffers(VulkanEventNode &eventNode, if(sh.module == ResourceId()) continue; - ResourceId origPipe = pipe; ResourceId origShad = sh.module; for(const ConstantBlock &constantBlock : sh.refl->constantBlocks) @@ -6615,7 +6611,6 @@ void WrappedVulkan::AddUsageForDescriptorSets(VulkanEventNode &eventNode) if(sh.module == ResourceId()) continue; - ResourceId origPipe = pipe; ResourceId origShad = sh.module; for(const ConstantBlock &constantBlock : sh.refl->constantBlocks) @@ -6774,7 +6769,7 @@ void WrappedVulkan::AddUsageForDescriptor(VulkanEventNode &eventNode, const Desc } if(id != ResourceId()) - eventNode.resourceUsage.push_back(make_rdcpair(id, usage)); + eventNode.AddResourceUsage(id, usage); } void WrappedVulkan::AddFramebufferUsage(VulkanEventNode &eventNode, @@ -6811,8 +6806,8 @@ void WrappedVulkan::AddFramebufferUsage(VulkanEventNode &eventNode, uint32_t att = sub.inputAttachments[i]; if(att == VK_ATTACHMENT_UNUSED) continue; - eventNode.resourceUsage.push_back( - make_rdcpair(c.m_ImageView[fbattachments[att]].image, ResourceUsage::InputTarget)); + eventNode.AddResourceUsage(c.m_ImageView[fbattachments[att]].image, + ResourceUsage::InputTarget); } for(size_t i = 0; i < sub.colorAttachments.size(); i++) @@ -6820,16 +6815,16 @@ void WrappedVulkan::AddFramebufferUsage(VulkanEventNode &eventNode, uint32_t att = sub.colorAttachments[i]; if(att == VK_ATTACHMENT_UNUSED) continue; - eventNode.resourceUsage.push_back(make_rdcpair( + eventNode.AddResourceUsage( c.m_ImageView[fbattachments[att]].image, - sub.customResolve ? ResourceUsage::ResolveDst : ResourceUsage::ColorTarget)); + sub.customResolve ? ResourceUsage::ResolveDst : ResourceUsage::ColorTarget); } if(sub.depthstencilAttachment >= 0) { int32_t att = sub.depthstencilAttachment; - eventNode.resourceUsage.push_back(make_rdcpair(c.m_ImageView[fbattachments[att]].image, - ResourceUsage::DepthStencilTarget)); + eventNode.AddResourceUsage(c.m_ImageView[fbattachments[att]].image, + ResourceUsage::DepthStencilTarget); } } } @@ -6846,15 +6841,15 @@ void WrappedVulkan::AddFramebufferUsage(VulkanEventNode &eventNode, (dyn.color[i].resolveMode & VK_RESOLVE_MODE_CUSTOM_BIT_EXT); if(!isCustomResolve) { - eventNode.resourceUsage.push_back(make_rdcpair( - c.m_ImageView[GetResID(dyn.color[i].imageView)].image, ResourceUsage::ColorTarget)); + eventNode.AddResourceUsage(c.m_ImageView[GetResID(dyn.color[i].imageView)].image, + ResourceUsage::ColorTarget); } else { - eventNode.resourceUsage.push_back(make_rdcpair( - c.m_ImageView[GetResID(dyn.color[i].imageView)].image, ResourceUsage::InputTarget)); - eventNode.resourceUsage.push_back(make_rdcpair( - c.m_ImageView[GetResID(dyn.color[i].resolveImageView)].image, ResourceUsage::ResolveDst)); + eventNode.AddResourceUsage(c.m_ImageView[GetResID(dyn.color[i].imageView)].image, + ResourceUsage::InputTarget); + eventNode.AddResourceUsage(c.m_ImageView[GetResID(dyn.color[i].resolveImageView)].image, + ResourceUsage::ResolveDst); } } @@ -6864,15 +6859,15 @@ void WrappedVulkan::AddFramebufferUsage(VulkanEventNode &eventNode, (dyn.depth.resolveMode & VK_RESOLVE_MODE_CUSTOM_BIT_EXT); if(!isCustomResolve) { - eventNode.resourceUsage.push_back(make_rdcpair( - c.m_ImageView[GetResID(dyn.depth.imageView)].image, ResourceUsage::DepthStencilTarget)); + eventNode.AddResourceUsage(c.m_ImageView[GetResID(dyn.depth.imageView)].image, + ResourceUsage::DepthStencilTarget); } else { - eventNode.resourceUsage.push_back(make_rdcpair( - c.m_ImageView[GetResID(dyn.depth.imageView)].image, ResourceUsage::InputTarget)); - eventNode.resourceUsage.push_back(make_rdcpair( - c.m_ImageView[GetResID(dyn.depth.resolveImageView)].image, ResourceUsage::ResolveDst)); + eventNode.AddResourceUsage(c.m_ImageView[GetResID(dyn.depth.imageView)].image, + ResourceUsage::InputTarget); + eventNode.AddResourceUsage(c.m_ImageView[GetResID(dyn.depth.resolveImageView)].image, + ResourceUsage::ResolveDst); } } @@ -6883,15 +6878,15 @@ void WrappedVulkan::AddFramebufferUsage(VulkanEventNode &eventNode, if(!isCustomResolve) { - eventNode.resourceUsage.push_back(make_rdcpair( - c.m_ImageView[GetResID(dyn.stencil.imageView)].image, ResourceUsage::DepthStencilTarget)); + eventNode.AddResourceUsage(c.m_ImageView[GetResID(dyn.stencil.imageView)].image, + ResourceUsage::DepthStencilTarget); } else { - eventNode.resourceUsage.push_back(make_rdcpair( - c.m_ImageView[GetResID(dyn.stencil.imageView)].image, ResourceUsage::InputTarget)); - eventNode.resourceUsage.push_back(make_rdcpair( - c.m_ImageView[GetResID(dyn.stencil.resolveImageView)].image, ResourceUsage::ResolveDst)); + eventNode.AddResourceUsage(c.m_ImageView[GetResID(dyn.stencil.imageView)].image, + ResourceUsage::InputTarget); + eventNode.AddResourceUsage(c.m_ImageView[GetResID(dyn.stencil.resolveImageView)].image, + ResourceUsage::ResolveDst); } } } diff --git a/renderdoc/driver/vulkan/vk_core.h b/renderdoc/driver/vulkan/vk_core.h index 4a1610a3511..ff577b9bede 100644 --- a/renderdoc/driver/vulkan/vk_core.h +++ b/renderdoc/driver/vulkan/vk_core.h @@ -134,6 +134,10 @@ struct VulkanEventNode { VulkanEventNode() = default; ~VulkanEventNode() = default; + void AddResourceUsage(ResourceId id, ResourceUsage usage) + { + resourceUsage.push_back(make_rdcpair(id, usage)); + } // eventId is not used APIEvent event; @@ -956,6 +960,7 @@ class WrappedVulkan : public IFrameCapturer ResourceId GetPartialCommandBuffer(); void UpdateRenderStateForSecondaries(BakedCmdBufferInfo &ancestorCB, BakedCmdBufferInfo ¤tCB); + void ResetRenderStateForParent(BakedCmdBufferInfo &ancestorCB); // this info is stored in the record on capture, but we // need it on replay too @@ -1195,6 +1200,12 @@ class WrappedVulkan : public IFrameCapturer void ApplyInitialContents(); + void AddEventResourceUsage(ResourceId id, ResourceUsage usage) + { + RDCASSERT(IsLoading(m_State)); + m_LoadingEventNode.AddResourceUsage(id, usage); + } + rdcarray m_Events; VulkanEventNode m_LoadingEventNode; rdcarray m_EventNodes; @@ -1258,11 +1269,17 @@ class WrappedVulkan : public IFrameCapturer VulkanEventNode &GetLastEventNode() { + RDCASSERT(IsLoading(m_State)); rdcarray &eventNodes = (m_LastCmdBufferID != ResourceId() ? m_BakedCmdBufferInfo[m_LastCmdBufferID].eventNodes : m_EventNodes); return eventNodes.back(); } + VulkanEventNode &GetLoadingEventNode() + { + RDCASSERT(IsLoading(m_State)); + return m_LoadingEventNode; + } void BakeEventNodes(ActionDescription &rootAction); diff --git a/renderdoc/driver/vulkan/vk_debug.cpp b/renderdoc/driver/vulkan/vk_debug.cpp index 1f53c45dbb9..46d3c553bdc 100644 --- a/renderdoc/driver/vulkan/vk_debug.cpp +++ b/renderdoc/driver/vulkan/vk_debug.cpp @@ -3896,44 +3896,24 @@ void VulkanReplay::CreateResources() { m_Device = m_pDriver->GetDev(); - RenderDoc::Inst().SetProgress(LoadProgress::DebugManagerInit, 0.0f); - m_General.Init(m_pDriver, VK_NULL_HANDLE); - RenderDoc::Inst().SetProgress(LoadProgress::DebugManagerInit, 0.1f); - m_TexRender.Init(m_pDriver, m_General.DescriptorPool); - RenderDoc::Inst().SetProgress(LoadProgress::DebugManagerInit, 0.3f); - m_Overlay.Init(m_pDriver, m_General.DescriptorPool); - RenderDoc::Inst().SetProgress(LoadProgress::DebugManagerInit, 0.4f); - m_MeshRender.Init(m_pDriver, m_General.DescriptorPool); - RenderDoc::Inst().SetProgress(LoadProgress::DebugManagerInit, 0.6f); - m_VertexPick.Init(m_pDriver, m_General.DescriptorPool); - RenderDoc::Inst().SetProgress(LoadProgress::DebugManagerInit, 0.7f); - m_PixelPick.Init(m_pDriver, m_General.DescriptorPool); - RenderDoc::Inst().SetProgress(LoadProgress::DebugManagerInit, 0.75f); - m_PixelHistory.Init(m_pDriver, m_General.DescriptorPool); - RenderDoc::Inst().SetProgress(LoadProgress::DebugManagerInit, 0.8f); - m_Histogram.Init(m_pDriver, m_General.DescriptorPool); - RenderDoc::Inst().SetProgress(LoadProgress::DebugManagerInit, 0.9f); - m_ShaderDebugData.Init(m_pDriver, m_General.DescriptorPool); - RenderDoc::Inst().SetProgress(LoadProgress::DebugManagerInit, 1.0f); - m_StorageMode = BufferStorageMode::Descriptor; if(m_pDriver->GetExtensions(NULL).ext_KHR_buffer_device_address) diff --git a/renderdoc/driver/vulkan/vk_info.cpp b/renderdoc/driver/vulkan/vk_info.cpp index 60b216d74d4..5ee2682153c 100644 --- a/renderdoc/driver/vulkan/vk_info.cpp +++ b/renderdoc/driver/vulkan/vk_info.cpp @@ -1176,8 +1176,7 @@ void VulkanCreationInfo::ShaderObject::Init(VulkanResourceManager *resourceMan, ShaderModuleReflection &reflData = info.m_ShaderModule[id].m_Reflections[key]; - reflData.Init(resourceMan, info, id, info.m_ShaderModule[id].spirv, shad.entryPoint, - pCreateInfo->stage, shad.specialization); + reflData.Init(resourceMan, info, id, shad.entryPoint, pCreateInfo->stage, shad.specialization); shad.refl = reflData.refl; shad.patchData = &reflData.patchData; @@ -1364,8 +1363,8 @@ void VulkanCreationInfo::Pipeline::Init(VulkanResourceManager *resourceMan, ShaderModuleReflection &reflData = info.m_ShaderModule[shadid].m_Reflections[key]; - reflData.Init(resourceMan, info, shadid, info.m_ShaderModule[shadid].spirv, shad.entryPoint, - pCreateInfo->pStages[i].stage, shad.specialization); + reflData.Init(resourceMan, info, shadid, shad.entryPoint, pCreateInfo->pStages[i].stage, + shad.specialization); shad.refl = reflData.refl; shad.patchData = &reflData.patchData; @@ -1696,6 +1695,9 @@ void VulkanCreationInfo::Pipeline::Init(VulkanResourceManager *resourceMan, { attachments[i].blendEnable = pCreateInfo->pColorBlendState->pAttachments[i].blendEnable ? true : false; + // Write is implicitly enabled, unless overriden by VkPipelineColorWriteCreateInfoEXT + // (below) or dynamic state. + attachments[i].writeEnable = true; attachments[i].blend.Source = pCreateInfo->pColorBlendState->pAttachments[i].srcColorBlendFactor; @@ -1735,8 +1737,7 @@ void VulkanCreationInfo::Pipeline::Init(VulkanResourceManager *resourceMan, RDCASSERTEQUAL(attachments.size(), colorWriteEnable->attachmentCount); for(size_t i = 0; i < attachments.size() && i < colorWriteEnable->attachmentCount; i++) { - if(!colorWriteEnable->pColorWriteEnables[i]) - attachments[i].channelWriteMask = 0; + attachments[i].writeEnable = colorWriteEnable->pColorWriteEnables[i] ? true : false; } } @@ -2055,8 +2056,8 @@ void VulkanCreationInfo::Pipeline::Init(VulkanResourceManager *resourceMan, Vulk ShaderModuleReflection &reflData = info.m_ShaderModule[shadid].m_Reflections[key]; - reflData.Init(resourceMan, info, shadid, info.m_ShaderModule[shadid].spirv, shad.entryPoint, - pCreateInfo->stage.stage, shad.specialization); + reflData.Init(resourceMan, info, shadid, shad.entryPoint, pCreateInfo->stage.stage, + shad.specialization); shad.refl = reflData.refl; shad.patchData = &reflData.patchData; @@ -2808,50 +2809,44 @@ void VulkanCreationInfo::ShaderModule::Init(VulkanResourceManager *resourceMan, else { RDCASSERT(pCreateInfo->codeSize % sizeof(uint32_t) == 0); - spirv.Parse(rdcarray((uint32_t *)(pCreateInfo->pCode), - pCreateInfo->codeSize / sizeof(uint32_t))); - initialSpirv.clear(); + spirv.Parse(pCreateInfo->pCode, pCreateInfo->codeSize); } } -bool VulkanCreationInfo::ShaderModule::Reinit() +bytebuf FindAndLoadDebugBlob(bool lz4, const rdcstr &searchFilePath, rdcstr &foundFilePath, + rdcstr &loadingLog) { - rdcstr loadingLog; - bool lz4 = false; + bytebuf ret; - rdcstr originalPath = unstrippedPath; + rdcstr curFilePath = searchFilePath; - if(!strncmp(originalPath.c_str(), "lz4#", 4)) - { - originalPath = originalPath.substr(4); - lz4 = true; - } // could support more if we're willing to compile in the decompressor FILE *originalShaderFile = NULL; - const rdcarray &searchPaths = DXBC_Debug_SearchDirPaths(); + const rdcarray &searchDirPaths = DXBC_Debug_SearchDirPaths(); - size_t numSearchPaths = searchPaths.size(); + size_t numSearchPaths = searchDirPaths.size(); - rdcstr foundFname = originalPath; - rdcstr foundPath; - - loadingLog = StringFormat::Fmt("Shader filepath '%s'\n", originalPath.c_str()); + loadingLog = StringFormat::Fmt( + "Details\n" + "-------\n\n" + "Shader filepath '%s'\n", + curFilePath.c_str()); if(numSearchPaths > 0) { - loadingLog += rdcstr("\nNon-Recursive Search Path(s):\n"); + loadingLog += rdcstr("\nSearch Path(s):\n"); for(size_t i = 0; i < numSearchPaths; i++) - loadingLog += StringFormat::Fmt("'%s'\n", searchPaths[i].c_str()); + loadingLog += StringFormat::Fmt("'%s'\n", searchDirPaths[i].c_str()); } else { - loadingLog += rdcstr("\nNo Non-Recursive Search Paths\n"); + loadingLog += rdcstr("\nNo Search Paths\n"); } // keep searching until we've exhausted all possible path options, or we've found a file that // opens - while(originalShaderFile == NULL && !originalPath.empty()) + while(originalShaderFile == NULL && !curFilePath.empty()) { // while we haven't found a file, keep trying through the search paths. For i==0 // check the path on its own, in case it's an absolute path. @@ -2860,20 +2855,26 @@ bool VulkanCreationInfo::ShaderModule::Reinit() if(i == 0) { loadingLog += rdcstr("\n"); - originalShaderFile = FileIO::fopen(originalPath, FileIO::ReadBinary); - foundPath = originalPath; + originalShaderFile = FileIO::fopen(curFilePath, FileIO::ReadBinary); + foundFilePath = curFilePath; if(originalShaderFile == NULL) - loadingLog += StringFormat::Fmt("File not found using filepath '%s'\n", foundPath.c_str()); + loadingLog += + StringFormat::Fmt("File not found using filepath '%s'\n", foundFilePath.c_str()); + else + loadingLog += StringFormat::Fmt("File found using filepath '%s'\n", foundFilePath.c_str()); continue; } else { - const rdcstr &searchPath = searchPaths[i - 1]; - foundPath = searchPath + "/" + originalPath; - originalShaderFile = FileIO::fopen(foundPath, FileIO::ReadBinary); + const rdcstr &searchDirPath = searchDirPaths[i - 1]; + foundFilePath = searchDirPath + "/" + curFilePath; + originalShaderFile = FileIO::fopen(foundFilePath, FileIO::ReadBinary); if(originalShaderFile == NULL) loadingLog += StringFormat::Fmt( - "File not found in search directory using filepath '%s'\n", foundPath.c_str()); + "File not found in search directory using filepath '%s'\n", foundFilePath.c_str()); + else + loadingLog += StringFormat::Fmt("File found in search directory using filepath '%s'\n", + foundFilePath.c_str()); } } @@ -2884,39 +2885,31 @@ bool VulkanCreationInfo::ShaderModule::Reinit() // append it to all search paths as-is, then strip off the top-level subdirectory to get // bar/blah.pdb and try that in all search directories, and keep going. So if we got here // and didn't open a file, try to strip off the the top directory and continue. - int32_t offs = originalPath.find_first_of("\\/"); + int32_t offs = curFilePath.find_first_of("\\/"); // if we couldn't find a directory separator there's nothing to do, stop looking if(offs == -1) break; // otherwise strip up to there and keep going - originalPath.erase(0, offs + 1); + curFilePath.erase(0, offs + 1); } } // Try to retrieve debug file from the externally referenced files in the capture - bytebuf debugBytecode; if(originalShaderFile == NULL) { - if(!RenderDoc::Inst().GetTrackedFileData(foundFname, debugBytecode)) + if(!RenderDoc::Inst().GetTrackedFileData(searchFilePath, ret)) { loadingLog += StringFormat::Fmt( "\nFile not found in files embedded in the capture using nickname '%s'\n", - foundFname.c_str()); - debugInfoLoadingLog = - StringFormat::Fmt("Did not find debug data for '%s'\n\n", foundFname.c_str()); - if(!loadingLog.empty()) - { - debugInfoLoadingLog += StringFormat::Fmt("Details\n"); - debugInfoLoadingLog += StringFormat::Fmt("-------\n\n"); - debugInfoLoadingLog += loadingLog; - } - return false; + searchFilePath.c_str()); + return bytebuf(); } + loadingLog += StringFormat::Fmt( "\nFound debug data from files embedded in the capture using nickname '%s'\n", - foundFname.c_str()); + searchFilePath.c_str()); } else { @@ -2924,94 +2917,104 @@ bool VulkanCreationInfo::ShaderModule::Reinit() uint64_t originalShaderSize = FileIO::ftell64(originalShaderFile); FileIO::fseek64(originalShaderFile, 0, SEEK_SET); - debugBytecode.resize((size_t)originalShaderSize); - FileIO::fread(&debugBytecode[0], sizeof(byte), (size_t)originalShaderSize, originalShaderFile); + ret.resize((size_t)originalShaderSize); + FileIO::fread(&ret[0], sizeof(byte), (size_t)originalShaderSize, originalShaderFile); FileIO::fclose(originalShaderFile); originalShaderFile = NULL; - loadingLog += StringFormat::Fmt("\nFound debug data using filepath '%s'\n", foundPath.c_str()); + loadingLog += + StringFormat::Fmt("\nFound debug data using filepath '%s'\n", foundFilePath.c_str()); } + if(lz4) { - if(lz4) - { - rdcarray decompressed; + rdcarray decompressed; - // first try decompressing to 1MB flat - decompressed.resize(100 * 1024); + // first try decompressing to 1MB flat + decompressed.resize(100 * 1024); - int ret = LZ4_decompress_safe((const char *)&debugBytecode[0], (char *)&decompressed[0], - (int)debugBytecode.size(), (int)decompressed.size()); + int lzret = LZ4_decompress_safe((const char *)&ret[0], (char *)&decompressed[0], + (int)ret.size(), (int)decompressed.size()); - if(ret < 0) - { - // if it failed, either source is corrupt or we didn't allocate enough space. - // Just allocate 255x compressed size since it can't need any more than that. - decompressed.resize(255 * debugBytecode.size()); + if(lzret < 0) + { + // if it failed, either source is corrupt or we didn't allocate enough space. + // Just allocate 255x compressed size since it can't need any more than that. + decompressed.resize(255 * ret.size()); - ret = LZ4_decompress_safe((const char *)&debugBytecode[0], (char *)&decompressed[0], - (int)debugBytecode.size(), (int)decompressed.size()); + lzret = LZ4_decompress_safe((const char *)&ret[0], (char *)&decompressed[0], (int)ret.size(), + (int)decompressed.size()); - if(ret < 0) - { - RDCERR("Failed to decompress LZ4 data from %s", foundPath.c_str()); - loadingLog += - StringFormat::Fmt("\nFailed to decompress LZ4 data from '%s'\n", foundPath.c_str()); - debugInfoLoadingLog = - StringFormat::Fmt("Did not find debug data for '%s'\n\n", foundFname.c_str()); - if(!loadingLog.empty()) - { - debugInfoLoadingLog += StringFormat::Fmt("Details\n"); - debugInfoLoadingLog += StringFormat::Fmt("-------\n\n"); - debugInfoLoadingLog += loadingLog; - } - return false; - } + if(lzret < 0) + { + loadingLog += + StringFormat::Fmt("\nFailed to decompress LZ4 data from '%s'\n", foundFilePath.c_str()); + return bytebuf(); } + } - RDCASSERT(ret > 0, ret); + RDCASSERT(lzret > 0, lzret); - // we resize and memcpy instead of just doing .swap() because that would - // transfer over the over-large pessimistic capacity needed for decompression - debugBytecode.resize(ret); - memcpy(&debugBytecode[0], &decompressed[0], debugBytecode.size()); - } + // we resize and memcpy instead of just doing .swap() because that would + // transfer over the over-large pessimistic capacity needed for decompression + ret.resize(lzret); + memcpy(&ret[0], &decompressed[0], ret.size()); + } - rdcspv::Reflector reflTest; - reflTest.Parse(rdcarray((uint32_t *)(debugBytecode.data()), - debugBytecode.size() / sizeof(uint32_t))); + return ret; +} + +bool VulkanCreationInfo::ShaderModule::Reinit() +{ + bool lz4 = false; + + rdcstr searchFilePath = unstrippedPath; - if(!reflTest.GetSPIRV().empty()) + if(!strncmp(searchFilePath.c_str(), "lz4#", 4)) + { + searchFilePath = searchFilePath.substr(4); + lz4 = true; + } + + rdcstr foundFilePath, loadingLog; + + bytebuf debugBytecode = FindAndLoadDebugBlob(lz4, searchFilePath, foundFilePath, loadingLog); + + bool success = false; + + if(!debugBytecode.empty()) + { + rdcspv::Reflector reflTest; + if(reflTest.Parse(debugBytecode.data(), debugBytecode.size())) { - if(initialSpirv.isEmpty()) - initialSpirv = spirv.GetSPIRV(); spirv = reflTest; - RenderDoc::Inst().AddTrackedFileReference(foundFname, foundPath); + RenderDoc::Inst().AddTrackedFileReference(searchFilePath, foundFilePath); loadingLog += StringFormat::Fmt("Debug data parsed successfully (%u bytes)\n", (uint32_t)debugBytecode.size()); - debugInfoLoadingLog = StringFormat::Fmt("Found debug data for '%s'\n\n", foundFname.c_str()); - if(!loadingLog.empty()) - { - debugInfoLoadingLog += StringFormat::Fmt("Details\n"); - debugInfoLoadingLog += StringFormat::Fmt("-------\n\n"); - debugInfoLoadingLog += loadingLog; - } - return true; + + debugBlobEverFound = true; + + success = true; } else { loadingLog += StringFormat::Fmt("Debug data failed to parse (%u bytes)\n", (uint32_t)debugBytecode.size()); - debugInfoLoadingLog = - StringFormat::Fmt("Did not find debug data for '%s'\n\n", foundFname.c_str()); } } - if(!loadingLog.empty()) - { - debugInfoLoadingLog += StringFormat::Fmt("Details\n"); - debugInfoLoadingLog += StringFormat::Fmt("-------\n\n"); - debugInfoLoadingLog += loadingLog; - } - return false; + + // we store the loading log if: + // - the last load succeeded, as that's the debug blob we're using + // - we don't have a current log from a successful debug blob load, so this is the + // most recent failed attempt + // + // this means the loading log always matches either the blob we're using or the most up to date + // failure. If we succeed once, load a blob, then reload/reinit and fail we don't keep the log + // from that failure. This could happen because the user deleted the file or changed search paths, + // the former of which can happen at any time even if we don't reload + if(success || !debugBlobEverFound) + debugInfoLoadingLog.swap(loadingLog); + + return success; } void VulkanCreationInfo::ShaderModule::Reload(VulkanResourceManager *resourceMan, @@ -3021,31 +3024,15 @@ void VulkanCreationInfo::ShaderModule::Reload(VulkanResourceManager *resourceMan if(unstrippedPath.empty()) return; - rdcarray currentSpirv = spirv.GetSPIRV(); - - // Loading debug data failed : reset the spirv to the initial spirv if(!Reinit()) - { - if(initialSpirv.isEmpty()) - return; - if(currentSpirv == initialSpirv) - return; - rdcspv::Reflector newSpirv; - newSpirv.Parse(initialSpirv); - spirv = newSpirv; - } - - // Nothing to do if the shader spirv did not change - if(spirv.GetSPIRV() == currentSpirv) return; for(auto it = m_Reflections.begin(); it != m_Reflections.end(); ++it) - it->second.Reload(resourceMan, info, id, spirv); + it->second.Reload(resourceMan, info, id); } void VulkanCreationInfo::ShaderModuleReflection::Init(VulkanResourceManager *resourceMan, const VulkanCreationInfo &info, ResourceId id, - const rdcspv::Reflector &spv, const rdcstr &entry, VkShaderStageFlagBits stage, const rdcarray &specInfo) @@ -3055,11 +3042,29 @@ void VulkanCreationInfo::ShaderModuleReflection::Init(VulkanResourceManager *res entryPoint = entry; stageIndex = StageIndex(stage); - spv.MakeReflection(GraphicsAPI::Vulkan, ShaderStage(stageIndex), entryPoint, specInfo, *refl, - patchData); + const ShaderModule &moduleInfo = info.m_ShaderModule.at(id); + + moduleInfo.spirv.MakeReflection(GraphicsAPI::Vulkan, ShaderStage(stageIndex), entryPoint, + specInfo, *refl, patchData); refl->resourceId = id; - refl->debugInfo.debugInfoLoadingLog = info.m_ShaderModule.at(id).debugInfoLoadingLog; + + if(!moduleInfo.debugInfoLoadingLog.empty()) + { + if(!moduleInfo.debugBlobEverFound) + { + refl->debugInfo.debugInfoLoadingLog = StringFormat::Fmt( + "Did not find debug data for '%s'\n\n", moduleInfo.unstrippedPath.c_str()); + } + else + { + refl->debugInfo.debugInfoLoadingLog = + StringFormat::Fmt("Found debug data for '%s'\n\n", moduleInfo.unstrippedPath.c_str()); + } + + refl->debugInfo.debugInfoLoadingLog += moduleInfo.debugInfoLoadingLog; + } + specConstantData = specInfo; } } @@ -3071,8 +3076,7 @@ void VulkanCreationInfo::ShaderModuleReflection::PopulateDisassembly(const rdcsp } void VulkanCreationInfo::ShaderModuleReflection::Reload(VulkanResourceManager *resourceMan, - const VulkanCreationInfo &info, - ResourceId id, const rdcspv::Reflector &spv) + const VulkanCreationInfo &info, ResourceId id) { const rdcstr entry = entryPoint; entryPoint.clear(); @@ -3082,7 +3086,7 @@ void VulkanCreationInfo::ShaderModuleReflection::Reload(VulkanResourceManager *r *refl = ShaderReflection(); patchData = SPIRVPatchData(); VkShaderStageFlagBits stage = (VkShaderStageFlagBits)ShaderMaskFromIndex((size_t)(stageIndex)); - Init(resourceMan, info, id, spv, entry, stage, specConstantData); + Init(resourceMan, info, id, entry, stage, specConstantData); } void VulkanCreationInfo::QueryPool::Init(VulkanResourceManager *resourceMan, VulkanCreationInfo &info, diff --git a/renderdoc/driver/vulkan/vk_info.h b/renderdoc/driver/vulkan/vk_info.h index 057beba6f05..ee06aaae866 100644 --- a/renderdoc/driver/vulkan/vk_info.h +++ b/renderdoc/driver/vulkan/vk_info.h @@ -232,12 +232,11 @@ struct VulkanCreationInfo rdcarray specConstantData; void Init(VulkanResourceManager *resourceMan, const VulkanCreationInfo &info, ResourceId id, - const rdcspv::Reflector &spv, const rdcstr &entry, VkShaderStageFlagBits stage, + const rdcstr &entry, VkShaderStageFlagBits stage, const rdcarray &specInfo); void PopulateDisassembly(const rdcspv::Reflector &spirv); - void Reload(VulkanResourceManager *resourceMan, const VulkanCreationInfo &info, ResourceId id, - const rdcspv::Reflector &spv); + void Reload(VulkanResourceManager *resourceMan, const VulkanCreationInfo &info, ResourceId id); }; struct ShaderEntry @@ -448,6 +447,7 @@ struct VulkanCreationInfo struct CBAttachment { bool blendEnable; + bool writeEnable; struct BlendOp { @@ -808,10 +808,13 @@ struct VulkanCreationInfo } rdcspv::Reflector spirv; - // Only set when separate debug spirv is found - rdcarray initialSpirv; rdcstr unstrippedPath; + + // indicate if we've ever found a debug blob, so that if we fail to on a second retry we don't + // overwrite the loading log from the successful load with anything but a successful load + bool debugBlobEverFound = false; + rdcstr debugInfoLoadingLog; std::map m_Reflections; diff --git a/renderdoc/driver/vulkan/vk_replay.cpp b/renderdoc/driver/vulkan/vk_replay.cpp index 44b475a33d6..12a017de904 100644 --- a/renderdoc/driver/vulkan/vk_replay.cpp +++ b/renderdoc/driver/vulkan/vk_replay.cpp @@ -487,7 +487,7 @@ const ShaderReflection *VulkanReplay::GetShader(ResourceId pipeline, ResourceId // if this shader was never used in a pipeline the reflection won't be prepared. Do that now - // this will be ignored if it was already prepared. shad->second.GetReflection(entry.stage, entry.name, pipeline) - .Init(GetResourceManager(), m_pDriver->m_CreationInfo, shader, shad->second.spirv, entry.name, + .Init(GetResourceManager(), m_pDriver->m_CreationInfo, shader, entry.name, VkShaderStageFlagBits(1 << uint32_t(entry.stage)), {}); return shad->second.GetReflection(entry.stage, entry.name, pipeline).refl; diff --git a/renderdoc/driver/vulkan/vk_shader_cache.cpp b/renderdoc/driver/vulkan/vk_shader_cache.cpp index 600bfbda75a..2ada8e415f3 100644 --- a/renderdoc/driver/vulkan/vk_shader_cache.cpp +++ b/renderdoc/driver/vulkan/vk_shader_cache.cpp @@ -962,6 +962,7 @@ void VulkanShaderCache::MakeGraphicsPipelineInfo(VkGraphicsPipelineCreateInfo &p cb.attachmentCount = (uint32_t)pipeInfo.attachments.size(); cb.pAttachments = atts; + bool anyWriteDisables = false; for(uint32_t i = 0; i < cb.attachmentCount; i++) { atts[i].blendEnable = pipeInfo.attachments[i].blendEnable; @@ -972,6 +973,25 @@ void VulkanShaderCache::MakeGraphicsPipelineInfo(VkGraphicsPipelineCreateInfo &p atts[i].colorBlendOp = pipeInfo.attachments[i].blend.Operation; atts[i].srcColorBlendFactor = pipeInfo.attachments[i].blend.Source; atts[i].dstColorBlendFactor = pipeInfo.attachments[i].blend.Destination; + + anyWriteDisables = anyWriteDisables || !pipeInfo.attachments[i].writeEnable; + } + + static VkPipelineColorWriteCreateInfoEXT cw = { + VK_STRUCTURE_TYPE_PIPELINE_COLOR_WRITE_CREATE_INFO_EXT}; + + static VkBool32 writeEnables[32] = {}; + cw.attachmentCount = cb.attachmentCount; + cw.pColorWriteEnables = writeEnables; + + if(anyWriteDisables) + { + for(uint32_t i = 0; i < cb.attachmentCount; i++) + { + writeEnables[i] = pipeInfo.attachments[i].writeEnable; + } + cw.pNext = rs.pNext; + rs.pNext = &cw; } RDCASSERT(ARRAY_COUNT(atts) >= pipeInfo.attachments.size()); diff --git a/renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp index e587a06f1d1..1643ad88e3a 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp @@ -425,14 +425,14 @@ void WrappedVulkan::AddImplicitResolveResourceUsage(uint32_t subpass) uint32_t attIdx = rpinfo.subpasses[subpass].resolveAttachments[i]; if(attIdx == VK_ATTACHMENT_UNUSED) continue; - ResourceId image = m_CreationInfo.m_ImageView[fbattachments[attIdx]].image; - m_LoadingEventNode.resourceUsage.push_back(make_rdcpair(image, ResourceUsage::ResolveDst)); + AddEventResourceUsage(m_CreationInfo.m_ImageView[fbattachments[attIdx]].image, + ResourceUsage::ResolveDst); attIdx = rpinfo.subpasses[subpass].colorAttachments[i]; if(attIdx == VK_ATTACHMENT_UNUSED) continue; - image = m_CreationInfo.m_ImageView[fbattachments[attIdx]].image; - m_LoadingEventNode.resourceUsage.push_back(make_rdcpair(image, ResourceUsage::ResolveSrc)); + AddEventResourceUsage(m_CreationInfo.m_ImageView[fbattachments[attIdx]].image, + ResourceUsage::ResolveSrc); } // also add any discards on the final subpass @@ -441,10 +441,8 @@ void WrappedVulkan::AddImplicitResolveResourceUsage(uint32_t subpass) for(size_t i = 0; i < rpinfo.attachments.size(); i++) { if(rpinfo.attachments[i].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE) - { - ResourceId image = m_CreationInfo.m_ImageView[fbattachments[i]].image; - m_LoadingEventNode.resourceUsage.push_back(make_rdcpair(image, ResourceUsage::Discard)); - } + AddEventResourceUsage(m_CreationInfo.m_ImageView[fbattachments[i]].image, + ResourceUsage::Discard); } } } @@ -2098,70 +2096,73 @@ bool WrappedVulkan::Serialise_vkCmdBeginRenderPass(SerialiserType &ser, VkComman if(IsReplayingAndReading()) { - VkRenderPassBeginInfo unwrappedInfo = RenderPassBegin; - unwrappedInfo.renderPass = Unwrap(unwrappedInfo.renderPass); - unwrappedInfo.framebuffer = Unwrap(unwrappedInfo.framebuffer); - - byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); - - UnwrapNextChain(m_State, "VkRenderPassBeginInfo", tempMem, (VkBaseInStructure *)&unwrappedInfo); - m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + bool replaySingleEvent = !loading && (m_FirstEventID == m_LastEventID); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - // only if we're partially recording do we update this state - if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, false)) - { - GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = - m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = true; - } + VkRenderPassBeginInfo unwrappedInfo = RenderPassBegin; + unwrappedInfo.renderPass = Unwrap(unwrappedInfo.renderPass); + unwrappedInfo.framebuffer = Unwrap(unwrappedInfo.framebuffer); - m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass = 0; + byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); - ResourceId fb = GetResID(RenderPassBegin.framebuffer); - VulkanCreationInfo::Framebuffer fbinfo = m_CreationInfo.m_Framebuffer[fb]; + UnwrapNextChain(m_State, "VkRenderPassBeginInfo", tempMem, (VkBaseInStructure *)&unwrappedInfo); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.subpass = 0; - renderstate.SetRenderPass(GetResID(RenderPassBegin.renderPass)); - renderstate.renderArea = RenderPassBegin.renderArea; - renderstate.subpassContents = contents; + // only if we're partially recording do we update this state + if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, false)) + { + GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = + m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = true; + } - renderstate.fragmentDensityMapOffsets.clear(); + m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass = 0; - const VkRenderPassAttachmentBeginInfo *attachmentsInfo = - (const VkRenderPassAttachmentBeginInfo *)FindNextStruct( - &RenderPassBegin, VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO); + ResourceId fb = GetResID(RenderPassBegin.framebuffer); + VulkanCreationInfo::Framebuffer fbinfo = m_CreationInfo.m_Framebuffer[fb]; + ResourceId rp = GetResID(RenderPassBegin.renderPass); - rdcarray attachments; - attachments.resize(fbinfo.attachments.size()); + rdcarray attachments; + { + VulkanRenderState &renderstate = GetCmdRenderState(); + renderstate.subpass = 0; + renderstate.SetRenderPass(rp); + renderstate.renderArea = RenderPassBegin.renderArea; + renderstate.subpassContents = contents; - // set framebuffer attachments - by default from the ones used to create it, but if it is - // imageless then look for the attachments in our pNext chain - if(!fbinfo.imageless) - { - for(size_t i = 0; i < fbinfo.attachments.size(); i++) - attachments[i] = fbinfo.attachments[i].createdView; - } - else - { - for(size_t i = 0; i < fbinfo.attachments.size(); i++) - attachments[i] = GetResID(attachmentsInfo->pAttachments[i]); - } - renderstate.SetFramebuffer(GetResID(RenderPassBegin.framebuffer), attachments); + renderstate.fragmentDensityMapOffsets.clear(); + + const VkRenderPassAttachmentBeginInfo *attachmentsInfo = + (const VkRenderPassAttachmentBeginInfo *)FindNextStruct( + &RenderPassBegin, VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO); + + attachments.resize(fbinfo.attachments.size()); + + // set framebuffer attachments - by default from the ones used to create it, but if it is + // imageless then look for the attachments in our pNext chain + if(!fbinfo.imageless) + { + for(size_t i = 0; i < fbinfo.attachments.size(); i++) + attachments[i] = fbinfo.attachments[i].createdView; + } + else + { + for(size_t i = 0; i < fbinfo.attachments.size(); i++) + attachments[i] = GetResID(attachmentsInfo->pAttachments[i]); } + renderstate.SetFramebuffer(fb, attachments); + } - const VulkanCreationInfo::RenderPass &rpinfo = - m_CreationInfo.m_RenderPass[GetCmdRenderState().GetRenderPass()]; + const VulkanCreationInfo::RenderPass &rpinfo = m_CreationInfo.m_RenderPass[rp]; - rdcarray imgBarriers = GetImplicitRenderPassBarriers(); + rdcarray imgBarriers = GetImplicitRenderPassBarriers(); + if(!loading) + { ApplyRPLoadDiscards(commandBuffer, RenderPassBegin.renderArea); // if we're just replaying the vkCmdBeginRenderPass on its own, we use the first loadRP @@ -2169,7 +2170,7 @@ bool WrappedVulkan::Serialise_vkCmdBeginRenderPass(SerialiserType &ser, VkComman // we need to manually do the subpass 0 barriers, since loadRP expects the image to already // be in subpass 0's layout // we also need to manually do any clears, since the loadRP will load all attachments - if(m_FirstEventID == m_LastEventID) + if(replaySingleEvent) { unwrappedInfo.renderPass = Unwrap(rpinfo.loadRPs[0]); unwrappedInfo.framebuffer = Unwrap(fbinfo.loadFBs[0]); @@ -2182,156 +2183,108 @@ bool WrappedVulkan::Serialise_vkCmdBeginRenderPass(SerialiserType &ser, VkComman barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL; } } - - DoPipelineBarrier(commandBuffer, imgBarriers.size(), imgBarriers.data()); } - ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::BeginPass; - uint32_t eventId = HandlePreCallback(commandBuffer, drawFlags); + DoPipelineBarrier(commandBuffer, imgBarriers.size(), imgBarriers.data()); + } + + ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::BeginPass; + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, drawFlags) : 0; + + ObjDisp(commandBuffer)->CmdBeginRenderPass(Unwrap(commandBuffer), &unwrappedInfo, contents); - ObjDisp(commandBuffer)->CmdBeginRenderPass(Unwrap(commandBuffer), &unwrappedInfo, contents); + if(replaySingleEvent) + { + const rdcarray &fbattachments = + m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetFramebufferAttachments(); - if(m_FirstEventID == m_LastEventID) + rdcarray clearatts; + rdcarray clearrects; + for(int32_t c = 0; c < rpinfo.subpasses[0].colorAttachments.count() + 1; c++) { - const rdcarray &fbattachments = - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetFramebufferAttachments(); + uint32_t att = ~0U; - rdcarray clearatts; - rdcarray clearrects; - for(int32_t c = 0; c < rpinfo.subpasses[0].colorAttachments.count() + 1; c++) - { - uint32_t att = ~0U; + if(c < rpinfo.subpasses[0].colorAttachments.count()) + att = rpinfo.subpasses[0].colorAttachments[c]; + else if(rpinfo.subpasses[0].depthstencilAttachment >= 0) + att = (uint32_t)rpinfo.subpasses[0].depthstencilAttachment; - if(c < rpinfo.subpasses[0].colorAttachments.count()) - att = rpinfo.subpasses[0].colorAttachments[c]; - else if(rpinfo.subpasses[0].depthstencilAttachment >= 0) - att = (uint32_t)rpinfo.subpasses[0].depthstencilAttachment; + if(att >= rpinfo.attachments.size()) + continue; - if(att >= rpinfo.attachments.size()) - continue; + VkImageAspectFlags clearAspects = 0; - VkImageAspectFlags clearAspects = 0; + // loadOp governs color, and depth + if(rpinfo.attachments[att].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) + clearAspects |= VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; + // stencilLoadOp governs the stencil + if(rpinfo.attachments[att].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) + clearAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; - // loadOp governs color, and depth - if(rpinfo.attachments[att].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) - clearAspects |= VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; - // stencilLoadOp governs the stencil - if(rpinfo.attachments[att].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) - clearAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; + // if any aspect is set to clear, go check it in more detail + if(clearAspects != 0) + { + VulkanCreationInfo::ImageView viewinfo = m_CreationInfo.m_ImageView[fbattachments[att]]; + bool isMultiview = rpinfo.subpasses[0].multiviews.size() > 1; + + VkClearRect rect = {unwrappedInfo.renderArea, 0, + isMultiview ? 1 : viewinfo.range.layerCount}; + VkClearAttachment clear = {}; + clear.aspectMask = FormatImageAspects(rpinfo.attachments[att].format) & clearAspects; + clear.colorAttachment = c; + if(att < unwrappedInfo.clearValueCount) + clear.clearValue = unwrappedInfo.pClearValues[att]; + else + RDCWARN("Missing clear value for attachment %u", att); - // if any aspect is set to clear, go check it in more detail - if(clearAspects != 0) + // check that the actual aspects in the attachment overlap with those being cleared. + // In particular this means we ignore stencil load op being CLEAR for a color + // attachment - that doesn't mean we should clear the color. This also means we don't + // clear the stencil if it's not specified, even when clearing depth *is* + if(clear.aspectMask != 0) { - VulkanCreationInfo::ImageView viewinfo = m_CreationInfo.m_ImageView[fbattachments[att]]; - bool isMultiview = rpinfo.subpasses[0].multiviews.size() > 1; - - VkClearRect rect = {unwrappedInfo.renderArea, 0, - isMultiview ? 1 : viewinfo.range.layerCount}; - VkClearAttachment clear = {}; - clear.aspectMask = FormatImageAspects(rpinfo.attachments[att].format) & clearAspects; - clear.colorAttachment = c; - if(att < unwrappedInfo.clearValueCount) - clear.clearValue = unwrappedInfo.pClearValues[att]; - else - RDCWARN("Missing clear value for attachment %u", att); - - // check that the actual aspects in the attachment overlap with those being cleared. - // In particular this means we ignore stencil load op being CLEAR for a color - // attachment - that doesn't mean we should clear the color. This also means we don't - // clear the stencil if it's not specified, even when clearing depth *is* - if(clear.aspectMask != 0) - { - clearrects.push_back(rect); - clearatts.push_back(clear); - } + clearrects.push_back(rect); + clearatts.push_back(clear); } } - - if(!clearatts.empty()) - ObjDisp(commandBuffer) - ->CmdClearAttachments(Unwrap(commandBuffer), (uint32_t)clearatts.size(), - clearatts.data(), (uint32_t)clearrects.size(), - clearrects.data()); - } - - if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) - { - // Do not call vkCmdBeginRenderPass again. - m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); } - GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, - FindCommandQueueFamily(m_LastCmdBufferID), - (uint32_t)imgBarriers.size(), imgBarriers.data()); + if(!clearatts.empty()) + ObjDisp(commandBuffer) + ->CmdClearAttachments(Unwrap(commandBuffer), (uint32_t)clearatts.size(), + clearatts.data(), (uint32_t)clearrects.size(), clearrects.data()); } - } - else - { - ObjDisp(commandBuffer)->CmdBeginRenderPass(Unwrap(commandBuffer), &unwrappedInfo, contents); - - // track while reading, for fetching the right set of outputs in AddAction - m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass = 0; - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.subpass = 0; - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.SetRenderPass( - GetResID(RenderPassBegin.renderPass)); - - ResourceId fb = GetResID(RenderPassBegin.framebuffer); - // set framebuffer attachments - by default from the ones used to create it, but if it is - // imageless then look for the attachments in our pNext chain + if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) { - VulkanCreationInfo::Framebuffer fbinfo = m_CreationInfo.m_Framebuffer[fb]; - rdcarray attachments; - attachments.resize(fbinfo.attachments.size()); - - if(!fbinfo.imageless) - { - for(size_t i = 0; i < fbinfo.attachments.size(); i++) - attachments[i] = fbinfo.attachments[i].createdView; - } - else - { - const VkRenderPassAttachmentBeginInfo *attachmentsInfo = - (const VkRenderPassAttachmentBeginInfo *)FindNextStruct( - &RenderPassBegin, VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO); - - for(size_t i = 0; i < fbinfo.attachments.size(); i++) - attachments[i] = GetResID(attachmentsInfo->pAttachments[i]); - } - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.SetFramebuffer(fb, attachments); + // Do not call vkCmdBeginRenderPass again. + m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); } - // Record image usage for images cleared in the beginning of the render pass. - const VulkanCreationInfo::RenderPass &rpinfo = - m_CreationInfo.m_RenderPass[GetResID(RenderPassBegin.renderPass)]; - const rdcarray &fbattachments = - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetFramebufferAttachments(); - for(size_t i = 0; i < rpinfo.attachments.size(); i++) + GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, + FindCommandQueueFamily(m_LastCmdBufferID), + (uint32_t)imgBarriers.size(), imgBarriers.data()); + if(loading) { - if(rpinfo.attachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR || - rpinfo.attachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE) + // Record image usage for images cleared in the beginning of the render pass. + for(size_t i = 0; i < rpinfo.attachments.size(); i++) { - ResourceId image = m_CreationInfo.m_ImageView[fbattachments[i]].image; - m_LoadingEventNode.resourceUsage.push_back( - make_rdcpair(image, rpinfo.attachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR + if(rpinfo.attachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR || + rpinfo.attachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE) + AddEventResourceUsage(m_CreationInfo.m_ImageView[attachments[i]].image, + rpinfo.attachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR ? ResourceUsage::Clear - : ResourceUsage::Discard)); + : ResourceUsage::Discard); } - } - rdcarray imgBarriers = GetImplicitRenderPassBarriers(); - - GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, - FindCommandQueueFamily(m_LastCmdBufferID), - (uint32_t)imgBarriers.size(), imgBarriers.data()); - - AddEvent(); - ActionDescription action; - action.customName = - StringFormat::Fmt("vkCmdBeginRenderPass(%s)", MakeRenderPassOpString(false).c_str()); - action.flags |= ActionFlags::PassBoundary | ActionFlags::BeginPass; + AddEvent(); + ActionDescription action; + action.customName = + StringFormat::Fmt("vkCmdBeginRenderPass(%s)", MakeRenderPassOpString(false).c_str()); + action.flags |= ActionFlags::PassBoundary | ActionFlags::BeginPass; - AddAction(action); + AddAction(action); + } } } @@ -2462,69 +2415,59 @@ bool WrappedVulkan::Serialise_vkCmdNextSubpass(SerialiserType &ser, VkCommandBuf { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + bool loading = IsLoading(m_State); + bool replaySingleEvent = !loading && (m_FirstEventID == m_LastEventID); + // don't do anything if we're executing a single draw, NextSubpass is meaningless (and invalid + // on a partial render pass) + if(InRerecordRange(m_LastCmdBufferID) && !replaySingleEvent) { - // don't do anything if we're executing a single draw, NextSubpass is meaningless (and invalid - // on a partial render pass) - if(InRerecordRange(m_LastCmdBufferID) && m_FirstEventID != m_LastEventID) - { + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - GetCmdRenderState().subpass++; - m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass++; - } - - ActionFlags drawFlags = - ActionFlags::PassBoundary | ActionFlags::BeginPass | ActionFlags::EndPass; - uint32_t eventId = HandlePreCallback(commandBuffer, drawFlags); + // Track usage before the renderstate is modified + if(loading) + AddImplicitResolveResourceUsage(); - ObjDisp(commandBuffer)->CmdNextSubpass(Unwrap(commandBuffer), contents); - - if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) - { - // Do not call vkCmdNextSubpass again. - m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); - } - - rdcarray imgBarriers = GetImplicitRenderPassBarriers(); - - GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, - FindCommandQueueFamily(m_LastCmdBufferID), - (uint32_t)imgBarriers.size(), imgBarriers.data()); - } - else if(IsRenderpassOpen(m_LastCmdBufferID) && m_FirstEventID != m_LastEventID) { - commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer)->CmdNextSubpass(Unwrap(commandBuffer), contents); - + GetCmdRenderState().subpass++; m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass++; - m_BakedCmdBufferInfo[m_LastCmdBufferID].endBarriers.append(GetImplicitRenderPassBarriers()); } - } - else - { - ObjDisp(commandBuffer)->CmdNextSubpass(Unwrap(commandBuffer), contents); - AddImplicitResolveResourceUsage(); + ActionFlags drawFlags = + ActionFlags::PassBoundary | ActionFlags::BeginPass | ActionFlags::EndPass; + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, drawFlags) : 0; - // track while reading, for fetching the right set of outputs in AddAction - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.subpass++; - m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass++; + ObjDisp(commandBuffer)->CmdNextSubpass(Unwrap(commandBuffer), contents); + + if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) + { + // Do not call vkCmdNextSubpass again. + m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); + } rdcarray imgBarriers = GetImplicitRenderPassBarriers(); GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, FindCommandQueueFamily(m_LastCmdBufferID), (uint32_t)imgBarriers.size(), imgBarriers.data()); + if(loading) + { + AddEvent(); + ActionDescription action; + action.customName = StringFormat::Fmt( + "vkCmdNextSubpass() => %u", m_BakedCmdBufferInfo[m_LastCmdBufferID].state.subpass); + action.flags |= ActionFlags::PassBoundary | ActionFlags::BeginPass | ActionFlags::EndPass; - AddEvent(); - ActionDescription action; - action.customName = StringFormat::Fmt("vkCmdNextSubpass() => %u", - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.subpass); - action.flags |= ActionFlags::PassBoundary | ActionFlags::BeginPass | ActionFlags::EndPass; + AddAction(action); + } + } + else if(IsRenderpassOpen(m_LastCmdBufferID) && m_FirstEventID != m_LastEventID) + { + commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); + ObjDisp(commandBuffer)->CmdNextSubpass(Unwrap(commandBuffer), contents); - AddAction(action); + m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass++; + m_BakedCmdBufferInfo[m_LastCmdBufferID].endBarriers.append(GetImplicitRenderPassBarriers()); } } @@ -2563,115 +2506,105 @@ bool WrappedVulkan::Serialise_vkCmdEndRenderPass(SerialiserType &ser, VkCommandB { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - rdcarray imgBarriers = GetImplicitRenderPassBarriers(~0U); + rdcarray imgBarriers = GetImplicitRenderPassBarriers(~0U); - // only if we're partially recording do we update this state - if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, false)) - { - GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = - m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; - } + // only if we're partially recording do we update this state + if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, false)) + { + GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = + m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; + } - rdcarray attachments; - VkRect2D renderArea; + rdcarray attachments; + VkRect2D renderArea; - // save the renderpass that we were in here, so we can look up the rpinfo below - ResourceId currentRP = GetCmdRenderState().GetRenderPass(); + // save the renderpass that we were in here, so we can look up the rpinfo below + ResourceId currentRP = GetCmdRenderState().GetRenderPass(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); + if(loading) { - VulkanRenderState &renderstate = GetCmdRenderState(); + // Track usage and action outputs before the renderstate is modified + AddImplicitResolveResourceUsage(~0U); - attachments = GetCmdRenderState().GetFramebufferAttachments(); - renderArea = GetCmdRenderState().renderArea; + AddEvent(); + ActionDescription action; + action.customName = + StringFormat::Fmt("vkCmdEndRenderPass(%s)", MakeRenderPassOpString(true).c_str()); + action.flags |= ActionFlags::PassBoundary | ActionFlags::EndPass; - renderstate.SetRenderPass(ResourceId()); - renderstate.SetFramebuffer(ResourceId(), rdcarray()); - renderstate.subpassContents = VK_SUBPASS_CONTENTS_MAX_ENUM; + AddAction(action); } - ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::EndPass; - uint32_t eventId = HandlePreCallback(commandBuffer, drawFlags); + attachments = renderstate.GetFramebufferAttachments(); + renderArea = renderstate.renderArea; - ObjDisp(commandBuffer)->CmdEndRenderPass(Unwrap(commandBuffer)); + renderstate.SetRenderPass(ResourceId()); + renderstate.SetFramebuffer(ResourceId(), rdcarray()); + renderstate.subpassContents = VK_SUBPASS_CONTENTS_MAX_ENUM; + } - if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) - { - // Do not call vkCmdEndRenderPass again. - m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); - } + ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::EndPass; + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, drawFlags) : 0; - if(m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest && - !m_FeedbackRPs.contains(currentRP)) - { - ApplyRPStoreDiscards(commandBuffer, renderArea, currentRP, attachments); - } + ObjDisp(commandBuffer)->CmdEndRenderPass(Unwrap(commandBuffer)); - GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, - FindCommandQueueFamily(m_LastCmdBufferID), - (uint32_t)imgBarriers.size(), imgBarriers.data()); + if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) + { + // Do not call vkCmdEndRenderPass again. + m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); } - else if(IsRenderpassOpen(m_LastCmdBufferID)) + + if(!loading && m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest && + !m_FeedbackRPs.contains(currentRP)) { - commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer)->CmdEndRenderPass(Unwrap(commandBuffer)); + ApplyRPStoreDiscards(commandBuffer, renderArea, currentRP, attachments); + } - m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; - m_BakedCmdBufferInfo[m_LastCmdBufferID].endBarriers.append(GetImplicitRenderPassBarriers(~0U)); + GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, + FindCommandQueueFamily(m_LastCmdBufferID), + (uint32_t)imgBarriers.size(), imgBarriers.data()); - ResourceId currentRP = GetCmdRenderState().GetRenderPass(); + if(loading) + { + // After the renderpass is ended + // fetch any queued indirect readbacks + for(const VkIndirectRecordData &indirectcopy : + m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies) + ExecuteIndirectReadback(commandBuffer, indirectcopy); - if(Vulkan_Hack_DisableRPNormalisation() && !m_FeedbackRPs.contains(currentRP)) - { - ApplyRPStoreDiscards(commandBuffer, GetCmdRenderState().renderArea, currentRP, - GetCmdRenderState().GetFramebufferAttachments()); - } + // and deferred descriptor buffer versions here + for(const BakedCmdBufferInfo::DeferredDescBufCopy &descVersion : + m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies) + CopyVersionedDescriptorBuffer(commandBuffer, descVersion.unwrappedDstBuffer, + descVersion.copyOffsets); + + m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies.clear(); + m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies.clear(); } } - else + else if(IsRenderpassOpen(m_LastCmdBufferID)) { + commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); ObjDisp(commandBuffer)->CmdEndRenderPass(Unwrap(commandBuffer)); - // fetch any queued indirect readbacks here - for(const VkIndirectRecordData &indirectcopy : - m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies) - ExecuteIndirectReadback(commandBuffer, indirectcopy); - - // and deferred descriptor buffer versions here - for(const BakedCmdBufferInfo::DeferredDescBufCopy &descVersion : - m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies) - CopyVersionedDescriptorBuffer(commandBuffer, descVersion.unwrappedDstBuffer, - descVersion.copyOffsets); - - m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies.clear(); - m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies.clear(); - - rdcarray imgBarriers = GetImplicitRenderPassBarriers(~0U); - - GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, - FindCommandQueueFamily(m_LastCmdBufferID), - (uint32_t)imgBarriers.size(), imgBarriers.data()); - - AddImplicitResolveResourceUsage(~0U); + m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; + m_BakedCmdBufferInfo[m_LastCmdBufferID].endBarriers.append(GetImplicitRenderPassBarriers(~0U)); - AddEvent(); - ActionDescription action; - action.customName = - StringFormat::Fmt("vkCmdEndRenderPass(%s)", MakeRenderPassOpString(true).c_str()); - action.flags |= ActionFlags::PassBoundary | ActionFlags::EndPass; - - AddAction(action); + ResourceId currentRP = GetCmdRenderState().GetRenderPass(); - // track while reading, reset this to empty so AddAction sets no outputs, - // but only AFTER the above AddAction (we want it grouped together) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.SetRenderPass(ResourceId()); - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.SetFramebuffer(ResourceId(), - rdcarray()); + if(Vulkan_Hack_DisableRPNormalisation() && !m_FeedbackRPs.contains(currentRP)) + { + ApplyRPStoreDiscards(commandBuffer, GetCmdRenderState().renderArea, currentRP, + GetCmdRenderState().GetFramebufferAttachments()); + } } } @@ -2720,71 +2653,77 @@ bool WrappedVulkan::Serialise_vkCmdBeginRenderPass2(SerialiserType &ser, if(IsReplayingAndReading()) { - VkRenderPassBeginInfo unwrappedInfo = RenderPassBegin; - unwrappedInfo.renderPass = Unwrap(unwrappedInfo.renderPass); - unwrappedInfo.framebuffer = Unwrap(unwrappedInfo.framebuffer); + m_LastCmdBufferID = GetResID(commandBuffer); - VkSubpassBeginInfo unwrappedBeginInfo = SubpassBegin; + if(InRerecordRange(m_LastCmdBufferID)) + { + bool loading = IsLoading(m_State); + bool replaySingleEvent = !loading && (m_FirstEventID == m_LastEventID); + if(!loading) + commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext) + - GetNextPatchSize(unwrappedBeginInfo.pNext)); + VkRenderPassBeginInfo unwrappedInfo = RenderPassBegin; + unwrappedInfo.renderPass = Unwrap(unwrappedInfo.renderPass); + unwrappedInfo.framebuffer = Unwrap(unwrappedInfo.framebuffer); - UnwrapNextChain(m_State, "VkRenderPassBeginInfo", tempMem, (VkBaseInStructure *)&unwrappedInfo); - UnwrapNextChain(m_State, "VkSubpassBeginInfo", tempMem, (VkBaseInStructure *)&unwrappedBeginInfo); + VkSubpassBeginInfo unwrappedBeginInfo = SubpassBegin; - m_LastCmdBufferID = GetResID(commandBuffer); + byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext) + + GetNextPatchSize(unwrappedBeginInfo.pNext)); - if(IsActiveReplaying(m_State)) - { - if(InRerecordRange(m_LastCmdBufferID)) + UnwrapNextChain(m_State, "VkRenderPassBeginInfo", tempMem, (VkBaseInStructure *)&unwrappedInfo); + UnwrapNextChain(m_State, "VkSubpassBeginInfo", tempMem, + (VkBaseInStructure *)&unwrappedBeginInfo); + + // only if we're partially recording do we update this state + if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, false)) { - commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); + GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = + m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = true; + } - // only if we're partially recording do we update this state - if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, false)) - { - GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = - m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = true; - } + m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass = 0; - m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass = 0; + ResourceId fb = GetResID(RenderPassBegin.framebuffer); + VulkanCreationInfo::Framebuffer fbinfo = m_CreationInfo.m_Framebuffer[fb]; + ResourceId rp = GetResID(RenderPassBegin.renderPass); - ResourceId fb = GetResID(RenderPassBegin.framebuffer); - VulkanCreationInfo::Framebuffer fbinfo = m_CreationInfo.m_Framebuffer[fb]; - { - VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.subpass = 0; - renderstate.SetRenderPass(GetResID(RenderPassBegin.renderPass)); - renderstate.renderArea = RenderPassBegin.renderArea; - renderstate.subpassContents = SubpassBegin.contents; + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.fragmentDensityMapOffsets.clear(); + renderstate.subpass = 0; + renderstate.SetRenderPass(GetResID(RenderPassBegin.renderPass)); + renderstate.renderArea = RenderPassBegin.renderArea; + renderstate.subpassContents = SubpassBegin.contents; + renderstate.fragmentDensityMapOffsets.clear(); - const VkRenderPassAttachmentBeginInfo *attachmentsInfo = - (const VkRenderPassAttachmentBeginInfo *)FindNextStruct( - &RenderPassBegin, VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO); + const VkRenderPassAttachmentBeginInfo *attachmentsInfo = + (const VkRenderPassAttachmentBeginInfo *)FindNextStruct( + &RenderPassBegin, VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO); - rdcarray attachments; - attachments.resize(fbinfo.attachments.size()); + rdcarray attachments; + attachments.resize(fbinfo.attachments.size()); - // set framebuffer attachments - by default from the ones used to create it, but if it is - // imageless then look for the attachments in our pNext chain - if(!fbinfo.imageless) - { - for(size_t i = 0; i < fbinfo.attachments.size(); i++) - attachments[i] = fbinfo.attachments[i].createdView; - } - else - { - for(size_t i = 0; i < fbinfo.attachments.size(); i++) - attachments[i] = GetResID(attachmentsInfo->pAttachments[i]); - } - renderstate.SetFramebuffer(GetResID(RenderPassBegin.framebuffer), attachments); + // set framebuffer attachments - by default from the ones used to create it, but if it is + // imageless then look for the attachments in our pNext chain + if(!fbinfo.imageless) + { + for(size_t i = 0; i < fbinfo.attachments.size(); i++) + attachments[i] = fbinfo.attachments[i].createdView; + } + else + { + for(size_t i = 0; i < fbinfo.attachments.size(); i++) + attachments[i] = GetResID(attachmentsInfo->pAttachments[i]); } + renderstate.SetFramebuffer(GetResID(RenderPassBegin.framebuffer), attachments); + } - const VulkanCreationInfo::RenderPass &rpinfo = - m_CreationInfo.m_RenderPass[GetCmdRenderState().GetRenderPass()]; + const VulkanCreationInfo::RenderPass &rpinfo = + m_CreationInfo.m_RenderPass[GetCmdRenderState().GetRenderPass()]; + if(!loading) + { ApplyRPLoadDiscards(commandBuffer, RenderPassBegin.renderArea); rdcarray imgBarriers = GetImplicitRenderPassBarriers(); @@ -2794,175 +2733,125 @@ bool WrappedVulkan::Serialise_vkCmdBeginRenderPass2(SerialiserType &ser, // we need to manually do the subpass 0 barriers, since loadRP expects the image to already // be in subpass 0's layout // we also need to manually do any clears, since the loadRP will load all attachments - if(m_FirstEventID == m_LastEventID) + if(replaySingleEvent) { unwrappedInfo.renderPass = Unwrap(rpinfo.loadRPs[0]); unwrappedInfo.framebuffer = Unwrap(fbinfo.loadFBs[0]); DoPipelineBarrier(commandBuffer, imgBarriers.size(), imgBarriers.data()); } + } - ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::BeginPass; - uint32_t eventId = HandlePreCallback(commandBuffer, drawFlags); + ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::BeginPass; + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, drawFlags) : 0; - ObjDisp(commandBuffer) - ->CmdBeginRenderPass2(Unwrap(commandBuffer), &unwrappedInfo, &unwrappedBeginInfo); + ObjDisp(commandBuffer) + ->CmdBeginRenderPass2(Unwrap(commandBuffer), &unwrappedInfo, &unwrappedBeginInfo); + + if(replaySingleEvent) + { + const rdcarray &fbattachments = + m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetFramebufferAttachments(); - if(m_FirstEventID == m_LastEventID) + rdcarray clearatts; + rdcarray clearrects; + RDCASSERT(unwrappedInfo.clearValueCount <= (uint32_t)rpinfo.attachments.size(), + unwrappedInfo.clearValueCount, rpinfo.attachments.size()); + for(int32_t c = 0; c < rpinfo.subpasses[0].colorAttachments.count() + 1; c++) { - const rdcarray &fbattachments = - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetFramebufferAttachments(); + uint32_t att = ~0U; - rdcarray clearatts; - rdcarray clearrects; - RDCASSERT(unwrappedInfo.clearValueCount <= (uint32_t)rpinfo.attachments.size(), - unwrappedInfo.clearValueCount, rpinfo.attachments.size()); - for(int32_t c = 0; c < rpinfo.subpasses[0].colorAttachments.count() + 1; c++) - { - uint32_t att = ~0U; + if(c < rpinfo.subpasses[0].colorAttachments.count()) + att = rpinfo.subpasses[0].colorAttachments[c]; + else if(rpinfo.subpasses[0].depthstencilAttachment >= 0) + att = (uint32_t)rpinfo.subpasses[0].depthstencilAttachment; - if(c < rpinfo.subpasses[0].colorAttachments.count()) - att = rpinfo.subpasses[0].colorAttachments[c]; - else if(rpinfo.subpasses[0].depthstencilAttachment >= 0) - att = (uint32_t)rpinfo.subpasses[0].depthstencilAttachment; + if(att >= rpinfo.attachments.size()) + continue; - if(att >= rpinfo.attachments.size()) - continue; + VkImageAspectFlags clearAspects = 0; - VkImageAspectFlags clearAspects = 0; + // loadOp governs color, and depth + if(rpinfo.attachments[att].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) + clearAspects |= VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; + // stencilLoadOp governs the stencil + if(rpinfo.attachments[att].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) + clearAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; - // loadOp governs color, and depth - if(rpinfo.attachments[att].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) - clearAspects |= VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; - // stencilLoadOp governs the stencil - if(rpinfo.attachments[att].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) - clearAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; + // if any aspect is set to clear, go check it in more detail + if(clearAspects != 0) + { + VulkanCreationInfo::ImageView viewinfo = m_CreationInfo.m_ImageView[fbattachments[att]]; + bool isMultiview = rpinfo.subpasses[0].multiviews.size() > 1; + + VkClearRect rect = {unwrappedInfo.renderArea, 0, + isMultiview ? 1 : viewinfo.range.layerCount}; + VkClearAttachment clear = {}; + clear.aspectMask = FormatImageAspects(rpinfo.attachments[att].format) & clearAspects; + clear.colorAttachment = c; + if(att < unwrappedInfo.clearValueCount) + clear.clearValue = unwrappedInfo.pClearValues[att]; + else + RDCWARN("Missing clear value for attachment %u", att); - // if any aspect is set to clear, go check it in more detail - if(clearAspects != 0) + // check that the actual aspects in the attachment overlap with those being cleared. + // In particular this means we ignore stencil load op being CLEAR for a color + // attachment - that doesn't mean we should clear the color. This also means we don't + // clear the stencil if it's not specified, even when clearing depth *is* + if(clear.aspectMask != 0) { - VulkanCreationInfo::ImageView viewinfo = m_CreationInfo.m_ImageView[fbattachments[att]]; - bool isMultiview = rpinfo.subpasses[0].multiviews.size() > 1; - - VkClearRect rect = {unwrappedInfo.renderArea, 0, - isMultiview ? 1 : viewinfo.range.layerCount}; - VkClearAttachment clear = {}; - clear.aspectMask = FormatImageAspects(rpinfo.attachments[att].format) & clearAspects; - clear.colorAttachment = c; - if(att < unwrappedInfo.clearValueCount) - clear.clearValue = unwrappedInfo.pClearValues[att]; - else - RDCWARN("Missing clear value for attachment %u", att); - - // check that the actual aspects in the attachment overlap with those being cleared. - // In particular this means we ignore stencil load op being CLEAR for a color - // attachment - that doesn't mean we should clear the color. This also means we don't - // clear the stencil if it's not specified, even when clearing depth *is* - if(clear.aspectMask != 0) - { - clearrects.push_back(rect); - clearatts.push_back(clear); - } + clearrects.push_back(rect); + clearatts.push_back(clear); } } - - if(!clearatts.empty()) - ObjDisp(commandBuffer) - ->CmdClearAttachments(Unwrap(commandBuffer), (uint32_t)clearatts.size(), - clearatts.data(), (uint32_t)clearrects.size(), - clearrects.data()); } - if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) + if(!clearatts.empty()) + ObjDisp(commandBuffer) + ->CmdClearAttachments(Unwrap(commandBuffer), (uint32_t)clearatts.size(), + clearatts.data(), (uint32_t)clearrects.size(), clearrects.data()); + } + + if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) + { + // Do not call vkCmdBeginRenderPass2 again. + m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); + } + + if(loading) + { + // Record image usage for images cleared in the beginning of the render pass. + const rdcarray &fbattachments = + m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetFramebufferAttachments(); + for(size_t i = 0; i < rpinfo.attachments.size(); i++) { - // Do not call vkCmdBeginRenderPass2 again. - m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); + if(rpinfo.attachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR || + rpinfo.attachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE) + AddEventResourceUsage(m_CreationInfo.m_ImageView[fbattachments[i]].image, + rpinfo.attachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR + ? ResourceUsage::Clear + : ResourceUsage::Discard); } - GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, - FindCommandQueueFamily(m_LastCmdBufferID), - (uint32_t)imgBarriers.size(), imgBarriers.data()); + AddEvent(); + ActionDescription action; + action.customName = + StringFormat::Fmt("vkCmdBeginRenderPass2(%s)", MakeRenderPassOpString(false).c_str()); + action.flags |= ActionFlags::PassBoundary | ActionFlags::BeginPass; + + AddAction(action); } } - else - { - ObjDisp(commandBuffer) - ->CmdBeginRenderPass2(Unwrap(commandBuffer), &unwrappedInfo, &unwrappedBeginInfo); + } - // track while reading, for fetching the right set of outputs in AddAction - m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass = 0; - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.subpass = 0; - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.SetRenderPass( - GetResID(RenderPassBegin.renderPass)); + return true; +} - ResourceId fb = GetResID(RenderPassBegin.framebuffer); - - // set framebuffer attachments - by default from the ones used to create it, but if it is - // imageless then look for the attachments in our pNext chain - { - VulkanCreationInfo::Framebuffer fbinfo = m_CreationInfo.m_Framebuffer[fb]; - rdcarray attachments; - attachments.resize(fbinfo.attachments.size()); - - if(!fbinfo.imageless) - { - for(size_t i = 0; i < fbinfo.attachments.size(); i++) - attachments[i] = fbinfo.attachments[i].createdView; - } - else - { - const VkRenderPassAttachmentBeginInfo *attachmentsInfo = - (const VkRenderPassAttachmentBeginInfo *)FindNextStruct( - &RenderPassBegin, VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO); - - for(size_t i = 0; i < fbinfo.attachments.size(); i++) - attachments[i] = GetResID(attachmentsInfo->pAttachments[i]); - } - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.SetFramebuffer(fb, attachments); - } - - // Record image usage for images cleared in the beginning of the render pass. - const VulkanCreationInfo::RenderPass &rpinfo = - m_CreationInfo.m_RenderPass[GetResID(RenderPassBegin.renderPass)]; - const rdcarray &fbattachments = - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetFramebufferAttachments(); - for(size_t i = 0; i < rpinfo.attachments.size(); i++) - { - if(rpinfo.attachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR || - rpinfo.attachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE) - { - ResourceId image = m_CreationInfo.m_ImageView[fbattachments[i]].image; - m_LoadingEventNode.resourceUsage.push_back( - make_rdcpair(image, rpinfo.attachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR - ? ResourceUsage::Clear - : ResourceUsage::Discard)); - } - } - - rdcarray imgBarriers = GetImplicitRenderPassBarriers(); - - GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, - FindCommandQueueFamily(m_LastCmdBufferID), - (uint32_t)imgBarriers.size(), imgBarriers.data()); - - AddEvent(); - ActionDescription action; - action.customName = - StringFormat::Fmt("vkCmdBeginRenderPass2(%s)", MakeRenderPassOpString(false).c_str()); - action.flags |= ActionFlags::PassBoundary | ActionFlags::BeginPass; - - AddAction(action); - } - } - - return true; -} - -void WrappedVulkan::vkCmdBeginRenderPass2(VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo *pRenderPassBegin, - const VkSubpassBeginInfo *pSubpassBeginInfo) -{ - SCOPED_DBG_SINK(); +void WrappedVulkan::vkCmdBeginRenderPass2(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo *pRenderPassBegin, + const VkSubpassBeginInfo *pSubpassBeginInfo) +{ + SCOPED_DBG_SINK(); VkRenderPassBeginInfo unwrappedInfo = *pRenderPassBegin; unwrappedInfo.renderPass = Unwrap(unwrappedInfo.renderPass); @@ -3097,58 +2986,32 @@ bool WrappedVulkan::Serialise_vkCmdNextSubpass2(SerialiserType &ser, VkCommandBu m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + bool loading = IsLoading(m_State); + bool replaySingleEvent = !loading && (m_FirstEventID == m_LastEventID); + // don't do anything if we're executing a single draw, NextSubpass is meaningless (and invalid + // on a partial render pass) + if(InRerecordRange(m_LastCmdBufferID) && !replaySingleEvent) { - // don't do anything if we're executing a single draw, NextSubpass is meaningless (and invalid - // on a partial render pass) - if(InRerecordRange(m_LastCmdBufferID) && m_FirstEventID != m_LastEventID) - { + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - GetCmdRenderState().subpass++; - m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass++; - } - - ActionFlags drawFlags = - ActionFlags::PassBoundary | ActionFlags::BeginPass | ActionFlags::EndPass; - uint32_t eventId = HandlePreCallback(commandBuffer, drawFlags); - - ObjDisp(commandBuffer) - ->CmdNextSubpass2(Unwrap(commandBuffer), &unwrappedBeginInfo, &unwrappedEndInfo); - - if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) - { - // Do not call vkCmdNextSubpass2 again. - m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); - } - - rdcarray imgBarriers = GetImplicitRenderPassBarriers(); - - GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, - FindCommandQueueFamily(m_LastCmdBufferID), - (uint32_t)imgBarriers.size(), imgBarriers.data()); - } - else if(IsRenderpassOpen(m_LastCmdBufferID) && m_FirstEventID != m_LastEventID) { - commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdNextSubpass2(Unwrap(commandBuffer), &unwrappedBeginInfo, &unwrappedEndInfo); - + GetCmdRenderState().subpass++; m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass++; - m_BakedCmdBufferInfo[m_LastCmdBufferID].endBarriers.append(GetImplicitRenderPassBarriers()); } - } - else - { + + ActionFlags drawFlags = + ActionFlags::PassBoundary | ActionFlags::BeginPass | ActionFlags::EndPass; + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, drawFlags) : 0; + ObjDisp(commandBuffer) ->CmdNextSubpass2(Unwrap(commandBuffer), &unwrappedBeginInfo, &unwrappedEndInfo); - AddImplicitResolveResourceUsage(); - - // track while reading, for fetching the right set of outputs in AddAction - m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass++; - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.subpass++; + if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) + { + // Do not call vkCmdNextSubpass2 again. + m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); + } rdcarray imgBarriers = GetImplicitRenderPassBarriers(); @@ -3156,13 +3019,27 @@ bool WrappedVulkan::Serialise_vkCmdNextSubpass2(SerialiserType &ser, VkCommandBu FindCommandQueueFamily(m_LastCmdBufferID), (uint32_t)imgBarriers.size(), imgBarriers.data()); - AddEvent(); - ActionDescription action; - action.customName = StringFormat::Fmt("vkCmdNextSubpass2() => %u", - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.subpass); - action.flags |= ActionFlags::PassBoundary | ActionFlags::BeginPass | ActionFlags::EndPass; + if(loading) + { + AddImplicitResolveResourceUsage(); - AddAction(action); + AddEvent(); + ActionDescription action; + action.customName = StringFormat::Fmt( + "vkCmdNextSubpass2() => %u", m_BakedCmdBufferInfo[m_LastCmdBufferID].state.subpass); + action.flags |= ActionFlags::PassBoundary | ActionFlags::BeginPass | ActionFlags::EndPass; + + AddAction(action); + } + } + else if(IsRenderpassOpen(m_LastCmdBufferID) && m_FirstEventID != m_LastEventID) + { + commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); + ObjDisp(commandBuffer) + ->CmdNextSubpass2(Unwrap(commandBuffer), &unwrappedBeginInfo, &unwrappedEndInfo); + + m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass++; + m_BakedCmdBufferInfo[m_LastCmdBufferID].endBarriers.append(GetImplicitRenderPassBarriers()); } } @@ -3222,125 +3099,116 @@ bool WrappedVulkan::Serialise_vkCmdEndRenderPass2(SerialiserType &ser, VkCommand m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - rdcarray imgBarriers = GetImplicitRenderPassBarriers(~0U); + rdcarray imgBarriers = GetImplicitRenderPassBarriers(~0U); - // only if we're partially recording do we update this state - if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, false)) - { - GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = - m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; - } + // only if we're partially recording do we update this state + if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, false)) + { + GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = + m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; + } - ResourceId currentRP = GetCmdRenderState().GetRenderPass(); + ResourceId currentRP = GetCmdRenderState().GetRenderPass(); - rdcarray attachments; - VkRect2D renderArea; + rdcarray attachments; + VkRect2D renderArea; + { + VulkanRenderState &renderstate = GetCmdRenderState(); + if(loading) { - VulkanRenderState &renderstate = GetCmdRenderState(); + // Track usage and action outputs before the renderstate is modified + AddImplicitResolveResourceUsage(~0U); - attachments = GetCmdRenderState().GetFramebufferAttachments(); - renderArea = GetCmdRenderState().renderArea; + AddEvent(); + ActionDescription action; + action.customName = + StringFormat::Fmt("vkCmdEndRenderPass2(%s)", MakeRenderPassOpString(true).c_str()); + action.flags |= ActionFlags::PassBoundary | ActionFlags::EndPass; - renderstate.SetRenderPass(ResourceId()); - renderstate.SetFramebuffer(ResourceId(), rdcarray()); - renderstate.subpassContents = VK_SUBPASS_CONTENTS_MAX_ENUM; + AddAction(action); } - ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::EndPass; - uint32_t eventId = HandlePreCallback(commandBuffer, drawFlags); - ObjDisp(commandBuffer)->CmdEndRenderPass2(Unwrap(commandBuffer), &unwrappedEndInfo); + attachments = GetCmdRenderState().GetFramebufferAttachments(); + renderArea = GetCmdRenderState().renderArea; - if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) - { - // Do not call vkCmdEndRenderPass2 again. - m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); - } + renderstate.SetRenderPass(ResourceId()); + renderstate.SetFramebuffer(ResourceId(), rdcarray()); + renderstate.subpassContents = VK_SUBPASS_CONTENTS_MAX_ENUM; + } - if(m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest && - !m_FeedbackRPs.contains(currentRP)) - { - ApplyRPStoreDiscards(commandBuffer, renderArea, currentRP, attachments); - } + ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::EndPass; + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, drawFlags) : 0; - GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, - FindCommandQueueFamily(m_LastCmdBufferID), - (uint32_t)imgBarriers.size(), imgBarriers.data()); - } - else if(IsRenderpassOpen(m_LastCmdBufferID)) + ObjDisp(commandBuffer)->CmdEndRenderPass2(Unwrap(commandBuffer), &unwrappedEndInfo); + + if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) { - commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer)->CmdEndRenderPass2(Unwrap(commandBuffer), &unwrappedEndInfo); + // Do not call vkCmdEndRenderPass2 again. + m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); + } - m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; - m_BakedCmdBufferInfo[m_LastCmdBufferID].endBarriers.append(GetImplicitRenderPassBarriers(~0U)); + if(!loading && m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest && + !m_FeedbackRPs.contains(currentRP)) + { + ApplyRPStoreDiscards(commandBuffer, renderArea, currentRP, attachments); + } - const VkRenderPassFragmentDensityMapOffsetEndInfoEXT *fragmentDensityOffsetStruct = - (const VkRenderPassFragmentDensityMapOffsetEndInfoEXT *)FindNextStruct( - &unwrappedEndInfo, - VK_STRUCTURE_TYPE_RENDER_PASS_FRAGMENT_DENSITY_MAP_OFFSET_END_INFO_EXT); + GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, + FindCommandQueueFamily(m_LastCmdBufferID), + (uint32_t)imgBarriers.size(), imgBarriers.data()); + if(loading) + { + // fetch any queued indirect readbacks here + for(const VkIndirectRecordData &indirectcopy : + m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies) + ExecuteIndirectReadback(commandBuffer, indirectcopy); - if(fragmentDensityOffsetStruct) - { - rdcarray &stateOffsets = GetCmdRenderState().fragmentDensityMapOffsets; - stateOffsets.resize(fragmentDensityOffsetStruct->fragmentDensityOffsetCount); - for(uint32_t i = 0; i < fragmentDensityOffsetStruct->fragmentDensityOffsetCount; i++) - { - stateOffsets[i] = fragmentDensityOffsetStruct->pFragmentDensityOffsets[i]; - } - } + // and deferred descriptor buffer versions here + for(const BakedCmdBufferInfo::DeferredDescBufCopy &descVersion : + m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies) + CopyVersionedDescriptorBuffer(commandBuffer, descVersion.unwrappedDstBuffer, + descVersion.copyOffsets); - ResourceId currentRP = GetCmdRenderState().GetRenderPass(); - if(Vulkan_Hack_DisableRPNormalisation() && !m_FeedbackRPs.contains(currentRP)) - { - ApplyRPStoreDiscards(commandBuffer, GetCmdRenderState().renderArea, currentRP, - GetCmdRenderState().GetFramebufferAttachments()); - } + m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies.clear(); + m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies.clear(); } } - else + else if(IsRenderpassOpen(m_LastCmdBufferID)) { + commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); ObjDisp(commandBuffer)->CmdEndRenderPass2(Unwrap(commandBuffer), &unwrappedEndInfo); - // fetch any queued indirect readbacks here - for(const VkIndirectRecordData &indirectcopy : - m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies) - ExecuteIndirectReadback(commandBuffer, indirectcopy); - - // and deferred descriptor buffer versions here - for(const BakedCmdBufferInfo::DeferredDescBufCopy &descVersion : - m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies) - CopyVersionedDescriptorBuffer(commandBuffer, descVersion.unwrappedDstBuffer, - descVersion.copyOffsets); - - m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies.clear(); - m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies.clear(); - - rdcarray imgBarriers = GetImplicitRenderPassBarriers(~0U); - - GetResourceManager()->RecordBarriers(m_BakedCmdBufferInfo[m_LastCmdBufferID].imageStates, - FindCommandQueueFamily(m_LastCmdBufferID), - (uint32_t)imgBarriers.size(), imgBarriers.data()); + m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; + m_BakedCmdBufferInfo[m_LastCmdBufferID].endBarriers.append(GetImplicitRenderPassBarriers(~0U)); - AddEvent(); - ActionDescription action; - action.customName = - StringFormat::Fmt("vkCmdEndRenderPass2(%s)", MakeRenderPassOpString(true).c_str()); - action.flags |= ActionFlags::PassBoundary | ActionFlags::EndPass; + const VkRenderPassFragmentDensityMapOffsetEndInfoEXT *fragmentDensityOffsetStruct = + (const VkRenderPassFragmentDensityMapOffsetEndInfoEXT *)FindNextStruct( + &unwrappedEndInfo, + VK_STRUCTURE_TYPE_RENDER_PASS_FRAGMENT_DENSITY_MAP_OFFSET_END_INFO_EXT); - AddAction(action); + if(fragmentDensityOffsetStruct) + { + rdcarray &stateOffsets = GetCmdRenderState().fragmentDensityMapOffsets; + stateOffsets.resize(fragmentDensityOffsetStruct->fragmentDensityOffsetCount); + for(uint32_t i = 0; i < fragmentDensityOffsetStruct->fragmentDensityOffsetCount; i++) + { + stateOffsets[i] = fragmentDensityOffsetStruct->pFragmentDensityOffsets[i]; + } + } - // track while reading, reset this to empty so AddAction sets no outputs, - // but only AFTER the above AddAction (we want it grouped together) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.SetRenderPass(ResourceId()); - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.SetFramebuffer(ResourceId(), - rdcarray()); + ResourceId currentRP = GetCmdRenderState().GetRenderPass(); + if(Vulkan_Hack_DisableRPNormalisation() && !m_FeedbackRPs.contains(currentRP)) + { + ApplyRPStoreDiscards(commandBuffer, GetCmdRenderState().renderArea, currentRP, + GetCmdRenderState().GetFramebufferAttachments()); + } } } @@ -3398,381 +3266,347 @@ bool WrappedVulkan::Serialise_vkCmdBindPipeline(SerialiserType &ser, VkCommandBu { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ResourceId id = GetResID(pipeline); + ResourceId id = GetResID(pipeline); + ResourceId prevPipeline; + { + VulkanRenderState &renderstate = GetCmdRenderState(); + if(pipelineBindPoint == VK_PIPELINE_BIND_POINT_COMPUTE) { - VulkanRenderState &renderstate = GetCmdRenderState(); - if(pipelineBindPoint == VK_PIPELINE_BIND_POINT_COMPUTE) - { - renderstate.compute.pipeline = id; - renderstate.compute.shaderObject = false; + prevPipeline = renderstate.compute.pipeline; + renderstate.compute.pipeline = id; + renderstate.compute.shaderObject = false; - // disturb compute shader bound via vkCmdBindShadersEXT, if any - renderstate.shaderObjects[(uint32_t)ShaderStage::Compute] = ResourceId(); + // disturb compute shader bound via vkCmdBindShadersEXT, if any + renderstate.shaderObjects[(uint32_t)ShaderStage::Compute] = ResourceId(); + } + else if(pipelineBindPoint == VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR) + { + prevPipeline = renderstate.rt.pipeline; + renderstate.rt.pipeline = id; + } + else + { + prevPipeline = renderstate.graphics.pipeline; + renderstate.graphics.pipeline = id; + renderstate.graphics.shaderObject = false; + + // disturb graphics shaders bound via vkCmdBindShadersEXT, if any + for(uint32_t i = 0; i < (uint32_t)ShaderStage::Count; i++) + { + if(i == (uint32_t)ShaderStage::Compute) + continue; + renderstate.shaderObjects[i] = ResourceId(); } - else if(pipelineBindPoint == VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR) + + const VulkanCreationInfo::Pipeline &pipeInfo = m_CreationInfo.m_Pipeline[id]; + + // any static state from the pipeline invalidates any dynamic state previously bound + for(uint32_t i = 0; i < VkDynamicCount; i++) + renderstate.dynamicStates[i] &= pipeInfo.dynamicStates[i]; + + if(!pipeInfo.dynamicStates[VkDynamicViewport] && + !pipeInfo.dynamicStates[VkDynamicViewportCount]) { - renderstate.rt.pipeline = id; + renderstate.views = pipeInfo.viewports; } - else + if(!pipeInfo.dynamicStates[VkDynamicScissor] && + !pipeInfo.dynamicStates[VkDynamicScissorCount]) { - renderstate.graphics.pipeline = id; - renderstate.graphics.shaderObject = false; - - // disturb graphics shaders bound via vkCmdBindShadersEXT, if any - for(uint32_t i = 0; i < (uint32_t)ShaderStage::Count; i++) - { - if(i == (uint32_t)ShaderStage::Compute) - continue; - renderstate.shaderObjects[i] = ResourceId(); - } + renderstate.scissors = pipeInfo.scissors; + } - const VulkanCreationInfo::Pipeline &pipeInfo = m_CreationInfo.m_Pipeline[id]; + if(!pipeInfo.dynamicStates[VkDynamicViewportCount]) + { + renderstate.views.resize(RDCMIN(renderstate.views.size(), pipeInfo.viewports.size())); + } + if(!pipeInfo.dynamicStates[VkDynamicScissorCount]) + { + renderstate.scissors.resize(RDCMIN(renderstate.scissors.size(), pipeInfo.scissors.size())); + } - // any static state from the pipeline invalidates any dynamic state previously bound - for(uint32_t i = 0; i < VkDynamicCount; i++) - renderstate.dynamicStates[i] &= pipeInfo.dynamicStates[i]; + if(!pipeInfo.dynamicStates[VkDynamicLineWidth]) + { + renderstate.lineWidth = pipeInfo.lineWidth; + } + if(!pipeInfo.dynamicStates[VkDynamicDepthBias]) + { + renderstate.bias.depth = pipeInfo.depthBiasConstantFactor; + renderstate.bias.biasclamp = pipeInfo.depthBiasClamp; + renderstate.bias.slope = pipeInfo.depthBiasSlopeFactor; + renderstate.bias.exact = pipeInfo.depthBiasExact != VK_FALSE; + renderstate.bias.repr = pipeInfo.depthBiasRepresentation; + } + if(!pipeInfo.dynamicStates[VkDynamicBlendConstants]) + { + memcpy(renderstate.blendConst, pipeInfo.blendConst, sizeof(float) * 4); + } + if(!pipeInfo.dynamicStates[VkDynamicDepthBounds]) + { + renderstate.mindepth = pipeInfo.minDepthBounds; + renderstate.maxdepth = pipeInfo.maxDepthBounds; + } + if(!pipeInfo.dynamicStates[VkDynamicStencilCompareMask]) + { + renderstate.front.compare = pipeInfo.front.compareMask; + renderstate.back.compare = pipeInfo.back.compareMask; + } + if(!pipeInfo.dynamicStates[VkDynamicStencilWriteMask]) + { + renderstate.front.write = pipeInfo.front.writeMask; + renderstate.back.write = pipeInfo.back.writeMask; + } + if(!pipeInfo.dynamicStates[VkDynamicStencilReference]) + { + renderstate.front.ref = pipeInfo.front.reference; + renderstate.back.ref = pipeInfo.back.reference; + } + if(!pipeInfo.dynamicStates[VkDynamicSampleLocationsEXT]) + { + renderstate.sampleLocations.locations = pipeInfo.sampleLocations.locations; + renderstate.sampleLocations.gridSize = pipeInfo.sampleLocations.gridSize; + renderstate.sampleLocations.sampleCount = pipeInfo.rasterizationSamples; + } + if(!pipeInfo.dynamicStates[VkDynamicDiscardRectangleEXT]) + { + renderstate.discardRectangles = pipeInfo.discardRectangles; + } + if(!pipeInfo.dynamicStates[VkDynamicShadingRateKHR]) + { + renderstate.pipelineShadingRate = pipeInfo.shadingRate; + renderstate.shadingRateCombiners[0] = pipeInfo.shadingRateCombiners[0]; + renderstate.shadingRateCombiners[1] = pipeInfo.shadingRateCombiners[1]; + } + if(!pipeInfo.dynamicStates[VkDynamicLineStipple]) + { + renderstate.stippleFactor = pipeInfo.stippleFactor; + renderstate.stipplePattern = pipeInfo.stipplePattern; + } + if(!pipeInfo.dynamicStates[VkDynamicCullMode]) + { + renderstate.cullMode = pipeInfo.cullMode; + } + if(!pipeInfo.dynamicStates[VkDynamicFrontFace]) + { + renderstate.frontFace = pipeInfo.frontFace; + } + if(!pipeInfo.dynamicStates[VkDynamicPrimitiveTopology]) + { + renderstate.primitiveTopology = pipeInfo.topology; + } + if(!pipeInfo.dynamicStates[VkDynamicDepthTestEnable]) + { + renderstate.depthTestEnable = pipeInfo.depthTestEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicDepthWriteEnable]) + { + renderstate.depthWriteEnable = pipeInfo.depthWriteEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicDepthCompareOp]) + { + renderstate.depthCompareOp = pipeInfo.depthCompareOp; + } + if(!pipeInfo.dynamicStates[VkDynamicDepthBoundsTestEnable]) + { + renderstate.depthBoundsTestEnable = pipeInfo.depthBoundsEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicStencilTestEnable]) + { + renderstate.stencilTestEnable = pipeInfo.stencilTestEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicStencilOp]) + { + renderstate.front.passOp = pipeInfo.front.passOp; + renderstate.back.passOp = pipeInfo.back.passOp; - if(!pipeInfo.dynamicStates[VkDynamicViewport] && - !pipeInfo.dynamicStates[VkDynamicViewportCount]) - { - renderstate.views = pipeInfo.viewports; - } - if(!pipeInfo.dynamicStates[VkDynamicScissor] && - !pipeInfo.dynamicStates[VkDynamicScissorCount]) - { - renderstate.scissors = pipeInfo.scissors; - } + renderstate.front.failOp = pipeInfo.front.failOp; + renderstate.back.failOp = pipeInfo.back.failOp; - if(!pipeInfo.dynamicStates[VkDynamicViewportCount]) - { - renderstate.views.resize(RDCMIN(renderstate.views.size(), pipeInfo.viewports.size())); - } - if(!pipeInfo.dynamicStates[VkDynamicScissorCount]) - { - renderstate.scissors.resize( - RDCMIN(renderstate.scissors.size(), pipeInfo.scissors.size())); - } + renderstate.front.depthFailOp = pipeInfo.front.depthFailOp; + renderstate.back.depthFailOp = pipeInfo.back.depthFailOp; - if(!pipeInfo.dynamicStates[VkDynamicLineWidth]) - { - renderstate.lineWidth = pipeInfo.lineWidth; - } - if(!pipeInfo.dynamicStates[VkDynamicDepthBias]) - { - renderstate.bias.depth = pipeInfo.depthBiasConstantFactor; - renderstate.bias.biasclamp = pipeInfo.depthBiasClamp; - renderstate.bias.slope = pipeInfo.depthBiasSlopeFactor; - renderstate.bias.exact = pipeInfo.depthBiasExact != VK_FALSE; - renderstate.bias.repr = pipeInfo.depthBiasRepresentation; - } - if(!pipeInfo.dynamicStates[VkDynamicBlendConstants]) - { - memcpy(renderstate.blendConst, pipeInfo.blendConst, sizeof(float) * 4); - } - if(!pipeInfo.dynamicStates[VkDynamicDepthBounds]) - { - renderstate.mindepth = pipeInfo.minDepthBounds; - renderstate.maxdepth = pipeInfo.maxDepthBounds; - } - if(!pipeInfo.dynamicStates[VkDynamicStencilCompareMask]) - { - renderstate.front.compare = pipeInfo.front.compareMask; - renderstate.back.compare = pipeInfo.back.compareMask; - } - if(!pipeInfo.dynamicStates[VkDynamicStencilWriteMask]) - { - renderstate.front.write = pipeInfo.front.writeMask; - renderstate.back.write = pipeInfo.back.writeMask; - } - if(!pipeInfo.dynamicStates[VkDynamicStencilReference]) - { - renderstate.front.ref = pipeInfo.front.reference; - renderstate.back.ref = pipeInfo.back.reference; - } - if(!pipeInfo.dynamicStates[VkDynamicSampleLocationsEXT]) - { - renderstate.sampleLocations.locations = pipeInfo.sampleLocations.locations; - renderstate.sampleLocations.gridSize = pipeInfo.sampleLocations.gridSize; - renderstate.sampleLocations.sampleCount = pipeInfo.rasterizationSamples; - } - if(!pipeInfo.dynamicStates[VkDynamicDiscardRectangleEXT]) - { - renderstate.discardRectangles = pipeInfo.discardRectangles; - } - if(!pipeInfo.dynamicStates[VkDynamicShadingRateKHR]) + renderstate.front.compareOp = pipeInfo.front.compareOp; + renderstate.back.compareOp = pipeInfo.back.compareOp; + } + if(!pipeInfo.dynamicStates[VkDynamicVertexInputBindingStride]) + { + for(const VulkanCreationInfo::Pipeline::VertBinding &bind : pipeInfo.vertexBindings) { - renderstate.pipelineShadingRate = pipeInfo.shadingRate; - renderstate.shadingRateCombiners[0] = pipeInfo.shadingRateCombiners[0]; - renderstate.shadingRateCombiners[1] = pipeInfo.shadingRateCombiners[1]; + renderstate.vbuffers.resize_for_index(bind.vbufferBinding); + renderstate.vbuffers[bind.vbufferBinding].stride = bind.bytestride; } - if(!pipeInfo.dynamicStates[VkDynamicLineStipple]) + } + if(!pipeInfo.dynamicStates[VkDynamicColorWriteEXT]) + { + renderstate.colorWriteEnable.resize(pipeInfo.attachments.size()); + for(size_t i = 0; i < renderstate.colorWriteEnable.size(); i++) + renderstate.colorWriteEnable[i] = pipeInfo.attachments[i].writeEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicDepthBiasEnable]) + { + renderstate.depthBiasEnable = pipeInfo.depthBiasEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicLogicOpEXT]) + { + renderstate.logicOp = pipeInfo.logicOp; + } + if(!pipeInfo.dynamicStates[VkDynamicControlPointsEXT]) + { + renderstate.patchControlPoints = pipeInfo.patchControlPoints; + } + if(!pipeInfo.dynamicStates[VkDynamicPrimRestart]) + { + renderstate.primRestartEnable = pipeInfo.primitiveRestartEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicRastDiscard]) + { + renderstate.rastDiscardEnable = pipeInfo.rasterizerDiscardEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicVertexInputEXT]) + { + renderstate.vertexAttributes.resize(pipeInfo.vertexAttrs.size()); + for(size_t i = 0; i < renderstate.vertexAttributes.size(); i++) { - renderstate.stippleFactor = pipeInfo.stippleFactor; - renderstate.stipplePattern = pipeInfo.stipplePattern; + renderstate.vertexAttributes[i].sType = + VK_STRUCTURE_TYPE_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION_2_EXT; + renderstate.vertexAttributes[i].pNext = NULL; + renderstate.vertexAttributes[i].format = pipeInfo.vertexAttrs[i].format; + renderstate.vertexAttributes[i].binding = pipeInfo.vertexAttrs[i].binding; + renderstate.vertexAttributes[i].offset = pipeInfo.vertexAttrs[i].byteoffset; + renderstate.vertexAttributes[i].location = pipeInfo.vertexAttrs[i].location; } - if(!pipeInfo.dynamicStates[VkDynamicCullMode]) + renderstate.vertexBindings.resize(pipeInfo.vertexBindings.size()); + for(size_t i = 0; i < renderstate.vertexBindings.size(); i++) { - renderstate.cullMode = pipeInfo.cullMode; + renderstate.vertexBindings[i].sType = + VK_STRUCTURE_TYPE_VERTEX_INPUT_BINDING_DESCRIPTION_2_EXT; + renderstate.vertexBindings[i].pNext = NULL; + renderstate.vertexBindings[i].binding = pipeInfo.vertexBindings[i].vbufferBinding; + renderstate.vertexBindings[i].inputRate = pipeInfo.vertexBindings[i].perInstance + ? VK_VERTEX_INPUT_RATE_INSTANCE + : VK_VERTEX_INPUT_RATE_VERTEX; + renderstate.vertexBindings[i].stride = pipeInfo.vertexBindings[i].bytestride; + renderstate.vertexBindings[i].divisor = pipeInfo.vertexBindings[i].instanceDivisor; } - if(!pipeInfo.dynamicStates[VkDynamicFrontFace]) + } + if(!pipeInfo.dynamicStates[VkDynamicAttachmentFeedbackLoopEnableEXT]) + { + renderstate.feedbackAspects = VK_IMAGE_ASPECT_NONE; + if(pipeInfo.flags & VK_PIPELINE_CREATE_COLOR_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT) + renderstate.feedbackAspects |= VK_IMAGE_ASPECT_COLOR_BIT; + if(pipeInfo.flags & VK_PIPELINE_CREATE_DEPTH_STENCIL_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT) + renderstate.feedbackAspects |= VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + } + if(!pipeInfo.dynamicStates[VkDynamicAlphaToCoverageEXT]) + { + renderstate.alphaToCoverageEnable = pipeInfo.alphaToCoverageEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicAlphaToOneEXT]) + { + renderstate.alphaToOneEnable = pipeInfo.alphaToOneEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicColorBlendEnableEXT]) + { + renderstate.colorBlendEnable.resize(pipeInfo.attachments.size()); + for(size_t i = 0; i < renderstate.colorBlendEnable.size(); i++) + renderstate.colorBlendEnable[i] = pipeInfo.attachments[i].blendEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicColorBlendEquationEXT]) + { + renderstate.colorBlendEquation.resize(pipeInfo.attachments.size()); + for(size_t i = 0; i < renderstate.colorBlendEquation.size(); i++) { - renderstate.frontFace = pipeInfo.frontFace; - } - if(!pipeInfo.dynamicStates[VkDynamicPrimitiveTopology]) - { - renderstate.primitiveTopology = pipeInfo.topology; - } - if(!pipeInfo.dynamicStates[VkDynamicDepthTestEnable]) - { - renderstate.depthTestEnable = pipeInfo.depthTestEnable; - } - if(!pipeInfo.dynamicStates[VkDynamicDepthWriteEnable]) - { - renderstate.depthWriteEnable = pipeInfo.depthWriteEnable; - } - if(!pipeInfo.dynamicStates[VkDynamicDepthCompareOp]) - { - renderstate.depthCompareOp = pipeInfo.depthCompareOp; - } - if(!pipeInfo.dynamicStates[VkDynamicDepthBoundsTestEnable]) - { - renderstate.depthBoundsTestEnable = pipeInfo.depthBoundsEnable; - } - if(!pipeInfo.dynamicStates[VkDynamicStencilTestEnable]) - { - renderstate.stencilTestEnable = pipeInfo.stencilTestEnable; - } - if(!pipeInfo.dynamicStates[VkDynamicStencilOp]) - { - renderstate.front.passOp = pipeInfo.front.passOp; - renderstate.back.passOp = pipeInfo.back.passOp; - - renderstate.front.failOp = pipeInfo.front.failOp; - renderstate.back.failOp = pipeInfo.back.failOp; - - renderstate.front.depthFailOp = pipeInfo.front.depthFailOp; - renderstate.back.depthFailOp = pipeInfo.back.depthFailOp; - - renderstate.front.compareOp = pipeInfo.front.compareOp; - renderstate.back.compareOp = pipeInfo.back.compareOp; - } - if(!pipeInfo.dynamicStates[VkDynamicVertexInputBindingStride]) - { - for(const VulkanCreationInfo::Pipeline::VertBinding &bind : pipeInfo.vertexBindings) - { - renderstate.vbuffers.resize_for_index(bind.vbufferBinding); - renderstate.vbuffers[bind.vbufferBinding].stride = bind.bytestride; - } - } - if(!pipeInfo.dynamicStates[VkDynamicColorWriteEXT]) - { - renderstate.colorWriteEnable.resize(pipeInfo.attachments.size()); - for(size_t i = 0; i < renderstate.colorWriteEnable.size(); i++) - renderstate.colorWriteEnable[i] = pipeInfo.attachments[i].channelWriteMask != 0; - } - if(!pipeInfo.dynamicStates[VkDynamicDepthBiasEnable]) - { - renderstate.depthBiasEnable = pipeInfo.depthBiasEnable; - } - if(!pipeInfo.dynamicStates[VkDynamicLogicOpEXT]) - { - renderstate.logicOp = pipeInfo.logicOp; - } - if(!pipeInfo.dynamicStates[VkDynamicControlPointsEXT]) - { - renderstate.patchControlPoints = pipeInfo.patchControlPoints; - } - if(!pipeInfo.dynamicStates[VkDynamicPrimRestart]) - { - renderstate.primRestartEnable = pipeInfo.primitiveRestartEnable; - } - if(!pipeInfo.dynamicStates[VkDynamicRastDiscard]) - { - renderstate.rastDiscardEnable = pipeInfo.rasterizerDiscardEnable; - } - if(!pipeInfo.dynamicStates[VkDynamicVertexInputEXT]) - { - renderstate.vertexAttributes.resize(pipeInfo.vertexAttrs.size()); - for(size_t i = 0; i < renderstate.vertexAttributes.size(); i++) - { - renderstate.vertexAttributes[i].sType = - VK_STRUCTURE_TYPE_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION_2_EXT; - renderstate.vertexAttributes[i].pNext = NULL; - renderstate.vertexAttributes[i].format = pipeInfo.vertexAttrs[i].format; - renderstate.vertexAttributes[i].binding = pipeInfo.vertexAttrs[i].binding; - renderstate.vertexAttributes[i].offset = pipeInfo.vertexAttrs[i].byteoffset; - renderstate.vertexAttributes[i].location = pipeInfo.vertexAttrs[i].location; - } - renderstate.vertexBindings.resize(pipeInfo.vertexBindings.size()); - for(size_t i = 0; i < renderstate.vertexBindings.size(); i++) - { - renderstate.vertexBindings[i].sType = - VK_STRUCTURE_TYPE_VERTEX_INPUT_BINDING_DESCRIPTION_2_EXT; - renderstate.vertexBindings[i].pNext = NULL; - renderstate.vertexBindings[i].binding = pipeInfo.vertexBindings[i].vbufferBinding; - renderstate.vertexBindings[i].inputRate = pipeInfo.vertexBindings[i].perInstance - ? VK_VERTEX_INPUT_RATE_INSTANCE - : VK_VERTEX_INPUT_RATE_VERTEX; - renderstate.vertexBindings[i].stride = pipeInfo.vertexBindings[i].bytestride; - renderstate.vertexBindings[i].divisor = pipeInfo.vertexBindings[i].instanceDivisor; - } - } - if(!pipeInfo.dynamicStates[VkDynamicAttachmentFeedbackLoopEnableEXT]) - { - renderstate.feedbackAspects = VK_IMAGE_ASPECT_NONE; - if(pipeInfo.flags & VK_PIPELINE_CREATE_COLOR_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT) - renderstate.feedbackAspects |= VK_IMAGE_ASPECT_COLOR_BIT; - if(pipeInfo.flags & VK_PIPELINE_CREATE_DEPTH_STENCIL_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT) - renderstate.feedbackAspects |= - VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; - } - if(!pipeInfo.dynamicStates[VkDynamicAlphaToCoverageEXT]) - { - renderstate.alphaToCoverageEnable = pipeInfo.alphaToCoverageEnable; - } - if(!pipeInfo.dynamicStates[VkDynamicAlphaToOneEXT]) - { - renderstate.alphaToOneEnable = pipeInfo.alphaToOneEnable; - } - if(!pipeInfo.dynamicStates[VkDynamicColorBlendEnableEXT]) - { - renderstate.colorBlendEnable.resize(pipeInfo.attachments.size()); - for(size_t i = 0; i < renderstate.colorBlendEnable.size(); i++) - renderstate.colorBlendEnable[i] = pipeInfo.attachments[i].blendEnable; - } - if(!pipeInfo.dynamicStates[VkDynamicColorBlendEquationEXT]) - { - renderstate.colorBlendEquation.resize(pipeInfo.attachments.size()); - for(size_t i = 0; i < renderstate.colorBlendEquation.size(); i++) - { - renderstate.colorBlendEquation[i].srcColorBlendFactor = - pipeInfo.attachments[i].blend.Source; - renderstate.colorBlendEquation[i].dstColorBlendFactor = - pipeInfo.attachments[i].blend.Destination; - renderstate.colorBlendEquation[i].colorBlendOp = - pipeInfo.attachments[i].blend.Operation; - renderstate.colorBlendEquation[i].srcAlphaBlendFactor = - pipeInfo.attachments[i].alphaBlend.Source; - renderstate.colorBlendEquation[i].dstAlphaBlendFactor = - pipeInfo.attachments[i].alphaBlend.Destination; - renderstate.colorBlendEquation[i].alphaBlendOp = - pipeInfo.attachments[i].alphaBlend.Operation; - } - } - if(!pipeInfo.dynamicStates[VkDynamicColorWriteMaskEXT]) - { - renderstate.colorWriteMask.resize(pipeInfo.attachments.size()); - for(size_t i = 0; i < renderstate.colorWriteMask.size(); i++) - { - renderstate.colorWriteMask[i] = (uint32_t)pipeInfo.attachments[i].channelWriteMask; - } - } - if(!pipeInfo.dynamicStates[VkDynamicConservativeRastModeEXT]) - { - renderstate.conservativeRastMode = pipeInfo.conservativeRasterizationMode; - } - if(!pipeInfo.dynamicStates[VkDynamicDepthClampEnableEXT]) - { - renderstate.depthClampEnable = pipeInfo.depthClampEnable; - } - if(!pipeInfo.dynamicStates[VkDynamicDepthClipEnableEXT]) - { - renderstate.depthClipEnable = pipeInfo.depthClipEnable; - } - if(!pipeInfo.dynamicStates[VkDynamicDepthClipNegativeOneEXT]) - { - renderstate.negativeOneToOne = pipeInfo.negativeOneToOne; - } - if(!pipeInfo.dynamicStates[VkDynamicOverstimationSizeEXT]) - { - renderstate.primOverestimationSize = pipeInfo.extraPrimitiveOverestimationSize; - } - if(!pipeInfo.dynamicStates[VkDynamicLineRastModeEXT]) - { - renderstate.lineRasterMode = pipeInfo.lineRasterMode; - } - if(!pipeInfo.dynamicStates[VkDynamicLineStippleEnableEXT]) - { - renderstate.stippledLineEnable = pipeInfo.stippleEnabled; - } - if(!pipeInfo.dynamicStates[VkDynamicLogicOpEnableEXT]) - { - renderstate.logicOpEnable = pipeInfo.logicOpEnable; - } - if(!pipeInfo.dynamicStates[VkDynamicPolygonModeEXT]) - { - renderstate.polygonMode = pipeInfo.polygonMode; - } - if(!pipeInfo.dynamicStates[VkDynamicProvokingVertexModeEXT]) - { - renderstate.provokingVertexMode = pipeInfo.provokingVertex; - } - if(!pipeInfo.dynamicStates[VkDynamicRasterizationSamplesEXT]) - { - renderstate.rastSamples = pipeInfo.rasterizationSamples; - } - if(!pipeInfo.dynamicStates[VkDynamicRasterizationStreamEXT]) - { - renderstate.rasterStream = pipeInfo.rasterizationStream; - } - if(!pipeInfo.dynamicStates[VkDynamicSampleLocationsEnableEXT]) - { - renderstate.sampleLocEnable = pipeInfo.sampleLocations.enabled; - } - if(!pipeInfo.dynamicStates[VkDynamicSampleMaskEXT]) - { - renderstate.sampleMask[0] = pipeInfo.sampleMask; - } - if(!pipeInfo.dynamicStates[VkDynamicTessDomainOriginEXT]) - { - renderstate.domainOrigin = pipeInfo.tessellationDomainOrigin; + renderstate.colorBlendEquation[i].srcColorBlendFactor = + pipeInfo.attachments[i].blend.Source; + renderstate.colorBlendEquation[i].dstColorBlendFactor = + pipeInfo.attachments[i].blend.Destination; + renderstate.colorBlendEquation[i].colorBlendOp = + pipeInfo.attachments[i].blend.Operation; + renderstate.colorBlendEquation[i].srcAlphaBlendFactor = + pipeInfo.attachments[i].alphaBlend.Source; + renderstate.colorBlendEquation[i].dstAlphaBlendFactor = + pipeInfo.attachments[i].alphaBlend.Destination; + renderstate.colorBlendEquation[i].alphaBlendOp = + pipeInfo.attachments[i].alphaBlend.Operation; } } + if(!pipeInfo.dynamicStates[VkDynamicColorWriteMaskEXT]) + { + renderstate.colorWriteMask.resize(pipeInfo.attachments.size()); + for(size_t i = 0; i < renderstate.colorWriteMask.size(); i++) + renderstate.colorWriteMask[i] = (uint32_t)pipeInfo.attachments[i].channelWriteMask; + } + if(!pipeInfo.dynamicStates[VkDynamicConservativeRastModeEXT]) + { + renderstate.conservativeRastMode = pipeInfo.conservativeRasterizationMode; + } + if(!pipeInfo.dynamicStates[VkDynamicDepthClampEnableEXT]) + { + renderstate.depthClampEnable = pipeInfo.depthClampEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicDepthClipEnableEXT]) + { + renderstate.depthClipEnable = pipeInfo.depthClipEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicDepthClipNegativeOneEXT]) + { + renderstate.negativeOneToOne = pipeInfo.negativeOneToOne; + } + if(!pipeInfo.dynamicStates[VkDynamicOverstimationSizeEXT]) + { + renderstate.primOverestimationSize = pipeInfo.extraPrimitiveOverestimationSize; + } + if(!pipeInfo.dynamicStates[VkDynamicLineRastModeEXT]) + { + renderstate.lineRasterMode = pipeInfo.lineRasterMode; + } + if(!pipeInfo.dynamicStates[VkDynamicLineStippleEnableEXT]) + { + renderstate.stippledLineEnable = pipeInfo.stippleEnabled; + } + if(!pipeInfo.dynamicStates[VkDynamicLogicOpEnableEXT]) + { + renderstate.logicOpEnable = pipeInfo.logicOpEnable; + } + if(!pipeInfo.dynamicStates[VkDynamicPolygonModeEXT]) + { + renderstate.polygonMode = pipeInfo.polygonMode; + } + if(!pipeInfo.dynamicStates[VkDynamicProvokingVertexModeEXT]) + { + renderstate.provokingVertexMode = pipeInfo.provokingVertex; + } + if(!pipeInfo.dynamicStates[VkDynamicRasterizationSamplesEXT]) + { + renderstate.rastSamples = pipeInfo.rasterizationSamples; + } + if(!pipeInfo.dynamicStates[VkDynamicRasterizationStreamEXT]) + { + renderstate.rasterStream = pipeInfo.rasterizationStream; + } + if(!pipeInfo.dynamicStates[VkDynamicSampleLocationsEnableEXT]) + { + renderstate.sampleLocEnable = pipeInfo.sampleLocations.enabled; + } + if(!pipeInfo.dynamicStates[VkDynamicSampleMaskEXT]) + { + renderstate.sampleMask[0] = pipeInfo.sampleMask; + } + if(!pipeInfo.dynamicStates[VkDynamicTessDomainOriginEXT]) + { + renderstate.domainOrigin = pipeInfo.tessellationDomainOrigin; + } } } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - else - { - ResourceId id = GetResID(pipeline); - - // track while reading, as we need to bind current topology & index byte width in AddAction - if(pipelineBindPoint == VK_PIPELINE_BIND_POINT_COMPUTE) - { - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.compute.pipeline = id; - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.compute.shaderObject = false; - } - else if(pipelineBindPoint == VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR) - { - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.rt.pipeline = id; - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.rt.shaderObject = false; - } - else - { - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.graphics.pipeline = id; - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.graphics.shaderObject = false; - - const VulkanCreationInfo::Pipeline &pipeInfo = m_CreationInfo.m_Pipeline[id]; - - if(!pipeInfo.dynamicStates[VkDynamicPrimitiveTopology]) - { - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.primitiveTopology = pipeInfo.topology; - } - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdBindPipeline(Unwrap(commandBuffer), pipelineBindPoint, Unwrap(pipeline)); + } } return true; @@ -3825,92 +3659,63 @@ bool WrappedVulkan::Serialise_vkCmdBindDescriptorSets( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdBindDescriptorSets(Unwrap(commandBuffer), pipelineBindPoint, Unwrap(layout), - firstSet, setCount, UnwrapArray(pDescriptorSets, setCount), - dynamicOffsetCount, pDynamicOffsets); + ObjDisp(commandBuffer) + ->CmdBindDescriptorSets(Unwrap(commandBuffer), pipelineBindPoint, Unwrap(layout), + firstSet, setCount, UnwrapArray(pDescriptorSets, setCount), + dynamicOffsetCount, pDynamicOffsets); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); - rdcarray &descsets = pipeline.descSets; + VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); + rdcarray &descsets = pipeline.descSets; - // descriptor buffers and descriptor sets can't co-exist, each invalidates the other - if(pipeline.UsingDescBufs()) - { - renderstate.descBufs.clear(); - descsets.clear(); - } + // descriptor buffers and descriptor sets can't co-exist, each invalidates the other + if(pipeline.UsingDescBufs()) + { + renderstate.descBufs.clear(); + descsets.clear(); + } - // expand as necessary - if(descsets.size() < firstSet + setCount) - descsets.resize(firstSet + setCount); + // expand as necessary + if(descsets.size() < firstSet + setCount) + descsets.resize(firstSet + setCount); - pipeline.lastBoundDescSet = firstSet; - pipeline.lastBoundDescBufSet = -1; + pipeline.lastBoundDescSet = firstSet; + pipeline.lastBoundDescBufSet = -1; - const rdcarray &descSetLayouts = - m_CreationInfo.m_PipelineLayout[GetResID(layout)].descSetLayouts; + const rdcarray &descSetLayouts = + m_CreationInfo.m_PipelineLayout[GetResID(layout)].descSetLayouts; - const uint32_t *offsIter = pDynamicOffsets; - uint32_t dynConsumed = 0; + const uint32_t *offsIter = pDynamicOffsets; + uint32_t dynConsumed = 0; - // consume the offsets linearly along the descriptor set layouts - for(uint32_t i = 0; i < setCount; i++) - { - descsets[firstSet + i] = VulkanStatePipeline::DescriptorAndOffsets(); - descsets[firstSet + i].pipeLayout = GetResID(layout); - descsets[firstSet + i].descSet = GetResID(pDescriptorSets[i]); + // consume the offsets linearly along the descriptor set layouts + for(uint32_t i = 0; i < setCount; i++) + { + descsets[firstSet + i] = VulkanStatePipeline::DescriptorAndOffsets(); + descsets[firstSet + i].pipeLayout = GetResID(layout); + descsets[firstSet + i].descSet = GetResID(pDescriptorSets[i]); + descsets[firstSet + i].push = false; - if(descSetLayouts[firstSet + i] == ResourceId()) - continue; + if(descSetLayouts[firstSet + i] == ResourceId()) + continue; - uint32_t dynCount = - m_CreationInfo.m_DescSetLayout[descSetLayouts[firstSet + i]].dynamicCount; - descsets[firstSet + i].offsets.assign(offsIter, dynCount); - offsIter += dynCount; - dynConsumed += dynCount; - RDCASSERT(dynConsumed <= dynamicOffsetCount); - } + uint32_t dynCount = + m_CreationInfo.m_DescSetLayout[descSetLayouts[firstSet + i]].dynamicCount; + descsets[firstSet + i].offsets.assign(offsIter, dynCount); + offsIter += dynCount; + dynConsumed += dynCount; + RDCASSERT(dynConsumed <= dynamicOffsetCount); } } } - else - { - // track while reading, as we need to track resource usage - rdcarray &descsets = - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetPipeline(pipelineBindPoint).descSets; - - // descriptor buffers and descriptor sets can't co-exist, each invalidates the other - if(m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetPipeline(pipelineBindPoint).UsingDescBufs()) - { - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.descBufs.clear(); - descsets.clear(); - } - - // expand as necessary - if(descsets.size() < firstSet + setCount) - descsets.resize(firstSet + setCount); - - for(uint32_t i = 0; i < setCount; i++) - { - descsets[firstSet + i] = VulkanStatePipeline::DescriptorAndOffsets(); - descsets[firstSet + i].descSet = GetResID(pDescriptorSets[i]); - descsets[firstSet + i].push = false; - } - - ObjDisp(commandBuffer) - ->CmdBindDescriptorSets(Unwrap(commandBuffer), pipelineBindPoint, Unwrap(layout), - firstSet, setCount, UnwrapArray(pDescriptorSets, setCount), - dynamicOffsetCount, pDynamicOffsets); - } } return true; @@ -3968,100 +3773,69 @@ bool WrappedVulkan::Serialise_vkCmdBindDescriptorSets2( { m_LastCmdBufferID = GetResID(commandBuffer); - byte *tempMem = GetTempMemory(GetNextPatchSize(&BindDescriptorSetsInfo)); - VkBindDescriptorSetsInfo *unwrappedInfo = - UnwrapStructAndChain(m_State, tempMem, &BindDescriptorSetsInfo); - - rdcarray pipelinesAffected = - PipelinesForStageMask(BindDescriptorSetsInfo.stageFlags); - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer)->CmdBindDescriptorSets2(Unwrap(commandBuffer), unwrappedInfo); + byte *tempMem = GetTempMemory(GetNextPatchSize(&BindDescriptorSetsInfo)); + VkBindDescriptorSetsInfo *unwrappedInfo = + UnwrapStructAndChain(m_State, tempMem, &BindDescriptorSetsInfo); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + rdcarray pipelinesAffected = + PipelinesForStageMask(BindDescriptorSetsInfo.stageFlags); - for(VkPipelineBindPoint bindPoint : pipelinesAffected) - { - VulkanStatePipeline &pipeline = renderstate.GetPipeline(bindPoint); - rdcarray &descsets = pipeline.descSets; + ObjDisp(commandBuffer)->CmdBindDescriptorSets2(Unwrap(commandBuffer), unwrappedInfo); - // descriptor buffers and descriptor sets can't co-exist, each invalidates the other - if(pipeline.UsingDescBufs()) - { - renderstate.descBufs.clear(); - descsets.clear(); - } + { + VulkanRenderState &renderstate = GetCmdRenderState(); - uint32_t firstSet = BindDescriptorSetsInfo.firstSet; + for(VkPipelineBindPoint bindPoint : pipelinesAffected) + { + VulkanStatePipeline &pipeline = renderstate.GetPipeline(bindPoint); + rdcarray &descsets = pipeline.descSets; - // expand as necessary - descsets.resize_for_index(firstSet + BindDescriptorSetsInfo.descriptorSetCount - 1); + // descriptor buffers and descriptor sets can't co-exist, each invalidates the other + if(pipeline.UsingDescBufs()) + { + renderstate.descBufs.clear(); + descsets.clear(); + } - pipeline.lastBoundDescSet = firstSet; - pipeline.lastBoundDescBufSet = -1; + uint32_t firstSet = BindDescriptorSetsInfo.firstSet; - const rdcarray &descSetLayouts = - m_CreationInfo.m_PipelineLayout[GetResID(BindDescriptorSetsInfo.layout)].descSetLayouts; + // expand as necessary + descsets.resize_for_index(firstSet + BindDescriptorSetsInfo.descriptorSetCount - 1); - const uint32_t *offsIter = BindDescriptorSetsInfo.pDynamicOffsets; - uint32_t dynConsumed = 0; + pipeline.lastBoundDescSet = firstSet; + pipeline.lastBoundDescBufSet = -1; - // consume the offsets linearly along the descriptor set layouts - for(uint32_t i = 0; i < BindDescriptorSetsInfo.descriptorSetCount; i++) - { - descsets[firstSet + i] = VulkanStatePipeline::DescriptorAndOffsets(); - descsets[firstSet + i].pipeLayout = GetResID(BindDescriptorSetsInfo.layout); - descsets[firstSet + i].descSet = GetResID(BindDescriptorSetsInfo.pDescriptorSets[i]); - - if(descSetLayouts[firstSet + i] == ResourceId()) - continue; - - uint32_t dynCount = - m_CreationInfo.m_DescSetLayout[descSetLayouts[firstSet + i]].dynamicCount; - descsets[firstSet + i].offsets.assign(offsIter, dynCount); - offsIter += dynCount; - dynConsumed += dynCount; - RDCASSERT(dynConsumed <= BindDescriptorSetsInfo.dynamicOffsetCount); - } - } - } - } - } - else - { - for(VkPipelineBindPoint bindPoint : pipelinesAffected) - { - // track while reading, as we need to track resource usage - rdcarray &descsets = - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetPipeline(bindPoint).descSets; + const rdcarray &descSetLayouts = + m_CreationInfo.m_PipelineLayout[GetResID(BindDescriptorSetsInfo.layout)].descSetLayouts; - // descriptor buffers and descriptor sets can't co-exist, each invalidates the other - if(m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetPipeline(bindPoint).UsingDescBufs()) - { - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.descBufs.clear(); - descsets.clear(); - } + const uint32_t *offsIter = BindDescriptorSetsInfo.pDynamicOffsets; + uint32_t dynConsumed = 0; - uint32_t firstSet = BindDescriptorSetsInfo.firstSet; + // consume the offsets linearly along the descriptor set layouts + for(uint32_t i = 0; i < BindDescriptorSetsInfo.descriptorSetCount; i++) + { + descsets[firstSet + i] = VulkanStatePipeline::DescriptorAndOffsets(); + descsets[firstSet + i].pipeLayout = GetResID(BindDescriptorSetsInfo.layout); + descsets[firstSet + i].descSet = GetResID(BindDescriptorSetsInfo.pDescriptorSets[i]); - // expand as necessary - descsets.resize_for_index(firstSet + BindDescriptorSetsInfo.descriptorSetCount - 1); + if(descSetLayouts[firstSet + i] == ResourceId()) + continue; - for(uint32_t i = 0; i < BindDescriptorSetsInfo.descriptorSetCount; i++) - { - descsets[firstSet + i] = VulkanStatePipeline::DescriptorAndOffsets(); - descsets[firstSet + i].descSet = GetResID(BindDescriptorSetsInfo.pDescriptorSets[i]); - descsets[firstSet + i].push = false; + uint32_t dynCount = + m_CreationInfo.m_DescSetLayout[descSetLayouts[firstSet + i]].dynamicCount; + descsets[firstSet + i].offsets.assign(offsIter, dynCount); + offsIter += dynCount; + dynConsumed += dynCount; + RDCASSERT(dynConsumed <= BindDescriptorSetsInfo.dynamicOffsetCount); + } } } - - ObjDisp(commandBuffer)->CmdBindDescriptorSets2(Unwrap(commandBuffer), unwrappedInfo); } } @@ -4122,42 +3896,28 @@ bool WrappedVulkan::Serialise_vkCmdBindVertexBuffers(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdBindVertexBuffers(Unwrap(commandBuffer), firstBinding, bindingCount, - UnwrapArray(pBuffers, bindingCount), pOffsets); - - { - VulkanRenderState &renderstate = GetCmdRenderState(); - if(renderstate.vbuffers.size() < firstBinding + bindingCount) - renderstate.vbuffers.resize(firstBinding + bindingCount); - - for(uint32_t i = 0; i < bindingCount; i++) - { - renderstate.vbuffers[firstBinding + i].buf = GetResID(pBuffers[i]); - renderstate.vbuffers[firstBinding + i].offs = pOffsets[i]; - renderstate.vbuffers[firstBinding + i].size = VK_WHOLE_SIZE; - } - } - } - } - else - { - // track while reading, as we need to track resource usage - if(m_BakedCmdBufferInfo[m_LastCmdBufferID].state.vbuffers.size() < firstBinding + bindingCount) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.vbuffers.resize(firstBinding + bindingCount); - - for(uint32_t i = 0; i < bindingCount; i++) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.vbuffers[firstBinding + i].buf = - GetResID(pBuffers[i]); ObjDisp(commandBuffer) ->CmdBindVertexBuffers(Unwrap(commandBuffer), firstBinding, bindingCount, UnwrapArray(pBuffers, bindingCount), pOffsets); + + { + VulkanRenderState &renderstate = GetCmdRenderState(); + if(renderstate.vbuffers.size() < firstBinding + bindingCount) + renderstate.vbuffers.resize(firstBinding + bindingCount); + + for(uint32_t i = 0; i < bindingCount; i++) + { + renderstate.vbuffers[firstBinding + i].buf = GetResID(pBuffers[i]); + renderstate.vbuffers[firstBinding + i].offs = pOffsets[i]; + renderstate.vbuffers[firstBinding + i].size = VK_WHOLE_SIZE; + } + } } } @@ -4217,58 +3977,44 @@ bool WrappedVulkan::Serialise_vkCmdBindVertexBuffers2( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdBindVertexBuffers2(Unwrap(commandBuffer), firstBinding, bindingCount, - UnwrapArray(pBuffers, bindingCount), pOffsets, pSizes, pStrides); + ObjDisp(commandBuffer) + ->CmdBindVertexBuffers2(Unwrap(commandBuffer), firstBinding, bindingCount, + UnwrapArray(pBuffers, bindingCount), pOffsets, pSizes, pStrides); + + { + VulkanRenderState &renderstate = GetCmdRenderState(); + if(renderstate.vbuffers.size() < firstBinding + bindingCount) + renderstate.vbuffers.resize(firstBinding + bindingCount); + + for(uint32_t i = 0; i < bindingCount; i++) { - VulkanRenderState &renderstate = GetCmdRenderState(); - if(renderstate.vbuffers.size() < firstBinding + bindingCount) - renderstate.vbuffers.resize(firstBinding + bindingCount); + renderstate.vbuffers[firstBinding + i].buf = GetResID(pBuffers[i]); + renderstate.vbuffers[firstBinding + i].offs = pOffsets[i]; + renderstate.vbuffers[firstBinding + i].size = pSizes ? pSizes[i] : VK_WHOLE_SIZE; - for(uint32_t i = 0; i < bindingCount; i++) + // if strides is NULL the pipeline bound must have had no dynamic state for stride and + // so stride was filled out then, we leave it as-is. + if(pStrides) { - renderstate.vbuffers[firstBinding + i].buf = GetResID(pBuffers[i]); - renderstate.vbuffers[firstBinding + i].offs = pOffsets[i]; - renderstate.vbuffers[firstBinding + i].size = pSizes ? pSizes[i] : VK_WHOLE_SIZE; - - // if strides is NULL the pipeline bound must have had no dynamic state for stride and - // so stride was filled out then, we leave it as-is. - if(pStrides) - { - renderstate.dynamicStates[VkDynamicVertexInputBindingStride] = true; + renderstate.dynamicStates[VkDynamicVertexInputBindingStride] = true; - renderstate.vbuffers[firstBinding + i].stride = pStrides[i]; + renderstate.vbuffers[firstBinding + i].stride = pStrides[i]; - // if we have dynamic vertex input data, update the strides. If we don't have any - // that's fine we can skip this, it means the application must provide a later - // vkCmdSetVertexInput which overrides anything we'd set here - if(firstBinding + i < renderstate.vertexBindings.size()) - renderstate.vertexBindings[firstBinding + i].stride = (uint32_t)pStrides[i]; - } + // if we have dynamic vertex input data, update the strides. If we don't have any + // that's fine we can skip this, it means the application must provide a later + // vkCmdSetVertexInput which overrides anything we'd set here + if(firstBinding + i < renderstate.vertexBindings.size()) + renderstate.vertexBindings[firstBinding + i].stride = (uint32_t)pStrides[i]; } } } } - else - { - // track while reading, as we need to track resource usage - if(m_BakedCmdBufferInfo[m_LastCmdBufferID].state.vbuffers.size() < firstBinding + bindingCount) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.vbuffers.resize(firstBinding + bindingCount); - - for(uint32_t i = 0; i < bindingCount; i++) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.vbuffers[firstBinding + i].buf = - GetResID(pBuffers[i]); - - ObjDisp(commandBuffer) - ->CmdBindVertexBuffers2(Unwrap(commandBuffer), firstBinding, bindingCount, - UnwrapArray(pBuffers, bindingCount), pOffsets, pSizes, pStrides); - } } return true; @@ -4325,44 +4071,28 @@ bool WrappedVulkan::Serialise_vkCmdBindIndexBuffer(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdBindIndexBuffer(Unwrap(commandBuffer), Unwrap(buffer), offset, indexType); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.ibuffer.buf = GetResID(buffer); - renderstate.ibuffer.offs = offset; - renderstate.ibuffer.size = VK_WHOLE_SIZE; + ObjDisp(commandBuffer)->CmdBindIndexBuffer(Unwrap(commandBuffer), Unwrap(buffer), offset, indexType); - if(indexType == VK_INDEX_TYPE_UINT32) - renderstate.ibuffer.bytewidth = 4; - else if(indexType == VK_INDEX_TYPE_UINT8) - renderstate.ibuffer.bytewidth = 1; - else - renderstate.ibuffer.bytewidth = 2; - } + { + VulkanRenderState &renderstate = GetCmdRenderState(); + renderstate.ibuffer.buf = GetResID(buffer); + renderstate.ibuffer.offs = offset; + renderstate.ibuffer.size = VK_WHOLE_SIZE; + + if(indexType == VK_INDEX_TYPE_UINT32) + renderstate.ibuffer.bytewidth = 4; + else if(indexType == VK_INDEX_TYPE_UINT8) + renderstate.ibuffer.bytewidth = 1; + else + renderstate.ibuffer.bytewidth = 2; } } - else - { - // track while reading, as we need to bind current topology & index byte width in AddAction - if(indexType == VK_INDEX_TYPE_UINT32) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.ibuffer.bytewidth = 4; - else if(indexType == VK_INDEX_TYPE_UINT8) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.ibuffer.bytewidth = 1; - else - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.ibuffer.bytewidth = 2; - - // track while reading, as we need to track resource usage - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.ibuffer.buf = GetResID(buffer); - - ObjDisp(commandBuffer)->CmdBindIndexBuffer(Unwrap(commandBuffer), Unwrap(buffer), offset, indexType); - } } return true; @@ -4413,34 +4143,28 @@ bool WrappedVulkan::Serialise_vkCmdPushConstants(SerialiserType &ser, VkCommandB { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdPushConstants(Unwrap(commandBuffer), Unwrap(layout), stageFlags, start, length, - values); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - RDCASSERT(start + length < (uint32_t)ARRAY_COUNT(renderstate.pushconsts)); + ObjDisp(commandBuffer) + ->CmdPushConstants(Unwrap(commandBuffer), Unwrap(layout), stageFlags, start, length, + values); + + { + VulkanRenderState &renderstate = GetCmdRenderState(); + RDCASSERT(start + length < (uint32_t)ARRAY_COUNT(renderstate.pushconsts)); - memcpy(renderstate.pushconsts + start, values, length); + memcpy(renderstate.pushconsts + start, values, length); - renderstate.pushConstSize = RDCMAX(renderstate.pushConstSize, start + length); - renderstate.pushLayout = GetResID(layout); + renderstate.pushConstSize = RDCMAX(renderstate.pushConstSize, start + length); + renderstate.pushLayout = GetResID(layout); - m_PushCommandBuffer = GetResourceManager()->GetUnreplacedID(m_LastCmdBufferID); - } + m_PushCommandBuffer = GetResourceManager()->GetUnreplacedID(m_LastCmdBufferID); } } - else - { - ObjDisp(commandBuffer) - ->CmdPushConstants(Unwrap(commandBuffer), Unwrap(layout), stageFlags, start, length, - values); - } } return true; @@ -4485,36 +4209,32 @@ bool WrappedVulkan::Serialise_vkCmdPushConstants2(SerialiserType &ser, VkCommand { m_LastCmdBufferID = GetResID(commandBuffer); - byte *tempMem = GetTempMemory(GetNextPatchSize(&PushConstantsInfo)); - VkPushConstantsInfo *unwrappedInfo = UnwrapStructAndChain(m_State, tempMem, &PushConstantsInfo); - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer)->CmdPushConstants2(Unwrap(commandBuffer), unwrappedInfo); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - RDCASSERT(PushConstantsInfo.offset + PushConstantsInfo.size < - (uint32_t)ARRAY_COUNT(renderstate.pushconsts)); + byte *tempMem = GetTempMemory(GetNextPatchSize(&PushConstantsInfo)); + VkPushConstantsInfo *unwrappedInfo = UnwrapStructAndChain(m_State, tempMem, &PushConstantsInfo); + + ObjDisp(commandBuffer)->CmdPushConstants2(Unwrap(commandBuffer), unwrappedInfo); - memcpy(renderstate.pushconsts + PushConstantsInfo.offset, PushConstantsInfo.pValues, - PushConstantsInfo.size); + { + VulkanRenderState &renderstate = GetCmdRenderState(); + RDCASSERT(PushConstantsInfo.offset + PushConstantsInfo.size < + (uint32_t)ARRAY_COUNT(renderstate.pushconsts)); - renderstate.pushConstSize = - RDCMAX(renderstate.pushConstSize, PushConstantsInfo.offset + PushConstantsInfo.size); - renderstate.pushLayout = GetResID(PushConstantsInfo.layout); + memcpy(renderstate.pushconsts + PushConstantsInfo.offset, PushConstantsInfo.pValues, + PushConstantsInfo.size); - m_PushCommandBuffer = GetResourceManager()->GetUnreplacedID(m_LastCmdBufferID); - } + renderstate.pushConstSize = + RDCMAX(renderstate.pushConstSize, PushConstantsInfo.offset + PushConstantsInfo.size); + renderstate.pushLayout = GetResID(PushConstantsInfo.layout); + + m_PushCommandBuffer = GetResourceManager()->GetUnreplacedID(m_LastCmdBufferID); } } - else - { - ObjDisp(commandBuffer)->CmdPushConstants2(Unwrap(commandBuffer), unwrappedInfo); - } } return true; @@ -4598,10 +4318,7 @@ bool WrappedVulkan::Serialise_vkCmdPipelineBarrier( bufBarriers.back().dstQueueFamilyIndex); if(IsLoading(m_State)) - { - m_LoadingEventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pBufferMemoryBarriers[i].buffer), ResourceUsage::Barrier)); - } + AddEventResourceUsage(GetResID(pBufferMemoryBarriers[i].buffer), ResourceUsage::Barrier); } } @@ -4616,10 +4333,7 @@ bool WrappedVulkan::Serialise_vkCmdPipelineBarrier( imgBarriers.back().dstQueueFamilyIndex); if(IsLoading(m_State)) - { - m_LoadingEventNode.resourceUsage.push_back( - make_rdcpair(GetResID(pImageMemoryBarriers[i].image), ResourceUsage::Barrier)); - } + AddEventResourceUsage(GetResID(pImageMemoryBarriers[i].image), ResourceUsage::Barrier); } } @@ -4639,10 +4353,7 @@ bool WrappedVulkan::Serialise_vkCmdPipelineBarrier( { VulkanCreationInfo::Image &imgInfo = m_CreationInfo.m_Image[GetResID(b.image)]; if(!imgInfo.external) - { - m_LoadingEventNode.resourceUsage.push_back( - make_rdcpair(GetResID(b.image), ResourceUsage::Discard)); - } + AddEventResourceUsage(GetResID(b.image), ResourceUsage::Discard); } } } @@ -4847,10 +4558,8 @@ bool WrappedVulkan::Serialise_vkCmdPipelineBarrier2(SerialiserType &ser, bufBarriers.back().dstQueueFamilyIndex); if(IsLoading(m_State)) - { - m_LoadingEventNode.resourceUsage.push_back(make_rdcpair( - GetResID(DependencyInfo.pBufferMemoryBarriers[i].buffer), ResourceUsage::Barrier)); - } + AddEventResourceUsage(GetResID(DependencyInfo.pBufferMemoryBarriers[i].buffer), + ResourceUsage::Barrier); } } @@ -4865,10 +4574,8 @@ bool WrappedVulkan::Serialise_vkCmdPipelineBarrier2(SerialiserType &ser, imgBarriers.back().dstQueueFamilyIndex); if(IsLoading(m_State)) - { - m_LoadingEventNode.resourceUsage.push_back(make_rdcpair( - GetResID(DependencyInfo.pImageMemoryBarriers[i].image), ResourceUsage::Barrier)); - } + AddEventResourceUsage(GetResID(DependencyInfo.pImageMemoryBarriers[i].image), + ResourceUsage::Barrier); } } @@ -4896,10 +4603,7 @@ bool WrappedVulkan::Serialise_vkCmdPipelineBarrier2(SerialiserType &ser, { VulkanCreationInfo::Image &imgInfo = m_CreationInfo.m_Image[GetResID(b.image)]; if(!imgInfo.external) - { - m_LoadingEventNode.resourceUsage.push_back( - make_rdcpair(GetResID(b.image), ResourceUsage::Discard)); - } + AddEventResourceUsage(GetResID(b.image), ResourceUsage::Discard); } } } @@ -5072,24 +4776,20 @@ bool WrappedVulkan::Serialise_vkCmdCopyQueryPoolResults( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - else - commandBuffer = VK_NULL_HANDLE; - } - VulkanCreationInfo::QueryPool &qpInfo = m_CreationInfo.m_QueryPool[GetResID(queryPool)]; + VulkanCreationInfo::QueryPool &qpInfo = m_CreationInfo.m_QueryPool[GetResID(queryPool)]; - // skip AS queries as we do not serialise them - if(qpInfo.queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR || - qpInfo.queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SIZE_KHR || - qpInfo.queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR || - qpInfo.queryType == - VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_BOTTOM_LEVEL_POINTERS_KHR) - { - if(commandBuffer != VK_NULL_HANDLE) + // skip AS queries as we do not serialise them + if(qpInfo.queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR || + qpInfo.queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SIZE_KHR || + qpInfo.queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR || + qpInfo.queryType == + VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_BOTTOM_LEVEL_POINTERS_KHR) { const bool is64bit = (flags & VK_QUERY_RESULT_64_BIT) > 0; const bool hasAvailability = (flags & VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) > 0; @@ -5102,13 +4802,10 @@ bool WrappedVulkan::Serialise_vkCmdCopyQueryPoolResults( ObjDisp(commandBuffer) ->CmdFillBuffer(Unwrap(commandBuffer), Unwrap(destBuffer), destOffset, size, 0); - } - return true; - } + return true; + } - if(commandBuffer != VK_NULL_HANDLE) - { ObjDisp(commandBuffer) ->CmdCopyQueryPoolResults(Unwrap(commandBuffer), Unwrap(queryPool), firstQuery, queryCount, Unwrap(destBuffer), destOffset, destStride, flags); @@ -5392,6 +5089,35 @@ void WrappedVulkan::UpdateRenderStateForSecondaries(BakedCmdBufferInfo &ancestor UpdateRenderStateForSecondaries(ancestorCB, m_BakedCmdBufferInfo[childCB]); } +void WrappedVulkan::ResetRenderStateForParent(BakedCmdBufferInfo &ancestorCB) +{ + // All state of the primary command buffer is undefined after executing a secondary command buffer + VulkanRenderState &state = ancestorCB.state; + + // Except: If the primary command buffer is inside a render pass instance, then the + // render pass and subpass state is not disturbed by executing secondary command buffers. + ResourceId rp = state.GetRenderPass(); + uint32_t subpass = state.subpass; + VkSubpassContents subpassContents = state.subpassContents; + ResourceId fb = state.GetFramebuffer(); + VkRect2D renderArea = state.renderArea; + rdcarray fbAtts = state.GetFramebufferAttachments(); + + state = VulkanRenderState(); + + state.SetRenderPass(rp); + state.subpass = subpass; + state.subpassContents = subpassContents; + state.renderArea = renderArea; + state.SetFramebuffer(fb, fbAtts); + + // Not Implemented + // Except: If the primary command buffer has a descriptor heap bound, and the address of that + // descriptor heap is specified in VkCommandBufferInheritanceDescriptorHeapInfoEXT for + // every secondary command buffer, that heap binding is not disturbed by executing + // secondary command buffers. +} + template bool WrappedVulkan::Serialise_vkCmdExecuteCommands(SerialiserType &ser, VkCommandBuffer commandBuffer, uint32_t commandBufferCount, @@ -5519,6 +5245,7 @@ bool WrappedVulkan::Serialise_vkCmdExecuteCommands(SerialiserType &ser, VkComman // because we don't have the extra popmarker event to 'absorb' the outer loop's // increment, and it incremented once too many for the last vkEndCommandBuffer // setmarker event in the loop over all commands + ResetRenderStateForParent(parentCmdBufInfo); } else { @@ -5687,6 +5414,7 @@ bool WrappedVulkan::Serialise_vkCmdExecuteCommands(SerialiserType &ser, VkComman ->CmdExecuteCommands(Unwrap(commandBuffer), (uint32_t)rerecordedCmds.size(), rerecordedCmds.data()); } + ResetRenderStateForParent(parentCmdBufInfo); } } } @@ -6106,75 +5834,45 @@ bool WrappedVulkan::Serialise_vkCmdPushDescriptorSet(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - ResourceId setId = - m_BakedCmdBufferInfo[m_LastCmdBufferID].GetPushDescriptorID(pipelineBindPoint, set); - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); - rdcarray &descsets = pipeline.descSets; - - // expand as necessary - if(descsets.size() < set + 1) - descsets.resize(set + 1); - - descsets[set] = VulkanStatePipeline::DescriptorAndOffsets(); - descsets[set].pipeLayout = GetResID(layout); - descsets[set].descSet = setId; - descsets[set].push = true; - ResourceId setLayout = - m_CreationInfo.m_PipelineLayout[GetResID(layout)].descSetLayouts[set]; - descsets[set].descBufferPush = - (m_CreationInfo.m_DescSetLayout[setLayout].flags & - VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT) != 0; - - if(descsets[set].descBufferPush) - { - pipeline.lastBoundDescSet = -1; - pipeline.lastBoundDescBufSet = set; - } - else - { - pipeline.lastBoundDescSet = set; - pipeline.lastBoundDescBufSet = -1; - } - } + ResourceId setId = + m_BakedCmdBufferInfo[m_LastCmdBufferID].GetPushDescriptorID(pipelineBindPoint, set); - // actual replay of the command will happen below - } - else { - commandBuffer = VK_NULL_HANDLE; - } - } - else - { - // track while reading, as we need to track resource usage - rdcarray &descsets = - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetPipeline(pipelineBindPoint).descSets; + VulkanRenderState &renderstate = GetCmdRenderState(); + VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); + rdcarray &descsets = pipeline.descSets; - // expand as necessary - if(descsets.size() < set + 1) - descsets.resize(set + 1); + // expand as necessary + if(descsets.size() < set + 1) + descsets.resize(set + 1); - // we use a 'special' ID for the push descriptor at this index, since there's no actual - // allocated object corresponding to it. - descsets[set] = VulkanStatePipeline::DescriptorAndOffsets(); - descsets[set].descSet = setId; - descsets[set].push = true; - ResourceId setLayout = m_CreationInfo.m_PipelineLayout[GetResID(layout)].descSetLayouts[set]; - descsets[set].descBufferPush = (m_CreationInfo.m_DescSetLayout[setLayout].flags & - VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT) != 0; - } + descsets[set] = VulkanStatePipeline::DescriptorAndOffsets(); + descsets[set].pipeLayout = GetResID(layout); + descsets[set].descSet = setId; + descsets[set].push = true; + ResourceId setLayout = m_CreationInfo.m_PipelineLayout[GetResID(layout)].descSetLayouts[set]; + descsets[set].descBufferPush = + (m_CreationInfo.m_DescSetLayout[setLayout].flags & + VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT) != 0; + + if(descsets[set].descBufferPush) + { + pipeline.lastBoundDescSet = -1; + pipeline.lastBoundDescBufSet = set; + } + else + { + pipeline.lastBoundDescSet = set; + pipeline.lastBoundDescBufSet = -1; + } + } - if(commandBuffer != VK_NULL_HANDLE) - { // since we version push descriptors per-command buffer, we can safely update them always // without worrying about overlap. We just need to check that we're in the record range so // that we don't pull in descriptor updates after the point in the command buffer we're @@ -6398,77 +6096,47 @@ bool WrappedVulkan::Serialise_vkCmdPushDescriptorSetWithTemplate( { m_LastCmdBufferID = GetResID(commandBuffer); - VkPipelineBindPoint bindPoint = - m_CreationInfo.m_DescUpdateTemplate[GetResID(descriptorUpdateTemplate)].bindPoint; - - ResourceId setId = m_BakedCmdBufferInfo[m_LastCmdBufferID].GetPushDescriptorID(bindPoint, set); - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - VulkanStatePipeline &pipeline = renderstate.GetPipeline(bindPoint); - rdcarray &descsets = pipeline.descSets; + VkPipelineBindPoint bindPoint = + m_CreationInfo.m_DescUpdateTemplate[GetResID(descriptorUpdateTemplate)].bindPoint; - // expand as necessary - if(descsets.size() < set + 1) - descsets.resize(set + 1); - - descsets[set] = VulkanStatePipeline::DescriptorAndOffsets(); - descsets[set].pipeLayout = GetResID(layout); - descsets[set].descSet = setId; - descsets[set].push = true; - ResourceId setLayout = - m_CreationInfo.m_PipelineLayout[GetResID(layout)].descSetLayouts[set]; - descsets[set].descBufferPush = - (m_CreationInfo.m_DescSetLayout[setLayout].flags & - VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT) != 0; - - if(descsets[set].descBufferPush) - { - pipeline.lastBoundDescSet = -1; - pipeline.lastBoundDescBufSet = set; - } - else - { - pipeline.lastBoundDescSet = set; - pipeline.lastBoundDescBufSet = -1; - } - } + ResourceId setId = m_BakedCmdBufferInfo[m_LastCmdBufferID].GetPushDescriptorID(bindPoint, set); - // actual replay of the command will happen below - } - else { - commandBuffer = VK_NULL_HANDLE; - } - } - else - { - // track while reading, as we need to track resource usage - rdcarray &descsets = - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetPipeline(bindPoint).descSets; + VulkanRenderState &renderstate = GetCmdRenderState(); + VulkanStatePipeline &pipeline = renderstate.GetPipeline(bindPoint); + rdcarray &descsets = pipeline.descSets; - // expand as necessary - if(descsets.size() < set + 1) - descsets.resize(set + 1); + // expand as necessary + if(descsets.size() < set + 1) + descsets.resize(set + 1); - // we use a 'special' ID for the push descriptor at this index, since there's no actual - // allocated object corresponding to it. - descsets[set] = VulkanStatePipeline::DescriptorAndOffsets(); - descsets[set].descSet = setId; - descsets[set].push = true; - ResourceId setLayout = m_CreationInfo.m_PipelineLayout[GetResID(layout)].descSetLayouts[set]; - descsets[set].descBufferPush = (m_CreationInfo.m_DescSetLayout[setLayout].flags & - VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT) != 0; - } + descsets[set] = VulkanStatePipeline::DescriptorAndOffsets(); + descsets[set].pipeLayout = GetResID(layout); + descsets[set].descSet = setId; + descsets[set].push = true; + ResourceId setLayout = m_CreationInfo.m_PipelineLayout[GetResID(layout)].descSetLayouts[set]; + descsets[set].descBufferPush = + (m_CreationInfo.m_DescSetLayout[setLayout].flags & + VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT) != 0; + + if(descsets[set].descBufferPush) + { + pipeline.lastBoundDescSet = -1; + pipeline.lastBoundDescBufSet = set; + } + else + { + pipeline.lastBoundDescSet = set; + pipeline.lastBoundDescBufSet = -1; + } + } - if(commandBuffer != VK_NULL_HANDLE) - { // since we version push descriptors per-command buffer, we can safely update them always // without worrying about overlap. We just need to check that we're in the record range so // that we don't pull in descriptor updates after the point in the command buffer we're @@ -6942,43 +6610,28 @@ bool WrappedVulkan::Serialise_vkCmdBindTransformFeedbackBuffersEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdBindTransformFeedbackBuffersEXT(Unwrap(commandBuffer), firstBinding, bindingCount, - UnwrapArray(pBuffers, bindingCount), pOffsets, - pSizes); - - { - VulkanRenderState &renderstate = GetCmdRenderState(); - if(renderstate.xfbbuffers.size() < firstBinding + bindingCount) - renderstate.xfbbuffers.resize(firstBinding + bindingCount); - - for(uint32_t i = 0; i < bindingCount; i++) - { - renderstate.xfbbuffers[firstBinding + i].buf = GetResID(pBuffers[i]); - renderstate.xfbbuffers[firstBinding + i].offs = pOffsets[i]; - renderstate.xfbbuffers[firstBinding + i].size = pSizes ? pSizes[i] : VK_WHOLE_SIZE; - } - } - } - } - else - { - // track while reading, as we need to track resource usage - if(m_BakedCmdBufferInfo[m_LastCmdBufferID].state.xfbbuffers.size() < firstBinding + bindingCount) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.xfbbuffers.resize(firstBinding + bindingCount); - - for(uint32_t i = 0; i < bindingCount; i++) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.xfbbuffers[firstBinding + i].buf = - GetResID(pBuffers[i]); ObjDisp(commandBuffer) ->CmdBindTransformFeedbackBuffersEXT(Unwrap(commandBuffer), firstBinding, bindingCount, UnwrapArray(pBuffers, bindingCount), pOffsets, pSizes); + + { + VulkanRenderState &renderstate = GetCmdRenderState(); + if(renderstate.xfbbuffers.size() < firstBinding + bindingCount) + renderstate.xfbbuffers.resize(firstBinding + bindingCount); + + for(uint32_t i = 0; i < bindingCount; i++) + { + renderstate.xfbbuffers[firstBinding + i].buf = GetResID(pBuffers[i]); + renderstate.xfbbuffers[firstBinding + i].offs = pOffsets[i]; + renderstate.xfbbuffers[firstBinding + i].size = pSizes ? pSizes[i] : VK_WHOLE_SIZE; + } + } } } @@ -7041,41 +6694,29 @@ bool WrappedVulkan::Serialise_vkCmdBeginTransformFeedbackEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.firstxfbcounter = firstBuffer; - renderstate.xfbcounters.resize(bufferCount); + { + VulkanRenderState &renderstate = GetCmdRenderState(); + renderstate.firstxfbcounter = firstBuffer; + renderstate.xfbcounters.resize(bufferCount); - for(uint32_t i = 0; i < bufferCount; i++) - { - renderstate.xfbcounters[i].buf = - pCounterBuffers ? GetResID(pCounterBuffers[i]) : ResourceId(); - renderstate.xfbcounters[i].offs = pCounterBufferOffsets ? pCounterBufferOffsets[i] : 0; - } + for(uint32_t i = 0; i < bufferCount; i++) + { + ResourceId buf = pCounterBuffers ? GetResID(pCounterBuffers[i]) : ResourceId(); + renderstate.xfbcounters[i].buf = buf; + renderstate.xfbcounters[i].offs = pCounterBufferOffsets ? pCounterBufferOffsets[i] : 0; } - - ObjDisp(commandBuffer) - ->CmdBeginTransformFeedbackEXT(Unwrap(commandBuffer), firstBuffer, bufferCount, - UnwrapArray(pCounterBuffers, bufferCount), - pCounterBufferOffsets); } - } - else - { + ObjDisp(commandBuffer) ->CmdBeginTransformFeedbackEXT(Unwrap(commandBuffer), firstBuffer, bufferCount, UnwrapArray(pCounterBuffers, bufferCount), pCounterBufferOffsets); - - // track while reading, for fetching the right set of outputs in AddAction - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.firstxfbcounter = firstBuffer; - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.xfbcounters.resize(bufferCount); } } @@ -7136,34 +6777,22 @@ bool WrappedVulkan::Serialise_vkCmdEndTransformFeedbackEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.firstxfbcounter = 0; - renderstate.xfbcounters.clear(); - } - - ObjDisp(commandBuffer) - ->CmdEndTransformFeedbackEXT(Unwrap(commandBuffer), firstBuffer, bufferCount, - UnwrapArray(pCounterBuffers, bufferCount), - pCounterBufferOffsets); + { + VulkanRenderState &renderstate = GetCmdRenderState(); + renderstate.firstxfbcounter = 0; + renderstate.xfbcounters.clear(); } - } - else - { + ObjDisp(commandBuffer) ->CmdEndTransformFeedbackEXT(Unwrap(commandBuffer), firstBuffer, bufferCount, UnwrapArray(pCounterBuffers, bufferCount), pCounterBufferOffsets); - - // track while reading, for fetching the right set of outputs in AddAction - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.firstxfbcounter = 0; - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.xfbcounters.clear(); } } @@ -7341,25 +6970,19 @@ bool WrappedVulkan::Serialise_vkCmdBeginConditionalRenderingEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.conditionalRendering.buffer = GetResID(BeginInfo.buffer); - renderstate.conditionalRendering.offset = BeginInfo.offset; - renderstate.conditionalRendering.flags = BeginInfo.flags; - } - - BeginInfo.buffer = Unwrap(BeginInfo.buffer); - ObjDisp(commandBuffer)->CmdBeginConditionalRenderingEXT(Unwrap(commandBuffer), &BeginInfo); + { + VulkanRenderState &renderstate = GetCmdRenderState(); + renderstate.conditionalRendering.buffer = GetResID(BeginInfo.buffer); + renderstate.conditionalRendering.offset = BeginInfo.offset; + renderstate.conditionalRendering.flags = BeginInfo.flags; } - } - else - { + BeginInfo.buffer = Unwrap(BeginInfo.buffer); ObjDisp(commandBuffer)->CmdBeginConditionalRenderingEXT(Unwrap(commandBuffer), &BeginInfo); } @@ -7413,22 +7036,17 @@ bool WrappedVulkan::Serialise_vkCmdEndConditionalRenderingEXT(SerialiserType &se { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.conditionalRendering.buffer = ResourceId(); - } - - ObjDisp(commandBuffer)->CmdEndConditionalRenderingEXT(Unwrap(commandBuffer)); + { + VulkanRenderState &renderstate = GetCmdRenderState(); + renderstate.conditionalRendering.buffer = ResourceId(); } - } - else - { + ObjDisp(commandBuffer)->CmdEndConditionalRenderingEXT(Unwrap(commandBuffer)); } } @@ -7476,44 +7094,36 @@ bool WrappedVulkan::Serialise_vkCmdSetVertexInputEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdSetVertexInputEXT(Unwrap(commandBuffer), vertexBindingDescriptionCount, - pVertexBindingDescriptions, vertexAttributeDescriptionCount, - pVertexAttributeDescriptions); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + ObjDisp(commandBuffer) + ->CmdSetVertexInputEXT(Unwrap(commandBuffer), vertexBindingDescriptionCount, + pVertexBindingDescriptions, vertexAttributeDescriptionCount, + pVertexAttributeDescriptions); + + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicVertexInputEXT] = true; + renderstate.dynamicStates[VkDynamicVertexInputEXT] = true; - renderstate.vertexBindings.assign(pVertexBindingDescriptions, - vertexBindingDescriptionCount); - renderstate.vertexAttributes.assign(pVertexAttributeDescriptions, - vertexAttributeDescriptionCount); + renderstate.vertexBindings.assign(pVertexBindingDescriptions, vertexBindingDescriptionCount); + renderstate.vertexAttributes.assign(pVertexAttributeDescriptions, + vertexAttributeDescriptionCount); - for(uint32_t i = 0; i < vertexBindingDescriptionCount; i++) - { - // set strides whether or not the vertex buffers have been bound, so that the stride is - // available if a later call to BindVertexBuffers2 doesn't pass any strides (it should - // use the strides from here) - renderstate.vbuffers.resize_for_index(i); - renderstate.vbuffers[i].stride = pVertexBindingDescriptions[i].stride; - } + for(uint32_t i = 0; i < vertexBindingDescriptionCount; i++) + { + // set strides whether or not the vertex buffers have been bound, so that the stride is + // available if a later call to BindVertexBuffers2 doesn't pass any strides (it should + // use the strides from here) + renderstate.vbuffers.resize_for_index(i); + renderstate.vbuffers[i].stride = pVertexBindingDescriptions[i].stride; } } } - else - { - ObjDisp(commandBuffer) - ->CmdSetVertexInputEXT(Unwrap(commandBuffer), vertexBindingDescriptionCount, - pVertexBindingDescriptions, vertexAttributeDescriptionCount, - pVertexAttributeDescriptions); - } } return true; @@ -7563,240 +7173,32 @@ bool WrappedVulkan::Serialise_vkCmdBeginRendering(SerialiserType &ser, VkCommand { m_LastCmdBufferID = GetResID(commandBuffer); - byte *tempMem = GetTempMemory(GetNextPatchSize(&RenderingInfo)); - VkRenderingInfo *unwrappedInfo = UnwrapStructAndChain(m_State, tempMem, &RenderingInfo); - - // do not replay with suspend/resume, explicitly load and store everything. - unwrappedInfo->flags &= ~(VK_RENDERING_SUSPENDING_BIT | VK_RENDERING_RESUMING_BIT); - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - // only if we're partially recording do we update this state - if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, true)) - { - GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = - m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = true; - GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassSuspended = false; - } - m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass = 0; - - VulkanRenderState &renderstate = GetCmdRenderState(); - - { - renderstate.subpass = 0; - renderstate.SetRenderPass(ResourceId()); - renderstate.renderArea = RenderingInfo.renderArea; - renderstate.dynamicRendering = VulkanRenderState::DynamicRendering(); - renderstate.dynamicRendering.active = true; - renderstate.dynamicRendering.suspended = false; - renderstate.dynamicRendering.flags = RenderingInfo.flags; - renderstate.dynamicRendering.layerCount = RenderingInfo.layerCount; - renderstate.dynamicRendering.viewMask = RenderingInfo.viewMask; - renderstate.dynamicRendering.color.assign(RenderingInfo.pColorAttachments, - RenderingInfo.colorAttachmentCount); - if(RenderingInfo.pDepthAttachment) - renderstate.dynamicRendering.depth = *RenderingInfo.pDepthAttachment; - if(RenderingInfo.pStencilAttachment) - renderstate.dynamicRendering.stencil = *RenderingInfo.pStencilAttachment; - - renderstate.dynamicRendering.CopyAttachmentNexts(); - - renderstate.fragmentDensityMapOffsets.clear(); - - const VkRenderingFragmentDensityMapAttachmentInfoEXT *fragmentDensityAttachment = - (const VkRenderingFragmentDensityMapAttachmentInfoEXT *)FindNextStruct( - &RenderingInfo, - VK_STRUCTURE_TYPE_RENDERING_FRAGMENT_DENSITY_MAP_ATTACHMENT_INFO_EXT); - - if(fragmentDensityAttachment) - { - renderstate.dynamicRendering.fragmentDensityView = fragmentDensityAttachment->imageView; - renderstate.dynamicRendering.fragmentDensityLayout = - fragmentDensityAttachment->imageLayout; - } - - const VkRenderingFragmentShadingRateAttachmentInfoKHR *shadingRateAttachment = - (const VkRenderingFragmentShadingRateAttachmentInfoKHR *)FindNextStruct( - &RenderingInfo, - VK_STRUCTURE_TYPE_RENDERING_FRAGMENT_SHADING_RATE_ATTACHMENT_INFO_KHR); - - if(shadingRateAttachment) - { - renderstate.dynamicRendering.shadingRateView = shadingRateAttachment->imageView; - renderstate.dynamicRendering.shadingRateLayout = shadingRateAttachment->imageLayout; - renderstate.dynamicRendering.shadingRateTexelSize = - shadingRateAttachment->shadingRateAttachmentTexelSize; - } - - const VkMultisampledRenderToSingleSampledInfoEXT *tileOnlyMSAA = - (const VkMultisampledRenderToSingleSampledInfoEXT *)FindNextStruct( - &RenderingInfo, VK_STRUCTURE_TYPE_MULTISAMPLED_RENDER_TO_SINGLE_SAMPLED_INFO_EXT); - - if(tileOnlyMSAA) - { - renderstate.dynamicRendering.tileOnlyMSAAEnable = - tileOnlyMSAA->multisampledRenderToSingleSampledEnable != VK_FALSE; - renderstate.dynamicRendering.tileOnlyMSAASampleCount = tileOnlyMSAA->rasterizationSamples; - } - - renderstate.dynamicRendering.beginCustomResolve = false; - - rdcarray attachments; - - for(size_t i = 0; i < renderstate.dynamicRendering.color.size(); i++) - attachments.push_back(GetResID(renderstate.dynamicRendering.color[i].imageView)); + byte *tempMem = GetTempMemory(GetNextPatchSize(&RenderingInfo)); + VkRenderingInfo *unwrappedInfo = UnwrapStructAndChain(m_State, tempMem, &RenderingInfo); - attachments.push_back(GetResID(renderstate.dynamicRendering.depth.imageView)); - attachments.push_back(GetResID(renderstate.dynamicRendering.stencil.imageView)); + // do not replay with suspend/resume, explicitly load and store everything. + unwrappedInfo->flags &= ~(VK_RENDERING_SUSPENDING_BIT | VK_RENDERING_RESUMING_BIT); - renderstate.SetFramebuffer(ResourceId(), attachments); - } - - // only do discards when not resuming! - if(m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest && - (RenderingInfo.flags & VK_RENDERING_RESUMING_BIT) == 0) - { - rdcarray dynAtts = renderstate.dynamicRendering.color; - - size_t depthIdx = ~0U; - size_t stencilIdx = ~0U; - VkImageAspectFlags depthAspects = VK_IMAGE_ASPECT_DEPTH_BIT; - - if(renderstate.dynamicRendering.depth.imageView != VK_NULL_HANDLE) - { - dynAtts.push_back(renderstate.dynamicRendering.depth); - depthIdx = dynAtts.size() - 1; - } - - // if we have different images attached, or different store ops, treat stencil separately - if(renderstate.dynamicRendering.depth.imageView != VK_NULL_HANDLE && - renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE && - (renderstate.dynamicRendering.depth.imageView != - renderstate.dynamicRendering.stencil.imageView || - renderstate.dynamicRendering.depth.loadOp != - renderstate.dynamicRendering.stencil.loadOp)) - { - dynAtts.push_back(renderstate.dynamicRendering.stencil); - stencilIdx = dynAtts.size() - 1; - } - // otherwise if the same image is bound and the storeOp is the same then include it - else if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE) - { - depthAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; - - if(renderstate.dynamicRendering.depth.imageView == VK_NULL_HANDLE) - { - dynAtts.push_back(renderstate.dynamicRendering.stencil); - stencilIdx = dynAtts.size() - 1; - } - } - - for(size_t i = 0; i < dynAtts.size(); i++) - { - // Color target - if(dynAtts[i].imageView != VK_NULL_HANDLE) - { - const VulkanCreationInfo::ImageView &viewInfo = - m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)]; - VkImage image = GetResourceManager()->GetHandle(viewInfo.image); - - if(dynAtts[i].loadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE) - { - VkImageSubresourceRange range = viewInfo.range; - - if(i == depthIdx) - range.aspectMask = depthAspects; - - // if this is a stencil-only attachment this will override depthAspects - if(i == stencilIdx) - range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; - - GetDebugManager()->FillWithDiscardPattern(commandBuffer, DiscardType::RenderPassLoad, - image, dynAtts[i].imageLayout, range, - renderstate.renderArea); - } - } - // Custom Resolve target - if(dynAtts[i].resolveMode & VK_RESOLVE_MODE_CUSTOM_BIT_EXT) - { - const VulkanCreationInfo::ImageView &viewInfo = - m_CreationInfo.m_ImageView[GetResID(dynAtts[i].resolveImageView)]; - VkImage image = GetResourceManager()->GetHandle(viewInfo.image); - VkImageSubresourceRange range = viewInfo.range; - GetDebugManager()->FillWithDiscardPattern(commandBuffer, DiscardType::RenderPassLoad, - image, dynAtts[i].resolveImageLayout, range, - renderstate.renderArea); - } - } - } - - ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::BeginPass; - uint32_t eventId = HandlePreCallback(commandBuffer, drawFlags); - - // do the same load/store op patching that we do for regular renderpass creates to enable - // introspection. It doesn't matter that we don't do this before during load because the - // effects of that are never user-visible. - // we must do this when resuming/suspending to ensure we promote to load/store - if(m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest || - (RenderingInfo.flags & (VK_RENDERING_SUSPENDING_BIT | VK_RENDERING_RESUMING_BIT))) - { - if(Vulkan_Hack_DisableRPNormalisation()) - { - static bool warned = false; - - if(!warned) - RDCWARN("RP attachment normalisation not applied!"); - - warned = true; - } - else - { - for(uint32_t i = 0; i < unwrappedInfo->colorAttachmentCount + 2; i++) - { - VkRenderingAttachmentInfo *att = - (VkRenderingAttachmentInfo *)unwrappedInfo->pColorAttachments + i; - - if(i == unwrappedInfo->colorAttachmentCount) - att = (VkRenderingAttachmentInfo *)unwrappedInfo->pDepthAttachment; - else if(i == unwrappedInfo->colorAttachmentCount + 1) - att = (VkRenderingAttachmentInfo *)unwrappedInfo->pStencilAttachment; - - if(!att) - continue; - - if(att->storeOp != VK_ATTACHMENT_STORE_OP_NONE) - att->storeOp = VK_ATTACHMENT_STORE_OP_STORE; - - if(att->loadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE) - att->loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; - - // if this is supposed to be resuming, don't apply any clears! - if(RenderingInfo.flags & VK_RENDERING_RESUMING_BIT) - att->loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; - } - } - } - - ObjDisp(commandBuffer)->CmdBeginRendering(Unwrap(commandBuffer), unwrappedInfo); - - if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) - { - // Do not call vkCmdBeginRendering again. - m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); - } + // only if we're partially recording do we update this state + if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, true)) + { + GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = + m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = true; + GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassSuspended = false; } - } - else - { - ObjDisp(commandBuffer)->CmdBeginRendering(Unwrap(commandBuffer), unwrappedInfo); + m_BakedCmdBufferInfo[m_LastCmdBufferID].activeSubpass = 0; - VulkanRenderState &renderstate = m_BakedCmdBufferInfo[m_LastCmdBufferID].state; + VulkanRenderState &renderstate = GetCmdRenderState(); { + renderstate.subpass = 0; + renderstate.SetRenderPass(ResourceId()); renderstate.renderArea = RenderingInfo.renderArea; renderstate.dynamicRendering = VulkanRenderState::DynamicRendering(); renderstate.dynamicRendering.active = true; @@ -7813,6 +7215,8 @@ bool WrappedVulkan::Serialise_vkCmdBeginRendering(SerialiserType &ser, VkCommand renderstate.dynamicRendering.CopyAttachmentNexts(); + renderstate.fragmentDensityMapOffsets.clear(); + const VkRenderingFragmentDensityMapAttachmentInfoEXT *fragmentDensityAttachment = (const VkRenderingFragmentDensityMapAttachmentInfoEXT *)FindNextStruct( &RenderingInfo, VK_STRUCTURE_TYPE_RENDERING_FRAGMENT_DENSITY_MAP_ATTACHMENT_INFO_EXT); @@ -7852,47 +7256,178 @@ bool WrappedVulkan::Serialise_vkCmdBeginRendering(SerialiserType &ser, VkCommand rdcarray attachments; for(size_t i = 0; i < renderstate.dynamicRendering.color.size(); i++) - attachments.push_back( - m_CreationInfo.m_ImageView[GetResID(renderstate.dynamicRendering.color[i].imageView)].image); + attachments.push_back(GetResID(renderstate.dynamicRendering.color[i].imageView)); - attachments.push_back( - m_CreationInfo.m_ImageView[GetResID(renderstate.dynamicRendering.depth.imageView)].image); - attachments.push_back( - m_CreationInfo.m_ImageView[GetResID(renderstate.dynamicRendering.stencil.imageView)].image); + attachments.push_back(GetResID(renderstate.dynamicRendering.depth.imageView)); + attachments.push_back(GetResID(renderstate.dynamicRendering.stencil.imageView)); renderstate.SetFramebuffer(ResourceId(), attachments); } - for(size_t i = 0; i < renderstate.dynamicRendering.color.size() + 2; i++) + // only do discards when not resuming! + if(!loading && m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest && + (RenderingInfo.flags & VK_RENDERING_RESUMING_BIT) == 0) { - const VkRenderingAttachmentInfo *att = - (const VkRenderingAttachmentInfo *)&renderstate.dynamicRendering.color[i]; + rdcarray dynAtts = renderstate.dynamicRendering.color; - if(i == renderstate.dynamicRendering.color.size()) - att = (const VkRenderingAttachmentInfo *)&renderstate.dynamicRendering.depth; - else if(i == renderstate.dynamicRendering.color.size() + 1) - att = (const VkRenderingAttachmentInfo *)&renderstate.dynamicRendering.stencil; + size_t depthIdx = ~0U; + size_t stencilIdx = ~0U; + VkImageAspectFlags depthAspects = VK_IMAGE_ASPECT_DEPTH_BIT; - if(!att || att->imageView == VK_NULL_HANDLE) - continue; + if(renderstate.dynamicRendering.depth.imageView != VK_NULL_HANDLE) + { + dynAtts.push_back(renderstate.dynamicRendering.depth); + depthIdx = dynAtts.size() - 1; + } + + // if we have different images attached, or different store ops, treat stencil separately + if(renderstate.dynamicRendering.depth.imageView != VK_NULL_HANDLE && + renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE && + (renderstate.dynamicRendering.depth.imageView != + renderstate.dynamicRendering.stencil.imageView || + renderstate.dynamicRendering.depth.loadOp != renderstate.dynamicRendering.stencil.loadOp)) + { + dynAtts.push_back(renderstate.dynamicRendering.stencil); + stencilIdx = dynAtts.size() - 1; + } + // otherwise if the same image is bound and the storeOp is the same then include it + else if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE) + { + depthAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; + + if(renderstate.dynamicRendering.depth.imageView == VK_NULL_HANDLE) + { + dynAtts.push_back(renderstate.dynamicRendering.stencil); + stencilIdx = dynAtts.size() - 1; + } + } + + for(size_t i = 0; i < dynAtts.size(); i++) + { + // Color target + if(dynAtts[i].imageView != VK_NULL_HANDLE) + { + const VulkanCreationInfo::ImageView &viewInfo = + m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)]; + VkImage image = GetResourceManager()->GetHandle(viewInfo.image); + + if(dynAtts[i].loadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE) + { + VkImageSubresourceRange range = viewInfo.range; + + if(i == depthIdx) + range.aspectMask = depthAspects; + + // if this is a stencil-only attachment this will override depthAspects + if(i == stencilIdx) + range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; + + GetDebugManager()->FillWithDiscardPattern(commandBuffer, DiscardType::RenderPassLoad, + image, dynAtts[i].imageLayout, range, + renderstate.renderArea); + } + } + // Custom Resolve target + if(dynAtts[i].resolveMode & VK_RESOLVE_MODE_CUSTOM_BIT_EXT) + { + const VulkanCreationInfo::ImageView &viewInfo = + m_CreationInfo.m_ImageView[GetResID(dynAtts[i].resolveImageView)]; + VkImage image = GetResourceManager()->GetHandle(viewInfo.image); + VkImageSubresourceRange range = viewInfo.range; + GetDebugManager()->FillWithDiscardPattern(commandBuffer, DiscardType::RenderPassLoad, + image, dynAtts[i].resolveImageLayout, range, + renderstate.renderArea); + } + } + } + + ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::BeginPass; + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, drawFlags) : 0; + + // do the same load/store op patching that we do for regular renderpass creates to enable + // introspection. It doesn't matter that we don't do this before during load because the + // effects of that are never user-visible. + // we must do this when resuming/suspending to ensure we promote to load/store + if(!loading && + (m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest || + (RenderingInfo.flags & (VK_RENDERING_SUSPENDING_BIT | VK_RENDERING_RESUMING_BIT)))) + { + if(Vulkan_Hack_DisableRPNormalisation()) + { + static bool warned = false; + + if(!warned) + RDCWARN("RP attachment normalisation not applied!"); - if(att->loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR || - att->loadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE) + warned = true; + } + else { - ResourceId image = m_CreationInfo.m_ImageView[GetResID(att->imageView)].image; - m_LoadingEventNode.resourceUsage.push_back(make_rdcpair( - image, att->loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR ? ResourceUsage::Clear - : ResourceUsage::Discard)); + for(uint32_t i = 0; i < unwrappedInfo->colorAttachmentCount + 2; i++) + { + VkRenderingAttachmentInfo *att = + (VkRenderingAttachmentInfo *)unwrappedInfo->pColorAttachments + i; + + if(i == unwrappedInfo->colorAttachmentCount) + att = (VkRenderingAttachmentInfo *)unwrappedInfo->pDepthAttachment; + else if(i == unwrappedInfo->colorAttachmentCount + 1) + att = (VkRenderingAttachmentInfo *)unwrappedInfo->pStencilAttachment; + + if(!att) + continue; + + if(att->storeOp != VK_ATTACHMENT_STORE_OP_NONE) + att->storeOp = VK_ATTACHMENT_STORE_OP_STORE; + + if(att->loadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE) + att->loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; + + // if this is supposed to be resuming, don't apply any clears! + if(RenderingInfo.flags & VK_RENDERING_RESUMING_BIT) + att->loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; + } } } - AddEvent(); - ActionDescription action; - action.customName = - StringFormat::Fmt("vkCmdBeginRendering(%s)", MakeRenderPassOpString(false).c_str()); - action.flags |= ActionFlags::PassBoundary | ActionFlags::BeginPass; + ObjDisp(commandBuffer)->CmdBeginRendering(Unwrap(commandBuffer), unwrappedInfo); - AddAction(action); + if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) + { + // Do not call vkCmdBeginRendering again. + m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); + } + + if(loading) + { + for(size_t i = 0; i < renderstate.dynamicRendering.color.size() + 2; i++) + { + const VkRenderingAttachmentInfo *att = + (const VkRenderingAttachmentInfo *)&renderstate.dynamicRendering.color[i]; + + if(i == renderstate.dynamicRendering.color.size()) + att = (const VkRenderingAttachmentInfo *)&renderstate.dynamicRendering.depth; + else if(i == renderstate.dynamicRendering.color.size() + 1) + att = (const VkRenderingAttachmentInfo *)&renderstate.dynamicRendering.stencil; + + if(!att || att->imageView == VK_NULL_HANDLE) + continue; + + if(att->loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR || + att->loadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE) + AddEventResourceUsage(m_CreationInfo.m_ImageView[GetResID(att->imageView)].image, + att->loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR + ? ResourceUsage::Clear + : ResourceUsage::Discard); + } + + AddEvent(); + ActionDescription action; + action.customName = + StringFormat::Fmt("vkCmdBeginRendering(%s)", MakeRenderPassOpString(false).c_str()); + action.flags |= ActionFlags::PassBoundary | ActionFlags::BeginPass; + + AddAction(action); + } } } @@ -8005,232 +7540,213 @@ bool WrappedVulkan::Serialise_vkCmdEndRendering(SerialiserType &ser, VkCommandBu { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) - { - VulkanRenderState &renderstate = GetCmdRenderState(); + VulkanRenderState &renderstate = GetCmdRenderState(); - bool suspending = (renderstate.dynamicRendering.flags & VK_RENDERING_SUSPENDING_BIT) != 0; + bool suspending = (renderstate.dynamicRendering.flags & VK_RENDERING_SUSPENDING_BIT) != 0; - if(InRerecordRange(m_LastCmdBufferID)) - { + if(InRerecordRange(m_LastCmdBufferID)) + { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, true)) - { - m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; - - if(IsCommandBufferPartial(m_LastCmdBufferID)) - { - // if this rendering is just being suspended, the pass is still active - if(!suspending) - GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = false; - GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassSuspended = suspending; - } - } - - ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::EndPass; - uint32_t eventId = HandlePreCallback(commandBuffer, drawFlags); - - ObjDisp(commandBuffer)->CmdEndRendering(Unwrap(commandBuffer)); - - if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) - { - // Do not call vkCmdEndRendering again. - m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); - } - - // only do discards when not suspending! - if(m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest && !suspending) - { - rdcarray dynAtts = renderstate.dynamicRendering.color; - dynAtts.push_back(renderstate.dynamicRendering.depth); - - size_t depthIdx = dynAtts.size() - 1; - size_t stencilIdx = ~0U; - VkImageAspectFlags depthAspects = VK_IMAGE_ASPECT_DEPTH_BIT; - - // if we have different images attached, or different store ops, treat stencil separately - if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE && - (renderstate.dynamicRendering.depth.imageView != - renderstate.dynamicRendering.stencil.imageView || - renderstate.dynamicRendering.depth.storeOp != - renderstate.dynamicRendering.stencil.storeOp)) - { - dynAtts.push_back(renderstate.dynamicRendering.stencil); - stencilIdx = dynAtts.size() - 1; - } - // otherwise if the same image is bound and the storeOp is the same then include it - else if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE) - { - depthAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; - } - - for(size_t i = 0; i < dynAtts.size(); i++) - { - if(dynAtts[i].imageView == VK_NULL_HANDLE) - continue; - - const VulkanCreationInfo::ImageView &viewInfo = - m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)]; - VkImage image = GetResourceManager()->GetHandle(viewInfo.image); - - if(dynAtts[i].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE) - { - VkImageSubresourceRange range = viewInfo.range; - - if(i == depthIdx) - range.aspectMask = depthAspects; - - if(i == stencilIdx) - range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; - - GetDebugManager()->FillWithDiscardPattern(commandBuffer, DiscardType::RenderPassStore, - image, dynAtts[i].imageLayout, range, - renderstate.renderArea); - } - } - } + if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, true)) + { + m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; - if(suspending) - { - renderstate.dynamicRendering.suspended = true; - } - else + if(IsCommandBufferPartial(m_LastCmdBufferID)) { - renderstate.dynamicRendering = VulkanRenderState::DynamicRendering(); - renderstate.SetFramebuffer(ResourceId(), rdcarray()); + // if this rendering is just being suspended, the pass is still active + if(!suspending) + GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = false; + GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassSuspended = suspending; } } - else if(IsRenderpassOpen(m_LastCmdBufferID)) + + ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::EndPass; + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, drawFlags) : 0; + + ObjDisp(commandBuffer)->CmdEndRendering(Unwrap(commandBuffer)); + + if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) { - commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer)->CmdEndRendering(Unwrap(commandBuffer)); + // Do not call vkCmdEndRendering again. + m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); + } - m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; + // only do discards when not suspending! + if(!loading && m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest && !suspending) + { + rdcarray dynAtts = renderstate.dynamicRendering.color; + dynAtts.push_back(renderstate.dynamicRendering.depth); + + size_t depthIdx = dynAtts.size() - 1; + size_t stencilIdx = ~0U; + VkImageAspectFlags depthAspects = VK_IMAGE_ASPECT_DEPTH_BIT; - // only do discards when not suspending! - if(Vulkan_Hack_DisableRPNormalisation() && !suspending) + // if we have different images attached, or different store ops, treat stencil separately + if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE && + (renderstate.dynamicRendering.depth.imageView != + renderstate.dynamicRendering.stencil.imageView || + renderstate.dynamicRendering.depth.storeOp != + renderstate.dynamicRendering.stencil.storeOp)) { - rdcarray dynAtts = renderstate.dynamicRendering.color; - dynAtts.push_back(renderstate.dynamicRendering.depth); + dynAtts.push_back(renderstate.dynamicRendering.stencil); + stencilIdx = dynAtts.size() - 1; + } + // otherwise if the same image is bound and the storeOp is the same then include it + else if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE) + { + depthAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; + } - size_t depthIdx = dynAtts.size() - 1; - size_t stencilIdx = ~0U; - VkImageAspectFlags depthAspects = VK_IMAGE_ASPECT_DEPTH_BIT; + for(size_t i = 0; i < dynAtts.size(); i++) + { + if(dynAtts[i].imageView == VK_NULL_HANDLE) + continue; - // if we have different images attached, or different store ops, treat stencil separately - if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE && - (renderstate.dynamicRendering.depth.imageView != - renderstate.dynamicRendering.stencil.imageView || - renderstate.dynamicRendering.depth.storeOp != - renderstate.dynamicRendering.stencil.storeOp)) - { - dynAtts.push_back(renderstate.dynamicRendering.stencil); - stencilIdx = dynAtts.size() - 1; - } - // otherwise if the same image is bound and the storeOp is the same then include it - else if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE) - { - depthAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; - } + const VulkanCreationInfo::ImageView &viewInfo = + m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)]; + VkImage image = GetResourceManager()->GetHandle(viewInfo.image); - for(size_t i = 0; i < dynAtts.size(); i++) + if(dynAtts[i].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE) { - if(dynAtts[i].imageView == VK_NULL_HANDLE) - continue; - - const VulkanCreationInfo::ImageView &viewInfo = - m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)]; - VkImage image = GetResourceManager()->GetHandle(viewInfo.image); - - if(dynAtts[i].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE) - { - VkImageSubresourceRange range = viewInfo.range; + VkImageSubresourceRange range = viewInfo.range; - if(i == depthIdx) - range.aspectMask = depthAspects; + if(i == depthIdx) + range.aspectMask = depthAspects; - if(i == stencilIdx) - range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; + if(i == stencilIdx) + range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; - GetDebugManager()->FillWithDiscardPattern(commandBuffer, DiscardType::RenderPassStore, - image, VK_IMAGE_LAYOUT_UNDEFINED, range, - renderstate.renderArea); - } + GetDebugManager()->FillWithDiscardPattern(commandBuffer, DiscardType::RenderPassStore, + image, dynAtts[i].imageLayout, range, + renderstate.renderArea); } } } - } - else - { - ObjDisp(commandBuffer)->CmdEndRendering(Unwrap(commandBuffer)); - // fetch any queued indirect readbacks here - for(const VkIndirectRecordData &indirectcopy : - m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies) - ExecuteIndirectReadback(commandBuffer, indirectcopy); + if(loading) + { + // fetch any queued indirect readbacks here + for(const VkIndirectRecordData &indirectcopy : + m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies) + ExecuteIndirectReadback(commandBuffer, indirectcopy); + + // and deferred descriptor buffer versions here + for(const BakedCmdBufferInfo::DeferredDescBufCopy &descVersion : + m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies) + CopyVersionedDescriptorBuffer(commandBuffer, descVersion.unwrappedDstBuffer, + descVersion.copyOffsets); - // and deferred descriptor buffer versions here - for(const BakedCmdBufferInfo::DeferredDescBufCopy &descVersion : - m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies) - CopyVersionedDescriptorBuffer(commandBuffer, descVersion.unwrappedDstBuffer, - descVersion.copyOffsets); + m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies.clear(); + m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies.clear(); - m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies.clear(); - m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies.clear(); + const VulkanRenderState::DynamicRendering &dyn = renderstate.dynamicRendering; - VulkanRenderState &state = m_BakedCmdBufferInfo[m_LastCmdBufferID].state; + rdcarray dynAtts = dyn.color; + dynAtts.push_back(dyn.depth); - rdcarray> &usage = m_LoadingEventNode.resourceUsage; + // if stencil attachment is different, or only one is resolving, add the stencil attachment. + // Otherwise depth will cover both (at most) + if((dyn.depth.imageView != dyn.stencil.imageView) || + (dyn.depth.resolveMode != 0) != (dyn.stencil.resolveMode != 0)) + dynAtts.push_back(dyn.stencil); - VulkanRenderState::DynamicRendering &dyn = state.dynamicRendering; + for(size_t i = 0; i < dynAtts.size(); i++) + { + if((dynAtts[i].resolveMode && !(dynAtts[i].resolveMode & VK_RESOLVE_MODE_CUSTOM_BIT_EXT)) && + dynAtts[i].imageView != VK_NULL_HANDLE && dynAtts[i].resolveImageView != VK_NULL_HANDLE) + { + AddEventResourceUsage(m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)].image, + ResourceUsage::ResolveSrc); - bool suspending = (dyn.flags & VK_RENDERING_SUSPENDING_BIT) != 0; + AddEventResourceUsage( + m_CreationInfo.m_ImageView[GetResID(dynAtts[i].resolveImageView)].image, + ResourceUsage::ResolveDst); + } - rdcarray dynAtts = dyn.color; - dynAtts.push_back(dyn.depth); + // also add any discards + if(dynAtts[i].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE) + AddEventResourceUsage(m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)].image, + ResourceUsage::Discard); + } - // if stencil attachment is different, or only one is resolving, add the stencil attachment. - // Otherwise depth will cover both (at most) - if((dyn.depth.imageView != dyn.stencil.imageView) || - (dyn.depth.resolveMode != 0) != (dyn.stencil.resolveMode != 0)) - dynAtts.push_back(dyn.stencil); + AddEvent(); + ActionDescription action; + action.customName = + StringFormat::Fmt("vkCmdEndRendering(%s)", MakeRenderPassOpString(true).c_str()); + action.flags |= ActionFlags::PassBoundary | ActionFlags::EndPass; - for(size_t i = 0; i < dynAtts.size(); i++) + AddAction(action); + } + if(suspending) { - if((dynAtts[i].resolveMode && !(dynAtts[i].resolveMode & VK_RESOLVE_MODE_CUSTOM_BIT_EXT)) && - dynAtts[i].imageView != VK_NULL_HANDLE && dynAtts[i].resolveImageView != VK_NULL_HANDLE) - { - usage.push_back(make_rdcpair(m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)].image, - ResourceUsage::ResolveSrc)); + renderstate.dynamicRendering.suspended = true; + } + else + { + renderstate.dynamicRendering = VulkanRenderState::DynamicRendering(); + renderstate.SetFramebuffer(ResourceId(), rdcarray()); + } + } + else if(IsRenderpassOpen(m_LastCmdBufferID)) + { + commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); + ObjDisp(commandBuffer)->CmdEndRendering(Unwrap(commandBuffer)); - usage.push_back( - make_rdcpair(m_CreationInfo.m_ImageView[GetResID(dynAtts[i].resolveImageView)].image, - ResourceUsage::ResolveDst)); - } + m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; + + // only do discards when not suspending! + if(Vulkan_Hack_DisableRPNormalisation() && !suspending) + { + rdcarray dynAtts = renderstate.dynamicRendering.color; + dynAtts.push_back(renderstate.dynamicRendering.depth); + + size_t depthIdx = dynAtts.size() - 1; + size_t stencilIdx = ~0U; + VkImageAspectFlags depthAspects = VK_IMAGE_ASPECT_DEPTH_BIT; - // also add any discards - if(dynAtts[i].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE) + // if we have different images attached, or different store ops, treat stencil separately + if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE && + (renderstate.dynamicRendering.depth.imageView != + renderstate.dynamicRendering.stencil.imageView || + renderstate.dynamicRendering.depth.storeOp != + renderstate.dynamicRendering.stencil.storeOp)) { - usage.push_back(make_rdcpair(m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)].image, - ResourceUsage::Discard)); + dynAtts.push_back(renderstate.dynamicRendering.stencil); + stencilIdx = dynAtts.size() - 1; + } + // otherwise if the same image is bound and the storeOp is the same then include it + else if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE) + { + depthAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; } - } - AddEvent(); - ActionDescription action; - action.customName = - StringFormat::Fmt("vkCmdEndRendering(%s)", MakeRenderPassOpString(true).c_str()); - action.flags |= ActionFlags::PassBoundary | ActionFlags::EndPass; + for(size_t i = 0; i < dynAtts.size(); i++) + { + if(dynAtts[i].imageView == VK_NULL_HANDLE) + continue; - AddAction(action); + const VulkanCreationInfo::ImageView &viewInfo = + m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)]; + VkImage image = GetResourceManager()->GetHandle(viewInfo.image); - if(!suspending) - { - // track while reading, reset this to empty so AddAction sets no outputs, - // but only AFTER the above AddAction (we want it grouped together) - state.dynamicRendering = VulkanRenderState::DynamicRendering(); - state.SetFramebuffer(ResourceId(), rdcarray()); + if(dynAtts[i].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE) + { + VkImageSubresourceRange range = viewInfo.range; + + if(i == depthIdx) + range.aspectMask = depthAspects; + + if(i == stencilIdx) + range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; + + GetDebugManager()->FillWithDiscardPattern(commandBuffer, DiscardType::RenderPassStore, + image, VK_IMAGE_LAYOUT_UNDEFINED, range, + renderstate.renderArea); + } + } } } } @@ -8276,247 +7792,228 @@ bool WrappedVulkan::Serialise_vkCmdEndRendering2EXT(SerialiserType &ser, UnwrapStructAndChain(m_State, tempMem, pRenderingEndInfo); m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) - { - VulkanRenderState &renderstate = GetCmdRenderState(); + VulkanRenderState &renderstate = GetCmdRenderState(); - bool suspending = (renderstate.dynamicRendering.flags & VK_RENDERING_SUSPENDING_BIT) != 0; + bool suspending = (renderstate.dynamicRendering.flags & VK_RENDERING_SUSPENDING_BIT) != 0; - if(InRerecordRange(m_LastCmdBufferID)) - { + if(InRerecordRange(m_LastCmdBufferID)) + { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, true)) - { - m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; + if(ShouldUpdateRenderpassActive(m_LastCmdBufferID, true)) + { + m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; - if(IsCommandBufferPartial(m_LastCmdBufferID)) - { - // if this rendering is just being suspended, the pass is still active - if(!suspending) - GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = false; - GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassSuspended = suspending; - } + if(IsCommandBufferPartial(m_LastCmdBufferID)) + { + // if this rendering is just being suspended, the pass is still active + if(!suspending) + GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassActive = false; + GetCommandBufferPartialSubmission(m_LastCmdBufferID)->renderPassSuspended = suspending; } + } - ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::EndPass; - uint32_t eventId = HandlePreCallback(commandBuffer, drawFlags); + ActionFlags drawFlags = ActionFlags::PassBoundary | ActionFlags::EndPass; + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, drawFlags) : 0; - ObjDisp(commandBuffer)->CmdEndRendering2EXT(Unwrap(commandBuffer), unwrappedEndInfo); + ObjDisp(commandBuffer)->CmdEndRendering2EXT(Unwrap(commandBuffer), unwrappedEndInfo); + + if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) + { + // Do not call vkCmdEndRendering2EXT again. + m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); + } - if(eventId && m_ActionCallback->PostMisc(eventId, drawFlags, commandBuffer)) + // only do discards when not suspending! + if(!loading && m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest && !suspending) + { + rdcarray dynAtts = renderstate.dynamicRendering.color; + dynAtts.push_back(renderstate.dynamicRendering.depth); + + size_t depthIdx = dynAtts.size() - 1; + size_t stencilIdx = ~0U; + VkImageAspectFlags depthAspects = VK_IMAGE_ASPECT_DEPTH_BIT; + + // if we have different images attached, or different store ops, treat stencil separately + if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE && + (renderstate.dynamicRendering.depth.imageView != + renderstate.dynamicRendering.stencil.imageView || + renderstate.dynamicRendering.depth.storeOp != + renderstate.dynamicRendering.stencil.storeOp)) { - // Do not call vkCmdEndRendering2EXT again. - m_ActionCallback->PostRemisc(eventId, drawFlags, commandBuffer); + dynAtts.push_back(renderstate.dynamicRendering.stencil); + stencilIdx = dynAtts.size() - 1; } - - // only do discards when not suspending! - if(m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest && !suspending) + // otherwise if the same image is bound and the storeOp is the same then include it + else if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE) { - rdcarray dynAtts = renderstate.dynamicRendering.color; - dynAtts.push_back(renderstate.dynamicRendering.depth); + depthAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; + } - size_t depthIdx = dynAtts.size() - 1; - size_t stencilIdx = ~0U; - VkImageAspectFlags depthAspects = VK_IMAGE_ASPECT_DEPTH_BIT; + for(size_t i = 0; i < dynAtts.size(); i++) + { + if(dynAtts[i].imageView == VK_NULL_HANDLE) + continue; - // if we have different images attached, or different store ops, treat stencil separately - if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE && - (renderstate.dynamicRendering.depth.imageView != - renderstate.dynamicRendering.stencil.imageView || - renderstate.dynamicRendering.depth.storeOp != - renderstate.dynamicRendering.stencil.storeOp)) - { - dynAtts.push_back(renderstate.dynamicRendering.stencil); - stencilIdx = dynAtts.size() - 1; - } - // otherwise if the same image is bound and the storeOp is the same then include it - else if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE) - { - depthAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; - } + const VulkanCreationInfo::ImageView &viewInfo = + m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)]; + VkImage image = GetResourceManager()->GetHandle(viewInfo.image); - for(size_t i = 0; i < dynAtts.size(); i++) + if(dynAtts[i].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE) { - if(dynAtts[i].imageView == VK_NULL_HANDLE) - continue; - - const VulkanCreationInfo::ImageView &viewInfo = - m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)]; - VkImage image = GetResourceManager()->GetHandle(viewInfo.image); - - if(dynAtts[i].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE) - { - VkImageSubresourceRange range = viewInfo.range; + VkImageSubresourceRange range = viewInfo.range; - if(i == depthIdx) - range.aspectMask = depthAspects; + if(i == depthIdx) + range.aspectMask = depthAspects; - if(i == stencilIdx) - range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; + if(i == stencilIdx) + range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; - GetDebugManager()->FillWithDiscardPattern(commandBuffer, DiscardType::RenderPassStore, - image, dynAtts[i].imageLayout, range, - renderstate.renderArea); - } + GetDebugManager()->FillWithDiscardPattern(commandBuffer, DiscardType::RenderPassStore, + image, dynAtts[i].imageLayout, range, + renderstate.renderArea); } } - - if(suspending) - { - renderstate.dynamicRendering.suspended = true; - } - else - { - renderstate.dynamicRendering = VulkanRenderState::DynamicRendering(); - renderstate.SetFramebuffer(ResourceId(), rdcarray()); - } } - else if(IsRenderpassOpen(m_LastCmdBufferID)) - { - commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer)->CmdEndRendering2EXT(Unwrap(commandBuffer), unwrappedEndInfo); - m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; + if(loading) + { + // fetch any queued indirect readbacks here + for(const VkIndirectRecordData &indirectcopy : + m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies) + ExecuteIndirectReadback(commandBuffer, indirectcopy); - const VkRenderPassFragmentDensityMapOffsetEndInfoEXT *fragmentDensityOffsetStruct = - (const VkRenderPassFragmentDensityMapOffsetEndInfoEXT *)FindNextStruct( - unwrappedEndInfo, - VK_STRUCTURE_TYPE_RENDER_PASS_FRAGMENT_DENSITY_MAP_OFFSET_END_INFO_EXT); + // and deferred descriptor buffer versions here + for(const BakedCmdBufferInfo::DeferredDescBufCopy &descVersion : + m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies) + CopyVersionedDescriptorBuffer(commandBuffer, descVersion.unwrappedDstBuffer, + descVersion.copyOffsets); - if(fragmentDensityOffsetStruct) - { - rdcarray &stateOffsets = GetCmdRenderState().fragmentDensityMapOffsets; - stateOffsets.resize(fragmentDensityOffsetStruct->fragmentDensityOffsetCount); - for(uint32_t i = 0; i < fragmentDensityOffsetStruct->fragmentDensityOffsetCount; i++) - { - stateOffsets[i] = fragmentDensityOffsetStruct->pFragmentDensityOffsets[i]; - } - } + m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies.clear(); + m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies.clear(); - // only do discards when not suspending! - if(Vulkan_Hack_DisableRPNormalisation() && !suspending) - { - rdcarray dynAtts = renderstate.dynamicRendering.color; - dynAtts.push_back(renderstate.dynamicRendering.depth); + const VulkanRenderState::DynamicRendering &dyn = renderstate.dynamicRendering; - size_t depthIdx = dynAtts.size() - 1; - size_t stencilIdx = ~0U; - VkImageAspectFlags depthAspects = VK_IMAGE_ASPECT_DEPTH_BIT; + rdcarray dynAtts = dyn.color; + dynAtts.push_back(dyn.depth); - // if we have different images attached, or different store ops, treat stencil separately - if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE && - (renderstate.dynamicRendering.depth.imageView != - renderstate.dynamicRendering.stencil.imageView || - renderstate.dynamicRendering.depth.storeOp != - renderstate.dynamicRendering.stencil.storeOp)) - { - dynAtts.push_back(renderstate.dynamicRendering.stencil); - stencilIdx = dynAtts.size() - 1; - } - // otherwise if the same image is bound and the storeOp is the same then include it - else if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE) - { - depthAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; - } + // if stencil attachment is different, or only one is resolving, add the stencil + // attachment. Otherwise depth will cover both (at most) + if((dyn.depth.imageView != dyn.stencil.imageView) || + (dyn.depth.resolveMode != 0) != (dyn.stencil.resolveMode != 0)) + dynAtts.push_back(dyn.stencil); - for(size_t i = 0; i < dynAtts.size(); i++) + for(size_t i = 0; i < dynAtts.size(); i++) + { + if((dynAtts[i].resolveMode && !(dynAtts[i].resolveMode & VK_RESOLVE_MODE_CUSTOM_BIT_EXT)) && + dynAtts[i].imageView != VK_NULL_HANDLE && dynAtts[i].resolveImageView != VK_NULL_HANDLE) { - if(dynAtts[i].imageView == VK_NULL_HANDLE) - continue; + AddEventResourceUsage(m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)].image, + ResourceUsage::ResolveSrc); - const VulkanCreationInfo::ImageView &viewInfo = - m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)]; - VkImage image = GetResourceManager()->GetHandle(viewInfo.image); - - if(dynAtts[i].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE) - { - VkImageSubresourceRange range = viewInfo.range; + AddEventResourceUsage( + m_CreationInfo.m_ImageView[GetResID(dynAtts[i].resolveImageView)].image, + ResourceUsage::ResolveDst); + } - if(i == depthIdx) - range.aspectMask = depthAspects; + // also add any discards + if(dynAtts[i].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE) + AddEventResourceUsage(m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)].image, + ResourceUsage::Discard); + } - if(i == stencilIdx) - range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; + AddEvent(); + ActionDescription action; + action.customName = + StringFormat::Fmt("vkCmdEndRendering2EXT(%s)", MakeRenderPassOpString(true).c_str()); + action.flags |= ActionFlags::PassBoundary | ActionFlags::EndPass; - GetDebugManager()->FillWithDiscardPattern(commandBuffer, DiscardType::RenderPassStore, - image, VK_IMAGE_LAYOUT_UNDEFINED, range, - renderstate.renderArea); - } - } - } + AddAction(action); + } + if(suspending) + { + renderstate.dynamicRendering.suspended = true; + } + else + { + renderstate.dynamicRendering = VulkanRenderState::DynamicRendering(); + renderstate.SetFramebuffer(ResourceId(), rdcarray()); } } - else + else if(IsRenderpassOpen(m_LastCmdBufferID)) { + commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); ObjDisp(commandBuffer)->CmdEndRendering2EXT(Unwrap(commandBuffer), unwrappedEndInfo); - // fetch any queued indirect readbacks here - for(const VkIndirectRecordData &indirectcopy : - m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies) - ExecuteIndirectReadback(commandBuffer, indirectcopy); + m_BakedCmdBufferInfo[m_LastCmdBufferID].renderPassOpen = false; - // and deferred descriptor buffer versions here - for(const BakedCmdBufferInfo::DeferredDescBufCopy &descVersion : - m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies) - CopyVersionedDescriptorBuffer(commandBuffer, descVersion.unwrappedDstBuffer, - descVersion.copyOffsets); + const VkRenderPassFragmentDensityMapOffsetEndInfoEXT *fragmentDensityOffsetStruct = + (const VkRenderPassFragmentDensityMapOffsetEndInfoEXT *)FindNextStruct( + unwrappedEndInfo, + VK_STRUCTURE_TYPE_RENDER_PASS_FRAGMENT_DENSITY_MAP_OFFSET_END_INFO_EXT); - m_BakedCmdBufferInfo[m_LastCmdBufferID].indirectCopies.clear(); - m_BakedCmdBufferInfo[m_LastCmdBufferID].descBufDeferredCopies.clear(); - - VulkanRenderState &state = m_BakedCmdBufferInfo[m_LastCmdBufferID].state; - - rdcarray> &usage = m_LoadingEventNode.resourceUsage; - - VulkanRenderState::DynamicRendering &dyn = state.dynamicRendering; - - bool suspending = (dyn.flags & VK_RENDERING_SUSPENDING_BIT) != 0; + if(fragmentDensityOffsetStruct) + { + rdcarray &stateOffsets = GetCmdRenderState().fragmentDensityMapOffsets; + stateOffsets.resize(fragmentDensityOffsetStruct->fragmentDensityOffsetCount); + for(uint32_t i = 0; i < fragmentDensityOffsetStruct->fragmentDensityOffsetCount; i++) + { + stateOffsets[i] = fragmentDensityOffsetStruct->pFragmentDensityOffsets[i]; + } + } - rdcarray dynAtts = dyn.color; - dynAtts.push_back(dyn.depth); + // only do discards when not suspending! + if(Vulkan_Hack_DisableRPNormalisation() && !suspending) + { + rdcarray dynAtts = renderstate.dynamicRendering.color; + dynAtts.push_back(renderstate.dynamicRendering.depth); - // if stencil attachment is different, or only one is resolving, add the stencil attachment. - // Otherwise depth will cover both (at most) - if((dyn.depth.imageView != dyn.stencil.imageView) || - (dyn.depth.resolveMode != 0) != (dyn.stencil.resolveMode != 0)) - dynAtts.push_back(dyn.stencil); + size_t depthIdx = dynAtts.size() - 1; + size_t stencilIdx = ~0U; + VkImageAspectFlags depthAspects = VK_IMAGE_ASPECT_DEPTH_BIT; - for(size_t i = 0; i < dynAtts.size(); i++) - { - if((dynAtts[i].resolveMode && !(dynAtts[i].resolveMode & VK_RESOLVE_MODE_CUSTOM_BIT_EXT)) && - dynAtts[i].imageView != VK_NULL_HANDLE && dynAtts[i].resolveImageView != VK_NULL_HANDLE) + // if we have different images attached, or different store ops, treat stencil separately + if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE && + (renderstate.dynamicRendering.depth.imageView != + renderstate.dynamicRendering.stencil.imageView || + renderstate.dynamicRendering.depth.storeOp != + renderstate.dynamicRendering.stencil.storeOp)) { - usage.push_back(make_rdcpair(m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)].image, - ResourceUsage::ResolveSrc)); - - usage.push_back( - make_rdcpair(m_CreationInfo.m_ImageView[GetResID(dynAtts[i].resolveImageView)].image, - ResourceUsage::ResolveDst)); + dynAtts.push_back(renderstate.dynamicRendering.stencil); + stencilIdx = dynAtts.size() - 1; } - - // also add any discards - if(dynAtts[i].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE) + // otherwise if the same image is bound and the storeOp is the same then include it + else if(renderstate.dynamicRendering.stencil.imageView != VK_NULL_HANDLE) { - usage.push_back(make_rdcpair(m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)].image, - ResourceUsage::Discard)); + depthAspects |= VK_IMAGE_ASPECT_STENCIL_BIT; } - } - AddEvent(); - ActionDescription action; - action.customName = - StringFormat::Fmt("vkCmdEndRendering2EXT(%s)", MakeRenderPassOpString(true).c_str()); - action.flags |= ActionFlags::PassBoundary | ActionFlags::EndPass; + for(size_t i = 0; i < dynAtts.size(); i++) + { + if(dynAtts[i].imageView == VK_NULL_HANDLE) + continue; - AddAction(action); + const VulkanCreationInfo::ImageView &viewInfo = + m_CreationInfo.m_ImageView[GetResID(dynAtts[i].imageView)]; + VkImage image = GetResourceManager()->GetHandle(viewInfo.image); - if(!suspending) - { - // track while reading, reset this to empty so AddAction sets no outputs, - // but only AFTER the above AddAction (we want it grouped together) - state.dynamicRendering = VulkanRenderState::DynamicRendering(); - state.SetFramebuffer(ResourceId(), rdcarray()); + if(dynAtts[i].storeOp == VK_ATTACHMENT_STORE_OP_DONT_CARE) + { + VkImageSubresourceRange range = viewInfo.range; + + if(i == depthIdx) + range.aspectMask = depthAspects; + + if(i == stencilIdx) + range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; + + GetDebugManager()->FillWithDiscardPattern(commandBuffer, DiscardType::RenderPassStore, + image, VK_IMAGE_LAYOUT_UNDEFINED, range, + renderstate.renderArea); + } + } } } } @@ -8586,37 +8083,55 @@ bool WrappedVulkan::Serialise_vkCmdBuildAccelerationStructuresIndirectKHR( if(IsReplayingAndReading()) { - size_t tempmemSize = sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; - for(uint32_t i = 0; i < infoCount; ++i) - tempmemSize += GetNextPatchSize(&pInfos[i]); + m_LastCmdBufferID = GetResID(commandBuffer); - byte *memory = GetTempMemory(tempmemSize); - VkAccelerationStructureBuildGeometryInfoKHR *unwrappedInfos = - (VkAccelerationStructureBuildGeometryInfoKHR *)memory; - memory += sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; + if(InRerecordRange(m_LastCmdBufferID)) + { + bool loading = IsLoading(m_State); + if(!loading) + commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - for(uint32_t i = 0; i < infoCount; ++i) - unwrappedInfos[i] = *UnwrapStructAndChain(m_State, memory, &pInfos[i]); + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, ActionFlags::BuildAccStruct) : 0; - // Convert the maxPrimitives back to a C-style array-of-arrays - rdcarray tmpMaxPrimitiveCounts(NULL, infoCount); - for(uint32_t i = 0; i < infoCount; ++i) - tmpMaxPrimitiveCounts[i] = maxPrimitives[i].data(); + size_t tempmemSize = sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; + for(uint32_t i = 0; i < infoCount; ++i) + tempmemSize += GetNextPatchSize(&pInfos[i]); - m_LastCmdBufferID = GetResID(commandBuffer); + byte *memory = GetTempMemory(tempmemSize); + VkAccelerationStructureBuildGeometryInfoKHR *unwrappedInfos = + (VkAccelerationStructureBuildGeometryInfoKHR *)memory; + memory += sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; - if(IsActiveReplaying(m_State)) - { - if(InRerecordRange(m_LastCmdBufferID)) - commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - else - return true; - } + for(uint32_t i = 0; i < infoCount; ++i) + unwrappedInfos[i] = *UnwrapStructAndChain(m_State, memory, &pInfos[i]); + + // Convert the maxPrimitives back to a C-style array-of-arrays + rdcarray tmpMaxPrimitiveCounts(NULL, infoCount); + for(uint32_t i = 0; i < infoCount; ++i) + tmpMaxPrimitiveCounts[i] = maxPrimitives[i].data(); + + ObjDisp(commandBuffer) + ->CmdBuildAccelerationStructuresIndirectKHR( + Unwrap(commandBuffer), infoCount, unwrappedInfos, pIndirectDeviceAddresses, + pIndirectStrides, tmpMaxPrimitiveCounts.data()); - ObjDisp(commandBuffer) - ->CmdBuildAccelerationStructuresIndirectKHR(Unwrap(commandBuffer), infoCount, - unwrappedInfos, pIndirectDeviceAddresses, - pIndirectStrides, tmpMaxPrimitiveCounts.data()); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::BuildAccStruct, commandBuffer)) + { + ObjDisp(commandBuffer) + ->CmdBuildAccelerationStructuresIndirectKHR( + Unwrap(commandBuffer), infoCount, unwrappedInfos, pIndirectDeviceAddresses, + pIndirectStrides, tmpMaxPrimitiveCounts.data()); + m_ActionCallback->PostRemisc(eventId, ActionFlags::BuildAccStruct, commandBuffer); + } + + if(loading) + { + AddEvent(); + ActionDescription action; + action.flags = ActionFlags::BuildAccStruct; + AddAction(action); + } + } } return true; @@ -8702,57 +8217,53 @@ bool WrappedVulkan::Serialise_vkCmdBuildAccelerationStructuresKHR( if(IsReplayingAndReading()) { - size_t tempmemSize = sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; - for(uint32_t i = 0; i < infoCount; ++i) - tempmemSize += GetNextPatchSize(&pInfos[i]); - - byte *memory = GetTempMemory(tempmemSize); - VkAccelerationStructureBuildGeometryInfoKHR *unwrappedInfos = - (VkAccelerationStructureBuildGeometryInfoKHR *)memory; - memory += sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; - - for(uint32_t i = 0; i < infoCount; ++i) - unwrappedInfos[i] = *UnwrapStructAndChain(m_State, memory, &pInfos[i]); - - // Convert the rangeInfos back to a C-style array-of-arrays - rdcarray tmpBuildRangeInfos; - tmpBuildRangeInfos.resize(infoCount); - for(uint32_t i = 0; i < infoCount; ++i) - tmpBuildRangeInfos[i] = rangeInfos[i].data(); - m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::BuildAccStruct); + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, ActionFlags::BuildAccStruct) : 0; - ObjDisp(commandBuffer) - ->CmdBuildAccelerationStructuresKHR(Unwrap(commandBuffer), infoCount, unwrappedInfos, - tmpBuildRangeInfos.data()); + size_t tempmemSize = sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; + for(uint32_t i = 0; i < infoCount; ++i) + tempmemSize += GetNextPatchSize(&pInfos[i]); + + byte *memory = GetTempMemory(tempmemSize); + VkAccelerationStructureBuildGeometryInfoKHR *unwrappedInfos = + (VkAccelerationStructureBuildGeometryInfoKHR *)memory; + memory += sizeof(VkAccelerationStructureBuildGeometryInfoKHR) * infoCount; + + for(uint32_t i = 0; i < infoCount; ++i) + unwrappedInfos[i] = *UnwrapStructAndChain(m_State, memory, &pInfos[i]); + + // Convert the rangeInfos back to a C-style array-of-arrays + rdcarray tmpBuildRangeInfos; + tmpBuildRangeInfos.resize(infoCount); + for(uint32_t i = 0; i < infoCount; ++i) + tmpBuildRangeInfos[i] = rangeInfos[i].data(); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::BuildAccStruct, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdBuildAccelerationStructuresKHR(Unwrap(commandBuffer), infoCount, unwrappedInfos, - tmpBuildRangeInfos.data()); - m_ActionCallback->PostRemisc(eventId, ActionFlags::BuildAccStruct, commandBuffer); - } - } - } - else - { ObjDisp(commandBuffer) ->CmdBuildAccelerationStructuresKHR(Unwrap(commandBuffer), infoCount, unwrappedInfos, tmpBuildRangeInfos.data()); - AddEvent(); - ActionDescription action; - action.flags = ActionFlags::BuildAccStruct; - AddAction(action); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::BuildAccStruct, commandBuffer)) + { + ObjDisp(commandBuffer) + ->CmdBuildAccelerationStructuresKHR(Unwrap(commandBuffer), infoCount, unwrappedInfos, + tmpBuildRangeInfos.data()); + m_ActionCallback->PostRemisc(eventId, ActionFlags::BuildAccStruct, commandBuffer); + } + + if(loading) + { + AddEvent(); + ActionDescription action; + action.flags = ActionFlags::BuildAccStruct; + AddAction(action); + } } } @@ -8830,38 +8341,36 @@ bool WrappedVulkan::Serialise_vkCmdCopyAccelerationStructureKHR( if(IsReplayingAndReading()) { - VkCopyAccelerationStructureInfoKHR unwrappedInfo = Info; - unwrappedInfo.src = Unwrap(unwrappedInfo.src); - unwrappedInfo.dst = Unwrap(unwrappedInfo.dst); - m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::BuildAccStruct); + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, ActionFlags::BuildAccStruct) : 0; - ObjDisp(commandBuffer)->CmdCopyAccelerationStructureKHR(Unwrap(commandBuffer), &unwrappedInfo); + VkCopyAccelerationStructureInfoKHR unwrappedInfo = Info; + unwrappedInfo.src = Unwrap(unwrappedInfo.src); + unwrappedInfo.dst = Unwrap(unwrappedInfo.dst); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::BuildAccStruct, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdCopyAccelerationStructureKHR(Unwrap(commandBuffer), &unwrappedInfo); + ObjDisp(commandBuffer)->CmdCopyAccelerationStructureKHR(Unwrap(commandBuffer), &unwrappedInfo); - m_ActionCallback->PostRemisc(eventId, ActionFlags::BuildAccStruct, commandBuffer); - } + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::BuildAccStruct, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdCopyAccelerationStructureKHR(Unwrap(commandBuffer), &unwrappedInfo); + + m_ActionCallback->PostRemisc(eventId, ActionFlags::BuildAccStruct, commandBuffer); } - } - else - { - ObjDisp(commandBuffer)->CmdCopyAccelerationStructureKHR(Unwrap(commandBuffer), &unwrappedInfo); - AddEvent(); - ActionDescription action; - action.flags = ActionFlags::BuildAccStruct; - AddAction(action); + if(loading) + { + AddEvent(); + ActionDescription action; + action.flags = ActionFlags::BuildAccStruct; + AddAction(action); + } } } @@ -8937,29 +8446,27 @@ bool WrappedVulkan::Serialise_vkCmdCopyMemoryToAccelerationStructureKHR( if(IsReplayingAndReading()) { - VkCopyMemoryToAccelerationStructureInfoKHR unwrappedInfo = Info; - unwrappedInfo.dst = Unwrap(unwrappedInfo.dst); - m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdCopyMemoryToAccelerationStructureKHR(Unwrap(commandBuffer), &unwrappedInfo); - } - } - else - { + + VkCopyMemoryToAccelerationStructureInfoKHR unwrappedInfo = Info; + unwrappedInfo.dst = Unwrap(unwrappedInfo.dst); + ObjDisp(commandBuffer) ->CmdCopyMemoryToAccelerationStructureKHR(Unwrap(commandBuffer), &unwrappedInfo); - AddEvent(); - ActionDescription action; - action.flags = ActionFlags::BuildAccStruct; - AddAction(action); + if(loading) + { + AddEvent(); + ActionDescription action; + action.flags = ActionFlags::BuildAccStruct; + AddAction(action); + } } } @@ -9120,69 +8627,42 @@ bool WrappedVulkan::Serialise_vkCmdBindShadersEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - for(uint32_t i = 0; i < stageCount; i++) - { - int stageIndex = StageIndex(pStages[i]); + for(uint32_t i = 0; i < stageCount; i++) + { + int stageIndex = StageIndex(pStages[i]); + ResourceId shader = + pShaders && (pShaders[i] != VK_NULL_HANDLE) ? GetResID(pShaders[i]) : ResourceId(); - renderstate.shaderObjects[stageIndex] = - pShaders && (pShaders[i] != VK_NULL_HANDLE) ? GetResID(pShaders[i]) : ResourceId(); + renderstate.shaderObjects[stageIndex] = shader; - // calling vkCmdBindShadersEXT disturbs the corresponding pipeline bind points - // such that any pipelines previously bound to those points are no longer bound - if(stageIndex == (int)ShaderStage::Compute) - { - renderstate.compute.shaderObject = true; - renderstate.compute.pipeline = ResourceId(); - } - else - { - renderstate.graphics.shaderObject = true; - renderstate.graphics.pipeline = ResourceId(); - } + // calling vkCmdBindShadersEXT disturbs the corresponding pipeline bind points + // such that any pipelines previously bound to those points are no longer bound + if(stageIndex == (int)ShaderStage::Compute) + { + renderstate.compute.shaderObject = true; + renderstate.compute.pipeline = ResourceId(); + } + else + { + renderstate.graphics.shaderObject = true; + renderstate.graphics.pipeline = ResourceId(); } } } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - else - { - // track while reading since Serialise_vkCmdBindPipeline does as well - for(uint32_t i = 0; i < stageCount; i++) - { - int stageIndex = StageIndex(pStages[i]); - - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.shaderObjects[stageIndex] = - pShaders && (pShaders[i] != VK_NULL_HANDLE) ? GetResID(pShaders[i]) : ResourceId(); - - if(stageIndex == (int)ShaderStage::Compute) - { - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.compute.pipeline = ResourceId(); - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.compute.shaderObject = true; - } - else - { - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.graphics.pipeline = ResourceId(); - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.graphics.shaderObject = true; - } - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdBindShadersEXT(Unwrap(commandBuffer), stageCount, pStages, UnwrapArray(pShaders, stageCount)); + } } return true; @@ -9240,44 +8720,29 @@ bool WrappedVulkan::Serialise_vkCmdBindIndexBuffer2(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdBindIndexBuffer2(Unwrap(commandBuffer), Unwrap(buffer), offset, size, indexType); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.ibuffer.buf = GetResID(buffer); - renderstate.ibuffer.offs = offset; - renderstate.ibuffer.size = size; + ObjDisp(commandBuffer) + ->CmdBindIndexBuffer2(Unwrap(commandBuffer), Unwrap(buffer), offset, size, indexType); - if(indexType == VK_INDEX_TYPE_UINT32) - renderstate.ibuffer.bytewidth = 4; - else if(indexType == VK_INDEX_TYPE_UINT8) - renderstate.ibuffer.bytewidth = 1; - else - renderstate.ibuffer.bytewidth = 2; - } - } - } - else - { - // track while reading, as we need to bind current topology & index byte width in AddAction - if(indexType == VK_INDEX_TYPE_UINT32) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.ibuffer.bytewidth = 4; - else if(indexType == VK_INDEX_TYPE_UINT8) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.ibuffer.bytewidth = 1; - else - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.ibuffer.bytewidth = 2; + { + VulkanRenderState &renderstate = GetCmdRenderState(); - // track while reading, as we need to track resource usage - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.ibuffer.buf = GetResID(buffer); + renderstate.ibuffer.buf = GetResID(buffer); + renderstate.ibuffer.offs = offset; + renderstate.ibuffer.size = size; - ObjDisp(commandBuffer) - ->CmdBindIndexBuffer2(Unwrap(commandBuffer), Unwrap(buffer), offset, size, indexType); + if(indexType == VK_INDEX_TYPE_UINT32) + renderstate.ibuffer.bytewidth = 4; + else if(indexType == VK_INDEX_TYPE_UINT8) + renderstate.ibuffer.bytewidth = 1; + else + renderstate.ibuffer.bytewidth = 2; + } } } @@ -9326,80 +8791,52 @@ bool WrappedVulkan::Serialise_vkCmdBindDescriptorBuffersEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - size_t memSize = 0; - for(uint32_t b = 0; b < bufferCount; b++) - memSize += GetNextPatchSize(&pBindingInfos[b]); - byte *tempMem = GetTempMemory(memSize); - rdcarray unwrappedInfos; - for(uint32_t b = 0; b < bufferCount; b++) - unwrappedInfos.push_back(*UnwrapStructAndChain(m_State, tempMem, &pBindingInfos[b])); - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdBindDescriptorBuffersEXT(Unwrap(commandBuffer), bufferCount, unwrappedInfos.data()); - - { - VulkanRenderState &renderstate = GetCmdRenderState(); - - // all descriptor buffers above bufferCount are unbound - renderstate.descBufs.resize(bufferCount); - for(uint32_t i = 0; i < bufferCount; i++) - { - renderstate.descBufs[i].address = pBindingInfos[i].address; - renderstate.descBufs[i].usage = pBindingInfos[i].usage; - renderstate.descBufs[i].flags2 = false; - - const VkBufferUsageFlags2CreateInfo *usage2 = - (const VkBufferUsageFlags2CreateInfo *)FindNextStruct( - &pBindingInfos[i], VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO); - if(usage2) - { - renderstate.descBufs[i].usage = usage2->usage; - renderstate.descBufs[i].flags2 = true; - } - const VkDescriptorBufferBindingPushDescriptorBufferHandleEXT *push = - (const VkDescriptorBufferBindingPushDescriptorBufferHandleEXT *)FindNextStruct( - &pBindingInfos[i], - VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_BINDING_PUSH_DESCRIPTOR_BUFFER_HANDLE_EXT); - if(push) - { - renderstate.descBufs[i].pushBuffer = GetResID(push->buffer); - } - } + size_t memSize = 0; + for(uint32_t b = 0; b < bufferCount; b++) + memSize += GetNextPatchSize(&pBindingInfos[b]); + byte *tempMem = GetTempMemory(memSize); + rdcarray unwrappedInfos; + for(uint32_t b = 0; b < bufferCount; b++) + unwrappedInfos.push_back(*UnwrapStructAndChain(m_State, tempMem, &pBindingInfos[b])); - // any offsets that refer to these buffers are invalidated, but then also other buffers - // are unbound meaning those are invalid - we can clear all bindings that refer to - // descriptor buffers however normal descriptor sets must remain as they are *not* - // invalidated and could still be used - for(VkPipelineBindPoint bindPoint : - {VK_PIPELINE_BIND_POINT_GRAPHICS, VK_PIPELINE_BIND_POINT_COMPUTE, - VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR}) - { - VulkanStatePipeline &pipe = renderstate.GetPipeline(bindPoint); - pipe.lastBoundDescBufSet = -1; + ObjDisp(commandBuffer) + ->CmdBindDescriptorBuffersEXT(Unwrap(commandBuffer), bufferCount, unwrappedInfos.data()); - for(uint32_t i = 0; i < pipe.descSets.size(); i++) - if(pipe.descSets[i].descSet == ResourceId()) - pipe.descSets[i] = {}; - } - } - } - } - else - { - // track while reading, for resource usage { - VulkanRenderState &renderstate = m_BakedCmdBufferInfo[m_LastCmdBufferID].state; + VulkanRenderState &renderstate = GetCmdRenderState(); // all descriptor buffers above bufferCount are unbound renderstate.descBufs.resize(bufferCount); for(uint32_t i = 0; i < bufferCount; i++) + { renderstate.descBufs[i].address = pBindingInfos[i].address; + renderstate.descBufs[i].usage = pBindingInfos[i].usage; + renderstate.descBufs[i].flags2 = false; + + const VkBufferUsageFlags2CreateInfo *usage2 = + (const VkBufferUsageFlags2CreateInfo *)FindNextStruct( + &pBindingInfos[i], VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO); + if(usage2) + { + renderstate.descBufs[i].usage = usage2->usage; + renderstate.descBufs[i].flags2 = true; + } + + const VkDescriptorBufferBindingPushDescriptorBufferHandleEXT *push = + (const VkDescriptorBufferBindingPushDescriptorBufferHandleEXT *)FindNextStruct( + &pBindingInfos[i], + VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_BINDING_PUSH_DESCRIPTOR_BUFFER_HANDLE_EXT); + if(push) + { + renderstate.descBufs[i].pushBuffer = GetResID(push->buffer); + } + } // any offsets that refer to these buffers are invalidated, but then also other buffers // are unbound meaning those are invalid - we can clear all bindings that refer to @@ -9410,17 +8847,16 @@ bool WrappedVulkan::Serialise_vkCmdBindDescriptorBuffersEXT( VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR}) { VulkanStatePipeline &pipe = renderstate.GetPipeline(bindPoint); + pipe.lastBoundDescBufSet = -1; for(uint32_t i = 0; i < pipe.descSets.size(); i++) if(pipe.descSets[i].descSet == ResourceId()) pipe.descSets[i] = {}; } - - VersionDescriptorBuffers(commandBuffer); } - - ObjDisp(commandBuffer) - ->CmdBindDescriptorBuffersEXT(Unwrap(commandBuffer), bufferCount, unwrappedInfos.data()); + // this needs to happen after the renderstate has been updated + if(loading) + VersionDescriptorBuffers(commandBuffer); } } @@ -9480,55 +8916,18 @@ bool WrappedVulkan::Serialise_vkCmdSetDescriptorBufferOffsetsEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdSetDescriptorBufferOffsetsEXT(Unwrap(commandBuffer), pipelineBindPoint, - Unwrap(layout), firstSet, setCount, pBufferIndices, - pOffsets); - - { - VulkanRenderState &renderstate = GetCmdRenderState(); - VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); - - pipeline.lastBoundDescBufSet = firstSet; - - // descriptor set bindings are overwritten/cleared by descriptor buffer bindings - for(uint32_t set = 0; set < setCount; set++) - { - pipeline.descSets.resize_for_index(firstSet + set); - pipeline.descSets[firstSet + set] = VulkanStatePipeline::DescriptorAndOffsets(); - - pipeline.descSets[firstSet + set].pipeLayout = GetResID(layout); - pipeline.descSets[firstSet + set].descBufferIdx = pBufferIndices[set]; - pipeline.descSets[firstSet + set].descBufferOffset = pOffsets[set]; - pipeline.descSets[firstSet + set].descBufferEmbeddedSamplers = false; - pipeline.descSets[firstSet + set].descBufferPush = false; - } - // any normal descriptor set bindings are invalidated - pipeline.lastBoundDescSet = -1; - for(VkPipelineBindPoint bindPoint : - {VK_PIPELINE_BIND_POINT_GRAPHICS, VK_PIPELINE_BIND_POINT_COMPUTE, - VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR}) - { - VulkanStatePipeline &pipe = renderstate.GetPipeline(bindPoint); + ObjDisp(commandBuffer) + ->CmdSetDescriptorBufferOffsetsEXT(Unwrap(commandBuffer), pipelineBindPoint, Unwrap(layout), + firstSet, setCount, pBufferIndices, pOffsets); - for(uint32_t i = 0; i < pipe.descSets.size(); i++) - if(!pipe.descSets[i].IsDescBufferBound()) - pipe.descSets[i] = {}; - } - } - } - } - else - { - // track while reading, for resource usage { - VulkanRenderState &renderstate = m_BakedCmdBufferInfo[m_LastCmdBufferID].state; + VulkanRenderState &renderstate = GetCmdRenderState(); VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); pipeline.lastBoundDescBufSet = firstSet; @@ -9559,10 +8958,6 @@ bool WrappedVulkan::Serialise_vkCmdSetDescriptorBufferOffsetsEXT( pipe.descSets[i] = {}; } } - - ObjDisp(commandBuffer) - ->CmdSetDescriptorBufferOffsetsEXT(Unwrap(commandBuffer), pipelineBindPoint, Unwrap(layout), - firstSet, setCount, pBufferIndices, pOffsets); } } @@ -9616,48 +9011,42 @@ bool WrappedVulkan::Serialise_vkCmdBindDescriptorBufferEmbeddedSamplersEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdBindDescriptorBufferEmbeddedSamplersEXT(Unwrap(commandBuffer), pipelineBindPoint, - Unwrap(layout), set); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); + ObjDisp(commandBuffer) + ->CmdBindDescriptorBufferEmbeddedSamplersEXT(Unwrap(commandBuffer), pipelineBindPoint, + Unwrap(layout), set); - pipeline.descSets.resize_for_index(set); + { + VulkanRenderState &renderstate = GetCmdRenderState(); + VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); - pipeline.descSets[set] = VulkanStatePipeline::DescriptorAndOffsets(); - pipeline.descSets[set].pipeLayout = GetResID(layout); - pipeline.descSets[set].descBufferIdx = ~0U; - pipeline.descSets[set].descBufferOffset = 0; - pipeline.descSets[set].descBufferEmbeddedSamplers = true; - pipeline.descSets[set].descBufferPush = false; + pipeline.descSets.resize_for_index(set); - // any normal descriptor set bindings are invalidated - for(VkPipelineBindPoint bindPoint : - {VK_PIPELINE_BIND_POINT_GRAPHICS, VK_PIPELINE_BIND_POINT_COMPUTE, - VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR}) - { - VulkanStatePipeline &pipe = renderstate.GetPipeline(bindPoint); + pipeline.descSets[set] = VulkanStatePipeline::DescriptorAndOffsets(); + pipeline.descSets[set].pipeLayout = GetResID(layout); + pipeline.descSets[set].descBufferIdx = ~0U; + pipeline.descSets[set].descBufferOffset = 0; + pipeline.descSets[set].descBufferEmbeddedSamplers = true; + pipeline.descSets[set].descBufferPush = false; - for(uint32_t i = 0; i < pipe.descSets.size(); i++) - if(!pipe.descSets[i].IsDescBufferBound()) - pipe.descSets[i] = {}; - } + // any normal descriptor set bindings are invalidated + for(VkPipelineBindPoint bindPoint : + {VK_PIPELINE_BIND_POINT_GRAPHICS, VK_PIPELINE_BIND_POINT_COMPUTE, + VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR}) + { + VulkanStatePipeline &pipe = renderstate.GetPipeline(bindPoint); + + for(uint32_t i = 0; i < pipe.descSets.size(); i++) + if(!pipe.descSets[i].IsDescBufferBound()) + pipe.descSets[i] = {}; } } } - else - { - ObjDisp(commandBuffer) - ->CmdBindDescriptorBufferEmbeddedSamplersEXT(Unwrap(commandBuffer), pipelineBindPoint, - Unwrap(layout), set); - } } return true; @@ -9705,65 +9094,24 @@ bool WrappedVulkan::Serialise_vkCmdSetDescriptorBufferOffsets2EXT( { m_LastCmdBufferID = GetResID(commandBuffer); - byte *tempMem = GetTempMemory(GetNextPatchSize(&SetDescriptorBufferOffsetsInfo)); - VkSetDescriptorBufferOffsetsInfoEXT *unwrappedInfo = - UnwrapStructAndChain(m_State, tempMem, &SetDescriptorBufferOffsetsInfo); - - rdcarray pipelinesAffected = - PipelinesForStageMask(SetDescriptorBufferOffsetsInfo.stageFlags); - uint32_t firstSet = SetDescriptorBufferOffsetsInfo.firstSet; - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer)->CmdSetDescriptorBufferOffsets2EXT(Unwrap(commandBuffer), unwrappedInfo); - - VulkanRenderState &renderstate = GetCmdRenderState(); - - for(VkPipelineBindPoint pipelineBindPoint : pipelinesAffected) - { - VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); - pipeline.lastBoundDescBufSet = firstSet; + byte *tempMem = GetTempMemory(GetNextPatchSize(&SetDescriptorBufferOffsetsInfo)); + VkSetDescriptorBufferOffsetsInfoEXT *unwrappedInfo = + UnwrapStructAndChain(m_State, tempMem, &SetDescriptorBufferOffsetsInfo); - // descriptor set bindings are overwritten/cleared by descriptor buffer bindings - for(uint32_t set = 0; set < SetDescriptorBufferOffsetsInfo.setCount; set++) - { - pipeline.descSets.resize_for_index(firstSet + set); - - pipeline.descSets[firstSet + set] = VulkanStatePipeline::DescriptorAndOffsets(); - pipeline.descSets[firstSet + set].pipeLayout = - GetResID(SetDescriptorBufferOffsetsInfo.layout); - pipeline.descSets[firstSet + set].descBufferIdx = - SetDescriptorBufferOffsetsInfo.pBufferIndices[set]; - pipeline.descSets[firstSet + set].descBufferOffset = - SetDescriptorBufferOffsetsInfo.pOffsets[set]; - pipeline.descSets[firstSet + set].descBufferEmbeddedSamplers = false; - pipeline.descSets[firstSet + set].descBufferPush = false; - } - } + rdcarray pipelinesAffected = + PipelinesForStageMask(SetDescriptorBufferOffsetsInfo.stageFlags); + uint32_t firstSet = SetDescriptorBufferOffsetsInfo.firstSet; - // any normal descriptor set bindings are invalidated - for(VkPipelineBindPoint bindPoint : - {VK_PIPELINE_BIND_POINT_GRAPHICS, VK_PIPELINE_BIND_POINT_COMPUTE, - VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR}) - { - VulkanStatePipeline &pipe = renderstate.GetPipeline(bindPoint); - pipe.lastBoundDescSet = -1; + ObjDisp(commandBuffer)->CmdSetDescriptorBufferOffsets2EXT(Unwrap(commandBuffer), unwrappedInfo); - for(uint32_t i = 0; i < pipe.descSets.size(); i++) - if(!pipe.descSets[i].IsDescBufferBound()) - pipe.descSets[i] = {}; - } - } - } - else - { - VulkanRenderState &renderstate = m_BakedCmdBufferInfo[m_LastCmdBufferID].state; + VulkanRenderState &renderstate = GetCmdRenderState(); - // track while reading, for resource usage for(VkPipelineBindPoint pipelineBindPoint : pipelinesAffected) { VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); @@ -9799,8 +9147,6 @@ bool WrappedVulkan::Serialise_vkCmdSetDescriptorBufferOffsets2EXT( if(!pipe.descSets[i].IsDescBufferBound()) pipe.descSets[i] = {}; } - - ObjDisp(commandBuffer)->CmdSetDescriptorBufferOffsets2EXT(Unwrap(commandBuffer), unwrappedInfo); } } @@ -9854,58 +9200,52 @@ bool WrappedVulkan::Serialise_vkCmdBindDescriptorBufferEmbeddedSamplers2EXT( { m_LastCmdBufferID = GetResID(commandBuffer); - byte *tempMem = GetTempMemory(GetNextPatchSize(&BindDescriptorBufferEmbeddedSamplersInfo)); - VkBindDescriptorBufferEmbeddedSamplersInfoEXT *unwrappedInfo = - UnwrapStructAndChain(m_State, tempMem, &BindDescriptorBufferEmbeddedSamplersInfo); - - rdcarray pipelinesAffected = - PipelinesForStageMask(BindDescriptorBufferEmbeddedSamplersInfo.stageFlags); - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdBindDescriptorBufferEmbeddedSamplers2EXT(Unwrap(commandBuffer), unwrappedInfo); - uint32_t set = BindDescriptorBufferEmbeddedSamplersInfo.set; + byte *tempMem = GetTempMemory(GetNextPatchSize(&BindDescriptorBufferEmbeddedSamplersInfo)); + VkBindDescriptorBufferEmbeddedSamplersInfoEXT *unwrappedInfo = + UnwrapStructAndChain(m_State, tempMem, &BindDescriptorBufferEmbeddedSamplersInfo); - VulkanRenderState &renderstate = GetCmdRenderState(); + rdcarray pipelinesAffected = + PipelinesForStageMask(BindDescriptorBufferEmbeddedSamplersInfo.stageFlags); - for(VkPipelineBindPoint pipelineBindPoint : pipelinesAffected) - { - VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); + ObjDisp(commandBuffer) + ->CmdBindDescriptorBufferEmbeddedSamplers2EXT(Unwrap(commandBuffer), unwrappedInfo); - pipeline.descSets.resize_for_index(set); + uint32_t set = BindDescriptorBufferEmbeddedSamplersInfo.set; - pipeline.descSets[set] = VulkanStatePipeline::DescriptorAndOffsets(); - pipeline.descSets[set].pipeLayout = - GetResID(BindDescriptorBufferEmbeddedSamplersInfo.layout); - pipeline.descSets[set].descBufferIdx = ~0U; - pipeline.descSets[set].descBufferOffset = 0; - pipeline.descSets[set].descBufferEmbeddedSamplers = true; - pipeline.descSets[set].descBufferPush = false; - } + VulkanRenderState &renderstate = GetCmdRenderState(); - // any normal descriptor set bindings are invalidated - for(VkPipelineBindPoint bindPoint : - {VK_PIPELINE_BIND_POINT_GRAPHICS, VK_PIPELINE_BIND_POINT_COMPUTE, - VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR}) - { - VulkanStatePipeline &pipe = renderstate.GetPipeline(bindPoint); + for(VkPipelineBindPoint pipelineBindPoint : pipelinesAffected) + { + VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); + + pipeline.descSets.resize_for_index(set); + + pipeline.descSets[set] = VulkanStatePipeline::DescriptorAndOffsets(); + pipeline.descSets[set].pipeLayout = GetResID(BindDescriptorBufferEmbeddedSamplersInfo.layout); + pipeline.descSets[set].descBufferIdx = ~0U; + pipeline.descSets[set].descBufferOffset = 0; + pipeline.descSets[set].descBufferEmbeddedSamplers = true; + pipeline.descSets[set].descBufferPush = false; + } + + // any normal descriptor set bindings are invalidated + for(VkPipelineBindPoint bindPoint : + {VK_PIPELINE_BIND_POINT_GRAPHICS, VK_PIPELINE_BIND_POINT_COMPUTE, + VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR}) + { + VulkanStatePipeline &pipe = renderstate.GetPipeline(bindPoint); - for(uint32_t i = 0; i < pipe.descSets.size(); i++) - if(!pipe.descSets[i].IsDescBufferBound()) - pipe.descSets[i] = {}; - } + for(uint32_t i = 0; i < pipe.descSets.size(); i++) + if(!pipe.descSets[i].IsDescBufferBound()) + pipe.descSets[i] = {}; } } - else - { - ObjDisp(commandBuffer) - ->CmdBindDescriptorBufferEmbeddedSamplers2EXT(Unwrap(commandBuffer), unwrappedInfo); - } } return true; @@ -9957,66 +9297,22 @@ bool WrappedVulkan::Serialise_vkCmdPushDescriptorSet2( { m_LastCmdBufferID = GetResID(commandBuffer); - rdcarray pipelinesAffected = - PipelinesForStageMask(PushDescriptorSetInfo.stageFlags); - - uint32_t set = PushDescriptorSetInfo.set; - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - for(VkPipelineBindPoint pipelineBindPoint : pipelinesAffected) - { - VulkanRenderState &renderstate = GetCmdRenderState(); - VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); - rdcarray &descsets = pipeline.descSets; - - ResourceId setId = - m_BakedCmdBufferInfo[m_LastCmdBufferID].GetPushDescriptorID(pipelineBindPoint, set); + rdcarray pipelinesAffected = + PipelinesForStageMask(PushDescriptorSetInfo.stageFlags); - // expand as necessary - if(descsets.size() < set + 1) - descsets.resize(set + 1); - - descsets[set] = VulkanStatePipeline::DescriptorAndOffsets(); - descsets[set].pipeLayout = GetResID(PushDescriptorSetInfo.layout); - descsets[set].descSet = setId; - descsets[set].push = true; - ResourceId setLayout = - m_CreationInfo.m_PipelineLayout[GetResID(PushDescriptorSetInfo.layout)].descSetLayouts[set]; - descsets[set].descBufferPush = - (m_CreationInfo.m_DescSetLayout[setLayout].flags & - VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT) != 0; - - if(descsets[set].descBufferPush) - { - pipeline.lastBoundDescSet = -1; - pipeline.lastBoundDescBufSet = set; - } - else - { - pipeline.lastBoundDescSet = set; - pipeline.lastBoundDescBufSet = -1; - } - } + uint32_t set = PushDescriptorSetInfo.set; - // actual replay of the command will happen below - } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - else - { for(VkPipelineBindPoint pipelineBindPoint : pipelinesAffected) { - // track while reading, as we need to track resource usage - rdcarray &descsets = - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetPipeline(pipelineBindPoint).descSets; + VulkanRenderState &renderstate = GetCmdRenderState(); + VulkanStatePipeline &pipeline = renderstate.GetPipeline(pipelineBindPoint); + rdcarray &descsets = pipeline.descSets; ResourceId setId = m_BakedCmdBufferInfo[m_LastCmdBufferID].GetPushDescriptorID(pipelineBindPoint, set); @@ -10025,9 +9321,8 @@ bool WrappedVulkan::Serialise_vkCmdPushDescriptorSet2( if(descsets.size() < set + 1) descsets.resize(set + 1); - // we use a 'special' ID for the push descriptor at this index, since there's no actual - // allocated object corresponding to it. descsets[set] = VulkanStatePipeline::DescriptorAndOffsets(); + descsets[set].pipeLayout = GetResID(PushDescriptorSetInfo.layout); descsets[set].descSet = setId; descsets[set].push = true; ResourceId setLayout = @@ -10035,11 +9330,19 @@ bool WrappedVulkan::Serialise_vkCmdPushDescriptorSet2( descsets[set].descBufferPush = (m_CreationInfo.m_DescSetLayout[setLayout].flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT) != 0; + + if(descsets[set].descBufferPush) + { + pipeline.lastBoundDescSet = -1; + pipeline.lastBoundDescBufSet = set; + } + else + { + pipeline.lastBoundDescSet = set; + pipeline.lastBoundDescBufSet = -1; + } } - } - if(commandBuffer != VK_NULL_HANDLE) - { // since we version push descriptors per-command buffer, we can safely update them always // without worrying about overlap. We just need to check that we're in the record range so // that we don't pull in descriptor updates after the point in the command buffer we're @@ -10135,79 +9438,52 @@ bool WrappedVulkan::Serialise_vkCmdPushDescriptorSetWithTemplate2( { m_LastCmdBufferID = GetResID(commandBuffer); - uint32_t set = PushDescriptorSetWithTemplateInfo.set; - - VkPipelineBindPoint bindPoint = - m_CreationInfo - .m_DescUpdateTemplate[GetResID(PushDescriptorSetWithTemplateInfo.descriptorUpdateTemplate)] - .bindPoint; - - ResourceId setId = m_BakedCmdBufferInfo[m_LastCmdBufferID].GetPushDescriptorID(bindPoint, set); - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - VulkanStatePipeline &pipeline = renderstate.GetPipeline(bindPoint); - rdcarray &descsets = pipeline.descSets; + uint32_t set = PushDescriptorSetWithTemplateInfo.set; - // expand as necessary - if(descsets.size() < set + 1) - descsets.resize(set + 1); - - descsets[set] = VulkanStatePipeline::DescriptorAndOffsets(); - descsets[set].pipeLayout = GetResID(PushDescriptorSetWithTemplateInfo.layout); - descsets[set].descSet = setId; - descsets[set].push = true; - ResourceId setLayout = - m_CreationInfo.m_PipelineLayout[GetResID(PushDescriptorSetWithTemplateInfo.layout)] - .descSetLayouts[set]; - descsets[set].descBufferPush = - (m_CreationInfo.m_DescSetLayout[setLayout].flags & - VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT) != 0; - - if(descsets[set].descBufferPush) - { - pipeline.lastBoundDescSet = -1; - pipeline.lastBoundDescBufSet = set; - } - else - { - pipeline.lastBoundDescSet = set; - pipeline.lastBoundDescBufSet = -1; - } - } + VkPipelineBindPoint bindPoint = + m_CreationInfo + .m_DescUpdateTemplate[GetResID(PushDescriptorSetWithTemplateInfo.descriptorUpdateTemplate)] + .bindPoint; + + ResourceId setId = m_BakedCmdBufferInfo[m_LastCmdBufferID].GetPushDescriptorID(bindPoint, set); - // actual replay of the command will happen below - } - else { - commandBuffer = VK_NULL_HANDLE; - } - } - else - { - // track while reading, as we need to track resource usage - rdcarray &descsets = - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.GetPipeline(bindPoint).descSets; + VulkanRenderState &renderstate = GetCmdRenderState(); + VulkanStatePipeline &pipeline = renderstate.GetPipeline(bindPoint); + rdcarray &descsets = pipeline.descSets; - // expand as necessary - if(descsets.size() < set + 1) - descsets.resize(set + 1); + // expand as necessary + if(descsets.size() < set + 1) + descsets.resize(set + 1); - // we use a 'special' ID for the push descriptor at this index, since there's no actual - // allocated object corresponding to it. - descsets[set] = VulkanStatePipeline::DescriptorAndOffsets(); - descsets[set].descSet = setId; - descsets[set].push = true; - } + descsets[set] = VulkanStatePipeline::DescriptorAndOffsets(); + descsets[set].pipeLayout = GetResID(PushDescriptorSetWithTemplateInfo.layout); + descsets[set].descSet = setId; + descsets[set].push = true; + ResourceId setLayout = + m_CreationInfo.m_PipelineLayout[GetResID(PushDescriptorSetWithTemplateInfo.layout)] + .descSetLayouts[set]; + descsets[set].descBufferPush = + (m_CreationInfo.m_DescSetLayout[setLayout].flags & + VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT) != 0; - if(commandBuffer != VK_NULL_HANDLE) - { + if(descsets[set].descBufferPush) + { + pipeline.lastBoundDescSet = -1; + pipeline.lastBoundDescBufSet = set; + } + else + { + pipeline.lastBoundDescSet = set; + pipeline.lastBoundDescBufSet = -1; + } + } // since we version push descriptors per-command buffer, we can safely update them always // without worrying about overlap. We just need to check that we're in the record range so // that we don't pull in descriptor updates after the point in the command buffer we're @@ -10306,50 +9582,19 @@ bool WrappedVulkan::Serialise_vkCmdBeginCustomResolveEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer)->CmdBeginCustomResolveEXT(Unwrap(commandBuffer), pBeginCustomResolveInfo); - - VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicRendering.beginCustomResolve = true; - - // The resolve images are now the framebuffer not the color images - rdcarray attachments; - for(size_t i = 0; i < renderstate.dynamicRendering.color.size(); i++) - { - VkRenderingAttachmentInfo &attInfo = renderstate.dynamicRendering.color[i]; - if(attInfo.resolveMode & VK_RESOLVE_MODE_CUSTOM_BIT_EXT) - { - attachments.push_back(GetResID(attInfo.resolveImageView)); - // The resolve images data is undefined and has an implicit store - renderstate.dynamicRendering.color[i].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - renderstate.dynamicRendering.color[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE; - } - else - { - attachments.push_back(GetResID(attInfo.imageView)); - } - } - - attachments.push_back(GetResID(renderstate.dynamicRendering.depth.resolveImageView)); - attachments.push_back(GetResID(renderstate.dynamicRendering.stencil.resolveImageView)); - renderstate.SetFramebuffer(ResourceId(), attachments); - } - } - else - { ObjDisp(commandBuffer)->CmdBeginCustomResolveEXT(Unwrap(commandBuffer), pBeginCustomResolveInfo); - VulkanRenderState &renderstate = m_BakedCmdBufferInfo[m_LastCmdBufferID].state; + VulkanRenderState &renderstate = GetCmdRenderState(); renderstate.dynamicRendering.beginCustomResolve = true; // The resolve images are now the framebuffer not the color images rdcarray attachments; - for(size_t i = 0; i < renderstate.dynamicRendering.color.size(); i++) { VkRenderingAttachmentInfo &attInfo = renderstate.dynamicRendering.color[i]; @@ -10357,12 +9602,12 @@ bool WrappedVulkan::Serialise_vkCmdBeginCustomResolveEXT( { ResourceId resolveImageView = GetResID(attInfo.resolveImageView); attachments.push_back(resolveImageView); + if(loading) + AddEventResourceUsage(m_CreationInfo.m_ImageView[resolveImageView].image, + ResourceUsage::Discard); // The resolve images data is undefined and has an implicit store renderstate.dynamicRendering.color[i].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; renderstate.dynamicRendering.color[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE; - - ResourceId image = m_CreationInfo.m_ImageView[resolveImageView].image; - m_LoadingEventNode.resourceUsage.push_back(make_rdcpair(image, ResourceUsage::Discard)); } else { @@ -10374,12 +9619,14 @@ bool WrappedVulkan::Serialise_vkCmdBeginCustomResolveEXT( attachments.push_back(GetResID(renderstate.dynamicRendering.stencil.resolveImageView)); renderstate.SetFramebuffer(ResourceId(), attachments); - - AddEvent(); - ActionDescription action; - action.customName = "vkCmdBeginCustomResolveEXT()"; - action.flags |= ActionFlags::PassBoundary | ActionFlags::BeginPass | ActionFlags::EndPass; - AddAction(action); + if(loading) + { + AddEvent(); + ActionDescription action; + action.customName = "vkCmdBeginCustomResolveEXT()"; + action.flags |= ActionFlags::PassBoundary | ActionFlags::BeginPass | ActionFlags::EndPass; + AddAction(action); + } } } return true; @@ -10473,44 +9720,28 @@ bool WrappedVulkan::Serialise_vkCmdBindIndexBuffer3KHR(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer)->CmdBindIndexBuffer3KHR(Unwrap(commandBuffer), &Info); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - GetResIDFromAddr(Info.addressRange.address, renderstate.ibuffer.buf, - renderstate.ibuffer.offs); - renderstate.ibuffer.size = Info.addressRange.size; + ObjDisp(commandBuffer)->CmdBindIndexBuffer3KHR(Unwrap(commandBuffer), &Info); - if(Info.indexType == VK_INDEX_TYPE_UINT32) - renderstate.ibuffer.bytewidth = 4; - else if(Info.indexType == VK_INDEX_TYPE_UINT8) - renderstate.ibuffer.bytewidth = 1; - else - renderstate.ibuffer.bytewidth = 2; - } + { + VulkanRenderState &renderstate = GetCmdRenderState(); + GetResIDFromAddr(Info.addressRange.address, renderstate.ibuffer.buf, + renderstate.ibuffer.offs); + renderstate.ibuffer.size = Info.addressRange.size; + + if(Info.indexType == VK_INDEX_TYPE_UINT32) + renderstate.ibuffer.bytewidth = 4; + else if(Info.indexType == VK_INDEX_TYPE_UINT8) + renderstate.ibuffer.bytewidth = 1; + else + renderstate.ibuffer.bytewidth = 2; } } - else - { - // track while reading, as we need to bind current topology & index byte width in AddAction - if(Info.indexType == VK_INDEX_TYPE_UINT32) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.ibuffer.bytewidth = 4; - else if(Info.indexType == VK_INDEX_TYPE_UINT8) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.ibuffer.bytewidth = 1; - else - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.ibuffer.bytewidth = 2; - - // track while reading, as we need to track resource usage - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.ibuffer.buf = - GetResIDFromAddr(Info.addressRange.address); - - ObjDisp(commandBuffer)->CmdBindIndexBuffer3KHR(Unwrap(commandBuffer), &Info); - } } return true; @@ -10556,58 +9787,44 @@ bool WrappedVulkan::Serialise_vkCmdBindVertexBuffers3KHR( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdBindVertexBuffers3KHR(Unwrap(commandBuffer), firstBinding, bindingCount, - pBindingInfos); + ObjDisp(commandBuffer) + ->CmdBindVertexBuffers3KHR(Unwrap(commandBuffer), firstBinding, bindingCount, + pBindingInfos); + + { + VulkanRenderState &renderstate = GetCmdRenderState(); + if(renderstate.vbuffers.size() < firstBinding + bindingCount) + renderstate.vbuffers.resize(firstBinding + bindingCount); + + for(uint32_t i = 0; i < bindingCount; i++) { - VulkanRenderState &renderstate = GetCmdRenderState(); - if(renderstate.vbuffers.size() < firstBinding + bindingCount) - renderstate.vbuffers.resize(firstBinding + bindingCount); + GetResIDFromAddr(pBindingInfos[i].addressRange.address, + renderstate.vbuffers[firstBinding + i].buf, + renderstate.vbuffers[firstBinding + i].offs); + renderstate.vbuffers[firstBinding + i].size = pBindingInfos[i].addressRange.size; - for(uint32_t i = 0; i < bindingCount; i++) + if(pBindingInfos[i].setStride) { - GetResIDFromAddr(pBindingInfos[i].addressRange.address, - renderstate.vbuffers[firstBinding + i].buf, - renderstate.vbuffers[firstBinding + i].offs); - renderstate.vbuffers[firstBinding + i].size = pBindingInfos[i].addressRange.size; - - if(pBindingInfos[i].setStride) - { - renderstate.dynamicStates[VkDynamicVertexInputBindingStride] = true; + renderstate.dynamicStates[VkDynamicVertexInputBindingStride] = true; - renderstate.vbuffers[firstBinding + i].stride = pBindingInfos[i].addressRange.stride; + renderstate.vbuffers[firstBinding + i].stride = pBindingInfos[i].addressRange.stride; - // if we have dynamic vertex input data, update the strides. If we don't have any - // that's fine we can skip this, it means the application must provide a later - // vkCmdSetVertexInput which overrides anything we'd set here - if(firstBinding + i < renderstate.vertexBindings.size()) - renderstate.vertexBindings[firstBinding + i].stride = - (uint32_t)pBindingInfos[i].addressRange.stride; - } + // if we have dynamic vertex input data, update the strides. If we don't have any + // that's fine we can skip this, it means the application must provide a later + // vkCmdSetVertexInput which overrides anything we'd set here + if(firstBinding + i < renderstate.vertexBindings.size()) + renderstate.vertexBindings[firstBinding + i].stride = + (uint32_t)pBindingInfos[i].addressRange.stride; } } } } - else - { - // track while reading, as we need to track resource usage - if(m_BakedCmdBufferInfo[m_LastCmdBufferID].state.vbuffers.size() < firstBinding + bindingCount) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.vbuffers.resize(firstBinding + bindingCount); - - for(uint32_t i = 0; i < bindingCount; i++) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.vbuffers[firstBinding + i].buf = - GetResIDFromAddr(pBindingInfos[i].addressRange.address); - - ObjDisp(commandBuffer) - ->CmdBindVertexBuffers3KHR(Unwrap(commandBuffer), firstBinding, bindingCount, - pBindingInfos); - } } return true; @@ -10661,26 +9878,20 @@ bool WrappedVulkan::Serialise_vkCmdCopyQueryPoolResultsToMemoryKHR( if(IsReplayingAndReading()) { - m_LastCmdBufferID = GetResID(commandBuffer); - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - else - commandBuffer = VK_NULL_HANDLE; - } - VulkanCreationInfo::QueryPool &qpInfo = m_CreationInfo.m_QueryPool[GetResID(queryPool)]; + VulkanCreationInfo::QueryPool &qpInfo = m_CreationInfo.m_QueryPool[GetResID(queryPool)]; - // skip AS queries as we do not serialise them - if(qpInfo.queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR || - qpInfo.queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SIZE_KHR || - qpInfo.queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR || - qpInfo.queryType == - VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_BOTTOM_LEVEL_POINTERS_KHR) - { - if(commandBuffer != VK_NULL_HANDLE) + // skip AS queries as we do not serialise them + if(qpInfo.queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR || + qpInfo.queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SIZE_KHR || + qpInfo.queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR || + qpInfo.queryType == + VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_BOTTOM_LEVEL_POINTERS_KHR) { const bool is64bit = (queryResultFlags & VK_QUERY_RESULT_64_BIT) > 0; const bool hasAvailability = (queryResultFlags & VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) > 0; @@ -10693,13 +9904,10 @@ bool WrappedVulkan::Serialise_vkCmdCopyQueryPoolResultsToMemoryKHR( VkDeviceAddressRangeKHR range = {DstRange.address, size}; ObjDisp(commandBuffer)->CmdFillMemoryKHR(Unwrap(commandBuffer), &range, dstFlags, 0); - } - return true; - } + return true; + } - if(commandBuffer != VK_NULL_HANDLE) - { ObjDisp(commandBuffer) ->CmdCopyQueryPoolResultsToMemoryKHR(Unwrap(commandBuffer), Unwrap(queryPool), firstQuery, queryCount, &DstRange, dstFlags, queryResultFlags); @@ -10879,24 +10087,19 @@ bool WrappedVulkan::Serialise_vkCmdBeginConditionalRendering2EXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - GetResIDFromAddr(BeginInfo.addressRange.address, renderstate.conditionalRendering.buffer, - renderstate.conditionalRendering.offset); - renderstate.conditionalRendering.flags = BeginInfo.flags; - } - - ObjDisp(commandBuffer)->CmdBeginConditionalRendering2EXT(Unwrap(commandBuffer), &BeginInfo); + { + VulkanRenderState &renderstate = GetCmdRenderState(); + GetResIDFromAddr(BeginInfo.addressRange.address, renderstate.conditionalRendering.buffer, + renderstate.conditionalRendering.offset); + renderstate.conditionalRendering.flags = BeginInfo.flags; } - } - else - { + ObjDisp(commandBuffer)->CmdBeginConditionalRendering2EXT(Unwrap(commandBuffer), &BeginInfo); } } @@ -10947,44 +10150,33 @@ bool WrappedVulkan::Serialise_vkCmdBeginTransformFeedback2EXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.firstxfbcounter = firstCounterRange; - renderstate.xfbcounters.resize(counterRangeCount); + { + VulkanRenderState &renderstate = GetCmdRenderState(); + renderstate.firstxfbcounter = firstCounterRange; + renderstate.xfbcounters.resize(counterRangeCount); - for(uint32_t i = 0; i < counterRangeCount; i++) + for(uint32_t i = 0; i < counterRangeCount; i++) + { + if(pCounterInfos) + GetResIDFromAddr(pCounterInfos[i].addressRange.address, renderstate.xfbcounters[i].buf, + renderstate.xfbcounters[i].offs); + else { - if(pCounterInfos) - GetResIDFromAddr(pCounterInfos[i].addressRange.address, renderstate.xfbcounters[i].buf, - renderstate.xfbcounters[i].offs); - else - { - renderstate.xfbcounters[i].buf = ResourceId(); - renderstate.xfbcounters[i].offs = 0; - } + renderstate.xfbcounters[i].buf = ResourceId(); + renderstate.xfbcounters[i].offs = 0; } } - - ObjDisp(commandBuffer) - ->CmdBeginTransformFeedback2EXT(Unwrap(commandBuffer), firstCounterRange, - counterRangeCount, pCounterInfos); } - } - else - { + ObjDisp(commandBuffer) ->CmdBeginTransformFeedback2EXT(Unwrap(commandBuffer), firstCounterRange, counterRangeCount, pCounterInfos); - - // track while reading, for fetching the right set of outputs in AddAction - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.firstxfbcounter = firstCounterRange; - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.xfbcounters.resize(counterRangeCount); } } @@ -11035,53 +10227,38 @@ bool WrappedVulkan::Serialise_vkCmdBindTransformFeedbackBuffers2EXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - ObjDisp(commandBuffer) - ->CmdBindTransformFeedbackBuffers2EXT(Unwrap(commandBuffer), firstBinding, bindingCount, - pBindingInfos); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - if(renderstate.xfbbuffers.size() < firstBinding + bindingCount) - renderstate.xfbbuffers.resize(firstBinding + bindingCount); + ObjDisp(commandBuffer) + ->CmdBindTransformFeedbackBuffers2EXT(Unwrap(commandBuffer), firstBinding, bindingCount, + pBindingInfos); + + { + VulkanRenderState &renderstate = GetCmdRenderState(); + if(renderstate.xfbbuffers.size() < firstBinding + bindingCount) + renderstate.xfbbuffers.resize(firstBinding + bindingCount); - for(uint32_t i = 0; i < bindingCount; i++) + for(uint32_t i = 0; i < bindingCount; i++) + { + auto &binding = renderstate.xfbbuffers[firstBinding + i]; + if(pBindingInfos) { - if(pBindingInfos) - { - GetResIDFromAddr(pBindingInfos[i].addressRange.address, - renderstate.xfbbuffers[firstBinding + i].buf, - renderstate.xfbbuffers[firstBinding + i].offs); - renderstate.xfbbuffers[firstBinding + i].size = pBindingInfos[i].addressRange.size; - } - else - { - renderstate.xfbbuffers[firstBinding + i].buf = ResourceId(); - renderstate.xfbbuffers[firstBinding + i].offs = 0; - renderstate.xfbbuffers[firstBinding + i].size = 0; - } + GetResIDFromAddr(pBindingInfos[i].addressRange.address, binding.buf, binding.offs); + binding.size = pBindingInfos[i].addressRange.size; + } + else + { + binding.buf = ResourceId(); + binding.offs = 0; + binding.size = 0; } } } } - else - { - // track while reading, as we need to track resource usage - if(m_BakedCmdBufferInfo[m_LastCmdBufferID].state.xfbbuffers.size() < firstBinding + bindingCount) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.xfbbuffers.resize(firstBinding + bindingCount); - - for(uint32_t i = 0; i < bindingCount; i++) - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.xfbbuffers[firstBinding + i].buf = - pBindingInfos ? GetResIDFromAddr(pBindingInfos[i].addressRange.address) : ResourceId(); - - ObjDisp(commandBuffer) - ->CmdBindTransformFeedbackBuffers2EXT(Unwrap(commandBuffer), firstBinding, bindingCount, - pBindingInfos); - } } return true; @@ -11131,32 +10308,21 @@ bool WrappedVulkan::Serialise_vkCmdEndTransformFeedback2EXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.firstxfbcounter = 0; - renderstate.xfbcounters.clear(); - } - - ObjDisp(commandBuffer) - ->CmdEndTransformFeedback2EXT(Unwrap(commandBuffer), firstCounterRange, - counterRangeCount, pCounterInfos); + { + VulkanRenderState &renderstate = GetCmdRenderState(); + renderstate.firstxfbcounter = 0; + renderstate.xfbcounters.clear(); } - } - else - { + ObjDisp(commandBuffer) ->CmdEndTransformFeedback2EXT(Unwrap(commandBuffer), firstCounterRange, counterRangeCount, pCounterInfos); - - // track while reading, for fetching the right set of outputs in AddAction - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.firstxfbcounter = 0; - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.xfbcounters.clear(); } } diff --git a/renderdoc/driver/vulkan/wrappers/vk_draw_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_draw_funcs.cpp index 6ccfda155a9..d4cd455f0fe 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_draw_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_draw_funcs.cpp @@ -330,35 +330,28 @@ bool WrappedVulkan::Serialise_vkCmdDraw(SerialiserType &ser, VkCommandBuffer com { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - if(!IsActionDisabled()) - { - uint32_t eventId = HandlePreCallback(commandBuffer); + if(loading || !IsActionDisabled()) + { + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer) : 0; - ObjDisp(commandBuffer) - ->CmdDraw(Unwrap(commandBuffer), vertexCount, instanceCount, firstVertex, - firstInstance); + ObjDisp(commandBuffer) + ->CmdDraw(Unwrap(commandBuffer), vertexCount, instanceCount, firstVertex, firstInstance); - if(eventId && m_ActionCallback->PostDraw(eventId, ActionFlags::Drawcall, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdDraw(Unwrap(commandBuffer), vertexCount, instanceCount, firstVertex, - firstInstance); - m_ActionCallback->PostRedraw(eventId, ActionFlags::Drawcall, commandBuffer); - } + if(eventId && m_ActionCallback->PostDraw(eventId, ActionFlags::Drawcall, commandBuffer)) + { + ObjDisp(commandBuffer) + ->CmdDraw(Unwrap(commandBuffer), vertexCount, instanceCount, firstVertex, firstInstance); + m_ActionCallback->PostRedraw(eventId, ActionFlags::Drawcall, commandBuffer); } } - } - else - { - ObjDisp(commandBuffer) - ->CmdDraw(Unwrap(commandBuffer), vertexCount, instanceCount, firstVertex, firstInstance); + if(loading) { AddEvent(); @@ -423,35 +416,30 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndexed(SerialiserType &ser, VkCommandBuf { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - if(!IsActionDisabled()) - { - uint32_t eventId = HandlePreCallback(commandBuffer); + if(loading || !IsActionDisabled()) + { + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer) : 0; + + ObjDisp(commandBuffer) + ->CmdDrawIndexed(Unwrap(commandBuffer), indexCount, instanceCount, firstIndex, + vertexOffset, firstInstance); + if(eventId && m_ActionCallback->PostDraw(eventId, ActionFlags::Drawcall, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdDrawIndexed(Unwrap(commandBuffer), indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); - - if(eventId && m_ActionCallback->PostDraw(eventId, ActionFlags::Drawcall, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdDrawIndexed(Unwrap(commandBuffer), indexCount, instanceCount, firstIndex, - vertexOffset, firstInstance); - m_ActionCallback->PostRedraw(eventId, ActionFlags::Drawcall, commandBuffer); - } + m_ActionCallback->PostRedraw(eventId, ActionFlags::Drawcall, commandBuffer); } } - } - else - { - ObjDisp(commandBuffer) - ->CmdDrawIndexed(Unwrap(commandBuffer), indexCount, instanceCount, firstIndex, - vertexOffset, firstInstance); + + if(loading) { AddEvent(); @@ -754,7 +742,7 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndirect(SerialiserType &ser, VkCommandBu VulkanEventNode &eventNode = GetLastEventNode(); eventNode.indirectPatch = indirectPatch; - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(buffer), ResourceUsage::Indirect)); + eventNode.AddResourceUsage(GetResID(buffer), ResourceUsage::Indirect); return true; } @@ -774,7 +762,7 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndirect(SerialiserType &ser, VkCommandBu VulkanEventNode &eventNode = GetLastEventNode(); eventNode.indirectPatch = indirectPatch; - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(buffer), ResourceUsage::Indirect)); + eventNode.AddResourceUsage(GetResID(buffer), ResourceUsage::Indirect); for(uint32_t i = 0; i < count; i++) { @@ -1113,7 +1101,7 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndexedIndirect(SerialiserType &ser, VulkanEventNode &eventNode = GetLastEventNode(); eventNode.indirectPatch = indirectPatch; - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(buffer), ResourceUsage::Indirect)); + eventNode.AddResourceUsage(GetResID(buffer), ResourceUsage::Indirect); return true; } @@ -1134,7 +1122,7 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndexedIndirect(SerialiserType &ser, VulkanEventNode &eventNode = GetLastEventNode(); eventNode.indirectPatch = indirectPatch; - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(buffer), ResourceUsage::Indirect)); + eventNode.AddResourceUsage(GetResID(buffer), ResourceUsage::Indirect); for(uint32_t i = 0; i < count; i++) { @@ -1227,31 +1215,26 @@ bool WrappedVulkan::Serialise_vkCmdDispatch(SerialiserType &ser, VkCommandBuffer { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - if(!IsActionDisabled()) - { - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Dispatch); + if(loading || !IsActionDisabled()) + { + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, ActionFlags::Dispatch) : 0; - ObjDisp(commandBuffer)->CmdDispatch(Unwrap(commandBuffer), x, y, z); + ObjDisp(commandBuffer)->CmdDispatch(Unwrap(commandBuffer), x, y, z); - if(eventId && - m_ActionCallback->PostDispatch(eventId, ActionFlags::Dispatch, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdDispatch(Unwrap(commandBuffer), x, y, z); - m_ActionCallback->PostRedispatch(eventId, ActionFlags::Dispatch, commandBuffer); - } + if(eventId && m_ActionCallback->PostDispatch(eventId, ActionFlags::Dispatch, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdDispatch(Unwrap(commandBuffer), x, y, z); + m_ActionCallback->PostRedispatch(eventId, ActionFlags::Dispatch, commandBuffer); } } - } - else - { - ObjDisp(commandBuffer)->CmdDispatch(Unwrap(commandBuffer), x, y, z); + if(loading) { AddEvent(); @@ -1307,30 +1290,29 @@ bool WrappedVulkan::Serialise_vkCmdDispatchIndirect(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Dispatch); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Dispatch)) : 0; - ObjDisp(commandBuffer)->CmdDispatchIndirect(Unwrap(commandBuffer), Unwrap(buffer), offset); - - if(eventId && m_ActionCallback->PostDispatch(eventId, ActionFlags::Dispatch, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdDispatchIndirect(Unwrap(commandBuffer), Unwrap(buffer), offset); - m_ActionCallback->PostRedispatch(eventId, ActionFlags::Dispatch, commandBuffer); - } - } - } - else - { - VkIndirectPatchData indirectPatch = - FetchIndirectData(VkIndirectPatchType::DispatchIndirect, commandBuffer, buffer, offset, 1); + VkIndirectPatchData indirectPatch; + if(loading) + indirectPatch = FetchIndirectData(VkIndirectPatchType::DispatchIndirect, commandBuffer, + buffer, offset, 1); ObjDisp(commandBuffer)->CmdDispatchIndirect(Unwrap(commandBuffer), Unwrap(buffer), offset); + if(eventId && m_ActionCallback->PostDispatch(eventId, ActionFlags::Dispatch, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdDispatchIndirect(Unwrap(commandBuffer), Unwrap(buffer), offset); + m_ActionCallback->PostRedispatch(eventId, ActionFlags::Dispatch, commandBuffer); + } + + if(loading) { AddEvent(); @@ -1346,7 +1328,7 @@ bool WrappedVulkan::Serialise_vkCmdDispatchIndirect(SerialiserType &ser, VulkanEventNode &eventNode = GetLastEventNode(); eventNode.indirectPatch = indirectPatch; - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(buffer), ResourceUsage::Indirect)); + eventNode.AddResourceUsage(GetResID(buffer), ResourceUsage::Indirect); } } } @@ -1403,34 +1385,28 @@ bool WrappedVulkan::Serialise_vkCmdBlitImage(SerialiserType &ser, VkCommandBuffe { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Resolve); + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, ActionFlags::Resolve) : 0; + ObjDisp(commandBuffer) + ->CmdBlitImage(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, Unwrap(destImage), + destImageLayout, regionCount, pRegions, filter); + + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Resolve, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdBlitImage(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, Unwrap(destImage), destImageLayout, regionCount, pRegions, filter); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Resolve, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdBlitImage(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, - Unwrap(destImage), destImageLayout, regionCount, pRegions, filter); - - m_ActionCallback->PostRemisc(eventId, ActionFlags::Resolve, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Resolve, commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdBlitImage(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, Unwrap(destImage), - destImageLayout, regionCount, pRegions, filter); + if(loading) { AddEvent(); @@ -1456,14 +1432,12 @@ bool WrappedVulkan::Serialise_vkCmdBlitImage(SerialiserType &ser, VkCommandBuffe VulkanEventNode &eventNode = GetLastEventNode(); if(srcImage == destImage) { - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(srcImage), ResourceUsage::Resolve)); + eventNode.AddResourceUsage(GetResID(srcImage), ResourceUsage::Resolve); } else { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(srcImage), ResourceUsage::ResolveSrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(destImage), ResourceUsage::ResolveDst)); + eventNode.AddResourceUsage(GetResID(srcImage), ResourceUsage::ResolveSrc); + eventNode.AddResourceUsage(GetResID(destImage), ResourceUsage::ResolveDst); } } } @@ -1548,34 +1522,28 @@ bool WrappedVulkan::Serialise_vkCmdResolveImage(SerialiserType &ser, VkCommandBu { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Resolve); + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, ActionFlags::Resolve) : 0; + + ObjDisp(commandBuffer) + ->CmdResolveImage(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, + Unwrap(destImage), destImageLayout, regionCount, pRegions); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Resolve, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdResolveImage(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, Unwrap(destImage), destImageLayout, regionCount, pRegions); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Resolve, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdResolveImage(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, - Unwrap(destImage), destImageLayout, regionCount, pRegions); - - m_ActionCallback->PostRemisc(eventId, ActionFlags::Resolve, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Resolve, commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdResolveImage(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, - Unwrap(destImage), destImageLayout, regionCount, pRegions); + if(loading) { AddEvent(); @@ -1601,14 +1569,12 @@ bool WrappedVulkan::Serialise_vkCmdResolveImage(SerialiserType &ser, VkCommandBu VulkanEventNode &eventNode = GetLastEventNode(); if(srcImage == destImage) { - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(srcImage), ResourceUsage::Resolve)); + eventNode.AddResourceUsage(GetResID(srcImage), ResourceUsage::Resolve); } else { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(srcImage), ResourceUsage::ResolveSrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(destImage), ResourceUsage::ResolveDst)); + eventNode.AddResourceUsage(GetResID(srcImage), ResourceUsage::ResolveSrc); + eventNode.AddResourceUsage(GetResID(destImage), ResourceUsage::ResolveDst); } } } @@ -1682,34 +1648,28 @@ bool WrappedVulkan::Serialise_vkCmdCopyImage(SerialiserType &ser, VkCommandBuffe { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Copy); + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, ActionFlags::Copy) : 0; + ObjDisp(commandBuffer) + ->CmdCopyImage(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, Unwrap(destImage), + destImageLayout, regionCount, pRegions); + + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdCopyImage(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, Unwrap(destImage), destImageLayout, regionCount, pRegions); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdCopyImage(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, - Unwrap(destImage), destImageLayout, regionCount, pRegions); - - m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdCopyImage(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, Unwrap(destImage), - destImageLayout, regionCount, pRegions); + if(loading) { AddEvent(); @@ -1736,12 +1696,12 @@ bool WrappedVulkan::Serialise_vkCmdCopyImage(SerialiserType &ser, VkCommandBuffe VulkanEventNode &eventNode = GetLastEventNode(); if(srcImage == destImage) { - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(srcImage), ResourceUsage::Copy)); + eventNode.AddResourceUsage(GetResID(srcImage), ResourceUsage::Copy); } else { - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(srcImage), ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(destImage), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(srcImage), ResourceUsage::CopySrc); + eventNode.AddResourceUsage(GetResID(destImage), ResourceUsage::CopyDst); } } } @@ -1811,34 +1771,28 @@ bool WrappedVulkan::Serialise_vkCmdCopyBufferToImage( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Copy); + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, ActionFlags::Copy) : 0; + ObjDisp(commandBuffer) + ->CmdCopyBufferToImage(Unwrap(commandBuffer), Unwrap(srcBuffer), Unwrap(destImage), + destImageLayout, regionCount, pRegions); + + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdCopyBufferToImage(Unwrap(commandBuffer), Unwrap(srcBuffer), Unwrap(destImage), destImageLayout, regionCount, pRegions); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdCopyBufferToImage(Unwrap(commandBuffer), Unwrap(srcBuffer), Unwrap(destImage), - destImageLayout, regionCount, pRegions); - - m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdCopyBufferToImage(Unwrap(commandBuffer), Unwrap(srcBuffer), Unwrap(destImage), - destImageLayout, regionCount, pRegions); + if(loading) { AddEvent(); @@ -1859,8 +1813,8 @@ bool WrappedVulkan::Serialise_vkCmdCopyBufferToImage( AddAction(action); VulkanEventNode &eventNode = GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(srcBuffer), ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(destImage), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(srcBuffer), ResourceUsage::CopySrc); + eventNode.AddResourceUsage(GetResID(destImage), ResourceUsage::CopyDst); } } } @@ -1919,34 +1873,28 @@ bool WrappedVulkan::Serialise_vkCmdCopyImageToBuffer(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Copy); + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, ActionFlags::Copy) : 0; + + ObjDisp(commandBuffer) + ->CmdCopyImageToBuffer(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, + Unwrap(destBuffer), regionCount, pRegions); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdCopyImageToBuffer(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, Unwrap(destBuffer), regionCount, pRegions); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdCopyImageToBuffer(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, - Unwrap(destBuffer), regionCount, pRegions); - - m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdCopyImageToBuffer(Unwrap(commandBuffer), Unwrap(srcImage), srcImageLayout, - Unwrap(destBuffer), regionCount, pRegions); + if(loading) { AddEvent(); @@ -1967,8 +1915,8 @@ bool WrappedVulkan::Serialise_vkCmdCopyImageToBuffer(SerialiserType &ser, AddAction(action); VulkanEventNode &eventNode = GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(srcImage), ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(destBuffer), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(srcImage), ResourceUsage::CopySrc); + eventNode.AddResourceUsage(GetResID(destBuffer), ResourceUsage::CopyDst); } } } @@ -2024,34 +1972,28 @@ bool WrappedVulkan::Serialise_vkCmdCopyBuffer(SerialiserType &ser, VkCommandBuff { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Copy); + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, ActionFlags::Copy) : 0; + + ObjDisp(commandBuffer) + ->CmdCopyBuffer(Unwrap(commandBuffer), Unwrap(srcBuffer), Unwrap(destBuffer), regionCount, + pRegions); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdCopyBuffer(Unwrap(commandBuffer), Unwrap(srcBuffer), Unwrap(destBuffer), regionCount, pRegions); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdCopyBuffer(Unwrap(commandBuffer), Unwrap(srcBuffer), Unwrap(destBuffer), - regionCount, pRegions); - - m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdCopyBuffer(Unwrap(commandBuffer), Unwrap(srcBuffer), Unwrap(destBuffer), regionCount, - pRegions); + if(loading) { AddEvent(); @@ -2071,13 +2013,12 @@ bool WrappedVulkan::Serialise_vkCmdCopyBuffer(SerialiserType &ser, VkCommandBuff VulkanEventNode &eventNode = GetLastEventNode(); if(srcBuffer == destBuffer) { - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(srcBuffer), ResourceUsage::Copy)); + eventNode.AddResourceUsage(GetResID(srcBuffer), ResourceUsage::Copy); } else { - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(srcBuffer), ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(destBuffer), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(srcBuffer), ResourceUsage::CopySrc); + eventNode.AddResourceUsage(GetResID(destBuffer), ResourceUsage::CopyDst); } } } @@ -2139,32 +2080,26 @@ bool WrappedVulkan::Serialise_vkCmdUpdateBuffer(SerialiserType &ser, VkCommandBu { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Copy); + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, ActionFlags::Copy) : 0; + + ObjDisp(commandBuffer) + ->CmdUpdateBuffer(Unwrap(commandBuffer), Unwrap(destBuffer), destOffset, dataSize, Data); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdUpdateBuffer(Unwrap(commandBuffer), Unwrap(destBuffer), destOffset, dataSize, Data); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdUpdateBuffer(Unwrap(commandBuffer), Unwrap(destBuffer), destOffset, dataSize, - Data); - - m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdUpdateBuffer(Unwrap(commandBuffer), Unwrap(destBuffer), destOffset, dataSize, Data); + if(loading) { AddEvent(); @@ -2178,7 +2113,7 @@ bool WrappedVulkan::Serialise_vkCmdUpdateBuffer(SerialiserType &ser, VkCommandBu AddAction(action); VulkanEventNode &eventNode = GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(destBuffer), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(destBuffer), ResourceUsage::CopyDst); } } } @@ -2232,31 +2167,26 @@ bool WrappedVulkan::Serialise_vkCmdFillBuffer(SerialiserType &ser, VkCommandBuff { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Clear); + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, ActionFlags::Clear) : 0; + + ObjDisp(commandBuffer) + ->CmdFillBuffer(Unwrap(commandBuffer), Unwrap(destBuffer), destOffset, fillSize, data); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Clear, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdFillBuffer(Unwrap(commandBuffer), Unwrap(destBuffer), destOffset, fillSize, data); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Clear, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdFillBuffer(Unwrap(commandBuffer), Unwrap(destBuffer), destOffset, fillSize, data); - - m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdFillBuffer(Unwrap(commandBuffer), Unwrap(destBuffer), destOffset, fillSize, data); + if(loading) { AddEvent(); @@ -2270,7 +2200,7 @@ bool WrappedVulkan::Serialise_vkCmdFillBuffer(SerialiserType &ser, VkCommandBuff AddAction(action); VulkanEventNode &eventNode = GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(destBuffer), ResourceUsage::Clear)); + eventNode.AddResourceUsage(GetResID(destBuffer), ResourceUsage::Clear); } } } @@ -2326,38 +2256,31 @@ bool WrappedVulkan::Serialise_vkCmdClearColorImage(SerialiserType &ser, VkComman { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback( - commandBuffer, ActionFlags(ActionFlags::Clear | ActionFlags::ClearColor)); + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer, ActionFlags::ClearColor) : 0; + + ObjDisp(commandBuffer) + ->CmdClearColorImage(Unwrap(commandBuffer), Unwrap(image), imageLayout, &Color, + rangeCount, pRanges); + if(eventId && + m_ActionCallback->PostMisc( + eventId, ActionFlags(ActionFlags::Clear | ActionFlags::ClearColor), commandBuffer)) + { ObjDisp(commandBuffer) ->CmdClearColorImage(Unwrap(commandBuffer), Unwrap(image), imageLayout, &Color, rangeCount, pRanges); - if(eventId && - m_ActionCallback->PostMisc( - eventId, ActionFlags(ActionFlags::Clear | ActionFlags::ClearColor), commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdClearColorImage(Unwrap(commandBuffer), Unwrap(image), imageLayout, &Color, - rangeCount, pRanges); - - m_ActionCallback->PostRemisc( - eventId, ActionFlags(ActionFlags::Clear | ActionFlags::ClearColor), commandBuffer); - } + m_ActionCallback->PostRemisc( + eventId, ActionFlags(ActionFlags::Clear | ActionFlags::ClearColor), commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdClearColorImage(Unwrap(commandBuffer), Unwrap(image), imageLayout, &Color, - rangeCount, pRanges); + if(loading) { AddEvent(); @@ -2372,7 +2295,7 @@ bool WrappedVulkan::Serialise_vkCmdClearColorImage(SerialiserType &ser, VkComman AddAction(action); VulkanEventNode &eventNode = GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(image), ResourceUsage::Clear)); + eventNode.AddResourceUsage(GetResID(image), ResourceUsage::Clear); } } } @@ -2435,39 +2358,35 @@ bool WrappedVulkan::Serialise_vkCmdClearDepthStencilImage( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback( - commandBuffer, ActionFlags(ActionFlags::Clear | ActionFlags::ClearDepthStencil)); + uint32_t eventId = + !loading + ? HandlePreCallback(commandBuffer, + ActionFlags(ActionFlags::Clear | ActionFlags::ClearDepthStencil)) + : 0; + + ObjDisp(commandBuffer) + ->CmdClearDepthStencilImage(Unwrap(commandBuffer), Unwrap(image), imageLayout, + &DepthStencil, rangeCount, pRanges); + if(eventId && m_ActionCallback->PostMisc( + eventId, ActionFlags(ActionFlags::Clear | ActionFlags::ClearDepthStencil), + commandBuffer)) + { ObjDisp(commandBuffer) ->CmdClearDepthStencilImage(Unwrap(commandBuffer), Unwrap(image), imageLayout, &DepthStencil, rangeCount, pRanges); - if(eventId && m_ActionCallback->PostMisc( - eventId, ActionFlags(ActionFlags::Clear | ActionFlags::ClearDepthStencil), - commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdClearDepthStencilImage(Unwrap(commandBuffer), Unwrap(image), imageLayout, - &DepthStencil, rangeCount, pRanges); - - m_ActionCallback->PostRemisc( - eventId, ActionFlags(ActionFlags::Clear | ActionFlags::ClearDepthStencil), - commandBuffer); - } + m_ActionCallback->PostRemisc( + eventId, ActionFlags(ActionFlags::Clear | ActionFlags::ClearDepthStencil), commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdClearDepthStencilImage(Unwrap(commandBuffer), Unwrap(image), imageLayout, - &DepthStencil, rangeCount, pRanges); + if(loading) { AddEvent(); @@ -2482,7 +2401,7 @@ bool WrappedVulkan::Serialise_vkCmdClearDepthStencilImage( AddAction(action); VulkanEventNode &eventNode = GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(image), ResourceUsage::Clear)); + eventNode.AddResourceUsage(GetResID(image), ResourceUsage::Clear); } } } @@ -2549,35 +2468,30 @@ bool WrappedVulkan::Serialise_vkCmdClearAttachments(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Clear)); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Clear)) : 0; + + ObjDisp(commandBuffer) + ->CmdClearAttachments(Unwrap(commandBuffer), attachmentCount, pAttachments, rectCount, + pRects); + if(eventId && + m_ActionCallback->PostMisc(eventId, ActionFlags(ActionFlags::Clear), commandBuffer)) + { ObjDisp(commandBuffer) ->CmdClearAttachments(Unwrap(commandBuffer), attachmentCount, pAttachments, rectCount, pRects); - if(eventId && - m_ActionCallback->PostMisc(eventId, ActionFlags(ActionFlags::Clear), commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdClearAttachments(Unwrap(commandBuffer), attachmentCount, pAttachments, rectCount, - pRects); - - m_ActionCallback->PostRemisc(eventId, ActionFlags(ActionFlags::Clear), commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags(ActionFlags::Clear), commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdClearAttachments(Unwrap(commandBuffer), attachmentCount, pAttachments, rectCount, - pRects); + if(loading) { AddEvent(); @@ -2613,9 +2527,9 @@ bool WrappedVulkan::Serialise_vkCmdClearAttachments(SerialiserType &ser, att = rp.subpasses[state.subpass].colorAttachments[att]; if(att < (uint32_t)state.GetFramebufferAttachments().size()) { - eventNode.resourceUsage.push_back(make_rdcpair( + eventNode.AddResourceUsage( m_CreationInfo.m_ImageView[state.GetFramebufferAttachments()[att]].image, - ResourceUsage::Clear)); + ResourceUsage::Clear); } } } @@ -2625,9 +2539,9 @@ bool WrappedVulkan::Serialise_vkCmdClearAttachments(SerialiserType &ser, if(rp.subpasses[state.subpass].depthstencilAttachment >= 0) { att = (uint32_t)rp.subpasses[state.subpass].depthstencilAttachment; - eventNode.resourceUsage.push_back(make_rdcpair( + eventNode.AddResourceUsage( m_CreationInfo.m_ImageView[state.GetFramebufferAttachments()[att]].image, - ResourceUsage::Clear)); + ResourceUsage::Clear); } } } @@ -2638,23 +2552,22 @@ bool WrappedVulkan::Serialise_vkCmdClearAttachments(SerialiserType &ser, for(size_t a = 0; a < dyn.color.size(); a++) { - eventNode.resourceUsage.push_back( - make_rdcpair(m_CreationInfo.m_ImageView[GetResID(dyn.color[a].imageView)].image, - ResourceUsage::Clear)); + eventNode.AddResourceUsage( + m_CreationInfo.m_ImageView[GetResID(dyn.color[a].imageView)].image, + ResourceUsage::Clear); } if(dyn.depth.imageView != VK_NULL_HANDLE) { - eventNode.resourceUsage.push_back( - make_rdcpair(m_CreationInfo.m_ImageView[GetResID(dyn.depth.imageView)].image, - ResourceUsage::Clear)); + eventNode.AddResourceUsage(m_CreationInfo.m_ImageView[GetResID(dyn.depth.imageView)].image, + ResourceUsage::Clear); } if(dyn.stencil.imageView != VK_NULL_HANDLE && dyn.depth.imageView != dyn.stencil.imageView) { - eventNode.resourceUsage.push_back( - make_rdcpair(m_CreationInfo.m_ImageView[GetResID(dyn.stencil.imageView)].image, - ResourceUsage::Clear)); + eventNode.AddResourceUsage( + m_CreationInfo.m_ImageView[GetResID(dyn.stencil.imageView)].image, + ResourceUsage::Clear); } } } @@ -2714,33 +2627,28 @@ bool WrappedVulkan::Serialise_vkCmdDispatchBase(SerialiserType &ser, VkCommandBu { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Dispatch); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Dispatch)) : 0; + ObjDisp(commandBuffer) + ->CmdDispatchBase(Unwrap(commandBuffer), baseGroupX, baseGroupY, baseGroupZ, groupCountX, + groupCountY, groupCountZ); + + if(eventId && m_ActionCallback->PostDispatch(eventId, ActionFlags::Dispatch, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdDispatchBase(Unwrap(commandBuffer), baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ); - - if(eventId && m_ActionCallback->PostDispatch(eventId, ActionFlags::Dispatch, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdDispatchBase(Unwrap(commandBuffer), baseGroupX, baseGroupY, baseGroupZ, - groupCountX, groupCountY, groupCountZ); - m_ActionCallback->PostRedispatch(eventId, ActionFlags::Dispatch, commandBuffer); - } + m_ActionCallback->PostRedispatch(eventId, ActionFlags::Dispatch, commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdDispatchBase(Unwrap(commandBuffer), baseGroupX, baseGroupY, baseGroupZ, groupCountX, - groupCountY, groupCountZ); + if(loading) { AddEvent(); @@ -3014,8 +2922,8 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndirectCount(SerialiserType &ser, VulkanEventNode &eventNode = GetLastEventNode(); eventNode.indirectPatch = indirectPatch; - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(buffer), ResourceUsage::Indirect)); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(countBuffer), ResourceUsage::Indirect)); + eventNode.AddResourceUsage(GetResID(buffer), ResourceUsage::Indirect); + eventNode.AddResourceUsage(GetResID(countBuffer), ResourceUsage::Indirect); if(maxDrawCount > 0) eventNode.action.flags = flags; @@ -3321,8 +3229,8 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndexedIndirectCount( VulkanEventNode &eventNode = GetLastEventNode(); eventNode.indirectPatch = indirectPatch; - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(buffer), ResourceUsage::Indirect)); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(countBuffer), ResourceUsage::Indirect)); + eventNode.AddResourceUsage(GetResID(buffer), ResourceUsage::Indirect); + eventNode.AddResourceUsage(GetResID(countBuffer), ResourceUsage::Indirect); if(maxDrawCount > 0) eventNode.action.flags = flags; @@ -3472,8 +3380,7 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndirectByteCountEXT( VulkanEventNode &eventNode = GetLastEventNode(); eventNode.indirectPatch = indirectPatch; - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(counterBuffer), ResourceUsage::Indirect)); + eventNode.AddResourceUsage(GetResID(counterBuffer), ResourceUsage::Indirect); return true; } @@ -3528,38 +3435,35 @@ bool WrappedVulkan::Serialise_vkCmdCopyBuffer2(SerialiserType &ser, VkCommandBuf if(IsReplayingAndReading()) { - VkCopyBufferInfo2 unwrappedInfo = CopyInfo; - unwrappedInfo.srcBuffer = Unwrap(unwrappedInfo.srcBuffer); - unwrappedInfo.dstBuffer = Unwrap(unwrappedInfo.dstBuffer); - - byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); - - UnwrapNextChain(m_State, "VkCopyBufferInfo2", tempMem, (VkBaseInStructure *)&unwrappedInfo); - m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Copy); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Copy)) : 0; - ObjDisp(commandBuffer)->CmdCopyBuffer2(Unwrap(commandBuffer), &unwrappedInfo); + VkCopyBufferInfo2 unwrappedInfo = CopyInfo; + unwrappedInfo.srcBuffer = Unwrap(unwrappedInfo.srcBuffer); + unwrappedInfo.dstBuffer = Unwrap(unwrappedInfo.dstBuffer); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdCopyBuffer2(Unwrap(commandBuffer), &unwrappedInfo); + byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); + + UnwrapNextChain(m_State, "VkCopyBufferInfo2", tempMem, (VkBaseInStructure *)&unwrappedInfo); - m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); - } - } - } - else - { ObjDisp(commandBuffer)->CmdCopyBuffer2(Unwrap(commandBuffer), &unwrappedInfo); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdCopyBuffer2(Unwrap(commandBuffer), &unwrappedInfo); + + m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); + } + + if(loading) { AddEvent(); @@ -3579,15 +3483,12 @@ bool WrappedVulkan::Serialise_vkCmdCopyBuffer2(SerialiserType &ser, VkCommandBuf VulkanEventNode &eventNode = GetLastEventNode(); if(srcid == dstid) { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(CopyInfo.srcBuffer), ResourceUsage::Copy)); + eventNode.AddResourceUsage(GetResID(CopyInfo.srcBuffer), ResourceUsage::Copy); } else { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(CopyInfo.srcBuffer), ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(CopyInfo.dstBuffer), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(CopyInfo.srcBuffer), ResourceUsage::CopySrc); + eventNode.AddResourceUsage(GetResID(CopyInfo.dstBuffer), ResourceUsage::CopyDst); } } } @@ -3648,38 +3549,35 @@ bool WrappedVulkan::Serialise_vkCmdCopyImage2(SerialiserType &ser, VkCommandBuff if(IsReplayingAndReading()) { - VkCopyImageInfo2 unwrappedInfo = CopyInfo; - unwrappedInfo.srcImage = Unwrap(unwrappedInfo.srcImage); - unwrappedInfo.dstImage = Unwrap(unwrappedInfo.dstImage); - - byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); - - UnwrapNextChain(m_State, "VkCopyImageInfo2", tempMem, (VkBaseInStructure *)&unwrappedInfo); - m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Copy); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Copy)) : 0; - ObjDisp(commandBuffer)->CmdCopyImage2(Unwrap(commandBuffer), &unwrappedInfo); + VkCopyImageInfo2 unwrappedInfo = CopyInfo; + unwrappedInfo.srcImage = Unwrap(unwrappedInfo.srcImage); + unwrappedInfo.dstImage = Unwrap(unwrappedInfo.dstImage); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdCopyImage2(Unwrap(commandBuffer), &unwrappedInfo); + byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); + + UnwrapNextChain(m_State, "VkCopyImageInfo2", tempMem, (VkBaseInStructure *)&unwrappedInfo); - m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); - } - } - } - else - { ObjDisp(commandBuffer)->CmdCopyImage2(Unwrap(commandBuffer), &unwrappedInfo); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdCopyImage2(Unwrap(commandBuffer), &unwrappedInfo); + + m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); + } + + if(loading) { AddEvent(); @@ -3699,15 +3597,12 @@ bool WrappedVulkan::Serialise_vkCmdCopyImage2(SerialiserType &ser, VkCommandBuff VulkanEventNode &eventNode = GetLastEventNode(); if(srcid == dstid) { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(CopyInfo.srcImage), ResourceUsage::Copy)); + eventNode.AddResourceUsage(GetResID(CopyInfo.srcImage), ResourceUsage::Copy); } else { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(CopyInfo.srcImage), ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(CopyInfo.dstImage), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(CopyInfo.srcImage), ResourceUsage::CopySrc); + eventNode.AddResourceUsage(GetResID(CopyInfo.dstImage), ResourceUsage::CopyDst); } } } @@ -3776,39 +3671,36 @@ bool WrappedVulkan::Serialise_vkCmdCopyBufferToImage2( if(IsReplayingAndReading()) { - VkCopyBufferToImageInfo2 unwrappedInfo = CopyInfo; - unwrappedInfo.srcBuffer = Unwrap(unwrappedInfo.srcBuffer); - unwrappedInfo.dstImage = Unwrap(unwrappedInfo.dstImage); - - byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); - - UnwrapNextChain(m_State, "VkCopyBufferToImageInfo2", tempMem, - (VkBaseInStructure *)&unwrappedInfo); - m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Copy); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Copy)) : 0; - ObjDisp(commandBuffer)->CmdCopyBufferToImage2(Unwrap(commandBuffer), &unwrappedInfo); + VkCopyBufferToImageInfo2 unwrappedInfo = CopyInfo; + unwrappedInfo.srcBuffer = Unwrap(unwrappedInfo.srcBuffer); + unwrappedInfo.dstImage = Unwrap(unwrappedInfo.dstImage); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdCopyBufferToImage2(Unwrap(commandBuffer), &unwrappedInfo); + byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); + + UnwrapNextChain(m_State, "VkCopyBufferToImageInfo2", tempMem, + (VkBaseInStructure *)&unwrappedInfo); - m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); - } - } - } - else - { ObjDisp(commandBuffer)->CmdCopyBufferToImage2(Unwrap(commandBuffer), &unwrappedInfo); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdCopyBufferToImage2(Unwrap(commandBuffer), &unwrappedInfo); + + m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); + } + + if(loading) { AddEvent(); @@ -3830,10 +3722,8 @@ bool WrappedVulkan::Serialise_vkCmdCopyBufferToImage2( AddAction(action); VulkanEventNode &eventNode = GetLastEventNode(); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(CopyInfo.srcBuffer), ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(CopyInfo.dstImage), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(CopyInfo.srcBuffer), ResourceUsage::CopySrc); + eventNode.AddResourceUsage(GetResID(CopyInfo.dstImage), ResourceUsage::CopyDst); } } } @@ -3905,39 +3795,36 @@ bool WrappedVulkan::Serialise_vkCmdCopyImageToBuffer2( if(IsReplayingAndReading()) { - VkCopyImageToBufferInfo2 unwrappedInfo = CopyInfo; - unwrappedInfo.srcImage = Unwrap(unwrappedInfo.srcImage); - unwrappedInfo.dstBuffer = Unwrap(unwrappedInfo.dstBuffer); - - byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); - - UnwrapNextChain(m_State, "VkCopyImageToBufferInfo2", tempMem, - (VkBaseInStructure *)&unwrappedInfo); - m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Copy); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Copy)) : 0; - ObjDisp(commandBuffer)->CmdCopyImageToBuffer2(Unwrap(commandBuffer), &unwrappedInfo); + VkCopyImageToBufferInfo2 unwrappedInfo = CopyInfo; + unwrappedInfo.srcImage = Unwrap(unwrappedInfo.srcImage); + unwrappedInfo.dstBuffer = Unwrap(unwrappedInfo.dstBuffer); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdCopyImageToBuffer2(Unwrap(commandBuffer), &unwrappedInfo); + byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); + + UnwrapNextChain(m_State, "VkCopyImageToBufferInfo2", tempMem, + (VkBaseInStructure *)&unwrappedInfo); - m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); - } - } - } - else - { ObjDisp(commandBuffer)->CmdCopyImageToBuffer2(Unwrap(commandBuffer), &unwrappedInfo); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdCopyImageToBuffer2(Unwrap(commandBuffer), &unwrappedInfo); + + m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); + } + + if(loading) { AddEvent(); @@ -3959,10 +3846,8 @@ bool WrappedVulkan::Serialise_vkCmdCopyImageToBuffer2( AddAction(action); VulkanEventNode &eventNode = GetLastEventNode(); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(CopyInfo.srcImage), ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(CopyInfo.dstBuffer), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(CopyInfo.srcImage), ResourceUsage::CopySrc); + eventNode.AddResourceUsage(GetResID(CopyInfo.dstBuffer), ResourceUsage::CopyDst); } } } @@ -4033,38 +3918,35 @@ bool WrappedVulkan::Serialise_vkCmdBlitImage2(SerialiserType &ser, VkCommandBuff if(IsReplayingAndReading()) { - VkBlitImageInfo2 unwrappedInfo = BlitInfo; - unwrappedInfo.srcImage = Unwrap(unwrappedInfo.srcImage); - unwrappedInfo.dstImage = Unwrap(unwrappedInfo.dstImage); - - byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); - - UnwrapNextChain(m_State, "VkBlitImageInfo2", tempMem, (VkBaseInStructure *)&unwrappedInfo); - m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Resolve); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Resolve)) : 0; - ObjDisp(commandBuffer)->CmdBlitImage2(Unwrap(commandBuffer), &unwrappedInfo); + VkBlitImageInfo2 unwrappedInfo = BlitInfo; + unwrappedInfo.srcImage = Unwrap(unwrappedInfo.srcImage); + unwrappedInfo.dstImage = Unwrap(unwrappedInfo.dstImage); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Resolve, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdBlitImage2(Unwrap(commandBuffer), &unwrappedInfo); + byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); + + UnwrapNextChain(m_State, "VkBlitImageInfo2", tempMem, (VkBaseInStructure *)&unwrappedInfo); - m_ActionCallback->PostRemisc(eventId, ActionFlags::Resolve, commandBuffer); - } - } - } - else - { ObjDisp(commandBuffer)->CmdBlitImage2(Unwrap(commandBuffer), &unwrappedInfo); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Resolve, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdBlitImage2(Unwrap(commandBuffer), &unwrappedInfo); + + m_ActionCallback->PostRemisc(eventId, ActionFlags::Resolve, commandBuffer); + } + + if(loading) { AddEvent(); @@ -4084,15 +3966,12 @@ bool WrappedVulkan::Serialise_vkCmdBlitImage2(SerialiserType &ser, VkCommandBuff VulkanEventNode &eventNode = GetLastEventNode(); if(srcid == dstid) { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(BlitInfo.srcImage), ResourceUsage::Resolve)); + eventNode.AddResourceUsage(GetResID(BlitInfo.srcImage), ResourceUsage::Resolve); } else { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(BlitInfo.srcImage), ResourceUsage::ResolveSrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(BlitInfo.dstImage), ResourceUsage::ResolveDst)); + eventNode.AddResourceUsage(GetResID(BlitInfo.srcImage), ResourceUsage::ResolveSrc); + eventNode.AddResourceUsage(GetResID(BlitInfo.dstImage), ResourceUsage::ResolveDst); } } } @@ -4170,38 +4049,35 @@ bool WrappedVulkan::Serialise_vkCmdResolveImage2(SerialiserType &ser, VkCommandB if(IsReplayingAndReading()) { - VkResolveImageInfo2 unwrappedInfo = ResolveInfo; - unwrappedInfo.srcImage = Unwrap(unwrappedInfo.srcImage); - unwrappedInfo.dstImage = Unwrap(unwrappedInfo.dstImage); - - byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); - - UnwrapNextChain(m_State, "VkResolveImageInfo2", tempMem, (VkBaseInStructure *)&unwrappedInfo); - m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Resolve); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Resolve)) : 0; - ObjDisp(commandBuffer)->CmdResolveImage2(Unwrap(commandBuffer), &unwrappedInfo); + VkResolveImageInfo2 unwrappedInfo = ResolveInfo; + unwrappedInfo.srcImage = Unwrap(unwrappedInfo.srcImage); + unwrappedInfo.dstImage = Unwrap(unwrappedInfo.dstImage); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Resolve, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdResolveImage2(Unwrap(commandBuffer), &unwrappedInfo); + byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); + + UnwrapNextChain(m_State, "VkResolveImageInfo2", tempMem, (VkBaseInStructure *)&unwrappedInfo); - m_ActionCallback->PostRemisc(eventId, ActionFlags::Resolve, commandBuffer); - } - } - } - else - { ObjDisp(commandBuffer)->CmdResolveImage2(Unwrap(commandBuffer), &unwrappedInfo); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Resolve, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdResolveImage2(Unwrap(commandBuffer), &unwrappedInfo); + + m_ActionCallback->PostRemisc(eventId, ActionFlags::Resolve, commandBuffer); + } + + if(loading) { AddEvent(); @@ -4221,15 +4097,12 @@ bool WrappedVulkan::Serialise_vkCmdResolveImage2(SerialiserType &ser, VkCommandB VulkanEventNode &eventNode = GetLastEventNode(); if(srcid == dstid) { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(ResolveInfo.srcImage), ResourceUsage::Resolve)); + eventNode.AddResourceUsage(GetResID(ResolveInfo.srcImage), ResourceUsage::Resolve); } else { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(ResolveInfo.srcImage), ResourceUsage::ResolveSrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(ResolveInfo.dstImage), ResourceUsage::ResolveDst)); + eventNode.AddResourceUsage(GetResID(ResolveInfo.srcImage), ResourceUsage::ResolveSrc); + eventNode.AddResourceUsage(GetResID(ResolveInfo.dstImage), ResourceUsage::ResolveDst); } } } @@ -4304,30 +4177,26 @@ bool WrappedVulkan::Serialise_vkCmdDrawMeshTasksEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::MeshDispatch); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::MeshDispatch)) : 0; + + ObjDisp(commandBuffer) + ->CmdDrawMeshTasksEXT(Unwrap(commandBuffer), groupCountX, groupCountY, groupCountZ); + if(eventId && m_ActionCallback->PostDraw(eventId, ActionFlags::MeshDispatch, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdDrawMeshTasksEXT(Unwrap(commandBuffer), groupCountX, groupCountY, groupCountZ); - - if(eventId && m_ActionCallback->PostDraw(eventId, ActionFlags::MeshDispatch, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdDrawMeshTasksEXT(Unwrap(commandBuffer), groupCountX, groupCountY, groupCountZ); - m_ActionCallback->PostRedraw(eventId, ActionFlags::MeshDispatch, commandBuffer); - } + m_ActionCallback->PostRedraw(eventId, ActionFlags::MeshDispatch, commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdDrawMeshTasksEXT(Unwrap(commandBuffer), groupCountX, groupCountY, groupCountZ); + if(loading) { AddEvent(); @@ -4632,7 +4501,7 @@ bool WrappedVulkan::Serialise_vkCmdDrawMeshTasksIndirectEXT(SerialiserType &ser, VulkanEventNode &eventNode = GetLastEventNode(); eventNode.indirectPatch = indirectPatch; - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(buffer), ResourceUsage::Indirect)); + eventNode.AddResourceUsage(GetResID(buffer), ResourceUsage::Indirect); return true; } @@ -4652,7 +4521,7 @@ bool WrappedVulkan::Serialise_vkCmdDrawMeshTasksIndirectEXT(SerialiserType &ser, VulkanEventNode &eventNode = GetLastEventNode(); eventNode.indirectPatch = indirectPatch; - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(buffer), ResourceUsage::Indirect)); + eventNode.AddResourceUsage(GetResID(buffer), ResourceUsage::Indirect); for(uint32_t i = 0; i < drawCount; i++) { @@ -4954,8 +4823,8 @@ bool WrappedVulkan::Serialise_vkCmdDrawMeshTasksIndirectCountEXT( VulkanEventNode &eventNode = GetLastEventNode(); eventNode.indirectPatch = indirectPatch; - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(buffer), ResourceUsage::Indirect)); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(countBuffer), ResourceUsage::Indirect)); + eventNode.AddResourceUsage(GetResID(buffer), ResourceUsage::Indirect); + eventNode.AddResourceUsage(GetResID(countBuffer), ResourceUsage::Indirect); // only allocate up to one indirect sub-command to avoid pessimistic allocation if // maxDrawCount is very high but the actual action count is low. @@ -5057,37 +4926,31 @@ bool WrappedVulkan::Serialise_vkCmdTraceRaysKHR( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::DispatchRay); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::DispatchRay)) : 0; + + ObjDisp(commandBuffer) + ->CmdTraceRaysKHR(Unwrap(commandBuffer), &RaygenShaderBindingTable, + &MissShaderBindingTable, &HitShaderBindingTable, + &CallableShaderBindingTable, width, height, depth); + if(eventId && m_ActionCallback->PostDispatch(eventId, ActionFlags::DispatchRay, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdTraceRaysKHR(Unwrap(commandBuffer), &RaygenShaderBindingTable, &MissShaderBindingTable, &HitShaderBindingTable, &CallableShaderBindingTable, width, height, depth); - if(eventId && m_ActionCallback->PostDispatch(eventId, ActionFlags::DispatchRay, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdTraceRaysKHR(Unwrap(commandBuffer), &RaygenShaderBindingTable, - &MissShaderBindingTable, &HitShaderBindingTable, - &CallableShaderBindingTable, width, height, depth); - - m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdTraceRaysKHR(Unwrap(commandBuffer), &RaygenShaderBindingTable, - &MissShaderBindingTable, &HitShaderBindingTable, - &CallableShaderBindingTable, width, height, depth); + if(loading) { AddEvent(); @@ -5161,37 +5024,31 @@ bool WrappedVulkan::Serialise_vkCmdTraceRaysIndirectKHR( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::DispatchRay); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::DispatchRay)) : 0; + + ObjDisp(commandBuffer) + ->CmdTraceRaysIndirectKHR(Unwrap(commandBuffer), &RaygenShaderBindingTable, + &MissShaderBindingTable, &HitShaderBindingTable, + &CallableShaderBindingTable, indirectDeviceAddress); + if(eventId && m_ActionCallback->PostDispatch(eventId, ActionFlags::DispatchRay, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdTraceRaysIndirectKHR(Unwrap(commandBuffer), &RaygenShaderBindingTable, &MissShaderBindingTable, &HitShaderBindingTable, &CallableShaderBindingTable, indirectDeviceAddress); - if(eventId && m_ActionCallback->PostDispatch(eventId, ActionFlags::DispatchRay, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdTraceRaysIndirectKHR(Unwrap(commandBuffer), &RaygenShaderBindingTable, - &MissShaderBindingTable, &HitShaderBindingTable, - &CallableShaderBindingTable, indirectDeviceAddress); - - m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdTraceRaysIndirectKHR(Unwrap(commandBuffer), &RaygenShaderBindingTable, - &MissShaderBindingTable, &HitShaderBindingTable, - &CallableShaderBindingTable, indirectDeviceAddress); + if(loading) { AddEvent(); @@ -5255,28 +5112,25 @@ bool WrappedVulkan::Serialise_vkCmdTraceRaysIndirect2KHR(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::DispatchRay); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::DispatchRay)) : 0; - ObjDisp(commandBuffer)->CmdTraceRaysIndirect2KHR(Unwrap(commandBuffer), indirectDeviceAddress); + ObjDisp(commandBuffer)->CmdTraceRaysIndirect2KHR(Unwrap(commandBuffer), indirectDeviceAddress); - if(eventId && m_ActionCallback->PostDispatch(eventId, ActionFlags::DispatchRay, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdTraceRaysIndirect2KHR(Unwrap(commandBuffer), indirectDeviceAddress); + if(eventId && m_ActionCallback->PostDispatch(eventId, ActionFlags::DispatchRay, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdTraceRaysIndirect2KHR(Unwrap(commandBuffer), indirectDeviceAddress); - m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, commandBuffer); } - } - else - { - ObjDisp(commandBuffer)->CmdTraceRaysIndirect2KHR(Unwrap(commandBuffer), indirectDeviceAddress); + if(loading) { AddEvent(); @@ -5340,38 +5194,35 @@ bool WrappedVulkan::Serialise_vkCmdCopyImageToMemoryKHR( if(IsReplayingAndReading()) { - VkCopyDeviceMemoryImageInfoKHR unwrappedInfo = CopyInfo; - unwrappedInfo.image = Unwrap(unwrappedInfo.image); - - byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); - - UnwrapNextChain(m_State, "VkCopyDeviceMemoryImageInfoKHR", tempMem, - (VkBaseInStructure *)&unwrappedInfo); - m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Copy); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Copy)) : 0; - ObjDisp(commandBuffer)->CmdCopyImageToMemoryKHR(Unwrap(commandBuffer), &unwrappedInfo); + VkCopyDeviceMemoryImageInfoKHR unwrappedInfo = CopyInfo; + unwrappedInfo.image = Unwrap(unwrappedInfo.image); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdCopyImageToMemoryKHR(Unwrap(commandBuffer), &unwrappedInfo); + byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); + + UnwrapNextChain(m_State, "VkCopyDeviceMemoryImageInfoKHR", tempMem, + (VkBaseInStructure *)&unwrappedInfo); - m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); - } - } - } - else - { ObjDisp(commandBuffer)->CmdCopyImageToMemoryKHR(Unwrap(commandBuffer), &unwrappedInfo); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdCopyImageToMemoryKHR(Unwrap(commandBuffer), &unwrappedInfo); + + m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); + } + + if(loading) { AddEvent(); @@ -5395,7 +5246,7 @@ bool WrappedVulkan::Serialise_vkCmdCopyImageToMemoryKHR( AddAction(action); VulkanEventNode &eventNode = GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(imgid, ResourceUsage::CopySrc)); + eventNode.AddResourceUsage(imgid, ResourceUsage::CopySrc); for(uint32_t i = 0; i < CopyInfo.regionCount; i++) RecordDeviceAddressUsage(CopyInfo.pRegions[i].addressRange.address, ResourceUsage::CopyDst); } @@ -5461,28 +5312,25 @@ bool WrappedVulkan::Serialise_vkCmdCopyMemoryKHR(SerialiserType &ser, VkCommandB { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Copy); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Copy)) : 0; - ObjDisp(commandBuffer)->CmdCopyMemoryKHR(Unwrap(commandBuffer), &CopyInfo); + ObjDisp(commandBuffer)->CmdCopyMemoryKHR(Unwrap(commandBuffer), &CopyInfo); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdCopyMemoryKHR(Unwrap(commandBuffer), &CopyInfo); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdCopyMemoryKHR(Unwrap(commandBuffer), &CopyInfo); - m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); } - } - else - { - ObjDisp(commandBuffer)->CmdCopyMemoryKHR(Unwrap(commandBuffer), &CopyInfo); + if(loading) { AddEvent(); @@ -5564,28 +5412,25 @@ bool WrappedVulkan::Serialise_vkCmdFillMemoryKHR(SerialiserType &ser, VkCommandB { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Clear); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Clear)) : 0; - ObjDisp(commandBuffer)->CmdFillMemoryKHR(Unwrap(commandBuffer), &DstRange, dstFlags, data); + ObjDisp(commandBuffer)->CmdFillMemoryKHR(Unwrap(commandBuffer), &DstRange, dstFlags, data); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Clear, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdFillMemoryKHR(Unwrap(commandBuffer), &DstRange, dstFlags, data); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Clear, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdFillMemoryKHR(Unwrap(commandBuffer), &DstRange, dstFlags, data); - m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Clear, commandBuffer); } - } - else - { - ObjDisp(commandBuffer)->CmdFillMemoryKHR(Unwrap(commandBuffer), &DstRange, dstFlags, data); + if(loading) { AddEvent(); @@ -5652,31 +5497,27 @@ bool WrappedVulkan::Serialise_vkCmdUpdateMemoryKHR(SerialiserType &ser, VkComman { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Copy); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Copy)) : 0; + ObjDisp(commandBuffer) + ->CmdUpdateMemoryKHR(Unwrap(commandBuffer), &DstRange, dstFlags, dataSize, Data); + + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) + { ObjDisp(commandBuffer) ->CmdUpdateMemoryKHR(Unwrap(commandBuffer), &DstRange, dstFlags, dataSize, Data); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdUpdateMemoryKHR(Unwrap(commandBuffer), &DstRange, dstFlags, dataSize, Data); - - m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); - } + m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); } - } - else - { - ObjDisp(commandBuffer) - ->CmdUpdateMemoryKHR(Unwrap(commandBuffer), &DstRange, dstFlags, dataSize, Data); + if(loading) { AddEvent(); @@ -5735,38 +5576,35 @@ bool WrappedVulkan::Serialise_vkCmdCopyMemoryToImageKHR( if(IsReplayingAndReading()) { - VkCopyDeviceMemoryImageInfoKHR unwrappedInfo = CopyInfo; - unwrappedInfo.image = Unwrap(unwrappedInfo.image); - - byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); - - UnwrapNextChain(m_State, "VkCopyDeviceMemoryImageInfoKHR", tempMem, - (VkBaseInStructure *)&unwrappedInfo); - m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Copy); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Copy)) : 0; - ObjDisp(commandBuffer)->CmdCopyMemoryToImageKHR(Unwrap(commandBuffer), &unwrappedInfo); + VkCopyDeviceMemoryImageInfoKHR unwrappedInfo = CopyInfo; + unwrappedInfo.image = Unwrap(unwrappedInfo.image); - if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdCopyMemoryToImageKHR(Unwrap(commandBuffer), &unwrappedInfo); + byte *tempMem = GetTempMemory(GetNextPatchSize(unwrappedInfo.pNext)); + + UnwrapNextChain(m_State, "VkCopyDeviceMemoryImageInfoKHR", tempMem, + (VkBaseInStructure *)&unwrappedInfo); - m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); - } - } - } - else - { ObjDisp(commandBuffer)->CmdCopyMemoryToImageKHR(Unwrap(commandBuffer), &unwrappedInfo); + if(eventId && m_ActionCallback->PostMisc(eventId, ActionFlags::Copy, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdCopyMemoryToImageKHR(Unwrap(commandBuffer), &unwrappedInfo); + + m_ActionCallback->PostRemisc(eventId, ActionFlags::Copy, commandBuffer); + } + + if(loading) { AddEvent(); @@ -5790,7 +5628,7 @@ bool WrappedVulkan::Serialise_vkCmdCopyMemoryToImageKHR( AddAction(action); VulkanEventNode &eventNode = GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(imgid, ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(imgid, ResourceUsage::CopyDst); for(uint32_t i = 0; i < CopyInfo.regionCount; i++) RecordDeviceAddressUsage(CopyInfo.pRegions[i].addressRange.address, ResourceUsage::CopySrc); } @@ -5858,35 +5696,36 @@ bool WrappedVulkan::Serialise_vkCmdDispatchIndirect2KHR(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer, ActionFlags::Dispatch); + uint32_t eventId = + !loading ? HandlePreCallback(commandBuffer, ActionFlags(ActionFlags::Dispatch)) : 0; - ObjDisp(commandBuffer)->CmdDispatchIndirect2KHR(Unwrap(commandBuffer), &Info); + VkIndirectPatchData indirectPatch; - if(eventId && m_ActionCallback->PostDispatch(eventId, ActionFlags::Dispatch, commandBuffer)) - { - ObjDisp(commandBuffer)->CmdDispatchIndirect2KHR(Unwrap(commandBuffer), &Info); - m_ActionCallback->PostRedispatch(eventId, ActionFlags::Dispatch, commandBuffer); - } - } - } - else - { - ResourceId id; - uint64_t offs; - GetResIDFromAddr(Info.addressRange.address, id, offs); + if(loading) + { + ResourceId id; + uint64_t offs; + GetResIDFromAddr(Info.addressRange.address, id, offs); - VkIndirectPatchData indirectPatch = - FetchIndirectData(VkIndirectPatchType::DispatchIndirect, commandBuffer, - GetResourceManager()->GetHandle(id), offs, 1); + indirectPatch = FetchIndirectData(VkIndirectPatchType::DispatchIndirect, commandBuffer, + GetResourceManager()->GetHandle(id), offs, 1); + } ObjDisp(commandBuffer)->CmdDispatchIndirect2KHR(Unwrap(commandBuffer), &Info); + if(eventId && m_ActionCallback->PostDispatch(eventId, ActionFlags::Dispatch, commandBuffer)) + { + ObjDisp(commandBuffer)->CmdDispatchIndirect2KHR(Unwrap(commandBuffer), &Info); + m_ActionCallback->PostRedispatch(eventId, ActionFlags::Dispatch, commandBuffer); + } + + if(loading) { AddEvent(); @@ -7313,57 +7152,56 @@ bool WrappedVulkan::Serialise_vkCmdDrawIndirectByteCount2EXT( m_LastCmdBufferID = GetResID(commandBuffer); // do execution (possibly partial) - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - uint32_t eventId = HandlePreCallback(commandBuffer); + uint32_t eventId = !loading ? HandlePreCallback(commandBuffer) : 0; - ObjDisp(commandBuffer) - ->CmdDrawIndirectByteCount2EXT(Unwrap(commandBuffer), instanceCount, firstInstance, - &CounterInfo, counterOffset, vertexStride); + VkIndirectPatchData indirectPatch; - if(eventId && m_ActionCallback->PostDraw(eventId, ActionFlags::Drawcall, commandBuffer)) - { - ObjDisp(commandBuffer) - ->CmdDrawIndirectByteCount2EXT(Unwrap(commandBuffer), instanceCount, firstInstance, - &CounterInfo, counterOffset, vertexStride); - m_ActionCallback->PostRedraw(eventId, ActionFlags::Drawcall, commandBuffer); - } + if(loading) + { + ResourceId id; + uint64_t offs; + GetResIDFromAddr(CounterInfo.addressRange.address, id, offs); + + indirectPatch = + FetchIndirectData(VkIndirectPatchType::DrawIndirectByteCount, commandBuffer, + GetResourceManager()->GetHandle(id), offs, 1, vertexStride); + indirectPatch.vertexoffset = counterOffset; } - } - else - { - ResourceId id; - uint64_t offs; - GetResIDFromAddr(CounterInfo.addressRange.address, id, offs); - - VkIndirectPatchData indirectPatch = - FetchIndirectData(VkIndirectPatchType::DrawIndirectByteCount, commandBuffer, - GetResourceManager()->GetHandle(id), offs, 1, vertexStride); - indirectPatch.vertexoffset = counterOffset; ObjDisp(commandBuffer) ->CmdDrawIndirectByteCount2EXT(Unwrap(commandBuffer), instanceCount, firstInstance, &CounterInfo, counterOffset, vertexStride); - ActionDescription action; + if(eventId && m_ActionCallback->PostDraw(eventId, ActionFlags::Drawcall, commandBuffer)) + { + ObjDisp(commandBuffer) + ->CmdDrawIndirectByteCount2EXT(Unwrap(commandBuffer), instanceCount, firstInstance, + &CounterInfo, counterOffset, vertexStride); + m_ActionCallback->PostRedraw(eventId, ActionFlags::Drawcall, commandBuffer); + } - AddEvent(); + if(loading) + { + ActionDescription action; - action.instanceOffset = firstInstance; - action.numInstances = instanceCount; - action.flags = ActionFlags::Drawcall | ActionFlags::Instanced | ActionFlags::Indirect; + AddEvent(); - AddAction(action); + action.instanceOffset = firstInstance; + action.numInstances = instanceCount; + action.flags = ActionFlags::Drawcall | ActionFlags::Instanced | ActionFlags::Indirect; - VulkanEventNode &eventNode = GetLastEventNode(); - eventNode.indirectPatch = indirectPatch; - RecordDeviceAddressUsage(CounterInfo.addressRange.address, ResourceUsage::Indirect); + AddAction(action); - return true; + VulkanEventNode &eventNode = GetLastEventNode(); + eventNode.indirectPatch = indirectPatch; + RecordDeviceAddressUsage(CounterInfo.addressRange.address, ResourceUsage::Indirect); + } } } diff --git a/renderdoc/driver/vulkan/wrappers/vk_dynamic_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_dynamic_funcs.cpp index ec1da000c76..9a8dd206e24 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_dynamic_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_dynamic_funcs.cpp @@ -44,33 +44,27 @@ bool WrappedVulkan::Serialise_vkCmdSetViewport(SerialiserType &ser, VkCommandBuf { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicViewport] = true; + renderstate.dynamicStates[VkDynamicViewport] = true; - if(renderstate.views.size() < firstViewport + viewportCount) - renderstate.views.resize(firstViewport + viewportCount); + if(renderstate.views.size() < firstViewport + viewportCount) + renderstate.views.resize(firstViewport + viewportCount); - for(uint32_t i = 0; i < viewportCount; i++) - renderstate.views[firstViewport + i] = pViewports[i]; - } + for(uint32_t i = 0; i < viewportCount; i++) + renderstate.views[firstViewport + i] = pViewports[i]; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetViewport(Unwrap(commandBuffer), firstViewport, viewportCount, pViewports); + } } return true; @@ -116,28 +110,22 @@ bool WrappedVulkan::Serialise_vkCmdSetViewportWithCount(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicViewportCount] = true; + renderstate.dynamicStates[VkDynamicViewportCount] = true; - renderstate.views.assign(pViewports, viewportCount); - } + renderstate.views.assign(pViewports, viewportCount); } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetViewportWithCount(Unwrap(commandBuffer), viewportCount, pViewports); + } } return true; @@ -182,32 +170,26 @@ bool WrappedVulkan::Serialise_vkCmdSetScissor(SerialiserType &ser, VkCommandBuff { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicScissor] = true; + renderstate.dynamicStates[VkDynamicScissor] = true; - if(renderstate.scissors.size() < firstScissor + scissorCount) - renderstate.scissors.resize(firstScissor + scissorCount); + if(renderstate.scissors.size() < firstScissor + scissorCount) + renderstate.scissors.resize(firstScissor + scissorCount); - for(uint32_t i = 0; i < scissorCount; i++) - renderstate.scissors[firstScissor + i] = pScissors[i]; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + for(uint32_t i = 0; i < scissorCount; i++) + renderstate.scissors[firstScissor + i] = pScissors[i]; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetScissor(Unwrap(commandBuffer), firstScissor, scissorCount, pScissors); + } } return true; @@ -253,28 +235,22 @@ bool WrappedVulkan::Serialise_vkCmdSetScissorWithCount(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicScissorCount] = true; + renderstate.dynamicStates[VkDynamicScissorCount] = true; - renderstate.scissors.assign(pScissors, scissorCount); - } + renderstate.scissors.assign(pScissors, scissorCount); } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetScissorWithCount(Unwrap(commandBuffer), scissorCount, pScissors); + } } return true; @@ -316,27 +292,21 @@ bool WrappedVulkan::Serialise_vkCmdSetLineWidth(SerialiserType &ser, VkCommandBu { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - - renderstate.dynamicStates[VkDynamicLineWidth] = true; - renderstate.lineWidth = lineWidth; - } - } - else { - commandBuffer = VK_NULL_HANDLE; + VulkanRenderState &renderstate = GetCmdRenderState(); + + renderstate.dynamicStates[VkDynamicLineWidth] = true; + renderstate.lineWidth = lineWidth; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetLineWidth(Unwrap(commandBuffer), lineWidth); + } } return true; @@ -379,41 +349,35 @@ bool WrappedVulkan::Serialise_vkCmdSetDepthBias(SerialiserType &ser, VkCommandBu { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicDepthBias] = true; + renderstate.dynamicStates[VkDynamicDepthBias] = true; - renderstate.bias.depth = depthBias; - renderstate.bias.biasclamp = depthBiasClamp; - renderstate.bias.slope = slopeScaledDepthBias; + renderstate.bias.depth = depthBias; + renderstate.bias.biasclamp = depthBiasClamp; + renderstate.bias.slope = slopeScaledDepthBias; - // Calling this function is equivalent to calling vkCmdSetDepthBias2EXT without a - // VkDepthBiasRepresentationInfoEXT in the pNext chain of VkDepthBiasInfoEXT. - // + - // If pNext does not contain a VkDepthBiasRepresentationInfoEXT structure, then this - // command is equivalent to including a VkDepthBiasRepresentationInfoEXT with - // depthBiasExact set to VK_FALSE and depthBiasRepresentation set to - // VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT. - renderstate.bias.exact = false; - renderstate.bias.repr = VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT; - } + // Calling this function is equivalent to calling vkCmdSetDepthBias2EXT without a + // VkDepthBiasRepresentationInfoEXT in the pNext chain of VkDepthBiasInfoEXT. + // + + // If pNext does not contain a VkDepthBiasRepresentationInfoEXT structure, then this + // command is equivalent to including a VkDepthBiasRepresentationInfoEXT with + // depthBiasExact set to VK_FALSE and depthBiasRepresentation set to + // VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT. + renderstate.bias.exact = false; + renderstate.bias.repr = VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetDepthBias(Unwrap(commandBuffer), depthBias, depthBiasClamp, slopeScaledDepthBias); + } } return true; @@ -457,28 +421,22 @@ bool WrappedVulkan::Serialise_vkCmdSetBlendConstants(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicBlendConstants] = true; + renderstate.dynamicStates[VkDynamicBlendConstants] = true; - memcpy(renderstate.blendConst, blendConst, sizeof(renderstate.blendConst)); - } + memcpy(renderstate.blendConst, blendConst, sizeof(renderstate.blendConst)); } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetBlendConstants(Unwrap(commandBuffer), blendConst); + } } return true; @@ -519,29 +477,23 @@ bool WrappedVulkan::Serialise_vkCmdSetDepthBounds(SerialiserType &ser, VkCommand { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicDepthBounds] = true; + renderstate.dynamicStates[VkDynamicDepthBounds] = true; - renderstate.mindepth = minDepthBounds; - renderstate.maxdepth = maxDepthBounds; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.mindepth = minDepthBounds; + renderstate.maxdepth = maxDepthBounds; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetDepthBounds(Unwrap(commandBuffer), minDepthBounds, maxDepthBounds); + } } return true; @@ -586,31 +538,25 @@ bool WrappedVulkan::Serialise_vkCmdSetStencilCompareMask(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicStencilCompareMask] = true; + renderstate.dynamicStates[VkDynamicStencilCompareMask] = true; - if(faceMask & VK_STENCIL_FACE_FRONT_BIT) - renderstate.front.compare = compareMask; - if(faceMask & VK_STENCIL_FACE_BACK_BIT) - renderstate.back.compare = compareMask; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + if(faceMask & VK_STENCIL_FACE_FRONT_BIT) + renderstate.front.compare = compareMask; + if(faceMask & VK_STENCIL_FACE_BACK_BIT) + renderstate.back.compare = compareMask; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetStencilCompareMask(Unwrap(commandBuffer), faceMask, compareMask); + } } return true; @@ -655,31 +601,25 @@ bool WrappedVulkan::Serialise_vkCmdSetStencilWriteMask(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicStencilWriteMask] = true; + renderstate.dynamicStates[VkDynamicStencilWriteMask] = true; - if(faceMask & VK_STENCIL_FACE_FRONT_BIT) - renderstate.front.write = writeMask; - if(faceMask & VK_STENCIL_FACE_BACK_BIT) - renderstate.back.write = writeMask; - } + if(faceMask & VK_STENCIL_FACE_FRONT_BIT) + renderstate.front.write = writeMask; + if(faceMask & VK_STENCIL_FACE_BACK_BIT) + renderstate.back.write = writeMask; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetStencilWriteMask(Unwrap(commandBuffer), faceMask, writeMask); + } } return true; @@ -724,31 +664,25 @@ bool WrappedVulkan::Serialise_vkCmdSetStencilReference(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicStencilReference] = true; + renderstate.dynamicStates[VkDynamicStencilReference] = true; - if(faceMask & VK_STENCIL_FACE_FRONT_BIT) - renderstate.front.ref = reference; - if(faceMask & VK_STENCIL_FACE_BACK_BIT) - renderstate.back.ref = reference; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + if(faceMask & VK_STENCIL_FACE_FRONT_BIT) + renderstate.front.ref = reference; + if(faceMask & VK_STENCIL_FACE_BACK_BIT) + renderstate.back.ref = reference; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetStencilReference(Unwrap(commandBuffer), faceMask, reference); + } } return true; @@ -791,31 +725,25 @@ bool WrappedVulkan::Serialise_vkCmdSetSampleLocationsEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicSampleLocationsEXT] = true; + renderstate.dynamicStates[VkDynamicSampleLocationsEXT] = true; - renderstate.sampleLocations.locations.assign(sampleInfo.pSampleLocations, - sampleInfo.sampleLocationsCount); - renderstate.sampleLocations.gridSize = sampleInfo.sampleLocationGridSize; - renderstate.sampleLocations.sampleCount = sampleInfo.sampleLocationsPerPixel; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.sampleLocations.locations.assign(sampleInfo.pSampleLocations, + sampleInfo.sampleLocationsCount); + renderstate.sampleLocations.gridSize = sampleInfo.sampleLocationGridSize; + renderstate.sampleLocations.sampleCount = sampleInfo.sampleLocationsPerPixel; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetSampleLocationsEXT(Unwrap(commandBuffer), &sampleInfo); + } } return true; @@ -862,34 +790,28 @@ bool WrappedVulkan::Serialise_vkCmdSetDiscardRectangleEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicDiscardRectangleEXT] = true; + renderstate.dynamicStates[VkDynamicDiscardRectangleEXT] = true; - if(renderstate.discardRectangles.size() < firstDiscardRectangle + discardRectangleCount) - renderstate.discardRectangles.resize(firstDiscardRectangle + discardRectangleCount); + if(renderstate.discardRectangles.size() < firstDiscardRectangle + discardRectangleCount) + renderstate.discardRectangles.resize(firstDiscardRectangle + discardRectangleCount); - for(uint32_t i = 0; i < discardRectangleCount; i++) - renderstate.discardRectangles[firstDiscardRectangle + i] = pDiscardRectangles[i]; - } + for(uint32_t i = 0; i < discardRectangleCount; i++) + renderstate.discardRectangles[firstDiscardRectangle + i] = pDiscardRectangles[i]; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetDiscardRectangleEXT(Unwrap(commandBuffer), firstDiscardRectangle, discardRectangleCount, pDiscardRectangles); + } } return true; @@ -937,32 +859,26 @@ bool WrappedVulkan::Serialise_vkCmdSetLineStipple(SerialiserType &ser, VkCommand { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicLineStipple] = true; + renderstate.dynamicStates[VkDynamicLineStipple] = true; - renderstate.stippleFactor = lineStippleFactor; - renderstate.stipplePattern = lineStipplePattern; - } + renderstate.stippleFactor = lineStippleFactor; + renderstate.stipplePattern = lineStipplePattern; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - // this could be the EXT function, we handle either one in our dispatch tables and assign to the - // other since it's a straight promotion. This allows us to share implementation between the two - if(commandBuffer != VK_NULL_HANDLE) + // this could be the EXT function, we handle either one in our dispatch tables and assign to the + // other since it's a straight promotion. This allows us to share implementation between the two ObjDisp(commandBuffer) ->CmdSetLineStipple(Unwrap(commandBuffer), lineStippleFactor, lineStipplePattern); + } } return true; @@ -1016,28 +932,22 @@ bool WrappedVulkan::Serialise_vkCmdSetCullMode(SerialiserType &ser, VkCommandBuf { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicCullMode] = true; + renderstate.dynamicStates[VkDynamicCullMode] = true; - renderstate.cullMode = cullMode; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.cullMode = cullMode; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetCullMode(Unwrap(commandBuffer), cullMode); + } } return true; @@ -1077,28 +987,22 @@ bool WrappedVulkan::Serialise_vkCmdSetFrontFace(SerialiserType &ser, VkCommandBu { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicFrontFace] = true; + renderstate.dynamicStates[VkDynamicFrontFace] = true; - renderstate.frontFace = frontFace; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.frontFace = frontFace; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetFrontFace(Unwrap(commandBuffer), frontFace); + } } return true; @@ -1139,32 +1043,22 @@ bool WrappedVulkan::Serialise_vkCmdSetPrimitiveTopology(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicPrimitiveTopology] = true; + renderstate.dynamicStates[VkDynamicPrimitiveTopology] = true; - renderstate.primitiveTopology = primitiveTopology; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.primitiveTopology = primitiveTopology; } - } - else - { - m_BakedCmdBufferInfo[m_LastCmdBufferID].state.primitiveTopology = primitiveTopology; - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetPrimitiveTopology(Unwrap(commandBuffer), primitiveTopology); + } } return true; @@ -1207,28 +1101,22 @@ bool WrappedVulkan::Serialise_vkCmdSetDepthTestEnable(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicDepthTestEnable] = true; + renderstate.dynamicStates[VkDynamicDepthTestEnable] = true; - renderstate.depthTestEnable = depthTestEnable; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.depthTestEnable = depthTestEnable; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetDepthTestEnable(Unwrap(commandBuffer), depthTestEnable); + } } return true; @@ -1270,28 +1158,22 @@ bool WrappedVulkan::Serialise_vkCmdSetDepthWriteEnable(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicDepthWriteEnable] = true; + renderstate.dynamicStates[VkDynamicDepthWriteEnable] = true; - renderstate.depthWriteEnable = depthWriteEnable; - } + renderstate.depthWriteEnable = depthWriteEnable; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetDepthWriteEnable(Unwrap(commandBuffer), depthWriteEnable); + } } return true; @@ -1333,28 +1215,22 @@ bool WrappedVulkan::Serialise_vkCmdSetDepthCompareOp(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicDepthCompareOp] = true; + renderstate.dynamicStates[VkDynamicDepthCompareOp] = true; - renderstate.depthCompareOp = depthCompareOp; - } + renderstate.depthCompareOp = depthCompareOp; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetDepthCompareOp(Unwrap(commandBuffer), depthCompareOp); + } } return true; @@ -1396,28 +1272,22 @@ bool WrappedVulkan::Serialise_vkCmdSetDepthBoundsTestEnable(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicDepthBoundsTestEnable] = true; + renderstate.dynamicStates[VkDynamicDepthBoundsTestEnable] = true; - renderstate.depthBoundsTestEnable = depthBoundsTestEnable; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.depthBoundsTestEnable = depthBoundsTestEnable; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetDepthBoundsTestEnable(Unwrap(commandBuffer), depthBoundsTestEnable); + } } return true; @@ -1460,28 +1330,22 @@ bool WrappedVulkan::Serialise_vkCmdSetStencilTestEnable(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicStencilTestEnable] = true; + renderstate.dynamicStates[VkDynamicStencilTestEnable] = true; - renderstate.stencilTestEnable = stencilTestEnable; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.stencilTestEnable = stencilTestEnable; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetStencilTestEnable(Unwrap(commandBuffer), stencilTestEnable); + } } return true; @@ -1529,42 +1393,36 @@ bool WrappedVulkan::Serialise_vkCmdSetStencilOp(SerialiserType &ser, VkCommandBu { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); + { + VulkanRenderState &renderstate = GetCmdRenderState(); + + renderstate.dynamicStates[VkDynamicStencilOp] = true; + + if(faceMask & VK_STENCIL_FACE_FRONT_BIT) { - VulkanRenderState &renderstate = GetCmdRenderState(); - - renderstate.dynamicStates[VkDynamicStencilOp] = true; - - if(faceMask & VK_STENCIL_FACE_FRONT_BIT) - { - renderstate.front.failOp = failOp; - renderstate.front.passOp = passOp; - renderstate.front.depthFailOp = depthFailOp; - renderstate.front.compareOp = compareOp; - } - if(faceMask & VK_STENCIL_FACE_BACK_BIT) - { - renderstate.back.failOp = failOp; - renderstate.back.passOp = passOp; - renderstate.back.depthFailOp = depthFailOp; - renderstate.back.compareOp = compareOp; - } + renderstate.front.failOp = failOp; + renderstate.front.passOp = passOp; + renderstate.front.depthFailOp = depthFailOp; + renderstate.front.compareOp = compareOp; + } + if(faceMask & VK_STENCIL_FACE_BACK_BIT) + { + renderstate.back.failOp = failOp; + renderstate.back.passOp = passOp; + renderstate.back.depthFailOp = depthFailOp; + renderstate.back.compareOp = compareOp; } } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetStencilOp(Unwrap(commandBuffer), faceMask, failOp, passOp, depthFailOp, compareOp); + } } return true; @@ -1611,29 +1469,23 @@ bool WrappedVulkan::Serialise_vkCmdSetColorWriteEnableEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicColorWriteEXT] = true; + renderstate.dynamicStates[VkDynamicColorWriteEXT] = true; - renderstate.colorWriteEnable.assign(pColorWriteEnables, attachmentCount); - } + renderstate.colorWriteEnable.assign(pColorWriteEnables, attachmentCount); } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetColorWriteEnableEXT(Unwrap(commandBuffer), attachmentCount, pColorWriteEnables); + } } return true; @@ -1678,28 +1530,22 @@ bool WrappedVulkan::Serialise_vkCmdSetDepthBiasEnable(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicDepthBiasEnable] = true; + renderstate.dynamicStates[VkDynamicDepthBiasEnable] = true; - renderstate.depthBiasEnable = depthBiasEnable; - } + renderstate.depthBiasEnable = depthBiasEnable; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetDepthBiasEnable(Unwrap(commandBuffer), depthBiasEnable); + } } return true; @@ -1740,28 +1586,22 @@ bool WrappedVulkan::Serialise_vkCmdSetLogicOpEXT(SerialiserType &ser, VkCommandB { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicLogicOpEXT] = true; + renderstate.dynamicStates[VkDynamicLogicOpEXT] = true; - renderstate.logicOp = logicOp; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.logicOp = logicOp; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetLogicOpEXT(Unwrap(commandBuffer), logicOp); + } } return true; @@ -1802,28 +1642,22 @@ bool WrappedVulkan::Serialise_vkCmdSetPatchControlPointsEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicControlPointsEXT] = true; + renderstate.dynamicStates[VkDynamicControlPointsEXT] = true; - renderstate.patchControlPoints = patchControlPoints; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.patchControlPoints = patchControlPoints; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetPatchControlPointsEXT(Unwrap(commandBuffer), patchControlPoints); + } } return true; @@ -1866,28 +1700,22 @@ bool WrappedVulkan::Serialise_vkCmdSetPrimitiveRestartEnable(SerialiserType &ser { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicPrimRestart] = true; + renderstate.dynamicStates[VkDynamicPrimRestart] = true; - renderstate.primRestartEnable = primitiveRestartEnable; - } + renderstate.primRestartEnable = primitiveRestartEnable; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetPrimitiveRestartEnable(Unwrap(commandBuffer), primitiveRestartEnable); + } } return true; @@ -1931,29 +1759,23 @@ bool WrappedVulkan::Serialise_vkCmdSetRasterizerDiscardEnable(SerialiserType &se { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicRastDiscard] = true; + renderstate.dynamicStates[VkDynamicRastDiscard] = true; - renderstate.rastDiscardEnable = rasterizerDiscardEnable; - } + renderstate.rastDiscardEnable = rasterizerDiscardEnable; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetRasterizerDiscardEnable(Unwrap(commandBuffer), rasterizerDiscardEnable); + } } return true; @@ -1998,31 +1820,25 @@ bool WrappedVulkan::Serialise_vkCmdSetFragmentShadingRateKHR( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicShadingRateKHR] = true; + renderstate.dynamicStates[VkDynamicShadingRateKHR] = true; - renderstate.pipelineShadingRate = *pFragmentSize; - renderstate.shadingRateCombiners[0] = combinerOps[0]; - renderstate.shadingRateCombiners[1] = combinerOps[1]; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.pipelineShadingRate = *pFragmentSize; + renderstate.shadingRateCombiners[0] = combinerOps[0]; + renderstate.shadingRateCombiners[1] = combinerOps[1]; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetFragmentShadingRateKHR(Unwrap(commandBuffer), pFragmentSize, combinerOps); + } } return true; @@ -2067,28 +1883,22 @@ bool WrappedVulkan::Serialise_vkCmdSetAttachmentFeedbackLoopEnableEXT(Serialiser { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicAttachmentFeedbackLoopEnableEXT] = true; + renderstate.dynamicStates[VkDynamicAttachmentFeedbackLoopEnableEXT] = true; - renderstate.feedbackAspects = aspectMask; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.feedbackAspects = aspectMask; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetAttachmentFeedbackLoopEnableEXT(Unwrap(commandBuffer), aspectMask); + } } return true; @@ -2131,28 +1941,22 @@ bool WrappedVulkan::Serialise_vkCmdSetAlphaToCoverageEnableEXT(SerialiserType &s { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicAlphaToCoverageEXT] = true; + renderstate.dynamicStates[VkDynamicAlphaToCoverageEXT] = true; - renderstate.alphaToCoverageEnable = alphaToCoverageEnable; - } + renderstate.alphaToCoverageEnable = alphaToCoverageEnable; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetAlphaToCoverageEnableEXT(Unwrap(commandBuffer), alphaToCoverageEnable); + } } return true; @@ -2196,28 +2000,22 @@ bool WrappedVulkan::Serialise_vkCmdSetAlphaToOneEnableEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicAlphaToOneEXT] = true; + renderstate.dynamicStates[VkDynamicAlphaToOneEXT] = true; - renderstate.alphaToOneEnable = alphaToOneEnable; - } + renderstate.alphaToOneEnable = alphaToOneEnable; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetAlphaToOneEnableEXT(Unwrap(commandBuffer), alphaToOneEnable); + } } return true; @@ -2271,34 +2069,28 @@ bool WrappedVulkan::Serialise_vkCmdSetColorBlendEnableEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicColorBlendEnableEXT] = true; + renderstate.dynamicStates[VkDynamicColorBlendEnableEXT] = true; - if(renderstate.colorBlendEnable.size() < firstAttachment + attachmentCount) - renderstate.colorBlendEnable.resize(firstAttachment + attachmentCount); + if(renderstate.colorBlendEnable.size() < firstAttachment + attachmentCount) + renderstate.colorBlendEnable.resize(firstAttachment + attachmentCount); - for(uint32_t i = 0; i < attachmentCount; i++) - renderstate.colorBlendEnable[firstAttachment + i] = pColorBlendEnables[i]; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + for(uint32_t i = 0; i < attachmentCount; i++) + renderstate.colorBlendEnable[firstAttachment + i] = pColorBlendEnables[i]; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetColorBlendEnableEXT(Unwrap(commandBuffer), firstAttachment, attachmentCount, pColorBlendEnables); + } } return true; @@ -2346,34 +2138,28 @@ bool WrappedVulkan::Serialise_vkCmdSetColorBlendEquationEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicColorBlendEquationEXT] = true; + renderstate.dynamicStates[VkDynamicColorBlendEquationEXT] = true; - if(renderstate.colorBlendEquation.size() < firstAttachment + attachmentCount) - renderstate.colorBlendEquation.resize(firstAttachment + attachmentCount); + if(renderstate.colorBlendEquation.size() < firstAttachment + attachmentCount) + renderstate.colorBlendEquation.resize(firstAttachment + attachmentCount); - for(uint32_t i = 0; i < attachmentCount; i++) - renderstate.colorBlendEquation[firstAttachment + i] = pColorBlendEquations[i]; - } + for(uint32_t i = 0; i < attachmentCount; i++) + renderstate.colorBlendEquation[firstAttachment + i] = pColorBlendEquations[i]; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetColorBlendEquationEXT(Unwrap(commandBuffer), firstAttachment, attachmentCount, pColorBlendEquations); + } } return true; @@ -2423,34 +2209,28 @@ bool WrappedVulkan::Serialise_vkCmdSetColorWriteMaskEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicColorWriteMaskEXT] = true; + renderstate.dynamicStates[VkDynamicColorWriteMaskEXT] = true; - if(renderstate.colorWriteMask.size() < firstAttachment + attachmentCount) - renderstate.colorWriteMask.resize(firstAttachment + attachmentCount); + if(renderstate.colorWriteMask.size() < firstAttachment + attachmentCount) + renderstate.colorWriteMask.resize(firstAttachment + attachmentCount); - for(uint32_t i = 0; i < attachmentCount; i++) - renderstate.colorWriteMask[firstAttachment + i] = pColorWriteMasks[i]; - } + for(uint32_t i = 0; i < attachmentCount; i++) + renderstate.colorWriteMask[firstAttachment + i] = pColorWriteMasks[i]; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetColorWriteMaskEXT(Unwrap(commandBuffer), firstAttachment, attachmentCount, pColorWriteMasks); + } } return true; @@ -2496,30 +2276,24 @@ bool WrappedVulkan::Serialise_vkCmdSetConservativeRasterizationModeEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicConservativeRastModeEXT] = true; + renderstate.dynamicStates[VkDynamicConservativeRastModeEXT] = true; - renderstate.conservativeRastMode = conservativeRasterizationMode; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.conservativeRastMode = conservativeRasterizationMode; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetConservativeRasterizationModeEXT(Unwrap(commandBuffer), conservativeRasterizationMode); + } } return true; @@ -2601,28 +2375,22 @@ bool WrappedVulkan::Serialise_vkCmdSetDepthClampEnableEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicDepthClampEnableEXT] = true; + renderstate.dynamicStates[VkDynamicDepthClampEnableEXT] = true; - renderstate.depthClampEnable = depthClampEnable; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.depthClampEnable = depthClampEnable; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetDepthClampEnableEXT(Unwrap(commandBuffer), depthClampEnable); + } } return true; @@ -2665,28 +2433,22 @@ bool WrappedVulkan::Serialise_vkCmdSetDepthClipEnableEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicDepthClipEnableEXT] = true; + renderstate.dynamicStates[VkDynamicDepthClipEnableEXT] = true; - renderstate.depthClipEnable = depthClipEnable; - } + renderstate.depthClipEnable = depthClipEnable; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetDepthClipEnableEXT(Unwrap(commandBuffer), depthClipEnable); + } } return true; @@ -2728,28 +2490,22 @@ bool WrappedVulkan::Serialise_vkCmdSetDepthClipNegativeOneToOneEXT(SerialiserTyp { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicDepthClipNegativeOneEXT] = true; + renderstate.dynamicStates[VkDynamicDepthClipNegativeOneEXT] = true; - renderstate.negativeOneToOne = negativeOneToOne; - } + renderstate.negativeOneToOne = negativeOneToOne; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetDepthClipNegativeOneToOneEXT(Unwrap(commandBuffer), negativeOneToOne); + } } return true; @@ -2792,30 +2548,24 @@ bool WrappedVulkan::Serialise_vkCmdSetExtraPrimitiveOverestimationSizeEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicOverstimationSizeEXT] = true; + renderstate.dynamicStates[VkDynamicOverstimationSizeEXT] = true; - renderstate.primOverestimationSize = extraPrimitiveOverestimationSize; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.primOverestimationSize = extraPrimitiveOverestimationSize; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetExtraPrimitiveOverestimationSizeEXT(Unwrap(commandBuffer), extraPrimitiveOverestimationSize); + } } return true; @@ -2859,28 +2609,22 @@ bool WrappedVulkan::Serialise_vkCmdSetLineRasterizationModeEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicLineRastModeEXT] = true; + renderstate.dynamicStates[VkDynamicLineRastModeEXT] = true; - renderstate.lineRasterMode = lineRasterizationMode; - } + renderstate.lineRasterMode = lineRasterizationMode; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetLineRasterizationModeEXT(Unwrap(commandBuffer), lineRasterizationMode); + } } return true; @@ -2924,28 +2668,22 @@ bool WrappedVulkan::Serialise_vkCmdSetLineStippleEnableEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicLineStippleEnableEXT] = true; + renderstate.dynamicStates[VkDynamicLineStippleEnableEXT] = true; - renderstate.stippledLineEnable = stippledLineEnable; - } + renderstate.stippledLineEnable = stippledLineEnable; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetLineStippleEnableEXT(Unwrap(commandBuffer), stippledLineEnable); + } } return true; @@ -2988,28 +2726,22 @@ bool WrappedVulkan::Serialise_vkCmdSetLogicOpEnableEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicLogicOpEnableEXT] = true; + renderstate.dynamicStates[VkDynamicLogicOpEnableEXT] = true; - renderstate.logicOpEnable = logicOpEnable; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.logicOpEnable = logicOpEnable; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetLogicOpEnableEXT(Unwrap(commandBuffer), logicOpEnable); + } } return true; @@ -3051,28 +2783,22 @@ bool WrappedVulkan::Serialise_vkCmdSetPolygonModeEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicPolygonModeEXT] = true; + renderstate.dynamicStates[VkDynamicPolygonModeEXT] = true; - renderstate.polygonMode = polygonMode; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.polygonMode = polygonMode; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetPolygonModeEXT(Unwrap(commandBuffer), polygonMode); + } } return true; @@ -3113,28 +2839,22 @@ bool WrappedVulkan::Serialise_vkCmdSetProvokingVertexModeEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicProvokingVertexModeEXT] = true; + renderstate.dynamicStates[VkDynamicProvokingVertexModeEXT] = true; - renderstate.provokingVertexMode = provokingVertexMode; - } + renderstate.provokingVertexMode = provokingVertexMode; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetProvokingVertexModeEXT(Unwrap(commandBuffer), provokingVertexMode); + } } return true; @@ -3176,28 +2896,22 @@ bool WrappedVulkan::Serialise_vkCmdSetRasterizationSamplesEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicRasterizationSamplesEXT] = true; + renderstate.dynamicStates[VkDynamicRasterizationSamplesEXT] = true; - renderstate.rastSamples = rasterizationSamples; - } + renderstate.rastSamples = rasterizationSamples; } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetRasterizationSamplesEXT(Unwrap(commandBuffer), rasterizationSamples); + } } return true; @@ -3240,28 +2954,22 @@ bool WrappedVulkan::Serialise_vkCmdSetRasterizationStreamEXT(SerialiserType &ser { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicRasterizationStreamEXT] = true; + renderstate.dynamicStates[VkDynamicRasterizationStreamEXT] = true; - renderstate.rasterStream = rasterizationStream; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.rasterStream = rasterizationStream; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetRasterizationStreamEXT(Unwrap(commandBuffer), rasterizationStream); + } } return true; @@ -3310,28 +3018,22 @@ bool WrappedVulkan::Serialise_vkCmdSetSampleLocationsEnableEXT(SerialiserType &s { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicSampleLocationsEnableEXT] = true; + renderstate.dynamicStates[VkDynamicSampleLocationsEnableEXT] = true; - renderstate.sampleLocEnable = sampleLocationsEnable; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.sampleLocEnable = sampleLocationsEnable; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetSampleLocationsEnableEXT(Unwrap(commandBuffer), sampleLocationsEnable); + } } return true; @@ -3377,28 +3079,22 @@ bool WrappedVulkan::Serialise_vkCmdSetSampleMaskEXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicSampleMaskEXT] = true; + renderstate.dynamicStates[VkDynamicSampleMaskEXT] = true; - renderstate.sampleMask.assign(pSampleMask, ((samples - 1) / 32) + 1); - } + renderstate.sampleMask.assign(pSampleMask, ((samples - 1) / 32) + 1); } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetSampleMaskEXT(Unwrap(commandBuffer), samples, pSampleMask); + } } return true; @@ -3447,28 +3143,22 @@ bool WrappedVulkan::Serialise_vkCmdSetTessellationDomainOriginEXT( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicTessDomainOriginEXT] = true; + renderstate.dynamicStates[VkDynamicTessDomainOriginEXT] = true; - renderstate.domainOrigin = domainOrigin; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.domainOrigin = domainOrigin; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetTessellationDomainOriginEXT(Unwrap(commandBuffer), domainOrigin); + } } return true; @@ -3524,29 +3214,23 @@ bool WrappedVulkan::Serialise_vkCmdSetRayTracingPipelineStackSizeKHR(SerialiserT { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); + { + VulkanRenderState &renderstate = GetCmdRenderState(); - renderstate.dynamicStates[VkDynamicRayTracingStackSizeKHR] = true; + renderstate.dynamicStates[VkDynamicRayTracingStackSizeKHR] = true; - renderstate.rtStackSize = pipelineStackSize; - } - } - else - { - commandBuffer = VK_NULL_HANDLE; + renderstate.rtStackSize = pipelineStackSize; } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetRayTracingPipelineStackSizeKHR(Unwrap(commandBuffer), pipelineStackSize); + } } return true; @@ -3590,26 +3274,20 @@ bool WrappedVulkan::Serialise_vkCmdSetRenderingAttachmentLocations( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - - renderstate.dynamicRendering.localRead.UpdateLocations(locationInfo); - } - } - else { - commandBuffer = VK_NULL_HANDLE; + VulkanRenderState &renderstate = GetCmdRenderState(); + + renderstate.dynamicRendering.localRead.UpdateLocations(locationInfo); } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetRenderingAttachmentLocations(Unwrap(commandBuffer), &locationInfo); + } } return true; @@ -3654,27 +3332,21 @@ bool WrappedVulkan::Serialise_vkCmdSetRenderingInputAttachmentIndices( { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - { - VulkanRenderState &renderstate = GetCmdRenderState(); - - renderstate.dynamicRendering.localRead.UpdateInputIndices(inputAttachmentIndexInfo); - } - } - else { - commandBuffer = VK_NULL_HANDLE; + VulkanRenderState &renderstate = GetCmdRenderState(); + + renderstate.dynamicRendering.localRead.UpdateInputIndices(inputAttachmentIndexInfo); } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer) ->CmdSetRenderingInputAttachmentIndices(Unwrap(commandBuffer), &inputAttachmentIndexInfo); + } } return true; @@ -3719,44 +3391,38 @@ bool WrappedVulkan::Serialise_vkCmdSetDepthBias2EXT(SerialiserType &ser, { m_LastCmdBufferID = GetResID(commandBuffer); - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) - { + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); + { + VulkanRenderState &renderstate = GetCmdRenderState(); + + renderstate.dynamicStates[VkDynamicDepthBias] = true; + + renderstate.bias.depth = DepthBiasInfo.depthBiasConstantFactor; + renderstate.bias.biasclamp = DepthBiasInfo.depthBiasClamp; + renderstate.bias.slope = DepthBiasInfo.depthBiasSlopeFactor; + + const VkDepthBiasRepresentationInfoEXT *depthBiasRepr = + (const VkDepthBiasRepresentationInfoEXT *)FindNextStruct( + &DepthBiasInfo, VK_STRUCTURE_TYPE_DEPTH_BIAS_REPRESENTATION_INFO_EXT); + if(depthBiasRepr) { - VulkanRenderState &renderstate = GetCmdRenderState(); - - renderstate.dynamicStates[VkDynamicDepthBias] = true; - - renderstate.bias.depth = DepthBiasInfo.depthBiasConstantFactor; - renderstate.bias.biasclamp = DepthBiasInfo.depthBiasClamp; - renderstate.bias.slope = DepthBiasInfo.depthBiasSlopeFactor; - - const VkDepthBiasRepresentationInfoEXT *depthBiasRepr = - (const VkDepthBiasRepresentationInfoEXT *)FindNextStruct( - &DepthBiasInfo, VK_STRUCTURE_TYPE_DEPTH_BIAS_REPRESENTATION_INFO_EXT); - if(depthBiasRepr) - { - renderstate.bias.repr = depthBiasRepr->depthBiasRepresentation; - renderstate.bias.exact = depthBiasRepr->depthBiasExact != VK_FALSE; - } - else - { - renderstate.bias.repr = VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT; - renderstate.bias.exact = false; - } + renderstate.bias.repr = depthBiasRepr->depthBiasRepresentation; + renderstate.bias.exact = depthBiasRepr->depthBiasExact != VK_FALSE; + } + else + { + renderstate.bias.repr = VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT; + renderstate.bias.exact = false; } } - else - { - commandBuffer = VK_NULL_HANDLE; - } - } - if(commandBuffer != VK_NULL_HANDLE) ObjDisp(commandBuffer)->CmdSetDepthBias2EXT(Unwrap(commandBuffer), &DepthBiasInfo); + } } return true; diff --git a/renderdoc/driver/vulkan/wrappers/vk_misc_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_misc_funcs.cpp index 82b204919fe..f395390970b 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_misc_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_misc_funcs.cpp @@ -1941,15 +1941,12 @@ bool WrappedVulkan::Serialise_vkCopyImageToImage(SerialiserType &ser, VkDevice d VulkanEventNode &eventNode = GetLastEventNode(); if(CopyImageToImageInfo.srcImage == CopyImageToImageInfo.dstImage) { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(CopyImageToImageInfo.srcImage), ResourceUsage::Copy)); + eventNode.AddResourceUsage(GetResID(CopyImageToImageInfo.srcImage), ResourceUsage::Copy); } else { - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(CopyImageToImageInfo.srcImage), ResourceUsage::CopySrc)); - eventNode.resourceUsage.push_back( - make_rdcpair(GetResID(CopyImageToImageInfo.dstImage), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(CopyImageToImageInfo.srcImage), ResourceUsage::CopySrc); + eventNode.AddResourceUsage(GetResID(CopyImageToImageInfo.dstImage), ResourceUsage::CopyDst); } } } @@ -2030,7 +2027,7 @@ bool WrappedVulkan::Serialise_vkCopyImageToMemory(SerialiserType &ser, VkDevice AddAction(action); VulkanEventNode &eventNode = GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(srcImage), ResourceUsage::CopySrc)); + eventNode.AddResourceUsage(GetResID(srcImage), ResourceUsage::CopySrc); } } @@ -2115,7 +2112,7 @@ bool WrappedVulkan::Serialise_vkCopyMemoryToImage(SerialiserType &ser, VkDevice AddAction(action); VulkanEventNode &eventNode = GetLastEventNode(); - eventNode.resourceUsage.push_back(make_rdcpair(GetResID(dstImage), ResourceUsage::CopyDst)); + eventNode.AddResourceUsage(GetResID(dstImage), ResourceUsage::CopyDst); } } diff --git a/renderdoc/driver/vulkan/wrappers/vk_queue_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_queue_funcs.cpp index 7804fc9a2c1..dad311e2337 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_queue_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_queue_funcs.cpp @@ -1324,7 +1324,7 @@ bool WrappedVulkan::Serialise_vkQueueSubmit(SerialiserType &ser, VkQueue queue, // add an action use for this submission, to tally up with any debug messages that come from it if(IsLoading(m_State)) - m_LoadingEventNode.addActionUse = true; + GetLoadingEventNode().addActionUse = true; rdcarray cmds; @@ -1553,13 +1553,18 @@ bool WrappedVulkan::Serialise_vkQueueSubmit2(SerialiserType &ser, VkQueue queue, // add an action use for this submission, to tally up with any debug messages that come from it if(IsLoading(m_State)) - m_LoadingEventNode.addActionUse = true; + GetLoadingEventNode().addActionUse = true; for(uint32_t sub = 0; sub < submitCount; sub++) { rdcstr basename = StringFormat::Fmt("vkQueueSubmit2(%u)", pSubmits[sub].commandBufferInfoCount); - ReplayQueueSubmit(queue, pSubmits[sub], basename); + VkSubmitInfo2 submitInfo = pSubmits[sub]; + submitInfo.waitSemaphoreInfoCount = 0; + submitInfo.pWaitSemaphoreInfos = NULL; + submitInfo.signalSemaphoreInfoCount = 0; + submitInfo.pSignalSemaphoreInfos = NULL; + ReplayQueueSubmit(queue, submitInfo, basename); } if(submitCount == 0) { diff --git a/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp index bdefe5e36b1..3f8f6e9dfa6 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp @@ -1106,8 +1106,7 @@ bool WrappedVulkan::SerialiseUnmap(SerialiserType &ser, VkDeviceMemory memory, u } if(IsLoading(m_State)) - m_LoadingEventNode.resourceUsage.push_back( - make_rdcpair(GetResID(memory), ResourceUsage::CPUWrite)); + AddEventResourceUsage(GetResID(memory), ResourceUsage::CPUWrite); const Intervals &bindings = m_CreationInfo.m_Memory[GetResID(memory)].bindings; @@ -1463,8 +1462,7 @@ bool WrappedVulkan::Serialise_vkFlushMappedMemoryRanges(SerialiserType &ser, VkD if(IsReplayingAndReading() && MemRange.memory != VK_NULL_HANDLE && MemRange.size > 0) { if(IsLoading(m_State)) - m_LoadingEventNode.resourceUsage.push_back( - make_rdcpair(GetResID(MemRange.memory), ResourceUsage::CPUWrite)); + AddEventResourceUsage(GetResID(MemRange.memory), ResourceUsage::CPUWrite); VkResult ret = ObjDisp(device)->MapMemory(Unwrap(device), Unwrap(MemRange.memory), MemRange.offset, diff --git a/renderdoc/driver/vulkan/wrappers/vk_sync_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_sync_funcs.cpp index 1867a1f0c68..90ad640b079 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_sync_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_sync_funcs.cpp @@ -461,6 +461,7 @@ VkResult WrappedVulkan::vkSetEvent(VkDevice device, VkEvent event) Serialise_vkSetEvent(ser, device, event); m_FrameCaptureRecord->AddChunk(scope.Get()); + GetResourceManager()->MarkResourceFrameReferenced(GetResID(event), eFrameRef_Read); } return ret; @@ -499,6 +500,7 @@ VkResult WrappedVulkan::vkResetEvent(VkDevice device, VkEvent event) Serialise_vkResetEvent(ser, device, event); m_FrameCaptureRecord->AddChunk(scope.Get()); + GetResourceManager()->MarkResourceFrameReferenced(GetResID(event), eFrameRef_Read); } return ret; @@ -549,6 +551,7 @@ VkResult WrappedVulkan::vkGetEventStatus(VkDevice device, VkEvent event) Serialise_vkGetEventStatus(ser, device, event); m_FrameCaptureRecord->AddChunk(scope.Get()); + GetResourceManager()->MarkResourceFrameReferenced(GetResID(event), eFrameRef_Read); } } @@ -658,17 +661,14 @@ bool WrappedVulkan::Serialise_vkCmdSetEvent(SerialiserType &ser, VkCommandBuffer m_LastCmdBufferID = GetResID(commandBuffer); // see top of this file for current event/fence handling - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - else - commandBuffer = VK_NULL_HANDLE; - } - // if(commandBuffer != VK_NULL_HANDLE) - // ObjDisp(commandBuffer)->CmdSetEvent(Unwrap(commandBuffer), Unwrap(event), stageMask); + // ObjDisp(commandBuffer)->CmdSetEvent(Unwrap(commandBuffer), Unwrap(event), stageMask); + } } return true; @@ -713,17 +713,12 @@ bool WrappedVulkan::Serialise_vkCmdResetEvent(SerialiserType &ser, VkCommandBuff m_LastCmdBufferID = GetResID(commandBuffer); // see top of this file for current event/fence handling - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - else - commandBuffer = VK_NULL_HANDLE; - } - if(commandBuffer != VK_NULL_HANDLE) - { // ObjDisp(commandBuffer)->CmdResetEvent(Unwrap(commandBuffer), Unwrap(event), mask); } } @@ -799,60 +794,53 @@ bool WrappedVulkan::Serialise_vkCmdWaitEvents( { m_LastCmdBufferID = GetResID(commandBuffer); - for(uint32_t i = 0; i < bufferMemoryBarrierCount; i++) + bool loading = IsLoading(m_State); + if(InRerecordRange(m_LastCmdBufferID)) { - if(pBufferMemoryBarriers[i].buffer != VK_NULL_HANDLE) + if(!loading) + commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); + + for(uint32_t i = 0; i < bufferMemoryBarrierCount; i++) { - bufBarriers.push_back(pBufferMemoryBarriers[i]); - bufBarriers.back().buffer = Unwrap(bufBarriers.back().buffer); + if(pBufferMemoryBarriers[i].buffer != VK_NULL_HANDLE) + { + bufBarriers.push_back(pBufferMemoryBarriers[i]); + bufBarriers.back().buffer = Unwrap(bufBarriers.back().buffer); - RemapQueueFamilyIndices(bufBarriers.back().srcQueueFamilyIndex, - bufBarriers.back().dstQueueFamilyIndex); + RemapQueueFamilyIndices(bufBarriers.back().srcQueueFamilyIndex, + bufBarriers.back().dstQueueFamilyIndex); + } } - } - for(uint32_t i = 0; i < imageMemoryBarrierCount; i++) - { - if(pImageMemoryBarriers[i].image != VK_NULL_HANDLE) + for(uint32_t i = 0; i < imageMemoryBarrierCount; i++) { - imgBarriers.push_back(pImageMemoryBarriers[i]); - imgBarriers.back().image = Unwrap(imgBarriers.back().image); + if(pImageMemoryBarriers[i].image != VK_NULL_HANDLE) + { + imgBarriers.push_back(pImageMemoryBarriers[i]); + imgBarriers.back().image = Unwrap(imgBarriers.back().image); - RemapQueueFamilyIndices(imgBarriers.back().srcQueueFamilyIndex, - imgBarriers.back().dstQueueFamilyIndex); + RemapQueueFamilyIndices(imgBarriers.back().srcQueueFamilyIndex, + imgBarriers.back().dstQueueFamilyIndex); + } } - } - // see top of this file for current event/fence handling - - VkEventCreateInfo evInfo = { - VK_STRUCTURE_TYPE_EVENT_CREATE_INFO, - NULL, - 0, - }; + // see top of this file for current event/fence handling + VkEventCreateInfo evInfo = { + VK_STRUCTURE_TYPE_EVENT_CREATE_INFO, + NULL, + 0, + }; - if(IsActiveReplaying(m_State)) - { - if(InRerecordRange(m_LastCmdBufferID)) - commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - else - commandBuffer = VK_NULL_HANDLE; - } - else - { - for(uint32_t i = 0; i < imageMemoryBarrierCount; i++) + if(loading) { - const VkImageMemoryBarrier &b = pImageMemoryBarriers[i]; - if(b.image != VK_NULL_HANDLE && b.oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) + for(uint32_t i = 0; i < imageMemoryBarrierCount; i++) { - m_LoadingEventNode.resourceUsage.push_back( - make_rdcpair(GetResID(b.image), ResourceUsage::Discard)); + const VkImageMemoryBarrier &b = pImageMemoryBarriers[i]; + if(b.image != VK_NULL_HANDLE && b.oldLayout == VK_IMAGE_LAYOUT_UNDEFINED) + AddEventResourceUsage(GetResID(b.image), ResourceUsage::Discard); } } - } - if(commandBuffer != VK_NULL_HANDLE) - { // don't wrap this event VkEvent ev = VK_NULL_HANDLE; ObjDisp(commandBuffer)->CreateEvent(Unwrap(GetDev()), &evInfo, NULL, &ev); @@ -878,7 +866,7 @@ bool WrappedVulkan::Serialise_vkCmdWaitEvents( memoryBarrierCount, pMemoryBarriers, (uint32_t)bufBarriers.size(), bufBarriers.data(), (uint32_t)imgBarriers.size(), imgBarriers.data()); - if(m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest) + if(!loading && m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest) { for(uint32_t i = 0; i < imageMemoryBarrierCount; i++) { @@ -1171,17 +1159,14 @@ bool WrappedVulkan::Serialise_vkCmdSetEvent2(SerialiserType &ser, VkCommandBuffe m_LastCmdBufferID = GetResID(commandBuffer); // see top of this file for current event/fence handling - - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - else - commandBuffer = VK_NULL_HANDLE; - } - // if(commandBuffer != VK_NULL_HANDLE) - // ObjDisp(commandBuffer)->CmdSetEvent2(Unwrap(commandBuffer), Unwrap(event), &DependencyInfo); + // ObjDisp(commandBuffer)->CmdSetEvent2(Unwrap(commandBuffer), Unwrap(event), &DependencyInfo); + } } return true; @@ -1233,20 +1218,14 @@ bool WrappedVulkan::Serialise_vkCmdResetEvent2(SerialiserType &ser, VkCommandBuf if(IsReplayingAndReading()) { - m_LastCmdBufferID = GetResID(commandBuffer); - // see top of this file for current event/fence handling - if(IsActiveReplaying(m_State)) + if(InRerecordRange(m_LastCmdBufferID)) { - if(InRerecordRange(m_LastCmdBufferID)) + bool loading = IsLoading(m_State); + if(!loading) commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - else - commandBuffer = VK_NULL_HANDLE; - } - if(commandBuffer != VK_NULL_HANDLE) - { // ObjDisp(commandBuffer)->CmdResetEvent2(Unwrap(commandBuffer), Unwrap(event), stageMask); } } @@ -1299,74 +1278,68 @@ bool WrappedVulkan::Serialise_vkCmdWaitEvents2(SerialiserType &ser, VkCommandBuf { m_LastCmdBufferID = GetResID(commandBuffer); - rdcarray imgBarriers; - rdcarray bufBarriers; - - for(uint32_t evIdx = 0; evIdx < eventCount; evIdx++) + bool loading = IsLoading(m_State); + if(InRerecordRange(m_LastCmdBufferID)) { - imgBarriers.clear(); - bufBarriers.clear(); + if(!loading) + commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - const VkDependencyInfo &depInfo = pDependencyInfos[evIdx]; - RemapMemoryRangeBarriers(depInfo); + rdcarray imgBarriers; + rdcarray bufBarriers; - for(uint32_t i = 0; i < depInfo.bufferMemoryBarrierCount; i++) + for(uint32_t evIdx = 0; evIdx < eventCount; evIdx++) { - if(depInfo.pBufferMemoryBarriers[i].buffer != VK_NULL_HANDLE) + imgBarriers.clear(); + bufBarriers.clear(); + + const VkDependencyInfo &depInfo = pDependencyInfos[evIdx]; + RemapMemoryRangeBarriers(depInfo); + + for(uint32_t i = 0; i < depInfo.bufferMemoryBarrierCount; i++) { - bufBarriers.push_back(depInfo.pBufferMemoryBarriers[i]); - bufBarriers.back().buffer = Unwrap(bufBarriers.back().buffer); + if(depInfo.pBufferMemoryBarriers[i].buffer != VK_NULL_HANDLE) + { + bufBarriers.push_back(depInfo.pBufferMemoryBarriers[i]); + bufBarriers.back().buffer = Unwrap(bufBarriers.back().buffer); - RemapQueueFamilyIndices(bufBarriers.back().srcQueueFamilyIndex, - bufBarriers.back().dstQueueFamilyIndex); + RemapQueueFamilyIndices(bufBarriers.back().srcQueueFamilyIndex, + bufBarriers.back().dstQueueFamilyIndex); + } } - } - for(uint32_t i = 0; i < depInfo.imageMemoryBarrierCount; i++) - { - if(depInfo.pImageMemoryBarriers[i].image != VK_NULL_HANDLE) + for(uint32_t i = 0; i < depInfo.imageMemoryBarrierCount; i++) { - imgBarriers.push_back(depInfo.pImageMemoryBarriers[i]); - imgBarriers.back().image = Unwrap(imgBarriers.back().image); + if(depInfo.pImageMemoryBarriers[i].image != VK_NULL_HANDLE) + { + imgBarriers.push_back(depInfo.pImageMemoryBarriers[i]); + imgBarriers.back().image = Unwrap(imgBarriers.back().image); - RemapQueueFamilyIndices(imgBarriers.back().srcQueueFamilyIndex, - imgBarriers.back().dstQueueFamilyIndex); + RemapQueueFamilyIndices(imgBarriers.back().srcQueueFamilyIndex, + imgBarriers.back().dstQueueFamilyIndex); + } } - } - // see top of this file for current event/fence handling + // see top of this file for current event/fence handling - VkDependencyInfo UnwrappedDependencyInfo = depInfo; + VkDependencyInfo UnwrappedDependencyInfo = depInfo; - UnwrappedDependencyInfo.pBufferMemoryBarriers = bufBarriers.data(); - UnwrappedDependencyInfo.bufferMemoryBarrierCount = (uint32_t)bufBarriers.size(); - UnwrappedDependencyInfo.pImageMemoryBarriers = imgBarriers.data(); - UnwrappedDependencyInfo.imageMemoryBarrierCount = (uint32_t)imgBarriers.size(); + UnwrappedDependencyInfo.pBufferMemoryBarriers = bufBarriers.data(); + UnwrappedDependencyInfo.bufferMemoryBarrierCount = (uint32_t)bufBarriers.size(); + UnwrappedDependencyInfo.pImageMemoryBarriers = imgBarriers.data(); + UnwrappedDependencyInfo.imageMemoryBarrierCount = (uint32_t)imgBarriers.size(); - if(IsActiveReplaying(m_State)) - { - if(InRerecordRange(m_LastCmdBufferID)) - commandBuffer = RerecordCmdBuf(m_LastCmdBufferID); - else - commandBuffer = VK_NULL_HANDLE; - } - else - { - for(uint32_t i = 0; i < depInfo.imageMemoryBarrierCount; i++) + if(loading) { - const VkImageMemoryBarrier2 &b = depInfo.pImageMemoryBarriers[i]; - if(b.image != VK_NULL_HANDLE && b.oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && - b.newLayout != VK_IMAGE_LAYOUT_UNDEFINED) + for(uint32_t i = 0; i < depInfo.imageMemoryBarrierCount; i++) { - m_LoadingEventNode.resourceUsage.push_back( - make_rdcpair(GetResID(b.image), ResourceUsage::Discard)); + const VkImageMemoryBarrier2 &b = depInfo.pImageMemoryBarriers[i]; + if(b.image != VK_NULL_HANDLE && b.oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && + b.newLayout != VK_IMAGE_LAYOUT_UNDEFINED) + AddEventResourceUsage(GetResID(b.image), ResourceUsage::Discard); } } - } - if(commandBuffer != VK_NULL_HANDLE) - { - if(IsLoading(m_State) && evIdx == 0) + if(loading && evIdx == 0) { bool descBarrier = false; @@ -1404,8 +1377,8 @@ bool WrappedVulkan::Serialise_vkCmdWaitEvents2(SerialiserType &ser, VkCommandBuf continue; } - if(!IsLoading(m_State) && (barrier.oldLayout == VK_IMAGE_LAYOUT_PREINITIALIZED || - barrier.oldLayout == VK_IMAGE_LAYOUT_ZERO_INITIALIZED_EXT)) + if(!loading && (barrier.oldLayout == VK_IMAGE_LAYOUT_PREINITIALIZED || + barrier.oldLayout == VK_IMAGE_LAYOUT_ZERO_INITIALIZED_EXT)) { // This is a transition from PRENITIALIZED, but we've already done this barrier once // (when loading); Since we couldn't transition back to PREINITIALIZED, we instead left @@ -1422,7 +1395,7 @@ bool WrappedVulkan::Serialise_vkCmdWaitEvents2(SerialiserType &ser, VkCommandBuf ObjDisp(commandBuffer)->CmdSetEvent2(Unwrap(commandBuffer), ev, &UnwrappedDependencyInfo); ObjDisp(commandBuffer)->CmdWaitEvents2(Unwrap(commandBuffer), 1, &ev, &UnwrappedDependencyInfo); - if(m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest) + if(!loading && m_ReplayOptions.optimisation != ReplayOptimisationLevel::Fastest) { for(uint32_t i = 0; i < depInfo.imageMemoryBarrierCount; i++) { diff --git a/renderdoc/os/posix/linux/linux_stringio.cpp b/renderdoc/os/posix/linux/linux_stringio.cpp index b9730336703..704b5035b55 100644 --- a/renderdoc/os/posix/linux/linux_stringio.cpp +++ b/renderdoc/os/posix/linux/linux_stringio.cpp @@ -739,11 +739,15 @@ iconv_t iconvUTF82Wide = (iconv_t)-1; // iconv is not thread safe when sharing an iconv_t descriptor // I don't expect much contention but if it happens we could TryLock // before creating a temporary iconv_t, or hold two iconv_ts, or something. -Threading::CriticalSection iconvLock; +Threading::CriticalSection &iconvLock() +{ + static Threading::CriticalSection *lock = new Threading::CriticalSection; + return *lock; +} void Shutdown() { - SCOPED_LOCK(iconvLock); + SCOPED_LOCK(iconvLock()); if(iconvWide2UTF8 != (iconv_t)-1) iconv_close(iconvWide2UTF8); @@ -766,7 +770,7 @@ rdcstr Wide2UTF8(const rdcwstr &s) size_t ret; { - SCOPED_LOCK(iconvLock); + SCOPED_LOCK(iconvLock()); if(iconvWide2UTF8 == (iconv_t)-1) iconvWide2UTF8 = iconv_open("UTF-8", "WCHAR_T"); @@ -811,7 +815,7 @@ rdcwstr UTF82Wide(const rdcstr &s) size_t ret; { - SCOPED_LOCK(iconvLock); + SCOPED_LOCK(iconvLock()); if(iconvUTF82Wide == (iconv_t)-1) iconvUTF82Wide = iconv_open("WCHAR_T", "UTF-8"); diff --git a/renderdoc/os/posix/posix_process.cpp b/renderdoc/os/posix/posix_process.cpp index 9d0b98fbc8a..96242dd5860 100644 --- a/renderdoc/os/posix/posix_process.cpp +++ b/renderdoc/os/posix/posix_process.cpp @@ -916,10 +916,19 @@ void GetHookedEnvp(char *const *envp, rdcstr &envpStr, rdcarray &modifie void ResetHookingEnvVars() { - direct_setenv(LIB_PATH_ENV_VAR, Process::GetEnvVariable("DCOMP_ORIGLIBPATH").c_str(), true); - direct_setenv(PRELOAD_ENV_VAR, Process::GetEnvVariable("DCOMP_ORIGPRELOAD").c_str(), true); - direct_setenv("DCOMP_ORIGLIBPATH", "", true); - direct_setenv("DCOMP_ORIGPRELOAD", "", true); + rdcstr origpath = Process::GetEnvVariable("DCOMP_ORIGLIBPATH"); + rdcstr origpreload = Process::GetEnvVariable("DCOMP_ORIGPRELOAD"); + + if(!origpath.empty()) + { + direct_setenv(LIB_PATH_ENV_VAR, origpath.c_str(), true); + direct_setenv("DCOMP_ORIGLIBPATH", "", true); + } + if(!origpreload.empty()) + { + direct_setenv(PRELOAD_ENV_VAR, origpreload.c_str(), true); + direct_setenv("DCOMP_ORIGPRELOAD", "", true); + } } rdcpair Process::LaunchAndInjectIntoProcess( diff --git a/renderdoc/replay/entry_points.cpp b/renderdoc/replay/entry_points.cpp index 0b75ddfbcb6..846081aea49 100644 --- a/renderdoc/replay/entry_points.cpp +++ b/renderdoc/replay/entry_points.cpp @@ -890,17 +890,17 @@ extern "C" RENDERDOC_API int RENDERDOC_CC DCOMP_RunFunctionalTests(const rdcarra { #if ENABLED(RDOC_WIN32) const char *moduledir = "/pymodules"; - const char *modulename = "dgcore.pyd"; + const char *modulename = "renderdoc.pyd"; rdcstr pythonlibs[] = {"python3?.dll"}; #elif ENABLED(RDOC_LINUX) const char *moduledir = ""; - const char *modulename = "dgcore.so"; + const char *modulename = "renderdoc.so"; // we don't care about pymalloc or not rdcstr pythonlibs[] = {"libpython3.?m.so.1.0", "libpython3.?.so.1.0", "libpython3.?m.so", "libpython3.?.so"}; #elif ENABLED(RDOC_APPLE) const char *moduledir = ""; - const char *modulename = "dgcore.so"; + const char *modulename = "renderdoc.so"; rdcstr pythonlibs[] = {"libpython3.?.dylib"}; #else const char *moduledir = ""; @@ -1007,10 +1007,10 @@ extern "C" RENDERDOC_API int RENDERDOC_CC DCOMP_RunFunctionalTests(const rdcarra // specify script path StringFormat::UTF82Wide(scriptPath), // specify native library path - L"--dgcore", + L"--renderdoc", StringFormat::UTF82Wide(libPath), // specify python module path - L"--pydgcore", + L"--pyrenderdoc", StringFormat::UTF82Wide(modulePath), }); diff --git a/renderdocshim/renderdocshim.cpp b/renderdocshim/renderdocshim.cpp index 1d0c87b0e17..1bfa02260cf 100644 --- a/renderdocshim/renderdocshim.cpp +++ b/renderdocshim/renderdocshim.cpp @@ -93,10 +93,7 @@ void CheckHook() if(exepath) { - // no memset :). - for(int i = 0; i < exepathLen; i++) - exepath[i] = 0; - + // VirtualAlloc leaves a zero terminator even when the path is truncated. GetModuleFileNameW(NULL, exepath, exepathLen - 1); // no str*cmp functions diff --git a/util/buildscripts/build_windows_release.ps1 b/util/buildscripts/build_windows_release.ps1 index ea9b5e98c0f..9e8e47cc64c 100644 --- a/util/buildscripts/build_windows_release.ps1 +++ b/util/buildscripts/build_windows_release.ps1 @@ -229,7 +229,7 @@ try } } - & $bootstrapExportCheck -Toolchain $Toolchain -Platform $Platform + & $bootstrapExportCheck -Toolchain $Toolchain -Platform $Platform -DumpbinPath $dumpbinPath if($LASTEXITCODE -ne 0) { throw 'Bootstrap export validation failed' diff --git a/util/buildscripts/check_windows_bootstrap_exports.ps1 b/util/buildscripts/check_windows_bootstrap_exports.ps1 index a8f7acf542b..65c1ec1de2c 100644 --- a/util/buildscripts/check_windows_bootstrap_exports.ps1 +++ b/util/buildscripts/check_windows_bootstrap_exports.ps1 @@ -4,25 +4,24 @@ param( [string]$Toolchain = 'MSVC', [ValidateSet('Win32', 'x64')] - [string]$Platform = 'x64' + [string]$Platform = 'x64', + + [string]$DumpbinPath ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' $repositoryRoot = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot '..\..')).Path -$vswherePath = Join-Path ${env:ProgramFiles(x86)} ` - 'Microsoft Visual Studio\Installer\vswhere.exe' -if(-not (Test-Path -LiteralPath $vswherePath -PathType Leaf)) +if(-not $DumpbinPath) { - throw "vswhere.exe was not found: $vswherePath" + . (Join-Path $PSScriptRoot 'windows_toolchain.ps1') + $selectedToolchain = Get-DCompWindowsToolchain + $DumpbinPath = Join-Path $selectedToolchain.ToolsRoot 'bin\Hostx64\x64\dumpbin.exe' } - -$dumpbinPath = & $vswherePath -latest -products * ` - -find 'VC\Tools\MSVC\**\bin\Hostx64\x64\dumpbin.exe' | Select-Object -First 1 -if(-not $dumpbinPath) +if(-not (Test-Path -LiteralPath $DumpbinPath -PathType Leaf)) { - throw 'dumpbin.exe was not found' + throw "dumpbin.exe was not found: $DumpbinPath" } function Get-ExportMap([string]$Path) diff --git a/util/buildscripts/tests/test_upstream_review.py b/util/buildscripts/tests/test_upstream_review.py index f0618a6e2f6..e2837969d2c 100644 --- a/util/buildscripts/tests/test_upstream_review.py +++ b/util/buildscripts/tests/test_upstream_review.py @@ -35,15 +35,14 @@ def test_indirect_address_operations_record_each_loading_event(self): self.assertIn(use, single, name) def test_async_capture_access_never_executes_inline(self): - body = source("qrenderdoc/Code/Interface/QRDInterface.h").split( - "bool AccessInvoke(", 1 - )[1].split("bool BlockAccessInvoke(", 1)[0] + body = source("qrenderdoc/Code/ReplayManager.cpp").split( + "bool ReplayManager::AccessInvoke(", 1 + )[1].split("void ReplayManager::CancelReplayLoop(", 1)[0] asynchronous = body.split("if(!blocking)", 1)[1].split("else if(", 1)[0] self.assertRegex(asynchronous, r"if\(!IsRunning\(\)\)\s+return false;") self.assertIn("AsyncInvoke(invoke, tag)", asynchronous) self.assertNotIn("callback(", asynchronous) self.assertIn("if(ICaptureAccess *access = GetCaptureAccess())", body) - self.assertIn("else if(CurrentRemote().IsConnected() && IsRunning())", body) def test_dependency_progress_waits_are_bounded_and_atomic(self): body = source("qrenderdoc/Code/CaptureContext.cpp").split( @@ -86,7 +85,9 @@ def test_failed_save_never_enters_transfer_wait(self): def test_remote_access_requires_a_running_replay_worker(self): body = source("qrenderdoc/Code/Interface/QRDInterface.h") - self.assertIn("if(CurrentRemote().IsConnected() && IsRunning())", body) + implementation = source("qrenderdoc/Code/ReplayManager.cpp") + self.assertIn("else if((CurrentRemote().IsConnected() || forceReplay) && IsRunning())", + implementation) self.assertIn("virtual bool IsRunning() = 0;", body) self.assertIn("virtual bool IsReplayThread() = 0;", body) @@ -122,8 +123,12 @@ def test_optional_counter_and_binding_arrays_reset_old_state(self): self.assertIn("renderstate.xfbcounters[i].offs = 0;", counters) bindings = body.split("bool WrappedVulkan::Serialise_vkCmdBindTransformFeedbackBuffers2EXT", 1)[1].split("void WrappedVulkan::vkCmdBindTransformFeedbackBuffers2EXT", 1)[0] self.assertIn("if(pBindingInfos)", bindings) - self.assertIn("renderstate.xfbbuffers[firstBinding + i].buf = ResourceId();", bindings) - self.assertIn("pBindingInfos ? GetResIDFromAddr", bindings) + self.assertIn("auto &binding = renderstate.xfbbuffers[firstBinding + i];", bindings) + self.assertIn("binding.buf = ResourceId();", bindings) + self.assertIn("binding.offs = 0;", bindings) + self.assertIn("binding.size = 0;", bindings) + self.assertIn("if(InRerecordRange(m_LastCmdBufferID))", bindings) + self.assertIn("if(!loading)", bindings) def test_memory_range_barriers_use_shared_replay_mapping(self): commands = source("renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp") diff --git a/util/test/demos/CMakeLists.txt b/util/test/demos/CMakeLists.txt index 861699db95e..dbab13e928e 100644 --- a/util/test/demos/CMakeLists.txt +++ b/util/test/demos/CMakeLists.txt @@ -118,12 +118,12 @@ set(VULKAN_SRC vk/vk_descriptor_reuse.cpp vk/vk_descriptor_variable_count.cpp vk/vk_descriptor_buffer_analyse.cpp + vk/vk_device_address_commands.cpp vk/vk_discard_rects.cpp vk/vk_discard_zoo.cpp vk/vk_draw_zoo.cpp vk/vk_dynamic_rendering.cpp vk/vk_empty_capture.cpp - vk/vk_ext_buffer_address.cpp vk/vk_custom_resolve.cpp vk/vk_extended_dyn_state.cpp vk/vk_graphics_pipeline.cpp @@ -166,6 +166,7 @@ set(VULKAN_SRC vk/vk_simple_triangle.cpp vk/vk_spec_constants.cpp vk/vk_spirv_13_shaders.cpp + vk/vk_stripped_shaders.cpp vk/vk_subgroup_zoo.cpp vk/vk_structured_buffer_nested.cpp vk/vk_sync2.cpp @@ -214,6 +215,7 @@ set(OPENGL_SRC gl/gl_resource_lifetimes.cpp gl/gl_runtime_bind_prog_to_pipe.cpp gl/gl_separable_geometry_shader.cpp + gl/gl_shader_debug_zoo.cpp gl/gl_shader_editing.cpp gl/gl_shader_isa.cpp gl/gl_simple_triangle.cpp @@ -234,6 +236,10 @@ set(SRC main.cpp project(demos) +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.1) + list(APPEND warning_flags -Wno-deprecated-literal-operator) +endif() + if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") list(APPEND warning_flags -Werror -Wno-unused-result -Wno-nullability-completeness) diff --git a/util/test/demos/d3d11/d3d11_amd_shader_extensions.cpp b/util/test/demos/d3d11/d3d11_amd_shader_extensions.cpp index 48efd363900..767862b433c 100644 --- a/util/test/demos/d3d11/d3d11_amd_shader_extensions.cpp +++ b/util/test/demos/d3d11/d3d11_amd_shader_extensions.cpp @@ -278,8 +278,9 @@ void main(uint3 threadID : SV_DispatchThreadID) ID3DBlobPtr vsblob = Compile(D3DDefaultVertex, "main", "vs_4_0"); // can't skip optimising and still have the extensions work, sadly - ID3DBlobPtr psblob = Compile(ags_header + BaryCentricPixel, "main", "ps_5_0", false); - ID3DBlobPtr csblob = Compile(ags_header + MaxCompute, "main", "cs_5_0", false); + ID3DBlobPtr psblob = + Compile(ags_header + BaryCentricPixel, "main", "ps_5_0", CompileOptionFlags::None); + ID3DBlobPtr csblob = Compile(ags_header + MaxCompute, "main", "cs_5_0", CompileOptionFlags::None); CreateDefaultInputLayout(vsblob); diff --git a/util/test/demos/d3d11/d3d11_groupshared.cpp b/util/test/demos/d3d11/d3d11_groupshared.cpp index e1692624ffa..82c9f80055d 100644 --- a/util/test/demos/d3d11/d3d11_groupshared.cpp +++ b/util/test/demos/d3d11/d3d11_groupshared.cpp @@ -163,7 +163,7 @@ void main(uint3 gid : SV_GroupThreadID) ID3D11UnorderedAccessViewPtr inUAV = MakeUAV(inBuf); ID3D11UnorderedAccessViewPtr outUAV = MakeUAV(outBuf); - ID3D11ComputeShaderPtr shad = CreateCS(Compile(comp, "main", "cs_5_0", true)); + ID3D11ComputeShaderPtr shad = CreateCS(Compile(comp, "main", "cs_5_0")); int cbufferdata[4]; memset(cbufferdata, 0, sizeof(cbufferdata)); diff --git a/util/test/demos/d3d11/d3d11_shader_debug_zoo.cpp b/util/test/demos/d3d11/d3d11_shader_debug_zoo.cpp index 2475f2e0799..44e33a14d87 100644 --- a/util/test/demos/d3d11/d3d11_shader_debug_zoo.cpp +++ b/util/test/demos/d3d11/d3d11_shader_debug_zoo.cpp @@ -1072,8 +1072,9 @@ float4 main(v2f IN, uint samp : SV_SampleIndex) : SV_Target0 vsblob->GetBufferSize(), &layout)); ID3D11VertexShaderPtr vs = CreateVS(vsblob); - ID3D11PixelShaderPtr ps = CreatePS(Compile(common + pixel, "main", "ps_5_0", true)); - ID3D11PixelShaderPtr psopt = CreatePS(Compile(common + pixel, "main", "ps_5_0", false)); + ID3D11PixelShaderPtr ps = CreatePS(Compile(common + pixel, "main", "ps_5_0")); + ID3D11PixelShaderPtr psopt = + CreatePS(Compile(common + pixel, "main", "ps_5_0", CompileOptionFlags::None)); ID3D11PixelShaderPtr flowps = CreatePS(Compile(common + flowPixel, "main", "ps_5_0")); static const uint32_t texDim = AlignUp(numTests, 64U) * 4; diff --git a/util/test/demos/d3d11/d3d11_storage_raster.cpp b/util/test/demos/d3d11/d3d11_storage_raster.cpp new file mode 100644 index 00000000000..50876770e53 --- /dev/null +++ b/util/test/demos/d3d11/d3d11_storage_raster.cpp @@ -0,0 +1,123 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2023-2026 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * 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 Software. + * + * THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "d3d11_test.h" + +RD_TEST(D3D11_Storage_Raster, D3D11GraphicsTest) +{ + static constexpr const char *Description = + "Testing stores to images from a rasterized draw with no rasterized outputs."; + + std::string vertex = R"EOSHADER( + +struct vertin +{ + float3 pos : POSITION; + float4 col : COLOR0; + float2 uv : TEXCOORD0; +}; + +struct v2f +{ + float4 pos : SV_POSITION; + float4 col : COLOR0; + float2 uv : TEXCOORD0; +}; + +v2f main(vertin IN) +{ + v2f OUT = (v2f)0; + + OUT.pos = float4(IN.pos.xyz, 1); + OUT.col = IN.col; + OUT.uv = IN.uv; + + return OUT; +} + +)EOSHADER"; + + std::string pixel = R"EOSHADER( + +struct v2f +{ + float4 pos : SV_POSITION; + float4 col : COLOR0; + float2 uv : TEXCOORD0; +}; + +RWByteAddressBuffer rwbuf : register(u0); + +void main(v2f IN) +{ + uint orig = 0; + rwbuf.InterlockedMin(0, uint(IN.pos.x), orig); + rwbuf.InterlockedMin(4, uint(IN.pos.y), orig); + rwbuf.InterlockedMax(8, uint(IN.pos.x), orig); + rwbuf.InterlockedMax(12, uint(IN.pos.y), orig); +} + +)EOSHADER"; + + int main() + { + // initialise, create window, create device, etc + if(!Init()) + return 3; + + ID3D11VertexShaderPtr vs = CreateVS(Compile(vertex, "main", "vs_5_0")); + ID3D11PixelShaderPtr ps = CreatePS(Compile(pixel, "main", "ps_5_0")); + + ID3D11BufferPtr buf = MakeBuffer().Size(64).ByteAddressed().UAV().SRV(); + ID3D11UnorderedAccessViewPtr uav = MakeUAV(buf).Format(DXGI_FORMAT_R32_TYPELESS); + + while(Running()) + { + ClearRenderTargetView(bbRTV, {0.2f, 0.2f, 0.2f, 1.0f}); + + ClearUnorderedAccessView(uav, Vec4u(150, 150, 150, 150)); + + IASetVertexBuffer(DefaultTriVB, sizeof(DefaultA2V), 0); + ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ctx->IASetInputLayout(defaultLayout); + + ctx->VSSetShader(vs, NULL, 0); + ctx->PSSetShader(ps, NULL, 0); + + RSSetViewport({0.0f, 0.0f, (float)screenWidth, (float)screenHeight, 0.0f, 1.0f}); + RSSetScissor({0, 0, screenWidth, screenHeight}); + + ctx->OMSetRenderTargetsAndUnorderedAccessViews(0, NULL, NULL, 0, 1, &uav.GetInterfacePtr(), + NULL); + + ctx->Draw(3, 0); + + Present(); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/demos/d3d11/d3d11_stripped_shaders.cpp b/util/test/demos/d3d11/d3d11_stripped_shaders.cpp index bd916b76135..7208af556f9 100644 --- a/util/test/demos/d3d11/d3d11_stripped_shaders.cpp +++ b/util/test/demos/d3d11/d3d11_stripped_shaders.cpp @@ -35,23 +35,45 @@ RD_TEST(D3D11_Stripped_Shaders, D3D11GraphicsTest) if(!Init()) return 3; - ID3DBlobPtr vsblob = Compile(D3DDefaultVertex, "main", "vs_5_0"); - ID3DBlobPtr psblob = Compile(D3DDefaultPixel, "main", "ps_5_0"); - - WriteBlob(GetCWD() + "tmp/D3D11_Stripped_Shaders/shader_debug.vs", vsblob, false); - WriteBlob(GetCWD() + "tmp/D3D11_Stripped_Shaders/shader_debug.ps", psblob, true); - - Strip(vsblob); - Strip(psblob); - - SetBlobPath(GetCWD() + "tmp/D3D11_Stripped_Shaders/shader_debug.vs", vsblob); + MakeDir((GetCWD() + "/tmp/D3D11_Stripped_Shaders").c_str()); + + // several variables: + // + // legacy whole unstripped blob, or dxc-style just pdb + // (for dxc-style) manual named or auto-named + // (for legacy-style) lz4 compressed or not + // (for legacy-style) PRIV pointed or SetPrivateData + // absolute or relative path + // + // we don't test all possible combinations but check at least one of each + + // PRIV will be set with absolute path + ID3DBlobPtr vsblob = + Compile(D3DDefaultVertex + "\n// shader source // vertex", "main", "vs_5_0", + CompileOptionFlags::SeparateDebugLegacy | CompileOptionFlags::SeparateDebugSetPRIV); + // we'll set relative SetPrivateData path below + ID3DBlobPtr psblob = + Compile(D3DDefaultPixel + "\n// shader source // pixel", "main", "ps_5_0", + CompileOptionFlags::SeparateDebugLegacy | CompileOptionFlags::ManualDebugName | + CompileOptionFlags::LZ4Compress); CreateDefaultInputLayout(vsblob); ID3D11VertexShaderPtr vs = CreateVS(vsblob); ID3D11PixelShaderPtr ps = CreatePS(psblob); - SetBlobPath("lz4#tmp/D3D11_Stripped_Shaders/shader_debug.ps", ps); + SetBlobPath("lz4#shader_ps.dbg", ps); + + // manual name will be set absolute in a manual ILDN + ID3DBlobPtr vsblob2 = + Compile(D3DDefaultVertex + "\n// shader source 2 // vertex", "main", "vs_5_0", + CompileOptionFlags::SeparateDebug | CompileOptionFlags::ManualDebugName); + // the fxc-generated ILDN will be relative + ID3DBlobPtr psblob2 = Compile(D3DDefaultPixel + "\n// shader source 2 // pixel", "main", + "ps_5_0", CompileOptionFlags::SeparateDebug); + + ID3D11VertexShaderPtr vs2 = CreateVS(vsblob2); + ID3D11PixelShaderPtr ps2 = CreatePS(psblob2); ID3D11BufferPtr vb = MakeBuffer().Vertex().Data(DefaultTri); @@ -70,6 +92,17 @@ RD_TEST(D3D11_Stripped_Shaders, D3D11GraphicsTest) ctx->OMSetRenderTargets(1, &bbRTV.GetInterfacePtr(), NULL); + setMarker("test: shader source"); + setMarker("vertex auto absolute"); + setMarker("pixel manual relative"); + ctx->Draw(3, 0); + + ctx->VSSetShader(vs2, NULL, 0); + ctx->PSSetShader(ps2, NULL, 0); + + setMarker("test: shader source 2"); + setMarker("vertex manual absolute"); + setMarker("pixel auto relative"); ctx->Draw(3, 0); Present(); diff --git a/util/test/demos/d3d11/d3d11_test.cpp b/util/test/demos/d3d11/d3d11_test.cpp index c6e4d194c1d..fcb385284f0 100644 --- a/util/test/demos/d3d11/d3d11_test.cpp +++ b/util/test/demos/d3d11/d3d11_test.cpp @@ -31,6 +31,7 @@ #include "../win32/win32_window.h" typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID, void **); +typedef HRESULT(WINAPI *PFN_GET_DEBUG_INTERFACE1)(UINT, REFIID, _COM_Outptr_ void **); namespace { @@ -51,6 +52,7 @@ struct Capabilities pD3DCompile dyn_D3DCompile = NULL; pD3DStripShader dyn_D3DStripShader = NULL; pD3DSetBlobPart dyn_D3DSetBlobPart = NULL; +pD3DGetBlobPart dyn_D3DGetBlobPart = NULL; PFN_D3D11_CREATE_DEVICE dyn_D3D11CreateDevice = NULL; PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN dyn_D3D11CreateDeviceAndSwapChain = NULL; @@ -94,6 +96,7 @@ void D3D11GraphicsTest::Prepare(int argc, char **argv) dyn_D3DCompile = (pD3DCompile)GetProcAddress(d3dcompiler, "D3DCompile"); dyn_D3DStripShader = (pD3DStripShader)GetProcAddress(d3dcompiler, "D3DStripShader"); dyn_D3DSetBlobPart = (pD3DSetBlobPart)GetProcAddress(d3dcompiler, "D3DSetBlobPart"); + dyn_D3DGetBlobPart = (pD3DGetBlobPart)GetProcAddress(d3dcompiler, "D3DGetBlobPart"); } HRESULT hr = S_OK; @@ -136,7 +139,7 @@ void D3D11GraphicsTest::Prepare(int argc, char **argv) else if(!factory) Avail = "Couldn't create DXGI factory"; else if(!dyn_D3D11CreateDevice || !dyn_D3D11CreateDeviceAndSwapChain || !dyn_D3DCompile || - !dyn_D3DStripShader || !dyn_D3DSetBlobPart) + !dyn_D3DStripShader || !dyn_D3DSetBlobPart || !dyn_D3DGetBlobPart) Avail = "Missing required entry point"; } @@ -319,6 +322,20 @@ void D3D11GraphicsTest::PostDeviceCreate() } } + if(breakOnDebug) + { + ID3D11InfoQueuePtr info = dev; + info->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, TRUE); + info->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, TRUE); + info->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, TRUE); + + D3D11_INFO_QUEUE_FILTER filter = {}; + filter.DenyList.NumIDs = (UINT)mutedMessages.size(); + filter.DenyList.pIDList = mutedMessages.data(); + + info->PushStorageFilter(&filter); + } + dev1 = dev; dev2 = dev; dev3 = dev; @@ -388,6 +405,20 @@ void D3D11GraphicsTest::Shutdown() DefaultTriPS = NULL; DefaultTriVB = NULL; + + PFN_GET_DEBUG_INTERFACE1 getDebug = + (PFN_GET_DEBUG_INTERFACE1)GetProcAddress(dxgi, "DXGIGetDebugInterface1"); + + if(debugDevice && getDebug && !subtest) + { + IDXGIDebug1Ptr dxgiDebug; + if(SUCCEEDED(getDebug(0, __uuidof(IDXGIDebug1), (void **)&dxgiDebug))) + { + dxgiDebug->ReportLiveObjects( + DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_FLAGS(DXGI_DEBUG_RLO_SUMMARY | DXGI_DEBUG_RLO_DETAIL | + DXGI_DEBUG_RLO_IGNORE_INTERNAL)); + } + } } bool D3D11GraphicsTest::Running() @@ -643,13 +674,24 @@ void D3D11GraphicsTest::SetStencilRef(UINT ref) } ID3DBlobPtr D3D11GraphicsTest::Compile(std::string src, std::string entry, std::string profile, - bool skipoptimise) + uint32_t compileOptions) { + const bool skipoptimise = ((compileOptions & CompileOptionFlags::SkipOptimise) != 0); + const bool separateDebugLegacy = ((compileOptions & CompileOptionFlags::SeparateDebugLegacy) != 0); + const bool separateDebugSetPRIV = + ((compileOptions & CompileOptionFlags::SeparateDebugSetPRIV) != 0); + const bool separateDebug = ((compileOptions & CompileOptionFlags::SeparateDebug) != 0); + const bool manualDebugName = ((compileOptions & CompileOptionFlags::ManualDebugName) != 0); + const bool lz4Compress = ((compileOptions & CompileOptionFlags::LZ4Compress) != 0); + ID3DBlobPtr blob = NULL; ID3DBlobPtr error = NULL; UINT flags = D3DCOMPILE_WARNINGS_ARE_ERRORS | D3DCOMPILE_DEBUG; + if((separateDebugLegacy || separateDebug) && !manualDebugName) + flags |= D3DCOMPILE_DEBUG_NAME_FOR_SOURCE; + if(skipoptimise) flags |= D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_OPTIMIZATION_LEVEL0; else @@ -668,6 +710,76 @@ ID3DBlobPtr D3D11GraphicsTest::Compile(std::string src, std::string entry, std:: return NULL; } + if(separateDebugLegacy || separateDebug) + { + std::string debugName; + if(manualDebugName) + { + debugName = "shader_" + profile.substr(0, 2) + ".dbg"; + } + else + { + ID3DBlobPtr nameBlob; + LPVOID bufferPointer = blob->GetBufferPointer(); + hr = dyn_D3DGetBlobPart(bufferPointer, blob->GetBufferSize(), D3D_BLOB_DEBUG_NAME, 0, + &nameBlob); + + if(SUCCEEDED(hr)) + { + const uint16_t *flags_len = (const uint16_t *)nameBlob->GetBufferPointer(); + + const char *name_str = (const char *)(flags_len + 2); + + debugName.assign(name_str, flags_len[1]); + } + else + { + TEST_ERROR("Couldn't get automatic name"); + debugName = "shader_" + profile.substr(0, 2) + ".dbg"; + } + } + + std::string path = tmpPath + "/" + debugName; + + if(separateDebug) + { + ID3DBlobPtr debugBlob; + dyn_D3DGetBlobPart(blob->GetBufferPointer(), blob->GetBufferSize(), D3D_BLOB_PDB, 0, + &debugBlob); + + WriteBlob(path, debugBlob, lz4Compress); + + if(manualDebugName) + { + std::string nameBlob = path; + // pad the blob to multiple of 4 + nameBlob.resize((path.size() + 0x3) & ~0x3); + + nameBlob.insert(0, 4, '\0'); + nameBlob[2] += path.size() & 0xff; + + if(path.size() > 255) + TEST_ERROR("tmp path is too long!"); + + ID3DBlobPtr newBlob; + + dyn_D3DSetBlobPart(blob->GetBufferPointer(), blob->GetBufferSize(), D3D_BLOB_DEBUG_NAME, 0, + nameBlob.c_str(), nameBlob.size(), &newBlob); + + blob = newBlob; + } + } + else if(separateDebugLegacy) + { + WriteBlob(path, blob, lz4Compress); + + if(separateDebugSetPRIV) + SetBlobPath(path, blob); + } + + Strip(blob); + } + return blob; } diff --git a/util/test/demos/d3d11/d3d11_test.h b/util/test/demos/d3d11/d3d11_test.h index 76397bf1340..93a1ee176ed 100644 --- a/util/test/demos/d3d11/d3d11_test.h +++ b/util/test/demos/d3d11/d3d11_test.h @@ -29,16 +29,6 @@ #include "dx/official/dxgi.h" #include "d3d11_helpers.h" -#include "dx/official/d3dcompiler.h" - -typedef HRESULT(WINAPI *pD3DStripShader)(_In_reads_bytes_(BytecodeLength) LPCVOID pShaderBytecode, - _In_ SIZE_T BytecodeLength, _In_ UINT uStripFlags, - _Out_ ID3DBlob **ppStrippedBlob); -typedef HRESULT(WINAPI *pD3DSetBlobPart)(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData, - _In_ SIZE_T SrcDataSize, _In_ D3D_BLOB_PART Part, - _In_ UINT Flags, _In_reads_bytes_(PartSize) LPCVOID pPart, - _In_ SIZE_T PartSize, _Out_ ID3DBlob **ppNewShader); - struct Win32Window; struct D3D11GraphicsTest : public GraphicsTest @@ -74,8 +64,25 @@ struct D3D11GraphicsTest : public GraphicsTest BufUAVType = 0xf00, }; + enum CompileOptionFlags + { + None = 0, + SkipOptimise = 1 << 0, + // the legacy path, where we write the unstripped blob somewhere and set a path either via PRIV + // name or SetPrivateData + SeparateDebugLegacy = 1 << 1, + SeparateDebugSetPRIV = 1 << 2, + // the 'new' path which is still manual but matches dxc's behaviour, where we pull out the PDB and set an ILDN name + SeparateDebug = 1 << 3, + // don't use the auto-generated name for a debug file, name it custom shader_Xs.dbg (so only one + // per stage per demo allowed) + ManualDebugName = 1 << 4, + // only possible for SeparateDebugLegacy and ManualDebugName, lz4 compress the resulting blob + LZ4Compress = 1 << 5, + }; + ID3DBlobPtr Compile(std::string src, std::string entry, std::string profile, - bool skipoptimise = true); + uint32_t compileOptions = CompileOptionFlags::SkipOptimise); void Strip(ID3DBlobPtr &ptr); void WriteBlob(std::string name, ID3DBlobPtr blob, bool compress); @@ -215,6 +222,8 @@ struct D3D11GraphicsTest : public GraphicsTest ID3D11DeviceContext4Ptr ctx4; ID3DUserDefinedAnnotationPtr annot; + std::vector mutedMessages; + private: static bool prepared_d3d11; }; diff --git a/util/test/demos/d3d11/d3d11_workgroup_zoo.cpp b/util/test/demos/d3d11/d3d11_workgroup_zoo.cpp index 37152d6227a..4ab4f8402b9 100644 --- a/util/test/demos/d3d11/d3d11_workgroup_zoo.cpp +++ b/util/test/demos/d3d11/d3d11_workgroup_zoo.cpp @@ -198,8 +198,8 @@ void main(uint3 inGTid : SV_GroupThreadID) compsizes[i].x, compsizes[i].y, compsizes[i].z); comppipe_name[i] = fmt::format("{}x{}x{}", compsizes[i].x, compsizes[i].y, compsizes[i].z); - testShaders[i] = CreateCS(Compile(defines + sizedefine + testShader, "main", "cs_5_0", true)); - perfShaders[i] = CreateCS(Compile(defines + sizedefine + perfShader, "main", "cs_5_0", true)); + testShaders[i] = CreateCS(Compile(defines + sizedefine + testShader, "main", "cs_5_0")); + perfShaders[i] = CreateCS(Compile(defines + sizedefine + perfShader, "main", "cs_5_0")); } while(Running()) diff --git a/util/test/demos/d3d12/d3d12_stripped_shaders.cpp b/util/test/demos/d3d12/d3d12_stripped_shaders.cpp new file mode 100644 index 00000000000..c86d156307a --- /dev/null +++ b/util/test/demos/d3d12/d3d12_stripped_shaders.cpp @@ -0,0 +1,102 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2023-2026 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * 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 Software. + * + * THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "d3d12_test.h" + +RD_TEST(D3D12_Stripped_Shaders, D3D12GraphicsTest) +{ + static constexpr const char *Description = + "Tests shaders with their debug/reflection info stripped out and stored in separate blobs."; + + void Prepare(int argc, char **argv) + { + D3D12GraphicsTest::Prepare(argc, argv); + + if(!Avail.empty()) + return; + + if(!m_DXILSupport) + Avail = "DXIL can't be compiled"; + } + + int main() + { + // initialise, create window, create device, etc + if(!Init()) + return 3; + + MakeDir((GetCWD() + "/tmp/D3D12_Stripped_Shaders").c_str()); + + // only a couple of variables: + // + // auto-named or manual named + // absolute or relative path + + // manual debug name will be absolute + ID3DBlobPtr vsblob = + Compile(D3DDefaultVertex + "\n// shader source // vertex", "main", "vs_6_0", + CompileOptionFlags::SeparateDebug | CompileOptionFlags::ManualDebugName); + // auto name will be relative + ID3DBlobPtr psblob = Compile(D3DDefaultPixel + "\n// shader source // pixel", "main", "ps_6_0", + CompileOptionFlags::SeparateDebug); + + ID3D12PipelineStatePtr pso = MakePSO().RootSig(DefaultTriSig).InputLayout().VS(vsblob).PS(psblob); + + while(Running()) + { + ID3D12GraphicsCommandListPtr cmd = GetCommandBuffer(); + + Reset(cmd); + + ID3D12ResourcePtr bb = StartUsingBackbuffer(cmd, D3D12_RESOURCE_STATE_RENDER_TARGET); + + ClearRenderTargetView(cmd, BBRTV, {0.2f, 0.2f, 0.2f, 1.0f}); + + cmd->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + + IASetVertexBuffer(cmd, DefaultTriVB, sizeof(DefaultA2V), 0); + cmd->SetPipelineState(pso); + cmd->SetGraphicsRootSignature(DefaultTriSig); + + SetMainWindowViewScissor(cmd); + + OMSetRenderTargets(cmd, {BBRTV}, {}); + + setMarker(cmd, "test: shader source"); + setMarker(cmd, "vertex manual absolute"); + setMarker(cmd, "pixel auto relative"); + cmd->DrawInstanced(3, 1, 0, 0); + + FinishUsingBackbuffer(cmd, D3D12_RESOURCE_STATE_RENDER_TARGET); + + cmd->Close(); + + SubmitAndPresent({cmd}); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/demos/d3d12/d3d12_test.cpp b/util/test/demos/d3d12/d3d12_test.cpp index 5d53f97557d..60880b87712 100644 --- a/util/test/demos/d3d12/d3d12_test.cpp +++ b/util/test/demos/d3d12/d3d12_test.cpp @@ -35,6 +35,7 @@ typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY1)(REFIID, void **); typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY2)(UINT, REFIID, void **); +typedef HRESULT(WINAPI *PFN_GET_DEBUG_INTERFACE1)(UINT, REFIID, _COM_Outptr_ void **); typedef DXC_API_IMPORT HRESULT(__stdcall *pDxcCreateInstance)(REFCLSID rclsid, REFIID riid, LPVOID *ppv); @@ -52,6 +53,7 @@ bool d3d12on7 = false; pD3DCompile dyn_D3DCompile = NULL; pD3DStripShader dyn_D3DStripShader = NULL; pD3DSetBlobPart dyn_D3DSetBlobPart = NULL; +pD3DGetBlobPart dyn_D3DGetBlobPart = NULL; pD3DCreateBlob dyn_CreateBlob = NULL; PFN_D3D12_CREATE_DEVICE dyn_D3D12CreateDevice = NULL; @@ -382,6 +384,7 @@ void D3D12GraphicsTest::Prepare(int argc, char **argv) dyn_D3DCompile = (pD3DCompile)GetProcAddress(d3dcompiler, "D3DCompile"); dyn_D3DStripShader = (pD3DStripShader)GetProcAddress(d3dcompiler, "D3DStripShader"); dyn_D3DSetBlobPart = (pD3DSetBlobPart)GetProcAddress(d3dcompiler, "D3DSetBlobPart"); + dyn_D3DGetBlobPart = (pD3DGetBlobPart)GetProcAddress(d3dcompiler, "D3DGetBlobPart"); dyn_CreateBlob = (pD3DCreateBlob)GetProcAddress(d3dcompiler, "D3DCreateBlob"); } @@ -441,7 +444,7 @@ void D3D12GraphicsTest::Prepare(int argc, char **argv) else if(!factory) Avail = "Couldn't create DXGI factory"; else if(!dyn_D3D12CreateDevice || !dyn_D3DCompile || !dyn_D3DStripShader || !dyn_D3DSetBlobPart || - !dyn_CreateBlob) + !dyn_D3DGetBlobPart || !dyn_CreateBlob) Avail = "Missing required entry point"; else if(!dyn_serializeRootSig && !dyn_serializeRootSigOld) Avail = "Missing required root signature serialize entry point"; @@ -486,6 +489,20 @@ bool D3D12GraphicsTest::Init() if(!dev) return false; + if(breakOnDebug) + { + ID3D12InfoQueuePtr info = dev; + info->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_CORRUPTION, TRUE); + info->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_ERROR, TRUE); + info->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_WARNING, TRUE); + + D3D12_INFO_QUEUE_FILTER filter = {}; + filter.DenyList.NumIDs = (UINT)mutedMessages.size(); + filter.DenyList.pIDList = mutedMessages.data(); + + info->PushStorageFilter(&filter); + } + { LUID luid = dev->GetAdapterLuid(); @@ -835,6 +852,21 @@ void D3D12GraphicsTest::Shutdown() queue = NULL; dev = NULL; devConfig = NULL; + + PFN_GET_DEBUG_INTERFACE1 getDebug = + (PFN_GET_DEBUG_INTERFACE1)GetProcAddress(dxgi, "DXGIGetDebugInterface1"); + + if(debugDevice && getDebug && !subtest) + { + IDXGIDebug1Ptr dxgiDebug; + if(SUCCEEDED(getDebug(0, __uuidof(IDXGIDebug1), (void **)&dxgiDebug))) + { + HRESULT hr = dxgiDebug->ReportLiveObjects( + DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_FLAGS(DXGI_DEBUG_RLO_SUMMARY | DXGI_DEBUG_RLO_DETAIL | + DXGI_DEBUG_RLO_IGNORE_INTERNAL)); + TEST_ASSERT(hr == S_OK, "Some objects are not released"); + } + } } bool D3D12GraphicsTest::Running() @@ -1441,9 +1473,10 @@ ID3DBlobPtr D3D12GraphicsTest::Compile(std::string src, std::string entry, std:: uint32_t compileOptions) { ID3DBlobPtr blob = NULL; - bool skipoptimise = ((compileOptions & CompileOptionFlags::SkipOptimise) != 0); - bool enable16BitTypes = ((compileOptions & CompileOptionFlags::Enable16BitTypes) != 0); - bool separateDebug = ((compileOptions & CompileOptionFlags::SeparateDebug) != 0); + const bool skipoptimise = ((compileOptions & CompileOptionFlags::SkipOptimise) != 0); + const bool enable16BitTypes = ((compileOptions & CompileOptionFlags::Enable16BitTypes) != 0); + const bool separateDebug = ((compileOptions & CompileOptionFlags::SeparateDebug) != 0); + const bool manualDebugName = ((compileOptions & CompileOptionFlags::ManualDebugName) != 0); if(profile[3] >= '6') { @@ -1516,6 +1549,10 @@ ID3DBlobPtr D3D12GraphicsTest::Compile(std::string src, std::string entry, std:: argStorage.push_back(L"-select-validator internal"); } + // use source for debug name so we can have just a comment and get different debug info if we want + if(!manualDebugName) + argStorage.push_back(L"-Zss"); + // Must be the final option argStorage.push_back(L"-Qembed_debug"); @@ -1529,6 +1566,8 @@ ID3DBlobPtr D3D12GraphicsTest::Compile(std::string src, std::string entry, std:: IDxcOperationResultPtr result; HRESULT hrStatus = E_NOINTERFACE; + std::string debugBlobPath; + if(separateDebug) { IDxcCompiler2Ptr compiler2 = compiler; @@ -1554,20 +1593,16 @@ ID3DBlobPtr D3D12GraphicsTest::Compile(std::string src, std::string entry, std:: CoTaskMemFree(debugBlobWideName); } + if(manualDebugName) + { + debugBlobName = "shader_" + profile.substr(0, 2) + ".dbg"; + } + if(debugBlob) { - std::string path = GetExecutableName(); - path.erase(path.find_last_of("/\\")); - path += "/tmp/"; - MakeDir(path.c_str()); - path += demoName; - path += "/"; - MakeDir(path.c_str()); - path += "dxcDebugBlobs/"; - MakeDir(path.c_str()); - - WriteBlob(path + debugBlobName, debugBlob->GetBufferPointer(), debugBlob->GetBufferSize(), - false); + debugBlobPath = tmpPath + "/" + debugBlobName; + + WriteBlob(debugBlobPath, debugBlob->GetBufferPointer(), debugBlob->GetBufferSize(), false); } if(result) @@ -1629,6 +1664,26 @@ ID3DBlobPtr D3D12GraphicsTest::Compile(std::string src, std::string entry, std:: TEST_ERROR("No compilation result found from DXC compile: %x", hr); } } + + if(manualDebugName) + { + std::string nameBlob = debugBlobPath; + // pad the blob to multiple of 4 + nameBlob.resize((debugBlobPath.size() + 0x3) & ~0x3); + + nameBlob.insert(0, 4, '\0'); + nameBlob[2] += debugBlobPath.size() & 0xff; + + if(debugBlobPath.size() > 255) + TEST_ERROR("tmp path is too long!"); + + ID3DBlobPtr newBlob; + + hr = dyn_D3DSetBlobPart(blob->GetBufferPointer(), blob->GetBufferSize(), D3D_BLOB_DEBUG_NAME, + 0, nameBlob.c_str(), nameBlob.size(), &newBlob); + + blob = newBlob; + } } else { diff --git a/util/test/demos/d3d12/d3d12_test.h b/util/test/demos/d3d12/d3d12_test.h index a82c3b46aea..5fa950fa15d 100644 --- a/util/test/demos/d3d12/d3d12_test.h +++ b/util/test/demos/d3d12/d3d12_test.h @@ -30,17 +30,6 @@ #include "dx/official/dxgi.h" #include "d3d12_helpers.h" -#include "dx/official/d3dcompiler.h" - -typedef HRESULT(WINAPI *pD3DStripShader)(_In_reads_bytes_(BytecodeLength) LPCVOID pShaderBytecode, - _In_ SIZE_T BytecodeLength, _In_ UINT uStripFlags, - _Out_ ID3DBlob **ppStrippedBlob); -typedef HRESULT(WINAPI *pD3DSetBlobPart)(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData, - _In_ SIZE_T SrcDataSize, _In_ D3D_BLOB_PART Part, - _In_ UINT Flags, _In_reads_bytes_(PartSize) LPCVOID pPart, - _In_ SIZE_T PartSize, _Out_ ID3DBlob **ppNewShader); -typedef HRESULT(WINAPI *pD3DCreateBlob)(SIZE_T Size, ID3DBlob **ppBlob); - struct Win32Window; struct D3D12GraphicsTest : public GraphicsTest @@ -83,6 +72,7 @@ struct D3D12GraphicsTest : public GraphicsTest SkipOptimise = 1 << 0, Enable16BitTypes = 1 << 1, SeparateDebug = 1 << 2, + ManualDebugName = 1 << 3, }; ID3DBlobPtr Compile(std::string src, std::string entry, std::string profile, @@ -281,6 +271,8 @@ struct D3D12GraphicsTest : public GraphicsTest std::vector freeCommandBuffers; std::vector> pendingCommandBuffers; + std::vector mutedMessages; + private: void AddHashIfMissing(void *ByteCode, size_t BytecodeLength); }; diff --git a/util/test/demos/demos.vcxproj b/util/test/demos/demos.vcxproj index e4b5d4bf15c..aa59eb81c52 100644 --- a/util/test/demos/demos.vcxproj +++ b/util/test/demos/demos.vcxproj @@ -158,6 +158,7 @@ + @@ -214,6 +215,7 @@ + @@ -348,6 +350,8 @@ + + @@ -356,7 +360,6 @@ - diff --git a/util/test/demos/demos.vcxproj.filters b/util/test/demos/demos.vcxproj.filters index 0496c145ddd..6e96880823c 100644 --- a/util/test/demos/demos.vcxproj.filters +++ b/util/test/demos/demos.vcxproj.filters @@ -358,9 +358,6 @@ Vulkan\demos - - Vulkan\demos - Vulkan\demos @@ -769,6 +766,18 @@ Vulkan\demos + + D3D12\demos + + + Vulkan\demos + + + Vulkan\demos + + + D3D11\demos + diff --git a/util/test/demos/dx/d3d_helpers.h b/util/test/demos/dx/d3d_helpers.h index 63669ba397c..f8419d78665 100644 --- a/util/test/demos/dx/d3d_helpers.h +++ b/util/test/demos/dx/d3d_helpers.h @@ -28,11 +28,26 @@ #include #include #include "dx/official/dxgi1_4.h" +#include "dx/official/dxgidebug.h" + +#include "dx/official/d3dcompiler.h" extern std::string D3DFullscreenQuadVertex; extern std::string D3DDefaultVertex; extern std::string D3DDefaultPixel; +typedef HRESULT(WINAPI *pD3DStripShader)(_In_reads_bytes_(BytecodeLength) LPCVOID pShaderBytecode, + _In_ SIZE_T BytecodeLength, _In_ UINT uStripFlags, + _Out_ ID3DBlob **ppStrippedBlob); +typedef HRESULT(WINAPI *pD3DSetBlobPart)(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData, + _In_ SIZE_T SrcDataSize, _In_ D3D_BLOB_PART Part, + _In_ UINT Flags, _In_reads_bytes_(PartSize) LPCVOID pPart, + _In_ SIZE_T PartSize, _Out_ ID3DBlob **ppNewShader); +typedef HRESULT(WINAPI *pD3DGetBlobPart)(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData, + _In_ SIZE_T SrcDataSize, _In_ D3D_BLOB_PART Part, + _In_ UINT Flags, _Out_ ID3DBlob **ppPart); +typedef HRESULT(WINAPI *pD3DCreateBlob)(SIZE_T Size, ID3DBlob **ppBlob); + #define COM_SMARTPTR(classname) _COM_SMARTPTR_TYPEDEF(classname, __uuidof(classname)) COM_SMARTPTR(IDXGISwapChain); @@ -45,6 +60,8 @@ COM_SMARTPTR(IDXGIFactory4); COM_SMARTPTR(IDXGIAdapter); COM_SMARTPTR(IDXGISurface); COM_SMARTPTR(IDXGIResource); +COM_SMARTPTR(IDXGIDebug); +COM_SMARTPTR(IDXGIDebug1); template ULONG GetRefcount(T *ptr) diff --git a/util/test/demos/dx/official/dxgidebug.h b/util/test/demos/dx/official/dxgidebug.h new file mode 100644 index 00000000000..c60827aa47b --- /dev/null +++ b/util/test/demos/dx/official/dxgidebug.h @@ -0,0 +1,995 @@ + + +/* this ALWAYS GENERATED file contains the definitions for the interfaces */ + + + /* File created by MIDL compiler version 8.01.0622 */ +/* @@MIDL_FILE_HEADING( ) */ + + + +/* verify that the version is high enough to compile this file*/ +#ifndef __REQUIRED_RPCNDR_H_VERSION__ +#define __REQUIRED_RPCNDR_H_VERSION__ 500 +#endif + +/* verify that the version is high enough to compile this file*/ +#ifndef __REQUIRED_RPCSAL_H_VERSION__ +#define __REQUIRED_RPCSAL_H_VERSION__ 100 +#endif + +#include "rpc.h" +#include "rpcndr.h" + +#ifndef __RPCNDR_H_VERSION__ +#error this stub requires an updated version of +#endif /* __RPCNDR_H_VERSION__ */ + +#ifndef COM_NO_WINDOWS_H +#include "windows.h" +#include "ole2.h" +#endif /*COM_NO_WINDOWS_H*/ + +#ifndef __dxgidebug_h__ +#define __dxgidebug_h__ + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +#pragma once +#endif + +/* Forward Declarations */ + +#ifndef __IDXGIInfoQueue_FWD_DEFINED__ +#define __IDXGIInfoQueue_FWD_DEFINED__ +typedef interface IDXGIInfoQueue IDXGIInfoQueue; + +#endif /* __IDXGIInfoQueue_FWD_DEFINED__ */ + + +#ifndef __IDXGIDebug_FWD_DEFINED__ +#define __IDXGIDebug_FWD_DEFINED__ +typedef interface IDXGIDebug IDXGIDebug; + +#endif /* __IDXGIDebug_FWD_DEFINED__ */ + + +#ifndef __IDXGIDebug1_FWD_DEFINED__ +#define __IDXGIDebug1_FWD_DEFINED__ +typedef interface IDXGIDebug1 IDXGIDebug1; + +#endif /* __IDXGIDebug1_FWD_DEFINED__ */ + + +/* header files for imported files */ +#include "oaidl.h" +#include "ocidl.h" + +#ifdef __cplusplus +extern "C"{ +#endif + + +/* interface __MIDL_itf_dxgidebug_0000_0000 */ +/* [local] */ + +#include "winapifamily.h" +#pragma region Application Family +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) +#define DXGI_DEBUG_BINARY_VERSION ( 1 ) + +typedef +enum DXGI_DEBUG_RLO_FLAGS + { + DXGI_DEBUG_RLO_SUMMARY = 0x1, + DXGI_DEBUG_RLO_DETAIL = 0x2, + DXGI_DEBUG_RLO_IGNORE_INTERNAL = 0x4, + DXGI_DEBUG_RLO_ALL = 0x7 + } DXGI_DEBUG_RLO_FLAGS; + +typedef GUID DXGI_DEBUG_ID; + +DEFINE_GUID(DXGI_DEBUG_ALL, 0xe48ae283, 0xda80, 0x490b, 0x87, 0xe6, 0x43, 0xe9, 0xa9, 0xcf, 0xda, 0x8); +DEFINE_GUID(DXGI_DEBUG_DX, 0x35cdd7fc, 0x13b2, 0x421d, 0xa5, 0xd7, 0x7e, 0x44, 0x51, 0x28, 0x7d, 0x64); +DEFINE_GUID(DXGI_DEBUG_DXGI, 0x25cddaa4, 0xb1c6, 0x47e1, 0xac, 0x3e, 0x98, 0x87, 0x5b, 0x5a, 0x2e, 0x2a); +DEFINE_GUID(DXGI_DEBUG_APP, 0x6cd6e01, 0x4219, 0x4ebd, 0x87, 0x9, 0x27, 0xed, 0x23, 0x36, 0xc, 0x62); +typedef +enum DXGI_INFO_QUEUE_MESSAGE_CATEGORY + { + DXGI_INFO_QUEUE_MESSAGE_CATEGORY_UNKNOWN = 0, + DXGI_INFO_QUEUE_MESSAGE_CATEGORY_MISCELLANEOUS = ( DXGI_INFO_QUEUE_MESSAGE_CATEGORY_UNKNOWN + 1 ) , + DXGI_INFO_QUEUE_MESSAGE_CATEGORY_INITIALIZATION = ( DXGI_INFO_QUEUE_MESSAGE_CATEGORY_MISCELLANEOUS + 1 ) , + DXGI_INFO_QUEUE_MESSAGE_CATEGORY_CLEANUP = ( DXGI_INFO_QUEUE_MESSAGE_CATEGORY_INITIALIZATION + 1 ) , + DXGI_INFO_QUEUE_MESSAGE_CATEGORY_COMPILATION = ( DXGI_INFO_QUEUE_MESSAGE_CATEGORY_CLEANUP + 1 ) , + DXGI_INFO_QUEUE_MESSAGE_CATEGORY_STATE_CREATION = ( DXGI_INFO_QUEUE_MESSAGE_CATEGORY_COMPILATION + 1 ) , + DXGI_INFO_QUEUE_MESSAGE_CATEGORY_STATE_SETTING = ( DXGI_INFO_QUEUE_MESSAGE_CATEGORY_STATE_CREATION + 1 ) , + DXGI_INFO_QUEUE_MESSAGE_CATEGORY_STATE_GETTING = ( DXGI_INFO_QUEUE_MESSAGE_CATEGORY_STATE_SETTING + 1 ) , + DXGI_INFO_QUEUE_MESSAGE_CATEGORY_RESOURCE_MANIPULATION = ( DXGI_INFO_QUEUE_MESSAGE_CATEGORY_STATE_GETTING + 1 ) , + DXGI_INFO_QUEUE_MESSAGE_CATEGORY_EXECUTION = ( DXGI_INFO_QUEUE_MESSAGE_CATEGORY_RESOURCE_MANIPULATION + 1 ) , + DXGI_INFO_QUEUE_MESSAGE_CATEGORY_SHADER = ( DXGI_INFO_QUEUE_MESSAGE_CATEGORY_EXECUTION + 1 ) + } DXGI_INFO_QUEUE_MESSAGE_CATEGORY; + +typedef +enum DXGI_INFO_QUEUE_MESSAGE_SEVERITY + { + DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION = 0, + DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR = ( DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION + 1 ) , + DXGI_INFO_QUEUE_MESSAGE_SEVERITY_WARNING = ( DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR + 1 ) , + DXGI_INFO_QUEUE_MESSAGE_SEVERITY_INFO = ( DXGI_INFO_QUEUE_MESSAGE_SEVERITY_WARNING + 1 ) , + DXGI_INFO_QUEUE_MESSAGE_SEVERITY_MESSAGE = ( DXGI_INFO_QUEUE_MESSAGE_SEVERITY_INFO + 1 ) + } DXGI_INFO_QUEUE_MESSAGE_SEVERITY; + +typedef int DXGI_INFO_QUEUE_MESSAGE_ID; + +#define DXGI_INFO_QUEUE_MESSAGE_ID_STRING_FROM_APPLICATION 0 +typedef struct DXGI_INFO_QUEUE_MESSAGE + { + DXGI_DEBUG_ID Producer; + DXGI_INFO_QUEUE_MESSAGE_CATEGORY Category; + DXGI_INFO_QUEUE_MESSAGE_SEVERITY Severity; + DXGI_INFO_QUEUE_MESSAGE_ID ID; + /* [annotation] */ + _Field_size_(DescriptionByteLength) const char *pDescription; + SIZE_T DescriptionByteLength; + } DXGI_INFO_QUEUE_MESSAGE; + +typedef struct DXGI_INFO_QUEUE_FILTER_DESC + { + UINT NumCategories; + /* [annotation] */ + _Field_size_(NumCategories) DXGI_INFO_QUEUE_MESSAGE_CATEGORY *pCategoryList; + UINT NumSeverities; + /* [annotation] */ + _Field_size_(NumSeverities) DXGI_INFO_QUEUE_MESSAGE_SEVERITY *pSeverityList; + UINT NumIDs; + /* [annotation] */ + _Field_size_(NumIDs) DXGI_INFO_QUEUE_MESSAGE_ID *pIDList; + } DXGI_INFO_QUEUE_FILTER_DESC; + +typedef struct DXGI_INFO_QUEUE_FILTER + { + DXGI_INFO_QUEUE_FILTER_DESC AllowList; + DXGI_INFO_QUEUE_FILTER_DESC DenyList; + } DXGI_INFO_QUEUE_FILTER; + +#define DXGI_INFO_QUEUE_DEFAULT_MESSAGE_COUNT_LIMIT 1024 +HRESULT WINAPI DXGIGetDebugInterface(REFIID riid, void **ppDebug); + + +extern RPC_IF_HANDLE __MIDL_itf_dxgidebug_0000_0000_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_dxgidebug_0000_0000_v0_0_s_ifspec; + +#ifndef __IDXGIInfoQueue_INTERFACE_DEFINED__ +#define __IDXGIInfoQueue_INTERFACE_DEFINED__ + +/* interface IDXGIInfoQueue */ +/* [unique][local][object][uuid] */ + + +EXTERN_C const IID IID_IDXGIInfoQueue; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("D67441C7-672A-476f-9E82-CD55B44949CE") + IDXGIInfoQueue : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE SetMessageCountLimit( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ UINT64 MessageCountLimit) = 0; + + virtual void STDMETHODCALLTYPE ClearStoredMessages( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetMessage( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ UINT64 MessageIndex, + /* [annotation] */ + _Out_writes_bytes_opt_(*pMessageByteLength) DXGI_INFO_QUEUE_MESSAGE *pMessage, + /* [annotation] */ + _Inout_ SIZE_T *pMessageByteLength) = 0; + + virtual UINT64 STDMETHODCALLTYPE GetNumStoredMessagesAllowedByRetrievalFilters( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual UINT64 STDMETHODCALLTYPE GetNumStoredMessages( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual UINT64 STDMETHODCALLTYPE GetNumMessagesDiscardedByMessageCountLimit( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual UINT64 STDMETHODCALLTYPE GetMessageCountLimit( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual UINT64 STDMETHODCALLTYPE GetNumMessagesAllowedByStorageFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual UINT64 STDMETHODCALLTYPE GetNumMessagesDeniedByStorageFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual HRESULT STDMETHODCALLTYPE AddStorageFilterEntries( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_FILTER *pFilter) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetStorageFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _Out_writes_bytes_opt_(*pFilterByteLength) DXGI_INFO_QUEUE_FILTER *pFilter, + /* [annotation] */ + _Inout_ SIZE_T *pFilterByteLength) = 0; + + virtual void STDMETHODCALLTYPE ClearStorageFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual HRESULT STDMETHODCALLTYPE PushEmptyStorageFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual HRESULT STDMETHODCALLTYPE PushDenyAllStorageFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual HRESULT STDMETHODCALLTYPE PushCopyOfStorageFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual HRESULT STDMETHODCALLTYPE PushStorageFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_FILTER *pFilter) = 0; + + virtual void STDMETHODCALLTYPE PopStorageFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual UINT STDMETHODCALLTYPE GetStorageFilterStackSize( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual HRESULT STDMETHODCALLTYPE AddRetrievalFilterEntries( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_FILTER *pFilter) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetRetrievalFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _Out_writes_bytes_opt_(*pFilterByteLength) DXGI_INFO_QUEUE_FILTER *pFilter, + /* [annotation] */ + _Inout_ SIZE_T *pFilterByteLength) = 0; + + virtual void STDMETHODCALLTYPE ClearRetrievalFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual HRESULT STDMETHODCALLTYPE PushEmptyRetrievalFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual HRESULT STDMETHODCALLTYPE PushDenyAllRetrievalFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual HRESULT STDMETHODCALLTYPE PushCopyOfRetrievalFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual HRESULT STDMETHODCALLTYPE PushRetrievalFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_FILTER *pFilter) = 0; + + virtual void STDMETHODCALLTYPE PopRetrievalFilter( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual UINT STDMETHODCALLTYPE GetRetrievalFilterStackSize( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + virtual HRESULT STDMETHODCALLTYPE AddMessage( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_CATEGORY Category, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_SEVERITY Severity, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_ID ID, + /* [annotation] */ + _In_ LPCSTR pDescription) = 0; + + virtual HRESULT STDMETHODCALLTYPE AddApplicationMessage( + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_SEVERITY Severity, + /* [annotation] */ + _In_ LPCSTR pDescription) = 0; + + virtual HRESULT STDMETHODCALLTYPE SetBreakOnCategory( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_CATEGORY Category, + /* [annotation] */ + _In_ BOOL bEnable) = 0; + + virtual HRESULT STDMETHODCALLTYPE SetBreakOnSeverity( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_SEVERITY Severity, + /* [annotation] */ + _In_ BOOL bEnable) = 0; + + virtual HRESULT STDMETHODCALLTYPE SetBreakOnID( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_ID ID, + /* [annotation] */ + _In_ BOOL bEnable) = 0; + + virtual BOOL STDMETHODCALLTYPE GetBreakOnCategory( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_CATEGORY Category) = 0; + + virtual BOOL STDMETHODCALLTYPE GetBreakOnSeverity( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_SEVERITY Severity) = 0; + + virtual BOOL STDMETHODCALLTYPE GetBreakOnID( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_ID ID) = 0; + + virtual void STDMETHODCALLTYPE SetMuteDebugOutput( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ BOOL bMute) = 0; + + virtual BOOL STDMETHODCALLTYPE GetMuteDebugOutput( + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer) = 0; + + }; + + +#else /* C style interface */ + + typedef struct IDXGIInfoQueueVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IDXGIInfoQueue * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IDXGIInfoQueue * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IDXGIInfoQueue * This); + + HRESULT ( STDMETHODCALLTYPE *SetMessageCountLimit )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ UINT64 MessageCountLimit); + + void ( STDMETHODCALLTYPE *ClearStoredMessages )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + HRESULT ( STDMETHODCALLTYPE *GetMessage )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ UINT64 MessageIndex, + /* [annotation] */ + _Out_writes_bytes_opt_(*pMessageByteLength) DXGI_INFO_QUEUE_MESSAGE *pMessage, + /* [annotation] */ + _Inout_ SIZE_T *pMessageByteLength); + + UINT64 ( STDMETHODCALLTYPE *GetNumStoredMessagesAllowedByRetrievalFilters )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + UINT64 ( STDMETHODCALLTYPE *GetNumStoredMessages )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + UINT64 ( STDMETHODCALLTYPE *GetNumMessagesDiscardedByMessageCountLimit )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + UINT64 ( STDMETHODCALLTYPE *GetMessageCountLimit )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + UINT64 ( STDMETHODCALLTYPE *GetNumMessagesAllowedByStorageFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + UINT64 ( STDMETHODCALLTYPE *GetNumMessagesDeniedByStorageFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + HRESULT ( STDMETHODCALLTYPE *AddStorageFilterEntries )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_FILTER *pFilter); + + HRESULT ( STDMETHODCALLTYPE *GetStorageFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _Out_writes_bytes_opt_(*pFilterByteLength) DXGI_INFO_QUEUE_FILTER *pFilter, + /* [annotation] */ + _Inout_ SIZE_T *pFilterByteLength); + + void ( STDMETHODCALLTYPE *ClearStorageFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + HRESULT ( STDMETHODCALLTYPE *PushEmptyStorageFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + HRESULT ( STDMETHODCALLTYPE *PushDenyAllStorageFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + HRESULT ( STDMETHODCALLTYPE *PushCopyOfStorageFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + HRESULT ( STDMETHODCALLTYPE *PushStorageFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_FILTER *pFilter); + + void ( STDMETHODCALLTYPE *PopStorageFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + UINT ( STDMETHODCALLTYPE *GetStorageFilterStackSize )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + HRESULT ( STDMETHODCALLTYPE *AddRetrievalFilterEntries )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_FILTER *pFilter); + + HRESULT ( STDMETHODCALLTYPE *GetRetrievalFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _Out_writes_bytes_opt_(*pFilterByteLength) DXGI_INFO_QUEUE_FILTER *pFilter, + /* [annotation] */ + _Inout_ SIZE_T *pFilterByteLength); + + void ( STDMETHODCALLTYPE *ClearRetrievalFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + HRESULT ( STDMETHODCALLTYPE *PushEmptyRetrievalFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + HRESULT ( STDMETHODCALLTYPE *PushDenyAllRetrievalFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + HRESULT ( STDMETHODCALLTYPE *PushCopyOfRetrievalFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + HRESULT ( STDMETHODCALLTYPE *PushRetrievalFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_FILTER *pFilter); + + void ( STDMETHODCALLTYPE *PopRetrievalFilter )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + UINT ( STDMETHODCALLTYPE *GetRetrievalFilterStackSize )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + HRESULT ( STDMETHODCALLTYPE *AddMessage )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_CATEGORY Category, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_SEVERITY Severity, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_ID ID, + /* [annotation] */ + _In_ LPCSTR pDescription); + + HRESULT ( STDMETHODCALLTYPE *AddApplicationMessage )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_SEVERITY Severity, + /* [annotation] */ + _In_ LPCSTR pDescription); + + HRESULT ( STDMETHODCALLTYPE *SetBreakOnCategory )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_CATEGORY Category, + /* [annotation] */ + _In_ BOOL bEnable); + + HRESULT ( STDMETHODCALLTYPE *SetBreakOnSeverity )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_SEVERITY Severity, + /* [annotation] */ + _In_ BOOL bEnable); + + HRESULT ( STDMETHODCALLTYPE *SetBreakOnID )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_ID ID, + /* [annotation] */ + _In_ BOOL bEnable); + + BOOL ( STDMETHODCALLTYPE *GetBreakOnCategory )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_CATEGORY Category); + + BOOL ( STDMETHODCALLTYPE *GetBreakOnSeverity )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_SEVERITY Severity); + + BOOL ( STDMETHODCALLTYPE *GetBreakOnID )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ DXGI_INFO_QUEUE_MESSAGE_ID ID); + + void ( STDMETHODCALLTYPE *SetMuteDebugOutput )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer, + /* [annotation] */ + _In_ BOOL bMute); + + BOOL ( STDMETHODCALLTYPE *GetMuteDebugOutput )( + IDXGIInfoQueue * This, + /* [annotation] */ + _In_ DXGI_DEBUG_ID Producer); + + END_INTERFACE + } IDXGIInfoQueueVtbl; + + interface IDXGIInfoQueue + { + CONST_VTBL struct IDXGIInfoQueueVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IDXGIInfoQueue_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define IDXGIInfoQueue_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define IDXGIInfoQueue_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define IDXGIInfoQueue_SetMessageCountLimit(This,Producer,MessageCountLimit) \ + ( (This)->lpVtbl -> SetMessageCountLimit(This,Producer,MessageCountLimit) ) + +#define IDXGIInfoQueue_ClearStoredMessages(This,Producer) \ + ( (This)->lpVtbl -> ClearStoredMessages(This,Producer) ) + +#define IDXGIInfoQueue_GetMessage(This,Producer,MessageIndex,pMessage,pMessageByteLength) \ + ( (This)->lpVtbl -> GetMessage(This,Producer,MessageIndex,pMessage,pMessageByteLength) ) + +#define IDXGIInfoQueue_GetNumStoredMessagesAllowedByRetrievalFilters(This,Producer) \ + ( (This)->lpVtbl -> GetNumStoredMessagesAllowedByRetrievalFilters(This,Producer) ) + +#define IDXGIInfoQueue_GetNumStoredMessages(This,Producer) \ + ( (This)->lpVtbl -> GetNumStoredMessages(This,Producer) ) + +#define IDXGIInfoQueue_GetNumMessagesDiscardedByMessageCountLimit(This,Producer) \ + ( (This)->lpVtbl -> GetNumMessagesDiscardedByMessageCountLimit(This,Producer) ) + +#define IDXGIInfoQueue_GetMessageCountLimit(This,Producer) \ + ( (This)->lpVtbl -> GetMessageCountLimit(This,Producer) ) + +#define IDXGIInfoQueue_GetNumMessagesAllowedByStorageFilter(This,Producer) \ + ( (This)->lpVtbl -> GetNumMessagesAllowedByStorageFilter(This,Producer) ) + +#define IDXGIInfoQueue_GetNumMessagesDeniedByStorageFilter(This,Producer) \ + ( (This)->lpVtbl -> GetNumMessagesDeniedByStorageFilter(This,Producer) ) + +#define IDXGIInfoQueue_AddStorageFilterEntries(This,Producer,pFilter) \ + ( (This)->lpVtbl -> AddStorageFilterEntries(This,Producer,pFilter) ) + +#define IDXGIInfoQueue_GetStorageFilter(This,Producer,pFilter,pFilterByteLength) \ + ( (This)->lpVtbl -> GetStorageFilter(This,Producer,pFilter,pFilterByteLength) ) + +#define IDXGIInfoQueue_ClearStorageFilter(This,Producer) \ + ( (This)->lpVtbl -> ClearStorageFilter(This,Producer) ) + +#define IDXGIInfoQueue_PushEmptyStorageFilter(This,Producer) \ + ( (This)->lpVtbl -> PushEmptyStorageFilter(This,Producer) ) + +#define IDXGIInfoQueue_PushDenyAllStorageFilter(This,Producer) \ + ( (This)->lpVtbl -> PushDenyAllStorageFilter(This,Producer) ) + +#define IDXGIInfoQueue_PushCopyOfStorageFilter(This,Producer) \ + ( (This)->lpVtbl -> PushCopyOfStorageFilter(This,Producer) ) + +#define IDXGIInfoQueue_PushStorageFilter(This,Producer,pFilter) \ + ( (This)->lpVtbl -> PushStorageFilter(This,Producer,pFilter) ) + +#define IDXGIInfoQueue_PopStorageFilter(This,Producer) \ + ( (This)->lpVtbl -> PopStorageFilter(This,Producer) ) + +#define IDXGIInfoQueue_GetStorageFilterStackSize(This,Producer) \ + ( (This)->lpVtbl -> GetStorageFilterStackSize(This,Producer) ) + +#define IDXGIInfoQueue_AddRetrievalFilterEntries(This,Producer,pFilter) \ + ( (This)->lpVtbl -> AddRetrievalFilterEntries(This,Producer,pFilter) ) + +#define IDXGIInfoQueue_GetRetrievalFilter(This,Producer,pFilter,pFilterByteLength) \ + ( (This)->lpVtbl -> GetRetrievalFilter(This,Producer,pFilter,pFilterByteLength) ) + +#define IDXGIInfoQueue_ClearRetrievalFilter(This,Producer) \ + ( (This)->lpVtbl -> ClearRetrievalFilter(This,Producer) ) + +#define IDXGIInfoQueue_PushEmptyRetrievalFilter(This,Producer) \ + ( (This)->lpVtbl -> PushEmptyRetrievalFilter(This,Producer) ) + +#define IDXGIInfoQueue_PushDenyAllRetrievalFilter(This,Producer) \ + ( (This)->lpVtbl -> PushDenyAllRetrievalFilter(This,Producer) ) + +#define IDXGIInfoQueue_PushCopyOfRetrievalFilter(This,Producer) \ + ( (This)->lpVtbl -> PushCopyOfRetrievalFilter(This,Producer) ) + +#define IDXGIInfoQueue_PushRetrievalFilter(This,Producer,pFilter) \ + ( (This)->lpVtbl -> PushRetrievalFilter(This,Producer,pFilter) ) + +#define IDXGIInfoQueue_PopRetrievalFilter(This,Producer) \ + ( (This)->lpVtbl -> PopRetrievalFilter(This,Producer) ) + +#define IDXGIInfoQueue_GetRetrievalFilterStackSize(This,Producer) \ + ( (This)->lpVtbl -> GetRetrievalFilterStackSize(This,Producer) ) + +#define IDXGIInfoQueue_AddMessage(This,Producer,Category,Severity,ID,pDescription) \ + ( (This)->lpVtbl -> AddMessage(This,Producer,Category,Severity,ID,pDescription) ) + +#define IDXGIInfoQueue_AddApplicationMessage(This,Severity,pDescription) \ + ( (This)->lpVtbl -> AddApplicationMessage(This,Severity,pDescription) ) + +#define IDXGIInfoQueue_SetBreakOnCategory(This,Producer,Category,bEnable) \ + ( (This)->lpVtbl -> SetBreakOnCategory(This,Producer,Category,bEnable) ) + +#define IDXGIInfoQueue_SetBreakOnSeverity(This,Producer,Severity,bEnable) \ + ( (This)->lpVtbl -> SetBreakOnSeverity(This,Producer,Severity,bEnable) ) + +#define IDXGIInfoQueue_SetBreakOnID(This,Producer,ID,bEnable) \ + ( (This)->lpVtbl -> SetBreakOnID(This,Producer,ID,bEnable) ) + +#define IDXGIInfoQueue_GetBreakOnCategory(This,Producer,Category) \ + ( (This)->lpVtbl -> GetBreakOnCategory(This,Producer,Category) ) + +#define IDXGIInfoQueue_GetBreakOnSeverity(This,Producer,Severity) \ + ( (This)->lpVtbl -> GetBreakOnSeverity(This,Producer,Severity) ) + +#define IDXGIInfoQueue_GetBreakOnID(This,Producer,ID) \ + ( (This)->lpVtbl -> GetBreakOnID(This,Producer,ID) ) + +#define IDXGIInfoQueue_SetMuteDebugOutput(This,Producer,bMute) \ + ( (This)->lpVtbl -> SetMuteDebugOutput(This,Producer,bMute) ) + +#define IDXGIInfoQueue_GetMuteDebugOutput(This,Producer) \ + ( (This)->lpVtbl -> GetMuteDebugOutput(This,Producer) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __IDXGIInfoQueue_INTERFACE_DEFINED__ */ + + +#ifndef __IDXGIDebug_INTERFACE_DEFINED__ +#define __IDXGIDebug_INTERFACE_DEFINED__ + +/* interface IDXGIDebug */ +/* [unique][local][object][uuid] */ + + +EXTERN_C const IID IID_IDXGIDebug; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("119E7452-DE9E-40fe-8806-88F90C12B441") + IDXGIDebug : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE ReportLiveObjects( + GUID apiid, + DXGI_DEBUG_RLO_FLAGS flags) = 0; + + }; + + +#else /* C style interface */ + + typedef struct IDXGIDebugVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IDXGIDebug * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IDXGIDebug * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IDXGIDebug * This); + + HRESULT ( STDMETHODCALLTYPE *ReportLiveObjects )( + IDXGIDebug * This, + GUID apiid, + DXGI_DEBUG_RLO_FLAGS flags); + + END_INTERFACE + } IDXGIDebugVtbl; + + interface IDXGIDebug + { + CONST_VTBL struct IDXGIDebugVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IDXGIDebug_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define IDXGIDebug_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define IDXGIDebug_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define IDXGIDebug_ReportLiveObjects(This,apiid,flags) \ + ( (This)->lpVtbl -> ReportLiveObjects(This,apiid,flags) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __IDXGIDebug_INTERFACE_DEFINED__ */ + + +#ifndef __IDXGIDebug1_INTERFACE_DEFINED__ +#define __IDXGIDebug1_INTERFACE_DEFINED__ + +/* interface IDXGIDebug1 */ +/* [unique][local][object][uuid] */ + + +EXTERN_C const IID IID_IDXGIDebug1; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("c5a05f0c-16f2-4adf-9f4d-a8c4d58ac550") + IDXGIDebug1 : public IDXGIDebug + { + public: + virtual void STDMETHODCALLTYPE EnableLeakTrackingForThread( void) = 0; + + virtual void STDMETHODCALLTYPE DisableLeakTrackingForThread( void) = 0; + + virtual BOOL STDMETHODCALLTYPE IsLeakTrackingEnabledForThread( void) = 0; + + }; + + +#else /* C style interface */ + + typedef struct IDXGIDebug1Vtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IDXGIDebug1 * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IDXGIDebug1 * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IDXGIDebug1 * This); + + HRESULT ( STDMETHODCALLTYPE *ReportLiveObjects )( + IDXGIDebug1 * This, + GUID apiid, + DXGI_DEBUG_RLO_FLAGS flags); + + void ( STDMETHODCALLTYPE *EnableLeakTrackingForThread )( + IDXGIDebug1 * This); + + void ( STDMETHODCALLTYPE *DisableLeakTrackingForThread )( + IDXGIDebug1 * This); + + BOOL ( STDMETHODCALLTYPE *IsLeakTrackingEnabledForThread )( + IDXGIDebug1 * This); + + END_INTERFACE + } IDXGIDebug1Vtbl; + + interface IDXGIDebug1 + { + CONST_VTBL struct IDXGIDebug1Vtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IDXGIDebug1_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define IDXGIDebug1_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define IDXGIDebug1_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define IDXGIDebug1_ReportLiveObjects(This,apiid,flags) \ + ( (This)->lpVtbl -> ReportLiveObjects(This,apiid,flags) ) + + +#define IDXGIDebug1_EnableLeakTrackingForThread(This) \ + ( (This)->lpVtbl -> EnableLeakTrackingForThread(This) ) + +#define IDXGIDebug1_DisableLeakTrackingForThread(This) \ + ( (This)->lpVtbl -> DisableLeakTrackingForThread(This) ) + +#define IDXGIDebug1_IsLeakTrackingEnabledForThread(This) \ + ( (This)->lpVtbl -> IsLeakTrackingEnabledForThread(This) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __IDXGIDebug1_INTERFACE_DEFINED__ */ + + +/* interface __MIDL_itf_dxgidebug_0000_0003 */ +/* [local] */ + +#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */ +#pragma endregion +#pragma region Desktop Family +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */ +#pragma endregion +DEFINE_GUID(IID_IDXGIInfoQueue,0xD67441C7,0x672A,0x476f,0x9E,0x82,0xCD,0x55,0xB4,0x49,0x49,0xCE); +DEFINE_GUID(IID_IDXGIDebug,0x119E7452,0xDE9E,0x40fe,0x88,0x06,0x88,0xF9,0x0C,0x12,0xB4,0x41); +DEFINE_GUID(IID_IDXGIDebug1,0xc5a05f0c,0x16f2,0x4adf,0x9f,0x4d,0xa8,0xc4,0xd5,0x8a,0xc5,0x50); + + +extern RPC_IF_HANDLE __MIDL_itf_dxgidebug_0000_0003_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_dxgidebug_0000_0003_v0_0_s_ifspec; + +/* Additional Prototypes for ALL interfaces */ + +/* end of Additional Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/util/test/demos/gl/gl_shader_debug_zoo.cpp b/util/test/demos/gl/gl_shader_debug_zoo.cpp index 3d9a368bd1a..aab634b1cd9 100644 --- a/util/test/demos/gl/gl_shader_debug_zoo.cpp +++ b/util/test/demos/gl/gl_shader_debug_zoo.cpp @@ -149,9 +149,11 @@ flat in vec3 v2fFlatFloat; noperspective in vec3 v2fNoPerspFloat; #endif +vec4 global_value = vec4(1.1f, 2.2f, 3.3f, 4.4f); + void main() { - outColor = v2fColor + v2fUV.xyxy; + outColor = v2fColor + v2fUV.xyxy + global_value; #ifdef BLOCK outColor.r += v2f.a; diff --git a/util/test/demos/gl/gl_test.cpp b/util/test/demos/gl/gl_test.cpp index f408ea2053b..ab58fecb36a 100644 --- a/util/test/demos/gl/gl_test.cpp +++ b/util/test/demos/gl/gl_test.cpp @@ -82,11 +82,15 @@ void main() static void APIENTRY debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) { + OpenGLGraphicsTest *test = (OpenGLGraphicsTest *)userParam; + // too much spam on these types if(type != GL_DEBUG_TYPE_PERFORMANCE && type != GL_DEBUG_TYPE_OTHER && source != GL_DEBUG_SOURCE_APPLICATION) { - TEST_ERROR("Debug message: %s", message); + TEST_WARN("Debug message: %s", message); + if(test && test->breakOnDebug && !test->ignoreErrors) + UNCONDITIONAL_DEBUG_BREAK(); } } @@ -96,7 +100,7 @@ void OpenGLGraphicsTest::PostInit() if(GLAD_GL_KHR_debug) { - glDebugMessageCallback(&debugCallback, NULL); + glDebugMessageCallback(&debugCallback, this); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); } diff --git a/util/test/demos/gl/gl_test.h b/util/test/demos/gl/gl_test.h index 54b00ac6ecc..58b48a84b5d 100644 --- a/util/test/demos/gl/gl_test.h +++ b/util/test/demos/gl/gl_test.h @@ -85,6 +85,8 @@ struct OpenGLGraphicsTest : public GraphicsTest void *mainContext = NULL; bool inited = false; + bool ignoreErrors = false; + struct { std::vector bufs, texs, progs, pipes, vaos, fbos; diff --git a/util/test/demos/linux/linux_platform.h b/util/test/demos/linux/linux_platform.h index 1ae31029fd6..49518662a54 100644 --- a/util/test/demos/linux/linux_platform.h +++ b/util/test/demos/linux/linux_platform.h @@ -33,6 +33,7 @@ #include #define DEBUG_BREAK() raise(SIGTRAP) +#define UNCONDITIONAL_DEBUG_BREAK() raise(SIGTRAP) #define MAX_PATH 256 @@ -42,5 +43,7 @@ #define MakeDir(dir) mkdir(dir, 0755) +#define SetEnv(name, value) setenv(name, value, 1) + std::string GetExecutableName(); uint32_t GetPID(); diff --git a/util/test/demos/main.cpp b/util/test/demos/main.cpp index 45963385f0d..5f5045981fe 100644 --- a/util/test/demos/main.cpp +++ b/util/test/demos/main.cpp @@ -691,8 +691,8 @@ Usage: %s Test_Name [test_options] if(testchoice == name) { TEST_LOG("Running '%s'", test.Name); - test.test->Prepare(argc, argv); test.test->SetName(test.Name); + test.test->Prepare(argc, argv); if(!test.IsAvailable()) { diff --git a/util/test/demos/test_common.cpp b/util/test/demos/test_common.cpp index f14cfe3e241..640319463e9 100644 --- a/util/test/demos/test_common.cpp +++ b/util/test/demos/test_common.cpp @@ -253,27 +253,38 @@ void LoadXPM(const char **XPM, Texture &tex) } static std::string externalCompiler; +static std::string externalASMCompiler; -bool SpvCompilationSupported() +bool CheckCompiler(std::string compiler) { - for(std::string compiler : {"glslc", "glslangValidator"}) + FILE *pipe = popen((compiler + EXECUTABLE_SUFFIX " --version 2>&1").c_str(), "r"); + + if(!pipe) + return false; + + char dummy[512]; + while(!feof(pipe)) { - FILE *pipe = popen((compiler + EXECUTABLE_SUFFIX " --version 2>&1").c_str(), "r"); + fread(dummy, 1, 512, pipe); + } - if(!pipe) - continue; + int code = pclose(pipe); - char dummy[512]; - while(!feof(pipe)) - { - fread(dummy, 1, 512, pipe); - } + return (WEXITSTATUS(code) == 0); +} - int code = pclose(pipe); +bool SpvCompilationSupported() +{ + if(CheckCompiler("spirv-as")) + externalASMCompiler = "spirv-as"; - if(WEXITSTATUS(code) == 0) + for(std::string compiler : {"glslc", "glslangValidator"}) + { + if(CheckCompiler(compiler)) { externalCompiler = compiler; + if(externalASMCompiler.empty()) + externalASMCompiler = compiler; return true; } } @@ -284,7 +295,8 @@ bool SpvCompilationSupported() std::vector CompileShaderToSpv(const char *demo_name, const std::string &source_text, SPIRVTarget target, ShaderLang lang, ShaderStage stage, const char *entry_point, - const std::map ¯os) + const std::map ¯os, + bool debug_info) { std::vector ret; @@ -301,9 +313,29 @@ std::vector CompileShaderToSpv(const char *demo_name, const std::strin std::string infile = path + "/input"; std::string outfile = path + "/output"; - if(externalCompiler == "glslc") + if(lang == ShaderLang::spvasm && externalASMCompiler == "spirv-as") + { + command_line = "spirv-as" EXECUTABLE_SUFFIX; + + if(target == SPIRVTarget::opengl) + command_line += " --target-env=opengl"; + else if(target == SPIRVTarget::vulkan) + command_line += " --target-env=vulkan1.0"; + else if(target == SPIRVTarget::vulkan11) + command_line += " --target-env=vulkan1.1"; + else if(target == SPIRVTarget::vulkan12) + command_line += " --target-env=vulkan1.2"; + + command_line += " -o "; + command_line += outfile; + command_line += " "; + command_line += infile; + } + else if(externalCompiler == "glslc") { - command_line = "glslc" EXECUTABLE_SUFFIX " -g -O0"; + command_line = "glslc" EXECUTABLE_SUFFIX; + if(debug_info) + command_line += " -g -O0"; command_line += " -fentry-point="; command_line += entry_point; @@ -349,7 +381,9 @@ std::vector CompileShaderToSpv(const char *demo_name, const std::strin } else if(externalCompiler == "glslangValidator") { - command_line = "glslangValidator" EXECUTABLE_SUFFIX " -g "; + command_line = "glslangValidator" EXECUTABLE_SUFFIX; + if(debug_info) + command_line += " -g "; command_line += " --entry-point "; command_line += entry_point; @@ -440,6 +474,7 @@ std::string GraphicsTest::dataRoot; int GraphicsTest::screenWidth = 400; int GraphicsTest::screenHeight = 300; bool GraphicsTest::debugDevice = false; +bool GraphicsTest::breakOnDebug = false; void GraphicsTest::Prepare(int argc, char **argv) { @@ -458,6 +493,11 @@ void GraphicsTest::Prepare(int argc, char **argv) if(dataRoot.empty()) dataRoot = GetCWD() + "/data/demos/"; + tmpPath = GetExecutableName(); + tmpPath.erase(tmpPath.find_last_of("/\\")); + tmpPath += "/tmp"; + MakeDir(tmpPath.c_str()); + // parse parameters for(int i = 0; i < argc; i++) { @@ -466,6 +506,11 @@ void GraphicsTest::Prepare(int argc, char **argv) debugDevice = true; } + if(!strcmp(argv[i], "--break-on-debug")) + { + breakOnDebug = true; + } + if(i + 1 < argc && (!strcmp(argv[i], "--frames") || !strcmp(argv[i], "--framecount") || !strcmp(argv[i], "--max-frames"))) { @@ -477,6 +522,11 @@ void GraphicsTest::Prepare(int argc, char **argv) logFile = fopen(argv[i + 1], "w"); } + if(i + 1 < argc && !strcmp(argv[i], "--tmp")) + { + tmpPath = argv[i + 1]; + } + if(i + 1 < argc && (!strcmp(argv[i], "--width") || !strcmp(argv[i], "-w"))) { screenWidth = atoi(argv[i + 1]); @@ -506,6 +556,10 @@ void GraphicsTest::Prepare(int argc, char **argv) } } + tmpPath += "/"; + tmpPath += demoName; + MakeDir(tmpPath.c_str()); + pDCOMP_GetAPI DCOMP_GetAPI = NULL; #if defined(WIN32) diff --git a/util/test/demos/test_common.h b/util/test/demos/test_common.h index f6039768aa7..0ced0b5f006 100644 --- a/util/test/demos/test_common.h +++ b/util/test/demos/test_common.h @@ -88,7 +88,8 @@ bool SpvCompilationSupported(); std::vector CompileShaderToSpv(const char *demo_name, const std::string &source_text, SPIRVTarget target, ShaderLang lang, ShaderStage stage, const char *entry_point, - const std::map ¯os = {}); + const std::map ¯os = {}, + bool debug_info = true); struct Vec2f { @@ -222,15 +223,19 @@ struct GraphicsTest const char *screenTitle = "RenderDoc test program"; bool headless = false; + bool subtest = false; RENDERDOC_API_1_7_0 *rdoc = NULL; + std::string tmpPath; + // shared parameters static int maxFrameCount; static std::string dataRoot; static int screenWidth; static int screenHeight; static bool debugDevice; + static bool breakOnDebug; }; enum class TestAPI diff --git a/util/test/demos/vk/vk_buffer_truncation.cpp b/util/test/demos/vk/vk_buffer_truncation.cpp index 19a1f451f6b..02c38d55024 100644 --- a/util/test/demos/vk/vk_buffer_truncation.cpp +++ b/util/test/demos/vk/vk_buffer_truncation.cpp @@ -71,8 +71,28 @@ void main() features.robustBufferAccess = VK_TRUE; devExts.push_back(VK_KHR_MAINTENANCE_5_EXTENSION_NAME); + optDevExts.push_back(VK_EXT_ROBUSTNESS_2_EXTENSION_NAME); VulkanGraphicsTest::Prepare(argc, argv); + + VkPhysicalDeviceRobustness2FeaturesEXT robustFeatsAvail = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT, + }; + + getPhysFeatures2(&robustFeatsAvail); + + static VkPhysicalDeviceRobustness2FeaturesEXT robustFeats = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT, + }; + + // enable robustBufferAccess2 as well for index buffers + if(hasExt(VK_EXT_ROBUSTNESS_2_EXTENSION_NAME) && robustFeatsAvail.robustBufferAccess2) + { + robustFeats.robustBufferAccess2 = VK_TRUE; + + robustFeats.pNext = (void *)devInfoNext; + devInfoNext = &robustFeats; + } } int main() diff --git a/util/test/demos/vk/vk_descriptor_buffer_analyse.cpp b/util/test/demos/vk/vk_descriptor_buffer_analyse.cpp index 54e42125f9a..c0581789f7f 100644 --- a/util/test/demos/vk/vk_descriptor_buffer_analyse.cpp +++ b/util/test/demos/vk/vk_descriptor_buffer_analyse.cpp @@ -1101,7 +1101,7 @@ RD_TEST(VK_Descriptor_Buffer_Analyse, VulkanGraphicsTest) VkBuffer sparseBuffer = {}; Image sparseImage = {}; - VkAccelerationStructureKHR blas[16]; + VkAccelerationStructureKHR blas[16] = {}; VkDeviceAddress blasAddr[16] = {}; SizedBytes blasCapData[16] = {}; @@ -1208,6 +1208,8 @@ RD_TEST(VK_Descriptor_Buffer_Analyse, VulkanGraphicsTest) img.name = "yuv3_combined"; img.view = createImageView(viewCreateInfo); + + vkDestroySamplerYcbcrConversionKHR(device, ycbcrChain.conversion, NULL); } if(makeImage(img, memory[i], i, offset, "yuv3_plane1", @@ -1246,6 +1248,8 @@ RD_TEST(VK_Descriptor_Buffer_Analyse, VulkanGraphicsTest) img.name = "yuv2_combined"; img.view = createImageView(viewCreateInfo); + + vkDestroySamplerYcbcrConversionKHR(device, ycbcrChain.conversion, NULL); } if(makeImage(img, memory[i], i, offset, "yuv2_plane1", @@ -1753,7 +1757,7 @@ RD_TEST(VK_Descriptor_Buffer_Analyse, VulkanGraphicsTest) VkDeviceSize alignStep = texelAlign; - // If the single texel alignment property is VK_TRUE, then the buffer view’s offset must be + // If the single texel alignment property is VK_TRUE, then the buffer view's offset must be // aligned to the lesser of the corresponding byte alignment value or the size of a single // texel, based on VkBufferViewCreateInfo::format if(texelAlignProps.uniformTexelBufferOffsetSingleTexelAlignment) @@ -1889,7 +1893,7 @@ RD_TEST(VK_Descriptor_Buffer_Analyse, VulkanGraphicsTest) VkDeviceSize alignStep = texelAlign; - // If the single texel alignment property is VK_TRUE, then the buffer view’s offset must be + // If the single texel alignment property is VK_TRUE, then the buffer view's offset must be // aligned to the lesser of the corresponding byte alignment value or the size of a single // texel, based on VkBufferViewCreateInfo::format if(texelAlignProps.storageTexelBufferOffsetSingleTexelAlignment) @@ -2341,6 +2345,26 @@ RD_TEST(VK_Descriptor_Buffer_Analyse, VulkanGraphicsTest) TEST_LOG(" Storage: %s", name(storage).c_str()); TEST_LOG(" Input: %s", name(input).c_str()); + if(sparseBuffer != VK_NULL_HANDLE) + vkDestroyBuffer(device, sparseBuffer, NULL); + if(sparseImage.img != VK_NULL_HANDLE) + vkDestroyImage(device, sparseImage.img, NULL); + + for(uint32_t i = 0; i < memProps->memoryTypeCount; i++) + { + if(memory[i] != VK_NULL_HANDLE) + vkFreeMemory(device, memory[i], NULL); + + if(buffer[i] != VK_NULL_HANDLE) + vkDestroyBuffer(device, buffer[i], NULL); + if(blas[i] != VK_NULL_HANDLE) + vkDestroyAccelerationStructureKHR(device, blas[i], NULL); + + for(const Image &img : images[i]) + if(img.img != VK_NULL_HANDLE) + vkDestroyImage(device, img.img, NULL); + } + return 0; } }; diff --git a/util/test/demos/vk/vk_descriptor_variable_count.cpp b/util/test/demos/vk/vk_descriptor_variable_count.cpp index 4796bcf7aa9..9656fedd29f 100644 --- a/util/test/demos/vk/vk_descriptor_variable_count.cpp +++ b/util/test/demos/vk/vk_descriptor_variable_count.cpp @@ -161,7 +161,7 @@ void main() if(!Init()) return 3; - const static uint32_t numDescriptorSets = 10 * 1024; + const static uint32_t numDescriptorSets = 7 * 1024; const static uint32_t numDescriptorsPerSet = 2; VkDescriptorSetLayoutBindingFlagsCreateInfoEXT descFlags = { diff --git a/util/test/demos/vk/vk_device_address_commands.cpp b/util/test/demos/vk/vk_device_address_commands.cpp index 4e88ead5188..1b1987cacfe 100644 --- a/util/test/demos/vk/vk_device_address_commands.cpp +++ b/util/test/demos/vk/vk_device_address_commands.cpp @@ -145,7 +145,8 @@ void main() AllocatedImage smiley( this, vkh::ImageCreateInfo(rgba8.width, rgba8.height, 0, VK_FORMAT_R8G8B8A8_UNORM, - VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT), + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | + VK_IMAGE_USAGE_SAMPLED_BIT), VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_GPU_ONLY})); { VkCommandBuffer cmd = GetCommandBuffer(); diff --git a/util/test/demos/vk/vk_discard_zoo.cpp b/util/test/demos/vk/vk_discard_zoo.cpp index 47974c1fd7d..124ac00957f 100644 --- a/util/test/demos/vk/vk_discard_zoo.cpp +++ b/util/test/demos/vk/vk_discard_zoo.cpp @@ -67,14 +67,28 @@ void main() else if(img.createInfo.format == VK_FORMAT_S8_UINT) range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; - vkh::cmdPipelineBarrier( - cmd, { - vkh::ImageMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT | - VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | - VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, - VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, - VK_IMAGE_LAYOUT_GENERAL, img.image, range), - }); + if(range.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) + { + vkh::cmdPipelineBarrier( + cmd, { + vkh::ImageMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_GENERAL, img.image, range), + }); + } + else + { + vkh::cmdPipelineBarrier( + cmd, { + vkh::ImageMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT | + VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_GENERAL, img.image, range), + }); + } VkClearDepthStencilValue val = {0.4f, 0x40}; @@ -105,6 +119,16 @@ void main() vkCmdCopyBufferToImage(cmd, emptyBuf.buffer, img.image, VK_IMAGE_LAYOUT_GENERAL, (uint32_t)regions.size(), regions.data()); + + vkh::cmdPipelineBarrier( + cmd, { + vkh::ImageMemoryBarrier( + VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, img.image, range), + }); + return; } @@ -118,10 +142,28 @@ void main() else vkCmdClearColorImage(cmd, img.image, VK_IMAGE_LAYOUT_GENERAL, vkh::ClearColorValue(0.0f, 1.0f, 0.0f, 1.0f), 1, range); + + vkh::cmdPipelineBarrier( + cmd, { + vkh::ImageMemoryBarrier( + VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, img.image, range), + }); } else { vkCmdClearDepthStencilImage(cmd, img.image, VK_IMAGE_LAYOUT_GENERAL, &val, 1, range); + + vkh::cmdPipelineBarrier( + cmd, { + vkh::ImageMemoryBarrier( + VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, img.image, range), + }); } } @@ -148,9 +190,12 @@ void main() AllocatedImage MakeTex2D(VkFormat fmt, uint32_t width, uint32_t height, uint32_t mips = 1, uint32_t arraySlices = 1) { - return AllocatedImage(this, - vkh::ImageCreateInfo(width, height, 0, fmt, - VK_IMAGE_USAGE_TRANSFER_DST_BIT, mips, arraySlices), + VkImageCreateFlags flags = VK_IMAGE_USAGE_TRANSFER_DST_BIT; + if(fmt == VK_FORMAT_D32_SFLOAT_S8_UINT || fmt == VK_FORMAT_D24_UNORM_S8_UINT || + fmt == VK_FORMAT_D32_SFLOAT || fmt == VK_FORMAT_D16_UNORM || fmt == VK_FORMAT_S8_UINT) + flags |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + + return AllocatedImage(this, vkh::ImageCreateInfo(width, height, 0, fmt, flags, mips, arraySlices), VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_GPU_ONLY})); } @@ -319,10 +364,10 @@ void main() renderPassCreateInfo.attachments[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; renderPassCreateInfo.attachments[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; - renderPassCreateInfo.attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; - renderPassCreateInfo.attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; - renderPassCreateInfo.attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD; - renderPassCreateInfo.attachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD; + renderPassCreateInfo.attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + renderPassCreateInfo.attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + renderPassCreateInfo.attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + renderPassCreateInfo.attachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; renderPassCreateInfo.attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE; renderPassCreateInfo.attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; renderPassCreateInfo.attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; diff --git a/util/test/demos/vk/vk_draw_zoo.cpp b/util/test/demos/vk/vk_draw_zoo.cpp index 5ed35ed8e25..6529060c6cb 100644 --- a/util/test/demos/vk/vk_draw_zoo.cpp +++ b/util/test/demos/vk/vk_draw_zoo.cpp @@ -347,10 +347,6 @@ void main() VkImage swapimg = StartUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); - vkCmdClearColorImage(cmd, swapimg, VK_IMAGE_LAYOUT_GENERAL, - vkh::ClearColorValue(0.2f, 0.2f, 0.2f, 1.0f), 1, - vkh::ImageSubresourceRange()); - vkCmdBeginRenderPass(cmd, vkh::RenderPassBeginInfo(renderPass, framebuffer, mainWindow->scissor, {vkh::ClearValue(0.2f, 0.2f, 0.2f, 1.0f)}), diff --git a/util/test/demos/vk/vk_dynamic_rendering.cpp b/util/test/demos/vk/vk_dynamic_rendering.cpp index 4b503c21162..24a671d16c1 100644 --- a/util/test/demos/vk/vk_dynamic_rendering.cpp +++ b/util/test/demos/vk/vk_dynamic_rendering.cpp @@ -97,6 +97,7 @@ void main() devExts.push_back(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME); features.geometryShader = VK_TRUE; + features.fragmentStoresAndAtomics = VK_TRUE; VulkanGraphicsTest::Prepare(argc, argv); @@ -239,7 +240,8 @@ void main() vkh::cmdPipelineBarrier( cmd, { vkh::ImageMemoryBarrier( - VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, swapimg), }); diff --git a/util/test/demos/vk/vk_ext_buffer_address.cpp b/util/test/demos/vk/vk_ext_buffer_address.cpp deleted file mode 100644 index 0728181ef80..00000000000 --- a/util/test/demos/vk/vk_ext_buffer_address.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/****************************************************************************** - * The MIT License (MIT) - * - * Copyright (c) 2019-2026 Baldur Karlsson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * 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 Software. - * - * THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ - -#include "vk_test.h" - -// only support on 64-bit, just because it's easier to share CPU & GPU structs if pointer size is -// identical - -#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || \ - defined(__ia64) || defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) || \ - (defined(__riscv) && __riscv_xlen == 64) - -RD_TEST(VK_EXT_Buffer_Address, VulkanGraphicsTest) -{ - static constexpr const char *Description = - "Test capture and replay of VK_EXT_buffer_device_address"; - - // should match definition below in GLSL - struct DrawData - { - DefaultA2V *vert_data; - // no alignment on Vec4f, use scalar block layout - Vec4f tint; - Vec2f offset; - Vec2f scale; - // padding to make the struct size 16 to make aligning the buffer easier. - Vec2f padding; - }; - - std::string common = R"EOSHADER( - -#version 460 core - -#extension GL_EXT_buffer_reference : require -#extension GL_EXT_scalar_block_layout : require - -struct v2f -{ - vec4 pos; - vec4 col; - vec4 uv; -}; - -struct DefaultA2V { - vec3 pos; - vec4 col; - vec2 uv; -}; - -layout(buffer_reference, scalar, buffer_reference_align = 16) buffer TriangleData { - DefaultA2V verts[3]; -}; - -layout(buffer_reference, scalar, buffer_reference_align = 16) buffer DrawData { - TriangleData tri; - vec4 tint; - vec2 offset; - vec2 scale; - vec2 padding; -}; - -layout(push_constant) uniform PushData { - DrawData data_ptr; -} push; - -)EOSHADER"; - - const std::string vertex = R"EOSHADER( - -layout(location = 0) out v2f vertOut; - -void main() -{ - DrawData draw = push.data_ptr; - DefaultA2V vert = draw.tri.verts[gl_VertexIndex]; - - gl_Position = vertOut.pos = vec4(vert.pos*vec3(draw.scale,1) + vec3(draw.offset, 0), 1); - vertOut.col = vert.col; - vertOut.uv = vec4(vert.uv, 0, 1); -} - -)EOSHADER"; - - const std::string pixel = R"EOSHADER( - -layout(location = 0) in v2f vertIn; - -layout(location = 0, index = 0) out vec4 Color; - -void main() -{ - DrawData draw = push.data_ptr; - - Color = vertIn.col * draw.tint; -} - -)EOSHADER"; - - void Prepare(int argc, char **argv) - { - devExts.push_back(VK_EXT_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME); - devExts.push_back(VK_EXT_SCALAR_BLOCK_LAYOUT_EXTENSION_NAME); - - VulkanGraphicsTest::Prepare(argc, argv); - - if(!Avail.empty()) - return; - - static VkPhysicalDeviceBufferDeviceAddressFeaturesEXT bufaddrFeatures = { - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT, - }; - - getPhysFeatures2(&bufaddrFeatures); - - if(!bufaddrFeatures.bufferDeviceAddress) - Avail = "Buffer device address feature 'bufferDeviceAddress' not available"; - - devInfoNext = &bufaddrFeatures; - } - - int main() - { - // initialise, create window, create context, etc - if(!Init()) - return 3; - - VkPipelineLayout layout = createPipelineLayout( - vkh::PipelineLayoutCreateInfo({}, {vkh::PushConstantRange(VK_SHADER_STAGE_ALL, 0, 8)})); - - vkh::GraphicsPipelineCreateInfo pipeCreateInfo; - - pipeCreateInfo.layout = layout; - pipeCreateInfo.renderPass = mainWindow->rp; - - pipeCreateInfo.stages = { - CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), - CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), - }; - - VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); - - vkh::BufferCreateInfo bufinfo(0x100000, VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_EXT); - - AllocatedBuffer databuf(this, bufinfo, VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_CPU_TO_GPU})); - - // north-facing primary colours triangle - const DefaultA2V tri1[3] = { - {Vec3f(-0.5f, -0.5f, 0.0f), Vec4f(1.0f, 0.0f, 0.0f, 1.0f), Vec2f(0.0f, 0.0f)}, - {Vec3f(0.0f, 0.5f, 0.0f), Vec4f(0.0f, 1.0f, 0.0f, 1.0f), Vec2f(0.0f, 1.0f)}, - {Vec3f(0.5f, -0.5f, 0.0f), Vec4f(0.0f, 0.0f, 1.0f, 1.0f), Vec2f(1.0f, 0.0f)}, - }; - - // north-west-facing triangle - const DefaultA2V tri2[3] = { - {Vec3f(-0.5f, 0.5f, 0.0f), Vec4f(1.0f, 0.2f, 1.0f, 1.0f), Vec2f(0.0f, 0.0f)}, - {Vec3f(0.5f, 0.5f, 0.0f), Vec4f(0.7f, 0.85f, 1.0f, 1.0f), Vec2f(0.0f, 1.0f)}, - {Vec3f(-0.5f, -0.5f, 0.0f), Vec4f(1.0f, 1.0f, 0.4f, 1.0f), Vec2f(1.0f, 0.0f)}, - }; - - VkBufferDeviceAddressInfoEXT info = {VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO_EXT}; - info.buffer = databuf.buffer; - - VkDeviceAddress baseAddr = vkGetBufferDeviceAddressEXT(device, &info); - byte *gpuptr = (byte *)baseAddr; // not a valid cpu pointer but useful for avoiding casting - - byte *cpuptr = databuf.map(); - - // put triangle data first - memcpy(cpuptr, tri1, sizeof(tri1)); - DefaultA2V *gputri1 = (DefaultA2V *)gpuptr; - cpuptr += sizeof(tri1); - gpuptr += sizeof(tri1); - - // align to 16 bytes - cpuptr = AlignUpPtr(cpuptr, 16); - gpuptr = AlignUpPtr(gpuptr, 16); - - memcpy(cpuptr, tri2, sizeof(tri2)); - DefaultA2V *gputri2 = (DefaultA2V *)gpuptr; - cpuptr += sizeof(tri2); - gpuptr += sizeof(tri2); - - // align to 16 bytes - cpuptr = AlignUpPtr(cpuptr, 16); - gpuptr = AlignUpPtr(gpuptr, 16); - - DrawData *drawscpu = (DrawData *)cpuptr; - DrawData *drawsgpu = (DrawData *)gpuptr; - - drawscpu[0].vert_data = gputri1; - drawscpu[0].offset = Vec2f(-0.5f, 0.0f); - drawscpu[0].scale = Vec2f(0.5f, 0.5f); - drawscpu[0].tint = Vec4f(1.0f, 0.5f, 0.5f, 1.0f); // tint red - - drawscpu[1].vert_data = gputri1; - drawscpu[1].offset = Vec2f(0.0f, 0.0f); - drawscpu[1].scale = Vec2f(0.5f, -0.5f); // flip vertically - drawscpu[1].tint = Vec4f(0.2f, 0.5f, 1.0f, 1.0f); // tint blue - - drawscpu[2].vert_data = gputri2; // use second triangle - drawscpu[2].offset = Vec2f(0.6f, 0.0f); - drawscpu[2].scale = Vec2f(0.5f, 0.5f); - drawscpu[2].tint = Vec4f(1.0f, 1.0f, 1.0f, 1.0f); - - float time = 0.0f; - - while(Running()) - { - VkCommandBuffer cmd = GetCommandBuffer(); - - vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo()); - - VkImage swapimg = - StartUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); - - vkCmdClearColorImage(cmd, swapimg, VK_IMAGE_LAYOUT_GENERAL, - vkh::ClearColorValue(0.2f, 0.2f, 0.2f, 1.0f), 1, - vkh::ImageSubresourceRange()); - - vkCmdBeginRenderPass( - cmd, vkh::RenderPassBeginInfo(mainWindow->rp, mainWindow->GetFB(), mainWindow->scissor), - VK_SUBPASS_CONTENTS_INLINE); - - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); - vkCmdSetViewport(cmd, 0, 1, &mainWindow->viewport); - vkCmdSetScissor(cmd, 0, 1, &mainWindow->scissor); - - // look ma, no binds - DrawData *bindptr = drawsgpu; - drawscpu[0].scale.x = (abs(sinf(time)) + 0.1f) * 0.5f; - vkCmdPushConstants(cmd, layout, VK_SHADER_STAGE_ALL, 0, 8, &bindptr); - vkCmdDraw(cmd, 3, 1, 0, 0); - - bindptr++; - drawscpu[1].scale.y = (abs(cosf(time)) + 0.1f) * 0.5f; - vkCmdPushConstants(cmd, layout, VK_SHADER_STAGE_ALL, 0, 8, &bindptr); - vkCmdDraw(cmd, 3, 1, 0, 0); - - bindptr++; - drawscpu[2].tint = Vec4f(cosf(time) * 0.5f + 0.5f, sinf(time) * 0.5f + 0.5f, - cosf(time + 3.14f) * 0.5f + 0.5f, 1.0f); - vkCmdPushConstants(cmd, layout, VK_SHADER_STAGE_ALL, 0, 8, &bindptr); - vkCmdDraw(cmd, 3, 1, 0, 0); - - vkCmdEndRenderPass(cmd); - - FinishUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); - - vkEndCommandBuffer(cmd); - - Submit(0, 1, {cmd}); - - Present(); - - time += 0.1f; - } - - databuf.unmap(); - - return 0; - } -}; - -REGISTER_TEST(); - -#endif // if 64-bit diff --git a/util/test/demos/vk/vk_extended_dyn_state.cpp b/util/test/demos/vk/vk_extended_dyn_state.cpp index 5fc43be4fea..77a9369468a 100644 --- a/util/test/demos/vk/vk_extended_dyn_state.cpp +++ b/util/test/demos/vk/vk_extended_dyn_state.cpp @@ -233,7 +233,7 @@ RD_TEST(VK_Extended_Dynamic_State, VulkanGraphicsTest) vkCmdEndRenderPass(cmd); - FinishUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); + FinishUsingBackbuffer(cmd, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); vkEndCommandBuffer(cmd); diff --git a/util/test/demos/vk/vk_graphics_pipeline.cpp b/util/test/demos/vk/vk_graphics_pipeline.cpp index 675c34c0eaf..2f9e9e6ec49 100644 --- a/util/test/demos/vk/vk_graphics_pipeline.cpp +++ b/util/test/demos/vk/vk_graphics_pipeline.cpp @@ -481,7 +481,7 @@ void main() vkCmdEndRenderPass(cmd); - FinishUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); + FinishUsingBackbuffer(cmd, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); vkEndCommandBuffer(cmd); diff --git a/util/test/demos/vk/vk_helpers.h b/util/test/demos/vk/vk_helpers.h index 8042c51dc2b..ea51b95ad31 100644 --- a/util/test/demos/vk/vk_helpers.h +++ b/util/test/demos/vk/vk_helpers.h @@ -1459,6 +1459,19 @@ struct RenderPassCreator : private VkRenderPassCreateInfo sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; pNext = NULL; flags = 0; + + // add deps to allow clear/copy on targets before or after + dependencies.push_back(vkh::SubpassDependency( + ~0U, 0, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT)); + dependencies.push_back(vkh::SubpassDependency( + 0, ~0U, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT)); } using VkRenderPassCreateInfo::pNext; @@ -1619,6 +1632,19 @@ struct RenderPassCreator2 : private VkRenderPassCreateInfo2KHR sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2_KHR; pNext = NULL; flags = 0; + + // add deps to allow clear/copy on targets before or after + dependencies.push_back(vkh::SubpassDependency2KHR( + ~0U, 0, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT)); + dependencies.push_back(vkh::SubpassDependency2KHR( + 0, ~0U, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT)); } using VkRenderPassCreateInfo2KHR::flags; diff --git a/util/test/demos/vk/vk_khr_buffer_address.cpp b/util/test/demos/vk/vk_khr_buffer_address.cpp index 31243594538..79bf9de1552 100644 --- a/util/test/demos/vk/vk_khr_buffer_address.cpp +++ b/util/test/demos/vk/vk_khr_buffer_address.cpp @@ -133,6 +133,11 @@ void main() VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_KHR, }; + static VkPhysicalDeviceScalarBlockLayoutFeaturesEXT scalarFeatures = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT, + }; + + getPhysFeatures2(&scalarFeatures); getPhysFeatures2(&bufaddrFeatures); if(!bufaddrFeatures.bufferDeviceAddress) @@ -142,6 +147,7 @@ void main() bufaddrFeatures.bufferDeviceAddressMultiDevice = 0; devInfoNext = &bufaddrFeatures; + bufaddrFeatures.pNext = &scalarFeatures; } int main() diff --git a/util/test/demos/vk/vk_large_descriptor_sets.cpp b/util/test/demos/vk/vk_large_descriptor_sets.cpp index 4fef1ea03ad..369282cc1c6 100644 --- a/util/test/demos/vk/vk_large_descriptor_sets.cpp +++ b/util/test/demos/vk/vk_large_descriptor_sets.cpp @@ -311,6 +311,8 @@ void main() Present(); } + vkDestroyDescriptorPool(device, descpool, NULL); + return 0; } }; diff --git a/util/test/demos/vk/vk_line_raster.cpp b/util/test/demos/vk/vk_line_raster.cpp index ba8c83969ce..db569a9ca2d 100644 --- a/util/test/demos/vk/vk_line_raster.cpp +++ b/util/test/demos/vk/vk_line_raster.cpp @@ -179,6 +179,7 @@ void main() tests.push_back({VK_NULL_HANDLE}); lineRasterSetup.stippledLineEnable = VK_TRUE; + lineRasterSetup.lineStippleFactor = 1; pipeCreateInfo.dynamicState.dynamicStates.push_back(VK_DYNAMIC_STATE_LINE_STIPPLE_EXT); if(lineRasterFeatures.rectangularLines && lineRasterFeatures.stippledRectangularLines) diff --git a/util/test/demos/vk/vk_load_store_none.cpp b/util/test/demos/vk/vk_load_store_none.cpp index 013c9c0613e..dbdb5acb0f2 100644 --- a/util/test/demos/vk/vk_load_store_none.cpp +++ b/util/test/demos/vk/vk_load_store_none.cpp @@ -110,6 +110,12 @@ void main() vkh::RenderPassCreator renderPassCreateInfo; + renderPassCreateInfo.dependencies.clear(); + renderPassCreateInfo.dependencies.push_back(vkh::SubpassDependency( + ~0U, 0, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT)); + renderPassCreateInfo.attachments.push_back( vkh::AttachmentDescription(VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, VK_ATTACHMENT_LOAD_OP_CLEAR)); diff --git a/util/test/demos/vk/vk_mesh_zoo.cpp b/util/test/demos/vk/vk_mesh_zoo.cpp index e5c882d69b1..5517feeba05 100644 --- a/util/test/demos/vk/vk_mesh_zoo.cpp +++ b/util/test/demos/vk/vk_mesh_zoo.cpp @@ -487,7 +487,7 @@ void main() vkCmdEndRenderPass(cmd); - FinishUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); + FinishUsingBackbuffer(cmd, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); vkEndCommandBuffer(cmd); diff --git a/util/test/demos/vk/vk_misaligned_dirty.cpp b/util/test/demos/vk/vk_misaligned_dirty.cpp index 386361c157e..af55eefbc3b 100644 --- a/util/test/demos/vk/vk_misaligned_dirty.cpp +++ b/util/test/demos/vk/vk_misaligned_dirty.cpp @@ -107,6 +107,10 @@ RD_TEST(VK_Misaligned_Dirty, VulkanGraphicsTest) vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo()); setMarker(cmd, "First Submit"); vkCmdUpdateBuffer(cmd, copy_src.buffer, sizeof(Vec3f), sizeof(Vec4f), &tri[0].col); + vkh::cmdPipelineBarrier( + cmd, {}, + {vkh::BufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, + copy_src.buffer)}); vkEndCommandBuffer(cmd); Submit(0, 3, {cmd}); @@ -134,6 +138,11 @@ RD_TEST(VK_Misaligned_Dirty, VulkanGraphicsTest) region.size = sizeof(DefaultA2V); vkCmdCopyBuffer(cmd, copy_src.buffer, vb.buffer, 1, ®ion); + vkh::cmdPipelineBarrier( + cmd, {}, + {vkh::BufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, vb.buffer)}); + vkCmdBeginRenderPass( cmd, vkh::RenderPassBeginInfo(mainWindow->rp, mainWindow->GetFB(), mainWindow->scissor), VK_SUBPASS_CONTENTS_INLINE); @@ -161,6 +170,10 @@ RD_TEST(VK_Misaligned_Dirty, VulkanGraphicsTest) // (we don't create reference data until after this) vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo()); setMarker(cmd, "Third Submit"); + vkh::cmdPipelineBarrier( + cmd, {}, + {vkh::BufferMemoryBarrier(VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT, copy_src.buffer)}); vkCmdUpdateBuffer(cmd, copy_src.buffer, sizeof(Vec3f), sizeof(Vec4f), &tri[0].col); vkEndCommandBuffer(cmd); Submit(2, 3, {cmd}); diff --git a/util/test/demos/vk/vk_multi_entry.cpp b/util/test/demos/vk/vk_multi_entry.cpp index bc7dc685dae..efb8d3016c8 100644 --- a/util/test/demos/vk/vk_multi_entry.cpp +++ b/util/test/demos/vk/vk_multi_entry.cpp @@ -35,10 +35,10 @@ RD_TEST(VK_Multi_Entry, VulkanGraphicsTest) OpMemoryModel Logical GLSL450 OpEntryPoint Vertex %fakev "fake" %posout - OpEntryPoint Fragment %fakef "fake" %ColorF + OpEntryPoint Fragment %fakef "fake" %ColorF %push %tex1 OpEntryPoint Vertex %mainv "main" %vertOut %Position %_ %Color %UV - OpEntryPoint Fragment %mainf "main" %ColorF %vertIn + OpEntryPoint Fragment %mainf "main" %ColorF %vertIn %push %tex OpExecutionMode %fakef OriginUpperLeft OpExecutionMode %mainf OriginUpperLeft @@ -241,7 +241,7 @@ RD_TEST(VK_Multi_Entry, VulkanGraphicsTest) }; VkPipelineShaderStageCreateInfo shad = CompileShaderModule( - combined_asm, ShaderLang::spvasm, ShaderStage::vert, "main", {}, SPIRVTarget::vulkan); + combined_asm, ShaderLang::spvasm, ShaderStage::vert, "main", {}, SPIRVTarget::vulkan12); pipeCreateInfo.stages = { shad, diff --git a/util/test/demos/vk/vk_multi_present.cpp b/util/test/demos/vk/vk_multi_present.cpp index e597bb48037..a031d4ac529 100644 --- a/util/test/demos/vk/vk_multi_present.cpp +++ b/util/test/demos/vk/vk_multi_present.cpp @@ -172,6 +172,8 @@ RD_TEST(VK_Multi_Present, VulkanGraphicsTest) for(size_t i = 0; i < windows.size(); i++) delete windows[i]; + mainWindow = NULL; + return 0; } }; diff --git a/util/test/demos/vk/vk_multi_thread_windows.cpp b/util/test/demos/vk/vk_multi_thread_windows.cpp index 6eef28d7a0f..d1fbe8da54e 100644 --- a/util/test/demos/vk/vk_multi_thread_windows.cpp +++ b/util/test/demos/vk/vk_multi_thread_windows.cpp @@ -133,7 +133,7 @@ RD_TEST(VK_Multi_Thread_Windows, VulkanGraphicsTest) win->Submit(0, 1, {cmd}, {}, q); - win->Present(q); + win->Present(q, true); } while(win); }; diff --git a/util/test/demos/vk/vk_parameter_zoo.cpp b/util/test/demos/vk/vk_parameter_zoo.cpp index 2adb847f8f4..9bcd14503bc 100644 --- a/util/test/demos/vk/vk_parameter_zoo.cpp +++ b/util/test/demos/vk/vk_parameter_zoo.cpp @@ -298,6 +298,7 @@ void main() optDevExts.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME); optDevExts.push_back(VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME); optDevExts.push_back(VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME); + optDevExts.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME); VulkanGraphicsTest::Prepare(argc, argv); @@ -409,10 +410,39 @@ void main() inlineFeats.pNext = (void *)devInfoNext; devInfoNext = &inlineFeats; } + + static VkPhysicalDeviceExtendedDynamicState3FeaturesEXT extFeatures3 = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_3_FEATURES_EXT, + }; + + if(hasExt(VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME)) + { + getPhysFeatures2(&extFeatures3); + + if(!extFeatures3.extendedDynamicState3ColorBlendEnable) + Avail = "feature 'extendedDynamicState3ColorBlendEnable' not available"; + if(!extFeatures3.extendedDynamicState3ColorBlendEquation) + Avail = "feature 'extendedDynamicState3ColorBlendEquation' not available"; + if(!extFeatures3.extendedDynamicState3ColorWriteMask) + Avail = "feature 'extendedDynamicState3ColorWriteMask' not available"; + + extFeatures3 = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_3_FEATURES_EXT, + }; + extFeatures3.extendedDynamicState3ColorBlendEnable = VK_TRUE; + extFeatures3.extendedDynamicState3ColorBlendEquation = VK_TRUE; + extFeatures3.extendedDynamicState3ColorWriteMask = VK_TRUE; + + extFeatures3.pNext = (void *)devInfoNext; + devInfoNext = &extFeatures3; + } } int main() { + // we deliberately test this behaviour, it's not invalid and we expectt the NULL this is warning us about + mutedMessages.push_back("WARNING-vkGetDeviceProcAddr-device"); + // initialise, create window, create context, etc if(!Init()) return 3; @@ -726,7 +756,30 @@ void main() CompileShaderModule(VKDefaultPixel, ShaderLang::glsl, ShaderStage::frag, "main"), }; - VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); + VkPipeline pipe; + + if(hasExt(VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME)) + { + vkh::GraphicsPipelineCreateInfo dupe = pipeCreateInfo; + + dupe.dynamicState.dynamicStates.push_back(VK_DYNAMIC_STATE_COLOR_BLEND_ENABLE_EXT); + dupe.dynamicState.dynamicStates.push_back(VK_DYNAMIC_STATE_COLOR_BLEND_EQUATION_EXT); + dupe.dynamicState.dynamicStates.push_back(VK_DYNAMIC_STATE_COLOR_WRITE_MASK_EXT); + + // force it to bake, _then_ invalidate attachments + VkGraphicsPipelineCreateInfo *info = dupe; + + VkPipelineColorBlendStateCreateInfo col = *info->pColorBlendState; + col.attachmentCount = 999999; + col.pAttachments = NULL; + info->pColorBlendState = &col; + + pipe = createGraphicsPipeline(info); + } + else + { + pipe = createGraphicsPipeline(pipeCreateInfo); + } pipeCreateInfo.layout = reflayout; @@ -969,7 +1022,8 @@ void main() VkCommandBuffer cmd = GetCommandBuffer(); vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo()); vkh::cmdPipelineBarrier(cmd, { - vkh::ImageMemoryBarrier(0, 0, VK_IMAGE_LAYOUT_UNDEFINED, + vkh::ImageMemoryBarrier(0, VK_ACCESS_TRANSFER_WRITE_BIT, + VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, img.image), }); vkCmdClearColorImage(cmd, img.image, VK_IMAGE_LAYOUT_GENERAL, @@ -1966,6 +2020,26 @@ void main() vkCmdDraw(cmd, 4, 1, 0, 0); vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); + + if(hasExt(VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME)) + { + // need to set color blend state + VkBool32 no = VK_FALSE; + vkCmdSetColorBlendEnableEXT(cmd, 0, 1, &no); + VkColorComponentFlags all = 0xf; + vkCmdSetColorWriteMaskEXT(cmd, 0, 1, &all); + VkColorBlendEquationEXT eq = { + VK_BLEND_FACTOR_SRC_ALPHA, + VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, + VK_BLEND_OP_ADD, + // alpha* + VK_BLEND_FACTOR_SRC_ALPHA, + VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, + VK_BLEND_OP_ADD, + }; + vkCmdSetColorBlendEquationEXT(cmd, 0, 1, &eq); + } + vkCmdSetViewport(cmd, 0, 1, &mainWindow->viewport); vkCmdSetScissor(cmd, 0, 1, &mainWindow->scissor); vkh::cmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, {descset}, diff --git a/util/test/demos/vk/vk_ray_query.cpp b/util/test/demos/vk/vk_ray_query.cpp index 7fecaf9c17c..e5ae4a05494 100644 --- a/util/test/demos/vk/vk_ray_query.cpp +++ b/util/test/demos/vk/vk_ray_query.cpp @@ -247,6 +247,10 @@ void main(void) VkCommandBuffer cmd = GetCommandBuffer(); CHECK_VKR(vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo())); vkCmdBuildAccelerationStructuresKHR(cmd, 1, &blasBuildGeometryInfo, &asBuildRangeInfos); + vkh::cmdPipelineBarrier(cmd, {}, + {vkh::BufferMemoryBarrier( + VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR, + VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR, blasBuffer.buffer)}); CHECK_VKR(vkEndCommandBuffer(cmd)); Submit(99, 99, {cmd}); } diff --git a/util/test/demos/vk/vk_resource_usage.cpp b/util/test/demos/vk/vk_resource_usage.cpp index 524fc25d175..f94d1071ab1 100644 --- a/util/test/demos/vk/vk_resource_usage.cpp +++ b/util/test/demos/vk/vk_resource_usage.cpp @@ -245,6 +245,7 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) devExts.push_back(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME); features.multiDrawIndirect = VK_TRUE; + features.drawIndirectFirstInstance = VK_TRUE; optDevExts.push_back(VK_EXT_DESCRIPTOR_BUFFER_EXTENSION_NAME); optDevExts.push_back(VK_EXT_NESTED_COMMAND_BUFFER_EXTENSION_NAME); @@ -542,6 +543,7 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) VkPipelineLayout meshShaderLayout = createPipelineLayout( vkh::PipelineLayoutCreateInfo({}, {vkh::PushConstantRange(VK_SHADER_STAGE_ALL, 0, 8)})); + setName(meshShaderLayout, "Mesh Shader Pipeline Layout"); VkPipeline meshShaderPipe = VK_NULL_HANDLE; if(meshShader) @@ -563,6 +565,7 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) vkMeshShaderPipeCreateInfo->pInputAssemblyState = NULL; meshShaderPipe = createGraphicsPipeline(vkMeshShaderPipeCreateInfo); + setName(meshShaderPipe, "Mesh Shader Pipeline"); } VkDescriptorSetLayout compDescSetLayout = @@ -574,7 +577,7 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) VkPipelineLayout compDescSetPipeLayout = createPipelineLayout(vkh::PipelineLayoutCreateInfo({compDescSetLayout})); - setName(compDescSetPipeLayout, "Compute Pipeline Layout"); + setName(compDescSetPipeLayout, "Compute Descriptor Set Pipeline Layout"); vkh::ComputePipelineCreateInfo compDescSetPipeCreateInfo( compDescSetPipeLayout, @@ -607,7 +610,7 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) if(descBuffer) { compDescBuffPipeLayout = createPipelineLayout(vkh::PipelineLayoutCreateInfo({descBuffLayout})); - setName(compDescSetPipeLayout, "Compute Descriptor Buffer Pipeline Layout"); + setName(compDescBuffPipeLayout, "Compute Descriptor Buffer Pipeline Layout"); vkh::ComputePipelineCreateInfo compDescBuffPipeCreateInfo( compDescBuffPipeLayout, @@ -827,6 +830,10 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) {vkh::BufferMemoryBarrier(VK_ACCESS_NONE, VK_ACCESS_NONE, barrierBuffer.buffer)}); vkEndCommandBuffer(barrierCmd); + VkEvent testEvent; + CHECK_VKR(vkCreateEvent(device, vkh::EventCreateInfo(), NULL, &testEvent)); + setName(testEvent, "Test Event"); + VkFence barrierCmdSubmitFence; CHECK_VKR(vkCreateFence(device, vkh::FenceCreateInfo(VK_FENCE_CREATE_SIGNALED_BIT), NULL, &barrierCmdSubmitFence)); @@ -836,6 +843,19 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) { viewPort = {0.0f, 0.0f, sqSize, sqSize, 0.0f, 1.0f}; setName(mainWindow->GetFB(), "Main Framebuffer"); + std::vector secondaries; + + vkh::updateDescriptorSets( + device, + { + vkh::WriteDescriptorSet(compWriteDataDescSet, 0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, + {vkh::DescriptorBufferInfo(indirectData.buffer)}), + vkh::WriteDescriptorSet(compDescSet, 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, + {vkh::DescriptorBufferInfo(compBufIn.buffer)}), + vkh::WriteDescriptorSet( + descSet, 2, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + {vkh::DescriptorImageInfo(offimgRTV, VK_IMAGE_LAYOUT_GENERAL, linearSampler)}), + }); VkCommandBuffer barrierSecCmd = GetCommandBuffer(VK_COMMAND_BUFFER_LEVEL_SECONDARY); vkBeginCommandBuffer(barrierSecCmd, vkh::CommandBufferBeginInfo( @@ -846,7 +866,7 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) {vkh::BufferMemoryBarrier(VK_ACCESS_NONE, VK_ACCESS_NONE, barrier2Buffer.buffer)}); vkEndCommandBuffer(barrierSecCmd); - VkCommandBuffer secCmdBuffers[3]; + std::vector secCmdBuffers; for(size_t i = 0; i < 2; i++) { VkCommandBuffer secCmd = GetCommandBuffer(VK_COMMAND_BUFFER_LEVEL_SECONDARY); @@ -876,7 +896,7 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) popMarker(secCmd); vkEndCommandBuffer(secCmd); - secCmdBuffers[i] = secCmd; + secCmdBuffers.push_back(secCmd); } { VkCommandBuffer emptySecCmd = GetCommandBuffer(VK_COMMAND_BUFFER_LEVEL_SECONDARY); @@ -885,7 +905,7 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, vkh::CommandBufferInheritanceInfo(renderPass, 0))); vkEndCommandBuffer(emptySecCmd); - secCmdBuffers[2] = emptySecCmd; + secCmdBuffers.push_back(emptySecCmd); } VkCommandBuffer nestedCmd = GetCommandBuffer(VK_COMMAND_BUFFER_LEVEL_SECONDARY); @@ -949,6 +969,7 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) VkCommandBuffer cmd = GetCommandBuffer(); vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo()); + setMarker(cmd, "Resource Usage: Start"); VkImage swapimg = StartUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); @@ -999,9 +1020,9 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) {vkh::BufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, indirectData.buffer)}); - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, compWriteDataPipe); vkh::cmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, compWriteDataPipeLayout, 0, {compWriteDataDescSet}, {}); + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, compWriteDataPipe); uint32_t mode = 0; vkCmdPushConstants(cmd, compWriteDataPipeLayout, VK_SHADER_STAGE_COMPUTE_BIT, 0, 4, &mode); @@ -1068,7 +1089,8 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) { vkCmdBeginRenderPass(cmd, mainWindow->beginRP(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); - vkCmdExecuteCommands(cmd, 3, secCmdBuffers); + vkCmdExecuteCommands(cmd, (uint32_t)secCmdBuffers.size(), secCmdBuffers.data()); + secondaries.insert(secondaries.end(), secCmdBuffers.begin(), secCmdBuffers.end()); vkCmdEndRenderPass(cmd); } popMarker(cmd); @@ -1092,6 +1114,7 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) pushMarker(cmd, "Secondary Command Buffer"); { vkCmdExecuteCommands(cmd, 1, &compSecCmd); + secondaries.push_back(compSecCmd); } popMarker(cmd); } @@ -1101,9 +1124,9 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) { pushMarker(cmd, "Indirect Dispatch Write IndirectDraw Data"); { - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, compWriteDataPipe); vkh::cmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, compWriteDataPipeLayout, 0, {compWriteDataDescSet}, {}); + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, compWriteDataPipe); uint32_t mode = 1; vkCmdPushConstants(cmd, compWriteDataPipeLayout, VK_SHADER_STAGE_COMPUTE_BIT, 0, 4, &mode); @@ -1187,9 +1210,9 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) {vkh::BufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, indirectData.buffer)}); - vkCmdBindPipeline(indirectCompSecCmd, VK_PIPELINE_BIND_POINT_COMPUTE, compWriteDataPipe); vkh::cmdBindDescriptorSets(indirectCompSecCmd, VK_PIPELINE_BIND_POINT_COMPUTE, compWriteDataPipeLayout, 0, {compWriteDataDescSet}, {}); + vkCmdBindPipeline(indirectCompSecCmd, VK_PIPELINE_BIND_POINT_COMPUTE, compWriteDataPipe); uint32_t mode = 0; vkCmdPushConstants(indirectCompSecCmd, compWriteDataPipeLayout, @@ -1201,10 +1224,11 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) vkCmdPushConstants(indirectCompSecCmd, compWriteDataPipeLayout, VK_SHADER_STAGE_COMPUTE_BIT, 0, 4, &mode); - vkh::cmdPipelineBarrier( - indirectCompSecCmd, {}, - {vkh::BufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, - VK_ACCESS_TRANSFER_WRITE_BIT, indirectData.buffer)}); + vkh::cmdPipelineBarrier(indirectCompSecCmd, {}, + {vkh::BufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT | + VK_ACCESS_INDIRECT_COMMAND_READ_BIT, + indirectData.buffer)}); setMarker(indirectCompSecCmd, "DispatchIndirect"); vkCmdDispatchIndirect(indirectCompSecCmd, indirectData.buffer, 0); @@ -1212,8 +1236,10 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) vkh::cmdPipelineBarrier( indirectCompSecCmd, {}, - {vkh::BufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, - VK_ACCESS_TRANSFER_WRITE_BIT, indirectData.buffer)}); + {vkh::BufferMemoryBarrier( + VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_INDIRECT_COMMAND_READ_BIT, + VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_INDIRECT_COMMAND_READ_BIT, + indirectData.buffer)}); vkCmdDispatchIndirect(indirectCompSecCmd, indirectData.buffer, 0); @@ -1226,6 +1252,7 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) } vkCmdExecuteCommands(cmd, 1, &indirectCompSecCmd); + secondaries.push_back(indirectCompSecCmd); vkCmdBeginRenderPass(cmd, mainWindow->beginRP(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); @@ -1242,14 +1269,13 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) uint32_t strideDraw = sizeof(uvec4); vkCmdSetScissor(indirectDrawSecCmd, 0, 1, &mainWindow->scissor); + setMarker(indirectDrawSecCmd, "DrawIndirect: Single"); vkh::cmdBindDescriptorSets(indirectDrawSecCmd, VK_PIPELINE_BIND_POINT_GRAPHICS, descSetPipeLayout, 0, {descSet}, {}); vkh::cmdBindVertexBuffers(indirectDrawSecCmd, 0, {vb.buffer}, {0}); vkCmdBindIndexBuffer(indirectDrawSecCmd, ib.buffer, 0, VK_INDEX_TYPE_UINT32); - vkCmdBindPipeline(indirectDrawSecCmd, VK_PIPELINE_BIND_POINT_GRAPHICS, descSetPipe); - - setMarker(indirectDrawSecCmd, "DrawIndirect: Single"); + vkCmdBindPipeline(indirectDrawSecCmd, VK_PIPELINE_BIND_POINT_GRAPHICS, descSetPipe); vkCmdSetViewport(indirectDrawSecCmd, 0, 1, &viewPort); vkCmdDrawIndirect(indirectDrawSecCmd, indirectData.buffer, offset, 1, strideDraw); NextTest(); @@ -1272,6 +1298,7 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) vkEndCommandBuffer(indirectDrawSecCmd); } vkCmdExecuteCommands(cmd, 1, &indirectDrawSecCmd); + secondaries.push_back(indirectDrawSecCmd); vkCmdEndRenderPass(cmd); } @@ -1288,13 +1315,13 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) vkCmdBeginRenderPass(cmd, mainWindow->beginRP(), VK_SUBPASS_CONTENTS_INLINE); vkCmdSetScissor(cmd, 0, 1, &mainWindow->scissor); + setMarker(cmd, "DrawIndirect: Single"); vkh::cmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, descSetPipeLayout, 0, {descSet}, {}); vkh::cmdBindVertexBuffers(cmd, 0, {vb.buffer}, {0}); vkCmdBindIndexBuffer(cmd, ib.buffer, 0, VK_INDEX_TYPE_UINT32); - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, descSetPipe); - setMarker(cmd, "DrawIndirect: Single"); + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, descSetPipe); vkCmdSetViewport(cmd, 0, 1, &viewPort); size_t drawIndirectOffset = offset; vkCmdDrawIndirect(cmd, indirectData.buffer, drawIndirectOffset, 1, strideDraw); @@ -1315,9 +1342,11 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) strideDrawIndexed); NextTest(); + setMarker(cmd, "DrawIndexedIndirect-UnBind"); vkCmdSetViewport(cmd, 0, 1, &viewPort); vkCmdBindIndexBuffer(cmd, indirectData.buffer, 1024, VK_INDEX_TYPE_UINT32); vkCmdDrawIndexedIndirect(cmd, indirectData.buffer, offset, 1, strideDrawIndexed); + setMarker(cmd, "DrawIndexedIndirect-Bind"); vkCmdBindIndexBuffer(cmd, ib.buffer, 0, VK_INDEX_TYPE_UINT32); NextTest(); offset += countDrawIndexed * strideDrawIndexed; @@ -1379,7 +1408,8 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) vkEndCommandBuffer(cmd); - Submit(0, 3, {cmd}); + Submit(0, 2, {cmd}, secondaries); + secondaries.clear(); cmd = GetCommandBuffer(); @@ -1397,10 +1427,12 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) vkCmdBeginRenderPass(cmd, mainWindow->beginRP(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); vkCmdExecuteCommands(cmd, 1, &nestedCmd); + secondaries.push_back(nestedCmd); vkCmdEndRenderPass(cmd); setMarker(cmd, "Dispatch"); vkCmdExecuteCommands(cmd, 1, &compNestedSecCmd); + secondaries.push_back(compNestedSecCmd); popMarker(cmd); } @@ -1442,7 +1474,7 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) vkh::cmdPipelineBarrier( restoreDescBufCmd, {}, { - vkh::BufferMemoryBarrier(VK_ACCESS_TRANSFER_READ_BIT, VK_ACCESS_TRANSFER_READ_BIT, + vkh::BufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, descBackupBuf.buffer), vkh::BufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, descBuf.buffer), @@ -1549,7 +1581,9 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) vkEndCommandBuffer(cmd); cmds.push_back(cmd); - Submit(1, 3, cmds); + // Final submit related to backbuffer + Submit(1, 2, cmds, secondaries); + secondaries.clear(); std::vector cmds2; cmds2.push_back(barrierCmd); @@ -1562,7 +1596,9 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) vkWaitForFences(device, 1, &barrierCmdSubmitFence, VK_TRUE, UINT64_MAX); } - cmd = GetCommandBuffer(); + CHECK_VKR(vkAllocateCommandBuffers(device, vkh::CommandBufferAllocateInfo(barrierCmdPool, 1), + &cmd)); + setName(cmd, "Multiple Secondary Executes Command Buffer"); vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo()); @@ -1575,9 +1611,19 @@ RD_TEST(VK_Resource_Usage, VulkanGraphicsTest) popMarker(cmd); } + setMarker(cmd, "Resource Usage: End"); vkEndCommandBuffer(cmd); - Submit(2, 3, {cmd}); + std::vector cmds3; + cmds3.push_back(cmd); + submit = vkh::SubmitInfo(cmds3); + vkWaitForFences(device, 1, &barrierCmdSubmitFence, VK_TRUE, UINT64_MAX); + vkResetFences(device, 1, &barrierCmdSubmitFence); + vkSetEvent(device, testEvent); + vkResetEvent(device, testEvent); + vkGetEventStatus(device, testEvent); + CHECK_VKR(vkQueueSubmit(queue, 1, &submit, barrierCmdSubmitFence)); + vkWaitForFences(device, 1, &barrierCmdSubmitFence, VK_TRUE, UINT64_MAX); Present(); } diff --git a/util/test/demos/vk/vk_secondary_cmdbuf.cpp b/util/test/demos/vk/vk_secondary_cmdbuf.cpp index eaf556e8ed9..3005b92e997 100644 --- a/util/test/demos/vk/vk_secondary_cmdbuf.cpp +++ b/util/test/demos/vk/vk_secondary_cmdbuf.cpp @@ -136,10 +136,6 @@ RD_TEST(VK_Secondary_CmdBuf, VulkanGraphicsTest) VkImage swapimg = StartUsingBackbuffer(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL); - vkCmdClearColorImage(cmd, swapimg, VK_IMAGE_LAYOUT_GENERAL, - vkh::ClearColorValue(0.2f, 0.2f, 0.2f, 1.0f), 1, - vkh::ImageSubresourceRange()); - vkCmdBeginRenderPass(cmd, vkh::RenderPassBeginInfo(renderPass, framebuffer, size, {vkh::ClearValue(0.2f, 0.2f, 0.2f, 1.0f)}), diff --git a/util/test/demos/vk/vk_separate_depth_stencil_layouts.cpp b/util/test/demos/vk/vk_separate_depth_stencil_layouts.cpp index dd06cf8ed88..48b12ecad2a 100644 --- a/util/test/demos/vk/vk_separate_depth_stencil_layouts.cpp +++ b/util/test/demos/vk/vk_separate_depth_stencil_layouts.cpp @@ -278,19 +278,28 @@ void main() renderPassCreateInfo.dependencies.push_back(vkh::SubpassDependency2KHR( 0, 1, - VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, - VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, - VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT)); + VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT)); renderPassCreateInfo.dependencies.push_back(vkh::SubpassDependency2KHR( 1, 2, - VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, - VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, - VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT)); + VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT)); renderPassCreateInfo.dependencies.push_back(vkh::SubpassDependency2KHR( 2, 3, - VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, - VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, - VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT)); + VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT)); CHECK_VKR(vkCreateRenderPass2KHR(device, renderPassCreateInfo, NULL, &renderPass)); } @@ -452,14 +461,20 @@ void main() vkh::cmdPipelineBarrier( cmd, { - vkh::ImageMemoryBarrier(0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, - VK_IMAGE_LAYOUT_UNDEFINED, - VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, colorImg.image), vkh::ImageMemoryBarrier( - 0, 0, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL_KHR, + 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, + VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, colorImg.image), + vkh::ImageMemoryBarrier( + 0, + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL_KHR, depthStencilImg.image, vkh::ImageSubresourceRange(VK_IMAGE_ASPECT_STENCIL_BIT)), vkh::ImageMemoryBarrier( - 0, 0, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL_KHR, + 0, + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL_KHR, depthStencilImg.image, vkh::ImageSubresourceRange(VK_IMAGE_ASPECT_DEPTH_BIT)), }); @@ -540,6 +555,7 @@ void main() vkDestroyRenderPass(device, renderPass, NULL); vkDestroyImageView(device, depthStencilView, NULL); + vkDestroyImageView(device, depthOnlyView, NULL); vkDestroyImageView(device, colorView, NULL); vkDestroyFramebuffer(device, frameBuffer, NULL); diff --git a/util/test/demos/vk/vk_shader_debug_zoo.cpp b/util/test/demos/vk/vk_shader_debug_zoo.cpp index a6594885f94..69e0d29bf78 100644 --- a/util/test/demos/vk/vk_shader_debug_zoo.cpp +++ b/util/test/demos/vk/vk_shader_debug_zoo.cpp @@ -3339,7 +3339,7 @@ OpBranch %_bottomlabel %_addr_bda_data_struct = OpLoad %uint2 %_ptr_addr_bda_data_struct %_ptr_bda_data_struct = OpBitcast %ptr_PhysicalStorageBuffer_bda_data_struct_f32_4 %_addr_bda_data_struct %_ptr_f32 = OpPtrAccessChain %ptr_PhysicalStorageBuffer_f32 %_ptr_bda_data_struct %int_dyn_1 -%_out_float = OpLoad %float %_ptr_f32 Aligned 16 +%_out_float = OpLoad %float %_ptr_f32 Aligned 4 )EOTEST", // OpPtrAccessChain : float[] : ArrayStride 8 R"EOTEST( @@ -3347,7 +3347,7 @@ OpBranch %_bottomlabel %_addr_bda_data_struct = OpLoad %uint2 %_ptr_addr_bda_data_struct %_ptr_bda_data_struct = OpBitcast %ptr_PhysicalStorageBuffer_bda_data_struct_f32_8 %_addr_bda_data_struct %_ptr_f32 = OpPtrAccessChain %ptr_PhysicalStorageBuffer_f32 %_ptr_bda_data_struct %int_dyn_1 -%_out_float = OpLoad %float %_ptr_f32 Aligned 16 +%_out_float = OpLoad %float %_ptr_f32 Aligned 4 )EOTEST", // OpPtrAccessChain : float[] : ArrayStride 12 R"EOTEST( @@ -3355,7 +3355,7 @@ OpBranch %_bottomlabel %_addr_bda_data_struct = OpLoad %uint2 %_ptr_addr_bda_data_struct %_ptr_bda_data_struct = OpBitcast %ptr_PhysicalStorageBuffer_bda_data_struct_f32_12 %_addr_bda_data_struct %_ptr_f32 = OpPtrAccessChain %ptr_PhysicalStorageBuffer_f32 %_ptr_bda_data_struct %int_dyn_1 -%_out_float = OpLoad %float %_ptr_f32 Aligned 16 +%_out_float = OpLoad %float %_ptr_f32 Aligned 4 )EOTEST", // Load through a bda ptr array which is a member of a structure pointed to by a uint2 address R"EOTEST( @@ -5021,11 +5021,6 @@ OpMemberDecorate %cbuffer_struct 17 Offset 216 ; double doublePackSource SPIRVTarget target = SPIRVTarget::vulkan; - if(vk_version >= 0x11) - target = SPIRVTarget::vulkan11; - if(vk_version >= 0x12) - target = SPIRVTarget::vulkan12; - pipeCreateInfo.stages = { CompileShaderModule(vertex, ShaderLang::glsl, ShaderStage::vert, "main"), CompileShaderModule(make_pixel_asm(), ShaderLang::spvasm, ShaderStage::frag, "main", {}, diff --git a/util/test/demos/vk/vk_storage_raster.cpp b/util/test/demos/vk/vk_storage_raster.cpp new file mode 100644 index 00000000000..19bace0c216 --- /dev/null +++ b/util/test/demos/vk/vk_storage_raster.cpp @@ -0,0 +1,191 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2023-2026 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * 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 Software. + * + * THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "vk_test.h" + +RD_TEST(VK_Storage_Raster, VulkanGraphicsTest) +{ + static constexpr const char *Description = + "Testing stores to images from a rasterized draw with no rasterized outputs."; + + std::string common = R"EOSHADER( + +#version 450 core + + +struct v2f +{ + vec4 pos; + vec4 col; + vec4 uv; +}; + +)EOSHADER"; + + const std::string vertex = R"EOSHADER( + +layout(location = 0) in vec3 Position; +layout(location = 1) in vec4 Color; +layout(location = 2) in vec2 UV; + +layout(location = 0) out v2f vertOut; + +void main() +{ + vertOut.pos = vec4(Position.xyz*vec3(1,-1,1), 1); + gl_Position = vertOut.pos; + vertOut.col = Color; + vertOut.uv = vec4(UV.xy, 0, 1); +} + +)EOSHADER"; + + const std::string pixel = R"EOSHADER( + +layout(location = 0) in v2f vertIn; + +layout(set = 0, binding = 0, std430) buffer atomicbuftype +{ + uint data[]; +} atomicbuf; + +void main() +{ + atomicMin(atomicbuf.data[0], int(gl_FragCoord.x)); + atomicMin(atomicbuf.data[1], int(gl_FragCoord.y)); + atomicMax(atomicbuf.data[2], int(gl_FragCoord.x)); + atomicMax(atomicbuf.data[3], int(gl_FragCoord.y)); +} + +)EOSHADER"; + + void Prepare(int argc, char **argv) + { + features.fragmentStoresAndAtomics = VK_TRUE; + + VulkanGraphicsTest::Prepare(argc, argv); + + if(!Avail.empty()) + return; + } + + int main() + { + // initialise, create window, create context, etc + if(!Init()) + return 3; + + AllocatedBuffer store_buffer(this, + vkh::BufferCreateInfo(64, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | + VK_BUFFER_USAGE_TRANSFER_DST_BIT), + VmaAllocationCreateInfo({0, VMA_MEMORY_USAGE_GPU_ONLY})); + + VkRenderPass noAttRP; + + vkh::RenderPassCreator renderPassCreateInfo; + renderPassCreateInfo.addSubpass({}); + noAttRP = createRenderPass(renderPassCreateInfo); + + VkExtent2D fbRect = {(uint32_t)screenWidth, (uint32_t)screenHeight}; + + VkFramebuffer noAttFB = createFramebuffer(vkh::FramebufferCreateInfo(noAttRP, {}, fbRect)); + + vkh::GraphicsPipelineCreateInfo pipeCreateInfo; + + VkDescriptorSetLayout setlayout = createDescriptorSetLayout(vkh::DescriptorSetLayoutCreateInfo({ + {0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_FRAGMENT_BIT}, + })); + + VkPipelineLayout layout = createPipelineLayout(vkh::PipelineLayoutCreateInfo({setlayout})); + + pipeCreateInfo.layout = layout; + pipeCreateInfo.renderPass = noAttRP; + + pipeCreateInfo.multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; + + pipeCreateInfo.vertexInputState.vertexBindingDescriptions = {vkh::vertexBind(0, DefaultA2V)}; + pipeCreateInfo.vertexInputState.vertexAttributeDescriptions = { + vkh::vertexAttr(0, 0, DefaultA2V, pos), + vkh::vertexAttr(1, 0, DefaultA2V, col), + vkh::vertexAttr(2, 0, DefaultA2V, uv), + }; + + pipeCreateInfo.stages = { + CompileShaderModule(common + vertex, ShaderLang::glsl, ShaderStage::vert, "main"), + CompileShaderModule(common + pixel, ShaderLang::glsl, ShaderStage::frag, "main"), + }; + + VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); + + VkDescriptorSet descset = allocateDescriptorSet(setlayout); + + vkh::updateDescriptorSets( + device, { + vkh::WriteDescriptorSet(descset, 0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, + {vkh::DescriptorBufferInfo(store_buffer.buffer)}), + }); + + while(Running()) + { + VkCommandBuffer cmd = GetCommandBuffer(); + + vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo()); + + vkCmdFillBuffer(cmd, store_buffer.buffer, 0, 64, 150); + + vkh::cmdPipelineBarrier( + cmd, {}, + {vkh::BufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, + store_buffer.buffer)}); + + VkImage swapimg = StartUsingBackbuffer(cmd); + + vkCmdClearColorImage(cmd, swapimg, VK_IMAGE_LAYOUT_GENERAL, + vkh::ClearColorValue(0.2f, 0.2f, 0.2f, 1.0f), 1, + vkh::ImageSubresourceRange()); + + vkCmdBeginRenderPass(cmd, vkh::RenderPassBeginInfo(noAttRP, noAttFB, mainWindow->scissor), + VK_SUBPASS_CONTENTS_INLINE); + + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); + mainWindow->setViewScissor(cmd); + vkh::cmdBindVertexBuffers(cmd, {DefaultTriVB.buffer}); + vkh::cmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, {descset}, {}); + vkCmdDraw(cmd, 3, 1, 0, 0); + + vkCmdEndRenderPass(cmd); + + FinishUsingBackbuffer(cmd); + + vkEndCommandBuffer(cmd); + + SubmitAndPresent({cmd}); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/demos/vk/vk_stripped_shaders.cpp b/util/test/demos/vk/vk_stripped_shaders.cpp new file mode 100644 index 00000000000..5dda19a2aab --- /dev/null +++ b/util/test/demos/vk/vk_stripped_shaders.cpp @@ -0,0 +1,97 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2023-2026 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * 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 Software. + * + * THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "vk_test.h" + +RD_TEST(VK_Stripped_Shaders, VulkanGraphicsTest) +{ + static constexpr const char *Description = + "Tests shaders with their debug/reflection info stripped out and stored in separate blobs."; + + int main() + { + // initialise, create window, create context, etc + if(!Init()) + return 3; + + vkh::GraphicsPipelineCreateInfo pipeCreateInfo; + + VkPipelineLayout layout = createPipelineLayout(vkh::PipelineLayoutCreateInfo()); + + pipeCreateInfo.layout = layout; + pipeCreateInfo.renderPass = mainWindow->rp; + + pipeCreateInfo.vertexInputState.vertexBindingDescriptions = {vkh::vertexBind(0, DefaultA2V)}; + pipeCreateInfo.vertexInputState.vertexAttributeDescriptions = { + vkh::vertexAttr(0, 0, DefaultA2V, pos), + vkh::vertexAttr(1, 0, DefaultA2V, col), + vkh::vertexAttr(2, 0, DefaultA2V, uv), + }; + + pipeCreateInfo.stages = { + CompileShaderModule(VKDefaultVertex + "\n// shader source // vertex", ShaderLang::glsl, + ShaderStage::vert, "main", {}, SPIRVTarget::vulkan, + CompileOptionFlags::SeparateDebug), + CompileShaderModule(VKDefaultPixel + "\n// shader source // pixel", ShaderLang::glsl, + ShaderStage::frag, "main", {}, SPIRVTarget::vulkan, + CompileOptionFlags::SeparateDebug | CompileOptionFlags::RelativeDebugName), + }; + + VkPipeline pipe = createGraphicsPipeline(pipeCreateInfo); + + while(Running()) + { + VkCommandBuffer cmd = GetCommandBuffer(); + + vkBeginCommandBuffer(cmd, vkh::CommandBufferBeginInfo()); + + VkImage swapimg = StartUsingBackbuffer(cmd); + + vkh::cmdClearImage(cmd, swapimg, vkh::ClearColorValue(0.2f, 0.2f, 0.2f, 1.0f)); + + vkCmdBeginRenderPass(cmd, mainWindow->beginRP(), VK_SUBPASS_CONTENTS_INLINE); + + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); + mainWindow->setViewScissor(cmd); + vkh::cmdBindVertexBuffers(cmd, {DefaultTriVB.buffer}); + + setMarker(cmd, "test: shader source"); + setMarker(cmd, "vertex manual absolute"); + setMarker(cmd, "pixel manual relative"); + vkCmdDraw(cmd, 3, 1, 0, 0); + + vkCmdEndRenderPass(cmd); + + FinishUsingBackbuffer(cmd); + + vkEndCommandBuffer(cmd); + + SubmitAndPresent({cmd}); + } + + return 0; + } +}; + +REGISTER_TEST(); diff --git a/util/test/demos/vk/vk_sync2.cpp b/util/test/demos/vk/vk_sync2.cpp index dc70f604998..31a4e68c22b 100644 --- a/util/test/demos/vk/vk_sync2.cpp +++ b/util/test/demos/vk/vk_sync2.cpp @@ -246,6 +246,8 @@ RD_TEST(VK_Synchronization_2, VulkanGraphicsTest) vkCmdResetEvent2KHR(cmd, ev, VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT_KHR); + vkh::cmdPipelineBarrier(cmd, {}, {}, {vkh::MemoryBarrier(0, 0)}); + vkCmdClearColorImage(cmd, swapimg, VK_IMAGE_LAYOUT_GENERAL, vkh::ClearColorValue(0.2f, 0.2f, 0.2f, 1.0f), 1, vkh::ImageSubresourceRange()); @@ -293,6 +295,7 @@ RD_TEST(VK_Synchronization_2, VulkanGraphicsTest) undefImg.free(); } + vkDestroyImage(device, unboundImg, NULL); vkDestroyQueryPool(device, pool, NULL); vkDestroyEvent(device, ev, NULL); diff --git a/util/test/demos/vk/vk_test.cpp b/util/test/demos/vk/vk_test.cpp index d758baedfe2..3500fc19e18 100644 --- a/util/test/demos/vk/vk_test.cpp +++ b/util/test/demos/vk/vk_test.cpp @@ -120,11 +120,30 @@ static VkBool32 VKAPI_PTR vulkanCallback(VkDebugUtilsMessageSeverityFlagBitsEXT const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData) { + VulkanGraphicsTest *test = (VulkanGraphicsTest *)pUserData; + + // semaphore nonsense if(strstr(pCallbackData->pMessageIdName, "-01779")) return false; + // GPU-VA enabling features + if(strstr(pCallbackData->pMessageIdName, "WARNING-Setting-Limit-Adjusted")) + return false; + + if(test) + { + for(std::string &msg : test->mutedMessages) + { + if(strstr(pCallbackData->pMessageIdName, msg.c_str())) + return false; + } + } + TEST_WARN("Vulkan message: [%s] %s", pCallbackData->pMessageIdName, pCallbackData->pMessage); + if(test && test->breakOnDebug) + UNCONDITIONAL_DEBUG_BREAK(); + return false; } @@ -147,6 +166,8 @@ void VulkanGraphicsTest::Prepare(int argc, char **argv) { GraphicsTest::Prepare(argc, argv); + SetEnv("DISABLE_VULKAN_OBS_CAPTURE", "1"); + static bool prepared = false; std::vector availInstLayers; @@ -318,6 +339,7 @@ void VulkanGraphicsTest::Prepare(int argc, char **argv) { featuresEXT.pNext = instInfoNext; instInfoNext = &featuresEXT; + break; } } } @@ -688,7 +710,7 @@ bool VulkanGraphicsTest::Init() { CHECK_VKR(vkCreateDebugUtilsMessengerEXT( instance, - vkh::DebugUtilsMessengerCreateInfoEXT(&vulkanCallback, NULL, + vkh::DebugUtilsMessengerCreateInfoEXT(&vulkanCallback, this, VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT), NULL, &debugUtilsMessenger)); @@ -1009,18 +1031,63 @@ VkPipelineShaderStageCreateInfo VulkanGraphicsTest::LoadShaderModule(const std:: VkPipelineShaderStageCreateInfo VulkanGraphicsTest::CompileShaderModule( const std::string &source_text, ShaderLang lang, ShaderStage stage, const char *entry_point, - const std::map ¯os, SPIRVTarget target) + const std::map ¯os, SPIRVTarget target, uint32_t compileOptions) { VkShaderModule ret = VK_NULL_HANDLE; + const bool separateDebug = ((compileOptions & CompileOptionFlags::SeparateDebug) != 0); + const bool relativeDebugName = ((compileOptions & CompileOptionFlags::RelativeDebugName) != 0); + std::vector spirv = ::CompileShaderToSpv(demoName, source_text, target, lang, stage, entry_point, macros); if(spirv.empty()) return {}; + std::string path; + if(separateDebug) + { + path = tmpPath + "/"; + + std::string filenames[] = { + "shader_vs.dbg", "shader_hs.dbg", "shader_ds.dbg", "shader_gs.dbg", + "shader_ps.dbg", "shader_cs.dbg", "shader_ms.dbg", "shader_as.dbg", + }; + + path += filenames[(int)stage]; + + FILE *f = fopen(path.c_str(), "wb"); + if(f) + { + fwrite(spirv.data(), 1, spirv.size() * sizeof(uint32_t), f); + fclose(f); + } + + spirv = + ::CompileShaderToSpv(demoName, source_text, target, lang, stage, entry_point, macros, false); + } + CHECK_VKR(vkCreateShaderModule(device, vkh::ShaderModuleCreateInfo(spirv), NULL, &ret)); + if(relativeDebugName) + { + path.erase(0, path.find_last_of("/\\") + 1); + // keep the demo name so we don't have to set up tons of search paths + path = std::string(demoName) + "/" + path; + } + + if(vkSetDebugUtilsObjectTagEXT && !path.empty()) + { + VkDebugUtilsObjectTagInfoEXT info = {}; + info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_TAG_INFO_EXT; + info.objectType = VK_OBJECT_TYPE_SHADER_MODULE; + info.objectHandle = (uint64_t)ret; + info.pTag = path.c_str(); + info.tagSize = path.size(); + info.tagName = RENDERDOC_ShaderDebugMagicValue_truncated; + vkSetDebugUtilsObjectTagEXT(device, &info); + } + shaders.push_back(ret); VkShaderStageFlagBits vkstage[] = { @@ -1102,6 +1169,12 @@ void VulkanGraphicsTest::setName(VkSemaphore obj, const std::string &name) setName(VK_OBJECT_TYPE_SEMAPHORE, (uint64_t)obj, name); } +template <> +void VulkanGraphicsTest::setName(VkEvent obj, const std::string &name) +{ + setName(VK_OBJECT_TYPE_EVENT, (uint64_t)obj, name); +} + template <> void VulkanGraphicsTest::setName(VkFence obj, const std::string &name) { @@ -1704,16 +1777,6 @@ bool VulkanWindow::CreateSwapchain() renderPassCreateInfo.addSubpass({VkAttachmentReference({0, VK_IMAGE_LAYOUT_GENERAL})}); - // add deps to allow clear/copy on the main target before or after - renderPassCreateInfo.dependencies.push_back(vkh::SubpassDependency( - ~0U, 0, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT, - VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT)); - renderPassCreateInfo.dependencies.push_back(vkh::SubpassDependency( - 0, ~0U, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, - VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT)); - rp = m_Test->createRenderPass(renderPassCreateInfo); } @@ -1828,12 +1891,15 @@ void VulkanWindow::MultiPresent(VkQueue queue, std::vector windo } } -void VulkanWindow::Present(VkQueue queue) +void VulkanWindow::Present(VkQueue queue, bool queueWaitIdle) { if(swap == VK_NULL_HANDLE) return; - vkDeviceWaitIdle(m_Test->device); + if(queueWaitIdle) + vkQueueWaitIdle(queue); + else + vkDeviceWaitIdle(m_Test->device); VkResult vkr = vkQueuePresentKHR(queue, vkh::PresentInfoKHR(swap, imgIndex, &renderEndSemaphore[semIdx])); diff --git a/util/test/demos/vk/vk_test.h b/util/test/demos/vk/vk_test.h index fe3e6135b37..1821845313f 100644 --- a/util/test/demos/vk/vk_test.h +++ b/util/test/demos/vk/vk_test.h @@ -164,7 +164,7 @@ struct VulkanWindow : public GraphicsWindow, public VulkanCommands void Submit(int index, int totalSubmits, const std::vector &cmds, const std::vector &seccmds, VkQueue q); static void MultiPresent(VkQueue queue, std::vector windows); - void Present(VkQueue q); + void Present(VkQueue q, bool queueWaitIdle = false); // forward GraphicsWindow functions to internal window void Resize(int width, int height) { m_Win->Resize(width, height); } @@ -194,6 +194,13 @@ struct VulkanGraphicsTest : public GraphicsTest { static const TestAPI API = TestAPI::Vulkan; + enum CompileOptionFlags + { + None = 0, + SeparateDebug = 1 << 0, + RelativeDebugName = 1 << 1, + }; + VulkanGraphicsTest(); void Prepare(int argc, char **argv); @@ -222,7 +229,7 @@ struct VulkanGraphicsTest : public GraphicsTest VkPipelineShaderStageCreateInfo CompileShaderModule( const std::string &source_text, ShaderLang lang, ShaderStage stage, const char *entry_point = "main", const std::map ¯os = {}, - SPIRVTarget target = SPIRVTarget::vulkan); + SPIRVTarget target = SPIRVTarget::vulkan, uint32_t compileOptions = CompileOptionFlags::None); VkCommandBuffer GetCommandBuffer(VkCommandBufferLevel level = VK_COMMAND_BUFFER_LEVEL_PRIMARY, VulkanWindow *window = NULL); @@ -336,6 +343,8 @@ struct VulkanGraphicsTest : public GraphicsTest bool vmaBDA = false; VmaAllocator allocator = VK_NULL_HANDLE; + std::vector mutedMessages; + private: static bool prepared_vk; diff --git a/util/test/demos/vk/vk_texture_zoo.cpp b/util/test/demos/vk/vk_texture_zoo.cpp index 00b2bf57725..fffa0056c0a 100644 --- a/util/test/demos/vk/vk_texture_zoo.cpp +++ b/util/test/demos/vk/vk_texture_zoo.cpp @@ -554,10 +554,9 @@ void main() if(f.cfg.type == TextureType::A8) props1D = {}; - // rendering to depth 3D textures is broken on NV, fixed in a future driver version (guess - // made, will be updated once fix ships) - if(depth && physProperties.vendorID == PCI_VENDOR_NV && - physProperties.driverVersion < VK_MAKE_VERSION_NV(445, 0, 0, 0)) + // unclear if rendering to slices of depth textures is supported and most other APIs don't + // support this at all, just disable it as unlikely anyone ever uses it + if(depth) props3D = {}; if(!renderable && !depth) diff --git a/util/test/demos/vk/vk_video_textures.cpp b/util/test/demos/vk/vk_video_textures.cpp index 01b586b36dc..2800e1a909c 100644 --- a/util/test/demos/vk/vk_video_textures.cpp +++ b/util/test/demos/vk/vk_video_textures.cpp @@ -229,6 +229,18 @@ void main() devExts.push_back(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME); VulkanGraphicsTest::Prepare(argc, argv); + + static VkPhysicalDeviceSamplerYcbcrConversionFeatures ycbcrFeats = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES, + }; + + getPhysFeatures2(&ycbcrFeats); + + if(!ycbcrFeats.samplerYcbcrConversion) + Avail = "feature 'samplerYcbcrConversion' not available"; + + ycbcrFeats.pNext = (void *)devInfoNext; + devInfoNext = &ycbcrFeats; } int main() @@ -565,9 +577,11 @@ void main() // vulkan doesn't have 4:4:4 packed formats, makes sense as it can use normal formats // MAKE_TEX(AYUV, VK_FORMAT_R8G8B8A8_UNORM, Vec4i(2, 1, 0, 1), yuv8, rgba8.width * 4); // MAKE_TEX(Y416, VK_FORMAT_R16G16B16A16_UNORM, Vec4i(1, 0, 2, 1), yuv16, rgba8.width * 8); + /* MAKE_TEX(444, VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR, VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR, Vec4i(1, 2, 0, 1), yuv16, rgba8.width * 8); + */ /////////////////////////////////////// // 4:4:4 3-plane @@ -866,7 +880,12 @@ void main() VkSamplerYcbcrConversionInfo ycbcrChain = {VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO}; ycbcrChain.conversion = ycbcr[i].conv; - ycbcr[i].sampler = createSampler(vkh::SamplerCreateInfo(VK_FILTER_LINEAR).next(&ycbcrChain)); + ycbcr[i].sampler = createSampler( + vkh::SamplerCreateInfo(VK_FILTER_LINEAR, VK_FILTER_LINEAR, VK_SAMPLER_MIPMAP_MODE_LINEAR, + VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, + VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, + VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE) + .next(&ycbcrChain)); setlayout = createDescriptorSetLayout(vkh::DescriptorSetLayoutCreateInfo({ {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, diff --git a/util/test/demos/vk/vk_vs_max_desc_set.cpp b/util/test/demos/vk/vk_vs_max_desc_set.cpp index c03a3e15987..b07534c3b94 100644 --- a/util/test/demos/vk/vk_vs_max_desc_set.cpp +++ b/util/test/demos/vk/vk_vs_max_desc_set.cpp @@ -77,6 +77,9 @@ void main() int main() { + // GPUVA needs a spare desc set but this test is deliberately not allowing that + mutedMessages.push_back("WARNING-GPU-Assisted-Validation"); + // initialise, create window, create context, etc if(!Init()) return 3; diff --git a/util/test/demos/win32/win32_platform.h b/util/test/demos/win32/win32_platform.h index fd6282f79b8..08025b80897 100644 --- a/util/test/demos/win32/win32_platform.h +++ b/util/test/demos/win32/win32_platform.h @@ -44,6 +44,8 @@ uint32_t GetPID(); __debugbreak(); \ } while(0) +#define UNCONDITIONAL_DEBUG_BREAK() __debugbreak() + #define popen _popen #define pclose _pclose @@ -53,4 +55,6 @@ uint32_t GetPID(); #define WEXITSTATUS(code) code +#define SetEnv(name, value) SetEnvironmentVariableA(name, value) + #define EXECUTABLE_SUFFIX ".exe" diff --git a/util/test/rdtest/__init__.py b/util/test/rdtest/__init__.py index ef1d26134f7..701e42c59fd 100644 --- a/util/test/rdtest/__init__.py +++ b/util/test/rdtest/__init__.py @@ -14,3 +14,4 @@ from .shared.Workgroup_Zoo import * from .shared.Groupshared import * from .shared.Annotations import * +from .shared.Stripped_Shaders import * diff --git a/util/test/rdtest/analyse.py b/util/test/rdtest/analyse.py index c56f7687979..9b06cf2f518 100644 --- a/util/test/rdtest/analyse.py +++ b/util/test/rdtest/analyse.py @@ -6,7 +6,7 @@ def open_capture( - filename="", cap: rd.CaptureFile | None = None, opts: rd.ReplayOptions | None = None + filename="", opts: rd.ReplayOptions | None = None ): """ Opens a capture file and begins a replay. @@ -21,32 +21,28 @@ def open_capture( if opts is None: opts = rd.ReplayOptions() - # Open a capture file handle - own_cap = False + cap = None api = "Unknown" result = None controller = None if util.get_remote_server() is None: - if cap is None: - own_cap = True + cap = rd.OpenCaptureFile() - cap = rd.OpenCaptureFile() + # Open a particular file + result = cap.OpenFile(filename, '', None) - # Open a particular file - result = cap.OpenFile(filename, '', None) + # Make sure the file opened successfully + if not result: + cap.Shutdown() + raise RuntimeError(f"Couldn't open '{filename}': {result!s}") - # Make sure the file opened successfully - if not result: - cap.Shutdown() - raise RuntimeError(f"Couldn't open '{filename}': {result!s}") + api = cap.DriverName() - api = cap.DriverName() - - # Make sure we can replay - if not cap.LocalReplaySupport(): - cap.Shutdown() - raise RuntimeError(f"{api} capture cannot be replayed") + # Make sure we can replay + if not cap.LocalReplaySupport(): + cap.Shutdown() + raise RuntimeError(f"{api} capture cannot be replayed") result, controller = cap.OpenCapture(opts, None) else: @@ -58,13 +54,10 @@ def open_capture( if result: api = util.get_remote_server().remote.DriverName() - if own_cap: - cap.Shutdown() - if not result: raise RuntimeError(f"Couldn't initialise replay for {api}: {result!s}") - return controller + return cap, controller def fetch_indices(controller: rd.ReplayController, action: rd.ActionDescription, mesh: rd.MeshFormat, index_offset: int, first_index: int, num_indices: int) -> List[int | None]: diff --git a/util/test/rdtest/shared/Stripped_Shaders.py b/util/test/rdtest/shared/Stripped_Shaders.py new file mode 100644 index 00000000000..9c5b5e02cf1 --- /dev/null +++ b/util/test/rdtest/shared/Stripped_Shaders.py @@ -0,0 +1,140 @@ +import rdtest +import shutil +import renderdoc as rd +import re + + +# Not a real test, re-used by API-specific tests +class Stripped_Shaders(rdtest.TestCase): + internal = True + demos_test_name = None + + def get_capture_options(self): + # We don't actually need to set any capture-time options but we'll use this to change the search dir paths + paths = rd.SetConfigSetting("DXBC.Debug.SearchDirPaths") + + paths.DeleteChildren() + paths.AddChild(rd.makeSDString("path", rdtest.get_tmp_dir())) + + # this won't automatically save and we won't call SaveConfigSettings() + + return rd.CaptureOptions() + + def check_capture(self): + self.check_debug_symbols(False) + + filename = self.retrieve_capture() + embed_path = rdtest.get_tmp_path("embedded.rdc") + + shutil.copy(filename, embed_path) + + # shut down the controller that is for the old file, to keep it the same + self.controller.Shutdown() + self.controller = None + if self.cap is not None: + self.cap.Shutdown() + self.cap = None + + # open the version we're going to embed into + self.cap, self.controller = rdtest.open_capture(embed_path) + + assert self.cap is not None + assert len(self.cap.GetPendingDependenciesNicknames()) > 0 + + # embed the dependencies + assert self.cap.EmbedDependenciesIntoCapture().OK() + + self.controller.Shutdown() + self.cap.Shutdown() + + # now clear the search paths, this should make at least one fail + rd.SetConfigSetting("DXBC.Debug.SearchDirPaths").DeleteChildren() + + self.cap, self.controller = rdtest.open_capture(embed_path) + self.sdfile = self.controller.GetStructuredFile() + + # check everything is still OK + self.check_debug_symbols(True) + + def check_debug_symbols(self, embedded: bool): + test = self.find_action("test:", 0) + + while test is not None: + pix_cfg = self.get_action(test.eventId + 2) + assert pix_cfg is not None + draw = self.get_action(test.eventId + 3) + assert draw is not None + + search_text = test.customName.replace("test: ", "") + assert "pixel" in pix_cfg.customName + + self.set_event(draw.eventId, False) + + pipe = self.controller.GetPipelineState() + + stages = [ + (1, rd.ShaderStage.Vertex, "vertex", "shader_vs.dbg"), + (2, rd.ShaderStage.Pixel, "pixel", "shader_ps.dbg"), + ] + + for offs, stage, name, manual_filename in stages: + cfg = self.get_action(test.eventId + offs) + assert cfg is not None + + assert name in cfg.customName + + refl = pipe.GetShaderReflection(stage) + + assert len(refl.debugInfo.files) == 1 + + src = refl.debugInfo.files[0].contents + + assert f"// {search_text} // {name}" in src + + log = refl.debugInfo.debugInfoLoadingLog + + assert re.match("Found ", log, re.IGNORECASE) + + if "auto" in cfg.customName: + assert re.search("[a-f0-9]{32}.pdb", log) is not None + elif "manual" in cfg.customName: + assert f"{manual_filename}'" in log + else: + raise rdtest.TestFailureException( + f"Unexpected {name} config {cfg.customName}" + ) + + filepath = re.search("Shader filepath '([^']*)'", log) + assert filepath is not None + + filepath = filepath[1].replace("\\", "/") + tmp_dir = rdtest.get_tmp_dir().replace("\\", "/") + + if "absolute" in cfg.customName: + assert tmp_dir in filepath + assert "File found using filepath" in log + assert "File found in search directory" not in log + assert "File found in recursive directory search" not in log + assert "embedded in the capture using nickname" not in log + elif "relative" in cfg.customName: + assert tmp_dir not in filepath + assert "File found using filepath" not in log + if embedded: + assert "embedded in the capture using nickname" in log + assert "File found in search directory" not in log + assert "File found in recursive directory search" not in log + else: + assert ( + "File found in search directory" in log + or "File found in recursive directory search" in log + ) + else: + raise rdtest.TestFailureException( + f"Unexpected {name} config {cfg.customName}" + ) + + rdtest.log.success(f"{name} shader debug info and loading log looks OK") + + test = self.find_action("test:", draw.eventId) + + rdtest.log.success("All draws had proper shader debug info") diff --git a/util/test/rdtest/testcase.py b/util/test/rdtest/testcase.py index c614174ceb2..92206ef07cf 100644 --- a/util/test/rdtest/testcase.py +++ b/util/test/rdtest/testcase.py @@ -263,6 +263,7 @@ def __init__(self): self.capture_filename = "" self.worker_thread = 0 self.controller: rd.ReplayController | None = None + self.cap: rd.CaptureFile | None = None self.sdfile: rd.SDFile | None = None self.contexts: List[ScopedContext] = [] self.cur_event = 0 @@ -319,7 +320,7 @@ def get_capture(self): if timeout is None: timeout = util.get_demos_timeout() return capture.run_and_capture(exe, - self.demos_test_name + " --log " + remote_logfile, + f"{self.demos_test_name} --log {remote_logfile} --tmp {util.get_tmp_dir()}", self.demos_frame_cap, frame_count=self.demos_frame_count, captures_expected=self.demos_captures_expected, logfile=logfile, opts=self.get_capture_options(), timeout=timeout) @@ -761,7 +762,7 @@ def run(self): log.print("Loading capture") - self.controller = analyse.open_capture(self.capture_filename, opts=self.get_replay_options()) + self.cap, self.controller = analyse.open_capture(self.capture_filename, opts=self.get_replay_options()) self.sdfile = self.controller.GetStructuredFile() if not self.validate_eventids(self.controller): @@ -782,6 +783,9 @@ def finish(self): else: self.controller.Shutdown() + if self.cap is not None: + self.cap.Shutdown() + def invoketest(self, debugMode: bool): start_time = self.get_time() self.run() diff --git a/util/test/tests/D3D11/D3D11_Stripped_Shaders.py b/util/test/tests/D3D11/D3D11_Stripped_Shaders.py new file mode 100644 index 00000000000..513e29607b6 --- /dev/null +++ b/util/test/tests/D3D11/D3D11_Stripped_Shaders.py @@ -0,0 +1,6 @@ +import rdtest + + +class D3D11_Stripped_Shaders(rdtest.Stripped_Shaders): + demos_test_name = 'D3D11_Stripped_Shaders' + internal = False \ No newline at end of file diff --git a/util/test/tests/D3D12/D3D12_Stripped_Shaders.py b/util/test/tests/D3D12/D3D12_Stripped_Shaders.py new file mode 100644 index 00000000000..3577c825951 --- /dev/null +++ b/util/test/tests/D3D12/D3D12_Stripped_Shaders.py @@ -0,0 +1,6 @@ +import rdtest + + +class D3D12_Stripped_Shaders(rdtest.Stripped_Shaders): + demos_test_name = 'D3D12_Stripped_Shaders' + internal = False \ No newline at end of file diff --git a/util/test/tests/GL/GL_Buffer_Updates.py b/util/test/tests/GL/GL_Buffer_Updates.py index 27297fb0202..4a44e94f576 100644 --- a/util/test/tests/GL/GL_Buffer_Updates.py +++ b/util/test/tests/GL/GL_Buffer_Updates.py @@ -30,19 +30,12 @@ def check_capture(self): rdtest.log.success("Draws are all green") - # Open the capture and grab the thumbnail, check that it is all green too (dirty way of verifying we didn't + # grab the thumbnail, check that it is all green too (dirty way of verifying we didn't # break in-app updates but somehow end up with the right data) - cap = rd.OpenCaptureFile() + if self.cap is None: + raise rdtest.TestFailureException(f"Don't have open capture {self.capture_filename}") - # Open a particular file - result = cap.OpenFile(self.capture_filename, '', None) - - # Make sure the file opened successfully - if not result: - cap.Shutdown() - raise rdtest.TestFailureException(f"Couldn't open '{self.capture_filename}': {result!s}") - - thumb = cap.GetThumbnail(rd.FileType.PNG, 0) + thumb = self.cap.GetThumbnail(rd.FileType.PNG, 0) tmp_path = rdtest.get_tmp_path('thumbnail.png') diff --git a/util/test/tests/GL/GL_Callstacks.py b/util/test/tests/GL/GL_Callstacks.py index d97722947de..1085e9b268c 100644 --- a/util/test/tests/GL/GL_Callstacks.py +++ b/util/test/tests/GL/GL_Callstacks.py @@ -21,21 +21,13 @@ def get_capture_options(self): return ret def check_capture(self): - # Need capture access. Rather than trying to keep the original around, we just open a new one - cap = rd.OpenCaptureFile() + if self.cap is None: + raise rdtest.TestFailureException(f"Don't have open capture {self.capture_filename}") - # Open a particular file - result = cap.OpenFile(self.capture_filename, '', None) - - # Make sure the file opened successfully - if not result: - cap.Shutdown() - raise rdtest.TestFailureException(f"Couldn't open capture {self.capture_filename} for access: {result!s}") - - if not cap.HasCallstacks(): + if not self.cap.HasCallstacks(): raise rdtest.TestFailureException("Capture does not report having callstacks") - if not cap.InitResolver(False, resolve_progress): + if not self.cap.InitResolver(False, resolve_progress): raise rdtest.TestFailureException("Failed to initialise callstack resolver") action = self.find_action("Draw") @@ -59,7 +51,7 @@ def check_capture(self): chunk = sdfile.chunks[event.chunkIndex] - callstack = cap.GetResolve(list(chunk.metadata.callstack)) + callstack = self.cap.GetResolve(list(chunk.metadata.callstack)) if len(callstack) < len(expected_funcs): raise rdtest.TestFailureException(f"Resolved callstack isn't long enough ({len(callstack)} stack frames), expected at least {len(expected_funcs)}") diff --git a/util/test/tests/Iter_Test.py b/util/test/tests/Iter_Test.py index 1e855e47e38..95fe98a64d0 100644 --- a/util/test/tests/Iter_Test.py +++ b/util/test/tests/Iter_Test.py @@ -436,7 +436,7 @@ def run(self): rdtest.log.print(f"Opening '{file.name}'.") try: - self.controller = rdtest.open_capture(file.path) + self.cap, self.controller = rdtest.open_capture(file.path) except RuntimeError as err: rdtest.log.print(f"Skipping. Can't open {file.path}: {err}") continue @@ -450,6 +450,8 @@ def run(self): rdtest.log.end_section(section_name) self.controller.Shutdown() + if self.cap is not None: + self.cap.Shutdown() rdtest.log.success("Iterated all files") diff --git a/util/test/tests/Repeat_Load.py b/util/test/tests/Repeat_Load.py index e61ab3879b7..5fc7faedafe 100644 --- a/util/test/tests/Repeat_Load.py +++ b/util/test/tests/Repeat_Load.py @@ -13,7 +13,7 @@ def repeat_load(self, path: str): rdtest.log.print(f"Loading for iteration {i + 1}") try: - controller = rdtest.open_capture(path) + cap, controller = rdtest.open_capture(path) except RuntimeError as err: rdtest.log.print(f"Skipping. Can't open {path}: {err}") return @@ -31,6 +31,8 @@ def repeat_load(self, path: str): memory_baseline = memory_usage controller.Shutdown() + if cap is not None: + cap.Shutdown() pct_over = 'N/A' diff --git a/util/test/tests/Vulkan/VK_Device_Address_Commands.py b/util/test/tests/Vulkan/VK_Device_Address_Commands.py index 5ee35a179ea..79497660e0b 100644 --- a/util/test/tests/Vulkan/VK_Device_Address_Commands.py +++ b/util/test/tests/Vulkan/VK_Device_Address_Commands.py @@ -91,7 +91,7 @@ def check_capture(self): buffer = self.get_resource_by_name("Address Buffer").resourceId - if int.from_bytes(self.controller.GetBufferData(buffer, 9404, 4)) == 0: + if int.from_bytes(self.controller.GetBufferData(buffer, 9404, 4), byteorder='big') == 0: raise rdtest.TestFailureException("ImageToMemory copy failed") else: rdtest.log.success('ImageToMemory copy succeeded') diff --git a/util/test/tests/Vulkan/VK_Large_Descriptor_Sets.py b/util/test/tests/Vulkan/VK_Large_Descriptor_Sets.py index 4fcc92a2288..4bb4db4c4a2 100644 --- a/util/test/tests/Vulkan/VK_Large_Descriptor_Sets.py +++ b/util/test/tests/Vulkan/VK_Large_Descriptor_Sets.py @@ -15,7 +15,7 @@ def run(self): memory_before = rd.GetCurrentProcessMemoryUsage() start_time = self.get_time() - self.controller = rdtest.open_capture(self.capture_filename, opts=self.get_replay_options()) + self.cap, self.controller = rdtest.open_capture(self.capture_filename, opts=self.get_replay_options()) duration = self.get_time() - start_time memory_after = rd.GetCurrentProcessMemoryUsage() @@ -37,3 +37,5 @@ def run(self): rdtest.log.print("Not checking time to load in non-release build") self.controller.Shutdown() + if self.cap is not None: + self.cap.Shutdown() diff --git a/util/test/tests/Vulkan/VK_Resource_Usage.py b/util/test/tests/Vulkan/VK_Resource_Usage.py index 9f4144c1b49..f1ca704d5cd 100644 --- a/util/test/tests/Vulkan/VK_Resource_Usage.py +++ b/util/test/tests/Vulkan/VK_Resource_Usage.py @@ -7,6 +7,8 @@ class VK_Resource_Usage(rdtest.TestCase): demos_test_name = 'VK_Resource_Usage' resourceUsages: Dict[rd.ResourceId, List[rd.EventUsage]] = {} eids: List[int] = [] + markerStart = 0 + markerEnd = 0 def add_action(self, action: rd.ActionDescription): self.eids.append(action.eventId) @@ -17,14 +19,21 @@ def add_action(self, action: rd.ActionDescription): def check_resource_usage(self, res: rd.ResourceDescription, expectedUsages: List[Tuple[int,rd.ResourceUsage]]): usages = self.resourceUsages[res.resourceId] - if len(usages) != len(expectedUsages): - for u in usages: - rdtest.log.print(f"Resource '{res.name}' {res.resourceId} usage EID:{u.eventId} usage:{u.usage.name}") + if len(usages) == 1 and usages[0].eventId == 0 and usages[0].usage == rd.ResourceUsage.Unused: + resUsages = usages + else: + resUsages = [u for u in usages if u.eventId >= self.markerStart and u.eventId <= self.markerEnd] + rdtest.log.print(f"Resource '{res.name}' type:{res.type.name} {res.resourceId} usages:{len(resUsages)} expectedUsages:{len(expectedUsages)}") + if len(resUsages) != len(expectedUsages): + rdtest.log.print(f"Usages for Resource '{res.name}' {res.resourceId}") + for u in resUsages: + rdtest.log.print(f"EID:{u.eventId} usage:{u.usage.name}") + rdtest.log.print(f"Expected Usages for Resource '{res.name}' {res.resourceId}") for u in expectedUsages: eid, usage = u - rdtest.log.print(f"Resource '{res.name}' {res.resourceId} usage EID:{eid} usage:{usage.name}") - raise rdtest.TestFailureException(f"'{res.name}' {res.resourceId} Incorrect resource usages count expected:{len(expectedUsages)} actual:{len(usages)}") - for i, u in enumerate(usages): + rdtest.log.print(f"EID:{eid} usage:{usage.name}") + raise rdtest.TestFailureException(f"'{res.name}' {res.resourceId} Incorrect resource usages count expected:{len(expectedUsages)} actual:{len(resUsages)}") + for i, u in enumerate(resUsages): eid, usage = expectedUsages[i] if u.usage != usage: raise rdtest.TestFailureException(f"'{res.name}' {res.resourceId} EID:{u.eventId} Incorrect resource usage expected:{usage.name} actual:{u.usage.name}") @@ -50,13 +59,6 @@ def check_capture(self): meshShader = self.find_action("Mesh Shader") is not None rdtest.log.print(f"Has Mesh Shader: {'Yes' if meshShader else 'No'}") - countDrawIndirectCount = 30 if drawIndirectCount else 0 - countNested = 39 if nestedSecondaries else 0 - countDescBufferCopy = 10 if descBuffer else 0 - countDescBuffer = 21 if descBuffer else 0 - countDescBuffer += countDescBufferCopy - countMeshShader = 33 if meshShader else 0 - # Walk the actions finding all the Dispatch, Draw, DrawIndexed, DrawIndirect, DrawIndirectCount sdfile = self.controller.GetStructuredFile() actions = self.controller.GetRootActions().copy() @@ -74,23 +76,53 @@ def check_capture(self): resetFencesEIDs: List[int] = [] descSetDrawEIDs: List[int] = [] descBufferDrawEIDs: List[int] = [] + cmdDrawIndirectEIDs: List[int] = [] + cmdMeshDispatchIndirectEIDs: List[int] = [] + endRenderPassEIDs : List[int] = [] + fillBufferEIDs: List[int] = [] + copyBufferEIDs: List[int] = [] + markerGraphics = 0 + markerGraphicsNoDescriptorSet = 0 markerGraphicsDescriptorSet = 0 markerGraphicsSecondaryCommandBuffer = 0 markerIndirect = 0 + markerIndirectWriteIndirectDispatchData = 0 + markerIndirectDispatchWriteIndirectDrawData = 0 + markerIndirectIndirectDraws = 0 + markerIndirectSecondaryCommandBuffer = 0 + markerIndirectSecondaryCommandBufferDispatchIndirect = 0 markerIndirectEnd = 0 markerNestedSecondaryCommandBuffer = 0 + markerNestedSecondaryCommandBufferDispatch = 0 markerDescriptorBuffer = 0 markerBarrierCommandSubmitFence = 0 markerCompute = 0 markerComputeDescriptorSet = 0 + markerComputeSecondaryCommandBuffer = 0 + markerLooseEventsAfterIndirectDrawsDrawIndirectSingle = 0 + markerMultipleCommandBufferSubmits = 0 + markerMultipleSecondaryCommandBufferExecutes = 0 + self.markerStart = self.find_action("Resource Usage: Start").eventId + self.markerEnd = self.find_action("Resource Usage: End").eventId + markerIndirectWriteIndirectDispatchData = self.find_action("Indirect Write IndirectDispatch Data").eventId + markerGraphics = self.find_action("Graphics").eventId + markerGraphicsNoDescriptorSet = self.find_action("No Descriptor Set", markerGraphics).eventId + markerGraphicsDescriptorSet = self.find_action("Descriptor Set", markerGraphicsNoDescriptorSet+1).eventId markerGraphicsSecondaryCommandBuffer = self.find_action("Secondary Command Buffer").eventId if nestedSecondaries: markerNestedSecondaryCommandBuffer = self.find_action("Nested Secondary Command Buffer").eventId + markerNestedSecondaryCommandBufferDispatch = self.find_action("Dispatch", markerNestedSecondaryCommandBuffer).eventId if descBuffer: markerDescriptorBuffer = self.find_action("Descriptor Buffer").eventId markerBarrierCommandSubmitFence = self.find_action("Barrier Command Submit Fence").eventId + markerCompute = self.find_action("Compute").eventId + markerComputeSecondaryCommandBuffer = self.find_action("Secondary Command Buffer", markerCompute).eventId + markerLooseEventsAfterIndirectDraws = self.find_action("Loose Events After Indirect Draws").eventId + markerLooseEventsAfterIndirectDrawsDrawIndirectSingle = self.find_action("DrawIndirect: Single", markerLooseEventsAfterIndirectDraws).eventId + markerMultipleCommandBufferSubmits = self.find_action("Multiple Command Buffer Submits").eventId + markerMultipleSecondaryCommandBufferExecutes = self.find_action("Multiple Secondary Command Buffer Executes").eventId while len(actions) > 0: action = actions.pop(0) @@ -115,19 +147,23 @@ def check_capture(self): meshDispatchEIDs.append(action.eventId) if flags & rd.ActionFlags.MultiAction: multiEIDs.append(action.eventId) + if "Count" in action.customName: + if not action.eventId in indirectCountEIDs: + indirectCountEIDs.append(action.eventId) if flags & rd.ActionFlags.PushMarker: parentName = action.parent.customName if action.parent is not None else None markerPath = parentName + "." + action.customName if parentName is not None else action.customName - if not markerGraphicsDescriptorSet and markerPath == "Graphics.Descriptor Set": - rdtest.log.print(f"{action.parent.customName} {action.parent.eventId} {action.customName} {action.eventId}") - markerGraphicsDescriptorSet = action.eventId if not markerIndirect and markerPath == "Indirect": markerIndirect = action.eventId markerIndirectEnd = action.children[-1].eventId - if not markerCompute and markerPath == "Compute": - markerCompute = action.eventId if not markerComputeDescriptorSet and markerPath == "Compute.Descriptor Set": markerComputeDescriptorSet = action.eventId + if "vkCmdDrawIndirect(" in action.customName: + cmdDrawIndirectEIDs.append(action.eventId) + if "vkCmdDrawIndexedIndirect(" in action.customName: + cmdDrawIndirectEIDs.append(action.eventId) + if "vkCmdDrawMeshTasksIndirectEXT(" in action.customName: + cmdMeshDispatchIndirectEIDs.append(action.eventId) for e in action.events: eventName = sdfile.chunks[e.chunkIndex].name if "vkQueueSubmit" in eventName: @@ -136,28 +172,41 @@ def check_capture(self): waitFencesEIDs.append(e.eventId) if "vkResetFences" in eventName: resetFencesEIDs.append(e.eventId) + if "vkCmdCopyBuffer" in eventName: + copyBufferEIDs.append(e.eventId) + if "vkCmdFillBuffer" in eventName: + fillBufferEIDs.append(e.eventId) + if "vkCmdEndRenderPass" in eventName: + endRenderPassEIDs.append(e.eventId) - for eid in drawEIDs: - if eid > markerGraphicsDescriptorSet and eid < markerGraphicsSecondaryCommandBuffer: - descSetDrawEIDs.append(eid) - elif eid > markerIndirect and (not nestedSecondaries or eid < markerNestedSecondaryCommandBuffer): - descSetDrawEIDs.append(eid) - elif descBuffer and eid > markerDescriptorBuffer: - descBufferDrawEIDs.append(eid) + markerIndirectDispatchWriteIndirectDrawData = self.find_action("Indirect Dispatch Write IndirectDraw Data", markerIndirect).eventId + markerIndirectIndirectDraws = self.find_action("Indirect Draws", markerIndirectDispatchWriteIndirectDrawData).eventId + markerIndirectSecondaryCommandBuffer = self.find_action("Secondary Command Buffer", markerIndirect).eventId + markerIndirectSecondaryCommandBufferDispatchIndirect = self.find_action("DispatchIndirect", markerIndirectSecondaryCommandBuffer).eventId + + descSetDrawEIDs += [eid for eid in drawEIDs + if (eid > markerGraphicsDescriptorSet and eid < markerGraphicsSecondaryCommandBuffer) or + (eid > markerIndirect and (not nestedSecondaries or eid < markerNestedSecondaryCommandBuffer))] + descBufferDrawEIDs += [eid for eid in drawEIDs if descBuffer and eid > markerDescriptorBuffer] drawEIDs.sort() indexedEIDs.sort() indexedSpecialEIDs.sort() dispatchEIDs.sort() + multiEIDs.sort() indirectEIDs.sort() meshDispatchEIDs.sort() - multiEIDs.sort() indirectCountEIDs.sort() submitEIDs.sort() waitFencesEIDs.sort() resetFencesEIDs.sort() descSetDrawEIDs.sort() descBufferDrawEIDs.sort() + fillBufferEIDs.sort() + copyBufferEIDs.sort() + endRenderPassEIDs.sort() + cmdDrawIndirectEIDs.sort() + cmdMeshDispatchIndirectEIDs.sort() action = self.find_action("Draw") self.set_event(action.eventId, False) @@ -176,16 +225,13 @@ def check_capture(self): # the swap chain image has usage, anything else does not if res.resourceId == swapImage: expectedUsage = [ - (6,rd.ResourceUsage.Barrier), - (6,rd.ResourceUsage.Discard), - (7,rd.ResourceUsage.Clear), - (8,rd.ResourceUsage.Barrier)] - for eid in drawEIDs: - expectedUsage.append((eid,rd.ResourceUsage.ColorTarget)) - for eid in meshDispatchEIDs: - expectedUsage.append((eid,rd.ResourceUsage.ColorTarget)) - expectedUsage += [ - (235+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier)] + (self.markerStart + 1,rd.ResourceUsage.Barrier), + (self.markerStart + 1,rd.ResourceUsage.Discard), + (self.markerStart + 2,rd.ResourceUsage.Clear), + (self.markerStart + 3,rd.ResourceUsage.Barrier)] + expectedUsage += [(eid,rd.ResourceUsage.ColorTarget) for eid in drawEIDs] + expectedUsage += [(eid,rd.ResourceUsage.ColorTarget) for eid in meshDispatchEIDs] + expectedUsage += [(markerBarrierCommandSubmitFence - 1, rd.ResourceUsage.Barrier)] else: expectedUsage = [] elif res.type == rd.ResourceType.RenderPass: @@ -204,116 +250,123 @@ def check_capture(self): expectedUsage = [(0,rd.ResourceUsage.Unused)] elif res.type == rd.ResourceType.Buffer: if res.name == "Vertex Buffer": - for eid in drawEIDs: - expectedUsage.append((eid,rd.ResourceUsage.VertexBuffer)) + expectedUsage += [(eid,rd.ResourceUsage.VertexBuffer) for eid in drawEIDs] if res.name == "Index Buffer": - for eid in indexedEIDs: - expectedUsage.append((eid,rd.ResourceUsage.IndexBuffer)) + expectedUsage += [(eid,rd.ResourceUsage.IndexBuffer) for eid in indexedEIDs] if res.name == "Compute Buffer In": # All dispatches within "Compute" region # All dispatches within "Nested Secondary Command Buffer" region - for eid in dispatchEIDs: - if eid > markerComputeDescriptorSet and eid < markerIndirect: - expectedUsage.append((eid,rd.ResourceUsage.CS_Constants)) - elif nestedSecondaries and eid > markerNestedSecondaryCommandBuffer: - expectedUsage.append((eid,rd.ResourceUsage.CS_Constants)) + expectedUsage += [(eid,rd.ResourceUsage.CS_Constants) for eid in dispatchEIDs + if (eid > markerComputeDescriptorSet and eid < markerIndirect) or + (nestedSecondaries and eid > markerNestedSecondaryCommandBuffer)] if res.name == "Compute Buffer Out": # All dispatches within "Compute" region # All dispatches within "Nested Secondary Command Buffer" region - for eid in dispatchEIDs: - if eid > markerComputeDescriptorSet and eid < markerIndirect: - expectedUsage.append((eid,rd.ResourceUsage.CS_RWResource)) - elif nestedSecondaries and eid > markerNestedSecondaryCommandBuffer: - expectedUsage.append((eid,rd.ResourceUsage.CS_RWResource)) + expectedUsage += [(eid,rd.ResourceUsage.CS_RWResource) for eid in dispatchEIDs + if (eid > markerComputeDescriptorSet and eid < markerIndirect) or + (nestedSecondaries and eid > markerNestedSecondaryCommandBuffer)] if res.name == "Indirect Data": - expectedUsage += [(14,rd.ResourceUsage.Barrier), - (15,rd.ResourceUsage.Clear), - (16,rd.ResourceUsage.Barrier), - (20,rd.ResourceUsage.CS_RWResource), - (21,rd.ResourceUsage.Barrier), - (97,rd.ResourceUsage.Barrier), - (109,rd.ResourceUsage.Barrier), - (120,rd.ResourceUsage.Indirect), - (124,rd.ResourceUsage.Indirect), - (142,rd.ResourceUsage.Indirect), - (144,rd.ResourceUsage.Barrier), - (149,rd.ResourceUsage.Barrier), - (150,rd.ResourceUsage.Clear), - (151,rd.ResourceUsage.Barrier), - (155,rd.ResourceUsage.CS_RWResource), - (157,rd.ResourceUsage.Barrier), - (161,rd.ResourceUsage.Barrier), - (163,rd.ResourceUsage.Barrier), - (177,rd.ResourceUsage.Indirect), - (208,rd.ResourceUsage.Indirect)] - if drawIndirectCount: - expectedUsage += [ - (247,rd.ResourceUsage.Indirect), - (254,rd.ResourceUsage.Indirect)] - expectedUsage += [(231+countDrawIndirectCount,rd.ResourceUsage.Barrier)] - if nestedSecondaries: - expectedUsage += [ - (268+countDrawIndirectCount+countDescBufferCopy,rd.ResourceUsage.Barrier)] - if meshShader: - expectedUsage += [ - (249+countDrawIndirectCount+countNested+countDescBuffer,rd.ResourceUsage.Indirect), - (252+countDrawIndirectCount+countNested+countDescBuffer,rd.ResourceUsage.Indirect), - (255+countDrawIndirectCount+countNested+countDescBuffer,rd.ResourceUsage.Indirect)] - for eid in indirectEIDs: - # Dispatch + Indirect - if eid in dispatchEIDs: + expectedUsage += [(markerIndirectWriteIndirectDispatchData + 1,rd.ResourceUsage.Barrier), + (markerIndirectWriteIndirectDispatchData + 2,rd.ResourceUsage.Clear), + (markerIndirectWriteIndirectDispatchData + 3,rd.ResourceUsage.Barrier)] + + expectedUsage += [(markerIndirectSecondaryCommandBuffer - 2,rd.ResourceUsage.Barrier), + (markerIndirectSecondaryCommandBuffer + 3,rd.ResourceUsage.Barrier), + (markerIndirectSecondaryCommandBuffer + 5,rd.ResourceUsage.Barrier)] + expectedUsage += [(markerIndirectIndirectDraws - 2,rd.ResourceUsage.Barrier)] + + expectedUsage += [(markerIndirectSecondaryCommandBufferDispatchIndirect - 1,rd.ResourceUsage.Barrier), + (markerIndirectSecondaryCommandBufferDispatchIndirect + 3,rd.ResourceUsage.Barrier), + (markerIndirectSecondaryCommandBufferDispatchIndirect + 5,rd.ResourceUsage.Barrier)] + + for eid in dispatchEIDs: + if eid in indirectEIDs: + continue + if eid in indirectCountEIDs: + continue + if eid in multiEIDs: + continue + if eid in indexedSpecialEIDs: + continue + if eid > markerIndirectWriteIndirectDispatchData and eid < markerGraphics: expectedUsage.append((eid,rd.ResourceUsage.CS_RWResource)) + expectedUsage.append((eid+1,rd.ResourceUsage.Barrier)) + if eid > markerComputeSecondaryCommandBuffer and eid < markerIndirect: + expectedUsage.append((eid+1,rd.ResourceUsage.Barrier)) + if eid > markerIndirectSecondaryCommandBuffer and eid < markerIndirectEnd: + expectedUsage.append((eid,rd.ResourceUsage.CS_RWResource)) + for eid in cmdDrawIndirectEIDs: + if eid in indirectCountEIDs: + continue + if eid in multiEIDs: + continue + if eid in indexedSpecialEIDs: + continue + if eid > markerIndirectIndirectDraws and eid < markerIndirectEnd: + expectedUsage.append((eid,rd.ResourceUsage.Indirect)) + if eid > markerLooseEventsAfterIndirectDrawsDrawIndirectSingle and eid < markerDescriptorBuffer: expectedUsage.append((eid,rd.ResourceUsage.Indirect)) - for eid in multiEIDs: - expectedUsage.append((eid,rd.ResourceUsage.Indirect)) - for eid in indirectCountEIDs: - expectedUsage.append((eid,rd.ResourceUsage.Indirect)) - for eid in indexedSpecialEIDs: - expectedUsage.append((eid,rd.ResourceUsage.IndexBuffer)) - expectedUsage.append((eid,rd.ResourceUsage.Indirect)) + expectedUsage += [(eid,rd.ResourceUsage.Clear) for eid in fillBufferEIDs + if eid > markerIndirect and eid < markerIndirectEnd] + expectedUsage += [(eid,rd.ResourceUsage.CS_RWResource) for eid in indirectEIDs if eid in dispatchEIDs] + expectedUsage += [(eid,rd.ResourceUsage.Indirect) for eid in indirectEIDs if eid in dispatchEIDs] + expectedUsage += [(eid,rd.ResourceUsage.Indirect) for eid in multiEIDs if not eid in indirectCountEIDs] + expectedUsage += [(eid,rd.ResourceUsage.Indirect) for eid in indirectCountEIDs] + expectedUsage += [(eid,rd.ResourceUsage.Indirect) for eid in indirectCountEIDs] + expectedUsage += [(eid,rd.ResourceUsage.IndexBuffer) for eid in indexedSpecialEIDs if not eid in indirectCountEIDs] + expectedUsage += [(eid,rd.ResourceUsage.Indirect) for eid in indexedSpecialEIDs if not eid in indirectCountEIDs] + expectedUsage += [(eid,rd.ResourceUsage.Indirect) for eid in cmdMeshDispatchIndirectEIDs if not eid in multiEIDs] + for eid in endRenderPassEIDs: + if eid > markerLooseEventsAfterIndirectDraws: + expectedUsage.append((eid+2,rd.ResourceUsage.Barrier)) + break + for eid in dispatchEIDs: + if nestedSecondaries and eid > markerNestedSecondaryCommandBufferDispatch: + expectedUsage.append((eid + 1,rd.ResourceUsage.Barrier)) + break if res.name == "Barrier Buffer": - expectedUsage = [(243+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier), - (251+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier), - (259+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier), - (267+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier), - (275+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier), - (283+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier), - (291+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier), - (299+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier), - (307+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier), - (315+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier)] + expectedUsage += [(eid,rd.ResourceUsage.Barrier) + for eid in range(markerMultipleCommandBufferSubmits + 1, markerMultipleCommandBufferSubmits + 1 + 10*8, 8)] if res.name == "Barrier2 Buffer": - expectedUsage = [(323+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier), - (328+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier), - (333+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier), - (338+countDrawIndirectCount+countNested+countDescBuffer+countMeshShader,rd.ResourceUsage.Barrier)] + expectedUsage += [(eid,rd.ResourceUsage.Barrier) + for eid in range(markerMultipleSecondaryCommandBufferExecutes + 3, markerMultipleSecondaryCommandBufferExecutes + 3 + 4*5, 5)] if res.name == "Descriptor Buffer": - if descBuffer: - expectedUsage = [(235+countDrawIndirectCount,rd.ResourceUsage.Barrier), - (236+countDrawIndirectCount,rd.ResourceUsage.CopySrc), - (237+countDrawIndirectCount,rd.ResourceUsage.Barrier), - (238+countDrawIndirectCount,rd.ResourceUsage.Clear), - (241+countDrawIndirectCount,rd.ResourceUsage.Barrier), - (242+countDrawIndirectCount,rd.ResourceUsage.CopyDst)] + first = True + for eid in copyBufferEIDs: + if eid > markerLooseEventsAfterIndirectDraws: + expectedUsage.append((eid-1,rd.ResourceUsage.Barrier)) + if first: + expectedUsage.append((eid,rd.ResourceUsage.CopySrc)) + first = False + else: + expectedUsage.append((eid,rd.ResourceUsage.CopyDst)) + for eid in fillBufferEIDs: + if eid > markerLooseEventsAfterIndirectDraws: + expectedUsage.append((eid-1,rd.ResourceUsage.Barrier)) + expectedUsage.append((eid,rd.ResourceUsage.Clear)) + break if res.name == "Descriptor Backup Buffer": - if descBuffer: - expectedUsage = [(235+countDrawIndirectCount,rd.ResourceUsage.Barrier), - (236+countDrawIndirectCount,rd.ResourceUsage.CopyDst), - (241+countDrawIndirectCount,rd.ResourceUsage.Barrier), - (242+countDrawIndirectCount,rd.ResourceUsage.CopySrc)] + first = True + for eid in copyBufferEIDs: + if eid > markerLooseEventsAfterIndirectDraws: + expectedUsage.append((eid-1,rd.ResourceUsage.Barrier)) + if first: + expectedUsage.append((eid,rd.ResourceUsage.CopyDst)) + first = False + else: + expectedUsage.append((eid,rd.ResourceUsage.CopySrc)) + break elif res.type == rd.ResourceType.Texture: if res.name == "Offscreen MSAA Image": - expectedUsage = [(11,rd.ResourceUsage.Barrier), - (11,rd.ResourceUsage.Discard), - (12,rd.ResourceUsage.Clear)] + expectedUsage = [(self.markerStart + 6,rd.ResourceUsage.Barrier), + (self.markerStart + 6,rd.ResourceUsage.Discard), + (self.markerStart + 7,rd.ResourceUsage.Clear)] if res.name == "Offscreen Image": - expectedUsage = [(9,rd.ResourceUsage.Barrier), - (9,rd.ResourceUsage.Discard), - (10,rd.ResourceUsage.Clear)] - for eid in descSetDrawEIDs: - expectedUsage.append((eid,rd.ResourceUsage.PS_Resource)) - for eid in descBufferDrawEIDs: - expectedUsage.append((eid,rd.ResourceUsage.PS_Resource)) + expectedUsage = [(self.markerStart + 4,rd.ResourceUsage.Barrier), + (self.markerStart + 4,rd.ResourceUsage.Discard), + (self.markerStart + 5,rd.ResourceUsage.Clear)] + expectedUsage += [(eid,rd.ResourceUsage.PS_Resource) for eid in descSetDrawEIDs] + expectedUsage += [(eid,rd.ResourceUsage.PS_Resource) for eid in descBufferDrawEIDs] elif res.type == rd.ResourceType.CommandBuffer: expectedUsage = [(0,rd.ResourceUsage.Unused)] elif res.type == rd.ResourceType.DescriptorStore: @@ -322,7 +375,6 @@ def check_capture(self): expectedUsage = [(0,rd.ResourceUsage.Unused)] else: raise rdtest.TestFailureException(f"'{res.name}' {res.resourceId} Unexpected resource type {res.type.name}") - rdtest.log.print(f"Resource '{res.name}' type:{res.type.name} {res.resourceId} usages:{len(self.resourceUsages[res.resourceId])} expectedUsages:{len(expectedUsage)}") expectedUsage.sort(key=lambda x: x[0]) self.check_resource_usage(res, expectedUsage) diff --git a/util/test/tests/Vulkan/VK_Stripped_Shaders.py b/util/test/tests/Vulkan/VK_Stripped_Shaders.py new file mode 100644 index 00000000000..f4577849c66 --- /dev/null +++ b/util/test/tests/Vulkan/VK_Stripped_Shaders.py @@ -0,0 +1,6 @@ +import rdtest + + +class VK_Stripped_Shaders(rdtest.Stripped_Shaders): + demos_test_name = 'VK_Stripped_Shaders' + internal = False \ No newline at end of file