bind buffers correctly

This commit is contained in:
Samuliak 2024-10-05 16:27:00 +02:00
parent c24e3c23ff
commit dac285f6d9
No known key found for this signature in database
5 changed files with 12 additions and 20 deletions

View file

@ -342,6 +342,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
void EmitContext::DefineInputs(Bindings& bindings) {
// Constant buffers
bindings.uniform_buffer = 0;
for (const auto& desc : info.constant_buffer_descriptors) {
const u32 cbuf_used_size{Common::DivCeil(info.constant_buffer_used_sizes[desc.index], 16U)};
const u32 cbuf_binding_size{info.uses_global_memory ? 0x1000U : cbuf_used_size};
@ -362,6 +363,7 @@ void EmitContext::DefineInputs(Bindings& bindings) {
// TODO
// Storage space buffers
bindings.uniform_buffer = 15;
u32 index{};
for (const auto& desc : info.storage_buffers_descriptors) {
if (has_at_least_one_input)

View file

@ -109,7 +109,7 @@ void BufferCacheRuntime::BindVertexBuffers(VideoCommon::HostBindings<Buffer>& bi
void BufferCacheRuntime::BindBuffer(size_t stage, u32 binding_index, MTL::Buffer* buffer,
u32 offset, u32 size) {
command_recorder.SetBuffer(stage, buffer, binding_index, offset);
command_recorder.SetBuffer(stage, buffer, offset, binding_index);
}
void BufferCacheRuntime::ReserveNullBuffer() {

View file

@ -124,6 +124,7 @@ public:
std::span<u8> BindMappedUniformBuffer(size_t stage, u32 binding_index, u32 size) {
const StagingBufferRef ref = staging_pool.Request(size, MemoryUsage::Upload);
BindBuffer(stage, binding_index, ref.buffer, static_cast<u32>(ref.offset), size);
return ref.mapped_span;
}

View file

@ -20,6 +20,7 @@ void CommandRecorder::BeginOrContinueRenderPass(MTL::RenderPassDescriptor* rende
render_state.render_pass = render_pass;
should_reset_bound_resources = true;
}
const auto bind_resources{[&](size_t stage) {
// Buffers
for (u8 i = 0; i < MAX_BUFFERS; i++) {
@ -28,17 +29,18 @@ void CommandRecorder::BeginOrContinueRenderPass(MTL::RenderPassDescriptor* rende
(bound_buffer.needs_update || should_reset_bound_resources)) {
switch (stage) {
case 0:
GetRenderCommandEncoderUnchecked()->setVertexBuffer(bound_buffer.buffer, i,
bound_buffer.offset);
GetRenderCommandEncoderUnchecked()->setVertexBuffer(bound_buffer.buffer,
bound_buffer.offset, i);
break;
case 4:
GetRenderCommandEncoderUnchecked()->setFragmentBuffer(bound_buffer.buffer, i,
bound_buffer.offset);
GetRenderCommandEncoderUnchecked()->setFragmentBuffer(bound_buffer.buffer,
bound_buffer.offset, i);
break;
}
bound_buffer.needs_update = false;
}
}
// Textures
for (u8 i = 0; i < MAX_TEXTURES; i++) {
auto& bound_texture = render_state.textures[stage][i];
@ -56,6 +58,7 @@ void CommandRecorder::BeginOrContinueRenderPass(MTL::RenderPassDescriptor* rende
bound_texture.needs_update = false;
}
}
// Sampler states
for (u8 i = 0; i < MAX_SAMPLERS; i++) {
auto& bound_sampler_state = render_state.sampler_states[stage][i];
@ -78,20 +81,6 @@ void CommandRecorder::BeginOrContinueRenderPass(MTL::RenderPassDescriptor* rende
bind_resources(0);
bind_resources(4);
if (should_reset_bound_resources) {
for (size_t stage = 0; stage < 5; stage++) {
for (u8 i = 0; i < MAX_BUFFERS; i++) {
render_state.buffers[stage][i].buffer = nullptr;
}
for (u8 i = 0; i < MAX_TEXTURES; i++) {
render_state.textures[stage][i].texture = nullptr;
}
for (u8 i = 0; i < MAX_SAMPLERS; i++) {
render_state.sampler_states[stage][i].sampler_state = nullptr;
}
}
}
}
void CommandRecorder::RequireComputeEncoder() {

View file

@ -114,7 +114,7 @@ public:
}
}
inline void SetBuffer(size_t stage, MTL::Buffer* buffer, size_t index, size_t offset) {
inline void SetBuffer(size_t stage, MTL::Buffer* buffer, size_t offset, size_t index) {
auto& bound_buffer = render_state.buffers[stage][index];
if (buffer != bound_buffer.buffer) {
bound_buffer = {true, buffer, offset};