Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
squidbus committed Feb 16, 2025
1 parent 556b7a7 commit a0a3e8e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,9 @@ static Id EmitLoadBufferBoundsCheck(EmitContext& ctx, Id index, Id buffer_size,
auto zero_value = is_float ? ctx.f32_zero_value : ctx.u32_zero_value;
if (N > 1) {
compare_index = ctx.OpIAdd(ctx.U32[1], index, ctx.ConstU32(N - 1));
boost::container::static_vector<Id, N> zero_ids;
for (u32 i = 0; i < N; i++) {
zero_ids.push_back(zero_value);
}
zero_value = ctx.OpCompositeConstruct(result_type, zero_ids);
std::array<Id, N> zero_ids;
zero_ids.fill(zero_value);
zero_value = ctx.ConstantComposite(result_type, zero_ids);
}
const Id in_bounds = ctx.OpULessThan(ctx.U1[1], compare_index, buffer_size);
return ctx.OpSelect(result_type, in_bounds, result, zero_value);
Expand Down
12 changes: 7 additions & 5 deletions src/shader_recompiler/backend/spirv/spirv_emit_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ Id EmitContext::GetBufferSize(const u32 sharp_idx) {
}

void EmitContext::DefineBufferProperties() {
for (BufferDefinition& buffer : buffers) {
for (u32 i = 0; i < buffers.size(); i++) {
BufferDefinition& buffer = buffers[i];
if (buffer.buffer_type != BufferType::Guest) {
continue;
}
Expand All @@ -230,10 +231,11 @@ void EmitContext::DefineBufferProperties() {
// Only need to load size if performing bounds checks and the buffer is both guest and not
// inline.
if (!profile.supports_robust_buffer_access && buffer.buffer_type == BufferType::Guest) {
if (buffer.desc.sharp_idx == std::numeric_limits<u32>::max()) {
buffer.size = ConstU32(buffer.desc.inline_cbuf.GetSize());
const BufferResource& desc = info.buffers[i];
if (desc.sharp_idx == std::numeric_limits<u32>::max()) {
buffer.size = ConstU32(desc.inline_cbuf.GetSize());
} else {
buffer.size = GetBufferSize(buffer.desc.sharp_idx);
buffer.size = GetBufferSize(desc.sharp_idx);
}
Name(buffer.size, fmt::format("buf{}_size", binding));
buffer.size_shorts = OpShiftRightLogical(U32[1], buffer.size, ConstU32(1U));
Expand Down Expand Up @@ -715,7 +717,7 @@ void EmitContext::DefineBuffers() {
const bool is_storage = desc.IsStorage(buf_sharp, profile);

// Define aliases depending on the shader usage.
auto& spv_buffer = buffers.emplace_back(binding.buffer++, desc.buffer_type, desc);
auto& spv_buffer = buffers.emplace_back(binding.buffer++, desc.buffer_type);
if (True(desc.used_types & IR::Type::U32)) {
spv_buffer[BufferAlias::U32] =
DefineBuffer(is_storage, desc.is_written, 2, desc.buffer_type, U32[1]);
Expand Down
1 change: 0 additions & 1 deletion src/shader_recompiler/backend/spirv/spirv_emit_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ class EmitContext final : public Sirit::Module {
struct BufferDefinition {
u32 binding;
BufferType buffer_type;
const BufferResource& desc;
Id offset;
Id offset_dwords;
Id size;
Expand Down

0 comments on commit a0a3e8e

Please sign in to comment.