Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan: Fix a bug in current DCE about dynamic offsets #2234

Merged
merged 1 commit into from
Sep 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions gapis/api/vulkan/footprint_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,13 +857,17 @@ func (ds *descriptorSet) setDescriptor(ctx context.Context,
d.img = vkImg
d.buf = vkBuf
d.sampler = sampler
d.ty = ty
d.bufRng = rng
d.bufOffset = boundOffset
if ty == VkDescriptorType_VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC ||
ty == VkDescriptorType_VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC {
ds.dynamicDescriptorCount++
}
if d.ty == VkDescriptorType_VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC ||
d.ty == VkDescriptorType_VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC {
ds.dynamicDescriptorCount--
}
d.ty = ty
} else {
log.E(ctx, "FootprintBuilder: Not *descriptor type in descriptorSet: %v, with "+
"binding: %v, array index: %v", *ds, bi, di)
Expand Down Expand Up @@ -1034,11 +1038,15 @@ type boundDescriptorSet struct {
}

func newBoundDescriptorSet(ctx context.Context, bh *dependencygraph.Behavior,
ds *descriptorSet, getDynamicOffset func() uint32) *boundDescriptorSet {
ds *descriptorSet, dynamicOffsets []uint32) *boundDescriptorSet {
bds := &boundDescriptorSet{descriptorSet: ds}
bds.dynamicOffsets = make([]uint32, ds.dynamicDescriptorCount)
for i := range bds.dynamicOffsets {
bds.dynamicOffsets[i] = getDynamicOffset()
dOffsetCount := len(dynamicOffsets)
if len(bds.dynamicOffsets) < dOffsetCount {
dOffsetCount = len(bds.dynamicOffsets)
}
for i := 0; i < dOffsetCount; i++ {
bds.dynamicOffsets[i] = dynamicOffsets[i]
}
write(ctx, bh, bds)
return bds
Expand Down Expand Up @@ -2278,28 +2286,17 @@ func (vb *FootprintBuilder) BuildFootprint(ctx context.Context,
}
firstSet := cmd.FirstSet()
dOffsets := []uint32{}
dOffsetsLeft := 0
if cmd.DynamicOffsetCount() > uint32(0) {
dOffsets = cmd.PDynamicOffsets().Slice(0, uint64(cmd.DynamicOffsetCount()),
l).MustRead(ctx, cmd, s, nil)
dOffsetsLeft = len(dOffsets)
}
getDynamicOffset := func() uint32 {
if dOffsetsLeft > 0 {
d := dOffsets[len(dOffsets)-dOffsetsLeft]
dOffsetsLeft--
return d
}
log.E(ctx, "FootprintBuilder: The number of dynamic offsets does not match with the number of dynamic descriptors")
return 0
}
cbc := vb.newCommand(ctx, bh, cmd.CommandBuffer())
cbc.behave = func(sc submittedCommand,
execInfo *queueExecutionState) {
cbh := sc.cmd.newBehavior(ctx, sc, execInfo)
for i, ds := range dss {
set := firstSet + uint32(i)
execInfo.currentCmdBufState.descriptorSets[set] = newBoundDescriptorSet(ctx, cbh, ds, getDynamicOffset)
execInfo.currentCmdBufState.descriptorSets[set] = newBoundDescriptorSet(ctx, cbh, ds, dOffsets)
}
ft.AddBehavior(ctx, cbh)
}
Expand Down