Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D3D11: Support debug names for resources #4591

Merged
merged 21 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2230bd7
[dxvk] Add convenience methods to check for debug utils support
doitsujin Nov 6, 2024
a8791fd
[dxvk] Add command buffer parameter to debug label functions
doitsujin Nov 6, 2024
2aa932d
[dxvk] Add support for resource debug names
doitsujin Jan 7, 2025
37ac1e7
[hud] Set debug names for HUD resources
doitsujin Jan 7, 2025
792b9d0
[dxvk] Set debug names for swap chain blitter resources
doitsujin Jan 7, 2025
566aea1
[dxvk] Set debug names for internal buffers
doitsujin Jan 8, 2025
611f1d5
[dxvk] Set debug names for memory allocations
doitsujin Jan 8, 2025
64bd8be
[d3d9] Set debug names for internal buffers
doitsujin Jan 8, 2025
f420c69
[d3d11] Set debug names for internal buffers
doitsujin Jan 8, 2025
ffbf8f0
[d3d11] Support debug names for buffers and textures
doitsujin Jan 7, 2025
c70504b
[dxvk] Add context feature flag for debug utils support
doitsujin Nov 8, 2024
f6bdca7
[dxvk] Add debug regions to command buffers
doitsujin Nov 6, 2024
2889769
[dxvk] Add debug region stack
doitsujin Jan 8, 2025
d023374
[dxvk] Add debug regions for render passes
doitsujin Jan 8, 2025
5b9bf8e
[dxvk] Add debug label for render target clears
doitsujin Jan 8, 2025
5037bcc
[dxvk] Add debug labels for pipeline binding
doitsujin Jan 8, 2025
26ad778
[dxvk] Add debug region for memory defragmentation
doitsujin Jan 8, 2025
1c0c6c6
[dxvk] Add debug region for mip generation
doitsujin Jan 8, 2025
b9dc562
[dxvk] Add debug regions for internal operations
doitsujin Jan 8, 2025
70f3e03
[dxvk] Add debug label for swap chain blitter
doitsujin Jan 8, 2025
74307e8
[hud] Add debug label for HUD rendering
doitsujin Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/d3d11/d3d11_annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace dxvk {
ContextType* container,
const Rc<DxvkDevice>& dxvkDevice)
: m_container(container), m_eventDepth(0),
m_annotationsEnabled(dxvkDevice->instance()->extensions().extDebugUtils) {
m_annotationsEnabled(dxvkDevice->isDebugEnabled()) {
if (!IsDeferred && m_annotationsEnabled)
RegisterUserDefinedAnnotation<true>(this);
}
Expand Down Expand Up @@ -87,7 +87,7 @@ namespace dxvk {
label.pLabelName = labelName.c_str();
DecodeD3DCOLOR(color, label.color);

ctx->beginDebugLabel(&label);
ctx->beginDebugLabel(label);
});

return m_eventDepth++;
Expand Down Expand Up @@ -125,7 +125,7 @@ namespace dxvk {
label.pLabelName = labelName.c_str();
DecodeD3DCOLOR(color, label.color);

ctx->insertDebugLabel(&label);
ctx->insertDebugLabel(label);
});
}

Expand Down
15 changes: 15 additions & 0 deletions src/d3d11/d3d11_buffer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "d3d11_buffer.h"
#include "d3d11_context.h"
#include "d3d11_context_imm.h"
#include "d3d11_device.h"

namespace dxvk {
Expand Down Expand Up @@ -211,6 +212,18 @@ namespace dxvk {
}


void D3D11Buffer::SetDebugName(const char* pName) {
if (m_buffer) {
m_parent->GetContext()->InjectCs([
cBuffer = m_buffer,
cName = std::string(pName ? pName : "")
] (DxvkContext* ctx) {
ctx->setDebugName(cBuffer, cName.c_str());
});
}
}


HRESULT D3D11Buffer::NormalizeBufferProperties(D3D11_BUFFER_DESC* pDesc) {
// Zero-sized buffers are illegal
if (!pDesc->ByteWidth && !(pDesc->MiscFlags & D3D11_RESOURCE_MISC_TILE_POOL))
Expand Down Expand Up @@ -370,6 +383,8 @@ namespace dxvk {
| VK_ACCESS_INDIRECT_COMMAND_READ_BIT
| VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_READ_BIT_EXT
| VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_WRITE_BIT_EXT;
info.debugName = "SO counter";

return device->createBuffer(info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
}

Expand Down
2 changes: 2 additions & 0 deletions src/d3d11/d3d11_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ namespace dxvk {
void STDMETHODCALLTYPE GetDesc(
D3D11_BUFFER_DESC *pDesc) final;

void STDMETHODCALLTYPE SetDebugName(const char* pName) final;

bool CheckViewCompatibility(
UINT BindFlags,
DXGI_FORMAT Format) const;
Expand Down
24 changes: 16 additions & 8 deletions src/d3d11/d3d11_device_child.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,28 @@ namespace dxvk {
}

HRESULT STDMETHODCALLTYPE GetPrivateData(
REFGUID guid,
UINT *pDataSize,
void *pData) final {
REFGUID guid,
UINT* pDataSize,
void* pData) final {
return m_privateData.getData(
guid, pDataSize, pData);
}

HRESULT STDMETHODCALLTYPE SetPrivateData(
REFGUID guid,
UINT DataSize,
const void *pData) final {
REFGUID guid,
UINT DataSize,
const void* pData) final {
// WKPDID_D3DDebugObjectName, can't use directly due to MSVC link errors
if (guid == GUID{0x429b8c22,0x9188,0x4b0c,0x87,0x42,0xac,0xb0,0xbf,0x85,0xc2,0x00})
SetDebugName(static_cast<const char*>(pData));

return m_privateData.setData(
guid, DataSize, pData);
}

HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
REFGUID guid,
const IUnknown *pUnknown) final {
REFGUID guid,
const IUnknown* pUnknown) final {
return m_privateData.setInterface(
guid, pUnknown);
}
Expand All @@ -46,6 +50,10 @@ namespace dxvk {
*ppDevice = ref(GetParentInterface());
}

virtual void STDMETHODCALLTYPE SetDebugName(const char* pName) {
// No-op by default
}

protected:

ID3D11Device* GetParentInterface() const {
Expand Down
1 change: 1 addition & 0 deletions src/d3d11/d3d11_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ namespace dxvk {
info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
info.stages = util::pipelineStages(shaderInfo.stage);
info.access = VK_ACCESS_UNIFORM_READ_BIT;
info.debugName = "Icb";

VkMemoryPropertyFlags memFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
Expand Down
3 changes: 3 additions & 0 deletions src/d3d11/d3d11_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ namespace dxvk {
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
imageInfo.layout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
imageInfo.shared = VK_TRUE;
imageInfo.debugName = "Swap image";

DxvkImageViewKey viewInfo;
viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
Expand Down Expand Up @@ -652,6 +653,8 @@ namespace dxvk {
cImages = std::move(images)
] (DxvkContext* ctx) {
for (size_t i = 0; i < cImages.size(); i++) {
ctx->setDebugName(cImages[i], str::format("Back buffer ", i).c_str());

ctx->initImage(cImages[i],
cImages[i]->getAvailableSubresources(),
VK_IMAGE_LAYOUT_UNDEFINED);
Expand Down
48 changes: 44 additions & 4 deletions src/d3d11/d3d11_texture.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "d3d11_device.h"
#include "d3d11_context_imm.h"
#include "d3d11_gdi.h"
#include "d3d11_texture.h"

Expand Down Expand Up @@ -372,8 +373,31 @@ namespace dxvk {
return viewFormat.Format == baseFormat.Format && planeCount == 1;
}
}




void D3D11CommonTexture::SetDebugName(const char* pName) {
if (m_image) {
m_device->GetContext()->InjectCs([
cImage = m_image,
cName = std::string(pName ? pName : "")
] (DxvkContext* ctx) {
ctx->setDebugName(cImage, cName.c_str());
});
}

if (m_mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_STAGING) {
for (uint32_t i = 0; i < m_buffers.size(); i++) {
m_device->GetContext()->InjectCs([
cBuffer = m_buffers[i].buffer,
cName = std::string(pName ? pName : "")
] (DxvkContext* ctx) {
ctx->setDebugName(cBuffer, cName.c_str());
});
}
}
}


HRESULT D3D11CommonTexture::NormalizeTextureProperties(D3D11_COMMON_TEXTURE_DESC* pDesc) {
if (pDesc->Width == 0 || pDesc->Height == 0 || pDesc->Depth == 0 || pDesc->ArraySize == 0)
return E_INVALIDARG;
Expand Down Expand Up @@ -754,6 +778,7 @@ namespace dxvk {
| VK_ACCESS_TRANSFER_WRITE_BIT
| VK_ACCESS_SHADER_READ_BIT
| VK_ACCESS_SHADER_WRITE_BIT;
info.debugName = "Image buffer";

// We may read mapped buffers even if it is
// marked as CPU write-only on the D3D11 side.
Expand Down Expand Up @@ -1193,8 +1218,13 @@ namespace dxvk {
pDesc->CPUAccessFlags = m_texture.Desc()->CPUAccessFlags;
pDesc->MiscFlags = m_texture.Desc()->MiscFlags;
}




void STDMETHODCALLTYPE D3D11Texture1D::SetDebugName(const char* pName) {
m_texture.SetDebugName(pName);
}


///////////////////////////////////////////
// D 3 D 1 1 T E X T U R E 2 D
D3D11Texture2D::D3D11Texture2D(
Expand Down Expand Up @@ -1376,6 +1406,11 @@ namespace dxvk {
}


void STDMETHODCALLTYPE D3D11Texture2D::SetDebugName(const char* pName) {
m_texture.SetDebugName(pName);
}


///////////////////////////////////////////
// D 3 D 1 1 T E X T U R E 3 D
D3D11Texture3D::D3D11Texture3D(
Expand Down Expand Up @@ -1487,6 +1522,11 @@ namespace dxvk {
}


void STDMETHODCALLTYPE D3D11Texture3D::SetDebugName(const char* pName) {
m_texture.SetDebugName(pName);
}


D3D11CommonTexture* GetCommonTexture(ID3D11Resource* pResource) {
D3D11_RESOURCE_DIMENSION dimension = D3D11_RESOURCE_DIMENSION_UNKNOWN;
pResource->GetType(&dimension);
Expand Down
14 changes: 14 additions & 0 deletions src/d3d11/d3d11_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,14 @@ namespace dxvk {
return m_11on12;
}

/**
* \brief Sets debug name for texture
*
* Passes the given name to the backing image or buffer.
* \param [in] name Debug name
*/
void SetDebugName(const char* pName);

/**
* \brief Normalizes and validates texture description
*
Expand Down Expand Up @@ -759,6 +767,8 @@ namespace dxvk {
void STDMETHODCALLTYPE GetDesc(
D3D11_TEXTURE1D_DESC *pDesc) final;

void STDMETHODCALLTYPE SetDebugName(const char* pName) final;

D3D11CommonTexture* GetCommonTexture() {
return &m_texture;
}
Expand Down Expand Up @@ -825,6 +835,8 @@ namespace dxvk {
void STDMETHODCALLTYPE GetDesc1(
D3D11_TEXTURE2D_DESC1* pDesc) final;

void STDMETHODCALLTYPE SetDebugName(const char* pName) final;

D3D11CommonTexture* GetCommonTexture() {
return &m_texture;
}
Expand Down Expand Up @@ -875,6 +887,8 @@ namespace dxvk {
void STDMETHODCALLTYPE GetDesc1(
D3D11_TEXTURE3D_DESC1* pDesc) final;

void STDMETHODCALLTYPE SetDebugName(const char* pName) final;

D3D11CommonTexture* GetCommonTexture() {
return &m_texture;
}
Expand Down
2 changes: 2 additions & 0 deletions src/d3d11/d3d11_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,8 @@ namespace dxvk {
bufferInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
bufferInfo.stages = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
bufferInfo.access = VK_ACCESS_UNIFORM_READ_BIT;
bufferInfo.debugName = "Video blit parameters";

m_ubo = m_device->createBuffer(bufferInfo, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
}

Expand Down
1 change: 1 addition & 0 deletions src/d3d11/d3d11_view_uav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ namespace dxvk {
| VK_ACCESS_TRANSFER_READ_BIT
| VK_ACCESS_SHADER_WRITE_BIT
| VK_ACCESS_SHADER_READ_BIT;
info.debugName = "UAV counter";

Rc<DxvkBuffer> buffer = device->createBuffer(info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);

Expand Down
4 changes: 2 additions & 2 deletions src/d3d9/d3d9_annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace dxvk {
label.pLabelName = labelName.c_str();
DecodeD3DCOLOR(color, label.color);

ctx->beginDebugLabel(&label);
ctx->beginDebugLabel(label);
});

// Handled by the global list.
Expand Down Expand Up @@ -165,7 +165,7 @@ namespace dxvk {
label.pLabelName = labelName.c_str();
DecodeD3DCOLOR(color, label.color);

ctx->insertDebugLabel(&label);
ctx->insertDebugLabel(label);
});
}

Expand Down
1 change: 1 addition & 0 deletions src/d3d9/d3d9_constant_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ namespace dxvk {
bufferInfo.usage = m_usage;
bufferInfo.access = 0;
bufferInfo.stages = util::pipelineStages(m_stages);
bufferInfo.debugName = "Constant buffer";

if (m_usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)
bufferInfo.access |= VK_ACCESS_UNIFORM_READ_BIT;
Expand Down
3 changes: 2 additions & 1 deletion src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace dxvk {
if (canSWVP)
Logger::info("D3D9DeviceEx: Using extended constant set for software vertex processing.");

if (m_dxvkDevice->instance()->extensions().extDebugUtils)
if (m_dxvkDevice->isDebugEnabled())
m_annotation = new D3D9UserDefinedAnnotation(this);

m_initializer = new D3D9Initializer(this);
Expand Down Expand Up @@ -4576,6 +4576,7 @@ namespace dxvk {
info.access = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
| VK_ACCESS_INDEX_READ_BIT;
info.stages = VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
info.debugName = "UP buffer";

Rc<DxvkBuffer> buffer = m_dxvkDevice->createBuffer(info, memoryFlags);
void* mapPtr = buffer->mapPtr(0);
Expand Down
38 changes: 37 additions & 1 deletion src/dxvk/dxvk_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ namespace dxvk {
m_info (createInfo) {
m_allocator->registerResource(this);

// Assign debug name to buffer
if (device->isDebugEnabled()) {
m_debugName = createDebugName(createInfo.debugName);
m_info.debugName = m_debugName.c_str();
} else {
m_info.debugName = nullptr;
}

// Create and assign actual buffer resource
assignStorage(allocateStorage());
}
Expand Down Expand Up @@ -99,5 +107,33 @@ namespace dxvk {

return m_allocator->createBufferResource(info, allocationInfo, nullptr);
}



void DxvkBuffer::setDebugName(const char* name) {
if (likely(!m_info.debugName))
return;

m_debugName = createDebugName(name);
m_info.debugName = m_debugName.c_str();

updateDebugName();
}


void DxvkBuffer::updateDebugName() {
if (m_storage->flags().test(DxvkAllocationFlag::OwnsBuffer)) {
VkDebugUtilsObjectNameInfoEXT nameInfo = { VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT };
nameInfo.objectType = VK_OBJECT_TYPE_BUFFER;
nameInfo.objectHandle = vk::getObjectHandle(m_bufferInfo.buffer);
nameInfo.pObjectName = m_info.debugName;

m_vkd->vkSetDebugUtilsObjectNameEXT(m_vkd->device(), &nameInfo);
}
}


std::string DxvkBuffer::createDebugName(const char* name) const {
return str::format(vk::isValidDebugName(name) ? name : "Buffer", " (", cookie(), ")");
}

}
Loading
Loading