Reland "Fix dynamic buffer offset issues on D3D12 backend"
Cannot reproduce failure on GTX1060 and GTX2080Ti with latest driver. So disable inherit test on compute shader and reland this patch Original change's description: > Fix dynamic buffer offset issues on D3D12 backend > > This patch fixes > 1. Inherit dynamic buffer offsets : dawn chooses vulkan > like inherit behaviour, so dynamic offsets need to be inherited. > This patch adds inherit dynamic offsets between pipelines support and > adds tests to cover it. > > 2. Dynamic offsets are skipped when groups have been set : in D3D12 > backend, when invoke SetBindGroup, dawn will check whether this group > has already been set and skip updating root signature if the answer is > yes. However, this behaviour will affect dynamic offsets update. With > the latest patch, we always update dynamic offsets, even if they didn't > change and adds tests to cover it. > > This patch also hit a dawn's issue about storage buffer validation in compute pass. > Currently the validation is a workaround to avoid access conflicts but will impact > using dynamic buffer offset in compute pipeline. Fix this issue is hard so disable > related test for now and will enable it after the issue been fixed. File dawn bug > 198 to track this > > BUG=dawn:55 BUG=dawn:55 Change-Id: Ia105786c035eafc6f68dcb54e6c1145b06c6a630 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9960 Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Shaobo Yan <shaobo.yan@intel.com>
This commit is contained in:
parent
3318caaa51
commit
b6d7c53708
|
@ -154,21 +154,24 @@ namespace dawn_native { namespace d3d12 {
|
||||||
uint32_t dynamicOffsetCount,
|
uint32_t dynamicOffsetCount,
|
||||||
uint64_t* dynamicOffsets,
|
uint64_t* dynamicOffsets,
|
||||||
bool force = false) {
|
bool force = false) {
|
||||||
if (mBindGroups[index] != group || force) {
|
// Usually, the application won't set the same offsets many times,
|
||||||
mBindGroups[index] = group;
|
// so always try to apply dynamic offsets even if the offsets stay the same
|
||||||
uint32_t currentDynamicBufferIndex = 0;
|
if (dynamicOffsetCount) {
|
||||||
|
// Update dynamic offsets
|
||||||
const BindGroupLayout::LayoutBindingInfo& layout =
|
const BindGroupLayout::LayoutBindingInfo& layout =
|
||||||
group->GetLayout()->GetBindingInfo();
|
group->GetLayout()->GetBindingInfo();
|
||||||
|
uint32_t currentDynamicBufferIndex = 0;
|
||||||
|
|
||||||
for (uint32_t bindingIndex : IterateBitSet(layout.dynamic)) {
|
for (uint32_t bindingIndex : IterateBitSet(layout.dynamic)) {
|
||||||
ASSERT(dynamicOffsetCount > 0);
|
ASSERT(dynamicOffsetCount > 0);
|
||||||
uint32_t parameterIndex =
|
uint32_t parameterIndex =
|
||||||
pipelineLayout->GetDynamicRootParameterIndex(index, bindingIndex);
|
pipelineLayout->GetDynamicRootParameterIndex(index, bindingIndex);
|
||||||
BufferBinding binding = group->GetBindingAsBufferBinding(bindingIndex);
|
BufferBinding binding = group->GetBindingAsBufferBinding(bindingIndex);
|
||||||
|
|
||||||
// Calculate buffer locations that root descriptors links to. The location is
|
// Calculate buffer locations that root descriptors links to. The location
|
||||||
// (base buffer location + initial offset + dynamic offset)
|
// is (base buffer location + initial offset + dynamic offset)
|
||||||
uint64_t offset = dynamicOffsets[currentDynamicBufferIndex++] + binding.offset;
|
uint64_t dynamicOffset = dynamicOffsets[currentDynamicBufferIndex];
|
||||||
|
uint64_t offset = binding.offset + dynamicOffset;
|
||||||
D3D12_GPU_VIRTUAL_ADDRESS bufferLocation =
|
D3D12_GPU_VIRTUAL_ADDRESS bufferLocation =
|
||||||
ToBackend(binding.buffer)->GetVA() + offset;
|
ToBackend(binding.buffer)->GetVA() + offset;
|
||||||
|
|
||||||
|
@ -198,7 +201,15 @@ namespace dawn_native { namespace d3d12 {
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Record current dynamic offsets for inheriting
|
||||||
|
mLastDynamicOffsets[index][currentDynamicBufferIndex] = dynamicOffset;
|
||||||
|
++currentDynamicBufferIndex;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mBindGroups[index] != group || force) {
|
||||||
|
mBindGroups[index] = group;
|
||||||
uint32_t cbvUavSrvCount =
|
uint32_t cbvUavSrvCount =
|
||||||
ToBackend(group->GetLayout())->GetCbvUavSrvDescriptorCount();
|
ToBackend(group->GetLayout())->GetCbvUavSrvDescriptorCount();
|
||||||
uint32_t samplerCount = ToBackend(group->GetLayout())->GetSamplerDescriptorCount();
|
uint32_t samplerCount = ToBackend(group->GetLayout())->GetSamplerDescriptorCount();
|
||||||
|
@ -244,12 +255,11 @@ namespace dawn_native { namespace d3d12 {
|
||||||
for (uint32_t i = 0; i < inheritUntil; ++i) {
|
for (uint32_t i = 0; i < inheritUntil; ++i) {
|
||||||
const BindGroupLayout* layout = ToBackend(mBindGroups[i]->GetLayout());
|
const BindGroupLayout* layout = ToBackend(mBindGroups[i]->GetLayout());
|
||||||
const uint32_t dynamicBufferCount = layout->GetDynamicBufferCount();
|
const uint32_t dynamicBufferCount = layout->GetDynamicBufferCount();
|
||||||
// TODO(shaobo.yan@intel.com) : Need to handle dynamic resources inherited with last
|
|
||||||
// dynamic offsets.
|
// Inherit dynamic offsets
|
||||||
if (dynamicBufferCount > 0) {
|
if (dynamicBufferCount > 0) {
|
||||||
std::vector<uint64_t> zeroOffsets(dynamicBufferCount, 0);
|
|
||||||
SetBindGroup(commandList, newLayout, mBindGroups[i], i, dynamicBufferCount,
|
SetBindGroup(commandList, newLayout, mBindGroups[i], i, dynamicBufferCount,
|
||||||
zeroOffsets.data(), true);
|
mLastDynamicOffsets[i].data(), true);
|
||||||
} else {
|
} else {
|
||||||
SetBindGroup(commandList, newLayout, mBindGroups[i], i, 0, nullptr, true);
|
SetBindGroup(commandList, newLayout, mBindGroups[i], i, 0, nullptr, true);
|
||||||
}
|
}
|
||||||
|
@ -280,6 +290,8 @@ namespace dawn_native { namespace d3d12 {
|
||||||
uint32_t mSamplerDescriptorHeapSize = 0;
|
uint32_t mSamplerDescriptorHeapSize = 0;
|
||||||
std::array<BindGroup*, kMaxBindGroups> mBindGroups = {};
|
std::array<BindGroup*, kMaxBindGroups> mBindGroups = {};
|
||||||
std::deque<BindGroup*> mBindGroupsList = {};
|
std::deque<BindGroup*> mBindGroupsList = {};
|
||||||
|
std::array<std::array<uint64_t, kMaxDynamicBufferCount>, kMaxBindGroups>
|
||||||
|
mLastDynamicOffsets;
|
||||||
bool mInCompute = false;
|
bool mInCompute = false;
|
||||||
|
|
||||||
DescriptorHeapHandle mCbvSrvUavGPUDescriptorHeap = {};
|
DescriptorHeapHandle mCbvSrvUavGPUDescriptorHeap = {};
|
||||||
|
@ -808,9 +820,11 @@ namespace dawn_native { namespace d3d12 {
|
||||||
SetBindGroupCmd* cmd = mCommands.NextCommand<SetBindGroupCmd>();
|
SetBindGroupCmd* cmd = mCommands.NextCommand<SetBindGroupCmd>();
|
||||||
BindGroup* group = ToBackend(cmd->group.Get());
|
BindGroup* group = ToBackend(cmd->group.Get());
|
||||||
uint64_t* dynamicOffsets = nullptr;
|
uint64_t* dynamicOffsets = nullptr;
|
||||||
|
|
||||||
if (cmd->dynamicOffsetCount > 0) {
|
if (cmd->dynamicOffsetCount > 0) {
|
||||||
dynamicOffsets = mCommands.NextData<uint64_t>(cmd->dynamicOffsetCount);
|
dynamicOffsets = mCommands.NextData<uint64_t>(cmd->dynamicOffsetCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
bindingTracker->SetBindGroup(commandList, lastLayout, group, cmd->index,
|
bindingTracker->SetBindGroup(commandList, lastLayout, group, cmd->index,
|
||||||
cmd->dynamicOffsetCount, dynamicOffsets);
|
cmd->dynamicOffsetCount, dynamicOffsets);
|
||||||
} break;
|
} break;
|
||||||
|
@ -1118,6 +1132,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
SetBindGroupCmd* cmd = mCommands.NextCommand<SetBindGroupCmd>();
|
SetBindGroupCmd* cmd = mCommands.NextCommand<SetBindGroupCmd>();
|
||||||
BindGroup* group = ToBackend(cmd->group.Get());
|
BindGroup* group = ToBackend(cmd->group.Get());
|
||||||
uint64_t* dynamicOffsets = nullptr;
|
uint64_t* dynamicOffsets = nullptr;
|
||||||
|
|
||||||
if (cmd->dynamicOffsetCount > 0) {
|
if (cmd->dynamicOffsetCount > 0) {
|
||||||
dynamicOffsets = mCommands.NextData<uint64_t>(cmd->dynamicOffsetCount);
|
dynamicOffsets = mCommands.NextData<uint64_t>(cmd->dynamicOffsetCount);
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,7 +165,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
return mSamplerRootParameterInfo[group];
|
return mSamplerRootParameterInfo[group];
|
||||||
}
|
}
|
||||||
|
|
||||||
ComPtr<ID3D12RootSignature> PipelineLayout::GetRootSignature() {
|
ComPtr<ID3D12RootSignature> PipelineLayout::GetRootSignature() const {
|
||||||
return mRootSignature;
|
return mRootSignature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
// Returns the index of the root parameter reserved for a dynamic buffer binding
|
// Returns the index of the root parameter reserved for a dynamic buffer binding
|
||||||
uint32_t GetDynamicRootParameterIndex(uint32_t group, uint32_t binding) const;
|
uint32_t GetDynamicRootParameterIndex(uint32_t group, uint32_t binding) const;
|
||||||
|
|
||||||
ComPtr<ID3D12RootSignature> GetRootSignature();
|
ComPtr<ID3D12RootSignature> GetRootSignature() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<uint32_t, kMaxBindGroups> mCbvUavSrvRootParameterInfo;
|
std::array<uint32_t, kMaxBindGroups> mCbvUavSrvRootParameterInfo;
|
||||||
|
|
|
@ -33,13 +33,14 @@ class DynamicBufferOffsetTests : public DawnTest {
|
||||||
uniformData[0] = 1;
|
uniformData[0] = 1;
|
||||||
uniformData[1] = 2;
|
uniformData[1] = 2;
|
||||||
|
|
||||||
mUniformBuffer = utils::CreateBufferFromData(device, uniformData.data(), kBufferSize,
|
mUniformBuffers[0] = utils::CreateBufferFromData(device, uniformData.data(), kBufferSize,
|
||||||
dawn::BufferUsageBit::Uniform);
|
dawn::BufferUsageBit::Uniform);
|
||||||
|
|
||||||
uniformData[uniformData.size() - 2] = 5;
|
uniformData[uniformData.size() - 2] = 5;
|
||||||
uniformData[uniformData.size() - 1] = 6;
|
uniformData[uniformData.size() - 1] = 6;
|
||||||
|
|
||||||
mDynamicUniformBuffer = utils::CreateBufferFromData(device, uniformData.data(), kBufferSize,
|
// Dynamic uniform buffer
|
||||||
|
mUniformBuffers[1] = utils::CreateBufferFromData(device, uniformData.data(), kBufferSize,
|
||||||
dawn::BufferUsageBit::Uniform);
|
dawn::BufferUsageBit::Uniform);
|
||||||
|
|
||||||
dawn::BufferDescriptor storageBufferDescriptor;
|
dawn::BufferDescriptor storageBufferDescriptor;
|
||||||
|
@ -48,11 +49,13 @@ class DynamicBufferOffsetTests : public DawnTest {
|
||||||
dawn::BufferUsageBit::CopyDst |
|
dawn::BufferUsageBit::CopyDst |
|
||||||
dawn::BufferUsageBit::CopySrc;
|
dawn::BufferUsageBit::CopySrc;
|
||||||
|
|
||||||
mStorageBuffer = device.CreateBuffer(&storageBufferDescriptor);
|
mStorageBuffers[0] = device.CreateBuffer(&storageBufferDescriptor);
|
||||||
|
|
||||||
mDynamicStorageBuffer = device.CreateBuffer(&storageBufferDescriptor);
|
// Dynamic storage buffer
|
||||||
|
mStorageBuffers[1] = device.CreateBuffer(&storageBufferDescriptor);
|
||||||
|
|
||||||
mBindGroupLayout = utils::MakeBindGroupLayout(
|
// Default bind group layout
|
||||||
|
mBindGroupLayouts[0] = utils::MakeBindGroupLayout(
|
||||||
device, {{0, dawn::ShaderStageBit::Compute | dawn::ShaderStageBit::Fragment,
|
device, {{0, dawn::ShaderStageBit::Compute | dawn::ShaderStageBit::Fragment,
|
||||||
dawn::BindingType::UniformBuffer},
|
dawn::BindingType::UniformBuffer},
|
||||||
{1, dawn::ShaderStageBit::Compute | dawn::ShaderStageBit::Fragment,
|
{1, dawn::ShaderStageBit::Compute | dawn::ShaderStageBit::Fragment,
|
||||||
|
@ -62,23 +65,35 @@ class DynamicBufferOffsetTests : public DawnTest {
|
||||||
{4, dawn::ShaderStageBit::Compute | dawn::ShaderStageBit::Fragment,
|
{4, dawn::ShaderStageBit::Compute | dawn::ShaderStageBit::Fragment,
|
||||||
dawn::BindingType::StorageBuffer, true}});
|
dawn::BindingType::StorageBuffer, true}});
|
||||||
|
|
||||||
mBindGroup = utils::MakeBindGroup(device, mBindGroupLayout,
|
// Default bind group
|
||||||
{{0, mUniformBuffer, 0, kBindingSize},
|
mBindGroups[0] = utils::MakeBindGroup(device, mBindGroupLayouts[0],
|
||||||
{1, mStorageBuffer, 0, kBindingSize},
|
{{0, mUniformBuffers[0], 0, kBindingSize},
|
||||||
{3, mDynamicUniformBuffer, 0, kBindingSize},
|
{1, mStorageBuffers[0], 0, kBindingSize},
|
||||||
{4, mDynamicStorageBuffer, 0, kBindingSize}});
|
{3, mUniformBuffers[1], 0, kBindingSize},
|
||||||
|
{4, mStorageBuffers[1], 0, kBindingSize}});
|
||||||
|
|
||||||
|
// Extra uniform buffer for inheriting test
|
||||||
|
mUniformBuffers[2] = utils::CreateBufferFromData(device, uniformData.data(), kBufferSize,
|
||||||
|
dawn::BufferUsageBit::Uniform);
|
||||||
|
|
||||||
|
// Bind group layout for inheriting test
|
||||||
|
mBindGroupLayouts[1] = utils::MakeBindGroupLayout(
|
||||||
|
device, {{0, dawn::ShaderStageBit::Compute | dawn::ShaderStageBit::Fragment,
|
||||||
|
dawn::BindingType::UniformBuffer}});
|
||||||
|
|
||||||
|
// Bind group for inheriting test
|
||||||
|
mBindGroups[1] = utils::MakeBindGroup(device, mBindGroupLayouts[1],
|
||||||
|
{{0, mUniformBuffers[2], 0, kBindingSize}});
|
||||||
}
|
}
|
||||||
// Create objects to use as resources inside test bind groups.
|
// Create objects to use as resources inside test bind groups.
|
||||||
|
|
||||||
dawn::BindGroup mBindGroup;
|
dawn::BindGroup mBindGroups[2];
|
||||||
dawn::BindGroupLayout mBindGroupLayout;
|
dawn::BindGroupLayout mBindGroupLayouts[2];
|
||||||
dawn::Buffer mUniformBuffer;
|
dawn::Buffer mUniformBuffers[3];
|
||||||
dawn::Buffer mStorageBuffer;
|
dawn::Buffer mStorageBuffers[2];
|
||||||
dawn::Buffer mDynamicUniformBuffer;
|
|
||||||
dawn::Buffer mDynamicStorageBuffer;
|
|
||||||
dawn::Texture mColorAttachment;
|
dawn::Texture mColorAttachment;
|
||||||
|
|
||||||
dawn::RenderPipeline CreateRenderPipeline() {
|
dawn::RenderPipeline CreateRenderPipeline(bool isInheritedPipeline = false) {
|
||||||
dawn::ShaderModule vsModule =
|
dawn::ShaderModule vsModule =
|
||||||
utils::CreateShaderModule(device, utils::ShaderStage::Vertex, R"(
|
utils::CreateShaderModule(device, utils::ShaderStage::Vertex, R"(
|
||||||
#version 450
|
#version 450
|
||||||
|
@ -87,8 +102,10 @@ class DynamicBufferOffsetTests : public DawnTest {
|
||||||
gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);
|
gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);
|
||||||
})");
|
})");
|
||||||
|
|
||||||
dawn::ShaderModule fsModule =
|
// Construct fragment shader source
|
||||||
utils::CreateShaderModule(device, utils::ShaderStage::Fragment, R"(
|
std::ostringstream fs;
|
||||||
|
std::string multipleNumber = isInheritedPipeline ? "2" : "1";
|
||||||
|
fs << R"(
|
||||||
#version 450
|
#version 450
|
||||||
layout(std140, set = 0, binding = 0) uniform uBufferNotDynamic {
|
layout(std140, set = 0, binding = 0) uniform uBufferNotDynamic {
|
||||||
uvec2 notDynamicValue;
|
uvec2 notDynamicValue;
|
||||||
|
@ -102,29 +119,50 @@ class DynamicBufferOffsetTests : public DawnTest {
|
||||||
layout(std140, set = 0, binding = 4) buffer SBuffer {
|
layout(std140, set = 0, binding = 4) buffer SBuffer {
|
||||||
uvec2 result;
|
uvec2 result;
|
||||||
} sBuffer;
|
} sBuffer;
|
||||||
layout(location = 0) out vec4 fragColor;
|
)";
|
||||||
void main() {
|
|
||||||
mid.notDynamicResult.xy = notDynamicValue.xy;
|
if (isInheritedPipeline) {
|
||||||
sBuffer.result.xy = value.xy + mid.notDynamicResult.xy;
|
fs << R"(
|
||||||
fragColor = vec4(value.x / 255.0f, value.y / 255.0f, 1.0f, 1.0f);
|
layout(std140, set = 1, binding = 0) uniform paddingBlock {
|
||||||
})");
|
uvec2 padding;
|
||||||
|
};
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
|
||||||
|
fs << " layout(location = 0) out vec4 fragColor;\n";
|
||||||
|
fs << " void main() {\n";
|
||||||
|
fs << " mid.notDynamicResult.xy = notDynamicValue.xy;\n";
|
||||||
|
fs << " sBuffer.result.xy = " << multipleNumber
|
||||||
|
<< " * (value.xy + mid.notDynamicResult.xy);\n";
|
||||||
|
fs << " fragColor = vec4(value.x / 255.0f, value.y / 255.0f, 1.0f, 1.0f);\n";
|
||||||
|
fs << " }\n";
|
||||||
|
|
||||||
|
dawn::ShaderModule fsModule =
|
||||||
|
utils::CreateShaderModule(device, utils::ShaderStage::Fragment, fs.str().c_str());
|
||||||
|
|
||||||
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
|
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
|
||||||
pipelineDescriptor.cVertexStage.module = vsModule;
|
pipelineDescriptor.cVertexStage.module = vsModule;
|
||||||
pipelineDescriptor.cFragmentStage.module = fsModule;
|
pipelineDescriptor.cFragmentStage.module = fsModule;
|
||||||
pipelineDescriptor.cColorStates[0]->format = dawn::TextureFormat::RGBA8Unorm;
|
pipelineDescriptor.cColorStates[0]->format = dawn::TextureFormat::RGBA8Unorm;
|
||||||
dawn::PipelineLayout pipelineLayout =
|
|
||||||
utils::MakeBasicPipelineLayout(device, &mBindGroupLayout);
|
dawn::PipelineLayoutDescriptor pipelineLayoutDescriptor;
|
||||||
pipelineDescriptor.layout = pipelineLayout;
|
if (isInheritedPipeline) {
|
||||||
|
pipelineLayoutDescriptor.bindGroupLayoutCount = 2;
|
||||||
|
} else {
|
||||||
|
pipelineLayoutDescriptor.bindGroupLayoutCount = 1;
|
||||||
|
}
|
||||||
|
pipelineLayoutDescriptor.bindGroupLayouts = mBindGroupLayouts;
|
||||||
|
pipelineDescriptor.layout = device.CreatePipelineLayout(&pipelineLayoutDescriptor);
|
||||||
|
|
||||||
return device.CreateRenderPipeline(&pipelineDescriptor);
|
return device.CreateRenderPipeline(&pipelineDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
dawn::ComputePipeline CreateComputePipeline() {
|
dawn::ComputePipeline CreateComputePipeline(bool isInheritedPipeline = false) {
|
||||||
dawn::ShaderModule csModule =
|
// Construct compute shader source
|
||||||
utils::CreateShaderModule(device, utils::ShaderStage::Compute, R"(
|
std::ostringstream cs;
|
||||||
|
std::string multipleNumber = isInheritedPipeline ? "2" : "1";
|
||||||
|
cs << R"(
|
||||||
#version 450
|
#version 450
|
||||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
|
||||||
layout(std140, set = 0, binding = 0) uniform uBufferNotDynamic {
|
layout(std140, set = 0, binding = 0) uniform uBufferNotDynamic {
|
||||||
uvec2 notDynamicValue;
|
uvec2 notDynamicValue;
|
||||||
};
|
};
|
||||||
|
@ -137,22 +175,40 @@ class DynamicBufferOffsetTests : public DawnTest {
|
||||||
layout(std140, set = 0, binding = 4) buffer SBuffer {
|
layout(std140, set = 0, binding = 4) buffer SBuffer {
|
||||||
uvec2 result;
|
uvec2 result;
|
||||||
} sBuffer;
|
} sBuffer;
|
||||||
|
)";
|
||||||
|
|
||||||
void main() {
|
if (isInheritedPipeline) {
|
||||||
mid.notDynamicResult.xy = notDynamicValue.xy;
|
cs << R"(
|
||||||
sBuffer.result.xy = value.xy + mid.notDynamicResult.xy;
|
layout(std140, set = 1, binding = 0) uniform paddingBlock {
|
||||||
})");
|
uvec2 padding;
|
||||||
|
};
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
|
||||||
|
cs << " void main() {\n";
|
||||||
|
cs << " mid.notDynamicResult.xy = notDynamicValue.xy;\n";
|
||||||
|
cs << " sBuffer.result.xy = " << multipleNumber
|
||||||
|
<< " * (value.xy + mid.notDynamicResult.xy);\n";
|
||||||
|
cs << " }\n";
|
||||||
|
|
||||||
|
dawn::ShaderModule csModule =
|
||||||
|
utils::CreateShaderModule(device, utils::ShaderStage::Compute, cs.str().c_str());
|
||||||
|
|
||||||
dawn::ComputePipelineDescriptor csDesc;
|
dawn::ComputePipelineDescriptor csDesc;
|
||||||
dawn::PipelineLayout pipelineLayout =
|
|
||||||
utils::MakeBasicPipelineLayout(device, &mBindGroupLayout);
|
|
||||||
csDesc.layout = pipelineLayout;
|
|
||||||
|
|
||||||
dawn::PipelineStageDescriptor computeStage;
|
dawn::PipelineStageDescriptor computeStage;
|
||||||
computeStage.module = csModule;
|
computeStage.module = csModule;
|
||||||
computeStage.entryPoint = "main";
|
computeStage.entryPoint = "main";
|
||||||
csDesc.computeStage = &computeStage;
|
csDesc.computeStage = &computeStage;
|
||||||
|
|
||||||
|
dawn::PipelineLayoutDescriptor pipelineLayoutDescriptor;
|
||||||
|
if (isInheritedPipeline) {
|
||||||
|
pipelineLayoutDescriptor.bindGroupLayoutCount = 2;
|
||||||
|
} else {
|
||||||
|
pipelineLayoutDescriptor.bindGroupLayoutCount = 1;
|
||||||
|
}
|
||||||
|
pipelineLayoutDescriptor.bindGroupLayouts = mBindGroupLayouts;
|
||||||
|
csDesc.layout = device.CreatePipelineLayout(&pipelineLayoutDescriptor);
|
||||||
|
|
||||||
return device.CreateComputePipeline(&csDesc);
|
return device.CreateComputePipeline(&csDesc);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -167,7 +223,7 @@ TEST_P(DynamicBufferOffsetTests, BasicRenderPipeline) {
|
||||||
dawn::RenderPassEncoder renderPassEncoder =
|
dawn::RenderPassEncoder renderPassEncoder =
|
||||||
commandEncoder.BeginRenderPass(&renderPass.renderPassInfo);
|
commandEncoder.BeginRenderPass(&renderPass.renderPassInfo);
|
||||||
renderPassEncoder.SetPipeline(pipeline);
|
renderPassEncoder.SetPipeline(pipeline);
|
||||||
renderPassEncoder.SetBindGroup(0, mBindGroup, offsets.size(), offsets.data());
|
renderPassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
|
||||||
renderPassEncoder.Draw(3, 1, 0, 0);
|
renderPassEncoder.Draw(3, 1, 0, 0);
|
||||||
renderPassEncoder.EndPass();
|
renderPassEncoder.EndPass();
|
||||||
dawn::CommandBuffer commands = commandEncoder.Finish();
|
dawn::CommandBuffer commands = commandEncoder.Finish();
|
||||||
|
@ -175,7 +231,7 @@ TEST_P(DynamicBufferOffsetTests, BasicRenderPipeline) {
|
||||||
|
|
||||||
std::vector<uint32_t> expectedData = {2, 4};
|
std::vector<uint32_t> expectedData = {2, 4};
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 2, 255, 255), renderPass.color, 0, 0);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 2, 255, 255), renderPass.color, 0, 0);
|
||||||
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mDynamicStorageBuffer, 0, expectedData.size());
|
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mStorageBuffers[1], 0, expectedData.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Have non-zero dynamic offsets.
|
// Have non-zero dynamic offsets.
|
||||||
|
@ -189,7 +245,7 @@ TEST_P(DynamicBufferOffsetTests, SetDynamicOffestsRenderPipeline) {
|
||||||
dawn::RenderPassEncoder renderPassEncoder =
|
dawn::RenderPassEncoder renderPassEncoder =
|
||||||
commandEncoder.BeginRenderPass(&renderPass.renderPassInfo);
|
commandEncoder.BeginRenderPass(&renderPass.renderPassInfo);
|
||||||
renderPassEncoder.SetPipeline(pipeline);
|
renderPassEncoder.SetPipeline(pipeline);
|
||||||
renderPassEncoder.SetBindGroup(0, mBindGroup, offsets.size(), offsets.data());
|
renderPassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
|
||||||
renderPassEncoder.Draw(3, 1, 0, 0);
|
renderPassEncoder.Draw(3, 1, 0, 0);
|
||||||
renderPassEncoder.EndPass();
|
renderPassEncoder.EndPass();
|
||||||
dawn::CommandBuffer commands = commandEncoder.Finish();
|
dawn::CommandBuffer commands = commandEncoder.Finish();
|
||||||
|
@ -197,7 +253,7 @@ TEST_P(DynamicBufferOffsetTests, SetDynamicOffestsRenderPipeline) {
|
||||||
|
|
||||||
std::vector<uint32_t> expectedData = {6, 8};
|
std::vector<uint32_t> expectedData = {6, 8};
|
||||||
EXPECT_PIXEL_RGBA8_EQ(RGBA8(5, 6, 255, 255), renderPass.color, 0, 0);
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(5, 6, 255, 255), renderPass.color, 0, 0);
|
||||||
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mDynamicStorageBuffer,
|
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mStorageBuffers[1],
|
||||||
kMinDynamicBufferOffsetAlignment, expectedData.size());
|
kMinDynamicBufferOffsetAlignment, expectedData.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,14 +266,14 @@ TEST_P(DynamicBufferOffsetTests, BasicComputePipeline) {
|
||||||
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
||||||
dawn::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass();
|
dawn::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass();
|
||||||
computePassEncoder.SetPipeline(pipeline);
|
computePassEncoder.SetPipeline(pipeline);
|
||||||
computePassEncoder.SetBindGroup(0, mBindGroup, offsets.size(), offsets.data());
|
computePassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
|
||||||
computePassEncoder.Dispatch(1, 1, 1);
|
computePassEncoder.Dispatch(1, 1, 1);
|
||||||
computePassEncoder.EndPass();
|
computePassEncoder.EndPass();
|
||||||
dawn::CommandBuffer commands = commandEncoder.Finish();
|
dawn::CommandBuffer commands = commandEncoder.Finish();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
std::vector<uint32_t> expectedData = {2, 4};
|
std::vector<uint32_t> expectedData = {2, 4};
|
||||||
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mDynamicStorageBuffer, 0, expectedData.size());
|
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mStorageBuffers[1], 0, expectedData.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Have non-zero dynamic offsets.
|
// Have non-zero dynamic offsets.
|
||||||
|
@ -230,17 +286,127 @@ TEST_P(DynamicBufferOffsetTests, SetDynamicOffestsComputePipeline) {
|
||||||
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
||||||
dawn::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass();
|
dawn::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass();
|
||||||
computePassEncoder.SetPipeline(pipeline);
|
computePassEncoder.SetPipeline(pipeline);
|
||||||
computePassEncoder.SetBindGroup(0, mBindGroup, offsets.size(), offsets.data());
|
computePassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
|
||||||
computePassEncoder.Dispatch(1, 1, 1);
|
computePassEncoder.Dispatch(1, 1, 1);
|
||||||
computePassEncoder.EndPass();
|
computePassEncoder.EndPass();
|
||||||
dawn::CommandBuffer commands = commandEncoder.Finish();
|
dawn::CommandBuffer commands = commandEncoder.Finish();
|
||||||
queue.Submit(1, &commands);
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
std::vector<uint32_t> expectedData = {6, 8};
|
std::vector<uint32_t> expectedData = {6, 8};
|
||||||
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mDynamicStorageBuffer,
|
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mStorageBuffers[1],
|
||||||
kMinDynamicBufferOffsetAlignment, expectedData.size());
|
kMinDynamicBufferOffsetAlignment, expectedData.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test inherit dynamic offsets on render pipeline
|
||||||
|
TEST_P(DynamicBufferOffsetTests, InheritDynamicOffestsRenderPipeline) {
|
||||||
|
// Using default pipeline and setting dynamic offsets
|
||||||
|
dawn::RenderPipeline pipeline = CreateRenderPipeline();
|
||||||
|
dawn::RenderPipeline testPipeline = CreateRenderPipeline(true);
|
||||||
|
|
||||||
|
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
|
||||||
|
|
||||||
|
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
||||||
|
std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment,
|
||||||
|
kMinDynamicBufferOffsetAlignment};
|
||||||
|
dawn::RenderPassEncoder renderPassEncoder =
|
||||||
|
commandEncoder.BeginRenderPass(&renderPass.renderPassInfo);
|
||||||
|
renderPassEncoder.SetPipeline(pipeline);
|
||||||
|
renderPassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
|
||||||
|
renderPassEncoder.Draw(3, 1, 0, 0);
|
||||||
|
renderPassEncoder.SetPipeline(testPipeline);
|
||||||
|
renderPassEncoder.SetBindGroup(1, mBindGroups[1], 0, nullptr);
|
||||||
|
renderPassEncoder.Draw(3, 1, 0, 0);
|
||||||
|
renderPassEncoder.EndPass();
|
||||||
|
dawn::CommandBuffer commands = commandEncoder.Finish();
|
||||||
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
|
std::vector<uint32_t> expectedData = {12, 16};
|
||||||
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(5, 6, 255, 255), renderPass.color, 0, 0);
|
||||||
|
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mStorageBuffers[1],
|
||||||
|
kMinDynamicBufferOffsetAlignment, expectedData.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test inherit dynamic offsets on compute pipeline
|
||||||
|
// TODO(shaobo.yan@intel.com) : Try this test on GTX1080 and cannot reproduce the failure.
|
||||||
|
// Suspect it is due to dawn doesn't handle sync between two dispatch and disable this case.
|
||||||
|
// Will double check root cause after got GTX1660.
|
||||||
|
TEST_P(DynamicBufferOffsetTests, InheritDynamicOffestsComputePipeline) {
|
||||||
|
DAWN_SKIP_TEST_IF(IsWindows() && IsNvidia());
|
||||||
|
dawn::ComputePipeline pipeline = CreateComputePipeline();
|
||||||
|
dawn::ComputePipeline testPipeline = CreateComputePipeline(true);
|
||||||
|
|
||||||
|
std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment,
|
||||||
|
kMinDynamicBufferOffsetAlignment};
|
||||||
|
|
||||||
|
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
||||||
|
dawn::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass();
|
||||||
|
computePassEncoder.SetPipeline(pipeline);
|
||||||
|
computePassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
|
||||||
|
computePassEncoder.Dispatch(1, 1, 1);
|
||||||
|
computePassEncoder.SetPipeline(testPipeline);
|
||||||
|
computePassEncoder.SetBindGroup(1, mBindGroups[1], 0, nullptr);
|
||||||
|
computePassEncoder.Dispatch(1, 1, 1);
|
||||||
|
computePassEncoder.EndPass();
|
||||||
|
dawn::CommandBuffer commands = commandEncoder.Finish();
|
||||||
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
|
std::vector<uint32_t> expectedData = {12, 16};
|
||||||
|
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mStorageBuffers[1],
|
||||||
|
kMinDynamicBufferOffsetAlignment, expectedData.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setting multiple dynamic offsets for the same bindgroup in one render pass.
|
||||||
|
TEST_P(DynamicBufferOffsetTests, UpdateDynamicOffestsMultipleTimesRenderPipeline) {
|
||||||
|
// Using default pipeline and setting dynamic offsets
|
||||||
|
dawn::RenderPipeline pipeline = CreateRenderPipeline();
|
||||||
|
|
||||||
|
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
|
||||||
|
|
||||||
|
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
||||||
|
std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment,
|
||||||
|
kMinDynamicBufferOffsetAlignment};
|
||||||
|
std::array<uint64_t, 2> testOffsets = {0, 0};
|
||||||
|
|
||||||
|
dawn::RenderPassEncoder renderPassEncoder =
|
||||||
|
commandEncoder.BeginRenderPass(&renderPass.renderPassInfo);
|
||||||
|
renderPassEncoder.SetPipeline(pipeline);
|
||||||
|
renderPassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
|
||||||
|
renderPassEncoder.Draw(3, 1, 0, 0);
|
||||||
|
renderPassEncoder.SetBindGroup(0, mBindGroups[0], testOffsets.size(), testOffsets.data());
|
||||||
|
renderPassEncoder.Draw(3, 1, 0, 0);
|
||||||
|
renderPassEncoder.EndPass();
|
||||||
|
dawn::CommandBuffer commands = commandEncoder.Finish();
|
||||||
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
|
std::vector<uint32_t> expectedData = {2, 4};
|
||||||
|
EXPECT_PIXEL_RGBA8_EQ(RGBA8(1, 2, 255, 255), renderPass.color, 0, 0);
|
||||||
|
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mStorageBuffers[1], 0, expectedData.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setting multiple dynamic offsets for the same bindgroup in one compute pass.
|
||||||
|
// TODO(shaobo.yan@intel.com) : enable this test after resolving dawn issue 198.
|
||||||
|
TEST_P(DynamicBufferOffsetTests, DISABLED_UpdateDynamicOffestsMultipleTimesComputePipeline) {
|
||||||
|
dawn::ComputePipeline pipeline = CreateComputePipeline();
|
||||||
|
|
||||||
|
std::array<uint64_t, 2> offsets = {kMinDynamicBufferOffsetAlignment,
|
||||||
|
kMinDynamicBufferOffsetAlignment};
|
||||||
|
std::array<uint64_t, 2> testOffsets = {0, 0};
|
||||||
|
|
||||||
|
dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
||||||
|
dawn::ComputePassEncoder computePassEncoder = commandEncoder.BeginComputePass();
|
||||||
|
computePassEncoder.SetPipeline(pipeline);
|
||||||
|
computePassEncoder.SetBindGroup(0, mBindGroups[0], offsets.size(), offsets.data());
|
||||||
|
computePassEncoder.Dispatch(1, 1, 1);
|
||||||
|
computePassEncoder.SetBindGroup(0, mBindGroups[0], testOffsets.size(), testOffsets.data());
|
||||||
|
computePassEncoder.Dispatch(1, 1, 1);
|
||||||
|
computePassEncoder.EndPass();
|
||||||
|
dawn::CommandBuffer commands = commandEncoder.Finish();
|
||||||
|
queue.Submit(1, &commands);
|
||||||
|
|
||||||
|
std::vector<uint32_t> expectedData = {2, 4};
|
||||||
|
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), mStorageBuffers[1], 0, expectedData.size());
|
||||||
|
}
|
||||||
|
|
||||||
DAWN_INSTANTIATE_TEST(DynamicBufferOffsetTests,
|
DAWN_INSTANTIATE_TEST(DynamicBufferOffsetTests,
|
||||||
D3D12Backend,
|
D3D12Backend,
|
||||||
MetalBackend,
|
MetalBackend,
|
||||||
|
|
Loading…
Reference in New Issue