fix(rhi): validate opengl compute uav set bindings
This commit is contained in:
@@ -854,3 +854,147 @@ void main() {
|
||||
pipelineState->Shutdown();
|
||||
delete pipelineState;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_SetComputeDescriptorSets_UsesSetAwareImageBindingsOnOpenGL) {
|
||||
if (GetBackendType() != RHIType::OpenGL) {
|
||||
GTEST_SKIP() << "OpenGL-specific compute descriptor binding";
|
||||
}
|
||||
|
||||
auto* openGLDevice = static_cast<OpenGLDevice*>(GetDevice());
|
||||
ASSERT_NE(openGLDevice, nullptr);
|
||||
ASSERT_TRUE(openGLDevice->MakeContextCurrent());
|
||||
|
||||
const uint8_t initialPixel[4] = { 0, 0, 0, 0 };
|
||||
|
||||
TextureDesc textureDesc = {};
|
||||
textureDesc.width = 1;
|
||||
textureDesc.height = 1;
|
||||
textureDesc.depth = 1;
|
||||
textureDesc.mipLevels = 1;
|
||||
textureDesc.arraySize = 1;
|
||||
textureDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
textureDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||||
textureDesc.sampleCount = 1;
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(textureDesc, initialPixel, sizeof(initialPixel), 4);
|
||||
ASSERT_NE(texture, nullptr);
|
||||
|
||||
ResourceViewDesc uavDesc = {};
|
||||
uavDesc.format = textureDesc.format;
|
||||
uavDesc.dimension = ResourceViewDimension::Texture2D;
|
||||
RHIResourceView* uav = GetDevice()->CreateUnorderedAccessView(texture, uavDesc);
|
||||
ASSERT_NE(uav, nullptr);
|
||||
|
||||
DescriptorPoolDesc poolDesc = {};
|
||||
poolDesc.type = DescriptorHeapType::CBV_SRV_UAV;
|
||||
poolDesc.descriptorCount = 1;
|
||||
poolDesc.shaderVisible = true;
|
||||
RHIDescriptorPool* pool = GetDevice()->CreateDescriptorPool(poolDesc);
|
||||
ASSERT_NE(pool, nullptr);
|
||||
|
||||
DescriptorSetLayoutBinding reservedBinding = {};
|
||||
reservedBinding.binding = 0;
|
||||
reservedBinding.type = static_cast<uint32_t>(DescriptorType::UAV);
|
||||
reservedBinding.count = 1;
|
||||
|
||||
DescriptorSetLayoutBinding actualBinding = {};
|
||||
actualBinding.binding = 0;
|
||||
actualBinding.type = static_cast<uint32_t>(DescriptorType::UAV);
|
||||
actualBinding.count = 1;
|
||||
|
||||
DescriptorSetLayoutDesc reservedLayout = {};
|
||||
reservedLayout.bindings = &reservedBinding;
|
||||
reservedLayout.bindingCount = 1;
|
||||
|
||||
DescriptorSetLayoutDesc actualLayout = {};
|
||||
actualLayout.bindings = &actualBinding;
|
||||
actualLayout.bindingCount = 1;
|
||||
|
||||
DescriptorSetLayoutDesc setLayouts[2] = {};
|
||||
setLayouts[0] = reservedLayout;
|
||||
setLayouts[1] = actualLayout;
|
||||
|
||||
RHIPipelineLayoutDesc pipelineLayoutDesc = {};
|
||||
pipelineLayoutDesc.setLayouts = setLayouts;
|
||||
pipelineLayoutDesc.setLayoutCount = 2;
|
||||
RHIPipelineLayout* pipelineLayout = GetDevice()->CreatePipelineLayout(pipelineLayoutDesc);
|
||||
ASSERT_NE(pipelineLayout, nullptr);
|
||||
|
||||
RHIDescriptorSet* descriptorSet = pool->AllocateSet(actualLayout);
|
||||
ASSERT_NE(descriptorSet, nullptr);
|
||||
descriptorSet->Update(0, uav);
|
||||
|
||||
GraphicsPipelineDesc pipelineDesc = {};
|
||||
RHIPipelineState* pipelineState = GetDevice()->CreatePipelineState(pipelineDesc);
|
||||
ASSERT_NE(pipelineState, nullptr);
|
||||
|
||||
ShaderCompileDesc shaderDesc = {};
|
||||
shaderDesc.sourceLanguage = ShaderLanguage::GLSL;
|
||||
static const char* computeSource = R"(
|
||||
#version 430
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
layout(binding = 1, rgba8) uniform writeonly image2D uImage;
|
||||
void main() {
|
||||
imageStore(uImage, ivec2(0, 0), vec4(1.0, 0.0, 0.0, 1.0));
|
||||
}
|
||||
)";
|
||||
shaderDesc.source.assign(computeSource, computeSource + strlen(computeSource));
|
||||
shaderDesc.profile = L"cs_4_30";
|
||||
RHIShader* computeShader = GetDevice()->CreateShader(shaderDesc);
|
||||
ASSERT_NE(computeShader, nullptr);
|
||||
pipelineState->SetComputeShader(computeShader);
|
||||
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
glBindImageTexture(0, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA8);
|
||||
glBindImageTexture(1, 0, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA8);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetPipelineState(pipelineState);
|
||||
RHIDescriptorSet* descriptorSets[] = { descriptorSet };
|
||||
cmdList->SetComputeDescriptorSets(1, 1, descriptorSets, pipelineLayout);
|
||||
|
||||
GLint boundImageAtZero = -1;
|
||||
GLint boundImageAtOne = -1;
|
||||
glGetIntegeri_v(GL_IMAGE_BINDING_NAME, 0, &boundImageAtZero);
|
||||
glGetIntegeri_v(GL_IMAGE_BINDING_NAME, 1, &boundImageAtOne);
|
||||
EXPECT_EQ(boundImageAtZero, 0);
|
||||
EXPECT_EQ(
|
||||
static_cast<unsigned int>(boundImageAtOne),
|
||||
static_cast<unsigned int>(reinterpret_cast<uintptr_t>(texture->GetNativeHandle())));
|
||||
|
||||
cmdList->Dispatch(1, 1, 1);
|
||||
glMemoryBarrier(GL_ALL_BARRIER_BITS);
|
||||
|
||||
uint8_t pixel[4] = {};
|
||||
glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(reinterpret_cast<uintptr_t>(texture->GetNativeHandle())));
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
EXPECT_EQ(pixel[0], 255u);
|
||||
EXPECT_EQ(pixel[1], 0u);
|
||||
EXPECT_EQ(pixel[2], 0u);
|
||||
EXPECT_EQ(pixel[3], 255u);
|
||||
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
computeShader->Shutdown();
|
||||
delete computeShader;
|
||||
pipelineState->Shutdown();
|
||||
delete pipelineState;
|
||||
descriptorSet->Shutdown();
|
||||
delete descriptorSet;
|
||||
pipelineLayout->Shutdown();
|
||||
delete pipelineLayout;
|
||||
pool->Shutdown();
|
||||
delete pool;
|
||||
uav->Shutdown();
|
||||
delete uav;
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ TEST_P(RHITestFixture, PipelineLayout_OpenGLSeparatesOverlappingBindingsAcrossSe
|
||||
GTEST_SKIP() << "OpenGL-specific binding point verification";
|
||||
}
|
||||
|
||||
DescriptorSetLayoutBinding set0Bindings[3] = {};
|
||||
DescriptorSetLayoutBinding set0Bindings[4] = {};
|
||||
set0Bindings[0].binding = 0;
|
||||
set0Bindings[0].type = static_cast<uint32_t>(DescriptorType::CBV);
|
||||
set0Bindings[0].count = 1;
|
||||
@@ -376,10 +376,13 @@ TEST_P(RHITestFixture, PipelineLayout_OpenGLSeparatesOverlappingBindingsAcrossSe
|
||||
set0Bindings[1].type = static_cast<uint32_t>(DescriptorType::SRV);
|
||||
set0Bindings[1].count = 1;
|
||||
set0Bindings[2].binding = 0;
|
||||
set0Bindings[2].type = static_cast<uint32_t>(DescriptorType::Sampler);
|
||||
set0Bindings[2].type = static_cast<uint32_t>(DescriptorType::UAV);
|
||||
set0Bindings[2].count = 1;
|
||||
set0Bindings[3].binding = 0;
|
||||
set0Bindings[3].type = static_cast<uint32_t>(DescriptorType::Sampler);
|
||||
set0Bindings[3].count = 1;
|
||||
|
||||
DescriptorSetLayoutBinding set1Bindings[3] = {};
|
||||
DescriptorSetLayoutBinding set1Bindings[4] = {};
|
||||
set1Bindings[0].binding = 0;
|
||||
set1Bindings[0].type = static_cast<uint32_t>(DescriptorType::CBV);
|
||||
set1Bindings[0].count = 1;
|
||||
@@ -387,14 +390,17 @@ TEST_P(RHITestFixture, PipelineLayout_OpenGLSeparatesOverlappingBindingsAcrossSe
|
||||
set1Bindings[1].type = static_cast<uint32_t>(DescriptorType::SRV);
|
||||
set1Bindings[1].count = 1;
|
||||
set1Bindings[2].binding = 0;
|
||||
set1Bindings[2].type = static_cast<uint32_t>(DescriptorType::Sampler);
|
||||
set1Bindings[2].type = static_cast<uint32_t>(DescriptorType::UAV);
|
||||
set1Bindings[2].count = 1;
|
||||
set1Bindings[3].binding = 0;
|
||||
set1Bindings[3].type = static_cast<uint32_t>(DescriptorType::Sampler);
|
||||
set1Bindings[3].count = 1;
|
||||
|
||||
DescriptorSetLayoutDesc setLayouts[2] = {};
|
||||
setLayouts[0].bindings = set0Bindings;
|
||||
setLayouts[0].bindingCount = 3;
|
||||
setLayouts[0].bindingCount = 4;
|
||||
setLayouts[1].bindings = set1Bindings;
|
||||
setLayouts[1].bindingCount = 3;
|
||||
setLayouts[1].bindingCount = 4;
|
||||
|
||||
RHIPipelineLayoutDesc desc = {};
|
||||
desc.setLayouts = setLayouts;
|
||||
@@ -412,6 +418,8 @@ TEST_P(RHITestFixture, PipelineLayout_OpenGLSeparatesOverlappingBindingsAcrossSe
|
||||
EXPECT_EQ(openGLLayout->GetConstantBufferBindingPoint(1, 0), 1u);
|
||||
EXPECT_EQ(openGLLayout->GetShaderResourceBindingPoint(0, 0), 0u);
|
||||
EXPECT_EQ(openGLLayout->GetShaderResourceBindingPoint(1, 0), 1u);
|
||||
EXPECT_EQ(openGLLayout->GetUnorderedAccessBindingPoint(0, 0), 0u);
|
||||
EXPECT_EQ(openGLLayout->GetUnorderedAccessBindingPoint(1, 0), 1u);
|
||||
EXPECT_EQ(openGLLayout->GetSamplerBindingPoint(0, 0), 0u);
|
||||
EXPECT_EQ(openGLLayout->GetSamplerBindingPoint(1, 0), 1u);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user