Skip to content

Commit

Permalink
slang test fixes (#44)
Browse files Browse the repository at this point in the history
* fix setting combined texture/sampler

* switch to new debug utils extension

* fix cube texture handling
  • Loading branch information
skallweitNV authored Sep 19, 2024
1 parent 22ff1f8 commit 018d66a
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 227 deletions.
2 changes: 1 addition & 1 deletion include/slang-rhi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ struct Binding
Binding(ComPtr<ITextureView> textureView) : type(BindingType::TextureView), resource(textureView) {}
Binding(ComPtr<ISampler> sampler) : type(BindingType::Sampler) , resource(sampler) {}
Binding(ComPtr<ITextureView> textureView, ComPtr<ISampler> sampler) : type(BindingType::CombinedTextureSampler), resource(textureView), resource2(sampler) {}
Binding(ComPtr<ITexture> texture, ComPtr<ISampler> sampler) : type(BindingType::CombinedTextureSampler) , resource(texture) {}
Binding(ComPtr<ITexture> texture, ComPtr<ISampler> sampler) : type(BindingType::CombinedTextureSampler) , resource(texture), resource2(sampler) {}
Binding(ComPtr<IAccelerationStructure> as) : type(BindingType::AccelerationStructure) , resource(as) {}
Binding(IAccelerationStructure* as) : Binding(ComPtr<IAccelerationStructure>(as)) {}
// clang-format on
Expand Down
10 changes: 4 additions & 6 deletions src/d3d11/d3d11-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,6 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
{
TextureDesc srcDesc = fixupTextureDesc(descIn);

const int effectiveArraySize = calcEffectiveArraySize(srcDesc);

const DXGI_FORMAT format = D3DUtil::getMapFormat(srcDesc.format);
if (format == DXGI_FORMAT_UNKNOWN)
{
Expand All @@ -503,10 +501,10 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
D3D11_SUBRESOURCE_DATA* subResourcesPtr = nullptr;
if (initData)
{
subRes.resize(srcDesc.numMipLevels * effectiveArraySize);
subRes.resize(srcDesc.numMipLevels * srcDesc.arraySize);
{
int subResourceIndex = 0;
for (int i = 0; i < effectiveArraySize; i++)
for (int i = 0; i < srcDesc.arraySize; i++)
{
for (int j = 0; j < srcDesc.numMipLevels; j++)
{
Expand Down Expand Up @@ -540,7 +538,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
desc.Format = format;
desc.MiscFlags = 0;
desc.MipLevels = srcDesc.numMipLevels;
desc.ArraySize = effectiveArraySize;
desc.ArraySize = srcDesc.arraySize;
desc.Width = srcDesc.size.width;
desc.Usage = D3D11_USAGE_DEFAULT;

Expand All @@ -559,7 +557,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
desc.Format = format;
desc.MiscFlags = 0;
desc.MipLevels = srcDesc.numMipLevels;
desc.ArraySize = effectiveArraySize;
desc.ArraySize = srcDesc.arraySize;

desc.Width = srcDesc.size.width;
desc.Height = srcDesc.size.height;
Expand Down
92 changes: 42 additions & 50 deletions src/d3d11/d3d11-helper-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,70 +291,62 @@ void initSrvDesc(const TextureDesc& textureDesc, DXGI_FORMAT pixelFormat, D3D11_
descOut.Format = (pixelFormat == DXGI_FORMAT_UNKNOWN)
? D3DUtil::calcFormat(D3DUtil::USAGE_SRV, D3DUtil::getMapFormat(textureDesc.format))
: pixelFormat;
const int arraySize = calcEffectiveArraySize(textureDesc);
if (arraySize <= 1)

switch(textureDesc.type)
{
switch (textureDesc.type)
case TextureType::Texture1D:
if (textureDesc.arraySize > 1)
{
descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
descOut.Texture1DArray.MostDetailedMip = 0;
descOut.Texture1DArray.MipLevels = textureDesc.numMipLevels;
descOut.Texture1DArray.FirstArraySlice = 0;
descOut.Texture1DArray.ArraySize = textureDesc.arraySize;
}
else
{
case TextureType::Texture1D:
descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
break;
case TextureType::Texture2D:
descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
break;
case TextureType::Texture3D:
descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
break;
default:
SLANG_RHI_ASSERT_FAILURE("Unknown dimension");
descOut.Texture1D.MostDetailedMip = 0;
descOut.Texture1D.MipLevels = textureDesc.numMipLevels;
}

descOut.Texture2D.MipLevels = textureDesc.numMipLevels;
descOut.Texture2D.MostDetailedMip = 0;
}
else if (textureDesc.type == TextureType::TextureCube)
{
break;
case TextureType::Texture2D:
if (textureDesc.arraySize > 1)
{
descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
descOut.Texture2DArray.MostDetailedMip = 0;
descOut.Texture2DArray.MipLevels = textureDesc.numMipLevels;
descOut.Texture2DArray.FirstArraySlice = 0;
descOut.Texture2DArray.ArraySize = textureDesc.arraySize;
}
else
{
descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
descOut.Texture2D.MostDetailedMip = 0;
descOut.Texture2D.MipLevels = textureDesc.numMipLevels;
}
break;
case TextureType::Texture3D:
descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
descOut.Texture3D.MostDetailedMip = 0;
descOut.Texture3D.MipLevels = textureDesc.numMipLevels;
break;
case TextureType::TextureCube:
if (textureDesc.arraySize > 6)
{
descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY;

descOut.TextureCubeArray.NumCubes = textureDesc.arraySize;
descOut.TextureCubeArray.First2DArrayFace = 0;
descOut.TextureCubeArray.MipLevels = textureDesc.numMipLevels;
descOut.TextureCubeArray.MostDetailedMip = 0;
descOut.TextureCubeArray.MipLevels = textureDesc.numMipLevels;
descOut.TextureCubeArray.First2DArrayFace = 0;
descOut.TextureCubeArray.NumCubes = textureDesc.arraySize / 6;
}
else
{
descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;

descOut.TextureCube.MipLevels = textureDesc.numMipLevels;
descOut.TextureCube.MostDetailedMip = 0;
descOut.TextureCube.MipLevels = textureDesc.numMipLevels;
}
}
else
{
SLANG_RHI_ASSERT(textureDesc.size.depth > 1 || arraySize > 1);

switch (textureDesc.type)
{
case TextureType::Texture1D:
descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
break;
case TextureType::Texture2D:
descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
break;
case TextureType::Texture3D:
descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
break;

default:
SLANG_RHI_ASSERT_FAILURE("Unknown dimension");
}

descOut.Texture2DArray.ArraySize = std::max(textureDesc.size.depth, arraySize);
descOut.Texture2DArray.MostDetailedMip = 0;
descOut.Texture2DArray.MipLevels = textureDesc.numMipLevels;
descOut.Texture2DArray.FirstArraySlice = 0;
break;
}
}
} // namespace rhi::d3d11
Expand Down
2 changes: 1 addition & 1 deletion src/d3d12/d3d12-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat

D3D12_RESOURCE_DESC resourceDesc = {};
initTextureDesc(resourceDesc, srcDesc);
const int arraySize = calcEffectiveArraySize(srcDesc);
const int arraySize = srcDesc.arraySize;
const int numMipMaps = srcDesc.numMipLevels;

RefPtr<TextureImpl> texture(new TextureImpl(this, srcDesc));
Expand Down
4 changes: 1 addition & 3 deletions src/d3d12/d3d12-helper-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ Result initTextureDesc(D3D12_RESOURCE_DESC& resourceDesc, const TextureDesc& src
return SLANG_FAIL;
}

const int arraySize = calcEffectiveArraySize(srcDesc);

const D3D12_RESOURCE_DIMENSION dimension = calcResourceDimension(srcDesc.type);
if (dimension == D3D12_RESOURCE_DIMENSION_UNKNOWN)
{
Expand All @@ -220,7 +218,7 @@ Result initTextureDesc(D3D12_RESOURCE_DESC& resourceDesc, const TextureDesc& src
resourceDesc.Format = pixelFormat;
resourceDesc.Width = srcDesc.size.width;
resourceDesc.Height = srcDesc.size.height;
resourceDesc.DepthOrArraySize = (srcDesc.size.depth > 1) ? srcDesc.size.depth : arraySize;
resourceDesc.DepthOrArraySize = srcDesc.type == TextureType::Texture3D ? srcDesc.size.depth : srcDesc.arraySize;

resourceDesc.MipLevels = numMipMaps;
resourceDesc.SampleDesc.Count = srcDesc.sampleCount;
Expand Down
15 changes: 4 additions & 11 deletions src/metal/metal-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
break;
}

bool isArray = desc.arraySize > 0;
GfxCount arrayLength = desc.arraySize / (desc.type == TextureType::TextureCube ? 6 : 1);
bool isArray = arrayLength > 1;

switch (desc.type)
{
Expand Down Expand Up @@ -399,7 +400,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
}

textureDesc->setMipmapLevelCount(desc.numMipLevels);
textureDesc->setArrayLength(isArray ? desc.arraySize : 1);
textureDesc->setArrayLength(arrayLength);
textureDesc->setPixelFormat(pixelFormat);
textureDesc->setUsage(textureUsage);
textureDesc->setSampleCount(desc.sampleCount);
Expand Down Expand Up @@ -432,13 +433,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
return SLANG_FAIL;
}

GfxCount sliceCount = isArray ? desc.arraySize : 1;
if (desc.type == TextureType::TextureCube)
{
sliceCount *= 6;
}

for (Index slice = 0; slice < sliceCount; ++slice)
for (Index slice = 0; slice < desc.arraySize; ++slice)
{
MTL::Region region;
region.origin = MTL::Origin(0, 0, 0);
Expand Down Expand Up @@ -558,8 +553,6 @@ Result DeviceImpl::createTextureView(ITexture* texture, const TextureViewDesc& d

const TextureDesc& textureDesc = textureImpl->m_desc;
SubresourceRange sr = viewImpl->m_desc.subresourceRange;
sr.mipLevelCount = sr.mipLevelCount == 0 ? textureDesc.numMipLevels - sr.mipLevel : sr.mipLevelCount;
sr.layerCount = sr.layerCount == 0 ? textureDesc.arraySize - sr.baseArrayLayer : sr.layerCount;
if (sr.mipLevel == 0 && sr.mipLevelCount == textureDesc.numMipLevels && sr.baseArrayLayer == 0 &&
sr.layerCount == textureDesc.arraySize)
{
Expand Down
2 changes: 2 additions & 0 deletions src/resource-desc-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ BufferDesc fixupBufferDesc(const BufferDesc& desc)
TextureDesc fixupTextureDesc(const TextureDesc& desc)
{
TextureDesc rs = desc;
if (desc.arraySize == 0)
rs.arraySize = desc.type == TextureType::TextureCube ? 6 : 1;
if (desc.numMipLevels == 0)
rs.numMipLevels = calcNumMipLevels(desc.type, desc.size);
return rs;
Expand Down
46 changes: 0 additions & 46 deletions src/resource-desc-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,6 @@ inline Extents calcMipSize(Extents size, int mipLevel)
return rs;
}

/// Calculate the effective array size - in essence the amount if mip map sets needed.
/// In practice takes into account if the arraySize is 0 (it's not an array, but it will still have
/// at least one mip set) and if the type is a cubemap (multiplies the amount of mip sets by 6)
inline int calcEffectiveArraySize(const TextureDesc& desc)
{
const int arrSize = (desc.arraySize > 0) ? desc.arraySize : 1;

switch (desc.type)
{
case TextureType::Texture1D: // fallthru
case TextureType::Texture2D:
{
return arrSize;
}
case TextureType::TextureCube:
return arrSize * 6;
case TextureType::Texture3D:
return 1;
default:
return 0;
}
}

/// Given the type works out the maximum dimension size
inline int calcMaxDimension(Extents size, TextureType type)
{
Expand All @@ -70,29 +47,6 @@ inline int calcNumMipLevels(TextureType type, Extents size)
return (maxDimensionSize > 0) ? (math::log2Floor(maxDimensionSize) + 1) : 0;
}

/// Calculate the total number of sub resources. 0 on error.
inline int calcNumSubResources(const TextureDesc& desc)
{
const int numMipMaps = (desc.numMipLevels > 0) ? desc.numMipLevels : calcNumMipLevels(desc.type, desc.size);
const int arrSize = (desc.arraySize > 0) ? desc.arraySize : 1;

switch (desc.type)
{
case TextureType::Texture1D:
case TextureType::Texture2D:
case TextureType::Texture3D:
{
return numMipMaps * arrSize;
}
case TextureType::TextureCube:
{
// There are 6 faces to a cubemap
return numMipMaps * arrSize * 6;
}
default:
return 0;
}
}

BufferDesc fixupBufferDesc(const BufferDesc& desc);
TextureDesc fixupTextureDesc(const TextureDesc& desc);
Expand Down
11 changes: 5 additions & 6 deletions src/vulkan/vk-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ namespace rhi::vk {
#define VK_API_INSTANCE_PROCS_OPT(x) \
x(vkGetPhysicalDeviceFeatures2) \
x(vkGetPhysicalDeviceProperties2) \
x(vkCreateDebugReportCallbackEXT) \
x(vkDestroyDebugReportCallbackEXT) \
x(vkDebugReportMessageEXT) \
x(vkCreateDebugUtilsMessengerEXT) \
x(vkDestroyDebugUtilsMessengerEXT) \
/* */

#define VK_API_INSTANCE_PROCS(x) \
Expand Down Expand Up @@ -211,9 +210,9 @@ namespace rhi::vk {
x(vkWaitSemaphores) \
x(vkWaitSemaphoresKHR) \
x(vkCmdSetSampleLocationsEXT) \
x(vkCmdDebugMarkerBeginEXT) \
x(vkCmdDebugMarkerEndEXT) \
x(vkDebugMarkerSetObjectNameEXT) \
x(vkCmdBeginDebugUtilsLabelEXT) \
x(vkCmdEndDebugUtilsLabelEXT) \
x(vkSetDebugUtilsObjectNameEXT) \
x(vkCmdDrawMeshTasksEXT) \
/* */

Expand Down
21 changes: 10 additions & 11 deletions src/vulkan/vk-command-encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,24 @@ void CommandEncoderImpl::bufferBarrier(GfxCount count, IBuffer* const* buffers,
void CommandEncoderImpl::beginDebugEvent(const char* name, float rgbColor[3])
{
auto& api = m_commandBuffer->m_device->m_api;
if (api.vkCmdDebugMarkerBeginEXT)
if (api.vkCmdBeginDebugUtilsLabelEXT)
{
VkDebugMarkerMarkerInfoEXT eventInfo = {};
eventInfo.sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_MARKER_INFO_EXT;
eventInfo.pMarkerName = name;
eventInfo.color[0] = rgbColor[0];
eventInfo.color[1] = rgbColor[1];
eventInfo.color[2] = rgbColor[2];
eventInfo.color[3] = 1.0f;
api.vkCmdDebugMarkerBeginEXT(m_commandBuffer->m_commandBuffer, &eventInfo);
VkDebugUtilsLabelEXT label = {VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT};
label.pLabelName = name;
label.color[0] = rgbColor[0];
label.color[1] = rgbColor[1];
label.color[2] = rgbColor[2];
label.color[3] = 1.0f;
api.vkCmdBeginDebugUtilsLabelEXT(m_commandBuffer->m_commandBuffer, &label);
}
}

void CommandEncoderImpl::endDebugEvent()
{
auto& api = m_commandBuffer->m_device->m_api;
if (api.vkCmdDebugMarkerEndEXT)
if (api.vkCmdEndDebugUtilsLabelEXT)
{
api.vkCmdDebugMarkerEndEXT(m_commandBuffer->m_commandBuffer);
api.vkCmdEndDebugUtilsLabelEXT(m_commandBuffer->m_commandBuffer);
}
}

Expand Down
Loading

0 comments on commit 018d66a

Please sign in to comment.