[Vulkan] Shader module debug object names

This commit is contained in:
DrChat 2018-02-22 23:07:54 -06:00
parent 824c39c38a
commit 5a4dcd7043
4 changed files with 37 additions and 32 deletions

View File

@ -35,7 +35,7 @@ using xe::ui::vulkan::CheckResult;
PipelineCache::PipelineCache(RegisterFile* register_file, PipelineCache::PipelineCache(RegisterFile* register_file,
ui::vulkan::VulkanDevice* device) ui::vulkan::VulkanDevice* device)
: register_file_(register_file), device_(*device) { : register_file_(register_file), device_(device) {
// We can also use the GLSL translator with a Vulkan dialect. // We can also use the GLSL translator with a Vulkan dialect.
shader_translator_.reset(new SpirvShaderTranslator()); shader_translator_.reset(new SpirvShaderTranslator());
} }
@ -58,7 +58,7 @@ VkResult PipelineCache::Initialize(
pipeline_cache_info.flags = 0; pipeline_cache_info.flags = 0;
pipeline_cache_info.initialDataSize = 0; pipeline_cache_info.initialDataSize = 0;
pipeline_cache_info.pInitialData = nullptr; pipeline_cache_info.pInitialData = nullptr;
status = vkCreatePipelineCache(device_, &pipeline_cache_info, nullptr, status = vkCreatePipelineCache(*device_, &pipeline_cache_info, nullptr,
&pipeline_cache_); &pipeline_cache_);
if (status != VK_SUCCESS) { if (status != VK_SUCCESS) {
return status; return status;
@ -96,7 +96,7 @@ VkResult PipelineCache::Initialize(
pipeline_layout_info.pushConstantRangeCount = pipeline_layout_info.pushConstantRangeCount =
static_cast<uint32_t>(xe::countof(push_constant_ranges)); static_cast<uint32_t>(xe::countof(push_constant_ranges));
pipeline_layout_info.pPushConstantRanges = push_constant_ranges; pipeline_layout_info.pPushConstantRanges = push_constant_ranges;
status = vkCreatePipelineLayout(device_, &pipeline_layout_info, nullptr, status = vkCreatePipelineLayout(*device_, &pipeline_layout_info, nullptr,
&pipeline_layout_); &pipeline_layout_);
if (status != VK_SUCCESS) { if (status != VK_SUCCESS) {
return status; return status;
@ -113,7 +113,7 @@ VkResult PipelineCache::Initialize(
static_cast<uint32_t>(sizeof(line_quad_list_geom)); static_cast<uint32_t>(sizeof(line_quad_list_geom));
shader_module_info.pCode = shader_module_info.pCode =
reinterpret_cast<const uint32_t*>(line_quad_list_geom); reinterpret_cast<const uint32_t*>(line_quad_list_geom);
status = vkCreateShaderModule(device_, &shader_module_info, nullptr, status = vkCreateShaderModule(*device_, &shader_module_info, nullptr,
&geometry_shaders_.line_quad_list); &geometry_shaders_.line_quad_list);
if (status != VK_SUCCESS) { if (status != VK_SUCCESS) {
return status; return status;
@ -121,7 +121,7 @@ VkResult PipelineCache::Initialize(
shader_module_info.codeSize = static_cast<uint32_t>(sizeof(point_list_geom)); shader_module_info.codeSize = static_cast<uint32_t>(sizeof(point_list_geom));
shader_module_info.pCode = reinterpret_cast<const uint32_t*>(point_list_geom); shader_module_info.pCode = reinterpret_cast<const uint32_t*>(point_list_geom);
status = vkCreateShaderModule(device_, &shader_module_info, nullptr, status = vkCreateShaderModule(*device_, &shader_module_info, nullptr,
&geometry_shaders_.point_list); &geometry_shaders_.point_list);
if (status != VK_SUCCESS) { if (status != VK_SUCCESS) {
return status; return status;
@ -129,7 +129,7 @@ VkResult PipelineCache::Initialize(
shader_module_info.codeSize = static_cast<uint32_t>(sizeof(quad_list_geom)); shader_module_info.codeSize = static_cast<uint32_t>(sizeof(quad_list_geom));
shader_module_info.pCode = reinterpret_cast<const uint32_t*>(quad_list_geom); shader_module_info.pCode = reinterpret_cast<const uint32_t*>(quad_list_geom);
status = vkCreateShaderModule(device_, &shader_module_info, nullptr, status = vkCreateShaderModule(*device_, &shader_module_info, nullptr,
&geometry_shaders_.quad_list); &geometry_shaders_.quad_list);
if (status != VK_SUCCESS) { if (status != VK_SUCCESS) {
return status; return status;
@ -137,7 +137,7 @@ VkResult PipelineCache::Initialize(
shader_module_info.codeSize = static_cast<uint32_t>(sizeof(rect_list_geom)); shader_module_info.codeSize = static_cast<uint32_t>(sizeof(rect_list_geom));
shader_module_info.pCode = reinterpret_cast<const uint32_t*>(rect_list_geom); shader_module_info.pCode = reinterpret_cast<const uint32_t*>(rect_list_geom);
status = vkCreateShaderModule(device_, &shader_module_info, nullptr, status = vkCreateShaderModule(*device_, &shader_module_info, nullptr,
&geometry_shaders_.rect_list); &geometry_shaders_.rect_list);
if (status != VK_SUCCESS) { if (status != VK_SUCCESS) {
return status; return status;
@ -145,7 +145,7 @@ VkResult PipelineCache::Initialize(
shader_module_info.codeSize = static_cast<uint32_t>(sizeof(dummy_frag)); shader_module_info.codeSize = static_cast<uint32_t>(sizeof(dummy_frag));
shader_module_info.pCode = reinterpret_cast<const uint32_t*>(dummy_frag); shader_module_info.pCode = reinterpret_cast<const uint32_t*>(dummy_frag);
status = vkCreateShaderModule(device_, &shader_module_info, nullptr, status = vkCreateShaderModule(*device_, &shader_module_info, nullptr,
&dummy_pixel_shader_); &dummy_pixel_shader_);
if (status != VK_SUCCESS) { if (status != VK_SUCCESS) {
return status; return status;
@ -157,38 +157,38 @@ VkResult PipelineCache::Initialize(
void PipelineCache::Shutdown() { void PipelineCache::Shutdown() {
// Destroy all pipelines. // Destroy all pipelines.
for (auto it : cached_pipelines_) { for (auto it : cached_pipelines_) {
vkDestroyPipeline(device_, it.second, nullptr); vkDestroyPipeline(*device_, it.second, nullptr);
} }
cached_pipelines_.clear(); cached_pipelines_.clear();
// Destroy geometry shaders. // Destroy geometry shaders.
if (geometry_shaders_.line_quad_list) { if (geometry_shaders_.line_quad_list) {
vkDestroyShaderModule(device_, geometry_shaders_.line_quad_list, nullptr); vkDestroyShaderModule(*device_, geometry_shaders_.line_quad_list, nullptr);
geometry_shaders_.line_quad_list = nullptr; geometry_shaders_.line_quad_list = nullptr;
} }
if (geometry_shaders_.point_list) { if (geometry_shaders_.point_list) {
vkDestroyShaderModule(device_, geometry_shaders_.point_list, nullptr); vkDestroyShaderModule(*device_, geometry_shaders_.point_list, nullptr);
geometry_shaders_.point_list = nullptr; geometry_shaders_.point_list = nullptr;
} }
if (geometry_shaders_.quad_list) { if (geometry_shaders_.quad_list) {
vkDestroyShaderModule(device_, geometry_shaders_.quad_list, nullptr); vkDestroyShaderModule(*device_, geometry_shaders_.quad_list, nullptr);
geometry_shaders_.quad_list = nullptr; geometry_shaders_.quad_list = nullptr;
} }
if (geometry_shaders_.rect_list) { if (geometry_shaders_.rect_list) {
vkDestroyShaderModule(device_, geometry_shaders_.rect_list, nullptr); vkDestroyShaderModule(*device_, geometry_shaders_.rect_list, nullptr);
geometry_shaders_.rect_list = nullptr; geometry_shaders_.rect_list = nullptr;
} }
if (dummy_pixel_shader_) { if (dummy_pixel_shader_) {
vkDestroyShaderModule(device_, dummy_pixel_shader_, nullptr); vkDestroyShaderModule(*device_, dummy_pixel_shader_, nullptr);
dummy_pixel_shader_ = nullptr; dummy_pixel_shader_ = nullptr;
} }
if (pipeline_layout_) { if (pipeline_layout_) {
vkDestroyPipelineLayout(device_, pipeline_layout_, nullptr); vkDestroyPipelineLayout(*device_, pipeline_layout_, nullptr);
pipeline_layout_ = nullptr; pipeline_layout_ = nullptr;
} }
if (pipeline_cache_) { if (pipeline_cache_) {
vkDestroyPipelineCache(device_, pipeline_cache_, nullptr); vkDestroyPipelineCache(*device_, pipeline_cache_, nullptr);
pipeline_cache_ = nullptr; pipeline_cache_ = nullptr;
} }
@ -322,7 +322,7 @@ VkPipeline PipelineCache::GetPipeline(const RenderState* render_state,
pipeline_info.basePipelineHandle = nullptr; pipeline_info.basePipelineHandle = nullptr;
pipeline_info.basePipelineIndex = -1; pipeline_info.basePipelineIndex = -1;
VkPipeline pipeline = nullptr; VkPipeline pipeline = nullptr;
auto result = vkCreateGraphicsPipelines(device_, pipeline_cache_, 1, auto result = vkCreateGraphicsPipelines(*device_, pipeline_cache_, 1,
&pipeline_info, nullptr, &pipeline); &pipeline_info, nullptr, &pipeline);
if (result != VK_SUCCESS) { if (result != VK_SUCCESS) {
XELOGE("vkCreateGraphicsPipelines failed with code %d", result); XELOGE("vkCreateGraphicsPipelines failed with code %d", result);
@ -385,22 +385,22 @@ void PipelineCache::DumpShaderDisasmNV(
pipeline_cache_info.flags = 0; pipeline_cache_info.flags = 0;
pipeline_cache_info.initialDataSize = 0; pipeline_cache_info.initialDataSize = 0;
pipeline_cache_info.pInitialData = nullptr; pipeline_cache_info.pInitialData = nullptr;
auto status = vkCreatePipelineCache(device_, &pipeline_cache_info, nullptr, auto status = vkCreatePipelineCache(*device_, &pipeline_cache_info, nullptr,
&dummy_pipeline_cache); &dummy_pipeline_cache);
CheckResult(status, "vkCreatePipelineCache"); CheckResult(status, "vkCreatePipelineCache");
// Create a pipeline on the dummy cache and dump it. // Create a pipeline on the dummy cache and dump it.
VkPipeline dummy_pipeline; VkPipeline dummy_pipeline;
status = vkCreateGraphicsPipelines(device_, dummy_pipeline_cache, 1, status = vkCreateGraphicsPipelines(*device_, dummy_pipeline_cache, 1,
&pipeline_info, nullptr, &dummy_pipeline); &pipeline_info, nullptr, &dummy_pipeline);
std::vector<uint8_t> pipeline_data; std::vector<uint8_t> pipeline_data;
size_t data_size = 0; size_t data_size = 0;
status = vkGetPipelineCacheData(device_, dummy_pipeline_cache, &data_size, status = vkGetPipelineCacheData(*device_, dummy_pipeline_cache, &data_size,
nullptr); nullptr);
if (status == VK_SUCCESS) { if (status == VK_SUCCESS) {
pipeline_data.resize(data_size); pipeline_data.resize(data_size);
vkGetPipelineCacheData(device_, dummy_pipeline_cache, &data_size, vkGetPipelineCacheData(*device_, dummy_pipeline_cache, &data_size,
pipeline_data.data()); pipeline_data.data());
// Scan the data for the disassembly. // Scan the data for the disassembly.
@ -457,8 +457,8 @@ void PipelineCache::DumpShaderDisasmNV(
disasm_fp.c_str()); disasm_fp.c_str());
} }
vkDestroyPipeline(device_, dummy_pipeline, nullptr); vkDestroyPipeline(*device_, dummy_pipeline, nullptr);
vkDestroyPipelineCache(device_, dummy_pipeline_cache, nullptr); vkDestroyPipelineCache(*device_, dummy_pipeline_cache, nullptr);
} }
VkShaderModule PipelineCache::GetGeometryShader(PrimitiveType primitive_type, VkShaderModule PipelineCache::GetGeometryShader(PrimitiveType primitive_type,

View File

@ -88,7 +88,7 @@ class PipelineCache {
bool is_line_mode); bool is_line_mode);
RegisterFile* register_file_ = nullptr; RegisterFile* register_file_ = nullptr;
VkDevice device_ = nullptr; ui::vulkan::VulkanDevice* device_ = nullptr;
// Reusable shader translator. // Reusable shader translator.
std::unique_ptr<ShaderTranslator> shader_translator_ = nullptr; std::unique_ptr<ShaderTranslator> shader_translator_ = nullptr;

View File

@ -12,6 +12,7 @@
#include "xenia/base/assert.h" #include "xenia/base/assert.h"
#include "xenia/base/logging.h" #include "xenia/base/logging.h"
#include "xenia/base/math.h" #include "xenia/base/math.h"
#include "xenia/ui/vulkan/vulkan_device.h"
#include "xenia/ui/vulkan/vulkan_util.h" #include "xenia/ui/vulkan/vulkan_util.h"
namespace xe { namespace xe {
@ -20,14 +21,14 @@ namespace vulkan {
using xe::ui::vulkan::CheckResult; using xe::ui::vulkan::CheckResult;
VulkanShader::VulkanShader(VkDevice device, ShaderType shader_type, VulkanShader::VulkanShader(ui::vulkan::VulkanDevice* device,
uint64_t data_hash, const uint32_t* dword_ptr, ShaderType shader_type, uint64_t data_hash,
uint32_t dword_count) const uint32_t* dword_ptr, uint32_t dword_count)
: Shader(shader_type, data_hash, dword_ptr, dword_count), device_(device) {} : Shader(shader_type, data_hash, dword_ptr, dword_count), device_(device) {}
VulkanShader::~VulkanShader() { VulkanShader::~VulkanShader() {
if (shader_module_) { if (shader_module_) {
vkDestroyShaderModule(device_, shader_module_, nullptr); vkDestroyShaderModule(*device_, shader_module_, nullptr);
shader_module_ = nullptr; shader_module_ = nullptr;
} }
} }
@ -45,9 +46,12 @@ bool VulkanShader::Prepare() {
shader_info.pCode = shader_info.pCode =
reinterpret_cast<const uint32_t*>(translated_binary_.data()); reinterpret_cast<const uint32_t*>(translated_binary_.data());
auto status = auto status =
vkCreateShaderModule(device_, &shader_info, nullptr, &shader_module_); vkCreateShaderModule(*device_, &shader_info, nullptr, &shader_module_);
CheckResult(status, "vkCreateShaderModule"); CheckResult(status, "vkCreateShaderModule");
device_->DbgSetObjectName(uint64_t(shader_module_),
VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT,
xe::format_string("%.16llX", ucode_data_hash()));
return status == VK_SUCCESS; return status == VK_SUCCESS;
} }

View File

@ -21,8 +21,9 @@ namespace vulkan {
class VulkanShader : public Shader { class VulkanShader : public Shader {
public: public:
VulkanShader(VkDevice device, ShaderType shader_type, uint64_t data_hash, VulkanShader(ui::vulkan::VulkanDevice* device, ShaderType shader_type,
const uint32_t* dword_ptr, uint32_t dword_count); uint64_t data_hash, const uint32_t* dword_ptr,
uint32_t dword_count);
~VulkanShader() override; ~VulkanShader() override;
// Available only if the shader is_valid and has been prepared. // Available only if the shader is_valid and has been prepared.
@ -31,7 +32,7 @@ class VulkanShader : public Shader {
bool Prepare(); bool Prepare();
private: private:
VkDevice device_ = nullptr; ui::vulkan::VulkanDevice* device_ = nullptr;
VkShaderModule shader_module_ = nullptr; VkShaderModule shader_module_ = nullptr;
}; };