Commit 0d218da4 by Xinghua Cao Committed by Commit Bot

Specify texture LOD in compute shader on D3D backend

D3D does not define LOD in compute shader, so Sample() is not supported, try to use SampleLevel(). Bug: angleproject:2756 TEST=angle_end2end_tests.ComputeShaderTest .TextureFunction/ES3_1_D3D11 dEQP.GLES31/functional_image_load_store_2d_store* Change-Id: I63e707d2b56e807cfe766cc21bc6b0819982ce80 Reviewed-on: https://chromium-review.googlesource.com/c/1379672 Commit-Queue: Xinghua Cao <xinghua.cao@intel.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 2db5082b
......@@ -1396,7 +1396,7 @@ ImmutableString TextureFunctionHLSL::useTextureFunction(const ImmutableString &n
bool bias = (argumentCount > mandatoryArgumentCount); // Bias argument is optional
if (lod0 || shaderType == GL_VERTEX_SHADER)
if (lod0 || shaderType == GL_VERTEX_SHADER || shaderType == GL_COMPUTE_SHADER)
{
if (bias)
{
......
......@@ -616,8 +616,8 @@ void main()
EXPECT_GL_NO_ERROR();
}
// Test that sampling texture works well in compute shader.
TEST_P(ComputeShaderTest, TextureSampling)
// Test that texelFetch works well in compute shader.
TEST_P(ComputeShaderTest, TexelFetchFunction)
{
ANGLE_SKIP_TEST_IF(IsD3D11());
......@@ -666,7 +666,7 @@ void main()
EXPECT_GL_NO_ERROR();
ANGLE_GL_COMPUTE_PROGRAM(program, kCS);
glUseProgram(program.get());
glUseProgram(program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
......@@ -677,16 +677,83 @@ void main()
glDispatchCompute(1, 1, 1);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
void *ptr = glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kWidth * kHeight * kArrayStride,
GL_MAP_READ_BIT);
const GLuint *ptr = reinterpret_cast<const GLuint *>(glMapBufferRange(
GL_SHADER_STORAGE_BUFFER, 0, kWidth * kHeight * kArrayStride, GL_MAP_READ_BIT));
EXPECT_GL_NO_ERROR();
for (unsigned int idx = 0; idx < kWidth * kHeight; idx++)
{
EXPECT_EQ(idx, *(reinterpret_cast<const GLuint *>(reinterpret_cast<const GLbyte *>(ptr) +
idx * kArrayStride)));
EXPECT_EQ(idx, *(ptr + idx * kArrayStride / 4));
}
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
}
// Test that texture function works well in compute shader.
TEST_P(ComputeShaderTest, TextureFunction)
{
constexpr char kCS[] = R"(#version 310 es
layout(local_size_x=16, local_size_y=16) in;
precision highp usampler2D;
uniform usampler2D tex;
layout(std140, binding = 0) buffer buf {
uint outData[16][16];
};
void main()
{
uint x = gl_LocalInvocationID.x;
uint y = gl_LocalInvocationID.y;
float xCoord = float(x) / float(16);
float yCoord = float(y) / float(16);
outData[y][x] = texture(tex, vec2(xCoord, yCoord)).x;
})";
constexpr unsigned int kWidth = 16;
constexpr unsigned int kHeight = 16;
GLTexture tex;
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32UI, kWidth, kHeight);
GLuint texels[kHeight][kWidth] = {{0}};
for (unsigned int y = 0; y < kHeight; ++y)
{
for (unsigned int x = 0; x < kWidth; ++x)
{
texels[y][x] = x + y * kWidth;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT,
texels);
glBindTexture(GL_TEXTURE_2D, 0);
// The array stride are rounded up to the base alignment of a vec4 for std140 layout.
constexpr unsigned int kArrayStride = 16;
GLBuffer ssbo;
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
glBufferData(GL_SHADER_STORAGE_BUFFER, kWidth * kHeight * kArrayStride, nullptr,
GL_STREAM_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
EXPECT_GL_NO_ERROR();
ANGLE_GL_COMPUTE_PROGRAM(program, kCS);
glUseProgram(program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glUniform1i(glGetUniformLocation(program, "tex"), 0);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, ssbo);
glDispatchCompute(1, 1, 1);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
const GLuint *ptr = reinterpret_cast<const GLuint *>(glMapBufferRange(
GL_SHADER_STORAGE_BUFFER, 0, kWidth * kHeight * kArrayStride, GL_MAP_READ_BIT));
EXPECT_GL_NO_ERROR();
for (unsigned int idx = 0; idx < kWidth * kHeight; idx++)
{
EXPECT_EQ(idx, *(ptr + idx * kArrayStride / 4));
}
}
// Test mixed use of sampler and image.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment