[DXBC] Cleanup texture/sampler name setting

This commit is contained in:
Triang3l 2022-05-17 22:30:55 +03:00
parent 533de3b477
commit 7675b6b140
3 changed files with 44 additions and 44 deletions

View File

@ -2428,7 +2428,7 @@ void DxbcShaderTranslator::WriteResourceDefinition() {
} else { } else {
for (uint32_t i = 0; i < uint32_t(sampler_bindings_.size()); ++i) { for (uint32_t i = 0; i < uint32_t(sampler_bindings_.size()); ++i) {
name_ptr += dxbc::AppendAlignedString( name_ptr += dxbc::AppendAlignedString(
shader_object_, sampler_bindings_[i].name.c_str()); shader_object_, sampler_bindings_[i].bindful_name.c_str());
} }
} }
} }
@ -2456,8 +2456,8 @@ void DxbcShaderTranslator::WriteResourceDefinition() {
} else { } else {
for (TextureBinding& texture_binding : texture_bindings_) { for (TextureBinding& texture_binding : texture_bindings_) {
texture_binding.bindful_srv_rdef_name_ptr = name_ptr; texture_binding.bindful_srv_rdef_name_ptr = name_ptr;
name_ptr += dxbc::AppendAlignedString(shader_object_, name_ptr += dxbc::AppendAlignedString(
texture_binding.name.c_str()); shader_object_, texture_binding.bindful_name.c_str());
} }
} }
uint32_t shared_memory_uav_name_ptr = name_ptr; uint32_t shared_memory_uav_name_ptr = name_ptr;
@ -2495,8 +2495,8 @@ void DxbcShaderTranslator::WriteResourceDefinition() {
sampler.bind_point = uint32_t(i); sampler.bind_point = uint32_t(i);
sampler.bind_count = 1; sampler.bind_count = 1;
sampler.id = uint32_t(i); sampler.id = uint32_t(i);
sampler_current_name_ptr += sampler_current_name_ptr += dxbc::GetAlignedStringLength(
dxbc::GetAlignedStringLength(sampler_bindings_[i].name.c_str()); sampler_bindings_[i].bindful_name.c_str());
} }
} }
} }

View File

@ -429,7 +429,7 @@ class DxbcShaderTranslator : public ShaderTranslator {
// descriptor handling simplicity. // descriptor handling simplicity.
xenos::FetchOpDimension dimension; xenos::FetchOpDimension dimension;
bool is_signed; bool is_signed;
std::string name; std::string bindful_name;
}; };
// Arbitrary limit - there can't be more than 2048 in a shader-visible // Arbitrary limit - there can't be more than 2048 in a shader-visible
@ -450,7 +450,7 @@ class DxbcShaderTranslator : public ShaderTranslator {
xenos::TextureFilter min_filter; xenos::TextureFilter min_filter;
xenos::TextureFilter mip_filter; xenos::TextureFilter mip_filter;
xenos::AnisoFilter aniso_filter; xenos::AnisoFilter aniso_filter;
std::string name; std::string bindful_name;
}; };
// Unordered access view bindings in space 0. // Unordered access view bindings in space 0.

View File

@ -487,7 +487,7 @@ uint32_t DxbcShaderTranslator::FindOrAddTextureBinding(
} }
uint32_t srv_index = UINT32_MAX; uint32_t srv_index = UINT32_MAX;
for (uint32_t i = 0; i < uint32_t(texture_bindings_.size()); ++i) { for (uint32_t i = 0; i < uint32_t(texture_bindings_.size()); ++i) {
TextureBinding& texture_binding = texture_bindings_[i]; const TextureBinding& texture_binding = texture_bindings_[i];
if (texture_binding.fetch_constant == fetch_constant && if (texture_binding.fetch_constant == fetch_constant &&
texture_binding.dimension == dimension && texture_binding.dimension == dimension &&
texture_binding.is_signed == is_signed) { texture_binding.is_signed == is_signed) {
@ -499,11 +499,25 @@ uint32_t DxbcShaderTranslator::FindOrAddTextureBinding(
return kMaxTextureBindings - 1; return kMaxTextureBindings - 1;
} }
uint32_t texture_binding_index = uint32_t(texture_bindings_.size()); uint32_t texture_binding_index = uint32_t(texture_bindings_.size());
TextureBinding new_texture_binding; TextureBinding& new_texture_binding = texture_bindings_.emplace_back();
if (!bindless_resources_used_) { if (!bindless_resources_used_) {
new_texture_binding.bindful_srv_index = srv_count_++; new_texture_binding.bindful_srv_index = srv_count_++;
texture_bindings_for_bindful_srv_indices_.insert( texture_bindings_for_bindful_srv_indices_.insert(
{new_texture_binding.bindful_srv_index, texture_binding_index}); {new_texture_binding.bindful_srv_index, texture_binding_index});
const char* dimension_name;
switch (dimension) {
case xenos::FetchOpDimension::k3DOrStacked:
dimension_name = "3d";
break;
case xenos::FetchOpDimension::kCube:
dimension_name = "cube";
break;
default:
dimension_name = "2d";
}
new_texture_binding.bindful_name =
fmt::format("xe_texture{}_{}_{}", fetch_constant, dimension_name,
is_signed ? 's' : 'u');
} else { } else {
new_texture_binding.bindful_srv_index = kBindingIndexUnallocated; new_texture_binding.bindful_srv_index = kBindingIndexUnallocated;
} }
@ -514,20 +528,6 @@ uint32_t DxbcShaderTranslator::FindOrAddTextureBinding(
new_texture_binding.fetch_constant = fetch_constant; new_texture_binding.fetch_constant = fetch_constant;
new_texture_binding.dimension = dimension; new_texture_binding.dimension = dimension;
new_texture_binding.is_signed = is_signed; new_texture_binding.is_signed = is_signed;
const char* dimension_name;
switch (dimension) {
case xenos::FetchOpDimension::k3DOrStacked:
dimension_name = "3d";
break;
case xenos::FetchOpDimension::kCube:
dimension_name = "cube";
break;
default:
dimension_name = "2d";
}
new_texture_binding.name = fmt::format("xe_texture{}_{}_{}", fetch_constant,
dimension_name, is_signed ? 's' : 'u');
texture_bindings_.emplace_back(std::move(new_texture_binding));
return texture_binding_index; return texture_binding_index;
} }
@ -558,23 +558,7 @@ uint32_t DxbcShaderTranslator::FindOrAddSamplerBinding(
assert_always(); assert_always();
return kMaxSamplerBindings - 1; return kMaxSamplerBindings - 1;
} }
std::ostringstream name; SamplerBinding& new_sampler_binding = sampler_bindings_.emplace_back();
name << "xe_sampler" << fetch_constant;
if (aniso_filter != xenos::AnisoFilter::kUseFetchConst) {
if (aniso_filter == xenos::AnisoFilter::kDisabled) {
name << "_a0";
} else {
name << "_a" << (1u << (uint32_t(aniso_filter) - 1));
}
}
if (aniso_filter == xenos::AnisoFilter::kDisabled ||
aniso_filter == xenos::AnisoFilter::kUseFetchConst) {
static const char* kFilterSuffixes[] = {"p", "l", "b", "f"};
name << "_" << kFilterSuffixes[uint32_t(mag_filter)]
<< kFilterSuffixes[uint32_t(min_filter)]
<< kFilterSuffixes[uint32_t(mip_filter)];
}
SamplerBinding new_sampler_binding;
// Consistently 0 if not bindless as it may be used for hashing. // Consistently 0 if not bindless as it may be used for hashing.
new_sampler_binding.bindless_descriptor_index = new_sampler_binding.bindless_descriptor_index =
bindless_resources_used_ ? GetBindlessResourceCount() : 0; bindless_resources_used_ ? GetBindlessResourceCount() : 0;
@ -583,10 +567,26 @@ uint32_t DxbcShaderTranslator::FindOrAddSamplerBinding(
new_sampler_binding.min_filter = min_filter; new_sampler_binding.min_filter = min_filter;
new_sampler_binding.mip_filter = mip_filter; new_sampler_binding.mip_filter = mip_filter;
new_sampler_binding.aniso_filter = aniso_filter; new_sampler_binding.aniso_filter = aniso_filter;
new_sampler_binding.name = name.str(); if (!bindless_resources_used_) {
uint32_t sampler_binding_index = uint32_t(sampler_bindings_.size()); std::ostringstream name;
sampler_bindings_.emplace_back(std::move(new_sampler_binding)); name << "xe_sampler" << fetch_constant;
return sampler_binding_index; if (aniso_filter == xenos::AnisoFilter::kDisabled ||
aniso_filter == xenos::AnisoFilter::kUseFetchConst) {
static const char kFilterSuffixes[] = {'p', 'l', 'b', 'f'};
name << '_' << kFilterSuffixes[uint32_t(mag_filter)]
<< kFilterSuffixes[uint32_t(min_filter)]
<< kFilterSuffixes[uint32_t(mip_filter)];
}
if (aniso_filter != xenos::AnisoFilter::kUseFetchConst) {
if (aniso_filter == xenos::AnisoFilter::kDisabled) {
name << "_a0";
} else {
name << "_a" << (UINT32_C(1) << (uint32_t(aniso_filter) - 1));
}
}
new_sampler_binding.bindful_name = name.str();
}
return uint32_t(sampler_bindings_.size() - 1);
} }
void DxbcShaderTranslator::ProcessTextureFetchInstruction( void DxbcShaderTranslator::ProcessTextureFetchInstruction(