Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

d3d10: Trace blobs for initial data.

  • Loading branch information...
commit 30fb4c3b5efba7481993b87e667fbee2f411870c 1 parent 00e67f1
@jrfonseca jrfonseca authored
View
1  .lvimrc
@@ -0,0 +1 @@
+set sw=4 ts=4 et
View
49 helpers/d3d10size.hpp
@@ -43,21 +43,11 @@
static size_t
-_calcDataSize(DXGI_FORMAT Format, UINT Width, UINT Height, INT RowPitch, UINT Depth = 1, INT DepthPitch = 0) {
+_calcDataSize(DXGI_FORMAT Format, UINT Width, UINT Height, UINT RowPitch, UINT Depth = 1, UINT DepthPitch = 0) {
if (Width == 0 || Height == 0 || Depth == 0) {
return 0;
}
- if (RowPitch < 0) {
- os::log("apitrace: warning: %s: negative row pitch %i\n", __FUNCTION__, RowPitch);
- return 0;
- }
-
- if (DepthPitch < 0) {
- os::log("apitrace: warning: %s: negative slice pitch %i\n", __FUNCTION__, DepthPitch);
- return 0;
- }
-
switch (Format) {
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC1_UNORM:
@@ -103,7 +93,7 @@ _calcDataSize(DXGI_FORMAT Format, UINT Width, UINT Height, INT RowPitch, UINT De
}
static size_t
-_calcMipDataSize(UINT MipLevel, DXGI_FORMAT Format, UINT Width, UINT Height, INT RowPitch, UINT Depth = 1, INT DepthPitch = 0) {
+_calcMipDataSize(UINT MipLevel, DXGI_FORMAT Format, UINT Width, UINT Height, UINT RowPitch, UINT Depth = 1, UINT DepthPitch = 0) {
if (Width == 0 || Height == 0 || Depth == 0) {
return 0;
}
@@ -168,6 +158,29 @@ _getNumSubResources(const D3D10_TEXTURE3D_DESC *pDesc) {
return _getNumMipLevels(pDesc);
}
+static inline size_t
+_calcSubresourceSize(const D3D10_BUFFER_DESC *pDesc, UINT Subresource, UINT RowPitch = 0, UINT SlicePitch = 0) {
+ return pDesc->ByteWidth;
+}
+
+static inline size_t
+_calcSubresourceSize(const D3D10_TEXTURE1D_DESC *pDesc, UINT Subresource, UINT RowPitch = 0, UINT SlicePitch = 0) {
+ UINT MipLevel = Subresource % _getNumMipLevels(pDesc);
+ return _calcMipDataSize(MipLevel, pDesc->Format, pDesc->Width, 1, RowPitch, 1, SlicePitch);
+}
+
+static inline size_t
+_calcSubresourceSize(const D3D10_TEXTURE2D_DESC *pDesc, UINT Subresource, UINT RowPitch, UINT SlicePitch = 0) {
+ UINT MipLevel = Subresource % _getNumMipLevels(pDesc);
+ return _calcMipDataSize(MipLevel, pDesc->Format, pDesc->Width, pDesc->Height, RowPitch, 1, SlicePitch);
+}
+
+static inline size_t
+_calcSubresourceSize(const D3D10_TEXTURE3D_DESC *pDesc, UINT Subresource, UINT RowPitch, UINT SlicePitch) {
+ UINT MipLevel = Subresource;
+ return _calcMipDataSize(MipLevel, pDesc->Format, pDesc->Width, pDesc->Height, RowPitch, pDesc->Depth, SlicePitch);
+}
+
static inline void
_getMapInfo(ID3D10Buffer *pResource, D3D10_MAP MapType, UINT MapFlags, void * * ppData,
void * & pMappedData, size_t & MappedSize) {
@@ -198,10 +211,8 @@ _getMapInfo(ID3D10Texture1D *pResource, UINT Subresource, D3D10_MAP MapType, UIN
D3D10_TEXTURE1D_DESC Desc;
pResource->GetDesc(&Desc);
- UINT MipLevel = Subresource % _getNumMipLevels(&Desc);
-
pMappedData = *ppData;
- MappedSize = _calcMipDataSize(MipLevel, Desc.Format, Desc.Width, 1, 0);
+ MappedSize = _calcSubresourceSize(&Desc, Subresource);
}
static inline void
@@ -217,10 +228,8 @@ _getMapInfo(ID3D10Texture2D *pResource, UINT Subresource, D3D10_MAP MapType, UIN
D3D10_TEXTURE2D_DESC Desc;
pResource->GetDesc(&Desc);
- UINT MipLevel = Subresource % _getNumMipLevels(&Desc);
-
pMappedData = pMappedTex2D->pData;
- MappedSize = _calcMipDataSize(MipLevel, Desc.Format, Desc.Width, Desc.Height, pMappedTex2D->RowPitch);
+ MappedSize = _calcSubresourceSize(&Desc, Subresource, pMappedTex2D->RowPitch);
}
static inline void
@@ -236,10 +245,8 @@ _getMapInfo(ID3D10Texture3D *pResource, UINT Subresource, D3D10_MAP MapType, UIN
D3D10_TEXTURE3D_DESC Desc;
pResource->GetDesc(&Desc);
- UINT MipLevel = Subresource;
-
pMappedData = pMappedTex3D->pData;
- MappedSize = _calcMipDataSize(MipLevel, Desc.Format, Desc.Width, Desc.Height, pMappedTex3D->RowPitch, Desc.Depth, pMappedTex3D->DepthPitch);
+ MappedSize = _calcSubresourceSize(&Desc, Subresource, pMappedTex3D->RowPitch, pMappedTex3D->DepthPitch);
}
View
4 specs/d3d10.py
@@ -544,7 +544,7 @@
])
D3D10_SUBRESOURCE_DATA = Struct("D3D10_SUBRESOURCE_DATA", [
- (OpaquePointer(Const(Void)), "pSysMem"),
+ (Blob(Const(Void), "_calcSubresourceSize(pDesc, {i}, {self}.SysMemPitch, {self}.SysMemSlicePitch)"), "pSysMem"),
(UINT, "SysMemPitch"),
(UINT, "SysMemSlicePitch"),
])
@@ -861,7 +861,7 @@
Method(HRESULT, "SetPrivateDataInterface", [(REFGUID, "guid"), (OpaquePointer(Const(IUnknown)), "pData")], sideeffects=False),
Method(Void, "ClearState", []),
Method(Void, "Flush", []),
- Method(HRESULT, "CreateBuffer", [(Pointer(Const(D3D10_BUFFER_DESC)), "pDesc"), (Pointer(Const(D3D10_SUBRESOURCE_DATA)), "pInitialData"), Out(Pointer(ObjPointer(ID3D10Buffer)), "ppBuffer")]),
+ Method(HRESULT, "CreateBuffer", [(Pointer(Const(D3D10_BUFFER_DESC)), "pDesc"), (Array(Const(D3D10_SUBRESOURCE_DATA), "1"), "pInitialData"), Out(Pointer(ObjPointer(ID3D10Buffer)), "ppBuffer")]),
Method(HRESULT, "CreateTexture1D", [(Pointer(Const(D3D10_TEXTURE1D_DESC)), "pDesc"), (Array(Const(D3D10_SUBRESOURCE_DATA), "_getNumSubResources(pDesc)"), "pInitialData"), Out(Pointer(ObjPointer(ID3D10Texture1D)), "ppTexture1D")]),
Method(HRESULT, "CreateTexture2D", [(Pointer(Const(D3D10_TEXTURE2D_DESC)), "pDesc"), (Array(Const(D3D10_SUBRESOURCE_DATA), "_getNumSubResources(pDesc)"), "pInitialData"), Out(Pointer(ObjPointer(ID3D10Texture2D)), "ppTexture2D")]),
Method(HRESULT, "CreateTexture3D", [(Pointer(Const(D3D10_TEXTURE3D_DESC)), "pDesc"), (Array(Const(D3D10_SUBRESOURCE_DATA), "_getNumSubResources(pDesc)"), "pInitialData"), Out(Pointer(ObjPointer(ID3D10Texture3D)), "ppTexture3D")]),
View
58 wrappers/trace.py
@@ -63,21 +63,13 @@ def visitConst(self, const):
self.visit(const.type)
def visitStruct(self, struct):
- for type, name in struct.members:
- self.visit(type)
- print 'static void _write__%s(const %s &value) {' % (struct.tag, struct.expr)
- print ' static const char * members[%u] = {' % (len(struct.members),)
+ print 'static const char * _struct%s_members[%u] = {' % (struct.tag, len(struct.members))
for type, name, in struct.members:
- print ' "%s",' % (name,)
- print ' };'
- print ' static const trace::StructSig sig = {'
- print ' %u, "%s", %u, members' % (struct.id, struct.name, len(struct.members))
- print ' };'
- print ' trace::localWriter.beginStruct(&sig);'
- for type, name in struct.members:
- self.serializer.visit(type, 'value.%s' % (name,))
- print ' trace::localWriter.endStruct();'
- print '}'
+ print ' "%s",' % (name,)
+ print '};'
+ print 'static const trace::StructSig _struct%s_sig = {' % (struct.tag,)
+ print ' %u, "%s", %u, _struct%s_members' % (struct.id, struct.name, len(struct.members), struct.tag)
+ print '};'
print
def visitArray(self, array):
@@ -158,6 +150,27 @@ class ValueSerializer(stdapi.Visitor):
ComplexValueSerializer visitor above.
'''
+ def __init__(self):
+ #stdapi.Visitor.__init__(self)
+ self.indices = []
+ self.instances = []
+
+ def expand(self, expr):
+ # Expand a C expression, replacing certain variables
+ variables = {}
+ try:
+ variables['self'] = self.instances[-1]
+ except IndexError:
+ pass
+ try:
+ variables['i'] = self.indices[-1]
+ except IndexError:
+ pass
+ expandedExpr = expr.format(**variables)
+ if expandedExpr != expr:
+ sys.stderr.write(" %r -> %r\n" % (expr, expandedExpr))
+ return expandedExpr
+
def visitLiteral(self, literal, instance):
print ' trace::localWriter.write%s(%s);' % (literal.kind, instance)
@@ -181,7 +194,14 @@ def visitConst(self, const, instance):
self.visit(const.type, instance)
def visitStruct(self, struct, instance):
- print ' _write__%s(%s);' % (struct.tag, instance)
+ print ' trace::localWriter.beginStruct(&_struct%s_sig);' % (struct.tag,)
+ self.instances.append(instance)
+ try:
+ for type, name in struct.members:
+ self.visit(type, '(%s).%s' % (instance, name,))
+ finally:
+ self.instances.pop()
+ print ' trace::localWriter.endStruct();'
def visitArray(self, array, instance):
length = '_c' + array.type.tag
@@ -191,7 +211,11 @@ def visitArray(self, array, instance):
print ' trace::localWriter.beginArray(%s);' % length
print ' for (size_t %s = 0; %s < %s; ++%s) {' % (index, index, length, index)
print ' trace::localWriter.beginElement();'
- self.visit(array.type, '(%s)[%s]' % (instance, index))
+ self.indices.append(index)
+ try:
+ self.visit(array.type, '(%s)[%s]' % (instance, index))
+ finally:
+ self.indices.pop()
print ' trace::localWriter.endElement();'
print ' }'
print ' trace::localWriter.endArray();'
@@ -200,7 +224,7 @@ def visitArray(self, array, instance):
print ' }'
def visitBlob(self, blob, instance):
- print ' trace::localWriter.writeBlob(%s, %s);' % (instance, blob.size)
+ print ' trace::localWriter.writeBlob(%s, %s);' % (instance, self.expand(blob.size))
def visitEnum(self, enum, instance):
print ' trace::localWriter.writeEnum(&_enum%s_sig, %s);' % (enum.tag, instance)
Please sign in to comment.
Something went wrong with that request. Please try again.