fix(vulkan): bind exact blend pixel and draw table ranges
- commit
- c9165de893f9367d7a0ba234a3490155438e3f4a
- author
- brice · · 2026-09-26 09:29 UTC
- parent
- 4121259
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +7 -6
M internal/adapters/vulkan/blend.go +5 -5
| @@ -132,12 +132,12 @@ func (r *Renderer) destroyBlend() { | |||
| 132 | 132 | *b = blendPipeline{} | |
| 133 | 133 | } | |
| 134 | 134 | ||
| 135 | - | // bindStaging points the set at the staging buffer: blended pixels in | |
| 136 | - | // [0, tableOffset), the draw table from tableOffset. | |
| 137 | - | func (r *Renderer) bindStaging(tableOffset int) { | |
| 135 | + | // bindStaging points the set at the staging buffer: pixels blended | |
| 136 | + | // pixel bytes from 0, and the draw table of n entries at tableOffset. | |
| 137 | + | func (r *Renderer) bindStaging(pixels, tableOffset, n int) { | |
| 138 | 138 | infos := []vk.DescriptorBufferInfo{ | |
| 139 | - | {Buffer: r.staging, Range: vk.DeviceSize(max(tableOffset, 4))}, | |
| 140 | - | {Buffer: r.staging, Offset: vk.DeviceSize(tableOffset), Range: wholeSize}, | |
| 139 | + | {Buffer: r.staging, Range: vk.DeviceSize(max(pixels, 4))}, | |
| 140 | + | {Buffer: r.staging, Offset: vk.DeviceSize(tableOffset), Range: vk.DeviceSize(n * drawSize)}, | |
| 141 | 141 | } | |
| 142 | 142 | writes := []vk.WriteDescriptorSet{ | |
| 143 | 143 | {SType: vk.StructureTypeWriteDescriptorSet, DstSet: r.blend.set, DstBinding: 0, DescriptorCount: 1, DescriptorType: vk.DescriptorTypeStorageBuffer, BufferInfo: &infos[0]}, | |
| @@ -132,12 +132,12 @@ func (r *Renderer) destroyBlend() { | |||||
| 132 | *b = blendPipeline{} | 132 | *b = blendPipeline{} | ||
| 133 | } | 133 | } | ||
| 134 | 134 | ||||
| 135 | - | // bindStaging points the set at the staging buffer: blended pixels in | 135 | + | // bindStaging points the set at the staging buffer: pixels blended |
| 136 | - | // [0, tableOffset), the draw table from tableOffset. | 136 | + | // pixel bytes from 0, and the draw table of n entries at tableOffset. |
| 137 | - | func (r *Renderer) bindStaging(tableOffset int) { | 137 | + | func (r *Renderer) bindStaging(pixels, tableOffset, n int) { |
| 138 | infos := []vk.DescriptorBufferInfo{ | 138 | infos := []vk.DescriptorBufferInfo{ | ||
| 139 | - | {Buffer: r.staging, Range: vk.DeviceSize(max(tableOffset, 4))}, | 139 | + | {Buffer: r.staging, Range: vk.DeviceSize(max(pixels, 4))}, |
| 140 | - | {Buffer: r.staging, Offset: vk.DeviceSize(tableOffset), Range: wholeSize}, | 140 | + | {Buffer: r.staging, Offset: vk.DeviceSize(tableOffset), Range: vk.DeviceSize(n * drawSize)}, |
| 141 | } | 141 | } | ||
| 142 | writes := []vk.WriteDescriptorSet{ | 142 | writes := []vk.WriteDescriptorSet{ | ||
| 143 | {SType: vk.StructureTypeWriteDescriptorSet, DstSet: r.blend.set, DstBinding: 0, DescriptorCount: 1, DescriptorType: vk.DescriptorTypeStorageBuffer, BufferInfo: &infos[0]}, | 143 | {SType: vk.StructureTypeWriteDescriptorSet, DstSet: r.blend.set, DstBinding: 0, DescriptorCount: 1, DescriptorType: vk.DescriptorTypeStorageBuffer, BufferInfo: &infos[0]}, | ||
M internal/adapters/vulkan/renderer.go +2 -1
| @@ -598,6 +598,7 @@ func (r *Renderer) Render(s ports.Scene, contents map[ports.WindowID]ports.Surfa | |||
| 598 | 598 | blends++ | |
| 599 | 599 | } | |
| 600 | 600 | } | |
| 601 | + | pixelBytes := used | |
| 601 | 602 | tableOffset := (used + r.align - 1) / r.align * r.align | |
| 602 | 603 | used = tableOffset + blends*drawSize | |
| 603 | 604 | for k := range uploads { | |
| @@ -611,7 +612,7 @@ func (r *Renderer) Render(s ports.Scene, contents map[ports.WindowID]ports.Surfa | |||
| 611 | 612 | } | |
| 612 | 613 | data := unsafe.Slice((*byte)(r.stagingMapped), r.stagingSize) | |
| 613 | 614 | if blends > 0 { | |
| 614 | - | r.bindStaging(tableOffset) | |
| 615 | + | r.bindStaging(pixelBytes, tableOffset, blends) | |
| 615 | 616 | i := 0 | |
| 616 | 617 | for k := range uploads { | |
| 617 | 618 | if uploads[k].blend { | |
| @@ -598,6 +598,7 @@ func (r *Renderer) Render(s ports.Scene, contents map[ports.WindowID]ports.Surfa | |||||
| 598 | blends++ | 598 | blends++ | ||
| 599 | } | 599 | } | ||
| 600 | } | 600 | } | ||
| 601 | + | pixelBytes := used | |||
| 601 | tableOffset := (used + r.align - 1) / r.align * r.align | 602 | tableOffset := (used + r.align - 1) / r.align * r.align | ||
| 602 | used = tableOffset + blends*drawSize | 603 | used = tableOffset + blends*drawSize | ||
| 603 | for k := range uploads { | 604 | for k := range uploads { | ||
| @@ -611,7 +612,7 @@ func (r *Renderer) Render(s ports.Scene, contents map[ports.WindowID]ports.Surfa | |||||
| 611 | } | 612 | } | ||
| 612 | data := unsafe.Slice((*byte)(r.stagingMapped), r.stagingSize) | 613 | data := unsafe.Slice((*byte)(r.stagingMapped), r.stagingSize) | ||
| 613 | if blends > 0 { | 614 | if blends > 0 { | ||
| 614 | - | r.bindStaging(tableOffset) | 615 | + | r.bindStaging(pixelBytes, tableOffset, blends) |
| 615 | i := 0 | 616 | i := 0 | ||
| 616 | for k := range uploads { | 617 | for k := range uploads { | ||
| 617 | if uploads[k].blend { | 618 | if uploads[k].blend { | ||