Update TextureFormatTests to use WGSL
Bug: dawn:572 Change-Id: I104465bfaf3056e0546cdf08b0aebfb43d84b488 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/33886 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
parent
24bf7a4fbb
commit
1229110f9c
|
@ -146,34 +146,33 @@ class TextureFormatTest : public DawnTest {
|
||||||
FormatTestInfo renderFormatInfo) {
|
FormatTestInfo renderFormatInfo) {
|
||||||
utils::ComboRenderPipelineDescriptor desc(device);
|
utils::ComboRenderPipelineDescriptor desc(device);
|
||||||
|
|
||||||
wgpu::ShaderModule vsModule =
|
wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"(
|
||||||
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
|
[[builtin(vertex_idx)]] var<in> VertexIndex : u32;
|
||||||
#version 450
|
[[builtin(position)]] var<out> Position : vec4<f32>;
|
||||||
void main() {
|
|
||||||
const vec2 pos[3] = vec2[3](
|
[[stage(vertex)]] fn main() -> void {
|
||||||
vec2(-3.0f, -1.0f),
|
const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
|
||||||
vec2( 3.0f, -1.0f),
|
vec2<f32>(-3.0, -1.0),
|
||||||
vec2( 0.0f, 2.0f)
|
vec2<f32>( 3.0, -1.0),
|
||||||
);
|
vec2<f32>( 0.0, 2.0));
|
||||||
gl_Position = vec4(pos[gl_VertexIndex], 0.0f, 1.0f);
|
|
||||||
|
Position = vec4<f32>(pos[VertexIndex], 0.0, 1.0);
|
||||||
})");
|
})");
|
||||||
|
|
||||||
// Compute the prefix needed for GLSL types that handle our texture's data.
|
// Compute the WGSL type of the texture's data.
|
||||||
const char* prefix = utils::GetColorTextureComponentTypePrefix(sampleFormatInfo.format);
|
const char* type = utils::GetColorTextureComponentWGSLType(sampleFormatInfo.format);
|
||||||
|
|
||||||
std::ostringstream fsSource;
|
std::ostringstream fsSource;
|
||||||
fsSource << "#version 450\n";
|
fsSource << "[[set(0), binding(0)]] var<uniform_constant> myTexture : texture_2d<" << type
|
||||||
fsSource << "layout(set=0, binding=0) uniform sampler mySampler;\n";
|
<< ">;\n";
|
||||||
fsSource << "layout(set=0, binding=1) uniform " << prefix << "texture2D myTexture;\n";
|
fsSource << "[[builtin(frag_coord)]] var<in> FragCoord : vec4<f32>;\n";
|
||||||
fsSource << "layout(location=0) out " << prefix << "vec4 fragColor;\n";
|
fsSource << "[[location(0)]] var<out> fragColor : vec4<" << type << ">;\n";
|
||||||
|
fsSource << "[[stage(fragment)]] fn main() -> void {\n";
|
||||||
fsSource << "void main() {\n";
|
fsSource << " fragColor = textureLoad(myTexture, vec2<i32>(FragCoord.xy), 0);\n";
|
||||||
fsSource << " fragColor = texelFetch(" << prefix
|
|
||||||
<< "sampler2D(myTexture, mySampler), ivec2(gl_FragCoord), 0);\n";
|
|
||||||
fsSource << "}";
|
fsSource << "}";
|
||||||
|
|
||||||
wgpu::ShaderModule fsModule = utils::CreateShaderModule(
|
wgpu::ShaderModule fsModule =
|
||||||
device, utils::SingleShaderStage::Fragment, fsSource.str().c_str());
|
utils::CreateShaderModuleFromWGSL(device, fsSource.str().c_str());
|
||||||
|
|
||||||
desc.vertexStage.module = vsModule;
|
desc.vertexStage.module = vsModule;
|
||||||
desc.cFragmentStage.module = fsModule;
|
desc.cFragmentStage.module = fsModule;
|
||||||
|
@ -229,15 +228,8 @@ class TextureFormatTest : public DawnTest {
|
||||||
|
|
||||||
// Prepare objects needed to sample from texture in the renderpass
|
// Prepare objects needed to sample from texture in the renderpass
|
||||||
wgpu::RenderPipeline pipeline = CreateSamplePipeline(sampleFormatInfo, renderFormatInfo);
|
wgpu::RenderPipeline pipeline = CreateSamplePipeline(sampleFormatInfo, renderFormatInfo);
|
||||||
|
wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
|
||||||
// In this test we always use the default values of mag/min/mipmap filter
|
{{0, sampleTexture.CreateView()}});
|
||||||
// (FilterMode::Nearest) because integer/unsigned integer textures must be sampled with
|
|
||||||
// FilterMode::Nearest.
|
|
||||||
wgpu::SamplerDescriptor samplerDesc;
|
|
||||||
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
|
|
||||||
wgpu::BindGroup bindGroup =
|
|
||||||
utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
|
|
||||||
{{0, sampler}, {1, sampleTexture.CreateView()}});
|
|
||||||
|
|
||||||
// Encode commands for the test that fill texture, sample it to render to renderTarget then
|
// Encode commands for the test that fill texture, sample it to render to renderTarget then
|
||||||
// copy renderTarget in a buffer so we can read it easily.
|
// copy renderTarget in a buffer so we can read it easily.
|
||||||
|
|
|
@ -64,6 +64,55 @@ namespace utils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* GetColorTextureComponentWGSLType(wgpu::TextureFormat textureFormat) {
|
||||||
|
switch (textureFormat) {
|
||||||
|
case wgpu::TextureFormat::R8Unorm:
|
||||||
|
case wgpu::TextureFormat::R8Snorm:
|
||||||
|
case wgpu::TextureFormat::R16Float:
|
||||||
|
case wgpu::TextureFormat::RG8Unorm:
|
||||||
|
case wgpu::TextureFormat::RG8Snorm:
|
||||||
|
case wgpu::TextureFormat::R32Float:
|
||||||
|
case wgpu::TextureFormat::RG16Float:
|
||||||
|
case wgpu::TextureFormat::RGBA8Unorm:
|
||||||
|
case wgpu::TextureFormat::RGBA8Snorm:
|
||||||
|
case wgpu::TextureFormat::RGB10A2Unorm:
|
||||||
|
case wgpu::TextureFormat::RG11B10Ufloat:
|
||||||
|
case wgpu::TextureFormat::RGB9E5Ufloat:
|
||||||
|
case wgpu::TextureFormat::RG32Float:
|
||||||
|
case wgpu::TextureFormat::RGBA16Float:
|
||||||
|
case wgpu::TextureFormat::RGBA32Float:
|
||||||
|
case wgpu::TextureFormat::BGRA8Unorm:
|
||||||
|
case wgpu::TextureFormat::BGRA8UnormSrgb:
|
||||||
|
case wgpu::TextureFormat::RGBA8UnormSrgb:
|
||||||
|
return "f32";
|
||||||
|
|
||||||
|
case wgpu::TextureFormat::R8Uint:
|
||||||
|
case wgpu::TextureFormat::R16Uint:
|
||||||
|
case wgpu::TextureFormat::RG8Uint:
|
||||||
|
case wgpu::TextureFormat::R32Uint:
|
||||||
|
case wgpu::TextureFormat::RG16Uint:
|
||||||
|
case wgpu::TextureFormat::RGBA8Uint:
|
||||||
|
case wgpu::TextureFormat::RG32Uint:
|
||||||
|
case wgpu::TextureFormat::RGBA16Uint:
|
||||||
|
case wgpu::TextureFormat::RGBA32Uint:
|
||||||
|
return "u32";
|
||||||
|
|
||||||
|
case wgpu::TextureFormat::R8Sint:
|
||||||
|
case wgpu::TextureFormat::R16Sint:
|
||||||
|
case wgpu::TextureFormat::RG8Sint:
|
||||||
|
case wgpu::TextureFormat::R32Sint:
|
||||||
|
case wgpu::TextureFormat::RG16Sint:
|
||||||
|
case wgpu::TextureFormat::RGBA8Sint:
|
||||||
|
case wgpu::TextureFormat::RG32Sint:
|
||||||
|
case wgpu::TextureFormat::RGBA16Sint:
|
||||||
|
case wgpu::TextureFormat::RGBA32Sint:
|
||||||
|
return "i32";
|
||||||
|
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool TextureFormatSupportsStorageTexture(wgpu::TextureFormat format) {
|
bool TextureFormatSupportsStorageTexture(wgpu::TextureFormat format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case wgpu::TextureFormat::R32Uint:
|
case wgpu::TextureFormat::R32Uint:
|
||||||
|
|
|
@ -88,6 +88,7 @@ namespace utils {
|
||||||
wgpu::TextureFormat::BC7RGBAUnorm, wgpu::TextureFormat::BC7RGBAUnormSrgb};
|
wgpu::TextureFormat::BC7RGBAUnorm, wgpu::TextureFormat::BC7RGBAUnormSrgb};
|
||||||
|
|
||||||
const char* GetColorTextureComponentTypePrefix(wgpu::TextureFormat textureFormat);
|
const char* GetColorTextureComponentTypePrefix(wgpu::TextureFormat textureFormat);
|
||||||
|
const char* GetColorTextureComponentWGSLType(wgpu::TextureFormat textureFormat);
|
||||||
bool TextureFormatSupportsStorageTexture(wgpu::TextureFormat format);
|
bool TextureFormatSupportsStorageTexture(wgpu::TextureFormat format);
|
||||||
|
|
||||||
uint32_t GetTexelBlockSizeInBytes(wgpu::TextureFormat textureFormat);
|
uint32_t GetTexelBlockSizeInBytes(wgpu::TextureFormat textureFormat);
|
||||||
|
|
Loading…
Reference in New Issue