Add texture clamp mode

This commit is contained in:
Jack Andersen 2017-09-30 18:23:28 -10:00
parent cbaa016b11
commit 2a49a8d447
12 changed files with 232 additions and 209 deletions

View File

@ -25,11 +25,11 @@ public:
IGraphicsBufferD* newDynamicBuffer(BufferUse use, size_t stride, size_t count); IGraphicsBufferD* newDynamicBuffer(BufferUse use, size_t stride, size_t count);
ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt, ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz); TextureClampMode clampMode, const void* data, size_t sz);
ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips, ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips,
TextureFormat fmt, const void* data, size_t sz); TextureFormat fmt, TextureClampMode clampMode, const void* data, size_t sz);
ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt); ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt, TextureClampMode clampMode);
ITextureR* newRenderTexture(size_t width, size_t height, ITextureR* newRenderTexture(size_t width, size_t height, TextureClampMode clampMode,
size_t colorBindingCount, size_t depthBindingCount); size_t colorBindingCount, size_t depthBindingCount);
bool bindingNeedsVertexFormat() const {return true;} bool bindingNeedsVertexFormat() const {return true;}

View File

@ -115,6 +115,12 @@ enum class TextureFormat
PVRTC4 PVRTC4
}; };
enum class TextureClampMode
{
Repeat,
ClampToWhite
};
/** Opaque token for representing the data layout of a vertex /** Opaque token for representing the data layout of a vertex
* in a VBO. Also able to reference buffers for platforms like * in a VBO. Also able to reference buffers for platforms like
* OpenGL that cache object refs */ * OpenGL that cache object refs */
@ -253,14 +259,14 @@ struct IGraphicsDataFactory
virtual ITextureS* virtual ITextureS*
newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt, newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz)=0; TextureClampMode clampMode, const void* data, size_t sz)=0;
virtual ITextureSA* virtual ITextureSA*
newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips, newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips,
TextureFormat fmt, const void* data, size_t sz)=0; TextureFormat fmt, TextureClampMode clampMode, const void* data, size_t sz)=0;
virtual ITextureD* virtual ITextureD*
newDynamicTexture(size_t width, size_t height, TextureFormat fmt)=0; newDynamicTexture(size_t width, size_t height, TextureFormat fmt, TextureClampMode clampMode)=0;
virtual ITextureR* virtual ITextureR*
newRenderTexture(size_t width, size_t height, newRenderTexture(size_t width, size_t height, TextureClampMode clampMode,
size_t colorBindingCount, size_t depthBindingCount)=0; size_t colorBindingCount, size_t depthBindingCount)=0;
virtual bool bindingNeedsVertexFormat() const=0; virtual bool bindingNeedsVertexFormat() const=0;

View File

@ -26,11 +26,11 @@ public:
IGraphicsBufferD* newDynamicBuffer(BufferUse use, size_t stride, size_t count); IGraphicsBufferD* newDynamicBuffer(BufferUse use, size_t stride, size_t count);
ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt, ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz); TextureClampMode clampMode, const void* data, size_t sz);
ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips, ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips,
TextureFormat fmt, const void* data, size_t sz); TextureFormat fmt, TextureClampMode clampMode, const void* data, size_t sz);
ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt); ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt, TextureClampMode clampMode);
ITextureR* newRenderTexture(size_t width, size_t height, ITextureR* newRenderTexture(size_t width, size_t height, TextureClampMode clampMode,
size_t colorBindCount, size_t depthBindCount); size_t colorBindCount, size_t depthBindCount);
bool bindingNeedsVertexFormat() const {return false;} bool bindingNeedsVertexFormat() const {return false;}

View File

@ -43,7 +43,7 @@ struct VulkanContext
VkRenderPass m_pass; VkRenderPass m_pass;
VkCommandPool m_loadPool; VkCommandPool m_loadPool;
VkCommandBuffer m_loadCmdBuf; VkCommandBuffer m_loadCmdBuf;
VkSampler m_linearSampler; VkSampler m_linearSamplers[2];
VkFormat m_displayFormat; VkFormat m_displayFormat;
struct Window struct Window
@ -117,11 +117,11 @@ public:
IGraphicsBufferD* newDynamicBuffer(BufferUse use, size_t stride, size_t count); IGraphicsBufferD* newDynamicBuffer(BufferUse use, size_t stride, size_t count);
ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt, ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz); TextureClampMode clampMode, const void* data, size_t sz);
ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips, ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips,
TextureFormat fmt, const void* data, size_t sz); TextureFormat fmt, TextureClampMode clampMode, const void* data, size_t sz);
ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt); ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt, TextureClampMode clampMode);
ITextureR* newRenderTexture(size_t width, size_t height, ITextureR* newRenderTexture(size_t width, size_t height, TextureClampMode clampMode,
size_t colorBindCount, size_t depthBindCount); size_t colorBindCount, size_t depthBindCount);
bool bindingNeedsVertexFormat() const {return false;} bool bindingNeedsVertexFormat() const {return false;}

View File

@ -314,29 +314,25 @@ class D3D11TextureR : public ITextureR
size_t m_colorBindCount; size_t m_colorBindCount;
size_t m_depthBindCount; size_t m_depthBindCount;
void Setup(D3D11Context* ctx, size_t width, size_t height, size_t samples, void Setup(D3D11Context* ctx)
size_t colorBindCount, size_t depthBindCount)
{ {
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM, width, height, ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height,
1, 1, D3D11_BIND_RENDER_TARGET, D3D11_USAGE_DEFAULT, 0, samples), nullptr, &m_colorTex)); 1, 1, D3D11_BIND_RENDER_TARGET, D3D11_USAGE_DEFAULT, 0, m_samples), nullptr, &m_colorTex));
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_D24_UNORM_S8_UINT, width, height, ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_D24_UNORM_S8_UINT, m_width, m_height,
1, 1, D3D11_BIND_DEPTH_STENCIL, D3D11_USAGE_DEFAULT, 0, samples), nullptr, &m_depthTex)); 1, 1, D3D11_BIND_DEPTH_STENCIL, D3D11_USAGE_DEFAULT, 0, m_samples), nullptr, &m_depthTex));
D3D11_RTV_DIMENSION rtvDim; D3D11_RTV_DIMENSION rtvDim;
D3D11_DSV_DIMENSION dsvDim; D3D11_DSV_DIMENSION dsvDim;
D3D11_SRV_DIMENSION srvDim;
if (samples > 1) if (samples > 1)
{ {
rtvDim = D3D11_RTV_DIMENSION_TEXTURE2DMS; rtvDim = D3D11_RTV_DIMENSION_TEXTURE2DMS;
dsvDim = D3D11_DSV_DIMENSION_TEXTURE2DMS; dsvDim = D3D11_DSV_DIMENSION_TEXTURE2DMS;
srvDim = D3D11_SRV_DIMENSION_TEXTURE2DMS;
} }
else else
{ {
rtvDim = D3D11_RTV_DIMENSION_TEXTURE2D; rtvDim = D3D11_RTV_DIMENSION_TEXTURE2D;
dsvDim = D3D11_DSV_DIMENSION_TEXTURE2D; dsvDim = D3D11_DSV_DIMENSION_TEXTURE2D;
srvDim = D3D11_SRV_DIMENSION_TEXTURE2D;
} }
ThrowIfFailed(ctx->m_dev->CreateRenderTargetView(m_colorTex.Get(), ThrowIfFailed(ctx->m_dev->CreateRenderTargetView(m_colorTex.Get(),
@ -344,20 +340,21 @@ class D3D11TextureR : public ITextureR
ThrowIfFailed(ctx->m_dev->CreateDepthStencilView(m_depthTex.Get(), ThrowIfFailed(ctx->m_dev->CreateDepthStencilView(m_depthTex.Get(),
&CD3D11_DEPTH_STENCIL_VIEW_DESC(m_depthTex.Get(), dsvDim), &m_dsv)); &CD3D11_DEPTH_STENCIL_VIEW_DESC(m_depthTex.Get(), dsvDim), &m_dsv));
for (size_t i=0 ; i<colorBindCount ; ++i) for (size_t i=0 ; i<m_colorBindCount ; ++i)
{ {
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM, width, height, ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height,
1, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0, samples), nullptr, &m_colorBindTex[i])); 1, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0, 1), nullptr, &m_colorBindTex[i]));
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_colorBindTex[i].Get(), ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_colorBindTex[i].Get(),
&CD3D11_SHADER_RESOURCE_VIEW_DESC(m_colorBindTex[i].Get(), srvDim), &m_colorSrv[i])); &CD3D11_SHADER_RESOURCE_VIEW_DESC(m_colorBindTex[i].Get(), D3D11_SRV_DIMENSION_TEXTURE2D), &m_colorSrv[i]));
} }
for (size_t i=0 ; i<depthBindCount ; ++i) for (size_t i=0 ; i<m_depthBindCount ; ++i)
{ {
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R24G8_TYPELESS, width, height, ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R24G8_TYPELESS, m_width, m_height,
1, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0, samples), nullptr, &m_depthBindTex[i])); 1, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0, 1), nullptr, &m_depthBindTex[i]));
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_depthBindTex[i].Get(), ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_depthBindTex[i].Get(),
&CD3D11_SHADER_RESOURCE_VIEW_DESC(m_depthBindTex[i].Get(), srvDim, DXGI_FORMAT_R24_UNORM_X8_TYPELESS), &m_depthSrv[i])); &CD3D11_SHADER_RESOURCE_VIEW_DESC(m_depthBindTex[i].Get(), D3D11_SRV_DIMENSION_TEXTURE2D,
DXGI_FORMAT_R24_UNORM_X8_TYPELESS), &m_depthSrv[i]));
} }
} }
@ -372,7 +369,7 @@ class D3D11TextureR : public ITextureR
Log.report(logvisor::Fatal, "too many depth bindings for render texture"); Log.report(logvisor::Fatal, "too many depth bindings for render texture");
if (samples == 0) m_samples = 1; if (samples == 0) m_samples = 1;
Setup(ctx, width, height, samples, colorBindCount, depthBindCount); Setup(ctx);
} }
public: public:
size_t samples() const {return m_samples;} size_t samples() const {return m_samples;}
@ -398,7 +395,7 @@ public:
height = 1; height = 1;
m_width = width; m_width = width;
m_height = height; m_height = height;
Setup(ctx, width, height, m_samples, m_colorBindCount, m_depthBindCount); Setup(ctx);
} }
}; };
@ -1024,8 +1021,8 @@ struct D3D11CommandQueue : IGraphicsCommandQueue
cbind->bind(m_deferredCtx.Get(), m_fillBuf); cbind->bind(m_deferredCtx.Get(), m_fillBuf);
m_cmdLists[m_fillBuf].resTokens.push_back(cbind->lock()); m_cmdLists[m_fillBuf].resTokens.push_back(cbind->lock());
ID3D11SamplerState* samp[] = {m_ctx->m_ss.Get()}; ID3D11SamplerState* samp[] = {m_ctx->m_ss[0].Get(), m_ctx->m_ss[1].Get()};
m_deferredCtx->PSSetSamplers(0, 1, samp); m_deferredCtx->PSSetSamplers(0, 2, samp);
} }
D3D11TextureR* m_boundTarget; D3D11TextureR* m_boundTarget;

View File

@ -435,8 +435,7 @@ class D3D12TextureR : public ITextureR
size_t m_colorBindCount; size_t m_colorBindCount;
size_t m_depthBindCount; size_t m_depthBindCount;
void Setup(D3D12Context* ctx, size_t width, size_t height, size_t samples, void Setup(D3D12Context* ctx)
size_t colorBindCount, size_t depthBindCount)
{ {
D3D12_DESCRIPTOR_HEAP_DESC rtvdesc = {D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1}; D3D12_DESCRIPTOR_HEAP_DESC rtvdesc = {D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1};
ThrowIfFailed(ctx->m_dev->CreateDescriptorHeap(&rtvdesc, __uuidof(ID3D12DescriptorHeap), &m_rtvHeap)); ThrowIfFailed(ctx->m_dev->CreateDescriptorHeap(&rtvdesc, __uuidof(ID3D12DescriptorHeap), &m_rtvHeap));
@ -449,30 +448,32 @@ class D3D12TextureR : public ITextureR
CD3DX12_RESOURCE_DESC rtvresdesc; CD3DX12_RESOURCE_DESC rtvresdesc;
CD3DX12_RESOURCE_DESC dsvresdesc; CD3DX12_RESOURCE_DESC dsvresdesc;
CD3DX12_RESOURCE_DESC cbindresdesc; CD3DX12_RESOURCE_DESC cbindresdesc;
CD3DX12_RESOURCE_DESC dbindresdesc;
if (samples > 1) if (m_samples > 1)
{ {
rtvDim = D3D12_RTV_DIMENSION_TEXTURE2DMS; rtvDim = D3D12_RTV_DIMENSION_TEXTURE2DMS;
dsvDim = D3D12_DSV_DIMENSION_TEXTURE2DMS; dsvDim = D3D12_DSV_DIMENSION_TEXTURE2DMS;
rtvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, width, height, 1, 1, samples, rtvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, 1, 1, m_samples,
0, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT); 0, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT);
dsvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R24G8_TYPELESS, width, height, 1, 1, samples, dsvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R24G8_TYPELESS, m_width, m_height, 1, 1, m_samples,
0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT); 0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT);
cbindresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, width, height, 1, 1, samples,
0, D3D12_RESOURCE_FLAG_NONE, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT);
} }
else else
{ {
rtvDim = D3D12_RTV_DIMENSION_TEXTURE2D; rtvDim = D3D12_RTV_DIMENSION_TEXTURE2D;
dsvDim = D3D12_DSV_DIMENSION_TEXTURE2D; dsvDim = D3D12_DSV_DIMENSION_TEXTURE2D;
rtvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, width, height, 1, 1, 1, rtvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, 1, 1, 1,
0, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET); 0, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET);
dsvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R24G8_TYPELESS, width, height, 1, 1, 1, dsvresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R24G8_TYPELESS, m_width, m_height, 1, 1, 1,
0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL); 0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL);
cbindresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, width, height, 1, 1, 1,
0, D3D12_RESOURCE_FLAG_NONE);
} }
cbindresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, 1, 1, 1,
0, D3D12_RESOURCE_FLAG_NONE);
dbindresdesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R24G8_TYPELESS, m_width, m_height, 1, 1, 1,
0, D3D12_RESOURCE_FLAG_NONE);
D3D12_CLEAR_VALUE colorClear = {}; D3D12_CLEAR_VALUE colorClear = {};
colorClear.Format = DXGI_FORMAT_R8G8B8A8_UNORM; colorClear.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE,
@ -491,17 +492,17 @@ class D3D12TextureR : public ITextureR
D3D12_DEPTH_STENCIL_VIEW_DESC dsvvdesc = {DXGI_FORMAT_D24_UNORM_S8_UINT, dsvDim}; D3D12_DEPTH_STENCIL_VIEW_DESC dsvvdesc = {DXGI_FORMAT_D24_UNORM_S8_UINT, dsvDim};
ctx->m_dev->CreateDepthStencilView(m_depthTex.Get(), &dsvvdesc, m_dsvHeap->GetCPUDescriptorHandleForHeapStart()); ctx->m_dev->CreateDepthStencilView(m_depthTex.Get(), &dsvvdesc, m_dsvHeap->GetCPUDescriptorHandleForHeapStart());
for (size_t i=0 ; i<colorBindCount ; ++i) for (size_t i=0 ; i<m_colorBindCount ; ++i)
{ {
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE,
&cbindresdesc, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, nullptr, &cbindresdesc, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, nullptr,
__uuidof(ID3D12Resource), &m_colorBindTex[i])); __uuidof(ID3D12Resource), &m_colorBindTex[i]));
} }
for (size_t i=0 ; i<depthBindCount ; ++i) for (size_t i=0 ; i<m_depthBindCount ; ++i)
{ {
ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, ThrowIfFailed(ctx->m_dev->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE,
&dsvresdesc, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, nullptr, &dbindresdesc, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, nullptr,
__uuidof(ID3D12Resource), &m_depthBindTex[i])); __uuidof(ID3D12Resource), &m_depthBindTex[i]));
} }
} }
@ -519,7 +520,7 @@ class D3D12TextureR : public ITextureR
Log.report(logvisor::Fatal, "too many depth bindings for render texture"); Log.report(logvisor::Fatal, "too many depth bindings for render texture");
if (samples == 0) m_samples = 1; if (samples == 0) m_samples = 1;
Setup(ctx, width, height, samples, colorBindCount, depthBindCount); Setup(ctx);
} }
public: public:
size_t samples() const {return m_samples;} size_t samples() const {return m_samples;}
@ -543,7 +544,7 @@ public:
height = 1; height = 1;
m_width = width; m_width = width;
m_height = height; m_height = height;
Setup(ctx, width, height, m_samples, m_colorBindCount, m_depthBindCount); Setup(ctx);
} }
}; };
@ -1739,8 +1740,16 @@ public:
ComPtr<ID3DBlob> rsOutBlob; ComPtr<ID3DBlob> rsOutBlob;
ComPtr<ID3DBlob> rsErrorBlob; ComPtr<ID3DBlob> rsErrorBlob;
D3D12_STATIC_SAMPLER_DESC samplers[] =
{
CD3DX12_STATIC_SAMPLER_DESC(0),
CD3DX12_STATIC_SAMPLER_DESC(1, D3D12_FILTER_ANISOTROPIC, D3D12_TEXTURE_ADDRESS_MODE_BORDER,
D3D12_TEXTURE_ADDRESS_MODE_BORDER, D3D12_TEXTURE_ADDRESS_MODE_BORDER)
};
ThrowIfFailed(D3D12SerializeRootSignaturePROC( ThrowIfFailed(D3D12SerializeRootSignaturePROC(
&CD3DX12_ROOT_SIGNATURE_DESC(1, rootParms, 1, &CD3DX12_STATIC_SAMPLER_DESC(0), &CD3DX12_ROOT_SIGNATURE_DESC(1, rootParms, 2, samplers,
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT),
D3D_ROOT_SIGNATURE_VERSION_1, &rsOutBlob, &rsErrorBlob)); D3D_ROOT_SIGNATURE_VERSION_1, &rsOutBlob, &rsErrorBlob));

View File

@ -172,12 +172,35 @@ GLDataFactory::Context::newStaticBuffer(BufferUse use, const void* data, size_t
return retval; return retval;
} }
static void SetClampMode(GLenum target, TextureClampMode clampMode)
{
switch (clampMode)
{
case TextureClampMode::Repeat:
{
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
break;
}
case TextureClampMode::ClampToWhite:
{
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
GLfloat color[] = {1.f, 1.f, 1.f, 1.f};
glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, color);
break;
}
}
}
class GLTextureS : public ITextureS class GLTextureS : public ITextureS
{ {
friend class GLDataFactory; friend class GLDataFactory;
GLuint m_tex; GLuint m_tex;
GLTextureS(GLData* parent, size_t width, size_t height, size_t mips, GLTextureS(GLData* parent, size_t width, size_t height, size_t mips,
TextureFormat fmt, const void* data, size_t sz) TextureFormat fmt, TextureClampMode clampMode, const void* data, size_t sz)
: ITextureS(parent) : ITextureS(parent)
{ {
const uint8_t* dataIt = static_cast<const uint8_t*>(data); const uint8_t* dataIt = static_cast<const uint8_t*>(data);
@ -192,6 +215,8 @@ class GLTextureS : public ITextureS
else else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
SetClampMode(GL_TEXTURE_2D, clampMode);
GLenum intFormat, format; GLenum intFormat, format;
int pxPitch; int pxPitch;
bool compressed = false; bool compressed = false;
@ -256,7 +281,7 @@ class GLTextureSA : public ITextureSA
friend class GLDataFactory; friend class GLDataFactory;
GLuint m_tex; GLuint m_tex;
GLTextureSA(GLData* parent, size_t width, size_t height, size_t layers, size_t mips, GLTextureSA(GLData* parent, size_t width, size_t height, size_t layers, size_t mips,
TextureFormat fmt, const void* data, size_t sz) TextureFormat fmt, TextureClampMode clampMode, const void* data, size_t sz)
: ITextureSA(parent) : ITextureSA(parent)
{ {
const uint8_t* dataIt = static_cast<const uint8_t*>(data); const uint8_t* dataIt = static_cast<const uint8_t*>(data);
@ -271,6 +296,8 @@ class GLTextureSA : public ITextureSA
else else
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
SetClampMode(GL_TEXTURE_2D_ARRAY, clampMode);
GLenum intFormat, format; GLenum intFormat, format;
int pxPitch; int pxPitch;
if (fmt == TextureFormat::RGBA8) if (fmt == TextureFormat::RGBA8)
@ -317,7 +344,7 @@ class GLTextureD : public ITextureD
size_t m_width = 0; size_t m_width = 0;
size_t m_height = 0; size_t m_height = 0;
int m_validMask = 0; int m_validMask = 0;
GLTextureD(IGraphicsData* parent, size_t width, size_t height, TextureFormat fmt); GLTextureD(IGraphicsData* parent, size_t width, size_t height, TextureFormat fmt, TextureClampMode clampMode);
void update(int b); void update(int b);
public: public:
~GLTextureD(); ~GLTextureD();
@ -344,7 +371,7 @@ class GLTextureR : public ITextureR
size_t m_samples = 0; size_t m_samples = 0;
GLenum m_target; GLenum m_target;
GLTextureR(IGraphicsData* parent, GLCommandQueue* q, size_t width, size_t height, size_t samples, GLTextureR(IGraphicsData* parent, GLCommandQueue* q, size_t width, size_t height, size_t samples,
size_t colorBindCount, size_t depthBindCount); TextureClampMode clampMode, size_t colorBindCount, size_t depthBindCount);
public: public:
~GLTextureR(); ~GLTextureR();
@ -365,24 +392,6 @@ public:
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, m_samples, GL_RGBA, width, height, GL_FALSE); glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, m_samples, GL_RGBA, width, height, GL_FALSE);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_texs[1]); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_texs[1]);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, m_samples, GL_DEPTH_COMPONENT24, width, height, GL_FALSE); glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, m_samples, GL_DEPTH_COMPONENT24, width, height, GL_FALSE);
for (int i=0 ; i<MAX_BIND_TEXS ; ++i)
{
if (m_bindTexs[0][i])
{
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_bindTexs[0][i]);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, m_samples, GL_RGBA, width, height, GL_FALSE);
}
}
for (int i=0 ; i<MAX_BIND_TEXS ; ++i)
{
if (m_bindTexs[1][i])
{
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_bindTexs[1][i]);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, m_samples, GL_DEPTH_COMPONENT24, width, height, GL_FALSE);
}
}
} }
else else
{ {
@ -394,6 +403,7 @@ public:
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
for (int i=0 ; i<MAX_BIND_TEXS ; ++i) for (int i=0 ; i<MAX_BIND_TEXS ; ++i)
{ {
@ -413,25 +423,24 @@ public:
} }
} }
} }
}
}; };
ITextureS* ITextureS*
GLDataFactory::Context::newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt, GLDataFactory::Context::newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz) TextureClampMode clampMode, const void* data, size_t sz)
{ {
GLData* d = GLDataFactoryImpl::m_deferredData.get(); GLData* d = GLDataFactoryImpl::m_deferredData.get();
GLTextureS* retval = new GLTextureS(d, width, height, mips, fmt, data, sz); GLTextureS* retval = new GLTextureS(d, width, height, mips, fmt, clampMode, data, sz);
d->m_STexs.emplace_back(retval); d->m_STexs.emplace_back(retval);
return retval; return retval;
} }
ITextureSA* ITextureSA*
GLDataFactory::Context::newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips, GLDataFactory::Context::newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips,
TextureFormat fmt, const void *data, size_t sz) TextureFormat fmt, TextureClampMode clampMode, const void *data, size_t sz)
{ {
GLData* d = GLDataFactoryImpl::m_deferredData.get(); GLData* d = GLDataFactoryImpl::m_deferredData.get();
GLTextureSA* retval = new GLTextureSA(d, width, height, layers, mips, fmt, data, sz); GLTextureSA* retval = new GLTextureSA(d, width, height, layers, mips, fmt, clampMode, data, sz);
d->m_SATexs.emplace_back(retval); d->m_SATexs.emplace_back(retval);
return retval; return retval;
} }
@ -1597,7 +1606,8 @@ GLDataFactory::Context::newDynamicBuffer(BufferUse use, size_t stride, size_t co
return retval; return retval;
} }
GLTextureD::GLTextureD(IGraphicsData* parent, size_t width, size_t height, TextureFormat fmt) GLTextureD::GLTextureD(IGraphicsData* parent, size_t width, size_t height, TextureFormat fmt,
TextureClampMode clampMode)
: boo::ITextureD(parent), m_width(width), m_height(height) : boo::ITextureD(parent), m_width(width), m_height(height)
{ {
int pxPitch = 4; int pxPitch = 4;
@ -1626,6 +1636,7 @@ GLTextureD::GLTextureD(IGraphicsData* parent, size_t width, size_t height, Textu
glTexImage2D(GL_TEXTURE_2D, 0, m_intFormat, width, height, 0, m_format, GL_UNSIGNED_BYTE, nullptr); glTexImage2D(GL_TEXTURE_2D, 0, m_intFormat, width, height, 0, m_format, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
SetClampMode(GL_TEXTURE_2D, clampMode);
} }
} }
GLTextureD::~GLTextureD() {glDeleteTextures(3, m_texs);} GLTextureD::~GLTextureD() {glDeleteTextures(3, m_texs);}
@ -1665,16 +1676,16 @@ void GLTextureD::bind(size_t idx, int b)
} }
ITextureD* ITextureD*
GLDataFactory::Context::newDynamicTexture(size_t width, size_t height, TextureFormat fmt) GLDataFactory::Context::newDynamicTexture(size_t width, size_t height, TextureFormat fmt, TextureClampMode clampMode)
{ {
GLData* d = GLDataFactoryImpl::m_deferredData.get(); GLData* d = GLDataFactoryImpl::m_deferredData.get();
GLTextureD* retval = new GLTextureD(d, width, height, fmt); GLTextureD* retval = new GLTextureD(d, width, height, fmt, clampMode);
d->m_DTexs.emplace_back(retval); d->m_DTexs.emplace_back(retval);
return retval; return retval;
} }
GLTextureR::GLTextureR(IGraphicsData* parent, GLCommandQueue* q, size_t width, size_t height, size_t samples, GLTextureR::GLTextureR(IGraphicsData* parent, GLCommandQueue* q, size_t width, size_t height, size_t samples,
size_t colorBindingCount, size_t depthBindingCount) TextureClampMode clampMode, size_t colorBindingCount, size_t depthBindingCount)
: boo::ITextureR(parent), m_q(q), m_width(width), m_height(height), m_samples(samples) : boo::ITextureR(parent), m_q(q), m_width(width), m_height(height), m_samples(samples)
{ {
glGenTextures(2, m_texs); glGenTextures(2, m_texs);
@ -1690,6 +1701,7 @@ GLTextureR::GLTextureR(IGraphicsData* parent, GLCommandQueue* q, size_t width, s
Log.report(logvisor::Fatal, "too many depth bindings for render texture"); Log.report(logvisor::Fatal, "too many depth bindings for render texture");
glGenTextures(depthBindingCount, m_bindTexs[1]); glGenTextures(depthBindingCount, m_bindTexs[1]);
} }
if (samples > 1) if (samples > 1)
{ {
m_target = GL_TEXTURE_2D_MULTISAMPLE; m_target = GL_TEXTURE_2D_MULTISAMPLE;
@ -1697,18 +1709,6 @@ GLTextureR::GLTextureR(IGraphicsData* parent, GLCommandQueue* q, size_t width, s
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGBA, width, height, GL_FALSE); glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGBA, width, height, GL_FALSE);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_texs[1]); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_texs[1]);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_DEPTH_COMPONENT24, width, height, GL_FALSE); glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_DEPTH_COMPONENT24, width, height, GL_FALSE);
for (int i=0 ; i<colorBindingCount ; ++i)
{
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_bindTexs[0][i]);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGBA, width, height, GL_FALSE);
}
for (int i=0 ; i<depthBindingCount ; ++i)
{
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_bindTexs[1][i]);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_DEPTH_COMPONENT24, width, height, GL_FALSE);
}
} }
else else
{ {
@ -1717,6 +1717,7 @@ GLTextureR::GLTextureR(IGraphicsData* parent, GLCommandQueue* q, size_t width, s
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glBindTexture(GL_TEXTURE_2D, m_texs[1]); glBindTexture(GL_TEXTURE_2D, m_texs[1]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
}
for (int i=0 ; i<colorBindingCount ; ++i) for (int i=0 ; i<colorBindingCount ; ++i)
{ {
@ -1724,6 +1725,7 @@ GLTextureR::GLTextureR(IGraphicsData* parent, GLCommandQueue* q, size_t width, s
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
SetClampMode(GL_TEXTURE_2D, clampMode);
} }
for (int i=0 ; i<depthBindingCount ; ++i) for (int i=0 ; i<depthBindingCount ; ++i)
{ {
@ -1731,10 +1733,12 @@ GLTextureR::GLTextureR(IGraphicsData* parent, GLCommandQueue* q, size_t width, s
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
SetClampMode(GL_TEXTURE_2D, clampMode);
} }
}
m_q->addFBO(this); m_q->addFBO(this);
} }
GLTextureR::~GLTextureR() GLTextureR::~GLTextureR()
{ {
glDeleteTextures(2, m_texs); glDeleteTextures(2, m_texs);
@ -1743,13 +1747,13 @@ GLTextureR::~GLTextureR()
} }
ITextureR* ITextureR*
GLDataFactory::Context::newRenderTexture(size_t width, size_t height, GLDataFactory::Context::newRenderTexture(size_t width, size_t height, TextureClampMode clampMode,
size_t colorBindingCount, size_t depthBindingCount) size_t colorBindingCount, size_t depthBindingCount)
{ {
GLData* d = GLDataFactoryImpl::m_deferredData.get(); GLData* d = GLDataFactoryImpl::m_deferredData.get();
GLDataFactoryImpl& factory = static_cast<GLDataFactoryImpl&>(m_parent); GLDataFactoryImpl& factory = static_cast<GLDataFactoryImpl&>(m_parent);
GLCommandQueue* q = static_cast<GLCommandQueue*>(factory.m_parent->getCommandQueue()); GLCommandQueue* q = static_cast<GLCommandQueue*>(factory.m_parent->getCommandQueue());
GLTextureR* retval = new GLTextureR(d, q, width, height, factory.m_drawSamples, GLTextureR* retval = new GLTextureR(d, q, width, height, factory.m_drawSamples, clampMode,
colorBindingCount, depthBindingCount); colorBindingCount, depthBindingCount);
q->resizeRenderTexture(retval, width, height); q->resizeRenderTexture(retval, width, height);
GLDataFactoryImpl::m_deferredData->m_RTexs.emplace_back(retval); GLDataFactoryImpl::m_deferredData->m_RTexs.emplace_back(retval);

View File

@ -313,49 +313,30 @@ class MetalTextureR : public ITextureR
size_t m_colorBindCount; size_t m_colorBindCount;
size_t m_depthBindCount; size_t m_depthBindCount;
void Setup(MetalContext* ctx, size_t width, size_t height, size_t samples, void Setup(MetalContext* ctx)
size_t colorBindCount, size_t depthBindCount)
{ {
m_width = width; if (m_colorBindCount > MAX_BIND_TEXS)
m_height = height;
if (colorBindCount > MAX_BIND_TEXS)
Log.report(logvisor::Fatal, "too many color bindings for render texture"); Log.report(logvisor::Fatal, "too many color bindings for render texture");
if (depthBindCount > MAX_BIND_TEXS) if (m_depthBindCount > MAX_BIND_TEXS)
Log.report(logvisor::Fatal, "too many depth bindings for render texture"); Log.report(logvisor::Fatal, "too many depth bindings for render texture");
@autoreleasepool @autoreleasepool
{ {
MTLTextureDescriptor* desc = MTLTextureDescriptor* desc =
[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
width:width height:height width:m_width height:m_height
mipmapped:NO]; mipmapped:NO];
desc.storageMode = MTLStorageModePrivate; desc.storageMode = MTLStorageModePrivate;
if (samples > 1) if (m_samples > 1)
{ {
desc.textureType = MTLTextureType2DMultisample; desc.textureType = MTLTextureType2DMultisample;
desc.sampleCount = samples; desc.sampleCount = m_samples;
desc.usage = MTLTextureUsageRenderTarget; desc.usage = MTLTextureUsageRenderTarget;
m_colorTex = [ctx->m_dev newTextureWithDescriptor:desc]; m_colorTex = [ctx->m_dev newTextureWithDescriptor:desc];
if (colorBindCount)
{
desc.usage = MTLTextureUsageShaderRead;
for (int i=0 ; i<colorBindCount ; ++i)
m_colorBindTex[i] = [ctx->m_dev newTextureWithDescriptor:desc];
}
desc.usage = MTLTextureUsageRenderTarget;
desc.pixelFormat = MTLPixelFormatDepth32Float; desc.pixelFormat = MTLPixelFormatDepth32Float;
m_depthTex = [ctx->m_dev newTextureWithDescriptor:desc]; m_depthTex = [ctx->m_dev newTextureWithDescriptor:desc];
if (depthBindCount)
{
desc.usage = MTLTextureUsageShaderRead;
for (int i=0 ; i<depthBindCount ; ++i)
m_depthBindTex[i] = [ctx->m_dev newTextureWithDescriptor:desc];
}
} }
else else
{ {
@ -364,24 +345,26 @@ class MetalTextureR : public ITextureR
desc.usage = MTLTextureUsageRenderTarget; desc.usage = MTLTextureUsageRenderTarget;
m_colorTex = [ctx->m_dev newTextureWithDescriptor:desc]; m_colorTex = [ctx->m_dev newTextureWithDescriptor:desc];
if (colorBindCount) desc.pixelFormat = MTLPixelFormatDepth32Float;
{ m_depthTex = [ctx->m_dev newTextureWithDescriptor:desc];
}
desc.textureType = MTLTextureType2D;
desc.sampleCount = 1;
desc.usage = MTLTextureUsageShaderRead; desc.usage = MTLTextureUsageShaderRead;
for (int i=0 ; i<colorBindCount ; ++i) if (m_colorBindCount)
{
desc.pixelFormat = MTLPixelFormatBGRA8Unorm;
for (int i=0 ; i<m_colorBindCount ; ++i)
m_colorBindTex[i] = [ctx->m_dev newTextureWithDescriptor:desc]; m_colorBindTex[i] = [ctx->m_dev newTextureWithDescriptor:desc];
} }
desc.usage = MTLTextureUsageRenderTarget; if (m_depthBindCount)
desc.pixelFormat = MTLPixelFormatDepth32Float;
m_depthTex = [ctx->m_dev newTextureWithDescriptor:desc];
if (depthBindCount)
{ {
desc.usage = MTLTextureUsageShaderRead; desc.pixelFormat = MTLPixelFormatDepth32Float;
for (int i=0 ; i<depthBindCount ; ++i) for (int i=0 ; i<m_depthBindCount ; ++i)
m_depthBindTex[i] = [ctx->m_dev newTextureWithDescriptor:desc]; m_depthBindTex[i] = [ctx->m_dev newTextureWithDescriptor:desc];
} }
}
{ {
m_passDesc = [MTLRenderPassDescriptor renderPassDescriptor]; m_passDesc = [MTLRenderPassDescriptor renderPassDescriptor];
@ -446,7 +429,7 @@ class MetalTextureR : public ITextureR
m_depthBindCount(depthBindCount) m_depthBindCount(depthBindCount)
{ {
if (samples == 0) m_samples = 1; if (samples == 0) m_samples = 1;
Setup(ctx, width, height, samples, colorBindCount, depthBindCount); Setup(ctx);
} }
public: public:
size_t samples() const {return m_samples;} size_t samples() const {return m_samples;}
@ -468,7 +451,7 @@ public:
height = 1; height = 1;
m_width = width; m_width = width;
m_height = height; m_height = height;
Setup(ctx, width, height, m_samples, m_colorBindCount, m_depthBindCount); Setup(ctx);
} }
}; };
@ -1255,7 +1238,7 @@ IGraphicsBufferD* MetalDataFactory::Context::newDynamicBuffer(BufferUse use, siz
} }
ITextureS* MetalDataFactory::Context::newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt, ITextureS* MetalDataFactory::Context::newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz) TextureClampMode clampMode, const void* data, size_t sz)
{ {
MetalData* d = MetalDataFactoryImpl::m_deferredData.get(); MetalData* d = MetalDataFactoryImpl::m_deferredData.get();
MetalDataFactoryImpl& factory = static_cast<MetalDataFactoryImpl&>(m_parent); MetalDataFactoryImpl& factory = static_cast<MetalDataFactoryImpl&>(m_parent);
@ -1264,7 +1247,8 @@ ITextureS* MetalDataFactory::Context::newStaticTexture(size_t width, size_t heig
return retval; return retval;
} }
ITextureSA* MetalDataFactory::Context::newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips, ITextureSA* MetalDataFactory::Context::newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips,
TextureFormat fmt, const void* data, size_t sz) TextureFormat fmt, TextureClampMode clampMode,
const void* data, size_t sz)
{ {
MetalData* d = MetalDataFactoryImpl::m_deferredData.get(); MetalData* d = MetalDataFactoryImpl::m_deferredData.get();
MetalDataFactoryImpl& factory = static_cast<MetalDataFactoryImpl&>(m_parent); MetalDataFactoryImpl& factory = static_cast<MetalDataFactoryImpl&>(m_parent);
@ -1272,7 +1256,8 @@ ITextureSA* MetalDataFactory::Context::newStaticArrayTexture(size_t width, size_
d->m_SATexs.emplace_back(retval); d->m_SATexs.emplace_back(retval);
return retval; return retval;
} }
ITextureD* MetalDataFactory::Context::newDynamicTexture(size_t width, size_t height, TextureFormat fmt) ITextureD* MetalDataFactory::Context::newDynamicTexture(size_t width, size_t height, TextureFormat fmt,
TextureClampMode clampMode)
{ {
MetalData* d = MetalDataFactoryImpl::m_deferredData.get(); MetalData* d = MetalDataFactoryImpl::m_deferredData.get();
MetalDataFactoryImpl& factory = static_cast<MetalDataFactoryImpl&>(m_parent); MetalDataFactoryImpl& factory = static_cast<MetalDataFactoryImpl&>(m_parent);
@ -1281,7 +1266,7 @@ ITextureD* MetalDataFactory::Context::newDynamicTexture(size_t width, size_t hei
d->m_DTexs.emplace_back(retval); d->m_DTexs.emplace_back(retval);
return retval; return retval;
} }
ITextureR* MetalDataFactory::Context::newRenderTexture(size_t width, size_t height, ITextureR* MetalDataFactory::Context::newRenderTexture(size_t width, size_t height, TextureClampMode clampMode,
size_t colorBindCount, size_t depthBindCount) size_t colorBindCount, size_t depthBindCount)
{ {
MetalData* d = MetalDataFactoryImpl::m_deferredData.get(); MetalData* d = MetalDataFactoryImpl::m_deferredData.get();

View File

@ -595,7 +595,14 @@ void VulkanContext::initSwapChain(VulkanContext::Window& windowCtx, VkSurfaceKHR
samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerInfo.maxAnisotropy = 1.f; samplerInfo.maxAnisotropy = 1.f;
ThrowIfFailed(vk::CreateSampler(m_dev, &samplerInfo, nullptr, &m_linearSampler)); ThrowIfFailed(vk::CreateSampler(m_dev, &samplerInfo, nullptr, &m_linearSamplers[0]));
/* Create shared white-clamped sampler */
samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
samplerInfo.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
ThrowIfFailed(vk::CreateSampler(m_dev, &samplerInfo, nullptr, &m_linearSamplers[1]));
/* images */ /* images */
sc.m_bufs.resize(swapchainImageCount); sc.m_bufs.resize(swapchainImageCount);
@ -960,7 +967,8 @@ class VulkanTextureS : public ITextureS
VulkanTextureS(IGraphicsData* parent, VulkanContext* ctx, VulkanTextureS(IGraphicsData* parent, VulkanContext* ctx,
size_t width, size_t height, size_t mips, size_t width, size_t height, size_t mips,
TextureFormat fmt, const void* data, size_t sz) TextureFormat fmt, TextureClampMode clampMode,
const void* data, size_t sz)
: ITextureS(parent), m_ctx(ctx), m_fmt(fmt), m_sz(sz), m_width(width), m_height(height), m_mips(mips) : ITextureS(parent), m_ctx(ctx), m_fmt(fmt), m_sz(sz), m_width(width), m_height(height), m_mips(mips)
{ {
VkFormat pfmt; VkFormat pfmt;
@ -1031,7 +1039,7 @@ class VulkanTextureS : public ITextureS
texCreateInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; texCreateInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_gpuTex)); ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_gpuTex));
m_descInfo.sampler = ctx->m_linearSampler; m_descInfo.sampler = ctx->m_linearSamplers[int(clampMode)];
m_descInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; m_descInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
} }
public: public:
@ -1159,7 +1167,8 @@ class VulkanTextureSA : public ITextureSA
VulkanTextureSA(IGraphicsData* parent, VulkanContext* ctx, VulkanTextureSA(IGraphicsData* parent, VulkanContext* ctx,
size_t width, size_t height, size_t layers, size_t width, size_t height, size_t layers,
size_t mips, TextureFormat fmt, const void* data, size_t sz) size_t mips, TextureFormat fmt, TextureClampMode clampMode,
const void* data, size_t sz)
: ITextureSA(parent), m_ctx(ctx), m_fmt(fmt), m_width(width), : ITextureSA(parent), m_ctx(ctx), m_fmt(fmt), m_width(width),
m_height(height), m_layers(layers), m_mips(mips), m_sz(sz) m_height(height), m_layers(layers), m_mips(mips), m_sz(sz)
{ {
@ -1226,7 +1235,7 @@ class VulkanTextureSA : public ITextureSA
texCreateInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; texCreateInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_gpuTex)); ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_gpuTex));
m_descInfo.sampler = ctx->m_linearSampler; m_descInfo.sampler = ctx->m_linearSamplers[int(clampMode)];
m_descInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; m_descInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
} }
public: public:
@ -1357,7 +1366,7 @@ class VulkanTextureD : public ITextureD
VkFormat m_vkFmt; VkFormat m_vkFmt;
int m_validSlots = 0; int m_validSlots = 0;
VulkanTextureD(IGraphicsData* parent, VulkanCommandQueue* q, VulkanContext* ctx, VulkanTextureD(IGraphicsData* parent, VulkanCommandQueue* q, VulkanContext* ctx,
size_t width, size_t height, TextureFormat fmt) size_t width, size_t height, TextureFormat fmt, TextureClampMode clampMode)
: ITextureD(parent), m_width(width), m_height(height), m_fmt(fmt), m_q(q) : ITextureD(parent), m_width(width), m_height(height), m_fmt(fmt), m_q(q)
{ {
VkFormat pfmt; VkFormat pfmt;
@ -1441,7 +1450,7 @@ class VulkanTextureD : public ITextureD
/* create gpu image */ /* create gpu image */
ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_gpuTex[i])); ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_gpuTex[i]));
m_descInfo[i].sampler = ctx->m_linearSampler; m_descInfo[i].sampler = ctx->m_linearSamplers[int(clampMode)];
m_descInfo[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; m_descInfo[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
} }
} }
@ -1519,11 +1528,11 @@ class VulkanTextureR : public ITextureR
size_t m_height = 0; size_t m_height = 0;
size_t m_samples = 0; size_t m_samples = 0;
TextureClampMode m_clampMode;
size_t m_colorBindCount; size_t m_colorBindCount;
size_t m_depthBindCount; size_t m_depthBindCount;
void Setup(VulkanContext* ctx, size_t width, size_t height, size_t samples, void Setup(VulkanContext* ctx)
size_t colorBindCount, size_t depthBindCount)
{ {
/* no-ops on first call */ /* no-ops on first call */
doDestroy(); doDestroy();
@ -1535,12 +1544,12 @@ class VulkanTextureR : public ITextureR
texCreateInfo.pNext = nullptr; texCreateInfo.pNext = nullptr;
texCreateInfo.imageType = VK_IMAGE_TYPE_2D; texCreateInfo.imageType = VK_IMAGE_TYPE_2D;
texCreateInfo.format = ctx->m_displayFormat; texCreateInfo.format = ctx->m_displayFormat;
texCreateInfo.extent.width = width; texCreateInfo.extent.width = m_width;
texCreateInfo.extent.height = height; texCreateInfo.extent.height = m_height;
texCreateInfo.extent.depth = 1; texCreateInfo.extent.depth = 1;
texCreateInfo.mipLevels = 1; texCreateInfo.mipLevels = 1;
texCreateInfo.arrayLayers = 1; texCreateInfo.arrayLayers = 1;
texCreateInfo.samples = VkSampleCountFlagBits(samples); texCreateInfo.samples = VkSampleCountFlagBits(m_samples);
texCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL; texCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
texCreateInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; texCreateInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
texCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; texCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
@ -1580,7 +1589,9 @@ class VulkanTextureR : public ITextureR
memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1); memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
memTypeBits &= memReqs.memoryTypeBits; memTypeBits &= memReqs.memoryTypeBits;
for (size_t i=0 ; i<colorBindCount ; ++i) texCreateInfo.samples = VkSampleCountFlagBits(1);
for (size_t i=0 ; i<m_colorBindCount ; ++i)
{ {
m_colorBindLayout[i] = VK_IMAGE_LAYOUT_UNDEFINED; m_colorBindLayout[i] = VK_IMAGE_LAYOUT_UNDEFINED;
texCreateInfo.format = ctx->m_displayFormat; texCreateInfo.format = ctx->m_displayFormat;
@ -1593,11 +1604,11 @@ class VulkanTextureR : public ITextureR
memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1); memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
memTypeBits &= memReqs.memoryTypeBits; memTypeBits &= memReqs.memoryTypeBits;
m_colorBindDescInfo[i].sampler = ctx->m_linearSampler; m_colorBindDescInfo[i].sampler = ctx->m_linearSamplers[int(m_clampMode)];
m_colorBindDescInfo[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; m_colorBindDescInfo[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
} }
for (size_t i=0 ; i<depthBindCount ; ++i) for (size_t i=0 ; i<m_depthBindCount ; ++i)
{ {
m_depthBindLayout[i] = VK_IMAGE_LAYOUT_UNDEFINED; m_depthBindLayout[i] = VK_IMAGE_LAYOUT_UNDEFINED;
texCreateInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; texCreateInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
@ -1610,7 +1621,7 @@ class VulkanTextureR : public ITextureR
memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1); memAlloc.allocationSize = (memAlloc.allocationSize + memReqs.alignment - 1) & ~(memReqs.alignment - 1);
memTypeBits &= memReqs.memoryTypeBits; memTypeBits &= memReqs.memoryTypeBits;
m_depthBindDescInfo[i].sampler = ctx->m_linearSampler; m_depthBindDescInfo[i].sampler = ctx->m_linearSamplers[int(m_clampMode)];
m_depthBindDescInfo[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; m_depthBindDescInfo[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
} }
@ -1651,7 +1662,7 @@ class VulkanTextureR : public ITextureR
viewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; viewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
ThrowIfFailed(vk::CreateImageView(ctx->m_dev, &viewCreateInfo, nullptr, &m_depthView)); ThrowIfFailed(vk::CreateImageView(ctx->m_dev, &viewCreateInfo, nullptr, &m_depthView));
for (size_t i=0 ; i<colorBindCount ; ++i) for (size_t i=0 ; i<m_colorBindCount ; ++i)
{ {
ThrowIfFailed(vk::BindImageMemory(ctx->m_dev, m_colorBindTex[i], m_gpuMem, colorOffsets[i])); ThrowIfFailed(vk::BindImageMemory(ctx->m_dev, m_colorBindTex[i], m_gpuMem, colorOffsets[i]));
viewCreateInfo.image = m_colorBindTex[i]; viewCreateInfo.image = m_colorBindTex[i];
@ -1661,7 +1672,7 @@ class VulkanTextureR : public ITextureR
m_colorBindDescInfo[i].imageView = m_colorBindView[i]; m_colorBindDescInfo[i].imageView = m_colorBindView[i];
} }
for (size_t i=0 ; i<depthBindCount ; ++i) for (size_t i=0 ; i<m_depthBindCount ; ++i)
{ {
ThrowIfFailed(vk::BindImageMemory(ctx->m_dev, m_depthBindTex[i], m_gpuMem, depthOffsets[i])); ThrowIfFailed(vk::BindImageMemory(ctx->m_dev, m_depthBindTex[i], m_gpuMem, depthOffsets[i]));
viewCreateInfo.image = m_depthBindTex[i]; viewCreateInfo.image = m_depthBindTex[i];
@ -1677,8 +1688,8 @@ class VulkanTextureR : public ITextureR
fbCreateInfo.pNext = nullptr; fbCreateInfo.pNext = nullptr;
fbCreateInfo.renderPass = ctx->m_pass; fbCreateInfo.renderPass = ctx->m_pass;
fbCreateInfo.attachmentCount = 2; fbCreateInfo.attachmentCount = 2;
fbCreateInfo.width = width; fbCreateInfo.width = m_width;
fbCreateInfo.height = height; fbCreateInfo.height = m_height;
fbCreateInfo.layers = 1; fbCreateInfo.layers = 1;
VkImageView attachments[2] = {m_colorView, m_depthView}; VkImageView attachments[2] = {m_colorView, m_depthView};
fbCreateInfo.pAttachments = attachments; fbCreateInfo.pAttachments = attachments;
@ -1690,17 +1701,18 @@ class VulkanTextureR : public ITextureR
m_passBeginInfo.framebuffer = m_framebuffer; m_passBeginInfo.framebuffer = m_framebuffer;
m_passBeginInfo.renderArea.offset.x = 0; m_passBeginInfo.renderArea.offset.x = 0;
m_passBeginInfo.renderArea.offset.y = 0; m_passBeginInfo.renderArea.offset.y = 0;
m_passBeginInfo.renderArea.extent.width = width; m_passBeginInfo.renderArea.extent.width = m_width;
m_passBeginInfo.renderArea.extent.height = height; m_passBeginInfo.renderArea.extent.height = m_height;
m_passBeginInfo.clearValueCount = 0; m_passBeginInfo.clearValueCount = 0;
m_passBeginInfo.pClearValues = nullptr; m_passBeginInfo.pClearValues = nullptr;
} }
VulkanCommandQueue* m_q; VulkanCommandQueue* m_q;
VulkanTextureR(IGraphicsData* parent, VulkanContext* ctx, VulkanCommandQueue* q, VulkanTextureR(IGraphicsData* parent, VulkanContext* ctx, VulkanCommandQueue* q,
size_t width, size_t height, size_t samples, size_t width, size_t height, size_t samples, TextureClampMode clampMode,
size_t colorBindCount, size_t depthBindCount) size_t colorBindCount, size_t depthBindCount)
: ITextureR(parent), m_q(q), m_width(width), m_height(height), m_samples(samples), : ITextureR(parent), m_q(q), m_width(width), m_height(height), m_samples(samples),
m_clampMode(clampMode),
m_colorBindCount(colorBindCount), m_colorBindCount(colorBindCount),
m_depthBindCount(depthBindCount) m_depthBindCount(depthBindCount)
{ {
@ -1710,7 +1722,7 @@ class VulkanTextureR : public ITextureR
Log.report(logvisor::Fatal, "too many depth bindings for render texture"); Log.report(logvisor::Fatal, "too many depth bindings for render texture");
if (samples == 0) m_samples = 1; if (samples == 0) m_samples = 1;
Setup(ctx, width, height, samples, colorBindCount, depthBindCount); Setup(ctx);
} }
public: public:
size_t samples() const {return m_samples;} size_t samples() const {return m_samples;}
@ -1748,7 +1760,7 @@ public:
height = 1; height = 1;
m_width = width; m_width = width;
m_height = height; m_height = height;
Setup(ctx, width, height, m_samples, m_colorBindCount, m_depthBindCount); Setup(ctx);
} }
}; };
@ -3050,7 +3062,7 @@ VulkanDataFactoryImpl::VulkanDataFactoryImpl(IGraphicsContext* parent,
layoutBindings[i].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; layoutBindings[i].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
layoutBindings[i].descriptorCount = 1; layoutBindings[i].descriptorCount = 1;
layoutBindings[i].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; layoutBindings[i].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
layoutBindings[i].pImmutableSamplers = &ctx->m_linearSampler; layoutBindings[i].pImmutableSamplers = nullptr;
} }
VkDescriptorSetLayoutCreateInfo descriptorLayout = {}; VkDescriptorSetLayoutCreateInfo descriptorLayout = {};
@ -3342,43 +3354,48 @@ IGraphicsBufferD* VulkanDataFactory::Context::newDynamicBuffer(BufferUse use, si
} }
ITextureS* VulkanDataFactory::Context::newStaticTexture(size_t width, size_t height, size_t mips, ITextureS* VulkanDataFactory::Context::newStaticTexture(size_t width, size_t height, size_t mips,
TextureFormat fmt, const void* data, size_t sz) TextureFormat fmt, TextureClampMode clampMode,
const void* data, size_t sz)
{ {
VulkanData* d = static_cast<VulkanData*>(VulkanDataFactoryImpl::m_deferredData.get()); VulkanData* d = static_cast<VulkanData*>(VulkanDataFactoryImpl::m_deferredData.get());
VulkanDataFactoryImpl& factory = static_cast<VulkanDataFactoryImpl&>(m_parent); VulkanDataFactoryImpl& factory = static_cast<VulkanDataFactoryImpl&>(m_parent);
VulkanTextureS* retval = new VulkanTextureS(d, factory.m_ctx, width, height, mips, fmt, data, sz); VulkanTextureS* retval = new VulkanTextureS(d, factory.m_ctx, width, height, mips, fmt,
clampMode, data, sz);
d->m_STexs.emplace_back(retval); d->m_STexs.emplace_back(retval);
return retval; return retval;
} }
ITextureSA* VulkanDataFactory::Context::newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips, ITextureSA* VulkanDataFactory::Context::newStaticArrayTexture(size_t width, size_t height, size_t layers, size_t mips,
TextureFormat fmt, const void* data, size_t sz) TextureFormat fmt, TextureClampMode clampMode,
const void* data, size_t sz)
{ {
VulkanData* d = static_cast<VulkanData*>(VulkanDataFactoryImpl::m_deferredData.get()); VulkanData* d = static_cast<VulkanData*>(VulkanDataFactoryImpl::m_deferredData.get());
VulkanDataFactoryImpl& factory = static_cast<VulkanDataFactoryImpl&>(m_parent); VulkanDataFactoryImpl& factory = static_cast<VulkanDataFactoryImpl&>(m_parent);
VulkanTextureSA* retval = new VulkanTextureSA(d, factory.m_ctx, width, height, layers, mips, fmt, data, sz); VulkanTextureSA* retval = new VulkanTextureSA(d, factory.m_ctx, width, height, layers, mips, fmt,
clampMode, data, sz);
d->m_SATexs.emplace_back(retval); d->m_SATexs.emplace_back(retval);
return retval; return retval;
} }
ITextureD* VulkanDataFactory::Context::newDynamicTexture(size_t width, size_t height, TextureFormat fmt) ITextureD* VulkanDataFactory::Context::newDynamicTexture(size_t width, size_t height, TextureFormat fmt,
TextureClampMode clampMode)
{ {
VulkanData* d = static_cast<VulkanData*>(VulkanDataFactoryImpl::m_deferredData.get()); VulkanData* d = static_cast<VulkanData*>(VulkanDataFactoryImpl::m_deferredData.get());
VulkanDataFactoryImpl& factory = static_cast<VulkanDataFactoryImpl&>(m_parent); VulkanDataFactoryImpl& factory = static_cast<VulkanDataFactoryImpl&>(m_parent);
VulkanCommandQueue* q = static_cast<VulkanCommandQueue*>(factory.m_parent->getCommandQueue()); VulkanCommandQueue* q = static_cast<VulkanCommandQueue*>(factory.m_parent->getCommandQueue());
VulkanTextureD* retval = new VulkanTextureD(d, q, factory.m_ctx, width, height, fmt); VulkanTextureD* retval = new VulkanTextureD(d, q, factory.m_ctx, width, height, fmt, clampMode);
d->m_DTexs.emplace_back(retval); d->m_DTexs.emplace_back(retval);
return retval; return retval;
} }
ITextureR* VulkanDataFactory::Context::newRenderTexture(size_t width, size_t height, ITextureR* VulkanDataFactory::Context::newRenderTexture(size_t width, size_t height, TextureClampMode clampMode,
size_t colorBindCount, size_t depthBindCount) size_t colorBindCount, size_t depthBindCount)
{ {
VulkanData* d = static_cast<VulkanData*>(VulkanDataFactoryImpl::m_deferredData.get()); VulkanData* d = static_cast<VulkanData*>(VulkanDataFactoryImpl::m_deferredData.get());
VulkanDataFactoryImpl& factory = static_cast<VulkanDataFactoryImpl&>(m_parent); VulkanDataFactoryImpl& factory = static_cast<VulkanDataFactoryImpl&>(m_parent);
VulkanCommandQueue* q = static_cast<VulkanCommandQueue*>(factory.m_parent->getCommandQueue()); VulkanCommandQueue* q = static_cast<VulkanCommandQueue*>(factory.m_parent->getCommandQueue());
VulkanTextureR* retval = new VulkanTextureR(d, factory.m_ctx, q, width, height, factory.m_drawSamples, VulkanTextureR* retval = new VulkanTextureR(d, factory.m_ctx, q, width, height, factory.m_drawSamples,
colorBindCount, depthBindCount); clampMode, colorBindCount, depthBindCount);
d->m_RTexs.emplace_back(retval); d->m_RTexs.emplace_back(retval);
return retval; return retval;
} }

View File

@ -265,7 +265,12 @@ public:
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
m_3dCtx.m_ctx11.m_dev->CreateSamplerState(&sampDesc, &m_3dCtx.m_ctx11.m_ss); m_3dCtx.m_ctx11.m_dev->CreateSamplerState(&sampDesc, &m_3dCtx.m_ctx11.m_ss[0]);
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_BORDER;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_BORDER;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
m_3dCtx.m_ctx11.m_dev->CreateSamplerState(&sampDesc, &m_3dCtx.m_ctx11.m_ss[1]);
Log.report(logvisor::Info, "initialized D3D11 renderer"); Log.report(logvisor::Info, "initialized D3D11 renderer");
return; return;

View File

@ -67,7 +67,7 @@ struct D3D11Context
ComPtr<IDXGIFactory2> m_dxFactory; ComPtr<IDXGIFactory2> m_dxFactory;
ComPtr<ID3D11Device1> m_dev; ComPtr<ID3D11Device1> m_dev;
ComPtr<ID3D11DeviceContext1> m_devCtx; ComPtr<ID3D11DeviceContext1> m_devCtx;
ComPtr<ID3D11SamplerState> m_ss; ComPtr<ID3D11SamplerState> m_ss[2];
struct Window struct Window
{ {
ComPtr<IDXGISwapChain1> m_swapChain; ComPtr<IDXGISwapChain1> m_swapChain;

View File

@ -267,7 +267,7 @@ struct TestApplicationCallback : IApplicationCallback
/* Create render target */ /* Create render target */
int x, y, w, h; int x, y, w, h;
self->mainWindow->getWindowFrame(x, y, w, h); self->mainWindow->getWindowFrame(x, y, w, h);
self->m_renderTarget = ctx.newRenderTexture(w, h, false, false); self->m_renderTarget = ctx.newRenderTexture(w, h, boo::TextureClampMode::Repeat, 0, 0);
/* Make Tri-strip VBO */ /* Make Tri-strip VBO */
struct Vert struct Vert
@ -305,7 +305,7 @@ struct TestApplicationCallback : IApplicationCallback
tex[i][j][3] = 0xff; tex[i][j][3] = 0xff;
} }
ITexture* texture = ITexture* texture =
ctx.newStaticTexture(256, 256, 1, TextureFormat::RGBA8, tex, 256*256*4); ctx.newStaticTexture(256, 256, 1, TextureFormat::RGBA8, boo::TextureClampMode::Repeat, tex, 256*256*4);
/* Make shader pipeline */ /* Make shader pipeline */
IShaderPipeline* pipeline = nullptr; IShaderPipeline* pipeline = nullptr;