diff --git a/src/xenia/gpu/d3d12/pipeline_cache.cc b/src/xenia/gpu/d3d12/pipeline_cache.cc index 1242229e8..bd089c30b 100644 --- a/src/xenia/gpu/d3d12/pipeline_cache.cc +++ b/src/xenia/gpu/d3d12/pipeline_cache.cc @@ -1140,10 +1140,10 @@ bool PipelineCache::TranslateAnalyzedShader( if (shader.EnterBindingLayoutUserUIDSetup()) { const std::vector& texture_bindings = shader.GetTextureBindingsAfterTranslation(); - uint32_t texture_binding_count = uint32_t(texture_bindings.size()); + size_t texture_binding_count = texture_bindings.size(); const std::vector& sampler_bindings = shader.GetSamplerBindingsAfterTranslation(); - uint32_t sampler_binding_count = uint32_t(sampler_bindings.size()); + size_t sampler_binding_count = sampler_bindings.size(); assert_false(bindless_resources_used_ && texture_binding_count + sampler_binding_count > D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * 4); @@ -1154,13 +1154,13 @@ bool PipelineCache::TranslateAnalyzedShader( texture_binding_layout_hash = XXH3_64bits(texture_bindings.data(), texture_binding_layout_bytes); } - uint32_t bindless_sampler_count = + size_t bindless_sampler_count = bindless_resources_used_ ? sampler_binding_count : 0; uint64_t bindless_sampler_layout_hash = 0; if (bindless_sampler_count) { XXH3_state_t hash_state; XXH3_64bits_reset(&hash_state); - for (uint32_t i = 0; i < bindless_sampler_count; ++i) { + for (size_t i = 0; i < bindless_sampler_count; ++i) { XXH3_64bits_update( &hash_state, &sampler_bindings[i].bindless_descriptor_index, sizeof(sampler_bindings[i].bindless_descriptor_index)); @@ -1178,11 +1178,10 @@ bool PipelineCache::TranslateAnalyzedShader( kLayoutUIDEmpty == 0, "Empty layout UID is assumed to be 0 because for bindful samplers, the " "UID is their count"); - size_t sampler_binding_layout_uid = bindless_resources_used_ - ? kLayoutUIDEmpty - : size_t(sampler_binding_count); + size_t sampler_binding_layout_uid = + bindless_resources_used_ ? kLayoutUIDEmpty : sampler_binding_count; if (texture_binding_count || bindless_sampler_count) { - std::lock_guard layouts_mutex_(layouts_mutex_); + std::lock_guard layouts_lock(layouts_mutex_); if (texture_binding_count) { auto found_range = texture_binding_layout_map_.equal_range( texture_binding_layout_hash); @@ -1225,7 +1224,7 @@ bool PipelineCache::TranslateAnalyzedShader( sampler_binding_layout_uid = it->second.uid; const uint32_t* vector_bindless_sampler_layout = bindless_sampler_layouts_.data() + it->second.vector_span_offset; - for (uint32_t i = 0; i < bindless_sampler_count; ++i) { + for (size_t i = 0; i < bindless_sampler_count; ++i) { if (vector_bindless_sampler_layout[i] != sampler_bindings[i].bindless_descriptor_index) { sampler_binding_layout_uid = kLayoutUIDEmpty; @@ -1250,7 +1249,7 @@ bool PipelineCache::TranslateAnalyzedShader( sampler_binding_count); uint32_t* vector_bindless_sampler_layout = bindless_sampler_layouts_.data() + new_uid.vector_span_offset; - for (uint32_t i = 0; i < bindless_sampler_count; ++i) { + for (size_t i = 0; i < bindless_sampler_count; ++i) { vector_bindless_sampler_layout[i] = sampler_bindings[i].bindless_descriptor_index; } diff --git a/src/xenia/gpu/dxbc_shader_translator.cc b/src/xenia/gpu/dxbc_shader_translator.cc index 4bb8c918e..513e46887 100644 --- a/src/xenia/gpu/dxbc_shader_translator.cc +++ b/src/xenia/gpu/dxbc_shader_translator.cc @@ -2428,7 +2428,7 @@ void DxbcShaderTranslator::WriteResourceDefinition() { } else { for (uint32_t i = 0; i < uint32_t(sampler_bindings_.size()); ++i) { 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 { for (TextureBinding& texture_binding : texture_bindings_) { texture_binding.bindful_srv_rdef_name_ptr = name_ptr; - name_ptr += dxbc::AppendAlignedString(shader_object_, - texture_binding.name.c_str()); + name_ptr += dxbc::AppendAlignedString( + shader_object_, texture_binding.bindful_name.c_str()); } } uint32_t shared_memory_uav_name_ptr = name_ptr; @@ -2495,8 +2495,8 @@ void DxbcShaderTranslator::WriteResourceDefinition() { sampler.bind_point = uint32_t(i); sampler.bind_count = 1; sampler.id = uint32_t(i); - sampler_current_name_ptr += - dxbc::GetAlignedStringLength(sampler_bindings_[i].name.c_str()); + sampler_current_name_ptr += dxbc::GetAlignedStringLength( + sampler_bindings_[i].bindful_name.c_str()); } } } diff --git a/src/xenia/gpu/dxbc_shader_translator.h b/src/xenia/gpu/dxbc_shader_translator.h index 9e029cb59..726f96cc2 100644 --- a/src/xenia/gpu/dxbc_shader_translator.h +++ b/src/xenia/gpu/dxbc_shader_translator.h @@ -429,7 +429,7 @@ class DxbcShaderTranslator : public ShaderTranslator { // descriptor handling simplicity. xenos::FetchOpDimension dimension; bool is_signed; - std::string name; + std::string bindful_name; }; // 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 mip_filter; xenos::AnisoFilter aniso_filter; - std::string name; + std::string bindful_name; }; // Unordered access view bindings in space 0. diff --git a/src/xenia/gpu/dxbc_shader_translator_fetch.cc b/src/xenia/gpu/dxbc_shader_translator_fetch.cc index 016841bc5..4a84119f8 100644 --- a/src/xenia/gpu/dxbc_shader_translator_fetch.cc +++ b/src/xenia/gpu/dxbc_shader_translator_fetch.cc @@ -487,7 +487,7 @@ uint32_t DxbcShaderTranslator::FindOrAddTextureBinding( } uint32_t srv_index = UINT32_MAX; 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 && texture_binding.dimension == dimension && texture_binding.is_signed == is_signed) { @@ -499,11 +499,25 @@ uint32_t DxbcShaderTranslator::FindOrAddTextureBinding( return kMaxTextureBindings - 1; } 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_) { new_texture_binding.bindful_srv_index = srv_count_++; texture_bindings_for_bindful_srv_indices_.insert( {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 { 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.dimension = dimension; 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; } @@ -558,23 +558,7 @@ uint32_t DxbcShaderTranslator::FindOrAddSamplerBinding( assert_always(); return kMaxSamplerBindings - 1; } - std::ostringstream name; - 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; + SamplerBinding& new_sampler_binding = sampler_bindings_.emplace_back(); // Consistently 0 if not bindless as it may be used for hashing. new_sampler_binding.bindless_descriptor_index = bindless_resources_used_ ? GetBindlessResourceCount() : 0; @@ -583,10 +567,26 @@ uint32_t DxbcShaderTranslator::FindOrAddSamplerBinding( new_sampler_binding.min_filter = min_filter; new_sampler_binding.mip_filter = mip_filter; new_sampler_binding.aniso_filter = aniso_filter; - new_sampler_binding.name = name.str(); - uint32_t sampler_binding_index = uint32_t(sampler_bindings_.size()); - sampler_bindings_.emplace_back(std::move(new_sampler_binding)); - return sampler_binding_index; + if (!bindless_resources_used_) { + std::ostringstream name; + name << "xe_sampler" << fetch_constant; + 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(