mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
Descriptorize Texture
This patch introduces texture descriptor for texture creation instead of texture builders. This patch also adds "arrayLayer" to texture descriptor and removes mDevice in TextureD3D12.
This commit is contained in:
committed by
Corentin Wallez
parent
75559bf1be
commit
425428f97b
@@ -690,14 +690,18 @@ TEST_P(BlendStateTest, IndependentBlendState) {
|
||||
std::array<dawn::Texture, 4> renderTargets;
|
||||
std::array<dawn::TextureView, 4> renderTargetViews;
|
||||
|
||||
dawn::TextureDescriptor descriptor;
|
||||
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||
descriptor.width = kRTSize;
|
||||
descriptor.height = kRTSize;
|
||||
descriptor.depth = 1;
|
||||
descriptor.arrayLayer = 1;
|
||||
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
descriptor.mipLevel = 1;
|
||||
descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc;
|
||||
|
||||
for (uint32_t i = 0; i < 4; ++i) {
|
||||
renderTargets[i] = device.CreateTextureBuilder()
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(kRTSize, kRTSize, 1)
|
||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
||||
.SetMipLevels(1)
|
||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc)
|
||||
.GetResult();
|
||||
renderTargets[i] = device.CreateTexture(&descriptor);
|
||||
renderTargetViews[i] = renderTargets[i].CreateTextureViewBuilder().GetResult();
|
||||
}
|
||||
|
||||
|
||||
@@ -72,13 +72,16 @@ class CopyTests_T2B : public CopyTests {
|
||||
|
||||
void DoTest(const TextureSpec& textureSpec, const BufferSpec& bufferSpec) {
|
||||
// Create a texture that is `width` x `height` with (`level` + 1) mip levels.
|
||||
dawn::Texture texture = device.CreateTextureBuilder()
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(textureSpec.width, textureSpec.height, 1)
|
||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
||||
.SetMipLevels(textureSpec.level + 1)
|
||||
.SetAllowedUsage(dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc)
|
||||
.GetResult();
|
||||
dawn::TextureDescriptor descriptor;
|
||||
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||
descriptor.width = textureSpec.width;
|
||||
descriptor.height = textureSpec.height;
|
||||
descriptor.depth = 1;
|
||||
descriptor.arrayLayer = 1;
|
||||
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
descriptor.mipLevel = textureSpec.level + 1;
|
||||
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc;
|
||||
dawn::Texture texture = device.CreateTexture(&descriptor);
|
||||
|
||||
uint32_t width = textureSpec.width >> textureSpec.level;
|
||||
uint32_t height = textureSpec.height >> textureSpec.level;
|
||||
@@ -158,13 +161,16 @@ protected:
|
||||
buffer.SetSubData(0, static_cast<uint32_t>(bufferData.size() * sizeof(RGBA8)), reinterpret_cast<const uint8_t*>(bufferData.data()));
|
||||
|
||||
// Create a texture that is `width` x `height` with (`level` + 1) mip levels.
|
||||
dawn::Texture texture = device.CreateTextureBuilder()
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(textureSpec.width, textureSpec.height, 1)
|
||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
||||
.SetMipLevels(textureSpec.level + 1)
|
||||
.SetAllowedUsage(dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc)
|
||||
.GetResult();
|
||||
dawn::TextureDescriptor descriptor;
|
||||
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||
descriptor.width = textureSpec.width;
|
||||
descriptor.height = textureSpec.height;
|
||||
descriptor.depth = 1;
|
||||
descriptor.arrayLayer = 1;
|
||||
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
descriptor.mipLevel = textureSpec.level + 1;
|
||||
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::TransferSrc;
|
||||
dawn::Texture texture = device.CreateTexture(&descriptor);
|
||||
|
||||
dawn::CommandBuffer commands[2];
|
||||
|
||||
|
||||
@@ -24,23 +24,29 @@ class DepthStencilStateTest : public DawnTest {
|
||||
void SetUp() override {
|
||||
DawnTest::SetUp();
|
||||
|
||||
renderTarget = device.CreateTextureBuilder()
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(kRTSize, kRTSize, 1)
|
||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
||||
.SetMipLevels(1)
|
||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc)
|
||||
.GetResult();
|
||||
dawn::TextureDescriptor renderTargetDescriptor;
|
||||
renderTargetDescriptor.dimension = dawn::TextureDimension::e2D;
|
||||
renderTargetDescriptor.width = kRTSize;
|
||||
renderTargetDescriptor.height = kRTSize;
|
||||
renderTargetDescriptor.depth = 1;
|
||||
renderTargetDescriptor.arrayLayer = 1;
|
||||
renderTargetDescriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
renderTargetDescriptor.mipLevel = 1;
|
||||
renderTargetDescriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc;
|
||||
renderTarget = device.CreateTexture(&renderTargetDescriptor);
|
||||
|
||||
renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult();
|
||||
|
||||
depthTexture = device.CreateTextureBuilder()
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(kRTSize, kRTSize, 1)
|
||||
.SetFormat(dawn::TextureFormat::D32FloatS8Uint)
|
||||
.SetMipLevels(1)
|
||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment)
|
||||
.GetResult();
|
||||
dawn::TextureDescriptor depthDescriptor;
|
||||
depthDescriptor.dimension = dawn::TextureDimension::e2D;
|
||||
depthDescriptor.width = kRTSize;
|
||||
depthDescriptor.height = kRTSize;
|
||||
depthDescriptor.depth = 1;
|
||||
depthDescriptor.arrayLayer = 1;
|
||||
depthDescriptor.format = dawn::TextureFormat::D32FloatS8Uint;
|
||||
depthDescriptor.mipLevel = 1;
|
||||
depthDescriptor.usage = dawn::TextureUsageBit::OutputAttachment;
|
||||
depthTexture = device.CreateTexture(&depthDescriptor);
|
||||
|
||||
depthTextureView = depthTexture.CreateTextureViewBuilder().GetResult();
|
||||
|
||||
|
||||
@@ -55,13 +55,16 @@ class RenderPassLoadOpTests : public DawnTest {
|
||||
void SetUp() override {
|
||||
DawnTest::SetUp();
|
||||
|
||||
renderTarget = device.CreateTextureBuilder()
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(kRTSize, kRTSize, 1)
|
||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
||||
.SetMipLevels(1)
|
||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc)
|
||||
.GetResult();
|
||||
dawn::TextureDescriptor descriptor;
|
||||
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||
descriptor.width = kRTSize;
|
||||
descriptor.height = kRTSize;
|
||||
descriptor.depth = 1;
|
||||
descriptor.arrayLayer = 1;
|
||||
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
descriptor.mipLevel = 1;
|
||||
descriptor.usage = dawn::TextureUsageBit::OutputAttachment | dawn::TextureUsageBit::TransferSrc;
|
||||
renderTarget = device.CreateTexture(&descriptor);
|
||||
|
||||
renderTargetView = renderTarget.CreateTextureViewBuilder().GetResult();
|
||||
|
||||
|
||||
@@ -80,13 +80,16 @@ protected:
|
||||
.SetStage(dawn::ShaderStage::Fragment, fsModule, "main")
|
||||
.GetResult();
|
||||
|
||||
auto texture = device.CreateTextureBuilder()
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(2, 2, 1)
|
||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
||||
.SetMipLevels(1)
|
||||
.SetAllowedUsage(dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled)
|
||||
.GetResult();
|
||||
dawn::TextureDescriptor descriptor;
|
||||
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||
descriptor.width = 2;
|
||||
descriptor.height = 2;
|
||||
descriptor.depth = 1;
|
||||
descriptor.arrayLayer = 1;
|
||||
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
descriptor.mipLevel = 1;
|
||||
descriptor.usage = dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Sampled;
|
||||
dawn::Texture texture = device.CreateTexture(&descriptor);
|
||||
|
||||
// Create a 2x2 checkerboard texture, with black in the top left and bottom right corners.
|
||||
const uint32_t rowPixels = kTextureRowPitchAlignment / sizeof(RGBA8);
|
||||
|
||||
@@ -28,13 +28,16 @@ class CopyCommandTest : public ValidationTest {
|
||||
|
||||
dawn::Texture Create2DTexture(uint32_t width, uint32_t height, uint32_t levels,
|
||||
dawn::TextureFormat format, dawn::TextureUsageBit usage) {
|
||||
dawn::Texture tex = AssertWillBeSuccess(device.CreateTextureBuilder())
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(width, height, 1)
|
||||
.SetFormat(format)
|
||||
.SetMipLevels(levels)
|
||||
.SetAllowedUsage(usage)
|
||||
.GetResult();
|
||||
dawn::TextureDescriptor descriptor;
|
||||
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||
descriptor.width = width;
|
||||
descriptor.height = height;
|
||||
descriptor.depth = 1;
|
||||
descriptor.arrayLayer = 1;
|
||||
descriptor.format = format;
|
||||
descriptor.mipLevel = levels;
|
||||
descriptor.usage = usage;
|
||||
dawn::Texture tex = device.CreateTexture(&descriptor);
|
||||
return tex;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,13 +22,16 @@ class RenderPassDescriptorValidationTest : public ValidationTest {
|
||||
};
|
||||
|
||||
dawn::TextureView Create2DAttachment(dawn::Device& device, uint32_t width, uint32_t height, dawn::TextureFormat format) {
|
||||
dawn::Texture attachment = device.CreateTextureBuilder()
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(width, height, 1)
|
||||
.SetFormat(format)
|
||||
.SetMipLevels(1)
|
||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment)
|
||||
.GetResult();
|
||||
dawn::TextureDescriptor descriptor;
|
||||
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||
descriptor.width = width;
|
||||
descriptor.height = height;
|
||||
descriptor.depth = 1;
|
||||
descriptor.arrayLayer = 1;
|
||||
descriptor.format = format;
|
||||
descriptor.mipLevel = 1;
|
||||
descriptor.usage = dawn::TextureUsageBit::OutputAttachment;
|
||||
dawn::Texture attachment = device.CreateTexture(&descriptor);
|
||||
|
||||
return attachment.CreateTextureViewBuilder()
|
||||
.GetResult();
|
||||
|
||||
@@ -71,13 +71,17 @@ bool ValidationTest::EndExpectDeviceError() {
|
||||
}
|
||||
|
||||
dawn::RenderPassDescriptor ValidationTest::CreateSimpleRenderPass() {
|
||||
auto colorBuffer = device.CreateTextureBuilder()
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(640, 480, 1)
|
||||
.SetFormat(dawn::TextureFormat::R8G8B8A8Unorm)
|
||||
.SetMipLevels(1)
|
||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment)
|
||||
.GetResult();
|
||||
dawn::TextureDescriptor descriptor;
|
||||
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||
descriptor.width = 640;
|
||||
descriptor.height = 480;
|
||||
descriptor.depth = 1;
|
||||
descriptor.arrayLayer = 1;
|
||||
descriptor.format = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
descriptor.mipLevel = 1;
|
||||
descriptor.usage = dawn::TextureUsageBit::OutputAttachment;
|
||||
|
||||
auto colorBuffer = device.CreateTexture(&descriptor);
|
||||
auto colorView = colorBuffer.CreateTextureViewBuilder()
|
||||
.GetResult();
|
||||
|
||||
@@ -119,13 +123,16 @@ ValidationTest::DummyRenderPass ValidationTest::CreateDummyRenderPass() {
|
||||
dummy.height = 400;
|
||||
dummy.attachmentFormat = dawn::TextureFormat::R8G8B8A8Unorm;
|
||||
|
||||
dummy.attachment = AssertWillBeSuccess(device.CreateTextureBuilder())
|
||||
.SetDimension(dawn::TextureDimension::e2D)
|
||||
.SetExtent(dummy.width, dummy.height, 1)
|
||||
.SetFormat(dummy.attachmentFormat)
|
||||
.SetMipLevels(1)
|
||||
.SetAllowedUsage(dawn::TextureUsageBit::OutputAttachment)
|
||||
.GetResult();
|
||||
dawn::TextureDescriptor descriptor;
|
||||
descriptor.dimension = dawn::TextureDimension::e2D;
|
||||
descriptor.width = dummy.width;
|
||||
descriptor.height = dummy.height;
|
||||
descriptor.depth = 1;
|
||||
descriptor.arrayLayer = 1;
|
||||
descriptor.format = dummy.attachmentFormat;
|
||||
descriptor.mipLevel = 1;
|
||||
descriptor.usage = dawn::TextureUsageBit::OutputAttachment;
|
||||
dummy.attachment = device.CreateTexture(&descriptor);
|
||||
|
||||
dawn::TextureView view = AssertWillBeSuccess(dummy.attachment.CreateTextureViewBuilder()).GetResult();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user