mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
Use a descriptor for BindGroupLayout (#211)
* Use a descriptor for BindGroupLayout * Fix MatchesLambda * Add WireTests.StructureOfStructureArrayArgument * Add BindGroupValidationTests.BindGroupLayoutCache
This commit is contained in:
@@ -50,6 +50,7 @@ class LambdaMatcherImpl : public MatcherInterface<Arg> {
|
||||
bool MatchAndExplain(Arg value, MatchResultListener* listener) const override {
|
||||
if (!mLambda(value)) {
|
||||
*listener << "which doesn't satisfy the custom predicate";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -410,15 +411,13 @@ TEST_F(WireTests, StructureOfValuesArgument) {
|
||||
|
||||
// Test that the wire is able to send structures that contain objects
|
||||
TEST_F(WireTests, StructureOfObjectArrayArgument) {
|
||||
nxtBindGroupLayoutBuilder bglBuilder = nxtDeviceCreateBindGroupLayoutBuilder(device);
|
||||
nxtBindGroupLayout bgl = nxtBindGroupLayoutBuilderGetResult(bglBuilder);
|
||||
nxtBindGroupLayoutDescriptor bglDescriptor;
|
||||
bglDescriptor.numBindings = 0;
|
||||
bglDescriptor.bindings = nullptr;
|
||||
|
||||
nxtBindGroupLayoutBuilder apiBglBuilder = api.GetNewBindGroupLayoutBuilder();
|
||||
EXPECT_CALL(api, DeviceCreateBindGroupLayoutBuilder(apiDevice))
|
||||
.WillOnce(Return(apiBglBuilder));
|
||||
nxtBindGroupLayout bgl = nxtDeviceCreateBindGroupLayout(device, &bglDescriptor);
|
||||
nxtBindGroupLayout apiBgl = api.GetNewBindGroupLayout();
|
||||
EXPECT_CALL(api, BindGroupLayoutBuilderGetResult(apiBglBuilder))
|
||||
.WillOnce(Return(apiBgl));
|
||||
EXPECT_CALL(api, DeviceCreateBindGroupLayout(apiDevice, _)).WillOnce(Return(apiBgl));
|
||||
|
||||
nxtPipelineLayoutDescriptor descriptor;
|
||||
descriptor.nextInChain = nullptr;
|
||||
@@ -436,6 +435,42 @@ TEST_F(WireTests, StructureOfObjectArrayArgument) {
|
||||
FlushClient();
|
||||
}
|
||||
|
||||
// Test that the wire is able to send structures that contain objects
|
||||
TEST_F(WireTests, StructureOfStructureArrayArgument) {
|
||||
static constexpr int NUM_BINDINGS = 3;
|
||||
nxtBindGroupBinding bindings[NUM_BINDINGS]{
|
||||
{0, NXT_SHADER_STAGE_BIT_VERTEX, NXT_BINDING_TYPE_SAMPLER},
|
||||
{1, NXT_SHADER_STAGE_BIT_VERTEX, NXT_BINDING_TYPE_SAMPLED_TEXTURE},
|
||||
{2,
|
||||
static_cast<nxtShaderStageBit>(NXT_SHADER_STAGE_BIT_VERTEX |
|
||||
NXT_SHADER_STAGE_BIT_FRAGMENT),
|
||||
NXT_BINDING_TYPE_UNIFORM_BUFFER},
|
||||
};
|
||||
nxtBindGroupLayoutDescriptor bglDescriptor;
|
||||
bglDescriptor.numBindings = NUM_BINDINGS;
|
||||
bglDescriptor.bindings = bindings;
|
||||
|
||||
nxtDeviceCreateBindGroupLayout(device, &bglDescriptor);
|
||||
nxtBindGroupLayout apiBgl = api.GetNewBindGroupLayout();
|
||||
EXPECT_CALL(
|
||||
api,
|
||||
DeviceCreateBindGroupLayout(
|
||||
apiDevice, MatchesLambda([bindings](const nxtBindGroupLayoutDescriptor* desc) -> bool {
|
||||
for (int i = 0; i < NUM_BINDINGS; ++i) {
|
||||
const auto& a = desc->bindings[i];
|
||||
const auto& b = bindings[i];
|
||||
if (a.binding != b.binding || a.visibility != b.visibility ||
|
||||
a.type != b.type) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return desc->nextInChain == nullptr && desc->numBindings == 3;
|
||||
})))
|
||||
.WillOnce(Return(apiBgl));
|
||||
|
||||
FlushClient();
|
||||
}
|
||||
|
||||
// Test that the server doesn't forward calls to error objects or with error objects
|
||||
// Also test that when GetResult is called on an error builder, the error callback is fired
|
||||
TEST_F(WireTests, CallsSkippedAfterBuilderError) {
|
||||
|
||||
@@ -13,21 +13,23 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include "tests/unittests/validation/ValidationTest.h"
|
||||
#include "utils/NXTHelpers.h"
|
||||
|
||||
class BindGroupValidationTest : public ValidationTest {
|
||||
};
|
||||
|
||||
TEST_F(BindGroupValidationTest, BufferViewOffset) {
|
||||
auto layout = device.CreateBindGroupLayoutBuilder()
|
||||
.SetBindingsType(nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer, 0, 1)
|
||||
.GetResult();
|
||||
auto layout = utils::MakeBindGroupLayout(
|
||||
device, {
|
||||
{0, nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer},
|
||||
});
|
||||
|
||||
auto buffer = device.CreateBufferBuilder()
|
||||
.SetAllowedUsage(nxt::BufferUsageBit::Uniform)
|
||||
.SetInitialUsage(nxt::BufferUsageBit::Uniform)
|
||||
.SetSize(512)
|
||||
.GetResult();
|
||||
|
||||
|
||||
// Check that offset 0 is valid
|
||||
{
|
||||
auto bufferView = buffer.CreateBufferViewBuilder()
|
||||
@@ -103,3 +105,21 @@ TEST_F(BindGroupValidationTest, BufferViewOffset) {
|
||||
.GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
// This test verifies that the BindGroupLayout cache is successfully caching/deduplicating objects.
|
||||
//
|
||||
// NOTE: This test only works currently because unittests are run without the wire - so the returned
|
||||
// BindGroupLayout pointers are actually visibly equivalent. With the wire, this would not be true.
|
||||
TEST_F(BindGroupValidationTest, BindGroupLayoutCache) {
|
||||
auto layout1 = utils::MakeBindGroupLayout(
|
||||
device, {
|
||||
{0, nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer},
|
||||
});
|
||||
auto layout2 = utils::MakeBindGroupLayout(
|
||||
device, {
|
||||
{0, nxt::ShaderStageBit::Vertex, nxt::BindingType::UniformBuffer},
|
||||
});
|
||||
|
||||
// Caching should cause these to be the same.
|
||||
ASSERT_EQ(layout1.Get(), layout2.Get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user