Permalink
Browse files

Vulkan: Show samplers in "shader debug"

  • Loading branch information...
hrydgard committed Dec 6, 2017
1 parent 3b78687 commit 2ebae034a49db1e9a18614bbdc2a461088b2980f
@@ -121,7 +121,7 @@ class DenseHashMap {
}
template<class T>
inline void Iterate(T func) {
inline void Iterate(T func) const {
for (size_t i = 0; i < map.size(); i++) {
if (state[i] == BucketState::TAKEN) {
func(map[i].key, map[i].value);
@@ -267,7 +267,7 @@ class PrehashMap {
}
template<class T>
void Iterate(T func) {
void Iterate(T func) const {
for (size_t i = 0; i < map.size(); i++) {
if (state[i] == BucketState::TAKEN) {
func(map[i].hash, map[i].value);
@@ -35,6 +35,7 @@ enum DebugShaderType {
SHADER_TYPE_VERTEXLOADER = 3, // Not really a shader, but might as well re-use this mechanism
SHADER_TYPE_PIPELINE = 4, // Vulkan and DX12 combines a bunch of state into pipeline objects. Might as well make them inspectable.
SHADER_TYPE_DEPAL = 5,
SHADER_TYPE_SAMPLER = 6, // Not really a shader either. Need to rename this enum...
};
enum DebugShaderStringType {
@@ -78,6 +78,13 @@ struct SamplerCacheKey {
bool operator < (const SamplerCacheKey &other) const {
return fullKey < other.fullKey;
}
void ToString(std::string *str) const {
str->resize(sizeof(*this));
memcpy(&(*str)[0], this, sizeof(*this));
}
void FromString(const std::string &str) {
memcpy(this, &str[0], sizeof(*this));
}
};
// TODO: Shrink this struct. There is some fluff.
@@ -715,8 +715,12 @@ std::vector<std::string> GPU_Vulkan::DebugGetShaderIDs(DebugShaderType type) {
} else if (type == SHADER_TYPE_DEPAL) {
///...
return std::vector<std::string>();
} else {
} else if (type == SHADER_TYPE_VERTEX || type == SHADER_TYPE_FRAGMENT) {
return shaderManagerVulkan_->DebugGetShaderIDs(type);
} else if (type == SHADER_TYPE_SAMPLER) {
return textureCacheVulkan_->DebugGetSamplerIDs();
} else {
return std::vector<std::string>();
}
}
@@ -727,7 +731,11 @@ std::string GPU_Vulkan::DebugGetShaderString(std::string id, DebugShaderType typ
return pipelineManager_->DebugGetObjectString(id, type, stringType);
} else if (type == SHADER_TYPE_DEPAL) {
return "";
} else {
} else if (type == SHADER_TYPE_SAMPLER) {
return textureCacheVulkan_->DebugGetSamplerString(id, stringType);
} else if (type == SHADER_TYPE_VERTEX || type == SHADER_TYPE_FRAGMENT) {
return shaderManagerVulkan_->DebugGetShaderString(id, type, stringType);
} else {
return std::string();
}
}
@@ -109,6 +109,20 @@ VkSampler SamplerCache::GetOrCreateSampler(const SamplerCacheKey &key) {
return sampler;
}
std::string SamplerCache::DebugGetSamplerString(std::string id, DebugShaderStringType stringType) {
SamplerCacheKey key;
key.FromString(id);
return StringFromFormat("%s/%s mag:%s min:%s mip:%s maxLod:%f minLod:%f bias:%f",
key.sClamp ? "Clamp" : "Wrap",
key.tClamp ? "Clamp" : "Wrap",
key.magFilt ? "Linear" : "Nearest",
key.minFilt ? "Linear" : "Nearest",
key.mipFilt ? "Linear" : "Nearest",
key.maxLevel / 256.0f,
key.minLevel / 256.0f,
key.lodBias / 256.0f);
}
void SamplerCache::DeviceLost() {
cache_.Iterate([&](const SamplerCacheKey &key, VkSampler sampler) {
vulkan_->Delete().QueueDeleteSampler(sampler);
@@ -120,6 +134,16 @@ void SamplerCache::DeviceRestore(VulkanContext *vulkan) {
vulkan_ = vulkan;
}
std::vector<std::string> SamplerCache::DebugGetSamplerIDs() const {
std::vector<std::string> ids;
cache_.Iterate([&](const SamplerCacheKey &id, VkSampler sampler) {
std::string idstr;
id.ToString(&idstr);
ids.push_back(idstr);
});
return ids;
}
TextureCacheVulkan::TextureCacheVulkan(Draw::DrawContext *draw, VulkanContext *vulkan)
: TextureCacheCommon(draw),
vulkan_(vulkan),
@@ -823,3 +847,11 @@ void TextureCacheVulkan::GetStats(char *ptr, size_t size) {
snprintf(ptr, size, "Alloc: %d slabs\nSlab min/max: %d/%d\nAlloc usage: %d%%",
allocator_->GetBlockCount(), allocator_->GetMinSlabSize(), allocator_->GetMaxSlabSize(), allocator_->ComputeUsagePercent());
}
std::vector<std::string> TextureCacheVulkan::DebugGetSamplerIDs() const {
return samplerCache_.DebugGetSamplerIDs();
}
std::string TextureCacheVulkan::DebugGetSamplerString(std::string id, DebugShaderStringType stringType) {
return samplerCache_.DebugGetSamplerString(id, stringType);
}
@@ -56,6 +56,9 @@ class SamplerCache {
void DeviceLost();
void DeviceRestore(VulkanContext *vulkan);
std::vector<std::string> DebugGetSamplerIDs() const;
std::string DebugGetSamplerString(std::string id, DebugShaderStringType stringType);
private:
VulkanContext *vulkan_;
DenseHashMap<SamplerCacheKey, VkSampler, (VkSampler)VK_NULL_HANDLE> cache_;
@@ -111,6 +114,9 @@ class TextureCacheVulkan : public TextureCacheCommon {
VulkanDeviceAllocator *GetAllocator() { return allocator_; }
std::vector<std::string> DebugGetSamplerIDs() const;
std::string DebugGetSamplerString(std::string id, DebugShaderStringType stringType);
protected:
void BindTexture(TexCacheEntry *entry) override;
void Unbind() override;
@@ -921,6 +921,7 @@ struct { DebugShaderType type; const char *name; } shaderTypes[] = {
{ SHADER_TYPE_VERTEXLOADER, "VertexLoader" },
{ SHADER_TYPE_PIPELINE, "Pipeline" },
{ SHADER_TYPE_DEPAL, "Depal" },
{ SHADER_TYPE_SAMPLER, "Sampler" },
};
void ShaderListScreen::CreateViews() {

0 comments on commit 2ebae03

Please sign in to comment.