Skip to content

Commit afc5dc4

Browse files
committed
Fix two issues in the Vulkan version of GPA
Make sure results are ready before trying to query them GPA_ContinueSampleOnCommandList failure
1 parent ab6a93e commit afc5dc4

File tree

8 files changed

+66
-26
lines changed

8 files changed

+66
-26
lines changed

Src/GPUPerfAPI-Common/GPAPass.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ GPASample* GPAPass::GetSampleById(ClientSampleId sampleId) const
8484
{
8585
std::lock_guard<std::mutex> lock(m_samplesMapMutex);
8686

87+
return GetSampleById_NotThreadSafe(sampleId);
88+
}
89+
90+
GPASample* GPAPass::GetSampleById_NotThreadSafe(ClientSampleId sampleId) const
91+
{
8792
GPASample* pRetVal = nullptr;
8893

8994
if (m_samplesMap.find(sampleId) != m_samplesMap.end())
@@ -154,7 +159,7 @@ bool GPAPass::ContinueSample(ClientSampleId srcSampleId, IGPACommandList* pPrima
154159
// We will mark the parent sample as to be continued by the client
155160

156161
bool success = false;
157-
GPASample* pParentSample = GetSampleById(srcSampleId);
162+
GPASample* pParentSample = GetSampleById_NotThreadSafe(srcSampleId);
158163

159164
if (nullptr != pParentSample)
160165
{
@@ -179,14 +184,19 @@ bool GPAPass::ContinueSample(ClientSampleId srcSampleId, IGPACommandList* pPrima
179184

180185
if (nullptr != pNewSample)
181186
{
182-
// TODO: Can these two be merged into the same entrypoint?
183-
// ie, if we link a continuing sample, isn't it by default continued by client?
184-
// is there a way that WE (GPA) would continue it on our own?
185-
// Mark the parent sample as getting continuing by client
186-
pParentSample->SetAsContinuedByClient();
187-
// Link the sample to the parent sample
188-
pParentSample->LinkContinuingSample(pNewSample);
189-
success = true;
187+
if (!pPrimaryGpaCmdList->BeginSample(srcSampleId, pNewSample))
188+
{
189+
GPA_LogError("Unable to begin continued sample in pass.");
190+
delete pNewSample;
191+
pNewSample = nullptr;
192+
}
193+
else
194+
{
195+
pParentSample->SetAsContinuedByClient();
196+
// Link the sample to the parent sample
197+
pParentSample->LinkContinuingSample(pNewSample);
198+
success = true;
199+
}
190200
}
191201
}
192202
else

Src/GPUPerfAPI-Common/GPAPass.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ class GPAPass
248248
/// \return True if the sample has been opened; False otherwise
249249
bool DoesSampleExist_NotThreadSafe(ClientSampleId clientSampleId) const;
250250

251+
/// Returns the sample by its client sample Id
252+
/// Does NOT lock the mutex, expects the calling method to do that.
253+
/// \param[in] sampleId Id of the sample
254+
/// \return GPA Sample object
255+
GPASample* GetSampleById_NotThreadSafe(ClientSampleId sampleId) const;
256+
251257
/// Create an API-specific GPASample of the supplied GpaSampleType.
252258
/// \param[in] pCmdList The commandList on which this sample is taking place.
253259
/// \param[in] sampleType Indicates whether the created sample should support Software or Hardware counters.

Src/GPUPerfAPI-Common/GPASample.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ GPA_THREAD_SAFE_FUNCTION bool GPASample::SetAsContinuedByClient()
212212
{
213213
std::lock_guard<std::mutex> lockSample(m_sampleMutex);
214214
bool success = false;
215-
m_gpaSampleState = GPASampleState::PENDING_RESULTS;
216215

217216
if (!m_isClosedByClient)
218217
{
@@ -259,6 +258,8 @@ IGPACommandList* GPASample::GetCmdList() const
259258

260259
bool GPASample::LinkContinuingSample(GPASample* pContinuingSample)
261260
{
261+
std::lock_guard<std::recursive_mutex> lock(m_continueSampleMutex);
262+
262263
if (nullptr == pContinuingSample)
263264
{
264265
return false;

Src/GPUPerfAPI-Common/GPASample.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,21 @@ class GPA_NOT_THREAD_SAFE_OBJECT GPASample
225225
/// Release allocated counters
226226
virtual void ReleaseCounters() = 0;
227227

228-
GPAPass* m_pPass; ///< GPA Pass Object
229-
IGPACommandList* m_pGpaCmdList; ///< Pointer to the command list object
230-
GpaSampleType m_gpaSampleType; ///< type of the GPA sample
231-
ClientSampleId m_clientSampleId; ///< Client-assigned sample Id
232-
DriverSampleId m_driverSampleId; ///< Driver created sample id
233-
GPASampleState m_gpaSampleState; ///< The state of this sample
234-
GPASampleResult* m_pSampleResult; ///< memory for sample Results
235-
GPASample* m_pContinuingSample; ///< Pointer to linked/continuing GpaSample
236-
std::mutex m_sampleMutex; ///< mutex for the GPA sample object
237-
bool m_isSecondary; ///< flag indicating a sample is a secondary sample; i.e. it has been created on a bundle or secondary command buffer
238-
bool m_isOpened; ///< flag indicating a sample is opened
239-
bool m_isClosedByClient; ///< flag indicating a sample is closed by the command list on which it is created
240-
bool m_isContinuedByClient; ///< flag indicating a sampe has been continued on another command list
241-
bool m_isCopiedSample; ///< flag indicating that sample has been copied to primary command list
228+
GPAPass* m_pPass; ///< GPA Pass Object
229+
IGPACommandList* m_pGpaCmdList; ///< Pointer to the command list object
230+
GpaSampleType m_gpaSampleType; ///< type of the GPA sample
231+
ClientSampleId m_clientSampleId; ///< Client-assigned sample Id
232+
DriverSampleId m_driverSampleId; ///< Driver created sample id
233+
GPASampleState m_gpaSampleState; ///< The state of this sample
234+
GPASampleResult* m_pSampleResult; ///< memory for sample Results
235+
GPASample* m_pContinuingSample; ///< Pointer to linked/continuing GpaSample
236+
std::recursive_mutex m_continueSampleMutex; ///< mutex for the GPA sample object
237+
std::mutex m_sampleMutex; ///< mutex for the GPA sample object
238+
bool m_isSecondary; ///< flag indicating a sample is a secondary sample; i.e. it has been created on a bundle or secondary command buffer
239+
bool m_isOpened; ///< flag indicating a sample is opened
240+
bool m_isClosedByClient; ///< flag indicating a sample is closed by the command list on which it is created
241+
bool m_isContinuedByClient; ///< flag indicating a sampe has been continued on another command list
242+
bool m_isCopiedSample; ///< flag indicating that sample has been copied to primary command list
242243
};
243244

244245
#endif // _GPA_SAMPLE_H_

Src/GPUPerfAPI-Common/GPASession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ bool GPASession::UpdateResults()
378378

379379
if (!areAllPassesComplete)
380380
{
381-
GPA_LogError("Pass is not complete.");
381+
GPA_LogDebugMessage("Pass is not complete.");
382382
}
383383
}
384384

Src/GPUPerfAPIVk/VkGPACommandList.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,25 @@ bool VkGPACommandList::CloseLastSampleRequest()
175175
return true;
176176
}
177177

178+
bool VkGPACommandList::IsResultReady() const
179+
{
180+
bool isResultReady = false;
181+
182+
VkGPAContext* pVkGPAContext = dynamic_cast<VkGPAContext*>(GetParentSession()->GetParentContext());
183+
184+
if (nullptr == pVkGPAContext)
185+
{
186+
GPA_LogError("Invalid profiling session encountered when checking for available results.");
187+
}
188+
else
189+
{
190+
VkResult isReady = _vkGetGpaSessionStatusAMD(pVkGPAContext->GetVkDevice(), m_gpaExtSessionAMD);
191+
isResultReady = VK_SUCCESS == isReady;
192+
}
193+
194+
return isResultReady;
195+
}
196+
178197
VkCommandBuffer VkGPACommandList::GetVkCommandBuffer() const
179198
{
180199
return m_vkCmdBuffer;

Src/GPUPerfAPIVk/VkGPACommandList.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class VkGPACommandList : public GPACommandList
4141
/// Destructor
4242
~VkGPACommandList();
4343

44+
/// \copydoc IGPACommandList::IsResultReady()
45+
bool IsResultReady() const override;
46+
4447
/// \copydoc IGPAInterfaceTrait::GetAPIType()
4548
GPA_API_Type GetAPIType() const override;
4649

Src/GPUPerfAPIVk/VkGPASession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ GPA_Status VkGPASession::ContinueSampleOnCommandList(gpa_uint32 srcSampleId, GPA
2626
{
2727
bool succeed = false;
2828

29-
if (primaryCommandListId->Object()->GetAPIType() == GPA_API_DIRECTX_12 &&
29+
if (primaryCommandListId->Object()->GetAPIType() == GetAPIType() &&
3030
primaryCommandListId->ObjectType() == GPAObjectType::GPA_OBJECT_TYPE_COMMAND_LIST)
3131
{
3232
VkGPACommandList* pVkGpaCmdList = reinterpret_cast<VkGPACommandList*>(primaryCommandListId->Object());

0 commit comments

Comments
 (0)