Skip to content

Commit

Permalink
remove SampleDesc
Browse files Browse the repository at this point in the history
  • Loading branch information
skallweitNV committed Aug 30, 2024
1 parent bb26f16 commit 81ae4bc
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- remove SampleDesc and instead add sampleCount and sampleQuality to TextureDesc
- rename ISamplerState -> ISampler
- rename ISamplerState::Desc -> SamlerDesc
- rename BufferDesc::sizeInBytes -> size
Expand Down
15 changes: 5 additions & 10 deletions include/slang-rhi.h
Original file line number Diff line number Diff line change
Expand Up @@ -717,14 +717,6 @@ struct Offset3D
}
};

struct SampleDesc
{
/// Number of samples per pixel.
GfxCount numSamples = 1;
/// The quality measure for the samples.
int quality = 0;
};

struct Extents
{
/// Width in pixels.
Expand All @@ -750,8 +742,11 @@ struct TextureDesc
GfxCount numMipLevels = 0;
/// The resources format.
Format format;
/// How the resource is sampled.
SampleDesc sampleDesc;
/// Number of samples per pixel.
GfxCount sampleCount = 1;
/// The quality measure for the samples.
int sampleQuality = 0;

ClearValue* optimalClearValue = nullptr;
};

Expand Down
2 changes: 1 addition & 1 deletion src/cpu/cpu-resource-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void* TextureViewImpl::_getTexelPtr(int32_t const* texelCoords)
int32_t baseCoordCount = baseShape->baseCoordCount;

bool isArray = (desc.arraySize != 0) || (desc.type == rhi::TextureType::TextureCube);
bool isMultisample = desc.sampleDesc.numSamples > 1;
bool isMultisample = desc.sampleCount > 1;
bool hasMipLevels = !isMultisample;

int32_t effectiveArrayElementCount = texture->m_effectiveArrayElementCount;
Expand Down
6 changes: 3 additions & 3 deletions src/d3d11/d3d11-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ Result DeviceImpl::readTexture(

auto texture = static_cast<TextureImpl*>(resource);
// Don't bother supporting MSAA for right now
if (texture->getDesc()->sampleDesc.numSamples > 1)
if (texture->getDesc()->sampleCount > 1)
{
fprintf(stderr, "ERROR: cannot capture multi-sample texture\n");
return E_INVALIDARG;
Expand Down Expand Up @@ -582,8 +582,8 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
desc.Width = srcDesc.size.width;
desc.Height = srcDesc.size.height;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.SampleDesc.Count = srcDesc.sampleDesc.numSamples;
desc.SampleDesc.Quality = srcDesc.sampleDesc.quality;
desc.SampleDesc.Count = srcDesc.sampleCount;
desc.SampleDesc.Quality = srcDesc.sampleQuality;

if (srcDesc.type == TextureType::TextureCube)
{
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 @@ -1342,7 +1342,7 @@ Result DeviceImpl::createTextureView(ITexture* texture, IResourceView::Desc cons
viewImpl->m_resource = resourceImpl;
viewImpl->m_desc = desc;
bool isArray = resourceImpl ? resourceImpl->getDesc()->arraySize > 1 : false;
bool isMultiSample = resourceImpl ? resourceImpl->getDesc()->sampleDesc.numSamples > 1 : false;
bool isMultiSample = resourceImpl ? resourceImpl->getDesc()->sampleCount > 1 : false;
switch (desc.type)
{
default:
Expand Down
10 changes: 5 additions & 5 deletions src/d3d12/d3d12-helper-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void initSrvDesc(
break;
case D3D12_RESOURCE_DIMENSION_TEXTURE2D:
descOut.ViewDimension =
textureDesc.sampleDesc.numSamples > 1 ? D3D12_SRV_DIMENSION_TEXTURE2DMS : D3D12_SRV_DIMENSION_TEXTURE2D;
textureDesc.sampleCount > 1 ? D3D12_SRV_DIMENSION_TEXTURE2DMS : D3D12_SRV_DIMENSION_TEXTURE2D;
descOut.Texture2D.PlaneSlice = D3DUtil::getPlaneSlice(descOut.Format, subresourceRange.aspectMask);
descOut.Texture2D.ResourceMinLODClamp = 0.0f;
descOut.Texture2D.MipLevels = subresourceRange.mipLevelCount == 0
Expand Down Expand Up @@ -297,8 +297,8 @@ void initSrvDesc(
: subresourceRange.mipLevelCount;
break;
case D3D12_RESOURCE_DIMENSION_TEXTURE2D:
descOut.ViewDimension = textureDesc.sampleDesc.numSamples > 1 ? D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY
: D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
descOut.ViewDimension =
textureDesc.sampleCount > 1 ? D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY : D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
if (descOut.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE2DARRAY)
{
descOut.Texture2DArray.ArraySize =
Expand Down Expand Up @@ -357,8 +357,8 @@ Result initTextureDesc(D3D12_RESOURCE_DESC& resourceDesc, const TextureDesc& src
resourceDesc.DepthOrArraySize = (srcDesc.size.depth > 1) ? srcDesc.size.depth : arraySize;

resourceDesc.MipLevels = numMipMaps;
resourceDesc.SampleDesc.Count = srcDesc.sampleDesc.numSamples;
resourceDesc.SampleDesc.Quality = srcDesc.sampleDesc.quality;
resourceDesc.SampleDesc.Count = srcDesc.sampleCount;
resourceDesc.SampleDesc.Quality = srcDesc.sampleQuality;

resourceDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
Expand Down
8 changes: 4 additions & 4 deletions src/metal/metal-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Result DeviceImpl::readTexture(

TextureImpl* textureImpl = static_cast<TextureImpl*>(texture);

if (textureImpl->getDesc()->sampleDesc.numSamples > 1)
if (textureImpl->getDesc()->sampleCount > 1)
{
return SLANG_E_NOT_IMPLEMENTED;
}
Expand Down Expand Up @@ -374,10 +374,10 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
textureDesc->setWidth(desc.size.width);
break;
case TextureType::Texture2D:
if (desc.sampleDesc.numSamples > 1)
if (desc.sampleCount > 1)
{
textureDesc->setTextureType(isArray ? MTL::TextureType2DMultisampleArray : MTL::TextureType2DMultisample);
textureDesc->setSampleCount(desc.sampleDesc.numSamples);
textureDesc->setSampleCount(desc.sampleCount);
}
else
{
Expand Down Expand Up @@ -432,7 +432,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
textureDesc->setArrayLength(isArray ? desc.arraySize : 1);
textureDesc->setPixelFormat(pixelFormat);
textureDesc->setUsage(textureUsage);
textureDesc->setSampleCount(desc.sampleDesc.numSamples);
textureDesc->setSampleCount(desc.sampleCount);
textureDesc->setAllowGPUOptimizedContents(desc.memoryType == MemoryType::DeviceLocal);

textureImpl->m_texture = NS::TransferPtr(m_device->newTexture(textureDesc.get()));
Expand Down
2 changes: 1 addition & 1 deletion src/metal/metal-framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Result FramebufferImpl::init(DeviceImpl* device, const IFramebuffer::Desc& desc)
const IResourceView::Desc* viewDesc = view->getViewDesc();
m_width = std::max(1u, uint32_t(textureDesc->size.width >> viewDesc->subresourceRange.mipLevel));
m_height = std::max(1u, uint32_t(textureDesc->size.height >> viewDesc->subresourceRange.mipLevel));
m_sampleCount = std::max(m_sampleCount, uint32_t(textureDesc->sampleDesc.numSamples));
m_sampleCount = std::max(m_sampleCount, uint32_t(textureDesc->sampleCount));
return SLANG_OK;
};

Expand Down
6 changes: 3 additions & 3 deletions src/vulkan/vk-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ Result DeviceImpl::getTextureAllocationInfo(const TextureDesc& descIn, Size* out
imageInfo.usage = _calcImageUsageFlags(desc.allowedStates, desc.memoryType, nullptr);
imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;

imageInfo.samples = (VkSampleCountFlagBits)desc.sampleDesc.numSamples;
imageInfo.samples = (VkSampleCountFlagBits)desc.sampleCount;

VkImage image;
SLANG_VK_RETURN_ON_FAIL(m_api.vkCreateImage(m_device, &imageInfo, nullptr, &image));
Expand Down Expand Up @@ -1535,7 +1535,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
imageInfo.usage = _calcImageUsageFlags(desc.allowedStates, desc.memoryType, initData);
imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;

imageInfo.samples = (VkSampleCountFlagBits)desc.sampleDesc.numSamples;
imageInfo.samples = (VkSampleCountFlagBits)desc.sampleCount;

VkExternalMemoryImageCreateInfo externalMemoryImageCreateInfo = {VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO
};
Expand Down Expand Up @@ -1689,7 +1689,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
);

if (desc.sampleDesc.numSamples != 1)
if (desc.sampleCount > 1)
{
// Handle senario where texture is sampled. We cannot use
// a simple buffer copy for sampled textures. ClearColorImage
Expand Down
2 changes: 1 addition & 1 deletion tests/test-resolve-resource-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct BaseResolveResourceTest
msaaTexDesc.defaultState = ResourceState::RenderTarget;
msaaTexDesc.allowedStates = ResourceStateSet(ResourceState::RenderTarget, ResourceState::ResolveSource);
msaaTexDesc.format = format;
msaaTexDesc.sampleDesc.numSamples = 4;
msaaTexDesc.sampleCount = 4;

REQUIRE_CALL(device->createTexture(msaaTexDesc, msaaTextureInfo.initData, msaaTexture.writeRef()));

Expand Down
2 changes: 1 addition & 1 deletion tests/test-texture-types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ struct RenderTargetTests : BaseTextureViewTest
sampledTexDesc.allowedStates =
ResourceStateSet(sampledTexDesc.defaultState, ResourceState::ResolveSource, ResourceState::CopySource);
sampledTexDesc.format = textureInfo->format;
sampledTexDesc.sampleDesc.numSamples = sampleCount;
sampledTexDesc.sampleCount = sampleCount;

REQUIRE_CALL(
device->createTexture(sampledTexDesc, textureInfo->subresourceDatas.data(), sampledTexture.writeRef())
Expand Down

0 comments on commit 81ae4bc

Please sign in to comment.