src/tests/end2end/IndexFormatTests.cpp
TEST_P(IndexFormatTest, SetIndexBufferBeforeSetPipeline) {
    wgpu::RenderPipeline pipeline = MakeTestPipeline(wgpu::IndexFormat::Uint32);

    wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
        device, wgpu::BufferUsage::Vertex,
        {-1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f});
    wgpu::Buffer indexBuffer =
        utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Index, {0, 1, 2});

    wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
    {
        wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
        pass.SetIndexBufferWithFormat(indexBuffer, wgpu::IndexFormat::Uint32);
        pass.SetPipeline(pipeline);
        pass.SetVertexBuffer(0, vertexBuffer);
        pass.DrawIndexed(3);
        pass.EndPass();
    }

    wgpu::CommandBuffer commands = encoder.Finish();
    queue.Submit(1, &commands);

    EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
}
// Test that setting the index buffer before the pipeline works, this is important
// for backends where the index format is passed inside the call to SetIndexBuffer
// because it needs to be done lazily (to query the format from the last pipeline).
// TODO(cwallez@chromium.org): This is currently disallowed by the validation but
// we want to support eventually.
Test that setting the index buffer before the pipeline works, this is important
for backends where the index format is passed inside the call to SetIndexBuffer
because it needs to be done lazily (to query the format from the last pipeline).
TODO(cwallez@chromium.org): This is currently disallowed by the validation but
we want to support eventually.
Test that setting the index buffer before the pipeline works this is important for backends where the index format is passed inside the call to SetIndexBuffer because it needs to be done lazily ( to query the format from the last pipeline ) . TODO ( cwallez@chromium . org ) : This is currently disallowed by the validation but we want to support eventually .
TEST_P(IndexFormatTest, SetIndexBufferBeforeSetPipeline) {
    wgpu::RenderPipeline pipeline = MakeTestPipeline(wgpu::IndexFormat::Uint32);
    wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
        device, wgpu::BufferUsage::Vertex,
        {-1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f});
    wgpu::Buffer indexBuffer =
        utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Index, {0, 1, 2});
    wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
    {
        wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
        pass.SetIndexBufferWithFormat(indexBuffer, wgpu::IndexFormat::Uint32);
        pass.SetPipeline(pipeline);
        pass.SetVertexBuffer(0, vertexBuffer);
        pass.DrawIndexed(3);
        pass.EndPass();
    }
    wgpu::CommandBuffer commands = encoder.Finish();
    queue.Submit(1, &commands);
    EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
}
TEST_P ( IndexFormatTest , SetIndexBufferBeforeSetPipeline ) { wgpu :: RenderPipeline pipeline = MakeTestPipeline ( wgpu :: IndexFormat :: Uint32 ) ; wgpu :: Buffer vertexBuffer = utils :: CreateBufferFromData < float > ( device , wgpu :: BufferUsage :: Vertex , { -1.0f , -1.0f , 0.0f , 1.0f , 1.0f , -1.0f , 0.0f , 1.0f , -1.0f , 1.0f , 0.0f , 1.0f } ) ; wgpu :: Buffer indexBuffer = utils :: CreateBufferFromData < uint32_t > ( device , wgpu :: BufferUsage :: Index , { 0 , 1 , 2 } ) ; wgpu :: CommandEncoder encoder = device . CreateCommandEncoder ( ) ; { wgpu :: RenderPassEncoder pass = encoder . BeginRenderPass ( & renderPass . renderPassInfo ) ; pass . SetIndexBufferWithFormat ( indexBuffer , wgpu :: IndexFormat :: Uint32 ) ; pass . SetPipeline ( pipeline ) ; pass . SetVertexBuffer ( 0 , vertexBuffer ) ; pass . DrawIndexed ( 3 ) ; pass . EndPass ( ) ; } wgpu :: CommandBuffer commands = encoder . Finish ( ) ; queue . Submit ( 1 , & commands ) ; EXPECT_PIXEL_RGBA8_EQ ( RGBA8 ( 0 , 255 , 0 , 255 ) , renderPass . color , 100 , 300 ) ; }
Test that setting the index buffer before the pipeline works, this is important
for backends where the index format is passed inside the call to SetIndexBuffer
because it needs to be done lazily (to query the format from the last pipeline).
Test that setting the index buffer before the pipeline works this is important for backends where the index format is passed inside the call to SetIndexBuffer because it needs to be done lazily ( to query the format from the last pipeline ) .